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 KS |
91 | static void |
92 | create_sals_from_location_default (const struct event_location *location, | |
93 | struct linespec_result *canonical, | |
94 | enum bptype type_wanted); | |
983af33b SDJ |
95 | |
96 | static void create_breakpoints_sal_default (struct gdbarch *, | |
97 | struct linespec_result *, | |
e1e01040 PA |
98 | gdb::unique_xmalloc_ptr<char>, |
99 | gdb::unique_xmalloc_ptr<char>, | |
100 | enum bptype, | |
983af33b SDJ |
101 | enum bpdisp, int, int, |
102 | int, | |
103 | const struct breakpoint_ops *, | |
44f238bb | 104 | int, int, int, unsigned); |
983af33b | 105 | |
6c5b2ebe PA |
106 | static std::vector<symtab_and_line> decode_location_default |
107 | (struct breakpoint *b, const struct event_location *location, | |
108 | struct program_space *search_pspace); | |
983af33b | 109 | |
a6535de1 TT |
110 | static int can_use_hardware_watchpoint |
111 | (const std::vector<value_ref_ptr> &vals); | |
c906108c | 112 | |
a14ed312 | 113 | static void mention (struct breakpoint *); |
c906108c | 114 | |
348d480f PA |
115 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
116 | enum bptype, | |
c0a91b2b | 117 | const struct breakpoint_ops *); |
3742cc8b YQ |
118 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
119 | const struct symtab_and_line *); | |
120 | ||
4a64f543 MS |
121 | /* This function is used in gdbtk sources and thus can not be made |
122 | static. */ | |
63c252f8 | 123 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 124 | struct symtab_and_line, |
c0a91b2b TT |
125 | enum bptype, |
126 | const struct breakpoint_ops *); | |
c906108c | 127 | |
06edf0c0 PA |
128 | static struct breakpoint * |
129 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
130 | enum bptype type, | |
a1aa2221 LM |
131 | const struct breakpoint_ops *ops, |
132 | int loc_enabled); | |
06edf0c0 | 133 | |
76897487 KB |
134 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
135 | ||
a6d9a66e UW |
136 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
137 | CORE_ADDR bpaddr, | |
88f7da05 | 138 | enum bptype bptype); |
76897487 | 139 | |
6c95b8df PA |
140 | static void describe_other_breakpoints (struct gdbarch *, |
141 | struct program_space *, CORE_ADDR, | |
5af949e3 | 142 | struct obj_section *, int); |
c906108c | 143 | |
85d721b8 PA |
144 | static int watchpoint_locations_match (struct bp_location *loc1, |
145 | struct bp_location *loc2); | |
146 | ||
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 | ||
adc36818 | 833 | void |
7a26bd4d | 834 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
835 | int from_tty) |
836 | { | |
3a5c3e22 PA |
837 | xfree (b->cond_string); |
838 | b->cond_string = NULL; | |
adc36818 | 839 | |
3a5c3e22 | 840 | if (is_watchpoint (b)) |
adc36818 | 841 | { |
3a5c3e22 PA |
842 | struct watchpoint *w = (struct watchpoint *) b; |
843 | ||
4d01a485 | 844 | w->cond_exp.reset (); |
3a5c3e22 PA |
845 | } |
846 | else | |
847 | { | |
848 | struct bp_location *loc; | |
849 | ||
850 | for (loc = b->loc; loc; loc = loc->next) | |
851 | { | |
4d01a485 | 852 | loc->cond.reset (); |
b775012e LM |
853 | |
854 | /* No need to free the condition agent expression | |
855 | bytecode (if we have one). We will handle this | |
856 | when we go through update_global_location_list. */ | |
3a5c3e22 | 857 | } |
adc36818 | 858 | } |
adc36818 PM |
859 | |
860 | if (*exp == 0) | |
861 | { | |
862 | if (from_tty) | |
863 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
864 | } | |
865 | else | |
866 | { | |
bbc13ae3 | 867 | const char *arg = exp; |
cc59ec59 | 868 | |
adc36818 PM |
869 | /* I don't know if it matters whether this is the string the user |
870 | typed in or the decompiled expression. */ | |
871 | b->cond_string = xstrdup (arg); | |
872 | b->condition_not_parsed = 0; | |
873 | ||
874 | if (is_watchpoint (b)) | |
875 | { | |
3a5c3e22 PA |
876 | struct watchpoint *w = (struct watchpoint *) b; |
877 | ||
699bd4cf | 878 | innermost_block_tracker tracker; |
adc36818 | 879 | arg = exp; |
699bd4cf | 880 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
adc36818 PM |
881 | if (*arg) |
882 | error (_("Junk at end of expression")); | |
699bd4cf | 883 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
884 | } |
885 | else | |
886 | { | |
3a5c3e22 PA |
887 | struct bp_location *loc; |
888 | ||
adc36818 PM |
889 | for (loc = b->loc; loc; loc = loc->next) |
890 | { | |
891 | arg = exp; | |
892 | loc->cond = | |
1bb9788d TT |
893 | parse_exp_1 (&arg, loc->address, |
894 | block_for_pc (loc->address), 0); | |
adc36818 PM |
895 | if (*arg) |
896 | error (_("Junk at end of expression")); | |
897 | } | |
898 | } | |
899 | } | |
b775012e LM |
900 | mark_breakpoint_modified (b); |
901 | ||
76727919 | 902 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
903 | } |
904 | ||
d55637df TT |
905 | /* Completion for the "condition" command. */ |
906 | ||
eb3ff9a5 | 907 | static void |
6f937416 | 908 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 909 | completion_tracker &tracker, |
6f937416 | 910 | const char *text, const char *word) |
d55637df | 911 | { |
6f937416 | 912 | const char *space; |
d55637df | 913 | |
f1735a53 TT |
914 | text = skip_spaces (text); |
915 | space = skip_to_space (text); | |
d55637df TT |
916 | if (*space == '\0') |
917 | { | |
918 | int len; | |
919 | struct breakpoint *b; | |
d55637df TT |
920 | |
921 | if (text[0] == '$') | |
922 | { | |
923 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
924 | if (!isdigit (text[1])) |
925 | complete_internalvar (tracker, &text[1]); | |
926 | return; | |
d55637df TT |
927 | } |
928 | ||
929 | /* We're completing the breakpoint number. */ | |
930 | len = strlen (text); | |
931 | ||
932 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
933 | { |
934 | char number[50]; | |
935 | ||
936 | xsnprintf (number, sizeof (number), "%d", b->number); | |
937 | ||
938 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 939 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 940 | } |
d55637df | 941 | |
eb3ff9a5 | 942 | return; |
d55637df TT |
943 | } |
944 | ||
945 | /* We're completing the expression part. */ | |
f1735a53 | 946 | text = skip_spaces (space); |
eb3ff9a5 | 947 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
948 | } |
949 | ||
c906108c SS |
950 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
951 | ||
952 | static void | |
0b39b52e | 953 | condition_command (const char *arg, int from_tty) |
c906108c | 954 | { |
52f0bd74 | 955 | struct breakpoint *b; |
0b39b52e | 956 | const char *p; |
52f0bd74 | 957 | int bnum; |
c906108c SS |
958 | |
959 | if (arg == 0) | |
e2e0b3e5 | 960 | error_no_arg (_("breakpoint number")); |
c906108c SS |
961 | |
962 | p = arg; | |
963 | bnum = get_number (&p); | |
5c44784c | 964 | if (bnum == 0) |
8a3fe4f8 | 965 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
966 | |
967 | ALL_BREAKPOINTS (b) | |
968 | if (b->number == bnum) | |
2f069f6f | 969 | { |
6dddc817 DE |
970 | /* Check if this breakpoint has a "stop" method implemented in an |
971 | extension language. This method and conditions entered into GDB | |
972 | from the CLI are mutually exclusive. */ | |
973 | const struct extension_language_defn *extlang | |
974 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
975 | ||
976 | if (extlang != NULL) | |
977 | { | |
978 | error (_("Only one stop condition allowed. There is currently" | |
979 | " a %s stop condition defined for this breakpoint."), | |
980 | ext_lang_capitalized_name (extlang)); | |
981 | } | |
2566ad2d | 982 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
983 | |
984 | if (is_breakpoint (b)) | |
44702360 | 985 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 986 | |
2f069f6f JB |
987 | return; |
988 | } | |
c906108c | 989 | |
8a3fe4f8 | 990 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
991 | } |
992 | ||
a7bdde9e VP |
993 | /* Check that COMMAND do not contain commands that are suitable |
994 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
995 | Throw if any such commands is found. */ |
996 | ||
a7bdde9e VP |
997 | static void |
998 | check_no_tracepoint_commands (struct command_line *commands) | |
999 | { | |
1000 | struct command_line *c; | |
cc59ec59 | 1001 | |
a7bdde9e VP |
1002 | for (c = commands; c; c = c->next) |
1003 | { | |
a7bdde9e | 1004 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
1005 | error (_("The 'while-stepping' command can " |
1006 | "only be used for tracepoints")); | |
a7bdde9e | 1007 | |
12973681 TT |
1008 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1009 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1010 | |
1011 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1012 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1013 | command directly. */ |
1014 | if (strstr (c->line, "collect ") == c->line) | |
1015 | error (_("The 'collect' command can only be used for tracepoints")); | |
1016 | ||
51661e93 VP |
1017 | if (strstr (c->line, "teval ") == c->line) |
1018 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1019 | } |
1020 | } | |
1021 | ||
c1fc2657 | 1022 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1023 | { |
c1fc2657 | 1024 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1025 | }; |
1026 | ||
d77f58be SS |
1027 | /* Encapsulate tests for different types of tracepoints. */ |
1028 | ||
3b0871f4 SM |
1029 | static bool |
1030 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1031 | { |
1032 | return (type == bp_tracepoint | |
1033 | || type == bp_fast_tracepoint | |
1034 | || type == bp_static_tracepoint); | |
1035 | } | |
1036 | ||
3b0871f4 SM |
1037 | static bool |
1038 | is_longjmp_type (bptype type) | |
1039 | { | |
1040 | return type == bp_longjmp || type == bp_exception; | |
1041 | } | |
1042 | ||
f2478a7e SM |
1043 | /* See breakpoint.h. */ |
1044 | ||
1045 | bool | |
d77f58be | 1046 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1047 | { |
d9b3f62e | 1048 | return is_tracepoint_type (b->type); |
a7bdde9e | 1049 | } |
d9b3f62e | 1050 | |
a5e364af SM |
1051 | /* Factory function to create an appropriate instance of breakpoint given |
1052 | TYPE. */ | |
1053 | ||
1054 | static std::unique_ptr<breakpoint> | |
1055 | new_breakpoint_from_type (bptype type) | |
1056 | { | |
1057 | breakpoint *b; | |
1058 | ||
1059 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1060 | b = new tracepoint (); |
3b0871f4 | 1061 | else if (is_longjmp_type (type)) |
c1fc2657 | 1062 | b = new longjmp_breakpoint (); |
a5e364af SM |
1063 | else |
1064 | b = new breakpoint (); | |
1065 | ||
1066 | return std::unique_ptr<breakpoint> (b); | |
1067 | } | |
1068 | ||
e5dd4106 | 1069 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1070 | breakpoint. This function will throw an exception if a problem is |
1071 | found. */ | |
48cb2d85 | 1072 | |
95a42b64 TT |
1073 | static void |
1074 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1075 | struct command_line *commands) | |
48cb2d85 | 1076 | { |
d77f58be | 1077 | if (is_tracepoint (b)) |
a7bdde9e | 1078 | { |
c9a6ce02 | 1079 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1080 | struct command_line *c; |
1081 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1082 | |
1083 | /* Reset the while-stepping step count. The previous commands | |
1084 | might have included a while-stepping action, while the new | |
1085 | ones might not. */ | |
1086 | t->step_count = 0; | |
1087 | ||
1088 | /* We need to verify that each top-level element of commands is | |
1089 | valid for tracepoints, that there's at most one | |
1090 | while-stepping element, and that the while-stepping's body | |
1091 | has valid tracing commands excluding nested while-stepping. | |
1092 | We also need to validate the tracepoint action line in the | |
1093 | context of the tracepoint --- validate_actionline actually | |
1094 | has side effects, like setting the tracepoint's | |
1095 | while-stepping STEP_COUNT, in addition to checking if the | |
1096 | collect/teval actions parse and make sense in the | |
1097 | tracepoint's context. */ | |
a7bdde9e VP |
1098 | for (c = commands; c; c = c->next) |
1099 | { | |
a7bdde9e VP |
1100 | if (c->control_type == while_stepping_control) |
1101 | { | |
1102 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1103 | error (_("The 'while-stepping' command " |
1104 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1105 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1106 | error (_("The 'while-stepping' command " |
1107 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1108 | |
1109 | if (while_stepping) | |
3e43a32a MS |
1110 | error (_("The 'while-stepping' command " |
1111 | "can be used only once")); | |
a7bdde9e VP |
1112 | else |
1113 | while_stepping = c; | |
1114 | } | |
c9a6ce02 PA |
1115 | |
1116 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1117 | } |
1118 | if (while_stepping) | |
1119 | { | |
1120 | struct command_line *c2; | |
1121 | ||
12973681 TT |
1122 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1123 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1124 | for (; c2; c2 = c2->next) |
1125 | { | |
a7bdde9e VP |
1126 | if (c2->control_type == while_stepping_control) |
1127 | error (_("The 'while-stepping' command cannot be nested")); | |
1128 | } | |
1129 | } | |
1130 | } | |
1131 | else | |
1132 | { | |
1133 | check_no_tracepoint_commands (commands); | |
1134 | } | |
95a42b64 TT |
1135 | } |
1136 | ||
0fb4aa4b PA |
1137 | /* Return a vector of all the static tracepoints set at ADDR. The |
1138 | caller is responsible for releasing the vector. */ | |
1139 | ||
f51e0e20 | 1140 | std::vector<breakpoint *> |
0fb4aa4b PA |
1141 | static_tracepoints_here (CORE_ADDR addr) |
1142 | { | |
1143 | struct breakpoint *b; | |
f51e0e20 | 1144 | std::vector<breakpoint *> found; |
0fb4aa4b PA |
1145 | struct bp_location *loc; |
1146 | ||
1147 | ALL_BREAKPOINTS (b) | |
1148 | if (b->type == bp_static_tracepoint) | |
1149 | { | |
1150 | for (loc = b->loc; loc; loc = loc->next) | |
1151 | if (loc->address == addr) | |
f51e0e20 | 1152 | found.push_back (b); |
0fb4aa4b PA |
1153 | } |
1154 | ||
1155 | return found; | |
1156 | } | |
1157 | ||
95a42b64 | 1158 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1159 | validate that only allowed commands are included. */ |
95a42b64 TT |
1160 | |
1161 | void | |
4a64f543 | 1162 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1163 | counted_command_line &&commands) |
95a42b64 | 1164 | { |
93921405 | 1165 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1166 | |
d1b0a7bf | 1167 | b->commands = std::move (commands); |
76727919 | 1168 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1169 | } |
1170 | ||
45a43567 TT |
1171 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1172 | is not the same as the "silent" that may appear in the breakpoint's | |
1173 | commands. */ | |
1174 | ||
1175 | void | |
1176 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1177 | { | |
1178 | int old_silent = b->silent; | |
1179 | ||
1180 | b->silent = silent; | |
1181 | if (old_silent != silent) | |
76727919 | 1182 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1183 | } |
1184 | ||
1185 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1186 | breakpoint work for any thread. */ | |
1187 | ||
1188 | void | |
1189 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1190 | { | |
1191 | int old_thread = b->thread; | |
1192 | ||
1193 | b->thread = thread; | |
1194 | if (old_thread != thread) | |
76727919 | 1195 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1196 | } |
1197 | ||
1198 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1199 | breakpoint work for any task. */ | |
1200 | ||
1201 | void | |
1202 | breakpoint_set_task (struct breakpoint *b, int task) | |
1203 | { | |
1204 | int old_task = b->task; | |
1205 | ||
1206 | b->task = task; | |
1207 | if (old_task != task) | |
76727919 | 1208 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1209 | } |
1210 | ||
95a42b64 | 1211 | static void |
896b6bda | 1212 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1213 | struct command_line *control) |
95a42b64 | 1214 | { |
d1b0a7bf | 1215 | counted_command_line cmd; |
999700cd PW |
1216 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1217 | NULL after the call to read_command_lines if the user provides an empty | |
1218 | list of command by just typing "end". */ | |
1219 | bool cmd_read = false; | |
95a42b64 | 1220 | |
896b6bda PA |
1221 | std::string new_arg; |
1222 | ||
95a42b64 TT |
1223 | if (arg == NULL || !*arg) |
1224 | { | |
86b17b60 | 1225 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1226 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1227 | breakpoint_count); | |
95a42b64 | 1228 | else if (breakpoint_count > 0) |
896b6bda | 1229 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1230 | arg = new_arg.c_str (); |
1231 | } | |
1232 | ||
1233 | map_breakpoint_numbers | |
1234 | (arg, [&] (breakpoint *b) | |
1235 | { | |
999700cd | 1236 | if (!cmd_read) |
48649e1b | 1237 | { |
999700cd | 1238 | gdb_assert (cmd == NULL); |
48649e1b | 1239 | if (control != NULL) |
12973681 | 1240 | cmd = control->body_list_0; |
48649e1b TT |
1241 | else |
1242 | { | |
81b1e71c TT |
1243 | std::string str |
1244 | = string_printf (_("Type commands for breakpoint(s) " | |
1245 | "%s, one per line."), | |
1246 | arg); | |
48649e1b | 1247 | |
60b3cef2 TT |
1248 | auto do_validate = [=] (const char *line) |
1249 | { | |
1250 | validate_actionline (line, b); | |
1251 | }; | |
1252 | gdb::function_view<void (const char *)> validator; | |
1253 | if (is_tracepoint (b)) | |
1254 | validator = do_validate; | |
1255 | ||
1256 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1257 | } |
999700cd | 1258 | cmd_read = true; |
48649e1b TT |
1259 | } |
1260 | ||
1261 | /* If a breakpoint was on the list more than once, we don't need to | |
1262 | do anything. */ | |
1263 | if (b->commands != cmd) | |
1264 | { | |
d1b0a7bf | 1265 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1266 | b->commands = cmd; |
76727919 | 1267 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1268 | } |
1269 | }); | |
95a42b64 TT |
1270 | } |
1271 | ||
1272 | static void | |
0b39b52e | 1273 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1274 | { |
1275 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1276 | } |
40c03ae8 EZ |
1277 | |
1278 | /* Like commands_command, but instead of reading the commands from | |
1279 | input stream, takes them from an already parsed command structure. | |
1280 | ||
1281 | This is used by cli-script.c to DTRT with breakpoint commands | |
1282 | that are part of if and while bodies. */ | |
1283 | enum command_control_type | |
896b6bda | 1284 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1285 | { |
95a42b64 TT |
1286 | commands_command_1 (arg, 0, cmd); |
1287 | return simple_control; | |
40c03ae8 | 1288 | } |
876fa593 JK |
1289 | |
1290 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1291 | ||
1292 | static int | |
1293 | bp_location_has_shadow (struct bp_location *bl) | |
1294 | { | |
1295 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1296 | return 0; | |
1297 | if (!bl->inserted) | |
1298 | return 0; | |
1299 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1300 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1301 | return 0; |
1302 | return 1; | |
1303 | } | |
1304 | ||
9d497a19 PA |
1305 | /* Update BUF, which is LEN bytes read from the target address |
1306 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1307 | contents. | |
1308 | ||
1309 | If READBUF is not NULL, this buffer must not overlap with the of | |
1310 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1311 | failed assertion internal error will be raised. */ | |
1312 | ||
1313 | static void | |
1314 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1315 | const gdb_byte *writebuf_org, | |
1316 | ULONGEST memaddr, LONGEST len, | |
1317 | struct bp_target_info *target_info, | |
1318 | struct gdbarch *gdbarch) | |
1319 | { | |
1320 | /* Now do full processing of the found relevant range of elements. */ | |
1321 | CORE_ADDR bp_addr = 0; | |
1322 | int bp_size = 0; | |
1323 | int bptoffset = 0; | |
1324 | ||
1325 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1326 | current_program_space->aspace, 0)) | |
1327 | { | |
1328 | /* The breakpoint is inserted in a different address space. */ | |
1329 | return; | |
1330 | } | |
1331 | ||
1332 | /* Addresses and length of the part of the breakpoint that | |
1333 | we need to copy. */ | |
1334 | bp_addr = target_info->placed_address; | |
1335 | bp_size = target_info->shadow_len; | |
1336 | ||
1337 | if (bp_addr + bp_size <= memaddr) | |
1338 | { | |
1339 | /* The breakpoint is entirely before the chunk of memory we are | |
1340 | reading. */ | |
1341 | return; | |
1342 | } | |
1343 | ||
1344 | if (bp_addr >= memaddr + len) | |
1345 | { | |
1346 | /* The breakpoint is entirely after the chunk of memory we are | |
1347 | reading. */ | |
1348 | return; | |
1349 | } | |
1350 | ||
1351 | /* Offset within shadow_contents. */ | |
1352 | if (bp_addr < memaddr) | |
1353 | { | |
1354 | /* Only copy the second part of the breakpoint. */ | |
1355 | bp_size -= memaddr - bp_addr; | |
1356 | bptoffset = memaddr - bp_addr; | |
1357 | bp_addr = memaddr; | |
1358 | } | |
1359 | ||
1360 | if (bp_addr + bp_size > memaddr + len) | |
1361 | { | |
1362 | /* Only copy the first part of the breakpoint. */ | |
1363 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1364 | } | |
1365 | ||
1366 | if (readbuf != NULL) | |
1367 | { | |
1368 | /* Verify that the readbuf buffer does not overlap with the | |
1369 | shadow_contents buffer. */ | |
1370 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1371 | || readbuf >= (target_info->shadow_contents | |
1372 | + target_info->shadow_len)); | |
1373 | ||
1374 | /* Update the read buffer with this inserted breakpoint's | |
1375 | shadow. */ | |
1376 | memcpy (readbuf + bp_addr - memaddr, | |
1377 | target_info->shadow_contents + bptoffset, bp_size); | |
1378 | } | |
1379 | else | |
1380 | { | |
1381 | const unsigned char *bp; | |
0d5ed153 MR |
1382 | CORE_ADDR addr = target_info->reqstd_address; |
1383 | int placed_size; | |
9d497a19 PA |
1384 | |
1385 | /* Update the shadow with what we want to write to memory. */ | |
1386 | memcpy (target_info->shadow_contents + bptoffset, | |
1387 | writebuf_org + bp_addr - memaddr, bp_size); | |
1388 | ||
1389 | /* Determine appropriate breakpoint contents and size for this | |
1390 | address. */ | |
0d5ed153 | 1391 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1392 | |
1393 | /* Update the final write buffer with this inserted | |
1394 | breakpoint's INSN. */ | |
1395 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1396 | } | |
1397 | } | |
1398 | ||
8defab1a | 1399 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1400 | by replacing any memory breakpoints with their shadowed contents. |
1401 | ||
35c63cd8 JB |
1402 | If READBUF is not NULL, this buffer must not overlap with any of |
1403 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1404 | a failed assertion internal error will be raised. | |
1405 | ||
876fa593 | 1406 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1407 | bl->address - bp_locations_placed_address_before_address_max |
1408 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1409 | The range we were requested to resolve shadows for is: |
1410 | memaddr ... memaddr + len | |
1411 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1412 | memaddr + len <= (bl->address |
f5336ca5 | 1413 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1414 | and: |
f5336ca5 | 1415 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1416 | |
8defab1a | 1417 | void |
f0ba3972 PA |
1418 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1419 | const gdb_byte *writebuf_org, | |
1420 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1421 | { |
4a64f543 MS |
1422 | /* Left boundary, right boundary and median element of our binary |
1423 | search. */ | |
876fa593 JK |
1424 | unsigned bc_l, bc_r, bc; |
1425 | ||
4a64f543 MS |
1426 | /* Find BC_L which is a leftmost element which may affect BUF |
1427 | content. It is safe to report lower value but a failure to | |
1428 | report higher one. */ | |
876fa593 JK |
1429 | |
1430 | bc_l = 0; | |
f5336ca5 | 1431 | bc_r = bp_locations_count; |
876fa593 JK |
1432 | while (bc_l + 1 < bc_r) |
1433 | { | |
35df4500 | 1434 | struct bp_location *bl; |
876fa593 JK |
1435 | |
1436 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1437 | bl = bp_locations[bc]; |
876fa593 | 1438 | |
4a64f543 MS |
1439 | /* Check first BL->ADDRESS will not overflow due to the added |
1440 | constant. Then advance the left boundary only if we are sure | |
1441 | the BC element can in no way affect the BUF content (MEMADDR | |
1442 | to MEMADDR + LEN range). | |
876fa593 | 1443 | |
f5336ca5 | 1444 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1445 | offset so that we cannot miss a breakpoint with its shadow |
1446 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1447 | |
f5336ca5 | 1448 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1449 | >= bl->address) |
f5336ca5 | 1450 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1451 | <= memaddr)) |
876fa593 JK |
1452 | bc_l = bc; |
1453 | else | |
1454 | bc_r = bc; | |
1455 | } | |
1456 | ||
128070bb PA |
1457 | /* Due to the binary search above, we need to make sure we pick the |
1458 | first location that's at BC_L's address. E.g., if there are | |
1459 | multiple locations at the same address, BC_L may end up pointing | |
1460 | at a duplicate location, and miss the "master"/"inserted" | |
1461 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1462 | B: | |
1463 | ||
1464 | L1@A, L2@A, L3@B, ... | |
1465 | ||
1466 | BC_L could end up pointing at location L2, while the "master" | |
1467 | location could be L1. Since the `loc->inserted' flag is only set | |
1468 | on "master" locations, we'd forget to restore the shadow of L1 | |
1469 | and L2. */ | |
1470 | while (bc_l > 0 | |
f5336ca5 | 1471 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1472 | bc_l--; |
1473 | ||
876fa593 JK |
1474 | /* Now do full processing of the found relevant range of elements. */ |
1475 | ||
f5336ca5 | 1476 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1477 | { |
f5336ca5 | 1478 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1479 | |
35df4500 TJB |
1480 | /* bp_location array has BL->OWNER always non-NULL. */ |
1481 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1482 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1483 | bl->owner->number); |
ffce0d52 | 1484 | |
e5dd4106 | 1485 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1486 | content. */ |
1487 | ||
f5336ca5 PA |
1488 | if (bl->address >= bp_locations_placed_address_before_address_max |
1489 | && memaddr + len <= (bl->address | |
1490 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1491 | break; |
1492 | ||
35df4500 | 1493 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1494 | continue; |
6c95b8df | 1495 | |
9d497a19 PA |
1496 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1497 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1498 | } | |
c906108c | 1499 | } |
9d497a19 | 1500 | |
f2478a7e | 1501 | /* See breakpoint.h. */ |
b775012e | 1502 | |
f2478a7e | 1503 | bool |
b775012e LM |
1504 | is_breakpoint (const struct breakpoint *bpt) |
1505 | { | |
1506 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1507 | || bpt->type == bp_hardware_breakpoint |
1508 | || bpt->type == bp_dprintf); | |
b775012e LM |
1509 | } |
1510 | ||
60e1c644 PA |
1511 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1512 | ||
f2478a7e | 1513 | static bool |
d77f58be | 1514 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1515 | { |
1516 | return (bpt->type == bp_hardware_watchpoint | |
1517 | || bpt->type == bp_read_watchpoint | |
1518 | || bpt->type == bp_access_watchpoint); | |
1519 | } | |
7270d8f2 | 1520 | |
f2478a7e | 1521 | /* See breakpoint.h. */ |
60e1c644 | 1522 | |
f2478a7e | 1523 | bool |
d77f58be | 1524 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1525 | { |
1526 | return (is_hardware_watchpoint (bpt) | |
1527 | || bpt->type == bp_watchpoint); | |
1528 | } | |
1529 | ||
3a5c3e22 PA |
1530 | /* Returns true if the current thread and its running state are safe |
1531 | to evaluate or update watchpoint B. Watchpoints on local | |
1532 | expressions need to be evaluated in the context of the thread that | |
1533 | was current when the watchpoint was created, and, that thread needs | |
1534 | to be stopped to be able to select the correct frame context. | |
1535 | Watchpoints on global expressions can be evaluated on any thread, | |
1536 | and in any state. It is presently left to the target allowing | |
1537 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1538 | |
1539 | static int | |
3a5c3e22 | 1540 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1541 | { |
c1fc2657 | 1542 | return (b->pspace == current_program_space |
d7e15655 TT |
1543 | && (b->watchpoint_thread == null_ptid |
1544 | || (inferior_ptid == b->watchpoint_thread | |
00431a78 | 1545 | && !inferior_thread ()->executing))); |
f6bc2008 PA |
1546 | } |
1547 | ||
d0fb5eae JK |
1548 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1549 | associated bp_watchpoint_scope breakpoint. */ | |
1550 | ||
1551 | static void | |
3a5c3e22 | 1552 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1553 | { |
c1fc2657 | 1554 | if (w->related_breakpoint != w) |
d0fb5eae | 1555 | { |
c1fc2657 SM |
1556 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1557 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1558 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1559 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1560 | w->related_breakpoint = w; | |
d0fb5eae | 1561 | } |
c1fc2657 | 1562 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1563 | } |
1564 | ||
bb9d5f81 PP |
1565 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1566 | watchpoint W. */ | |
1567 | ||
1568 | static struct value * | |
1569 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1570 | { | |
1571 | struct value *bit_val; | |
1572 | ||
1573 | if (val == NULL) | |
1574 | return NULL; | |
1575 | ||
1576 | bit_val = allocate_value (value_type (val)); | |
1577 | ||
1578 | unpack_value_bitfield (bit_val, | |
1579 | w->val_bitpos, | |
1580 | w->val_bitsize, | |
1581 | value_contents_for_printing (val), | |
1582 | value_offset (val), | |
1583 | val); | |
1584 | ||
1585 | return bit_val; | |
1586 | } | |
1587 | ||
c6d81124 PA |
1588 | /* Allocate a dummy location and add it to B, which must be a software |
1589 | watchpoint. This is required because even if a software watchpoint | |
1590 | is not watching any memory, bpstat_stop_status requires a location | |
1591 | to be able to report stops. */ | |
1592 | ||
1593 | static void | |
1594 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1595 | struct program_space *pspace) | |
1596 | { | |
1597 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1598 | ||
1599 | b->loc = allocate_bp_location (b); | |
1600 | b->loc->pspace = pspace; | |
1601 | b->loc->address = -1; | |
1602 | b->loc->length = -1; | |
1603 | } | |
1604 | ||
1605 | /* Returns true if B is a software watchpoint that is not watching any | |
1606 | memory (e.g., "watch $pc"). */ | |
1607 | ||
f2478a7e | 1608 | static bool |
c6d81124 PA |
1609 | is_no_memory_software_watchpoint (struct breakpoint *b) |
1610 | { | |
1611 | return (b->type == bp_watchpoint | |
1612 | && b->loc != NULL | |
1613 | && b->loc->next == NULL | |
1614 | && b->loc->address == -1 | |
1615 | && b->loc->length == -1); | |
1616 | } | |
1617 | ||
567e1b4e JB |
1618 | /* Assuming that B is a watchpoint: |
1619 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1620 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1621 | - Evaluate the condition if there is one, and store the result |
1622 | in b->loc->cond. | |
a5606eee VP |
1623 | - Update the list of values that must be watched in B->loc. |
1624 | ||
4a64f543 MS |
1625 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1626 | nothing. If this is local watchpoint that is out of scope, delete | |
1627 | it. | |
1628 | ||
1629 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1630 | removed + inserted on each stop here. Normal breakpoints must | |
1631 | never be removed because they might be missed by a running thread | |
1632 | when debugging in non-stop mode. On the other hand, hardware | |
1633 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1634 | to each LWP since they are stored in each LWP's hardware debug | |
1635 | registers. Therefore, such LWP must be stopped first in order to | |
1636 | be able to modify its hardware watchpoints. | |
1637 | ||
1638 | Hardware watchpoints must be reset exactly once after being | |
1639 | presented to the user. It cannot be done sooner, because it would | |
1640 | reset the data used to present the watchpoint hit to the user. And | |
1641 | it must not be done later because it could display the same single | |
1642 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1643 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1644 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1645 | not user-visible - its hit is suppressed if the memory content has | |
1646 | not changed. | |
1647 | ||
1648 | The following constraints influence the location where we can reset | |
1649 | hardware watchpoints: | |
1650 | ||
1651 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1652 | called several times when GDB stops. | |
1653 | ||
1654 | [linux] | |
1655 | * Multiple hardware watchpoints can be hit at the same time, | |
1656 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1657 | hit at a time as the reason for stopping, and all the other hits | |
1658 | are presented later, one after the other, each time the user | |
1659 | requests the execution to be resumed. Execution is not resumed | |
1660 | for the threads still having pending hit event stored in | |
1661 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1662 | the inferior on the first stop the thread hit event is kept being | |
1663 | reported from its cached value by linux_nat_stopped_data_address | |
1664 | until the real thread resume happens after the watchpoint gets | |
1665 | presented and thus its LWP_INFO->STATUS gets reset. | |
1666 | ||
1667 | Therefore the hardware watchpoint hit can get safely reset on the | |
1668 | watchpoint removal from inferior. */ | |
a79d3c27 | 1669 | |
b40ce68a | 1670 | static void |
3a5c3e22 | 1671 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1672 | { |
a5606eee | 1673 | int within_current_scope; |
a5606eee | 1674 | struct frame_id saved_frame_id; |
66076460 | 1675 | int frame_saved; |
a5606eee | 1676 | |
f6bc2008 PA |
1677 | /* If this is a local watchpoint, we only want to check if the |
1678 | watchpoint frame is in scope if the current thread is the thread | |
1679 | that was used to create the watchpoint. */ | |
1680 | if (!watchpoint_in_thread_scope (b)) | |
1681 | return; | |
1682 | ||
c1fc2657 | 1683 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1684 | return; |
1685 | ||
66076460 | 1686 | frame_saved = 0; |
a5606eee VP |
1687 | |
1688 | /* Determine if the watchpoint is within scope. */ | |
1689 | if (b->exp_valid_block == NULL) | |
1690 | within_current_scope = 1; | |
1691 | else | |
1692 | { | |
b5db5dfc UW |
1693 | struct frame_info *fi = get_current_frame (); |
1694 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1695 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1696 | ||
c9cf6e20 MG |
1697 | /* If we're at a point where the stack has been destroyed |
1698 | (e.g. in a function epilogue), unwinding may not work | |
1699 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1700 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1701 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1702 | return; |
66076460 DJ |
1703 | |
1704 | /* Save the current frame's ID so we can restore it after | |
1705 | evaluating the watchpoint expression on its own frame. */ | |
1706 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1707 | took a frame parameter, so that we didn't have to change the | |
1708 | selected frame. */ | |
1709 | frame_saved = 1; | |
1710 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1711 | ||
a5606eee VP |
1712 | fi = frame_find_by_id (b->watchpoint_frame); |
1713 | within_current_scope = (fi != NULL); | |
1714 | if (within_current_scope) | |
1715 | select_frame (fi); | |
1716 | } | |
1717 | ||
b5db5dfc UW |
1718 | /* We don't free locations. They are stored in the bp_location array |
1719 | and update_global_location_list will eventually delete them and | |
1720 | remove breakpoints if needed. */ | |
c1fc2657 | 1721 | b->loc = NULL; |
b5db5dfc | 1722 | |
a5606eee VP |
1723 | if (within_current_scope && reparse) |
1724 | { | |
bbc13ae3 | 1725 | const char *s; |
d63d0675 | 1726 | |
4d01a485 | 1727 | b->exp.reset (); |
d63d0675 | 1728 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1729 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1730 | /* If the meaning of expression itself changed, the old value is |
1731 | no longer relevant. We don't want to report a watchpoint hit | |
1732 | to the user when the old value and the new value may actually | |
1733 | be completely different objects. */ | |
fa4727a6 | 1734 | b->val = NULL; |
4c1d86d9 | 1735 | b->val_valid = false; |
60e1c644 PA |
1736 | |
1737 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1738 | expression is stored in the breakpoint object, not in the | |
1739 | locations (re)created below. */ | |
c1fc2657 | 1740 | if (b->cond_string != NULL) |
60e1c644 | 1741 | { |
4d01a485 | 1742 | b->cond_exp.reset (); |
60e1c644 | 1743 | |
c1fc2657 | 1744 | s = b->cond_string; |
1bb9788d | 1745 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1746 | } |
a5606eee | 1747 | } |
a5606eee VP |
1748 | |
1749 | /* If we failed to parse the expression, for example because | |
1750 | it refers to a global variable in a not-yet-loaded shared library, | |
1751 | don't try to insert watchpoint. We don't automatically delete | |
1752 | such watchpoint, though, since failure to parse expression | |
1753 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1754 | if (!target_has_execution) |
2d134ed3 PA |
1755 | { |
1756 | /* Without execution, memory can't change. No use to try and | |
1757 | set watchpoint locations. The watchpoint will be reset when | |
1758 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1759 | if (!can_use_hw_watchpoints) |
1760 | { | |
c1fc2657 SM |
1761 | if (b->ops->works_in_software_mode (b)) |
1762 | b->type = bp_watchpoint; | |
e8369a73 | 1763 | else |
638aa5a1 AB |
1764 | error (_("Can't set read/access watchpoint when " |
1765 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1766 | } |
2d134ed3 PA |
1767 | } |
1768 | else if (within_current_scope && b->exp) | |
a5606eee | 1769 | { |
0cf6dd15 | 1770 | int pc = 0; |
a6535de1 | 1771 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 1772 | struct value *v, *result; |
2d134ed3 | 1773 | struct program_space *frame_pspace; |
a5606eee | 1774 | |
4d01a485 | 1775 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1776 | |
a5606eee VP |
1777 | /* Avoid setting b->val if it's already set. The meaning of |
1778 | b->val is 'the last value' user saw, and we should update | |
1779 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1780 | happens, the code that reports it updates b->val directly. |
1781 | We don't keep track of the memory value for masked | |
1782 | watchpoints. */ | |
c1fc2657 | 1783 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1784 | { |
bb9d5f81 | 1785 | if (b->val_bitsize != 0) |
850645cf TT |
1786 | v = extract_bitfield_from_watchpoint_value (b, v); |
1787 | b->val = release_value (v); | |
4c1d86d9 | 1788 | b->val_valid = true; |
fa4727a6 | 1789 | } |
a5606eee | 1790 | |
2d134ed3 PA |
1791 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1792 | ||
a5606eee | 1793 | /* Look at each value on the value chain. */ |
a6535de1 TT |
1794 | gdb_assert (!val_chain.empty ()); |
1795 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 1796 | { |
a6535de1 TT |
1797 | v = iter.get (); |
1798 | ||
a5606eee VP |
1799 | /* If it's a memory location, and GDB actually needed |
1800 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1801 | must watch it. If the first value returned is |
1802 | still lazy, that means an error occurred reading it; | |
1803 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1804 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 1805 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
1806 | { |
1807 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1808 | |
a5606eee VP |
1809 | /* We only watch structs and arrays if user asked |
1810 | for it explicitly, never if they just happen to | |
1811 | appear in the middle of some value chain. */ | |
fa4727a6 | 1812 | if (v == result |
78134374 SM |
1813 | || (vtype->code () != TYPE_CODE_STRUCT |
1814 | && vtype->code () != TYPE_CODE_ARRAY)) | |
a5606eee VP |
1815 | { |
1816 | CORE_ADDR addr; | |
f486487f | 1817 | enum target_hw_bp_type type; |
a5606eee | 1818 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1819 | int bitpos = 0, bitsize = 0; |
1820 | ||
1821 | if (value_bitsize (v) != 0) | |
1822 | { | |
1823 | /* Extract the bit parameters out from the bitfield | |
1824 | sub-expression. */ | |
1825 | bitpos = value_bitpos (v); | |
1826 | bitsize = value_bitsize (v); | |
1827 | } | |
1828 | else if (v == result && b->val_bitsize != 0) | |
1829 | { | |
1830 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1831 | lvalue whose bit parameters are saved in the fields | |
1832 | VAL_BITPOS and VAL_BITSIZE. */ | |
1833 | bitpos = b->val_bitpos; | |
1834 | bitsize = b->val_bitsize; | |
1835 | } | |
a5606eee | 1836 | |
42ae5230 | 1837 | addr = value_address (v); |
bb9d5f81 PP |
1838 | if (bitsize != 0) |
1839 | { | |
1840 | /* Skip the bytes that don't contain the bitfield. */ | |
1841 | addr += bitpos / 8; | |
1842 | } | |
1843 | ||
a5606eee | 1844 | type = hw_write; |
c1fc2657 | 1845 | if (b->type == bp_read_watchpoint) |
a5606eee | 1846 | type = hw_read; |
c1fc2657 | 1847 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1848 | type = hw_access; |
3a5c3e22 | 1849 | |
c1fc2657 SM |
1850 | loc = allocate_bp_location (b); |
1851 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1852 | ; |
1853 | *tmp = loc; | |
a6d9a66e | 1854 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1855 | |
1856 | loc->pspace = frame_pspace; | |
f17d9474 | 1857 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
1858 | |
1859 | if (bitsize != 0) | |
1860 | { | |
1861 | /* Just cover the bytes that make up the bitfield. */ | |
1862 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1863 | } | |
1864 | else | |
1865 | loc->length = TYPE_LENGTH (value_type (v)); | |
1866 | ||
a5606eee VP |
1867 | loc->watchpoint_type = type; |
1868 | } | |
1869 | } | |
9fa40276 TJB |
1870 | } |
1871 | ||
1872 | /* Change the type of breakpoint between hardware assisted or | |
1873 | an ordinary watchpoint depending on the hardware support | |
1874 | and free hardware slots. REPARSE is set when the inferior | |
1875 | is started. */ | |
a9634178 | 1876 | if (reparse) |
9fa40276 | 1877 | { |
e09342b5 | 1878 | int reg_cnt; |
9fa40276 TJB |
1879 | enum bp_loc_type loc_type; |
1880 | struct bp_location *bl; | |
a5606eee | 1881 | |
a9634178 | 1882 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1883 | |
1884 | if (reg_cnt) | |
9fa40276 TJB |
1885 | { |
1886 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1887 | enum bptype type; |
9fa40276 | 1888 | |
a9634178 TJB |
1889 | /* Use an exact watchpoint when there's only one memory region to be |
1890 | watched, and only one debug register is needed to watch it. */ | |
1891 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1892 | ||
9fa40276 | 1893 | /* We need to determine how many resources are already |
e09342b5 TJB |
1894 | used for all other hardware watchpoints plus this one |
1895 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1896 | this watchpoint in as well. */ |
1897 | ||
1898 | /* If this is a software watchpoint, we try to turn it | |
1899 | to a hardware one -- count resources as if B was of | |
1900 | hardware watchpoint type. */ | |
c1fc2657 | 1901 | type = b->type; |
a1398e0c PA |
1902 | if (type == bp_watchpoint) |
1903 | type = bp_hardware_watchpoint; | |
1904 | ||
1905 | /* This watchpoint may or may not have been placed on | |
1906 | the list yet at this point (it won't be in the list | |
1907 | if we're trying to create it for the first time, | |
1908 | through watch_command), so always account for it | |
1909 | manually. */ | |
1910 | ||
1911 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 1912 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
1913 | |
1914 | /* Add in the resources needed for B. */ | |
c1fc2657 | 1915 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
1916 | |
1917 | target_resources_ok | |
1918 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1919 | if (target_resources_ok <= 0) |
a9634178 | 1920 | { |
c1fc2657 | 1921 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
1922 | |
1923 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1924 | error (_("Target does not support this type of " |
1925 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1926 | else if (target_resources_ok < 0 && !sw_mode) |
1927 | error (_("There are not enough available hardware " | |
1928 | "resources for this watchpoint.")); | |
a1398e0c PA |
1929 | |
1930 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 1931 | b->type = bp_watchpoint; |
a1398e0c PA |
1932 | } |
1933 | else | |
1934 | { | |
1935 | /* If this was a software watchpoint, we've just | |
1936 | found we have enough resources to turn it to a | |
1937 | hardware watchpoint. Otherwise, this is a | |
1938 | nop. */ | |
c1fc2657 | 1939 | b->type = type; |
a9634178 | 1940 | } |
9fa40276 | 1941 | } |
c1fc2657 | 1942 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
1943 | { |
1944 | if (!can_use_hw_watchpoints) | |
1945 | error (_("Can't set read/access watchpoint when " | |
1946 | "hardware watchpoints are disabled.")); | |
1947 | else | |
1948 | error (_("Expression cannot be implemented with " | |
1949 | "read/access watchpoint.")); | |
1950 | } | |
9fa40276 | 1951 | else |
c1fc2657 | 1952 | b->type = bp_watchpoint; |
9fa40276 | 1953 | |
c1fc2657 | 1954 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 1955 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 1956 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
1957 | bl->loc_type = loc_type; |
1958 | } | |
1959 | ||
c7437ca6 PA |
1960 | /* If a software watchpoint is not watching any memory, then the |
1961 | above left it without any location set up. But, | |
1962 | bpstat_stop_status requires a location to be able to report | |
1963 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
1964 | if (b->type == bp_watchpoint && b->loc == NULL) |
1965 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
1966 | } |
1967 | else if (!within_current_scope) | |
7270d8f2 | 1968 | { |
ac74f770 MS |
1969 | printf_filtered (_("\ |
1970 | Watchpoint %d deleted because the program has left the block\n\ | |
1971 | in which its expression is valid.\n"), | |
c1fc2657 | 1972 | b->number); |
d0fb5eae | 1973 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1974 | } |
a5606eee VP |
1975 | |
1976 | /* Restore the selected frame. */ | |
66076460 DJ |
1977 | if (frame_saved) |
1978 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1979 | } |
1980 | ||
a5606eee | 1981 | |
74960c60 | 1982 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1983 | inserted in the inferior. We don't differentiate the type of BL's owner |
1984 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1985 | breakpoint_ops is not defined, because in insert_bp_location, | |
1986 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1987 | static int |
35df4500 | 1988 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1989 | { |
35df4500 | 1990 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1991 | return 0; |
1992 | ||
35df4500 | 1993 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1994 | return 0; |
1995 | ||
35df4500 | 1996 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1997 | return 0; |
1998 | ||
f8eba3c6 TT |
1999 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2000 | return 0; | |
2001 | ||
56710373 PA |
2002 | /* This is set for example, when we're attached to the parent of a |
2003 | vfork, and have detached from the child. The child is running | |
2004 | free, and we expect it to do an exec or exit, at which point the | |
2005 | OS makes the parent schedulable again (and the target reports | |
2006 | that the vfork is done). Until the child is done with the shared | |
2007 | memory region, do not insert breakpoints in the parent, otherwise | |
2008 | the child could still trip on the parent's breakpoints. Since | |
2009 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2010 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2011 | return 0; |
2012 | ||
31e77af2 | 2013 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2014 | location, except if the breakpoint is a single-step breakpoint, |
2015 | and the breakpoint's thread is the thread which is stepping past | |
2016 | a breakpoint. */ | |
31e77af2 PA |
2017 | if ((bl->loc_type == bp_loc_software_breakpoint |
2018 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2019 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2020 | bl->address) |
2021 | /* The single-step breakpoint may be inserted at the location | |
2022 | we're trying to step if the instruction branches to itself. | |
2023 | However, the instruction won't be executed at all and it may | |
2024 | break the semantics of the instruction, for example, the | |
2025 | instruction is a conditional branch or updates some flags. | |
2026 | We can't fix it unless GDB is able to emulate the instruction | |
2027 | or switch to displaced stepping. */ | |
2028 | && !(bl->owner->type == bp_single_step | |
2029 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2030 | { |
2031 | if (debug_infrun) | |
2032 | { | |
2033 | fprintf_unfiltered (gdb_stdlog, | |
2034 | "infrun: skipping breakpoint: " | |
2035 | "stepping past insn at: %s\n", | |
2036 | paddress (bl->gdbarch, bl->address)); | |
2037 | } | |
2038 | return 0; | |
2039 | } | |
31e77af2 | 2040 | |
963f9c80 PA |
2041 | /* Don't insert watchpoints if we're trying to step past the |
2042 | instruction that triggered one. */ | |
2043 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2044 | && stepping_past_nonsteppable_watchpoint ()) | |
2045 | { | |
2046 | if (debug_infrun) | |
2047 | { | |
2048 | fprintf_unfiltered (gdb_stdlog, | |
2049 | "infrun: stepping past non-steppable watchpoint. " | |
2050 | "skipping watchpoint at %s:%d\n", | |
2051 | paddress (bl->gdbarch, bl->address), | |
2052 | bl->length); | |
2053 | } | |
2054 | return 0; | |
2055 | } | |
2056 | ||
74960c60 VP |
2057 | return 1; |
2058 | } | |
2059 | ||
934709f0 PW |
2060 | /* Same as should_be_inserted but does the check assuming |
2061 | that the location is not duplicated. */ | |
2062 | ||
2063 | static int | |
2064 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2065 | { | |
2066 | int result; | |
2067 | const int save_duplicate = bl->duplicate; | |
2068 | ||
2069 | bl->duplicate = 0; | |
2070 | result = should_be_inserted (bl); | |
2071 | bl->duplicate = save_duplicate; | |
2072 | return result; | |
2073 | } | |
2074 | ||
b775012e LM |
2075 | /* Parses a conditional described by an expression COND into an |
2076 | agent expression bytecode suitable for evaluation | |
2077 | by the bytecode interpreter. Return NULL if there was | |
2078 | any error during parsing. */ | |
2079 | ||
833177a4 | 2080 | static agent_expr_up |
b775012e LM |
2081 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2082 | { | |
833177a4 | 2083 | if (cond == NULL) |
b775012e LM |
2084 | return NULL; |
2085 | ||
833177a4 PA |
2086 | agent_expr_up aexpr; |
2087 | ||
b775012e LM |
2088 | /* We don't want to stop processing, so catch any errors |
2089 | that may show up. */ | |
a70b8144 | 2090 | try |
b775012e | 2091 | { |
036e657b | 2092 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2093 | } |
2094 | ||
230d2906 | 2095 | catch (const gdb_exception_error &ex) |
b775012e LM |
2096 | { |
2097 | /* If we got here, it means the condition could not be parsed to a valid | |
2098 | bytecode expression and thus can't be evaluated on the target's side. | |
2099 | It's no use iterating through the conditions. */ | |
b775012e LM |
2100 | } |
2101 | ||
2102 | /* We have a valid agent expression. */ | |
2103 | return aexpr; | |
2104 | } | |
2105 | ||
2106 | /* Based on location BL, create a list of breakpoint conditions to be | |
2107 | passed on to the target. If we have duplicated locations with different | |
2108 | conditions, we will add such conditions to the list. The idea is that the | |
2109 | target will evaluate the list of conditions and will only notify GDB when | |
2110 | one of them is true. */ | |
2111 | ||
2112 | static void | |
2113 | build_target_condition_list (struct bp_location *bl) | |
2114 | { | |
2115 | struct bp_location **locp = NULL, **loc2p; | |
2116 | int null_condition_or_parse_error = 0; | |
2117 | int modified = bl->needs_update; | |
2118 | struct bp_location *loc; | |
2119 | ||
8b4f3082 | 2120 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2121 | bl->target_info.conditions.clear (); |
8b4f3082 | 2122 | |
b775012e LM |
2123 | /* This is only meaningful if the target is |
2124 | evaluating conditions and if the user has | |
2125 | opted for condition evaluation on the target's | |
2126 | side. */ | |
2127 | if (gdb_evaluates_breakpoint_condition_p () | |
2128 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2129 | return; | |
2130 | ||
2131 | /* Do a first pass to check for locations with no assigned | |
7f32a4d5 PA |
2132 | conditions or conditions that fail to parse to a valid agent |
2133 | expression bytecode. If any of these happen, then it's no use to | |
2134 | send conditions to the target since this location will always | |
2135 | trigger and generate a response back to GDB. Note we consider | |
2136 | all locations at the same address irrespective of type, i.e., | |
2137 | even if the locations aren't considered duplicates (e.g., | |
2138 | software breakpoint and hardware breakpoint at the same | |
2139 | address). */ | |
b775012e LM |
2140 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2141 | { | |
2142 | loc = (*loc2p); | |
2143 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2144 | { | |
2145 | if (modified) | |
2146 | { | |
b775012e LM |
2147 | /* Re-parse the conditions since something changed. In that |
2148 | case we already freed the condition bytecodes (see | |
2149 | force_breakpoint_reinsertion). We just | |
2150 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2151 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2152 | loc->cond.get ()); | |
b775012e LM |
2153 | } |
2154 | ||
2155 | /* If we have a NULL bytecode expression, it means something | |
2156 | went wrong or we have a null condition expression. */ | |
2157 | if (!loc->cond_bytecode) | |
2158 | { | |
2159 | null_condition_or_parse_error = 1; | |
2160 | break; | |
2161 | } | |
2162 | } | |
2163 | } | |
2164 | ||
2165 | /* If any of these happened, it means we will have to evaluate the conditions | |
2166 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2167 | for all the other duplicate locations, thus we free all of them here. | |
2168 | ||
2169 | This is so we have a finer control over which locations' conditions are | |
2170 | being evaluated by GDB or the remote stub. */ | |
2171 | if (null_condition_or_parse_error) | |
2172 | { | |
2173 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2174 | { | |
2175 | loc = (*loc2p); | |
2176 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2177 | { | |
2178 | /* Only go as far as the first NULL bytecode is | |
2179 | located. */ | |
2180 | if (!loc->cond_bytecode) | |
2181 | return; | |
2182 | ||
833177a4 | 2183 | loc->cond_bytecode.reset (); |
b775012e LM |
2184 | } |
2185 | } | |
2186 | } | |
2187 | ||
7f32a4d5 PA |
2188 | /* No NULL conditions or failed bytecode generation. Build a |
2189 | condition list for this location's address. If we have software | |
2190 | and hardware locations at the same address, they aren't | |
2191 | considered duplicates, but we still marge all the conditions | |
2192 | anyway, as it's simpler, and doesn't really make a practical | |
2193 | difference. */ | |
b775012e LM |
2194 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2195 | { | |
2196 | loc = (*loc2p); | |
2197 | if (loc->cond | |
2198 | && is_breakpoint (loc->owner) | |
2199 | && loc->pspace->num == bl->pspace->num | |
2200 | && loc->owner->enable_state == bp_enabled | |
2201 | && loc->enabled) | |
3cde5c42 PA |
2202 | { |
2203 | /* Add the condition to the vector. This will be used later | |
2204 | to send the conditions to the target. */ | |
2205 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2206 | } | |
b775012e LM |
2207 | } |
2208 | ||
2209 | return; | |
2210 | } | |
2211 | ||
d3ce09f5 SS |
2212 | /* Parses a command described by string CMD into an agent expression |
2213 | bytecode suitable for evaluation by the bytecode interpreter. | |
2214 | Return NULL if there was any error during parsing. */ | |
2215 | ||
833177a4 | 2216 | static agent_expr_up |
d3ce09f5 SS |
2217 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2218 | { | |
bbc13ae3 KS |
2219 | const char *cmdrest; |
2220 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2221 | struct gdbarch *gdbarch = get_current_arch (); |
2222 | ||
833177a4 | 2223 | if (cmd == NULL) |
d3ce09f5 SS |
2224 | return NULL; |
2225 | ||
2226 | cmdrest = cmd; | |
2227 | ||
2228 | if (*cmdrest == ',') | |
2229 | ++cmdrest; | |
f1735a53 | 2230 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2231 | |
2232 | if (*cmdrest++ != '"') | |
2233 | error (_("No format string following the location")); | |
2234 | ||
2235 | format_start = cmdrest; | |
2236 | ||
8e481c3b | 2237 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2238 | |
2239 | format_end = cmdrest; | |
2240 | ||
2241 | if (*cmdrest++ != '"') | |
2242 | error (_("Bad format string, non-terminated '\"'.")); | |
2243 | ||
f1735a53 | 2244 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2245 | |
2246 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2247 | error (_("Invalid argument syntax")); | |
2248 | ||
2249 | if (*cmdrest == ',') | |
2250 | cmdrest++; | |
f1735a53 | 2251 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2252 | |
2253 | /* For each argument, make an expression. */ | |
2254 | ||
8e481c3b | 2255 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2256 | while (*cmdrest != '\0') |
2257 | { | |
bbc13ae3 | 2258 | const char *cmd1; |
d3ce09f5 SS |
2259 | |
2260 | cmd1 = cmdrest; | |
4d01a485 | 2261 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2262 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2263 | cmdrest = cmd1; |
2264 | if (*cmdrest == ',') | |
2265 | ++cmdrest; | |
2266 | } | |
2267 | ||
833177a4 PA |
2268 | agent_expr_up aexpr; |
2269 | ||
d3ce09f5 SS |
2270 | /* We don't want to stop processing, so catch any errors |
2271 | that may show up. */ | |
a70b8144 | 2272 | try |
d3ce09f5 | 2273 | { |
036e657b JB |
2274 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2275 | format_start, format_end - format_start, | |
8e481c3b | 2276 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2277 | } |
230d2906 | 2278 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2279 | { |
2280 | /* If we got here, it means the command could not be parsed to a valid | |
2281 | bytecode expression and thus can't be evaluated on the target's side. | |
2282 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2283 | } |
492d29ea | 2284 | |
d3ce09f5 SS |
2285 | /* We have a valid agent expression, return it. */ |
2286 | return aexpr; | |
2287 | } | |
2288 | ||
2289 | /* Based on location BL, create a list of breakpoint commands to be | |
2290 | passed on to the target. If we have duplicated locations with | |
2291 | different commands, we will add any such to the list. */ | |
2292 | ||
2293 | static void | |
2294 | build_target_command_list (struct bp_location *bl) | |
2295 | { | |
2296 | struct bp_location **locp = NULL, **loc2p; | |
2297 | int null_command_or_parse_error = 0; | |
2298 | int modified = bl->needs_update; | |
2299 | struct bp_location *loc; | |
2300 | ||
3cde5c42 PA |
2301 | /* Clear commands left over from a previous insert. */ |
2302 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2303 | |
41fac0cf | 2304 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2305 | return; |
2306 | ||
41fac0cf PA |
2307 | /* For now, limit to agent-style dprintf breakpoints. */ |
2308 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2309 | return; |
2310 | ||
7f32a4d5 PA |
2311 | /* For now, if we have any location at the same address that isn't a |
2312 | dprintf, don't install the target-side commands, as that would | |
2313 | make the breakpoint not be reported to the core, and we'd lose | |
41fac0cf PA |
2314 | control. */ |
2315 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2316 | { | |
2317 | loc = (*loc2p); | |
2318 | if (is_breakpoint (loc->owner) | |
2319 | && loc->pspace->num == bl->pspace->num | |
2320 | && loc->owner->type != bp_dprintf) | |
2321 | return; | |
2322 | } | |
2323 | ||
d3ce09f5 SS |
2324 | /* Do a first pass to check for locations with no assigned |
2325 | conditions or conditions that fail to parse to a valid agent expression | |
2326 | bytecode. If any of these happen, then it's no use to send conditions | |
2327 | to the target since this location will always trigger and generate a | |
2328 | response back to GDB. */ | |
2329 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2330 | { | |
2331 | loc = (*loc2p); | |
2332 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2333 | { | |
2334 | if (modified) | |
2335 | { | |
d3ce09f5 SS |
2336 | /* Re-parse the commands since something changed. In that |
2337 | case we already freed the command bytecodes (see | |
2338 | force_breakpoint_reinsertion). We just | |
2339 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2340 | loc->cmd_bytecode |
2341 | = parse_cmd_to_aexpr (bl->address, | |
2342 | loc->owner->extra_string); | |
d3ce09f5 SS |
2343 | } |
2344 | ||
2345 | /* If we have a NULL bytecode expression, it means something | |
2346 | went wrong or we have a null command expression. */ | |
2347 | if (!loc->cmd_bytecode) | |
2348 | { | |
2349 | null_command_or_parse_error = 1; | |
2350 | break; | |
2351 | } | |
2352 | } | |
2353 | } | |
2354 | ||
2355 | /* If anything failed, then we're not doing target-side commands, | |
2356 | and so clean up. */ | |
2357 | if (null_command_or_parse_error) | |
2358 | { | |
2359 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2360 | { | |
2361 | loc = (*loc2p); | |
2362 | if (is_breakpoint (loc->owner) | |
2363 | && loc->pspace->num == bl->pspace->num) | |
2364 | { | |
2365 | /* Only go as far as the first NULL bytecode is | |
2366 | located. */ | |
40fb6c5e | 2367 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2368 | return; |
2369 | ||
833177a4 | 2370 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2371 | } |
2372 | } | |
2373 | } | |
2374 | ||
7f32a4d5 PA |
2375 | /* No NULL commands or failed bytecode generation. Build a command |
2376 | list for all duplicate locations at this location's address. | |
2377 | Note that here we must care for whether the breakpoint location | |
2378 | types are considered duplicates, otherwise, say, if we have a | |
2379 | software and hardware location at the same address, the target | |
2380 | could end up running the commands twice. For the moment, we only | |
2381 | support targets-side commands with dprintf, but it doesn't hurt | |
2382 | to be pedantically correct in case that changes. */ | |
d3ce09f5 SS |
2383 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2384 | { | |
2385 | loc = (*loc2p); | |
7f32a4d5 PA |
2386 | if (breakpoint_locations_match (bl, loc) |
2387 | && loc->owner->extra_string | |
d3ce09f5 SS |
2388 | && is_breakpoint (loc->owner) |
2389 | && loc->pspace->num == bl->pspace->num | |
2390 | && loc->owner->enable_state == bp_enabled | |
2391 | && loc->enabled) | |
3cde5c42 PA |
2392 | { |
2393 | /* Add the command to the vector. This will be used later | |
2394 | to send the commands to the target. */ | |
2395 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2396 | } | |
d3ce09f5 SS |
2397 | } |
2398 | ||
2399 | bl->target_info.persist = 0; | |
2400 | /* Maybe flag this location as persistent. */ | |
2401 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2402 | bl->target_info.persist = 1; | |
2403 | } | |
2404 | ||
833b7ab5 YQ |
2405 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2406 | of breakpoint according to ADDR except single-step breakpoint. | |
2407 | Get the kind of single-step breakpoint according to the current | |
2408 | registers state. */ | |
cd6c3b4f YQ |
2409 | |
2410 | static int | |
2411 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2412 | { | |
833b7ab5 YQ |
2413 | if (bl->owner->type == bp_single_step) |
2414 | { | |
2415 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2416 | struct regcache *regcache; | |
2417 | ||
00431a78 | 2418 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2419 | |
2420 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2421 | regcache, addr); | |
2422 | } | |
2423 | else | |
2424 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2425 | } |
2426 | ||
35df4500 TJB |
2427 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2428 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2429 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2430 | Returns 0 for success, 1 if the bp_location type is not supported or |
2431 | -1 for failure. | |
879bfdc2 | 2432 | |
4a64f543 MS |
2433 | NOTE drow/2003-09-09: This routine could be broken down to an |
2434 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2435 | static int |
35df4500 | 2436 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2437 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2438 | int *disabled_breaks, |
dd61ec5c MW |
2439 | int *hw_breakpoint_error, |
2440 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2441 | { |
cc06b668 | 2442 | gdb_exception bp_excpt; |
879bfdc2 | 2443 | |
b775012e | 2444 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2445 | return 0; |
2446 | ||
35c63cd8 JB |
2447 | /* Note we don't initialize bl->target_info, as that wipes out |
2448 | the breakpoint location's shadow_contents if the breakpoint | |
2449 | is still inserted at that location. This in turn breaks | |
2450 | target_read_memory which depends on these buffers when | |
2451 | a memory read is requested at the breakpoint location: | |
2452 | Once the target_info has been wiped, we fail to see that | |
2453 | we have a breakpoint inserted at that address and thus | |
2454 | read the breakpoint instead of returning the data saved in | |
2455 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2456 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2457 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2458 | bl->target_info.length = bl->length; |
8181d85f | 2459 | |
b775012e LM |
2460 | /* When working with target-side conditions, we must pass all the conditions |
2461 | for the same breakpoint address down to the target since GDB will not | |
2462 | insert those locations. With a list of breakpoint conditions, the target | |
2463 | can decide when to stop and notify GDB. */ | |
2464 | ||
2465 | if (is_breakpoint (bl->owner)) | |
2466 | { | |
2467 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2468 | build_target_command_list (bl); |
2469 | /* Reset the modification marker. */ | |
b775012e LM |
2470 | bl->needs_update = 0; |
2471 | } | |
2472 | ||
7f32a4d5 PA |
2473 | /* If "set breakpoint auto-hw" is "on" and a software breakpoint was |
2474 | set at a read-only address, then a breakpoint location will have | |
2475 | been changed to hardware breakpoint before we get here. If it is | |
2476 | "off" however, error out before actually trying to insert the | |
2477 | breakpoint, with a nicer error message. */ | |
35df4500 | 2478 | if (bl->loc_type == bp_loc_software_breakpoint |
7f32a4d5 | 2479 | && !automatic_hardware_breakpoints) |
879bfdc2 | 2480 | { |
7f32a4d5 | 2481 | mem_region *mr = lookup_mem_region (bl->address); |
cc59ec59 | 2482 | |
7f32a4d5 PA |
2483 | if (mr != nullptr && mr->attrib.mode != MEM_RW) |
2484 | { | |
2485 | fprintf_unfiltered (tmp_error_stream, | |
2486 | _("Cannot insert breakpoint %d.\n" | |
2487 | "Cannot set software breakpoint " | |
2488 | "at read-only address %s\n"), | |
2489 | bl->owner->number, | |
2490 | paddress (bl->gdbarch, bl->address)); | |
2491 | return 1; | |
765dc015 | 2492 | } |
7f32a4d5 PA |
2493 | } |
2494 | ||
2495 | if (bl->loc_type == bp_loc_software_breakpoint | |
2496 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2497 | { | |
879bfdc2 DJ |
2498 | /* First check to see if we have to handle an overlay. */ |
2499 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2500 | || bl->section == NULL |
2501 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2502 | { |
2503 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2504 | try |
dd61ec5c | 2505 | { |
0000e5cc PA |
2506 | int val; |
2507 | ||
dd61ec5c | 2508 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2509 | if (val) |
688fca4f | 2510 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2511 | } |
94aeb44b | 2512 | catch (gdb_exception &e) |
dd61ec5c | 2513 | { |
94aeb44b | 2514 | bp_excpt = std::move (e); |
dd61ec5c | 2515 | } |
879bfdc2 DJ |
2516 | } |
2517 | else | |
2518 | { | |
4a64f543 | 2519 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2520 | Shall we set a breakpoint at the LMA? */ |
2521 | if (!overlay_events_enabled) | |
2522 | { | |
2523 | /* Yes -- overlay event support is not active, | |
2524 | so we must try to set a breakpoint at the LMA. | |
2525 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2526 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2527 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2528 | bl->owner->number); |
879bfdc2 DJ |
2529 | else |
2530 | { | |
35df4500 TJB |
2531 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2532 | bl->section); | |
879bfdc2 | 2533 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2534 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2535 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2536 | |
2537 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2538 | try |
0000e5cc PA |
2539 | { |
2540 | int val; | |
2541 | ||
579c6ad9 | 2542 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2543 | = breakpoint_kind (bl, &addr); |
2544 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2545 | val = target_insert_breakpoint (bl->gdbarch, |
2546 | &bl->overlay_target_info); | |
2547 | if (val) | |
688fca4f PA |
2548 | bp_excpt |
2549 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2550 | } |
94aeb44b | 2551 | catch (gdb_exception &e) |
0000e5cc | 2552 | { |
94aeb44b | 2553 | bp_excpt = std::move (e); |
0000e5cc PA |
2554 | } |
2555 | ||
688fca4f | 2556 | if (bp_excpt.reason != 0) |
99361f52 | 2557 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2558 | "Overlay breakpoint %d " |
2559 | "failed: in ROM?\n", | |
35df4500 | 2560 | bl->owner->number); |
879bfdc2 DJ |
2561 | } |
2562 | } | |
2563 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2564 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2565 | { |
2566 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2567 | try |
dd61ec5c | 2568 | { |
0000e5cc PA |
2569 | int val; |
2570 | ||
dd61ec5c | 2571 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2572 | if (val) |
688fca4f | 2573 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2574 | } |
94aeb44b | 2575 | catch (gdb_exception &e) |
dd61ec5c | 2576 | { |
94aeb44b | 2577 | bp_excpt = std::move (e); |
dd61ec5c | 2578 | } |
879bfdc2 DJ |
2579 | } |
2580 | else | |
2581 | { | |
2582 | /* No. This breakpoint will not be inserted. | |
2583 | No error, but do not mark the bp as 'inserted'. */ | |
2584 | return 0; | |
2585 | } | |
2586 | } | |
2587 | ||
688fca4f | 2588 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2589 | { |
2590 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2591 | |
2592 | /* In some cases, we might not be able to insert a | |
2593 | breakpoint in a shared library that has already been | |
2594 | removed, but we have not yet processed the shlib unload | |
2595 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2596 | breakpoint insertion themselves can't tell why the |
2597 | breakpoint insertion failed (e.g., the remote target | |
2598 | doesn't define error codes), so we must treat generic | |
2599 | errors as memory errors. */ | |
688fca4f PA |
2600 | if (bp_excpt.reason == RETURN_ERROR |
2601 | && (bp_excpt.error == GENERIC_ERROR | |
2602 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2603 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2604 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2605 | || shared_objfile_contains_address_p (bl->pspace, |
2606 | bl->address))) | |
879bfdc2 | 2607 | { |
4a64f543 | 2608 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2609 | bl->shlib_disabled = 1; |
76727919 | 2610 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2611 | if (!*disabled_breaks) |
2612 | { | |
2613 | fprintf_unfiltered (tmp_error_stream, | |
2614 | "Cannot insert breakpoint %d.\n", | |
2615 | bl->owner->number); | |
2616 | fprintf_unfiltered (tmp_error_stream, | |
2617 | "Temporarily disabling shared " | |
2618 | "library breakpoints:\n"); | |
2619 | } | |
2620 | *disabled_breaks = 1; | |
879bfdc2 | 2621 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2622 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2623 | return 0; |
879bfdc2 DJ |
2624 | } |
2625 | else | |
879bfdc2 | 2626 | { |
35df4500 | 2627 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2628 | { |
0000e5cc | 2629 | *hw_breakpoint_error = 1; |
688fca4f | 2630 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dd61ec5c MW |
2631 | fprintf_unfiltered (tmp_error_stream, |
2632 | "Cannot insert hardware breakpoint %d%s", | |
688fca4f PA |
2633 | bl->owner->number, |
2634 | bp_excpt.message ? ":" : ".\n"); | |
2635 | if (bp_excpt.message != NULL) | |
2636 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
3d6e9d23 | 2637 | bp_excpt.what ()); |
879bfdc2 DJ |
2638 | } |
2639 | else | |
2640 | { | |
688fca4f | 2641 | if (bp_excpt.message == NULL) |
0000e5cc | 2642 | { |
1ccbe998 | 2643 | std::string message |
0000e5cc PA |
2644 | = memory_error_message (TARGET_XFER_E_IO, |
2645 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2646 | |
2647 | fprintf_unfiltered (tmp_error_stream, | |
2648 | "Cannot insert breakpoint %d.\n" | |
2649 | "%s\n", | |
1ccbe998 | 2650 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2651 | } |
2652 | else | |
2653 | { | |
2654 | fprintf_unfiltered (tmp_error_stream, | |
2655 | "Cannot insert breakpoint %d: %s\n", | |
2656 | bl->owner->number, | |
3d6e9d23 | 2657 | bp_excpt.what ()); |
0000e5cc | 2658 | } |
879bfdc2 | 2659 | } |
0000e5cc | 2660 | return 1; |
879bfdc2 DJ |
2661 | |
2662 | } | |
2663 | } | |
2664 | else | |
35df4500 | 2665 | bl->inserted = 1; |
879bfdc2 | 2666 | |
0000e5cc | 2667 | return 0; |
879bfdc2 DJ |
2668 | } |
2669 | ||
35df4500 | 2670 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2671 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2672 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2673 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2674 | { |
0000e5cc PA |
2675 | int val; |
2676 | ||
77b06cd7 TJB |
2677 | gdb_assert (bl->owner->ops != NULL |
2678 | && bl->owner->ops->insert_location != NULL); | |
2679 | ||
2680 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2681 | |
2682 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2683 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2684 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2685 | { |
2686 | struct bp_location *loc, **loc_temp; | |
2687 | ||
2688 | /* But don't try to insert it, if there's already another | |
2689 | hw_access location that would be considered a duplicate | |
2690 | of this one. */ | |
2691 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2692 | if (loc != bl |
85d721b8 | 2693 | && loc->watchpoint_type == hw_access |
35df4500 | 2694 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2695 | { |
35df4500 TJB |
2696 | bl->duplicate = 1; |
2697 | bl->inserted = 1; | |
2698 | bl->target_info = loc->target_info; | |
2699 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2700 | val = 0; |
2701 | break; | |
2702 | } | |
2703 | ||
2704 | if (val == 1) | |
2705 | { | |
77b06cd7 TJB |
2706 | bl->watchpoint_type = hw_access; |
2707 | val = bl->owner->ops->insert_location (bl); | |
2708 | ||
2709 | if (val) | |
2710 | /* Back to the original value. */ | |
2711 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2712 | } |
2713 | } | |
2714 | ||
35df4500 | 2715 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2716 | } |
2717 | ||
35df4500 | 2718 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2719 | { |
0000e5cc PA |
2720 | int val; |
2721 | ||
77b06cd7 TJB |
2722 | gdb_assert (bl->owner->ops != NULL |
2723 | && bl->owner->ops->insert_location != NULL); | |
2724 | ||
2725 | val = bl->owner->ops->insert_location (bl); | |
2726 | if (val) | |
2727 | { | |
2728 | bl->owner->enable_state = bp_disabled; | |
2729 | ||
2730 | if (val == 1) | |
2731 | warning (_("\ | |
2732 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2733 | of catchpoint."), bl->owner->number); | |
2734 | else | |
2735 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2736 | } | |
2737 | ||
2738 | bl->inserted = (val == 0); | |
1640b821 DJ |
2739 | |
2740 | /* We've already printed an error message if there was a problem | |
2741 | inserting this catchpoint, and we've disabled the catchpoint, | |
2742 | so just return success. */ | |
2743 | return 0; | |
879bfdc2 DJ |
2744 | } |
2745 | ||
2746 | return 0; | |
2747 | } | |
2748 | ||
6c95b8df PA |
2749 | /* This function is called when program space PSPACE is about to be |
2750 | deleted. It takes care of updating breakpoints to not reference | |
2751 | PSPACE anymore. */ | |
2752 | ||
2753 | void | |
2754 | breakpoint_program_space_exit (struct program_space *pspace) | |
2755 | { | |
2756 | struct breakpoint *b, *b_temp; | |
876fa593 | 2757 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2758 | |
2759 | /* Remove any breakpoint that was set through this program space. */ | |
2760 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2761 | { | |
2762 | if (b->pspace == pspace) | |
2763 | delete_breakpoint (b); | |
2764 | } | |
2765 | ||
2766 | /* Breakpoints set through other program spaces could have locations | |
2767 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2768 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2769 | { |
2770 | struct bp_location *tmp; | |
2771 | ||
2772 | if (loc->pspace == pspace) | |
2773 | { | |
2bdf28a0 | 2774 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2775 | if (loc->owner->loc == loc) |
2776 | loc->owner->loc = loc->next; | |
2777 | else | |
2778 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2779 | if (tmp->next == loc) | |
2780 | { | |
2781 | tmp->next = loc->next; | |
2782 | break; | |
2783 | } | |
2784 | } | |
2785 | } | |
2786 | ||
2787 | /* Now update the global location list to permanently delete the | |
2788 | removed locations above. */ | |
44702360 | 2789 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2790 | } |
2791 | ||
74960c60 VP |
2792 | /* Make sure all breakpoints are inserted in inferior. |
2793 | Throws exception on any error. | |
2794 | A breakpoint that is already inserted won't be inserted | |
2795 | again, so calling this function twice is safe. */ | |
2796 | void | |
2797 | insert_breakpoints (void) | |
2798 | { | |
2799 | struct breakpoint *bpt; | |
2800 | ||
2801 | ALL_BREAKPOINTS (bpt) | |
2802 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2803 | { |
2804 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2805 | ||
2806 | update_watchpoint (w, 0 /* don't reparse. */); | |
2807 | } | |
74960c60 | 2808 | |
04086b45 PA |
2809 | /* Updating watchpoints creates new locations, so update the global |
2810 | location list. Explicitly tell ugll to insert locations and | |
7f32a4d5 PA |
2811 | ignore breakpoints_always_inserted_mode. Also, |
2812 | update_global_location_list tries to "upgrade" software | |
2813 | breakpoints to hardware breakpoints to handle "set breakpoint | |
2814 | auto-hw", so we need to call it even if we don't have new | |
2815 | locations. */ | |
04086b45 | 2816 | update_global_location_list (UGLL_INSERT); |
74960c60 VP |
2817 | } |
2818 | ||
20388dd6 YQ |
2819 | /* Invoke CALLBACK for each of bp_location. */ |
2820 | ||
2821 | void | |
2822 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2823 | { | |
2824 | struct bp_location *loc, **loc_tmp; | |
2825 | ||
2826 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2827 | { | |
2828 | callback (loc, NULL); | |
2829 | } | |
2830 | } | |
2831 | ||
b775012e LM |
2832 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2833 | target. It is the case with deleting and disabling of breakpoints when using | |
2834 | always-inserted mode. */ | |
2835 | ||
2836 | static void | |
2837 | update_inserted_breakpoint_locations (void) | |
2838 | { | |
2839 | struct bp_location *bl, **blp_tmp; | |
2840 | int error_flag = 0; | |
2841 | int val = 0; | |
2842 | int disabled_breaks = 0; | |
2843 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2844 | int hw_bp_details_reported = 0; |
b775012e | 2845 | |
d7e74731 | 2846 | string_file tmp_error_stream; |
b775012e LM |
2847 | |
2848 | /* Explicitly mark the warning -- this will only be printed if | |
2849 | there was an error. */ | |
d7e74731 | 2850 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2851 | |
5ed8105e | 2852 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2853 | |
2854 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2855 | { | |
2856 | /* We only want to update software breakpoints and hardware | |
2857 | breakpoints. */ | |
2858 | if (!is_breakpoint (bl->owner)) | |
2859 | continue; | |
2860 | ||
2861 | /* We only want to update locations that are already inserted | |
2862 | and need updating. This is to avoid unwanted insertion during | |
2863 | deletion of breakpoints. */ | |
4daf1902 | 2864 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
2865 | continue; |
2866 | ||
2867 | switch_to_program_space_and_thread (bl->pspace); | |
2868 | ||
2869 | /* For targets that support global breakpoints, there's no need | |
2870 | to select an inferior to insert breakpoint to. In fact, even | |
2871 | if we aren't attached to any process yet, we should still | |
2872 | insert breakpoints. */ | |
f5656ead | 2873 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
5b6d1e4f | 2874 | && (inferior_ptid == null_ptid || !target_has_execution)) |
b775012e LM |
2875 | continue; |
2876 | ||
d7e74731 | 2877 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2878 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2879 | if (val) |
2880 | error_flag = val; | |
2881 | } | |
2882 | ||
2883 | if (error_flag) | |
2884 | { | |
223ffa71 | 2885 | target_terminal::ours_for_output (); |
b775012e LM |
2886 | error_stream (tmp_error_stream); |
2887 | } | |
b775012e LM |
2888 | } |
2889 | ||
c30eee59 | 2890 | /* Used when starting or continuing the program. */ |
c906108c | 2891 | |
74960c60 VP |
2892 | static void |
2893 | insert_breakpoint_locations (void) | |
c906108c | 2894 | { |
a5606eee | 2895 | struct breakpoint *bpt; |
35df4500 | 2896 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2897 | int error_flag = 0; |
c906108c | 2898 | int val = 0; |
3fbb6ffa | 2899 | int disabled_breaks = 0; |
81d0cc19 | 2900 | int hw_breakpoint_error = 0; |
dd61ec5c | 2901 | int hw_bp_error_explained_already = 0; |
c906108c | 2902 | |
d7e74731 PA |
2903 | string_file tmp_error_stream; |
2904 | ||
81d0cc19 GS |
2905 | /* Explicitly mark the warning -- this will only be printed if |
2906 | there was an error. */ | |
d7e74731 | 2907 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 2908 | |
5ed8105e | 2909 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 2910 | |
35df4500 | 2911 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2912 | { |
b775012e | 2913 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2914 | continue; |
2915 | ||
4a64f543 MS |
2916 | /* There is no point inserting thread-specific breakpoints if |
2917 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2918 | has BL->OWNER always non-NULL. */ | |
35df4500 | 2919 | if (bl->owner->thread != -1 |
5d5658a1 | 2920 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
2921 | continue; |
2922 | ||
35df4500 | 2923 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2924 | |
2925 | /* For targets that support global breakpoints, there's no need | |
2926 | to select an inferior to insert breakpoint to. In fact, even | |
2927 | if we aren't attached to any process yet, we should still | |
2928 | insert breakpoints. */ | |
f5656ead | 2929 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
5b6d1e4f | 2930 | && (inferior_ptid == null_ptid || !target_has_execution)) |
6c95b8df PA |
2931 | continue; |
2932 | ||
d7e74731 | 2933 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2934 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2935 | if (val) |
eacd795a | 2936 | error_flag = val; |
879bfdc2 | 2937 | } |
c906108c | 2938 | |
4a64f543 MS |
2939 | /* If we failed to insert all locations of a watchpoint, remove |
2940 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2941 | ALL_BREAKPOINTS (bpt) |
2942 | { | |
2943 | int some_failed = 0; | |
2944 | struct bp_location *loc; | |
2945 | ||
2946 | if (!is_hardware_watchpoint (bpt)) | |
2947 | continue; | |
2948 | ||
d6b74ac4 | 2949 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2950 | continue; |
74960c60 VP |
2951 | |
2952 | if (bpt->disposition == disp_del_at_next_stop) | |
2953 | continue; | |
a5606eee VP |
2954 | |
2955 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2956 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2957 | { |
2958 | some_failed = 1; | |
2959 | break; | |
2960 | } | |
2961 | if (some_failed) | |
2962 | { | |
2963 | for (loc = bpt->loc; loc; loc = loc->next) | |
2964 | if (loc->inserted) | |
834c0d03 | 2965 | remove_breakpoint (loc); |
a5606eee VP |
2966 | |
2967 | hw_breakpoint_error = 1; | |
d7e74731 PA |
2968 | tmp_error_stream.printf ("Could not insert " |
2969 | "hardware watchpoint %d.\n", | |
2970 | bpt->number); | |
eacd795a | 2971 | error_flag = -1; |
a5606eee VP |
2972 | } |
2973 | } | |
2974 | ||
eacd795a | 2975 | if (error_flag) |
81d0cc19 GS |
2976 | { |
2977 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2978 | message about possibly exhausted resources. */ | |
dd61ec5c | 2979 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2980 | { |
d7e74731 | 2981 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 2982 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 2983 | } |
223ffa71 | 2984 | target_terminal::ours_for_output (); |
81d0cc19 GS |
2985 | error_stream (tmp_error_stream); |
2986 | } | |
c906108c SS |
2987 | } |
2988 | ||
c30eee59 TJB |
2989 | /* Used when the program stops. |
2990 | Returns zero if successful, or non-zero if there was a problem | |
2991 | removing a breakpoint location. */ | |
2992 | ||
c906108c | 2993 | int |
fba45db2 | 2994 | remove_breakpoints (void) |
c906108c | 2995 | { |
35df4500 | 2996 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2997 | int val = 0; |
c906108c | 2998 | |
35df4500 | 2999 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3000 | { |
1e4d1764 | 3001 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3002 | val |= remove_breakpoint (bl); |
c5aa993b | 3003 | } |
3a1bae8e | 3004 | return val; |
c906108c SS |
3005 | } |
3006 | ||
49fa26b0 PA |
3007 | /* When a thread exits, remove breakpoints that are related to |
3008 | that thread. */ | |
3009 | ||
3010 | static void | |
3011 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3012 | { | |
3013 | struct breakpoint *b, *b_tmp; | |
3014 | ||
3015 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3016 | { | |
5d5658a1 | 3017 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3018 | { |
3019 | b->disposition = disp_del_at_next_stop; | |
3020 | ||
3021 | printf_filtered (_("\ | |
43792cf0 PA |
3022 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3023 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3024 | |
3025 | /* Hide it from the user. */ | |
3026 | b->number = 0; | |
3027 | } | |
3028 | } | |
3029 | } | |
3030 | ||
f3869b1a | 3031 | /* See breakpoint.h. */ |
6c95b8df | 3032 | |
f3869b1a | 3033 | void |
00431a78 | 3034 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3035 | { |
35df4500 | 3036 | struct bp_location *bl, **blp_tmp; |
6c95b8df | 3037 | int val; |
6c95b8df | 3038 | |
35df4500 | 3039 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3040 | { |
35df4500 | 3041 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3042 | continue; |
3043 | ||
fc126975 | 3044 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3045 | { |
834c0d03 | 3046 | val = remove_breakpoint (bl); |
6c95b8df | 3047 | if (val != 0) |
f3869b1a | 3048 | return; |
6c95b8df PA |
3049 | } |
3050 | } | |
6c95b8df PA |
3051 | } |
3052 | ||
e58b0e63 PA |
3053 | static int internal_breakpoint_number = -1; |
3054 | ||
84f4c1fe PM |
3055 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3056 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3057 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3058 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3059 | breakpoint_count and that value incremented. Internal breakpoints |
3060 | do not set the internal var bpnum. */ | |
3061 | static void | |
3062 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3063 | { | |
3064 | if (internal) | |
3065 | b->number = internal_breakpoint_number--; | |
3066 | else | |
3067 | { | |
3068 | set_breakpoint_count (breakpoint_count + 1); | |
3069 | b->number = breakpoint_count; | |
3070 | } | |
3071 | } | |
3072 | ||
e62c965a | 3073 | static struct breakpoint * |
a6d9a66e | 3074 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3075 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3076 | const struct breakpoint_ops *ops) |
e62c965a | 3077 | { |
51abb421 | 3078 | symtab_and_line sal; |
e62c965a PP |
3079 | sal.pc = address; |
3080 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3081 | sal.pspace = current_program_space; |
e62c965a | 3082 | |
51abb421 | 3083 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3084 | b->number = internal_breakpoint_number--; |
3085 | b->disposition = disp_donttouch; | |
3086 | ||
3087 | return b; | |
3088 | } | |
3089 | ||
17450429 PP |
3090 | static const char *const longjmp_names[] = |
3091 | { | |
3092 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3093 | }; | |
3094 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3095 | ||
3096 | /* Per-objfile data private to breakpoint.c. */ | |
3097 | struct breakpoint_objfile_data | |
3098 | { | |
3099 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3100 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3101 | |
3102 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3103 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3104 | |
28106bc2 | 3105 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3106 | int longjmp_searched = 0; |
28106bc2 | 3107 | |
45461e0d SM |
3108 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3109 | references. */ | |
3110 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3111 | |
17450429 | 3112 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3113 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3114 | |
3115 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3116 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3117 | |
3118 | /* True if we have looked for exception probes. */ | |
43dce439 | 3119 | int exception_searched = 0; |
28106bc2 | 3120 | |
45461e0d SM |
3121 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3122 | references. */ | |
3123 | std::vector<probe *> exception_probes; | |
17450429 PP |
3124 | }; |
3125 | ||
51d3063a TT |
3126 | static const struct objfile_key<breakpoint_objfile_data> |
3127 | breakpoint_objfile_key; | |
17450429 PP |
3128 | |
3129 | /* Minimal symbol not found sentinel. */ | |
3130 | static struct minimal_symbol msym_not_found; | |
3131 | ||
3132 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3133 | ||
3134 | static int | |
3135 | msym_not_found_p (const struct minimal_symbol *msym) | |
3136 | { | |
3137 | return msym == &msym_not_found; | |
3138 | } | |
3139 | ||
3140 | /* Return per-objfile data needed by breakpoint.c. | |
3141 | Allocate the data if necessary. */ | |
3142 | ||
3143 | static struct breakpoint_objfile_data * | |
3144 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3145 | { | |
3146 | struct breakpoint_objfile_data *bp_objfile_data; | |
3147 | ||
51d3063a | 3148 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3149 | if (bp_objfile_data == NULL) |
51d3063a | 3150 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3151 | return bp_objfile_data; |
3152 | } | |
3153 | ||
e62c965a | 3154 | static void |
af02033e | 3155 | create_overlay_event_breakpoint (void) |
e62c965a | 3156 | { |
af02033e | 3157 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3158 | |
2030c079 | 3159 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3160 | { |
3161 | struct breakpoint *b; | |
17450429 PP |
3162 | struct breakpoint_objfile_data *bp_objfile_data; |
3163 | CORE_ADDR addr; | |
67994074 | 3164 | struct explicit_location explicit_loc; |
69de3c6a | 3165 | |
17450429 PP |
3166 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3167 | ||
3b7344d5 | 3168 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3169 | continue; |
3170 | ||
3b7344d5 | 3171 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3172 | { |
3b7344d5 | 3173 | struct bound_minimal_symbol m; |
17450429 PP |
3174 | |
3175 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3176 | if (m.minsym == NULL) |
17450429 PP |
3177 | { |
3178 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3179 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3180 | continue; |
3181 | } | |
3182 | bp_objfile_data->overlay_msym = m; | |
3183 | } | |
e62c965a | 3184 | |
77e371c0 | 3185 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
08feed99 | 3186 | b = create_internal_breakpoint (objfile->arch (), addr, |
06edf0c0 PA |
3187 | bp_overlay_event, |
3188 | &internal_breakpoint_ops); | |
67994074 KS |
3189 | initialize_explicit_location (&explicit_loc); |
3190 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3191 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3192 | |
69de3c6a PP |
3193 | if (overlay_debugging == ovly_auto) |
3194 | { | |
3195 | b->enable_state = bp_enabled; | |
3196 | overlay_events_enabled = 1; | |
3197 | } | |
3198 | else | |
3199 | { | |
3200 | b->enable_state = bp_disabled; | |
3201 | overlay_events_enabled = 0; | |
3202 | } | |
e62c965a | 3203 | } |
e62c965a PP |
3204 | } |
3205 | ||
0fd8e87f | 3206 | static void |
af02033e | 3207 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3208 | { |
5ed8105e | 3209 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3210 | |
94c93c35 TT |
3211 | for (struct program_space *pspace : program_spaces) |
3212 | { | |
3213 | set_current_program_space (pspace); | |
af02033e | 3214 | |
94c93c35 TT |
3215 | for (objfile *objfile : current_program_space->objfiles ()) |
3216 | { | |
3217 | int i; | |
3218 | struct gdbarch *gdbarch; | |
3219 | struct breakpoint_objfile_data *bp_objfile_data; | |
0fd8e87f | 3220 | |
94c93c35 | 3221 | gdbarch = objfile->arch (); |
0fd8e87f | 3222 | |
94c93c35 | 3223 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3224 | |
94c93c35 TT |
3225 | if (!bp_objfile_data->longjmp_searched) |
3226 | { | |
3227 | std::vector<probe *> ret | |
3228 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
25f9533e | 3229 | |
94c93c35 TT |
3230 | if (!ret.empty ()) |
3231 | { | |
3232 | /* We are only interested in checking one element. */ | |
3233 | probe *p = ret[0]; | |
aed57c53 | 3234 | |
94c93c35 TT |
3235 | if (!p->can_evaluate_arguments ()) |
3236 | { | |
3237 | /* We cannot use the probe interface here, | |
3238 | because it does not know how to evaluate | |
3239 | arguments. */ | |
3240 | ret.clear (); | |
3241 | } | |
3242 | } | |
3243 | bp_objfile_data->longjmp_probes = ret; | |
3244 | bp_objfile_data->longjmp_searched = 1; | |
3245 | } | |
25f9533e | 3246 | |
94c93c35 TT |
3247 | if (!bp_objfile_data->longjmp_probes.empty ()) |
3248 | { | |
3249 | for (probe *p : bp_objfile_data->longjmp_probes) | |
3250 | { | |
3251 | struct breakpoint *b; | |
3252 | ||
3253 | b = create_internal_breakpoint (gdbarch, | |
3254 | p->get_relocated_address (objfile), | |
3255 | bp_longjmp_master, | |
3256 | &internal_breakpoint_ops); | |
3257 | b->location = new_probe_location ("-probe-stap libc:longjmp"); | |
3258 | b->enable_state = bp_disabled; | |
3259 | } | |
28106bc2 | 3260 | |
94c93c35 TT |
3261 | continue; |
3262 | } | |
28106bc2 | 3263 | |
94c93c35 TT |
3264 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3265 | continue; | |
28106bc2 | 3266 | |
94c93c35 TT |
3267 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
3268 | { | |
3269 | struct breakpoint *b; | |
3270 | const char *func_name; | |
3271 | CORE_ADDR addr; | |
3272 | struct explicit_location explicit_loc; | |
0fd8e87f | 3273 | |
94c93c35 TT |
3274 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
3275 | continue; | |
17450429 | 3276 | |
94c93c35 TT |
3277 | func_name = longjmp_names[i]; |
3278 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3279 | { | |
3280 | struct bound_minimal_symbol m; | |
aed57c53 | 3281 | |
94c93c35 TT |
3282 | m = lookup_minimal_symbol_text (func_name, objfile); |
3283 | if (m.minsym == NULL) | |
3284 | { | |
3285 | /* Prevent future lookups in this objfile. */ | |
3286 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
3287 | continue; | |
3288 | } | |
3289 | bp_objfile_data->longjmp_msym[i] = m; | |
3290 | } | |
17450429 | 3291 | |
94c93c35 TT |
3292 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
3293 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, | |
3294 | &internal_breakpoint_ops); | |
3295 | initialize_explicit_location (&explicit_loc); | |
3296 | explicit_loc.function_name = ASTRDUP (func_name); | |
3297 | b->location = new_explicit_location (&explicit_loc); | |
3298 | b->enable_state = bp_disabled; | |
3299 | } | |
3300 | } | |
3301 | } | |
0fd8e87f UW |
3302 | } |
3303 | ||
af02033e | 3304 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3305 | static void |
af02033e | 3306 | create_std_terminate_master_breakpoint (void) |
aa7d318d | 3307 | { |
af02033e | 3308 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3309 | |
5ed8105e | 3310 | scoped_restore_current_program_space restore_pspace; |
aa7d318d | 3311 | |
94c93c35 TT |
3312 | for (struct program_space *pspace : program_spaces) |
3313 | { | |
3314 | CORE_ADDR addr; | |
17450429 | 3315 | |
94c93c35 | 3316 | set_current_program_space (pspace); |
17450429 | 3317 | |
94c93c35 TT |
3318 | for (objfile *objfile : current_program_space->objfiles ()) |
3319 | { | |
3320 | struct breakpoint *b; | |
3321 | struct breakpoint_objfile_data *bp_objfile_data; | |
3322 | struct explicit_location explicit_loc; | |
aa7d318d | 3323 | |
94c93c35 | 3324 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3325 | |
94c93c35 TT |
3326 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3327 | continue; | |
17450429 | 3328 | |
94c93c35 TT |
3329 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3330 | { | |
3331 | struct bound_minimal_symbol m; | |
17450429 | 3332 | |
94c93c35 TT |
3333 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
3334 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text | |
3335 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
3336 | { | |
3337 | /* Prevent future lookups in this objfile. */ | |
3338 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3339 | continue; | |
3340 | } | |
3341 | bp_objfile_data->terminate_msym = m; | |
3342 | } | |
aa7d318d | 3343 | |
94c93c35 TT |
3344 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3345 | b = create_internal_breakpoint (objfile->arch (), addr, | |
3346 | bp_std_terminate_master, | |
3347 | &internal_breakpoint_ops); | |
3348 | initialize_explicit_location (&explicit_loc); | |
3349 | explicit_loc.function_name = ASTRDUP (func_name); | |
3350 | b->location = new_explicit_location (&explicit_loc); | |
3351 | b->enable_state = bp_disabled; | |
3352 | } | |
3353 | } | |
aa7d318d TT |
3354 | } |
3355 | ||
186c406b TT |
3356 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3357 | ||
70221824 | 3358 | static void |
186c406b TT |
3359 | create_exception_master_breakpoint (void) |
3360 | { | |
17450429 | 3361 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b | 3362 | |
2030c079 | 3363 | for (objfile *objfile : current_program_space->objfiles ()) |
186c406b | 3364 | { |
17450429 PP |
3365 | struct breakpoint *b; |
3366 | struct gdbarch *gdbarch; | |
3367 | struct breakpoint_objfile_data *bp_objfile_data; | |
3368 | CORE_ADDR addr; | |
67994074 | 3369 | struct explicit_location explicit_loc; |
17450429 PP |
3370 | |
3371 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3372 | ||
28106bc2 SDJ |
3373 | /* We prefer the SystemTap probe point if it exists. */ |
3374 | if (!bp_objfile_data->exception_searched) | |
3375 | { | |
45461e0d SM |
3376 | std::vector<probe *> ret |
3377 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
25f9533e | 3378 | |
45461e0d | 3379 | if (!ret.empty ()) |
25f9533e SDJ |
3380 | { |
3381 | /* We are only interested in checking one element. */ | |
45461e0d | 3382 | probe *p = ret[0]; |
25f9533e | 3383 | |
935676c9 | 3384 | if (!p->can_evaluate_arguments ()) |
25f9533e SDJ |
3385 | { |
3386 | /* We cannot use the probe interface here, because it does | |
3387 | not know how to evaluate arguments. */ | |
45461e0d | 3388 | ret.clear (); |
25f9533e SDJ |
3389 | } |
3390 | } | |
3391 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3392 | bp_objfile_data->exception_searched = 1; |
3393 | } | |
3394 | ||
45461e0d | 3395 | if (!bp_objfile_data->exception_probes.empty ()) |
28106bc2 | 3396 | { |
08feed99 | 3397 | gdbarch = objfile->arch (); |
45461e0d SM |
3398 | |
3399 | for (probe *p : bp_objfile_data->exception_probes) | |
28106bc2 | 3400 | { |
729662a5 | 3401 | b = create_internal_breakpoint (gdbarch, |
935676c9 | 3402 | p->get_relocated_address (objfile), |
28106bc2 SDJ |
3403 | bp_exception_master, |
3404 | &internal_breakpoint_ops); | |
d28cd78a | 3405 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3406 | b->enable_state = bp_disabled; |
3407 | } | |
3408 | ||
3409 | continue; | |
3410 | } | |
3411 | ||
3412 | /* Otherwise, try the hook function. */ | |
3413 | ||
3b7344d5 | 3414 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3415 | continue; |
3416 | ||
08feed99 | 3417 | gdbarch = objfile->arch (); |
186c406b | 3418 | |
3b7344d5 | 3419 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3420 | { |
3b7344d5 | 3421 | struct bound_minimal_symbol debug_hook; |
186c406b | 3422 | |
17450429 | 3423 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3424 | if (debug_hook.minsym == NULL) |
17450429 | 3425 | { |
3b7344d5 | 3426 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3427 | continue; |
3428 | } | |
3429 | ||
3430 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3431 | } |
17450429 | 3432 | |
77e371c0 | 3433 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
8b88a78e PA |
3434 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3435 | current_top_target ()); | |
06edf0c0 PA |
3436 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3437 | &internal_breakpoint_ops); | |
67994074 KS |
3438 | initialize_explicit_location (&explicit_loc); |
3439 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3440 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3441 | b->enable_state = bp_disabled; |
186c406b | 3442 | } |
186c406b TT |
3443 | } |
3444 | ||
9ef9e6a6 KS |
3445 | /* Does B have a location spec? */ |
3446 | ||
3447 | static int | |
3448 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3449 | { | |
d28cd78a | 3450 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3451 | } |
3452 | ||
c906108c | 3453 | void |
fba45db2 | 3454 | update_breakpoints_after_exec (void) |
c906108c | 3455 | { |
35df4500 | 3456 | struct breakpoint *b, *b_tmp; |
876fa593 | 3457 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3458 | |
25b22b0a PA |
3459 | /* We're about to delete breakpoints from GDB's lists. If the |
3460 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3461 | writing the breakpoints' "shadow contents" back into memory. The | |
3462 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3463 | do that. Instead, the target is responsible from marking | |
3464 | breakpoints out as soon as it detects an exec. We don't do that | |
3465 | here instead, because there may be other attempts to delete | |
3466 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3467 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3468 | if (bploc->pspace == current_program_space) |
3469 | gdb_assert (!bploc->inserted); | |
c906108c | 3470 | |
35df4500 | 3471 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3472 | { |
6c95b8df PA |
3473 | if (b->pspace != current_program_space) |
3474 | continue; | |
3475 | ||
4a64f543 | 3476 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3477 | if (b->type == bp_shlib_event) |
3478 | { | |
3479 | delete_breakpoint (b); | |
3480 | continue; | |
3481 | } | |
c906108c | 3482 | |
4a64f543 | 3483 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3484 | if (b->type == bp_jit_event) |
3485 | { | |
3486 | delete_breakpoint (b); | |
3487 | continue; | |
3488 | } | |
3489 | ||
1900040c | 3490 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3491 | as must overlay event and longjmp master breakpoints. */ |
3492 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3493 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3494 | || b->type == bp_exception_master) | |
c4093a6a JM |
3495 | { |
3496 | delete_breakpoint (b); | |
3497 | continue; | |
3498 | } | |
3499 | ||
4a64f543 | 3500 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3501 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3502 | { |
3503 | delete_breakpoint (b); | |
3504 | continue; | |
3505 | } | |
3506 | ||
7c16b83e PA |
3507 | /* Just like single-step breakpoints. */ |
3508 | if (b->type == bp_single_step) | |
3509 | { | |
3510 | delete_breakpoint (b); | |
3511 | continue; | |
3512 | } | |
3513 | ||
611c83ae PA |
3514 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3515 | after an exec. */ | |
186c406b | 3516 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3517 | || b->type == bp_longjmp_call_dummy |
186c406b | 3518 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3519 | { |
3520 | delete_breakpoint (b); | |
3521 | continue; | |
3522 | } | |
3523 | ||
ce78b96d JB |
3524 | if (b->type == bp_catchpoint) |
3525 | { | |
3526 | /* For now, none of the bp_catchpoint breakpoints need to | |
3527 | do anything at this point. In the future, if some of | |
3528 | the catchpoints need to something, we will need to add | |
3529 | a new method, and call this method from here. */ | |
3530 | continue; | |
3531 | } | |
3532 | ||
c5aa993b JM |
3533 | /* bp_finish is a special case. The only way we ought to be able |
3534 | to see one of these when an exec() has happened, is if the user | |
3535 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3536 | carries them to the call-site of the current callee, by setting | |
3537 | a temporary bp there and resuming. But in this case, the finish | |
3538 | will carry them entirely through the vfork & exec. | |
3539 | ||
3540 | We don't want to allow a bp_finish to remain inserted now. But | |
3541 | we can't safely delete it, 'cause finish_command has a handle to | |
3542 | the bp on a bpstat, and will later want to delete it. There's a | |
3543 | chance (and I've seen it happen) that if we delete the bp_finish | |
3544 | here, that its storage will get reused by the time finish_command | |
3545 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3546 | We really must allow finish_command to delete a bp_finish. | |
3547 | ||
e5dd4106 | 3548 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3549 | it's safe to delete something others may have handles to?" |
3550 | problem, what we'll do here is just uninsert the bp_finish, and | |
3551 | let finish_command delete it. | |
3552 | ||
3553 | (We know the bp_finish is "doomed" in the sense that it's | |
3554 | momentary, and will be deleted as soon as finish_command sees | |
3555 | the inferior stopped. So it doesn't matter that the bp's | |
3556 | address is probably bogus in the new a.out, unlike e.g., the | |
3557 | solib breakpoints.) */ | |
c5aa993b | 3558 | |
c5aa993b JM |
3559 | if (b->type == bp_finish) |
3560 | { | |
3561 | continue; | |
3562 | } | |
3563 | ||
3564 | /* Without a symbolic address, we have little hope of the | |
3565 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3566 | a.out. */ |
9ef9e6a6 | 3567 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3568 | { |
3569 | delete_breakpoint (b); | |
3570 | continue; | |
3571 | } | |
c5aa993b | 3572 | } |
c906108c SS |
3573 | } |
3574 | ||
3575 | int | |
d80ee84f | 3576 | detach_breakpoints (ptid_t ptid) |
c906108c | 3577 | { |
35df4500 | 3578 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3579 | int val = 0; |
2989a365 | 3580 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3581 | struct inferior *inf = current_inferior (); |
c5aa993b | 3582 | |
e99b03dc | 3583 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3584 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3585 | |
6c95b8df | 3586 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3587 | inferior_ptid = ptid; |
35df4500 | 3588 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3589 | { |
35df4500 | 3590 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3591 | continue; |
3592 | ||
bd9673a4 PW |
3593 | /* This function must physically remove breakpoints locations |
3594 | from the specified ptid, without modifying the breakpoint | |
3595 | package's state. Locations of type bp_loc_other are only | |
3596 | maintained at GDB side. So, there is no need to remove | |
3597 | these bp_loc_other locations. Moreover, removing these | |
3598 | would modify the breakpoint package's state. */ | |
3599 | if (bl->loc_type == bp_loc_other) | |
3600 | continue; | |
3601 | ||
35df4500 | 3602 | if (bl->inserted) |
b2b6a7da | 3603 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3604 | } |
d03285ec | 3605 | |
3a1bae8e | 3606 | return val; |
c906108c SS |
3607 | } |
3608 | ||
35df4500 | 3609 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3610 | Note that this is used to detach breakpoints from a child fork. |
3611 | When we get here, the child isn't in the inferior list, and neither | |
3612 | do we have objects to represent its address space --- we should | |
35df4500 | 3613 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3614 | |
c906108c | 3615 | static int |
b2b6a7da | 3616 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3617 | { |
3618 | int val; | |
c5aa993b | 3619 | |
35df4500 TJB |
3620 | /* BL is never in moribund_locations by our callers. */ |
3621 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3622 | |
74960c60 VP |
3623 | /* The type of none suggests that owner is actually deleted. |
3624 | This should not ever happen. */ | |
35df4500 | 3625 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3626 | |
35df4500 TJB |
3627 | if (bl->loc_type == bp_loc_software_breakpoint |
3628 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3629 | { |
c02f5703 MS |
3630 | /* "Normal" instruction breakpoint: either the standard |
3631 | trap-instruction bp (bp_breakpoint), or a | |
3632 | bp_hardware_breakpoint. */ | |
3633 | ||
3634 | /* First check to see if we have to handle an overlay. */ | |
3635 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3636 | || bl->section == NULL |
3637 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3638 | { |
3639 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3640 | |
3641 | /* If we're trying to uninsert a memory breakpoint that we | |
3642 | know is set in a dynamic object that is marked | |
3643 | shlib_disabled, then either the dynamic object was | |
3644 | removed with "remove-symbol-file" or with | |
3645 | "nosharedlibrary". In the former case, we don't know | |
3646 | whether another dynamic object might have loaded over the | |
3647 | breakpoint's address -- the user might well let us know | |
3648 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3649 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3650 | list of dynamically loaded objects). If we have the |
3651 | breakpoint's shadow memory, that is, this is a software | |
3652 | breakpoint managed by GDB, check whether the breakpoint | |
3653 | is still inserted in memory, to avoid overwriting wrong | |
3654 | code with stale saved shadow contents. Note that HW | |
3655 | breakpoints don't have shadow memory, as they're | |
3656 | implemented using a mechanism that is not dependent on | |
3657 | being able to modify the target's memory, and as such | |
3658 | they should always be removed. */ | |
3659 | if (bl->shlib_disabled | |
3660 | && bl->target_info.shadow_len != 0 | |
3661 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3662 | val = 0; | |
3663 | else | |
73971819 | 3664 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3665 | } |
c906108c SS |
3666 | else |
3667 | { | |
4a64f543 | 3668 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3669 | Did we set a breakpoint at the LMA? */ |
3670 | if (!overlay_events_enabled) | |
3671 | { | |
3672 | /* Yes -- overlay event support is not active, so we | |
3673 | should have set a breakpoint at the LMA. Remove it. | |
3674 | */ | |
c02f5703 MS |
3675 | /* Ignore any failures: if the LMA is in ROM, we will |
3676 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3677 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3678 | target_remove_hw_breakpoint (bl->gdbarch, | |
3679 | &bl->overlay_target_info); | |
c02f5703 | 3680 | else |
35df4500 | 3681 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3682 | &bl->overlay_target_info, |
3683 | reason); | |
c02f5703 MS |
3684 | } |
3685 | /* Did we set a breakpoint at the VMA? | |
3686 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3687 | if (bl->inserted) |
c906108c | 3688 | { |
c02f5703 MS |
3689 | /* Yes -- remove it. Previously we did not bother to |
3690 | remove the breakpoint if the section had been | |
3691 | unmapped, but let's not rely on that being safe. We | |
3692 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3693 | |
3694 | /* However, we should remove *software* breakpoints only | |
3695 | if the section is still mapped, or else we overwrite | |
3696 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3697 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3698 | || section_is_mapped (bl->section)) | |
73971819 | 3699 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3700 | else |
3701 | val = 0; | |
c906108c | 3702 | } |
c02f5703 MS |
3703 | else |
3704 | { | |
3705 | /* No -- not inserted, so no need to remove. No error. */ | |
3706 | val = 0; | |
3707 | } | |
c906108c | 3708 | } |
879d1e6b | 3709 | |
08351840 PA |
3710 | /* In some cases, we might not be able to remove a breakpoint in |
3711 | a shared library that has already been removed, but we have | |
3712 | not yet processed the shlib unload event. Similarly for an | |
3713 | unloaded add-symbol-file object - the user might not yet have | |
3714 | had the chance to remove-symbol-file it. shlib_disabled will | |
3715 | be set if the library/object has already been removed, but | |
3716 | the breakpoint hasn't been uninserted yet, e.g., after | |
3717 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3718 | always-inserted mode. */ | |
076855f9 | 3719 | if (val |
08351840 PA |
3720 | && (bl->loc_type == bp_loc_software_breakpoint |
3721 | && (bl->shlib_disabled | |
3722 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3723 | || shared_objfile_contains_address_p (bl->pspace, |
3724 | bl->address)))) | |
879d1e6b UW |
3725 | val = 0; |
3726 | ||
c906108c SS |
3727 | if (val) |
3728 | return val; | |
b2b6a7da | 3729 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3730 | } |
35df4500 | 3731 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3732 | { |
77b06cd7 TJB |
3733 | gdb_assert (bl->owner->ops != NULL |
3734 | && bl->owner->ops->remove_location != NULL); | |
3735 | ||
b2b6a7da | 3736 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3737 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3738 | |
c906108c | 3739 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3740 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3741 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3742 | bl->owner->number); |
c906108c | 3743 | } |
35df4500 TJB |
3744 | else if (bl->owner->type == bp_catchpoint |
3745 | && breakpoint_enabled (bl->owner) | |
3746 | && !bl->duplicate) | |
ce78b96d | 3747 | { |
77b06cd7 TJB |
3748 | gdb_assert (bl->owner->ops != NULL |
3749 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3750 | |
73971819 | 3751 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3752 | if (val) |
3753 | return val; | |
77b06cd7 | 3754 | |
b2b6a7da | 3755 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3756 | } |
c906108c SS |
3757 | |
3758 | return 0; | |
3759 | } | |
3760 | ||
6c95b8df | 3761 | static int |
834c0d03 | 3762 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3763 | { |
35df4500 TJB |
3764 | /* BL is never in moribund_locations by our callers. */ |
3765 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3766 | |
6c95b8df PA |
3767 | /* The type of none suggests that owner is actually deleted. |
3768 | This should not ever happen. */ | |
35df4500 | 3769 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3770 | |
5ed8105e | 3771 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3772 | |
35df4500 | 3773 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3774 | |
5ed8105e | 3775 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3776 | } |
3777 | ||
c906108c SS |
3778 | /* Clear the "inserted" flag in all breakpoints. */ |
3779 | ||
25b22b0a | 3780 | void |
fba45db2 | 3781 | mark_breakpoints_out (void) |
c906108c | 3782 | { |
35df4500 | 3783 | struct bp_location *bl, **blp_tmp; |
c906108c | 3784 | |
35df4500 | 3785 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3786 | if (bl->pspace == current_program_space) |
35df4500 | 3787 | bl->inserted = 0; |
c906108c SS |
3788 | } |
3789 | ||
53a5351d JM |
3790 | /* Clear the "inserted" flag in all breakpoints and delete any |
3791 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3792 | |
3793 | Plus other such housekeeping that has to be done for breakpoints | |
3794 | between runs. | |
3795 | ||
53a5351d JM |
3796 | Note: this function gets called at the end of a run (by |
3797 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3798 | init_wait_for_inferior). */ |
c906108c SS |
3799 | |
3800 | ||
3801 | ||
3802 | void | |
fba45db2 | 3803 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3804 | { |
35df4500 | 3805 | struct breakpoint *b, *b_tmp; |
6c95b8df | 3806 | struct program_space *pspace = current_program_space; |
c906108c | 3807 | |
50c71eaf PA |
3808 | /* If breakpoint locations are shared across processes, then there's |
3809 | nothing to do. */ | |
f5656ead | 3810 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3811 | return; |
3812 | ||
1a853c52 | 3813 | mark_breakpoints_out (); |
075f6582 | 3814 | |
35df4500 | 3815 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3816 | { |
6c95b8df PA |
3817 | if (b->loc && b->loc->pspace != pspace) |
3818 | continue; | |
3819 | ||
c5aa993b JM |
3820 | switch (b->type) |
3821 | { | |
3822 | case bp_call_dummy: | |
e2e4d78b | 3823 | case bp_longjmp_call_dummy: |
c906108c | 3824 | |
c5aa993b | 3825 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3826 | cause problems when the inferior is rerun, so we better get |
3827 | rid of it. */ | |
3828 | ||
3829 | case bp_watchpoint_scope: | |
3830 | ||
3831 | /* Also get rid of scope breakpoints. */ | |
3832 | ||
3833 | case bp_shlib_event: | |
3834 | ||
3835 | /* Also remove solib event breakpoints. Their addresses may | |
3836 | have changed since the last time we ran the program. | |
3837 | Actually we may now be debugging against different target; | |
3838 | and so the solib backend that installed this breakpoint may | |
3839 | not be used in by the target. E.g., | |
3840 | ||
3841 | (gdb) file prog-linux | |
3842 | (gdb) run # native linux target | |
3843 | ... | |
3844 | (gdb) kill | |
3845 | (gdb) file prog-win.exe | |
3846 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3847 | */ | |
c906108c | 3848 | |
f59f708a PA |
3849 | case bp_step_resume: |
3850 | ||
3851 | /* Also remove step-resume breakpoints. */ | |
3852 | ||
7c16b83e PA |
3853 | case bp_single_step: |
3854 | ||
3855 | /* Also remove single-step breakpoints. */ | |
3856 | ||
c5aa993b JM |
3857 | delete_breakpoint (b); |
3858 | break; | |
c906108c | 3859 | |
c5aa993b JM |
3860 | case bp_watchpoint: |
3861 | case bp_hardware_watchpoint: | |
3862 | case bp_read_watchpoint: | |
3863 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3864 | { |
3865 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3866 | |
3a5c3e22 PA |
3867 | /* Likewise for watchpoints on local expressions. */ |
3868 | if (w->exp_valid_block != NULL) | |
3869 | delete_breakpoint (b); | |
63000888 | 3870 | else |
3a5c3e22 | 3871 | { |
63000888 PA |
3872 | /* Get rid of existing locations, which are no longer |
3873 | valid. New ones will be created in | |
3874 | update_watchpoint, when the inferior is restarted. | |
3875 | The next update_global_location_list call will | |
3876 | garbage collect them. */ | |
3877 | b->loc = NULL; | |
3878 | ||
3879 | if (context == inf_starting) | |
3880 | { | |
3881 | /* Reset val field to force reread of starting value in | |
3882 | insert_breakpoints. */ | |
850645cf | 3883 | w->val.reset (nullptr); |
4c1d86d9 | 3884 | w->val_valid = false; |
63000888 PA |
3885 | } |
3886 | } | |
3a5c3e22 | 3887 | } |
c5aa993b JM |
3888 | break; |
3889 | default: | |
c5aa993b JM |
3890 | break; |
3891 | } | |
3892 | } | |
1c5cfe86 PA |
3893 | |
3894 | /* Get rid of the moribund locations. */ | |
1123588c | 3895 | for (bp_location *bl : moribund_locations) |
35df4500 | 3896 | decref_bp_location (&bl); |
1123588c | 3897 | moribund_locations.clear (); |
c906108c SS |
3898 | } |
3899 | ||
6c95b8df PA |
3900 | /* These functions concern about actual breakpoints inserted in the |
3901 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3902 | we need to hop over the bkpt --- so we check for address space | |
3903 | match, not program space. */ | |
3904 | ||
c2c6d25f JM |
3905 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3906 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3907 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3908 | permanent breakpoint. | |
3909 | - When continuing from a location with an ordinary breakpoint, we | |
3910 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3911 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3912 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3913 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3914 | |
c2c6d25f | 3915 | enum breakpoint_here |
accd0bcd | 3916 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 3917 | { |
35df4500 | 3918 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3919 | int any_breakpoint_here = 0; |
c906108c | 3920 | |
35df4500 | 3921 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3922 | { |
35df4500 TJB |
3923 | if (bl->loc_type != bp_loc_software_breakpoint |
3924 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3925 | continue; |
3926 | ||
f1310107 | 3927 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 3928 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 3929 | || bl->permanent) |
f1310107 | 3930 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3931 | { |
3932 | if (overlay_debugging | |
35df4500 TJB |
3933 | && section_is_overlay (bl->section) |
3934 | && !section_is_mapped (bl->section)) | |
075f6582 | 3935 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 3936 | else if (bl->permanent) |
075f6582 DJ |
3937 | return permanent_breakpoint_here; |
3938 | else | |
3939 | any_breakpoint_here = 1; | |
3940 | } | |
3941 | } | |
c906108c | 3942 | |
f486487f | 3943 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
3944 | } |
3945 | ||
d35ae833 PA |
3946 | /* See breakpoint.h. */ |
3947 | ||
3948 | int | |
accd0bcd | 3949 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
3950 | CORE_ADDR addr, ULONGEST len) |
3951 | { | |
3952 | struct bp_location *bl, **blp_tmp; | |
3953 | ||
3954 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3955 | { | |
3956 | if (bl->loc_type != bp_loc_software_breakpoint | |
3957 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
3958 | continue; | |
3959 | ||
3960 | if ((breakpoint_enabled (bl->owner) | |
3961 | || bl->permanent) | |
3962 | && breakpoint_location_address_range_overlap (bl, aspace, | |
3963 | addr, len)) | |
3964 | { | |
3965 | if (overlay_debugging | |
3966 | && section_is_overlay (bl->section) | |
3967 | && !section_is_mapped (bl->section)) | |
3968 | { | |
3969 | /* Unmapped overlay -- can't be a match. */ | |
3970 | continue; | |
3971 | } | |
3972 | ||
3973 | return 1; | |
3974 | } | |
3975 | } | |
3976 | ||
3977 | return 0; | |
3978 | } | |
3979 | ||
1c5cfe86 PA |
3980 | /* Return true if there's a moribund breakpoint at PC. */ |
3981 | ||
3982 | int | |
accd0bcd | 3983 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 3984 | { |
1123588c | 3985 | for (bp_location *loc : moribund_locations) |
f1310107 | 3986 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
3987 | return 1; |
3988 | ||
3989 | return 0; | |
3990 | } | |
c2c6d25f | 3991 | |
f7ce857f PA |
3992 | /* Returns non-zero iff BL is inserted at PC, in address space |
3993 | ASPACE. */ | |
3994 | ||
3995 | static int | |
3996 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 3997 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
3998 | { |
3999 | if (bl->inserted | |
4000 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4001 | aspace, pc)) | |
4002 | { | |
4003 | if (overlay_debugging | |
4004 | && section_is_overlay (bl->section) | |
4005 | && !section_is_mapped (bl->section)) | |
4006 | return 0; /* unmapped overlay -- can't be a match */ | |
4007 | else | |
4008 | return 1; | |
4009 | } | |
4010 | return 0; | |
4011 | } | |
4012 | ||
a1fd2fa5 | 4013 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4014 | |
4015 | int | |
accd0bcd | 4016 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4017 | { |
f7ce857f | 4018 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4019 | |
f7ce857f | 4020 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4021 | { |
f7ce857f PA |
4022 | struct bp_location *bl = *blp; |
4023 | ||
35df4500 TJB |
4024 | if (bl->loc_type != bp_loc_software_breakpoint |
4025 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4026 | continue; |
4027 | ||
f7ce857f PA |
4028 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4029 | return 1; | |
c5aa993b | 4030 | } |
c36b740a VP |
4031 | return 0; |
4032 | } | |
4033 | ||
a1fd2fa5 PA |
4034 | /* This function returns non-zero iff there is a software breakpoint |
4035 | inserted at PC. */ | |
c36b740a VP |
4036 | |
4037 | int | |
accd0bcd | 4038 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4039 | CORE_ADDR pc) |
4fa8626c | 4040 | { |
f7ce857f | 4041 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4042 | |
f7ce857f | 4043 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4044 | { |
f7ce857f PA |
4045 | struct bp_location *bl = *blp; |
4046 | ||
35df4500 | 4047 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4048 | continue; |
4049 | ||
f7ce857f PA |
4050 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4051 | return 1; | |
4fa8626c DJ |
4052 | } |
4053 | ||
4054 | return 0; | |
9c02b525 PA |
4055 | } |
4056 | ||
4057 | /* See breakpoint.h. */ | |
4058 | ||
4059 | int | |
accd0bcd | 4060 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4061 | CORE_ADDR pc) |
4062 | { | |
4063 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4064 | |
4065 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4066 | { | |
4067 | struct bp_location *bl = *blp; | |
4068 | ||
4069 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4070 | continue; | |
4071 | ||
4072 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4073 | return 1; | |
4074 | } | |
4075 | ||
4076 | return 0; | |
4fa8626c DJ |
4077 | } |
4078 | ||
9093389c | 4079 | int |
accd0bcd | 4080 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4081 | CORE_ADDR addr, ULONGEST len) |
4082 | { | |
4083 | struct breakpoint *bpt; | |
4084 | ||
4085 | ALL_BREAKPOINTS (bpt) | |
4086 | { | |
4087 | struct bp_location *loc; | |
4088 | ||
4089 | if (bpt->type != bp_hardware_watchpoint | |
4090 | && bpt->type != bp_access_watchpoint) | |
4091 | continue; | |
4092 | ||
4093 | if (!breakpoint_enabled (bpt)) | |
4094 | continue; | |
4095 | ||
4096 | for (loc = bpt->loc; loc; loc = loc->next) | |
4097 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4098 | { | |
4099 | CORE_ADDR l, h; | |
4100 | ||
4101 | /* Check for intersection. */ | |
768adc05 PA |
4102 | l = std::max<CORE_ADDR> (loc->address, addr); |
4103 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4104 | if (l < h) |
4105 | return 1; | |
4106 | } | |
4107 | } | |
4108 | return 0; | |
4109 | } | |
c5aa993b | 4110 | |
f2478a7e | 4111 | /* See breakpoint.h. */ |
c906108c | 4112 | |
f2478a7e SM |
4113 | bool |
4114 | is_catchpoint (struct breakpoint *b) | |
c906108c | 4115 | { |
f2478a7e | 4116 | return (b->type == bp_catchpoint); |
c906108c SS |
4117 | } |
4118 | ||
f431efe5 PA |
4119 | /* Frees any storage that is part of a bpstat. Does not walk the |
4120 | 'next' chain. */ | |
4121 | ||
04afa70c | 4122 | bpstats::~bpstats () |
198757a8 | 4123 | { |
04afa70c TT |
4124 | if (bp_location_at != NULL) |
4125 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4126 | } |
4127 | ||
c906108c SS |
4128 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4129 | Also free any storage that is part of a bpstat. */ | |
4130 | ||
4131 | void | |
fba45db2 | 4132 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4133 | { |
4134 | bpstat p; | |
4135 | bpstat q; | |
4136 | ||
4137 | if (bsp == 0) | |
4138 | return; | |
4139 | p = *bsp; | |
4140 | while (p != NULL) | |
4141 | { | |
4142 | q = p->next; | |
04afa70c | 4143 | delete p; |
c906108c SS |
4144 | p = q; |
4145 | } | |
4146 | *bsp = NULL; | |
4147 | } | |
4148 | ||
04afa70c TT |
4149 | bpstats::bpstats (const bpstats &other) |
4150 | : next (NULL), | |
4151 | bp_location_at (other.bp_location_at), | |
4152 | breakpoint_at (other.breakpoint_at), | |
4153 | commands (other.commands), | |
04afa70c TT |
4154 | print (other.print), |
4155 | stop (other.stop), | |
4156 | print_it (other.print_it) | |
4157 | { | |
850645cf TT |
4158 | if (other.old_val != NULL) |
4159 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c | 4160 | incref_bp_location (bp_location_at); |
04afa70c TT |
4161 | } |
4162 | ||
c906108c SS |
4163 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4164 | is part of the bpstat is copied as well. */ | |
4165 | ||
4166 | bpstat | |
fba45db2 | 4167 | bpstat_copy (bpstat bs) |
c906108c SS |
4168 | { |
4169 | bpstat p = NULL; | |
4170 | bpstat tmp; | |
4171 | bpstat retval = NULL; | |
4172 | ||
4173 | if (bs == NULL) | |
4174 | return bs; | |
4175 | ||
4176 | for (; bs != NULL; bs = bs->next) | |
4177 | { | |
04afa70c | 4178 | tmp = new bpstats (*bs); |
31cc81e9 | 4179 | |
c906108c SS |
4180 | if (p == NULL) |
4181 | /* This is the first thing in the chain. */ | |
4182 | retval = tmp; | |
4183 | else | |
4184 | p->next = tmp; | |
4185 | p = tmp; | |
4186 | } | |
4187 | p->next = NULL; | |
4188 | return retval; | |
4189 | } | |
4190 | ||
4a64f543 | 4191 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4192 | |
4193 | bpstat | |
fba45db2 | 4194 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4195 | { |
c5aa993b JM |
4196 | if (bsp == NULL) |
4197 | return NULL; | |
c906108c | 4198 | |
c5aa993b JM |
4199 | for (; bsp != NULL; bsp = bsp->next) |
4200 | { | |
f431efe5 | 4201 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4202 | return bsp; |
4203 | } | |
c906108c SS |
4204 | return NULL; |
4205 | } | |
4206 | ||
ab04a2af TT |
4207 | /* See breakpoint.h. */ |
4208 | ||
4c462cb0 | 4209 | bool |
427cd150 | 4210 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4211 | { |
ab04a2af TT |
4212 | for (; bsp != NULL; bsp = bsp->next) |
4213 | { | |
427cd150 TT |
4214 | if (bsp->breakpoint_at == NULL) |
4215 | { | |
4216 | /* A moribund location can never explain a signal other than | |
4217 | GDB_SIGNAL_TRAP. */ | |
4218 | if (sig == GDB_SIGNAL_TRAP) | |
4c462cb0 | 4219 | return true; |
427cd150 TT |
4220 | } |
4221 | else | |
47591c29 PA |
4222 | { |
4223 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4224 | sig)) | |
4c462cb0 | 4225 | return true; |
47591c29 | 4226 | } |
ab04a2af TT |
4227 | } |
4228 | ||
4c462cb0 | 4229 | return false; |
ab04a2af TT |
4230 | } |
4231 | ||
4a64f543 MS |
4232 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4233 | stopped at. *BSP upon return is a bpstat which points to the | |
4234 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4235 | good for anything but further calls to bpstat_num). | |
4236 | ||
8671a17b PA |
4237 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4238 | Return -1 if stopped at a breakpoint that has been deleted since | |
4239 | we set it. | |
4240 | Return 1 otherwise. */ | |
c906108c SS |
4241 | |
4242 | int | |
8671a17b | 4243 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4244 | { |
4245 | struct breakpoint *b; | |
4246 | ||
4247 | if ((*bsp) == NULL) | |
4248 | return 0; /* No more breakpoint values */ | |
8671a17b | 4249 | |
4a64f543 MS |
4250 | /* We assume we'll never have several bpstats that correspond to a |
4251 | single breakpoint -- otherwise, this function might return the | |
4252 | same number more than once and this will look ugly. */ | |
f431efe5 | 4253 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4254 | *bsp = (*bsp)->next; |
4255 | if (b == NULL) | |
4256 | return -1; /* breakpoint that's been deleted since */ | |
4257 | ||
4258 | *num = b->number; /* We have its number */ | |
4259 | return 1; | |
c906108c SS |
4260 | } |
4261 | ||
e93ca019 | 4262 | /* See breakpoint.h. */ |
c906108c SS |
4263 | |
4264 | void | |
e93ca019 | 4265 | bpstat_clear_actions (void) |
c906108c | 4266 | { |
e93ca019 JK |
4267 | bpstat bs; |
4268 | ||
00431a78 | 4269 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4270 | return; |
4271 | ||
00431a78 | 4272 | thread_info *tp = inferior_thread (); |
e93ca019 | 4273 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4274 | { |
d1b0a7bf | 4275 | bs->commands = NULL; |
850645cf | 4276 | bs->old_val.reset (nullptr); |
c906108c SS |
4277 | } |
4278 | } | |
4279 | ||
f3b1572e PA |
4280 | /* Called when a command is about to proceed the inferior. */ |
4281 | ||
4282 | static void | |
4283 | breakpoint_about_to_proceed (void) | |
4284 | { | |
d7e15655 | 4285 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4286 | { |
4287 | struct thread_info *tp = inferior_thread (); | |
4288 | ||
4289 | /* Allow inferior function calls in breakpoint commands to not | |
4290 | interrupt the command list. When the call finishes | |
4291 | successfully, the inferior will be standing at the same | |
4292 | breakpoint as if nothing happened. */ | |
16c381f0 | 4293 | if (tp->control.in_infcall) |
f3b1572e PA |
4294 | return; |
4295 | } | |
4296 | ||
4297 | breakpoint_proceeded = 1; | |
4298 | } | |
4299 | ||
abf85f46 JK |
4300 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4301 | or its equivalent. */ | |
4302 | ||
4303 | static int | |
4304 | command_line_is_silent (struct command_line *cmd) | |
4305 | { | |
4f45d445 | 4306 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4307 | } |
4308 | ||
4a64f543 MS |
4309 | /* Execute all the commands associated with all the breakpoints at |
4310 | this location. Any of these commands could cause the process to | |
4311 | proceed beyond this point, etc. We look out for such changes by | |
4312 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4313 | |
347bddb7 PA |
4314 | Returns true if a breakpoint command resumed the inferior. In that |
4315 | case, it is the caller's responsibility to recall it again with the | |
4316 | bpstat of the current thread. */ | |
4317 | ||
4318 | static int | |
4319 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4320 | { |
4321 | bpstat bs; | |
347bddb7 | 4322 | int again = 0; |
c906108c SS |
4323 | |
4324 | /* Avoid endless recursion if a `source' command is contained | |
4325 | in bs->commands. */ | |
4326 | if (executing_breakpoint_commands) | |
347bddb7 | 4327 | return 0; |
c906108c | 4328 | |
81b1e71c TT |
4329 | scoped_restore save_executing |
4330 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4331 | |
1ac32117 | 4332 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4333 | |
4a64f543 | 4334 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4335 | bs = *bsp; |
4336 | ||
4337 | breakpoint_proceeded = 0; | |
4338 | for (; bs != NULL; bs = bs->next) | |
4339 | { | |
d1b0a7bf | 4340 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4341 | |
4342 | /* Take ownership of the BSP's command tree, if it has one. | |
4343 | ||
4344 | The command tree could legitimately contain commands like | |
4345 | 'step' and 'next', which call clear_proceed_status, which | |
4346 | frees stop_bpstat's command tree. To make sure this doesn't | |
4347 | free the tree we're executing out from under us, we need to | |
4348 | take ownership of the tree ourselves. Since a given bpstat's | |
4349 | commands are only executed once, we don't need to copy it; we | |
4350 | can clear the pointer in the bpstat, and make sure we free | |
4351 | the tree when we're done. */ | |
d1b0a7bf | 4352 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4353 | bs->commands = NULL; |
d1b0a7bf TT |
4354 | if (ccmd != NULL) |
4355 | cmd = ccmd.get (); | |
abf85f46 JK |
4356 | if (command_line_is_silent (cmd)) |
4357 | { | |
4358 | /* The action has been already done by bpstat_stop_status. */ | |
4359 | cmd = cmd->next; | |
4360 | } | |
6c50ab1c | 4361 | |
c906108c SS |
4362 | while (cmd != NULL) |
4363 | { | |
4364 | execute_control_command (cmd); | |
4365 | ||
4366 | if (breakpoint_proceeded) | |
4367 | break; | |
4368 | else | |
4369 | cmd = cmd->next; | |
4370 | } | |
6c50ab1c | 4371 | |
c906108c | 4372 | if (breakpoint_proceeded) |
32c1e744 | 4373 | { |
cb814510 | 4374 | if (current_ui->async) |
347bddb7 PA |
4375 | /* If we are in async mode, then the target might be still |
4376 | running, not stopped at any breakpoint, so nothing for | |
4377 | us to do here -- just return to the event loop. */ | |
4378 | ; | |
32c1e744 VP |
4379 | else |
4380 | /* In sync mode, when execute_control_command returns | |
4381 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4382 | Breakpoint commands for that stop were not run, since |
4383 | execute_command does not run breakpoint commands -- | |
4384 | only command_line_handler does, but that one is not | |
4385 | involved in execution of breakpoint commands. So, we | |
4386 | can now execute breakpoint commands. It should be | |
4387 | noted that making execute_command do bpstat actions is | |
4388 | not an option -- in this case we'll have recursive | |
4389 | invocation of bpstat for each breakpoint with a | |
4390 | command, and can easily blow up GDB stack. Instead, we | |
4391 | return true, which will trigger the caller to recall us | |
4392 | with the new stop_bpstat. */ | |
4393 | again = 1; | |
4394 | break; | |
32c1e744 | 4395 | } |
c906108c | 4396 | } |
347bddb7 PA |
4397 | return again; |
4398 | } | |
4399 | ||
00431a78 PA |
4400 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4401 | one, is alive and has execution. Return NULL otherwise. */ | |
4402 | ||
4403 | static thread_info * | |
4404 | get_bpstat_thread () | |
4405 | { | |
4406 | if (inferior_ptid == null_ptid || !target_has_execution) | |
4407 | return NULL; | |
4408 | ||
4409 | thread_info *tp = inferior_thread (); | |
4410 | if (tp->state == THREAD_EXITED || tp->executing) | |
4411 | return NULL; | |
4412 | return tp; | |
4413 | } | |
4414 | ||
347bddb7 PA |
4415 | void |
4416 | bpstat_do_actions (void) | |
4417 | { | |
694c6bf5 | 4418 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4419 | thread_info *tp; |
353d1d73 | 4420 | |
347bddb7 | 4421 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4422 | while ((tp = get_bpstat_thread ()) != NULL) |
4423 | { | |
4424 | /* Since in sync mode, bpstat_do_actions may resume the | |
4425 | inferior, and only return when it is stopped at the next | |
4426 | breakpoint, we keep doing breakpoint actions until it returns | |
4427 | false to indicate the inferior was not resumed. */ | |
4428 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4429 | break; | |
4430 | } | |
353d1d73 | 4431 | |
694c6bf5 | 4432 | cleanup_if_error.release (); |
c906108c SS |
4433 | } |
4434 | ||
fa4727a6 DJ |
4435 | /* Print out the (old or new) value associated with a watchpoint. */ |
4436 | ||
4437 | static void | |
4438 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4439 | { | |
4440 | if (val == NULL) | |
7f6aba03 | 4441 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
fa4727a6 | 4442 | else |
79a45b7d TT |
4443 | { |
4444 | struct value_print_options opts; | |
4445 | get_user_print_options (&opts); | |
4446 | value_print (val, stream, &opts); | |
4447 | } | |
fa4727a6 DJ |
4448 | } |
4449 | ||
f303dbd6 PA |
4450 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4451 | debugging multiple threads. */ | |
4452 | ||
4453 | void | |
4454 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4455 | { | |
112e8700 | 4456 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4457 | return; |
4458 | ||
112e8700 | 4459 | uiout->text ("\n"); |
f303dbd6 PA |
4460 | |
4461 | if (show_thread_that_caused_stop ()) | |
4462 | { | |
4463 | const char *name; | |
4464 | struct thread_info *thr = inferior_thread (); | |
4465 | ||
112e8700 | 4466 | uiout->text ("Thread "); |
33eca680 | 4467 | uiout->field_string ("thread-id", print_thread_id (thr)); |
f303dbd6 PA |
4468 | |
4469 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4470 | if (name != NULL) | |
4471 | { | |
112e8700 | 4472 | uiout->text (" \""); |
33eca680 | 4473 | uiout->field_string ("name", name); |
112e8700 | 4474 | uiout->text ("\""); |
f303dbd6 PA |
4475 | } |
4476 | ||
112e8700 | 4477 | uiout->text (" hit "); |
f303dbd6 PA |
4478 | } |
4479 | } | |
4480 | ||
e514a9d6 | 4481 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4482 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4483 | 'print_it' in the bpstat structure. Under some circumstances we |
4484 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4485 | normal_stop(). */ |
e514a9d6 JM |
4486 | |
4487 | static enum print_stop_action | |
4488 | print_bp_stop_message (bpstat bs) | |
4489 | { | |
4490 | switch (bs->print_it) | |
4491 | { | |
4492 | case print_it_noop: | |
4a64f543 | 4493 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4494 | return PRINT_UNKNOWN; |
4495 | break; | |
4496 | ||
4497 | case print_it_done: | |
4498 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4499 | relevant messages. */ |
e514a9d6 JM |
4500 | return PRINT_SRC_AND_LOC; |
4501 | break; | |
4502 | ||
4503 | case print_it_normal: | |
4f8d1dc6 | 4504 | { |
f431efe5 PA |
4505 | struct breakpoint *b = bs->breakpoint_at; |
4506 | ||
1a6a67de TJB |
4507 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4508 | which has since been deleted. */ | |
4509 | if (b == NULL) | |
4510 | return PRINT_UNKNOWN; | |
4511 | ||
348d480f PA |
4512 | /* Normal case. Call the breakpoint's print_it method. */ |
4513 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4514 | } |
348d480f | 4515 | break; |
3086aeae | 4516 | |
e514a9d6 | 4517 | default: |
8e65ff28 | 4518 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4519 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4520 | break; |
c906108c | 4521 | } |
c906108c SS |
4522 | } |
4523 | ||
edcc5120 TT |
4524 | /* A helper function that prints a shared library stopped event. */ |
4525 | ||
4526 | static void | |
4527 | print_solib_event (int is_catchpoint) | |
4528 | { | |
6fb16ce6 | 4529 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4530 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4531 | |
4532 | if (!is_catchpoint) | |
4533 | { | |
4534 | if (any_added || any_deleted) | |
112e8700 | 4535 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4536 | else |
112e8700 SM |
4537 | current_uiout->text (_("Stopped due to shared library event (no " |
4538 | "libraries added or removed)\n")); | |
edcc5120 TT |
4539 | } |
4540 | ||
112e8700 SM |
4541 | if (current_uiout->is_mi_like_p ()) |
4542 | current_uiout->field_string ("reason", | |
4543 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4544 | |
4545 | if (any_deleted) | |
4546 | { | |
112e8700 | 4547 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4548 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4549 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4550 | { |
6fb16ce6 SM |
4551 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4552 | ||
edcc5120 | 4553 | if (ix > 0) |
112e8700 SM |
4554 | current_uiout->text (" "); |
4555 | current_uiout->field_string ("library", name); | |
4556 | current_uiout->text ("\n"); | |
edcc5120 | 4557 | } |
edcc5120 TT |
4558 | } |
4559 | ||
4560 | if (any_added) | |
4561 | { | |
112e8700 | 4562 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4563 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4564 | bool first = true; |
52941706 | 4565 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4566 | { |
bcb430e4 | 4567 | if (!first) |
112e8700 | 4568 | current_uiout->text (" "); |
bcb430e4 | 4569 | first = false; |
112e8700 SM |
4570 | current_uiout->field_string ("library", iter->so_name); |
4571 | current_uiout->text ("\n"); | |
edcc5120 | 4572 | } |
edcc5120 TT |
4573 | } |
4574 | } | |
4575 | ||
e514a9d6 JM |
4576 | /* Print a message indicating what happened. This is called from |
4577 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4578 | list - a list of the eventpoints that caused this stop. KIND is |
4579 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4580 | routine calls the generic print routine for printing a message |
4581 | about reasons for stopping. This will print (for example) the | |
4582 | "Breakpoint n," part of the output. The return value of this | |
4583 | routine is one of: | |
c906108c | 4584 | |
4a64f543 | 4585 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4586 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4587 | code to print the location. An example is |
c5aa993b JM |
4588 | "Breakpoint 1, " which should be followed by |
4589 | the location. | |
917317f4 | 4590 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4591 | to also print the location part of the message. |
4592 | An example is the catch/throw messages, which | |
4a64f543 | 4593 | don't require a location appended to the end. |
917317f4 | 4594 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4595 | further info to be printed. */ |
c906108c | 4596 | |
917317f4 | 4597 | enum print_stop_action |
36dfb11c | 4598 | bpstat_print (bpstat bs, int kind) |
c906108c | 4599 | { |
f486487f | 4600 | enum print_stop_action val; |
c5aa993b | 4601 | |
c906108c | 4602 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4603 | (Currently all watchpoints go on the bpstat whether hit or not. |
4604 | That probably could (should) be changed, provided care is taken | |
c906108c | 4605 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4606 | for (; bs; bs = bs->next) |
4607 | { | |
4608 | val = print_bp_stop_message (bs); | |
4609 | if (val == PRINT_SRC_ONLY | |
4610 | || val == PRINT_SRC_AND_LOC | |
4611 | || val == PRINT_NOTHING) | |
4612 | return val; | |
4613 | } | |
c906108c | 4614 | |
36dfb11c TT |
4615 | /* If we had hit a shared library event breakpoint, |
4616 | print_bp_stop_message would print out this message. If we hit an | |
4617 | OS-level shared library event, do the same thing. */ | |
4618 | if (kind == TARGET_WAITKIND_LOADED) | |
4619 | { | |
edcc5120 | 4620 | print_solib_event (0); |
36dfb11c TT |
4621 | return PRINT_NOTHING; |
4622 | } | |
4623 | ||
e514a9d6 | 4624 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4625 | with and nothing was printed. */ |
917317f4 | 4626 | return PRINT_UNKNOWN; |
c906108c SS |
4627 | } |
4628 | ||
bf469271 | 4629 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4630 | |
bf469271 PA |
4631 | static bool |
4632 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4633 | { |
278cd55f | 4634 | struct value *mark = value_mark (); |
bf469271 | 4635 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4636 | |
c906108c | 4637 | value_free_to_mark (mark); |
bf469271 | 4638 | return res; |
c906108c SS |
4639 | } |
4640 | ||
5760d0ab | 4641 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4642 | |
04afa70c TT |
4643 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4644 | : next (NULL), | |
4645 | bp_location_at (bl), | |
4646 | breakpoint_at (bl->owner), | |
4647 | commands (NULL), | |
04afa70c TT |
4648 | print (0), |
4649 | stop (0), | |
4650 | print_it (print_it_normal) | |
c906108c | 4651 | { |
f431efe5 | 4652 | incref_bp_location (bl); |
04afa70c TT |
4653 | **bs_link_pointer = this; |
4654 | *bs_link_pointer = &next; | |
4655 | } | |
4656 | ||
4657 | bpstats::bpstats () | |
4658 | : next (NULL), | |
4659 | bp_location_at (NULL), | |
4660 | breakpoint_at (NULL), | |
4661 | commands (NULL), | |
04afa70c TT |
4662 | print (0), |
4663 | stop (0), | |
4664 | print_it (print_it_normal) | |
4665 | { | |
c906108c SS |
4666 | } |
4667 | \f | |
d983da9c DJ |
4668 | /* The target has stopped with waitstatus WS. Check if any hardware |
4669 | watchpoints have triggered, according to the target. */ | |
4670 | ||
4671 | int | |
4672 | watchpoints_triggered (struct target_waitstatus *ws) | |
4673 | { | |
57810aa7 | 4674 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4675 | CORE_ADDR addr; |
4676 | struct breakpoint *b; | |
4677 | ||
4678 | if (!stopped_by_watchpoint) | |
4679 | { | |
4680 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4681 | as not triggered. */ | |
4682 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4683 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4684 | { |
4685 | struct watchpoint *w = (struct watchpoint *) b; | |
4686 | ||
4687 | w->watchpoint_triggered = watch_triggered_no; | |
4688 | } | |
d983da9c DJ |
4689 | |
4690 | return 0; | |
4691 | } | |
4692 | ||
8b88a78e | 4693 | if (!target_stopped_data_address (current_top_target (), &addr)) |
d983da9c DJ |
4694 | { |
4695 | /* We were stopped by a watchpoint, but we don't know where. | |
4696 | Mark all watchpoints as unknown. */ | |
4697 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4698 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4699 | { |
4700 | struct watchpoint *w = (struct watchpoint *) b; | |
4701 | ||
4702 | w->watchpoint_triggered = watch_triggered_unknown; | |
4703 | } | |
d983da9c | 4704 | |
3c4797ba | 4705 | return 1; |
d983da9c DJ |
4706 | } |
4707 | ||
4708 | /* The target could report the data address. Mark watchpoints | |
4709 | affected by this data address as triggered, and all others as not | |
4710 | triggered. */ | |
4711 | ||
4712 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4713 | if (is_hardware_watchpoint (b)) |
d983da9c | 4714 | { |
3a5c3e22 | 4715 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4716 | struct bp_location *loc; |
d983da9c | 4717 | |
3a5c3e22 | 4718 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4719 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4720 | { |
3a5c3e22 | 4721 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4722 | { |
3a5c3e22 PA |
4723 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4724 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4725 | |
4726 | if (newaddr == start) | |
4727 | { | |
3a5c3e22 | 4728 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4729 | break; |
4730 | } | |
4731 | } | |
4732 | /* Exact match not required. Within range is sufficient. */ | |
8b88a78e | 4733 | else if (target_watchpoint_addr_within_range (current_top_target (), |
9c06b0b4 TJB |
4734 | addr, loc->address, |
4735 | loc->length)) | |
4736 | { | |
3a5c3e22 | 4737 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4738 | break; |
4739 | } | |
4740 | } | |
d983da9c DJ |
4741 | } |
4742 | ||
4743 | return 1; | |
4744 | } | |
4745 | ||
bf469271 PA |
4746 | /* Possible return values for watchpoint_check. */ |
4747 | enum wp_check_result | |
4748 | { | |
4749 | /* The watchpoint has been deleted. */ | |
4750 | WP_DELETED = 1, | |
4751 | ||
4752 | /* The value has changed. */ | |
4753 | WP_VALUE_CHANGED = 2, | |
4754 | ||
4755 | /* The value has not changed. */ | |
4756 | WP_VALUE_NOT_CHANGED = 3, | |
4757 | ||
4758 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4759 | WP_IGNORE = 4, | |
4760 | }; | |
c906108c SS |
4761 | |
4762 | #define BP_TEMPFLAG 1 | |
4763 | #define BP_HARDWAREFLAG 2 | |
4764 | ||
4a64f543 | 4765 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4766 | changed. */ |
553e4c11 | 4767 | |
bf469271 PA |
4768 | static wp_check_result |
4769 | watchpoint_check (bpstat bs) | |
c906108c | 4770 | { |
3a5c3e22 | 4771 | struct watchpoint *b; |
c906108c SS |
4772 | struct frame_info *fr; |
4773 | int within_current_scope; | |
4774 | ||
f431efe5 | 4775 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4776 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4777 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4778 | |
f6bc2008 PA |
4779 | /* If this is a local watchpoint, we only want to check if the |
4780 | watchpoint frame is in scope if the current thread is the thread | |
4781 | that was used to create the watchpoint. */ | |
4782 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4783 | return WP_IGNORE; |
f6bc2008 | 4784 | |
c906108c SS |
4785 | if (b->exp_valid_block == NULL) |
4786 | within_current_scope = 1; | |
4787 | else | |
4788 | { | |
edb3359d DJ |
4789 | struct frame_info *frame = get_current_frame (); |
4790 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4791 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4792 | ||
c9cf6e20 | 4793 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4794 | still in the function but the stack frame has already been |
4795 | invalidated. Since we can't rely on the values of local | |
4796 | variables after the stack has been destroyed, we are treating | |
4797 | the watchpoint in that state as `not changed' without further | |
4798 | checking. Don't mark watchpoints as changed if the current | |
4799 | frame is in an epilogue - even if they are in some other | |
4800 | frame, our view of the stack is likely to be wrong and | |
4801 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4802 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4803 | return WP_IGNORE; |
a0f49112 | 4804 | |
101dcfbe | 4805 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4806 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4807 | |
4808 | /* If we've gotten confused in the unwinder, we might have | |
4809 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4810 | if (within_current_scope) |
4811 | { | |
4812 | struct symbol *function; | |
4813 | ||
4814 | function = get_frame_function (fr); | |
4815 | if (function == NULL | |
4816 | || !contained_in (b->exp_valid_block, | |
4817 | SYMBOL_BLOCK_VALUE (function))) | |
4818 | within_current_scope = 0; | |
4819 | } | |
69fbadd5 | 4820 | |
edb3359d | 4821 | if (within_current_scope) |
c906108c SS |
4822 | /* If we end up stopping, the current frame will get selected |
4823 | in normal_stop. So this call to select_frame won't affect | |
4824 | the user. */ | |
0f7d239c | 4825 | select_frame (fr); |
c906108c | 4826 | } |
c5aa993b | 4827 | |
c906108c SS |
4828 | if (within_current_scope) |
4829 | { | |
4a64f543 MS |
4830 | /* We use value_{,free_to_}mark because it could be a *long* |
4831 | time before we return to the command level and call | |
4832 | free_all_values. We can't call free_all_values because we | |
4833 | might be in the middle of evaluating a function call. */ | |
c906108c | 4834 | |
0cf6dd15 | 4835 | int pc = 0; |
9c06b0b4 | 4836 | struct value *mark; |
fa4727a6 DJ |
4837 | struct value *new_val; |
4838 | ||
c1fc2657 | 4839 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
4840 | /* Since we don't know the exact trigger address (from |
4841 | stopped_data_address), just tell the user we've triggered | |
4842 | a mask watchpoint. */ | |
4843 | return WP_VALUE_CHANGED; | |
4844 | ||
4845 | mark = value_mark (); | |
4d01a485 | 4846 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4847 | |
bb9d5f81 PP |
4848 | if (b->val_bitsize != 0) |
4849 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
4850 | ||
4a64f543 MS |
4851 | /* We use value_equal_contents instead of value_equal because |
4852 | the latter coerces an array to a pointer, thus comparing just | |
4853 | the address of the array instead of its contents. This is | |
4854 | not what we want. */ | |
fa4727a6 | 4855 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
4856 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
4857 | new_val))) | |
c906108c | 4858 | { |
c906108c | 4859 | bs->old_val = b->val; |
850645cf | 4860 | b->val = release_value (new_val); |
4c1d86d9 | 4861 | b->val_valid = true; |
850645cf TT |
4862 | if (new_val != NULL) |
4863 | value_free_to_mark (mark); | |
c906108c SS |
4864 | return WP_VALUE_CHANGED; |
4865 | } | |
4866 | else | |
4867 | { | |
60e1c644 | 4868 | /* Nothing changed. */ |
c906108c | 4869 | value_free_to_mark (mark); |
c906108c SS |
4870 | return WP_VALUE_NOT_CHANGED; |
4871 | } | |
4872 | } | |
4873 | else | |
4874 | { | |
4875 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
4876 | if we temporarily ignored the watchpoint, then when |
4877 | we reenter the block in which it is valid it contains | |
4878 | garbage (in the case of a function, it may have two | |
4879 | garbage values, one before and one after the prologue). | |
4880 | So we can't even detect the first assignment to it and | |
4881 | watch after that (since the garbage may or may not equal | |
4882 | the first value assigned). */ | |
348d480f PA |
4883 | /* We print all the stop information in |
4884 | breakpoint_ops->print_it, but in this case, by the time we | |
4885 | call breakpoint_ops->print_it this bp will be deleted | |
4886 | already. So we have no choice but print the information | |
4887 | here. */ | |
468afe6c | 4888 | |
0e454242 | 4889 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
4890 | { |
4891 | struct ui_out *uiout = current_uiout; | |
4892 | ||
112e8700 SM |
4893 | if (uiout->is_mi_like_p ()) |
4894 | uiout->field_string | |
4895 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
6a831f06 PA |
4896 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
4897 | "left the block in\n" | |
4898 | "which its expression is valid.\n", | |
4899 | signed_field ("wpnum", b->number)); | |
468afe6c | 4900 | } |
4ce44c66 | 4901 | |
cdac0397 | 4902 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 4903 | b->commands = NULL; |
d0fb5eae | 4904 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4905 | |
4906 | return WP_DELETED; | |
4907 | } | |
4908 | } | |
4909 | ||
18a18393 | 4910 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4911 | breakpoint location BL. This function does not check if we should |
4912 | stop, only if BL explains the stop. */ | |
4913 | ||
18a18393 | 4914 | static int |
6c95b8df | 4915 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 4916 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 4917 | const struct target_waitstatus *ws) |
18a18393 VP |
4918 | { |
4919 | struct breakpoint *b = bl->owner; | |
4920 | ||
348d480f | 4921 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4922 | gdb_assert (b != NULL); |
4923 | ||
bd522513 | 4924 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4925 | } |
4926 | ||
3a5c3e22 PA |
4927 | /* Determine if the watched values have actually changed, and we |
4928 | should stop. If not, set BS->stop to 0. */ | |
4929 | ||
18a18393 VP |
4930 | static void |
4931 | bpstat_check_watchpoint (bpstat bs) | |
4932 | { | |
2bdf28a0 | 4933 | const struct bp_location *bl; |
3a5c3e22 | 4934 | struct watchpoint *b; |
2bdf28a0 JK |
4935 | |
4936 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4937 | bl = bs->bp_location_at; |
2bdf28a0 | 4938 | gdb_assert (bl != NULL); |
3a5c3e22 | 4939 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4940 | gdb_assert (b != NULL); |
18a18393 | 4941 | |
18a18393 | 4942 | { |
18a18393 VP |
4943 | int must_check_value = 0; |
4944 | ||
c1fc2657 | 4945 | if (b->type == bp_watchpoint) |
18a18393 VP |
4946 | /* For a software watchpoint, we must always check the |
4947 | watched value. */ | |
4948 | must_check_value = 1; | |
4949 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4950 | /* We have a hardware watchpoint (read, write, or access) | |
4951 | and the target earlier reported an address watched by | |
4952 | this watchpoint. */ | |
4953 | must_check_value = 1; | |
4954 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 4955 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
4956 | /* We were stopped by a hardware watchpoint, but the target could |
4957 | not report the data address. We must check the watchpoint's | |
4958 | value. Access and read watchpoints are out of luck; without | |
4959 | a data address, we can't figure it out. */ | |
4960 | must_check_value = 1; | |
3a5c3e22 | 4961 | |
18a18393 VP |
4962 | if (must_check_value) |
4963 | { | |
bf469271 PA |
4964 | wp_check_result e; |
4965 | ||
a70b8144 | 4966 | try |
bf469271 PA |
4967 | { |
4968 | e = watchpoint_check (bs); | |
4969 | } | |
230d2906 | 4970 | catch (const gdb_exception &ex) |
bf469271 PA |
4971 | { |
4972 | exception_fprintf (gdb_stderr, ex, | |
4973 | "Error evaluating expression " | |
4974 | "for watchpoint %d\n", | |
4975 | b->number); | |
4976 | ||
4977 | SWITCH_THRU_ALL_UIS () | |
4978 | { | |
4979 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
4980 | b->number); | |
4981 | } | |
4982 | watchpoint_del_at_next_stop (b); | |
4983 | e = WP_DELETED; | |
4984 | } | |
bf469271 | 4985 | |
18a18393 VP |
4986 | switch (e) |
4987 | { | |
4988 | case WP_DELETED: | |
4989 | /* We've already printed what needs to be printed. */ | |
4990 | bs->print_it = print_it_done; | |
4991 | /* Stop. */ | |
4992 | break; | |
60e1c644 PA |
4993 | case WP_IGNORE: |
4994 | bs->print_it = print_it_noop; | |
4995 | bs->stop = 0; | |
4996 | break; | |
18a18393 | 4997 | case WP_VALUE_CHANGED: |
c1fc2657 | 4998 | if (b->type == bp_read_watchpoint) |
18a18393 | 4999 | { |
85d721b8 PA |
5000 | /* There are two cases to consider here: |
5001 | ||
4a64f543 | 5002 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5003 | In that case, trust the target, and always report |
5004 | the watchpoint hit to the user. Even though | |
5005 | reads don't cause value changes, the value may | |
5006 | have changed since the last time it was read, and | |
5007 | since we're not trapping writes, we will not see | |
5008 | those, and as such we should ignore our notion of | |
5009 | old value. | |
5010 | ||
4a64f543 | 5011 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5012 | reads and writes. There are two ways this may |
5013 | happen: | |
5014 | ||
4a64f543 | 5015 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5016 | reads only, but can break on accesses (reads or |
5017 | writes), such as e.g., x86. We detect this case | |
5018 | at the time we try to insert read watchpoints. | |
5019 | ||
4a64f543 | 5020 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5021 | watchpoints, but, the user set an access or write |
5022 | watchpoint watching the same memory as this read | |
5023 | watchpoint. | |
5024 | ||
5025 | If we're watching memory writes as well as reads, | |
5026 | ignore watchpoint hits when we find that the | |
5027 | value hasn't changed, as reads don't cause | |
5028 | changes. This still gives false positives when | |
5029 | the program writes the same value to memory as | |
5030 | what there was already in memory (we will confuse | |
5031 | it for a read), but it's much better than | |
5032 | nothing. */ | |
5033 | ||
5034 | int other_write_watchpoint = 0; | |
5035 | ||
5036 | if (bl->watchpoint_type == hw_read) | |
5037 | { | |
5038 | struct breakpoint *other_b; | |
5039 | ||
5040 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5041 | if (other_b->type == bp_hardware_watchpoint |
5042 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5043 | { |
3a5c3e22 PA |
5044 | struct watchpoint *other_w = |
5045 | (struct watchpoint *) other_b; | |
5046 | ||
5047 | if (other_w->watchpoint_triggered | |
5048 | == watch_triggered_yes) | |
5049 | { | |
5050 | other_write_watchpoint = 1; | |
5051 | break; | |
5052 | } | |
85d721b8 PA |
5053 | } |
5054 | } | |
5055 | ||
5056 | if (other_write_watchpoint | |
5057 | || bl->watchpoint_type == hw_access) | |
5058 | { | |
5059 | /* We're watching the same memory for writes, | |
5060 | and the value changed since the last time we | |
5061 | updated it, so this trap must be for a write. | |
5062 | Ignore it. */ | |
5063 | bs->print_it = print_it_noop; | |
5064 | bs->stop = 0; | |
5065 | } | |
18a18393 VP |
5066 | } |
5067 | break; | |
5068 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5069 | if (b->type == bp_hardware_watchpoint |
5070 | || b->type == bp_watchpoint) | |
18a18393 VP |
5071 | { |
5072 | /* Don't stop: write watchpoints shouldn't fire if | |
5073 | the value hasn't changed. */ | |
5074 | bs->print_it = print_it_noop; | |
5075 | bs->stop = 0; | |
5076 | } | |
5077 | /* Stop. */ | |
5078 | break; | |
5079 | default: | |
5080 | /* Can't happen. */ | |
18a18393 VP |
5081 | break; |
5082 | } | |
5083 | } | |
5084 | else /* must_check_value == 0 */ | |
5085 | { | |
5086 | /* This is a case where some watchpoint(s) triggered, but | |
5087 | not at the address of this watchpoint, or else no | |
5088 | watchpoint triggered after all. So don't print | |
5089 | anything for this watchpoint. */ | |
5090 | bs->print_it = print_it_noop; | |
5091 | bs->stop = 0; | |
5092 | } | |
5093 | } | |
5094 | } | |
5095 | ||
7d4df6a4 DE |
5096 | /* For breakpoints that are currently marked as telling gdb to stop, |
5097 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5098 | of breakpoint referred to by BS. If we should not stop for this |
5099 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5100 | |
18a18393 | 5101 | static void |
00431a78 | 5102 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
18a18393 | 5103 | { |
2bdf28a0 JK |
5104 | const struct bp_location *bl; |
5105 | struct breakpoint *b; | |
bf469271 PA |
5106 | /* Assume stop. */ |
5107 | bool condition_result = true; | |
7d4df6a4 DE |
5108 | struct expression *cond; |
5109 | ||
5110 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5111 | |
5112 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5113 | bl = bs->bp_location_at; |
2bdf28a0 | 5114 | gdb_assert (bl != NULL); |
f431efe5 | 5115 | b = bs->breakpoint_at; |
2bdf28a0 | 5116 | gdb_assert (b != NULL); |
18a18393 | 5117 | |
b775012e LM |
5118 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5119 | need to do so again since GDB does not know if we stopped due to a | |
5120 | breakpoint or a single step breakpoint. */ | |
5121 | ||
18a18393 | 5122 | if (frame_id_p (b->frame_id) |
edb3359d | 5123 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5124 | { |
7d4df6a4 DE |
5125 | bs->stop = 0; |
5126 | return; | |
5127 | } | |
60e1c644 | 5128 | |
12ab52e9 PA |
5129 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5130 | evaluating the condition if this isn't the specified | |
5131 | thread/task. */ | |
00431a78 PA |
5132 | if ((b->thread != -1 && b->thread != thread->global_num) |
5133 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5134 | { |
5135 | bs->stop = 0; | |
5136 | return; | |
5137 | } | |
5138 | ||
6dddc817 DE |
5139 | /* Evaluate extension language breakpoints that have a "stop" method |
5140 | implemented. */ | |
5141 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5142 | |
7d4df6a4 DE |
5143 | if (is_watchpoint (b)) |
5144 | { | |
5145 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5146 | |
4d01a485 | 5147 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5148 | } |
5149 | else | |
4d01a485 | 5150 | cond = bl->cond.get (); |
60e1c644 | 5151 | |
7d4df6a4 DE |
5152 | if (cond && b->disposition != disp_del_at_next_stop) |
5153 | { | |
5154 | int within_current_scope = 1; | |
5155 | struct watchpoint * w; | |
60e1c644 | 5156 | |
7d4df6a4 DE |
5157 | /* We use value_mark and value_free_to_mark because it could |
5158 | be a long time before we return to the command level and | |
5159 | call free_all_values. We can't call free_all_values | |
5160 | because we might be in the middle of evaluating a | |
5161 | function call. */ | |
5162 | struct value *mark = value_mark (); | |
5163 | ||
5164 | if (is_watchpoint (b)) | |
5165 | w = (struct watchpoint *) b; | |
5166 | else | |
5167 | w = NULL; | |
5168 | ||
5169 | /* Need to select the frame, with all that implies so that | |
5170 | the conditions will have the right context. Because we | |
5171 | use the frame, we will not see an inlined function's | |
5172 | variables when we arrive at a breakpoint at the start | |
5173 | of the inlined function; the current frame will be the | |
5174 | call site. */ | |
5175 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5176 | select_frame (get_current_frame ()); | |
5177 | else | |
18a18393 | 5178 | { |
7d4df6a4 DE |
5179 | struct frame_info *frame; |
5180 | ||
5181 | /* For local watchpoint expressions, which particular | |
5182 | instance of a local is being watched matters, so we | |
5183 | keep track of the frame to evaluate the expression | |
5184 | in. To evaluate the condition however, it doesn't | |
5185 | really matter which instantiation of the function | |
5186 | where the condition makes sense triggers the | |
5187 | watchpoint. This allows an expression like "watch | |
5188 | global if q > 10" set in `func', catch writes to | |
5189 | global on all threads that call `func', or catch | |
5190 | writes on all recursive calls of `func' by a single | |
5191 | thread. We simply always evaluate the condition in | |
5192 | the innermost frame that's executing where it makes | |
5193 | sense to evaluate the condition. It seems | |
5194 | intuitive. */ | |
5195 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5196 | if (frame != NULL) | |
5197 | select_frame (frame); | |
5198 | else | |
5199 | within_current_scope = 0; | |
18a18393 | 5200 | } |
7d4df6a4 | 5201 | if (within_current_scope) |
bf469271 | 5202 | { |
a70b8144 | 5203 | try |
bf469271 PA |
5204 | { |
5205 | condition_result = breakpoint_cond_eval (cond); | |
5206 | } | |
230d2906 | 5207 | catch (const gdb_exception &ex) |
bf469271 PA |
5208 | { |
5209 | exception_fprintf (gdb_stderr, ex, | |
5210 | "Error in testing breakpoint condition:\n"); | |
5211 | } | |
bf469271 | 5212 | } |
7d4df6a4 | 5213 | else |
18a18393 | 5214 | { |
7d4df6a4 DE |
5215 | warning (_("Watchpoint condition cannot be tested " |
5216 | "in the current scope")); | |
5217 | /* If we failed to set the right context for this | |
5218 | watchpoint, unconditionally report it. */ | |
18a18393 | 5219 | } |
7d4df6a4 DE |
5220 | /* FIXME-someday, should give breakpoint #. */ |
5221 | value_free_to_mark (mark); | |
18a18393 | 5222 | } |
7d4df6a4 | 5223 | |
bf469271 | 5224 | if (cond && !condition_result) |
7d4df6a4 DE |
5225 | { |
5226 | bs->stop = 0; | |
5227 | } | |
7d4df6a4 DE |
5228 | else if (b->ignore_count > 0) |
5229 | { | |
5230 | b->ignore_count--; | |
5231 | bs->stop = 0; | |
5232 | /* Increase the hit count even though we don't stop. */ | |
5233 | ++(b->hit_count); | |
76727919 | 5234 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5235 | } |
18a18393 VP |
5236 | } |
5237 | ||
1cf4d951 PA |
5238 | /* Returns true if we need to track moribund locations of LOC's type |
5239 | on the current target. */ | |
5240 | ||
5241 | static int | |
5242 | need_moribund_for_location_type (struct bp_location *loc) | |
5243 | { | |
5244 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5245 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5246 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5247 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5248 | } | |
5249 | ||
ddfe970e | 5250 | /* See breakpoint.h. */ |
c906108c SS |
5251 | |
5252 | bpstat | |
ddfe970e | 5253 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5254 | const struct target_waitstatus *ws) |
c906108c | 5255 | { |
ddfe970e | 5256 | struct breakpoint *b; |
5760d0ab | 5257 | bpstat bs_head = NULL, *bs_link = &bs_head; |
c5aa993b | 5258 | |
429374b8 JK |
5259 | ALL_BREAKPOINTS (b) |
5260 | { | |
1a853c52 | 5261 | if (!breakpoint_enabled (b)) |
429374b8 | 5262 | continue; |
a5606eee | 5263 | |
ddfe970e | 5264 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
429374b8 | 5265 | { |
4a64f543 MS |
5266 | /* For hardware watchpoints, we look only at the first |
5267 | location. The watchpoint_check function will work on the | |
5268 | entire expression, not the individual locations. For | |
5269 | read watchpoints, the watchpoints_triggered function has | |
5270 | checked all locations already. */ | |
429374b8 JK |
5271 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5272 | break; | |
18a18393 | 5273 | |
f6592439 | 5274 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5275 | continue; |
c5aa993b | 5276 | |
09ac7c10 | 5277 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5278 | continue; |
c5aa993b | 5279 | |
4a64f543 MS |
5280 | /* Come here if it's a watchpoint, or if the break address |
5281 | matches. */ | |
c5aa993b | 5282 | |
ddfe970e KS |
5283 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
5284 | explain stop. */ | |
c5aa993b | 5285 | |
f431efe5 PA |
5286 | /* Assume we stop. Should we find a watchpoint that is not |
5287 | actually triggered, or if the condition of the breakpoint | |
5288 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5289 | bs->stop = 1; |
5290 | bs->print = 1; | |
d983da9c | 5291 | |
f431efe5 PA |
5292 | /* If this is a scope breakpoint, mark the associated |
5293 | watchpoint as triggered so that we will handle the | |
5294 | out-of-scope event. We'll get to the watchpoint next | |
5295 | iteration. */ | |
d0fb5eae | 5296 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5297 | { |
5298 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5299 | ||
5300 | w->watchpoint_triggered = watch_triggered_yes; | |
5301 | } | |
f431efe5 PA |
5302 | } |
5303 | } | |
5304 | ||
7c16b83e | 5305 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5306 | if (!target_supports_stopped_by_sw_breakpoint () |
5307 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5308 | { |
1123588c | 5309 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5310 | { |
1cf4d951 PA |
5311 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5312 | && need_moribund_for_location_type (loc)) | |
5313 | { | |
ddfe970e | 5314 | bpstat bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5315 | /* For hits of moribund locations, we should just proceed. */ |
5316 | bs->stop = 0; | |
5317 | bs->print = 0; | |
5318 | bs->print_it = print_it_noop; | |
5319 | } | |
f431efe5 PA |
5320 | } |
5321 | } | |
5322 | ||
ddfe970e KS |
5323 | return bs_head; |
5324 | } | |
5325 | ||
5326 | /* See breakpoint.h. */ | |
5327 | ||
5328 | bpstat | |
5329 | bpstat_stop_status (const address_space *aspace, | |
00431a78 | 5330 | CORE_ADDR bp_addr, thread_info *thread, |
ddfe970e KS |
5331 | const struct target_waitstatus *ws, |
5332 | bpstat stop_chain) | |
5333 | { | |
5334 | struct breakpoint *b = NULL; | |
5335 | /* First item of allocated bpstat's. */ | |
5336 | bpstat bs_head = stop_chain; | |
5337 | bpstat bs; | |
5338 | int need_remove_insert; | |
5339 | int removed_any; | |
5340 | ||
5341 | /* First, build the bpstat chain with locations that explain a | |
5342 | target stop, while being careful to not set the target running, | |
5343 | as that may invalidate locations (in particular watchpoint | |
5344 | locations are recreated). Resuming will happen here with | |
5345 | breakpoint conditions or watchpoint expressions that include | |
5346 | inferior function calls. */ | |
5347 | if (bs_head == NULL) | |
5348 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5349 | ||
edcc5120 TT |
5350 | /* A bit of special processing for shlib breakpoints. We need to |
5351 | process solib loading here, so that the lists of loaded and | |
5352 | unloaded libraries are correct before we handle "catch load" and | |
5353 | "catch unload". */ | |
5354 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5355 | { | |
5d268276 | 5356 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5357 | { |
5358 | handle_solib_event (); | |
5359 | break; | |
5360 | } | |
5361 | } | |
5362 | ||
f431efe5 PA |
5363 | /* Now go through the locations that caused the target to stop, and |
5364 | check whether we're interested in reporting this stop to higher | |
5365 | layers, or whether we should resume the target transparently. */ | |
5366 | ||
5367 | removed_any = 0; | |
5368 | ||
5760d0ab | 5369 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5370 | { |
5371 | if (!bs->stop) | |
5372 | continue; | |
5373 | ||
f431efe5 | 5374 | b = bs->breakpoint_at; |
348d480f PA |
5375 | b->ops->check_status (bs); |
5376 | if (bs->stop) | |
28010a5d | 5377 | { |
00431a78 | 5378 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5379 | |
429374b8 JK |
5380 | if (bs->stop) |
5381 | { | |
5382 | ++(b->hit_count); | |
76727919 | 5383 | gdb::observers::breakpoint_modified.notify (b); |
c906108c | 5384 | |
4a64f543 | 5385 | /* We will stop here. */ |
429374b8 JK |
5386 | if (b->disposition == disp_disable) |
5387 | { | |
816338b5 | 5388 | --(b->enable_count); |
1a853c52 | 5389 | if (b->enable_count <= 0) |
429374b8 | 5390 | b->enable_state = bp_disabled; |
f431efe5 | 5391 | removed_any = 1; |
429374b8 JK |
5392 | } |
5393 | if (b->silent) | |
5394 | bs->print = 0; | |
5395 | bs->commands = b->commands; | |
abf85f46 | 5396 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5397 | ? bs->commands.get () : NULL)) |
abf85f46 | 5398 | bs->print = 0; |
9d6e6e84 HZ |
5399 | |
5400 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5401 | } |
5402 | ||
348d480f | 5403 | } |
a9b3a50f PA |
5404 | |
5405 | /* Print nothing for this entry if we don't stop or don't | |
5406 | print. */ | |
5407 | if (!bs->stop || !bs->print) | |
5408 | bs->print_it = print_it_noop; | |
429374b8 | 5409 | } |
876fa593 | 5410 | |
d983da9c DJ |
5411 | /* If we aren't stopping, the value of some hardware watchpoint may |
5412 | not have changed, but the intermediate memory locations we are | |
5413 | watching may have. Don't bother if we're stopping; this will get | |
5414 | done later. */ | |
d832cb68 | 5415 | need_remove_insert = 0; |
5760d0ab JK |
5416 | if (! bpstat_causes_stop (bs_head)) |
5417 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5418 | if (!bs->stop |
f431efe5 PA |
5419 | && bs->breakpoint_at |
5420 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5421 | { |
3a5c3e22 PA |
5422 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5423 | ||
5424 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5425 | need_remove_insert = 1; |
d983da9c DJ |
5426 | } |
5427 | ||
d832cb68 | 5428 | if (need_remove_insert) |
44702360 | 5429 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5430 | else if (removed_any) |
44702360 | 5431 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5432 | |
5760d0ab | 5433 | return bs_head; |
c906108c | 5434 | } |
628fe4e4 JK |
5435 | |
5436 | static void | |
5437 | handle_jit_event (void) | |
5438 | { | |
5439 | struct frame_info *frame; | |
5440 | struct gdbarch *gdbarch; | |
5441 | ||
243a9253 PA |
5442 | if (debug_infrun) |
5443 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5444 | ||
628fe4e4 JK |
5445 | /* Switch terminal for any messages produced by |
5446 | breakpoint_re_set. */ | |
223ffa71 | 5447 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5448 | |
5449 | frame = get_current_frame (); | |
5450 | gdbarch = get_frame_arch (frame); | |
fe053b9e | 5451 | objfile *jiter = symbol_objfile (get_frame_function (frame)); |
628fe4e4 | 5452 | |
fe053b9e | 5453 | jit_event_handler (gdbarch, jiter); |
628fe4e4 | 5454 | |
223ffa71 | 5455 | target_terminal::inferior (); |
628fe4e4 JK |
5456 | } |
5457 | ||
5458 | /* Prepare WHAT final decision for infrun. */ | |
5459 | ||
5460 | /* Decide what infrun needs to do with this bpstat. */ | |
5461 | ||
c906108c | 5462 | struct bpstat_what |
0e30163f | 5463 | bpstat_what (bpstat bs_head) |
c906108c | 5464 | { |
c906108c | 5465 | struct bpstat_what retval; |
0e30163f | 5466 | bpstat bs; |
c906108c | 5467 | |
628fe4e4 | 5468 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5469 | retval.call_dummy = STOP_NONE; |
e2d0f980 | 5470 | retval.is_longjmp = false; |
628fe4e4 | 5471 | |
0e30163f | 5472 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5473 | { |
628fe4e4 JK |
5474 | /* Extract this BS's action. After processing each BS, we check |
5475 | if its action overrides all we've seem so far. */ | |
5476 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5477 | enum bptype bptype; | |
5478 | ||
c906108c | 5479 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5480 | { |
5481 | /* I suspect this can happen if it was a momentary | |
5482 | breakpoint which has since been deleted. */ | |
5483 | bptype = bp_none; | |
5484 | } | |
20874c92 | 5485 | else |
f431efe5 | 5486 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5487 | |
5488 | switch (bptype) | |
c906108c SS |
5489 | { |
5490 | case bp_none: | |
628fe4e4 | 5491 | break; |
c906108c SS |
5492 | case bp_breakpoint: |
5493 | case bp_hardware_breakpoint: | |
7c16b83e | 5494 | case bp_single_step: |
c906108c SS |
5495 | case bp_until: |
5496 | case bp_finish: | |
a9b3a50f | 5497 | case bp_shlib_event: |
c906108c SS |
5498 | if (bs->stop) |
5499 | { | |
5500 | if (bs->print) | |
628fe4e4 | 5501 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5502 | else |
628fe4e4 | 5503 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5504 | } |
5505 | else | |
628fe4e4 | 5506 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5507 | break; |
5508 | case bp_watchpoint: | |
5509 | case bp_hardware_watchpoint: | |
5510 | case bp_read_watchpoint: | |
5511 | case bp_access_watchpoint: | |
5512 | if (bs->stop) | |
5513 | { | |
5514 | if (bs->print) | |
628fe4e4 | 5515 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5516 | else |
628fe4e4 | 5517 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5518 | } |
5519 | else | |
628fe4e4 JK |
5520 | { |
5521 | /* There was a watchpoint, but we're not stopping. | |
5522 | This requires no further action. */ | |
5523 | } | |
c906108c SS |
5524 | break; |
5525 | case bp_longjmp: | |
e2e4d78b | 5526 | case bp_longjmp_call_dummy: |
186c406b | 5527 | case bp_exception: |
0a39bb32 PA |
5528 | if (bs->stop) |
5529 | { | |
5530 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5531 | retval.is_longjmp = bptype != bp_exception; | |
5532 | } | |
5533 | else | |
5534 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5535 | break; |
5536 | case bp_longjmp_resume: | |
186c406b | 5537 | case bp_exception_resume: |
0a39bb32 PA |
5538 | if (bs->stop) |
5539 | { | |
5540 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5541 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5542 | } | |
5543 | else | |
5544 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5545 | break; |
5546 | case bp_step_resume: | |
5547 | if (bs->stop) | |
628fe4e4 JK |
5548 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5549 | else | |
c906108c | 5550 | { |
628fe4e4 JK |
5551 | /* It is for the wrong frame. */ |
5552 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5553 | } |
c906108c | 5554 | break; |
2c03e5be PA |
5555 | case bp_hp_step_resume: |
5556 | if (bs->stop) | |
5557 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5558 | else | |
5559 | { | |
5560 | /* It is for the wrong frame. */ | |
5561 | this_action = BPSTAT_WHAT_SINGLE; | |
5562 | } | |
5563 | break; | |
c906108c | 5564 | case bp_watchpoint_scope: |
c4093a6a | 5565 | case bp_thread_event: |
1900040c | 5566 | case bp_overlay_event: |
0fd8e87f | 5567 | case bp_longjmp_master: |
aa7d318d | 5568 | case bp_std_terminate_master: |
186c406b | 5569 | case bp_exception_master: |
628fe4e4 | 5570 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5571 | break; |
ce78b96d | 5572 | case bp_catchpoint: |
c5aa993b JM |
5573 | if (bs->stop) |
5574 | { | |
5575 | if (bs->print) | |
628fe4e4 | 5576 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5577 | else |
628fe4e4 | 5578 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5579 | } |
5580 | else | |
628fe4e4 | 5581 | { |
cb1e4e32 PA |
5582 | /* Some catchpoints are implemented with breakpoints. |
5583 | For those, we need to step over the breakpoint. */ | |
5584 | if (bs->bp_location_at->loc_type != bp_loc_other) | |
5585 | this_action = BPSTAT_WHAT_SINGLE; | |
628fe4e4 JK |
5586 | } |
5587 | break; | |
628fe4e4 | 5588 | case bp_jit_event: |
628fe4e4 | 5589 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5590 | break; |
c906108c | 5591 | case bp_call_dummy: |
53a5351d JM |
5592 | /* Make sure the action is stop (silent or noisy), |
5593 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5594 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5595 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5596 | break; |
5597 | case bp_std_terminate: | |
5598 | /* Make sure the action is stop (silent or noisy), | |
5599 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5600 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5601 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5602 | break; |
1042e4c0 | 5603 | case bp_tracepoint: |
7a697b8d | 5604 | case bp_fast_tracepoint: |
0fb4aa4b | 5605 | case bp_static_tracepoint: |
1042e4c0 SS |
5606 | /* Tracepoint hits should not be reported back to GDB, and |
5607 | if one got through somehow, it should have been filtered | |
5608 | out already. */ | |
5609 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5610 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5611 | break; |
5612 | case bp_gnu_ifunc_resolver: | |
5613 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5614 | this_action = BPSTAT_WHAT_SINGLE; | |
5615 | break; | |
5616 | case bp_gnu_ifunc_resolver_return: | |
5617 | /* The breakpoint will be removed, execution will restart from the | |
5618 | PC of the former breakpoint. */ | |
5619 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5620 | break; | |
e7e0cddf SS |
5621 | |
5622 | case bp_dprintf: | |
a11cfd87 HZ |
5623 | if (bs->stop) |
5624 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5625 | else | |
5626 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5627 | break; |
5628 | ||
628fe4e4 JK |
5629 | default: |
5630 | internal_error (__FILE__, __LINE__, | |
5631 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5632 | } |
628fe4e4 | 5633 | |
325fac50 | 5634 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5635 | } |
628fe4e4 | 5636 | |
243a9253 PA |
5637 | return retval; |
5638 | } | |
628fe4e4 | 5639 | |
243a9253 PA |
5640 | void |
5641 | bpstat_run_callbacks (bpstat bs_head) | |
5642 | { | |
5643 | bpstat bs; | |
628fe4e4 | 5644 | |
0e30163f JK |
5645 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5646 | { | |
5647 | struct breakpoint *b = bs->breakpoint_at; | |
5648 | ||
5649 | if (b == NULL) | |
5650 | continue; | |
5651 | switch (b->type) | |
5652 | { | |
243a9253 PA |
5653 | case bp_jit_event: |
5654 | handle_jit_event (); | |
5655 | break; | |
0e30163f JK |
5656 | case bp_gnu_ifunc_resolver: |
5657 | gnu_ifunc_resolver_stop (b); | |
5658 | break; | |
5659 | case bp_gnu_ifunc_resolver_return: | |
5660 | gnu_ifunc_resolver_return_stop (b); | |
5661 | break; | |
5662 | } | |
5663 | } | |
c906108c SS |
5664 | } |
5665 | ||
4c462cb0 | 5666 | /* See breakpoint.h. */ |
c906108c | 5667 | |
4c462cb0 SM |
5668 | bool |
5669 | bpstat_should_step () | |
c906108c SS |
5670 | { |
5671 | struct breakpoint *b; | |
cc59ec59 | 5672 | |
c906108c | 5673 | ALL_BREAKPOINTS (b) |
717a8278 | 5674 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
4c462cb0 SM |
5675 | return true; |
5676 | return false; | |
c906108c SS |
5677 | } |
5678 | ||
4c462cb0 SM |
5679 | /* See breakpoint.h. */ |
5680 | ||
5681 | bool | |
67822962 PA |
5682 | bpstat_causes_stop (bpstat bs) |
5683 | { | |
5684 | for (; bs != NULL; bs = bs->next) | |
5685 | if (bs->stop) | |
4c462cb0 | 5686 | return true; |
67822962 | 5687 | |
4c462cb0 | 5688 | return false; |
67822962 PA |
5689 | } |
5690 | ||
c906108c | 5691 | \f |
c5aa993b | 5692 | |
170b53b2 UW |
5693 | /* Compute a string of spaces suitable to indent the next line |
5694 | so it starts at the position corresponding to the table column | |
5695 | named COL_NAME in the currently active table of UIOUT. */ | |
5696 | ||
5697 | static char * | |
5698 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5699 | { | |
5700 | static char wrap_indent[80]; | |
5701 | int i, total_width, width, align; | |
c5209615 | 5702 | const char *text; |
170b53b2 UW |
5703 | |
5704 | total_width = 0; | |
112e8700 | 5705 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5706 | { |
5707 | if (strcmp (text, col_name) == 0) | |
5708 | { | |
5709 | gdb_assert (total_width < sizeof wrap_indent); | |
5710 | memset (wrap_indent, ' ', total_width); | |
5711 | wrap_indent[total_width] = 0; | |
5712 | ||
5713 | return wrap_indent; | |
5714 | } | |
5715 | ||
5716 | total_width += width + 1; | |
5717 | } | |
5718 | ||
5719 | return NULL; | |
5720 | } | |
5721 | ||
b775012e LM |
5722 | /* Determine if the locations of this breakpoint will have their conditions |
5723 | evaluated by the target, host or a mix of both. Returns the following: | |
5724 | ||
5725 | "host": Host evals condition. | |
5726 | "host or target": Host or Target evals condition. | |
5727 | "target": Target evals condition. | |
5728 | */ | |
5729 | ||
5730 | static const char * | |
5731 | bp_condition_evaluator (struct breakpoint *b) | |
5732 | { | |
5733 | struct bp_location *bl; | |
5734 | char host_evals = 0; | |
5735 | char target_evals = 0; | |
5736 | ||
5737 | if (!b) | |
5738 | return NULL; | |
5739 | ||
5740 | if (!is_breakpoint (b)) | |
5741 | return NULL; | |
5742 | ||
5743 | if (gdb_evaluates_breakpoint_condition_p () | |
5744 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5745 | return condition_evaluation_host; | |
5746 | ||
5747 | for (bl = b->loc; bl; bl = bl->next) | |
5748 | { | |
5749 | if (bl->cond_bytecode) | |
5750 | target_evals++; | |
5751 | else | |
5752 | host_evals++; | |
5753 | } | |
5754 | ||
5755 | if (host_evals && target_evals) | |
5756 | return condition_evaluation_both; | |
5757 | else if (target_evals) | |
5758 | return condition_evaluation_target; | |
5759 | else | |
5760 | return condition_evaluation_host; | |
5761 | } | |
5762 | ||
5763 | /* Determine the breakpoint location's condition evaluator. This is | |
5764 | similar to bp_condition_evaluator, but for locations. */ | |
5765 | ||
5766 | static const char * | |
5767 | bp_location_condition_evaluator (struct bp_location *bl) | |
5768 | { | |
5769 | if (bl && !is_breakpoint (bl->owner)) | |
5770 | return NULL; | |
5771 | ||
5772 | if (gdb_evaluates_breakpoint_condition_p () | |
5773 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5774 | return condition_evaluation_host; | |
5775 | ||
5776 | if (bl && bl->cond_bytecode) | |
5777 | return condition_evaluation_target; | |
5778 | else | |
5779 | return condition_evaluation_host; | |
5780 | } | |
5781 | ||
859825b8 JK |
5782 | /* Print the LOC location out of the list of B->LOC locations. */ |
5783 | ||
170b53b2 UW |
5784 | static void |
5785 | print_breakpoint_location (struct breakpoint *b, | |
5786 | struct bp_location *loc) | |
0d381245 | 5787 | { |
79a45e25 | 5788 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5789 | |
5790 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5791 | |
859825b8 JK |
5792 | if (loc != NULL && loc->shlib_disabled) |
5793 | loc = NULL; | |
5794 | ||
6c95b8df PA |
5795 | if (loc != NULL) |
5796 | set_current_program_space (loc->pspace); | |
5797 | ||
56435ebe | 5798 | if (b->display_canonical) |
d28cd78a | 5799 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5800 | else if (loc && loc->symtab) |
0d381245 | 5801 | { |
4a27f119 KS |
5802 | const struct symbol *sym = loc->symbol; |
5803 | ||
0d381245 VP |
5804 | if (sym) |
5805 | { | |
112e8700 | 5806 | uiout->text ("in "); |
987012b8 | 5807 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 5808 | function_name_style.style ()); |
112e8700 SM |
5809 | uiout->text (" "); |
5810 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5811 | uiout->text ("at "); | |
0d381245 | 5812 | } |
112e8700 | 5813 | uiout->field_string ("file", |
cbe56571 | 5814 | symtab_to_filename_for_display (loc->symtab), |
e43b10e1 | 5815 | file_name_style.style ()); |
112e8700 | 5816 | uiout->text (":"); |
05cba821 | 5817 | |
112e8700 SM |
5818 | if (uiout->is_mi_like_p ()) |
5819 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 5820 | |
381befee | 5821 | uiout->field_signed ("line", loc->line_number); |
0d381245 | 5822 | } |
859825b8 | 5823 | else if (loc) |
0d381245 | 5824 | { |
d7e74731 | 5825 | string_file stb; |
170b53b2 | 5826 | |
d7e74731 | 5827 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 5828 | demangle, ""); |
112e8700 | 5829 | uiout->field_stream ("at", stb); |
0d381245 | 5830 | } |
859825b8 | 5831 | else |
f00aae0f | 5832 | { |
d28cd78a TT |
5833 | uiout->field_string ("pending", |
5834 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
5835 | /* If extra_string is available, it could be holding a condition |
5836 | or dprintf arguments. In either case, make sure it is printed, | |
5837 | too, but only for non-MI streams. */ | |
112e8700 | 5838 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
5839 | { |
5840 | if (b->type == bp_dprintf) | |
112e8700 | 5841 | uiout->text (","); |
f00aae0f | 5842 | else |
112e8700 SM |
5843 | uiout->text (" "); |
5844 | uiout->text (b->extra_string); | |
f00aae0f KS |
5845 | } |
5846 | } | |
6c95b8df | 5847 | |
b775012e LM |
5848 | if (loc && is_breakpoint (b) |
5849 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5850 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5851 | { | |
112e8700 SM |
5852 | uiout->text (" ("); |
5853 | uiout->field_string ("evaluated-by", | |
b775012e | 5854 | bp_location_condition_evaluator (loc)); |
112e8700 | 5855 | uiout->text (")"); |
b775012e | 5856 | } |
0d381245 VP |
5857 | } |
5858 | ||
269b11a2 PA |
5859 | static const char * |
5860 | bptype_string (enum bptype type) | |
c906108c | 5861 | { |
c4093a6a JM |
5862 | struct ep_type_description |
5863 | { | |
5864 | enum bptype type; | |
a121b7c1 | 5865 | const char *description; |
c4093a6a JM |
5866 | }; |
5867 | static struct ep_type_description bptypes[] = | |
c906108c | 5868 | { |
c5aa993b JM |
5869 | {bp_none, "?deleted?"}, |
5870 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5871 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 5872 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
5873 | {bp_until, "until"}, |
5874 | {bp_finish, "finish"}, | |
5875 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5876 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5877 | {bp_read_watchpoint, "read watchpoint"}, |
5878 | {bp_access_watchpoint, "acc watchpoint"}, | |
5879 | {bp_longjmp, "longjmp"}, | |
5880 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5881 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5882 | {bp_exception, "exception"}, |
5883 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5884 | {bp_step_resume, "step resume"}, |
2c03e5be | 5885 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5886 | {bp_watchpoint_scope, "watchpoint scope"}, |
5887 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5888 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5889 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5890 | {bp_thread_event, "thread events"}, |
1900040c | 5891 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5892 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5893 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5894 | {bp_exception_master, "exception master"}, |
ce78b96d | 5895 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5896 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5897 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5898 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5899 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5900 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5901 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5902 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5903 | }; |
269b11a2 PA |
5904 | |
5905 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5906 | || ((int) type != bptypes[(int) type].type)) | |
5907 | internal_error (__FILE__, __LINE__, | |
5908 | _("bptypes table does not describe type #%d."), | |
5909 | (int) type); | |
5910 | ||
5911 | return bptypes[(int) type].description; | |
5912 | } | |
5913 | ||
998580f1 MK |
5914 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5915 | For CLI, prefix the list with the string 'inf'. */ | |
5916 | ||
5917 | static void | |
5918 | output_thread_groups (struct ui_out *uiout, | |
5919 | const char *field_name, | |
5c632425 | 5920 | const std::vector<int> &inf_nums, |
998580f1 MK |
5921 | int mi_only) |
5922 | { | |
112e8700 | 5923 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
5924 | |
5925 | /* For backward compatibility, don't display inferiors in CLI unless | |
5926 | there are several. Always display them for MI. */ | |
5927 | if (!is_mi && mi_only) | |
5928 | return; | |
5929 | ||
10f489e5 | 5930 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 5931 | |
5c632425 | 5932 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
5933 | { |
5934 | if (is_mi) | |
5935 | { | |
5936 | char mi_group[10]; | |
5937 | ||
5c632425 | 5938 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 5939 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
5940 | } |
5941 | else | |
5942 | { | |
5943 | if (i == 0) | |
112e8700 | 5944 | uiout->text (" inf "); |
998580f1 | 5945 | else |
112e8700 | 5946 | uiout->text (", "); |
998580f1 | 5947 | |
5c632425 | 5948 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
5949 | } |
5950 | } | |
998580f1 MK |
5951 | } |
5952 | ||
a38118e5 PA |
5953 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
5954 | instead of going via breakpoint_ops::print_one. This makes "maint | |
5955 | info breakpoints" show the software breakpoint locations of | |
5956 | catchpoints, which are considered internal implementation | |
5957 | detail. */ | |
269b11a2 PA |
5958 | |
5959 | static void | |
5960 | print_one_breakpoint_location (struct breakpoint *b, | |
5961 | struct bp_location *loc, | |
5962 | int loc_number, | |
5963 | struct bp_location **last_loc, | |
a38118e5 | 5964 | int allflag, bool raw_loc) |
269b11a2 PA |
5965 | { |
5966 | struct command_line *l; | |
c2c6d25f | 5967 | static char bpenables[] = "nynny"; |
c906108c | 5968 | |
79a45e25 | 5969 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5970 | int header_of_multiple = 0; |
5971 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5972 | struct value_print_options opts; |
5973 | ||
5974 | get_user_print_options (&opts); | |
0d381245 VP |
5975 | |
5976 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5977 | /* See comment in print_one_breakpoint concerning treatment of |
5978 | breakpoints with single disabled location. */ | |
0d381245 VP |
5979 | if (loc == NULL |
5980 | && (b->loc != NULL | |
5981 | && (b->loc->next != NULL || !b->loc->enabled))) | |
5982 | header_of_multiple = 1; | |
5983 | if (loc == NULL) | |
5984 | loc = b->loc; | |
5985 | ||
c4093a6a JM |
5986 | annotate_record (); |
5987 | ||
5988 | /* 1 */ | |
5989 | annotate_field (0); | |
0d381245 | 5990 | if (part_of_multiple) |
528e1572 | 5991 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
0d381245 | 5992 | else |
381befee | 5993 | uiout->field_signed ("number", b->number); |
c4093a6a JM |
5994 | |
5995 | /* 2 */ | |
5996 | annotate_field (1); | |
0d381245 | 5997 | if (part_of_multiple) |
112e8700 | 5998 | uiout->field_skip ("type"); |
269b11a2 | 5999 | else |
112e8700 | 6000 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6001 | |
6002 | /* 3 */ | |
6003 | annotate_field (2); | |
0d381245 | 6004 | if (part_of_multiple) |
112e8700 | 6005 | uiout->field_skip ("disp"); |
0d381245 | 6006 | else |
112e8700 | 6007 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6008 | |
c4093a6a JM |
6009 | /* 4 */ |
6010 | annotate_field (3); | |
0d381245 | 6011 | if (part_of_multiple) |
112e8700 | 6012 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6013 | else |
112e8700 | 6014 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
0d381245 | 6015 | |
c4093a6a | 6016 | /* 5 and 6 */ |
a38118e5 | 6017 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
b58a68fe | 6018 | b->ops->print_one (b, last_loc); |
3086aeae | 6019 | else |
a38118e5 PA |
6020 | { |
6021 | if (is_watchpoint (b)) | |
3a5c3e22 PA |
6022 | { |
6023 | struct watchpoint *w = (struct watchpoint *) b; | |
6024 | ||
6025 | /* Field 4, the address, is omitted (which makes the columns | |
6026 | not line up too nicely with the headers, but the effect | |
6027 | is relatively readable). */ | |
6028 | if (opts.addressprint) | |
112e8700 | 6029 | uiout->field_skip ("addr"); |
3a5c3e22 | 6030 | annotate_field (5); |
112e8700 | 6031 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6032 | } |
f06f1252 TT |
6033 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
6034 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6035 | { |
6036 | if (opts.addressprint) | |
6037 | { | |
6038 | annotate_field (4); | |
6039 | if (header_of_multiple) | |
7f6aba03 TT |
6040 | uiout->field_string ("addr", "<MULTIPLE>", |
6041 | metadata_style.style ()); | |
a38118e5 | 6042 | else if (b->loc == NULL || loc->shlib_disabled) |
7f6aba03 TT |
6043 | uiout->field_string ("addr", "<PENDING>", |
6044 | metadata_style.style ()); | |
a38118e5 PA |
6045 | else |
6046 | uiout->field_core_addr ("addr", | |
6047 | loc->gdbarch, loc->address); | |
6048 | } | |
6049 | annotate_field (5); | |
6050 | if (!header_of_multiple) | |
6051 | print_breakpoint_location (b, loc); | |
6052 | if (b->loc) | |
6053 | *last_loc = b->loc; | |
6054 | } | |
6055 | } | |
6c95b8df | 6056 | |
998580f1 | 6057 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6058 | { |
5c632425 | 6059 | std::vector<int> inf_nums; |
998580f1 | 6060 | int mi_only = 1; |
6c95b8df | 6061 | |
08036331 | 6062 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6063 | { |
6064 | if (inf->pspace == loc->pspace) | |
5c632425 | 6065 | inf_nums.push_back (inf->num); |
6c95b8df | 6066 | } |
998580f1 MK |
6067 | |
6068 | /* For backward compatibility, don't display inferiors in CLI unless | |
6069 | there are several. Always display for MI. */ | |
6070 | if (allflag | |
6071 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
94c93c35 | 6072 | && (program_spaces.size () > 1 |
998580f1 MK |
6073 | || number_of_inferiors () > 1) |
6074 | /* LOC is for existing B, it cannot be in | |
6075 | moribund_locations and thus having NULL OWNER. */ | |
6076 | && loc->owner->type != bp_catchpoint)) | |
6077 | mi_only = 0; | |
5c632425 | 6078 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6079 | } |
6080 | ||
4a306c9a | 6081 | if (!part_of_multiple) |
c4093a6a | 6082 | { |
4a306c9a JB |
6083 | if (b->thread != -1) |
6084 | { | |
6085 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6086 | "stop only in" line a little further down. */ |
112e8700 | 6087 | uiout->text (" thread "); |
381befee | 6088 | uiout->field_signed ("thread", b->thread); |
4a306c9a JB |
6089 | } |
6090 | else if (b->task != 0) | |
6091 | { | |
112e8700 | 6092 | uiout->text (" task "); |
381befee | 6093 | uiout->field_signed ("task", b->task); |
4a306c9a | 6094 | } |
c4093a6a | 6095 | } |
f1310107 | 6096 | |
112e8700 | 6097 | uiout->text ("\n"); |
f1310107 | 6098 | |
348d480f | 6099 | if (!part_of_multiple) |
f1310107 TJB |
6100 | b->ops->print_one_detail (b, uiout); |
6101 | ||
0d381245 | 6102 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6103 | { |
6104 | annotate_field (6); | |
112e8700 | 6105 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6106 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6107 | the frame ID. */ |
112e8700 | 6108 | uiout->field_core_addr ("frame", |
5af949e3 | 6109 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6110 | uiout->text ("\n"); |
c4093a6a JM |
6111 | } |
6112 | ||
28010a5d | 6113 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6114 | { |
6115 | annotate_field (7); | |
d77f58be | 6116 | if (is_tracepoint (b)) |
112e8700 | 6117 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6118 | else |
112e8700 SM |
6119 | uiout->text ("\tstop only if "); |
6120 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6121 | |
6122 | /* Print whether the target is doing the breakpoint's condition | |
6123 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6124 | if (is_breakpoint (b) | |
6125 | && breakpoint_condition_evaluation_mode () | |
6126 | == condition_evaluation_target) | |
6127 | { | |
6a831f06 PA |
6128 | uiout->message (" (%pF evals)", |
6129 | string_field ("evaluated-by", | |
6130 | bp_condition_evaluator (b))); | |
b775012e | 6131 | } |
112e8700 | 6132 | uiout->text ("\n"); |
0101ce28 JJ |
6133 | } |
6134 | ||
0d381245 | 6135 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6136 | { |
4a64f543 | 6137 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6138 | uiout->text ("\tstop only in thread "); |
6139 | if (uiout->is_mi_like_p ()) | |
381befee | 6140 | uiout->field_signed ("thread", b->thread); |
5d5658a1 PA |
6141 | else |
6142 | { | |
6143 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6144 | ||
112e8700 | 6145 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6146 | } |
112e8700 | 6147 | uiout->text ("\n"); |
c4093a6a JM |
6148 | } |
6149 | ||
556ec64d YQ |
6150 | if (!part_of_multiple) |
6151 | { | |
6152 | if (b->hit_count) | |
31f56a27 YQ |
6153 | { |
6154 | /* FIXME should make an annotation for this. */ | |
6155 | if (is_catchpoint (b)) | |
112e8700 | 6156 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6157 | else if (is_tracepoint (b)) |
112e8700 | 6158 | uiout->text ("\ttracepoint"); |
31f56a27 | 6159 | else |
112e8700 SM |
6160 | uiout->text ("\tbreakpoint"); |
6161 | uiout->text (" already hit "); | |
381befee | 6162 | uiout->field_signed ("times", b->hit_count); |
31f56a27 | 6163 | if (b->hit_count == 1) |
112e8700 | 6164 | uiout->text (" time\n"); |
31f56a27 | 6165 | else |
112e8700 | 6166 | uiout->text (" times\n"); |
31f56a27 | 6167 | } |
556ec64d YQ |
6168 | else |
6169 | { | |
31f56a27 | 6170 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 | 6171 | if (uiout->is_mi_like_p ()) |
381befee | 6172 | uiout->field_signed ("times", b->hit_count); |
556ec64d YQ |
6173 | } |
6174 | } | |
8b93c638 | 6175 | |
0d381245 | 6176 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6177 | { |
6178 | annotate_field (8); | |
6a831f06 PA |
6179 | uiout->message ("\tignore next %pF hits\n", |
6180 | signed_field ("ignore", b->ignore_count)); | |
c4093a6a | 6181 | } |
059fb39f | 6182 | |
816338b5 SS |
6183 | /* Note that an enable count of 1 corresponds to "enable once" |
6184 | behavior, which is reported by the combination of enablement and | |
6185 | disposition, so we don't need to mention it here. */ | |
6186 | if (!part_of_multiple && b->enable_count > 1) | |
6187 | { | |
6188 | annotate_field (8); | |
112e8700 | 6189 | uiout->text ("\tdisable after "); |
816338b5 SS |
6190 | /* Tweak the wording to clarify that ignore and enable counts |
6191 | are distinct, and have additive effect. */ | |
6192 | if (b->ignore_count) | |
112e8700 | 6193 | uiout->text ("additional "); |
816338b5 | 6194 | else |
112e8700 | 6195 | uiout->text ("next "); |
381befee | 6196 | uiout->field_signed ("enable", b->enable_count); |
112e8700 | 6197 | uiout->text (" hits\n"); |
816338b5 SS |
6198 | } |
6199 | ||
f196051f SS |
6200 | if (!part_of_multiple && is_tracepoint (b)) |
6201 | { | |
6202 | struct tracepoint *tp = (struct tracepoint *) b; | |
6203 | ||
6204 | if (tp->traceframe_usage) | |
6205 | { | |
112e8700 | 6206 | uiout->text ("\ttrace buffer usage "); |
381befee | 6207 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
112e8700 | 6208 | uiout->text (" bytes\n"); |
f196051f SS |
6209 | } |
6210 | } | |
d3ce09f5 | 6211 | |
d1b0a7bf | 6212 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6213 | if (!part_of_multiple && l) |
c4093a6a JM |
6214 | { |
6215 | annotate_field (9); | |
2e783024 | 6216 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6217 | print_command_lines (uiout, l, 4); |
c4093a6a | 6218 | } |
d24317b4 | 6219 | |
d9b3f62e | 6220 | if (is_tracepoint (b)) |
1042e4c0 | 6221 | { |
d9b3f62e PA |
6222 | struct tracepoint *t = (struct tracepoint *) b; |
6223 | ||
6224 | if (!part_of_multiple && t->pass_count) | |
6225 | { | |
6226 | annotate_field (10); | |
112e8700 | 6227 | uiout->text ("\tpass count "); |
381befee | 6228 | uiout->field_signed ("pass", t->pass_count); |
112e8700 | 6229 | uiout->text (" \n"); |
d9b3f62e | 6230 | } |
f2a8bc8a YQ |
6231 | |
6232 | /* Don't display it when tracepoint or tracepoint location is | |
6233 | pending. */ | |
6234 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6235 | { | |
6236 | annotate_field (11); | |
6237 | ||
112e8700 SM |
6238 | if (uiout->is_mi_like_p ()) |
6239 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6240 | loc->inserted ? "y" : "n"); |
6241 | else | |
6242 | { | |
6243 | if (loc->inserted) | |
112e8700 | 6244 | uiout->text ("\t"); |
f2a8bc8a | 6245 | else |
112e8700 SM |
6246 | uiout->text ("\tnot "); |
6247 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6248 | } |
6249 | } | |
1042e4c0 SS |
6250 | } |
6251 | ||
112e8700 | 6252 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6253 | { |
3a5c3e22 PA |
6254 | if (is_watchpoint (b)) |
6255 | { | |
6256 | struct watchpoint *w = (struct watchpoint *) b; | |
6257 | ||
112e8700 | 6258 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6259 | } |
f00aae0f | 6260 | else if (b->location != NULL |
d28cd78a | 6261 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6262 | uiout->field_string ("original-location", |
d28cd78a | 6263 | event_location_to_string (b->location.get ())); |
d24317b4 | 6264 | } |
c4093a6a | 6265 | } |
c5aa993b | 6266 | |
13674803 SM |
6267 | /* See breakpoint.h. */ |
6268 | ||
6269 | bool fix_multi_location_breakpoint_output_globally = false; | |
6270 | ||
0d381245 VP |
6271 | static void |
6272 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6273 | struct bp_location **last_loc, |
6c95b8df | 6274 | int allflag) |
0d381245 | 6275 | { |
79a45e25 | 6276 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6277 | bool use_fixed_output |
6278 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6279 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6280 | |
b4be1b06 | 6281 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
a38118e5 | 6282 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
8d3788bd | 6283 | |
b4be1b06 SM |
6284 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6285 | are outside. */ | |
6286 | if (!use_fixed_output) | |
6287 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6288 | |
6289 | /* If this breakpoint has custom print function, | |
6290 | it's already printed. Otherwise, print individual | |
6291 | locations, if any. */ | |
a38118e5 PA |
6292 | if (b->ops == NULL |
6293 | || b->ops->print_one == NULL | |
6294 | || allflag) | |
0d381245 | 6295 | { |
4a64f543 MS |
6296 | /* If breakpoint has a single location that is disabled, we |
6297 | print it as if it had several locations, since otherwise it's | |
6298 | hard to represent "breakpoint enabled, location disabled" | |
6299 | situation. | |
6300 | ||
6301 | Note that while hardware watchpoints have several locations | |
a38118e5 PA |
6302 | internally, that's not a property exposed to users. |
6303 | ||
6304 | Likewise, while catchpoints may be implemented with | |
6305 | breakpoints (e.g., catch throw), that's not a property | |
6306 | exposed to users. We do however display the internal | |
6307 | breakpoint locations with "maint info breakpoints". */ | |
6308 | if (!is_hardware_watchpoint (b) | |
f06f1252 TT |
6309 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
6310 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6311 | && (allflag |
6312 | || (b->loc && (b->loc->next || !b->loc->enabled)))) | |
0d381245 | 6313 | { |
b4be1b06 SM |
6314 | gdb::optional<ui_out_emit_list> locations_list; |
6315 | ||
6316 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6317 | MI record. For later versions, place breakpoint locations in a | |
6318 | list. */ | |
6319 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6320 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6321 | |
b4be1b06 SM |
6322 | int n = 1; |
6323 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) | |
8d3788bd | 6324 | { |
b4be1b06 | 6325 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
a38118e5 PA |
6326 | print_one_breakpoint_location (b, loc, n, last_loc, |
6327 | allflag, allflag); | |
8d3788bd | 6328 | } |
0d381245 VP |
6329 | } |
6330 | } | |
6331 | } | |
6332 | ||
a6d9a66e UW |
6333 | static int |
6334 | breakpoint_address_bits (struct breakpoint *b) | |
6335 | { | |
6336 | int print_address_bits = 0; | |
6337 | struct bp_location *loc; | |
6338 | ||
c6d81124 PA |
6339 | /* Software watchpoints that aren't watching memory don't have an |
6340 | address to print. */ | |
6341 | if (is_no_memory_software_watchpoint (b)) | |
6342 | return 0; | |
6343 | ||
a6d9a66e UW |
6344 | for (loc = b->loc; loc; loc = loc->next) |
6345 | { | |
c7437ca6 PA |
6346 | int addr_bit; |
6347 | ||
c7437ca6 | 6348 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6349 | if (addr_bit > print_address_bits) |
6350 | print_address_bits = addr_bit; | |
6351 | } | |
6352 | ||
6353 | return print_address_bits; | |
6354 | } | |
0d381245 | 6355 | |
65630365 | 6356 | /* See breakpoint.h. */ |
c5aa993b | 6357 | |
65630365 PA |
6358 | void |
6359 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6360 | { |
a6d9a66e | 6361 | struct bp_location *dummy_loc = NULL; |
65630365 | 6362 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6363 | } |
c5aa993b | 6364 | |
09d682a4 TT |
6365 | /* Return true if this breakpoint was set by the user, false if it is |
6366 | internal or momentary. */ | |
6367 | ||
6368 | int | |
6369 | user_breakpoint_p (struct breakpoint *b) | |
6370 | { | |
46c6471b | 6371 | return b->number > 0; |
09d682a4 TT |
6372 | } |
6373 | ||
93daf339 TT |
6374 | /* See breakpoint.h. */ |
6375 | ||
6376 | int | |
6377 | pending_breakpoint_p (struct breakpoint *b) | |
6378 | { | |
6379 | return b->loc == NULL; | |
6380 | } | |
6381 | ||
5c458ae8 SM |
6382 | /* Print information on breakpoints (including watchpoints and tracepoints). |
6383 | ||
6384 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as | |
6385 | understood by number_or_range_parser. Only breakpoints included in this | |
6386 | list are then printed. | |
6387 | ||
6388 | If SHOW_INTERNAL is true, print internal breakpoints. | |
6389 | ||
6390 | If FILTER is non-NULL, call it on each breakpoint and only include the | |
6391 | ones for which it returns true. | |
6392 | ||
6393 | Return the total number of breakpoints listed. */ | |
c906108c | 6394 | |
d77f58be | 6395 | static int |
5c458ae8 | 6396 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
f2478a7e | 6397 | bool (*filter) (const struct breakpoint *)) |
c4093a6a | 6398 | { |
52f0bd74 | 6399 | struct breakpoint *b; |
a6d9a66e | 6400 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6401 | int nr_printable_breakpoints; |
79a45b7d | 6402 | struct value_print_options opts; |
a6d9a66e | 6403 | int print_address_bits = 0; |
269b11a2 | 6404 | int print_type_col_width = 14; |
79a45e25 | 6405 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6406 | |
79a45b7d TT |
6407 | get_user_print_options (&opts); |
6408 | ||
4a64f543 MS |
6409 | /* Compute the number of rows in the table, as well as the size |
6410 | required for address fields. */ | |
7f3b0473 AC |
6411 | nr_printable_breakpoints = 0; |
6412 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6413 | { |
6414 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6415 | if (filter && !filter (b)) | |
6416 | continue; | |
6417 | ||
5c458ae8 | 6418 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
e5a67952 | 6419 | accept. Skip the others. */ |
5c458ae8 | 6420 | if (bp_num_list != NULL && *bp_num_list != '\0') |
e5a67952 | 6421 | { |
5c458ae8 | 6422 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
e5a67952 | 6423 | continue; |
5c458ae8 | 6424 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
e5a67952 MS |
6425 | continue; |
6426 | } | |
269b11a2 | 6427 | |
5c458ae8 | 6428 | if (show_internal || user_breakpoint_p (b)) |
e5a67952 MS |
6429 | { |
6430 | int addr_bit, type_len; | |
a6d9a66e | 6431 | |
e5a67952 MS |
6432 | addr_bit = breakpoint_address_bits (b); |
6433 | if (addr_bit > print_address_bits) | |
6434 | print_address_bits = addr_bit; | |
269b11a2 | 6435 | |
e5a67952 MS |
6436 | type_len = strlen (bptype_string (b->type)); |
6437 | if (type_len > print_type_col_width) | |
6438 | print_type_col_width = type_len; | |
6439 | ||
6440 | nr_printable_breakpoints++; | |
6441 | } | |
6442 | } | |
7f3b0473 | 6443 | |
4a2b031d TT |
6444 | { |
6445 | ui_out_emit_table table_emitter (uiout, | |
6446 | opts.addressprint ? 6 : 5, | |
6447 | nr_printable_breakpoints, | |
6448 | "BreakpointTable"); | |
6449 | ||
6450 | if (nr_printable_breakpoints > 0) | |
6451 | annotate_breakpoints_headers (); | |
6452 | if (nr_printable_breakpoints > 0) | |
6453 | annotate_field (0); | |
6454 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6455 | if (nr_printable_breakpoints > 0) | |
6456 | annotate_field (1); | |
6457 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6458 | if (nr_printable_breakpoints > 0) | |
6459 | annotate_field (2); | |
6460 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6461 | if (nr_printable_breakpoints > 0) | |
6462 | annotate_field (3); | |
6463 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6464 | if (opts.addressprint) | |
6465 | { | |
6466 | if (nr_printable_breakpoints > 0) | |
6467 | annotate_field (4); | |
6468 | if (print_address_bits <= 32) | |
6469 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6470 | else | |
6471 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6472 | } | |
6473 | if (nr_printable_breakpoints > 0) | |
6474 | annotate_field (5); | |
6475 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6476 | uiout->table_body (); | |
6477 | if (nr_printable_breakpoints > 0) | |
6478 | annotate_breakpoints_table (); | |
6479 | ||
6480 | ALL_BREAKPOINTS (b) | |
6481 | { | |
6482 | QUIT; | |
6483 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6484 | if (filter && !filter (b)) | |
6485 | continue; | |
e5a67952 | 6486 | |
5c458ae8 | 6487 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
4a2b031d | 6488 | accept. Skip the others. */ |
e5a67952 | 6489 | |
5c458ae8 | 6490 | if (bp_num_list != NULL && *bp_num_list != '\0') |
4a2b031d | 6491 | { |
5c458ae8 | 6492 | if (show_internal) /* maintenance info breakpoint */ |
4a2b031d | 6493 | { |
5c458ae8 | 6494 | if (parse_and_eval_long (bp_num_list) != b->number) |
4a2b031d TT |
6495 | continue; |
6496 | } | |
6497 | else /* all others */ | |
6498 | { | |
5c458ae8 | 6499 | if (!number_is_in_list (bp_num_list, b->number)) |
4a2b031d TT |
6500 | continue; |
6501 | } | |
6502 | } | |
6503 | /* We only print out user settable breakpoints unless the | |
5c458ae8 SM |
6504 | show_internal is set. */ |
6505 | if (show_internal || user_breakpoint_p (b)) | |
6506 | print_one_breakpoint (b, &last_loc, show_internal); | |
4a2b031d TT |
6507 | } |
6508 | } | |
698384cd | 6509 | |
7f3b0473 | 6510 | if (nr_printable_breakpoints == 0) |
c906108c | 6511 | { |
4a64f543 MS |
6512 | /* If there's a filter, let the caller decide how to report |
6513 | empty list. */ | |
d77f58be SS |
6514 | if (!filter) |
6515 | { | |
5c458ae8 | 6516 | if (bp_num_list == NULL || *bp_num_list == '\0') |
112e8700 | 6517 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6518 | else |
112e8700 | 6519 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
5c458ae8 | 6520 | bp_num_list); |
d77f58be | 6521 | } |
c906108c SS |
6522 | } |
6523 | else | |
c4093a6a | 6524 | { |
a6d9a66e UW |
6525 | if (last_loc && !server_command) |
6526 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6527 | } |
c906108c | 6528 | |
4a64f543 | 6529 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6530 | there have been breakpoints? */ |
c906108c | 6531 | annotate_breakpoints_table_end (); |
d77f58be SS |
6532 | |
6533 | return nr_printable_breakpoints; | |
c906108c SS |
6534 | } |
6535 | ||
ad443146 SS |
6536 | /* Display the value of default-collect in a way that is generally |
6537 | compatible with the breakpoint list. */ | |
6538 | ||
6539 | static void | |
6540 | default_collect_info (void) | |
6541 | { | |
79a45e25 PA |
6542 | struct ui_out *uiout = current_uiout; |
6543 | ||
ad443146 SS |
6544 | /* If it has no value (which is frequently the case), say nothing; a |
6545 | message like "No default-collect." gets in user's face when it's | |
6546 | not wanted. */ | |
6547 | if (!*default_collect) | |
6548 | return; | |
6549 | ||
6550 | /* The following phrase lines up nicely with per-tracepoint collect | |
6551 | actions. */ | |
112e8700 SM |
6552 | uiout->text ("default collect "); |
6553 | uiout->field_string ("default-collect", default_collect); | |
6554 | uiout->text (" \n"); | |
ad443146 SS |
6555 | } |
6556 | ||
c906108c | 6557 | static void |
0b39b52e | 6558 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6559 | { |
5c458ae8 | 6560 | breakpoint_1 (args, false, NULL); |
ad443146 SS |
6561 | |
6562 | default_collect_info (); | |
d77f58be SS |
6563 | } |
6564 | ||
6565 | static void | |
1d12d88f | 6566 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6567 | { |
5c458ae8 | 6568 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
79a45e25 | 6569 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6570 | |
6571 | if (num_printed == 0) | |
6572 | { | |
e5a67952 | 6573 | if (args == NULL || *args == '\0') |
112e8700 | 6574 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6575 | else |
112e8700 | 6576 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6577 | } |
c906108c SS |
6578 | } |
6579 | ||
7a292a7a | 6580 | static void |
4495129a | 6581 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6582 | { |
5c458ae8 | 6583 | breakpoint_1 (args, true, NULL); |
ad443146 SS |
6584 | |
6585 | default_collect_info (); | |
c906108c SS |
6586 | } |
6587 | ||
0d381245 | 6588 | static int |
714835d5 | 6589 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6590 | struct program_space *pspace, |
714835d5 | 6591 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6592 | { |
6593 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6594 | |
0d381245 VP |
6595 | for (; bl; bl = bl->next) |
6596 | { | |
6c95b8df PA |
6597 | if (bl->pspace == pspace |
6598 | && bl->address == pc | |
0d381245 VP |
6599 | && (!overlay_debugging || bl->section == section)) |
6600 | return 1; | |
6601 | } | |
6602 | return 0; | |
6603 | } | |
6604 | ||
672f9b60 | 6605 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6606 | concerns with logical breakpoints, so we match program spaces, not |
6607 | address spaces. */ | |
c906108c SS |
6608 | |
6609 | static void | |
6c95b8df PA |
6610 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6611 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6612 | struct obj_section *section, int thread) |
c906108c | 6613 | { |
52f0bd74 AC |
6614 | int others = 0; |
6615 | struct breakpoint *b; | |
c906108c SS |
6616 | |
6617 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6618 | others += (user_breakpoint_p (b) |
6619 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6620 | if (others > 0) |
6621 | { | |
a3f17187 AC |
6622 | if (others == 1) |
6623 | printf_filtered (_("Note: breakpoint ")); | |
6624 | else /* if (others == ???) */ | |
6625 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6626 | ALL_BREAKPOINTS (b) |
672f9b60 | 6627 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6628 | { |
6629 | others--; | |
6630 | printf_filtered ("%d", b->number); | |
6631 | if (b->thread == -1 && thread != -1) | |
6632 | printf_filtered (" (all threads)"); | |
6633 | else if (b->thread != -1) | |
6634 | printf_filtered (" (thread %d)", b->thread); | |
6635 | printf_filtered ("%s%s ", | |
059fb39f | 6636 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6637 | || b->enable_state == bp_call_disabled) |
0d381245 | 6638 | ? " (disabled)" |
0d381245 VP |
6639 | : ""), |
6640 | (others > 1) ? "," | |
6641 | : ((others == 1) ? " and" : "")); | |
6642 | } | |
6a831f06 PA |
6643 | current_uiout->message (_("also set at pc %ps.\n"), |
6644 | styled_string (address_style.style (), | |
6645 | paddress (gdbarch, pc))); | |
c906108c SS |
6646 | } |
6647 | } | |
6648 | \f | |
c906108c | 6649 | |
cb1e4e32 PA |
6650 | /* Return true iff it is meaningful to use the address member of LOC. |
6651 | For some breakpoint types, the locations' address members are | |
6652 | irrelevant and it makes no sense to attempt to compare them to | |
6653 | other addresses (or use them for any other purpose either). | |
2d134ed3 | 6654 | |
cb1e4e32 PA |
6655 | More specifically, software watchpoints and catchpoints that are |
6656 | not backed by breakpoints always have a zero valued location | |
6657 | address and we don't want to mark breakpoints of any of these types | |
6658 | to be a duplicate of an actual breakpoint location at address | |
6659 | zero. */ | |
e4f237da | 6660 | |
cb1e4e32 PA |
6661 | static bool |
6662 | bl_address_is_meaningful (bp_location *loc) | |
e4f237da | 6663 | { |
cb1e4e32 | 6664 | return loc->loc_type != bp_loc_other; |
2d134ed3 PA |
6665 | } |
6666 | ||
6667 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6668 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6669 | ||
6670 | static int | |
4a64f543 MS |
6671 | watchpoint_locations_match (struct bp_location *loc1, |
6672 | struct bp_location *loc2) | |
2d134ed3 | 6673 | { |
3a5c3e22 PA |
6674 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6675 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6676 | ||
6677 | /* Both of them must exist. */ | |
6678 | gdb_assert (w1 != NULL); | |
6679 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6680 | |
4a64f543 MS |
6681 | /* If the target can evaluate the condition expression in hardware, |
6682 | then we we need to insert both watchpoints even if they are at | |
6683 | the same place. Otherwise the watchpoint will only trigger when | |
6684 | the condition of whichever watchpoint was inserted evaluates to | |
6685 | true, not giving a chance for GDB to check the condition of the | |
6686 | other watchpoint. */ | |
3a5c3e22 | 6687 | if ((w1->cond_exp |
4a64f543 MS |
6688 | && target_can_accel_watchpoint_condition (loc1->address, |
6689 | loc1->length, | |
0cf6dd15 | 6690 | loc1->watchpoint_type, |
4d01a485 | 6691 | w1->cond_exp.get ())) |
3a5c3e22 | 6692 | || (w2->cond_exp |
4a64f543 MS |
6693 | && target_can_accel_watchpoint_condition (loc2->address, |
6694 | loc2->length, | |
0cf6dd15 | 6695 | loc2->watchpoint_type, |
4d01a485 | 6696 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6697 | return 0; |
6698 | ||
85d721b8 PA |
6699 | /* Note that this checks the owner's type, not the location's. In |
6700 | case the target does not support read watchpoints, but does | |
6701 | support access watchpoints, we'll have bp_read_watchpoint | |
6702 | watchpoints with hw_access locations. Those should be considered | |
6703 | duplicates of hw_read locations. The hw_read locations will | |
6704 | become hw_access locations later. */ | |
2d134ed3 PA |
6705 | return (loc1->owner->type == loc2->owner->type |
6706 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6707 | && loc1->address == loc2->address | |
6708 | && loc1->length == loc2->length); | |
e4f237da KB |
6709 | } |
6710 | ||
31e77af2 | 6711 | /* See breakpoint.h. */ |
6c95b8df | 6712 | |
31e77af2 | 6713 | int |
accd0bcd YQ |
6714 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6715 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6716 | { |
f5656ead | 6717 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6718 | || aspace1 == aspace2) |
6719 | && addr1 == addr2); | |
6720 | } | |
6721 | ||
f1310107 TJB |
6722 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6723 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6724 | matches ASPACE2. On targets that have global breakpoints, the address | |
6725 | space doesn't really matter. */ | |
6726 | ||
6727 | static int | |
accd0bcd YQ |
6728 | breakpoint_address_match_range (const address_space *aspace1, |
6729 | CORE_ADDR addr1, | |
6730 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6731 | CORE_ADDR addr2) |
6732 | { | |
f5656ead | 6733 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6734 | || aspace1 == aspace2) |
6735 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6736 | } | |
6737 | ||
6738 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6739 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6740 | matches the breakpoint's address space. On targets that have global | |
6741 | breakpoints, the address space doesn't really matter. */ | |
6742 | ||
6743 | static int | |
6744 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6745 | const address_space *aspace, |
f1310107 TJB |
6746 | CORE_ADDR addr) |
6747 | { | |
6748 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6749 | aspace, addr) | |
6750 | || (bl->length | |
6751 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6752 | bl->address, bl->length, | |
6753 | aspace, addr))); | |
6754 | } | |
6755 | ||
d35ae833 PA |
6756 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6757 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6758 | match happens only if ASPACE matches the breakpoint's address | |
6759 | space. On targets that have global breakpoints, the address space | |
6760 | doesn't really matter. */ | |
6761 | ||
6762 | static int | |
6763 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6764 | const address_space *aspace, |
d35ae833 PA |
6765 | CORE_ADDR addr, int len) |
6766 | { | |
6767 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6768 | || bl->pspace->aspace == aspace) | |
6769 | { | |
6770 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6771 | ||
6772 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6773 | return 1; | |
6774 | } | |
6775 | return 0; | |
6776 | } | |
6777 | ||
1e4d1764 YQ |
6778 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6779 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6780 | true, otherwise returns false. */ | |
6781 | ||
6782 | static int | |
6783 | tracepoint_locations_match (struct bp_location *loc1, | |
6784 | struct bp_location *loc2) | |
6785 | { | |
6786 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6787 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6788 | locations at the same address of different tracepoints are regarded as | |
6789 | different locations. */ | |
6790 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6791 | else | |
6792 | return 0; | |
6793 | } | |
6794 | ||
2d134ed3 | 6795 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
cb1e4e32 | 6796 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
7f32a4d5 PA |
6797 | the same location. If SW_HW_BPS_MATCH is true, then software |
6798 | breakpoint locations and hardware breakpoint locations match, | |
6799 | otherwise they don't. */ | |
2d134ed3 PA |
6800 | |
6801 | static int | |
7f32a4d5 PA |
6802 | breakpoint_locations_match (struct bp_location *loc1, |
6803 | struct bp_location *loc2, | |
6804 | bool sw_hw_bps_match) | |
2d134ed3 | 6805 | { |
2bdf28a0 JK |
6806 | int hw_point1, hw_point2; |
6807 | ||
6808 | /* Both of them must not be in moribund_locations. */ | |
6809 | gdb_assert (loc1->owner != NULL); | |
6810 | gdb_assert (loc2->owner != NULL); | |
6811 | ||
6812 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6813 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6814 | |
6815 | if (hw_point1 != hw_point2) | |
6816 | return 0; | |
6817 | else if (hw_point1) | |
6818 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6819 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6820 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6821 | else |
7f32a4d5 PA |
6822 | /* We compare bp_location.length in order to cover ranged |
6823 | breakpoints. Keep this in sync with | |
6824 | bp_location_is_less_than. */ | |
f1310107 TJB |
6825 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
6826 | loc2->pspace->aspace, loc2->address) | |
7f32a4d5 | 6827 | && (loc1->loc_type == loc2->loc_type || sw_hw_bps_match) |
f1310107 | 6828 | && loc1->length == loc2->length); |
2d134ed3 PA |
6829 | } |
6830 | ||
76897487 KB |
6831 | static void |
6832 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6833 | int bnum, int have_bnum) | |
6834 | { | |
f63fbe86 MS |
6835 | /* The longest string possibly returned by hex_string_custom |
6836 | is 50 chars. These must be at least that big for safety. */ | |
6837 | char astr1[64]; | |
6838 | char astr2[64]; | |
76897487 | 6839 | |
bb599908 PH |
6840 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6841 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6842 | if (have_bnum) |
8a3fe4f8 | 6843 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6844 | bnum, astr1, astr2); |
6845 | else | |
8a3fe4f8 | 6846 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6847 | } |
6848 | ||
4a64f543 MS |
6849 | /* Adjust a breakpoint's address to account for architectural |
6850 | constraints on breakpoint placement. Return the adjusted address. | |
6851 | Note: Very few targets require this kind of adjustment. For most | |
6852 | targets, this function is simply the identity function. */ | |
76897487 KB |
6853 | |
6854 | static CORE_ADDR | |
a6d9a66e UW |
6855 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6856 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6857 | { |
a0de8c21 YQ |
6858 | if (bptype == bp_watchpoint |
6859 | || bptype == bp_hardware_watchpoint | |
6860 | || bptype == bp_read_watchpoint | |
6861 | || bptype == bp_access_watchpoint | |
6862 | || bptype == bp_catchpoint) | |
88f7da05 KB |
6863 | { |
6864 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6865 | have their addresses modified. */ | |
6866 | return bpaddr; | |
6867 | } | |
7c16b83e PA |
6868 | else if (bptype == bp_single_step) |
6869 | { | |
6870 | /* Single-step breakpoints should not have their addresses | |
6871 | modified. If there's any architectural constrain that | |
6872 | applies to this address, then it should have already been | |
6873 | taken into account when the breakpoint was created in the | |
6874 | first place. If we didn't do this, stepping through e.g., | |
6875 | Thumb-2 IT blocks would break. */ | |
6876 | return bpaddr; | |
6877 | } | |
76897487 KB |
6878 | else |
6879 | { | |
a0de8c21 YQ |
6880 | CORE_ADDR adjusted_bpaddr = bpaddr; |
6881 | ||
6882 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
6883 | { | |
6884 | /* Some targets have architectural constraints on the placement | |
6885 | of breakpoint instructions. Obtain the adjusted address. */ | |
6886 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
6887 | } | |
76897487 | 6888 | |
a0de8c21 | 6889 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
6890 | |
6891 | /* An adjusted breakpoint address can significantly alter | |
6892 | a user's expectations. Print a warning if an adjustment | |
6893 | is required. */ | |
6894 | if (adjusted_bpaddr != bpaddr) | |
6895 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6896 | ||
6897 | return adjusted_bpaddr; | |
6898 | } | |
6899 | } | |
6900 | ||
cb1e4e32 PA |
6901 | static bp_loc_type |
6902 | bp_location_from_bp_type (bptype type) | |
7cc221ef | 6903 | { |
cb1e4e32 | 6904 | switch (type) |
e049a4b5 DJ |
6905 | { |
6906 | case bp_breakpoint: | |
7c16b83e | 6907 | case bp_single_step: |
e049a4b5 DJ |
6908 | case bp_until: |
6909 | case bp_finish: | |
6910 | case bp_longjmp: | |
6911 | case bp_longjmp_resume: | |
e2e4d78b | 6912 | case bp_longjmp_call_dummy: |
186c406b TT |
6913 | case bp_exception: |
6914 | case bp_exception_resume: | |
e049a4b5 | 6915 | case bp_step_resume: |
2c03e5be | 6916 | case bp_hp_step_resume: |
e049a4b5 DJ |
6917 | case bp_watchpoint_scope: |
6918 | case bp_call_dummy: | |
aa7d318d | 6919 | case bp_std_terminate: |
e049a4b5 DJ |
6920 | case bp_shlib_event: |
6921 | case bp_thread_event: | |
6922 | case bp_overlay_event: | |
4efc6507 | 6923 | case bp_jit_event: |
0fd8e87f | 6924 | case bp_longjmp_master: |
aa7d318d | 6925 | case bp_std_terminate_master: |
186c406b | 6926 | case bp_exception_master: |
0e30163f JK |
6927 | case bp_gnu_ifunc_resolver: |
6928 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6929 | case bp_dprintf: |
cb1e4e32 | 6930 | return bp_loc_software_breakpoint; |
e049a4b5 | 6931 | case bp_hardware_breakpoint: |
cb1e4e32 | 6932 | return bp_loc_hardware_breakpoint; |
e049a4b5 DJ |
6933 | case bp_hardware_watchpoint: |
6934 | case bp_read_watchpoint: | |
6935 | case bp_access_watchpoint: | |
cb1e4e32 | 6936 | return bp_loc_hardware_watchpoint; |
e049a4b5 | 6937 | case bp_watchpoint: |
ce78b96d | 6938 | case bp_catchpoint: |
15c3d785 PA |
6939 | case bp_tracepoint: |
6940 | case bp_fast_tracepoint: | |
0fb4aa4b | 6941 | case bp_static_tracepoint: |
cb1e4e32 | 6942 | return bp_loc_other; |
e049a4b5 | 6943 | default: |
e2e0b3e5 | 6944 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 | 6945 | } |
cb1e4e32 PA |
6946 | } |
6947 | ||
6948 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) | |
6949 | { | |
6950 | this->owner = owner; | |
6951 | this->cond_bytecode = NULL; | |
6952 | this->shlib_disabled = 0; | |
6953 | this->enabled = 1; | |
6954 | ||
6955 | this->loc_type = type; | |
e049a4b5 | 6956 | |
cb1e4e32 PA |
6957 | if (this->loc_type == bp_loc_software_breakpoint |
6958 | || this->loc_type == bp_loc_hardware_breakpoint) | |
6959 | mark_breakpoint_location_modified (this); | |
6960 | ||
6961 | this->refc = 1; | |
6962 | } | |
6963 | ||
6964 | bp_location::bp_location (breakpoint *owner) | |
6965 | : bp_location::bp_location (owner, | |
6966 | bp_location_from_bp_type (owner->type)) | |
6967 | { | |
28010a5d PA |
6968 | } |
6969 | ||
6970 | /* Allocate a struct bp_location. */ | |
6971 | ||
6972 | static struct bp_location * | |
6973 | allocate_bp_location (struct breakpoint *bpt) | |
6974 | { | |
348d480f PA |
6975 | return bpt->ops->allocate_location (bpt); |
6976 | } | |
7cc221ef | 6977 | |
f431efe5 PA |
6978 | static void |
6979 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6980 | { |
4d01a485 | 6981 | delete loc; |
fe3f5fa8 VP |
6982 | } |
6983 | ||
f431efe5 PA |
6984 | /* Increment reference count. */ |
6985 | ||
6986 | static void | |
6987 | incref_bp_location (struct bp_location *bl) | |
6988 | { | |
6989 | ++bl->refc; | |
6990 | } | |
6991 | ||
6992 | /* Decrement reference count. If the reference count reaches 0, | |
6993 | destroy the bp_location. Sets *BLP to NULL. */ | |
6994 | ||
6995 | static void | |
6996 | decref_bp_location (struct bp_location **blp) | |
6997 | { | |
0807b50c PA |
6998 | gdb_assert ((*blp)->refc > 0); |
6999 | ||
f431efe5 PA |
7000 | if (--(*blp)->refc == 0) |
7001 | free_bp_location (*blp); | |
7002 | *blp = NULL; | |
7003 | } | |
7004 | ||
346774a9 | 7005 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7006 | |
b270e6f9 TT |
7007 | static breakpoint * |
7008 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7009 | { |
346774a9 | 7010 | struct breakpoint *b1; |
b270e6f9 | 7011 | struct breakpoint *result = b.get (); |
c906108c | 7012 | |
346774a9 PA |
7013 | /* Add this breakpoint to the end of the chain so that a list of |
7014 | breakpoints will come out in order of increasing numbers. */ | |
7015 | ||
7016 | b1 = breakpoint_chain; | |
7017 | if (b1 == 0) | |
b270e6f9 | 7018 | breakpoint_chain = b.release (); |
346774a9 PA |
7019 | else |
7020 | { | |
7021 | while (b1->next) | |
7022 | b1 = b1->next; | |
b270e6f9 | 7023 | b1->next = b.release (); |
346774a9 | 7024 | } |
b270e6f9 TT |
7025 | |
7026 | return result; | |
346774a9 PA |
7027 | } |
7028 | ||
7029 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7030 | ||
7031 | static void | |
7032 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7033 | struct gdbarch *gdbarch, | |
28010a5d | 7034 | enum bptype bptype, |
c0a91b2b | 7035 | const struct breakpoint_ops *ops) |
346774a9 | 7036 | { |
348d480f PA |
7037 | gdb_assert (ops != NULL); |
7038 | ||
28010a5d | 7039 | b->ops = ops; |
4d28f7a8 | 7040 | b->type = bptype; |
a6d9a66e | 7041 | b->gdbarch = gdbarch; |
c906108c SS |
7042 | b->language = current_language->la_language; |
7043 | b->input_radix = input_radix; | |
d0fb5eae | 7044 | b->related_breakpoint = b; |
346774a9 PA |
7045 | } |
7046 | ||
7047 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7048 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7049 | |
7050 | static struct breakpoint * | |
7051 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7052 | enum bptype bptype, |
c0a91b2b | 7053 | const struct breakpoint_ops *ops) |
346774a9 | 7054 | { |
3b0871f4 | 7055 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7056 | |
3b0871f4 | 7057 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7058 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7059 | } |
7060 | ||
0ba852ab | 7061 | /* Initialize loc->function_name. */ |
0e30163f | 7062 | |
0d381245 | 7063 | static void |
0ba852ab | 7064 | set_breakpoint_location_function (struct bp_location *loc) |
0d381245 | 7065 | { |
2bdf28a0 JK |
7066 | gdb_assert (loc->owner != NULL); |
7067 | ||
0d381245 | 7068 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7069 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7070 | || is_tracepoint (loc->owner)) |
0d381245 | 7071 | { |
2c02bd72 | 7072 | const char *function_name; |
0e30163f | 7073 | |
3467ec66 | 7074 | if (loc->msymbol != NULL |
f50776aa | 7075 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
0ba852ab | 7076 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
0e30163f JK |
7077 | { |
7078 | struct breakpoint *b = loc->owner; | |
7079 | ||
c9d95fa3 | 7080 | function_name = loc->msymbol->linkage_name (); |
3467ec66 PA |
7081 | |
7082 | if (b->type == bp_breakpoint && b->loc == loc | |
7083 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7084 | { |
7085 | /* Create only the whole new breakpoint of this type but do not | |
7086 | mess more complicated breakpoints with multiple locations. */ | |
7087 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7088 | /* Remember the resolver's address for use by the return |
7089 | breakpoint. */ | |
3467ec66 | 7090 | loc->related_address = loc->address; |
0e30163f JK |
7091 | } |
7092 | } | |
3467ec66 PA |
7093 | else |
7094 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7095 | |
2c02bd72 DE |
7096 | if (function_name) |
7097 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7098 | } |
7099 | } | |
7100 | ||
a6d9a66e | 7101 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7102 | struct gdbarch * |
a6d9a66e UW |
7103 | get_sal_arch (struct symtab_and_line sal) |
7104 | { | |
7105 | if (sal.section) | |
08feed99 | 7106 | return sal.section->objfile->arch (); |
a6d9a66e | 7107 | if (sal.symtab) |
08feed99 | 7108 | return SYMTAB_OBJFILE (sal.symtab)->arch (); |
a6d9a66e UW |
7109 | |
7110 | return NULL; | |
7111 | } | |
7112 | ||
346774a9 PA |
7113 | /* Low level routine for partially initializing a breakpoint of type |
7114 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7115 | file name, and line number are provided by SAL. |
0d381245 VP |
7116 | |
7117 | It is expected that the caller will complete the initialization of | |
7118 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7119 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7120 | |
346774a9 PA |
7121 | static void |
7122 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7123 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7124 | const struct breakpoint_ops *ops) |
0d381245 | 7125 | { |
28010a5d | 7126 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7127 | |
3742cc8b | 7128 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7129 | |
6c95b8df PA |
7130 | if (bptype != bp_catchpoint) |
7131 | gdb_assert (sal.pspace != NULL); | |
7132 | ||
f8eba3c6 TT |
7133 | /* Store the program space that was used to set the breakpoint, |
7134 | except for ordinary breakpoints, which are independent of the | |
7135 | program space. */ | |
7136 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7137 | b->pspace = sal.pspace; | |
346774a9 | 7138 | } |
c906108c | 7139 | |
346774a9 PA |
7140 | /* set_raw_breakpoint is a low level routine for allocating and |
7141 | partially initializing a breakpoint of type BPTYPE. The newly | |
7142 | created breakpoint's address, section, source file name, and line | |
7143 | number are provided by SAL. The newly created and partially | |
7144 | initialized breakpoint is added to the breakpoint chain and | |
7145 | is also returned as the value of this function. | |
7146 | ||
7147 | It is expected that the caller will complete the initialization of | |
7148 | the newly created breakpoint struct as well as output any status | |
7149 | information regarding the creation of a new breakpoint. In | |
7150 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7151 | number! Care should be taken to not allow an error to occur | |
7152 | prior to completing the initialization of the breakpoint. If this | |
7153 | should happen, a bogus breakpoint will be left on the chain. */ | |
7154 | ||
7155 | struct breakpoint * | |
7156 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7157 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7158 | const struct breakpoint_ops *ops) |
346774a9 | 7159 | { |
3b0871f4 | 7160 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7161 | |
3b0871f4 | 7162 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7163 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7164 | } |
7165 | ||
53a5351d | 7166 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7167 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7168 | initiated the operation. */ | |
c906108c SS |
7169 | |
7170 | void | |
186c406b | 7171 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7172 | { |
35df4500 | 7173 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7174 | int thread = tp->global_num; |
0fd8e87f UW |
7175 | |
7176 | /* To avoid having to rescan all objfile symbols at every step, | |
7177 | we maintain a list of continually-inserted but always disabled | |
7178 | longjmp "master" breakpoints. Here, we simply create momentary | |
7179 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7180 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7181 | if (b->pspace == current_program_space |
186c406b TT |
7182 | && (b->type == bp_longjmp_master |
7183 | || b->type == bp_exception_master)) | |
0fd8e87f | 7184 | { |
06edf0c0 PA |
7185 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7186 | struct breakpoint *clone; | |
cc59ec59 | 7187 | |
e2e4d78b JK |
7188 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7189 | after their removal. */ | |
06edf0c0 | 7190 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7191 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7192 | clone->thread = thread; |
7193 | } | |
186c406b TT |
7194 | |
7195 | tp->initiating_frame = frame; | |
c906108c SS |
7196 | } |
7197 | ||
611c83ae | 7198 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7199 | void |
611c83ae | 7200 | delete_longjmp_breakpoint (int thread) |
c906108c | 7201 | { |
35df4500 | 7202 | struct breakpoint *b, *b_tmp; |
c906108c | 7203 | |
35df4500 | 7204 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7205 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7206 | { |
7207 | if (b->thread == thread) | |
7208 | delete_breakpoint (b); | |
7209 | } | |
c906108c SS |
7210 | } |
7211 | ||
f59f708a PA |
7212 | void |
7213 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7214 | { | |
7215 | struct breakpoint *b, *b_tmp; | |
7216 | ||
7217 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7218 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7219 | { | |
7220 | if (b->thread == thread) | |
7221 | b->disposition = disp_del_at_next_stop; | |
7222 | } | |
7223 | } | |
7224 | ||
e2e4d78b JK |
7225 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7226 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7227 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7228 | breakpoints. */ | |
7229 | ||
7230 | struct breakpoint * | |
7231 | set_longjmp_breakpoint_for_call_dummy (void) | |
7232 | { | |
7233 | struct breakpoint *b, *retval = NULL; | |
7234 | ||
7235 | ALL_BREAKPOINTS (b) | |
7236 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7237 | { | |
7238 | struct breakpoint *new_b; | |
7239 | ||
7240 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7241 | &momentary_breakpoint_ops, |
7242 | 1); | |
00431a78 | 7243 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7244 | |
7245 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7246 | ||
7247 | gdb_assert (new_b->related_breakpoint == new_b); | |
7248 | if (retval == NULL) | |
7249 | retval = new_b; | |
7250 | new_b->related_breakpoint = retval; | |
7251 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7252 | retval = retval->related_breakpoint; | |
7253 | retval->related_breakpoint = new_b; | |
7254 | } | |
7255 | ||
7256 | return retval; | |
7257 | } | |
7258 | ||
7259 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7260 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7261 | stack. |
7262 | ||
7263 | You should call this function only at places where it is safe to currently | |
7264 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7265 | frames. */ | |
7266 | ||
7267 | void | |
b67a2c6f | 7268 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7269 | { |
7270 | struct breakpoint *b, *b_tmp; | |
7271 | ||
7272 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7273 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7274 | { |
7275 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7276 | ||
7277 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7278 | dummy_b = dummy_b->related_breakpoint; | |
7279 | if (dummy_b->type != bp_call_dummy | |
7280 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7281 | continue; | |
7282 | ||
00431a78 | 7283 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7284 | |
7285 | while (b->related_breakpoint != b) | |
7286 | { | |
7287 | if (b_tmp == b->related_breakpoint) | |
7288 | b_tmp = b->related_breakpoint->next; | |
7289 | delete_breakpoint (b->related_breakpoint); | |
7290 | } | |
7291 | delete_breakpoint (b); | |
7292 | } | |
7293 | } | |
7294 | ||
1900040c MS |
7295 | void |
7296 | enable_overlay_breakpoints (void) | |
7297 | { | |
52f0bd74 | 7298 | struct breakpoint *b; |
1900040c MS |
7299 | |
7300 | ALL_BREAKPOINTS (b) | |
7301 | if (b->type == bp_overlay_event) | |
7302 | { | |
7303 | b->enable_state = bp_enabled; | |
44702360 | 7304 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7305 | overlay_events_enabled = 1; |
1900040c MS |
7306 | } |
7307 | } | |
7308 | ||
7309 | void | |
7310 | disable_overlay_breakpoints (void) | |
7311 | { | |
52f0bd74 | 7312 | struct breakpoint *b; |
1900040c MS |
7313 | |
7314 | ALL_BREAKPOINTS (b) | |
7315 | if (b->type == bp_overlay_event) | |
7316 | { | |
7317 | b->enable_state = bp_disabled; | |
44702360 | 7318 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7319 | overlay_events_enabled = 0; |
1900040c MS |
7320 | } |
7321 | } | |
7322 | ||
aa7d318d TT |
7323 | /* Set an active std::terminate breakpoint for each std::terminate |
7324 | master breakpoint. */ | |
7325 | void | |
7326 | set_std_terminate_breakpoint (void) | |
7327 | { | |
35df4500 | 7328 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7329 | |
35df4500 | 7330 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7331 | if (b->pspace == current_program_space |
7332 | && b->type == bp_std_terminate_master) | |
7333 | { | |
06edf0c0 | 7334 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7335 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7336 | } |
7337 | } | |
7338 | ||
7339 | /* Delete all the std::terminate breakpoints. */ | |
7340 | void | |
7341 | delete_std_terminate_breakpoint (void) | |
7342 | { | |
35df4500 | 7343 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7344 | |
35df4500 | 7345 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7346 | if (b->type == bp_std_terminate) |
7347 | delete_breakpoint (b); | |
7348 | } | |
7349 | ||
c4093a6a | 7350 | struct breakpoint * |
a6d9a66e | 7351 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7352 | { |
7353 | struct breakpoint *b; | |
c4093a6a | 7354 | |
06edf0c0 PA |
7355 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7356 | &internal_breakpoint_ops); | |
7357 | ||
b5de0fa7 | 7358 | b->enable_state = bp_enabled; |
f00aae0f | 7359 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7360 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7361 | |
44702360 | 7362 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7363 | |
c4093a6a JM |
7364 | return b; |
7365 | } | |
7366 | ||
0101ce28 JJ |
7367 | struct lang_and_radix |
7368 | { | |
7369 | enum language lang; | |
7370 | int radix; | |
7371 | }; | |
7372 | ||
4efc6507 DE |
7373 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7374 | ||
7375 | struct breakpoint * | |
7376 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7377 | { | |
2a7f3dff PA |
7378 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7379 | &internal_breakpoint_ops); | |
4efc6507 | 7380 | } |
0101ce28 | 7381 | |
03673fc7 PP |
7382 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7383 | ||
7384 | void | |
7385 | remove_jit_event_breakpoints (void) | |
7386 | { | |
7387 | struct breakpoint *b, *b_tmp; | |
7388 | ||
7389 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7390 | if (b->type == bp_jit_event | |
7391 | && b->loc->pspace == current_program_space) | |
7392 | delete_breakpoint (b); | |
7393 | } | |
7394 | ||
cae688ec JJ |
7395 | void |
7396 | remove_solib_event_breakpoints (void) | |
7397 | { | |
35df4500 | 7398 | struct breakpoint *b, *b_tmp; |
cae688ec | 7399 | |
35df4500 | 7400 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7401 | if (b->type == bp_shlib_event |
7402 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7403 | delete_breakpoint (b); |
7404 | } | |
7405 | ||
f37f681c PA |
7406 | /* See breakpoint.h. */ |
7407 | ||
7408 | void | |
7409 | remove_solib_event_breakpoints_at_next_stop (void) | |
7410 | { | |
7411 | struct breakpoint *b, *b_tmp; | |
7412 | ||
7413 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7414 | if (b->type == bp_shlib_event | |
7415 | && b->loc->pspace == current_program_space) | |
7416 | b->disposition = disp_del_at_next_stop; | |
7417 | } | |
7418 | ||
04086b45 PA |
7419 | /* Helper for create_solib_event_breakpoint / |
7420 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7421 | INSERT_MODE to pass through to update_global_location_list. */ | |
7422 | ||
7423 | static struct breakpoint * | |
7424 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7425 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7426 | { |
7427 | struct breakpoint *b; | |
7428 | ||
06edf0c0 PA |
7429 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7430 | &internal_breakpoint_ops); | |
04086b45 | 7431 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7432 | return b; |
7433 | } | |
7434 | ||
04086b45 PA |
7435 | struct breakpoint * |
7436 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7437 | { | |
7438 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7439 | } | |
7440 | ||
f37f681c PA |
7441 | /* See breakpoint.h. */ |
7442 | ||
7443 | struct breakpoint * | |
7444 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7445 | { | |
7446 | struct breakpoint *b; | |
7447 | ||
04086b45 PA |
7448 | /* Explicitly tell update_global_location_list to insert |
7449 | locations. */ | |
7450 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7451 | if (!b->loc->inserted) |
7452 | { | |
7453 | delete_breakpoint (b); | |
7454 | return NULL; | |
7455 | } | |
7456 | return b; | |
7457 | } | |
7458 | ||
cae688ec JJ |
7459 | /* Disable any breakpoints that are on code in shared libraries. Only |
7460 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7461 | ||
7462 | void | |
cb851954 | 7463 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7464 | { |
876fa593 | 7465 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7466 | |
876fa593 | 7467 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7468 | { |
2bdf28a0 | 7469 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7470 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7471 | |
4a64f543 MS |
7472 | /* We apply the check to all breakpoints, including disabled for |
7473 | those with loc->duplicate set. This is so that when breakpoint | |
7474 | becomes enabled, or the duplicate is removed, gdb will try to | |
7475 | insert all breakpoints. If we don't set shlib_disabled here, | |
7476 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7477 | if (((b->type == bp_breakpoint) |
508ccb1f | 7478 | || (b->type == bp_jit_event) |
1042e4c0 | 7479 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7480 | || (is_tracepoint (b))) |
6c95b8df | 7481 | && loc->pspace == current_program_space |
0d381245 | 7482 | && !loc->shlib_disabled |
6c95b8df | 7483 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7484 | ) |
0d381245 VP |
7485 | { |
7486 | loc->shlib_disabled = 1; | |
7487 | } | |
cae688ec JJ |
7488 | } |
7489 | } | |
7490 | ||
63644780 NB |
7491 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7492 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7493 | disabled ones can just stay disabled. */ | |
84acb35a | 7494 | |
75149521 | 7495 | static void |
84acb35a JJ |
7496 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7497 | { | |
876fa593 | 7498 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7499 | int disabled_shlib_breaks = 0; |
7500 | ||
876fa593 | 7501 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7502 | { |
2bdf28a0 | 7503 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7504 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7505 | |
1e4d1764 | 7506 | if (solib->pspace == loc->pspace |
e2dd7057 | 7507 | && !loc->shlib_disabled |
1e4d1764 YQ |
7508 | && (((b->type == bp_breakpoint |
7509 | || b->type == bp_jit_event | |
7510 | || b->type == bp_hardware_breakpoint) | |
7511 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7512 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7513 | || is_tracepoint (b)) | |
e2dd7057 | 7514 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7515 | { |
e2dd7057 PP |
7516 | loc->shlib_disabled = 1; |
7517 | /* At this point, we cannot rely on remove_breakpoint | |
7518 | succeeding so we must mark the breakpoint as not inserted | |
7519 | to prevent future errors occurring in remove_breakpoints. */ | |
7520 | loc->inserted = 0; | |
8d3788bd VP |
7521 | |
7522 | /* This may cause duplicate notifications for the same breakpoint. */ | |
76727919 | 7523 | gdb::observers::breakpoint_modified.notify (b); |
8d3788bd | 7524 | |
e2dd7057 PP |
7525 | if (!disabled_shlib_breaks) |
7526 | { | |
223ffa71 | 7527 | target_terminal::ours_for_output (); |
3e43a32a MS |
7528 | warning (_("Temporarily disabling breakpoints " |
7529 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7530 | solib->so_name); |
84acb35a | 7531 | } |
e2dd7057 | 7532 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7533 | } |
7534 | } | |
84acb35a JJ |
7535 | } |
7536 | ||
63644780 NB |
7537 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7538 | notification of free_objfile. Only apply to enabled breakpoints, | |
7539 | disabled ones can just stay disabled. */ | |
7540 | ||
7541 | static void | |
7542 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7543 | { | |
7544 | struct breakpoint *b; | |
7545 | ||
7546 | if (objfile == NULL) | |
7547 | return; | |
7548 | ||
d03de421 PA |
7549 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7550 | managed by the user with add-symbol-file/remove-symbol-file. | |
7551 | Similarly to how breakpoints in shared libraries are handled in | |
7552 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7553 | shlib_disabled so they end up uninserted on the next global |
7554 | location list update. Shared libraries not loaded by the user | |
7555 | aren't handled here -- they're already handled in | |
7556 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7557 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7558 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7559 | main objfile). */ | |
7560 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7561 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7562 | return; |
7563 | ||
7564 | ALL_BREAKPOINTS (b) | |
7565 | { | |
7566 | struct bp_location *loc; | |
7567 | int bp_modified = 0; | |
7568 | ||
7569 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7570 | continue; | |
7571 | ||
7572 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7573 | { | |
7574 | CORE_ADDR loc_addr = loc->address; | |
7575 | ||
7576 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7577 | && loc->loc_type != bp_loc_software_breakpoint) | |
7578 | continue; | |
7579 | ||
7580 | if (loc->shlib_disabled != 0) | |
7581 | continue; | |
7582 | ||
7583 | if (objfile->pspace != loc->pspace) | |
7584 | continue; | |
7585 | ||
7586 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7587 | && loc->loc_type != bp_loc_software_breakpoint) | |
7588 | continue; | |
7589 | ||
7590 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7591 | { | |
7592 | loc->shlib_disabled = 1; | |
08351840 PA |
7593 | /* At this point, we don't know whether the object was |
7594 | unmapped from the inferior or not, so leave the | |
7595 | inserted flag alone. We'll handle failure to | |
7596 | uninsert quietly, in case the object was indeed | |
7597 | unmapped. */ | |
63644780 NB |
7598 | |
7599 | mark_breakpoint_location_modified (loc); | |
7600 | ||
7601 | bp_modified = 1; | |
7602 | } | |
7603 | } | |
7604 | ||
7605 | if (bp_modified) | |
76727919 | 7606 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7607 | } |
7608 | } | |
7609 | ||
ce78b96d JB |
7610 | /* FORK & VFORK catchpoints. */ |
7611 | ||
e29a4733 | 7612 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7613 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7614 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7615 | |
c1fc2657 | 7616 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7617 | { |
e29a4733 PA |
7618 | /* Process id of a child process whose forking triggered this |
7619 | catchpoint. This field is only valid immediately after this | |
7620 | catchpoint has triggered. */ | |
7621 | ptid_t forked_inferior_pid; | |
7622 | }; | |
7623 | ||
4a64f543 MS |
7624 | /* Implement the "insert" breakpoint_ops method for fork |
7625 | catchpoints. */ | |
ce78b96d | 7626 | |
77b06cd7 TJB |
7627 | static int |
7628 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7629 | { |
e99b03dc | 7630 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7631 | } |
7632 | ||
4a64f543 MS |
7633 | /* Implement the "remove" breakpoint_ops method for fork |
7634 | catchpoints. */ | |
ce78b96d JB |
7635 | |
7636 | static int | |
73971819 | 7637 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7638 | { |
e99b03dc | 7639 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7640 | } |
7641 | ||
7642 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7643 | catchpoints. */ | |
7644 | ||
7645 | static int | |
f1310107 | 7646 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
bd522513 | 7647 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7648 | const struct target_waitstatus *ws) |
ce78b96d | 7649 | { |
e29a4733 PA |
7650 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7651 | ||
f90263c1 TT |
7652 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7653 | return 0; | |
7654 | ||
7655 | c->forked_inferior_pid = ws->value.related_pid; | |
7656 | return 1; | |
ce78b96d JB |
7657 | } |
7658 | ||
4a64f543 MS |
7659 | /* Implement the "print_it" breakpoint_ops method for fork |
7660 | catchpoints. */ | |
ce78b96d JB |
7661 | |
7662 | static enum print_stop_action | |
348d480f | 7663 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7664 | { |
36dfb11c | 7665 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7666 | struct breakpoint *b = bs->breakpoint_at; |
7667 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7668 | |
ce78b96d | 7669 | annotate_catchpoint (b->number); |
f303dbd6 | 7670 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7671 | if (b->disposition == disp_del) |
112e8700 | 7672 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7673 | else |
112e8700 SM |
7674 | uiout->text ("Catchpoint "); |
7675 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7676 | { |
112e8700 SM |
7677 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7678 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7679 | } |
381befee | 7680 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7681 | uiout->text (" (forked process "); |
381befee | 7682 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7683 | uiout->text ("), "); |
ce78b96d JB |
7684 | return PRINT_SRC_AND_LOC; |
7685 | } | |
7686 | ||
4a64f543 MS |
7687 | /* Implement the "print_one" breakpoint_ops method for fork |
7688 | catchpoints. */ | |
ce78b96d JB |
7689 | |
7690 | static void | |
a6d9a66e | 7691 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7692 | { |
e29a4733 | 7693 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7694 | struct value_print_options opts; |
79a45e25 | 7695 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7696 | |
7697 | get_user_print_options (&opts); | |
7698 | ||
4a64f543 MS |
7699 | /* Field 4, the address, is omitted (which makes the columns not |
7700 | line up too nicely with the headers, but the effect is relatively | |
7701 | readable). */ | |
79a45b7d | 7702 | if (opts.addressprint) |
112e8700 | 7703 | uiout->field_skip ("addr"); |
ce78b96d | 7704 | annotate_field (5); |
112e8700 | 7705 | uiout->text ("fork"); |
d7e15655 | 7706 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7707 | { |
112e8700 | 7708 | uiout->text (", process "); |
381befee | 7709 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7710 | uiout->spaces (1); |
ce78b96d | 7711 | } |
8ac3646f | 7712 | |
112e8700 SM |
7713 | if (uiout->is_mi_like_p ()) |
7714 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7715 | } |
7716 | ||
7717 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7718 | catchpoints. */ | |
7719 | ||
7720 | static void | |
7721 | print_mention_catch_fork (struct breakpoint *b) | |
7722 | { | |
7723 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7724 | } | |
7725 | ||
6149aea9 PA |
7726 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7727 | catchpoints. */ | |
7728 | ||
7729 | static void | |
7730 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7731 | { | |
7732 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7733 | print_recreate_thread (b, fp); |
6149aea9 PA |
7734 | } |
7735 | ||
ce78b96d JB |
7736 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7737 | ||
2060206e | 7738 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7739 | |
4a64f543 MS |
7740 | /* Implement the "insert" breakpoint_ops method for vfork |
7741 | catchpoints. */ | |
ce78b96d | 7742 | |
77b06cd7 TJB |
7743 | static int |
7744 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7745 | { |
e99b03dc | 7746 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7747 | } |
7748 | ||
4a64f543 MS |
7749 | /* Implement the "remove" breakpoint_ops method for vfork |
7750 | catchpoints. */ | |
ce78b96d JB |
7751 | |
7752 | static int | |
73971819 | 7753 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7754 | { |
e99b03dc | 7755 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7756 | } |
7757 | ||
7758 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7759 | catchpoints. */ | |
7760 | ||
7761 | static int | |
f1310107 | 7762 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
bd522513 | 7763 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7764 | const struct target_waitstatus *ws) |
ce78b96d | 7765 | { |
e29a4733 PA |
7766 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7767 | ||
f90263c1 TT |
7768 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7769 | return 0; | |
7770 | ||
7771 | c->forked_inferior_pid = ws->value.related_pid; | |
7772 | return 1; | |
ce78b96d JB |
7773 | } |
7774 | ||
4a64f543 MS |
7775 | /* Implement the "print_it" breakpoint_ops method for vfork |
7776 | catchpoints. */ | |
ce78b96d JB |
7777 | |
7778 | static enum print_stop_action | |
348d480f | 7779 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7780 | { |
36dfb11c | 7781 | struct ui_out *uiout = current_uiout; |
348d480f | 7782 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7783 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7784 | ||
ce78b96d | 7785 | annotate_catchpoint (b->number); |
f303dbd6 | 7786 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7787 | if (b->disposition == disp_del) |
112e8700 | 7788 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7789 | else |
112e8700 SM |
7790 | uiout->text ("Catchpoint "); |
7791 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7792 | { |
112e8700 SM |
7793 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
7794 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7795 | } |
381befee | 7796 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7797 | uiout->text (" (vforked process "); |
381befee | 7798 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7799 | uiout->text ("), "); |
ce78b96d JB |
7800 | return PRINT_SRC_AND_LOC; |
7801 | } | |
7802 | ||
4a64f543 MS |
7803 | /* Implement the "print_one" breakpoint_ops method for vfork |
7804 | catchpoints. */ | |
ce78b96d JB |
7805 | |
7806 | static void | |
a6d9a66e | 7807 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7808 | { |
e29a4733 | 7809 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7810 | struct value_print_options opts; |
79a45e25 | 7811 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7812 | |
7813 | get_user_print_options (&opts); | |
4a64f543 MS |
7814 | /* Field 4, the address, is omitted (which makes the columns not |
7815 | line up too nicely with the headers, but the effect is relatively | |
7816 | readable). */ | |
79a45b7d | 7817 | if (opts.addressprint) |
112e8700 | 7818 | uiout->field_skip ("addr"); |
ce78b96d | 7819 | annotate_field (5); |
112e8700 | 7820 | uiout->text ("vfork"); |
d7e15655 | 7821 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7822 | { |
112e8700 | 7823 | uiout->text (", process "); |
381befee | 7824 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7825 | uiout->spaces (1); |
ce78b96d | 7826 | } |
8ac3646f | 7827 | |
112e8700 SM |
7828 | if (uiout->is_mi_like_p ()) |
7829 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
7830 | } |
7831 | ||
7832 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7833 | catchpoints. */ | |
7834 | ||
7835 | static void | |
7836 | print_mention_catch_vfork (struct breakpoint *b) | |
7837 | { | |
7838 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7839 | } | |
7840 | ||
6149aea9 PA |
7841 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7842 | catchpoints. */ | |
7843 | ||
7844 | static void | |
7845 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7846 | { | |
7847 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7848 | print_recreate_thread (b, fp); |
6149aea9 PA |
7849 | } |
7850 | ||
ce78b96d JB |
7851 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7852 | ||
2060206e | 7853 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7854 | |
edcc5120 | 7855 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 7856 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
7857 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
7858 | ||
c1fc2657 | 7859 | struct solib_catchpoint : public breakpoint |
edcc5120 | 7860 | { |
c1fc2657 | 7861 | ~solib_catchpoint () override; |
edcc5120 TT |
7862 | |
7863 | /* True for "catch load", false for "catch unload". */ | |
7864 | unsigned char is_load; | |
7865 | ||
7866 | /* Regular expression to match, if any. COMPILED is only valid when | |
7867 | REGEX is non-NULL. */ | |
7868 | char *regex; | |
2d7cc5c7 | 7869 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
7870 | }; |
7871 | ||
c1fc2657 | 7872 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 7873 | { |
c1fc2657 | 7874 | xfree (this->regex); |
edcc5120 TT |
7875 | } |
7876 | ||
7877 | static int | |
7878 | insert_catch_solib (struct bp_location *ignore) | |
7879 | { | |
7880 | return 0; | |
7881 | } | |
7882 | ||
7883 | static int | |
73971819 | 7884 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
7885 | { |
7886 | return 0; | |
7887 | } | |
7888 | ||
7889 | static int | |
7890 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 7891 | const address_space *aspace, |
edcc5120 TT |
7892 | CORE_ADDR bp_addr, |
7893 | const struct target_waitstatus *ws) | |
7894 | { | |
7895 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7896 | struct breakpoint *other; | |
7897 | ||
7898 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7899 | return 1; | |
7900 | ||
7901 | ALL_BREAKPOINTS (other) | |
7902 | { | |
7903 | struct bp_location *other_bl; | |
7904 | ||
7905 | if (other == bl->owner) | |
7906 | continue; | |
7907 | ||
7908 | if (other->type != bp_shlib_event) | |
7909 | continue; | |
7910 | ||
c1fc2657 | 7911 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
7912 | continue; |
7913 | ||
7914 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7915 | { | |
7916 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7917 | return 1; | |
7918 | } | |
7919 | } | |
7920 | ||
7921 | return 0; | |
7922 | } | |
7923 | ||
7924 | static void | |
7925 | check_status_catch_solib (struct bpstats *bs) | |
7926 | { | |
7927 | struct solib_catchpoint *self | |
7928 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
edcc5120 TT |
7929 | |
7930 | if (self->is_load) | |
7931 | { | |
52941706 | 7932 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 TT |
7933 | { |
7934 | if (!self->regex | |
2d7cc5c7 | 7935 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
7936 | return; |
7937 | } | |
7938 | } | |
7939 | else | |
7940 | { | |
6fb16ce6 | 7941 | for (const std::string &iter : current_program_space->deleted_solibs) |
edcc5120 TT |
7942 | { |
7943 | if (!self->regex | |
6fb16ce6 | 7944 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
edcc5120 TT |
7945 | return; |
7946 | } | |
7947 | } | |
7948 | ||
7949 | bs->stop = 0; | |
7950 | bs->print_it = print_it_noop; | |
7951 | } | |
7952 | ||
7953 | static enum print_stop_action | |
7954 | print_it_catch_solib (bpstat bs) | |
7955 | { | |
7956 | struct breakpoint *b = bs->breakpoint_at; | |
7957 | struct ui_out *uiout = current_uiout; | |
7958 | ||
7959 | annotate_catchpoint (b->number); | |
f303dbd6 | 7960 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 7961 | if (b->disposition == disp_del) |
112e8700 | 7962 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 7963 | else |
112e8700 | 7964 | uiout->text ("Catchpoint "); |
381befee | 7965 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
7966 | uiout->text ("\n"); |
7967 | if (uiout->is_mi_like_p ()) | |
7968 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
7969 | print_solib_event (1); |
7970 | return PRINT_SRC_AND_LOC; | |
7971 | } | |
7972 | ||
7973 | static void | |
7974 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7975 | { | |
7976 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7977 | struct value_print_options opts; | |
7978 | struct ui_out *uiout = current_uiout; | |
edcc5120 TT |
7979 | |
7980 | get_user_print_options (&opts); | |
7981 | /* Field 4, the address, is omitted (which makes the columns not | |
7982 | line up too nicely with the headers, but the effect is relatively | |
7983 | readable). */ | |
7984 | if (opts.addressprint) | |
7985 | { | |
7986 | annotate_field (4); | |
112e8700 | 7987 | uiout->field_skip ("addr"); |
edcc5120 TT |
7988 | } |
7989 | ||
528e1572 | 7990 | std::string msg; |
edcc5120 TT |
7991 | annotate_field (5); |
7992 | if (self->is_load) | |
7993 | { | |
7994 | if (self->regex) | |
528e1572 | 7995 | msg = string_printf (_("load of library matching %s"), self->regex); |
edcc5120 | 7996 | else |
528e1572 | 7997 | msg = _("load of library"); |
edcc5120 TT |
7998 | } |
7999 | else | |
8000 | { | |
8001 | if (self->regex) | |
528e1572 | 8002 | msg = string_printf (_("unload of library matching %s"), self->regex); |
edcc5120 | 8003 | else |
528e1572 | 8004 | msg = _("unload of library"); |
edcc5120 | 8005 | } |
112e8700 | 8006 | uiout->field_string ("what", msg); |
8ac3646f | 8007 | |
112e8700 SM |
8008 | if (uiout->is_mi_like_p ()) |
8009 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8010 | } |
8011 | ||
8012 | static void | |
8013 | print_mention_catch_solib (struct breakpoint *b) | |
8014 | { | |
8015 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8016 | ||
8017 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8018 | self->is_load ? "load" : "unload"); | |
8019 | } | |
8020 | ||
8021 | static void | |
8022 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8023 | { | |
8024 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8025 | ||
8026 | fprintf_unfiltered (fp, "%s %s", | |
8027 | b->disposition == disp_del ? "tcatch" : "catch", | |
8028 | self->is_load ? "load" : "unload"); | |
8029 | if (self->regex) | |
8030 | fprintf_unfiltered (fp, " %s", self->regex); | |
8031 | fprintf_unfiltered (fp, "\n"); | |
8032 | } | |
8033 | ||
8034 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8035 | ||
91985142 MG |
8036 | /* Shared helper function (MI and CLI) for creating and installing |
8037 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8038 | the events to be caught are load events, otherwise they are | |
8039 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8040 | temporary one. If ENABLED is non-zero the catchpoint is | |
8041 | created in an enabled state. */ | |
edcc5120 | 8042 | |
91985142 | 8043 | void |
a121b7c1 | 8044 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8045 | { |
edcc5120 | 8046 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8047 | |
edcc5120 TT |
8048 | if (!arg) |
8049 | arg = ""; | |
f1735a53 | 8050 | arg = skip_spaces (arg); |
edcc5120 | 8051 | |
36bd8eaa | 8052 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8053 | |
8054 | if (*arg != '\0') | |
8055 | { | |
2d7cc5c7 PA |
8056 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8057 | _("Invalid regexp"))); | |
edcc5120 TT |
8058 | c->regex = xstrdup (arg); |
8059 | } | |
8060 | ||
8061 | c->is_load = is_load; | |
36bd8eaa | 8062 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8063 | &catch_solib_breakpoint_ops); |
8064 | ||
c1fc2657 | 8065 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8066 | |
b270e6f9 | 8067 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8068 | } |
8069 | ||
91985142 MG |
8070 | /* A helper function that does all the work for "catch load" and |
8071 | "catch unload". */ | |
8072 | ||
8073 | static void | |
eb4c3f4a | 8074 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
8075 | struct cmd_list_element *command) |
8076 | { | |
8077 | int tempflag; | |
8078 | const int enabled = 1; | |
8079 | ||
8080 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8081 | ||
8082 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8083 | } | |
8084 | ||
edcc5120 | 8085 | static void |
eb4c3f4a | 8086 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8087 | struct cmd_list_element *command) |
8088 | { | |
8089 | catch_load_or_unload (arg, from_tty, 1, command); | |
8090 | } | |
8091 | ||
8092 | static void | |
eb4c3f4a | 8093 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8094 | struct cmd_list_element *command) |
8095 | { | |
8096 | catch_load_or_unload (arg, from_tty, 0, command); | |
8097 | } | |
8098 | ||
346774a9 PA |
8099 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8100 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8101 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8102 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8103 | |
ab04a2af | 8104 | void |
346774a9 PA |
8105 | init_catchpoint (struct breakpoint *b, |
8106 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8107 | const char *cond_string, |
c0a91b2b | 8108 | const struct breakpoint_ops *ops) |
c906108c | 8109 | { |
51abb421 | 8110 | symtab_and_line sal; |
6c95b8df | 8111 | sal.pspace = current_program_space; |
c5aa993b | 8112 | |
28010a5d | 8113 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8114 | |
1b36a34b | 8115 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8116 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8117 | } |
8118 | ||
28010a5d | 8119 | void |
b270e6f9 | 8120 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8121 | { |
b270e6f9 | 8122 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8123 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8124 | if (is_tracepoint (b)) |
8125 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8126 | if (!internal) |
8127 | mention (b); | |
76727919 | 8128 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
8129 | |
8130 | if (update_gll) | |
44702360 | 8131 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8132 | } |
8133 | ||
9b70b993 | 8134 | static void |
a6d9a66e | 8135 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8136 | int tempflag, const char *cond_string, |
c0a91b2b | 8137 | const struct breakpoint_ops *ops) |
c906108c | 8138 | { |
b270e6f9 | 8139 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8140 | |
b270e6f9 | 8141 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8142 | |
8143 | c->forked_inferior_pid = null_ptid; | |
8144 | ||
b270e6f9 | 8145 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8146 | } |
8147 | ||
fe798b75 JB |
8148 | /* Exec catchpoints. */ |
8149 | ||
b4d90040 | 8150 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8151 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8152 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8153 | ||
c1fc2657 | 8154 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8155 | { |
c1fc2657 | 8156 | ~exec_catchpoint () override; |
b4d90040 PA |
8157 | |
8158 | /* Filename of a program whose exec triggered this catchpoint. | |
8159 | This field is only valid immediately after this catchpoint has | |
8160 | triggered. */ | |
8161 | char *exec_pathname; | |
8162 | }; | |
8163 | ||
c1fc2657 | 8164 | /* Exec catchpoint destructor. */ |
b4d90040 | 8165 | |
c1fc2657 | 8166 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8167 | { |
c1fc2657 | 8168 | xfree (this->exec_pathname); |
b4d90040 PA |
8169 | } |
8170 | ||
77b06cd7 TJB |
8171 | static int |
8172 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8173 | { |
e99b03dc | 8174 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8175 | } |
c906108c | 8176 | |
fe798b75 | 8177 | static int |
73971819 | 8178 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8179 | { |
e99b03dc | 8180 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8181 | } |
c906108c | 8182 | |
fe798b75 | 8183 | static int |
f1310107 | 8184 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
bd522513 | 8185 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 8186 | const struct target_waitstatus *ws) |
fe798b75 | 8187 | { |
b4d90040 PA |
8188 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8189 | ||
f90263c1 TT |
8190 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8191 | return 0; | |
8192 | ||
8193 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8194 | return 1; | |
fe798b75 | 8195 | } |
c906108c | 8196 | |
fe798b75 | 8197 | static enum print_stop_action |
348d480f | 8198 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8199 | { |
36dfb11c | 8200 | struct ui_out *uiout = current_uiout; |
348d480f | 8201 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8202 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8203 | ||
fe798b75 | 8204 | annotate_catchpoint (b->number); |
f303dbd6 | 8205 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8206 | if (b->disposition == disp_del) |
112e8700 | 8207 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8208 | else |
112e8700 SM |
8209 | uiout->text ("Catchpoint "); |
8210 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8211 | { |
112e8700 SM |
8212 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8213 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8214 | } |
381befee | 8215 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
8216 | uiout->text (" (exec'd "); |
8217 | uiout->field_string ("new-exec", c->exec_pathname); | |
8218 | uiout->text ("), "); | |
36dfb11c | 8219 | |
fe798b75 | 8220 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8221 | } |
8222 | ||
fe798b75 | 8223 | static void |
a6d9a66e | 8224 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8225 | { |
b4d90040 | 8226 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8227 | struct value_print_options opts; |
79a45e25 | 8228 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8229 | |
8230 | get_user_print_options (&opts); | |
8231 | ||
8232 | /* Field 4, the address, is omitted (which makes the columns | |
8233 | not line up too nicely with the headers, but the effect | |
8234 | is relatively readable). */ | |
8235 | if (opts.addressprint) | |
112e8700 | 8236 | uiout->field_skip ("addr"); |
fe798b75 | 8237 | annotate_field (5); |
112e8700 | 8238 | uiout->text ("exec"); |
b4d90040 | 8239 | if (c->exec_pathname != NULL) |
fe798b75 | 8240 | { |
112e8700 SM |
8241 | uiout->text (", program \""); |
8242 | uiout->field_string ("what", c->exec_pathname); | |
8243 | uiout->text ("\" "); | |
fe798b75 | 8244 | } |
8ac3646f | 8245 | |
112e8700 SM |
8246 | if (uiout->is_mi_like_p ()) |
8247 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8248 | } |
8249 | ||
8250 | static void | |
8251 | print_mention_catch_exec (struct breakpoint *b) | |
8252 | { | |
8253 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8254 | } | |
8255 | ||
6149aea9 PA |
8256 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8257 | catchpoints. */ | |
8258 | ||
8259 | static void | |
8260 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8261 | { | |
8262 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8263 | print_recreate_thread (b, fp); |
6149aea9 PA |
8264 | } |
8265 | ||
2060206e | 8266 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8267 | |
c906108c | 8268 | static int |
fba45db2 | 8269 | hw_breakpoint_used_count (void) |
c906108c | 8270 | { |
c906108c | 8271 | int i = 0; |
f1310107 TJB |
8272 | struct breakpoint *b; |
8273 | struct bp_location *bl; | |
c906108c SS |
8274 | |
8275 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8276 | { |
d6b74ac4 | 8277 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8278 | for (bl = b->loc; bl; bl = bl->next) |
8279 | { | |
8280 | /* Special types of hardware breakpoints may use more than | |
8281 | one register. */ | |
348d480f | 8282 | i += b->ops->resources_needed (bl); |
f1310107 | 8283 | } |
c5aa993b | 8284 | } |
c906108c SS |
8285 | |
8286 | return i; | |
8287 | } | |
8288 | ||
a1398e0c PA |
8289 | /* Returns the resources B would use if it were a hardware |
8290 | watchpoint. */ | |
8291 | ||
c906108c | 8292 | static int |
a1398e0c | 8293 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8294 | { |
c906108c | 8295 | int i = 0; |
e09342b5 | 8296 | struct bp_location *bl; |
c906108c | 8297 | |
a1398e0c PA |
8298 | if (!breakpoint_enabled (b)) |
8299 | return 0; | |
8300 | ||
8301 | for (bl = b->loc; bl; bl = bl->next) | |
8302 | { | |
8303 | /* Special types of hardware watchpoints may use more than | |
8304 | one register. */ | |
8305 | i += b->ops->resources_needed (bl); | |
8306 | } | |
8307 | ||
8308 | return i; | |
8309 | } | |
8310 | ||
8311 | /* Returns the sum the used resources of all hardware watchpoints of | |
8312 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8313 | the sum of the used resources of all hardware watchpoints of other | |
8314 | types _not_ TYPE. */ | |
8315 | ||
8316 | static int | |
8317 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8318 | enum bptype type, int *other_type_used) | |
8319 | { | |
8320 | int i = 0; | |
8321 | struct breakpoint *b; | |
8322 | ||
c906108c SS |
8323 | *other_type_used = 0; |
8324 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8325 | { |
a1398e0c PA |
8326 | if (b == except) |
8327 | continue; | |
e09342b5 TJB |
8328 | if (!breakpoint_enabled (b)) |
8329 | continue; | |
8330 | ||
a1398e0c PA |
8331 | if (b->type == type) |
8332 | i += hw_watchpoint_use_count (b); | |
8333 | else if (is_hardware_watchpoint (b)) | |
8334 | *other_type_used = 1; | |
e09342b5 TJB |
8335 | } |
8336 | ||
c906108c SS |
8337 | return i; |
8338 | } | |
8339 | ||
c906108c | 8340 | void |
fba45db2 | 8341 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8342 | { |
c5aa993b | 8343 | struct breakpoint *b; |
c906108c SS |
8344 | |
8345 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8346 | { |
cc60f2e3 | 8347 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8348 | { |
b5de0fa7 | 8349 | b->enable_state = bp_call_disabled; |
44702360 | 8350 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8351 | } |
8352 | } | |
c906108c SS |
8353 | } |
8354 | ||
8355 | void | |
fba45db2 | 8356 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8357 | { |
c5aa993b | 8358 | struct breakpoint *b; |
c906108c SS |
8359 | |
8360 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8361 | { |
cc60f2e3 | 8362 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8363 | { |
b5de0fa7 | 8364 | b->enable_state = bp_enabled; |
44702360 | 8365 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8366 | } |
8367 | } | |
c906108c SS |
8368 | } |
8369 | ||
8bea4e01 UW |
8370 | void |
8371 | disable_breakpoints_before_startup (void) | |
8372 | { | |
6c95b8df | 8373 | current_program_space->executing_startup = 1; |
44702360 | 8374 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8375 | } |
8376 | ||
8377 | void | |
8378 | enable_breakpoints_after_startup (void) | |
8379 | { | |
6c95b8df | 8380 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8381 | breakpoint_re_set (); |
8bea4e01 UW |
8382 | } |
8383 | ||
7c16b83e PA |
8384 | /* Create a new single-step breakpoint for thread THREAD, with no |
8385 | locations. */ | |
c906108c | 8386 | |
7c16b83e PA |
8387 | static struct breakpoint * |
8388 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8389 | { | |
b270e6f9 | 8390 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8391 | |
b270e6f9 | 8392 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8393 | &momentary_breakpoint_ops); |
8394 | ||
8395 | b->disposition = disp_donttouch; | |
8396 | b->frame_id = null_frame_id; | |
8397 | ||
8398 | b->thread = thread; | |
8399 | gdb_assert (b->thread != 0); | |
8400 | ||
b270e6f9 | 8401 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8402 | } |
8403 | ||
8404 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8405 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8406 | frame. */ | |
c906108c | 8407 | |
454dafbd | 8408 | breakpoint_up |
a6d9a66e UW |
8409 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8410 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8411 | { |
52f0bd74 | 8412 | struct breakpoint *b; |
edb3359d | 8413 | |
193facb3 JK |
8414 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8415 | tail-called one. */ | |
8416 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8417 | |
06edf0c0 | 8418 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8419 | b->enable_state = bp_enabled; |
8420 | b->disposition = disp_donttouch; | |
818dd999 | 8421 | b->frame_id = frame_id; |
c906108c | 8422 | |
00431a78 | 8423 | b->thread = inferior_thread ()->global_num; |
c906108c | 8424 | |
44702360 | 8425 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8426 | |
454dafbd | 8427 | return breakpoint_up (b); |
c906108c | 8428 | } |
611c83ae | 8429 | |
06edf0c0 | 8430 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8431 | The new breakpoint will have type TYPE, use OPS as its |
8432 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8433 | |
06edf0c0 PA |
8434 | static struct breakpoint * |
8435 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8436 | enum bptype type, | |
a1aa2221 LM |
8437 | const struct breakpoint_ops *ops, |
8438 | int loc_enabled) | |
e58b0e63 PA |
8439 | { |
8440 | struct breakpoint *copy; | |
8441 | ||
06edf0c0 | 8442 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8443 | copy->loc = allocate_bp_location (copy); |
0ba852ab | 8444 | set_breakpoint_location_function (copy->loc); |
e58b0e63 | 8445 | |
a6d9a66e | 8446 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8447 | copy->loc->requested_address = orig->loc->requested_address; |
8448 | copy->loc->address = orig->loc->address; | |
8449 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8450 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8451 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8452 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8453 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8454 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8455 | copy->frame_id = orig->frame_id; |
8456 | copy->thread = orig->thread; | |
6c95b8df | 8457 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8458 | |
8459 | copy->enable_state = bp_enabled; | |
8460 | copy->disposition = disp_donttouch; | |
8461 | copy->number = internal_breakpoint_number--; | |
8462 | ||
44702360 | 8463 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8464 | return copy; |
8465 | } | |
8466 | ||
06edf0c0 PA |
8467 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8468 | ORIG is NULL. */ | |
8469 | ||
8470 | struct breakpoint * | |
8471 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8472 | { | |
8473 | /* If there's nothing to clone, then return nothing. */ | |
8474 | if (orig == NULL) | |
8475 | return NULL; | |
8476 | ||
a1aa2221 | 8477 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8478 | } |
8479 | ||
454dafbd | 8480 | breakpoint_up |
a6d9a66e UW |
8481 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8482 | enum bptype type) | |
611c83ae PA |
8483 | { |
8484 | struct symtab_and_line sal; | |
8485 | ||
8486 | sal = find_pc_line (pc, 0); | |
8487 | sal.pc = pc; | |
8488 | sal.section = find_pc_overlay (pc); | |
8489 | sal.explicit_pc = 1; | |
8490 | ||
a6d9a66e | 8491 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8492 | } |
c906108c | 8493 | \f |
c5aa993b | 8494 | |
c906108c SS |
8495 | /* Tell the user we have just set a breakpoint B. */ |
8496 | ||
8497 | static void | |
fba45db2 | 8498 | mention (struct breakpoint *b) |
c906108c | 8499 | { |
348d480f | 8500 | b->ops->print_mention (b); |
2d33446d | 8501 | current_uiout->text ("\n"); |
c906108c | 8502 | } |
c906108c | 8503 | \f |
c5aa993b | 8504 | |
5133a315 | 8505 | static bool bp_loc_is_permanent (struct bp_location *loc); |
1a853c52 | 8506 | |
7f32a4d5 PA |
8507 | /* Handle "set breakpoint auto-hw on". |
8508 | ||
8509 | If the explicitly specified breakpoint type is not hardware | |
8510 | breakpoint, check the memory map to see whether the breakpoint | |
8511 | address is in read-only memory. | |
8512 | ||
8513 | - location type is not hardware breakpoint, memory is read-only. | |
8514 | We change the type of the location to hardware breakpoint. | |
8515 | ||
8516 | - location type is hardware breakpoint, memory is read-write. This | |
8517 | means we've previously made the location hardware one, but then the | |
8518 | memory map changed, so we undo. | |
8519 | */ | |
8520 | ||
8521 | static void | |
8522 | handle_automatic_hardware_breakpoints (bp_location *bl) | |
8523 | { | |
8524 | if (automatic_hardware_breakpoints | |
8525 | && bl->owner->type != bp_hardware_breakpoint | |
8526 | && (bl->loc_type == bp_loc_software_breakpoint | |
8527 | || bl->loc_type == bp_loc_hardware_breakpoint)) | |
8528 | { | |
8529 | /* When breakpoints are removed, remove_breakpoints will use | |
8530 | location types we've just set here, the only possible problem | |
8531 | is that memory map has changed during running program, but | |
8532 | it's not going to work anyway with current gdb. */ | |
8533 | mem_region *mr = lookup_mem_region (bl->address); | |
8534 | ||
8535 | if (mr != nullptr) | |
8536 | { | |
8537 | enum bp_loc_type new_type; | |
8538 | ||
8539 | if (mr->attrib.mode != MEM_RW) | |
8540 | new_type = bp_loc_hardware_breakpoint; | |
8541 | else | |
8542 | new_type = bp_loc_software_breakpoint; | |
8543 | ||
8544 | if (new_type != bl->loc_type) | |
8545 | { | |
8546 | static bool said = false; | |
8547 | ||
8548 | bl->loc_type = new_type; | |
8549 | if (!said) | |
8550 | { | |
8551 | fprintf_filtered (gdb_stdout, | |
8552 | _("Note: automatically using " | |
8553 | "hardware breakpoints for " | |
8554 | "read-only addresses.\n")); | |
8555 | said = true; | |
8556 | } | |
8557 | } | |
8558 | } | |
8559 | } | |
8560 | } | |
8561 | ||
0d381245 | 8562 | static struct bp_location * |
39d61571 | 8563 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8564 | const struct symtab_and_line *sal) |
8565 | { | |
8566 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8567 | CORE_ADDR adjusted_address; |
8568 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8569 | ||
8570 | if (loc_gdbarch == NULL) | |
8571 | loc_gdbarch = b->gdbarch; | |
8572 | ||
8573 | /* Adjust the breakpoint's address prior to allocating a location. | |
8574 | Once we call allocate_bp_location(), that mostly uninitialized | |
8575 | location will be placed on the location chain. Adjustment of the | |
8576 | breakpoint may cause target_read_memory() to be called and we do | |
8577 | not want its scan of the location chain to find a breakpoint and | |
8578 | location that's only been partially initialized. */ | |
8579 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8580 | sal->pc, b->type); | |
0d381245 | 8581 | |
d30113d4 | 8582 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8583 | loc = allocate_bp_location (b); |
d30113d4 JK |
8584 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8585 | tmp = &((*tmp)->next)) | |
0d381245 | 8586 | ; |
d30113d4 | 8587 | loc->next = *tmp; |
0d381245 | 8588 | *tmp = loc; |
3742cc8b | 8589 | |
0d381245 | 8590 | loc->requested_address = sal->pc; |
3742cc8b | 8591 | loc->address = adjusted_address; |
6c95b8df | 8592 | loc->pspace = sal->pspace; |
935676c9 | 8593 | loc->probe.prob = sal->prob; |
729662a5 | 8594 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8595 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8596 | loc->section = sal->section; |
3742cc8b | 8597 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8598 | loc->line_number = sal->line; |
2f202fde | 8599 | loc->symtab = sal->symtab; |
4a27f119 | 8600 | loc->symbol = sal->symbol; |
3467ec66 PA |
8601 | loc->msymbol = sal->msymbol; |
8602 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8603 | |
0ba852ab | 8604 | set_breakpoint_location_function (loc); |
1a853c52 | 8605 | |
6ae88661 LM |
8606 | /* While by definition, permanent breakpoints are already present in the |
8607 | code, we don't mark the location as inserted. Normally one would expect | |
8608 | that GDB could rely on that breakpoint instruction to stop the program, | |
8609 | thus removing the need to insert its own breakpoint, except that executing | |
8610 | the breakpoint instruction can kill the target instead of reporting a | |
8611 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8612 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8613 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8614 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8615 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8616 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8617 | it manually increments the PC, thus avoiding executing the breakpoint | |
8618 | instruction.) */ | |
1a853c52 | 8619 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8620 | loc->permanent = 1; |
1a853c52 | 8621 | |
0d381245 VP |
8622 | return loc; |
8623 | } | |
514f746b AR |
8624 | \f |
8625 | ||
5133a315 LM |
8626 | /* Return true if LOC is pointing to a permanent breakpoint, |
8627 | return false otherwise. */ | |
1cf4d951 | 8628 | |
5133a315 | 8629 | static bool |
1cf4d951 PA |
8630 | bp_loc_is_permanent (struct bp_location *loc) |
8631 | { | |
514f746b AR |
8632 | gdb_assert (loc != NULL); |
8633 | ||
cb1e4e32 PA |
8634 | /* If we have a non-breakpoint-backed catchpoint or a software |
8635 | watchpoint, just return 0. We should not attempt to read from | |
8636 | the addresses the locations of these breakpoint types point to. | |
5133a315 | 8637 | gdbarch_program_breakpoint_here_p, below, will attempt to read |
244558af | 8638 | memory. */ |
cb1e4e32 | 8639 | if (!bl_address_is_meaningful (loc)) |
5133a315 | 8640 | return false; |
244558af | 8641 | |
5ed8105e | 8642 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8643 | switch_to_program_space_and_thread (loc->pspace); |
5133a315 | 8644 | return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8645 | } |
8646 | ||
e7e0cddf SS |
8647 | /* Build a command list for the dprintf corresponding to the current |
8648 | settings of the dprintf style options. */ | |
8649 | ||
8650 | static void | |
8651 | update_dprintf_command_list (struct breakpoint *b) | |
8652 | { | |
8653 | char *dprintf_args = b->extra_string; | |
8654 | char *printf_line = NULL; | |
8655 | ||
8656 | if (!dprintf_args) | |
8657 | return; | |
8658 | ||
8659 | dprintf_args = skip_spaces (dprintf_args); | |
8660 | ||
8661 | /* Allow a comma, as it may have terminated a location, but don't | |
8662 | insist on it. */ | |
8663 | if (*dprintf_args == ',') | |
8664 | ++dprintf_args; | |
8665 | dprintf_args = skip_spaces (dprintf_args); | |
8666 | ||
8667 | if (*dprintf_args != '"') | |
8668 | error (_("Bad format string, missing '\"'.")); | |
8669 | ||
d3ce09f5 | 8670 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8671 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8672 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8673 | { |
8674 | if (!dprintf_function) | |
8675 | error (_("No function supplied for dprintf call")); | |
8676 | ||
8677 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8678 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8679 | dprintf_function, | |
8680 | dprintf_channel, | |
8681 | dprintf_args); | |
8682 | else | |
8683 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8684 | dprintf_function, | |
8685 | dprintf_args); | |
8686 | } | |
d3ce09f5 SS |
8687 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8688 | { | |
8689 | if (target_can_run_breakpoint_commands ()) | |
8690 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8691 | else | |
8692 | { | |
8693 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8694 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8695 | } | |
8696 | } | |
e7e0cddf SS |
8697 | else |
8698 | internal_error (__FILE__, __LINE__, | |
8699 | _("Invalid dprintf style.")); | |
8700 | ||
f28045c2 | 8701 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8702 | |
12973681 TT |
8703 | /* Manufacture a printf sequence. */ |
8704 | struct command_line *printf_cmd_line | |
8705 | = new struct command_line (simple_control, printf_line); | |
8706 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, | |
8707 | command_lines_deleter ())); | |
e7e0cddf SS |
8708 | } |
8709 | ||
8710 | /* Update all dprintf commands, making their command lists reflect | |
8711 | current style settings. */ | |
8712 | ||
8713 | static void | |
eb4c3f4a | 8714 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8715 | struct cmd_list_element *c) |
8716 | { | |
8717 | struct breakpoint *b; | |
8718 | ||
8719 | ALL_BREAKPOINTS (b) | |
8720 | { | |
8721 | if (b->type == bp_dprintf) | |
8722 | update_dprintf_command_list (b); | |
8723 | } | |
8724 | } | |
c3f6f71d | 8725 | |
f00aae0f KS |
8726 | /* Create a breakpoint with SAL as location. Use LOCATION |
8727 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8728 | as condition expression. If LOCATION is NULL then create an |
8729 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8730 | |
8731 | static void | |
d9b3f62e | 8732 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8733 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8734 | event_location_up &&location, |
e1e01040 PA |
8735 | gdb::unique_xmalloc_ptr<char> filter, |
8736 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8737 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8738 | enum bptype type, enum bpdisp disposition, |
8739 | int thread, int task, int ignore_count, | |
c0a91b2b | 8740 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8741 | int enabled, int internal, unsigned flags, |
8742 | int display_canonical) | |
018d34a4 | 8743 | { |
0d381245 | 8744 | int i; |
018d34a4 VP |
8745 | |
8746 | if (type == bp_hardware_breakpoint) | |
8747 | { | |
fbbd034e AS |
8748 | int target_resources_ok; |
8749 | ||
8750 | i = hw_breakpoint_used_count (); | |
8751 | target_resources_ok = | |
8752 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8753 | i + 1, 0); |
8754 | if (target_resources_ok == 0) | |
8755 | error (_("No hardware breakpoint support in the target.")); | |
8756 | else if (target_resources_ok < 0) | |
8757 | error (_("Hardware breakpoints used exceeds limit.")); | |
8758 | } | |
8759 | ||
6c5b2ebe | 8760 | gdb_assert (!sals.empty ()); |
6c95b8df | 8761 | |
6c5b2ebe | 8762 | for (const auto &sal : sals) |
0d381245 | 8763 | { |
0d381245 VP |
8764 | struct bp_location *loc; |
8765 | ||
8766 | if (from_tty) | |
5af949e3 UW |
8767 | { |
8768 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8769 | if (!loc_gdbarch) | |
8770 | loc_gdbarch = gdbarch; | |
8771 | ||
8772 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8773 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8774 | } |
0d381245 | 8775 | |
6c5b2ebe | 8776 | if (&sal == &sals[0]) |
0d381245 | 8777 | { |
d9b3f62e | 8778 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8779 | b->thread = thread; |
4a306c9a | 8780 | b->task = task; |
855a6e68 | 8781 | |
e1e01040 PA |
8782 | b->cond_string = cond_string.release (); |
8783 | b->extra_string = extra_string.release (); | |
0d381245 | 8784 | b->ignore_count = ignore_count; |
41447f92 | 8785 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8786 | b->disposition = disposition; |
6c95b8df | 8787 | |
44f238bb PA |
8788 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8789 | b->loc->inserted = 1; | |
8790 | ||
0fb4aa4b PA |
8791 | if (type == bp_static_tracepoint) |
8792 | { | |
d9b3f62e | 8793 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8794 | struct static_tracepoint_marker marker; |
8795 | ||
983af33b | 8796 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8797 | { |
8798 | /* We already know the marker exists, otherwise, we | |
8799 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8800 | const char *p |
8801 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8802 | const char *endp; |
0fb4aa4b | 8803 | |
f1735a53 | 8804 | p = skip_spaces (p); |
0fb4aa4b | 8805 | |
f1735a53 | 8806 | endp = skip_to_space (p); |
0fb4aa4b | 8807 | |
5d9310c4 | 8808 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8809 | |
3e43a32a MS |
8810 | printf_filtered (_("Probed static tracepoint " |
8811 | "marker \"%s\"\n"), | |
5d9310c4 | 8812 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8813 | } |
8814 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8815 | { | |
5d9310c4 | 8816 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8817 | |
3e43a32a MS |
8818 | printf_filtered (_("Probed static tracepoint " |
8819 | "marker \"%s\"\n"), | |
5d9310c4 | 8820 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8821 | } |
8822 | else | |
3e43a32a MS |
8823 | warning (_("Couldn't determine the static " |
8824 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8825 | } |
8826 | ||
0d381245 VP |
8827 | loc = b->loc; |
8828 | } | |
8829 | else | |
018d34a4 | 8830 | { |
39d61571 | 8831 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8832 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8833 | loc->inserted = 1; | |
0d381245 VP |
8834 | } |
8835 | ||
8836 | if (b->cond_string) | |
8837 | { | |
bbc13ae3 KS |
8838 | const char *arg = b->cond_string; |
8839 | ||
1bb9788d TT |
8840 | loc->cond = parse_exp_1 (&arg, loc->address, |
8841 | block_for_pc (loc->address), 0); | |
0d381245 | 8842 | if (*arg) |
588ae58c | 8843 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 8844 | } |
e7e0cddf SS |
8845 | |
8846 | /* Dynamic printf requires and uses additional arguments on the | |
8847 | command line, otherwise it's an error. */ | |
8848 | if (type == bp_dprintf) | |
8849 | { | |
8850 | if (b->extra_string) | |
8851 | update_dprintf_command_list (b); | |
8852 | else | |
8853 | error (_("Format string required")); | |
8854 | } | |
8855 | else if (b->extra_string) | |
588ae58c | 8856 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 8857 | } |
018d34a4 | 8858 | |
56435ebe | 8859 | b->display_canonical = display_canonical; |
f00aae0f | 8860 | if (location != NULL) |
d28cd78a | 8861 | b->location = std::move (location); |
018d34a4 | 8862 | else |
d28cd78a | 8863 | b->location = new_address_location (b->loc->address, NULL, 0); |
c0e8dcd8 | 8864 | b->filter = std::move (filter); |
d9b3f62e | 8865 | } |
018d34a4 | 8866 | |
d9b3f62e PA |
8867 | static void |
8868 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 8869 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8870 | event_location_up &&location, |
e1e01040 PA |
8871 | gdb::unique_xmalloc_ptr<char> filter, |
8872 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8873 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8874 | enum bptype type, enum bpdisp disposition, |
8875 | int thread, int task, int ignore_count, | |
c0a91b2b | 8876 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8877 | int enabled, int internal, unsigned flags, |
8878 | int display_canonical) | |
d9b3f62e | 8879 | { |
a5e364af | 8880 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 8881 | |
a5e364af | 8882 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 8883 | sals, std::move (location), |
e1e01040 PA |
8884 | std::move (filter), |
8885 | std::move (cond_string), | |
8886 | std::move (extra_string), | |
d9b3f62e PA |
8887 | type, disposition, |
8888 | thread, task, ignore_count, | |
8889 | ops, from_tty, | |
44f238bb PA |
8890 | enabled, internal, flags, |
8891 | display_canonical); | |
d9b3f62e | 8892 | |
b270e6f9 | 8893 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
8894 | } |
8895 | ||
8896 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8897 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8898 | value. COND_STRING, if not NULL, specified the condition to be | |
8899 | used for all breakpoints. Essentially the only case where | |
8900 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8901 | function. In that case, it's still not possible to specify | |
8902 | separate conditions for different overloaded functions, so | |
8903 | we take just a single condition string. | |
8904 | ||
c3f6f71d | 8905 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8906 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8907 | array contents). If the function fails (error() is called), the |
8908 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8909 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8910 | |
8911 | static void | |
8cdf0e15 | 8912 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8913 | struct linespec_result *canonical, |
e1e01040 PA |
8914 | gdb::unique_xmalloc_ptr<char> cond_string, |
8915 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
8916 | enum bptype type, enum bpdisp disposition, |
8917 | int thread, int task, int ignore_count, | |
c0a91b2b | 8918 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8919 | int enabled, int internal, unsigned flags) |
c906108c | 8920 | { |
f8eba3c6 | 8921 | if (canonical->pre_expanded) |
6c5b2ebe | 8922 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 8923 | |
6c5b2ebe | 8924 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 8925 | { |
f00aae0f | 8926 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 8927 | 'break', without arguments. */ |
ffc2605c | 8928 | event_location_up location |
f00aae0f | 8929 | = (canonical->location != NULL |
8e9e35b1 | 8930 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 8931 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 8932 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 8933 | |
6c5b2ebe | 8934 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 8935 | std::move (location), |
e1e01040 PA |
8936 | std::move (filter_string), |
8937 | std::move (cond_string), | |
8938 | std::move (extra_string), | |
e7e0cddf | 8939 | type, disposition, |
84f4c1fe | 8940 | thread, task, ignore_count, ops, |
44f238bb | 8941 | from_tty, enabled, internal, flags, |
56435ebe | 8942 | canonical->special_display); |
c3f6f71d | 8943 | } |
c3f6f71d | 8944 | } |
c906108c | 8945 | |
f00aae0f | 8946 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 8947 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
8948 | addresses found. LOCATION points to the end of the SAL (for |
8949 | linespec locations). | |
9998af43 TJB |
8950 | |
8951 | The array and the line spec strings are allocated on the heap, it is | |
8952 | the caller's responsibility to free them. */ | |
c906108c | 8953 | |
b9362cc7 | 8954 | static void |
f00aae0f | 8955 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 8956 | struct linespec_result *canonical) |
c3f6f71d | 8957 | { |
f00aae0f KS |
8958 | struct symtab_and_line cursal; |
8959 | ||
8960 | if (event_location_type (location) == LINESPEC_LOCATION) | |
8961 | { | |
a20714ff | 8962 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 8963 | |
a20714ff | 8964 | if (spec == NULL) |
f00aae0f KS |
8965 | { |
8966 | /* The last displayed codepoint, if it's valid, is our default | |
8967 | breakpoint address. */ | |
8968 | if (last_displayed_sal_is_valid ()) | |
8969 | { | |
f00aae0f KS |
8970 | /* Set sal's pspace, pc, symtab, and line to the values |
8971 | corresponding to the last call to print_frame_info. | |
8972 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
8973 | as the breakpoint line number is inappropriate otherwise. | |
8974 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
8975 | symtab_and_line sal = get_last_displayed_sal (); |
8976 | CORE_ADDR pc = sal.pc; | |
8977 | ||
f00aae0f KS |
8978 | sal = find_pc_line (pc, 0); |
8979 | ||
8980 | /* "break" without arguments is equivalent to "break *PC" | |
8981 | where PC is the last displayed codepoint's address. So | |
8982 | make sure to set sal.explicit_pc to prevent GDB from | |
8983 | trying to expand the list of sals to include all other | |
8984 | instances with the same symtab and line. */ | |
8985 | sal.pc = pc; | |
8986 | sal.explicit_pc = 1; | |
8987 | ||
6c5b2ebe PA |
8988 | struct linespec_sals lsal; |
8989 | lsal.sals = {sal}; | |
f00aae0f KS |
8990 | lsal.canonical = NULL; |
8991 | ||
6c5b2ebe | 8992 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
8993 | return; |
8994 | } | |
8995 | else | |
8996 | error (_("No default breakpoint address now.")); | |
c906108c | 8997 | } |
c906108c | 8998 | } |
f00aae0f KS |
8999 | |
9000 | /* Force almost all breakpoints to be in terms of the | |
9001 | current_source_symtab (which is decode_line_1's default). | |
9002 | This should produce the results we want almost all of the | |
9003 | time while leaving default_breakpoint_* alone. | |
9004 | ||
9005 | ObjC: However, don't match an Objective-C method name which | |
9006 | may have a '+' or '-' succeeded by a '['. */ | |
9007 | cursal = get_current_source_symtab_and_line (); | |
9008 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9009 | { |
a20714ff | 9010 | const char *spec = NULL; |
cc80f267 | 9011 | |
f00aae0f | 9012 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 9013 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 9014 | |
f00aae0f | 9015 | if (!cursal.symtab |
a20714ff PA |
9016 | || (spec != NULL |
9017 | && strchr ("+-", spec[0]) != NULL | |
9018 | && spec[1] != '[')) | |
f00aae0f | 9019 | { |
c2f4122d | 9020 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9021 | get_last_displayed_symtab (), |
9022 | get_last_displayed_line (), | |
9023 | canonical, NULL, NULL); | |
9024 | return; | |
9025 | } | |
c906108c | 9026 | } |
f00aae0f | 9027 | |
c2f4122d | 9028 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9029 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9030 | } |
c906108c | 9031 | |
c906108c | 9032 | |
c3f6f71d | 9033 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9034 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9035 | |
b9362cc7 | 9036 | static void |
6c5b2ebe | 9037 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9038 | { |
6c5b2ebe PA |
9039 | for (auto &sal : sals) |
9040 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9041 | } |
9042 | ||
7a697b8d SS |
9043 | /* Fast tracepoints may have restrictions on valid locations. For |
9044 | instance, a fast tracepoint using a jump instead of a trap will | |
9045 | likely have to overwrite more bytes than a trap would, and so can | |
9046 | only be placed where the instruction is longer than the jump, or a | |
9047 | multi-instruction sequence does not have a jump into the middle of | |
9048 | it, etc. */ | |
9049 | ||
9050 | static void | |
9051 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9052 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9053 | { |
6c5b2ebe | 9054 | for (const auto &sal : sals) |
7a697b8d | 9055 | { |
f8eba3c6 TT |
9056 | struct gdbarch *sarch; |
9057 | ||
6c5b2ebe | 9058 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9059 | /* We fall back to GDBARCH if there is no architecture |
9060 | associated with SAL. */ | |
9061 | if (sarch == NULL) | |
9062 | sarch = gdbarch; | |
281d762b TT |
9063 | std::string msg; |
9064 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 9065 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 9066 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
9067 | } |
9068 | } | |
9069 | ||
018d34a4 VP |
9070 | /* Given TOK, a string specification of condition and thread, as |
9071 | accepted by the 'break' command, extract the condition | |
9072 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9073 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9074 | If no condition is found, *COND_STRING is set to NULL. |
9075 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9076 | |
9077 | static void | |
bbc13ae3 | 9078 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9079 | char **cond_string, int *thread, int *task, |
9080 | char **rest) | |
018d34a4 VP |
9081 | { |
9082 | *cond_string = NULL; | |
9083 | *thread = -1; | |
ed1d1739 KS |
9084 | *task = 0; |
9085 | *rest = NULL; | |
9086 | ||
018d34a4 VP |
9087 | while (tok && *tok) |
9088 | { | |
bbc13ae3 | 9089 | const char *end_tok; |
018d34a4 | 9090 | int toklen; |
bbc13ae3 KS |
9091 | const char *cond_start = NULL; |
9092 | const char *cond_end = NULL; | |
cc59ec59 | 9093 | |
f1735a53 | 9094 | tok = skip_spaces (tok); |
e7e0cddf SS |
9095 | |
9096 | if ((*tok == '"' || *tok == ',') && rest) | |
9097 | { | |
9098 | *rest = savestring (tok, strlen (tok)); | |
9099 | return; | |
9100 | } | |
9101 | ||
f1735a53 | 9102 | end_tok = skip_to_space (tok); |
d634f2de | 9103 | |
018d34a4 | 9104 | toklen = end_tok - tok; |
d634f2de | 9105 | |
018d34a4 VP |
9106 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9107 | { | |
9108 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9109 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9110 | cond_end = tok; |
d634f2de | 9111 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9112 | } |
9113 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9114 | { | |
5d5658a1 PA |
9115 | const char *tmptok; |
9116 | struct thread_info *thr; | |
d634f2de | 9117 | |
018d34a4 | 9118 | tok = end_tok + 1; |
5d5658a1 | 9119 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9120 | if (tok == tmptok) |
9121 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9122 | *thread = thr->global_num; |
bbc13ae3 | 9123 | tok = tmptok; |
018d34a4 | 9124 | } |
4a306c9a JB |
9125 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9126 | { | |
9127 | char *tmptok; | |
9128 | ||
9129 | tok = end_tok + 1; | |
bbc13ae3 | 9130 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9131 | if (tok == tmptok) |
9132 | error (_("Junk after task keyword.")); | |
9133 | if (!valid_task_id (*task)) | |
b6199126 | 9134 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9135 | tok = tmptok; |
4a306c9a | 9136 | } |
e7e0cddf SS |
9137 | else if (rest) |
9138 | { | |
9139 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9140 | return; |
e7e0cddf | 9141 | } |
018d34a4 VP |
9142 | else |
9143 | error (_("Junk at end of arguments.")); | |
9144 | } | |
9145 | } | |
9146 | ||
0fb4aa4b PA |
9147 | /* Decode a static tracepoint marker spec. */ |
9148 | ||
6c5b2ebe | 9149 | static std::vector<symtab_and_line> |
f00aae0f | 9150 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 9151 | { |
f00aae0f KS |
9152 | const char *p = &(*arg_p)[3]; |
9153 | const char *endp; | |
0fb4aa4b | 9154 | |
f1735a53 | 9155 | p = skip_spaces (p); |
0fb4aa4b | 9156 | |
f1735a53 | 9157 | endp = skip_to_space (p); |
0fb4aa4b | 9158 | |
81b1e71c | 9159 | std::string marker_str (p, endp - p); |
0fb4aa4b | 9160 | |
5d9310c4 SM |
9161 | std::vector<static_tracepoint_marker> markers |
9162 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
9163 | if (markers.empty ()) | |
81b1e71c TT |
9164 | error (_("No known static tracepoint marker named %s"), |
9165 | marker_str.c_str ()); | |
0fb4aa4b | 9166 | |
6c5b2ebe | 9167 | std::vector<symtab_and_line> sals; |
5d9310c4 | 9168 | sals.reserve (markers.size ()); |
0fb4aa4b | 9169 | |
5d9310c4 | 9170 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 9171 | { |
5d9310c4 SM |
9172 | symtab_and_line sal = find_pc_line (marker.address, 0); |
9173 | sal.pc = marker.address; | |
6c5b2ebe | 9174 | sals.push_back (sal); |
5d9310c4 | 9175 | } |
0fb4aa4b | 9176 | |
0fb4aa4b PA |
9177 | *arg_p = endp; |
9178 | return sals; | |
9179 | } | |
9180 | ||
bac7c5cf GB |
9181 | /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and |
9182 | according to IS_TRACEPOINT. */ | |
9183 | ||
9184 | static const struct breakpoint_ops * | |
9185 | breakpoint_ops_for_event_location_type (enum event_location_type location_type, | |
9186 | bool is_tracepoint) | |
9187 | { | |
9188 | if (is_tracepoint) | |
9189 | { | |
9190 | if (location_type == PROBE_LOCATION) | |
9191 | return &tracepoint_probe_breakpoint_ops; | |
9192 | else | |
9193 | return &tracepoint_breakpoint_ops; | |
9194 | } | |
9195 | else | |
9196 | { | |
9197 | if (location_type == PROBE_LOCATION) | |
9198 | return &bkpt_probe_breakpoint_ops; | |
9199 | else | |
9200 | return &bkpt_breakpoint_ops; | |
9201 | } | |
9202 | } | |
9203 | ||
9204 | /* See breakpoint.h. */ | |
9205 | ||
9206 | const struct breakpoint_ops * | |
9207 | breakpoint_ops_for_event_location (const struct event_location *location, | |
9208 | bool is_tracepoint) | |
9209 | { | |
9210 | if (location != nullptr) | |
9211 | return breakpoint_ops_for_event_location_type | |
9212 | (event_location_type (location), is_tracepoint); | |
9213 | return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; | |
9214 | } | |
9215 | ||
f00aae0f | 9216 | /* See breakpoint.h. */ |
0101ce28 | 9217 | |
8cdf0e15 VP |
9218 | int |
9219 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9220 | const struct event_location *location, |
9221 | const char *cond_string, | |
9222 | int thread, const char *extra_string, | |
f00aae0f | 9223 | int parse_extra, |
0fb4aa4b | 9224 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9225 | int ignore_count, |
9226 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9227 | const struct breakpoint_ops *ops, |
44f238bb PA |
9228 | int from_tty, int enabled, int internal, |
9229 | unsigned flags) | |
c3f6f71d | 9230 | { |
7efd8fc2 | 9231 | struct linespec_result canonical; |
0101ce28 | 9232 | int pending = 0; |
4a306c9a | 9233 | int task = 0; |
86b17b60 | 9234 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9235 | |
348d480f PA |
9236 | gdb_assert (ops != NULL); |
9237 | ||
f00aae0f KS |
9238 | /* If extra_string isn't useful, set it to NULL. */ |
9239 | if (extra_string != NULL && *extra_string == '\0') | |
9240 | extra_string = NULL; | |
9241 | ||
a70b8144 | 9242 | try |
b78a6381 | 9243 | { |
f00aae0f | 9244 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9245 | } |
230d2906 | 9246 | catch (const gdb_exception_error &e) |
0101ce28 | 9247 | { |
492d29ea PA |
9248 | /* If caller is interested in rc value from parse, set |
9249 | value. */ | |
9250 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9251 | { |
05ff989b AC |
9252 | /* If pending breakpoint support is turned off, throw |
9253 | error. */ | |
fa8d40ab JJ |
9254 | |
9255 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 9256 | throw; |
723a2275 VP |
9257 | |
9258 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9259 | |
05ff989b AC |
9260 | /* If pending breakpoint support is auto query and the user |
9261 | selects no, then simply return the error code. */ | |
059fb39f | 9262 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9263 | && !nquery (_("Make %s pending on future shared library load? "), |
9264 | bptype_string (type_wanted))) | |
fd9b8c24 | 9265 | return 0; |
fa8d40ab | 9266 | |
05ff989b AC |
9267 | /* At this point, either the user was queried about setting |
9268 | a pending breakpoint and selected yes, or pending | |
9269 | breakpoint behavior is on and thus a pending breakpoint | |
9270 | is defaulted on behalf of the user. */ | |
f00aae0f | 9271 | pending = 1; |
0101ce28 | 9272 | } |
492d29ea | 9273 | else |
eedc3f4f | 9274 | throw; |
0101ce28 | 9275 | } |
492d29ea | 9276 | |
6c5b2ebe | 9277 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9278 | return 0; |
c3f6f71d | 9279 | |
c3f6f71d JM |
9280 | /* Resolve all line numbers to PC's and verify that the addresses |
9281 | are ok for the target. */ | |
0101ce28 | 9282 | if (!pending) |
f8eba3c6 | 9283 | { |
6c5b2ebe PA |
9284 | for (auto &lsal : canonical.lsals) |
9285 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9286 | } |
c3f6f71d | 9287 | |
7a697b8d | 9288 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9289 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9290 | { |
6c5b2ebe PA |
9291 | for (const auto &lsal : canonical.lsals) |
9292 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9293 | } |
7a697b8d | 9294 | |
c3f6f71d JM |
9295 | /* Verify that condition can be parsed, before setting any |
9296 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9297 | breakpoint. */ |
0101ce28 | 9298 | if (!pending) |
c3f6f71d | 9299 | { |
e1e01040 PA |
9300 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9301 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9302 | ||
f00aae0f | 9303 | if (parse_extra) |
72b2ff0e | 9304 | { |
0878d0fa | 9305 | char *rest; |
e1e01040 | 9306 | char *cond; |
52d361e1 | 9307 | |
6c5b2ebe | 9308 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9309 | |
0878d0fa YQ |
9310 | /* Here we only parse 'arg' to separate condition |
9311 | from thread number, so parsing in context of first | |
9312 | sal is OK. When setting the breakpoint we'll | |
9313 | re-parse it in context of each sal. */ | |
9314 | ||
6c5b2ebe | 9315 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9316 | &cond, &thread, &task, &rest); |
9317 | cond_string_copy.reset (cond); | |
9318 | extra_string_copy.reset (rest); | |
72b2ff0e | 9319 | } |
2f069f6f | 9320 | else |
72b2ff0e | 9321 | { |
f00aae0f KS |
9322 | if (type_wanted != bp_dprintf |
9323 | && extra_string != NULL && *extra_string != '\0') | |
9324 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9325 | |
9326 | /* Create a private copy of condition string. */ | |
9327 | if (cond_string) | |
e1e01040 | 9328 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9329 | /* Create a private copy of any extra string. */ |
9330 | if (extra_string) | |
e1e01040 | 9331 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9332 | } |
0fb4aa4b | 9333 | |
52d361e1 | 9334 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9335 | std::move (cond_string_copy), |
9336 | std::move (extra_string_copy), | |
9337 | type_wanted, | |
d9b3f62e PA |
9338 | tempflag ? disp_del : disp_donttouch, |
9339 | thread, task, ignore_count, ops, | |
44f238bb | 9340 | from_tty, enabled, internal, flags); |
c906108c | 9341 | } |
0101ce28 JJ |
9342 | else |
9343 | { | |
a5e364af | 9344 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9345 | |
a5e364af | 9346 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9347 | b->location = copy_event_location (location); |
bfccc43c | 9348 | |
f00aae0f KS |
9349 | if (parse_extra) |
9350 | b->cond_string = NULL; | |
e12c7713 MK |
9351 | else |
9352 | { | |
9353 | /* Create a private copy of condition string. */ | |
e1e01040 | 9354 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9355 | b->thread = thread; |
e12c7713 | 9356 | } |
f00aae0f KS |
9357 | |
9358 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9359 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9360 | b->ignore_count = ignore_count; |
0101ce28 | 9361 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9362 | b->condition_not_parsed = 1; |
41447f92 | 9363 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9364 | if ((type_wanted != bp_breakpoint |
9365 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9366 | b->pspace = current_program_space; |
8bea4e01 | 9367 | |
b270e6f9 | 9368 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9369 | } |
9370 | ||
6c5b2ebe | 9371 | if (canonical.lsals.size () > 1) |
95a42b64 | 9372 | { |
3e43a32a MS |
9373 | warning (_("Multiple breakpoints were set.\nUse the " |
9374 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9375 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9376 | } |
9377 | ||
44702360 | 9378 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9379 | |
9380 | return 1; | |
c3f6f71d | 9381 | } |
c906108c | 9382 | |
348d480f | 9383 | /* Set a breakpoint. |
72b2ff0e VP |
9384 | ARG is a string describing breakpoint address, |
9385 | condition, and thread. | |
9386 | FLAG specifies if a breakpoint is hardware on, | |
9387 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9388 | and BP_TEMPFLAG. */ | |
348d480f | 9389 | |
98deb0da | 9390 | static void |
f2fc3015 | 9391 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9392 | { |
72b2ff0e | 9393 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9394 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9395 | ? bp_hardware_breakpoint | |
9396 | : bp_breakpoint); | |
f00aae0f | 9397 | |
ffc2605c | 9398 | event_location_up location = string_to_event_location (&arg, current_language); |
bac7c5cf GB |
9399 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
9400 | (location.get (), false /* is_tracepoint */); | |
c3f6f71d | 9401 | |
8cdf0e15 | 9402 | create_breakpoint (get_current_arch (), |
ffc2605c | 9403 | location.get (), |
f00aae0f | 9404 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9405 | tempflag, type_wanted, |
8cdf0e15 VP |
9406 | 0 /* Ignore count */, |
9407 | pending_break_support, | |
55aa24fb | 9408 | ops, |
8cdf0e15 | 9409 | from_tty, |
84f4c1fe | 9410 | 1 /* enabled */, |
44f238bb PA |
9411 | 0 /* internal */, |
9412 | 0); | |
c906108c SS |
9413 | } |
9414 | ||
c906108c SS |
9415 | /* Helper function for break_command_1 and disassemble_command. */ |
9416 | ||
9417 | void | |
fba45db2 | 9418 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9419 | { |
9420 | CORE_ADDR pc; | |
9421 | ||
9422 | if (sal->pc == 0 && sal->symtab != NULL) | |
9423 | { | |
9424 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9425 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9426 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9427 | sal->pc = pc; |
6a048695 | 9428 | |
4a64f543 MS |
9429 | /* If this SAL corresponds to a breakpoint inserted using a line |
9430 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9431 | if (sal->explicit_line) |
059acae7 | 9432 | skip_prologue_sal (sal); |
c906108c SS |
9433 | } |
9434 | ||
9435 | if (sal->section == 0 && sal->symtab != NULL) | |
9436 | { | |
346d1dfe | 9437 | const struct blockvector *bv; |
3977b71f | 9438 | const struct block *b; |
c5aa993b | 9439 | struct symbol *sym; |
c906108c | 9440 | |
43f3e411 DE |
9441 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9442 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9443 | if (bv != NULL) |
9444 | { | |
7f0df278 | 9445 | sym = block_linkage_function (b); |
c906108c SS |
9446 | if (sym != NULL) |
9447 | { | |
eb822aa6 DE |
9448 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9449 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9450 | sym); | |
c906108c SS |
9451 | } |
9452 | else | |
9453 | { | |
4a64f543 MS |
9454 | /* It really is worthwhile to have the section, so we'll |
9455 | just have to look harder. This case can be executed | |
9456 | if we have line numbers but no functions (as can | |
9457 | happen in assembly source). */ | |
c906108c | 9458 | |
5ed8105e | 9459 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9460 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9461 | |
5ed8105e | 9462 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9463 | if (msym.minsym) |
efd66ac6 | 9464 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9465 | } |
9466 | } | |
9467 | } | |
9468 | } | |
9469 | ||
9470 | void | |
0b39b52e | 9471 | break_command (const char *arg, int from_tty) |
c906108c | 9472 | { |
db107f19 | 9473 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9474 | } |
9475 | ||
c906108c | 9476 | void |
0b39b52e | 9477 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9478 | { |
db107f19 | 9479 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9480 | } |
9481 | ||
c906108c | 9482 | static void |
0b39b52e | 9483 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9484 | { |
db107f19 | 9485 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9486 | } |
9487 | ||
9488 | static void | |
0b39b52e | 9489 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9490 | { |
db107f19 | 9491 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9492 | } |
9493 | ||
9494 | static void | |
ee7ddd71 | 9495 | stop_command (const char *arg, int from_tty) |
c906108c | 9496 | { |
a3f17187 | 9497 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9498 | Usage: stop in <function | address>\n\ |
a3f17187 | 9499 | stop at <line>\n")); |
c906108c SS |
9500 | } |
9501 | ||
9502 | static void | |
4495129a | 9503 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9504 | { |
9505 | int badInput = 0; | |
9506 | ||
cafb3438 | 9507 | if (arg == NULL) |
c906108c SS |
9508 | badInput = 1; |
9509 | else if (*arg != '*') | |
9510 | { | |
4495129a | 9511 | const char *argptr = arg; |
c906108c SS |
9512 | int hasColon = 0; |
9513 | ||
4a64f543 | 9514 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9515 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9516 | function/method name. */ |
c906108c | 9517 | while (*argptr && !hasColon) |
c5aa993b JM |
9518 | { |
9519 | hasColon = (*argptr == ':'); | |
9520 | argptr++; | |
9521 | } | |
c906108c SS |
9522 | |
9523 | if (hasColon) | |
c5aa993b | 9524 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9525 | else |
c5aa993b | 9526 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9527 | } |
9528 | ||
9529 | if (badInput) | |
a3f17187 | 9530 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9531 | else |
db107f19 | 9532 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9533 | } |
9534 | ||
9535 | static void | |
4495129a | 9536 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9537 | { |
9538 | int badInput = 0; | |
9539 | ||
cafb3438 | 9540 | if (arg == NULL || *arg == '*') /* no line number */ |
c906108c SS |
9541 | badInput = 1; |
9542 | else | |
9543 | { | |
4495129a | 9544 | const char *argptr = arg; |
c906108c SS |
9545 | int hasColon = 0; |
9546 | ||
4a64f543 MS |
9547 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9548 | it is probably a line number. */ | |
c906108c | 9549 | while (*argptr && !hasColon) |
c5aa993b JM |
9550 | { |
9551 | hasColon = (*argptr == ':'); | |
9552 | argptr++; | |
9553 | } | |
c906108c SS |
9554 | |
9555 | if (hasColon) | |
c5aa993b | 9556 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9557 | else |
c5aa993b | 9558 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9559 | } |
9560 | ||
9561 | if (badInput) | |
65e65158 | 9562 | printf_filtered (_("Usage: stop at LINE\n")); |
c906108c | 9563 | else |
db107f19 | 9564 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9565 | } |
9566 | ||
e7e0cddf SS |
9567 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9568 | with a prewired command list consisting of a single output command, | |
9569 | built from extra arguments supplied on the dprintf command | |
9570 | line. */ | |
9571 | ||
da821c7b | 9572 | static void |
0b39b52e | 9573 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9574 | { |
ffc2605c | 9575 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9576 | |
9577 | /* If non-NULL, ARG should have been advanced past the location; | |
9578 | the next character must be ','. */ | |
9579 | if (arg != NULL) | |
9580 | { | |
9581 | if (arg[0] != ',' || arg[1] == '\0') | |
9582 | error (_("Format string required")); | |
9583 | else | |
9584 | { | |
9585 | /* Skip the comma. */ | |
9586 | ++arg; | |
9587 | } | |
9588 | } | |
9589 | ||
e7e0cddf | 9590 | create_breakpoint (get_current_arch (), |
ffc2605c | 9591 | location.get (), |
f00aae0f | 9592 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9593 | 0, bp_dprintf, |
9594 | 0 /* Ignore count */, | |
9595 | pending_break_support, | |
9596 | &dprintf_breakpoint_ops, | |
9597 | from_tty, | |
9598 | 1 /* enabled */, | |
9599 | 0 /* internal */, | |
9600 | 0); | |
9601 | } | |
9602 | ||
d3ce09f5 | 9603 | static void |
0b39b52e | 9604 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9605 | { |
9606 | error (_("May only run agent-printf on the target")); | |
9607 | } | |
9608 | ||
f1310107 TJB |
9609 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9610 | ranged breakpoints. */ | |
9611 | ||
9612 | static int | |
9613 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9614 | const address_space *aspace, |
09ac7c10 TT |
9615 | CORE_ADDR bp_addr, |
9616 | const struct target_waitstatus *ws) | |
f1310107 | 9617 | { |
09ac7c10 | 9618 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9619 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9620 | return 0; |
9621 | ||
f1310107 TJB |
9622 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9623 | bl->length, aspace, bp_addr); | |
9624 | } | |
9625 | ||
9626 | /* Implement the "resources_needed" breakpoint_ops method for | |
9627 | ranged breakpoints. */ | |
9628 | ||
9629 | static int | |
9630 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9631 | { | |
9632 | return target_ranged_break_num_registers (); | |
9633 | } | |
9634 | ||
9635 | /* Implement the "print_it" breakpoint_ops method for | |
9636 | ranged breakpoints. */ | |
9637 | ||
9638 | static enum print_stop_action | |
348d480f | 9639 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9640 | { |
348d480f | 9641 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9642 | struct bp_location *bl = b->loc; |
79a45e25 | 9643 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9644 | |
9645 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9646 | ||
9647 | /* Ranged breakpoints have only one location. */ | |
9648 | gdb_assert (bl && bl->next == NULL); | |
9649 | ||
9650 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9651 | |
9652 | maybe_print_thread_hit_breakpoint (uiout); | |
9653 | ||
f1310107 | 9654 | if (b->disposition == disp_del) |
112e8700 | 9655 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9656 | else |
112e8700 SM |
9657 | uiout->text ("Ranged breakpoint "); |
9658 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9659 | { |
112e8700 | 9660 | uiout->field_string ("reason", |
f1310107 | 9661 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9662 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9663 | } |
381befee | 9664 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 9665 | uiout->text (", "); |
f1310107 TJB |
9666 | |
9667 | return PRINT_SRC_AND_LOC; | |
9668 | } | |
9669 | ||
9670 | /* Implement the "print_one" breakpoint_ops method for | |
9671 | ranged breakpoints. */ | |
9672 | ||
9673 | static void | |
9674 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9675 | struct bp_location **last_loc) | |
9676 | { | |
9677 | struct bp_location *bl = b->loc; | |
9678 | struct value_print_options opts; | |
79a45e25 | 9679 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9680 | |
9681 | /* Ranged breakpoints have only one location. */ | |
9682 | gdb_assert (bl && bl->next == NULL); | |
9683 | ||
9684 | get_user_print_options (&opts); | |
9685 | ||
9686 | if (opts.addressprint) | |
9687 | /* We don't print the address range here, it will be printed later | |
9688 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9689 | uiout->field_skip ("addr"); |
f1310107 TJB |
9690 | annotate_field (5); |
9691 | print_breakpoint_location (b, bl); | |
9692 | *last_loc = bl; | |
9693 | } | |
9694 | ||
9695 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9696 | ranged breakpoints. */ | |
9697 | ||
9698 | static void | |
9699 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9700 | struct ui_out *uiout) | |
9701 | { | |
9702 | CORE_ADDR address_start, address_end; | |
9703 | struct bp_location *bl = b->loc; | |
d7e74731 | 9704 | string_file stb; |
f1310107 TJB |
9705 | |
9706 | gdb_assert (bl); | |
9707 | ||
9708 | address_start = bl->address; | |
9709 | address_end = address_start + bl->length - 1; | |
9710 | ||
112e8700 | 9711 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9712 | stb.printf ("[%s, %s]", |
9713 | print_core_address (bl->gdbarch, address_start), | |
9714 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9715 | uiout->field_stream ("addr", stb); |
9716 | uiout->text ("\n"); | |
f1310107 TJB |
9717 | } |
9718 | ||
9719 | /* Implement the "print_mention" breakpoint_ops method for | |
9720 | ranged breakpoints. */ | |
9721 | ||
9722 | static void | |
9723 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9724 | { | |
9725 | struct bp_location *bl = b->loc; | |
79a45e25 | 9726 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9727 | |
9728 | gdb_assert (bl); | |
9729 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9730 | ||
2d33446d TT |
9731 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
9732 | b->number, paddress (bl->gdbarch, bl->address), | |
9733 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
f1310107 TJB |
9734 | } |
9735 | ||
9736 | /* Implement the "print_recreate" breakpoint_ops method for | |
9737 | ranged breakpoints. */ | |
9738 | ||
9739 | static void | |
9740 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9741 | { | |
f00aae0f | 9742 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9743 | event_location_to_string (b->location.get ()), |
9744 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9745 | print_recreate_thread (b, fp); |
f1310107 TJB |
9746 | } |
9747 | ||
9748 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9749 | ||
2060206e | 9750 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9751 | |
9752 | /* Find the address where the end of the breakpoint range should be | |
9753 | placed, given the SAL of the end of the range. This is so that if | |
9754 | the user provides a line number, the end of the range is set to the | |
9755 | last instruction of the given line. */ | |
9756 | ||
9757 | static CORE_ADDR | |
9758 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9759 | { | |
9760 | CORE_ADDR end; | |
9761 | ||
9762 | /* If the user provided a PC value, use it. Otherwise, | |
9763 | find the address of the end of the given location. */ | |
9764 | if (sal.explicit_pc) | |
9765 | end = sal.pc; | |
9766 | else | |
9767 | { | |
9768 | int ret; | |
9769 | CORE_ADDR start; | |
9770 | ||
9771 | ret = find_line_pc_range (sal, &start, &end); | |
9772 | if (!ret) | |
9773 | error (_("Could not find location of the end of the range.")); | |
9774 | ||
9775 | /* find_line_pc_range returns the start of the next line. */ | |
9776 | end--; | |
9777 | } | |
9778 | ||
9779 | return end; | |
9780 | } | |
9781 | ||
9782 | /* Implement the "break-range" CLI command. */ | |
9783 | ||
9784 | static void | |
0b39b52e | 9785 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9786 | { |
f2fc3015 | 9787 | const char *arg_start; |
f1310107 TJB |
9788 | struct linespec_result canonical_start, canonical_end; |
9789 | int bp_count, can_use_bp, length; | |
9790 | CORE_ADDR end; | |
9791 | struct breakpoint *b; | |
f1310107 TJB |
9792 | |
9793 | /* We don't support software ranged breakpoints. */ | |
9794 | if (target_ranged_break_num_registers () < 0) | |
9795 | error (_("This target does not support hardware ranged breakpoints.")); | |
9796 | ||
9797 | bp_count = hw_breakpoint_used_count (); | |
9798 | bp_count += target_ranged_break_num_registers (); | |
9799 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9800 | bp_count, 0); | |
9801 | if (can_use_bp < 0) | |
9802 | error (_("Hardware breakpoints used exceeds limit.")); | |
9803 | ||
f8eba3c6 | 9804 | arg = skip_spaces (arg); |
f1310107 TJB |
9805 | if (arg == NULL || arg[0] == '\0') |
9806 | error(_("No address range specified.")); | |
9807 | ||
f8eba3c6 | 9808 | arg_start = arg; |
ffc2605c TT |
9809 | event_location_up start_location = string_to_event_location (&arg, |
9810 | current_language); | |
9811 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
9812 | |
9813 | if (arg[0] != ',') | |
9814 | error (_("Too few arguments.")); | |
6c5b2ebe | 9815 | else if (canonical_start.lsals.empty ()) |
f1310107 | 9816 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 9817 | |
6c5b2ebe | 9818 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 9819 | |
6c5b2ebe PA |
9820 | if (canonical_start.lsals.size () > 1 |
9821 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
9822 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9823 | ||
6c5b2ebe | 9824 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 9825 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
9826 | |
9827 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9828 | arg = skip_spaces (arg); |
f1310107 TJB |
9829 | |
9830 | /* Parse the end location. */ | |
9831 | ||
f1310107 TJB |
9832 | arg_start = arg; |
9833 | ||
f8eba3c6 | 9834 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9835 | parse_breakpoint_sals because we need to specify the start location's |
9836 | symtab and line as the default symtab and line for the end of the | |
9837 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9838 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
9839 | event_location_up end_location = string_to_event_location (&arg, |
9840 | current_language); | |
9841 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
9842 | sal_start.symtab, sal_start.line, |
9843 | &canonical_end, NULL, NULL); | |
9844 | ||
6c5b2ebe | 9845 | if (canonical_end.lsals.empty ()) |
f1310107 | 9846 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 9847 | |
6c5b2ebe PA |
9848 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
9849 | if (canonical_end.lsals.size () > 1 | |
9850 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
9851 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9852 | ||
6c5b2ebe | 9853 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
9854 | |
9855 | end = find_breakpoint_range_end (sal_end); | |
9856 | if (sal_start.pc > end) | |
177b42fe | 9857 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9858 | |
9859 | length = end - sal_start.pc + 1; | |
9860 | if (length < 0) | |
9861 | /* Length overflowed. */ | |
9862 | error (_("Address range too large.")); | |
9863 | else if (length == 1) | |
9864 | { | |
9865 | /* This range is simple enough to be handled by | |
9866 | the `hbreak' command. */ | |
81b1e71c | 9867 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
9868 | |
9869 | return; | |
9870 | } | |
9871 | ||
9872 | /* Now set up the breakpoint. */ | |
9873 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9874 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9875 | set_breakpoint_count (breakpoint_count + 1); |
9876 | b->number = breakpoint_count; | |
9877 | b->disposition = disp_donttouch; | |
d28cd78a TT |
9878 | b->location = std::move (start_location); |
9879 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
9880 | b->loc->length = length; |
9881 | ||
f1310107 | 9882 | mention (b); |
76727919 | 9883 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 9884 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
9885 | } |
9886 | ||
4a64f543 MS |
9887 | /* Return non-zero if EXP is verified as constant. Returned zero |
9888 | means EXP is variable. Also the constant detection may fail for | |
9889 | some constant expressions and in such case still falsely return | |
9890 | zero. */ | |
2e6e3d9c | 9891 | |
65d79d4b SDJ |
9892 | static int |
9893 | watchpoint_exp_is_const (const struct expression *exp) | |
9894 | { | |
9895 | int i = exp->nelts; | |
9896 | ||
9897 | while (i > 0) | |
9898 | { | |
9899 | int oplenp, argsp; | |
9900 | ||
9901 | /* We are only interested in the descriptor of each element. */ | |
9902 | operator_length (exp, i, &oplenp, &argsp); | |
9903 | i -= oplenp; | |
9904 | ||
9905 | switch (exp->elts[i].opcode) | |
9906 | { | |
9907 | case BINOP_ADD: | |
9908 | case BINOP_SUB: | |
9909 | case BINOP_MUL: | |
9910 | case BINOP_DIV: | |
9911 | case BINOP_REM: | |
9912 | case BINOP_MOD: | |
9913 | case BINOP_LSH: | |
9914 | case BINOP_RSH: | |
9915 | case BINOP_LOGICAL_AND: | |
9916 | case BINOP_LOGICAL_OR: | |
9917 | case BINOP_BITWISE_AND: | |
9918 | case BINOP_BITWISE_IOR: | |
9919 | case BINOP_BITWISE_XOR: | |
9920 | case BINOP_EQUAL: | |
9921 | case BINOP_NOTEQUAL: | |
9922 | case BINOP_LESS: | |
9923 | case BINOP_GTR: | |
9924 | case BINOP_LEQ: | |
9925 | case BINOP_GEQ: | |
9926 | case BINOP_REPEAT: | |
9927 | case BINOP_COMMA: | |
9928 | case BINOP_EXP: | |
9929 | case BINOP_MIN: | |
9930 | case BINOP_MAX: | |
9931 | case BINOP_INTDIV: | |
9932 | case BINOP_CONCAT: | |
65d79d4b SDJ |
9933 | case TERNOP_COND: |
9934 | case TERNOP_SLICE: | |
65d79d4b SDJ |
9935 | |
9936 | case OP_LONG: | |
edd079d9 | 9937 | case OP_FLOAT: |
65d79d4b SDJ |
9938 | case OP_LAST: |
9939 | case OP_COMPLEX: | |
9940 | case OP_STRING: | |
65d79d4b SDJ |
9941 | case OP_ARRAY: |
9942 | case OP_TYPE: | |
608b4967 TT |
9943 | case OP_TYPEOF: |
9944 | case OP_DECLTYPE: | |
6e72ca20 | 9945 | case OP_TYPEID: |
65d79d4b SDJ |
9946 | case OP_NAME: |
9947 | case OP_OBJC_NSSTRING: | |
9948 | ||
9949 | case UNOP_NEG: | |
9950 | case UNOP_LOGICAL_NOT: | |
9951 | case UNOP_COMPLEMENT: | |
9952 | case UNOP_ADDR: | |
9953 | case UNOP_HIGH: | |
aeaa2474 | 9954 | case UNOP_CAST: |
9eaf6705 TT |
9955 | |
9956 | case UNOP_CAST_TYPE: | |
9957 | case UNOP_REINTERPRET_CAST: | |
9958 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
9959 | /* Unary, binary and ternary operators: We have to check |
9960 | their operands. If they are constant, then so is the | |
9961 | result of that operation. For instance, if A and B are | |
9962 | determined to be constants, then so is "A + B". | |
9963 | ||
9964 | UNOP_IND is one exception to the rule above, because the | |
9965 | value of *ADDR is not necessarily a constant, even when | |
9966 | ADDR is. */ | |
65d79d4b SDJ |
9967 | break; |
9968 | ||
9969 | case OP_VAR_VALUE: | |
9970 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 9971 | |
65d79d4b | 9972 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
9973 | possible that a buggy compiler could mark a variable as |
9974 | constant even when it is not, and TYPE_CONST would return | |
9975 | true in this case, while SYMBOL_CLASS wouldn't. | |
9976 | ||
9977 | We also have to check for function symbols because they | |
9978 | are always constant. */ | |
65d79d4b SDJ |
9979 | { |
9980 | struct symbol *s = exp->elts[i + 2].symbol; | |
9981 | ||
9982 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
9983 | && SYMBOL_CLASS (s) != LOC_CONST | |
9984 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
9985 | return 0; | |
9986 | break; | |
9987 | } | |
9988 | ||
9989 | /* The default action is to return 0 because we are using | |
9990 | the optimistic approach here: If we don't know something, | |
9991 | then it is not a constant. */ | |
9992 | default: | |
9993 | return 0; | |
9994 | } | |
9995 | } | |
9996 | ||
9997 | return 1; | |
9998 | } | |
9999 | ||
c1fc2657 | 10000 | /* Watchpoint destructor. */ |
3a5c3e22 | 10001 | |
c1fc2657 | 10002 | watchpoint::~watchpoint () |
3a5c3e22 | 10003 | { |
c1fc2657 SM |
10004 | xfree (this->exp_string); |
10005 | xfree (this->exp_string_reparse); | |
3a5c3e22 PA |
10006 | } |
10007 | ||
348d480f PA |
10008 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10009 | ||
10010 | static void | |
10011 | re_set_watchpoint (struct breakpoint *b) | |
10012 | { | |
3a5c3e22 PA |
10013 | struct watchpoint *w = (struct watchpoint *) b; |
10014 | ||
348d480f PA |
10015 | /* Watchpoint can be either on expression using entirely global |
10016 | variables, or it can be on local variables. | |
10017 | ||
10018 | Watchpoints of the first kind are never auto-deleted, and even | |
10019 | persist across program restarts. Since they can use variables | |
10020 | from shared libraries, we need to reparse expression as libraries | |
10021 | are loaded and unloaded. | |
10022 | ||
10023 | Watchpoints on local variables can also change meaning as result | |
10024 | of solib event. For example, if a watchpoint uses both a local | |
10025 | and a global variables in expression, it's a local watchpoint, | |
10026 | but unloading of a shared library will make the expression | |
10027 | invalid. This is not a very common use case, but we still | |
10028 | re-evaluate expression, to avoid surprises to the user. | |
10029 | ||
10030 | Note that for local watchpoints, we re-evaluate it only if | |
10031 | watchpoints frame id is still valid. If it's not, it means the | |
10032 | watchpoint is out of scope and will be deleted soon. In fact, | |
10033 | I'm not sure we'll ever be called in this case. | |
10034 | ||
10035 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10036 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10037 | |
3a5c3e22 PA |
10038 | Don't do anything about disabled watchpoints, since they will be |
10039 | reevaluated again when enabled. */ | |
10040 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10041 | } |
10042 | ||
77b06cd7 TJB |
10043 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10044 | ||
10045 | static int | |
10046 | insert_watchpoint (struct bp_location *bl) | |
10047 | { | |
3a5c3e22 PA |
10048 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10049 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10050 | |
10051 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10052 | w->cond_exp.get ()); |
77b06cd7 TJB |
10053 | } |
10054 | ||
10055 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10056 | ||
10057 | static int | |
73971819 | 10058 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10059 | { |
3a5c3e22 PA |
10060 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10061 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10062 | |
10063 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10064 | w->cond_exp.get ()); |
e09342b5 TJB |
10065 | } |
10066 | ||
e09342b5 | 10067 | static int |
348d480f | 10068 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 10069 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 10070 | const struct target_waitstatus *ws) |
e09342b5 | 10071 | { |
348d480f | 10072 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10073 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10074 | |
348d480f PA |
10075 | /* Continuable hardware watchpoints are treated as non-existent if the |
10076 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10077 | some data address). Otherwise gdb won't stop on a break instruction | |
10078 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10079 | been defined. Also skip watchpoints which we know did not trigger | |
10080 | (did not match the data address). */ | |
10081 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10082 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10083 | return 0; |
9c06b0b4 | 10084 | |
348d480f | 10085 | return 1; |
9c06b0b4 TJB |
10086 | } |
10087 | ||
348d480f PA |
10088 | static void |
10089 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10090 | { |
348d480f | 10091 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10092 | |
348d480f | 10093 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10094 | } |
10095 | ||
10096 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10097 | hardware watchpoints. */ |
9c06b0b4 TJB |
10098 | |
10099 | static int | |
348d480f | 10100 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10101 | { |
3a5c3e22 PA |
10102 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10103 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10104 | |
10105 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10106 | } |
10107 | ||
10108 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10109 | hardware watchpoints. */ |
9c06b0b4 TJB |
10110 | |
10111 | static int | |
348d480f | 10112 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10113 | { |
efa80663 PA |
10114 | /* Read and access watchpoints only work with hardware support. */ |
10115 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10116 | } |
10117 | ||
9c06b0b4 | 10118 | static enum print_stop_action |
348d480f | 10119 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10120 | { |
348d480f | 10121 | struct breakpoint *b; |
348d480f | 10122 | enum print_stop_action result; |
3a5c3e22 | 10123 | struct watchpoint *w; |
79a45e25 | 10124 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10125 | |
10126 | gdb_assert (bs->bp_location_at != NULL); | |
10127 | ||
348d480f | 10128 | b = bs->breakpoint_at; |
3a5c3e22 | 10129 | w = (struct watchpoint *) b; |
348d480f | 10130 | |
f303dbd6 PA |
10131 | annotate_watchpoint (b->number); |
10132 | maybe_print_thread_hit_breakpoint (uiout); | |
10133 | ||
d7e74731 PA |
10134 | string_file stb; |
10135 | ||
76f9c9cf | 10136 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10137 | switch (b->type) |
10138 | { | |
348d480f | 10139 | case bp_watchpoint: |
9c06b0b4 | 10140 | case bp_hardware_watchpoint: |
112e8700 SM |
10141 | if (uiout->is_mi_like_p ()) |
10142 | uiout->field_string | |
10143 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10144 | mention (b); |
76f9c9cf | 10145 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10146 | uiout->text ("\nOld value = "); |
850645cf | 10147 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10148 | uiout->field_stream ("old", stb); |
10149 | uiout->text ("\nNew value = "); | |
850645cf | 10150 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10151 | uiout->field_stream ("new", stb); |
10152 | uiout->text ("\n"); | |
348d480f PA |
10153 | /* More than one watchpoint may have been triggered. */ |
10154 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10155 | break; |
10156 | ||
10157 | case bp_read_watchpoint: | |
112e8700 SM |
10158 | if (uiout->is_mi_like_p ()) |
10159 | uiout->field_string | |
10160 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10161 | mention (b); |
76f9c9cf | 10162 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10163 | uiout->text ("\nValue = "); |
850645cf | 10164 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10165 | uiout->field_stream ("value", stb); |
10166 | uiout->text ("\n"); | |
348d480f | 10167 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10168 | break; |
10169 | ||
10170 | case bp_access_watchpoint: | |
348d480f PA |
10171 | if (bs->old_val != NULL) |
10172 | { | |
112e8700 SM |
10173 | if (uiout->is_mi_like_p ()) |
10174 | uiout->field_string | |
10175 | ("reason", | |
348d480f PA |
10176 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10177 | mention (b); | |
76f9c9cf | 10178 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10179 | uiout->text ("\nOld value = "); |
850645cf | 10180 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10181 | uiout->field_stream ("old", stb); |
10182 | uiout->text ("\nNew value = "); | |
348d480f PA |
10183 | } |
10184 | else | |
10185 | { | |
10186 | mention (b); | |
112e8700 SM |
10187 | if (uiout->is_mi_like_p ()) |
10188 | uiout->field_string | |
10189 | ("reason", | |
348d480f | 10190 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10191 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10192 | uiout->text ("\nValue = "); |
348d480f | 10193 | } |
850645cf | 10194 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10195 | uiout->field_stream ("new", stb); |
10196 | uiout->text ("\n"); | |
348d480f | 10197 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10198 | break; |
10199 | default: | |
348d480f | 10200 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10201 | } |
10202 | ||
348d480f PA |
10203 | return result; |
10204 | } | |
10205 | ||
10206 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10207 | watchpoints. */ | |
10208 | ||
10209 | static void | |
10210 | print_mention_watchpoint (struct breakpoint *b) | |
10211 | { | |
3a5c3e22 | 10212 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10213 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10214 | const char *tuple_name; |
348d480f PA |
10215 | |
10216 | switch (b->type) | |
10217 | { | |
10218 | case bp_watchpoint: | |
112e8700 | 10219 | uiout->text ("Watchpoint "); |
46b9c129 | 10220 | tuple_name = "wpt"; |
348d480f PA |
10221 | break; |
10222 | case bp_hardware_watchpoint: | |
112e8700 | 10223 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10224 | tuple_name = "wpt"; |
348d480f PA |
10225 | break; |
10226 | case bp_read_watchpoint: | |
112e8700 | 10227 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10228 | tuple_name = "hw-rwpt"; |
348d480f PA |
10229 | break; |
10230 | case bp_access_watchpoint: | |
112e8700 | 10231 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10232 | tuple_name = "hw-awpt"; |
348d480f PA |
10233 | break; |
10234 | default: | |
10235 | internal_error (__FILE__, __LINE__, | |
10236 | _("Invalid hardware watchpoint type.")); | |
10237 | } | |
10238 | ||
46b9c129 | 10239 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10240 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10241 | uiout->text (": "); |
10242 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10243 | } |
10244 | ||
10245 | /* Implement the "print_recreate" breakpoint_ops method for | |
10246 | watchpoints. */ | |
10247 | ||
10248 | static void | |
10249 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10250 | { | |
3a5c3e22 PA |
10251 | struct watchpoint *w = (struct watchpoint *) b; |
10252 | ||
348d480f PA |
10253 | switch (b->type) |
10254 | { | |
10255 | case bp_watchpoint: | |
10256 | case bp_hardware_watchpoint: | |
10257 | fprintf_unfiltered (fp, "watch"); | |
10258 | break; | |
10259 | case bp_read_watchpoint: | |
10260 | fprintf_unfiltered (fp, "rwatch"); | |
10261 | break; | |
10262 | case bp_access_watchpoint: | |
10263 | fprintf_unfiltered (fp, "awatch"); | |
10264 | break; | |
10265 | default: | |
10266 | internal_error (__FILE__, __LINE__, | |
10267 | _("Invalid watchpoint type.")); | |
10268 | } | |
10269 | ||
3a5c3e22 | 10270 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10271 | print_recreate_thread (b, fp); |
348d480f PA |
10272 | } |
10273 | ||
427cd150 TT |
10274 | /* Implement the "explains_signal" breakpoint_ops method for |
10275 | watchpoints. */ | |
10276 | ||
47591c29 | 10277 | static int |
427cd150 TT |
10278 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10279 | { | |
10280 | /* A software watchpoint cannot cause a signal other than | |
10281 | GDB_SIGNAL_TRAP. */ | |
10282 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10283 | return 0; |
427cd150 | 10284 | |
47591c29 | 10285 | return 1; |
427cd150 TT |
10286 | } |
10287 | ||
348d480f PA |
10288 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10289 | ||
2060206e | 10290 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10291 | |
10292 | /* Implement the "insert" breakpoint_ops method for | |
10293 | masked hardware watchpoints. */ | |
10294 | ||
10295 | static int | |
10296 | insert_masked_watchpoint (struct bp_location *bl) | |
10297 | { | |
3a5c3e22 PA |
10298 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10299 | ||
10300 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10301 | bl->watchpoint_type); |
10302 | } | |
10303 | ||
10304 | /* Implement the "remove" breakpoint_ops method for | |
10305 | masked hardware watchpoints. */ | |
10306 | ||
10307 | static int | |
73971819 | 10308 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10309 | { |
3a5c3e22 PA |
10310 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10311 | ||
10312 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10313 | bl->watchpoint_type); |
10314 | } | |
10315 | ||
10316 | /* Implement the "resources_needed" breakpoint_ops method for | |
10317 | masked hardware watchpoints. */ | |
10318 | ||
10319 | static int | |
10320 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10321 | { | |
3a5c3e22 PA |
10322 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10323 | ||
10324 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10325 | } |
10326 | ||
10327 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10328 | masked hardware watchpoints. */ | |
10329 | ||
10330 | static int | |
10331 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10332 | { | |
10333 | return 0; | |
10334 | } | |
10335 | ||
10336 | /* Implement the "print_it" breakpoint_ops method for | |
10337 | masked hardware watchpoints. */ | |
10338 | ||
10339 | static enum print_stop_action | |
10340 | print_it_masked_watchpoint (bpstat bs) | |
10341 | { | |
10342 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10343 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10344 | |
10345 | /* Masked watchpoints have only one location. */ | |
10346 | gdb_assert (b->loc && b->loc->next == NULL); | |
10347 | ||
f303dbd6 PA |
10348 | annotate_watchpoint (b->number); |
10349 | maybe_print_thread_hit_breakpoint (uiout); | |
10350 | ||
348d480f PA |
10351 | switch (b->type) |
10352 | { | |
10353 | case bp_hardware_watchpoint: | |
112e8700 SM |
10354 | if (uiout->is_mi_like_p ()) |
10355 | uiout->field_string | |
10356 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10357 | break; |
10358 | ||
10359 | case bp_read_watchpoint: | |
112e8700 SM |
10360 | if (uiout->is_mi_like_p ()) |
10361 | uiout->field_string | |
10362 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10363 | break; |
10364 | ||
10365 | case bp_access_watchpoint: | |
112e8700 SM |
10366 | if (uiout->is_mi_like_p ()) |
10367 | uiout->field_string | |
10368 | ("reason", | |
348d480f PA |
10369 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10370 | break; | |
10371 | default: | |
10372 | internal_error (__FILE__, __LINE__, | |
10373 | _("Invalid hardware watchpoint type.")); | |
10374 | } | |
10375 | ||
10376 | mention (b); | |
112e8700 | 10377 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10378 | Check the underlying instruction at PC for the memory\n\ |
10379 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10380 | uiout->text ("\n"); |
9c06b0b4 TJB |
10381 | |
10382 | /* More than one watchpoint may have been triggered. */ | |
10383 | return PRINT_UNKNOWN; | |
10384 | } | |
10385 | ||
10386 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10387 | masked hardware watchpoints. */ | |
10388 | ||
10389 | static void | |
10390 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10391 | struct ui_out *uiout) | |
10392 | { | |
3a5c3e22 PA |
10393 | struct watchpoint *w = (struct watchpoint *) b; |
10394 | ||
9c06b0b4 TJB |
10395 | /* Masked watchpoints have only one location. */ |
10396 | gdb_assert (b->loc && b->loc->next == NULL); | |
10397 | ||
112e8700 SM |
10398 | uiout->text ("\tmask "); |
10399 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10400 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10401 | } |
10402 | ||
10403 | /* Implement the "print_mention" breakpoint_ops method for | |
10404 | masked hardware watchpoints. */ | |
10405 | ||
10406 | static void | |
10407 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10408 | { | |
3a5c3e22 | 10409 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10410 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10411 | const char *tuple_name; |
9c06b0b4 TJB |
10412 | |
10413 | switch (b->type) | |
10414 | { | |
10415 | case bp_hardware_watchpoint: | |
112e8700 | 10416 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10417 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10418 | break; |
10419 | case bp_read_watchpoint: | |
112e8700 | 10420 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10421 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10422 | break; |
10423 | case bp_access_watchpoint: | |
112e8700 | 10424 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10425 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10426 | break; |
10427 | default: | |
10428 | internal_error (__FILE__, __LINE__, | |
10429 | _("Invalid hardware watchpoint type.")); | |
10430 | } | |
10431 | ||
46b9c129 | 10432 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10433 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10434 | uiout->text (": "); |
10435 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10436 | } |
10437 | ||
10438 | /* Implement the "print_recreate" breakpoint_ops method for | |
10439 | masked hardware watchpoints. */ | |
10440 | ||
10441 | static void | |
10442 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10443 | { | |
3a5c3e22 | 10444 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10445 | |
10446 | switch (b->type) | |
10447 | { | |
10448 | case bp_hardware_watchpoint: | |
10449 | fprintf_unfiltered (fp, "watch"); | |
10450 | break; | |
10451 | case bp_read_watchpoint: | |
10452 | fprintf_unfiltered (fp, "rwatch"); | |
10453 | break; | |
10454 | case bp_access_watchpoint: | |
10455 | fprintf_unfiltered (fp, "awatch"); | |
10456 | break; | |
10457 | default: | |
10458 | internal_error (__FILE__, __LINE__, | |
10459 | _("Invalid hardware watchpoint type.")); | |
10460 | } | |
10461 | ||
53807e9f TT |
10462 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, |
10463 | phex (w->hw_wp_mask, sizeof (CORE_ADDR))); | |
d9b3f62e | 10464 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10465 | } |
10466 | ||
10467 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10468 | ||
2060206e | 10469 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10470 | |
10471 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10472 | ||
f2478a7e | 10473 | static bool |
9c06b0b4 TJB |
10474 | is_masked_watchpoint (const struct breakpoint *b) |
10475 | { | |
10476 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10477 | } | |
10478 | ||
53a5351d JM |
10479 | /* accessflag: hw_write: watch write, |
10480 | hw_read: watch read, | |
10481 | hw_access: watch access (read or write) */ | |
c906108c | 10482 | static void |
bbc13ae3 | 10483 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10484 | int just_location, int internal) |
c906108c | 10485 | { |
c1fc2657 | 10486 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10487 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 10488 | struct value *result; |
bb9d5f81 | 10489 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10490 | const char *exp_start = NULL; |
10491 | const char *exp_end = NULL; | |
10492 | const char *tok, *end_tok; | |
9c06b0b4 | 10493 | int toklen = -1; |
bbc13ae3 KS |
10494 | const char *cond_start = NULL; |
10495 | const char *cond_end = NULL; | |
c906108c | 10496 | enum bptype bp_type; |
37e4754d | 10497 | int thread = -1; |
0cf6dd15 | 10498 | int pc = 0; |
9c06b0b4 TJB |
10499 | /* Flag to indicate whether we are going to use masks for |
10500 | the hardware watchpoint. */ | |
10501 | int use_mask = 0; | |
10502 | CORE_ADDR mask = 0; | |
c906108c | 10503 | |
37e4754d LM |
10504 | /* Make sure that we actually have parameters to parse. */ |
10505 | if (arg != NULL && arg[0] != '\0') | |
10506 | { | |
bbc13ae3 KS |
10507 | const char *value_start; |
10508 | ||
10509 | exp_end = arg + strlen (arg); | |
37e4754d | 10510 | |
9c06b0b4 TJB |
10511 | /* Look for "parameter value" pairs at the end |
10512 | of the arguments string. */ | |
bbc13ae3 | 10513 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10514 | { |
10515 | /* Skip whitespace at the end of the argument list. */ | |
10516 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10517 | tok--; | |
10518 | ||
10519 | /* Find the beginning of the last token. | |
10520 | This is the value of the parameter. */ | |
10521 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10522 | tok--; | |
10523 | value_start = tok + 1; | |
10524 | ||
10525 | /* Skip whitespace. */ | |
10526 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10527 | tok--; | |
10528 | ||
10529 | end_tok = tok; | |
10530 | ||
10531 | /* Find the beginning of the second to last token. | |
10532 | This is the parameter itself. */ | |
10533 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10534 | tok--; | |
10535 | tok++; | |
10536 | toklen = end_tok - tok + 1; | |
10537 | ||
61012eef | 10538 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10539 | { |
5d5658a1 | 10540 | struct thread_info *thr; |
9c06b0b4 TJB |
10541 | /* At this point we've found a "thread" token, which means |
10542 | the user is trying to set a watchpoint that triggers | |
10543 | only in a specific thread. */ | |
5d5658a1 | 10544 | const char *endp; |
37e4754d | 10545 | |
9c06b0b4 TJB |
10546 | if (thread != -1) |
10547 | error(_("You can specify only one thread.")); | |
37e4754d | 10548 | |
9c06b0b4 | 10549 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10550 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10551 | |
5d5658a1 | 10552 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10553 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10554 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10555 | |
5d5658a1 | 10556 | thread = thr->global_num; |
9c06b0b4 | 10557 | } |
61012eef | 10558 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10559 | { |
10560 | /* We've found a "mask" token, which means the user wants to | |
10561 | create a hardware watchpoint that is going to have the mask | |
10562 | facility. */ | |
10563 | struct value *mask_value, *mark; | |
37e4754d | 10564 | |
9c06b0b4 TJB |
10565 | if (use_mask) |
10566 | error(_("You can specify only one mask.")); | |
37e4754d | 10567 | |
9c06b0b4 | 10568 | use_mask = just_location = 1; |
37e4754d | 10569 | |
9c06b0b4 TJB |
10570 | mark = value_mark (); |
10571 | mask_value = parse_to_comma_and_eval (&value_start); | |
10572 | mask = value_as_address (mask_value); | |
10573 | value_free_to_mark (mark); | |
10574 | } | |
10575 | else | |
10576 | /* We didn't recognize what we found. We should stop here. */ | |
10577 | break; | |
37e4754d | 10578 | |
9c06b0b4 TJB |
10579 | /* Truncate the string and get rid of the "parameter value" pair before |
10580 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10581 | exp_end = tok; |
9c06b0b4 | 10582 | } |
37e4754d | 10583 | } |
bbc13ae3 KS |
10584 | else |
10585 | exp_end = arg; | |
37e4754d | 10586 | |
bbc13ae3 KS |
10587 | /* Parse the rest of the arguments. From here on out, everything |
10588 | is in terms of a newly allocated string instead of the original | |
10589 | ARG. */ | |
81b1e71c TT |
10590 | std::string expression (arg, exp_end - arg); |
10591 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10592 | innermost_block_tracker tracker; |
10593 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10594 | exp_end = arg; |
fa8a61dc TT |
10595 | /* Remove trailing whitespace from the expression before saving it. |
10596 | This makes the eventual display of the expression string a bit | |
10597 | prettier. */ | |
10598 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10599 | --exp_end; | |
10600 | ||
65d79d4b | 10601 | /* Checking if the expression is not constant. */ |
4d01a485 | 10602 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10603 | { |
10604 | int len; | |
10605 | ||
10606 | len = exp_end - exp_start; | |
10607 | while (len > 0 && isspace (exp_start[len - 1])) | |
10608 | len--; | |
10609 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10610 | } | |
10611 | ||
699bd4cf | 10612 | exp_valid_block = tracker.block (); |
b926417a | 10613 | struct value *mark = value_mark (); |
850645cf TT |
10614 | struct value *val_as_value = nullptr; |
10615 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, | |
10616 | just_location); | |
06a64a0b | 10617 | |
850645cf | 10618 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10619 | { |
850645cf TT |
10620 | saved_bitpos = value_bitpos (val_as_value); |
10621 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10622 | } |
10623 | ||
850645cf | 10624 | value_ref_ptr val; |
06a64a0b TT |
10625 | if (just_location) |
10626 | { | |
9c06b0b4 TJB |
10627 | int ret; |
10628 | ||
06a64a0b | 10629 | exp_valid_block = NULL; |
850645cf | 10630 | val = release_value (value_addr (result)); |
06a64a0b | 10631 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10632 | |
10633 | if (use_mask) | |
10634 | { | |
850645cf | 10635 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10636 | mask); |
10637 | if (ret == -1) | |
10638 | error (_("This target does not support masked watchpoints.")); | |
10639 | else if (ret == -2) | |
10640 | error (_("Invalid mask or memory region.")); | |
10641 | } | |
06a64a0b | 10642 | } |
850645cf TT |
10643 | else if (val_as_value != NULL) |
10644 | val = release_value (val_as_value); | |
c906108c | 10645 | |
f1735a53 TT |
10646 | tok = skip_spaces (arg); |
10647 | end_tok = skip_to_space (tok); | |
c906108c SS |
10648 | |
10649 | toklen = end_tok - tok; | |
10650 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10651 | { | |
10652 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10653 | innermost_block_tracker if_tracker; |
10654 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10655 | |
10656 | /* The watchpoint expression may not be local, but the condition | |
10657 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10658 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10659 | |
c906108c SS |
10660 | cond_end = tok; |
10661 | } | |
10662 | if (*tok) | |
8a3fe4f8 | 10663 | error (_("Junk at end of command.")); |
c906108c | 10664 | |
441d7c93 PA |
10665 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10666 | ||
10667 | /* Save this because create_internal_breakpoint below invalidates | |
10668 | 'wp_frame'. */ | |
10669 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10670 | |
10671 | /* If the expression is "local", then set up a "watchpoint scope" | |
10672 | breakpoint at the point where we've left the scope of the watchpoint | |
10673 | expression. Create the scope breakpoint before the watchpoint, so | |
10674 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10675 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10676 | { |
441d7c93 PA |
10677 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10678 | ||
10679 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10680 | { |
441d7c93 PA |
10681 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10682 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10683 | ||
edb3359d | 10684 | scope_breakpoint |
441d7c93 | 10685 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10686 | bp_watchpoint_scope, |
10687 | &momentary_breakpoint_ops); | |
d983da9c | 10688 | |
441d7c93 PA |
10689 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10690 | wp_frame = NULL; | |
10691 | ||
edb3359d | 10692 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10693 | |
edb3359d DJ |
10694 | /* Automatically delete the breakpoint when it hits. */ |
10695 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10696 | |
edb3359d | 10697 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10698 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10699 | |
edb3359d | 10700 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10701 | scope_breakpoint->loc->gdbarch = caller_arch; |
10702 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10703 | scope_breakpoint->loc->address |
a6d9a66e UW |
10704 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10705 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10706 | scope_breakpoint->type); |
10707 | } | |
d983da9c DJ |
10708 | } |
10709 | ||
e8369a73 AB |
10710 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10711 | watchpoints here even if hardware watchpoints are turned off, a call | |
10712 | to update_watchpoint later in this function will cause the type to | |
10713 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10714 | ||
10715 | if (accessflag == hw_read) | |
10716 | bp_type = bp_read_watchpoint; | |
10717 | else if (accessflag == hw_access) | |
10718 | bp_type = bp_access_watchpoint; | |
10719 | else | |
10720 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10721 | |
b270e6f9 | 10722 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10723 | |
348d480f | 10724 | if (use_mask) |
b270e6f9 | 10725 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10726 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10727 | else |
b270e6f9 | 10728 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10729 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10730 | w->thread = thread; |
10731 | w->disposition = disp_donttouch; | |
10732 | w->pspace = current_program_space; | |
b22e99fd | 10733 | w->exp = std::move (exp); |
3a5c3e22 PA |
10734 | w->exp_valid_block = exp_valid_block; |
10735 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10736 | if (just_location) |
10737 | { | |
850645cf TT |
10738 | struct type *t = value_type (val.get ()); |
10739 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10740 | |
43cc5389 | 10741 | w->exp_string_reparse |
f16a9f57 | 10742 | = current_language->watch_location_expression (t, addr).release (); |
06a64a0b | 10743 | |
3a5c3e22 | 10744 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 10745 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
10746 | } |
10747 | else | |
3a5c3e22 | 10748 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10749 | |
10750 | if (use_mask) | |
10751 | { | |
3a5c3e22 | 10752 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10753 | } |
10754 | else | |
10755 | { | |
3a5c3e22 | 10756 | w->val = val; |
bb9d5f81 PP |
10757 | w->val_bitpos = saved_bitpos; |
10758 | w->val_bitsize = saved_bitsize; | |
4c1d86d9 | 10759 | w->val_valid = true; |
9c06b0b4 | 10760 | } |
77b06cd7 | 10761 | |
c906108c | 10762 | if (cond_start) |
c1fc2657 | 10763 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 10764 | else |
c1fc2657 | 10765 | w->cond_string = 0; |
c5aa993b | 10766 | |
441d7c93 | 10767 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10768 | { |
441d7c93 | 10769 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10770 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10771 | } |
c906108c | 10772 | else |
f6bc2008 | 10773 | { |
3a5c3e22 PA |
10774 | w->watchpoint_frame = null_frame_id; |
10775 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10776 | } |
c906108c | 10777 | |
d983da9c | 10778 | if (scope_breakpoint != NULL) |
c906108c | 10779 | { |
d983da9c DJ |
10780 | /* The scope breakpoint is related to the watchpoint. We will |
10781 | need to act on them together. */ | |
c1fc2657 | 10782 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10783 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10784 | } |
d983da9c | 10785 | |
06a64a0b TT |
10786 | if (!just_location) |
10787 | value_free_to_mark (mark); | |
2d134ed3 | 10788 | |
b270e6f9 TT |
10789 | /* Finally update the new watchpoint. This creates the locations |
10790 | that should be inserted. */ | |
10791 | update_watchpoint (w.get (), 1); | |
a9634178 | 10792 | |
b270e6f9 | 10793 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10794 | } |
10795 | ||
e09342b5 | 10796 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10797 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10798 | |
c906108c | 10799 | static int |
a6535de1 | 10800 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
10801 | { |
10802 | int found_memory_cnt = 0; | |
10803 | ||
10804 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10805 | if (!can_use_hw_watchpoints) |
c906108c | 10806 | return 0; |
c5aa993b | 10807 | |
a6535de1 TT |
10808 | gdb_assert (!vals.empty ()); |
10809 | struct value *head = vals[0].get (); | |
10810 | ||
5c44784c JM |
10811 | /* Make sure that the value of the expression depends only upon |
10812 | memory contents, and values computed from them within GDB. If we | |
10813 | find any register references or function calls, we can't use a | |
10814 | hardware watchpoint. | |
10815 | ||
10816 | The idea here is that evaluating an expression generates a series | |
10817 | of values, one holding the value of every subexpression. (The | |
10818 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10819 | a*b+c.) GDB's values hold almost enough information to establish | |
10820 | the criteria given above --- they identify memory lvalues, | |
10821 | register lvalues, computed values, etcetera. So we can evaluate | |
10822 | the expression, and then scan the chain of values that leaves | |
10823 | behind to decide whether we can detect any possible change to the | |
10824 | expression's final value using only hardware watchpoints. | |
10825 | ||
10826 | However, I don't think that the values returned by inferior | |
10827 | function calls are special in any way. So this function may not | |
10828 | notice that an expression involving an inferior function call | |
10829 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 10830 | for (const value_ref_ptr &iter : vals) |
c906108c | 10831 | { |
a6535de1 TT |
10832 | struct value *v = iter.get (); |
10833 | ||
5c44784c | 10834 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10835 | { |
8464be76 DJ |
10836 | if (v != head && value_lazy (v)) |
10837 | /* A lazy memory lvalue in the chain is one that GDB never | |
10838 | needed to fetch; we either just used its address (e.g., | |
10839 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10840 | in `a,b'). This doesn't apply to HEAD; if that is | |
10841 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10842 | ; |
53a5351d | 10843 | else |
5c44784c JM |
10844 | { |
10845 | /* Ahh, memory we actually used! Check if we can cover | |
10846 | it with hardware watchpoints. */ | |
df407dfe | 10847 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10848 | |
10849 | /* We only watch structs and arrays if user asked for it | |
10850 | explicitly, never if they just happen to appear in a | |
10851 | middle of some value chain. */ | |
10852 | if (v == head | |
78134374 SM |
10853 | || (vtype->code () != TYPE_CODE_STRUCT |
10854 | && vtype->code () != TYPE_CODE_ARRAY)) | |
2e70b7b9 | 10855 | { |
42ae5230 | 10856 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10857 | int len; |
10858 | int num_regs; | |
10859 | ||
a9634178 | 10860 | len = (target_exact_watchpoints |
e09342b5 TJB |
10861 | && is_scalar_type_recursive (vtype))? |
10862 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10863 | |
e09342b5 TJB |
10864 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10865 | if (!num_regs) | |
2e70b7b9 MS |
10866 | return 0; |
10867 | else | |
e09342b5 | 10868 | found_memory_cnt += num_regs; |
2e70b7b9 | 10869 | } |
5c44784c | 10870 | } |
c5aa993b | 10871 | } |
5086187c AC |
10872 | else if (VALUE_LVAL (v) != not_lval |
10873 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10874 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10875 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10876 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10877 | } |
10878 | ||
10879 | /* The expression itself looks suitable for using a hardware | |
10880 | watchpoint, but give the target machine a chance to reject it. */ | |
10881 | return found_memory_cnt; | |
10882 | } | |
10883 | ||
8b93c638 | 10884 | void |
f2fc3015 | 10885 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10886 | { |
84f4c1fe | 10887 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10888 | } |
10889 | ||
06a64a0b TT |
10890 | /* A helper function that looks for the "-location" argument and then |
10891 | calls watch_command_1. */ | |
10892 | ||
10893 | static void | |
0b39b52e | 10894 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b TT |
10895 | { |
10896 | int just_location = 0; | |
10897 | ||
10898 | if (arg | |
10899 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
10900 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
cbba3ecd | 10901 | just_location = 1; |
06a64a0b | 10902 | |
84f4c1fe | 10903 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 10904 | } |
8926118c | 10905 | |
c5aa993b | 10906 | static void |
0b39b52e | 10907 | watch_command (const char *arg, int from_tty) |
c906108c | 10908 | { |
06a64a0b | 10909 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10910 | } |
10911 | ||
8b93c638 | 10912 | void |
f2fc3015 | 10913 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10914 | { |
84f4c1fe | 10915 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10916 | } |
8926118c | 10917 | |
c5aa993b | 10918 | static void |
0b39b52e | 10919 | rwatch_command (const char *arg, int from_tty) |
c906108c | 10920 | { |
06a64a0b | 10921 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10922 | } |
10923 | ||
8b93c638 | 10924 | void |
f2fc3015 | 10925 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10926 | { |
84f4c1fe | 10927 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10928 | } |
8926118c | 10929 | |
c5aa993b | 10930 | static void |
0b39b52e | 10931 | awatch_command (const char *arg, int from_tty) |
c906108c | 10932 | { |
06a64a0b | 10933 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10934 | } |
c906108c | 10935 | \f |
c5aa993b | 10936 | |
cfc31633 PA |
10937 | /* Data for the FSM that manages the until(location)/advance commands |
10938 | in infcmd.c. Here because it uses the mechanisms of | |
10939 | breakpoints. */ | |
c906108c | 10940 | |
46e3ed7f | 10941 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 10942 | { |
46e3ed7f | 10943 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
10944 | int thread; |
10945 | ||
10946 | /* The breakpoint set at the destination location. */ | |
46e3ed7f | 10947 | breakpoint_up location_breakpoint; |
cfc31633 PA |
10948 | |
10949 | /* Breakpoint set at the return address in the caller frame. May be | |
10950 | NULL. */ | |
46e3ed7f | 10951 | breakpoint_up caller_breakpoint; |
cfc31633 | 10952 | |
46e3ed7f TT |
10953 | until_break_fsm (struct interp *cmd_interp, int thread, |
10954 | breakpoint_up &&location_breakpoint, | |
10955 | breakpoint_up &&caller_breakpoint) | |
10956 | : thread_fsm (cmd_interp), | |
10957 | thread (thread), | |
10958 | location_breakpoint (std::move (location_breakpoint)), | |
10959 | caller_breakpoint (std::move (caller_breakpoint)) | |
10960 | { | |
10961 | } | |
cfc31633 | 10962 | |
46e3ed7f TT |
10963 | void clean_up (struct thread_info *thread) override; |
10964 | bool should_stop (struct thread_info *thread) override; | |
10965 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
10966 | }; |
10967 | ||
cfc31633 PA |
10968 | /* Implementation of the 'should_stop' FSM method for the |
10969 | until(location)/advance commands. */ | |
10970 | ||
46e3ed7f TT |
10971 | bool |
10972 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 10973 | { |
cfc31633 | 10974 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10975 | location_breakpoint.get ()) != NULL |
10976 | || (caller_breakpoint != NULL | |
cfc31633 | 10977 | && bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10978 | caller_breakpoint.get ()) != NULL)) |
10979 | set_finished (); | |
cfc31633 | 10980 | |
46e3ed7f | 10981 | return true; |
cfc31633 PA |
10982 | } |
10983 | ||
10984 | /* Implementation of the 'clean_up' FSM method for the | |
10985 | until(location)/advance commands. */ | |
10986 | ||
46e3ed7f TT |
10987 | void |
10988 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 10989 | { |
cfc31633 | 10990 | /* Clean up our temporary breakpoints. */ |
46e3ed7f TT |
10991 | location_breakpoint.reset (); |
10992 | caller_breakpoint.reset (); | |
10993 | delete_longjmp_breakpoint (thread); | |
cfc31633 PA |
10994 | } |
10995 | ||
10996 | /* Implementation of the 'async_reply_reason' FSM method for the | |
10997 | until(location)/advance commands. */ | |
10998 | ||
46e3ed7f TT |
10999 | enum async_reply_reason |
11000 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
11001 | { |
11002 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11003 | } |
11004 | ||
c906108c | 11005 | void |
f2fc3015 | 11006 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 11007 | { |
8556afb4 PA |
11008 | struct frame_info *frame; |
11009 | struct gdbarch *frame_gdbarch; | |
11010 | struct frame_id stack_frame_id; | |
11011 | struct frame_id caller_frame_id; | |
186c406b TT |
11012 | int thread; |
11013 | struct thread_info *tp; | |
c906108c | 11014 | |
70509625 | 11015 | clear_proceed_status (0); |
c906108c SS |
11016 | |
11017 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11018 | this function. */ |
c5aa993b | 11019 | |
ffc2605c | 11020 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11021 | |
6c5b2ebe PA |
11022 | std::vector<symtab_and_line> sals |
11023 | = (last_displayed_sal_is_valid () | |
11024 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11025 | get_last_displayed_symtab (), | |
11026 | get_last_displayed_line ()) | |
11027 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 11028 | NULL, NULL, 0)); |
c5aa993b | 11029 | |
6c5b2ebe | 11030 | if (sals.size () != 1) |
8a3fe4f8 | 11031 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11032 | |
6c5b2ebe | 11033 | symtab_and_line &sal = sals[0]; |
c5aa993b | 11034 | |
c906108c | 11035 | if (*arg) |
8a3fe4f8 | 11036 | error (_("Junk at end of arguments.")); |
c5aa993b | 11037 | |
c906108c | 11038 | resolve_sal_pc (&sal); |
c5aa993b | 11039 | |
186c406b | 11040 | tp = inferior_thread (); |
5d5658a1 | 11041 | thread = tp->global_num; |
186c406b | 11042 | |
8556afb4 PA |
11043 | /* Note linespec handling above invalidates the frame chain. |
11044 | Installing a breakpoint also invalidates the frame chain (as it | |
11045 | may need to switch threads), so do any frame handling before | |
11046 | that. */ | |
11047 | ||
11048 | frame = get_selected_frame (NULL); | |
11049 | frame_gdbarch = get_frame_arch (frame); | |
11050 | stack_frame_id = get_stack_frame_id (frame); | |
11051 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11052 | |
ae66c1fc EZ |
11053 | /* Keep within the current frame, or in frames called by the current |
11054 | one. */ | |
edb3359d | 11055 | |
454dafbd | 11056 | breakpoint_up caller_breakpoint; |
5419bdae TT |
11057 | |
11058 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
11059 | ||
883bc8d1 | 11060 | if (frame_id_p (caller_frame_id)) |
c906108c | 11061 | { |
883bc8d1 | 11062 | struct symtab_and_line sal2; |
cfc31633 | 11063 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11064 | |
11065 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11066 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11067 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11068 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11069 | sal2, | |
11070 | caller_frame_id, | |
11071 | bp_until); | |
186c406b | 11072 | |
883bc8d1 | 11073 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 11074 | lj_deleter.emplace (thread); |
c906108c | 11075 | } |
c5aa993b | 11076 | |
c70a6932 JK |
11077 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11078 | frame = NULL; | |
11079 | ||
454dafbd | 11080 | breakpoint_up location_breakpoint; |
883bc8d1 PA |
11081 | if (anywhere) |
11082 | /* If the user told us to continue until a specified location, | |
11083 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11084 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11085 | null_frame_id, bp_until); | |
883bc8d1 PA |
11086 | else |
11087 | /* Otherwise, specify the selected frame, because we want to stop | |
11088 | only at the very same frame. */ | |
cfc31633 PA |
11089 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11090 | stack_frame_id, bp_until); | |
883bc8d1 | 11091 | |
46e3ed7f TT |
11092 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
11093 | std::move (location_breakpoint), | |
11094 | std::move (caller_breakpoint)); | |
f107f563 | 11095 | |
5419bdae TT |
11096 | if (lj_deleter) |
11097 | lj_deleter->release (); | |
f107f563 | 11098 | |
cfc31633 | 11099 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11100 | } |
ae66c1fc | 11101 | |
c906108c SS |
11102 | /* This function attempts to parse an optional "if <cond>" clause |
11103 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11104 | |
c906108c SS |
11105 | Else, it returns a pointer to the condition string. (It does not |
11106 | attempt to evaluate the string against a particular block.) And, | |
11107 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11108 | if clause in the arg string. */ |
53a5351d | 11109 | |
63160a43 PA |
11110 | const char * |
11111 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11112 | { |
63160a43 | 11113 | const char *cond_string; |
c5aa993b JM |
11114 | |
11115 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11116 | return NULL; |
c5aa993b | 11117 | |
4a64f543 | 11118 | /* Skip the "if" keyword. */ |
c906108c | 11119 | (*arg) += 2; |
c5aa993b | 11120 | |
c906108c | 11121 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11122 | condition string. */ |
f1735a53 | 11123 | *arg = skip_spaces (*arg); |
c906108c | 11124 | cond_string = *arg; |
c5aa993b | 11125 | |
4a64f543 MS |
11126 | /* Assume that the condition occupies the remainder of the arg |
11127 | string. */ | |
c906108c | 11128 | (*arg) += strlen (cond_string); |
c5aa993b | 11129 | |
c906108c SS |
11130 | return cond_string; |
11131 | } | |
c5aa993b | 11132 | |
c906108c SS |
11133 | /* Commands to deal with catching events, such as signals, exceptions, |
11134 | process start/exit, etc. */ | |
c5aa993b JM |
11135 | |
11136 | typedef enum | |
11137 | { | |
44feb3ce TT |
11138 | catch_fork_temporary, catch_vfork_temporary, |
11139 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11140 | } |
11141 | catch_fork_kind; | |
11142 | ||
c906108c | 11143 | static void |
eb4c3f4a | 11144 | catch_fork_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11145 | struct cmd_list_element *command) |
c906108c | 11146 | { |
a6d9a66e | 11147 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11148 | const char *cond_string = NULL; |
44feb3ce TT |
11149 | catch_fork_kind fork_kind; |
11150 | int tempflag; | |
11151 | ||
11152 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11153 | tempflag = (fork_kind == catch_fork_temporary | |
11154 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11155 | |
44feb3ce TT |
11156 | if (!arg) |
11157 | arg = ""; | |
f1735a53 | 11158 | arg = skip_spaces (arg); |
c5aa993b | 11159 | |
c906108c | 11160 | /* The allowed syntax is: |
c5aa993b JM |
11161 | catch [v]fork |
11162 | catch [v]fork if <cond> | |
11163 | ||
4a64f543 | 11164 | First, check if there's an if clause. */ |
c906108c | 11165 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11166 | |
c906108c | 11167 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11168 | error (_("Junk at end of arguments.")); |
c5aa993b | 11169 | |
c906108c | 11170 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11171 | and enable reporting of such events. */ |
c5aa993b JM |
11172 | switch (fork_kind) |
11173 | { | |
44feb3ce TT |
11174 | case catch_fork_temporary: |
11175 | case catch_fork_permanent: | |
a6d9a66e | 11176 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11177 | &catch_fork_breakpoint_ops); |
c906108c | 11178 | break; |
44feb3ce TT |
11179 | case catch_vfork_temporary: |
11180 | case catch_vfork_permanent: | |
a6d9a66e | 11181 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11182 | &catch_vfork_breakpoint_ops); |
c906108c | 11183 | break; |
c5aa993b | 11184 | default: |
8a3fe4f8 | 11185 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11186 | break; |
c5aa993b | 11187 | } |
c906108c SS |
11188 | } |
11189 | ||
11190 | static void | |
eb4c3f4a | 11191 | catch_exec_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11192 | struct cmd_list_element *command) |
c906108c | 11193 | { |
a6d9a66e | 11194 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11195 | int tempflag; |
63160a43 | 11196 | const char *cond_string = NULL; |
c906108c | 11197 | |
44feb3ce TT |
11198 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11199 | ||
11200 | if (!arg) | |
11201 | arg = ""; | |
f1735a53 | 11202 | arg = skip_spaces (arg); |
c906108c SS |
11203 | |
11204 | /* The allowed syntax is: | |
c5aa993b JM |
11205 | catch exec |
11206 | catch exec if <cond> | |
c906108c | 11207 | |
4a64f543 | 11208 | First, check if there's an if clause. */ |
c906108c SS |
11209 | cond_string = ep_parse_optional_if_clause (&arg); |
11210 | ||
11211 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11212 | error (_("Junk at end of arguments.")); |
c906108c | 11213 | |
b270e6f9 TT |
11214 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11215 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11216 | &catch_exec_breakpoint_ops); |
11217 | c->exec_pathname = NULL; | |
11218 | ||
b270e6f9 | 11219 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11220 | } |
c5aa993b | 11221 | |
9ac4176b | 11222 | void |
28010a5d PA |
11223 | init_ada_exception_breakpoint (struct breakpoint *b, |
11224 | struct gdbarch *gdbarch, | |
11225 | struct symtab_and_line sal, | |
f2fc3015 | 11226 | const char *addr_string, |
c0a91b2b | 11227 | const struct breakpoint_ops *ops, |
28010a5d | 11228 | int tempflag, |
349774ef | 11229 | int enabled, |
28010a5d | 11230 | int from_tty) |
f7f9143b | 11231 | { |
f7f9143b JB |
11232 | if (from_tty) |
11233 | { | |
5af949e3 UW |
11234 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11235 | if (!loc_gdbarch) | |
11236 | loc_gdbarch = gdbarch; | |
11237 | ||
6c95b8df PA |
11238 | describe_other_breakpoints (loc_gdbarch, |
11239 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11240 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11241 | version for exception catchpoints, because two catchpoints | |
11242 | used for different exception names will use the same address. | |
11243 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11244 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11245 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11246 | the user what type of catchpoint it is. The above is good |
11247 | enough for now, though. */ | |
11248 | } | |
11249 | ||
f06f1252 | 11250 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
f7f9143b | 11251 | |
349774ef | 11252 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11253 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11254 | b->location = string_to_event_location (&addr_string, |
11255 | language_def (language_ada)); | |
f7f9143b | 11256 | b->language = language_ada; |
f7f9143b JB |
11257 | } |
11258 | ||
c906108c SS |
11259 | \f |
11260 | ||
81b1e71c | 11261 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
11262 | |
11263 | static int | |
81b1e71c | 11264 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 11265 | { |
81b1e71c TT |
11266 | uintptr_t ua = (uintptr_t) a; |
11267 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 11268 | |
81b1e71c | 11269 | if (a->number < b->number) |
8a2c437b | 11270 | return -1; |
81b1e71c | 11271 | else if (a->number > b->number) |
8a2c437b TT |
11272 | return 1; |
11273 | ||
11274 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11275 | the number 0. */ | |
11276 | if (ua < ub) | |
11277 | return -1; | |
94b0e70d | 11278 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11279 | } |
11280 | ||
80f8a6eb | 11281 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11282 | |
11283 | static void | |
0b39b52e | 11284 | clear_command (const char *arg, int from_tty) |
c906108c | 11285 | { |
81b1e71c | 11286 | struct breakpoint *b; |
c906108c | 11287 | int default_match; |
c906108c | 11288 | |
6c5b2ebe PA |
11289 | std::vector<symtab_and_line> decoded_sals; |
11290 | symtab_and_line last_sal; | |
11291 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11292 | if (arg) |
11293 | { | |
6c5b2ebe PA |
11294 | decoded_sals |
11295 | = decode_line_with_current_source (arg, | |
11296 | (DECODE_LINE_FUNFIRSTLINE | |
11297 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11298 | default_match = 0; |
6c5b2ebe | 11299 | sals = decoded_sals; |
c906108c SS |
11300 | } |
11301 | else | |
11302 | { | |
1bfeeb0f JL |
11303 | /* Set sal's line, symtab, pc, and pspace to the values |
11304 | corresponding to the last call to print_frame_info. If the | |
11305 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11306 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11307 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11308 | error (_("No source file specified.")); |
c906108c | 11309 | |
c906108c | 11310 | default_match = 1; |
6c5b2ebe | 11311 | sals = last_sal; |
c906108c SS |
11312 | } |
11313 | ||
4a64f543 MS |
11314 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11315 | seems, because all existing breakpoints typically have both | |
11316 | file/line and pc set. So, if clear is given file/line, we can | |
11317 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11318 | |
11319 | We only support clearing given the address explicitly | |
11320 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11321 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11322 | due to optimization, all in one block. |
4a64f543 MS |
11323 | |
11324 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11325 | PC corresponding to the same file:line, the breakpoint won't |
11326 | be cleared. We probably can still clear the breakpoint, but | |
11327 | since the other PC value is never presented to user, user | |
11328 | can only find it by guessing, and it does not seem important | |
11329 | to support that. */ | |
11330 | ||
4a64f543 MS |
11331 | /* For each line spec given, delete bps which correspond to it. Do |
11332 | it in two passes, solely to preserve the current behavior that | |
11333 | from_tty is forced true if we delete more than one | |
11334 | breakpoint. */ | |
c906108c | 11335 | |
81b1e71c | 11336 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 11337 | for (const auto &sal : sals) |
c906108c | 11338 | { |
05cba821 JK |
11339 | const char *sal_fullname; |
11340 | ||
c906108c | 11341 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11342 | If line given (pc == 0), clear all bpts on specified line. |
11343 | If defaulting, clear all bpts on default line | |
c906108c | 11344 | or at default pc. |
c5aa993b JM |
11345 | |
11346 | defaulting sal.pc != 0 tests to do | |
11347 | ||
11348 | 0 1 pc | |
11349 | 1 1 pc _and_ line | |
11350 | 0 0 line | |
11351 | 1 0 <can't happen> */ | |
c906108c | 11352 | |
05cba821 JK |
11353 | sal_fullname = (sal.symtab == NULL |
11354 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11355 | |
4a64f543 | 11356 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11357 | ALL_BREAKPOINTS (b) |
c5aa993b | 11358 | { |
0d381245 | 11359 | int match = 0; |
4a64f543 | 11360 | /* Are we going to delete b? */ |
cc60f2e3 | 11361 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11362 | { |
11363 | struct bp_location *loc = b->loc; | |
11364 | for (; loc; loc = loc->next) | |
11365 | { | |
f8eba3c6 TT |
11366 | /* If the user specified file:line, don't allow a PC |
11367 | match. This matches historical gdb behavior. */ | |
11368 | int pc_match = (!sal.explicit_line | |
11369 | && sal.pc | |
11370 | && (loc->pspace == sal.pspace) | |
11371 | && (loc->address == sal.pc) | |
11372 | && (!section_is_overlay (loc->section) | |
11373 | || loc->section == sal.section)); | |
4aac40c8 TT |
11374 | int line_match = 0; |
11375 | ||
11376 | if ((default_match || sal.explicit_line) | |
2f202fde | 11377 | && loc->symtab != NULL |
05cba821 | 11378 | && sal_fullname != NULL |
4aac40c8 | 11379 | && sal.pspace == loc->pspace |
05cba821 JK |
11380 | && loc->line_number == sal.line |
11381 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11382 | sal_fullname) == 0) | |
11383 | line_match = 1; | |
4aac40c8 | 11384 | |
0d381245 VP |
11385 | if (pc_match || line_match) |
11386 | { | |
11387 | match = 1; | |
11388 | break; | |
11389 | } | |
11390 | } | |
11391 | } | |
11392 | ||
11393 | if (match) | |
81b1e71c | 11394 | found.push_back (b); |
c906108c | 11395 | } |
80f8a6eb | 11396 | } |
8a2c437b | 11397 | |
80f8a6eb | 11398 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11399 | if (found.empty ()) |
80f8a6eb MS |
11400 | { |
11401 | if (arg) | |
8a3fe4f8 | 11402 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11403 | else |
8a3fe4f8 | 11404 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11405 | } |
c906108c | 11406 | |
8a2c437b | 11407 | /* Remove duplicates from the vec. */ |
81b1e71c | 11408 | std::sort (found.begin (), found.end (), |
b926417a | 11409 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11410 | { |
b926417a | 11411 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
11412 | }); |
11413 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 11414 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11415 | { |
b926417a | 11416 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
11417 | }), |
11418 | found.end ()); | |
8a2c437b | 11419 | |
81b1e71c | 11420 | if (found.size () > 1) |
4a64f543 | 11421 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11422 | if (from_tty) |
a3f17187 | 11423 | { |
81b1e71c | 11424 | if (found.size () == 1) |
a3f17187 AC |
11425 | printf_unfiltered (_("Deleted breakpoint ")); |
11426 | else | |
11427 | printf_unfiltered (_("Deleted breakpoints ")); | |
11428 | } | |
d6e956e5 | 11429 | |
81b1e71c | 11430 | for (breakpoint *iter : found) |
80f8a6eb | 11431 | { |
c5aa993b | 11432 | if (from_tty) |
81b1e71c TT |
11433 | printf_unfiltered ("%d ", iter->number); |
11434 | delete_breakpoint (iter); | |
c906108c | 11435 | } |
80f8a6eb MS |
11436 | if (from_tty) |
11437 | putchar_unfiltered ('\n'); | |
c906108c SS |
11438 | } |
11439 | \f | |
11440 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11441 | all breakpoints that are marked for deletion, whether hit or not. | |
11442 | This is called after any breakpoint is hit, or after errors. */ | |
11443 | ||
11444 | void | |
fba45db2 | 11445 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11446 | { |
35df4500 | 11447 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11448 | |
11449 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11450 | if (bs->breakpoint_at |
11451 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11452 | && bs->stop) |
f431efe5 | 11453 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11454 | |
35df4500 | 11455 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11456 | { |
b5de0fa7 | 11457 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11458 | delete_breakpoint (b); |
11459 | } | |
c906108c SS |
11460 | } |
11461 | ||
4a64f543 | 11462 | /* A comparison function for bp_location AP and BP being interfaced to |
39ef2f62 | 11463 | std::sort. Sort elements primarily by their ADDRESS (no matter what |
cb1e4e32 PA |
11464 | bl_address_is_meaningful says), secondarily by ordering first |
11465 | permanent elements and terciarily just ensuring the array is sorted | |
39ef2f62 | 11466 | stable way despite std::sort being an unstable algorithm. */ |
876fa593 JK |
11467 | |
11468 | static int | |
39ef2f62 | 11469 | bp_location_is_less_than (const bp_location *a, const bp_location *b) |
876fa593 | 11470 | { |
876fa593 | 11471 | if (a->address != b->address) |
39ef2f62 | 11472 | return a->address < b->address; |
876fa593 | 11473 | |
dea2aa5f LM |
11474 | /* Sort locations at the same address by their pspace number, keeping |
11475 | locations of the same inferior (in a multi-inferior environment) | |
11476 | grouped. */ | |
11477 | ||
11478 | if (a->pspace->num != b->pspace->num) | |
39ef2f62 | 11479 | return a->pspace->num < b->pspace->num; |
dea2aa5f | 11480 | |
876fa593 | 11481 | /* Sort permanent breakpoints first. */ |
1a853c52 | 11482 | if (a->permanent != b->permanent) |
39ef2f62 | 11483 | return a->permanent > b->permanent; |
876fa593 | 11484 | |
7f32a4d5 PA |
11485 | /* Sort by type in order to make duplicate determination easier. |
11486 | See update_global_location_list. This is kept in sync with | |
11487 | breakpoint_locations_match. */ | |
11488 | if (a->loc_type < b->loc_type) | |
11489 | return true; | |
11490 | ||
11491 | /* Likewise, for range-breakpoints, sort by length. */ | |
11492 | if (a->loc_type == bp_loc_hardware_breakpoint | |
11493 | && b->loc_type == bp_loc_hardware_breakpoint | |
11494 | && a->length < b->length) | |
11495 | return true; | |
11496 | ||
c56a97f9 JK |
11497 | /* Make the internal GDB representation stable across GDB runs |
11498 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11499 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11500 | |
11501 | if (a->owner->number != b->owner->number) | |
39ef2f62 | 11502 | return a->owner->number < b->owner->number; |
876fa593 | 11503 | |
39ef2f62 | 11504 | return a < b; |
876fa593 JK |
11505 | } |
11506 | ||
f5336ca5 PA |
11507 | /* Set bp_locations_placed_address_before_address_max and |
11508 | bp_locations_shadow_len_after_address_max according to the current | |
11509 | content of the bp_locations array. */ | |
f7545552 TT |
11510 | |
11511 | static void | |
f5336ca5 | 11512 | bp_locations_target_extensions_update (void) |
f7545552 | 11513 | { |
876fa593 JK |
11514 | struct bp_location *bl, **blp_tmp; |
11515 | ||
f5336ca5 PA |
11516 | bp_locations_placed_address_before_address_max = 0; |
11517 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11518 | |
11519 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11520 | { | |
11521 | CORE_ADDR start, end, addr; | |
11522 | ||
11523 | if (!bp_location_has_shadow (bl)) | |
11524 | continue; | |
11525 | ||
11526 | start = bl->target_info.placed_address; | |
11527 | end = start + bl->target_info.shadow_len; | |
11528 | ||
11529 | gdb_assert (bl->address >= start); | |
11530 | addr = bl->address - start; | |
f5336ca5 PA |
11531 | if (addr > bp_locations_placed_address_before_address_max) |
11532 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11533 | |
11534 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11535 | ||
11536 | gdb_assert (bl->address < end); | |
11537 | addr = end - bl->address; | |
f5336ca5 PA |
11538 | if (addr > bp_locations_shadow_len_after_address_max) |
11539 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11540 | } |
f7545552 TT |
11541 | } |
11542 | ||
1e4d1764 YQ |
11543 | /* Download tracepoint locations if they haven't been. */ |
11544 | ||
11545 | static void | |
11546 | download_tracepoint_locations (void) | |
11547 | { | |
7ed2c994 | 11548 | struct breakpoint *b; |
dd2e65cc | 11549 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11550 | |
5ed8105e | 11551 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11552 | |
7ed2c994 | 11553 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11554 | { |
7ed2c994 | 11555 | struct bp_location *bl; |
1e4d1764 | 11556 | struct tracepoint *t; |
f2a8bc8a | 11557 | int bp_location_downloaded = 0; |
1e4d1764 | 11558 | |
7ed2c994 | 11559 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11560 | ? !may_insert_fast_tracepoints |
11561 | : !may_insert_tracepoints)) | |
11562 | continue; | |
11563 | ||
dd2e65cc YQ |
11564 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11565 | { | |
11566 | if (target_can_download_tracepoint ()) | |
11567 | can_download_tracepoint = TRIBOOL_TRUE; | |
11568 | else | |
11569 | can_download_tracepoint = TRIBOOL_FALSE; | |
11570 | } | |
11571 | ||
11572 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11573 | break; | |
11574 | ||
7ed2c994 YQ |
11575 | for (bl = b->loc; bl; bl = bl->next) |
11576 | { | |
11577 | /* In tracepoint, locations are _never_ duplicated, so | |
11578 | should_be_inserted is equivalent to | |
11579 | unduplicated_should_be_inserted. */ | |
11580 | if (!should_be_inserted (bl) || bl->inserted) | |
11581 | continue; | |
1e4d1764 | 11582 | |
7ed2c994 | 11583 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11584 | |
7ed2c994 | 11585 | target_download_tracepoint (bl); |
1e4d1764 | 11586 | |
7ed2c994 | 11587 | bl->inserted = 1; |
f2a8bc8a | 11588 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11589 | } |
11590 | t = (struct tracepoint *) b; | |
11591 | t->number_on_target = b->number; | |
f2a8bc8a | 11592 | if (bp_location_downloaded) |
76727919 | 11593 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11594 | } |
1e4d1764 YQ |
11595 | } |
11596 | ||
934709f0 PW |
11597 | /* Swap the insertion/duplication state between two locations. */ |
11598 | ||
11599 | static void | |
11600 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11601 | { | |
11602 | const int left_inserted = left->inserted; | |
11603 | const int left_duplicate = left->duplicate; | |
b775012e | 11604 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11605 | const struct bp_target_info left_target_info = left->target_info; |
11606 | ||
1e4d1764 YQ |
11607 | /* Locations of tracepoints can never be duplicated. */ |
11608 | if (is_tracepoint (left->owner)) | |
11609 | gdb_assert (!left->duplicate); | |
11610 | if (is_tracepoint (right->owner)) | |
11611 | gdb_assert (!right->duplicate); | |
11612 | ||
934709f0 PW |
11613 | left->inserted = right->inserted; |
11614 | left->duplicate = right->duplicate; | |
b775012e | 11615 | left->needs_update = right->needs_update; |
934709f0 PW |
11616 | left->target_info = right->target_info; |
11617 | right->inserted = left_inserted; | |
11618 | right->duplicate = left_duplicate; | |
b775012e | 11619 | right->needs_update = left_needs_update; |
934709f0 PW |
11620 | right->target_info = left_target_info; |
11621 | } | |
11622 | ||
b775012e LM |
11623 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11624 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11625 | conditions on the target's side. Such conditions need to be updated on | |
11626 | the target. */ | |
11627 | ||
11628 | static void | |
11629 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11630 | { | |
11631 | struct bp_location **locp = NULL, **loc2p; | |
11632 | struct bp_location *loc; | |
11633 | CORE_ADDR address = 0; | |
11634 | int pspace_num; | |
11635 | ||
11636 | address = bl->address; | |
11637 | pspace_num = bl->pspace->num; | |
11638 | ||
11639 | /* This is only meaningful if the target is | |
11640 | evaluating conditions and if the user has | |
11641 | opted for condition evaluation on the target's | |
11642 | side. */ | |
11643 | if (gdb_evaluates_breakpoint_condition_p () | |
11644 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11645 | return; | |
11646 | ||
11647 | /* Flag all breakpoint locations with this address and | |
11648 | the same program space as the location | |
11649 | as "its condition has changed". We need to | |
11650 | update the conditions on the target's side. */ | |
11651 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11652 | { | |
11653 | loc = *loc2p; | |
11654 | ||
11655 | if (!is_breakpoint (loc->owner) | |
11656 | || pspace_num != loc->pspace->num) | |
11657 | continue; | |
11658 | ||
11659 | /* Flag the location appropriately. We use a different state to | |
11660 | let everyone know that we already updated the set of locations | |
11661 | with addr bl->address and program space bl->pspace. This is so | |
11662 | we don't have to keep calling these functions just to mark locations | |
11663 | that have already been marked. */ | |
11664 | loc->condition_changed = condition_updated; | |
11665 | ||
11666 | /* Free the agent expression bytecode as well. We will compute | |
11667 | it later on. */ | |
833177a4 | 11668 | loc->cond_bytecode.reset (); |
b775012e LM |
11669 | } |
11670 | } | |
7f32a4d5 | 11671 | |
44702360 PA |
11672 | /* Called whether new breakpoints are created, or existing breakpoints |
11673 | deleted, to update the global location list and recompute which | |
11674 | locations are duplicate of which. | |
b775012e | 11675 | |
04086b45 PA |
11676 | The INSERT_MODE flag determines whether locations may not, may, or |
11677 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11678 | info. */ | |
b60e7edf | 11679 | |
0d381245 | 11680 | static void |
44702360 | 11681 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11682 | { |
74960c60 | 11683 | struct breakpoint *b; |
876fa593 | 11684 | struct bp_location **locp, *loc; |
b775012e LM |
11685 | /* Last breakpoint location address that was marked for update. */ |
11686 | CORE_ADDR last_addr = 0; | |
11687 | /* Last breakpoint location program space that was marked for update. */ | |
11688 | int last_pspace_num = -1; | |
f7545552 | 11689 | |
2d134ed3 PA |
11690 | /* Used in the duplicates detection below. When iterating over all |
11691 | bp_locations, points to the first bp_location of a given address. | |
11692 | Breakpoints and watchpoints of different types are never | |
11693 | duplicates of each other. Keep one pointer for each type of | |
11694 | breakpoint/watchpoint, so we only need to loop over all locations | |
11695 | once. */ | |
11696 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11697 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11698 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11699 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11700 | |
f5336ca5 PA |
11701 | /* Saved former bp_locations array which we compare against the newly |
11702 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
81b1e71c | 11703 | struct bp_location **old_locp; |
f5336ca5 | 11704 | unsigned old_locations_count; |
81b1e71c | 11705 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
876fa593 | 11706 | |
f5336ca5 PA |
11707 | old_locations_count = bp_locations_count; |
11708 | bp_locations = NULL; | |
11709 | bp_locations_count = 0; | |
0d381245 | 11710 | |
74960c60 | 11711 | ALL_BREAKPOINTS (b) |
876fa593 | 11712 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 11713 | bp_locations_count++; |
876fa593 | 11714 | |
f5336ca5 PA |
11715 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
11716 | locp = bp_locations; | |
876fa593 JK |
11717 | ALL_BREAKPOINTS (b) |
11718 | for (loc = b->loc; loc; loc = loc->next) | |
11719 | *locp++ = loc; | |
7f32a4d5 PA |
11720 | |
11721 | /* See if we need to "upgrade" a software breakpoint to a hardware | |
11722 | breakpoint. Do this before deciding whether locations are | |
11723 | duplicates. Also do this before sorting because sorting order | |
11724 | depends on location type. */ | |
11725 | for (locp = bp_locations; | |
11726 | locp < bp_locations + bp_locations_count; | |
11727 | locp++) | |
11728 | { | |
11729 | loc = *locp; | |
11730 | if (!loc->inserted && should_be_inserted (loc)) | |
11731 | handle_automatic_hardware_breakpoints (loc); | |
11732 | } | |
11733 | ||
39ef2f62 CB |
11734 | std::sort (bp_locations, bp_locations + bp_locations_count, |
11735 | bp_location_is_less_than); | |
876fa593 | 11736 | |
f5336ca5 | 11737 | bp_locations_target_extensions_update (); |
74960c60 | 11738 | |
4a64f543 MS |
11739 | /* Identify bp_location instances that are no longer present in the |
11740 | new list, and therefore should be freed. Note that it's not | |
11741 | necessary that those locations should be removed from inferior -- | |
11742 | if there's another location at the same address (previously | |
11743 | marked as duplicate), we don't need to remove/insert the | |
11744 | location. | |
876fa593 | 11745 | |
4a64f543 MS |
11746 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11747 | and former bp_location array state respectively. */ | |
876fa593 | 11748 | |
f5336ca5 | 11749 | locp = bp_locations; |
81b1e71c TT |
11750 | for (old_locp = old_locations.get (); |
11751 | old_locp < old_locations.get () + old_locations_count; | |
876fa593 | 11752 | old_locp++) |
74960c60 | 11753 | { |
876fa593 | 11754 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11755 | struct bp_location **loc2p; |
876fa593 | 11756 | |
e5dd4106 | 11757 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11758 | not, we have to free it. */ |
c7d46a38 | 11759 | int found_object = 0; |
20874c92 VP |
11760 | /* Tells if the location should remain inserted in the target. */ |
11761 | int keep_in_target = 0; | |
11762 | int removed = 0; | |
876fa593 | 11763 | |
4a64f543 MS |
11764 | /* Skip LOCP entries which will definitely never be needed. |
11765 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 11766 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 11767 | && (*locp)->address < old_loc->address) |
876fa593 | 11768 | locp++; |
c7d46a38 PA |
11769 | |
11770 | for (loc2p = locp; | |
f5336ca5 | 11771 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
11772 | && (*loc2p)->address == old_loc->address); |
11773 | loc2p++) | |
11774 | { | |
b775012e LM |
11775 | /* Check if this is a new/duplicated location or a duplicated |
11776 | location that had its condition modified. If so, we want to send | |
11777 | its condition to the target if evaluation of conditions is taking | |
11778 | place there. */ | |
11779 | if ((*loc2p)->condition_changed == condition_modified | |
11780 | && (last_addr != old_loc->address | |
11781 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11782 | { |
b775012e LM |
11783 | force_breakpoint_reinsertion (*loc2p); |
11784 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11785 | } |
b775012e LM |
11786 | |
11787 | if (*loc2p == old_loc) | |
11788 | found_object = 1; | |
c7d46a38 | 11789 | } |
74960c60 | 11790 | |
b775012e LM |
11791 | /* We have already handled this address, update it so that we don't |
11792 | have to go through updates again. */ | |
11793 | last_addr = old_loc->address; | |
11794 | ||
11795 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11796 | if (!found_object) | |
11797 | force_breakpoint_reinsertion (old_loc); | |
11798 | ||
4a64f543 MS |
11799 | /* If this location is no longer present, and inserted, look if |
11800 | there's maybe a new location at the same address. If so, | |
11801 | mark that one inserted, and don't remove this one. This is | |
11802 | needed so that we don't have a time window where a breakpoint | |
11803 | at certain location is not inserted. */ | |
74960c60 | 11804 | |
876fa593 | 11805 | if (old_loc->inserted) |
0d381245 | 11806 | { |
4a64f543 MS |
11807 | /* If the location is inserted now, we might have to remove |
11808 | it. */ | |
74960c60 | 11809 | |
876fa593 | 11810 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11811 | { |
4a64f543 MS |
11812 | /* The location is still present in the location list, |
11813 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11814 | keep_in_target = 1; |
74960c60 VP |
11815 | } |
11816 | else | |
11817 | { | |
b775012e LM |
11818 | /* This location still exists, but it won't be kept in the |
11819 | target since it may have been disabled. We proceed to | |
11820 | remove its target-side condition. */ | |
11821 | ||
4a64f543 MS |
11822 | /* The location is either no longer present, or got |
11823 | disabled. See if there's another location at the | |
11824 | same address, in which case we don't need to remove | |
11825 | this one from the target. */ | |
876fa593 | 11826 | |
2bdf28a0 | 11827 | /* OLD_LOC comes from existing struct breakpoint. */ |
cb1e4e32 | 11828 | if (bl_address_is_meaningful (old_loc)) |
876fa593 | 11829 | { |
876fa593 | 11830 | for (loc2p = locp; |
f5336ca5 | 11831 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 11832 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
11833 | loc2p++) |
11834 | { | |
11835 | struct bp_location *loc2 = *loc2p; | |
11836 | ||
7f32a4d5 PA |
11837 | if (loc2 == old_loc) |
11838 | continue; | |
11839 | ||
2d134ed3 | 11840 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11841 | { |
85d721b8 PA |
11842 | /* Read watchpoint locations are switched to |
11843 | access watchpoints, if the former are not | |
11844 | supported, but the latter are. */ | |
11845 | if (is_hardware_watchpoint (old_loc->owner)) | |
11846 | { | |
11847 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11848 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11849 | } | |
11850 | ||
934709f0 PW |
11851 | /* loc2 is a duplicated location. We need to check |
11852 | if it should be inserted in case it will be | |
11853 | unduplicated. */ | |
7f32a4d5 | 11854 | if (unduplicated_should_be_inserted (loc2)) |
c7d46a38 | 11855 | { |
934709f0 | 11856 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11857 | keep_in_target = 1; |
11858 | break; | |
11859 | } | |
876fa593 JK |
11860 | } |
11861 | } | |
11862 | } | |
74960c60 VP |
11863 | } |
11864 | ||
20874c92 VP |
11865 | if (!keep_in_target) |
11866 | { | |
834c0d03 | 11867 | if (remove_breakpoint (old_loc)) |
20874c92 | 11868 | { |
4a64f543 MS |
11869 | /* This is just about all we can do. We could keep |
11870 | this location on the global list, and try to | |
11871 | remove it next time, but there's no particular | |
11872 | reason why we will succeed next time. | |
20874c92 | 11873 | |
4a64f543 MS |
11874 | Note that at this point, old_loc->owner is still |
11875 | valid, as delete_breakpoint frees the breakpoint | |
11876 | only after calling us. */ | |
3e43a32a MS |
11877 | printf_filtered (_("warning: Error removing " |
11878 | "breakpoint %d\n"), | |
876fa593 | 11879 | old_loc->owner->number); |
20874c92 VP |
11880 | } |
11881 | removed = 1; | |
11882 | } | |
0d381245 | 11883 | } |
74960c60 VP |
11884 | |
11885 | if (!found_object) | |
1c5cfe86 | 11886 | { |
fbea99ea | 11887 | if (removed && target_is_non_stop_p () |
1cf4d951 | 11888 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 11889 | { |
db82e815 PA |
11890 | /* This location was removed from the target. In |
11891 | non-stop mode, a race condition is possible where | |
11892 | we've removed a breakpoint, but stop events for that | |
11893 | breakpoint are already queued and will arrive later. | |
11894 | We apply an heuristic to be able to distinguish such | |
11895 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11896 | breakpoint location for a bit, and will retire it | |
11897 | after we see some number of events. The theory here | |
11898 | is that reporting of events should, "on the average", | |
11899 | be fair, so after a while we'll see events from all | |
11900 | threads that have anything of interest, and no longer | |
11901 | need to keep this breakpoint location around. We | |
11902 | don't hold locations forever so to reduce chances of | |
11903 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11904 | SIGTRAP. | |
11905 | ||
11906 | The heuristic failing can be disastrous on | |
11907 | decr_pc_after_break targets. | |
11908 | ||
11909 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11910 | if we fail to recognize a late breakpoint SIGTRAP, | |
11911 | because events_till_retirement has reached 0 too | |
11912 | soon, we'll fail to do the PC adjustment, and report | |
11913 | a random SIGTRAP to the user. When the user resumes | |
11914 | the inferior, it will most likely immediately crash | |
2dec564e | 11915 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11916 | corrupted, because of being resumed e.g., in the |
11917 | middle of a multi-byte instruction, or skipped a | |
11918 | one-byte instruction. This was actually seen happen | |
11919 | on native x86-linux, and should be less rare on | |
11920 | targets that do not support new thread events, like | |
11921 | remote, due to the heuristic depending on | |
11922 | thread_count. | |
11923 | ||
11924 | Mistaking a random SIGTRAP for a breakpoint trap | |
11925 | causes similar symptoms (PC adjustment applied when | |
11926 | it shouldn't), but then again, playing with SIGTRAPs | |
11927 | behind the debugger's back is asking for trouble. | |
11928 | ||
11929 | Since hardware watchpoint traps are always | |
11930 | distinguishable from other traps, so we don't need to | |
11931 | apply keep hardware watchpoint moribund locations | |
11932 | around. We simply always ignore hardware watchpoint | |
11933 | traps we can no longer explain. */ | |
11934 | ||
5b6d1e4f PA |
11935 | process_stratum_target *proc_target = nullptr; |
11936 | for (inferior *inf : all_inferiors ()) | |
11937 | if (inf->pspace == old_loc->pspace) | |
11938 | { | |
11939 | proc_target = inf->process_target (); | |
11940 | break; | |
11941 | } | |
11942 | if (proc_target != nullptr) | |
11943 | old_loc->events_till_retirement | |
11944 | = 3 * (thread_count (proc_target) + 1); | |
11945 | else | |
11946 | old_loc->events_till_retirement = 1; | |
876fa593 | 11947 | old_loc->owner = NULL; |
20874c92 | 11948 | |
1123588c | 11949 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
11950 | } |
11951 | else | |
f431efe5 PA |
11952 | { |
11953 | old_loc->owner = NULL; | |
11954 | decref_bp_location (&old_loc); | |
11955 | } | |
20874c92 | 11956 | } |
74960c60 | 11957 | } |
1c5cfe86 | 11958 | |
348d480f PA |
11959 | /* Rescan breakpoints at the same address and section, marking the |
11960 | first one as "first" and any others as "duplicates". This is so | |
11961 | that the bpt instruction is only inserted once. If we have a | |
11962 | permanent breakpoint at the same place as BPT, make that one the | |
11963 | official one, and the rest as duplicates. Permanent breakpoints | |
11964 | are sorted first for the same address. | |
11965 | ||
11966 | Do the same for hardware watchpoints, but also considering the | |
11967 | watchpoint's type (regular/access/read) and length. */ | |
11968 | ||
11969 | bp_loc_first = NULL; | |
11970 | wp_loc_first = NULL; | |
11971 | awp_loc_first = NULL; | |
11972 | rwp_loc_first = NULL; | |
11973 | ALL_BP_LOCATIONS (loc, locp) | |
11974 | { | |
11975 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11976 | non-NULL. */ | |
348d480f | 11977 | struct bp_location **loc_first_p; |
d3fbdd86 | 11978 | b = loc->owner; |
348d480f | 11979 | |
6f380991 | 11980 | if (!unduplicated_should_be_inserted (loc) |
cb1e4e32 | 11981 | || !bl_address_is_meaningful (loc) |
1e4d1764 YQ |
11982 | /* Don't detect duplicate for tracepoint locations because they are |
11983 | never duplicated. See the comments in field `duplicate' of | |
11984 | `struct bp_location'. */ | |
348d480f | 11985 | || is_tracepoint (b)) |
b775012e LM |
11986 | { |
11987 | /* Clear the condition modification flag. */ | |
11988 | loc->condition_changed = condition_unchanged; | |
11989 | continue; | |
11990 | } | |
348d480f | 11991 | |
348d480f PA |
11992 | if (b->type == bp_hardware_watchpoint) |
11993 | loc_first_p = &wp_loc_first; | |
11994 | else if (b->type == bp_read_watchpoint) | |
11995 | loc_first_p = &rwp_loc_first; | |
11996 | else if (b->type == bp_access_watchpoint) | |
11997 | loc_first_p = &awp_loc_first; | |
11998 | else | |
11999 | loc_first_p = &bp_loc_first; | |
12000 | ||
12001 | if (*loc_first_p == NULL | |
12002 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12003 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12004 | { | |
12005 | *loc_first_p = loc; | |
12006 | loc->duplicate = 0; | |
b775012e LM |
12007 | |
12008 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12009 | { | |
12010 | loc->needs_update = 1; | |
12011 | /* Clear the condition modification flag. */ | |
12012 | loc->condition_changed = condition_unchanged; | |
12013 | } | |
348d480f PA |
12014 | continue; |
12015 | } | |
12016 | ||
934709f0 PW |
12017 | |
12018 | /* This and the above ensure the invariant that the first location | |
12019 | is not duplicated, and is the inserted one. | |
12020 | All following are marked as duplicated, and are not inserted. */ | |
12021 | if (loc->inserted) | |
12022 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12023 | loc->duplicate = 1; |
12024 | ||
b775012e LM |
12025 | /* Clear the condition modification flag. */ |
12026 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12027 | } |
12028 | ||
a25a5a45 | 12029 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12030 | { |
04086b45 | 12031 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12032 | insert_breakpoint_locations (); |
12033 | else | |
12034 | { | |
44702360 PA |
12035 | /* Even though the caller told us to not insert new |
12036 | locations, we may still need to update conditions on the | |
12037 | target's side of breakpoints that were already inserted | |
12038 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12039 | only update conditions for locations that are marked |
12040 | "needs_update". */ | |
12041 | update_inserted_breakpoint_locations (); | |
12042 | } | |
12043 | } | |
348d480f | 12044 | |
04086b45 | 12045 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 12046 | download_tracepoint_locations (); |
348d480f PA |
12047 | } |
12048 | ||
12049 | void | |
12050 | breakpoint_retire_moribund (void) | |
12051 | { | |
1123588c TT |
12052 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
12053 | { | |
12054 | struct bp_location *loc = moribund_locations[ix]; | |
12055 | if (--(loc->events_till_retirement) == 0) | |
12056 | { | |
12057 | decref_bp_location (&loc); | |
12058 | unordered_remove (moribund_locations, ix); | |
12059 | --ix; | |
12060 | } | |
12061 | } | |
348d480f PA |
12062 | } |
12063 | ||
12064 | static void | |
44702360 | 12065 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12066 | { |
348d480f | 12067 | |
a70b8144 | 12068 | try |
492d29ea PA |
12069 | { |
12070 | update_global_location_list (insert_mode); | |
12071 | } | |
230d2906 | 12072 | catch (const gdb_exception_error &e) |
492d29ea PA |
12073 | { |
12074 | } | |
348d480f PA |
12075 | } |
12076 | ||
12077 | /* Clear BKP from a BPS. */ | |
12078 | ||
12079 | static void | |
12080 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12081 | { | |
12082 | bpstat bs; | |
12083 | ||
12084 | for (bs = bps; bs; bs = bs->next) | |
12085 | if (bs->breakpoint_at == bpt) | |
12086 | { | |
12087 | bs->breakpoint_at = NULL; | |
12088 | bs->old_val = NULL; | |
12089 | /* bs->commands will be freed later. */ | |
12090 | } | |
12091 | } | |
12092 | ||
12093 | /* Callback for iterate_over_threads. */ | |
12094 | static int | |
12095 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12096 | { | |
9a3c8263 | 12097 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12098 | |
12099 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12100 | return 0; | |
12101 | } | |
12102 | ||
12103 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12104 | callbacks. */ | |
12105 | ||
12106 | static void | |
12107 | say_where (struct breakpoint *b) | |
12108 | { | |
12109 | struct value_print_options opts; | |
12110 | ||
12111 | get_user_print_options (&opts); | |
12112 | ||
12113 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12114 | single string. */ | |
12115 | if (b->loc == NULL) | |
12116 | { | |
f00aae0f KS |
12117 | /* For pending locations, the output differs slightly based |
12118 | on b->extra_string. If this is non-NULL, it contains either | |
12119 | a condition or dprintf arguments. */ | |
12120 | if (b->extra_string == NULL) | |
12121 | { | |
12122 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12123 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12124 | } |
12125 | else if (b->type == bp_dprintf) | |
12126 | { | |
12127 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12128 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12129 | b->extra_string); |
12130 | } | |
12131 | else | |
12132 | { | |
12133 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12134 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12135 | b->extra_string); |
12136 | } | |
348d480f PA |
12137 | } |
12138 | else | |
12139 | { | |
2f202fde | 12140 | if (opts.addressprint || b->loc->symtab == NULL) |
6a831f06 PA |
12141 | printf_filtered (" at %ps", |
12142 | styled_string (address_style.style (), | |
12143 | paddress (b->loc->gdbarch, | |
12144 | b->loc->address))); | |
2f202fde | 12145 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12146 | { |
12147 | /* If there is a single location, we can print the location | |
12148 | more nicely. */ | |
12149 | if (b->loc->next == NULL) | |
0bb296cb | 12150 | { |
6a831f06 PA |
12151 | const char *filename |
12152 | = symtab_to_filename_for_display (b->loc->symtab); | |
12153 | printf_filtered (": file %ps, line %d.", | |
12154 | styled_string (file_name_style.style (), | |
12155 | filename), | |
0bb296cb TT |
12156 | b->loc->line_number); |
12157 | } | |
f8eba3c6 TT |
12158 | else |
12159 | /* This is not ideal, but each location may have a | |
12160 | different file name, and this at least reflects the | |
12161 | real situation somewhat. */ | |
f00aae0f | 12162 | printf_filtered (": %s.", |
d28cd78a | 12163 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12164 | } |
348d480f PA |
12165 | |
12166 | if (b->loc->next) | |
12167 | { | |
12168 | struct bp_location *loc = b->loc; | |
12169 | int n = 0; | |
12170 | for (; loc; loc = loc->next) | |
12171 | ++n; | |
12172 | printf_filtered (" (%d locations)", n); | |
12173 | } | |
12174 | } | |
12175 | } | |
12176 | ||
5f486660 | 12177 | bp_location::~bp_location () |
348d480f | 12178 | { |
5f486660 | 12179 | xfree (function_name); |
348d480f PA |
12180 | } |
12181 | ||
c1fc2657 | 12182 | /* Destructor for the breakpoint base class. */ |
348d480f | 12183 | |
c1fc2657 | 12184 | breakpoint::~breakpoint () |
348d480f | 12185 | { |
c1fc2657 SM |
12186 | xfree (this->cond_string); |
12187 | xfree (this->extra_string); | |
348d480f PA |
12188 | } |
12189 | ||
2060206e PA |
12190 | static struct bp_location * |
12191 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12192 | { |
5f486660 | 12193 | return new bp_location (self); |
348d480f PA |
12194 | } |
12195 | ||
2060206e PA |
12196 | static void |
12197 | base_breakpoint_re_set (struct breakpoint *b) | |
12198 | { | |
12199 | /* Nothing to re-set. */ | |
12200 | } | |
12201 | ||
12202 | #define internal_error_pure_virtual_called() \ | |
12203 | gdb_assert_not_reached ("pure virtual function called") | |
12204 | ||
12205 | static int | |
12206 | base_breakpoint_insert_location (struct bp_location *bl) | |
12207 | { | |
12208 | internal_error_pure_virtual_called (); | |
12209 | } | |
12210 | ||
12211 | static int | |
73971819 PA |
12212 | base_breakpoint_remove_location (struct bp_location *bl, |
12213 | enum remove_bp_reason reason) | |
2060206e PA |
12214 | { |
12215 | internal_error_pure_virtual_called (); | |
12216 | } | |
12217 | ||
12218 | static int | |
12219 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12220 | const address_space *aspace, |
09ac7c10 TT |
12221 | CORE_ADDR bp_addr, |
12222 | const struct target_waitstatus *ws) | |
2060206e PA |
12223 | { |
12224 | internal_error_pure_virtual_called (); | |
12225 | } | |
12226 | ||
12227 | static void | |
12228 | base_breakpoint_check_status (bpstat bs) | |
12229 | { | |
12230 | /* Always stop. */ | |
12231 | } | |
12232 | ||
12233 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12234 | errors. */ | |
12235 | ||
12236 | static int | |
12237 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12238 | { | |
12239 | internal_error_pure_virtual_called (); | |
12240 | } | |
12241 | ||
12242 | /* A "resources_needed" breakpoint_ops method that just internal | |
12243 | errors. */ | |
12244 | ||
12245 | static int | |
12246 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12247 | { | |
12248 | internal_error_pure_virtual_called (); | |
12249 | } | |
12250 | ||
12251 | static enum print_stop_action | |
12252 | base_breakpoint_print_it (bpstat bs) | |
12253 | { | |
12254 | internal_error_pure_virtual_called (); | |
12255 | } | |
12256 | ||
12257 | static void | |
12258 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12259 | struct ui_out *uiout) | |
12260 | { | |
12261 | /* nothing */ | |
12262 | } | |
12263 | ||
12264 | static void | |
12265 | base_breakpoint_print_mention (struct breakpoint *b) | |
12266 | { | |
12267 | internal_error_pure_virtual_called (); | |
12268 | } | |
12269 | ||
12270 | static void | |
12271 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12272 | { | |
12273 | internal_error_pure_virtual_called (); | |
12274 | } | |
12275 | ||
983af33b | 12276 | static void |
f00aae0f KS |
12277 | base_breakpoint_create_sals_from_location |
12278 | (const struct event_location *location, | |
12279 | struct linespec_result *canonical, | |
12280 | enum bptype type_wanted) | |
983af33b SDJ |
12281 | { |
12282 | internal_error_pure_virtual_called (); | |
12283 | } | |
12284 | ||
12285 | static void | |
12286 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12287 | struct linespec_result *c, | |
e1e01040 PA |
12288 | gdb::unique_xmalloc_ptr<char> cond_string, |
12289 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12290 | enum bptype type_wanted, |
12291 | enum bpdisp disposition, | |
12292 | int thread, | |
12293 | int task, int ignore_count, | |
12294 | const struct breakpoint_ops *o, | |
12295 | int from_tty, int enabled, | |
44f238bb | 12296 | int internal, unsigned flags) |
983af33b SDJ |
12297 | { |
12298 | internal_error_pure_virtual_called (); | |
12299 | } | |
12300 | ||
6c5b2ebe | 12301 | static std::vector<symtab_and_line> |
f00aae0f KS |
12302 | base_breakpoint_decode_location (struct breakpoint *b, |
12303 | const struct event_location *location, | |
6c5b2ebe | 12304 | struct program_space *search_pspace) |
983af33b SDJ |
12305 | { |
12306 | internal_error_pure_virtual_called (); | |
12307 | } | |
12308 | ||
ab04a2af TT |
12309 | /* The default 'explains_signal' method. */ |
12310 | ||
47591c29 | 12311 | static int |
427cd150 | 12312 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12313 | { |
47591c29 | 12314 | return 1; |
ab04a2af TT |
12315 | } |
12316 | ||
9d6e6e84 HZ |
12317 | /* The default "after_condition_true" method. */ |
12318 | ||
12319 | static void | |
12320 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12321 | { | |
12322 | /* Nothing to do. */ | |
12323 | } | |
12324 | ||
ab04a2af | 12325 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12326 | { |
2060206e PA |
12327 | base_breakpoint_allocate_location, |
12328 | base_breakpoint_re_set, | |
12329 | base_breakpoint_insert_location, | |
12330 | base_breakpoint_remove_location, | |
12331 | base_breakpoint_breakpoint_hit, | |
12332 | base_breakpoint_check_status, | |
12333 | base_breakpoint_resources_needed, | |
12334 | base_breakpoint_works_in_software_mode, | |
12335 | base_breakpoint_print_it, | |
12336 | NULL, | |
12337 | base_breakpoint_print_one_detail, | |
12338 | base_breakpoint_print_mention, | |
983af33b | 12339 | base_breakpoint_print_recreate, |
5f700d83 | 12340 | base_breakpoint_create_sals_from_location, |
983af33b | 12341 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12342 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12343 | base_breakpoint_explains_signal, |
12344 | base_breakpoint_after_condition_true, | |
2060206e PA |
12345 | }; |
12346 | ||
12347 | /* Default breakpoint_ops methods. */ | |
12348 | ||
12349 | static void | |
348d480f PA |
12350 | bkpt_re_set (struct breakpoint *b) |
12351 | { | |
06edf0c0 | 12352 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12353 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12354 | { |
f00aae0f | 12355 | /* Anything without a location can't be re-set. */ |
348d480f | 12356 | delete_breakpoint (b); |
06edf0c0 | 12357 | return; |
348d480f | 12358 | } |
06edf0c0 PA |
12359 | |
12360 | breakpoint_re_set_default (b); | |
348d480f PA |
12361 | } |
12362 | ||
2060206e | 12363 | static int |
348d480f PA |
12364 | bkpt_insert_location (struct bp_location *bl) |
12365 | { | |
cd6c3b4f YQ |
12366 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12367 | ||
579c6ad9 | 12368 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12369 | bl->target_info.placed_address = addr; |
12370 | ||
348d480f | 12371 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12372 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12373 | else |
7c16b83e | 12374 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12375 | } |
12376 | ||
2060206e | 12377 | static int |
73971819 | 12378 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12379 | { |
12380 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12381 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12382 | else | |
73971819 | 12383 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12384 | } |
12385 | ||
2060206e | 12386 | static int |
348d480f | 12387 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 12388 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12389 | const struct target_waitstatus *ws) |
348d480f | 12390 | { |
09ac7c10 | 12391 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12392 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12393 | return 0; |
12394 | ||
348d480f PA |
12395 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12396 | aspace, bp_addr)) | |
12397 | return 0; | |
12398 | ||
12399 | if (overlay_debugging /* unmapped overlay section */ | |
12400 | && section_is_overlay (bl->section) | |
12401 | && !section_is_mapped (bl->section)) | |
12402 | return 0; | |
12403 | ||
12404 | return 1; | |
12405 | } | |
12406 | ||
cd1608cc PA |
12407 | static int |
12408 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12409 | const address_space *aspace, CORE_ADDR bp_addr, |
cd1608cc PA |
12410 | const struct target_waitstatus *ws) |
12411 | { | |
12412 | if (dprintf_style == dprintf_style_agent | |
12413 | && target_can_run_breakpoint_commands ()) | |
12414 | { | |
12415 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12416 | for this address it must be for a breakpoint that happens to | |
12417 | be set at the same address. */ | |
12418 | return 0; | |
12419 | } | |
12420 | ||
12421 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12422 | } | |
12423 | ||
2060206e | 12424 | static int |
348d480f PA |
12425 | bkpt_resources_needed (const struct bp_location *bl) |
12426 | { | |
12427 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12428 | ||
12429 | return 1; | |
12430 | } | |
12431 | ||
2060206e | 12432 | static enum print_stop_action |
348d480f PA |
12433 | bkpt_print_it (bpstat bs) |
12434 | { | |
348d480f PA |
12435 | struct breakpoint *b; |
12436 | const struct bp_location *bl; | |
001c8c33 | 12437 | int bp_temp; |
79a45e25 | 12438 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12439 | |
12440 | gdb_assert (bs->bp_location_at != NULL); | |
12441 | ||
12442 | bl = bs->bp_location_at; | |
12443 | b = bs->breakpoint_at; | |
12444 | ||
001c8c33 PA |
12445 | bp_temp = b->disposition == disp_del; |
12446 | if (bl->address != bl->requested_address) | |
12447 | breakpoint_adjustment_warning (bl->requested_address, | |
12448 | bl->address, | |
12449 | b->number, 1); | |
12450 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12451 | maybe_print_thread_hit_breakpoint (uiout); |
12452 | ||
112e8700 | 12453 | if (uiout->is_mi_like_p ()) |
348d480f | 12454 | { |
112e8700 | 12455 | uiout->field_string ("reason", |
001c8c33 | 12456 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12457 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12458 | } |
6a831f06 PA |
12459 | if (bp_temp) |
12460 | uiout->message ("Temporary breakpoint %pF, ", | |
12461 | signed_field ("bkptno", b->number)); | |
12462 | else | |
12463 | uiout->message ("Breakpoint %pF, ", | |
12464 | signed_field ("bkptno", b->number)); | |
06edf0c0 | 12465 | |
001c8c33 | 12466 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12467 | } |
12468 | ||
2060206e | 12469 | static void |
06edf0c0 PA |
12470 | bkpt_print_mention (struct breakpoint *b) |
12471 | { | |
112e8700 | 12472 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12473 | return; |
12474 | ||
12475 | switch (b->type) | |
12476 | { | |
12477 | case bp_breakpoint: | |
12478 | case bp_gnu_ifunc_resolver: | |
12479 | if (b->disposition == disp_del) | |
12480 | printf_filtered (_("Temporary breakpoint")); | |
12481 | else | |
12482 | printf_filtered (_("Breakpoint")); | |
12483 | printf_filtered (_(" %d"), b->number); | |
12484 | if (b->type == bp_gnu_ifunc_resolver) | |
12485 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12486 | break; | |
12487 | case bp_hardware_breakpoint: | |
12488 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12489 | break; | |
e7e0cddf SS |
12490 | case bp_dprintf: |
12491 | printf_filtered (_("Dprintf %d"), b->number); | |
12492 | break; | |
06edf0c0 PA |
12493 | } |
12494 | ||
12495 | say_where (b); | |
12496 | } | |
12497 | ||
2060206e | 12498 | static void |
06edf0c0 PA |
12499 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12500 | { | |
12501 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12502 | fprintf_unfiltered (fp, "tbreak"); | |
12503 | else if (tp->type == bp_breakpoint) | |
12504 | fprintf_unfiltered (fp, "break"); | |
12505 | else if (tp->type == bp_hardware_breakpoint | |
12506 | && tp->disposition == disp_del) | |
12507 | fprintf_unfiltered (fp, "thbreak"); | |
12508 | else if (tp->type == bp_hardware_breakpoint) | |
12509 | fprintf_unfiltered (fp, "hbreak"); | |
12510 | else | |
12511 | internal_error (__FILE__, __LINE__, | |
12512 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12513 | ||
f00aae0f | 12514 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12515 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12516 | |
12517 | /* Print out extra_string if this breakpoint is pending. It might | |
12518 | contain, for example, conditions that were set by the user. */ | |
12519 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12520 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12521 | ||
dd11a36c | 12522 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12523 | } |
12524 | ||
983af33b | 12525 | static void |
f00aae0f KS |
12526 | bkpt_create_sals_from_location (const struct event_location *location, |
12527 | struct linespec_result *canonical, | |
12528 | enum bptype type_wanted) | |
983af33b | 12529 | { |
f00aae0f | 12530 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12531 | } |
12532 | ||
12533 | static void | |
12534 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12535 | struct linespec_result *canonical, | |
e1e01040 PA |
12536 | gdb::unique_xmalloc_ptr<char> cond_string, |
12537 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12538 | enum bptype type_wanted, |
12539 | enum bpdisp disposition, | |
12540 | int thread, | |
12541 | int task, int ignore_count, | |
12542 | const struct breakpoint_ops *ops, | |
12543 | int from_tty, int enabled, | |
44f238bb | 12544 | int internal, unsigned flags) |
983af33b | 12545 | { |
023fa29b | 12546 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12547 | std::move (cond_string), |
12548 | std::move (extra_string), | |
e7e0cddf | 12549 | type_wanted, |
983af33b SDJ |
12550 | disposition, thread, task, |
12551 | ignore_count, ops, from_tty, | |
44f238bb | 12552 | enabled, internal, flags); |
983af33b SDJ |
12553 | } |
12554 | ||
6c5b2ebe | 12555 | static std::vector<symtab_and_line> |
f00aae0f KS |
12556 | bkpt_decode_location (struct breakpoint *b, |
12557 | const struct event_location *location, | |
6c5b2ebe | 12558 | struct program_space *search_pspace) |
983af33b | 12559 | { |
6c5b2ebe | 12560 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12561 | } |
12562 | ||
06edf0c0 PA |
12563 | /* Virtual table for internal breakpoints. */ |
12564 | ||
12565 | static void | |
12566 | internal_bkpt_re_set (struct breakpoint *b) | |
12567 | { | |
12568 | switch (b->type) | |
12569 | { | |
12570 | /* Delete overlay event and longjmp master breakpoints; they | |
12571 | will be reset later by breakpoint_re_set. */ | |
12572 | case bp_overlay_event: | |
12573 | case bp_longjmp_master: | |
12574 | case bp_std_terminate_master: | |
12575 | case bp_exception_master: | |
12576 | delete_breakpoint (b); | |
12577 | break; | |
12578 | ||
12579 | /* This breakpoint is special, it's set up when the inferior | |
12580 | starts and we really don't want to touch it. */ | |
12581 | case bp_shlib_event: | |
12582 | ||
12583 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12584 | it is set up, we do not want to touch it. */ | |
12585 | case bp_thread_event: | |
12586 | break; | |
12587 | } | |
12588 | } | |
12589 | ||
12590 | static void | |
12591 | internal_bkpt_check_status (bpstat bs) | |
12592 | { | |
a9b3a50f PA |
12593 | if (bs->breakpoint_at->type == bp_shlib_event) |
12594 | { | |
12595 | /* If requested, stop when the dynamic linker notifies GDB of | |
12596 | events. This allows the user to get control and place | |
12597 | breakpoints in initializer routines for dynamically loaded | |
12598 | objects (among other things). */ | |
12599 | bs->stop = stop_on_solib_events; | |
12600 | bs->print = stop_on_solib_events; | |
12601 | } | |
12602 | else | |
12603 | bs->stop = 0; | |
06edf0c0 PA |
12604 | } |
12605 | ||
12606 | static enum print_stop_action | |
12607 | internal_bkpt_print_it (bpstat bs) | |
12608 | { | |
06edf0c0 | 12609 | struct breakpoint *b; |
06edf0c0 | 12610 | |
06edf0c0 PA |
12611 | b = bs->breakpoint_at; |
12612 | ||
06edf0c0 PA |
12613 | switch (b->type) |
12614 | { | |
348d480f PA |
12615 | case bp_shlib_event: |
12616 | /* Did we stop because the user set the stop_on_solib_events | |
12617 | variable? (If so, we report this as a generic, "Stopped due | |
12618 | to shlib event" message.) */ | |
edcc5120 | 12619 | print_solib_event (0); |
348d480f PA |
12620 | break; |
12621 | ||
12622 | case bp_thread_event: | |
12623 | /* Not sure how we will get here. | |
12624 | GDB should not stop for these breakpoints. */ | |
12625 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12626 | break; |
12627 | ||
12628 | case bp_overlay_event: | |
12629 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12630 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12631 | break; |
12632 | ||
12633 | case bp_longjmp_master: | |
12634 | /* These should never be enabled. */ | |
12635 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12636 | break; |
12637 | ||
12638 | case bp_std_terminate_master: | |
12639 | /* These should never be enabled. */ | |
12640 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12641 | "gdb should not stop!\n")); | |
348d480f PA |
12642 | break; |
12643 | ||
12644 | case bp_exception_master: | |
12645 | /* These should never be enabled. */ | |
12646 | printf_filtered (_("Exception Master Breakpoint: " | |
12647 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12648 | break; |
12649 | } | |
12650 | ||
001c8c33 | 12651 | return PRINT_NOTHING; |
06edf0c0 PA |
12652 | } |
12653 | ||
12654 | static void | |
12655 | internal_bkpt_print_mention (struct breakpoint *b) | |
12656 | { | |
12657 | /* Nothing to mention. These breakpoints are internal. */ | |
12658 | } | |
12659 | ||
06edf0c0 PA |
12660 | /* Virtual table for momentary breakpoints */ |
12661 | ||
12662 | static void | |
12663 | momentary_bkpt_re_set (struct breakpoint *b) | |
12664 | { | |
12665 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12666 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12667 | Otherwise these should have been blown away via the cleanup chain |
12668 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12669 | } | |
12670 | ||
12671 | static void | |
12672 | momentary_bkpt_check_status (bpstat bs) | |
12673 | { | |
12674 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12675 | } | |
12676 | ||
12677 | static enum print_stop_action | |
12678 | momentary_bkpt_print_it (bpstat bs) | |
12679 | { | |
001c8c33 | 12680 | return PRINT_UNKNOWN; |
348d480f PA |
12681 | } |
12682 | ||
06edf0c0 PA |
12683 | static void |
12684 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12685 | { |
06edf0c0 | 12686 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12687 | } |
12688 | ||
e2e4d78b JK |
12689 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12690 | ||
12691 | It gets cleared already on the removal of the first one of such placed | |
12692 | breakpoints. This is OK as they get all removed altogether. */ | |
12693 | ||
c1fc2657 | 12694 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12695 | { |
c1fc2657 | 12696 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12697 | |
c1fc2657 | 12698 | if (tp != NULL) |
e2e4d78b | 12699 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12700 | } |
12701 | ||
55aa24fb SDJ |
12702 | /* Specific methods for probe breakpoints. */ |
12703 | ||
12704 | static int | |
12705 | bkpt_probe_insert_location (struct bp_location *bl) | |
12706 | { | |
12707 | int v = bkpt_insert_location (bl); | |
12708 | ||
12709 | if (v == 0) | |
12710 | { | |
12711 | /* The insertion was successful, now let's set the probe's semaphore | |
12712 | if needed. */ | |
935676c9 | 12713 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12714 | } |
12715 | ||
12716 | return v; | |
12717 | } | |
12718 | ||
12719 | static int | |
73971819 PA |
12720 | bkpt_probe_remove_location (struct bp_location *bl, |
12721 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
12722 | { |
12723 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 12724 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 12725 | |
73971819 | 12726 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
12727 | } |
12728 | ||
12729 | static void | |
f00aae0f | 12730 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12731 | struct linespec_result *canonical, |
f00aae0f | 12732 | enum bptype type_wanted) |
55aa24fb SDJ |
12733 | { |
12734 | struct linespec_sals lsal; | |
12735 | ||
c2f4122d | 12736 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
12737 | lsal.canonical |
12738 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12739 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
12740 | } |
12741 | ||
6c5b2ebe | 12742 | static std::vector<symtab_and_line> |
f00aae0f KS |
12743 | bkpt_probe_decode_location (struct breakpoint *b, |
12744 | const struct event_location *location, | |
6c5b2ebe | 12745 | struct program_space *search_pspace) |
55aa24fb | 12746 | { |
6c5b2ebe PA |
12747 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
12748 | if (sals.empty ()) | |
55aa24fb | 12749 | error (_("probe not found")); |
6c5b2ebe | 12750 | return sals; |
55aa24fb SDJ |
12751 | } |
12752 | ||
348d480f | 12753 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12754 | |
348d480f PA |
12755 | static void |
12756 | tracepoint_re_set (struct breakpoint *b) | |
12757 | { | |
12758 | breakpoint_re_set_default (b); | |
12759 | } | |
876fa593 | 12760 | |
348d480f PA |
12761 | static int |
12762 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12763 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12764 | const struct target_waitstatus *ws) |
348d480f PA |
12765 | { |
12766 | /* By definition, the inferior does not report stops at | |
12767 | tracepoints. */ | |
12768 | return 0; | |
74960c60 VP |
12769 | } |
12770 | ||
12771 | static void | |
348d480f PA |
12772 | tracepoint_print_one_detail (const struct breakpoint *self, |
12773 | struct ui_out *uiout) | |
74960c60 | 12774 | { |
d9b3f62e | 12775 | struct tracepoint *tp = (struct tracepoint *) self; |
5d9310c4 | 12776 | if (!tp->static_trace_marker_id.empty ()) |
348d480f PA |
12777 | { |
12778 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12779 | |
6a831f06 PA |
12780 | uiout->message ("\tmarker id is %pF\n", |
12781 | string_field ("static-tracepoint-marker-string-id", | |
12782 | tp->static_trace_marker_id.c_str ())); | |
348d480f | 12783 | } |
0d381245 VP |
12784 | } |
12785 | ||
a474d7c2 | 12786 | static void |
348d480f | 12787 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12788 | { |
112e8700 | 12789 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12790 | return; |
cc59ec59 | 12791 | |
348d480f PA |
12792 | switch (b->type) |
12793 | { | |
12794 | case bp_tracepoint: | |
12795 | printf_filtered (_("Tracepoint")); | |
12796 | printf_filtered (_(" %d"), b->number); | |
12797 | break; | |
12798 | case bp_fast_tracepoint: | |
12799 | printf_filtered (_("Fast tracepoint")); | |
12800 | printf_filtered (_(" %d"), b->number); | |
12801 | break; | |
12802 | case bp_static_tracepoint: | |
12803 | printf_filtered (_("Static tracepoint")); | |
12804 | printf_filtered (_(" %d"), b->number); | |
12805 | break; | |
12806 | default: | |
12807 | internal_error (__FILE__, __LINE__, | |
12808 | _("unhandled tracepoint type %d"), (int) b->type); | |
12809 | } | |
12810 | ||
12811 | say_where (b); | |
a474d7c2 PA |
12812 | } |
12813 | ||
348d480f | 12814 | static void |
d9b3f62e | 12815 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12816 | { |
d9b3f62e PA |
12817 | struct tracepoint *tp = (struct tracepoint *) self; |
12818 | ||
12819 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12820 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 12821 | else if (self->type == bp_static_tracepoint) |
348d480f | 12822 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12823 | else if (self->type == bp_tracepoint) |
348d480f PA |
12824 | fprintf_unfiltered (fp, "trace"); |
12825 | else | |
12826 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12827 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12828 | |
f00aae0f | 12829 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12830 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
12831 | print_recreate_thread (self, fp); |
12832 | ||
12833 | if (tp->pass_count) | |
12834 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12835 | } |
12836 | ||
983af33b | 12837 | static void |
f00aae0f KS |
12838 | tracepoint_create_sals_from_location (const struct event_location *location, |
12839 | struct linespec_result *canonical, | |
12840 | enum bptype type_wanted) | |
983af33b | 12841 | { |
f00aae0f | 12842 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12843 | } |
12844 | ||
12845 | static void | |
12846 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12847 | struct linespec_result *canonical, | |
e1e01040 PA |
12848 | gdb::unique_xmalloc_ptr<char> cond_string, |
12849 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12850 | enum bptype type_wanted, |
12851 | enum bpdisp disposition, | |
12852 | int thread, | |
12853 | int task, int ignore_count, | |
12854 | const struct breakpoint_ops *ops, | |
12855 | int from_tty, int enabled, | |
44f238bb | 12856 | int internal, unsigned flags) |
983af33b | 12857 | { |
023fa29b | 12858 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12859 | std::move (cond_string), |
12860 | std::move (extra_string), | |
e7e0cddf | 12861 | type_wanted, |
983af33b SDJ |
12862 | disposition, thread, task, |
12863 | ignore_count, ops, from_tty, | |
44f238bb | 12864 | enabled, internal, flags); |
983af33b SDJ |
12865 | } |
12866 | ||
6c5b2ebe | 12867 | static std::vector<symtab_and_line> |
f00aae0f KS |
12868 | tracepoint_decode_location (struct breakpoint *b, |
12869 | const struct event_location *location, | |
6c5b2ebe | 12870 | struct program_space *search_pspace) |
983af33b | 12871 | { |
6c5b2ebe | 12872 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12873 | } |
12874 | ||
2060206e | 12875 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12876 | |
bac7c5cf | 12877 | /* Virtual table for tracepoints on static probes. */ |
55aa24fb SDJ |
12878 | |
12879 | static void | |
f00aae0f KS |
12880 | tracepoint_probe_create_sals_from_location |
12881 | (const struct event_location *location, | |
12882 | struct linespec_result *canonical, | |
12883 | enum bptype type_wanted) | |
55aa24fb SDJ |
12884 | { |
12885 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 12886 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
12887 | } |
12888 | ||
6c5b2ebe | 12889 | static std::vector<symtab_and_line> |
f00aae0f KS |
12890 | tracepoint_probe_decode_location (struct breakpoint *b, |
12891 | const struct event_location *location, | |
6c5b2ebe | 12892 | struct program_space *search_pspace) |
55aa24fb SDJ |
12893 | { |
12894 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 12895 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
12896 | } |
12897 | ||
5c2b4418 HZ |
12898 | /* Dprintf breakpoint_ops methods. */ |
12899 | ||
12900 | static void | |
12901 | dprintf_re_set (struct breakpoint *b) | |
12902 | { | |
12903 | breakpoint_re_set_default (b); | |
12904 | ||
f00aae0f KS |
12905 | /* extra_string should never be non-NULL for dprintf. */ |
12906 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
12907 | |
12908 | /* 1 - connect to target 1, that can run breakpoint commands. | |
12909 | 2 - create a dprintf, which resolves fine. | |
12910 | 3 - disconnect from target 1 | |
12911 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
12912 | ||
12913 | After steps #3/#4, you'll want the dprintf command list to | |
12914 | be updated, because target 1 and 2 may well return different | |
12915 | answers for target_can_run_breakpoint_commands(). | |
12916 | Given absence of finer grained resetting, we get to do | |
12917 | it all the time. */ | |
12918 | if (b->extra_string != NULL) | |
12919 | update_dprintf_command_list (b); | |
12920 | } | |
12921 | ||
2d9442cc HZ |
12922 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
12923 | ||
12924 | static void | |
12925 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
12926 | { | |
f00aae0f | 12927 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 12928 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
12929 | tp->extra_string); |
12930 | print_recreate_thread (tp, fp); | |
12931 | } | |
12932 | ||
9d6e6e84 HZ |
12933 | /* Implement the "after_condition_true" breakpoint_ops method for |
12934 | dprintf. | |
12935 | ||
12936 | dprintf's are implemented with regular commands in their command | |
12937 | list, but we run the commands here instead of before presenting the | |
12938 | stop to the user, as dprintf's don't actually cause a stop. This | |
12939 | also makes it so that the commands of multiple dprintfs at the same | |
12940 | address are all handled. */ | |
12941 | ||
12942 | static void | |
12943 | dprintf_after_condition_true (struct bpstats *bs) | |
12944 | { | |
04afa70c | 12945 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
12946 | struct bpstats *tmp_bs_p = &tmp_bs; |
12947 | ||
12948 | /* dprintf's never cause a stop. This wasn't set in the | |
12949 | check_status hook instead because that would make the dprintf's | |
12950 | condition not be evaluated. */ | |
12951 | bs->stop = 0; | |
12952 | ||
12953 | /* Run the command list here. Take ownership of it instead of | |
12954 | copying. We never want these commands to run later in | |
12955 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
12956 | be set at same address as this dprintf, or even if running the | |
12957 | commands here throws. */ | |
12958 | tmp_bs.commands = bs->commands; | |
12959 | bs->commands = NULL; | |
9d6e6e84 HZ |
12960 | |
12961 | bpstat_do_actions_1 (&tmp_bs_p); | |
12962 | ||
12963 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
12964 | bpstat_do_actions_1 may return early without processing the whole | |
12965 | list. */ | |
9d6e6e84 HZ |
12966 | } |
12967 | ||
983af33b SDJ |
12968 | /* The breakpoint_ops structure to be used on static tracepoints with |
12969 | markers (`-m'). */ | |
12970 | ||
12971 | static void | |
f00aae0f | 12972 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12973 | struct linespec_result *canonical, |
f00aae0f | 12974 | enum bptype type_wanted) |
983af33b SDJ |
12975 | { |
12976 | struct linespec_sals lsal; | |
f00aae0f | 12977 | const char *arg_start, *arg; |
983af33b | 12978 | |
a20714ff | 12979 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 12980 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 12981 | |
f2fc3015 TT |
12982 | std::string str (arg_start, arg - arg_start); |
12983 | const char *ptr = str.c_str (); | |
a20714ff PA |
12984 | canonical->location |
12985 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 12986 | |
8e9e35b1 TT |
12987 | lsal.canonical |
12988 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12989 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
12990 | } |
12991 | ||
12992 | static void | |
12993 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12994 | struct linespec_result *canonical, | |
e1e01040 PA |
12995 | gdb::unique_xmalloc_ptr<char> cond_string, |
12996 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12997 | enum bptype type_wanted, |
12998 | enum bpdisp disposition, | |
12999 | int thread, | |
13000 | int task, int ignore_count, | |
13001 | const struct breakpoint_ops *ops, | |
13002 | int from_tty, int enabled, | |
44f238bb | 13003 | int internal, unsigned flags) |
983af33b | 13004 | { |
6c5b2ebe | 13005 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
13006 | |
13007 | /* If the user is creating a static tracepoint by marker id | |
13008 | (strace -m MARKER_ID), then store the sals index, so that | |
13009 | breakpoint_re_set can try to match up which of the newly | |
13010 | found markers corresponds to this one, and, don't try to | |
13011 | expand multiple locations for each sal, given than SALS | |
13012 | already should contain all sals for MARKER_ID. */ | |
13013 | ||
6c5b2ebe | 13014 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 13015 | { |
6c5b2ebe PA |
13016 | event_location_up location |
13017 | = copy_event_location (canonical->location.get ()); | |
983af33b | 13018 | |
b270e6f9 | 13019 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 13020 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 13021 | std::move (location), NULL, |
e1e01040 PA |
13022 | std::move (cond_string), |
13023 | std::move (extra_string), | |
e7e0cddf | 13024 | type_wanted, disposition, |
983af33b | 13025 | thread, task, ignore_count, ops, |
44f238bb | 13026 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13027 | canonical->special_display); |
13028 | /* Given that its possible to have multiple markers with | |
13029 | the same string id, if the user is creating a static | |
13030 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13031 | store the sals index, so that breakpoint_re_set can | |
13032 | try to match up which of the newly found markers | |
13033 | corresponds to this one */ | |
13034 | tp->static_trace_marker_id_idx = i; | |
13035 | ||
b270e6f9 | 13036 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13037 | } |
13038 | } | |
13039 | ||
6c5b2ebe | 13040 | static std::vector<symtab_and_line> |
f00aae0f KS |
13041 | strace_marker_decode_location (struct breakpoint *b, |
13042 | const struct event_location *location, | |
6c5b2ebe | 13043 | struct program_space *search_pspace) |
983af33b SDJ |
13044 | { |
13045 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 13046 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 13047 | |
6c5b2ebe PA |
13048 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13049 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13050 | { |
6c5b2ebe PA |
13051 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13052 | sals.resize (1); | |
13053 | return sals; | |
983af33b SDJ |
13054 | } |
13055 | else | |
5d9310c4 | 13056 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
983af33b SDJ |
13057 | } |
13058 | ||
13059 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13060 | ||
13061 | static int | |
13062 | strace_marker_p (struct breakpoint *b) | |
13063 | { | |
13064 | return b->ops == &strace_marker_breakpoint_ops; | |
13065 | } | |
13066 | ||
53a5351d | 13067 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13068 | structures. */ |
c906108c SS |
13069 | |
13070 | void | |
fba45db2 | 13071 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13072 | { |
52f0bd74 | 13073 | struct breakpoint *b; |
c906108c | 13074 | |
8a3fe4f8 | 13075 | gdb_assert (bpt != NULL); |
c906108c | 13076 | |
4a64f543 MS |
13077 | /* Has this bp already been deleted? This can happen because |
13078 | multiple lists can hold pointers to bp's. bpstat lists are | |
13079 | especial culprits. | |
13080 | ||
13081 | One example of this happening is a watchpoint's scope bp. When | |
13082 | the scope bp triggers, we notice that the watchpoint is out of | |
13083 | scope, and delete it. We also delete its scope bp. But the | |
13084 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13085 | That bpstat is then checked for auto-deleting bp's, which are | |
13086 | deleted. | |
13087 | ||
13088 | A real solution to this problem might involve reference counts in | |
13089 | bp's, and/or giving them pointers back to their referencing | |
13090 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13091 | storage when no more references were extent. A cheaper bandaid | |
13092 | was chosen. */ | |
c906108c SS |
13093 | if (bpt->type == bp_none) |
13094 | return; | |
13095 | ||
4a64f543 MS |
13096 | /* At least avoid this stale reference until the reference counting |
13097 | of breakpoints gets resolved. */ | |
d0fb5eae | 13098 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13099 | { |
d0fb5eae | 13100 | struct breakpoint *related; |
3a5c3e22 | 13101 | struct watchpoint *w; |
d0fb5eae JK |
13102 | |
13103 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13104 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13105 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13106 | w = (struct watchpoint *) bpt; |
13107 | else | |
13108 | w = NULL; | |
13109 | if (w != NULL) | |
13110 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13111 | |
13112 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13113 | for (related = bpt; related->related_breakpoint != bpt; | |
13114 | related = related->related_breakpoint); | |
13115 | related->related_breakpoint = bpt->related_breakpoint; | |
13116 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13117 | } |
13118 | ||
a9634178 TJB |
13119 | /* watch_command_1 creates a watchpoint but only sets its number if |
13120 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13121 | a problem in that process, we'll be asked to delete the half-created | |
13122 | watchpoint. In that case, don't announce the deletion. */ | |
13123 | if (bpt->number) | |
76727919 | 13124 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 13125 | |
c906108c SS |
13126 | if (breakpoint_chain == bpt) |
13127 | breakpoint_chain = bpt->next; | |
13128 | ||
c906108c SS |
13129 | ALL_BREAKPOINTS (b) |
13130 | if (b->next == bpt) | |
c5aa993b JM |
13131 | { |
13132 | b->next = bpt->next; | |
13133 | break; | |
13134 | } | |
c906108c | 13135 | |
f431efe5 PA |
13136 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13137 | been freed. */ | |
13138 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13139 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13140 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13141 | commands are associated with the bpstat; if we remove it here, | |
13142 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13143 | event-top.c won't do anything, and temporary breakpoints with | |
13144 | commands won't work. */ | |
13145 | ||
13146 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13147 | ||
4a64f543 MS |
13148 | /* Now that breakpoint is removed from breakpoint list, update the |
13149 | global location list. This will remove locations that used to | |
13150 | belong to this breakpoint. Do this before freeing the breakpoint | |
13151 | itself, since remove_breakpoint looks at location's owner. It | |
13152 | might be better design to have location completely | |
13153 | self-contained, but it's not the case now. */ | |
44702360 | 13154 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13155 | |
4a64f543 MS |
13156 | /* On the chance that someone will soon try again to delete this |
13157 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13158 | bpt->type = bp_none; |
4d01a485 | 13159 | delete bpt; |
c906108c SS |
13160 | } |
13161 | ||
51be5b68 PA |
13162 | /* Iterator function to call a user-provided callback function once |
13163 | for each of B and its related breakpoints. */ | |
13164 | ||
13165 | static void | |
13166 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13167 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13168 | { |
13169 | struct breakpoint *related; | |
13170 | ||
13171 | related = b; | |
13172 | do | |
13173 | { | |
13174 | struct breakpoint *next; | |
13175 | ||
13176 | /* FUNCTION may delete RELATED. */ | |
13177 | next = related->related_breakpoint; | |
13178 | ||
13179 | if (next == related) | |
13180 | { | |
13181 | /* RELATED is the last ring entry. */ | |
48649e1b | 13182 | function (related); |
51be5b68 PA |
13183 | |
13184 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13185 | B. There's nothing left to do anyway, so just break | |
13186 | out. */ | |
13187 | break; | |
13188 | } | |
13189 | else | |
48649e1b | 13190 | function (related); |
51be5b68 PA |
13191 | |
13192 | related = next; | |
13193 | } | |
13194 | while (related != b); | |
13195 | } | |
95a42b64 | 13196 | |
4495129a | 13197 | static void |
981a3fb3 | 13198 | delete_command (const char *arg, int from_tty) |
c906108c | 13199 | { |
35df4500 | 13200 | struct breakpoint *b, *b_tmp; |
c906108c | 13201 | |
ea9365bb TT |
13202 | dont_repeat (); |
13203 | ||
c906108c SS |
13204 | if (arg == 0) |
13205 | { | |
13206 | int breaks_to_delete = 0; | |
13207 | ||
46c6471b PA |
13208 | /* Delete all breakpoints if no argument. Do not delete |
13209 | internal breakpoints, these have to be deleted with an | |
13210 | explicit breakpoint number argument. */ | |
c5aa993b | 13211 | ALL_BREAKPOINTS (b) |
46c6471b | 13212 | if (user_breakpoint_p (b)) |
973d738b DJ |
13213 | { |
13214 | breaks_to_delete = 1; | |
13215 | break; | |
13216 | } | |
c906108c SS |
13217 | |
13218 | /* Ask user only if there are some breakpoints to delete. */ | |
13219 | if (!from_tty | |
e2e0b3e5 | 13220 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13221 | { |
35df4500 | 13222 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13223 | if (user_breakpoint_p (b)) |
c5aa993b | 13224 | delete_breakpoint (b); |
c906108c SS |
13225 | } |
13226 | } | |
13227 | else | |
48649e1b | 13228 | map_breakpoint_numbers |
b926417a | 13229 | (arg, [&] (breakpoint *br) |
48649e1b | 13230 | { |
b926417a | 13231 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 13232 | }); |
c906108c SS |
13233 | } |
13234 | ||
c2f4122d PA |
13235 | /* Return true if all locations of B bound to PSPACE are pending. If |
13236 | PSPACE is NULL, all locations of all program spaces are | |
13237 | considered. */ | |
13238 | ||
0d381245 | 13239 | static int |
c2f4122d | 13240 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13241 | { |
c2f4122d PA |
13242 | struct bp_location *loc; |
13243 | ||
13244 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13245 | if ((pspace == NULL | |
13246 | || loc->pspace == pspace) | |
13247 | && !loc->shlib_disabled | |
8645ff69 | 13248 | && !loc->pspace->executing_startup) |
0d381245 VP |
13249 | return 0; |
13250 | return 1; | |
fe3f5fa8 VP |
13251 | } |
13252 | ||
776592bf DE |
13253 | /* Subroutine of update_breakpoint_locations to simplify it. |
13254 | Return non-zero if multiple fns in list LOC have the same name. | |
13255 | Null names are ignored. */ | |
13256 | ||
13257 | static int | |
13258 | ambiguous_names_p (struct bp_location *loc) | |
13259 | { | |
13260 | struct bp_location *l; | |
459a2e4c TT |
13261 | htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
13262 | xcalloc, xfree); | |
776592bf DE |
13263 | |
13264 | for (l = loc; l != NULL; l = l->next) | |
13265 | { | |
13266 | const char **slot; | |
13267 | const char *name = l->function_name; | |
13268 | ||
13269 | /* Allow for some names to be NULL, ignore them. */ | |
13270 | if (name == NULL) | |
13271 | continue; | |
13272 | ||
13273 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13274 | INSERT); | |
4a64f543 MS |
13275 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13276 | returns NULL. */ | |
776592bf DE |
13277 | if (*slot != NULL) |
13278 | { | |
13279 | htab_delete (htab); | |
13280 | return 1; | |
13281 | } | |
13282 | *slot = name; | |
13283 | } | |
13284 | ||
13285 | htab_delete (htab); | |
13286 | return 0; | |
13287 | } | |
13288 | ||
0fb4aa4b PA |
13289 | /* When symbols change, it probably means the sources changed as well, |
13290 | and it might mean the static tracepoint markers are no longer at | |
13291 | the same address or line numbers they used to be at last we | |
13292 | checked. Losing your static tracepoints whenever you rebuild is | |
13293 | undesirable. This function tries to resync/rematch gdb static | |
13294 | tracepoints with the markers on the target, for static tracepoints | |
13295 | that have not been set by marker id. Static tracepoint that have | |
13296 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13297 | The heuristic is: | |
13298 | ||
13299 | 1) For a tracepoint set at a specific address, look for a marker at | |
13300 | the old PC. If one is found there, assume to be the same marker. | |
13301 | If the name / string id of the marker found is different from the | |
13302 | previous known name, assume that means the user renamed the marker | |
13303 | in the sources, and output a warning. | |
13304 | ||
13305 | 2) For a tracepoint set at a given line number, look for a marker | |
13306 | at the new address of the old line number. If one is found there, | |
13307 | assume to be the same marker. If the name / string id of the | |
13308 | marker found is different from the previous known name, assume that | |
13309 | means the user renamed the marker in the sources, and output a | |
13310 | warning. | |
13311 | ||
13312 | 3) If a marker is no longer found at the same address or line, it | |
13313 | may mean the marker no longer exists. But it may also just mean | |
13314 | the code changed a bit. Maybe the user added a few lines of code | |
13315 | that made the marker move up or down (in line number terms). Ask | |
13316 | the target for info about the marker with the string id as we knew | |
13317 | it. If found, update line number and address in the matching | |
13318 | static tracepoint. This will get confused if there's more than one | |
13319 | marker with the same ID (possible in UST, although unadvised | |
13320 | precisely because it confuses tools). */ | |
13321 | ||
13322 | static struct symtab_and_line | |
13323 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13324 | { | |
d9b3f62e | 13325 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13326 | struct static_tracepoint_marker marker; |
13327 | CORE_ADDR pc; | |
0fb4aa4b PA |
13328 | |
13329 | pc = sal.pc; | |
13330 | if (sal.line) | |
13331 | find_line_pc (sal.symtab, sal.line, &pc); | |
13332 | ||
13333 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13334 | { | |
5d9310c4 | 13335 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 13336 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
13337 | b->number, tp->static_trace_marker_id.c_str (), |
13338 | marker.str_id.c_str ()); | |
0fb4aa4b | 13339 | |
5d9310c4 | 13340 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
13341 | |
13342 | return sal; | |
13343 | } | |
13344 | ||
13345 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13346 | by string ID. */ | |
13347 | if (!sal.explicit_pc | |
13348 | && sal.line != 0 | |
13349 | && sal.symtab != NULL | |
5d9310c4 | 13350 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 13351 | { |
5d9310c4 SM |
13352 | std::vector<static_tracepoint_marker> markers |
13353 | = target_static_tracepoint_markers_by_strid | |
13354 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 13355 | |
5d9310c4 | 13356 | if (!markers.empty ()) |
0fb4aa4b | 13357 | { |
0fb4aa4b | 13358 | struct symbol *sym; |
80e1d417 | 13359 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13360 | struct ui_out *uiout = current_uiout; |
67994074 | 13361 | struct explicit_location explicit_loc; |
0fb4aa4b | 13362 | |
5d9310c4 | 13363 | tpmarker = &markers[0]; |
0fb4aa4b | 13364 | |
5d9310c4 | 13365 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
13366 | |
13367 | warning (_("marker for static tracepoint %d (%s) not " | |
13368 | "found at previous line number"), | |
5d9310c4 | 13369 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 13370 | |
51abb421 | 13371 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13372 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13373 | uiout->text ("Now in "); |
0fb4aa4b PA |
13374 | if (sym) |
13375 | { | |
987012b8 | 13376 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 13377 | function_name_style.style ()); |
112e8700 | 13378 | uiout->text (" at "); |
0fb4aa4b | 13379 | } |
112e8700 | 13380 | uiout->field_string ("file", |
cbe56571 | 13381 | symtab_to_filename_for_display (sal2.symtab), |
e43b10e1 | 13382 | file_name_style.style ()); |
112e8700 | 13383 | uiout->text (":"); |
0fb4aa4b | 13384 | |
112e8700 | 13385 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13386 | { |
0b0865da | 13387 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13388 | |
112e8700 | 13389 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13390 | } |
13391 | ||
381befee | 13392 | uiout->field_signed ("line", sal2.line); |
112e8700 | 13393 | uiout->text ("\n"); |
0fb4aa4b | 13394 | |
80e1d417 | 13395 | b->loc->line_number = sal2.line; |
2f202fde | 13396 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13397 | |
d28cd78a | 13398 | b->location.reset (NULL); |
67994074 KS |
13399 | initialize_explicit_location (&explicit_loc); |
13400 | explicit_loc.source_filename | |
00e52e53 | 13401 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13402 | explicit_loc.line_offset.offset = b->loc->line_number; |
13403 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13404 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13405 | |
13406 | /* Might be nice to check if function changed, and warn if | |
13407 | so. */ | |
0fb4aa4b PA |
13408 | } |
13409 | } | |
13410 | return sal; | |
13411 | } | |
13412 | ||
8d3788bd VP |
13413 | /* Returns 1 iff locations A and B are sufficiently same that |
13414 | we don't need to report breakpoint as changed. */ | |
13415 | ||
13416 | static int | |
13417 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13418 | { | |
13419 | while (a && b) | |
13420 | { | |
13421 | if (a->address != b->address) | |
13422 | return 0; | |
13423 | ||
13424 | if (a->shlib_disabled != b->shlib_disabled) | |
13425 | return 0; | |
13426 | ||
13427 | if (a->enabled != b->enabled) | |
13428 | return 0; | |
13429 | ||
13430 | a = a->next; | |
13431 | b = b->next; | |
13432 | } | |
13433 | ||
13434 | if ((a == NULL) != (b == NULL)) | |
13435 | return 0; | |
13436 | ||
13437 | return 1; | |
13438 | } | |
13439 | ||
c2f4122d PA |
13440 | /* Split all locations of B that are bound to PSPACE out of B's |
13441 | location list to a separate list and return that list's head. If | |
13442 | PSPACE is NULL, hoist out all locations of B. */ | |
13443 | ||
13444 | static struct bp_location * | |
13445 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13446 | { | |
13447 | struct bp_location head; | |
13448 | struct bp_location *i = b->loc; | |
13449 | struct bp_location **i_link = &b->loc; | |
13450 | struct bp_location *hoisted = &head; | |
13451 | ||
13452 | if (pspace == NULL) | |
13453 | { | |
13454 | i = b->loc; | |
13455 | b->loc = NULL; | |
13456 | return i; | |
13457 | } | |
13458 | ||
13459 | head.next = NULL; | |
13460 | ||
13461 | while (i != NULL) | |
13462 | { | |
13463 | if (i->pspace == pspace) | |
13464 | { | |
13465 | *i_link = i->next; | |
13466 | i->next = NULL; | |
13467 | hoisted->next = i; | |
13468 | hoisted = i; | |
13469 | } | |
13470 | else | |
13471 | i_link = &i->next; | |
13472 | i = *i_link; | |
13473 | } | |
13474 | ||
13475 | return head.next; | |
13476 | } | |
13477 | ||
13478 | /* Create new breakpoint locations for B (a hardware or software | |
13479 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13480 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13481 | FILTER_PSPACE. Locations of other program spaces are left | |
13482 | untouched. */ | |
f1310107 | 13483 | |
0e30163f | 13484 | void |
0d381245 | 13485 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13486 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13487 | gdb::array_view<const symtab_and_line> sals, |
13488 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13489 | { |
c2f4122d | 13490 | struct bp_location *existing_locations; |
0d381245 | 13491 | |
6c5b2ebe | 13492 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13493 | { |
13494 | /* Ranged breakpoints have only one start location and one end | |
13495 | location. */ | |
13496 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13497 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13498 | "multiple locations found\n"), | |
13499 | b->number); | |
13500 | return; | |
13501 | } | |
f1310107 | 13502 | |
4a64f543 MS |
13503 | /* If there's no new locations, and all existing locations are |
13504 | pending, don't do anything. This optimizes the common case where | |
13505 | all locations are in the same shared library, that was unloaded. | |
13506 | We'd like to retain the location, so that when the library is | |
13507 | loaded again, we don't loose the enabled/disabled status of the | |
13508 | individual locations. */ | |
6c5b2ebe | 13509 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13510 | return; |
13511 | ||
c2f4122d | 13512 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13513 | |
6c5b2ebe | 13514 | for (const auto &sal : sals) |
fe3f5fa8 | 13515 | { |
f8eba3c6 TT |
13516 | struct bp_location *new_loc; |
13517 | ||
6c5b2ebe | 13518 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13519 | |
6c5b2ebe | 13520 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13521 | |
0d381245 VP |
13522 | /* Reparse conditions, they might contain references to the |
13523 | old symtab. */ | |
13524 | if (b->cond_string != NULL) | |
13525 | { | |
bbc13ae3 | 13526 | const char *s; |
fe3f5fa8 | 13527 | |
0d381245 | 13528 | s = b->cond_string; |
a70b8144 | 13529 | try |
0d381245 | 13530 | { |
6c5b2ebe PA |
13531 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13532 | block_for_pc (sal.pc), | |
0d381245 VP |
13533 | 0); |
13534 | } | |
230d2906 | 13535 | catch (const gdb_exception_error &e) |
0d381245 | 13536 | { |
3e43a32a MS |
13537 | warning (_("failed to reevaluate condition " |
13538 | "for breakpoint %d: %s"), | |
3d6e9d23 | 13539 | b->number, e.what ()); |
0d381245 VP |
13540 | new_loc->enabled = 0; |
13541 | } | |
13542 | } | |
fe3f5fa8 | 13543 | |
6c5b2ebe | 13544 | if (!sals_end.empty ()) |
f1310107 | 13545 | { |
6c5b2ebe | 13546 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13547 | |
6c5b2ebe | 13548 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13549 | } |
0d381245 | 13550 | } |
fe3f5fa8 | 13551 | |
4a64f543 MS |
13552 | /* If possible, carry over 'disable' status from existing |
13553 | breakpoints. */ | |
0d381245 VP |
13554 | { |
13555 | struct bp_location *e = existing_locations; | |
776592bf DE |
13556 | /* If there are multiple breakpoints with the same function name, |
13557 | e.g. for inline functions, comparing function names won't work. | |
13558 | Instead compare pc addresses; this is just a heuristic as things | |
13559 | may have moved, but in practice it gives the correct answer | |
13560 | often enough until a better solution is found. */ | |
13561 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13562 | ||
0d381245 VP |
13563 | for (; e; e = e->next) |
13564 | { | |
13565 | if (!e->enabled && e->function_name) | |
13566 | { | |
13567 | struct bp_location *l = b->loc; | |
776592bf DE |
13568 | if (have_ambiguous_names) |
13569 | { | |
13570 | for (; l; l = l->next) | |
7f32a4d5 PA |
13571 | { |
13572 | /* Ignore software vs hardware location type at | |
13573 | this point, because with "set breakpoint | |
13574 | auto-hw", after a re-set, locations that were | |
13575 | hardware can end up as software, or vice versa. | |
13576 | As mentioned above, this is an heuristic and in | |
13577 | practice should give the correct answer often | |
13578 | enough. */ | |
13579 | if (breakpoint_locations_match (e, l, true)) | |
13580 | { | |
13581 | l->enabled = 0; | |
13582 | break; | |
13583 | } | |
13584 | } | |
776592bf DE |
13585 | } |
13586 | else | |
13587 | { | |
13588 | for (; l; l = l->next) | |
13589 | if (l->function_name | |
13590 | && strcmp (e->function_name, l->function_name) == 0) | |
13591 | { | |
13592 | l->enabled = 0; | |
13593 | break; | |
13594 | } | |
13595 | } | |
0d381245 VP |
13596 | } |
13597 | } | |
13598 | } | |
fe3f5fa8 | 13599 | |
8d3788bd | 13600 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 13601 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
13602 | } |
13603 | ||
f00aae0f | 13604 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13605 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13606 | ||
6c5b2ebe | 13607 | static std::vector<symtab_and_line> |
f00aae0f | 13608 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13609 | struct program_space *search_pspace, int *found) |
ef23e705 | 13610 | { |
cc06b668 | 13611 | struct gdb_exception exception; |
ef23e705 | 13612 | |
983af33b | 13613 | gdb_assert (b->ops != NULL); |
ef23e705 | 13614 | |
6c5b2ebe PA |
13615 | std::vector<symtab_and_line> sals; |
13616 | ||
a70b8144 | 13617 | try |
ef23e705 | 13618 | { |
6c5b2ebe | 13619 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13620 | } |
94aeb44b | 13621 | catch (gdb_exception_error &e) |
ef23e705 TJB |
13622 | { |
13623 | int not_found_and_ok = 0; | |
492d29ea | 13624 | |
ef23e705 TJB |
13625 | /* For pending breakpoints, it's expected that parsing will |
13626 | fail until the right shared library is loaded. User has | |
13627 | already told to create pending breakpoints and don't need | |
13628 | extra messages. If breakpoint is in bp_shlib_disabled | |
13629 | state, then user already saw the message about that | |
13630 | breakpoint being disabled, and don't want to see more | |
13631 | errors. */ | |
58438ac1 | 13632 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13633 | && (b->condition_not_parsed |
13634 | || (b->loc != NULL | |
13635 | && search_pspace != NULL | |
13636 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13637 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13638 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13639 | || b->enable_state == bp_disabled)) |
13640 | not_found_and_ok = 1; | |
13641 | ||
13642 | if (!not_found_and_ok) | |
13643 | { | |
13644 | /* We surely don't want to warn about the same breakpoint | |
13645 | 10 times. One solution, implemented here, is disable | |
13646 | the breakpoint on error. Another solution would be to | |
13647 | have separate 'warning emitted' flag. Since this | |
13648 | happens only when a binary has changed, I don't know | |
13649 | which approach is better. */ | |
13650 | b->enable_state = bp_disabled; | |
eedc3f4f | 13651 | throw; |
ef23e705 | 13652 | } |
94aeb44b TT |
13653 | |
13654 | exception = std::move (e); | |
ef23e705 TJB |
13655 | } |
13656 | ||
492d29ea | 13657 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13658 | { |
6c5b2ebe PA |
13659 | for (auto &sal : sals) |
13660 | resolve_sal_pc (&sal); | |
f00aae0f | 13661 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13662 | { |
ed1d1739 KS |
13663 | char *cond_string, *extra_string; |
13664 | int thread, task; | |
ef23e705 | 13665 | |
6c5b2ebe | 13666 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
13667 | &cond_string, &thread, &task, |
13668 | &extra_string); | |
f00aae0f | 13669 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13670 | if (cond_string) |
13671 | b->cond_string = cond_string; | |
13672 | b->thread = thread; | |
13673 | b->task = task; | |
e7e0cddf | 13674 | if (extra_string) |
f00aae0f KS |
13675 | { |
13676 | xfree (b->extra_string); | |
13677 | b->extra_string = extra_string; | |
13678 | } | |
ef23e705 TJB |
13679 | b->condition_not_parsed = 0; |
13680 | } | |
13681 | ||
983af33b | 13682 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13683 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13684 | |
58438ac1 TT |
13685 | *found = 1; |
13686 | } | |
13687 | else | |
13688 | *found = 0; | |
ef23e705 TJB |
13689 | |
13690 | return sals; | |
13691 | } | |
13692 | ||
348d480f PA |
13693 | /* The default re_set method, for typical hardware or software |
13694 | breakpoints. Reevaluate the breakpoint and recreate its | |
13695 | locations. */ | |
13696 | ||
13697 | static void | |
28010a5d | 13698 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13699 | { |
c2f4122d | 13700 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13701 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13702 | |
6c5b2ebe PA |
13703 | int found; |
13704 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13705 | filter_pspace, &found); | |
ef23e705 | 13706 | if (found) |
6c5b2ebe | 13707 | expanded = std::move (sals); |
ef23e705 | 13708 | |
f00aae0f | 13709 | if (b->location_range_end != NULL) |
f1310107 | 13710 | { |
6c5b2ebe PA |
13711 | std::vector<symtab_and_line> sals_end |
13712 | = location_to_sals (b, b->location_range_end.get (), | |
13713 | filter_pspace, &found); | |
f1310107 | 13714 | if (found) |
6c5b2ebe | 13715 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13716 | } |
13717 | ||
c2f4122d | 13718 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13719 | } |
13720 | ||
983af33b SDJ |
13721 | /* Default method for creating SALs from an address string. It basically |
13722 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13723 | ||
13724 | static void | |
f00aae0f KS |
13725 | create_sals_from_location_default (const struct event_location *location, |
13726 | struct linespec_result *canonical, | |
13727 | enum bptype type_wanted) | |
983af33b | 13728 | { |
f00aae0f | 13729 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
13730 | } |
13731 | ||
13732 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13733 | function for the `create_breakpoints_sal' method of | |
13734 | breakpoint_ops. */ | |
13735 | ||
13736 | static void | |
13737 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13738 | struct linespec_result *canonical, | |
e1e01040 PA |
13739 | gdb::unique_xmalloc_ptr<char> cond_string, |
13740 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13741 | enum bptype type_wanted, |
13742 | enum bpdisp disposition, | |
13743 | int thread, | |
13744 | int task, int ignore_count, | |
13745 | const struct breakpoint_ops *ops, | |
13746 | int from_tty, int enabled, | |
44f238bb | 13747 | int internal, unsigned flags) |
983af33b | 13748 | { |
e1e01040 PA |
13749 | create_breakpoints_sal (gdbarch, canonical, |
13750 | std::move (cond_string), | |
13751 | std::move (extra_string), | |
983af33b SDJ |
13752 | type_wanted, disposition, |
13753 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13754 | enabled, internal, flags); |
983af33b SDJ |
13755 | } |
13756 | ||
13757 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 13758 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 13759 | |
6c5b2ebe | 13760 | static std::vector<symtab_and_line> |
f00aae0f KS |
13761 | decode_location_default (struct breakpoint *b, |
13762 | const struct event_location *location, | |
6c5b2ebe | 13763 | struct program_space *search_pspace) |
983af33b SDJ |
13764 | { |
13765 | struct linespec_result canonical; | |
13766 | ||
c2f4122d | 13767 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 13768 | NULL, 0, &canonical, multiple_symbols_all, |
c0e8dcd8 | 13769 | b->filter.get ()); |
983af33b SDJ |
13770 | |
13771 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 13772 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 13773 | |
6c5b2ebe | 13774 | if (!canonical.lsals.empty ()) |
983af33b | 13775 | { |
6c5b2ebe PA |
13776 | const linespec_sals &lsal = canonical.lsals[0]; |
13777 | return std::move (lsal.sals); | |
983af33b | 13778 | } |
6c5b2ebe | 13779 | return {}; |
983af33b SDJ |
13780 | } |
13781 | ||
bf469271 | 13782 | /* Reset a breakpoint. */ |
c906108c | 13783 | |
bf469271 PA |
13784 | static void |
13785 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 13786 | { |
fdf44873 TT |
13787 | input_radix = b->input_radix; |
13788 | set_language (b->language); | |
c906108c | 13789 | |
348d480f | 13790 | b->ops->re_set (b); |
c906108c SS |
13791 | } |
13792 | ||
c2f4122d PA |
13793 | /* Re-set breakpoint locations for the current program space. |
13794 | Locations bound to other program spaces are left untouched. */ | |
13795 | ||
c906108c | 13796 | void |
69de3c6a | 13797 | breakpoint_re_set (void) |
c906108c | 13798 | { |
35df4500 | 13799 | struct breakpoint *b, *b_tmp; |
2a7f3dff | 13800 | |
c5aa993b | 13801 | { |
fdf44873 TT |
13802 | scoped_restore_current_language save_language; |
13803 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 13804 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 13805 | |
8e817061 JB |
13806 | /* breakpoint_re_set_one sets the current_language to the language |
13807 | of the breakpoint it is resetting (see prepare_re_set_context) | |
13808 | before re-evaluating the breakpoint's location. This change can | |
13809 | unfortunately get undone by accident if the language_mode is set | |
13810 | to auto, and we either switch frames, or more likely in this context, | |
13811 | we select the current frame. | |
13812 | ||
13813 | We prevent this by temporarily turning the language_mode to | |
13814 | language_mode_manual. We restore it once all breakpoints | |
13815 | have been reset. */ | |
13816 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
13817 | language_mode = language_mode_manual; | |
13818 | ||
5ed8105e PA |
13819 | /* Note: we must not try to insert locations until after all |
13820 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
13821 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
13822 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 13823 | |
5ed8105e PA |
13824 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
13825 | { | |
a70b8144 | 13826 | try |
bf469271 PA |
13827 | { |
13828 | breakpoint_re_set_one (b); | |
13829 | } | |
230d2906 | 13830 | catch (const gdb_exception &ex) |
bf469271 PA |
13831 | { |
13832 | exception_fprintf (gdb_stderr, ex, | |
13833 | "Error in re-setting breakpoint %d: ", | |
13834 | b->number); | |
13835 | } | |
5ed8105e | 13836 | } |
5ed8105e PA |
13837 | |
13838 | jit_breakpoint_re_set (); | |
13839 | } | |
6c95b8df | 13840 | |
af02033e PP |
13841 | create_overlay_event_breakpoint (); |
13842 | create_longjmp_master_breakpoint (); | |
13843 | create_std_terminate_master_breakpoint (); | |
186c406b | 13844 | create_exception_master_breakpoint (); |
2a7f3dff PA |
13845 | |
13846 | /* Now we can insert. */ | |
13847 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
13848 | } |
13849 | \f | |
c906108c SS |
13850 | /* Reset the thread number of this breakpoint: |
13851 | ||
13852 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13853 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13854 | void |
fba45db2 | 13855 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13856 | { |
13857 | if (b->thread != -1) | |
13858 | { | |
00431a78 | 13859 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
13860 | |
13861 | /* We're being called after following a fork. The new fork is | |
13862 | selected as current, and unless this was a vfork will have a | |
13863 | different program space from the original thread. Reset that | |
13864 | as well. */ | |
13865 | b->loc->pspace = current_program_space; | |
c906108c SS |
13866 | } |
13867 | } | |
13868 | ||
03ac34d5 MS |
13869 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13870 | If from_tty is nonzero, it prints a message to that effect, | |
13871 | which ends with a period (no newline). */ | |
13872 | ||
c906108c | 13873 | void |
fba45db2 | 13874 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13875 | { |
52f0bd74 | 13876 | struct breakpoint *b; |
c906108c SS |
13877 | |
13878 | if (count < 0) | |
13879 | count = 0; | |
13880 | ||
13881 | ALL_BREAKPOINTS (b) | |
13882 | if (b->number == bptnum) | |
c5aa993b | 13883 | { |
d77f58be SS |
13884 | if (is_tracepoint (b)) |
13885 | { | |
13886 | if (from_tty && count != 0) | |
13887 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13888 | bptnum); | |
13889 | return; | |
13890 | } | |
13891 | ||
c5aa993b | 13892 | b->ignore_count = count; |
221ea385 KS |
13893 | if (from_tty) |
13894 | { | |
13895 | if (count == 0) | |
3e43a32a MS |
13896 | printf_filtered (_("Will stop next time " |
13897 | "breakpoint %d is reached."), | |
221ea385 KS |
13898 | bptnum); |
13899 | else if (count == 1) | |
a3f17187 | 13900 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
13901 | bptnum); |
13902 | else | |
3e43a32a MS |
13903 | printf_filtered (_("Will ignore next %d " |
13904 | "crossings of breakpoint %d."), | |
221ea385 KS |
13905 | count, bptnum); |
13906 | } | |
76727919 | 13907 | gdb::observers::breakpoint_modified.notify (b); |
c5aa993b JM |
13908 | return; |
13909 | } | |
c906108c | 13910 | |
8a3fe4f8 | 13911 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13912 | } |
13913 | ||
c906108c SS |
13914 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13915 | ||
13916 | static void | |
0b39b52e | 13917 | ignore_command (const char *args, int from_tty) |
c906108c | 13918 | { |
0b39b52e | 13919 | const char *p = args; |
52f0bd74 | 13920 | int num; |
c906108c SS |
13921 | |
13922 | if (p == 0) | |
e2e0b3e5 | 13923 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13924 | |
c906108c | 13925 | num = get_number (&p); |
5c44784c | 13926 | if (num == 0) |
8a3fe4f8 | 13927 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13928 | if (*p == 0) |
8a3fe4f8 | 13929 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13930 | |
13931 | set_ignore_count (num, | |
13932 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13933 | from_tty); | |
221ea385 KS |
13934 | if (from_tty) |
13935 | printf_filtered ("\n"); | |
c906108c SS |
13936 | } |
13937 | \f | |
d0fe4701 XR |
13938 | |
13939 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
13940 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
13941 | |
13942 | static void | |
d0fe4701 XR |
13943 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
13944 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 13945 | { |
d0fe4701 XR |
13946 | if (bp_num_range.first == 0) |
13947 | { | |
13948 | warning (_("bad breakpoint number at or near '%d'"), | |
13949 | bp_num_range.first); | |
13950 | } | |
13951 | else | |
c906108c | 13952 | { |
d0fe4701 | 13953 | struct breakpoint *b, *tmp; |
197f0a60 | 13954 | |
d0fe4701 | 13955 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 13956 | { |
d0fe4701 XR |
13957 | bool match = false; |
13958 | ||
5c44784c | 13959 | ALL_BREAKPOINTS_SAFE (b, tmp) |
d0fe4701 | 13960 | if (b->number == i) |
5c44784c | 13961 | { |
bfd28288 | 13962 | match = true; |
48649e1b | 13963 | function (b); |
11cf8741 | 13964 | break; |
5c44784c | 13965 | } |
bfd28288 | 13966 | if (!match) |
d0fe4701 | 13967 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 13968 | } |
c906108c SS |
13969 | } |
13970 | } | |
13971 | ||
d0fe4701 XR |
13972 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
13973 | ARGS. */ | |
13974 | ||
13975 | static void | |
13976 | map_breakpoint_numbers (const char *args, | |
13977 | gdb::function_view<void (breakpoint *)> function) | |
13978 | { | |
13979 | if (args == NULL || *args == '\0') | |
13980 | error_no_arg (_("one or more breakpoint numbers")); | |
13981 | ||
13982 | number_or_range_parser parser (args); | |
13983 | ||
13984 | while (!parser.finished ()) | |
13985 | { | |
13986 | int num = parser.get_number (); | |
13987 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
13988 | } | |
13989 | } | |
13990 | ||
13991 | /* Return the breakpoint location structure corresponding to the | |
13992 | BP_NUM and LOC_NUM values. */ | |
13993 | ||
0d381245 | 13994 | static struct bp_location * |
d0fe4701 | 13995 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 13996 | { |
0d381245 | 13997 | struct breakpoint *b; |
0d381245 VP |
13998 | |
13999 | ALL_BREAKPOINTS (b) | |
14000 | if (b->number == bp_num) | |
14001 | { | |
14002 | break; | |
14003 | } | |
14004 | ||
14005 | if (!b || b->number != bp_num) | |
d0fe4701 | 14006 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 14007 | |
0d381245 | 14008 | if (loc_num == 0) |
d0fe4701 | 14009 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 14010 | |
d0fe4701 XR |
14011 | int n = 0; |
14012 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
14013 | if (++n == loc_num) | |
14014 | return loc; | |
14015 | ||
14016 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
14017 | } |
14018 | ||
95e95a6d PA |
14019 | /* Modes of operation for extract_bp_num. */ |
14020 | enum class extract_bp_kind | |
14021 | { | |
14022 | /* Extracting a breakpoint number. */ | |
14023 | bp, | |
14024 | ||
14025 | /* Extracting a location number. */ | |
14026 | loc, | |
14027 | }; | |
14028 | ||
14029 | /* Extract a breakpoint or location number (as determined by KIND) | |
14030 | from the string starting at START. TRAILER is a character which | |
14031 | can be found after the number. If you don't want a trailer, use | |
14032 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
14033 | string. This always returns a positive integer. */ | |
14034 | ||
14035 | static int | |
14036 | extract_bp_num (extract_bp_kind kind, const char *start, | |
14037 | int trailer, const char **end_out = NULL) | |
14038 | { | |
14039 | const char *end = start; | |
14040 | int num = get_number_trailer (&end, trailer); | |
14041 | if (num < 0) | |
14042 | error (kind == extract_bp_kind::bp | |
14043 | ? _("Negative breakpoint number '%.*s'") | |
14044 | : _("Negative breakpoint location number '%.*s'"), | |
14045 | int (end - start), start); | |
14046 | if (num == 0) | |
14047 | error (kind == extract_bp_kind::bp | |
14048 | ? _("Bad breakpoint number '%.*s'") | |
14049 | : _("Bad breakpoint location number '%.*s'"), | |
14050 | int (end - start), start); | |
14051 | ||
14052 | if (end_out != NULL) | |
14053 | *end_out = end; | |
14054 | return num; | |
14055 | } | |
14056 | ||
14057 | /* Extract a breakpoint or location range (as determined by KIND) in | |
14058 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
14059 | representing the (inclusive) range. The returned pair's elements | |
14060 | are always positive integers. */ | |
14061 | ||
14062 | static std::pair<int, int> | |
14063 | extract_bp_or_bp_range (extract_bp_kind kind, | |
14064 | const std::string &arg, | |
14065 | std::string::size_type arg_offset) | |
14066 | { | |
14067 | std::pair<int, int> range; | |
14068 | const char *bp_loc = &arg[arg_offset]; | |
14069 | std::string::size_type dash = arg.find ('-', arg_offset); | |
14070 | if (dash != std::string::npos) | |
14071 | { | |
14072 | /* bp_loc is a range (x-z). */ | |
14073 | if (arg.length () == dash + 1) | |
14074 | error (kind == extract_bp_kind::bp | |
14075 | ? _("Bad breakpoint number at or near: '%s'") | |
14076 | : _("Bad breakpoint location number at or near: '%s'"), | |
14077 | bp_loc); | |
14078 | ||
14079 | const char *end; | |
14080 | const char *start_first = bp_loc; | |
14081 | const char *start_second = &arg[dash + 1]; | |
14082 | range.first = extract_bp_num (kind, start_first, '-'); | |
14083 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
14084 | ||
14085 | if (range.first > range.second) | |
14086 | error (kind == extract_bp_kind::bp | |
14087 | ? _("Inverted breakpoint range at '%.*s'") | |
14088 | : _("Inverted breakpoint location range at '%.*s'"), | |
14089 | int (end - start_first), start_first); | |
14090 | } | |
14091 | else | |
14092 | { | |
14093 | /* bp_loc is a single value. */ | |
14094 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
14095 | range.second = range.first; | |
14096 | } | |
14097 | return range; | |
14098 | } | |
14099 | ||
d0fe4701 XR |
14100 | /* Extract the breakpoint/location range specified by ARG. Returns |
14101 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
14102 | BP_LOC_RANGE. | |
14103 | ||
14104 | ARG may be in any of the following forms: | |
14105 | ||
14106 | x where 'x' is a breakpoint number. | |
14107 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
14108 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
14109 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
14110 | location number range. | |
14111 | */ | |
14112 | ||
cc638e86 | 14113 | static void |
d0fe4701 XR |
14114 | extract_bp_number_and_location (const std::string &arg, |
14115 | std::pair<int, int> &bp_num_range, | |
14116 | std::pair<int, int> &bp_loc_range) | |
14117 | { | |
14118 | std::string::size_type dot = arg.find ('.'); | |
14119 | ||
14120 | if (dot != std::string::npos) | |
14121 | { | |
14122 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
14123 | ||
14124 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 14125 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 14126 | |
95e95a6d PA |
14127 | bp_num_range.first |
14128 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
14129 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 14130 | |
95e95a6d PA |
14131 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
14132 | arg, dot + 1); | |
d0fe4701 XR |
14133 | } |
14134 | else | |
14135 | { | |
14136 | /* Handle x and x-y cases. */ | |
d0fe4701 | 14137 | |
95e95a6d | 14138 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
14139 | bp_loc_range.first = 0; |
14140 | bp_loc_range.second = 0; | |
14141 | } | |
d0fe4701 XR |
14142 | } |
14143 | ||
14144 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
14145 | specifies whether to enable or disable. */ | |
14146 | ||
14147 | static void | |
14148 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
14149 | { | |
14150 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
14151 | if (loc != NULL) | |
14152 | { | |
14153 | if (loc->enabled != enable) | |
14154 | { | |
14155 | loc->enabled = enable; | |
14156 | mark_breakpoint_location_modified (loc); | |
14157 | } | |
14158 | if (target_supports_enable_disable_tracepoint () | |
14159 | && current_trace_status ()->running && loc->owner | |
14160 | && is_tracepoint (loc->owner)) | |
14161 | target_disable_tracepoint (loc); | |
14162 | } | |
14163 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
14164 | |
14165 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
14166 | } |
14167 | ||
14168 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
14169 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
14170 | (inclusive) range of location numbers of that breakpoint to | |
14171 | enable/disable. ENABLE specifies whether to enable or disable the | |
14172 | location. */ | |
14173 | ||
14174 | static void | |
14175 | enable_disable_breakpoint_location_range (int bp_num, | |
14176 | std::pair<int, int> &bp_loc_range, | |
14177 | bool enable) | |
14178 | { | |
14179 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
14180 | enable_disable_bp_num_loc (bp_num, i, enable); | |
14181 | } | |
0d381245 | 14182 | |
1900040c MS |
14183 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14184 | If from_tty is nonzero, it prints a message to that effect, | |
14185 | which ends with a period (no newline). */ | |
14186 | ||
c906108c | 14187 | void |
fba45db2 | 14188 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14189 | { |
14190 | /* Never disable a watchpoint scope breakpoint; we want to | |
14191 | hit them when we leave scope so we can delete both the | |
14192 | watchpoint and its scope breakpoint at that time. */ | |
14193 | if (bpt->type == bp_watchpoint_scope) | |
14194 | return; | |
14195 | ||
b5de0fa7 | 14196 | bpt->enable_state = bp_disabled; |
c906108c | 14197 | |
b775012e LM |
14198 | /* Mark breakpoint locations modified. */ |
14199 | mark_breakpoint_modified (bpt); | |
14200 | ||
d248b706 KY |
14201 | if (target_supports_enable_disable_tracepoint () |
14202 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14203 | { | |
14204 | struct bp_location *location; | |
14205 | ||
14206 | for (location = bpt->loc; location; location = location->next) | |
14207 | target_disable_tracepoint (location); | |
14208 | } | |
14209 | ||
44702360 | 14210 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14211 | |
76727919 | 14212 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14213 | } |
14214 | ||
d0fe4701 XR |
14215 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
14216 | specified in ARGS. ARGS may be in any of the formats handled by | |
14217 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
14218 | or disable the breakpoints/locations. */ | |
14219 | ||
c906108c | 14220 | static void |
d0fe4701 | 14221 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 14222 | { |
c906108c | 14223 | if (args == 0) |
46c6471b PA |
14224 | { |
14225 | struct breakpoint *bpt; | |
14226 | ||
14227 | ALL_BREAKPOINTS (bpt) | |
14228 | if (user_breakpoint_p (bpt)) | |
d0fe4701 XR |
14229 | { |
14230 | if (enable) | |
14231 | enable_breakpoint (bpt); | |
14232 | else | |
14233 | disable_breakpoint (bpt); | |
14234 | } | |
46c6471b | 14235 | } |
9eaabc75 | 14236 | else |
0d381245 | 14237 | { |
cb791d59 | 14238 | std::string num = extract_arg (&args); |
9eaabc75 | 14239 | |
cb791d59 | 14240 | while (!num.empty ()) |
d248b706 | 14241 | { |
d0fe4701 | 14242 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 14243 | |
cc638e86 PA |
14244 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
14245 | ||
14246 | if (bp_loc_range.first == bp_loc_range.second | |
14247 | && bp_loc_range.first == 0) | |
d0fe4701 | 14248 | { |
cc638e86 PA |
14249 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
14250 | map_breakpoint_number_range (bp_num_range, | |
14251 | enable | |
14252 | ? enable_breakpoint | |
14253 | : disable_breakpoint); | |
14254 | } | |
14255 | else | |
14256 | { | |
14257 | /* Handle breakpoint ids with formats 'x.y' or | |
14258 | 'x.y-z'. */ | |
14259 | enable_disable_breakpoint_location_range | |
14260 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 14261 | } |
9eaabc75 | 14262 | num = extract_arg (&args); |
d248b706 | 14263 | } |
0d381245 | 14264 | } |
c906108c SS |
14265 | } |
14266 | ||
d0fe4701 XR |
14267 | /* The disable command disables the specified breakpoints/locations |
14268 | (or all defined breakpoints) so they're no longer effective in | |
14269 | stopping the inferior. ARGS may be in any of the forms defined in | |
14270 | extract_bp_number_and_location. */ | |
14271 | ||
14272 | static void | |
14273 | disable_command (const char *args, int from_tty) | |
14274 | { | |
14275 | enable_disable_command (args, from_tty, false); | |
14276 | } | |
14277 | ||
c906108c | 14278 | static void |
816338b5 SS |
14279 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14280 | int count) | |
c906108c | 14281 | { |
afe38095 | 14282 | int target_resources_ok; |
c906108c SS |
14283 | |
14284 | if (bpt->type == bp_hardware_breakpoint) | |
14285 | { | |
14286 | int i; | |
c5aa993b | 14287 | i = hw_breakpoint_used_count (); |
53a5351d | 14288 | target_resources_ok = |
d92524f1 | 14289 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14290 | i + 1, 0); |
c906108c | 14291 | if (target_resources_ok == 0) |
8a3fe4f8 | 14292 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14293 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14294 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14295 | } |
14296 | ||
cc60f2e3 | 14297 | if (is_watchpoint (bpt)) |
c906108c | 14298 | { |
d07205c2 | 14299 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14300 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14301 | |
a70b8144 | 14302 | try |
c906108c | 14303 | { |
3a5c3e22 PA |
14304 | struct watchpoint *w = (struct watchpoint *) bpt; |
14305 | ||
1e718ff1 TJB |
14306 | orig_enable_state = bpt->enable_state; |
14307 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14308 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14309 | } |
230d2906 | 14310 | catch (const gdb_exception &e) |
c5aa993b | 14311 | { |
1e718ff1 | 14312 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14313 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14314 | bpt->number); | |
14315 | return; | |
c5aa993b | 14316 | } |
c906108c | 14317 | } |
0101ce28 | 14318 | |
b775012e LM |
14319 | bpt->enable_state = bp_enabled; |
14320 | ||
14321 | /* Mark breakpoint locations modified. */ | |
14322 | mark_breakpoint_modified (bpt); | |
14323 | ||
d248b706 KY |
14324 | if (target_supports_enable_disable_tracepoint () |
14325 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14326 | { | |
14327 | struct bp_location *location; | |
14328 | ||
14329 | for (location = bpt->loc; location; location = location->next) | |
14330 | target_enable_tracepoint (location); | |
14331 | } | |
14332 | ||
b4c291bb | 14333 | bpt->disposition = disposition; |
816338b5 | 14334 | bpt->enable_count = count; |
44702360 | 14335 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14336 | |
76727919 | 14337 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14338 | } |
14339 | ||
fe3f5fa8 | 14340 | |
c906108c | 14341 | void |
fba45db2 | 14342 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14343 | { |
816338b5 | 14344 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14345 | } |
14346 | ||
d0fe4701 XR |
14347 | /* The enable command enables the specified breakpoints/locations (or |
14348 | all defined breakpoints) so they once again become (or continue to | |
14349 | be) effective in stopping the inferior. ARGS may be in any of the | |
14350 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 14351 | |
c906108c | 14352 | static void |
981a3fb3 | 14353 | enable_command (const char *args, int from_tty) |
c906108c | 14354 | { |
d0fe4701 | 14355 | enable_disable_command (args, from_tty, true); |
c906108c SS |
14356 | } |
14357 | ||
c906108c | 14358 | static void |
4495129a | 14359 | enable_once_command (const char *args, int from_tty) |
c906108c | 14360 | { |
48649e1b TT |
14361 | map_breakpoint_numbers |
14362 | (args, [&] (breakpoint *b) | |
14363 | { | |
14364 | iterate_over_related_breakpoints | |
14365 | (b, [&] (breakpoint *bpt) | |
14366 | { | |
14367 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14368 | }); | |
14369 | }); | |
816338b5 SS |
14370 | } |
14371 | ||
14372 | static void | |
4495129a | 14373 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14374 | { |
b9d61307 SM |
14375 | int count; |
14376 | ||
14377 | if (args == NULL) | |
14378 | error_no_arg (_("hit count")); | |
14379 | ||
14380 | count = get_number (&args); | |
816338b5 | 14381 | |
48649e1b TT |
14382 | map_breakpoint_numbers |
14383 | (args, [&] (breakpoint *b) | |
14384 | { | |
14385 | iterate_over_related_breakpoints | |
14386 | (b, [&] (breakpoint *bpt) | |
14387 | { | |
14388 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14389 | }); | |
14390 | }); | |
c906108c SS |
14391 | } |
14392 | ||
c906108c | 14393 | static void |
4495129a | 14394 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14395 | { |
48649e1b TT |
14396 | map_breakpoint_numbers |
14397 | (args, [&] (breakpoint *b) | |
14398 | { | |
14399 | iterate_over_related_breakpoints | |
14400 | (b, [&] (breakpoint *bpt) | |
14401 | { | |
14402 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14403 | }); | |
14404 | }); | |
c906108c SS |
14405 | } |
14406 | \f | |
1f3b5d1b PP |
14407 | /* Invalidate last known value of any hardware watchpoint if |
14408 | the memory which that value represents has been written to by | |
14409 | GDB itself. */ | |
14410 | ||
14411 | static void | |
8de0566d YQ |
14412 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14413 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14414 | const bfd_byte *data) |
14415 | { | |
14416 | struct breakpoint *bp; | |
14417 | ||
14418 | ALL_BREAKPOINTS (bp) | |
14419 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14420 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14421 | { |
3a5c3e22 | 14422 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14423 | |
850645cf | 14424 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 PA |
14425 | { |
14426 | struct bp_location *loc; | |
14427 | ||
14428 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14429 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14430 | && loc->address + loc->length > addr | |
14431 | && addr + len > loc->address) | |
14432 | { | |
3a5c3e22 | 14433 | wp->val = NULL; |
4c1d86d9 | 14434 | wp->val_valid = false; |
3a5c3e22 PA |
14435 | } |
14436 | } | |
1f3b5d1b PP |
14437 | } |
14438 | } | |
14439 | ||
8181d85f DJ |
14440 | /* Create and insert a breakpoint for software single step. */ |
14441 | ||
14442 | void | |
6c95b8df | 14443 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 14444 | const address_space *aspace, |
4a64f543 | 14445 | CORE_ADDR next_pc) |
8181d85f | 14446 | { |
7c16b83e PA |
14447 | struct thread_info *tp = inferior_thread (); |
14448 | struct symtab_and_line sal; | |
14449 | CORE_ADDR pc = next_pc; | |
8181d85f | 14450 | |
34b7e8a6 PA |
14451 | if (tp->control.single_step_breakpoints == NULL) |
14452 | { | |
14453 | tp->control.single_step_breakpoints | |
5d5658a1 | 14454 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14455 | } |
8181d85f | 14456 | |
7c16b83e PA |
14457 | sal = find_pc_line (pc, 0); |
14458 | sal.pc = pc; | |
14459 | sal.section = find_pc_overlay (pc); | |
14460 | sal.explicit_pc = 1; | |
34b7e8a6 | 14461 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14462 | |
7c16b83e | 14463 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14464 | } |
14465 | ||
93f9a11f YQ |
14466 | /* Insert single step breakpoints according to the current state. */ |
14467 | ||
14468 | int | |
14469 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14470 | { | |
f5ea389a | 14471 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14472 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14473 | |
f5ea389a | 14474 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14475 | |
a0ff9e1a | 14476 | if (!next_pcs.empty ()) |
93f9a11f | 14477 | { |
f5ea389a | 14478 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14479 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14480 | |
a0ff9e1a | 14481 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14482 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14483 | ||
93f9a11f YQ |
14484 | return 1; |
14485 | } | |
14486 | else | |
14487 | return 0; | |
14488 | } | |
14489 | ||
34b7e8a6 | 14490 | /* See breakpoint.h. */ |
f02253f1 HZ |
14491 | |
14492 | int | |
7c16b83e | 14493 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14494 | const address_space *aspace, |
7c16b83e | 14495 | CORE_ADDR pc) |
1aafd4da | 14496 | { |
7c16b83e | 14497 | struct bp_location *loc; |
1aafd4da | 14498 | |
7c16b83e PA |
14499 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14500 | if (loc->inserted | |
14501 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14502 | return 1; | |
1aafd4da | 14503 | |
7c16b83e | 14504 | return 0; |
ef370185 JB |
14505 | } |
14506 | ||
14507 | /* Check whether a software single-step breakpoint is inserted at | |
14508 | PC. */ | |
14509 | ||
14510 | int | |
accd0bcd | 14511 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14512 | CORE_ADDR pc) |
14513 | { | |
34b7e8a6 PA |
14514 | struct breakpoint *bpt; |
14515 | ||
14516 | ALL_BREAKPOINTS (bpt) | |
14517 | { | |
14518 | if (bpt->type == bp_single_step | |
14519 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14520 | return 1; | |
14521 | } | |
14522 | return 0; | |
1aafd4da UW |
14523 | } |
14524 | ||
1042e4c0 SS |
14525 | /* Tracepoint-specific operations. */ |
14526 | ||
14527 | /* Set tracepoint count to NUM. */ | |
14528 | static void | |
14529 | set_tracepoint_count (int num) | |
14530 | { | |
14531 | tracepoint_count = num; | |
4fa62494 | 14532 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14533 | } |
14534 | ||
70221824 | 14535 | static void |
0b39b52e | 14536 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14537 | { |
ffc2605c TT |
14538 | event_location_up location = string_to_event_location (&arg, |
14539 | current_language); | |
bac7c5cf GB |
14540 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
14541 | (location.get (), true /* is_tracepoint */); | |
55aa24fb | 14542 | |
558a9d82 | 14543 | create_breakpoint (get_current_arch (), |
ffc2605c | 14544 | location.get (), |
f00aae0f | 14545 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14546 | 0 /* tempflag */, |
14547 | bp_tracepoint /* type_wanted */, | |
14548 | 0 /* Ignore count */, | |
14549 | pending_break_support, | |
14550 | ops, | |
14551 | from_tty, | |
14552 | 1 /* enabled */, | |
14553 | 0 /* internal */, 0); | |
1042e4c0 SS |
14554 | } |
14555 | ||
70221824 | 14556 | static void |
0b39b52e | 14557 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14558 | { |
ffc2605c TT |
14559 | event_location_up location = string_to_event_location (&arg, |
14560 | current_language); | |
558a9d82 | 14561 | create_breakpoint (get_current_arch (), |
ffc2605c | 14562 | location.get (), |
f00aae0f | 14563 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14564 | 0 /* tempflag */, |
14565 | bp_fast_tracepoint /* type_wanted */, | |
14566 | 0 /* Ignore count */, | |
14567 | pending_break_support, | |
14568 | &tracepoint_breakpoint_ops, | |
14569 | from_tty, | |
14570 | 1 /* enabled */, | |
14571 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14572 | } |
14573 | ||
14574 | /* strace command implementation. Creates a static tracepoint. */ | |
14575 | ||
70221824 | 14576 | static void |
0b39b52e | 14577 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14578 | { |
983af33b | 14579 | struct breakpoint_ops *ops; |
ffc2605c | 14580 | event_location_up location; |
983af33b SDJ |
14581 | |
14582 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14583 | or with a normal static tracepoint. */ | |
61012eef | 14584 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14585 | { |
14586 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14587 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14588 | } |
983af33b | 14589 | else |
f00aae0f KS |
14590 | { |
14591 | ops = &tracepoint_breakpoint_ops; | |
14592 | location = string_to_event_location (&arg, current_language); | |
14593 | } | |
983af33b | 14594 | |
558a9d82 | 14595 | create_breakpoint (get_current_arch (), |
ffc2605c | 14596 | location.get (), |
f00aae0f | 14597 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14598 | 0 /* tempflag */, |
14599 | bp_static_tracepoint /* type_wanted */, | |
14600 | 0 /* Ignore count */, | |
14601 | pending_break_support, | |
14602 | ops, | |
14603 | from_tty, | |
14604 | 1 /* enabled */, | |
14605 | 0 /* internal */, 0); | |
7a697b8d SS |
14606 | } |
14607 | ||
409873ef SS |
14608 | /* Set up a fake reader function that gets command lines from a linked |
14609 | list that was acquired during tracepoint uploading. */ | |
14610 | ||
14611 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14612 | static int next_cmd; |
409873ef SS |
14613 | |
14614 | static char * | |
14615 | read_uploaded_action (void) | |
14616 | { | |
a18ba4e4 | 14617 | char *rslt = nullptr; |
409873ef | 14618 | |
a18ba4e4 SM |
14619 | if (next_cmd < this_utp->cmd_strings.size ()) |
14620 | { | |
67aa1f3c | 14621 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
14622 | next_cmd++; |
14623 | } | |
409873ef SS |
14624 | |
14625 | return rslt; | |
14626 | } | |
14627 | ||
00bf0b85 SS |
14628 | /* Given information about a tracepoint as recorded on a target (which |
14629 | can be either a live system or a trace file), attempt to create an | |
14630 | equivalent GDB tracepoint. This is not a reliable process, since | |
14631 | the target does not necessarily have all the information used when | |
14632 | the tracepoint was originally defined. */ | |
14633 | ||
d9b3f62e | 14634 | struct tracepoint * |
00bf0b85 | 14635 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14636 | { |
f2fc3015 TT |
14637 | const char *addr_str; |
14638 | char small_buf[100]; | |
d9b3f62e | 14639 | struct tracepoint *tp; |
fd9b8c24 | 14640 | |
409873ef | 14641 | if (utp->at_string) |
67aa1f3c | 14642 | addr_str = utp->at_string.get (); |
409873ef SS |
14643 | else |
14644 | { | |
14645 | /* In the absence of a source location, fall back to raw | |
14646 | address. Since there is no way to confirm that the address | |
14647 | means the same thing as when the trace was started, warn the | |
14648 | user. */ | |
3e43a32a MS |
14649 | warning (_("Uploaded tracepoint %d has no " |
14650 | "source location, using raw address"), | |
409873ef | 14651 | utp->number); |
8c042590 | 14652 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14653 | addr_str = small_buf; |
14654 | } | |
14655 | ||
14656 | /* There's not much we can do with a sequence of bytecodes. */ | |
14657 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14658 | warning (_("Uploaded tracepoint %d condition " |
14659 | "has no source form, ignoring it"), | |
409873ef | 14660 | utp->number); |
d5551862 | 14661 | |
ffc2605c TT |
14662 | event_location_up location = string_to_event_location (&addr_str, |
14663 | current_language); | |
8cdf0e15 | 14664 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14665 | location.get (), |
67aa1f3c | 14666 | utp->cond_string.get (), -1, addr_str, |
e7e0cddf | 14667 | 0 /* parse cond/thread */, |
8cdf0e15 | 14668 | 0 /* tempflag */, |
0fb4aa4b | 14669 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14670 | 0 /* Ignore count */, |
14671 | pending_break_support, | |
348d480f | 14672 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14673 | 0 /* from_tty */, |
84f4c1fe | 14674 | utp->enabled /* enabled */, |
44f238bb PA |
14675 | 0 /* internal */, |
14676 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14677 | return NULL; |
fd9b8c24 | 14678 | |
409873ef | 14679 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14680 | tp = get_tracepoint (tracepoint_count); |
14681 | gdb_assert (tp != NULL); | |
d5551862 | 14682 | |
00bf0b85 SS |
14683 | if (utp->pass > 0) |
14684 | { | |
8c042590 | 14685 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14686 | tp->number); |
00bf0b85 | 14687 | |
409873ef | 14688 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14689 | } |
14690 | ||
409873ef SS |
14691 | /* If we have uploaded versions of the original commands, set up a |
14692 | special-purpose "reader" function and call the usual command line | |
14693 | reader, then pass the result to the breakpoint command-setting | |
14694 | function. */ | |
a18ba4e4 | 14695 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 14696 | { |
12973681 | 14697 | counted_command_line cmd_list; |
00bf0b85 | 14698 | |
409873ef | 14699 | this_utp = utp; |
3149d8c1 | 14700 | next_cmd = 0; |
d5551862 | 14701 | |
60b3cef2 | 14702 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 14703 | |
c1fc2657 | 14704 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14705 | } |
a18ba4e4 SM |
14706 | else if (!utp->actions.empty () |
14707 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
14708 | warning (_("Uploaded tracepoint %d actions " |
14709 | "have no source form, ignoring them"), | |
409873ef | 14710 | utp->number); |
00bf0b85 | 14711 | |
f196051f | 14712 | /* Copy any status information that might be available. */ |
c1fc2657 | 14713 | tp->hit_count = utp->hit_count; |
f196051f SS |
14714 | tp->traceframe_usage = utp->traceframe_usage; |
14715 | ||
00bf0b85 | 14716 | return tp; |
d9b3f62e | 14717 | } |
00bf0b85 | 14718 | |
1042e4c0 SS |
14719 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14720 | omitted. */ | |
14721 | ||
14722 | static void | |
1d12d88f | 14723 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 14724 | { |
79a45e25 | 14725 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14726 | int num_printed; |
1042e4c0 | 14727 | |
5c458ae8 | 14728 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
d77f58be SS |
14729 | |
14730 | if (num_printed == 0) | |
1042e4c0 | 14731 | { |
e5a67952 | 14732 | if (args == NULL || *args == '\0') |
112e8700 | 14733 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14734 | else |
112e8700 | 14735 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14736 | } |
ad443146 SS |
14737 | |
14738 | default_collect_info (); | |
1042e4c0 SS |
14739 | } |
14740 | ||
4a64f543 | 14741 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14742 | Not supported by all targets. */ |
14743 | static void | |
5fed81ff | 14744 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14745 | { |
14746 | enable_command (args, from_tty); | |
14747 | } | |
14748 | ||
4a64f543 | 14749 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14750 | Not supported by all targets. */ |
14751 | static void | |
5fed81ff | 14752 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14753 | { |
14754 | disable_command (args, from_tty); | |
14755 | } | |
14756 | ||
4a64f543 | 14757 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14758 | static void |
4495129a | 14759 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14760 | { |
35df4500 | 14761 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14762 | |
14763 | dont_repeat (); | |
14764 | ||
14765 | if (arg == 0) | |
14766 | { | |
14767 | int breaks_to_delete = 0; | |
14768 | ||
14769 | /* Delete all breakpoints if no argument. | |
14770 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14771 | have to be deleted with an explicit breakpoint number |
14772 | argument. */ | |
1042e4c0 | 14773 | ALL_TRACEPOINTS (b) |
46c6471b | 14774 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14775 | { |
14776 | breaks_to_delete = 1; | |
14777 | break; | |
14778 | } | |
1042e4c0 SS |
14779 | |
14780 | /* Ask user only if there are some breakpoints to delete. */ | |
14781 | if (!from_tty | |
14782 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14783 | { | |
35df4500 | 14784 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14785 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14786 | delete_breakpoint (b); |
1042e4c0 SS |
14787 | } |
14788 | } | |
14789 | else | |
48649e1b | 14790 | map_breakpoint_numbers |
b926417a | 14791 | (arg, [&] (breakpoint *br) |
48649e1b | 14792 | { |
b926417a | 14793 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 14794 | }); |
1042e4c0 SS |
14795 | } |
14796 | ||
197f0a60 TT |
14797 | /* Helper function for trace_pass_command. */ |
14798 | ||
14799 | static void | |
d9b3f62e | 14800 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14801 | { |
d9b3f62e | 14802 | tp->pass_count = count; |
76727919 | 14803 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 TT |
14804 | if (from_tty) |
14805 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 14806 | tp->number, count); |
197f0a60 TT |
14807 | } |
14808 | ||
1042e4c0 SS |
14809 | /* Set passcount for tracepoint. |
14810 | ||
14811 | First command argument is passcount, second is tracepoint number. | |
14812 | If tracepoint number omitted, apply to most recently defined. | |
14813 | Also accepts special argument "all". */ | |
14814 | ||
14815 | static void | |
0b39b52e | 14816 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 14817 | { |
d9b3f62e | 14818 | struct tracepoint *t1; |
0b39b52e | 14819 | ULONGEST count; |
1042e4c0 SS |
14820 | |
14821 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14822 | error (_("passcount command requires an " |
14823 | "argument (count + optional TP num)")); | |
1042e4c0 | 14824 | |
0b39b52e | 14825 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 14826 | |
529480d0 | 14827 | args = skip_spaces (args); |
1042e4c0 SS |
14828 | if (*args && strncasecmp (args, "all", 3) == 0) |
14829 | { | |
d9b3f62e PA |
14830 | struct breakpoint *b; |
14831 | ||
1042e4c0 | 14832 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
14833 | if (*args) |
14834 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14835 | |
d9b3f62e | 14836 | ALL_TRACEPOINTS (b) |
197f0a60 | 14837 | { |
d9b3f62e | 14838 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
14839 | trace_pass_set_count (t1, count, from_tty); |
14840 | } | |
14841 | } | |
14842 | else if (*args == '\0') | |
1042e4c0 | 14843 | { |
5fa1d40e | 14844 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 14845 | if (t1) |
197f0a60 TT |
14846 | trace_pass_set_count (t1, count, from_tty); |
14847 | } | |
14848 | else | |
14849 | { | |
bfd28288 PA |
14850 | number_or_range_parser parser (args); |
14851 | while (!parser.finished ()) | |
1042e4c0 | 14852 | { |
bfd28288 | 14853 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
14854 | if (t1) |
14855 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14856 | } |
14857 | } | |
1042e4c0 SS |
14858 | } |
14859 | ||
d9b3f62e | 14860 | struct tracepoint * |
1042e4c0 SS |
14861 | get_tracepoint (int num) |
14862 | { | |
14863 | struct breakpoint *t; | |
14864 | ||
14865 | ALL_TRACEPOINTS (t) | |
14866 | if (t->number == num) | |
d9b3f62e | 14867 | return (struct tracepoint *) t; |
1042e4c0 SS |
14868 | |
14869 | return NULL; | |
14870 | } | |
14871 | ||
d5551862 SS |
14872 | /* Find the tracepoint with the given target-side number (which may be |
14873 | different from the tracepoint number after disconnecting and | |
14874 | reconnecting). */ | |
14875 | ||
d9b3f62e | 14876 | struct tracepoint * |
d5551862 SS |
14877 | get_tracepoint_by_number_on_target (int num) |
14878 | { | |
d9b3f62e | 14879 | struct breakpoint *b; |
d5551862 | 14880 | |
d9b3f62e PA |
14881 | ALL_TRACEPOINTS (b) |
14882 | { | |
14883 | struct tracepoint *t = (struct tracepoint *) b; | |
14884 | ||
14885 | if (t->number_on_target == num) | |
14886 | return t; | |
14887 | } | |
d5551862 SS |
14888 | |
14889 | return NULL; | |
14890 | } | |
14891 | ||
1042e4c0 | 14892 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 14893 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
14894 | If the argument is missing, the most recent tracepoint |
14895 | (tracepoint_count) is returned. */ | |
14896 | ||
d9b3f62e | 14897 | struct tracepoint * |
0b39b52e | 14898 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 14899 | number_or_range_parser *parser) |
1042e4c0 | 14900 | { |
1042e4c0 SS |
14901 | struct breakpoint *t; |
14902 | int tpnum; | |
0b39b52e | 14903 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 14904 | |
bfd28288 | 14905 | if (parser != NULL) |
197f0a60 | 14906 | { |
bfd28288 PA |
14907 | gdb_assert (!parser->finished ()); |
14908 | tpnum = parser->get_number (); | |
197f0a60 TT |
14909 | } |
14910 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 14911 | tpnum = tracepoint_count; |
1042e4c0 | 14912 | else |
197f0a60 | 14913 | tpnum = get_number (arg); |
1042e4c0 SS |
14914 | |
14915 | if (tpnum <= 0) | |
14916 | { | |
14917 | if (instring && *instring) | |
14918 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14919 | instring); | |
14920 | else | |
5fa1d40e | 14921 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
14922 | return NULL; |
14923 | } | |
14924 | ||
14925 | ALL_TRACEPOINTS (t) | |
14926 | if (t->number == tpnum) | |
14927 | { | |
d9b3f62e | 14928 | return (struct tracepoint *) t; |
1042e4c0 SS |
14929 | } |
14930 | ||
1042e4c0 SS |
14931 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
14932 | return NULL; | |
14933 | } | |
14934 | ||
d9b3f62e PA |
14935 | void |
14936 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14937 | { | |
14938 | if (b->thread != -1) | |
14939 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14940 | ||
14941 | if (b->task != 0) | |
14942 | fprintf_unfiltered (fp, " task %d", b->task); | |
14943 | ||
14944 | fprintf_unfiltered (fp, "\n"); | |
14945 | } | |
14946 | ||
6149aea9 PA |
14947 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14948 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14949 | on each breakpoint and only include the ones for which it returns | |
f2478a7e | 14950 | true. */ |
6149aea9 | 14951 | |
1042e4c0 | 14952 | static void |
4495129a | 14953 | save_breakpoints (const char *filename, int from_tty, |
f2478a7e | 14954 | bool (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
14955 | { |
14956 | struct breakpoint *tp; | |
6149aea9 | 14957 | int any = 0; |
6149aea9 | 14958 | int extra_trace_bits = 0; |
1042e4c0 | 14959 | |
6149aea9 PA |
14960 | if (filename == 0 || *filename == 0) |
14961 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14962 | |
14963 | /* See if we have anything to save. */ | |
6149aea9 | 14964 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14965 | { |
6149aea9 | 14966 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14967 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
14968 | continue; |
14969 | ||
14970 | /* If we have a filter, only save the breakpoints it accepts. */ | |
14971 | if (filter && !filter (tp)) | |
14972 | continue; | |
14973 | ||
14974 | any = 1; | |
14975 | ||
14976 | if (is_tracepoint (tp)) | |
14977 | { | |
14978 | extra_trace_bits = 1; | |
14979 | ||
14980 | /* We can stop searching. */ | |
14981 | break; | |
14982 | } | |
1042e4c0 | 14983 | } |
6149aea9 PA |
14984 | |
14985 | if (!any) | |
1042e4c0 | 14986 | { |
6149aea9 | 14987 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14988 | return; |
14989 | } | |
14990 | ||
ee0c3293 | 14991 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
14992 | |
14993 | stdio_file fp; | |
14994 | ||
ee0c3293 | 14995 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 14996 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 14997 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 14998 | |
6149aea9 | 14999 | if (extra_trace_bits) |
d7e74731 | 15000 | save_trace_state_variables (&fp); |
8bf6485c | 15001 | |
6149aea9 | 15002 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15003 | { |
6149aea9 | 15004 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15005 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15006 | continue; |
8bf6485c | 15007 | |
6149aea9 PA |
15008 | /* If we have a filter, only save the breakpoints it accepts. */ |
15009 | if (filter && !filter (tp)) | |
15010 | continue; | |
15011 | ||
d7e74731 | 15012 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15013 | |
6149aea9 PA |
15014 | /* Note, we can't rely on tp->number for anything, as we can't |
15015 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15016 | instead. */ | |
15017 | ||
15018 | if (tp->cond_string) | |
d7e74731 | 15019 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15020 | |
15021 | if (tp->ignore_count) | |
d7e74731 | 15022 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15023 | |
2d9442cc | 15024 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15025 | { |
d7e74731 | 15026 | fp.puts (" commands\n"); |
a7bdde9e | 15027 | |
d7e74731 | 15028 | current_uiout->redirect (&fp); |
a70b8144 | 15029 | try |
1042e4c0 | 15030 | { |
d1b0a7bf | 15031 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 15032 | } |
230d2906 | 15033 | catch (const gdb_exception &ex) |
492d29ea | 15034 | { |
112e8700 | 15035 | current_uiout->redirect (NULL); |
eedc3f4f | 15036 | throw; |
492d29ea | 15037 | } |
1042e4c0 | 15038 | |
112e8700 | 15039 | current_uiout->redirect (NULL); |
d7e74731 | 15040 | fp.puts (" end\n"); |
1042e4c0 | 15041 | } |
6149aea9 PA |
15042 | |
15043 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15044 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15045 | |
15046 | /* If this is a multi-location breakpoint, check if the locations | |
15047 | should be individually disabled. Watchpoint locations are | |
15048 | special, and not user visible. */ | |
15049 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15050 | { | |
15051 | struct bp_location *loc; | |
15052 | int n = 1; | |
15053 | ||
15054 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15055 | if (!loc->enabled) | |
d7e74731 | 15056 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15057 | } |
1042e4c0 | 15058 | } |
8bf6485c | 15059 | |
6149aea9 | 15060 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15061 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15062 | |
1042e4c0 | 15063 | if (from_tty) |
ee0c3293 | 15064 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15065 | } |
15066 | ||
15067 | /* The `save breakpoints' command. */ | |
15068 | ||
15069 | static void | |
4495129a | 15070 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15071 | { |
15072 | save_breakpoints (args, from_tty, NULL); | |
15073 | } | |
15074 | ||
15075 | /* The `save tracepoints' command. */ | |
15076 | ||
15077 | static void | |
4495129a | 15078 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15079 | { |
15080 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15081 | } |
15082 | ||
15083 | /* Create a vector of all tracepoints. */ | |
15084 | ||
f51e0e20 | 15085 | std::vector<breakpoint *> |
eeae04df | 15086 | all_tracepoints (void) |
1042e4c0 | 15087 | { |
f51e0e20 | 15088 | std::vector<breakpoint *> tp_vec; |
1042e4c0 SS |
15089 | struct breakpoint *tp; |
15090 | ||
15091 | ALL_TRACEPOINTS (tp) | |
15092 | { | |
f51e0e20 | 15093 | tp_vec.push_back (tp); |
1042e4c0 SS |
15094 | } |
15095 | ||
15096 | return tp_vec; | |
15097 | } | |
15098 | ||
c906108c | 15099 | \f |
629500fa KS |
15100 | /* This help string is used to consolidate all the help string for specifying |
15101 | locations used by several commands. */ | |
15102 | ||
15103 | #define LOCATION_HELP_STRING \ | |
15104 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15105 | source filename, function name, label name, and line number.\n\ | |
15106 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15107 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15108 | \"factorial.c:fact:the_top\".\n\ | |
15109 | \n\ | |
15110 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15111 | program. Example: To specify the fourth byte past the start function\n\ | |
15112 | \"main\", use \"*main + 4\".\n\ | |
15113 | \n\ | |
15114 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15115 | syntax to specify location parameters.\n\ | |
15116 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15117 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
15118 | -function fact -label the_top\".\n\ |
15119 | \n\ | |
15120 | By default, a specified function is matched against the program's\n\ | |
15121 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
15122 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
15123 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
15124 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 15125 | specified name as a complete fully-qualified name instead." |
629500fa | 15126 | |
4a64f543 MS |
15127 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15128 | commands. It is defined as a macro to prevent duplication. | |
15129 | COMMAND should be a string constant containing the name of the | |
15130 | command. */ | |
629500fa | 15131 | |
31e2b00f | 15132 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15133 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15134 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15135 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15136 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15137 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15138 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15139 | below.\n\ | |
15140 | \n\ | |
dc10affe PA |
15141 | With no LOCATION, uses current execution address of the selected\n\ |
15142 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15143 | \n\ |
15144 | THREADNUM is the number from \"info threads\".\n\ | |
15145 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15146 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15147 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15148 | conditions are different.\n\ | |
31e2b00f AS |
15149 | \n\ |
15150 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15151 | ||
44feb3ce TT |
15152 | /* List of subcommands for "catch". */ |
15153 | static struct cmd_list_element *catch_cmdlist; | |
15154 | ||
15155 | /* List of subcommands for "tcatch". */ | |
15156 | static struct cmd_list_element *tcatch_cmdlist; | |
15157 | ||
9ac4176b | 15158 | void |
a121b7c1 | 15159 | add_catch_command (const char *name, const char *docstring, |
eb4c3f4a | 15160 | cmd_const_sfunc_ftype *sfunc, |
625e8578 | 15161 | completer_ftype *completer, |
44feb3ce TT |
15162 | void *user_data_catch, |
15163 | void *user_data_tcatch) | |
15164 | { | |
15165 | struct cmd_list_element *command; | |
15166 | ||
0450cc4c | 15167 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15168 | &catch_cmdlist); |
15169 | set_cmd_sfunc (command, sfunc); | |
15170 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15171 | set_cmd_completer (command, completer); |
44feb3ce | 15172 | |
0450cc4c | 15173 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15174 | &tcatch_cmdlist); |
15175 | set_cmd_sfunc (command, sfunc); | |
15176 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15177 | set_cmd_completer (command, completer); |
44feb3ce TT |
15178 | } |
15179 | ||
84f4c1fe | 15180 | struct breakpoint * |
95da600f | 15181 | iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback) |
84f4c1fe | 15182 | { |
35df4500 | 15183 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15184 | |
35df4500 | 15185 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe | 15186 | { |
95da600f | 15187 | if (callback (b)) |
84f4c1fe PM |
15188 | return b; |
15189 | } | |
15190 | ||
15191 | return NULL; | |
15192 | } | |
15193 | ||
0574c78f GB |
15194 | /* Zero if any of the breakpoint's locations could be a location where |
15195 | functions have been inlined, nonzero otherwise. */ | |
15196 | ||
15197 | static int | |
15198 | is_non_inline_function (struct breakpoint *b) | |
15199 | { | |
15200 | /* The shared library event breakpoint is set on the address of a | |
15201 | non-inline function. */ | |
15202 | if (b->type == bp_shlib_event) | |
15203 | return 1; | |
15204 | ||
15205 | return 0; | |
15206 | } | |
15207 | ||
15208 | /* Nonzero if the specified PC cannot be a location where functions | |
15209 | have been inlined. */ | |
15210 | ||
15211 | int | |
accd0bcd | 15212 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
09ac7c10 | 15213 | const struct target_waitstatus *ws) |
0574c78f GB |
15214 | { |
15215 | struct breakpoint *b; | |
15216 | struct bp_location *bl; | |
15217 | ||
15218 | ALL_BREAKPOINTS (b) | |
15219 | { | |
15220 | if (!is_non_inline_function (b)) | |
15221 | continue; | |
15222 | ||
15223 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15224 | { | |
15225 | if (!bl->shlib_disabled | |
09ac7c10 | 15226 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15227 | return 1; |
15228 | } | |
15229 | } | |
15230 | ||
15231 | return 0; | |
15232 | } | |
15233 | ||
2f202fde JK |
15234 | /* Remove any references to OBJFILE which is going to be freed. */ |
15235 | ||
15236 | void | |
15237 | breakpoint_free_objfile (struct objfile *objfile) | |
15238 | { | |
15239 | struct bp_location **locp, *loc; | |
15240 | ||
15241 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15242 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15243 | loc->symtab = NULL; |
15244 | } | |
15245 | ||
2060206e PA |
15246 | void |
15247 | initialize_breakpoint_ops (void) | |
15248 | { | |
15249 | static int initialized = 0; | |
15250 | ||
15251 | struct breakpoint_ops *ops; | |
15252 | ||
15253 | if (initialized) | |
15254 | return; | |
15255 | initialized = 1; | |
15256 | ||
15257 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15258 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15259 | internal and momentary breakpoints, etc.). */ | |
15260 | ops = &bkpt_base_breakpoint_ops; | |
15261 | *ops = base_breakpoint_ops; | |
15262 | ops->re_set = bkpt_re_set; | |
15263 | ops->insert_location = bkpt_insert_location; | |
15264 | ops->remove_location = bkpt_remove_location; | |
15265 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15266 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15267 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15268 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15269 | |
15270 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15271 | ops = &bkpt_breakpoint_ops; | |
15272 | *ops = bkpt_base_breakpoint_ops; | |
15273 | ops->re_set = bkpt_re_set; | |
15274 | ops->resources_needed = bkpt_resources_needed; | |
15275 | ops->print_it = bkpt_print_it; | |
15276 | ops->print_mention = bkpt_print_mention; | |
15277 | ops->print_recreate = bkpt_print_recreate; | |
15278 | ||
15279 | /* Ranged breakpoints. */ | |
15280 | ops = &ranged_breakpoint_ops; | |
15281 | *ops = bkpt_breakpoint_ops; | |
15282 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15283 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15284 | ops->print_it = print_it_ranged_breakpoint; | |
15285 | ops->print_one = print_one_ranged_breakpoint; | |
15286 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15287 | ops->print_mention = print_mention_ranged_breakpoint; | |
15288 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15289 | ||
15290 | /* Internal breakpoints. */ | |
15291 | ops = &internal_breakpoint_ops; | |
15292 | *ops = bkpt_base_breakpoint_ops; | |
15293 | ops->re_set = internal_bkpt_re_set; | |
15294 | ops->check_status = internal_bkpt_check_status; | |
15295 | ops->print_it = internal_bkpt_print_it; | |
15296 | ops->print_mention = internal_bkpt_print_mention; | |
15297 | ||
15298 | /* Momentary breakpoints. */ | |
15299 | ops = &momentary_breakpoint_ops; | |
15300 | *ops = bkpt_base_breakpoint_ops; | |
15301 | ops->re_set = momentary_bkpt_re_set; | |
15302 | ops->check_status = momentary_bkpt_check_status; | |
15303 | ops->print_it = momentary_bkpt_print_it; | |
15304 | ops->print_mention = momentary_bkpt_print_mention; | |
15305 | ||
55aa24fb SDJ |
15306 | /* Probe breakpoints. */ |
15307 | ops = &bkpt_probe_breakpoint_ops; | |
15308 | *ops = bkpt_breakpoint_ops; | |
15309 | ops->insert_location = bkpt_probe_insert_location; | |
15310 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15311 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15312 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15313 | |
2060206e PA |
15314 | /* Watchpoints. */ |
15315 | ops = &watchpoint_breakpoint_ops; | |
15316 | *ops = base_breakpoint_ops; | |
15317 | ops->re_set = re_set_watchpoint; | |
15318 | ops->insert_location = insert_watchpoint; | |
15319 | ops->remove_location = remove_watchpoint; | |
15320 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15321 | ops->check_status = check_status_watchpoint; | |
15322 | ops->resources_needed = resources_needed_watchpoint; | |
15323 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15324 | ops->print_it = print_it_watchpoint; | |
15325 | ops->print_mention = print_mention_watchpoint; | |
15326 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15327 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15328 | |
15329 | /* Masked watchpoints. */ | |
15330 | ops = &masked_watchpoint_breakpoint_ops; | |
15331 | *ops = watchpoint_breakpoint_ops; | |
15332 | ops->insert_location = insert_masked_watchpoint; | |
15333 | ops->remove_location = remove_masked_watchpoint; | |
15334 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15335 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15336 | ops->print_it = print_it_masked_watchpoint; | |
15337 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15338 | ops->print_mention = print_mention_masked_watchpoint; | |
15339 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15340 | ||
15341 | /* Tracepoints. */ | |
15342 | ops = &tracepoint_breakpoint_ops; | |
15343 | *ops = base_breakpoint_ops; | |
15344 | ops->re_set = tracepoint_re_set; | |
15345 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15346 | ops->print_one_detail = tracepoint_print_one_detail; | |
15347 | ops->print_mention = tracepoint_print_mention; | |
15348 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15349 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15350 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15351 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15352 | |
55aa24fb SDJ |
15353 | /* Probe tracepoints. */ |
15354 | ops = &tracepoint_probe_breakpoint_ops; | |
15355 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15356 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15357 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15358 | |
983af33b SDJ |
15359 | /* Static tracepoints with marker (`-m'). */ |
15360 | ops = &strace_marker_breakpoint_ops; | |
15361 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15362 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15363 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15364 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15365 | |
15366 | /* Fork catchpoints. */ | |
15367 | ops = &catch_fork_breakpoint_ops; | |
15368 | *ops = base_breakpoint_ops; | |
15369 | ops->insert_location = insert_catch_fork; | |
15370 | ops->remove_location = remove_catch_fork; | |
15371 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15372 | ops->print_it = print_it_catch_fork; | |
15373 | ops->print_one = print_one_catch_fork; | |
15374 | ops->print_mention = print_mention_catch_fork; | |
15375 | ops->print_recreate = print_recreate_catch_fork; | |
15376 | ||
15377 | /* Vfork catchpoints. */ | |
15378 | ops = &catch_vfork_breakpoint_ops; | |
15379 | *ops = base_breakpoint_ops; | |
15380 | ops->insert_location = insert_catch_vfork; | |
15381 | ops->remove_location = remove_catch_vfork; | |
15382 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15383 | ops->print_it = print_it_catch_vfork; | |
15384 | ops->print_one = print_one_catch_vfork; | |
15385 | ops->print_mention = print_mention_catch_vfork; | |
15386 | ops->print_recreate = print_recreate_catch_vfork; | |
15387 | ||
15388 | /* Exec catchpoints. */ | |
15389 | ops = &catch_exec_breakpoint_ops; | |
15390 | *ops = base_breakpoint_ops; | |
2060206e PA |
15391 | ops->insert_location = insert_catch_exec; |
15392 | ops->remove_location = remove_catch_exec; | |
15393 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15394 | ops->print_it = print_it_catch_exec; | |
15395 | ops->print_one = print_one_catch_exec; | |
15396 | ops->print_mention = print_mention_catch_exec; | |
15397 | ops->print_recreate = print_recreate_catch_exec; | |
15398 | ||
edcc5120 TT |
15399 | /* Solib-related catchpoints. */ |
15400 | ops = &catch_solib_breakpoint_ops; | |
15401 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15402 | ops->insert_location = insert_catch_solib; |
15403 | ops->remove_location = remove_catch_solib; | |
15404 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15405 | ops->check_status = check_status_catch_solib; | |
15406 | ops->print_it = print_it_catch_solib; | |
15407 | ops->print_one = print_one_catch_solib; | |
15408 | ops->print_mention = print_mention_catch_solib; | |
15409 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15410 | |
15411 | ops = &dprintf_breakpoint_ops; | |
15412 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15413 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15414 | ops->resources_needed = bkpt_resources_needed; |
15415 | ops->print_it = bkpt_print_it; | |
15416 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15417 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15418 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15419 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15420 | } |
15421 | ||
8bfd80db YQ |
15422 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15423 | ||
15424 | static struct cmd_list_element *enablebreaklist = NULL; | |
15425 | ||
8588b356 SM |
15426 | /* See breakpoint.h. */ |
15427 | ||
15428 | cmd_list_element *commands_cmd_element = nullptr; | |
15429 | ||
6c265988 | 15430 | void _initialize_breakpoint (); |
c906108c | 15431 | void |
6c265988 | 15432 | _initialize_breakpoint () |
c906108c SS |
15433 | { |
15434 | struct cmd_list_element *c; | |
15435 | ||
2060206e PA |
15436 | initialize_breakpoint_ops (); |
15437 | ||
76727919 TT |
15438 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
15439 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); | |
15440 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); | |
84acb35a | 15441 | |
c906108c SS |
15442 | breakpoint_chain = 0; |
15443 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15444 | before a breakpoint is set. */ | |
15445 | breakpoint_count = 0; | |
15446 | ||
1042e4c0 SS |
15447 | tracepoint_count = 0; |
15448 | ||
1bedd215 AC |
15449 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15450 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15451 | Usage is `ignore N COUNT'.")); | |
c906108c | 15452 | |
8588b356 SM |
15453 | commands_cmd_element = add_com ("commands", class_breakpoint, |
15454 | commands_command, _("\ | |
18da0c51 MG |
15455 | Set commands to be executed when the given breakpoints are hit.\n\ |
15456 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15457 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15458 | (e.g. `5-7').\n\ | |
c906108c SS |
15459 | With no argument, the targeted breakpoint is the last one set.\n\ |
15460 | The commands themselves follow starting on the next line.\n\ | |
15461 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15462 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15463 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15464 | |
d55637df | 15465 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15466 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15467 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15468 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15469 | set_cmd_completer (c, condition_completer); |
c906108c | 15470 | |
1bedd215 | 15471 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15472 | Set a temporary breakpoint.\n\ |
c906108c SS |
15473 | Like \"break\" except the breakpoint is only temporary,\n\ |
15474 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15475 | by using \"enable delete\" on the breakpoint number.\n\ |
15476 | \n" | |
15477 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15478 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15479 | |
1bedd215 | 15480 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15481 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15482 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15483 | some target hardware may not have this support.\n\ |
15484 | \n" | |
15485 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15486 | set_cmd_completer (c, location_completer); |
c906108c | 15487 | |
1bedd215 | 15488 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15489 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15490 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15491 | so it will be deleted when hit.\n\ |
15492 | \n" | |
15493 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15494 | set_cmd_completer (c, location_completer); |
c906108c | 15495 | |
1bedd215 | 15496 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
590042fc PW |
15497 | Enable all or some breakpoints.\n\ |
15498 | Usage: enable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15499 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15500 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15501 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15502 | With a subcommand you can enable temporarily."), |
c906108c | 15503 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15504 | |
15505 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15506 | ||
84951ab5 | 15507 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
590042fc PW |
15508 | Enable all or some breakpoints.\n\ |
15509 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15510 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15511 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 15512 | May be abbreviated to simply \"enable\"."), |
c5aa993b | 15513 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15514 | |
1a966eab | 15515 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15516 | Enable some breakpoints for one hit.\n\ |
15517 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ | |
1a966eab | 15518 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
c906108c SS |
15519 | &enablebreaklist); |
15520 | ||
1a966eab | 15521 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15522 | Enable some breakpoints and delete when hit.\n\ |
15523 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ | |
1a966eab | 15524 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15525 | &enablebreaklist); |
15526 | ||
816338b5 | 15527 | add_cmd ("count", no_class, enable_count_command, _("\ |
590042fc PW |
15528 | Enable some breakpoints for COUNT hits.\n\ |
15529 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15530 | If a breakpoint is hit while enabled in this fashion,\n\ |
15531 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15532 | &enablebreaklist); | |
15533 | ||
1a966eab | 15534 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15535 | Enable some breakpoints and delete when hit.\n\ |
15536 | Usage: enable delete BREAKPOINTNUM...\n\ | |
1a966eab | 15537 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15538 | &enablelist); |
15539 | ||
1a966eab | 15540 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15541 | Enable some breakpoints for one hit.\n\ |
15542 | Usage: enable once BREAKPOINTNUM...\n\ | |
1a966eab | 15543 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
816338b5 SS |
15544 | &enablelist); |
15545 | ||
15546 | add_cmd ("count", no_class, enable_count_command, _("\ | |
590042fc PW |
15547 | Enable some breakpoints for COUNT hits.\n\ |
15548 | Usage: enable count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15549 | If a breakpoint is hit while enabled in this fashion,\n\ |
15550 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15551 | &enablelist); |
15552 | ||
1bedd215 | 15553 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
590042fc PW |
15554 | Disable all or some breakpoints.\n\ |
15555 | Usage: disable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15556 | Arguments are breakpoint numbers with spaces in between.\n\ |
15557 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15558 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15559 | &disablelist, "disable ", 1, &cmdlist); |
15560 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15561 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15562 | |
57b4f16e | 15563 | add_cmd ("breakpoints", class_breakpoint, disable_command, _("\ |
590042fc PW |
15564 | Disable all or some breakpoints.\n\ |
15565 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15566 | Arguments are breakpoint numbers with spaces in between.\n\ |
15567 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15568 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15569 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15570 | &disablelist); |
15571 | ||
1bedd215 | 15572 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
590042fc PW |
15573 | Delete all or some breakpoints.\n\ |
15574 | Usage: delete [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15575 | Arguments are breakpoint numbers with spaces in between.\n\ |
15576 | To delete all breakpoints, give no argument.\n\ | |
15577 | \n\ | |
590042fc | 15578 | Also a prefix command for deletion of other GDB objects."), |
c906108c SS |
15579 | &deletelist, "delete ", 1, &cmdlist); |
15580 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15581 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15582 | |
57b4f16e | 15583 | add_cmd ("breakpoints", class_breakpoint, delete_command, _("\ |
590042fc PW |
15584 | Delete all or some breakpoints or auto-display expressions.\n\ |
15585 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15586 | Arguments are breakpoint numbers with spaces in between.\n\ |
15587 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15588 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15589 | &deletelist); |
15590 | ||
1bedd215 | 15591 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15592 | Clear breakpoint at specified location.\n\ |
15593 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15594 | \n\ |
15595 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 15596 | is executing in.\n" |
89549d7f | 15597 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 15598 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15599 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15600 | |
1bedd215 | 15601 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15602 | Set breakpoint at specified location.\n" |
31e2b00f | 15603 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15604 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15605 | |
c906108c SS |
15606 | add_com_alias ("b", "break", class_run, 1); |
15607 | add_com_alias ("br", "break", class_run, 1); | |
15608 | add_com_alias ("bre", "break", class_run, 1); | |
15609 | add_com_alias ("brea", "break", class_run, 1); | |
15610 | ||
c906108c SS |
15611 | if (dbx_commands) |
15612 | { | |
1bedd215 AC |
15613 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15614 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15615 | &stoplist, "stop ", 1, &cmdlist); |
15616 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15617 | _("Break in function or address."), &stoplist); |
c5aa993b | 15618 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15619 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15620 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15621 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15622 | The \"Type\" column indicates one of:\n\ |
15623 | \tbreakpoint - normal breakpoint\n\ | |
15624 | \twatchpoint - watchpoint\n\ | |
15625 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15626 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15627 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15628 | address and file/line number respectively.\n\ |
15629 | \n\ | |
15630 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15631 | are set to the address of the last breakpoint listed unless the command\n\ |
15632 | is prefixed with \"server \".\n\n\ | |
c906108c | 15633 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15634 | breakpoint set.")); |
c906108c SS |
15635 | } |
15636 | ||
11db9430 | 15637 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15638 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15639 | The \"Type\" column indicates one of:\n\ |
15640 | \tbreakpoint - normal breakpoint\n\ | |
15641 | \twatchpoint - watchpoint\n\ | |
15642 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15643 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15644 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15645 | address and file/line number respectively.\n\ |
15646 | \n\ | |
15647 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15648 | are set to the address of the last breakpoint listed unless the command\n\ |
15649 | is prefixed with \"server \".\n\n\ | |
c906108c | 15650 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15651 | breakpoint set.")); |
c906108c | 15652 | |
6b04bdb7 MS |
15653 | add_info_alias ("b", "breakpoints", 1); |
15654 | ||
1a966eab AC |
15655 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15656 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15657 | The \"Type\" column indicates one of:\n\ |
15658 | \tbreakpoint - normal breakpoint\n\ | |
15659 | \twatchpoint - watchpoint\n\ | |
15660 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15661 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15662 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15663 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15664 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15665 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15666 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15667 | address and file/line number respectively.\n\ |
15668 | \n\ | |
15669 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15670 | are set to the address of the last breakpoint listed unless the command\n\ |
15671 | is prefixed with \"server \".\n\n\ | |
c906108c | 15672 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15673 | breakpoint set."), |
c906108c SS |
15674 | &maintenanceinfolist); |
15675 | ||
3b6acaee | 15676 | add_basic_prefix_cmd ("catch", class_breakpoint, _("\ |
44feb3ce | 15677 | Set catchpoints to catch events."), |
3b6acaee TT |
15678 | &catch_cmdlist, "catch ", |
15679 | 0/*allow-unknown*/, &cmdlist); | |
44feb3ce | 15680 | |
3b6acaee | 15681 | add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\ |
44feb3ce | 15682 | Set temporary catchpoints to catch events."), |
3b6acaee TT |
15683 | &tcatch_cmdlist, "tcatch ", |
15684 | 0/*allow-unknown*/, &cmdlist); | |
44feb3ce | 15685 | |
44feb3ce TT |
15686 | add_catch_command ("fork", _("Catch calls to fork."), |
15687 | catch_fork_command_1, | |
a96d9b2e | 15688 | NULL, |
44feb3ce TT |
15689 | (void *) (uintptr_t) catch_fork_permanent, |
15690 | (void *) (uintptr_t) catch_fork_temporary); | |
15691 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15692 | catch_fork_command_1, | |
a96d9b2e | 15693 | NULL, |
44feb3ce TT |
15694 | (void *) (uintptr_t) catch_vfork_permanent, |
15695 | (void *) (uintptr_t) catch_vfork_temporary); | |
15696 | add_catch_command ("exec", _("Catch calls to exec."), | |
15697 | catch_exec_command_1, | |
a96d9b2e SDJ |
15698 | NULL, |
15699 | CATCH_PERMANENT, | |
15700 | CATCH_TEMPORARY); | |
edcc5120 TT |
15701 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15702 | Usage: catch load [REGEX]\n\ | |
15703 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15704 | catch_load_command_1, | |
15705 | NULL, | |
15706 | CATCH_PERMANENT, | |
15707 | CATCH_TEMPORARY); | |
15708 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15709 | Usage: catch unload [REGEX]\n\ | |
15710 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15711 | catch_unload_command_1, | |
15712 | NULL, | |
15713 | CATCH_PERMANENT, | |
15714 | CATCH_TEMPORARY); | |
c5aa993b | 15715 | |
1bedd215 AC |
15716 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15717 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15718 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15719 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15720 | an expression changes.\n\ |
15721 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15722 | the memory to which it refers.")); | |
65d12d83 | 15723 | set_cmd_completer (c, expression_completer); |
c906108c | 15724 | |
1bedd215 AC |
15725 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15726 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15727 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15728 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15729 | an expression is read.\n\ |
15730 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15731 | the memory to which it refers.")); | |
65d12d83 | 15732 | set_cmd_completer (c, expression_completer); |
c906108c | 15733 | |
1bedd215 AC |
15734 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15735 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15736 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15737 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15738 | an expression is either read or written.\n\ |
15739 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15740 | the memory to which it refers.")); | |
65d12d83 | 15741 | set_cmd_completer (c, expression_completer); |
c906108c | 15742 | |
11db9430 | 15743 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15744 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15745 | |
920d2a44 AC |
15746 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15747 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15748 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15749 | &can_use_hw_watchpoints, _("\ | |
15750 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15751 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15752 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15753 | such is available. (However, any hardware watchpoints that were\n\ | |
15754 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15755 | hardware.)"), |
15756 | NULL, | |
920d2a44 | 15757 | show_can_use_hw_watchpoints, |
85c07804 | 15758 | &setlist, &showlist); |
c906108c SS |
15759 | |
15760 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15761 | |
1042e4c0 SS |
15762 | /* Tracepoint manipulation commands. */ |
15763 | ||
15764 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15765 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15766 | \n" |
15767 | BREAK_ARGS_HELP ("trace") "\n\ | |
15768 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15769 | set_cmd_completer (c, location_completer); | |
15770 | ||
57b4f16e PW |
15771 | add_com_alias ("tp", "trace", class_breakpoint, 0); |
15772 | add_com_alias ("tr", "trace", class_breakpoint, 1); | |
15773 | add_com_alias ("tra", "trace", class_breakpoint, 1); | |
15774 | add_com_alias ("trac", "trace", class_breakpoint, 1); | |
1042e4c0 | 15775 | |
7a697b8d | 15776 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15777 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15778 | \n" |
15779 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15780 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15781 | set_cmd_completer (c, location_completer); | |
15782 | ||
0fb4aa4b | 15783 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15784 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15785 | \n\ |
15786 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15787 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15788 | or -m MARKER_ID.\n\n\ | |
15789 | If a marker id is specified, probe the marker with that name. With\n\ | |
15790 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15791 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15792 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15793 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15794 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15795 | \n\ | |
15796 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15797 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15798 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15799 | conditions are different.\n\ | |
0fb4aa4b PA |
15800 | \n\ |
15801 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15802 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15803 | set_cmd_completer (c, location_completer); | |
15804 | ||
11db9430 | 15805 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 15806 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15807 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15808 | last tracepoint set.")); | |
15809 | ||
15810 | add_info_alias ("tp", "tracepoints", 1); | |
15811 | ||
15812 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15813 | Delete specified tracepoints.\n\ | |
15814 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15815 | No argument means delete all tracepoints."), | |
15816 | &deletelist); | |
7e20dfcd | 15817 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
15818 | |
15819 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15820 | Disable specified tracepoints.\n\ | |
15821 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15822 | No argument means disable all tracepoints."), | |
15823 | &disablelist); | |
15824 | deprecate_cmd (c, "disable"); | |
15825 | ||
15826 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15827 | Enable specified tracepoints.\n\ | |
15828 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15829 | No argument means enable all tracepoints."), | |
15830 | &enablelist); | |
15831 | deprecate_cmd (c, "enable"); | |
15832 | ||
15833 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15834 | Set the passcount for a tracepoint.\n\ | |
15835 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15836 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15837 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15838 | ||
0743fc83 TT |
15839 | add_basic_prefix_cmd ("save", class_breakpoint, |
15840 | _("Save breakpoint definitions as a script."), | |
15841 | &save_cmdlist, "save ", | |
15842 | 0/*allow-unknown*/, &cmdlist); | |
6149aea9 PA |
15843 | |
15844 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15845 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15846 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15847 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15848 | session to restore them."), | |
15849 | &save_cmdlist); | |
15850 | set_cmd_completer (c, filename_completer); | |
15851 | ||
15852 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15853 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15854 | Use the 'source' command in another debug session to restore them."), |
15855 | &save_cmdlist); | |
1042e4c0 SS |
15856 | set_cmd_completer (c, filename_completer); |
15857 | ||
6149aea9 PA |
15858 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
15859 | deprecate_cmd (c, "save tracepoints"); | |
15860 | ||
3b6acaee | 15861 | add_basic_prefix_cmd ("breakpoint", class_maintenance, _("\ |
590042fc | 15862 | Breakpoint specific settings.\n\ |
fa8d40ab | 15863 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15864 | pending breakpoint behavior."), |
3b6acaee TT |
15865 | &breakpoint_set_cmdlist, "set breakpoint ", |
15866 | 0/*allow-unknown*/, &setlist); | |
15867 | add_show_prefix_cmd ("breakpoint", class_maintenance, _("\ | |
590042fc | 15868 | Breakpoint specific settings.\n\ |
fa8d40ab | 15869 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15870 | pending breakpoint behavior."), |
3b6acaee TT |
15871 | &breakpoint_show_cmdlist, "show breakpoint ", |
15872 | 0/*allow-unknown*/, &showlist); | |
fa8d40ab | 15873 | |
7915a72c AC |
15874 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15875 | &pending_break_support, _("\ | |
15876 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15877 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15878 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15879 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15880 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15881 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15882 | NULL, |
920d2a44 | 15883 | show_pending_break_support, |
6e1d7d6c AC |
15884 | &breakpoint_set_cmdlist, |
15885 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15886 | |
15887 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15888 | |
15889 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15890 | &automatic_hardware_breakpoints, _("\ | |
15891 | Set automatic usage of hardware breakpoints."), _("\ | |
15892 | Show automatic usage of hardware breakpoints."), _("\ | |
15893 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15894 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15895 | a warning will be emitted for such breakpoints."), | |
15896 | NULL, | |
15897 | show_automatic_hardware_breakpoints, | |
15898 | &breakpoint_set_cmdlist, | |
15899 | &breakpoint_show_cmdlist); | |
74960c60 | 15900 | |
a25a5a45 PA |
15901 | add_setshow_boolean_cmd ("always-inserted", class_support, |
15902 | &always_inserted_mode, _("\ | |
74960c60 VP |
15903 | Set mode for inserting breakpoints."), _("\ |
15904 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
15905 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
15906 | they're created, kept inserted even when execution stops, and removed\n\ | |
15907 | only when the user deletes them. When this mode is off (the default),\n\ | |
15908 | breakpoints are inserted only when execution continues, and removed\n\ | |
15909 | when execution stops."), | |
72d0e2c5 YQ |
15910 | NULL, |
15911 | &show_always_inserted_mode, | |
15912 | &breakpoint_set_cmdlist, | |
15913 | &breakpoint_show_cmdlist); | |
f1310107 | 15914 | |
b775012e LM |
15915 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15916 | condition_evaluation_enums, | |
15917 | &condition_evaluation_mode_1, _("\ | |
15918 | Set mode of breakpoint condition evaluation."), _("\ | |
15919 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 15920 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
15921 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
15922 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15923 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15924 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15925 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
15926 | be set to \"gdb\""), | |
15927 | &set_condition_evaluation_mode, | |
15928 | &show_condition_evaluation_mode, | |
15929 | &breakpoint_set_cmdlist, | |
15930 | &breakpoint_show_cmdlist); | |
15931 | ||
f1310107 TJB |
15932 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15933 | Set a breakpoint for an address range.\n\ | |
15934 | break-range START-LOCATION, END-LOCATION\n\ | |
15935 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15936 | LINENUM, for that line in the current file,\n\ | |
15937 | FILE:LINENUM, for that line in that file,\n\ | |
15938 | +OFFSET, for that number of lines after the current line\n\ | |
15939 | or the start of the range\n\ | |
15940 | FUNCTION, for the first line in that function,\n\ | |
15941 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15942 | *ADDRESS, for the instruction at that address.\n\ | |
15943 | \n\ | |
15944 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15945 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15946 | range (including START-LOCATION and END-LOCATION).")); | |
15947 | ||
e7e0cddf | 15948 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 15949 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 15950 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
15951 | location may be a linespec, explicit, or address location.\n" |
15952 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
15953 | set_cmd_completer (c, location_completer); |
15954 | ||
15955 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
15956 | dprintf_style_enums, &dprintf_style, _("\ | |
15957 | Set the style of usage for dynamic printf."), _("\ | |
15958 | Show the style of usage for dynamic printf."), _("\ | |
15959 | This setting chooses how GDB will do a dynamic printf.\n\ | |
15960 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
15961 | console, as with the \"printf\" command.\n\ | |
15962 | If the value is \"call\", the print is done by calling a function in your\n\ | |
15963 | program; by default printf(), but you can choose a different function or\n\ | |
15964 | output stream by setting dprintf-function and dprintf-channel."), | |
15965 | update_dprintf_commands, NULL, | |
15966 | &setlist, &showlist); | |
15967 | ||
15968 | dprintf_function = xstrdup ("printf"); | |
15969 | add_setshow_string_cmd ("dprintf-function", class_support, | |
15970 | &dprintf_function, _("\ | |
590042fc PW |
15971 | Set the function to use for dynamic printf."), _("\ |
15972 | Show the function to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15973 | update_dprintf_commands, NULL, |
15974 | &setlist, &showlist); | |
15975 | ||
15976 | dprintf_channel = xstrdup (""); | |
15977 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
15978 | &dprintf_channel, _("\ | |
590042fc PW |
15979 | Set the channel to use for dynamic printf."), _("\ |
15980 | Show the channel to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15981 | update_dprintf_commands, NULL, |
15982 | &setlist, &showlist); | |
15983 | ||
d3ce09f5 SS |
15984 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
15985 | &disconnected_dprintf, _("\ | |
15986 | Set whether dprintf continues after GDB disconnects."), _("\ | |
15987 | Show whether dprintf continues after GDB disconnects."), _("\ | |
15988 | Use this to let dprintf commands continue to hit and produce output\n\ | |
15989 | even if GDB disconnects or detaches from the target."), | |
15990 | NULL, | |
15991 | NULL, | |
15992 | &setlist, &showlist); | |
15993 | ||
15994 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
590042fc PW |
15995 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
15996 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
15997 | This supports most C printf format specifications, like %s, %d, etc.\n\ | |
15998 | This is useful for formatted output in user-defined commands.")); | |
d3ce09f5 | 15999 | |
491144b5 | 16000 | automatic_hardware_breakpoints = true; |
f3b1572e | 16001 | |
76727919 TT |
16002 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
16003 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); | |
c906108c | 16004 | } |