]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
4a94e368 | 3 | Copyright (C) 1986-2022 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" |
d322d6d6 | 59 | #include "gdbsupport/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" |
0f8e2034 | 70 | #include "cli/cli-decode.h" |
d3ce09f5 | 71 | |
1042e4c0 | 72 | /* readline include files */ |
073bbbb0 | 73 | #include "readline/tilde.h" |
1042e4c0 SS |
74 | |
75 | /* readline defines this. */ | |
76 | #undef savestring | |
77 | ||
034dad6f | 78 | #include "mi/mi-common.h" |
6dddc817 | 79 | #include "extension.h" |
325fac50 | 80 | #include <algorithm> |
5ed8105e | 81 | #include "progspace-and-thread.h" |
268a13a5 TT |
82 | #include "gdbsupport/array-view.h" |
83 | #include "gdbsupport/gdb_optional.h" | |
104c1213 | 84 | |
4a64f543 | 85 | /* Prototypes for local functions. */ |
c906108c | 86 | |
896b6bda | 87 | static void map_breakpoint_numbers (const char *, |
48649e1b | 88 | gdb::function_view<void (breakpoint *)>); |
c906108c | 89 | |
348d480f PA |
90 | static void breakpoint_re_set_default (struct breakpoint *); |
91 | ||
f00aae0f | 92 | static void |
626d2320 | 93 | create_sals_from_location_default (struct event_location *location, |
f00aae0f KS |
94 | struct linespec_result *canonical, |
95 | enum bptype type_wanted); | |
983af33b SDJ |
96 | |
97 | static void create_breakpoints_sal_default (struct gdbarch *, | |
98 | struct linespec_result *, | |
e1e01040 PA |
99 | gdb::unique_xmalloc_ptr<char>, |
100 | gdb::unique_xmalloc_ptr<char>, | |
101 | enum bptype, | |
983af33b SDJ |
102 | enum bpdisp, int, int, |
103 | int, | |
104 | const struct breakpoint_ops *, | |
44f238bb | 105 | int, int, int, unsigned); |
983af33b | 106 | |
6c5b2ebe | 107 | static std::vector<symtab_and_line> decode_location_default |
626d2320 | 108 | (struct breakpoint *b, struct event_location *location, |
6c5b2ebe | 109 | struct program_space *search_pspace); |
983af33b | 110 | |
a6535de1 TT |
111 | static int can_use_hardware_watchpoint |
112 | (const std::vector<value_ref_ptr> &vals); | |
c906108c | 113 | |
a14ed312 | 114 | static void mention (struct breakpoint *); |
c906108c | 115 | |
348d480f PA |
116 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
117 | enum bptype, | |
c0a91b2b | 118 | const struct breakpoint_ops *); |
3742cc8b YQ |
119 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
120 | const struct symtab_and_line *); | |
121 | ||
4a64f543 MS |
122 | /* This function is used in gdbtk sources and thus can not be made |
123 | static. */ | |
cd0f67f3 SM |
124 | static struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
125 | struct symtab_and_line, | |
126 | enum bptype, | |
127 | const struct breakpoint_ops *); | |
c906108c | 128 | |
06edf0c0 PA |
129 | static struct breakpoint * |
130 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
131 | enum bptype type, | |
a1aa2221 LM |
132 | const struct breakpoint_ops *ops, |
133 | int loc_enabled); | |
06edf0c0 | 134 | |
76897487 KB |
135 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
136 | ||
a6d9a66e UW |
137 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
138 | CORE_ADDR bpaddr, | |
dda83cd7 | 139 | enum bptype bptype); |
76897487 | 140 | |
6c95b8df PA |
141 | static void describe_other_breakpoints (struct gdbarch *, |
142 | struct program_space *, CORE_ADDR, | |
5af949e3 | 143 | struct obj_section *, int); |
c906108c | 144 | |
85d721b8 PA |
145 | static int watchpoint_locations_match (struct bp_location *loc1, |
146 | struct bp_location *loc2); | |
147 | ||
7f32a4d5 PA |
148 | static int breakpoint_locations_match (struct bp_location *loc1, |
149 | struct bp_location *loc2, | |
150 | bool sw_hw_bps_match = false); | |
151 | ||
f1310107 | 152 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 153 | const struct address_space *aspace, |
f1310107 TJB |
154 | CORE_ADDR addr); |
155 | ||
d35ae833 | 156 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 157 | const address_space *, |
d35ae833 PA |
158 | CORE_ADDR, int); |
159 | ||
834c0d03 | 160 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 161 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 162 | |
313f3b21 | 163 | static enum print_stop_action print_bp_stop_message (bpstat *bs); |
c906108c | 164 | |
a14ed312 | 165 | static int hw_breakpoint_used_count (void); |
c906108c | 166 | |
a1398e0c PA |
167 | static int hw_watchpoint_use_count (struct breakpoint *); |
168 | ||
169 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
170 | enum bptype type, | |
171 | int *other_type_used); | |
c906108c | 172 | |
816338b5 SS |
173 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
174 | int count); | |
c906108c | 175 | |
f431efe5 | 176 | static void decref_bp_location (struct bp_location **loc); |
fe3f5fa8 | 177 | |
39d61571 | 178 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 179 | |
44702360 PA |
180 | /* update_global_location_list's modes of operation wrt to whether to |
181 | insert locations now. */ | |
182 | enum ugll_insert_mode | |
183 | { | |
184 | /* Don't insert any breakpoint locations into the inferior, only | |
185 | remove already-inserted locations that no longer should be | |
186 | inserted. Functions that delete a breakpoint or breakpoints | |
187 | should specify this mode, so that deleting a breakpoint doesn't | |
188 | have the side effect of inserting the locations of other | |
189 | breakpoints that are marked not-inserted, but should_be_inserted | |
190 | returns true on them. | |
191 | ||
192 | This behavior is useful is situations close to tear-down -- e.g., | |
193 | after an exec, while the target still has execution, but | |
194 | breakpoint shadows of the previous executable image should *NOT* | |
195 | be restored to the new image; or before detaching, where the | |
196 | target still has execution and wants to delete breakpoints from | |
197 | GDB's lists, and all breakpoints had already been removed from | |
198 | the inferior. */ | |
199 | UGLL_DONT_INSERT, | |
200 | ||
a25a5a45 PA |
201 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
202 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
203 | UGLL_MAY_INSERT, |
204 | ||
a25a5a45 PA |
205 | /* Insert locations now, irrespective of |
206 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
207 | stopped right now, and the user did "continue". We need to | |
208 | insert breakpoints _before_ resuming the target, but | |
209 | UGLL_MAY_INSERT wouldn't insert them, because | |
210 | breakpoints_should_be_inserted_now returns false at that point, | |
211 | as no thread is running yet. */ | |
04086b45 | 212 | UGLL_INSERT |
44702360 PA |
213 | }; |
214 | ||
215 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 216 | |
44702360 | 217 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 218 | |
74960c60 | 219 | static void insert_breakpoint_locations (void); |
a5606eee | 220 | |
0b39b52e | 221 | static void trace_pass_command (const char *, int); |
1042e4c0 | 222 | |
558a9d82 YQ |
223 | static void set_tracepoint_count (int num); |
224 | ||
f2478a7e | 225 | static bool is_masked_watchpoint (const struct breakpoint *b); |
9c06b0b4 | 226 | |
983af33b SDJ |
227 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
228 | otherwise. */ | |
229 | ||
230 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 231 | |
2060206e PA |
232 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
233 | that are implemented on top of software or hardware breakpoints | |
234 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
235 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
236 | ||
237 | /* Internal breakpoints class type. */ | |
06edf0c0 | 238 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
239 | |
240 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
241 | static struct breakpoint_ops momentary_breakpoint_ops; |
242 | ||
2060206e PA |
243 | /* The breakpoint_ops structure to be used in regular user created |
244 | breakpoints. */ | |
245 | struct breakpoint_ops bkpt_breakpoint_ops; | |
246 | ||
55aa24fb SDJ |
247 | /* Breakpoints set on probes. */ |
248 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
249 | ||
bac7c5cf GB |
250 | /* Tracepoints set on probes. */ |
251 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
252 | ||
e7e0cddf | 253 | /* Dynamic printf class type. */ |
c5867ab6 | 254 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 255 | |
d3ce09f5 SS |
256 | /* The style in which to perform a dynamic printf. This is a user |
257 | option because different output options have different tradeoffs; | |
258 | if GDB does the printing, there is better error handling if there | |
259 | is a problem with any of the arguments, but using an inferior | |
260 | function lets you have special-purpose printers and sending of | |
261 | output to the same place as compiled-in print functions. */ | |
262 | ||
263 | static const char dprintf_style_gdb[] = "gdb"; | |
264 | static const char dprintf_style_call[] = "call"; | |
265 | static const char dprintf_style_agent[] = "agent"; | |
266 | static const char *const dprintf_style_enums[] = { | |
267 | dprintf_style_gdb, | |
268 | dprintf_style_call, | |
269 | dprintf_style_agent, | |
270 | NULL | |
271 | }; | |
272 | static const char *dprintf_style = dprintf_style_gdb; | |
273 | ||
274 | /* The function to use for dynamic printf if the preferred style is to | |
275 | call into the inferior. The value is simply a string that is | |
276 | copied into the command, so it can be anything that GDB can | |
277 | evaluate to a callable address, not necessarily a function name. */ | |
278 | ||
e0700ba4 | 279 | static std::string dprintf_function = "printf"; |
d3ce09f5 SS |
280 | |
281 | /* The channel to use for dynamic printf if the preferred style is to | |
282 | call into the inferior; if a nonempty string, it will be passed to | |
283 | the call as the first argument, with the format string as the | |
284 | second. As with the dprintf function, this can be anything that | |
285 | GDB knows how to evaluate, so in addition to common choices like | |
286 | "stderr", this could be an app-specific expression like | |
287 | "mystreams[curlogger]". */ | |
288 | ||
e0700ba4 | 289 | static std::string dprintf_channel; |
d3ce09f5 SS |
290 | |
291 | /* True if dprintf commands should continue to operate even if GDB | |
292 | has disconnected. */ | |
491144b5 | 293 | static bool disconnected_dprintf = true; |
d3ce09f5 | 294 | |
5cea2a26 PA |
295 | struct command_line * |
296 | breakpoint_commands (struct breakpoint *b) | |
297 | { | |
d1b0a7bf | 298 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 299 | } |
3daf8fe5 | 300 | |
f3b1572e PA |
301 | /* Flag indicating that a command has proceeded the inferior past the |
302 | current breakpoint. */ | |
303 | ||
491144b5 | 304 | static bool breakpoint_proceeded; |
f3b1572e | 305 | |
956a9fb9 | 306 | const char * |
2cec12e5 AR |
307 | bpdisp_text (enum bpdisp disp) |
308 | { | |
4a64f543 MS |
309 | /* NOTE: the following values are a part of MI protocol and |
310 | represent values of 'disp' field returned when inferior stops at | |
311 | a breakpoint. */ | |
bc043ef3 | 312 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 313 | |
2cec12e5 AR |
314 | return bpdisps[(int) disp]; |
315 | } | |
c906108c | 316 | |
4a64f543 | 317 | /* Prototypes for exported functions. */ |
c906108c | 318 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 319 | if such is available. */ |
c906108c SS |
320 | static int can_use_hw_watchpoints; |
321 | ||
920d2a44 AC |
322 | static void |
323 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
324 | struct cmd_list_element *c, | |
325 | const char *value) | |
326 | { | |
3e43a32a MS |
327 | fprintf_filtered (file, |
328 | _("Debugger's willingness to use " | |
329 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
330 | value); |
331 | } | |
332 | ||
fa8d40ab JJ |
333 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
334 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 335 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
336 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
337 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
338 | static void |
339 | show_pending_break_support (struct ui_file *file, int from_tty, | |
340 | struct cmd_list_element *c, | |
341 | const char *value) | |
342 | { | |
3e43a32a MS |
343 | fprintf_filtered (file, |
344 | _("Debugger's behavior regarding " | |
345 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
346 | value); |
347 | } | |
fa8d40ab | 348 | |
491144b5 | 349 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 350 | set with "break" but falling in read-only memory. |
491144b5 | 351 | If false, gdb will warn about such breakpoints, but won't automatically |
765dc015 | 352 | use hardware breakpoints. */ |
491144b5 | 353 | static bool automatic_hardware_breakpoints; |
765dc015 VP |
354 | static void |
355 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
356 | struct cmd_list_element *c, | |
357 | const char *value) | |
358 | { | |
3e43a32a MS |
359 | fprintf_filtered (file, |
360 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
361 | value); |
362 | } | |
363 | ||
a25a5a45 PA |
364 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
365 | stopped, and immediately inserts any new breakpoints as soon as | |
366 | they're created. If off (default), GDB keeps breakpoints off of | |
367 | the target as long as possible. That is, it delays inserting | |
368 | breakpoints until the next resume, and removes them again when the | |
369 | target fully stops. This is a bit safer in case GDB crashes while | |
370 | processing user input. */ | |
491144b5 | 371 | static bool always_inserted_mode = false; |
72d0e2c5 | 372 | |
33e5cbd6 | 373 | static void |
74960c60 | 374 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 375 | struct cmd_list_element *c, const char *value) |
74960c60 | 376 | { |
a25a5a45 PA |
377 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
378 | value); | |
74960c60 VP |
379 | } |
380 | ||
b57bacec PA |
381 | /* See breakpoint.h. */ |
382 | ||
33e5cbd6 | 383 | int |
a25a5a45 | 384 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 385 | { |
a25a5a45 PA |
386 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
387 | { | |
388 | /* If breakpoints are global, they should be inserted even if no | |
389 | thread under gdb's control is running, or even if there are | |
390 | no threads under GDB's control yet. */ | |
391 | return 1; | |
392 | } | |
5b6d1e4f | 393 | else |
a25a5a45 | 394 | { |
a25a5a45 PA |
395 | if (always_inserted_mode) |
396 | { | |
397 | /* The user wants breakpoints inserted even if all threads | |
398 | are stopped. */ | |
399 | return 1; | |
400 | } | |
401 | ||
5b6d1e4f PA |
402 | for (inferior *inf : all_inferiors ()) |
403 | if (inf->has_execution () | |
404 | && threads_are_executing (inf->process_target ())) | |
405 | return 1; | |
372316f1 PA |
406 | |
407 | /* Don't remove breakpoints yet if, even though all threads are | |
408 | stopped, we still have events to process. */ | |
08036331 | 409 | for (thread_info *tp : all_non_exited_threads ()) |
1edb66d8 | 410 | if (tp->resumed () && tp->has_pending_waitstatus ()) |
372316f1 | 411 | return 1; |
a25a5a45 PA |
412 | } |
413 | return 0; | |
33e5cbd6 | 414 | } |
765dc015 | 415 | |
b775012e LM |
416 | static const char condition_evaluation_both[] = "host or target"; |
417 | ||
418 | /* Modes for breakpoint condition evaluation. */ | |
419 | static const char condition_evaluation_auto[] = "auto"; | |
420 | static const char condition_evaluation_host[] = "host"; | |
421 | static const char condition_evaluation_target[] = "target"; | |
422 | static const char *const condition_evaluation_enums[] = { | |
423 | condition_evaluation_auto, | |
424 | condition_evaluation_host, | |
425 | condition_evaluation_target, | |
426 | NULL | |
427 | }; | |
428 | ||
429 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
430 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
431 | ||
432 | /* Global that we use to display information to the user (gets its value from | |
433 | condition_evaluation_mode_1. */ | |
434 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
435 | ||
436 | /* Translate a condition evaluation mode MODE into either "host" | |
437 | or "target". This is used mostly to translate from "auto" to the | |
438 | real setting that is being used. It returns the translated | |
439 | evaluation mode. */ | |
440 | ||
441 | static const char * | |
442 | translate_condition_evaluation_mode (const char *mode) | |
443 | { | |
444 | if (mode == condition_evaluation_auto) | |
445 | { | |
446 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
447 | return condition_evaluation_target; | |
448 | else | |
449 | return condition_evaluation_host; | |
450 | } | |
451 | else | |
452 | return mode; | |
453 | } | |
454 | ||
455 | /* Discovers what condition_evaluation_auto translates to. */ | |
456 | ||
457 | static const char * | |
458 | breakpoint_condition_evaluation_mode (void) | |
459 | { | |
460 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
461 | } | |
462 | ||
463 | /* Return true if GDB should evaluate breakpoint conditions or false | |
464 | otherwise. */ | |
465 | ||
466 | static int | |
467 | gdb_evaluates_breakpoint_condition_p (void) | |
468 | { | |
469 | const char *mode = breakpoint_condition_evaluation_mode (); | |
470 | ||
471 | return (mode == condition_evaluation_host); | |
472 | } | |
473 | ||
c906108c SS |
474 | /* Are we executing breakpoint commands? */ |
475 | static int executing_breakpoint_commands; | |
476 | ||
c02f5703 MS |
477 | /* Are overlay event breakpoints enabled? */ |
478 | static int overlay_events_enabled; | |
479 | ||
e09342b5 | 480 | /* See description in breakpoint.h. */ |
491144b5 | 481 | bool target_exact_watchpoints = false; |
e09342b5 | 482 | |
c906108c | 483 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 484 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 485 | current breakpoint. */ |
c906108c | 486 | |
5c44784c JM |
487 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
488 | for (B = breakpoint_chain; \ | |
489 | B ? (TMP=B->next, 1): 0; \ | |
490 | B = TMP) | |
c906108c | 491 | |
7cc221ef | 492 | /* Chains of all breakpoints defined. */ |
c906108c | 493 | |
81e6b8eb | 494 | static struct breakpoint *breakpoint_chain; |
c906108c | 495 | |
240edef6 | 496 | /* See breakpoint.h. */ |
43892fdf | 497 | |
240edef6 | 498 | breakpoint_range |
43892fdf SM |
499 | all_breakpoints () |
500 | { | |
501 | return breakpoint_range (breakpoint_chain); | |
502 | } | |
503 | ||
240edef6 | 504 | /* See breakpoint.h. */ |
1428b37a | 505 | |
240edef6 | 506 | breakpoint_safe_range |
1428b37a SM |
507 | all_breakpoints_safe () |
508 | { | |
509 | return breakpoint_safe_range (all_breakpoints ()); | |
510 | } | |
511 | ||
f6d17b2b SM |
512 | /* See breakpoint.h. */ |
513 | ||
514 | tracepoint_range | |
515 | all_tracepoints () | |
516 | { | |
517 | return tracepoint_range (breakpoint_chain); | |
518 | } | |
519 | ||
39ef2f62 | 520 | /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ |
876fa593 | 521 | |
5d51cd5d | 522 | static std::vector<bp_location *> bp_locations; |
876fa593 | 523 | |
055c879f SM |
524 | /* See breakpoint.h. */ |
525 | ||
526 | const std::vector<bp_location *> & | |
48d7020b SM |
527 | all_bp_locations () |
528 | { | |
529 | return bp_locations; | |
530 | } | |
531 | ||
e0d9a270 SM |
532 | /* Range to iterate over breakpoint locations at a given address. */ |
533 | ||
534 | struct bp_locations_at_addr_range | |
535 | { | |
536 | using iterator = std::vector<bp_location *>::iterator; | |
537 | ||
538 | bp_locations_at_addr_range (CORE_ADDR addr) | |
539 | { | |
540 | struct compare | |
541 | { | |
542 | bool operator() (const bp_location *loc, CORE_ADDR addr_) const | |
543 | { return loc->address < addr_; } | |
544 | ||
545 | bool operator() (CORE_ADDR addr_, const bp_location *loc) const | |
546 | { return addr_ < loc->address; } | |
547 | }; | |
548 | ||
549 | auto it_pair = std::equal_range (bp_locations.begin (), bp_locations.end (), | |
550 | addr, compare ()); | |
551 | ||
552 | m_begin = it_pair.first; | |
553 | m_end = it_pair.second; | |
554 | } | |
555 | ||
556 | iterator begin () const | |
557 | { return m_begin; } | |
558 | ||
559 | iterator end () const | |
560 | { return m_end; } | |
561 | ||
562 | private: | |
563 | iterator m_begin; | |
564 | iterator m_end; | |
565 | }; | |
566 | ||
567 | /* Return a range to iterate over all breakpoint locations exactly at address | |
568 | ADDR. | |
569 | ||
570 | If it's needed to iterate multiple times on the same range, it's possible | |
571 | to save the range in a local variable and use it multiple times: | |
572 | ||
573 | auto range = all_bp_locations_at_addr (addr); | |
574 | ||
575 | for (bp_location *loc : range) | |
576 | // use loc | |
577 | ||
578 | for (bp_location *loc : range) | |
579 | // use loc | |
580 | ||
581 | This saves a bit of time, as it avoids re-doing the binary searches to find | |
582 | the range's boundaries. Just remember not to change the bp_locations vector | |
583 | in the mean time, as it could make the range's iterators stale. */ | |
584 | ||
585 | static bp_locations_at_addr_range | |
586 | all_bp_locations_at_addr (CORE_ADDR addr) | |
587 | { | |
588 | return bp_locations_at_addr_range (addr); | |
589 | } | |
590 | ||
4a64f543 | 591 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 592 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 593 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 594 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 595 | an address you need to read. */ |
876fa593 | 596 | |
f5336ca5 | 597 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 598 | |
4a64f543 MS |
599 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
600 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
601 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
602 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 603 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 604 | |
f5336ca5 | 605 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 606 | |
4a64f543 | 607 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
608 | from the bp_locations array, but for which a hit may still be |
609 | reported by a target. */ | |
1123588c | 610 | static std::vector<bp_location *> moribund_locations; |
20874c92 | 611 | |
c906108c SS |
612 | /* Number of last breakpoint made. */ |
613 | ||
95a42b64 TT |
614 | static int breakpoint_count; |
615 | ||
86b17b60 PA |
616 | /* The value of `breakpoint_count' before the last command that |
617 | created breakpoints. If the last (break-like) command created more | |
618 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
619 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
620 | static int prev_breakpoint_count; | |
c906108c | 621 | |
1042e4c0 SS |
622 | /* Number of last tracepoint made. */ |
623 | ||
95a42b64 | 624 | static int tracepoint_count; |
1042e4c0 | 625 | |
6149aea9 PA |
626 | static struct cmd_list_element *breakpoint_set_cmdlist; |
627 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 628 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 629 | |
468d015d JJ |
630 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
631 | static int | |
632 | breakpoint_enabled (struct breakpoint *b) | |
633 | { | |
0d381245 | 634 | return (b->enable_state == bp_enabled); |
468d015d JJ |
635 | } |
636 | ||
c906108c SS |
637 | /* Set breakpoint count to NUM. */ |
638 | ||
95a42b64 | 639 | static void |
fba45db2 | 640 | set_breakpoint_count (int num) |
c906108c | 641 | { |
86b17b60 | 642 | prev_breakpoint_count = breakpoint_count; |
c906108c | 643 | breakpoint_count = num; |
4fa62494 | 644 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
645 | } |
646 | ||
86b17b60 PA |
647 | /* Used by `start_rbreak_breakpoints' below, to record the current |
648 | breakpoint count before "rbreak" creates any breakpoint. */ | |
649 | static int rbreak_start_breakpoint_count; | |
650 | ||
95a42b64 TT |
651 | /* Called at the start an "rbreak" command to record the first |
652 | breakpoint made. */ | |
86b17b60 | 653 | |
c80049d3 | 654 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 655 | { |
86b17b60 | 656 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
657 | } |
658 | ||
659 | /* Called at the end of an "rbreak" command to record the last | |
660 | breakpoint made. */ | |
86b17b60 | 661 | |
c80049d3 | 662 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 663 | { |
86b17b60 | 664 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
665 | } |
666 | ||
4a64f543 | 667 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
668 | |
669 | void | |
fba45db2 | 670 | clear_breakpoint_hit_counts (void) |
c906108c | 671 | { |
43892fdf | 672 | for (breakpoint *b : all_breakpoints ()) |
c906108c SS |
673 | b->hit_count = 0; |
674 | } | |
675 | ||
c906108c | 676 | \f |
48cb2d85 VP |
677 | /* Return the breakpoint with the specified number, or NULL |
678 | if the number does not refer to an existing breakpoint. */ | |
679 | ||
680 | struct breakpoint * | |
681 | get_breakpoint (int num) | |
682 | { | |
43892fdf | 683 | for (breakpoint *b : all_breakpoints ()) |
48cb2d85 VP |
684 | if (b->number == num) |
685 | return b; | |
686 | ||
43892fdf | 687 | return nullptr; |
48cb2d85 | 688 | } |
5c44784c | 689 | |
c906108c | 690 | \f |
adc36818 | 691 | |
b775012e LM |
692 | /* Mark locations as "conditions have changed" in case the target supports |
693 | evaluating conditions on its side. */ | |
694 | ||
695 | static void | |
696 | mark_breakpoint_modified (struct breakpoint *b) | |
697 | { | |
b775012e LM |
698 | /* This is only meaningful if the target is |
699 | evaluating conditions and if the user has | |
700 | opted for condition evaluation on the target's | |
701 | side. */ | |
702 | if (gdb_evaluates_breakpoint_condition_p () | |
703 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
704 | return; | |
705 | ||
706 | if (!is_breakpoint (b)) | |
707 | return; | |
708 | ||
40cb8ca5 | 709 | for (bp_location *loc : b->locations ()) |
b775012e LM |
710 | loc->condition_changed = condition_modified; |
711 | } | |
712 | ||
713 | /* Mark location as "conditions have changed" in case the target supports | |
714 | evaluating conditions on its side. */ | |
715 | ||
716 | static void | |
717 | mark_breakpoint_location_modified (struct bp_location *loc) | |
718 | { | |
719 | /* This is only meaningful if the target is | |
720 | evaluating conditions and if the user has | |
721 | opted for condition evaluation on the target's | |
722 | side. */ | |
723 | if (gdb_evaluates_breakpoint_condition_p () | |
724 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
725 | ||
726 | return; | |
727 | ||
728 | if (!is_breakpoint (loc->owner)) | |
729 | return; | |
730 | ||
731 | loc->condition_changed = condition_modified; | |
732 | } | |
733 | ||
734 | /* Sets the condition-evaluation mode using the static global | |
735 | condition_evaluation_mode. */ | |
736 | ||
737 | static void | |
eb4c3f4a | 738 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
739 | struct cmd_list_element *c) |
740 | { | |
b775012e LM |
741 | const char *old_mode, *new_mode; |
742 | ||
743 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
744 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
745 | { | |
746 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
747 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
748 | "Using host evaluation mode instead.")); | |
749 | return; | |
750 | } | |
751 | ||
752 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
753 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
754 | ||
abf1152a JK |
755 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
756 | settings was "auto". */ | |
757 | condition_evaluation_mode = condition_evaluation_mode_1; | |
758 | ||
b775012e LM |
759 | /* Only update the mode if the user picked a different one. */ |
760 | if (new_mode != old_mode) | |
761 | { | |
b775012e LM |
762 | /* If the user switched to a different evaluation mode, we |
763 | need to synch the changes with the target as follows: | |
764 | ||
765 | "host" -> "target": Send all (valid) conditions to the target. | |
766 | "target" -> "host": Remove all the conditions from the target. | |
767 | */ | |
768 | ||
b775012e LM |
769 | if (new_mode == condition_evaluation_target) |
770 | { | |
771 | /* Mark everything modified and synch conditions with the | |
772 | target. */ | |
48d7020b | 773 | for (bp_location *loc : all_bp_locations ()) |
b775012e | 774 | mark_breakpoint_location_modified (loc); |
24b21115 | 775 | } |
b775012e LM |
776 | else |
777 | { | |
778 | /* Manually mark non-duplicate locations to synch conditions | |
779 | with the target. We do this to remove all the conditions the | |
780 | target knows about. */ | |
48d7020b | 781 | for (bp_location *loc : all_bp_locations ()) |
b775012e LM |
782 | if (is_breakpoint (loc->owner) && loc->inserted) |
783 | loc->needs_update = 1; | |
784 | } | |
785 | ||
786 | /* Do the update. */ | |
44702360 | 787 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
788 | } |
789 | ||
790 | return; | |
791 | } | |
792 | ||
793 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
794 | what "auto" is translating to. */ | |
795 | ||
796 | static void | |
797 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
798 | struct cmd_list_element *c, const char *value) | |
799 | { | |
800 | if (condition_evaluation_mode == condition_evaluation_auto) | |
801 | fprintf_filtered (file, | |
802 | _("Breakpoint condition evaluation " | |
803 | "mode is %s (currently %s).\n"), | |
804 | value, | |
805 | breakpoint_condition_evaluation_mode ()); | |
806 | else | |
807 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
808 | value); | |
809 | } | |
810 | ||
b5fa468f TBA |
811 | /* Parse COND_STRING in the context of LOC and set as the condition |
812 | expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is | |
813 | the number of LOC within its owner. In case of parsing error, mark | |
814 | LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */ | |
815 | ||
816 | static void | |
817 | set_breakpoint_location_condition (const char *cond_string, bp_location *loc, | |
818 | int bp_num, int loc_num) | |
819 | { | |
820 | bool has_junk = false; | |
821 | try | |
822 | { | |
823 | expression_up new_exp = parse_exp_1 (&cond_string, loc->address, | |
824 | block_for_pc (loc->address), 0); | |
825 | if (*cond_string != 0) | |
826 | has_junk = true; | |
827 | else | |
828 | { | |
829 | loc->cond = std::move (new_exp); | |
830 | if (loc->disabled_by_cond && loc->enabled) | |
831 | printf_filtered (_("Breakpoint %d's condition is now valid at " | |
832 | "location %d, enabling.\n"), | |
833 | bp_num, loc_num); | |
834 | ||
835 | loc->disabled_by_cond = false; | |
836 | } | |
837 | } | |
838 | catch (const gdb_exception_error &e) | |
839 | { | |
840 | if (loc->enabled) | |
841 | { | |
842 | /* Warn if a user-enabled location is now becoming disabled-by-cond. | |
843 | BP_NUM is 0 if the breakpoint is being defined for the first | |
844 | time using the "break ... if ..." command, and non-zero if | |
845 | already defined. */ | |
846 | if (bp_num != 0) | |
847 | warning (_("failed to validate condition at location %d.%d, " | |
848 | "disabling:\n %s"), bp_num, loc_num, e.what ()); | |
849 | else | |
850 | warning (_("failed to validate condition at location %d, " | |
851 | "disabling:\n %s"), loc_num, e.what ()); | |
852 | } | |
853 | ||
854 | loc->disabled_by_cond = true; | |
855 | } | |
856 | ||
857 | if (has_junk) | |
858 | error (_("Garbage '%s' follows condition"), cond_string); | |
859 | } | |
860 | ||
adc36818 | 861 | void |
7a26bd4d | 862 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
733d554a | 863 | int from_tty, bool force) |
adc36818 | 864 | { |
4c55e970 | 865 | if (*exp == 0) |
3a5c3e22 | 866 | { |
6f781ee3 | 867 | b->cond_string.reset (); |
3a5c3e22 | 868 | |
4c55e970 | 869 | if (is_watchpoint (b)) |
78319c15 | 870 | static_cast<watchpoint *> (b)->cond_exp.reset (); |
4c55e970 TBA |
871 | else |
872 | { | |
b5fa468f | 873 | int loc_num = 1; |
40cb8ca5 | 874 | for (bp_location *loc : b->locations ()) |
4c55e970 TBA |
875 | { |
876 | loc->cond.reset (); | |
b5fa468f TBA |
877 | if (loc->disabled_by_cond && loc->enabled) |
878 | printf_filtered (_("Breakpoint %d's condition is now valid at " | |
879 | "location %d, enabling.\n"), | |
880 | b->number, loc_num); | |
881 | loc->disabled_by_cond = false; | |
882 | loc_num++; | |
4c55e970 TBA |
883 | |
884 | /* No need to free the condition agent expression | |
885 | bytecode (if we have one). We will handle this | |
886 | when we go through update_global_location_list. */ | |
887 | } | |
888 | } | |
1e620590 | 889 | |
adc36818 PM |
890 | if (from_tty) |
891 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
892 | } | |
893 | else | |
894 | { | |
adc36818 PM |
895 | if (is_watchpoint (b)) |
896 | { | |
699bd4cf | 897 | innermost_block_tracker tracker; |
78319c15 | 898 | const char *arg = exp; |
4c55e970 | 899 | expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
78319c15 | 900 | if (*arg != 0) |
adc36818 | 901 | error (_("Junk at end of expression")); |
78319c15 | 902 | watchpoint *w = static_cast<watchpoint *> (b); |
4c55e970 | 903 | w->cond_exp = std::move (new_exp); |
699bd4cf | 904 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
905 | } |
906 | else | |
907 | { | |
4c55e970 TBA |
908 | /* Parse and set condition expressions. We make two passes. |
909 | In the first, we parse the condition string to see if it | |
b5fa468f TBA |
910 | is valid in at least one location. If so, the condition |
911 | would be accepted. So we go ahead and set the locations' | |
912 | conditions. In case no valid case is found, we throw | |
4c55e970 TBA |
913 | the error and the condition string will be rejected. |
914 | This two-pass approach is taken to avoid setting the | |
915 | state of locations in case of a reject. */ | |
40cb8ca5 | 916 | for (bp_location *loc : b->locations ()) |
4c55e970 | 917 | { |
b5fa468f TBA |
918 | try |
919 | { | |
920 | const char *arg = exp; | |
921 | parse_exp_1 (&arg, loc->address, | |
922 | block_for_pc (loc->address), 0); | |
923 | if (*arg != 0) | |
924 | error (_("Junk at end of expression")); | |
925 | break; | |
926 | } | |
927 | catch (const gdb_exception_error &e) | |
928 | { | |
929 | /* Condition string is invalid. If this happens to | |
733d554a TBA |
930 | be the last loc, abandon (if not forced) or continue |
931 | (if forced). */ | |
932 | if (loc->next == nullptr && !force) | |
b5fa468f TBA |
933 | throw; |
934 | } | |
4c55e970 TBA |
935 | } |
936 | ||
b5fa468f | 937 | /* If we reach here, the condition is valid at some locations. */ |
dda83cd7 | 938 | int loc_num = 1; |
40cb8ca5 SM |
939 | for (bp_location *loc : b->locations ()) |
940 | { | |
941 | set_breakpoint_location_condition (exp, loc, b->number, loc_num); | |
942 | loc_num++; | |
943 | } | |
adc36818 | 944 | } |
1e620590 TBA |
945 | |
946 | /* We know that the new condition parsed successfully. The | |
947 | condition string of the breakpoint can be safely updated. */ | |
6f781ee3 | 948 | b->cond_string = make_unique_xstrdup (exp); |
1e620590 | 949 | b->condition_not_parsed = 0; |
adc36818 | 950 | } |
b775012e LM |
951 | mark_breakpoint_modified (b); |
952 | ||
76727919 | 953 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
954 | } |
955 | ||
79aabb73 TBA |
956 | /* See breakpoint.h. */ |
957 | ||
958 | void | |
959 | set_breakpoint_condition (int bpnum, const char *exp, int from_tty, | |
960 | bool force) | |
961 | { | |
43892fdf | 962 | for (breakpoint *b : all_breakpoints ()) |
79aabb73 TBA |
963 | if (b->number == bpnum) |
964 | { | |
965 | /* Check if this breakpoint has a "stop" method implemented in an | |
966 | extension language. This method and conditions entered into GDB | |
967 | from the CLI are mutually exclusive. */ | |
968 | const struct extension_language_defn *extlang | |
969 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
970 | ||
971 | if (extlang != NULL) | |
972 | { | |
973 | error (_("Only one stop condition allowed. There is currently" | |
974 | " a %s stop condition defined for this breakpoint."), | |
975 | ext_lang_capitalized_name (extlang)); | |
976 | } | |
977 | set_breakpoint_condition (b, exp, from_tty, force); | |
978 | ||
979 | if (is_breakpoint (b)) | |
980 | update_global_location_list (UGLL_MAY_INSERT); | |
981 | ||
982 | return; | |
983 | } | |
984 | ||
985 | error (_("No breakpoint number %d."), bpnum); | |
986 | } | |
987 | ||
b1d4d8d1 TBA |
988 | /* The options for the "condition" command. */ |
989 | ||
990 | struct condition_command_opts | |
991 | { | |
992 | /* For "-force". */ | |
993 | bool force_condition = false; | |
994 | }; | |
995 | ||
996 | static const gdb::option::option_def condition_command_option_defs[] = { | |
997 | ||
998 | gdb::option::flag_option_def<condition_command_opts> { | |
999 | "force", | |
1000 | [] (condition_command_opts *opts) { return &opts->force_condition; }, | |
1001 | N_("Set the condition even if it is invalid for all current locations."), | |
1002 | }, | |
1003 | ||
1004 | }; | |
1005 | ||
1006 | /* Create an option_def_group for the "condition" options, with | |
1007 | CC_OPTS as context. */ | |
1008 | ||
1009 | static inline gdb::option::option_def_group | |
1010 | make_condition_command_options_def_group (condition_command_opts *cc_opts) | |
1011 | { | |
1012 | return {{condition_command_option_defs}, cc_opts}; | |
1013 | } | |
1014 | ||
d55637df TT |
1015 | /* Completion for the "condition" command. */ |
1016 | ||
eb3ff9a5 | 1017 | static void |
6f937416 | 1018 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 1019 | completion_tracker &tracker, |
b1d4d8d1 | 1020 | const char *text, const char * /*word*/) |
d55637df | 1021 | { |
b1d4d8d1 TBA |
1022 | bool has_no_arguments = (*text == '\0'); |
1023 | condition_command_opts cc_opts; | |
1024 | const auto group = make_condition_command_options_def_group (&cc_opts); | |
1025 | if (gdb::option::complete_options | |
1026 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group)) | |
1027 | return; | |
d55637df | 1028 | |
f1735a53 | 1029 | text = skip_spaces (text); |
b1d4d8d1 | 1030 | const char *space = skip_to_space (text); |
d55637df TT |
1031 | if (*space == '\0') |
1032 | { | |
1033 | int len; | |
d55637df TT |
1034 | |
1035 | if (text[0] == '$') | |
1036 | { | |
b1d4d8d1 | 1037 | tracker.advance_custom_word_point_by (1); |
d55637df | 1038 | /* We don't support completion of history indices. */ |
eb3ff9a5 PA |
1039 | if (!isdigit (text[1])) |
1040 | complete_internalvar (tracker, &text[1]); | |
1041 | return; | |
d55637df TT |
1042 | } |
1043 | ||
b1d4d8d1 TBA |
1044 | /* Suggest the "-force" flag if no arguments are given. If |
1045 | arguments were passed, they either already include the flag, | |
1046 | or we are beyond the point of suggesting it because it's | |
1047 | positionally the first argument. */ | |
1048 | if (has_no_arguments) | |
1049 | gdb::option::complete_on_all_options (tracker, group); | |
1050 | ||
d55637df TT |
1051 | /* We're completing the breakpoint number. */ |
1052 | len = strlen (text); | |
1053 | ||
43892fdf | 1054 | for (breakpoint *b : all_breakpoints ()) |
58ce7251 SDJ |
1055 | { |
1056 | char number[50]; | |
1057 | ||
1058 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1059 | ||
1060 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 1061 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 1062 | } |
d55637df | 1063 | |
eb3ff9a5 | 1064 | return; |
d55637df TT |
1065 | } |
1066 | ||
b1d4d8d1 TBA |
1067 | /* We're completing the expression part. Skip the breakpoint num. */ |
1068 | const char *exp_start = skip_spaces (space); | |
1069 | tracker.advance_custom_word_point_by (exp_start - text); | |
1070 | text = exp_start; | |
1071 | const char *word = advance_to_expression_complete_word_point (tracker, text); | |
eb3ff9a5 | 1072 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
1073 | } |
1074 | ||
c906108c SS |
1075 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1076 | ||
1077 | static void | |
0b39b52e | 1078 | condition_command (const char *arg, int from_tty) |
c906108c | 1079 | { |
0b39b52e | 1080 | const char *p; |
52f0bd74 | 1081 | int bnum; |
c906108c SS |
1082 | |
1083 | if (arg == 0) | |
e2e0b3e5 | 1084 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1085 | |
1086 | p = arg; | |
733d554a TBA |
1087 | |
1088 | /* Check if the "-force" flag was passed. */ | |
b1d4d8d1 TBA |
1089 | condition_command_opts cc_opts; |
1090 | const auto group = make_condition_command_options_def_group (&cc_opts); | |
1091 | gdb::option::process_options | |
1092 | (&p, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group); | |
733d554a | 1093 | |
c906108c | 1094 | bnum = get_number (&p); |
5c44784c | 1095 | if (bnum == 0) |
8a3fe4f8 | 1096 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c | 1097 | |
79aabb73 | 1098 | set_breakpoint_condition (bnum, p, from_tty, cc_opts.force_condition); |
c906108c SS |
1099 | } |
1100 | ||
a7bdde9e VP |
1101 | /* Check that COMMAND do not contain commands that are suitable |
1102 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1103 | Throw if any such commands is found. */ |
1104 | ||
a7bdde9e VP |
1105 | static void |
1106 | check_no_tracepoint_commands (struct command_line *commands) | |
1107 | { | |
1108 | struct command_line *c; | |
cc59ec59 | 1109 | |
a7bdde9e VP |
1110 | for (c = commands; c; c = c->next) |
1111 | { | |
a7bdde9e | 1112 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
1113 | error (_("The 'while-stepping' command can " |
1114 | "only be used for tracepoints")); | |
a7bdde9e | 1115 | |
12973681 TT |
1116 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1117 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1118 | |
1119 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1120 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1121 | command directly. */ |
1122 | if (strstr (c->line, "collect ") == c->line) | |
1123 | error (_("The 'collect' command can only be used for tracepoints")); | |
1124 | ||
51661e93 VP |
1125 | if (strstr (c->line, "teval ") == c->line) |
1126 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1127 | } |
1128 | } | |
1129 | ||
c1fc2657 | 1130 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1131 | { |
c1fc2657 | 1132 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1133 | }; |
1134 | ||
d77f58be SS |
1135 | /* Encapsulate tests for different types of tracepoints. */ |
1136 | ||
3b0871f4 SM |
1137 | static bool |
1138 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1139 | { |
1140 | return (type == bp_tracepoint | |
1141 | || type == bp_fast_tracepoint | |
1142 | || type == bp_static_tracepoint); | |
1143 | } | |
1144 | ||
3b0871f4 SM |
1145 | static bool |
1146 | is_longjmp_type (bptype type) | |
1147 | { | |
1148 | return type == bp_longjmp || type == bp_exception; | |
1149 | } | |
1150 | ||
f2478a7e SM |
1151 | /* See breakpoint.h. */ |
1152 | ||
1153 | bool | |
d77f58be | 1154 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1155 | { |
d9b3f62e | 1156 | return is_tracepoint_type (b->type); |
a7bdde9e | 1157 | } |
d9b3f62e | 1158 | |
a5e364af SM |
1159 | /* Factory function to create an appropriate instance of breakpoint given |
1160 | TYPE. */ | |
1161 | ||
1162 | static std::unique_ptr<breakpoint> | |
1163 | new_breakpoint_from_type (bptype type) | |
1164 | { | |
1165 | breakpoint *b; | |
1166 | ||
1167 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1168 | b = new tracepoint (); |
3b0871f4 | 1169 | else if (is_longjmp_type (type)) |
c1fc2657 | 1170 | b = new longjmp_breakpoint (); |
a5e364af SM |
1171 | else |
1172 | b = new breakpoint (); | |
1173 | ||
1174 | return std::unique_ptr<breakpoint> (b); | |
1175 | } | |
1176 | ||
e5dd4106 | 1177 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1178 | breakpoint. This function will throw an exception if a problem is |
1179 | found. */ | |
48cb2d85 | 1180 | |
95a42b64 TT |
1181 | static void |
1182 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1183 | struct command_line *commands) | |
48cb2d85 | 1184 | { |
d77f58be | 1185 | if (is_tracepoint (b)) |
a7bdde9e | 1186 | { |
c9a6ce02 | 1187 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1188 | struct command_line *c; |
1189 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1190 | |
1191 | /* Reset the while-stepping step count. The previous commands | |
dda83cd7 SM |
1192 | might have included a while-stepping action, while the new |
1193 | ones might not. */ | |
c9a6ce02 PA |
1194 | t->step_count = 0; |
1195 | ||
1196 | /* We need to verify that each top-level element of commands is | |
1197 | valid for tracepoints, that there's at most one | |
1198 | while-stepping element, and that the while-stepping's body | |
1199 | has valid tracing commands excluding nested while-stepping. | |
1200 | We also need to validate the tracepoint action line in the | |
1201 | context of the tracepoint --- validate_actionline actually | |
1202 | has side effects, like setting the tracepoint's | |
1203 | while-stepping STEP_COUNT, in addition to checking if the | |
1204 | collect/teval actions parse and make sense in the | |
1205 | tracepoint's context. */ | |
a7bdde9e VP |
1206 | for (c = commands; c; c = c->next) |
1207 | { | |
a7bdde9e VP |
1208 | if (c->control_type == while_stepping_control) |
1209 | { | |
1210 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1211 | error (_("The 'while-stepping' command " |
1212 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1213 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1214 | error (_("The 'while-stepping' command " |
1215 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1216 | |
1217 | if (while_stepping) | |
3e43a32a MS |
1218 | error (_("The 'while-stepping' command " |
1219 | "can be used only once")); | |
a7bdde9e VP |
1220 | else |
1221 | while_stepping = c; | |
1222 | } | |
c9a6ce02 PA |
1223 | |
1224 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1225 | } |
1226 | if (while_stepping) | |
1227 | { | |
1228 | struct command_line *c2; | |
1229 | ||
12973681 TT |
1230 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1231 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1232 | for (; c2; c2 = c2->next) |
1233 | { | |
a7bdde9e VP |
1234 | if (c2->control_type == while_stepping_control) |
1235 | error (_("The 'while-stepping' command cannot be nested")); | |
1236 | } | |
1237 | } | |
1238 | } | |
1239 | else | |
1240 | { | |
1241 | check_no_tracepoint_commands (commands); | |
1242 | } | |
95a42b64 TT |
1243 | } |
1244 | ||
0fb4aa4b PA |
1245 | /* Return a vector of all the static tracepoints set at ADDR. The |
1246 | caller is responsible for releasing the vector. */ | |
1247 | ||
f51e0e20 | 1248 | std::vector<breakpoint *> |
0fb4aa4b PA |
1249 | static_tracepoints_here (CORE_ADDR addr) |
1250 | { | |
f51e0e20 | 1251 | std::vector<breakpoint *> found; |
0fb4aa4b | 1252 | |
43892fdf | 1253 | for (breakpoint *b : all_breakpoints ()) |
0fb4aa4b PA |
1254 | if (b->type == bp_static_tracepoint) |
1255 | { | |
40cb8ca5 | 1256 | for (bp_location *loc : b->locations ()) |
0fb4aa4b | 1257 | if (loc->address == addr) |
f51e0e20 | 1258 | found.push_back (b); |
0fb4aa4b PA |
1259 | } |
1260 | ||
1261 | return found; | |
1262 | } | |
1263 | ||
95a42b64 | 1264 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1265 | validate that only allowed commands are included. */ |
95a42b64 TT |
1266 | |
1267 | void | |
4a64f543 | 1268 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1269 | counted_command_line &&commands) |
95a42b64 | 1270 | { |
93921405 | 1271 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1272 | |
d1b0a7bf | 1273 | b->commands = std::move (commands); |
76727919 | 1274 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1275 | } |
1276 | ||
45a43567 TT |
1277 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1278 | is not the same as the "silent" that may appear in the breakpoint's | |
1279 | commands. */ | |
1280 | ||
1281 | void | |
1282 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1283 | { | |
1284 | int old_silent = b->silent; | |
1285 | ||
1286 | b->silent = silent; | |
1287 | if (old_silent != silent) | |
76727919 | 1288 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1289 | } |
1290 | ||
1291 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1292 | breakpoint work for any thread. */ | |
1293 | ||
1294 | void | |
1295 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1296 | { | |
1297 | int old_thread = b->thread; | |
1298 | ||
1299 | b->thread = thread; | |
1300 | if (old_thread != thread) | |
76727919 | 1301 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1302 | } |
1303 | ||
1304 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1305 | breakpoint work for any task. */ | |
1306 | ||
1307 | void | |
1308 | breakpoint_set_task (struct breakpoint *b, int task) | |
1309 | { | |
1310 | int old_task = b->task; | |
1311 | ||
1312 | b->task = task; | |
1313 | if (old_task != task) | |
76727919 | 1314 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1315 | } |
1316 | ||
95a42b64 | 1317 | static void |
896b6bda | 1318 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1319 | struct command_line *control) |
95a42b64 | 1320 | { |
d1b0a7bf | 1321 | counted_command_line cmd; |
999700cd PW |
1322 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1323 | NULL after the call to read_command_lines if the user provides an empty | |
1324 | list of command by just typing "end". */ | |
1325 | bool cmd_read = false; | |
95a42b64 | 1326 | |
896b6bda PA |
1327 | std::string new_arg; |
1328 | ||
95a42b64 TT |
1329 | if (arg == NULL || !*arg) |
1330 | { | |
da1df1db | 1331 | /* Argument not explicitly given. Synthesize it. */ |
86b17b60 | 1332 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1333 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1334 | breakpoint_count); | |
95a42b64 | 1335 | else if (breakpoint_count > 0) |
896b6bda | 1336 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b | 1337 | } |
da1df1db TBA |
1338 | else |
1339 | { | |
1340 | /* Create a copy of ARG. This is needed because the "commands" | |
1341 | command may be coming from a script. In that case, the read | |
1342 | line buffer is going to be overwritten in the lambda of | |
1343 | 'map_breakpoint_numbers' below when reading the next line | |
1344 | before we are are done parsing the breakpoint numbers. */ | |
1345 | new_arg = arg; | |
1346 | } | |
1347 | arg = new_arg.c_str (); | |
48649e1b TT |
1348 | |
1349 | map_breakpoint_numbers | |
1350 | (arg, [&] (breakpoint *b) | |
1351 | { | |
999700cd | 1352 | if (!cmd_read) |
48649e1b | 1353 | { |
999700cd | 1354 | gdb_assert (cmd == NULL); |
48649e1b | 1355 | if (control != NULL) |
12973681 | 1356 | cmd = control->body_list_0; |
48649e1b TT |
1357 | else |
1358 | { | |
81b1e71c TT |
1359 | std::string str |
1360 | = string_printf (_("Type commands for breakpoint(s) " | |
1361 | "%s, one per line."), | |
1362 | arg); | |
48649e1b | 1363 | |
60b3cef2 TT |
1364 | auto do_validate = [=] (const char *line) |
1365 | { | |
1366 | validate_actionline (line, b); | |
1367 | }; | |
1368 | gdb::function_view<void (const char *)> validator; | |
1369 | if (is_tracepoint (b)) | |
1370 | validator = do_validate; | |
1371 | ||
1372 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1373 | } |
999700cd | 1374 | cmd_read = true; |
48649e1b TT |
1375 | } |
1376 | ||
1377 | /* If a breakpoint was on the list more than once, we don't need to | |
1378 | do anything. */ | |
1379 | if (b->commands != cmd) | |
1380 | { | |
d1b0a7bf | 1381 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1382 | b->commands = cmd; |
76727919 | 1383 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1384 | } |
1385 | }); | |
95a42b64 TT |
1386 | } |
1387 | ||
1388 | static void | |
0b39b52e | 1389 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1390 | { |
1391 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1392 | } |
40c03ae8 EZ |
1393 | |
1394 | /* Like commands_command, but instead of reading the commands from | |
1395 | input stream, takes them from an already parsed command structure. | |
1396 | ||
1397 | This is used by cli-script.c to DTRT with breakpoint commands | |
1398 | that are part of if and while bodies. */ | |
1399 | enum command_control_type | |
896b6bda | 1400 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1401 | { |
95a42b64 TT |
1402 | commands_command_1 (arg, 0, cmd); |
1403 | return simple_control; | |
40c03ae8 | 1404 | } |
876fa593 JK |
1405 | |
1406 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1407 | ||
1408 | static int | |
1409 | bp_location_has_shadow (struct bp_location *bl) | |
1410 | { | |
1411 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1412 | return 0; | |
1413 | if (!bl->inserted) | |
1414 | return 0; | |
1415 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1416 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1417 | return 0; |
1418 | return 1; | |
1419 | } | |
1420 | ||
9d497a19 PA |
1421 | /* Update BUF, which is LEN bytes read from the target address |
1422 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1423 | contents. | |
1424 | ||
1425 | If READBUF is not NULL, this buffer must not overlap with the of | |
1426 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1427 | failed assertion internal error will be raised. */ | |
1428 | ||
1429 | static void | |
1430 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1431 | const gdb_byte *writebuf_org, | |
1432 | ULONGEST memaddr, LONGEST len, | |
1433 | struct bp_target_info *target_info, | |
1434 | struct gdbarch *gdbarch) | |
1435 | { | |
1436 | /* Now do full processing of the found relevant range of elements. */ | |
1437 | CORE_ADDR bp_addr = 0; | |
1438 | int bp_size = 0; | |
1439 | int bptoffset = 0; | |
1440 | ||
1441 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1442 | current_program_space->aspace, 0)) | |
1443 | { | |
1444 | /* The breakpoint is inserted in a different address space. */ | |
1445 | return; | |
1446 | } | |
1447 | ||
1448 | /* Addresses and length of the part of the breakpoint that | |
1449 | we need to copy. */ | |
1450 | bp_addr = target_info->placed_address; | |
1451 | bp_size = target_info->shadow_len; | |
1452 | ||
1453 | if (bp_addr + bp_size <= memaddr) | |
1454 | { | |
1455 | /* The breakpoint is entirely before the chunk of memory we are | |
1456 | reading. */ | |
1457 | return; | |
1458 | } | |
1459 | ||
1460 | if (bp_addr >= memaddr + len) | |
1461 | { | |
1462 | /* The breakpoint is entirely after the chunk of memory we are | |
1463 | reading. */ | |
1464 | return; | |
1465 | } | |
1466 | ||
1467 | /* Offset within shadow_contents. */ | |
1468 | if (bp_addr < memaddr) | |
1469 | { | |
1470 | /* Only copy the second part of the breakpoint. */ | |
1471 | bp_size -= memaddr - bp_addr; | |
1472 | bptoffset = memaddr - bp_addr; | |
1473 | bp_addr = memaddr; | |
1474 | } | |
1475 | ||
1476 | if (bp_addr + bp_size > memaddr + len) | |
1477 | { | |
1478 | /* Only copy the first part of the breakpoint. */ | |
1479 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1480 | } | |
1481 | ||
1482 | if (readbuf != NULL) | |
1483 | { | |
1484 | /* Verify that the readbuf buffer does not overlap with the | |
1485 | shadow_contents buffer. */ | |
1486 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1487 | || readbuf >= (target_info->shadow_contents | |
1488 | + target_info->shadow_len)); | |
1489 | ||
1490 | /* Update the read buffer with this inserted breakpoint's | |
1491 | shadow. */ | |
1492 | memcpy (readbuf + bp_addr - memaddr, | |
1493 | target_info->shadow_contents + bptoffset, bp_size); | |
1494 | } | |
1495 | else | |
1496 | { | |
1497 | const unsigned char *bp; | |
0d5ed153 MR |
1498 | CORE_ADDR addr = target_info->reqstd_address; |
1499 | int placed_size; | |
9d497a19 PA |
1500 | |
1501 | /* Update the shadow with what we want to write to memory. */ | |
1502 | memcpy (target_info->shadow_contents + bptoffset, | |
1503 | writebuf_org + bp_addr - memaddr, bp_size); | |
1504 | ||
1505 | /* Determine appropriate breakpoint contents and size for this | |
1506 | address. */ | |
0d5ed153 | 1507 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1508 | |
1509 | /* Update the final write buffer with this inserted | |
1510 | breakpoint's INSN. */ | |
1511 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1512 | } | |
1513 | } | |
1514 | ||
8defab1a | 1515 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1516 | by replacing any memory breakpoints with their shadowed contents. |
1517 | ||
35c63cd8 JB |
1518 | If READBUF is not NULL, this buffer must not overlap with any of |
1519 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1520 | a failed assertion internal error will be raised. | |
1521 | ||
876fa593 | 1522 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1523 | bl->address - bp_locations_placed_address_before_address_max |
1524 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1525 | The range we were requested to resolve shadows for is: |
1526 | memaddr ... memaddr + len | |
1527 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1528 | memaddr + len <= (bl->address |
f5336ca5 | 1529 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1530 | and: |
f5336ca5 | 1531 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1532 | |
8defab1a | 1533 | void |
f0ba3972 PA |
1534 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1535 | const gdb_byte *writebuf_org, | |
1536 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1537 | { |
4a64f543 MS |
1538 | /* Left boundary, right boundary and median element of our binary |
1539 | search. */ | |
876fa593 JK |
1540 | unsigned bc_l, bc_r, bc; |
1541 | ||
4a64f543 MS |
1542 | /* Find BC_L which is a leftmost element which may affect BUF |
1543 | content. It is safe to report lower value but a failure to | |
1544 | report higher one. */ | |
876fa593 JK |
1545 | |
1546 | bc_l = 0; | |
5d51cd5d | 1547 | bc_r = bp_locations.size (); |
876fa593 JK |
1548 | while (bc_l + 1 < bc_r) |
1549 | { | |
35df4500 | 1550 | struct bp_location *bl; |
876fa593 JK |
1551 | |
1552 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1553 | bl = bp_locations[bc]; |
876fa593 | 1554 | |
4a64f543 MS |
1555 | /* Check first BL->ADDRESS will not overflow due to the added |
1556 | constant. Then advance the left boundary only if we are sure | |
1557 | the BC element can in no way affect the BUF content (MEMADDR | |
1558 | to MEMADDR + LEN range). | |
876fa593 | 1559 | |
f5336ca5 | 1560 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1561 | offset so that we cannot miss a breakpoint with its shadow |
1562 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1563 | |
f5336ca5 | 1564 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1565 | >= bl->address) |
f5336ca5 | 1566 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1567 | <= memaddr)) |
876fa593 JK |
1568 | bc_l = bc; |
1569 | else | |
1570 | bc_r = bc; | |
1571 | } | |
1572 | ||
128070bb PA |
1573 | /* Due to the binary search above, we need to make sure we pick the |
1574 | first location that's at BC_L's address. E.g., if there are | |
1575 | multiple locations at the same address, BC_L may end up pointing | |
1576 | at a duplicate location, and miss the "master"/"inserted" | |
1577 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1578 | B: | |
1579 | ||
1580 | L1@A, L2@A, L3@B, ... | |
1581 | ||
1582 | BC_L could end up pointing at location L2, while the "master" | |
1583 | location could be L1. Since the `loc->inserted' flag is only set | |
1584 | on "master" locations, we'd forget to restore the shadow of L1 | |
1585 | and L2. */ | |
1586 | while (bc_l > 0 | |
f5336ca5 | 1587 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1588 | bc_l--; |
1589 | ||
876fa593 JK |
1590 | /* Now do full processing of the found relevant range of elements. */ |
1591 | ||
5d51cd5d | 1592 | for (bc = bc_l; bc < bp_locations.size (); bc++) |
01add95b SM |
1593 | { |
1594 | struct bp_location *bl = bp_locations[bc]; | |
876fa593 | 1595 | |
01add95b SM |
1596 | /* bp_location array has BL->OWNER always non-NULL. */ |
1597 | if (bl->owner->type == bp_none) | |
1598 | warning (_("reading through apparently deleted breakpoint #%d?"), | |
1599 | bl->owner->number); | |
ffce0d52 | 1600 | |
01add95b SM |
1601 | /* Performance optimization: any further element can no longer affect BUF |
1602 | content. */ | |
876fa593 | 1603 | |
01add95b SM |
1604 | if (bl->address >= bp_locations_placed_address_before_address_max |
1605 | && (memaddr + len | |
1606 | <= (bl->address | |
1607 | - bp_locations_placed_address_before_address_max))) | |
1608 | break; | |
876fa593 | 1609 | |
01add95b SM |
1610 | if (!bp_location_has_shadow (bl)) |
1611 | continue; | |
6c95b8df | 1612 | |
01add95b SM |
1613 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1614 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1615 | } | |
c906108c | 1616 | } |
9d497a19 | 1617 | |
f2478a7e | 1618 | /* See breakpoint.h. */ |
b775012e | 1619 | |
f2478a7e | 1620 | bool |
b775012e LM |
1621 | is_breakpoint (const struct breakpoint *bpt) |
1622 | { | |
1623 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1624 | || bpt->type == bp_hardware_breakpoint |
1625 | || bpt->type == bp_dprintf); | |
b775012e LM |
1626 | } |
1627 | ||
60e1c644 PA |
1628 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1629 | ||
f2478a7e | 1630 | static bool |
d77f58be | 1631 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1632 | { |
1633 | return (bpt->type == bp_hardware_watchpoint | |
1634 | || bpt->type == bp_read_watchpoint | |
1635 | || bpt->type == bp_access_watchpoint); | |
1636 | } | |
7270d8f2 | 1637 | |
f2478a7e | 1638 | /* See breakpoint.h. */ |
60e1c644 | 1639 | |
f2478a7e | 1640 | bool |
d77f58be | 1641 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1642 | { |
1643 | return (is_hardware_watchpoint (bpt) | |
1644 | || bpt->type == bp_watchpoint); | |
1645 | } | |
1646 | ||
3a5c3e22 PA |
1647 | /* Returns true if the current thread and its running state are safe |
1648 | to evaluate or update watchpoint B. Watchpoints on local | |
1649 | expressions need to be evaluated in the context of the thread that | |
1650 | was current when the watchpoint was created, and, that thread needs | |
1651 | to be stopped to be able to select the correct frame context. | |
1652 | Watchpoints on global expressions can be evaluated on any thread, | |
1653 | and in any state. It is presently left to the target allowing | |
1654 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1655 | |
1656 | static int | |
3a5c3e22 | 1657 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1658 | { |
c1fc2657 | 1659 | return (b->pspace == current_program_space |
d7e15655 TT |
1660 | && (b->watchpoint_thread == null_ptid |
1661 | || (inferior_ptid == b->watchpoint_thread | |
611841bb | 1662 | && !inferior_thread ()->executing ()))); |
f6bc2008 PA |
1663 | } |
1664 | ||
d0fb5eae JK |
1665 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1666 | associated bp_watchpoint_scope breakpoint. */ | |
1667 | ||
1668 | static void | |
3a5c3e22 | 1669 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1670 | { |
c1fc2657 | 1671 | if (w->related_breakpoint != w) |
d0fb5eae | 1672 | { |
c1fc2657 SM |
1673 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1674 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1675 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1676 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1677 | w->related_breakpoint = w; | |
d0fb5eae | 1678 | } |
c1fc2657 | 1679 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1680 | } |
1681 | ||
bb9d5f81 PP |
1682 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1683 | watchpoint W. */ | |
1684 | ||
1685 | static struct value * | |
1686 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1687 | { | |
1688 | struct value *bit_val; | |
1689 | ||
1690 | if (val == NULL) | |
1691 | return NULL; | |
1692 | ||
1693 | bit_val = allocate_value (value_type (val)); | |
1694 | ||
1695 | unpack_value_bitfield (bit_val, | |
1696 | w->val_bitpos, | |
1697 | w->val_bitsize, | |
50888e42 | 1698 | value_contents_for_printing (val).data (), |
bb9d5f81 PP |
1699 | value_offset (val), |
1700 | val); | |
1701 | ||
1702 | return bit_val; | |
1703 | } | |
1704 | ||
c6d81124 PA |
1705 | /* Allocate a dummy location and add it to B, which must be a software |
1706 | watchpoint. This is required because even if a software watchpoint | |
1707 | is not watching any memory, bpstat_stop_status requires a location | |
1708 | to be able to report stops. */ | |
1709 | ||
1710 | static void | |
1711 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1712 | struct program_space *pspace) | |
1713 | { | |
1714 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1715 | ||
1716 | b->loc = allocate_bp_location (b); | |
1717 | b->loc->pspace = pspace; | |
1718 | b->loc->address = -1; | |
1719 | b->loc->length = -1; | |
1720 | } | |
1721 | ||
1722 | /* Returns true if B is a software watchpoint that is not watching any | |
1723 | memory (e.g., "watch $pc"). */ | |
1724 | ||
f2478a7e | 1725 | static bool |
c6d81124 PA |
1726 | is_no_memory_software_watchpoint (struct breakpoint *b) |
1727 | { | |
1728 | return (b->type == bp_watchpoint | |
1729 | && b->loc != NULL | |
1730 | && b->loc->next == NULL | |
1731 | && b->loc->address == -1 | |
1732 | && b->loc->length == -1); | |
1733 | } | |
1734 | ||
567e1b4e JB |
1735 | /* Assuming that B is a watchpoint: |
1736 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1737 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1738 | - Evaluate the condition if there is one, and store the result |
1739 | in b->loc->cond. | |
a5606eee VP |
1740 | - Update the list of values that must be watched in B->loc. |
1741 | ||
4a64f543 MS |
1742 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1743 | nothing. If this is local watchpoint that is out of scope, delete | |
1744 | it. | |
1745 | ||
1746 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1747 | removed + inserted on each stop here. Normal breakpoints must | |
1748 | never be removed because they might be missed by a running thread | |
1749 | when debugging in non-stop mode. On the other hand, hardware | |
1750 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1751 | to each LWP since they are stored in each LWP's hardware debug | |
1752 | registers. Therefore, such LWP must be stopped first in order to | |
1753 | be able to modify its hardware watchpoints. | |
1754 | ||
1755 | Hardware watchpoints must be reset exactly once after being | |
1756 | presented to the user. It cannot be done sooner, because it would | |
1757 | reset the data used to present the watchpoint hit to the user. And | |
1758 | it must not be done later because it could display the same single | |
1759 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1760 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1761 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1762 | not user-visible - its hit is suppressed if the memory content has | |
1763 | not changed. | |
1764 | ||
1765 | The following constraints influence the location where we can reset | |
1766 | hardware watchpoints: | |
1767 | ||
1768 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1769 | called several times when GDB stops. | |
1770 | ||
1771 | [linux] | |
1772 | * Multiple hardware watchpoints can be hit at the same time, | |
1773 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1774 | hit at a time as the reason for stopping, and all the other hits | |
1775 | are presented later, one after the other, each time the user | |
1776 | requests the execution to be resumed. Execution is not resumed | |
1777 | for the threads still having pending hit event stored in | |
1778 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1779 | the inferior on the first stop the thread hit event is kept being | |
1780 | reported from its cached value by linux_nat_stopped_data_address | |
1781 | until the real thread resume happens after the watchpoint gets | |
1782 | presented and thus its LWP_INFO->STATUS gets reset. | |
1783 | ||
1784 | Therefore the hardware watchpoint hit can get safely reset on the | |
1785 | watchpoint removal from inferior. */ | |
a79d3c27 | 1786 | |
b40ce68a | 1787 | static void |
3a5c3e22 | 1788 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1789 | { |
a5606eee | 1790 | int within_current_scope; |
a5606eee | 1791 | struct frame_id saved_frame_id; |
66076460 | 1792 | int frame_saved; |
a5606eee | 1793 | |
f6bc2008 PA |
1794 | /* If this is a local watchpoint, we only want to check if the |
1795 | watchpoint frame is in scope if the current thread is the thread | |
1796 | that was used to create the watchpoint. */ | |
1797 | if (!watchpoint_in_thread_scope (b)) | |
1798 | return; | |
1799 | ||
c1fc2657 | 1800 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1801 | return; |
1802 | ||
66076460 | 1803 | frame_saved = 0; |
a5606eee VP |
1804 | |
1805 | /* Determine if the watchpoint is within scope. */ | |
1806 | if (b->exp_valid_block == NULL) | |
1807 | within_current_scope = 1; | |
1808 | else | |
1809 | { | |
b5db5dfc UW |
1810 | struct frame_info *fi = get_current_frame (); |
1811 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1812 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1813 | ||
c9cf6e20 MG |
1814 | /* If we're at a point where the stack has been destroyed |
1815 | (e.g. in a function epilogue), unwinding may not work | |
1816 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1817 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1818 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1819 | return; |
66076460 DJ |
1820 | |
1821 | /* Save the current frame's ID so we can restore it after | |
dda83cd7 | 1822 | evaluating the watchpoint expression on its own frame. */ |
66076460 | 1823 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
dda83cd7 SM |
1824 | took a frame parameter, so that we didn't have to change the |
1825 | selected frame. */ | |
66076460 DJ |
1826 | frame_saved = 1; |
1827 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1828 | ||
a5606eee VP |
1829 | fi = frame_find_by_id (b->watchpoint_frame); |
1830 | within_current_scope = (fi != NULL); | |
1831 | if (within_current_scope) | |
1832 | select_frame (fi); | |
1833 | } | |
1834 | ||
b5db5dfc UW |
1835 | /* We don't free locations. They are stored in the bp_location array |
1836 | and update_global_location_list will eventually delete them and | |
1837 | remove breakpoints if needed. */ | |
c1fc2657 | 1838 | b->loc = NULL; |
b5db5dfc | 1839 | |
a5606eee VP |
1840 | if (within_current_scope && reparse) |
1841 | { | |
bbc13ae3 | 1842 | const char *s; |
d63d0675 | 1843 | |
4d01a485 | 1844 | b->exp.reset (); |
a4c50be3 TT |
1845 | s = (b->exp_string_reparse |
1846 | ? b->exp_string_reparse.get () | |
1847 | : b->exp_string.get ()); | |
1bb9788d | 1848 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1849 | /* If the meaning of expression itself changed, the old value is |
1850 | no longer relevant. We don't want to report a watchpoint hit | |
1851 | to the user when the old value and the new value may actually | |
1852 | be completely different objects. */ | |
fa4727a6 | 1853 | b->val = NULL; |
4c1d86d9 | 1854 | b->val_valid = false; |
60e1c644 PA |
1855 | |
1856 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1857 | expression is stored in the breakpoint object, not in the | |
1858 | locations (re)created below. */ | |
c1fc2657 | 1859 | if (b->cond_string != NULL) |
60e1c644 | 1860 | { |
4d01a485 | 1861 | b->cond_exp.reset (); |
60e1c644 | 1862 | |
6f781ee3 | 1863 | s = b->cond_string.get (); |
1bb9788d | 1864 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1865 | } |
a5606eee | 1866 | } |
a5606eee VP |
1867 | |
1868 | /* If we failed to parse the expression, for example because | |
1869 | it refers to a global variable in a not-yet-loaded shared library, | |
1870 | don't try to insert watchpoint. We don't automatically delete | |
1871 | such watchpoint, though, since failure to parse expression | |
1872 | is different from out-of-scope watchpoint. */ | |
55f6301a | 1873 | if (!target_has_execution ()) |
2d134ed3 PA |
1874 | { |
1875 | /* Without execution, memory can't change. No use to try and | |
1876 | set watchpoint locations. The watchpoint will be reset when | |
1877 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1878 | if (!can_use_hw_watchpoints) |
1879 | { | |
c1fc2657 SM |
1880 | if (b->ops->works_in_software_mode (b)) |
1881 | b->type = bp_watchpoint; | |
e8369a73 | 1882 | else |
638aa5a1 AB |
1883 | error (_("Can't set read/access watchpoint when " |
1884 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1885 | } |
2d134ed3 PA |
1886 | } |
1887 | else if (within_current_scope && b->exp) | |
a5606eee | 1888 | { |
a6535de1 | 1889 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 1890 | struct value *v, *result; |
2d134ed3 | 1891 | struct program_space *frame_pspace; |
a5606eee | 1892 | |
1eaebe02 | 1893 | fetch_subexp_value (b->exp.get (), b->exp->op.get (), &v, &result, |
413403fc | 1894 | &val_chain, false); |
a5606eee | 1895 | |
a5606eee VP |
1896 | /* Avoid setting b->val if it's already set. The meaning of |
1897 | b->val is 'the last value' user saw, and we should update | |
1898 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1899 | happens, the code that reports it updates b->val directly. |
1900 | We don't keep track of the memory value for masked | |
1901 | watchpoints. */ | |
c1fc2657 | 1902 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1903 | { |
bb9d5f81 | 1904 | if (b->val_bitsize != 0) |
850645cf TT |
1905 | v = extract_bitfield_from_watchpoint_value (b, v); |
1906 | b->val = release_value (v); | |
4c1d86d9 | 1907 | b->val_valid = true; |
fa4727a6 | 1908 | } |
a5606eee | 1909 | |
2d134ed3 PA |
1910 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1911 | ||
a5606eee | 1912 | /* Look at each value on the value chain. */ |
a6535de1 TT |
1913 | gdb_assert (!val_chain.empty ()); |
1914 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 1915 | { |
a6535de1 TT |
1916 | v = iter.get (); |
1917 | ||
a5606eee VP |
1918 | /* If it's a memory location, and GDB actually needed |
1919 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1920 | must watch it. If the first value returned is |
1921 | still lazy, that means an error occurred reading it; | |
1922 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1923 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 1924 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
1925 | { |
1926 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1927 | |
a5606eee VP |
1928 | /* We only watch structs and arrays if user asked |
1929 | for it explicitly, never if they just happen to | |
1930 | appear in the middle of some value chain. */ | |
fa4727a6 | 1931 | if (v == result |
78134374 SM |
1932 | || (vtype->code () != TYPE_CODE_STRUCT |
1933 | && vtype->code () != TYPE_CODE_ARRAY)) | |
a5606eee VP |
1934 | { |
1935 | CORE_ADDR addr; | |
f486487f | 1936 | enum target_hw_bp_type type; |
a5606eee | 1937 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1938 | int bitpos = 0, bitsize = 0; |
1939 | ||
1940 | if (value_bitsize (v) != 0) | |
1941 | { | |
1942 | /* Extract the bit parameters out from the bitfield | |
1943 | sub-expression. */ | |
1944 | bitpos = value_bitpos (v); | |
1945 | bitsize = value_bitsize (v); | |
1946 | } | |
1947 | else if (v == result && b->val_bitsize != 0) | |
1948 | { | |
1949 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1950 | lvalue whose bit parameters are saved in the fields | |
1951 | VAL_BITPOS and VAL_BITSIZE. */ | |
1952 | bitpos = b->val_bitpos; | |
1953 | bitsize = b->val_bitsize; | |
1954 | } | |
a5606eee | 1955 | |
42ae5230 | 1956 | addr = value_address (v); |
bb9d5f81 PP |
1957 | if (bitsize != 0) |
1958 | { | |
1959 | /* Skip the bytes that don't contain the bitfield. */ | |
1960 | addr += bitpos / 8; | |
1961 | } | |
1962 | ||
a5606eee | 1963 | type = hw_write; |
c1fc2657 | 1964 | if (b->type == bp_read_watchpoint) |
a5606eee | 1965 | type = hw_read; |
c1fc2657 | 1966 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1967 | type = hw_access; |
3a5c3e22 | 1968 | |
c1fc2657 SM |
1969 | loc = allocate_bp_location (b); |
1970 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1971 | ; |
1972 | *tmp = loc; | |
8ee511af | 1973 | loc->gdbarch = value_type (v)->arch (); |
6c95b8df PA |
1974 | |
1975 | loc->pspace = frame_pspace; | |
f17d9474 | 1976 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
1977 | |
1978 | if (bitsize != 0) | |
1979 | { | |
1980 | /* Just cover the bytes that make up the bitfield. */ | |
1981 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1982 | } | |
1983 | else | |
1984 | loc->length = TYPE_LENGTH (value_type (v)); | |
1985 | ||
a5606eee VP |
1986 | loc->watchpoint_type = type; |
1987 | } | |
1988 | } | |
9fa40276 TJB |
1989 | } |
1990 | ||
1991 | /* Change the type of breakpoint between hardware assisted or | |
1992 | an ordinary watchpoint depending on the hardware support | |
1993 | and free hardware slots. REPARSE is set when the inferior | |
1994 | is started. */ | |
a9634178 | 1995 | if (reparse) |
9fa40276 | 1996 | { |
e09342b5 | 1997 | int reg_cnt; |
9fa40276 | 1998 | enum bp_loc_type loc_type; |
a5606eee | 1999 | |
a9634178 | 2000 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2001 | |
2002 | if (reg_cnt) | |
9fa40276 TJB |
2003 | { |
2004 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2005 | enum bptype type; |
9fa40276 | 2006 | |
a9634178 TJB |
2007 | /* Use an exact watchpoint when there's only one memory region to be |
2008 | watched, and only one debug register is needed to watch it. */ | |
2009 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2010 | ||
9fa40276 | 2011 | /* We need to determine how many resources are already |
e09342b5 TJB |
2012 | used for all other hardware watchpoints plus this one |
2013 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2014 | this watchpoint in as well. */ |
2015 | ||
2016 | /* If this is a software watchpoint, we try to turn it | |
2017 | to a hardware one -- count resources as if B was of | |
2018 | hardware watchpoint type. */ | |
c1fc2657 | 2019 | type = b->type; |
a1398e0c PA |
2020 | if (type == bp_watchpoint) |
2021 | type = bp_hardware_watchpoint; | |
2022 | ||
2023 | /* This watchpoint may or may not have been placed on | |
2024 | the list yet at this point (it won't be in the list | |
2025 | if we're trying to create it for the first time, | |
2026 | through watch_command), so always account for it | |
2027 | manually. */ | |
2028 | ||
2029 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 2030 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
2031 | |
2032 | /* Add in the resources needed for B. */ | |
c1fc2657 | 2033 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
2034 | |
2035 | target_resources_ok | |
2036 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2037 | if (target_resources_ok <= 0) |
a9634178 | 2038 | { |
c1fc2657 | 2039 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
2040 | |
2041 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2042 | error (_("Target does not support this type of " |
2043 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2044 | else if (target_resources_ok < 0 && !sw_mode) |
2045 | error (_("There are not enough available hardware " | |
2046 | "resources for this watchpoint.")); | |
a1398e0c PA |
2047 | |
2048 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 2049 | b->type = bp_watchpoint; |
a1398e0c PA |
2050 | } |
2051 | else | |
2052 | { | |
2053 | /* If this was a software watchpoint, we've just | |
2054 | found we have enough resources to turn it to a | |
2055 | hardware watchpoint. Otherwise, this is a | |
2056 | nop. */ | |
c1fc2657 | 2057 | b->type = type; |
a9634178 | 2058 | } |
9fa40276 | 2059 | } |
c1fc2657 | 2060 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
2061 | { |
2062 | if (!can_use_hw_watchpoints) | |
2063 | error (_("Can't set read/access watchpoint when " | |
2064 | "hardware watchpoints are disabled.")); | |
2065 | else | |
2066 | error (_("Expression cannot be implemented with " | |
2067 | "read/access watchpoint.")); | |
2068 | } | |
9fa40276 | 2069 | else |
c1fc2657 | 2070 | b->type = bp_watchpoint; |
9fa40276 | 2071 | |
c1fc2657 | 2072 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2073 | : bp_loc_hardware_watchpoint); |
40cb8ca5 | 2074 | for (bp_location *bl : b->locations ()) |
9fa40276 TJB |
2075 | bl->loc_type = loc_type; |
2076 | } | |
2077 | ||
c7437ca6 PA |
2078 | /* If a software watchpoint is not watching any memory, then the |
2079 | above left it without any location set up. But, | |
2080 | bpstat_stop_status requires a location to be able to report | |
2081 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2082 | if (b->type == bp_watchpoint && b->loc == NULL) |
2083 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2084 | } |
2085 | else if (!within_current_scope) | |
7270d8f2 | 2086 | { |
ac74f770 MS |
2087 | printf_filtered (_("\ |
2088 | Watchpoint %d deleted because the program has left the block\n\ | |
2089 | in which its expression is valid.\n"), | |
c1fc2657 | 2090 | b->number); |
d0fb5eae | 2091 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2092 | } |
a5606eee VP |
2093 | |
2094 | /* Restore the selected frame. */ | |
66076460 DJ |
2095 | if (frame_saved) |
2096 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2097 | } |
2098 | ||
a5606eee | 2099 | |
74960c60 | 2100 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2101 | inserted in the inferior. We don't differentiate the type of BL's owner |
2102 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2103 | breakpoint_ops is not defined, because in insert_bp_location, | |
2104 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2105 | static int |
35df4500 | 2106 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2107 | { |
35df4500 | 2108 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2109 | return 0; |
2110 | ||
35df4500 | 2111 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2112 | return 0; |
2113 | ||
b5fa468f TBA |
2114 | if (!bl->enabled || bl->disabled_by_cond |
2115 | || bl->shlib_disabled || bl->duplicate) | |
74960c60 VP |
2116 | return 0; |
2117 | ||
f8eba3c6 TT |
2118 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2119 | return 0; | |
2120 | ||
56710373 PA |
2121 | /* This is set for example, when we're attached to the parent of a |
2122 | vfork, and have detached from the child. The child is running | |
2123 | free, and we expect it to do an exec or exit, at which point the | |
2124 | OS makes the parent schedulable again (and the target reports | |
2125 | that the vfork is done). Until the child is done with the shared | |
2126 | memory region, do not insert breakpoints in the parent, otherwise | |
2127 | the child could still trip on the parent's breakpoints. Since | |
2128 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2129 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2130 | return 0; |
2131 | ||
31e77af2 | 2132 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2133 | location, except if the breakpoint is a single-step breakpoint, |
2134 | and the breakpoint's thread is the thread which is stepping past | |
2135 | a breakpoint. */ | |
31e77af2 PA |
2136 | if ((bl->loc_type == bp_loc_software_breakpoint |
2137 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2138 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2139 | bl->address) |
2140 | /* The single-step breakpoint may be inserted at the location | |
2141 | we're trying to step if the instruction branches to itself. | |
2142 | However, the instruction won't be executed at all and it may | |
2143 | break the semantics of the instruction, for example, the | |
2144 | instruction is a conditional branch or updates some flags. | |
2145 | We can't fix it unless GDB is able to emulate the instruction | |
2146 | or switch to displaced stepping. */ | |
2147 | && !(bl->owner->type == bp_single_step | |
2148 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 | 2149 | { |
1eb8556f SM |
2150 | infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s", |
2151 | paddress (bl->gdbarch, bl->address)); | |
e558d7c1 PA |
2152 | return 0; |
2153 | } | |
31e77af2 | 2154 | |
963f9c80 PA |
2155 | /* Don't insert watchpoints if we're trying to step past the |
2156 | instruction that triggered one. */ | |
2157 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2158 | && stepping_past_nonsteppable_watchpoint ()) | |
2159 | { | |
1eb8556f | 2160 | infrun_debug_printf ("stepping past non-steppable watchpoint. " |
ae1f4d2d | 2161 | "skipping watchpoint at %s:%d", |
1eb8556f | 2162 | paddress (bl->gdbarch, bl->address), bl->length); |
963f9c80 PA |
2163 | return 0; |
2164 | } | |
2165 | ||
74960c60 VP |
2166 | return 1; |
2167 | } | |
2168 | ||
934709f0 PW |
2169 | /* Same as should_be_inserted but does the check assuming |
2170 | that the location is not duplicated. */ | |
2171 | ||
2172 | static int | |
2173 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2174 | { | |
2175 | int result; | |
2176 | const int save_duplicate = bl->duplicate; | |
2177 | ||
2178 | bl->duplicate = 0; | |
2179 | result = should_be_inserted (bl); | |
2180 | bl->duplicate = save_duplicate; | |
2181 | return result; | |
2182 | } | |
2183 | ||
b775012e LM |
2184 | /* Parses a conditional described by an expression COND into an |
2185 | agent expression bytecode suitable for evaluation | |
2186 | by the bytecode interpreter. Return NULL if there was | |
2187 | any error during parsing. */ | |
2188 | ||
833177a4 | 2189 | static agent_expr_up |
b775012e LM |
2190 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2191 | { | |
833177a4 | 2192 | if (cond == NULL) |
b775012e LM |
2193 | return NULL; |
2194 | ||
833177a4 PA |
2195 | agent_expr_up aexpr; |
2196 | ||
b775012e LM |
2197 | /* We don't want to stop processing, so catch any errors |
2198 | that may show up. */ | |
a70b8144 | 2199 | try |
b775012e | 2200 | { |
036e657b | 2201 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2202 | } |
2203 | ||
230d2906 | 2204 | catch (const gdb_exception_error &ex) |
b775012e LM |
2205 | { |
2206 | /* If we got here, it means the condition could not be parsed to a valid | |
2207 | bytecode expression and thus can't be evaluated on the target's side. | |
2208 | It's no use iterating through the conditions. */ | |
b775012e LM |
2209 | } |
2210 | ||
2211 | /* We have a valid agent expression. */ | |
2212 | return aexpr; | |
2213 | } | |
2214 | ||
2215 | /* Based on location BL, create a list of breakpoint conditions to be | |
2216 | passed on to the target. If we have duplicated locations with different | |
2217 | conditions, we will add such conditions to the list. The idea is that the | |
2218 | target will evaluate the list of conditions and will only notify GDB when | |
2219 | one of them is true. */ | |
2220 | ||
2221 | static void | |
2222 | build_target_condition_list (struct bp_location *bl) | |
2223 | { | |
b775012e LM |
2224 | int null_condition_or_parse_error = 0; |
2225 | int modified = bl->needs_update; | |
b775012e | 2226 | |
8b4f3082 | 2227 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2228 | bl->target_info.conditions.clear (); |
8b4f3082 | 2229 | |
b775012e LM |
2230 | /* This is only meaningful if the target is |
2231 | evaluating conditions and if the user has | |
2232 | opted for condition evaluation on the target's | |
2233 | side. */ | |
2234 | if (gdb_evaluates_breakpoint_condition_p () | |
2235 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2236 | return; | |
2237 | ||
e0d9a270 SM |
2238 | auto loc_range = all_bp_locations_at_addr (bl->address); |
2239 | ||
b775012e | 2240 | /* Do a first pass to check for locations with no assigned |
7f32a4d5 PA |
2241 | conditions or conditions that fail to parse to a valid agent |
2242 | expression bytecode. If any of these happen, then it's no use to | |
2243 | send conditions to the target since this location will always | |
2244 | trigger and generate a response back to GDB. Note we consider | |
2245 | all locations at the same address irrespective of type, i.e., | |
2246 | even if the locations aren't considered duplicates (e.g., | |
2247 | software breakpoint and hardware breakpoint at the same | |
2248 | address). */ | |
e0d9a270 | 2249 | for (bp_location *loc : loc_range) |
b775012e | 2250 | { |
b775012e LM |
2251 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
2252 | { | |
2253 | if (modified) | |
2254 | { | |
b775012e LM |
2255 | /* Re-parse the conditions since something changed. In that |
2256 | case we already freed the condition bytecodes (see | |
2257 | force_breakpoint_reinsertion). We just | |
2258 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2259 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2260 | loc->cond.get ()); | |
b775012e LM |
2261 | } |
2262 | ||
2263 | /* If we have a NULL bytecode expression, it means something | |
2264 | went wrong or we have a null condition expression. */ | |
2265 | if (!loc->cond_bytecode) | |
2266 | { | |
2267 | null_condition_or_parse_error = 1; | |
2268 | break; | |
2269 | } | |
2270 | } | |
2271 | } | |
2272 | ||
2273 | /* If any of these happened, it means we will have to evaluate the conditions | |
2274 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2275 | for all the other duplicate locations, thus we free all of them here. | |
2276 | ||
2277 | This is so we have a finer control over which locations' conditions are | |
2278 | being evaluated by GDB or the remote stub. */ | |
2279 | if (null_condition_or_parse_error) | |
2280 | { | |
e0d9a270 | 2281 | for (bp_location *loc : loc_range) |
b775012e | 2282 | { |
b775012e LM |
2283 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
2284 | { | |
2285 | /* Only go as far as the first NULL bytecode is | |
2286 | located. */ | |
2287 | if (!loc->cond_bytecode) | |
2288 | return; | |
2289 | ||
833177a4 | 2290 | loc->cond_bytecode.reset (); |
b775012e LM |
2291 | } |
2292 | } | |
2293 | } | |
2294 | ||
7f32a4d5 PA |
2295 | /* No NULL conditions or failed bytecode generation. Build a |
2296 | condition list for this location's address. If we have software | |
2297 | and hardware locations at the same address, they aren't | |
2298 | considered duplicates, but we still marge all the conditions | |
2299 | anyway, as it's simpler, and doesn't really make a practical | |
2300 | difference. */ | |
e0d9a270 SM |
2301 | for (bp_location *loc : loc_range) |
2302 | if (loc->cond | |
2303 | && is_breakpoint (loc->owner) | |
2304 | && loc->pspace->num == bl->pspace->num | |
2305 | && loc->owner->enable_state == bp_enabled | |
2306 | && loc->enabled | |
2307 | && !loc->disabled_by_cond) | |
2308 | { | |
2309 | /* Add the condition to the vector. This will be used later | |
2310 | to send the conditions to the target. */ | |
2311 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2312 | } | |
b775012e LM |
2313 | |
2314 | return; | |
2315 | } | |
2316 | ||
d3ce09f5 SS |
2317 | /* Parses a command described by string CMD into an agent expression |
2318 | bytecode suitable for evaluation by the bytecode interpreter. | |
2319 | Return NULL if there was any error during parsing. */ | |
2320 | ||
833177a4 | 2321 | static agent_expr_up |
d3ce09f5 SS |
2322 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2323 | { | |
bbc13ae3 KS |
2324 | const char *cmdrest; |
2325 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2326 | struct gdbarch *gdbarch = get_current_arch (); |
2327 | ||
833177a4 | 2328 | if (cmd == NULL) |
d3ce09f5 SS |
2329 | return NULL; |
2330 | ||
2331 | cmdrest = cmd; | |
2332 | ||
2333 | if (*cmdrest == ',') | |
2334 | ++cmdrest; | |
f1735a53 | 2335 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2336 | |
2337 | if (*cmdrest++ != '"') | |
2338 | error (_("No format string following the location")); | |
2339 | ||
2340 | format_start = cmdrest; | |
2341 | ||
8e481c3b | 2342 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2343 | |
2344 | format_end = cmdrest; | |
2345 | ||
2346 | if (*cmdrest++ != '"') | |
2347 | error (_("Bad format string, non-terminated '\"'.")); | |
2348 | ||
f1735a53 | 2349 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2350 | |
2351 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2352 | error (_("Invalid argument syntax")); | |
2353 | ||
2354 | if (*cmdrest == ',') | |
2355 | cmdrest++; | |
f1735a53 | 2356 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2357 | |
2358 | /* For each argument, make an expression. */ | |
2359 | ||
8e481c3b | 2360 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2361 | while (*cmdrest != '\0') |
2362 | { | |
bbc13ae3 | 2363 | const char *cmd1; |
d3ce09f5 SS |
2364 | |
2365 | cmd1 = cmdrest; | |
4d01a485 | 2366 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2367 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2368 | cmdrest = cmd1; |
2369 | if (*cmdrest == ',') | |
2370 | ++cmdrest; | |
2371 | } | |
2372 | ||
833177a4 PA |
2373 | agent_expr_up aexpr; |
2374 | ||
d3ce09f5 SS |
2375 | /* We don't want to stop processing, so catch any errors |
2376 | that may show up. */ | |
a70b8144 | 2377 | try |
d3ce09f5 | 2378 | { |
036e657b JB |
2379 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2380 | format_start, format_end - format_start, | |
8e481c3b | 2381 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2382 | } |
230d2906 | 2383 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2384 | { |
2385 | /* If we got here, it means the command could not be parsed to a valid | |
2386 | bytecode expression and thus can't be evaluated on the target's side. | |
2387 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2388 | } |
492d29ea | 2389 | |
d3ce09f5 SS |
2390 | /* We have a valid agent expression, return it. */ |
2391 | return aexpr; | |
2392 | } | |
2393 | ||
2394 | /* Based on location BL, create a list of breakpoint commands to be | |
2395 | passed on to the target. If we have duplicated locations with | |
2396 | different commands, we will add any such to the list. */ | |
2397 | ||
2398 | static void | |
2399 | build_target_command_list (struct bp_location *bl) | |
2400 | { | |
d3ce09f5 SS |
2401 | int null_command_or_parse_error = 0; |
2402 | int modified = bl->needs_update; | |
d3ce09f5 | 2403 | |
3cde5c42 PA |
2404 | /* Clear commands left over from a previous insert. */ |
2405 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2406 | |
41fac0cf | 2407 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2408 | return; |
2409 | ||
41fac0cf PA |
2410 | /* For now, limit to agent-style dprintf breakpoints. */ |
2411 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2412 | return; |
2413 | ||
e0d9a270 SM |
2414 | auto loc_range = all_bp_locations_at_addr (bl->address); |
2415 | ||
7f32a4d5 PA |
2416 | /* For now, if we have any location at the same address that isn't a |
2417 | dprintf, don't install the target-side commands, as that would | |
2418 | make the breakpoint not be reported to the core, and we'd lose | |
41fac0cf | 2419 | control. */ |
e0d9a270 SM |
2420 | for (bp_location *loc : loc_range) |
2421 | if (is_breakpoint (loc->owner) | |
2422 | && loc->pspace->num == bl->pspace->num | |
2423 | && loc->owner->type != bp_dprintf) | |
2424 | return; | |
41fac0cf | 2425 | |
d3ce09f5 SS |
2426 | /* Do a first pass to check for locations with no assigned |
2427 | conditions or conditions that fail to parse to a valid agent expression | |
2428 | bytecode. If any of these happen, then it's no use to send conditions | |
2429 | to the target since this location will always trigger and generate a | |
2430 | response back to GDB. */ | |
e0d9a270 | 2431 | for (bp_location *loc : loc_range) |
d3ce09f5 | 2432 | { |
d3ce09f5 SS |
2433 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
2434 | { | |
2435 | if (modified) | |
2436 | { | |
d3ce09f5 SS |
2437 | /* Re-parse the commands since something changed. In that |
2438 | case we already freed the command bytecodes (see | |
2439 | force_breakpoint_reinsertion). We just | |
2440 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2441 | loc->cmd_bytecode |
2442 | = parse_cmd_to_aexpr (bl->address, | |
6f781ee3 | 2443 | loc->owner->extra_string.get ()); |
d3ce09f5 SS |
2444 | } |
2445 | ||
2446 | /* If we have a NULL bytecode expression, it means something | |
2447 | went wrong or we have a null command expression. */ | |
2448 | if (!loc->cmd_bytecode) | |
2449 | { | |
2450 | null_command_or_parse_error = 1; | |
2451 | break; | |
2452 | } | |
2453 | } | |
2454 | } | |
2455 | ||
2456 | /* If anything failed, then we're not doing target-side commands, | |
2457 | and so clean up. */ | |
2458 | if (null_command_or_parse_error) | |
2459 | { | |
e0d9a270 SM |
2460 | for (bp_location *loc : loc_range) |
2461 | if (is_breakpoint (loc->owner) | |
2462 | && loc->pspace->num == bl->pspace->num) | |
2463 | { | |
2464 | /* Only go as far as the first NULL bytecode is | |
2465 | located. */ | |
2466 | if (loc->cmd_bytecode == NULL) | |
2467 | return; | |
d3ce09f5 | 2468 | |
e0d9a270 SM |
2469 | loc->cmd_bytecode.reset (); |
2470 | } | |
d3ce09f5 SS |
2471 | } |
2472 | ||
7f32a4d5 PA |
2473 | /* No NULL commands or failed bytecode generation. Build a command |
2474 | list for all duplicate locations at this location's address. | |
2475 | Note that here we must care for whether the breakpoint location | |
2476 | types are considered duplicates, otherwise, say, if we have a | |
2477 | software and hardware location at the same address, the target | |
2478 | could end up running the commands twice. For the moment, we only | |
2479 | support targets-side commands with dprintf, but it doesn't hurt | |
2480 | to be pedantically correct in case that changes. */ | |
e0d9a270 SM |
2481 | for (bp_location *loc : loc_range) |
2482 | if (breakpoint_locations_match (bl, loc) | |
2483 | && loc->owner->extra_string | |
2484 | && is_breakpoint (loc->owner) | |
2485 | && loc->pspace->num == bl->pspace->num | |
2486 | && loc->owner->enable_state == bp_enabled | |
2487 | && loc->enabled | |
2488 | && !loc->disabled_by_cond) | |
2489 | { | |
2490 | /* Add the command to the vector. This will be used later | |
2491 | to send the commands to the target. */ | |
2492 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2493 | } | |
d3ce09f5 SS |
2494 | |
2495 | bl->target_info.persist = 0; | |
2496 | /* Maybe flag this location as persistent. */ | |
2497 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2498 | bl->target_info.persist = 1; | |
2499 | } | |
2500 | ||
833b7ab5 YQ |
2501 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2502 | of breakpoint according to ADDR except single-step breakpoint. | |
2503 | Get the kind of single-step breakpoint according to the current | |
2504 | registers state. */ | |
cd6c3b4f YQ |
2505 | |
2506 | static int | |
2507 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2508 | { | |
833b7ab5 YQ |
2509 | if (bl->owner->type == bp_single_step) |
2510 | { | |
2511 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2512 | struct regcache *regcache; | |
2513 | ||
00431a78 | 2514 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2515 | |
2516 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2517 | regcache, addr); | |
2518 | } | |
2519 | else | |
2520 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2521 | } |
2522 | ||
35df4500 TJB |
2523 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2524 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2525 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2526 | Returns 0 for success, 1 if the bp_location type is not supported or |
2527 | -1 for failure. | |
879bfdc2 | 2528 | |
4a64f543 MS |
2529 | NOTE drow/2003-09-09: This routine could be broken down to an |
2530 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2531 | static int |
35df4500 | 2532 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2533 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2534 | int *disabled_breaks, |
dd61ec5c MW |
2535 | int *hw_breakpoint_error, |
2536 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2537 | { |
cc06b668 | 2538 | gdb_exception bp_excpt; |
879bfdc2 | 2539 | |
b775012e | 2540 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2541 | return 0; |
2542 | ||
35c63cd8 JB |
2543 | /* Note we don't initialize bl->target_info, as that wipes out |
2544 | the breakpoint location's shadow_contents if the breakpoint | |
2545 | is still inserted at that location. This in turn breaks | |
2546 | target_read_memory which depends on these buffers when | |
2547 | a memory read is requested at the breakpoint location: | |
2548 | Once the target_info has been wiped, we fail to see that | |
2549 | we have a breakpoint inserted at that address and thus | |
2550 | read the breakpoint instead of returning the data saved in | |
2551 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2552 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2553 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2554 | bl->target_info.length = bl->length; |
8181d85f | 2555 | |
b775012e LM |
2556 | /* When working with target-side conditions, we must pass all the conditions |
2557 | for the same breakpoint address down to the target since GDB will not | |
2558 | insert those locations. With a list of breakpoint conditions, the target | |
2559 | can decide when to stop and notify GDB. */ | |
2560 | ||
2561 | if (is_breakpoint (bl->owner)) | |
2562 | { | |
2563 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2564 | build_target_command_list (bl); |
2565 | /* Reset the modification marker. */ | |
b775012e LM |
2566 | bl->needs_update = 0; |
2567 | } | |
2568 | ||
7f32a4d5 PA |
2569 | /* If "set breakpoint auto-hw" is "on" and a software breakpoint was |
2570 | set at a read-only address, then a breakpoint location will have | |
2571 | been changed to hardware breakpoint before we get here. If it is | |
2572 | "off" however, error out before actually trying to insert the | |
2573 | breakpoint, with a nicer error message. */ | |
35df4500 | 2574 | if (bl->loc_type == bp_loc_software_breakpoint |
7f32a4d5 | 2575 | && !automatic_hardware_breakpoints) |
879bfdc2 | 2576 | { |
7f32a4d5 | 2577 | mem_region *mr = lookup_mem_region (bl->address); |
cc59ec59 | 2578 | |
7f32a4d5 PA |
2579 | if (mr != nullptr && mr->attrib.mode != MEM_RW) |
2580 | { | |
2581 | fprintf_unfiltered (tmp_error_stream, | |
2582 | _("Cannot insert breakpoint %d.\n" | |
2583 | "Cannot set software breakpoint " | |
2584 | "at read-only address %s\n"), | |
2585 | bl->owner->number, | |
2586 | paddress (bl->gdbarch, bl->address)); | |
2587 | return 1; | |
765dc015 | 2588 | } |
7f32a4d5 PA |
2589 | } |
2590 | ||
2591 | if (bl->loc_type == bp_loc_software_breakpoint | |
2592 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2593 | { | |
879bfdc2 DJ |
2594 | /* First check to see if we have to handle an overlay. */ |
2595 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2596 | || bl->section == NULL |
2597 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2598 | { |
2599 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2600 | try |
dd61ec5c | 2601 | { |
0000e5cc PA |
2602 | int val; |
2603 | ||
dd61ec5c | 2604 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2605 | if (val) |
688fca4f | 2606 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2607 | } |
94aeb44b | 2608 | catch (gdb_exception &e) |
dd61ec5c | 2609 | { |
94aeb44b | 2610 | bp_excpt = std::move (e); |
dd61ec5c | 2611 | } |
879bfdc2 DJ |
2612 | } |
2613 | else | |
2614 | { | |
4a64f543 | 2615 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2616 | Shall we set a breakpoint at the LMA? */ |
2617 | if (!overlay_events_enabled) | |
2618 | { | |
2619 | /* Yes -- overlay event support is not active, | |
2620 | so we must try to set a breakpoint at the LMA. | |
2621 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2622 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2623 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2624 | bl->owner->number); |
879bfdc2 DJ |
2625 | else |
2626 | { | |
35df4500 TJB |
2627 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2628 | bl->section); | |
879bfdc2 | 2629 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2630 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2631 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2632 | |
2633 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2634 | try |
0000e5cc PA |
2635 | { |
2636 | int val; | |
2637 | ||
579c6ad9 | 2638 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2639 | = breakpoint_kind (bl, &addr); |
2640 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2641 | val = target_insert_breakpoint (bl->gdbarch, |
2642 | &bl->overlay_target_info); | |
2643 | if (val) | |
688fca4f PA |
2644 | bp_excpt |
2645 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2646 | } |
94aeb44b | 2647 | catch (gdb_exception &e) |
0000e5cc | 2648 | { |
94aeb44b | 2649 | bp_excpt = std::move (e); |
0000e5cc PA |
2650 | } |
2651 | ||
688fca4f | 2652 | if (bp_excpt.reason != 0) |
99361f52 | 2653 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2654 | "Overlay breakpoint %d " |
2655 | "failed: in ROM?\n", | |
35df4500 | 2656 | bl->owner->number); |
879bfdc2 DJ |
2657 | } |
2658 | } | |
2659 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2660 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2661 | { |
2662 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2663 | try |
dda83cd7 | 2664 | { |
0000e5cc PA |
2665 | int val; |
2666 | ||
dda83cd7 | 2667 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2668 | if (val) |
688fca4f | 2669 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dda83cd7 | 2670 | } |
94aeb44b | 2671 | catch (gdb_exception &e) |
dda83cd7 | 2672 | { |
94aeb44b | 2673 | bp_excpt = std::move (e); |
dda83cd7 | 2674 | } |
879bfdc2 DJ |
2675 | } |
2676 | else | |
2677 | { | |
2678 | /* No. This breakpoint will not be inserted. | |
2679 | No error, but do not mark the bp as 'inserted'. */ | |
2680 | return 0; | |
2681 | } | |
2682 | } | |
2683 | ||
688fca4f | 2684 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2685 | { |
2686 | /* Can't set the breakpoint. */ | |
0000e5cc | 2687 | |
80dc83fd AB |
2688 | /* If the target has closed then it will have deleted any |
2689 | breakpoints inserted within the target inferior, as a result | |
2690 | any further attempts to interact with the breakpoint objects | |
2691 | is not possible. Just rethrow the error. */ | |
2692 | if (bp_excpt.error == TARGET_CLOSE_ERROR) | |
2693 | throw bp_excpt; | |
2694 | gdb_assert (bl->owner != nullptr); | |
2695 | ||
0000e5cc PA |
2696 | /* In some cases, we might not be able to insert a |
2697 | breakpoint in a shared library that has already been | |
2698 | removed, but we have not yet processed the shlib unload | |
2699 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2700 | breakpoint insertion themselves can't tell why the |
2701 | breakpoint insertion failed (e.g., the remote target | |
2702 | doesn't define error codes), so we must treat generic | |
2703 | errors as memory errors. */ | |
688fca4f PA |
2704 | if (bp_excpt.reason == RETURN_ERROR |
2705 | && (bp_excpt.error == GENERIC_ERROR | |
2706 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2707 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2708 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2709 | || shared_objfile_contains_address_p (bl->pspace, |
2710 | bl->address))) | |
879bfdc2 | 2711 | { |
4a64f543 | 2712 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2713 | bl->shlib_disabled = 1; |
76727919 | 2714 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2715 | if (!*disabled_breaks) |
2716 | { | |
2717 | fprintf_unfiltered (tmp_error_stream, | |
2718 | "Cannot insert breakpoint %d.\n", | |
2719 | bl->owner->number); | |
2720 | fprintf_unfiltered (tmp_error_stream, | |
2721 | "Temporarily disabling shared " | |
2722 | "library breakpoints:\n"); | |
2723 | } | |
2724 | *disabled_breaks = 1; | |
879bfdc2 | 2725 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2726 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2727 | return 0; |
879bfdc2 DJ |
2728 | } |
2729 | else | |
879bfdc2 | 2730 | { |
35df4500 | 2731 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2732 | { |
0000e5cc | 2733 | *hw_breakpoint_error = 1; |
688fca4f | 2734 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dda83cd7 SM |
2735 | fprintf_unfiltered (tmp_error_stream, |
2736 | "Cannot insert hardware breakpoint %d%s", | |
2737 | bl->owner->number, | |
688fca4f | 2738 | bp_excpt.message ? ":" : ".\n"); |
dda83cd7 SM |
2739 | if (bp_excpt.message != NULL) |
2740 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
3d6e9d23 | 2741 | bp_excpt.what ()); |
879bfdc2 DJ |
2742 | } |
2743 | else | |
2744 | { | |
688fca4f | 2745 | if (bp_excpt.message == NULL) |
0000e5cc | 2746 | { |
1ccbe998 | 2747 | std::string message |
0000e5cc PA |
2748 | = memory_error_message (TARGET_XFER_E_IO, |
2749 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2750 | |
2751 | fprintf_unfiltered (tmp_error_stream, | |
2752 | "Cannot insert breakpoint %d.\n" | |
2753 | "%s\n", | |
1ccbe998 | 2754 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2755 | } |
2756 | else | |
2757 | { | |
2758 | fprintf_unfiltered (tmp_error_stream, | |
2759 | "Cannot insert breakpoint %d: %s\n", | |
2760 | bl->owner->number, | |
3d6e9d23 | 2761 | bp_excpt.what ()); |
0000e5cc | 2762 | } |
879bfdc2 | 2763 | } |
0000e5cc | 2764 | return 1; |
879bfdc2 DJ |
2765 | |
2766 | } | |
2767 | } | |
2768 | else | |
35df4500 | 2769 | bl->inserted = 1; |
879bfdc2 | 2770 | |
0000e5cc | 2771 | return 0; |
879bfdc2 DJ |
2772 | } |
2773 | ||
35df4500 | 2774 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2775 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2776 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2777 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2778 | { |
0000e5cc PA |
2779 | int val; |
2780 | ||
77b06cd7 TJB |
2781 | gdb_assert (bl->owner->ops != NULL |
2782 | && bl->owner->ops->insert_location != NULL); | |
2783 | ||
2784 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2785 | |
2786 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2787 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2788 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 | 2789 | { |
85d721b8 PA |
2790 | /* But don't try to insert it, if there's already another |
2791 | hw_access location that would be considered a duplicate | |
2792 | of this one. */ | |
48d7020b | 2793 | for (bp_location *loc : all_bp_locations ()) |
35df4500 | 2794 | if (loc != bl |
85d721b8 | 2795 | && loc->watchpoint_type == hw_access |
35df4500 | 2796 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2797 | { |
35df4500 TJB |
2798 | bl->duplicate = 1; |
2799 | bl->inserted = 1; | |
2800 | bl->target_info = loc->target_info; | |
2801 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2802 | val = 0; |
2803 | break; | |
2804 | } | |
2805 | ||
2806 | if (val == 1) | |
2807 | { | |
77b06cd7 TJB |
2808 | bl->watchpoint_type = hw_access; |
2809 | val = bl->owner->ops->insert_location (bl); | |
2810 | ||
2811 | if (val) | |
2812 | /* Back to the original value. */ | |
2813 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2814 | } |
2815 | } | |
2816 | ||
35df4500 | 2817 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2818 | } |
2819 | ||
35df4500 | 2820 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2821 | { |
0000e5cc PA |
2822 | int val; |
2823 | ||
77b06cd7 TJB |
2824 | gdb_assert (bl->owner->ops != NULL |
2825 | && bl->owner->ops->insert_location != NULL); | |
2826 | ||
2827 | val = bl->owner->ops->insert_location (bl); | |
2828 | if (val) | |
2829 | { | |
2830 | bl->owner->enable_state = bp_disabled; | |
2831 | ||
2832 | if (val == 1) | |
2833 | warning (_("\ | |
2834 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2835 | of catchpoint."), bl->owner->number); | |
2836 | else | |
2837 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2838 | } | |
2839 | ||
2840 | bl->inserted = (val == 0); | |
1640b821 DJ |
2841 | |
2842 | /* We've already printed an error message if there was a problem | |
2843 | inserting this catchpoint, and we've disabled the catchpoint, | |
2844 | so just return success. */ | |
2845 | return 0; | |
879bfdc2 DJ |
2846 | } |
2847 | ||
2848 | return 0; | |
2849 | } | |
2850 | ||
6c95b8df PA |
2851 | /* This function is called when program space PSPACE is about to be |
2852 | deleted. It takes care of updating breakpoints to not reference | |
2853 | PSPACE anymore. */ | |
2854 | ||
2855 | void | |
2856 | breakpoint_program_space_exit (struct program_space *pspace) | |
2857 | { | |
6c95b8df | 2858 | /* Remove any breakpoint that was set through this program space. */ |
1428b37a SM |
2859 | for (breakpoint *b : all_breakpoints_safe ()) |
2860 | if (b->pspace == pspace) | |
2861 | delete_breakpoint (b); | |
6c95b8df PA |
2862 | |
2863 | /* Breakpoints set through other program spaces could have locations | |
2864 | bound to PSPACE as well. Remove those. */ | |
48d7020b | 2865 | for (bp_location *loc : all_bp_locations ()) |
6c95b8df PA |
2866 | { |
2867 | struct bp_location *tmp; | |
2868 | ||
2869 | if (loc->pspace == pspace) | |
2870 | { | |
2bdf28a0 | 2871 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2872 | if (loc->owner->loc == loc) |
2873 | loc->owner->loc = loc->next; | |
2874 | else | |
2875 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2876 | if (tmp->next == loc) | |
2877 | { | |
2878 | tmp->next = loc->next; | |
2879 | break; | |
2880 | } | |
2881 | } | |
2882 | } | |
2883 | ||
2884 | /* Now update the global location list to permanently delete the | |
2885 | removed locations above. */ | |
44702360 | 2886 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2887 | } |
2888 | ||
74960c60 VP |
2889 | /* Make sure all breakpoints are inserted in inferior. |
2890 | Throws exception on any error. | |
2891 | A breakpoint that is already inserted won't be inserted | |
2892 | again, so calling this function twice is safe. */ | |
2893 | void | |
2894 | insert_breakpoints (void) | |
2895 | { | |
43892fdf | 2896 | for (breakpoint *bpt : all_breakpoints ()) |
74960c60 | 2897 | if (is_hardware_watchpoint (bpt)) |
3a5c3e22 PA |
2898 | { |
2899 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2900 | ||
2901 | update_watchpoint (w, 0 /* don't reparse. */); | |
2902 | } | |
74960c60 | 2903 | |
04086b45 PA |
2904 | /* Updating watchpoints creates new locations, so update the global |
2905 | location list. Explicitly tell ugll to insert locations and | |
7f32a4d5 PA |
2906 | ignore breakpoints_always_inserted_mode. Also, |
2907 | update_global_location_list tries to "upgrade" software | |
2908 | breakpoints to hardware breakpoints to handle "set breakpoint | |
2909 | auto-hw", so we need to call it even if we don't have new | |
2910 | locations. */ | |
04086b45 | 2911 | update_global_location_list (UGLL_INSERT); |
74960c60 VP |
2912 | } |
2913 | ||
b775012e LM |
2914 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2915 | target. It is the case with deleting and disabling of breakpoints when using | |
2916 | always-inserted mode. */ | |
2917 | ||
2918 | static void | |
2919 | update_inserted_breakpoint_locations (void) | |
2920 | { | |
b775012e LM |
2921 | int error_flag = 0; |
2922 | int val = 0; | |
2923 | int disabled_breaks = 0; | |
2924 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2925 | int hw_bp_details_reported = 0; |
b775012e | 2926 | |
d7e74731 | 2927 | string_file tmp_error_stream; |
b775012e LM |
2928 | |
2929 | /* Explicitly mark the warning -- this will only be printed if | |
2930 | there was an error. */ | |
d7e74731 | 2931 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2932 | |
5ed8105e | 2933 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e | 2934 | |
48d7020b | 2935 | for (bp_location *bl : all_bp_locations ()) |
b775012e LM |
2936 | { |
2937 | /* We only want to update software breakpoints and hardware | |
2938 | breakpoints. */ | |
2939 | if (!is_breakpoint (bl->owner)) | |
2940 | continue; | |
2941 | ||
2942 | /* We only want to update locations that are already inserted | |
2943 | and need updating. This is to avoid unwanted insertion during | |
2944 | deletion of breakpoints. */ | |
4daf1902 | 2945 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
2946 | continue; |
2947 | ||
2948 | switch_to_program_space_and_thread (bl->pspace); | |
2949 | ||
2950 | /* For targets that support global breakpoints, there's no need | |
2951 | to select an inferior to insert breakpoint to. In fact, even | |
2952 | if we aren't attached to any process yet, we should still | |
2953 | insert breakpoints. */ | |
f5656ead | 2954 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
55f6301a | 2955 | && (inferior_ptid == null_ptid || !target_has_execution ())) |
b775012e LM |
2956 | continue; |
2957 | ||
d7e74731 | 2958 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2959 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2960 | if (val) |
2961 | error_flag = val; | |
2962 | } | |
2963 | ||
2964 | if (error_flag) | |
2965 | { | |
223ffa71 | 2966 | target_terminal::ours_for_output (); |
b775012e LM |
2967 | error_stream (tmp_error_stream); |
2968 | } | |
b775012e LM |
2969 | } |
2970 | ||
c30eee59 | 2971 | /* Used when starting or continuing the program. */ |
c906108c | 2972 | |
74960c60 VP |
2973 | static void |
2974 | insert_breakpoint_locations (void) | |
c906108c | 2975 | { |
eacd795a | 2976 | int error_flag = 0; |
c906108c | 2977 | int val = 0; |
3fbb6ffa | 2978 | int disabled_breaks = 0; |
81d0cc19 | 2979 | int hw_breakpoint_error = 0; |
dd61ec5c | 2980 | int hw_bp_error_explained_already = 0; |
c906108c | 2981 | |
d7e74731 PA |
2982 | string_file tmp_error_stream; |
2983 | ||
81d0cc19 GS |
2984 | /* Explicitly mark the warning -- this will only be printed if |
2985 | there was an error. */ | |
d7e74731 | 2986 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 2987 | |
5ed8105e | 2988 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 2989 | |
48d7020b | 2990 | for (bp_location *bl : all_bp_locations ()) |
879bfdc2 | 2991 | { |
b775012e | 2992 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2993 | continue; |
2994 | ||
4a64f543 MS |
2995 | /* There is no point inserting thread-specific breakpoints if |
2996 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2997 | has BL->OWNER always non-NULL. */ | |
35df4500 | 2998 | if (bl->owner->thread != -1 |
5d5658a1 | 2999 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3000 | continue; |
3001 | ||
35df4500 | 3002 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3003 | |
3004 | /* For targets that support global breakpoints, there's no need | |
3005 | to select an inferior to insert breakpoint to. In fact, even | |
3006 | if we aren't attached to any process yet, we should still | |
3007 | insert breakpoints. */ | |
f5656ead | 3008 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
55f6301a | 3009 | && (inferior_ptid == null_ptid || !target_has_execution ())) |
6c95b8df PA |
3010 | continue; |
3011 | ||
d7e74731 | 3012 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3013 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3014 | if (val) |
eacd795a | 3015 | error_flag = val; |
879bfdc2 | 3016 | } |
c906108c | 3017 | |
4a64f543 MS |
3018 | /* If we failed to insert all locations of a watchpoint, remove |
3019 | them, as half-inserted watchpoint is of limited use. */ | |
43892fdf | 3020 | for (breakpoint *bpt : all_breakpoints ()) |
a5606eee VP |
3021 | { |
3022 | int some_failed = 0; | |
a5606eee VP |
3023 | |
3024 | if (!is_hardware_watchpoint (bpt)) | |
3025 | continue; | |
3026 | ||
d6b74ac4 | 3027 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3028 | continue; |
74960c60 VP |
3029 | |
3030 | if (bpt->disposition == disp_del_at_next_stop) | |
3031 | continue; | |
a5606eee | 3032 | |
40cb8ca5 | 3033 | for (bp_location *loc : bpt->locations ()) |
56710373 | 3034 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3035 | { |
3036 | some_failed = 1; | |
3037 | break; | |
3038 | } | |
40cb8ca5 | 3039 | |
a5606eee VP |
3040 | if (some_failed) |
3041 | { | |
40cb8ca5 | 3042 | for (bp_location *loc : bpt->locations ()) |
a5606eee | 3043 | if (loc->inserted) |
834c0d03 | 3044 | remove_breakpoint (loc); |
a5606eee VP |
3045 | |
3046 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3047 | tmp_error_stream.printf ("Could not insert " |
3048 | "hardware watchpoint %d.\n", | |
3049 | bpt->number); | |
eacd795a | 3050 | error_flag = -1; |
a5606eee VP |
3051 | } |
3052 | } | |
3053 | ||
eacd795a | 3054 | if (error_flag) |
81d0cc19 GS |
3055 | { |
3056 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
dda83cd7 | 3057 | message about possibly exhausted resources. */ |
dd61ec5c | 3058 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3059 | { |
d7e74731 | 3060 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3061 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3062 | } |
223ffa71 | 3063 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3064 | error_stream (tmp_error_stream); |
3065 | } | |
c906108c SS |
3066 | } |
3067 | ||
c30eee59 TJB |
3068 | /* Used when the program stops. |
3069 | Returns zero if successful, or non-zero if there was a problem | |
3070 | removing a breakpoint location. */ | |
3071 | ||
c906108c | 3072 | int |
fba45db2 | 3073 | remove_breakpoints (void) |
c906108c | 3074 | { |
3a1bae8e | 3075 | int val = 0; |
c906108c | 3076 | |
48d7020b | 3077 | for (bp_location *bl : all_bp_locations ()) |
1e4d1764 | 3078 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3079 | val |= remove_breakpoint (bl); |
01add95b | 3080 | |
3a1bae8e | 3081 | return val; |
c906108c SS |
3082 | } |
3083 | ||
49fa26b0 PA |
3084 | /* When a thread exits, remove breakpoints that are related to |
3085 | that thread. */ | |
3086 | ||
3087 | static void | |
3088 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3089 | { | |
1428b37a | 3090 | for (breakpoint *b : all_breakpoints_safe ()) |
49fa26b0 | 3091 | { |
5d5658a1 | 3092 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3093 | { |
3094 | b->disposition = disp_del_at_next_stop; | |
3095 | ||
3096 | printf_filtered (_("\ | |
43792cf0 PA |
3097 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3098 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3099 | |
3100 | /* Hide it from the user. */ | |
3101 | b->number = 0; | |
3102 | } | |
3103 | } | |
3104 | } | |
3105 | ||
f3869b1a | 3106 | /* See breakpoint.h. */ |
6c95b8df | 3107 | |
f3869b1a | 3108 | void |
00431a78 | 3109 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3110 | { |
6c95b8df | 3111 | int val; |
6c95b8df | 3112 | |
48d7020b | 3113 | for (bp_location *bl : all_bp_locations ()) |
01add95b SM |
3114 | { |
3115 | if (bl->pspace != inf->pspace) | |
3116 | continue; | |
6c95b8df | 3117 | |
01add95b SM |
3118 | if (bl->inserted && !bl->target_info.persist) |
3119 | { | |
3120 | val = remove_breakpoint (bl); | |
3121 | if (val != 0) | |
3122 | return; | |
3123 | } | |
3124 | } | |
6c95b8df PA |
3125 | } |
3126 | ||
e58b0e63 PA |
3127 | static int internal_breakpoint_number = -1; |
3128 | ||
84f4c1fe PM |
3129 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3130 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3131 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3132 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3133 | breakpoint_count and that value incremented. Internal breakpoints |
3134 | do not set the internal var bpnum. */ | |
3135 | static void | |
3136 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3137 | { | |
3138 | if (internal) | |
3139 | b->number = internal_breakpoint_number--; | |
3140 | else | |
3141 | { | |
3142 | set_breakpoint_count (breakpoint_count + 1); | |
3143 | b->number = breakpoint_count; | |
3144 | } | |
3145 | } | |
3146 | ||
e62c965a | 3147 | static struct breakpoint * |
a6d9a66e | 3148 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3149 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3150 | const struct breakpoint_ops *ops) |
e62c965a | 3151 | { |
51abb421 | 3152 | symtab_and_line sal; |
e62c965a PP |
3153 | sal.pc = address; |
3154 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3155 | sal.pspace = current_program_space; |
e62c965a | 3156 | |
51abb421 | 3157 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3158 | b->number = internal_breakpoint_number--; |
3159 | b->disposition = disp_donttouch; | |
3160 | ||
3161 | return b; | |
3162 | } | |
3163 | ||
17450429 PP |
3164 | static const char *const longjmp_names[] = |
3165 | { | |
3166 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3167 | }; | |
3168 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3169 | ||
3170 | /* Per-objfile data private to breakpoint.c. */ | |
3171 | struct breakpoint_objfile_data | |
3172 | { | |
3173 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3174 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3175 | |
3176 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3177 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3178 | |
28106bc2 | 3179 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3180 | int longjmp_searched = 0; |
28106bc2 | 3181 | |
45461e0d SM |
3182 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3183 | references. */ | |
3184 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3185 | |
17450429 | 3186 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3187 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3188 | |
3189 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3190 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3191 | |
3192 | /* True if we have looked for exception probes. */ | |
43dce439 | 3193 | int exception_searched = 0; |
28106bc2 | 3194 | |
45461e0d SM |
3195 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3196 | references. */ | |
3197 | std::vector<probe *> exception_probes; | |
17450429 PP |
3198 | }; |
3199 | ||
51d3063a TT |
3200 | static const struct objfile_key<breakpoint_objfile_data> |
3201 | breakpoint_objfile_key; | |
17450429 PP |
3202 | |
3203 | /* Minimal symbol not found sentinel. */ | |
3204 | static struct minimal_symbol msym_not_found; | |
3205 | ||
3206 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3207 | ||
3208 | static int | |
3209 | msym_not_found_p (const struct minimal_symbol *msym) | |
3210 | { | |
3211 | return msym == &msym_not_found; | |
3212 | } | |
3213 | ||
3214 | /* Return per-objfile data needed by breakpoint.c. | |
3215 | Allocate the data if necessary. */ | |
3216 | ||
3217 | static struct breakpoint_objfile_data * | |
3218 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3219 | { | |
3220 | struct breakpoint_objfile_data *bp_objfile_data; | |
3221 | ||
51d3063a | 3222 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3223 | if (bp_objfile_data == NULL) |
51d3063a | 3224 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3225 | return bp_objfile_data; |
3226 | } | |
3227 | ||
e62c965a | 3228 | static void |
af02033e | 3229 | create_overlay_event_breakpoint (void) |
e62c965a | 3230 | { |
af02033e | 3231 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3232 | |
2030c079 | 3233 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3234 | { |
3235 | struct breakpoint *b; | |
17450429 PP |
3236 | struct breakpoint_objfile_data *bp_objfile_data; |
3237 | CORE_ADDR addr; | |
67994074 | 3238 | struct explicit_location explicit_loc; |
69de3c6a | 3239 | |
17450429 PP |
3240 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3241 | ||
3b7344d5 | 3242 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3243 | continue; |
3244 | ||
3b7344d5 | 3245 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3246 | { |
3b7344d5 | 3247 | struct bound_minimal_symbol m; |
17450429 PP |
3248 | |
3249 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3250 | if (m.minsym == NULL) |
17450429 PP |
3251 | { |
3252 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3253 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3254 | continue; |
3255 | } | |
3256 | bp_objfile_data->overlay_msym = m; | |
3257 | } | |
e62c965a | 3258 | |
77e371c0 | 3259 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
08feed99 | 3260 | b = create_internal_breakpoint (objfile->arch (), addr, |
dda83cd7 | 3261 | bp_overlay_event, |
06edf0c0 | 3262 | &internal_breakpoint_ops); |
67994074 KS |
3263 | initialize_explicit_location (&explicit_loc); |
3264 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3265 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3266 | |
69de3c6a | 3267 | if (overlay_debugging == ovly_auto) |
dda83cd7 SM |
3268 | { |
3269 | b->enable_state = bp_enabled; | |
3270 | overlay_events_enabled = 1; | |
3271 | } | |
69de3c6a PP |
3272 | else |
3273 | { | |
dda83cd7 SM |
3274 | b->enable_state = bp_disabled; |
3275 | overlay_events_enabled = 0; | |
69de3c6a | 3276 | } |
e62c965a | 3277 | } |
e62c965a PP |
3278 | } |
3279 | ||
2a7f6487 TV |
3280 | /* Install a master longjmp breakpoint for OBJFILE using a probe. Return |
3281 | true if a breakpoint was installed. */ | |
3282 | ||
3283 | static bool | |
3284 | create_longjmp_master_breakpoint_probe (objfile *objfile) | |
0fd8e87f | 3285 | { |
2a7f6487 TV |
3286 | struct gdbarch *gdbarch = objfile->arch (); |
3287 | struct breakpoint_objfile_data *bp_objfile_data | |
3288 | = get_breakpoint_objfile_data (objfile); | |
0fd8e87f | 3289 | |
2a7f6487 | 3290 | if (!bp_objfile_data->longjmp_searched) |
94c93c35 | 3291 | { |
2a7f6487 TV |
3292 | std::vector<probe *> ret |
3293 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
af02033e | 3294 | |
2a7f6487 | 3295 | if (!ret.empty ()) |
94c93c35 | 3296 | { |
2a7f6487 TV |
3297 | /* We are only interested in checking one element. */ |
3298 | probe *p = ret[0]; | |
0fd8e87f | 3299 | |
2a7f6487 TV |
3300 | if (!p->can_evaluate_arguments ()) |
3301 | { | |
3302 | /* We cannot use the probe interface here, | |
3303 | because it does not know how to evaluate | |
3304 | arguments. */ | |
3305 | ret.clear (); | |
3306 | } | |
3307 | } | |
3308 | bp_objfile_data->longjmp_probes = ret; | |
3309 | bp_objfile_data->longjmp_searched = 1; | |
3310 | } | |
0fd8e87f | 3311 | |
2a7f6487 TV |
3312 | if (bp_objfile_data->longjmp_probes.empty ()) |
3313 | return false; | |
17450429 | 3314 | |
2a7f6487 TV |
3315 | for (probe *p : bp_objfile_data->longjmp_probes) |
3316 | { | |
3317 | struct breakpoint *b; | |
25f9533e | 3318 | |
2a7f6487 TV |
3319 | b = create_internal_breakpoint (gdbarch, |
3320 | p->get_relocated_address (objfile), | |
3321 | bp_longjmp_master, | |
3322 | &internal_breakpoint_ops); | |
3323 | b->location = new_probe_location ("-probe-stap libc:longjmp"); | |
3324 | b->enable_state = bp_disabled; | |
3325 | } | |
aed57c53 | 3326 | |
2a7f6487 TV |
3327 | return true; |
3328 | } | |
25f9533e | 3329 | |
2a7f6487 TV |
3330 | /* Install master longjmp breakpoints for OBJFILE using longjmp_names. |
3331 | Return true if at least one breakpoint was installed. */ | |
3332 | ||
3333 | static bool | |
3334 | create_longjmp_master_breakpoint_names (objfile *objfile) | |
3335 | { | |
3336 | struct gdbarch *gdbarch = objfile->arch (); | |
3337 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
3338 | return false; | |
3339 | ||
3340 | struct breakpoint_objfile_data *bp_objfile_data | |
3341 | = get_breakpoint_objfile_data (objfile); | |
3342 | unsigned int installed_bp = 0; | |
3343 | ||
3344 | for (int i = 0; i < NUM_LONGJMP_NAMES; i++) | |
3345 | { | |
3346 | struct breakpoint *b; | |
3347 | const char *func_name; | |
3348 | CORE_ADDR addr; | |
3349 | struct explicit_location explicit_loc; | |
3350 | ||
3351 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) | |
3352 | continue; | |
28106bc2 | 3353 | |
2a7f6487 TV |
3354 | func_name = longjmp_names[i]; |
3355 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3356 | { | |
3357 | struct bound_minimal_symbol m; | |
3358 | ||
3359 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3360 | if (m.minsym == NULL) | |
3361 | { | |
3362 | /* Prevent future lookups in this objfile. */ | |
3363 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
94c93c35 TT |
3364 | continue; |
3365 | } | |
2a7f6487 TV |
3366 | bp_objfile_data->longjmp_msym[i] = m; |
3367 | } | |
28106bc2 | 3368 | |
2a7f6487 TV |
3369 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
3370 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, | |
3371 | &internal_breakpoint_ops); | |
3372 | initialize_explicit_location (&explicit_loc); | |
3373 | explicit_loc.function_name = ASTRDUP (func_name); | |
3374 | b->location = new_explicit_location (&explicit_loc); | |
3375 | b->enable_state = bp_disabled; | |
3376 | installed_bp++; | |
3377 | } | |
28106bc2 | 3378 | |
2a7f6487 TV |
3379 | return installed_bp > 0; |
3380 | } | |
0fd8e87f | 3381 | |
2a7f6487 | 3382 | /* Create a master longjmp breakpoint. */ |
17450429 | 3383 | |
2a7f6487 TV |
3384 | static void |
3385 | create_longjmp_master_breakpoint (void) | |
3386 | { | |
3387 | scoped_restore_current_program_space restore_pspace; | |
aed57c53 | 3388 | |
2a7f6487 TV |
3389 | for (struct program_space *pspace : program_spaces) |
3390 | { | |
3391 | set_current_program_space (pspace); | |
17450429 | 3392 | |
2a7f6487 TV |
3393 | for (objfile *obj : current_program_space->objfiles ()) |
3394 | { | |
3395 | /* Skip separate debug object, it's handled in the loop below. */ | |
3396 | if (obj->separate_debug_objfile_backlink != nullptr) | |
3397 | continue; | |
3398 | ||
3399 | /* Try a probe kind breakpoint on main objfile. */ | |
3400 | if (create_longjmp_master_breakpoint_probe (obj)) | |
3401 | continue; | |
3402 | ||
3403 | /* Try longjmp_names kind breakpoints on main and separate_debug | |
3404 | objfiles. */ | |
3405 | for (objfile *debug_objfile : obj->separate_debug_objfiles ()) | |
3406 | if (create_longjmp_master_breakpoint_names (debug_objfile)) | |
3407 | break; | |
94c93c35 TT |
3408 | } |
3409 | } | |
0fd8e87f UW |
3410 | } |
3411 | ||
af02033e | 3412 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3413 | static void |
af02033e | 3414 | create_std_terminate_master_breakpoint (void) |
aa7d318d | 3415 | { |
af02033e | 3416 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3417 | |
5ed8105e | 3418 | scoped_restore_current_program_space restore_pspace; |
aa7d318d | 3419 | |
94c93c35 TT |
3420 | for (struct program_space *pspace : program_spaces) |
3421 | { | |
3422 | CORE_ADDR addr; | |
17450429 | 3423 | |
94c93c35 | 3424 | set_current_program_space (pspace); |
17450429 | 3425 | |
94c93c35 TT |
3426 | for (objfile *objfile : current_program_space->objfiles ()) |
3427 | { | |
3428 | struct breakpoint *b; | |
3429 | struct breakpoint_objfile_data *bp_objfile_data; | |
3430 | struct explicit_location explicit_loc; | |
aa7d318d | 3431 | |
94c93c35 | 3432 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3433 | |
94c93c35 TT |
3434 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3435 | continue; | |
17450429 | 3436 | |
94c93c35 TT |
3437 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3438 | { | |
3439 | struct bound_minimal_symbol m; | |
17450429 | 3440 | |
94c93c35 TT |
3441 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
3442 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text | |
3443 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
3444 | { | |
3445 | /* Prevent future lookups in this objfile. */ | |
3446 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3447 | continue; | |
3448 | } | |
3449 | bp_objfile_data->terminate_msym = m; | |
3450 | } | |
aa7d318d | 3451 | |
94c93c35 TT |
3452 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3453 | b = create_internal_breakpoint (objfile->arch (), addr, | |
3454 | bp_std_terminate_master, | |
3455 | &internal_breakpoint_ops); | |
3456 | initialize_explicit_location (&explicit_loc); | |
3457 | explicit_loc.function_name = ASTRDUP (func_name); | |
3458 | b->location = new_explicit_location (&explicit_loc); | |
3459 | b->enable_state = bp_disabled; | |
3460 | } | |
3461 | } | |
aa7d318d TT |
3462 | } |
3463 | ||
1940319c TV |
3464 | /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a |
3465 | probe. Return true if a breakpoint was installed. */ | |
186c406b | 3466 | |
1940319c TV |
3467 | static bool |
3468 | create_exception_master_breakpoint_probe (objfile *objfile) | |
186c406b | 3469 | { |
1940319c TV |
3470 | struct breakpoint *b; |
3471 | struct gdbarch *gdbarch; | |
3472 | struct breakpoint_objfile_data *bp_objfile_data; | |
186c406b | 3473 | |
1940319c | 3474 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3475 | |
1940319c TV |
3476 | /* We prefer the SystemTap probe point if it exists. */ |
3477 | if (!bp_objfile_data->exception_searched) | |
3478 | { | |
3479 | std::vector<probe *> ret | |
3480 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
17450429 | 3481 | |
1940319c | 3482 | if (!ret.empty ()) |
28106bc2 | 3483 | { |
1940319c TV |
3484 | /* We are only interested in checking one element. */ |
3485 | probe *p = ret[0]; | |
25f9533e | 3486 | |
1940319c | 3487 | if (!p->can_evaluate_arguments ()) |
25f9533e | 3488 | { |
1940319c TV |
3489 | /* We cannot use the probe interface here, because it does |
3490 | not know how to evaluate arguments. */ | |
3491 | ret.clear (); | |
25f9533e | 3492 | } |
28106bc2 | 3493 | } |
1940319c TV |
3494 | bp_objfile_data->exception_probes = ret; |
3495 | bp_objfile_data->exception_searched = 1; | |
3496 | } | |
28106bc2 | 3497 | |
1940319c TV |
3498 | if (bp_objfile_data->exception_probes.empty ()) |
3499 | return false; | |
45461e0d | 3500 | |
1940319c | 3501 | gdbarch = objfile->arch (); |
28106bc2 | 3502 | |
1940319c TV |
3503 | for (probe *p : bp_objfile_data->exception_probes) |
3504 | { | |
3505 | b = create_internal_breakpoint (gdbarch, | |
3506 | p->get_relocated_address (objfile), | |
3507 | bp_exception_master, | |
3508 | &internal_breakpoint_ops); | |
3509 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); | |
3510 | b->enable_state = bp_disabled; | |
3511 | } | |
28106bc2 | 3512 | |
1940319c TV |
3513 | return true; |
3514 | } | |
28106bc2 | 3515 | |
1940319c TV |
3516 | /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using |
3517 | _Unwind_DebugHook. Return true if a breakpoint was installed. */ | |
17450429 | 3518 | |
1940319c TV |
3519 | static bool |
3520 | create_exception_master_breakpoint_hook (objfile *objfile) | |
3521 | { | |
3522 | const char *const func_name = "_Unwind_DebugHook"; | |
3523 | struct breakpoint *b; | |
3524 | struct gdbarch *gdbarch; | |
3525 | struct breakpoint_objfile_data *bp_objfile_data; | |
3526 | CORE_ADDR addr; | |
3527 | struct explicit_location explicit_loc; | |
186c406b | 3528 | |
1940319c | 3529 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
186c406b | 3530 | |
1940319c TV |
3531 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
3532 | return false; | |
17450429 | 3533 | |
1940319c TV |
3534 | gdbarch = objfile->arch (); |
3535 | ||
3536 | if (bp_objfile_data->exception_msym.minsym == NULL) | |
3537 | { | |
3538 | struct bound_minimal_symbol debug_hook; | |
3539 | ||
3540 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); | |
3541 | if (debug_hook.minsym == NULL) | |
3542 | { | |
3543 | bp_objfile_data->exception_msym.minsym = &msym_not_found; | |
3544 | return false; | |
186c406b | 3545 | } |
17450429 | 3546 | |
1940319c TV |
3547 | bp_objfile_data->exception_msym = debug_hook; |
3548 | } | |
3549 | ||
3550 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
328d42d8 SM |
3551 | addr = gdbarch_convert_from_func_ptr_addr |
3552 | (gdbarch, addr, current_inferior ()->top_target ()); | |
1940319c TV |
3553 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3554 | &internal_breakpoint_ops); | |
3555 | initialize_explicit_location (&explicit_loc); | |
3556 | explicit_loc.function_name = ASTRDUP (func_name); | |
3557 | b->location = new_explicit_location (&explicit_loc); | |
3558 | b->enable_state = bp_disabled; | |
3559 | ||
3560 | return true; | |
3561 | } | |
3562 | ||
3563 | /* Install a master breakpoint on the unwinder's debug hook. */ | |
3564 | ||
3565 | static void | |
3566 | create_exception_master_breakpoint (void) | |
3567 | { | |
3568 | for (objfile *obj : current_program_space->objfiles ()) | |
3569 | { | |
3570 | /* Skip separate debug object. */ | |
3571 | if (obj->separate_debug_objfile_backlink) | |
3572 | continue; | |
3573 | ||
3574 | /* Try a probe kind breakpoint. */ | |
3575 | if (create_exception_master_breakpoint_probe (obj)) | |
3576 | continue; | |
3577 | ||
7c6944ab TV |
3578 | /* Iterate over main and separate debug objects and try an |
3579 | _Unwind_DebugHook kind breakpoint. */ | |
3580 | for (objfile *debug_objfile : obj->separate_debug_objfiles ()) | |
3581 | if (create_exception_master_breakpoint_hook (debug_objfile)) | |
1940319c | 3582 | break; |
186c406b | 3583 | } |
186c406b TT |
3584 | } |
3585 | ||
9ef9e6a6 KS |
3586 | /* Does B have a location spec? */ |
3587 | ||
3588 | static int | |
3589 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3590 | { | |
d28cd78a | 3591 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3592 | } |
3593 | ||
c906108c | 3594 | void |
fba45db2 | 3595 | update_breakpoints_after_exec (void) |
c906108c | 3596 | { |
25b22b0a PA |
3597 | /* We're about to delete breakpoints from GDB's lists. If the |
3598 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3599 | writing the breakpoints' "shadow contents" back into memory. The | |
3600 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3601 | do that. Instead, the target is responsible from marking | |
3602 | breakpoints out as soon as it detects an exec. We don't do that | |
3603 | here instead, because there may be other attempts to delete | |
3604 | breakpoints after detecting an exec and before reaching here. */ | |
48d7020b | 3605 | for (bp_location *bploc : all_bp_locations ()) |
6c95b8df PA |
3606 | if (bploc->pspace == current_program_space) |
3607 | gdb_assert (!bploc->inserted); | |
c906108c | 3608 | |
1428b37a | 3609 | for (breakpoint *b : all_breakpoints_safe ()) |
01add95b SM |
3610 | { |
3611 | if (b->pspace != current_program_space) | |
c5aa993b | 3612 | continue; |
c906108c | 3613 | |
01add95b SM |
3614 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
3615 | if (b->type == bp_shlib_event) | |
3616 | { | |
3617 | delete_breakpoint (b); | |
3618 | continue; | |
3619 | } | |
4efc6507 | 3620 | |
01add95b SM |
3621 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
3622 | if (b->type == bp_jit_event) | |
3623 | { | |
3624 | delete_breakpoint (b); | |
3625 | continue; | |
3626 | } | |
c4093a6a | 3627 | |
01add95b SM |
3628 | /* Thread event breakpoints must be set anew after an exec(), |
3629 | as must overlay event and longjmp master breakpoints. */ | |
3630 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
3631 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master | |
3632 | || b->type == bp_exception_master) | |
3633 | { | |
3634 | delete_breakpoint (b); | |
3635 | continue; | |
3636 | } | |
c5aa993b | 3637 | |
01add95b SM |
3638 | /* Step-resume breakpoints are meaningless after an exec(). */ |
3639 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) | |
3640 | { | |
3641 | delete_breakpoint (b); | |
3642 | continue; | |
3643 | } | |
7c16b83e | 3644 | |
01add95b SM |
3645 | /* Just like single-step breakpoints. */ |
3646 | if (b->type == bp_single_step) | |
3647 | { | |
3648 | delete_breakpoint (b); | |
3649 | continue; | |
3650 | } | |
611c83ae | 3651 | |
01add95b SM |
3652 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3653 | after an exec. */ | |
3654 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume | |
3655 | || b->type == bp_longjmp_call_dummy | |
3656 | || b->type == bp_exception || b->type == bp_exception_resume) | |
3657 | { | |
3658 | delete_breakpoint (b); | |
3659 | continue; | |
3660 | } | |
ce78b96d | 3661 | |
01add95b SM |
3662 | if (b->type == bp_catchpoint) |
3663 | { | |
3664 | /* For now, none of the bp_catchpoint breakpoints need to | |
3665 | do anything at this point. In the future, if some of | |
3666 | the catchpoints need to something, we will need to add | |
3667 | a new method, and call this method from here. */ | |
3668 | continue; | |
3669 | } | |
c5aa993b | 3670 | |
01add95b SM |
3671 | /* bp_finish is a special case. The only way we ought to be able |
3672 | to see one of these when an exec() has happened, is if the user | |
3673 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3674 | carries them to the call-site of the current callee, by setting | |
3675 | a temporary bp there and resuming. But in this case, the finish | |
3676 | will carry them entirely through the vfork & exec. | |
3677 | ||
3678 | We don't want to allow a bp_finish to remain inserted now. But | |
3679 | we can't safely delete it, 'cause finish_command has a handle to | |
3680 | the bp on a bpstat, and will later want to delete it. There's a | |
3681 | chance (and I've seen it happen) that if we delete the bp_finish | |
3682 | here, that its storage will get reused by the time finish_command | |
3683 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3684 | We really must allow finish_command to delete a bp_finish. | |
3685 | ||
3686 | In the absence of a general solution for the "how do we know | |
3687 | it's safe to delete something others may have handles to?" | |
3688 | problem, what we'll do here is just uninsert the bp_finish, and | |
3689 | let finish_command delete it. | |
3690 | ||
3691 | (We know the bp_finish is "doomed" in the sense that it's | |
3692 | momentary, and will be deleted as soon as finish_command sees | |
3693 | the inferior stopped. So it doesn't matter that the bp's | |
3694 | address is probably bogus in the new a.out, unlike e.g., the | |
3695 | solib breakpoints.) */ | |
3696 | ||
3697 | if (b->type == bp_finish) | |
3698 | { | |
3699 | continue; | |
3700 | } | |
3701 | ||
3702 | /* Without a symbolic address, we have little hope of the | |
3703 | pre-exec() address meaning the same thing in the post-exec() | |
3704 | a.out. */ | |
3705 | if (breakpoint_event_location_empty_p (b)) | |
3706 | { | |
3707 | delete_breakpoint (b); | |
3708 | continue; | |
3709 | } | |
3710 | } | |
c906108c SS |
3711 | } |
3712 | ||
3713 | int | |
d80ee84f | 3714 | detach_breakpoints (ptid_t ptid) |
c906108c | 3715 | { |
3a1bae8e | 3716 | int val = 0; |
2989a365 | 3717 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3718 | struct inferior *inf = current_inferior (); |
c5aa993b | 3719 | |
e99b03dc | 3720 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3721 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3722 | |
6c95b8df | 3723 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3724 | inferior_ptid = ptid; |
48d7020b | 3725 | for (bp_location *bl : all_bp_locations ()) |
01add95b SM |
3726 | { |
3727 | if (bl->pspace != inf->pspace) | |
3728 | continue; | |
3729 | ||
3730 | /* This function must physically remove breakpoints locations | |
3731 | from the specified ptid, without modifying the breakpoint | |
3732 | package's state. Locations of type bp_loc_other are only | |
3733 | maintained at GDB side. So, there is no need to remove | |
3734 | these bp_loc_other locations. Moreover, removing these | |
3735 | would modify the breakpoint package's state. */ | |
3736 | if (bl->loc_type == bp_loc_other) | |
3737 | continue; | |
3738 | ||
3739 | if (bl->inserted) | |
3740 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); | |
3741 | } | |
d03285ec | 3742 | |
3a1bae8e | 3743 | return val; |
c906108c SS |
3744 | } |
3745 | ||
35df4500 | 3746 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3747 | Note that this is used to detach breakpoints from a child fork. |
3748 | When we get here, the child isn't in the inferior list, and neither | |
3749 | do we have objects to represent its address space --- we should | |
35df4500 | 3750 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3751 | |
c906108c | 3752 | static int |
b2b6a7da | 3753 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3754 | { |
3755 | int val; | |
c5aa993b | 3756 | |
35df4500 TJB |
3757 | /* BL is never in moribund_locations by our callers. */ |
3758 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3759 | |
74960c60 VP |
3760 | /* The type of none suggests that owner is actually deleted. |
3761 | This should not ever happen. */ | |
35df4500 | 3762 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3763 | |
35df4500 TJB |
3764 | if (bl->loc_type == bp_loc_software_breakpoint |
3765 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3766 | { |
c02f5703 MS |
3767 | /* "Normal" instruction breakpoint: either the standard |
3768 | trap-instruction bp (bp_breakpoint), or a | |
3769 | bp_hardware_breakpoint. */ | |
3770 | ||
3771 | /* First check to see if we have to handle an overlay. */ | |
3772 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3773 | || bl->section == NULL |
3774 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3775 | { |
3776 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3777 | |
3778 | /* If we're trying to uninsert a memory breakpoint that we | |
3779 | know is set in a dynamic object that is marked | |
3780 | shlib_disabled, then either the dynamic object was | |
3781 | removed with "remove-symbol-file" or with | |
3782 | "nosharedlibrary". In the former case, we don't know | |
3783 | whether another dynamic object might have loaded over the | |
3784 | breakpoint's address -- the user might well let us know | |
3785 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3786 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3787 | list of dynamically loaded objects). If we have the |
3788 | breakpoint's shadow memory, that is, this is a software | |
3789 | breakpoint managed by GDB, check whether the breakpoint | |
3790 | is still inserted in memory, to avoid overwriting wrong | |
3791 | code with stale saved shadow contents. Note that HW | |
3792 | breakpoints don't have shadow memory, as they're | |
3793 | implemented using a mechanism that is not dependent on | |
3794 | being able to modify the target's memory, and as such | |
3795 | they should always be removed. */ | |
3796 | if (bl->shlib_disabled | |
3797 | && bl->target_info.shadow_len != 0 | |
3798 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3799 | val = 0; | |
3800 | else | |
73971819 | 3801 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3802 | } |
c906108c SS |
3803 | else |
3804 | { | |
4a64f543 | 3805 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3806 | Did we set a breakpoint at the LMA? */ |
3807 | if (!overlay_events_enabled) | |
3808 | { | |
3809 | /* Yes -- overlay event support is not active, so we | |
3810 | should have set a breakpoint at the LMA. Remove it. | |
3811 | */ | |
c02f5703 MS |
3812 | /* Ignore any failures: if the LMA is in ROM, we will |
3813 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3814 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3815 | target_remove_hw_breakpoint (bl->gdbarch, | |
3816 | &bl->overlay_target_info); | |
c02f5703 | 3817 | else |
35df4500 | 3818 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3819 | &bl->overlay_target_info, |
3820 | reason); | |
c02f5703 MS |
3821 | } |
3822 | /* Did we set a breakpoint at the VMA? | |
3823 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3824 | if (bl->inserted) |
c906108c | 3825 | { |
c02f5703 MS |
3826 | /* Yes -- remove it. Previously we did not bother to |
3827 | remove the breakpoint if the section had been | |
3828 | unmapped, but let's not rely on that being safe. We | |
3829 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3830 | |
3831 | /* However, we should remove *software* breakpoints only | |
3832 | if the section is still mapped, or else we overwrite | |
3833 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3834 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3835 | || section_is_mapped (bl->section)) | |
73971819 | 3836 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3837 | else |
3838 | val = 0; | |
c906108c | 3839 | } |
c02f5703 MS |
3840 | else |
3841 | { | |
3842 | /* No -- not inserted, so no need to remove. No error. */ | |
3843 | val = 0; | |
3844 | } | |
c906108c | 3845 | } |
879d1e6b | 3846 | |
08351840 PA |
3847 | /* In some cases, we might not be able to remove a breakpoint in |
3848 | a shared library that has already been removed, but we have | |
3849 | not yet processed the shlib unload event. Similarly for an | |
3850 | unloaded add-symbol-file object - the user might not yet have | |
3851 | had the chance to remove-symbol-file it. shlib_disabled will | |
3852 | be set if the library/object has already been removed, but | |
3853 | the breakpoint hasn't been uninserted yet, e.g., after | |
3854 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3855 | always-inserted mode. */ | |
076855f9 | 3856 | if (val |
08351840 PA |
3857 | && (bl->loc_type == bp_loc_software_breakpoint |
3858 | && (bl->shlib_disabled | |
3859 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3860 | || shared_objfile_contains_address_p (bl->pspace, |
3861 | bl->address)))) | |
879d1e6b UW |
3862 | val = 0; |
3863 | ||
c906108c SS |
3864 | if (val) |
3865 | return val; | |
b2b6a7da | 3866 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3867 | } |
35df4500 | 3868 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3869 | { |
77b06cd7 TJB |
3870 | gdb_assert (bl->owner->ops != NULL |
3871 | && bl->owner->ops->remove_location != NULL); | |
3872 | ||
b2b6a7da | 3873 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3874 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3875 | |
c906108c | 3876 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3877 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3878 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3879 | bl->owner->number); |
c906108c | 3880 | } |
35df4500 | 3881 | else if (bl->owner->type == bp_catchpoint |
dda83cd7 SM |
3882 | && breakpoint_enabled (bl->owner) |
3883 | && !bl->duplicate) | |
ce78b96d | 3884 | { |
77b06cd7 TJB |
3885 | gdb_assert (bl->owner->ops != NULL |
3886 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3887 | |
73971819 | 3888 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3889 | if (val) |
3890 | return val; | |
77b06cd7 | 3891 | |
b2b6a7da | 3892 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3893 | } |
c906108c SS |
3894 | |
3895 | return 0; | |
3896 | } | |
3897 | ||
6c95b8df | 3898 | static int |
834c0d03 | 3899 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3900 | { |
35df4500 TJB |
3901 | /* BL is never in moribund_locations by our callers. */ |
3902 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3903 | |
6c95b8df PA |
3904 | /* The type of none suggests that owner is actually deleted. |
3905 | This should not ever happen. */ | |
35df4500 | 3906 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3907 | |
5ed8105e | 3908 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3909 | |
35df4500 | 3910 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3911 | |
5ed8105e | 3912 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3913 | } |
3914 | ||
c906108c SS |
3915 | /* Clear the "inserted" flag in all breakpoints. */ |
3916 | ||
25b22b0a | 3917 | void |
fba45db2 | 3918 | mark_breakpoints_out (void) |
c906108c | 3919 | { |
48d7020b | 3920 | for (bp_location *bl : all_bp_locations ()) |
66c4b3e8 | 3921 | if (bl->pspace == current_program_space) |
35df4500 | 3922 | bl->inserted = 0; |
c906108c SS |
3923 | } |
3924 | ||
53a5351d JM |
3925 | /* Clear the "inserted" flag in all breakpoints and delete any |
3926 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3927 | |
3928 | Plus other such housekeeping that has to be done for breakpoints | |
3929 | between runs. | |
3930 | ||
53a5351d JM |
3931 | Note: this function gets called at the end of a run (by |
3932 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3933 | init_wait_for_inferior). */ |
c906108c SS |
3934 | |
3935 | ||
3936 | ||
3937 | void | |
fba45db2 | 3938 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3939 | { |
6c95b8df | 3940 | struct program_space *pspace = current_program_space; |
c906108c | 3941 | |
50c71eaf PA |
3942 | /* If breakpoint locations are shared across processes, then there's |
3943 | nothing to do. */ | |
f5656ead | 3944 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3945 | return; |
3946 | ||
1a853c52 | 3947 | mark_breakpoints_out (); |
075f6582 | 3948 | |
1428b37a | 3949 | for (breakpoint *b : all_breakpoints_safe ()) |
01add95b SM |
3950 | { |
3951 | if (b->loc && b->loc->pspace != pspace) | |
3952 | continue; | |
6c95b8df | 3953 | |
01add95b SM |
3954 | switch (b->type) |
3955 | { | |
3956 | case bp_call_dummy: | |
3957 | case bp_longjmp_call_dummy: | |
c906108c | 3958 | |
01add95b SM |
3959 | /* If the call dummy breakpoint is at the entry point it will |
3960 | cause problems when the inferior is rerun, so we better get | |
3961 | rid of it. */ | |
ab92d69b | 3962 | |
01add95b | 3963 | case bp_watchpoint_scope: |
ab92d69b | 3964 | |
01add95b | 3965 | /* Also get rid of scope breakpoints. */ |
ab92d69b | 3966 | |
01add95b | 3967 | case bp_shlib_event: |
ab92d69b | 3968 | |
01add95b SM |
3969 | /* Also remove solib event breakpoints. Their addresses may |
3970 | have changed since the last time we ran the program. | |
3971 | Actually we may now be debugging against different target; | |
3972 | and so the solib backend that installed this breakpoint may | |
3973 | not be used in by the target. E.g., | |
ab92d69b | 3974 | |
01add95b SM |
3975 | (gdb) file prog-linux |
3976 | (gdb) run # native linux target | |
3977 | ... | |
3978 | (gdb) kill | |
3979 | (gdb) file prog-win.exe | |
3980 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3981 | */ | |
c906108c | 3982 | |
01add95b | 3983 | case bp_step_resume: |
f59f708a | 3984 | |
01add95b | 3985 | /* Also remove step-resume breakpoints. */ |
f59f708a | 3986 | |
01add95b | 3987 | case bp_single_step: |
7c16b83e | 3988 | |
01add95b | 3989 | /* Also remove single-step breakpoints. */ |
7c16b83e | 3990 | |
01add95b SM |
3991 | delete_breakpoint (b); |
3992 | break; | |
c906108c | 3993 | |
01add95b SM |
3994 | case bp_watchpoint: |
3995 | case bp_hardware_watchpoint: | |
3996 | case bp_read_watchpoint: | |
3997 | case bp_access_watchpoint: | |
3998 | { | |
3999 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4000 | |
01add95b SM |
4001 | /* Likewise for watchpoints on local expressions. */ |
4002 | if (w->exp_valid_block != NULL) | |
4003 | delete_breakpoint (b); | |
4004 | else | |
4005 | { | |
4006 | /* Get rid of existing locations, which are no longer | |
4007 | valid. New ones will be created in | |
4008 | update_watchpoint, when the inferior is restarted. | |
4009 | The next update_global_location_list call will | |
4010 | garbage collect them. */ | |
4011 | b->loc = NULL; | |
4012 | ||
4013 | if (context == inf_starting) | |
4014 | { | |
4015 | /* Reset val field to force reread of starting value in | |
4016 | insert_breakpoints. */ | |
4017 | w->val.reset (nullptr); | |
4018 | w->val_valid = false; | |
4019 | } | |
4020 | } | |
4021 | } | |
4022 | break; | |
4023 | default: | |
4024 | break; | |
3a5c3e22 | 4025 | } |
01add95b | 4026 | } |
1c5cfe86 PA |
4027 | |
4028 | /* Get rid of the moribund locations. */ | |
1123588c | 4029 | for (bp_location *bl : moribund_locations) |
35df4500 | 4030 | decref_bp_location (&bl); |
1123588c | 4031 | moribund_locations.clear (); |
c906108c SS |
4032 | } |
4033 | ||
6c95b8df PA |
4034 | /* These functions concern about actual breakpoints inserted in the |
4035 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4036 | we need to hop over the bkpt --- so we check for address space | |
4037 | match, not program space. */ | |
4038 | ||
c2c6d25f JM |
4039 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4040 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4041 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4042 | permanent breakpoint. | |
4043 | - When continuing from a location with an ordinary breakpoint, we | |
4044 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4045 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4046 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4047 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4048 | |
c2c6d25f | 4049 | enum breakpoint_here |
accd0bcd | 4050 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4051 | { |
c2c6d25f | 4052 | int any_breakpoint_here = 0; |
c906108c | 4053 | |
48d7020b | 4054 | for (bp_location *bl : all_bp_locations ()) |
075f6582 | 4055 | { |
35df4500 TJB |
4056 | if (bl->loc_type != bp_loc_software_breakpoint |
4057 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4058 | continue; |
4059 | ||
f1310107 | 4060 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4061 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4062 | || bl->permanent) |
f1310107 | 4063 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4064 | { |
4065 | if (overlay_debugging | |
35df4500 TJB |
4066 | && section_is_overlay (bl->section) |
4067 | && !section_is_mapped (bl->section)) | |
075f6582 | 4068 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4069 | else if (bl->permanent) |
075f6582 DJ |
4070 | return permanent_breakpoint_here; |
4071 | else | |
4072 | any_breakpoint_here = 1; | |
4073 | } | |
4074 | } | |
c906108c | 4075 | |
f486487f | 4076 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4077 | } |
4078 | ||
d35ae833 PA |
4079 | /* See breakpoint.h. */ |
4080 | ||
4081 | int | |
accd0bcd | 4082 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
4083 | CORE_ADDR addr, ULONGEST len) |
4084 | { | |
48d7020b | 4085 | for (bp_location *bl : all_bp_locations ()) |
d35ae833 PA |
4086 | { |
4087 | if (bl->loc_type != bp_loc_software_breakpoint | |
4088 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4089 | continue; | |
4090 | ||
4091 | if ((breakpoint_enabled (bl->owner) | |
4092 | || bl->permanent) | |
4093 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4094 | addr, len)) | |
4095 | { | |
4096 | if (overlay_debugging | |
4097 | && section_is_overlay (bl->section) | |
4098 | && !section_is_mapped (bl->section)) | |
4099 | { | |
4100 | /* Unmapped overlay -- can't be a match. */ | |
4101 | continue; | |
4102 | } | |
4103 | ||
4104 | return 1; | |
4105 | } | |
4106 | } | |
4107 | ||
4108 | return 0; | |
4109 | } | |
4110 | ||
1c5cfe86 PA |
4111 | /* Return true if there's a moribund breakpoint at PC. */ |
4112 | ||
4113 | int | |
accd0bcd | 4114 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 4115 | { |
1123588c | 4116 | for (bp_location *loc : moribund_locations) |
f1310107 | 4117 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4118 | return 1; |
4119 | ||
4120 | return 0; | |
4121 | } | |
c2c6d25f | 4122 | |
f7ce857f PA |
4123 | /* Returns non-zero iff BL is inserted at PC, in address space |
4124 | ASPACE. */ | |
4125 | ||
4126 | static int | |
4127 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4128 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4129 | { |
4130 | if (bl->inserted | |
4131 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4132 | aspace, pc)) | |
4133 | { | |
4134 | if (overlay_debugging | |
4135 | && section_is_overlay (bl->section) | |
4136 | && !section_is_mapped (bl->section)) | |
4137 | return 0; /* unmapped overlay -- can't be a match */ | |
4138 | else | |
4139 | return 1; | |
4140 | } | |
4141 | return 0; | |
4142 | } | |
4143 | ||
a1fd2fa5 | 4144 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4145 | |
4146 | int | |
accd0bcd | 4147 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4148 | { |
e0d9a270 | 4149 | for (bp_location *bl : all_bp_locations_at_addr (pc)) |
c5aa993b | 4150 | { |
35df4500 TJB |
4151 | if (bl->loc_type != bp_loc_software_breakpoint |
4152 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4153 | continue; |
4154 | ||
f7ce857f PA |
4155 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4156 | return 1; | |
c5aa993b | 4157 | } |
c36b740a VP |
4158 | return 0; |
4159 | } | |
4160 | ||
a1fd2fa5 PA |
4161 | /* This function returns non-zero iff there is a software breakpoint |
4162 | inserted at PC. */ | |
c36b740a VP |
4163 | |
4164 | int | |
accd0bcd | 4165 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4166 | CORE_ADDR pc) |
4fa8626c | 4167 | { |
e0d9a270 | 4168 | for (bp_location *bl : all_bp_locations_at_addr (pc)) |
4fa8626c | 4169 | { |
35df4500 | 4170 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4171 | continue; |
4172 | ||
f7ce857f PA |
4173 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4174 | return 1; | |
4fa8626c DJ |
4175 | } |
4176 | ||
4177 | return 0; | |
9c02b525 PA |
4178 | } |
4179 | ||
4180 | /* See breakpoint.h. */ | |
4181 | ||
4182 | int | |
accd0bcd | 4183 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4184 | CORE_ADDR pc) |
4185 | { | |
e0d9a270 | 4186 | for (bp_location *bl : all_bp_locations_at_addr (pc)) |
9c02b525 | 4187 | { |
9c02b525 PA |
4188 | if (bl->loc_type != bp_loc_hardware_breakpoint) |
4189 | continue; | |
4190 | ||
4191 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4192 | return 1; | |
4193 | } | |
4194 | ||
4195 | return 0; | |
4fa8626c DJ |
4196 | } |
4197 | ||
9093389c | 4198 | int |
accd0bcd | 4199 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4200 | CORE_ADDR addr, ULONGEST len) |
4201 | { | |
43892fdf | 4202 | for (breakpoint *bpt : all_breakpoints ()) |
9093389c | 4203 | { |
9093389c PA |
4204 | if (bpt->type != bp_hardware_watchpoint |
4205 | && bpt->type != bp_access_watchpoint) | |
4206 | continue; | |
4207 | ||
4208 | if (!breakpoint_enabled (bpt)) | |
4209 | continue; | |
4210 | ||
40cb8ca5 | 4211 | for (bp_location *loc : bpt->locations ()) |
9093389c PA |
4212 | if (loc->pspace->aspace == aspace && loc->inserted) |
4213 | { | |
4214 | CORE_ADDR l, h; | |
4215 | ||
4216 | /* Check for intersection. */ | |
768adc05 PA |
4217 | l = std::max<CORE_ADDR> (loc->address, addr); |
4218 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4219 | if (l < h) |
4220 | return 1; | |
4221 | } | |
4222 | } | |
4223 | return 0; | |
4224 | } | |
c5aa993b | 4225 | |
f2478a7e | 4226 | /* See breakpoint.h. */ |
c906108c | 4227 | |
f2478a7e SM |
4228 | bool |
4229 | is_catchpoint (struct breakpoint *b) | |
c906108c | 4230 | { |
f2478a7e | 4231 | return (b->type == bp_catchpoint); |
c906108c SS |
4232 | } |
4233 | ||
c906108c SS |
4234 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4235 | Also free any storage that is part of a bpstat. */ | |
4236 | ||
4237 | void | |
313f3b21 | 4238 | bpstat_clear (bpstat **bsp) |
c906108c | 4239 | { |
313f3b21 SM |
4240 | bpstat *p; |
4241 | bpstat *q; | |
c906108c SS |
4242 | |
4243 | if (bsp == 0) | |
4244 | return; | |
4245 | p = *bsp; | |
4246 | while (p != NULL) | |
4247 | { | |
4248 | q = p->next; | |
04afa70c | 4249 | delete p; |
c906108c SS |
4250 | p = q; |
4251 | } | |
4252 | *bsp = NULL; | |
4253 | } | |
4254 | ||
313f3b21 | 4255 | bpstat::bpstat (const bpstat &other) |
04afa70c TT |
4256 | : next (NULL), |
4257 | bp_location_at (other.bp_location_at), | |
4258 | breakpoint_at (other.breakpoint_at), | |
4259 | commands (other.commands), | |
04afa70c TT |
4260 | print (other.print), |
4261 | stop (other.stop), | |
4262 | print_it (other.print_it) | |
4263 | { | |
850645cf TT |
4264 | if (other.old_val != NULL) |
4265 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c TT |
4266 | } |
4267 | ||
c906108c SS |
4268 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4269 | is part of the bpstat is copied as well. */ | |
4270 | ||
313f3b21 SM |
4271 | bpstat * |
4272 | bpstat_copy (bpstat *bs) | |
c906108c | 4273 | { |
313f3b21 SM |
4274 | bpstat *p = nullptr; |
4275 | bpstat *tmp; | |
4276 | bpstat *retval = nullptr; | |
c906108c SS |
4277 | |
4278 | if (bs == NULL) | |
4279 | return bs; | |
4280 | ||
4281 | for (; bs != NULL; bs = bs->next) | |
4282 | { | |
313f3b21 | 4283 | tmp = new bpstat (*bs); |
31cc81e9 | 4284 | |
c906108c SS |
4285 | if (p == NULL) |
4286 | /* This is the first thing in the chain. */ | |
4287 | retval = tmp; | |
4288 | else | |
4289 | p->next = tmp; | |
4290 | p = tmp; | |
4291 | } | |
4292 | p->next = NULL; | |
4293 | return retval; | |
4294 | } | |
4295 | ||
4a64f543 | 4296 | /* Find the bpstat associated with this breakpoint. */ |
c906108c | 4297 | |
313f3b21 SM |
4298 | bpstat * |
4299 | bpstat_find_breakpoint (bpstat *bsp, struct breakpoint *breakpoint) | |
c906108c | 4300 | { |
c5aa993b JM |
4301 | if (bsp == NULL) |
4302 | return NULL; | |
c906108c | 4303 | |
c5aa993b JM |
4304 | for (; bsp != NULL; bsp = bsp->next) |
4305 | { | |
f431efe5 | 4306 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4307 | return bsp; |
4308 | } | |
c906108c SS |
4309 | return NULL; |
4310 | } | |
4311 | ||
ab04a2af TT |
4312 | /* See breakpoint.h. */ |
4313 | ||
4c462cb0 | 4314 | bool |
313f3b21 | 4315 | bpstat_explains_signal (bpstat *bsp, enum gdb_signal sig) |
ab04a2af | 4316 | { |
ab04a2af TT |
4317 | for (; bsp != NULL; bsp = bsp->next) |
4318 | { | |
427cd150 TT |
4319 | if (bsp->breakpoint_at == NULL) |
4320 | { | |
4321 | /* A moribund location can never explain a signal other than | |
4322 | GDB_SIGNAL_TRAP. */ | |
4323 | if (sig == GDB_SIGNAL_TRAP) | |
4c462cb0 | 4324 | return true; |
427cd150 TT |
4325 | } |
4326 | else | |
47591c29 PA |
4327 | { |
4328 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4329 | sig)) | |
4c462cb0 | 4330 | return true; |
47591c29 | 4331 | } |
ab04a2af TT |
4332 | } |
4333 | ||
4c462cb0 | 4334 | return false; |
ab04a2af TT |
4335 | } |
4336 | ||
4a64f543 MS |
4337 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4338 | stopped at. *BSP upon return is a bpstat which points to the | |
4339 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4340 | good for anything but further calls to bpstat_num). | |
4341 | ||
8671a17b PA |
4342 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4343 | Return -1 if stopped at a breakpoint that has been deleted since | |
4344 | we set it. | |
4345 | Return 1 otherwise. */ | |
c906108c SS |
4346 | |
4347 | int | |
313f3b21 | 4348 | bpstat_num (bpstat **bsp, int *num) |
c906108c SS |
4349 | { |
4350 | struct breakpoint *b; | |
4351 | ||
4352 | if ((*bsp) == NULL) | |
4353 | return 0; /* No more breakpoint values */ | |
8671a17b | 4354 | |
4a64f543 MS |
4355 | /* We assume we'll never have several bpstats that correspond to a |
4356 | single breakpoint -- otherwise, this function might return the | |
4357 | same number more than once and this will look ugly. */ | |
f431efe5 | 4358 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4359 | *bsp = (*bsp)->next; |
4360 | if (b == NULL) | |
4361 | return -1; /* breakpoint that's been deleted since */ | |
4362 | ||
4363 | *num = b->number; /* We have its number */ | |
4364 | return 1; | |
c906108c SS |
4365 | } |
4366 | ||
e93ca019 | 4367 | /* See breakpoint.h. */ |
c906108c SS |
4368 | |
4369 | void | |
e93ca019 | 4370 | bpstat_clear_actions (void) |
c906108c | 4371 | { |
313f3b21 | 4372 | bpstat *bs; |
e93ca019 | 4373 | |
00431a78 | 4374 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4375 | return; |
4376 | ||
00431a78 | 4377 | thread_info *tp = inferior_thread (); |
e93ca019 | 4378 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4379 | { |
d1b0a7bf | 4380 | bs->commands = NULL; |
850645cf | 4381 | bs->old_val.reset (nullptr); |
c906108c SS |
4382 | } |
4383 | } | |
4384 | ||
f3b1572e PA |
4385 | /* Called when a command is about to proceed the inferior. */ |
4386 | ||
4387 | static void | |
4388 | breakpoint_about_to_proceed (void) | |
4389 | { | |
d7e15655 | 4390 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4391 | { |
4392 | struct thread_info *tp = inferior_thread (); | |
4393 | ||
4394 | /* Allow inferior function calls in breakpoint commands to not | |
4395 | interrupt the command list. When the call finishes | |
4396 | successfully, the inferior will be standing at the same | |
4397 | breakpoint as if nothing happened. */ | |
16c381f0 | 4398 | if (tp->control.in_infcall) |
f3b1572e PA |
4399 | return; |
4400 | } | |
4401 | ||
4402 | breakpoint_proceeded = 1; | |
4403 | } | |
4404 | ||
abf85f46 JK |
4405 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4406 | or its equivalent. */ | |
4407 | ||
4408 | static int | |
4409 | command_line_is_silent (struct command_line *cmd) | |
4410 | { | |
4f45d445 | 4411 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4412 | } |
4413 | ||
4a64f543 MS |
4414 | /* Execute all the commands associated with all the breakpoints at |
4415 | this location. Any of these commands could cause the process to | |
4416 | proceed beyond this point, etc. We look out for such changes by | |
4417 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4418 | |
347bddb7 PA |
4419 | Returns true if a breakpoint command resumed the inferior. In that |
4420 | case, it is the caller's responsibility to recall it again with the | |
4421 | bpstat of the current thread. */ | |
4422 | ||
4423 | static int | |
313f3b21 | 4424 | bpstat_do_actions_1 (bpstat **bsp) |
c906108c | 4425 | { |
313f3b21 | 4426 | bpstat *bs; |
347bddb7 | 4427 | int again = 0; |
c906108c SS |
4428 | |
4429 | /* Avoid endless recursion if a `source' command is contained | |
4430 | in bs->commands. */ | |
4431 | if (executing_breakpoint_commands) | |
347bddb7 | 4432 | return 0; |
c906108c | 4433 | |
81b1e71c TT |
4434 | scoped_restore save_executing |
4435 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4436 | |
1ac32117 | 4437 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4438 | |
4a64f543 | 4439 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4440 | bs = *bsp; |
4441 | ||
4442 | breakpoint_proceeded = 0; | |
4443 | for (; bs != NULL; bs = bs->next) | |
4444 | { | |
d1b0a7bf | 4445 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4446 | |
4447 | /* Take ownership of the BSP's command tree, if it has one. | |
4448 | ||
dda83cd7 SM |
4449 | The command tree could legitimately contain commands like |
4450 | 'step' and 'next', which call clear_proceed_status, which | |
4451 | frees stop_bpstat's command tree. To make sure this doesn't | |
4452 | free the tree we're executing out from under us, we need to | |
4453 | take ownership of the tree ourselves. Since a given bpstat's | |
4454 | commands are only executed once, we don't need to copy it; we | |
4455 | can clear the pointer in the bpstat, and make sure we free | |
4456 | the tree when we're done. */ | |
d1b0a7bf | 4457 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4458 | bs->commands = NULL; |
d1b0a7bf TT |
4459 | if (ccmd != NULL) |
4460 | cmd = ccmd.get (); | |
abf85f46 JK |
4461 | if (command_line_is_silent (cmd)) |
4462 | { | |
4463 | /* The action has been already done by bpstat_stop_status. */ | |
4464 | cmd = cmd->next; | |
4465 | } | |
6c50ab1c | 4466 | |
c906108c SS |
4467 | while (cmd != NULL) |
4468 | { | |
4469 | execute_control_command (cmd); | |
4470 | ||
4471 | if (breakpoint_proceeded) | |
4472 | break; | |
4473 | else | |
4474 | cmd = cmd->next; | |
4475 | } | |
6c50ab1c | 4476 | |
c906108c | 4477 | if (breakpoint_proceeded) |
32c1e744 | 4478 | { |
cb814510 | 4479 | if (current_ui->async) |
347bddb7 PA |
4480 | /* If we are in async mode, then the target might be still |
4481 | running, not stopped at any breakpoint, so nothing for | |
4482 | us to do here -- just return to the event loop. */ | |
4483 | ; | |
32c1e744 VP |
4484 | else |
4485 | /* In sync mode, when execute_control_command returns | |
4486 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4487 | Breakpoint commands for that stop were not run, since |
4488 | execute_command does not run breakpoint commands -- | |
4489 | only command_line_handler does, but that one is not | |
4490 | involved in execution of breakpoint commands. So, we | |
4491 | can now execute breakpoint commands. It should be | |
4492 | noted that making execute_command do bpstat actions is | |
4493 | not an option -- in this case we'll have recursive | |
4494 | invocation of bpstat for each breakpoint with a | |
4495 | command, and can easily blow up GDB stack. Instead, we | |
4496 | return true, which will trigger the caller to recall us | |
4497 | with the new stop_bpstat. */ | |
4498 | again = 1; | |
4499 | break; | |
32c1e744 | 4500 | } |
c906108c | 4501 | } |
347bddb7 PA |
4502 | return again; |
4503 | } | |
4504 | ||
00431a78 PA |
4505 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4506 | one, is alive and has execution. Return NULL otherwise. */ | |
4507 | ||
4508 | static thread_info * | |
4509 | get_bpstat_thread () | |
4510 | { | |
55f6301a | 4511 | if (inferior_ptid == null_ptid || !target_has_execution ()) |
00431a78 PA |
4512 | return NULL; |
4513 | ||
4514 | thread_info *tp = inferior_thread (); | |
611841bb | 4515 | if (tp->state == THREAD_EXITED || tp->executing ()) |
00431a78 PA |
4516 | return NULL; |
4517 | return tp; | |
4518 | } | |
4519 | ||
347bddb7 PA |
4520 | void |
4521 | bpstat_do_actions (void) | |
4522 | { | |
694c6bf5 | 4523 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4524 | thread_info *tp; |
353d1d73 | 4525 | |
347bddb7 | 4526 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4527 | while ((tp = get_bpstat_thread ()) != NULL) |
4528 | { | |
4529 | /* Since in sync mode, bpstat_do_actions may resume the | |
4530 | inferior, and only return when it is stopped at the next | |
4531 | breakpoint, we keep doing breakpoint actions until it returns | |
4532 | false to indicate the inferior was not resumed. */ | |
4533 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4534 | break; | |
4535 | } | |
353d1d73 | 4536 | |
694c6bf5 | 4537 | cleanup_if_error.release (); |
c906108c SS |
4538 | } |
4539 | ||
fa4727a6 DJ |
4540 | /* Print out the (old or new) value associated with a watchpoint. */ |
4541 | ||
4542 | static void | |
4543 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4544 | { | |
4545 | if (val == NULL) | |
7f6aba03 | 4546 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
fa4727a6 | 4547 | else |
79a45b7d TT |
4548 | { |
4549 | struct value_print_options opts; | |
4550 | get_user_print_options (&opts); | |
4551 | value_print (val, stream, &opts); | |
4552 | } | |
fa4727a6 DJ |
4553 | } |
4554 | ||
f303dbd6 PA |
4555 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4556 | debugging multiple threads. */ | |
4557 | ||
4558 | void | |
4559 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4560 | { | |
112e8700 | 4561 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4562 | return; |
4563 | ||
112e8700 | 4564 | uiout->text ("\n"); |
f303dbd6 PA |
4565 | |
4566 | if (show_thread_that_caused_stop ()) | |
4567 | { | |
f303dbd6 PA |
4568 | struct thread_info *thr = inferior_thread (); |
4569 | ||
112e8700 | 4570 | uiout->text ("Thread "); |
33eca680 | 4571 | uiout->field_string ("thread-id", print_thread_id (thr)); |
f303dbd6 | 4572 | |
25558938 | 4573 | const char *name = thread_name (thr); |
f303dbd6 PA |
4574 | if (name != NULL) |
4575 | { | |
112e8700 | 4576 | uiout->text (" \""); |
33eca680 | 4577 | uiout->field_string ("name", name); |
112e8700 | 4578 | uiout->text ("\""); |
f303dbd6 PA |
4579 | } |
4580 | ||
112e8700 | 4581 | uiout->text (" hit "); |
f303dbd6 PA |
4582 | } |
4583 | } | |
4584 | ||
e514a9d6 | 4585 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4586 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4587 | 'print_it' in the bpstat structure. Under some circumstances we |
4588 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4589 | normal_stop(). */ |
e514a9d6 JM |
4590 | |
4591 | static enum print_stop_action | |
313f3b21 | 4592 | print_bp_stop_message (bpstat *bs) |
e514a9d6 JM |
4593 | { |
4594 | switch (bs->print_it) | |
4595 | { | |
4596 | case print_it_noop: | |
4a64f543 | 4597 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4598 | return PRINT_UNKNOWN; |
4599 | break; | |
4600 | ||
4601 | case print_it_done: | |
4602 | /* We still want to print the frame, but we already printed the | |
dda83cd7 | 4603 | relevant messages. */ |
e514a9d6 JM |
4604 | return PRINT_SRC_AND_LOC; |
4605 | break; | |
4606 | ||
4607 | case print_it_normal: | |
4f8d1dc6 | 4608 | { |
f431efe5 PA |
4609 | struct breakpoint *b = bs->breakpoint_at; |
4610 | ||
1a6a67de TJB |
4611 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4612 | which has since been deleted. */ | |
4613 | if (b == NULL) | |
4614 | return PRINT_UNKNOWN; | |
4615 | ||
348d480f PA |
4616 | /* Normal case. Call the breakpoint's print_it method. */ |
4617 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4618 | } |
348d480f | 4619 | break; |
3086aeae | 4620 | |
e514a9d6 | 4621 | default: |
8e65ff28 | 4622 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4623 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4624 | break; |
c906108c | 4625 | } |
c906108c SS |
4626 | } |
4627 | ||
edcc5120 TT |
4628 | /* A helper function that prints a shared library stopped event. */ |
4629 | ||
4630 | static void | |
4631 | print_solib_event (int is_catchpoint) | |
4632 | { | |
6fb16ce6 | 4633 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4634 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4635 | |
4636 | if (!is_catchpoint) | |
4637 | { | |
4638 | if (any_added || any_deleted) | |
112e8700 | 4639 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4640 | else |
112e8700 SM |
4641 | current_uiout->text (_("Stopped due to shared library event (no " |
4642 | "libraries added or removed)\n")); | |
edcc5120 TT |
4643 | } |
4644 | ||
112e8700 SM |
4645 | if (current_uiout->is_mi_like_p ()) |
4646 | current_uiout->field_string ("reason", | |
4647 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4648 | |
4649 | if (any_deleted) | |
4650 | { | |
112e8700 | 4651 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4652 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4653 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4654 | { |
6fb16ce6 SM |
4655 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4656 | ||
edcc5120 | 4657 | if (ix > 0) |
112e8700 SM |
4658 | current_uiout->text (" "); |
4659 | current_uiout->field_string ("library", name); | |
4660 | current_uiout->text ("\n"); | |
edcc5120 | 4661 | } |
edcc5120 TT |
4662 | } |
4663 | ||
4664 | if (any_added) | |
4665 | { | |
112e8700 | 4666 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4667 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4668 | bool first = true; |
52941706 | 4669 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4670 | { |
bcb430e4 | 4671 | if (!first) |
112e8700 | 4672 | current_uiout->text (" "); |
bcb430e4 | 4673 | first = false; |
112e8700 SM |
4674 | current_uiout->field_string ("library", iter->so_name); |
4675 | current_uiout->text ("\n"); | |
edcc5120 | 4676 | } |
edcc5120 TT |
4677 | } |
4678 | } | |
4679 | ||
e514a9d6 JM |
4680 | /* Print a message indicating what happened. This is called from |
4681 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4682 | list - a list of the eventpoints that caused this stop. KIND is |
4683 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4684 | routine calls the generic print routine for printing a message |
4685 | about reasons for stopping. This will print (for example) the | |
4686 | "Breakpoint n," part of the output. The return value of this | |
4687 | routine is one of: | |
c906108c | 4688 | |
4a64f543 | 4689 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4690 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4691 | code to print the location. An example is |
c5aa993b JM |
4692 | "Breakpoint 1, " which should be followed by |
4693 | the location. | |
917317f4 | 4694 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4695 | to also print the location part of the message. |
4696 | An example is the catch/throw messages, which | |
4a64f543 | 4697 | don't require a location appended to the end. |
917317f4 | 4698 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4699 | further info to be printed. */ |
c906108c | 4700 | |
917317f4 | 4701 | enum print_stop_action |
313f3b21 | 4702 | bpstat_print (bpstat *bs, int kind) |
c906108c | 4703 | { |
f486487f | 4704 | enum print_stop_action val; |
c5aa993b | 4705 | |
c906108c | 4706 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4707 | (Currently all watchpoints go on the bpstat whether hit or not. |
4708 | That probably could (should) be changed, provided care is taken | |
c906108c | 4709 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4710 | for (; bs; bs = bs->next) |
4711 | { | |
4712 | val = print_bp_stop_message (bs); | |
4713 | if (val == PRINT_SRC_ONLY | |
4714 | || val == PRINT_SRC_AND_LOC | |
4715 | || val == PRINT_NOTHING) | |
4716 | return val; | |
4717 | } | |
c906108c | 4718 | |
36dfb11c TT |
4719 | /* If we had hit a shared library event breakpoint, |
4720 | print_bp_stop_message would print out this message. If we hit an | |
4721 | OS-level shared library event, do the same thing. */ | |
4722 | if (kind == TARGET_WAITKIND_LOADED) | |
4723 | { | |
edcc5120 | 4724 | print_solib_event (0); |
36dfb11c TT |
4725 | return PRINT_NOTHING; |
4726 | } | |
4727 | ||
e514a9d6 | 4728 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4729 | with and nothing was printed. */ |
917317f4 | 4730 | return PRINT_UNKNOWN; |
c906108c SS |
4731 | } |
4732 | ||
bf469271 | 4733 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4734 | |
bf469271 PA |
4735 | static bool |
4736 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4737 | { |
278cd55f | 4738 | struct value *mark = value_mark (); |
bf469271 | 4739 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4740 | |
c906108c | 4741 | value_free_to_mark (mark); |
bf469271 | 4742 | return res; |
c906108c SS |
4743 | } |
4744 | ||
5760d0ab | 4745 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4746 | |
313f3b21 | 4747 | bpstat::bpstat (struct bp_location *bl, bpstat ***bs_link_pointer) |
04afa70c | 4748 | : next (NULL), |
b6433ede | 4749 | bp_location_at (bp_location_ref_ptr::new_reference (bl)), |
04afa70c TT |
4750 | breakpoint_at (bl->owner), |
4751 | commands (NULL), | |
04afa70c TT |
4752 | print (0), |
4753 | stop (0), | |
4754 | print_it (print_it_normal) | |
c906108c | 4755 | { |
04afa70c TT |
4756 | **bs_link_pointer = this; |
4757 | *bs_link_pointer = &next; | |
4758 | } | |
4759 | ||
313f3b21 | 4760 | bpstat::bpstat () |
04afa70c | 4761 | : next (NULL), |
04afa70c TT |
4762 | breakpoint_at (NULL), |
4763 | commands (NULL), | |
04afa70c TT |
4764 | print (0), |
4765 | stop (0), | |
4766 | print_it (print_it_normal) | |
4767 | { | |
c906108c SS |
4768 | } |
4769 | \f | |
d983da9c DJ |
4770 | /* The target has stopped with waitstatus WS. Check if any hardware |
4771 | watchpoints have triggered, according to the target. */ | |
4772 | ||
4773 | int | |
c272a98c | 4774 | watchpoints_triggered (const target_waitstatus &ws) |
d983da9c | 4775 | { |
57810aa7 | 4776 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c | 4777 | CORE_ADDR addr; |
d983da9c DJ |
4778 | |
4779 | if (!stopped_by_watchpoint) | |
4780 | { | |
4781 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4782 | as not triggered. */ | |
43892fdf | 4783 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 4784 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4785 | { |
4786 | struct watchpoint *w = (struct watchpoint *) b; | |
4787 | ||
4788 | w->watchpoint_triggered = watch_triggered_no; | |
4789 | } | |
d983da9c DJ |
4790 | |
4791 | return 0; | |
4792 | } | |
4793 | ||
328d42d8 | 4794 | if (!target_stopped_data_address (current_inferior ()->top_target (), &addr)) |
d983da9c DJ |
4795 | { |
4796 | /* We were stopped by a watchpoint, but we don't know where. | |
4797 | Mark all watchpoints as unknown. */ | |
43892fdf | 4798 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 4799 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4800 | { |
4801 | struct watchpoint *w = (struct watchpoint *) b; | |
4802 | ||
4803 | w->watchpoint_triggered = watch_triggered_unknown; | |
4804 | } | |
d983da9c | 4805 | |
3c4797ba | 4806 | return 1; |
d983da9c DJ |
4807 | } |
4808 | ||
4809 | /* The target could report the data address. Mark watchpoints | |
4810 | affected by this data address as triggered, and all others as not | |
4811 | triggered. */ | |
4812 | ||
43892fdf | 4813 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 4814 | if (is_hardware_watchpoint (b)) |
d983da9c | 4815 | { |
3a5c3e22 | 4816 | struct watchpoint *w = (struct watchpoint *) b; |
d983da9c | 4817 | |
3a5c3e22 | 4818 | w->watchpoint_triggered = watch_triggered_no; |
40cb8ca5 | 4819 | for (bp_location *loc : b->locations ()) |
9c06b0b4 | 4820 | { |
3a5c3e22 | 4821 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4822 | { |
3a5c3e22 PA |
4823 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4824 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4825 | |
4826 | if (newaddr == start) | |
4827 | { | |
3a5c3e22 | 4828 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4829 | break; |
4830 | } | |
4831 | } | |
4832 | /* Exact match not required. Within range is sufficient. */ | |
328d42d8 SM |
4833 | else if (target_watchpoint_addr_within_range |
4834 | (current_inferior ()->top_target (), addr, loc->address, | |
4835 | loc->length)) | |
9c06b0b4 | 4836 | { |
3a5c3e22 | 4837 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4838 | break; |
4839 | } | |
4840 | } | |
d983da9c DJ |
4841 | } |
4842 | ||
4843 | return 1; | |
4844 | } | |
4845 | ||
bf469271 PA |
4846 | /* Possible return values for watchpoint_check. */ |
4847 | enum wp_check_result | |
4848 | { | |
4849 | /* The watchpoint has been deleted. */ | |
4850 | WP_DELETED = 1, | |
4851 | ||
4852 | /* The value has changed. */ | |
4853 | WP_VALUE_CHANGED = 2, | |
4854 | ||
4855 | /* The value has not changed. */ | |
4856 | WP_VALUE_NOT_CHANGED = 3, | |
4857 | ||
4858 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4859 | WP_IGNORE = 4, | |
4860 | }; | |
c906108c SS |
4861 | |
4862 | #define BP_TEMPFLAG 1 | |
4863 | #define BP_HARDWAREFLAG 2 | |
4864 | ||
4a64f543 | 4865 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4866 | changed. */ |
553e4c11 | 4867 | |
bf469271 | 4868 | static wp_check_result |
313f3b21 | 4869 | watchpoint_check (bpstat *bs) |
c906108c | 4870 | { |
3a5c3e22 | 4871 | struct watchpoint *b; |
c906108c SS |
4872 | struct frame_info *fr; |
4873 | int within_current_scope; | |
4874 | ||
f431efe5 | 4875 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4876 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4877 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4878 | |
f6bc2008 PA |
4879 | /* If this is a local watchpoint, we only want to check if the |
4880 | watchpoint frame is in scope if the current thread is the thread | |
4881 | that was used to create the watchpoint. */ | |
4882 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4883 | return WP_IGNORE; |
f6bc2008 | 4884 | |
c906108c SS |
4885 | if (b->exp_valid_block == NULL) |
4886 | within_current_scope = 1; | |
4887 | else | |
4888 | { | |
edb3359d DJ |
4889 | struct frame_info *frame = get_current_frame (); |
4890 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4891 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4892 | ||
c9cf6e20 | 4893 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4894 | still in the function but the stack frame has already been |
4895 | invalidated. Since we can't rely on the values of local | |
4896 | variables after the stack has been destroyed, we are treating | |
4897 | the watchpoint in that state as `not changed' without further | |
4898 | checking. Don't mark watchpoints as changed if the current | |
4899 | frame is in an epilogue - even if they are in some other | |
4900 | frame, our view of the stack is likely to be wrong and | |
4901 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4902 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4903 | return WP_IGNORE; |
a0f49112 | 4904 | |
101dcfbe | 4905 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4906 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4907 | |
4908 | /* If we've gotten confused in the unwinder, we might have | |
4909 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4910 | if (within_current_scope) |
4911 | { | |
4912 | struct symbol *function; | |
4913 | ||
4914 | function = get_frame_function (fr); | |
4915 | if (function == NULL | |
4916 | || !contained_in (b->exp_valid_block, | |
4917 | SYMBOL_BLOCK_VALUE (function))) | |
4918 | within_current_scope = 0; | |
4919 | } | |
69fbadd5 | 4920 | |
edb3359d | 4921 | if (within_current_scope) |
c906108c SS |
4922 | /* If we end up stopping, the current frame will get selected |
4923 | in normal_stop. So this call to select_frame won't affect | |
4924 | the user. */ | |
0f7d239c | 4925 | select_frame (fr); |
c906108c | 4926 | } |
c5aa993b | 4927 | |
c906108c SS |
4928 | if (within_current_scope) |
4929 | { | |
4a64f543 | 4930 | /* We use value_{,free_to_}mark because it could be a *long* |
dda83cd7 SM |
4931 | time before we return to the command level and call |
4932 | free_all_values. We can't call free_all_values because we | |
4933 | might be in the middle of evaluating a function call. */ | |
c906108c | 4934 | |
9c06b0b4 | 4935 | struct value *mark; |
fa4727a6 DJ |
4936 | struct value *new_val; |
4937 | ||
c1fc2657 | 4938 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
4939 | /* Since we don't know the exact trigger address (from |
4940 | stopped_data_address), just tell the user we've triggered | |
4941 | a mask watchpoint. */ | |
4942 | return WP_VALUE_CHANGED; | |
4943 | ||
4944 | mark = value_mark (); | |
1eaebe02 | 4945 | fetch_subexp_value (b->exp.get (), b->exp->op.get (), &new_val, |
413403fc | 4946 | NULL, NULL, false); |
218d2fc6 | 4947 | |
bb9d5f81 PP |
4948 | if (b->val_bitsize != 0) |
4949 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
4950 | ||
4a64f543 MS |
4951 | /* We use value_equal_contents instead of value_equal because |
4952 | the latter coerces an array to a pointer, thus comparing just | |
4953 | the address of the array instead of its contents. This is | |
4954 | not what we want. */ | |
fa4727a6 | 4955 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
4956 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
4957 | new_val))) | |
c906108c | 4958 | { |
c906108c | 4959 | bs->old_val = b->val; |
850645cf | 4960 | b->val = release_value (new_val); |
4c1d86d9 | 4961 | b->val_valid = true; |
850645cf TT |
4962 | if (new_val != NULL) |
4963 | value_free_to_mark (mark); | |
c906108c SS |
4964 | return WP_VALUE_CHANGED; |
4965 | } | |
4966 | else | |
4967 | { | |
60e1c644 | 4968 | /* Nothing changed. */ |
c906108c | 4969 | value_free_to_mark (mark); |
c906108c SS |
4970 | return WP_VALUE_NOT_CHANGED; |
4971 | } | |
4972 | } | |
4973 | else | |
4974 | { | |
4975 | /* This seems like the only logical thing to do because | |
dda83cd7 SM |
4976 | if we temporarily ignored the watchpoint, then when |
4977 | we reenter the block in which it is valid it contains | |
4978 | garbage (in the case of a function, it may have two | |
4979 | garbage values, one before and one after the prologue). | |
4980 | So we can't even detect the first assignment to it and | |
4981 | watch after that (since the garbage may or may not equal | |
4982 | the first value assigned). */ | |
348d480f PA |
4983 | /* We print all the stop information in |
4984 | breakpoint_ops->print_it, but in this case, by the time we | |
4985 | call breakpoint_ops->print_it this bp will be deleted | |
4986 | already. So we have no choice but print the information | |
4987 | here. */ | |
468afe6c | 4988 | |
0e454242 | 4989 | SWITCH_THRU_ALL_UIS () |
dda83cd7 | 4990 | { |
468afe6c PA |
4991 | struct ui_out *uiout = current_uiout; |
4992 | ||
112e8700 SM |
4993 | if (uiout->is_mi_like_p ()) |
4994 | uiout->field_string | |
4995 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
6a831f06 PA |
4996 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
4997 | "left the block in\n" | |
4998 | "which its expression is valid.\n", | |
4999 | signed_field ("wpnum", b->number)); | |
468afe6c | 5000 | } |
4ce44c66 | 5001 | |
cdac0397 | 5002 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 5003 | b->commands = NULL; |
d0fb5eae | 5004 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5005 | |
5006 | return WP_DELETED; | |
5007 | } | |
5008 | } | |
5009 | ||
18a18393 | 5010 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5011 | breakpoint location BL. This function does not check if we should |
5012 | stop, only if BL explains the stop. */ | |
5013 | ||
18a18393 | 5014 | static int |
6c95b8df | 5015 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 5016 | const address_space *aspace, CORE_ADDR bp_addr, |
c272a98c | 5017 | const target_waitstatus &ws) |
18a18393 VP |
5018 | { |
5019 | struct breakpoint *b = bl->owner; | |
5020 | ||
348d480f | 5021 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5022 | gdb_assert (b != NULL); |
5023 | ||
bd522513 | 5024 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5025 | } |
5026 | ||
3a5c3e22 PA |
5027 | /* Determine if the watched values have actually changed, and we |
5028 | should stop. If not, set BS->stop to 0. */ | |
5029 | ||
18a18393 | 5030 | static void |
313f3b21 | 5031 | bpstat_check_watchpoint (bpstat *bs) |
18a18393 | 5032 | { |
2bdf28a0 | 5033 | const struct bp_location *bl; |
3a5c3e22 | 5034 | struct watchpoint *b; |
2bdf28a0 JK |
5035 | |
5036 | /* BS is built for existing struct breakpoint. */ | |
b6433ede | 5037 | bl = bs->bp_location_at.get (); |
2bdf28a0 | 5038 | gdb_assert (bl != NULL); |
3a5c3e22 | 5039 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5040 | gdb_assert (b != NULL); |
18a18393 | 5041 | |
18a18393 | 5042 | { |
18a18393 VP |
5043 | int must_check_value = 0; |
5044 | ||
c1fc2657 | 5045 | if (b->type == bp_watchpoint) |
18a18393 VP |
5046 | /* For a software watchpoint, we must always check the |
5047 | watched value. */ | |
5048 | must_check_value = 1; | |
5049 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5050 | /* We have a hardware watchpoint (read, write, or access) | |
5051 | and the target earlier reported an address watched by | |
5052 | this watchpoint. */ | |
5053 | must_check_value = 1; | |
5054 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5055 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5056 | /* We were stopped by a hardware watchpoint, but the target could |
5057 | not report the data address. We must check the watchpoint's | |
5058 | value. Access and read watchpoints are out of luck; without | |
5059 | a data address, we can't figure it out. */ | |
5060 | must_check_value = 1; | |
3a5c3e22 | 5061 | |
18a18393 VP |
5062 | if (must_check_value) |
5063 | { | |
bf469271 PA |
5064 | wp_check_result e; |
5065 | ||
a70b8144 | 5066 | try |
bf469271 PA |
5067 | { |
5068 | e = watchpoint_check (bs); | |
5069 | } | |
230d2906 | 5070 | catch (const gdb_exception &ex) |
bf469271 PA |
5071 | { |
5072 | exception_fprintf (gdb_stderr, ex, | |
5073 | "Error evaluating expression " | |
5074 | "for watchpoint %d\n", | |
5075 | b->number); | |
5076 | ||
5077 | SWITCH_THRU_ALL_UIS () | |
5078 | { | |
5079 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5080 | b->number); | |
5081 | } | |
5082 | watchpoint_del_at_next_stop (b); | |
5083 | e = WP_DELETED; | |
5084 | } | |
bf469271 | 5085 | |
18a18393 VP |
5086 | switch (e) |
5087 | { | |
5088 | case WP_DELETED: | |
5089 | /* We've already printed what needs to be printed. */ | |
5090 | bs->print_it = print_it_done; | |
5091 | /* Stop. */ | |
5092 | break; | |
60e1c644 PA |
5093 | case WP_IGNORE: |
5094 | bs->print_it = print_it_noop; | |
5095 | bs->stop = 0; | |
5096 | break; | |
18a18393 | 5097 | case WP_VALUE_CHANGED: |
c1fc2657 | 5098 | if (b->type == bp_read_watchpoint) |
18a18393 | 5099 | { |
85d721b8 PA |
5100 | /* There are two cases to consider here: |
5101 | ||
4a64f543 | 5102 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5103 | In that case, trust the target, and always report |
5104 | the watchpoint hit to the user. Even though | |
5105 | reads don't cause value changes, the value may | |
5106 | have changed since the last time it was read, and | |
5107 | since we're not trapping writes, we will not see | |
5108 | those, and as such we should ignore our notion of | |
5109 | old value. | |
5110 | ||
4a64f543 | 5111 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5112 | reads and writes. There are two ways this may |
5113 | happen: | |
5114 | ||
4a64f543 | 5115 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5116 | reads only, but can break on accesses (reads or |
5117 | writes), such as e.g., x86. We detect this case | |
5118 | at the time we try to insert read watchpoints. | |
5119 | ||
4a64f543 | 5120 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5121 | watchpoints, but, the user set an access or write |
5122 | watchpoint watching the same memory as this read | |
5123 | watchpoint. | |
5124 | ||
5125 | If we're watching memory writes as well as reads, | |
5126 | ignore watchpoint hits when we find that the | |
5127 | value hasn't changed, as reads don't cause | |
5128 | changes. This still gives false positives when | |
5129 | the program writes the same value to memory as | |
5130 | what there was already in memory (we will confuse | |
5131 | it for a read), but it's much better than | |
5132 | nothing. */ | |
5133 | ||
5134 | int other_write_watchpoint = 0; | |
5135 | ||
5136 | if (bl->watchpoint_type == hw_read) | |
5137 | { | |
43892fdf | 5138 | for (breakpoint *other_b : all_breakpoints ()) |
3a5c3e22 PA |
5139 | if (other_b->type == bp_hardware_watchpoint |
5140 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5141 | { |
3a5c3e22 PA |
5142 | struct watchpoint *other_w = |
5143 | (struct watchpoint *) other_b; | |
5144 | ||
5145 | if (other_w->watchpoint_triggered | |
5146 | == watch_triggered_yes) | |
5147 | { | |
5148 | other_write_watchpoint = 1; | |
5149 | break; | |
5150 | } | |
85d721b8 PA |
5151 | } |
5152 | } | |
5153 | ||
5154 | if (other_write_watchpoint | |
5155 | || bl->watchpoint_type == hw_access) | |
5156 | { | |
5157 | /* We're watching the same memory for writes, | |
5158 | and the value changed since the last time we | |
5159 | updated it, so this trap must be for a write. | |
5160 | Ignore it. */ | |
5161 | bs->print_it = print_it_noop; | |
5162 | bs->stop = 0; | |
5163 | } | |
18a18393 VP |
5164 | } |
5165 | break; | |
5166 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5167 | if (b->type == bp_hardware_watchpoint |
5168 | || b->type == bp_watchpoint) | |
18a18393 VP |
5169 | { |
5170 | /* Don't stop: write watchpoints shouldn't fire if | |
5171 | the value hasn't changed. */ | |
5172 | bs->print_it = print_it_noop; | |
5173 | bs->stop = 0; | |
5174 | } | |
5175 | /* Stop. */ | |
5176 | break; | |
5177 | default: | |
5178 | /* Can't happen. */ | |
18a18393 VP |
5179 | break; |
5180 | } | |
5181 | } | |
5182 | else /* must_check_value == 0 */ | |
5183 | { | |
5184 | /* This is a case where some watchpoint(s) triggered, but | |
5185 | not at the address of this watchpoint, or else no | |
5186 | watchpoint triggered after all. So don't print | |
5187 | anything for this watchpoint. */ | |
5188 | bs->print_it = print_it_noop; | |
5189 | bs->stop = 0; | |
5190 | } | |
5191 | } | |
5192 | } | |
5193 | ||
7d4df6a4 DE |
5194 | /* For breakpoints that are currently marked as telling gdb to stop, |
5195 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5196 | of breakpoint referred to by BS. If we should not stop for this |
5197 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5198 | |
18a18393 | 5199 | static void |
313f3b21 | 5200 | bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) |
18a18393 | 5201 | { |
2bdf28a0 JK |
5202 | const struct bp_location *bl; |
5203 | struct breakpoint *b; | |
bf469271 PA |
5204 | /* Assume stop. */ |
5205 | bool condition_result = true; | |
7d4df6a4 DE |
5206 | struct expression *cond; |
5207 | ||
5208 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5209 | |
5210 | /* BS is built for existing struct breakpoint. */ | |
b6433ede | 5211 | bl = bs->bp_location_at.get (); |
2bdf28a0 | 5212 | gdb_assert (bl != NULL); |
f431efe5 | 5213 | b = bs->breakpoint_at; |
2bdf28a0 | 5214 | gdb_assert (b != NULL); |
18a18393 | 5215 | |
b775012e LM |
5216 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5217 | need to do so again since GDB does not know if we stopped due to a | |
5218 | breakpoint or a single step breakpoint. */ | |
5219 | ||
18a18393 | 5220 | if (frame_id_p (b->frame_id) |
edb3359d | 5221 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5222 | { |
7d4df6a4 DE |
5223 | bs->stop = 0; |
5224 | return; | |
5225 | } | |
60e1c644 | 5226 | |
12ab52e9 PA |
5227 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5228 | evaluating the condition if this isn't the specified | |
5229 | thread/task. */ | |
00431a78 PA |
5230 | if ((b->thread != -1 && b->thread != thread->global_num) |
5231 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5232 | { |
5233 | bs->stop = 0; | |
5234 | return; | |
5235 | } | |
5236 | ||
6dddc817 DE |
5237 | /* Evaluate extension language breakpoints that have a "stop" method |
5238 | implemented. */ | |
5239 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5240 | |
7d4df6a4 DE |
5241 | if (is_watchpoint (b)) |
5242 | { | |
5243 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5244 | |
4d01a485 | 5245 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5246 | } |
5247 | else | |
4d01a485 | 5248 | cond = bl->cond.get (); |
60e1c644 | 5249 | |
7d4df6a4 DE |
5250 | if (cond && b->disposition != disp_del_at_next_stop) |
5251 | { | |
5252 | int within_current_scope = 1; | |
5253 | struct watchpoint * w; | |
60e1c644 | 5254 | |
7d4df6a4 DE |
5255 | /* We use value_mark and value_free_to_mark because it could |
5256 | be a long time before we return to the command level and | |
5257 | call free_all_values. We can't call free_all_values | |
5258 | because we might be in the middle of evaluating a | |
5259 | function call. */ | |
5260 | struct value *mark = value_mark (); | |
5261 | ||
5262 | if (is_watchpoint (b)) | |
5263 | w = (struct watchpoint *) b; | |
5264 | else | |
5265 | w = NULL; | |
5266 | ||
5267 | /* Need to select the frame, with all that implies so that | |
5268 | the conditions will have the right context. Because we | |
5269 | use the frame, we will not see an inlined function's | |
5270 | variables when we arrive at a breakpoint at the start | |
5271 | of the inlined function; the current frame will be the | |
5272 | call site. */ | |
5273 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5274 | select_frame (get_current_frame ()); | |
5275 | else | |
18a18393 | 5276 | { |
7d4df6a4 DE |
5277 | struct frame_info *frame; |
5278 | ||
5279 | /* For local watchpoint expressions, which particular | |
5280 | instance of a local is being watched matters, so we | |
5281 | keep track of the frame to evaluate the expression | |
5282 | in. To evaluate the condition however, it doesn't | |
5283 | really matter which instantiation of the function | |
5284 | where the condition makes sense triggers the | |
5285 | watchpoint. This allows an expression like "watch | |
5286 | global if q > 10" set in `func', catch writes to | |
5287 | global on all threads that call `func', or catch | |
5288 | writes on all recursive calls of `func' by a single | |
5289 | thread. We simply always evaluate the condition in | |
5290 | the innermost frame that's executing where it makes | |
5291 | sense to evaluate the condition. It seems | |
5292 | intuitive. */ | |
5293 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5294 | if (frame != NULL) | |
5295 | select_frame (frame); | |
5296 | else | |
5297 | within_current_scope = 0; | |
18a18393 | 5298 | } |
7d4df6a4 | 5299 | if (within_current_scope) |
bf469271 | 5300 | { |
a70b8144 | 5301 | try |
bf469271 PA |
5302 | { |
5303 | condition_result = breakpoint_cond_eval (cond); | |
5304 | } | |
230d2906 | 5305 | catch (const gdb_exception &ex) |
bf469271 PA |
5306 | { |
5307 | exception_fprintf (gdb_stderr, ex, | |
5308 | "Error in testing breakpoint condition:\n"); | |
5309 | } | |
bf469271 | 5310 | } |
7d4df6a4 | 5311 | else |
18a18393 | 5312 | { |
7d4df6a4 DE |
5313 | warning (_("Watchpoint condition cannot be tested " |
5314 | "in the current scope")); | |
5315 | /* If we failed to set the right context for this | |
5316 | watchpoint, unconditionally report it. */ | |
18a18393 | 5317 | } |
7d4df6a4 DE |
5318 | /* FIXME-someday, should give breakpoint #. */ |
5319 | value_free_to_mark (mark); | |
18a18393 | 5320 | } |
7d4df6a4 | 5321 | |
bf469271 | 5322 | if (cond && !condition_result) |
7d4df6a4 DE |
5323 | { |
5324 | bs->stop = 0; | |
5325 | } | |
7d4df6a4 DE |
5326 | else if (b->ignore_count > 0) |
5327 | { | |
5328 | b->ignore_count--; | |
5329 | bs->stop = 0; | |
5330 | /* Increase the hit count even though we don't stop. */ | |
5331 | ++(b->hit_count); | |
76727919 | 5332 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5333 | } |
18a18393 VP |
5334 | } |
5335 | ||
1cf4d951 PA |
5336 | /* Returns true if we need to track moribund locations of LOC's type |
5337 | on the current target. */ | |
5338 | ||
5339 | static int | |
5340 | need_moribund_for_location_type (struct bp_location *loc) | |
5341 | { | |
5342 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5343 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5344 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5345 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5346 | } | |
5347 | ||
ddfe970e | 5348 | /* See breakpoint.h. */ |
c906108c | 5349 | |
313f3b21 | 5350 | bpstat * |
ddfe970e | 5351 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
c272a98c | 5352 | const target_waitstatus &ws) |
c906108c | 5353 | { |
313f3b21 | 5354 | bpstat *bs_head = nullptr, **bs_link = &bs_head; |
c5aa993b | 5355 | |
43892fdf | 5356 | for (breakpoint *b : all_breakpoints ()) |
429374b8 | 5357 | { |
1a853c52 | 5358 | if (!breakpoint_enabled (b)) |
429374b8 | 5359 | continue; |
a5606eee | 5360 | |
40cb8ca5 | 5361 | for (bp_location *bl : b->locations ()) |
429374b8 | 5362 | { |
4a64f543 MS |
5363 | /* For hardware watchpoints, we look only at the first |
5364 | location. The watchpoint_check function will work on the | |
5365 | entire expression, not the individual locations. For | |
5366 | read watchpoints, the watchpoints_triggered function has | |
5367 | checked all locations already. */ | |
429374b8 JK |
5368 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5369 | break; | |
18a18393 | 5370 | |
b5fa468f | 5371 | if (!bl->enabled || bl->disabled_by_cond || bl->shlib_disabled) |
429374b8 | 5372 | continue; |
c5aa993b | 5373 | |
09ac7c10 | 5374 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5375 | continue; |
c5aa993b | 5376 | |
4a64f543 MS |
5377 | /* Come here if it's a watchpoint, or if the break address |
5378 | matches. */ | |
c5aa993b | 5379 | |
313f3b21 | 5380 | bpstat *bs = new bpstat (bl, &bs_link); /* Alloc a bpstat to |
ddfe970e | 5381 | explain stop. */ |
c5aa993b | 5382 | |
f431efe5 PA |
5383 | /* Assume we stop. Should we find a watchpoint that is not |
5384 | actually triggered, or if the condition of the breakpoint | |
5385 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5386 | bs->stop = 1; |
5387 | bs->print = 1; | |
d983da9c | 5388 | |
f431efe5 PA |
5389 | /* If this is a scope breakpoint, mark the associated |
5390 | watchpoint as triggered so that we will handle the | |
5391 | out-of-scope event. We'll get to the watchpoint next | |
5392 | iteration. */ | |
d0fb5eae | 5393 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5394 | { |
5395 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5396 | ||
5397 | w->watchpoint_triggered = watch_triggered_yes; | |
5398 | } | |
f431efe5 PA |
5399 | } |
5400 | } | |
5401 | ||
7c16b83e | 5402 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5403 | if (!target_supports_stopped_by_sw_breakpoint () |
5404 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5405 | { |
1123588c | 5406 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5407 | { |
1cf4d951 PA |
5408 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5409 | && need_moribund_for_location_type (loc)) | |
5410 | { | |
313f3b21 | 5411 | bpstat *bs = new bpstat (loc, &bs_link); |
1cf4d951 PA |
5412 | /* For hits of moribund locations, we should just proceed. */ |
5413 | bs->stop = 0; | |
5414 | bs->print = 0; | |
5415 | bs->print_it = print_it_noop; | |
5416 | } | |
f431efe5 PA |
5417 | } |
5418 | } | |
5419 | ||
ddfe970e KS |
5420 | return bs_head; |
5421 | } | |
5422 | ||
5423 | /* See breakpoint.h. */ | |
5424 | ||
313f3b21 | 5425 | bpstat * |
ddfe970e | 5426 | bpstat_stop_status (const address_space *aspace, |
00431a78 | 5427 | CORE_ADDR bp_addr, thread_info *thread, |
c272a98c | 5428 | const target_waitstatus &ws, |
313f3b21 | 5429 | bpstat *stop_chain) |
ddfe970e KS |
5430 | { |
5431 | struct breakpoint *b = NULL; | |
5432 | /* First item of allocated bpstat's. */ | |
313f3b21 SM |
5433 | bpstat *bs_head = stop_chain; |
5434 | bpstat *bs; | |
ddfe970e KS |
5435 | int need_remove_insert; |
5436 | int removed_any; | |
5437 | ||
5438 | /* First, build the bpstat chain with locations that explain a | |
5439 | target stop, while being careful to not set the target running, | |
5440 | as that may invalidate locations (in particular watchpoint | |
5441 | locations are recreated). Resuming will happen here with | |
5442 | breakpoint conditions or watchpoint expressions that include | |
5443 | inferior function calls. */ | |
5444 | if (bs_head == NULL) | |
5445 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5446 | ||
edcc5120 TT |
5447 | /* A bit of special processing for shlib breakpoints. We need to |
5448 | process solib loading here, so that the lists of loaded and | |
5449 | unloaded libraries are correct before we handle "catch load" and | |
5450 | "catch unload". */ | |
5451 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5452 | { | |
5d268276 | 5453 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5454 | { |
5455 | handle_solib_event (); | |
5456 | break; | |
5457 | } | |
5458 | } | |
5459 | ||
f431efe5 PA |
5460 | /* Now go through the locations that caused the target to stop, and |
5461 | check whether we're interested in reporting this stop to higher | |
5462 | layers, or whether we should resume the target transparently. */ | |
5463 | ||
5464 | removed_any = 0; | |
5465 | ||
5760d0ab | 5466 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5467 | { |
5468 | if (!bs->stop) | |
5469 | continue; | |
5470 | ||
f431efe5 | 5471 | b = bs->breakpoint_at; |
348d480f PA |
5472 | b->ops->check_status (bs); |
5473 | if (bs->stop) | |
28010a5d | 5474 | { |
00431a78 | 5475 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5476 | |
429374b8 JK |
5477 | if (bs->stop) |
5478 | { | |
5479 | ++(b->hit_count); | |
c906108c | 5480 | |
4a64f543 | 5481 | /* We will stop here. */ |
429374b8 JK |
5482 | if (b->disposition == disp_disable) |
5483 | { | |
816338b5 | 5484 | --(b->enable_count); |
1a853c52 | 5485 | if (b->enable_count <= 0) |
429374b8 | 5486 | b->enable_state = bp_disabled; |
f431efe5 | 5487 | removed_any = 1; |
429374b8 | 5488 | } |
bd7ccaa9 | 5489 | gdb::observers::breakpoint_modified.notify (b); |
429374b8 JK |
5490 | if (b->silent) |
5491 | bs->print = 0; | |
5492 | bs->commands = b->commands; | |
abf85f46 | 5493 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5494 | ? bs->commands.get () : NULL)) |
abf85f46 | 5495 | bs->print = 0; |
9d6e6e84 HZ |
5496 | |
5497 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5498 | } |
5499 | ||
348d480f | 5500 | } |
a9b3a50f PA |
5501 | |
5502 | /* Print nothing for this entry if we don't stop or don't | |
5503 | print. */ | |
5504 | if (!bs->stop || !bs->print) | |
5505 | bs->print_it = print_it_noop; | |
429374b8 | 5506 | } |
876fa593 | 5507 | |
d983da9c DJ |
5508 | /* If we aren't stopping, the value of some hardware watchpoint may |
5509 | not have changed, but the intermediate memory locations we are | |
5510 | watching may have. Don't bother if we're stopping; this will get | |
5511 | done later. */ | |
d832cb68 | 5512 | need_remove_insert = 0; |
5760d0ab JK |
5513 | if (! bpstat_causes_stop (bs_head)) |
5514 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5515 | if (!bs->stop |
f431efe5 PA |
5516 | && bs->breakpoint_at |
5517 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5518 | { |
3a5c3e22 PA |
5519 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5520 | ||
5521 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5522 | need_remove_insert = 1; |
d983da9c DJ |
5523 | } |
5524 | ||
d832cb68 | 5525 | if (need_remove_insert) |
44702360 | 5526 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5527 | else if (removed_any) |
44702360 | 5528 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5529 | |
5760d0ab | 5530 | return bs_head; |
c906108c | 5531 | } |
628fe4e4 JK |
5532 | |
5533 | static void | |
61c26be8 | 5534 | handle_jit_event (CORE_ADDR address) |
628fe4e4 | 5535 | { |
628fe4e4 JK |
5536 | struct gdbarch *gdbarch; |
5537 | ||
1eb8556f | 5538 | infrun_debug_printf ("handling bp_jit_event"); |
243a9253 | 5539 | |
628fe4e4 JK |
5540 | /* Switch terminal for any messages produced by |
5541 | breakpoint_re_set. */ | |
223ffa71 | 5542 | target_terminal::ours_for_output (); |
628fe4e4 | 5543 | |
61c26be8 MS |
5544 | gdbarch = get_frame_arch (get_current_frame ()); |
5545 | /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`, | |
5546 | thus it is expected that its objectfile can be found through | |
5547 | minimal symbol lookup. If it doesn't work (and assert fails), it | |
5548 | most likely means that `jit_breakpoint_re_set` was changes and this | |
5549 | function needs to be updated too. */ | |
5550 | bound_minimal_symbol jit_bp_sym = lookup_minimal_symbol_by_pc (address); | |
5551 | gdb_assert (jit_bp_sym.objfile != nullptr); | |
5552 | jit_event_handler (gdbarch, jit_bp_sym.objfile); | |
628fe4e4 | 5553 | |
223ffa71 | 5554 | target_terminal::inferior (); |
628fe4e4 JK |
5555 | } |
5556 | ||
5557 | /* Prepare WHAT final decision for infrun. */ | |
5558 | ||
5559 | /* Decide what infrun needs to do with this bpstat. */ | |
5560 | ||
c906108c | 5561 | struct bpstat_what |
313f3b21 | 5562 | bpstat_what (bpstat *bs_head) |
c906108c | 5563 | { |
c906108c | 5564 | struct bpstat_what retval; |
313f3b21 | 5565 | bpstat *bs; |
c906108c | 5566 | |
628fe4e4 | 5567 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5568 | retval.call_dummy = STOP_NONE; |
e2d0f980 | 5569 | retval.is_longjmp = false; |
628fe4e4 | 5570 | |
0e30163f | 5571 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5572 | { |
628fe4e4 JK |
5573 | /* Extract this BS's action. After processing each BS, we check |
5574 | if its action overrides all we've seem so far. */ | |
5575 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5576 | enum bptype bptype; | |
5577 | ||
c906108c | 5578 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5579 | { |
5580 | /* I suspect this can happen if it was a momentary | |
5581 | breakpoint which has since been deleted. */ | |
5582 | bptype = bp_none; | |
5583 | } | |
20874c92 | 5584 | else |
f431efe5 | 5585 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5586 | |
5587 | switch (bptype) | |
c906108c SS |
5588 | { |
5589 | case bp_none: | |
628fe4e4 | 5590 | break; |
c906108c SS |
5591 | case bp_breakpoint: |
5592 | case bp_hardware_breakpoint: | |
7c16b83e | 5593 | case bp_single_step: |
c906108c SS |
5594 | case bp_until: |
5595 | case bp_finish: | |
a9b3a50f | 5596 | case bp_shlib_event: |
c906108c SS |
5597 | if (bs->stop) |
5598 | { | |
5599 | if (bs->print) | |
628fe4e4 | 5600 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5601 | else |
628fe4e4 | 5602 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5603 | } |
5604 | else | |
628fe4e4 | 5605 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5606 | break; |
5607 | case bp_watchpoint: | |
5608 | case bp_hardware_watchpoint: | |
5609 | case bp_read_watchpoint: | |
5610 | case bp_access_watchpoint: | |
5611 | if (bs->stop) | |
5612 | { | |
5613 | if (bs->print) | |
628fe4e4 | 5614 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5615 | else |
628fe4e4 | 5616 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5617 | } |
5618 | else | |
628fe4e4 JK |
5619 | { |
5620 | /* There was a watchpoint, but we're not stopping. | |
5621 | This requires no further action. */ | |
5622 | } | |
c906108c SS |
5623 | break; |
5624 | case bp_longjmp: | |
e2e4d78b | 5625 | case bp_longjmp_call_dummy: |
186c406b | 5626 | case bp_exception: |
0a39bb32 PA |
5627 | if (bs->stop) |
5628 | { | |
5629 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5630 | retval.is_longjmp = bptype != bp_exception; | |
5631 | } | |
5632 | else | |
5633 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5634 | break; |
5635 | case bp_longjmp_resume: | |
186c406b | 5636 | case bp_exception_resume: |
0a39bb32 PA |
5637 | if (bs->stop) |
5638 | { | |
5639 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5640 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5641 | } | |
5642 | else | |
5643 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5644 | break; |
5645 | case bp_step_resume: | |
5646 | if (bs->stop) | |
628fe4e4 JK |
5647 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5648 | else | |
c906108c | 5649 | { |
628fe4e4 JK |
5650 | /* It is for the wrong frame. */ |
5651 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5652 | } |
c906108c | 5653 | break; |
2c03e5be PA |
5654 | case bp_hp_step_resume: |
5655 | if (bs->stop) | |
5656 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5657 | else | |
5658 | { | |
5659 | /* It is for the wrong frame. */ | |
5660 | this_action = BPSTAT_WHAT_SINGLE; | |
5661 | } | |
5662 | break; | |
c906108c | 5663 | case bp_watchpoint_scope: |
c4093a6a | 5664 | case bp_thread_event: |
1900040c | 5665 | case bp_overlay_event: |
0fd8e87f | 5666 | case bp_longjmp_master: |
aa7d318d | 5667 | case bp_std_terminate_master: |
186c406b | 5668 | case bp_exception_master: |
628fe4e4 | 5669 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5670 | break; |
ce78b96d | 5671 | case bp_catchpoint: |
c5aa993b JM |
5672 | if (bs->stop) |
5673 | { | |
5674 | if (bs->print) | |
628fe4e4 | 5675 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5676 | else |
628fe4e4 | 5677 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5678 | } |
5679 | else | |
628fe4e4 | 5680 | { |
cb1e4e32 PA |
5681 | /* Some catchpoints are implemented with breakpoints. |
5682 | For those, we need to step over the breakpoint. */ | |
5683 | if (bs->bp_location_at->loc_type != bp_loc_other) | |
5684 | this_action = BPSTAT_WHAT_SINGLE; | |
628fe4e4 JK |
5685 | } |
5686 | break; | |
628fe4e4 | 5687 | case bp_jit_event: |
628fe4e4 | 5688 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5689 | break; |
c906108c | 5690 | case bp_call_dummy: |
53a5351d JM |
5691 | /* Make sure the action is stop (silent or noisy), |
5692 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5693 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5694 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5695 | break; |
5696 | case bp_std_terminate: | |
5697 | /* Make sure the action is stop (silent or noisy), | |
5698 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5699 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5700 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5701 | break; |
1042e4c0 | 5702 | case bp_tracepoint: |
7a697b8d | 5703 | case bp_fast_tracepoint: |
0fb4aa4b | 5704 | case bp_static_tracepoint: |
1042e4c0 SS |
5705 | /* Tracepoint hits should not be reported back to GDB, and |
5706 | if one got through somehow, it should have been filtered | |
5707 | out already. */ | |
5708 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5709 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5710 | break; |
5711 | case bp_gnu_ifunc_resolver: | |
5712 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5713 | this_action = BPSTAT_WHAT_SINGLE; | |
5714 | break; | |
5715 | case bp_gnu_ifunc_resolver_return: | |
5716 | /* The breakpoint will be removed, execution will restart from the | |
5717 | PC of the former breakpoint. */ | |
5718 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5719 | break; | |
e7e0cddf SS |
5720 | |
5721 | case bp_dprintf: | |
a11cfd87 HZ |
5722 | if (bs->stop) |
5723 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5724 | else | |
5725 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5726 | break; |
5727 | ||
628fe4e4 JK |
5728 | default: |
5729 | internal_error (__FILE__, __LINE__, | |
5730 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5731 | } |
628fe4e4 | 5732 | |
325fac50 | 5733 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5734 | } |
628fe4e4 | 5735 | |
243a9253 PA |
5736 | return retval; |
5737 | } | |
628fe4e4 | 5738 | |
243a9253 | 5739 | void |
313f3b21 | 5740 | bpstat_run_callbacks (bpstat *bs_head) |
243a9253 | 5741 | { |
313f3b21 | 5742 | bpstat *bs; |
628fe4e4 | 5743 | |
0e30163f JK |
5744 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5745 | { | |
5746 | struct breakpoint *b = bs->breakpoint_at; | |
5747 | ||
5748 | if (b == NULL) | |
5749 | continue; | |
5750 | switch (b->type) | |
5751 | { | |
243a9253 | 5752 | case bp_jit_event: |
61c26be8 | 5753 | handle_jit_event (bs->bp_location_at->address); |
243a9253 | 5754 | break; |
0e30163f JK |
5755 | case bp_gnu_ifunc_resolver: |
5756 | gnu_ifunc_resolver_stop (b); | |
5757 | break; | |
5758 | case bp_gnu_ifunc_resolver_return: | |
5759 | gnu_ifunc_resolver_return_stop (b); | |
5760 | break; | |
5761 | } | |
5762 | } | |
c906108c SS |
5763 | } |
5764 | ||
4c462cb0 | 5765 | /* See breakpoint.h. */ |
c906108c | 5766 | |
4c462cb0 SM |
5767 | bool |
5768 | bpstat_should_step () | |
c906108c | 5769 | { |
43892fdf | 5770 | for (breakpoint *b : all_breakpoints ()) |
717a8278 | 5771 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
4c462cb0 | 5772 | return true; |
43892fdf | 5773 | |
4c462cb0 | 5774 | return false; |
c906108c SS |
5775 | } |
5776 | ||
4c462cb0 SM |
5777 | /* See breakpoint.h. */ |
5778 | ||
5779 | bool | |
313f3b21 | 5780 | bpstat_causes_stop (bpstat *bs) |
67822962 PA |
5781 | { |
5782 | for (; bs != NULL; bs = bs->next) | |
5783 | if (bs->stop) | |
4c462cb0 | 5784 | return true; |
67822962 | 5785 | |
4c462cb0 | 5786 | return false; |
67822962 PA |
5787 | } |
5788 | ||
c906108c | 5789 | \f |
c5aa993b | 5790 | |
170b53b2 UW |
5791 | /* Compute a string of spaces suitable to indent the next line |
5792 | so it starts at the position corresponding to the table column | |
5793 | named COL_NAME in the currently active table of UIOUT. */ | |
5794 | ||
5795 | static char * | |
5796 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5797 | { | |
5798 | static char wrap_indent[80]; | |
5799 | int i, total_width, width, align; | |
c5209615 | 5800 | const char *text; |
170b53b2 UW |
5801 | |
5802 | total_width = 0; | |
112e8700 | 5803 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5804 | { |
5805 | if (strcmp (text, col_name) == 0) | |
5806 | { | |
5807 | gdb_assert (total_width < sizeof wrap_indent); | |
5808 | memset (wrap_indent, ' ', total_width); | |
5809 | wrap_indent[total_width] = 0; | |
5810 | ||
5811 | return wrap_indent; | |
5812 | } | |
5813 | ||
5814 | total_width += width + 1; | |
5815 | } | |
5816 | ||
5817 | return NULL; | |
5818 | } | |
5819 | ||
b775012e LM |
5820 | /* Determine if the locations of this breakpoint will have their conditions |
5821 | evaluated by the target, host or a mix of both. Returns the following: | |
5822 | ||
5823 | "host": Host evals condition. | |
5824 | "host or target": Host or Target evals condition. | |
5825 | "target": Target evals condition. | |
5826 | */ | |
5827 | ||
5828 | static const char * | |
5829 | bp_condition_evaluator (struct breakpoint *b) | |
5830 | { | |
b775012e LM |
5831 | char host_evals = 0; |
5832 | char target_evals = 0; | |
5833 | ||
5834 | if (!b) | |
5835 | return NULL; | |
5836 | ||
5837 | if (!is_breakpoint (b)) | |
5838 | return NULL; | |
5839 | ||
5840 | if (gdb_evaluates_breakpoint_condition_p () | |
5841 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5842 | return condition_evaluation_host; | |
5843 | ||
40cb8ca5 | 5844 | for (bp_location *bl : b->locations ()) |
b775012e LM |
5845 | { |
5846 | if (bl->cond_bytecode) | |
5847 | target_evals++; | |
5848 | else | |
5849 | host_evals++; | |
5850 | } | |
5851 | ||
5852 | if (host_evals && target_evals) | |
5853 | return condition_evaluation_both; | |
5854 | else if (target_evals) | |
5855 | return condition_evaluation_target; | |
5856 | else | |
5857 | return condition_evaluation_host; | |
5858 | } | |
5859 | ||
5860 | /* Determine the breakpoint location's condition evaluator. This is | |
5861 | similar to bp_condition_evaluator, but for locations. */ | |
5862 | ||
5863 | static const char * | |
5864 | bp_location_condition_evaluator (struct bp_location *bl) | |
5865 | { | |
5866 | if (bl && !is_breakpoint (bl->owner)) | |
5867 | return NULL; | |
5868 | ||
5869 | if (gdb_evaluates_breakpoint_condition_p () | |
5870 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5871 | return condition_evaluation_host; | |
5872 | ||
5873 | if (bl && bl->cond_bytecode) | |
5874 | return condition_evaluation_target; | |
5875 | else | |
5876 | return condition_evaluation_host; | |
5877 | } | |
5878 | ||
859825b8 JK |
5879 | /* Print the LOC location out of the list of B->LOC locations. */ |
5880 | ||
170b53b2 UW |
5881 | static void |
5882 | print_breakpoint_location (struct breakpoint *b, | |
5883 | struct bp_location *loc) | |
0d381245 | 5884 | { |
79a45e25 | 5885 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5886 | |
5887 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5888 | |
859825b8 JK |
5889 | if (loc != NULL && loc->shlib_disabled) |
5890 | loc = NULL; | |
5891 | ||
6c95b8df PA |
5892 | if (loc != NULL) |
5893 | set_current_program_space (loc->pspace); | |
5894 | ||
56435ebe | 5895 | if (b->display_canonical) |
d28cd78a | 5896 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5897 | else if (loc && loc->symtab) |
0d381245 | 5898 | { |
4a27f119 KS |
5899 | const struct symbol *sym = loc->symbol; |
5900 | ||
0d381245 VP |
5901 | if (sym) |
5902 | { | |
112e8700 | 5903 | uiout->text ("in "); |
987012b8 | 5904 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 5905 | function_name_style.style ()); |
112e8700 SM |
5906 | uiout->text (" "); |
5907 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5908 | uiout->text ("at "); | |
0d381245 | 5909 | } |
112e8700 | 5910 | uiout->field_string ("file", |
cbe56571 | 5911 | symtab_to_filename_for_display (loc->symtab), |
e43b10e1 | 5912 | file_name_style.style ()); |
112e8700 | 5913 | uiout->text (":"); |
05cba821 | 5914 | |
112e8700 SM |
5915 | if (uiout->is_mi_like_p ()) |
5916 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 5917 | |
381befee | 5918 | uiout->field_signed ("line", loc->line_number); |
0d381245 | 5919 | } |
859825b8 | 5920 | else if (loc) |
0d381245 | 5921 | { |
d7e74731 | 5922 | string_file stb; |
170b53b2 | 5923 | |
d7e74731 | 5924 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 5925 | demangle, ""); |
112e8700 | 5926 | uiout->field_stream ("at", stb); |
0d381245 | 5927 | } |
859825b8 | 5928 | else |
f00aae0f | 5929 | { |
d28cd78a TT |
5930 | uiout->field_string ("pending", |
5931 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
5932 | /* If extra_string is available, it could be holding a condition |
5933 | or dprintf arguments. In either case, make sure it is printed, | |
5934 | too, but only for non-MI streams. */ | |
112e8700 | 5935 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
5936 | { |
5937 | if (b->type == bp_dprintf) | |
112e8700 | 5938 | uiout->text (","); |
f00aae0f | 5939 | else |
112e8700 | 5940 | uiout->text (" "); |
6f781ee3 | 5941 | uiout->text (b->extra_string.get ()); |
f00aae0f KS |
5942 | } |
5943 | } | |
6c95b8df | 5944 | |
b775012e LM |
5945 | if (loc && is_breakpoint (b) |
5946 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5947 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5948 | { | |
112e8700 SM |
5949 | uiout->text (" ("); |
5950 | uiout->field_string ("evaluated-by", | |
b775012e | 5951 | bp_location_condition_evaluator (loc)); |
112e8700 | 5952 | uiout->text (")"); |
b775012e | 5953 | } |
0d381245 VP |
5954 | } |
5955 | ||
269b11a2 PA |
5956 | static const char * |
5957 | bptype_string (enum bptype type) | |
c906108c | 5958 | { |
c4093a6a JM |
5959 | struct ep_type_description |
5960 | { | |
5961 | enum bptype type; | |
a121b7c1 | 5962 | const char *description; |
c4093a6a JM |
5963 | }; |
5964 | static struct ep_type_description bptypes[] = | |
c906108c | 5965 | { |
c5aa993b JM |
5966 | {bp_none, "?deleted?"}, |
5967 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5968 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 5969 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
5970 | {bp_until, "until"}, |
5971 | {bp_finish, "finish"}, | |
5972 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5973 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5974 | {bp_read_watchpoint, "read watchpoint"}, |
5975 | {bp_access_watchpoint, "acc watchpoint"}, | |
5976 | {bp_longjmp, "longjmp"}, | |
5977 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5978 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5979 | {bp_exception, "exception"}, |
5980 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5981 | {bp_step_resume, "step resume"}, |
2c03e5be | 5982 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5983 | {bp_watchpoint_scope, "watchpoint scope"}, |
5984 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5985 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5986 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5987 | {bp_thread_event, "thread events"}, |
1900040c | 5988 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5989 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5990 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5991 | {bp_exception_master, "exception master"}, |
ce78b96d | 5992 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5993 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5994 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5995 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5996 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5997 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5998 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5999 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6000 | }; |
269b11a2 PA |
6001 | |
6002 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6003 | || ((int) type != bptypes[(int) type].type)) | |
6004 | internal_error (__FILE__, __LINE__, | |
6005 | _("bptypes table does not describe type #%d."), | |
6006 | (int) type); | |
6007 | ||
6008 | return bptypes[(int) type].description; | |
6009 | } | |
6010 | ||
998580f1 MK |
6011 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6012 | For CLI, prefix the list with the string 'inf'. */ | |
6013 | ||
6014 | static void | |
6015 | output_thread_groups (struct ui_out *uiout, | |
6016 | const char *field_name, | |
5c632425 | 6017 | const std::vector<int> &inf_nums, |
998580f1 MK |
6018 | int mi_only) |
6019 | { | |
112e8700 | 6020 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6021 | |
6022 | /* For backward compatibility, don't display inferiors in CLI unless | |
6023 | there are several. Always display them for MI. */ | |
6024 | if (!is_mi && mi_only) | |
6025 | return; | |
6026 | ||
10f489e5 | 6027 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6028 | |
5c632425 | 6029 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
6030 | { |
6031 | if (is_mi) | |
6032 | { | |
6033 | char mi_group[10]; | |
6034 | ||
5c632425 | 6035 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 6036 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6037 | } |
6038 | else | |
6039 | { | |
6040 | if (i == 0) | |
112e8700 | 6041 | uiout->text (" inf "); |
998580f1 | 6042 | else |
112e8700 | 6043 | uiout->text (", "); |
998580f1 | 6044 | |
5c632425 | 6045 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
6046 | } |
6047 | } | |
998580f1 MK |
6048 | } |
6049 | ||
a38118e5 PA |
6050 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
6051 | instead of going via breakpoint_ops::print_one. This makes "maint | |
6052 | info breakpoints" show the software breakpoint locations of | |
6053 | catchpoints, which are considered internal implementation | |
6054 | detail. */ | |
269b11a2 PA |
6055 | |
6056 | static void | |
6057 | print_one_breakpoint_location (struct breakpoint *b, | |
6058 | struct bp_location *loc, | |
6059 | int loc_number, | |
6060 | struct bp_location **last_loc, | |
a38118e5 | 6061 | int allflag, bool raw_loc) |
269b11a2 PA |
6062 | { |
6063 | struct command_line *l; | |
c2c6d25f | 6064 | static char bpenables[] = "nynny"; |
c906108c | 6065 | |
79a45e25 | 6066 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6067 | int header_of_multiple = 0; |
6068 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6069 | struct value_print_options opts; |
6070 | ||
6071 | get_user_print_options (&opts); | |
0d381245 VP |
6072 | |
6073 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6074 | /* See comment in print_one_breakpoint concerning treatment of |
6075 | breakpoints with single disabled location. */ | |
0d381245 VP |
6076 | if (loc == NULL |
6077 | && (b->loc != NULL | |
b5fa468f TBA |
6078 | && (b->loc->next != NULL |
6079 | || !b->loc->enabled || b->loc->disabled_by_cond))) | |
0d381245 VP |
6080 | header_of_multiple = 1; |
6081 | if (loc == NULL) | |
6082 | loc = b->loc; | |
6083 | ||
c4093a6a JM |
6084 | annotate_record (); |
6085 | ||
6086 | /* 1 */ | |
6087 | annotate_field (0); | |
0d381245 | 6088 | if (part_of_multiple) |
528e1572 | 6089 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
0d381245 | 6090 | else |
381befee | 6091 | uiout->field_signed ("number", b->number); |
c4093a6a JM |
6092 | |
6093 | /* 2 */ | |
6094 | annotate_field (1); | |
0d381245 | 6095 | if (part_of_multiple) |
112e8700 | 6096 | uiout->field_skip ("type"); |
269b11a2 | 6097 | else |
112e8700 | 6098 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6099 | |
6100 | /* 3 */ | |
6101 | annotate_field (2); | |
0d381245 | 6102 | if (part_of_multiple) |
112e8700 | 6103 | uiout->field_skip ("disp"); |
0d381245 | 6104 | else |
112e8700 | 6105 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6106 | |
c4093a6a JM |
6107 | /* 4 */ |
6108 | annotate_field (3); | |
85c88e2a TBA |
6109 | /* For locations that are disabled because of an invalid condition, |
6110 | display "N*" on CLI, where "*" refers to a footnote below the | |
6111 | table. For MI, simply display a "N" without a footnote. */ | |
6112 | const char *N = (uiout->is_mi_like_p ()) ? "N" : "N*"; | |
0d381245 | 6113 | if (part_of_multiple) |
85c88e2a | 6114 | uiout->field_string ("enabled", (loc->disabled_by_cond ? N |
b5fa468f | 6115 | : (loc->enabled ? "y" : "n"))); |
0d381245 | 6116 | else |
112e8700 | 6117 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
0d381245 | 6118 | |
c4093a6a | 6119 | /* 5 and 6 */ |
a38118e5 | 6120 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
b58a68fe | 6121 | b->ops->print_one (b, last_loc); |
3086aeae | 6122 | else |
a38118e5 PA |
6123 | { |
6124 | if (is_watchpoint (b)) | |
3a5c3e22 PA |
6125 | { |
6126 | struct watchpoint *w = (struct watchpoint *) b; | |
6127 | ||
6128 | /* Field 4, the address, is omitted (which makes the columns | |
6129 | not line up too nicely with the headers, but the effect | |
6130 | is relatively readable). */ | |
6131 | if (opts.addressprint) | |
112e8700 | 6132 | uiout->field_skip ("addr"); |
3a5c3e22 | 6133 | annotate_field (5); |
a4c50be3 | 6134 | uiout->field_string ("what", w->exp_string.get ()); |
3a5c3e22 | 6135 | } |
f06f1252 TT |
6136 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
6137 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6138 | { |
6139 | if (opts.addressprint) | |
6140 | { | |
6141 | annotate_field (4); | |
6142 | if (header_of_multiple) | |
7f6aba03 TT |
6143 | uiout->field_string ("addr", "<MULTIPLE>", |
6144 | metadata_style.style ()); | |
a38118e5 | 6145 | else if (b->loc == NULL || loc->shlib_disabled) |
7f6aba03 TT |
6146 | uiout->field_string ("addr", "<PENDING>", |
6147 | metadata_style.style ()); | |
a38118e5 PA |
6148 | else |
6149 | uiout->field_core_addr ("addr", | |
6150 | loc->gdbarch, loc->address); | |
6151 | } | |
6152 | annotate_field (5); | |
6153 | if (!header_of_multiple) | |
6154 | print_breakpoint_location (b, loc); | |
6155 | if (b->loc) | |
6156 | *last_loc = b->loc; | |
6157 | } | |
6158 | } | |
6c95b8df | 6159 | |
998580f1 | 6160 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6161 | { |
5c632425 | 6162 | std::vector<int> inf_nums; |
998580f1 | 6163 | int mi_only = 1; |
6c95b8df | 6164 | |
08036331 | 6165 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6166 | { |
6167 | if (inf->pspace == loc->pspace) | |
5c632425 | 6168 | inf_nums.push_back (inf->num); |
6c95b8df | 6169 | } |
998580f1 | 6170 | |
dda83cd7 | 6171 | /* For backward compatibility, don't display inferiors in CLI unless |
998580f1 MK |
6172 | there are several. Always display for MI. */ |
6173 | if (allflag | |
6174 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
94c93c35 | 6175 | && (program_spaces.size () > 1 |
998580f1 MK |
6176 | || number_of_inferiors () > 1) |
6177 | /* LOC is for existing B, it cannot be in | |
6178 | moribund_locations and thus having NULL OWNER. */ | |
6179 | && loc->owner->type != bp_catchpoint)) | |
6180 | mi_only = 0; | |
5c632425 | 6181 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6182 | } |
6183 | ||
4a306c9a | 6184 | if (!part_of_multiple) |
c4093a6a | 6185 | { |
4a306c9a JB |
6186 | if (b->thread != -1) |
6187 | { | |
6188 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6189 | "stop only in" line a little further down. */ |
112e8700 | 6190 | uiout->text (" thread "); |
381befee | 6191 | uiout->field_signed ("thread", b->thread); |
4a306c9a JB |
6192 | } |
6193 | else if (b->task != 0) | |
6194 | { | |
112e8700 | 6195 | uiout->text (" task "); |
381befee | 6196 | uiout->field_signed ("task", b->task); |
4a306c9a | 6197 | } |
c4093a6a | 6198 | } |
f1310107 | 6199 | |
112e8700 | 6200 | uiout->text ("\n"); |
f1310107 | 6201 | |
348d480f | 6202 | if (!part_of_multiple) |
f1310107 TJB |
6203 | b->ops->print_one_detail (b, uiout); |
6204 | ||
0d381245 | 6205 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6206 | { |
6207 | annotate_field (6); | |
112e8700 | 6208 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6209 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
dda83cd7 | 6210 | the frame ID. */ |
112e8700 | 6211 | uiout->field_core_addr ("frame", |
5af949e3 | 6212 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6213 | uiout->text ("\n"); |
c4093a6a JM |
6214 | } |
6215 | ||
28010a5d | 6216 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6217 | { |
6218 | annotate_field (7); | |
d77f58be | 6219 | if (is_tracepoint (b)) |
112e8700 | 6220 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6221 | else |
112e8700 | 6222 | uiout->text ("\tstop only if "); |
6f781ee3 | 6223 | uiout->field_string ("cond", b->cond_string.get ()); |
b775012e LM |
6224 | |
6225 | /* Print whether the target is doing the breakpoint's condition | |
6226 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6227 | if (is_breakpoint (b) | |
6228 | && breakpoint_condition_evaluation_mode () | |
6229 | == condition_evaluation_target) | |
6230 | { | |
6a831f06 PA |
6231 | uiout->message (" (%pF evals)", |
6232 | string_field ("evaluated-by", | |
6233 | bp_condition_evaluator (b))); | |
b775012e | 6234 | } |
112e8700 | 6235 | uiout->text ("\n"); |
0101ce28 JJ |
6236 | } |
6237 | ||
0d381245 | 6238 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6239 | { |
4a64f543 | 6240 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6241 | uiout->text ("\tstop only in thread "); |
6242 | if (uiout->is_mi_like_p ()) | |
381befee | 6243 | uiout->field_signed ("thread", b->thread); |
5d5658a1 PA |
6244 | else |
6245 | { | |
6246 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6247 | ||
112e8700 | 6248 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6249 | } |
112e8700 | 6250 | uiout->text ("\n"); |
c4093a6a JM |
6251 | } |
6252 | ||
556ec64d YQ |
6253 | if (!part_of_multiple) |
6254 | { | |
6255 | if (b->hit_count) | |
31f56a27 YQ |
6256 | { |
6257 | /* FIXME should make an annotation for this. */ | |
6258 | if (is_catchpoint (b)) | |
112e8700 | 6259 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6260 | else if (is_tracepoint (b)) |
112e8700 | 6261 | uiout->text ("\ttracepoint"); |
31f56a27 | 6262 | else |
112e8700 SM |
6263 | uiout->text ("\tbreakpoint"); |
6264 | uiout->text (" already hit "); | |
381befee | 6265 | uiout->field_signed ("times", b->hit_count); |
31f56a27 | 6266 | if (b->hit_count == 1) |
112e8700 | 6267 | uiout->text (" time\n"); |
31f56a27 | 6268 | else |
112e8700 | 6269 | uiout->text (" times\n"); |
31f56a27 | 6270 | } |
556ec64d YQ |
6271 | else |
6272 | { | |
31f56a27 | 6273 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 | 6274 | if (uiout->is_mi_like_p ()) |
381befee | 6275 | uiout->field_signed ("times", b->hit_count); |
556ec64d YQ |
6276 | } |
6277 | } | |
8b93c638 | 6278 | |
0d381245 | 6279 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6280 | { |
6281 | annotate_field (8); | |
6a831f06 PA |
6282 | uiout->message ("\tignore next %pF hits\n", |
6283 | signed_field ("ignore", b->ignore_count)); | |
c4093a6a | 6284 | } |
059fb39f | 6285 | |
816338b5 SS |
6286 | /* Note that an enable count of 1 corresponds to "enable once" |
6287 | behavior, which is reported by the combination of enablement and | |
6288 | disposition, so we don't need to mention it here. */ | |
6289 | if (!part_of_multiple && b->enable_count > 1) | |
6290 | { | |
6291 | annotate_field (8); | |
112e8700 | 6292 | uiout->text ("\tdisable after "); |
816338b5 SS |
6293 | /* Tweak the wording to clarify that ignore and enable counts |
6294 | are distinct, and have additive effect. */ | |
6295 | if (b->ignore_count) | |
112e8700 | 6296 | uiout->text ("additional "); |
816338b5 | 6297 | else |
112e8700 | 6298 | uiout->text ("next "); |
381befee | 6299 | uiout->field_signed ("enable", b->enable_count); |
112e8700 | 6300 | uiout->text (" hits\n"); |
816338b5 SS |
6301 | } |
6302 | ||
f196051f SS |
6303 | if (!part_of_multiple && is_tracepoint (b)) |
6304 | { | |
6305 | struct tracepoint *tp = (struct tracepoint *) b; | |
6306 | ||
6307 | if (tp->traceframe_usage) | |
6308 | { | |
112e8700 | 6309 | uiout->text ("\ttrace buffer usage "); |
381befee | 6310 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
112e8700 | 6311 | uiout->text (" bytes\n"); |
f196051f SS |
6312 | } |
6313 | } | |
d3ce09f5 | 6314 | |
d1b0a7bf | 6315 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6316 | if (!part_of_multiple && l) |
c4093a6a JM |
6317 | { |
6318 | annotate_field (9); | |
2e783024 | 6319 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6320 | print_command_lines (uiout, l, 4); |
c4093a6a | 6321 | } |
d24317b4 | 6322 | |
d9b3f62e | 6323 | if (is_tracepoint (b)) |
1042e4c0 | 6324 | { |
d9b3f62e PA |
6325 | struct tracepoint *t = (struct tracepoint *) b; |
6326 | ||
6327 | if (!part_of_multiple && t->pass_count) | |
6328 | { | |
6329 | annotate_field (10); | |
112e8700 | 6330 | uiout->text ("\tpass count "); |
381befee | 6331 | uiout->field_signed ("pass", t->pass_count); |
112e8700 | 6332 | uiout->text (" \n"); |
d9b3f62e | 6333 | } |
f2a8bc8a YQ |
6334 | |
6335 | /* Don't display it when tracepoint or tracepoint location is | |
6336 | pending. */ | |
6337 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6338 | { | |
6339 | annotate_field (11); | |
6340 | ||
112e8700 SM |
6341 | if (uiout->is_mi_like_p ()) |
6342 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6343 | loc->inserted ? "y" : "n"); |
6344 | else | |
6345 | { | |
6346 | if (loc->inserted) | |
112e8700 | 6347 | uiout->text ("\t"); |
f2a8bc8a | 6348 | else |
112e8700 SM |
6349 | uiout->text ("\tnot "); |
6350 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6351 | } |
6352 | } | |
1042e4c0 SS |
6353 | } |
6354 | ||
112e8700 | 6355 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6356 | { |
3a5c3e22 PA |
6357 | if (is_watchpoint (b)) |
6358 | { | |
6359 | struct watchpoint *w = (struct watchpoint *) b; | |
6360 | ||
a4c50be3 | 6361 | uiout->field_string ("original-location", w->exp_string.get ()); |
3a5c3e22 | 6362 | } |
f00aae0f | 6363 | else if (b->location != NULL |
d28cd78a | 6364 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6365 | uiout->field_string ("original-location", |
d28cd78a | 6366 | event_location_to_string (b->location.get ())); |
d24317b4 | 6367 | } |
c4093a6a | 6368 | } |
c5aa993b | 6369 | |
13674803 SM |
6370 | /* See breakpoint.h. */ |
6371 | ||
6372 | bool fix_multi_location_breakpoint_output_globally = false; | |
6373 | ||
0d381245 VP |
6374 | static void |
6375 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6376 | struct bp_location **last_loc, |
6c95b8df | 6377 | int allflag) |
0d381245 | 6378 | { |
79a45e25 | 6379 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6380 | bool use_fixed_output |
6381 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6382 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6383 | |
b4be1b06 | 6384 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
a38118e5 | 6385 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
8d3788bd | 6386 | |
b4be1b06 SM |
6387 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6388 | are outside. */ | |
6389 | if (!use_fixed_output) | |
6390 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6391 | |
6392 | /* If this breakpoint has custom print function, | |
6393 | it's already printed. Otherwise, print individual | |
6394 | locations, if any. */ | |
a38118e5 PA |
6395 | if (b->ops == NULL |
6396 | || b->ops->print_one == NULL | |
6397 | || allflag) | |
0d381245 | 6398 | { |
4a64f543 MS |
6399 | /* If breakpoint has a single location that is disabled, we |
6400 | print it as if it had several locations, since otherwise it's | |
6401 | hard to represent "breakpoint enabled, location disabled" | |
6402 | situation. | |
6403 | ||
6404 | Note that while hardware watchpoints have several locations | |
a38118e5 PA |
6405 | internally, that's not a property exposed to users. |
6406 | ||
6407 | Likewise, while catchpoints may be implemented with | |
6408 | breakpoints (e.g., catch throw), that's not a property | |
6409 | exposed to users. We do however display the internal | |
6410 | breakpoint locations with "maint info breakpoints". */ | |
6411 | if (!is_hardware_watchpoint (b) | |
f06f1252 TT |
6412 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
6413 | || is_ada_exception_catchpoint (b)) | |
a38118e5 | 6414 | && (allflag |
b5fa468f TBA |
6415 | || (b->loc && (b->loc->next |
6416 | || !b->loc->enabled | |
6417 | || b->loc->disabled_by_cond)))) | |
0d381245 | 6418 | { |
b4be1b06 SM |
6419 | gdb::optional<ui_out_emit_list> locations_list; |
6420 | ||
6421 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6422 | MI record. For later versions, place breakpoint locations in a | |
6423 | list. */ | |
6424 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6425 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6426 | |
b4be1b06 | 6427 | int n = 1; |
40cb8ca5 | 6428 | for (bp_location *loc : b->locations ()) |
8d3788bd | 6429 | { |
b4be1b06 | 6430 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
a38118e5 PA |
6431 | print_one_breakpoint_location (b, loc, n, last_loc, |
6432 | allflag, allflag); | |
40cb8ca5 | 6433 | n++; |
8d3788bd | 6434 | } |
0d381245 VP |
6435 | } |
6436 | } | |
6437 | } | |
6438 | ||
a6d9a66e UW |
6439 | static int |
6440 | breakpoint_address_bits (struct breakpoint *b) | |
6441 | { | |
6442 | int print_address_bits = 0; | |
a6d9a66e | 6443 | |
c6d81124 PA |
6444 | /* Software watchpoints that aren't watching memory don't have an |
6445 | address to print. */ | |
6446 | if (is_no_memory_software_watchpoint (b)) | |
6447 | return 0; | |
6448 | ||
40cb8ca5 | 6449 | for (bp_location *loc : b->locations ()) |
a6d9a66e | 6450 | { |
c7437ca6 PA |
6451 | int addr_bit; |
6452 | ||
c7437ca6 | 6453 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6454 | if (addr_bit > print_address_bits) |
6455 | print_address_bits = addr_bit; | |
6456 | } | |
6457 | ||
6458 | return print_address_bits; | |
6459 | } | |
0d381245 | 6460 | |
65630365 | 6461 | /* See breakpoint.h. */ |
c5aa993b | 6462 | |
65630365 PA |
6463 | void |
6464 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6465 | { |
a6d9a66e | 6466 | struct bp_location *dummy_loc = NULL; |
65630365 | 6467 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6468 | } |
c5aa993b | 6469 | |
09d682a4 TT |
6470 | /* Return true if this breakpoint was set by the user, false if it is |
6471 | internal or momentary. */ | |
6472 | ||
6473 | int | |
6474 | user_breakpoint_p (struct breakpoint *b) | |
6475 | { | |
46c6471b | 6476 | return b->number > 0; |
09d682a4 TT |
6477 | } |
6478 | ||
93daf339 TT |
6479 | /* See breakpoint.h. */ |
6480 | ||
6481 | int | |
6482 | pending_breakpoint_p (struct breakpoint *b) | |
6483 | { | |
6484 | return b->loc == NULL; | |
6485 | } | |
6486 | ||
5c458ae8 SM |
6487 | /* Print information on breakpoints (including watchpoints and tracepoints). |
6488 | ||
6489 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as | |
6490 | understood by number_or_range_parser. Only breakpoints included in this | |
6491 | list are then printed. | |
6492 | ||
6493 | If SHOW_INTERNAL is true, print internal breakpoints. | |
6494 | ||
6495 | If FILTER is non-NULL, call it on each breakpoint and only include the | |
6496 | ones for which it returns true. | |
6497 | ||
6498 | Return the total number of breakpoints listed. */ | |
c906108c | 6499 | |
d77f58be | 6500 | static int |
5c458ae8 | 6501 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
f2478a7e | 6502 | bool (*filter) (const struct breakpoint *)) |
c4093a6a | 6503 | { |
a6d9a66e | 6504 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6505 | int nr_printable_breakpoints; |
79a45b7d | 6506 | struct value_print_options opts; |
a6d9a66e | 6507 | int print_address_bits = 0; |
269b11a2 | 6508 | int print_type_col_width = 14; |
79a45e25 | 6509 | struct ui_out *uiout = current_uiout; |
b5fa468f | 6510 | bool has_disabled_by_cond_location = false; |
269b11a2 | 6511 | |
79a45b7d TT |
6512 | get_user_print_options (&opts); |
6513 | ||
4a64f543 MS |
6514 | /* Compute the number of rows in the table, as well as the size |
6515 | required for address fields. */ | |
7f3b0473 | 6516 | nr_printable_breakpoints = 0; |
43892fdf | 6517 | for (breakpoint *b : all_breakpoints ()) |
e5a67952 MS |
6518 | { |
6519 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6520 | if (filter && !filter (b)) | |
6521 | continue; | |
6522 | ||
5c458ae8 | 6523 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
e5a67952 | 6524 | accept. Skip the others. */ |
5c458ae8 | 6525 | if (bp_num_list != NULL && *bp_num_list != '\0') |
e5a67952 | 6526 | { |
5c458ae8 | 6527 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
e5a67952 | 6528 | continue; |
5c458ae8 | 6529 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
e5a67952 MS |
6530 | continue; |
6531 | } | |
269b11a2 | 6532 | |
5c458ae8 | 6533 | if (show_internal || user_breakpoint_p (b)) |
e5a67952 MS |
6534 | { |
6535 | int addr_bit, type_len; | |
a6d9a66e | 6536 | |
e5a67952 MS |
6537 | addr_bit = breakpoint_address_bits (b); |
6538 | if (addr_bit > print_address_bits) | |
6539 | print_address_bits = addr_bit; | |
269b11a2 | 6540 | |
e5a67952 MS |
6541 | type_len = strlen (bptype_string (b->type)); |
6542 | if (type_len > print_type_col_width) | |
6543 | print_type_col_width = type_len; | |
6544 | ||
6545 | nr_printable_breakpoints++; | |
6546 | } | |
6547 | } | |
7f3b0473 | 6548 | |
4a2b031d TT |
6549 | { |
6550 | ui_out_emit_table table_emitter (uiout, | |
6551 | opts.addressprint ? 6 : 5, | |
6552 | nr_printable_breakpoints, | |
6553 | "BreakpointTable"); | |
6554 | ||
6555 | if (nr_printable_breakpoints > 0) | |
6556 | annotate_breakpoints_headers (); | |
6557 | if (nr_printable_breakpoints > 0) | |
6558 | annotate_field (0); | |
6559 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6560 | if (nr_printable_breakpoints > 0) | |
6561 | annotate_field (1); | |
6562 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6563 | if (nr_printable_breakpoints > 0) | |
6564 | annotate_field (2); | |
6565 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6566 | if (nr_printable_breakpoints > 0) | |
6567 | annotate_field (3); | |
6568 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6569 | if (opts.addressprint) | |
6570 | { | |
6571 | if (nr_printable_breakpoints > 0) | |
6572 | annotate_field (4); | |
6573 | if (print_address_bits <= 32) | |
6574 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6575 | else | |
6576 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6577 | } | |
6578 | if (nr_printable_breakpoints > 0) | |
6579 | annotate_field (5); | |
6580 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6581 | uiout->table_body (); | |
6582 | if (nr_printable_breakpoints > 0) | |
6583 | annotate_breakpoints_table (); | |
6584 | ||
43892fdf | 6585 | for (breakpoint *b : all_breakpoints ()) |
4a2b031d TT |
6586 | { |
6587 | QUIT; | |
6588 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6589 | if (filter && !filter (b)) | |
6590 | continue; | |
e5a67952 | 6591 | |
5c458ae8 | 6592 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
4a2b031d | 6593 | accept. Skip the others. */ |
e5a67952 | 6594 | |
5c458ae8 | 6595 | if (bp_num_list != NULL && *bp_num_list != '\0') |
4a2b031d | 6596 | { |
5c458ae8 | 6597 | if (show_internal) /* maintenance info breakpoint */ |
4a2b031d | 6598 | { |
5c458ae8 | 6599 | if (parse_and_eval_long (bp_num_list) != b->number) |
4a2b031d TT |
6600 | continue; |
6601 | } | |
6602 | else /* all others */ | |
6603 | { | |
5c458ae8 | 6604 | if (!number_is_in_list (bp_num_list, b->number)) |
4a2b031d TT |
6605 | continue; |
6606 | } | |
6607 | } | |
6608 | /* We only print out user settable breakpoints unless the | |
5c458ae8 SM |
6609 | show_internal is set. */ |
6610 | if (show_internal || user_breakpoint_p (b)) | |
b5fa468f TBA |
6611 | { |
6612 | print_one_breakpoint (b, &last_loc, show_internal); | |
40cb8ca5 | 6613 | for (bp_location *loc : b->locations ()) |
b5fa468f TBA |
6614 | if (loc->disabled_by_cond) |
6615 | has_disabled_by_cond_location = true; | |
6616 | } | |
4a2b031d TT |
6617 | } |
6618 | } | |
698384cd | 6619 | |
7f3b0473 | 6620 | if (nr_printable_breakpoints == 0) |
c906108c | 6621 | { |
4a64f543 MS |
6622 | /* If there's a filter, let the caller decide how to report |
6623 | empty list. */ | |
d77f58be SS |
6624 | if (!filter) |
6625 | { | |
5c458ae8 | 6626 | if (bp_num_list == NULL || *bp_num_list == '\0') |
112e8700 | 6627 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6628 | else |
112e8700 | 6629 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
5c458ae8 | 6630 | bp_num_list); |
d77f58be | 6631 | } |
c906108c SS |
6632 | } |
6633 | else | |
c4093a6a | 6634 | { |
a6d9a66e UW |
6635 | if (last_loc && !server_command) |
6636 | set_next_address (last_loc->gdbarch, last_loc->address); | |
b5fa468f | 6637 | |
85c88e2a | 6638 | if (has_disabled_by_cond_location && !uiout->is_mi_like_p ()) |
b5fa468f TBA |
6639 | uiout->message (_("(*): Breakpoint condition is invalid at this " |
6640 | "location.\n")); | |
c4093a6a | 6641 | } |
c906108c | 6642 | |
4a64f543 | 6643 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6644 | there have been breakpoints? */ |
c906108c | 6645 | annotate_breakpoints_table_end (); |
d77f58be SS |
6646 | |
6647 | return nr_printable_breakpoints; | |
c906108c SS |
6648 | } |
6649 | ||
ad443146 SS |
6650 | /* Display the value of default-collect in a way that is generally |
6651 | compatible with the breakpoint list. */ | |
6652 | ||
6653 | static void | |
6654 | default_collect_info (void) | |
6655 | { | |
79a45e25 PA |
6656 | struct ui_out *uiout = current_uiout; |
6657 | ||
ad443146 SS |
6658 | /* If it has no value (which is frequently the case), say nothing; a |
6659 | message like "No default-collect." gets in user's face when it's | |
6660 | not wanted. */ | |
e0700ba4 | 6661 | if (default_collect.empty ()) |
ad443146 SS |
6662 | return; |
6663 | ||
6664 | /* The following phrase lines up nicely with per-tracepoint collect | |
6665 | actions. */ | |
112e8700 SM |
6666 | uiout->text ("default collect "); |
6667 | uiout->field_string ("default-collect", default_collect); | |
6668 | uiout->text (" \n"); | |
ad443146 SS |
6669 | } |
6670 | ||
c906108c | 6671 | static void |
0b39b52e | 6672 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6673 | { |
5c458ae8 | 6674 | breakpoint_1 (args, false, NULL); |
ad443146 SS |
6675 | |
6676 | default_collect_info (); | |
d77f58be SS |
6677 | } |
6678 | ||
6679 | static void | |
1d12d88f | 6680 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6681 | { |
5c458ae8 | 6682 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
79a45e25 | 6683 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6684 | |
6685 | if (num_printed == 0) | |
6686 | { | |
e5a67952 | 6687 | if (args == NULL || *args == '\0') |
112e8700 | 6688 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6689 | else |
112e8700 | 6690 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6691 | } |
c906108c SS |
6692 | } |
6693 | ||
7a292a7a | 6694 | static void |
4495129a | 6695 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6696 | { |
5c458ae8 | 6697 | breakpoint_1 (args, true, NULL); |
ad443146 SS |
6698 | |
6699 | default_collect_info (); | |
c906108c SS |
6700 | } |
6701 | ||
0d381245 | 6702 | static int |
714835d5 | 6703 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6704 | struct program_space *pspace, |
714835d5 | 6705 | CORE_ADDR pc, struct obj_section *section) |
0d381245 | 6706 | { |
40cb8ca5 | 6707 | for (bp_location *bl : b->locations ()) |
0d381245 | 6708 | { |
6c95b8df PA |
6709 | if (bl->pspace == pspace |
6710 | && bl->address == pc | |
0d381245 VP |
6711 | && (!overlay_debugging || bl->section == section)) |
6712 | return 1; | |
6713 | } | |
6714 | return 0; | |
6715 | } | |
6716 | ||
672f9b60 | 6717 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6718 | concerns with logical breakpoints, so we match program spaces, not |
6719 | address spaces. */ | |
c906108c SS |
6720 | |
6721 | static void | |
6c95b8df PA |
6722 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6723 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6724 | struct obj_section *section, int thread) |
c906108c | 6725 | { |
52f0bd74 | 6726 | int others = 0; |
c906108c | 6727 | |
43892fdf | 6728 | for (breakpoint *b : all_breakpoints ()) |
672f9b60 | 6729 | others += (user_breakpoint_p (b) |
dda83cd7 | 6730 | && breakpoint_has_pc (b, pspace, pc, section)); |
43892fdf | 6731 | |
c906108c SS |
6732 | if (others > 0) |
6733 | { | |
a3f17187 AC |
6734 | if (others == 1) |
6735 | printf_filtered (_("Note: breakpoint ")); | |
6736 | else /* if (others == ???) */ | |
6737 | printf_filtered (_("Note: breakpoints ")); | |
43892fdf | 6738 | for (breakpoint *b : all_breakpoints ()) |
672f9b60 | 6739 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6740 | { |
6741 | others--; | |
6742 | printf_filtered ("%d", b->number); | |
6743 | if (b->thread == -1 && thread != -1) | |
6744 | printf_filtered (" (all threads)"); | |
6745 | else if (b->thread != -1) | |
6746 | printf_filtered (" (thread %d)", b->thread); | |
6747 | printf_filtered ("%s%s ", | |
059fb39f | 6748 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6749 | || b->enable_state == bp_call_disabled) |
0d381245 | 6750 | ? " (disabled)" |
0d381245 VP |
6751 | : ""), |
6752 | (others > 1) ? "," | |
6753 | : ((others == 1) ? " and" : "")); | |
6754 | } | |
6a831f06 PA |
6755 | current_uiout->message (_("also set at pc %ps.\n"), |
6756 | styled_string (address_style.style (), | |
6757 | paddress (gdbarch, pc))); | |
c906108c SS |
6758 | } |
6759 | } | |
6760 | \f | |
c906108c | 6761 | |
cb1e4e32 PA |
6762 | /* Return true iff it is meaningful to use the address member of LOC. |
6763 | For some breakpoint types, the locations' address members are | |
6764 | irrelevant and it makes no sense to attempt to compare them to | |
6765 | other addresses (or use them for any other purpose either). | |
2d134ed3 | 6766 | |
cb1e4e32 PA |
6767 | More specifically, software watchpoints and catchpoints that are |
6768 | not backed by breakpoints always have a zero valued location | |
6769 | address and we don't want to mark breakpoints of any of these types | |
6770 | to be a duplicate of an actual breakpoint location at address | |
6771 | zero. */ | |
e4f237da | 6772 | |
cb1e4e32 PA |
6773 | static bool |
6774 | bl_address_is_meaningful (bp_location *loc) | |
e4f237da | 6775 | { |
cb1e4e32 | 6776 | return loc->loc_type != bp_loc_other; |
2d134ed3 PA |
6777 | } |
6778 | ||
6779 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6780 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6781 | ||
6782 | static int | |
4a64f543 MS |
6783 | watchpoint_locations_match (struct bp_location *loc1, |
6784 | struct bp_location *loc2) | |
2d134ed3 | 6785 | { |
3a5c3e22 PA |
6786 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6787 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6788 | ||
6789 | /* Both of them must exist. */ | |
6790 | gdb_assert (w1 != NULL); | |
6791 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6792 | |
4a64f543 MS |
6793 | /* If the target can evaluate the condition expression in hardware, |
6794 | then we we need to insert both watchpoints even if they are at | |
6795 | the same place. Otherwise the watchpoint will only trigger when | |
6796 | the condition of whichever watchpoint was inserted evaluates to | |
6797 | true, not giving a chance for GDB to check the condition of the | |
6798 | other watchpoint. */ | |
3a5c3e22 | 6799 | if ((w1->cond_exp |
4a64f543 MS |
6800 | && target_can_accel_watchpoint_condition (loc1->address, |
6801 | loc1->length, | |
0cf6dd15 | 6802 | loc1->watchpoint_type, |
4d01a485 | 6803 | w1->cond_exp.get ())) |
3a5c3e22 | 6804 | || (w2->cond_exp |
4a64f543 MS |
6805 | && target_can_accel_watchpoint_condition (loc2->address, |
6806 | loc2->length, | |
0cf6dd15 | 6807 | loc2->watchpoint_type, |
4d01a485 | 6808 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6809 | return 0; |
6810 | ||
85d721b8 PA |
6811 | /* Note that this checks the owner's type, not the location's. In |
6812 | case the target does not support read watchpoints, but does | |
6813 | support access watchpoints, we'll have bp_read_watchpoint | |
6814 | watchpoints with hw_access locations. Those should be considered | |
6815 | duplicates of hw_read locations. The hw_read locations will | |
6816 | become hw_access locations later. */ | |
2d134ed3 PA |
6817 | return (loc1->owner->type == loc2->owner->type |
6818 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6819 | && loc1->address == loc2->address | |
6820 | && loc1->length == loc2->length); | |
e4f237da KB |
6821 | } |
6822 | ||
31e77af2 | 6823 | /* See breakpoint.h. */ |
6c95b8df | 6824 | |
31e77af2 | 6825 | int |
accd0bcd YQ |
6826 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6827 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6828 | { |
f5656ead | 6829 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6830 | || aspace1 == aspace2) |
6831 | && addr1 == addr2); | |
6832 | } | |
6833 | ||
f1310107 TJB |
6834 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6835 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6836 | matches ASPACE2. On targets that have global breakpoints, the address | |
6837 | space doesn't really matter. */ | |
6838 | ||
6839 | static int | |
accd0bcd YQ |
6840 | breakpoint_address_match_range (const address_space *aspace1, |
6841 | CORE_ADDR addr1, | |
6842 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6843 | CORE_ADDR addr2) |
6844 | { | |
f5656ead | 6845 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6846 | || aspace1 == aspace2) |
6847 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6848 | } | |
6849 | ||
6850 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6851 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6852 | matches the breakpoint's address space. On targets that have global | |
6853 | breakpoints, the address space doesn't really matter. */ | |
6854 | ||
6855 | static int | |
6856 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6857 | const address_space *aspace, |
f1310107 TJB |
6858 | CORE_ADDR addr) |
6859 | { | |
6860 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6861 | aspace, addr) | |
6862 | || (bl->length | |
6863 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6864 | bl->address, bl->length, | |
6865 | aspace, addr))); | |
6866 | } | |
6867 | ||
d35ae833 PA |
6868 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6869 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6870 | match happens only if ASPACE matches the breakpoint's address | |
6871 | space. On targets that have global breakpoints, the address space | |
6872 | doesn't really matter. */ | |
6873 | ||
6874 | static int | |
6875 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6876 | const address_space *aspace, |
d35ae833 PA |
6877 | CORE_ADDR addr, int len) |
6878 | { | |
6879 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6880 | || bl->pspace->aspace == aspace) | |
6881 | { | |
6882 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6883 | ||
6884 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6885 | return 1; | |
6886 | } | |
6887 | return 0; | |
6888 | } | |
6889 | ||
1e4d1764 YQ |
6890 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6891 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6892 | true, otherwise returns false. */ | |
6893 | ||
6894 | static int | |
6895 | tracepoint_locations_match (struct bp_location *loc1, | |
6896 | struct bp_location *loc2) | |
6897 | { | |
6898 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6899 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6900 | locations at the same address of different tracepoints are regarded as | |
6901 | different locations. */ | |
6902 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6903 | else | |
6904 | return 0; | |
6905 | } | |
6906 | ||
2d134ed3 | 6907 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
cb1e4e32 | 6908 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
7f32a4d5 PA |
6909 | the same location. If SW_HW_BPS_MATCH is true, then software |
6910 | breakpoint locations and hardware breakpoint locations match, | |
6911 | otherwise they don't. */ | |
2d134ed3 PA |
6912 | |
6913 | static int | |
7f32a4d5 PA |
6914 | breakpoint_locations_match (struct bp_location *loc1, |
6915 | struct bp_location *loc2, | |
6916 | bool sw_hw_bps_match) | |
2d134ed3 | 6917 | { |
2bdf28a0 JK |
6918 | int hw_point1, hw_point2; |
6919 | ||
6920 | /* Both of them must not be in moribund_locations. */ | |
6921 | gdb_assert (loc1->owner != NULL); | |
6922 | gdb_assert (loc2->owner != NULL); | |
6923 | ||
6924 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6925 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6926 | |
6927 | if (hw_point1 != hw_point2) | |
6928 | return 0; | |
6929 | else if (hw_point1) | |
6930 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6931 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6932 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6933 | else |
7f32a4d5 PA |
6934 | /* We compare bp_location.length in order to cover ranged |
6935 | breakpoints. Keep this in sync with | |
6936 | bp_location_is_less_than. */ | |
f1310107 TJB |
6937 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
6938 | loc2->pspace->aspace, loc2->address) | |
7f32a4d5 | 6939 | && (loc1->loc_type == loc2->loc_type || sw_hw_bps_match) |
f1310107 | 6940 | && loc1->length == loc2->length); |
2d134ed3 PA |
6941 | } |
6942 | ||
76897487 KB |
6943 | static void |
6944 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
dda83cd7 | 6945 | int bnum, int have_bnum) |
76897487 | 6946 | { |
f63fbe86 MS |
6947 | /* The longest string possibly returned by hex_string_custom |
6948 | is 50 chars. These must be at least that big for safety. */ | |
6949 | char astr1[64]; | |
6950 | char astr2[64]; | |
76897487 | 6951 | |
bb599908 PH |
6952 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6953 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6954 | if (have_bnum) |
8a3fe4f8 | 6955 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
dda83cd7 | 6956 | bnum, astr1, astr2); |
76897487 | 6957 | else |
8a3fe4f8 | 6958 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6959 | } |
6960 | ||
4a64f543 MS |
6961 | /* Adjust a breakpoint's address to account for architectural |
6962 | constraints on breakpoint placement. Return the adjusted address. | |
6963 | Note: Very few targets require this kind of adjustment. For most | |
6964 | targets, this function is simply the identity function. */ | |
76897487 KB |
6965 | |
6966 | static CORE_ADDR | |
a6d9a66e UW |
6967 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6968 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6969 | { |
a0de8c21 YQ |
6970 | if (bptype == bp_watchpoint |
6971 | || bptype == bp_hardware_watchpoint | |
6972 | || bptype == bp_read_watchpoint | |
6973 | || bptype == bp_access_watchpoint | |
6974 | || bptype == bp_catchpoint) | |
88f7da05 KB |
6975 | { |
6976 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
dda83cd7 | 6977 | have their addresses modified. */ |
88f7da05 KB |
6978 | return bpaddr; |
6979 | } | |
7c16b83e PA |
6980 | else if (bptype == bp_single_step) |
6981 | { | |
6982 | /* Single-step breakpoints should not have their addresses | |
6983 | modified. If there's any architectural constrain that | |
6984 | applies to this address, then it should have already been | |
6985 | taken into account when the breakpoint was created in the | |
6986 | first place. If we didn't do this, stepping through e.g., | |
6987 | Thumb-2 IT blocks would break. */ | |
6988 | return bpaddr; | |
6989 | } | |
76897487 KB |
6990 | else |
6991 | { | |
a0de8c21 YQ |
6992 | CORE_ADDR adjusted_bpaddr = bpaddr; |
6993 | ||
6994 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
6995 | { | |
6996 | /* Some targets have architectural constraints on the placement | |
6997 | of breakpoint instructions. Obtain the adjusted address. */ | |
6998 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
6999 | } | |
76897487 | 7000 | |
a0de8c21 | 7001 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
7002 | |
7003 | /* An adjusted breakpoint address can significantly alter | |
dda83cd7 | 7004 | a user's expectations. Print a warning if an adjustment |
76897487 KB |
7005 | is required. */ |
7006 | if (adjusted_bpaddr != bpaddr) | |
7007 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7008 | ||
7009 | return adjusted_bpaddr; | |
7010 | } | |
7011 | } | |
7012 | ||
cb1e4e32 PA |
7013 | static bp_loc_type |
7014 | bp_location_from_bp_type (bptype type) | |
7cc221ef | 7015 | { |
cb1e4e32 | 7016 | switch (type) |
e049a4b5 DJ |
7017 | { |
7018 | case bp_breakpoint: | |
7c16b83e | 7019 | case bp_single_step: |
e049a4b5 DJ |
7020 | case bp_until: |
7021 | case bp_finish: | |
7022 | case bp_longjmp: | |
7023 | case bp_longjmp_resume: | |
e2e4d78b | 7024 | case bp_longjmp_call_dummy: |
186c406b TT |
7025 | case bp_exception: |
7026 | case bp_exception_resume: | |
e049a4b5 | 7027 | case bp_step_resume: |
2c03e5be | 7028 | case bp_hp_step_resume: |
e049a4b5 DJ |
7029 | case bp_watchpoint_scope: |
7030 | case bp_call_dummy: | |
aa7d318d | 7031 | case bp_std_terminate: |
e049a4b5 DJ |
7032 | case bp_shlib_event: |
7033 | case bp_thread_event: | |
7034 | case bp_overlay_event: | |
4efc6507 | 7035 | case bp_jit_event: |
0fd8e87f | 7036 | case bp_longjmp_master: |
aa7d318d | 7037 | case bp_std_terminate_master: |
186c406b | 7038 | case bp_exception_master: |
0e30163f JK |
7039 | case bp_gnu_ifunc_resolver: |
7040 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7041 | case bp_dprintf: |
cb1e4e32 | 7042 | return bp_loc_software_breakpoint; |
e049a4b5 | 7043 | case bp_hardware_breakpoint: |
cb1e4e32 | 7044 | return bp_loc_hardware_breakpoint; |
e049a4b5 DJ |
7045 | case bp_hardware_watchpoint: |
7046 | case bp_read_watchpoint: | |
7047 | case bp_access_watchpoint: | |
cb1e4e32 | 7048 | return bp_loc_hardware_watchpoint; |
e049a4b5 | 7049 | case bp_watchpoint: |
ce78b96d | 7050 | case bp_catchpoint: |
15c3d785 PA |
7051 | case bp_tracepoint: |
7052 | case bp_fast_tracepoint: | |
0fb4aa4b | 7053 | case bp_static_tracepoint: |
cb1e4e32 | 7054 | return bp_loc_other; |
e049a4b5 | 7055 | default: |
e2e0b3e5 | 7056 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 | 7057 | } |
cb1e4e32 PA |
7058 | } |
7059 | ||
7060 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) | |
7061 | { | |
7062 | this->owner = owner; | |
7063 | this->cond_bytecode = NULL; | |
7064 | this->shlib_disabled = 0; | |
7065 | this->enabled = 1; | |
b5fa468f | 7066 | this->disabled_by_cond = false; |
cb1e4e32 PA |
7067 | |
7068 | this->loc_type = type; | |
e049a4b5 | 7069 | |
cb1e4e32 PA |
7070 | if (this->loc_type == bp_loc_software_breakpoint |
7071 | || this->loc_type == bp_loc_hardware_breakpoint) | |
7072 | mark_breakpoint_location_modified (this); | |
7073 | ||
b6433ede | 7074 | incref (); |
cb1e4e32 PA |
7075 | } |
7076 | ||
7077 | bp_location::bp_location (breakpoint *owner) | |
7078 | : bp_location::bp_location (owner, | |
7079 | bp_location_from_bp_type (owner->type)) | |
7080 | { | |
28010a5d PA |
7081 | } |
7082 | ||
7083 | /* Allocate a struct bp_location. */ | |
7084 | ||
7085 | static struct bp_location * | |
7086 | allocate_bp_location (struct breakpoint *bpt) | |
7087 | { | |
348d480f PA |
7088 | return bpt->ops->allocate_location (bpt); |
7089 | } | |
7cc221ef | 7090 | |
f431efe5 PA |
7091 | /* Decrement reference count. If the reference count reaches 0, |
7092 | destroy the bp_location. Sets *BLP to NULL. */ | |
7093 | ||
7094 | static void | |
7095 | decref_bp_location (struct bp_location **blp) | |
7096 | { | |
b6433ede | 7097 | bp_location_ref_policy::decref (*blp); |
f431efe5 PA |
7098 | *blp = NULL; |
7099 | } | |
7100 | ||
346774a9 | 7101 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7102 | |
b270e6f9 TT |
7103 | static breakpoint * |
7104 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7105 | { |
346774a9 | 7106 | struct breakpoint *b1; |
b270e6f9 | 7107 | struct breakpoint *result = b.get (); |
c906108c | 7108 | |
346774a9 PA |
7109 | /* Add this breakpoint to the end of the chain so that a list of |
7110 | breakpoints will come out in order of increasing numbers. */ | |
7111 | ||
7112 | b1 = breakpoint_chain; | |
7113 | if (b1 == 0) | |
b270e6f9 | 7114 | breakpoint_chain = b.release (); |
346774a9 PA |
7115 | else |
7116 | { | |
7117 | while (b1->next) | |
7118 | b1 = b1->next; | |
b270e6f9 | 7119 | b1->next = b.release (); |
346774a9 | 7120 | } |
b270e6f9 TT |
7121 | |
7122 | return result; | |
346774a9 PA |
7123 | } |
7124 | ||
7125 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7126 | ||
7127 | static void | |
7128 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7129 | struct gdbarch *gdbarch, | |
28010a5d | 7130 | enum bptype bptype, |
c0a91b2b | 7131 | const struct breakpoint_ops *ops) |
346774a9 | 7132 | { |
348d480f PA |
7133 | gdb_assert (ops != NULL); |
7134 | ||
28010a5d | 7135 | b->ops = ops; |
4d28f7a8 | 7136 | b->type = bptype; |
a6d9a66e | 7137 | b->gdbarch = gdbarch; |
c906108c SS |
7138 | b->language = current_language->la_language; |
7139 | b->input_radix = input_radix; | |
d0fb5eae | 7140 | b->related_breakpoint = b; |
346774a9 PA |
7141 | } |
7142 | ||
7143 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7144 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7145 | |
7146 | static struct breakpoint * | |
7147 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7148 | enum bptype bptype, |
c0a91b2b | 7149 | const struct breakpoint_ops *ops) |
346774a9 | 7150 | { |
3b0871f4 | 7151 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7152 | |
3b0871f4 | 7153 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7154 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7155 | } |
7156 | ||
0ba852ab | 7157 | /* Initialize loc->function_name. */ |
0e30163f | 7158 | |
0d381245 | 7159 | static void |
0ba852ab | 7160 | set_breakpoint_location_function (struct bp_location *loc) |
0d381245 | 7161 | { |
2bdf28a0 JK |
7162 | gdb_assert (loc->owner != NULL); |
7163 | ||
0d381245 | 7164 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7165 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7166 | || is_tracepoint (loc->owner)) |
0d381245 | 7167 | { |
2c02bd72 | 7168 | const char *function_name; |
0e30163f | 7169 | |
3467ec66 | 7170 | if (loc->msymbol != NULL |
f50776aa | 7171 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
0ba852ab | 7172 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
0e30163f JK |
7173 | { |
7174 | struct breakpoint *b = loc->owner; | |
7175 | ||
c9d95fa3 | 7176 | function_name = loc->msymbol->linkage_name (); |
3467ec66 PA |
7177 | |
7178 | if (b->type == bp_breakpoint && b->loc == loc | |
7179 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7180 | { |
7181 | /* Create only the whole new breakpoint of this type but do not | |
7182 | mess more complicated breakpoints with multiple locations. */ | |
7183 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b | 7184 | /* Remember the resolver's address for use by the return |
dda83cd7 | 7185 | breakpoint. */ |
3467ec66 | 7186 | loc->related_address = loc->address; |
0e30163f JK |
7187 | } |
7188 | } | |
3467ec66 PA |
7189 | else |
7190 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7191 | |
2c02bd72 | 7192 | if (function_name) |
23d6ee64 | 7193 | loc->function_name = make_unique_xstrdup (function_name); |
0d381245 VP |
7194 | } |
7195 | } | |
7196 | ||
a6d9a66e | 7197 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7198 | struct gdbarch * |
a6d9a66e UW |
7199 | get_sal_arch (struct symtab_and_line sal) |
7200 | { | |
7201 | if (sal.section) | |
08feed99 | 7202 | return sal.section->objfile->arch (); |
a6d9a66e | 7203 | if (sal.symtab) |
08feed99 | 7204 | return SYMTAB_OBJFILE (sal.symtab)->arch (); |
a6d9a66e UW |
7205 | |
7206 | return NULL; | |
7207 | } | |
7208 | ||
346774a9 PA |
7209 | /* Low level routine for partially initializing a breakpoint of type |
7210 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7211 | file name, and line number are provided by SAL. |
0d381245 VP |
7212 | |
7213 | It is expected that the caller will complete the initialization of | |
7214 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7215 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7216 | |
346774a9 PA |
7217 | static void |
7218 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7219 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7220 | const struct breakpoint_ops *ops) |
0d381245 | 7221 | { |
28010a5d | 7222 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7223 | |
3742cc8b | 7224 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7225 | |
6c95b8df PA |
7226 | if (bptype != bp_catchpoint) |
7227 | gdb_assert (sal.pspace != NULL); | |
7228 | ||
f8eba3c6 TT |
7229 | /* Store the program space that was used to set the breakpoint, |
7230 | except for ordinary breakpoints, which are independent of the | |
7231 | program space. */ | |
7232 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7233 | b->pspace = sal.pspace; | |
346774a9 | 7234 | } |
c906108c | 7235 | |
346774a9 PA |
7236 | /* set_raw_breakpoint is a low level routine for allocating and |
7237 | partially initializing a breakpoint of type BPTYPE. The newly | |
7238 | created breakpoint's address, section, source file name, and line | |
7239 | number are provided by SAL. The newly created and partially | |
7240 | initialized breakpoint is added to the breakpoint chain and | |
7241 | is also returned as the value of this function. | |
7242 | ||
7243 | It is expected that the caller will complete the initialization of | |
7244 | the newly created breakpoint struct as well as output any status | |
7245 | information regarding the creation of a new breakpoint. In | |
7246 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7247 | number! Care should be taken to not allow an error to occur | |
7248 | prior to completing the initialization of the breakpoint. If this | |
7249 | should happen, a bogus breakpoint will be left on the chain. */ | |
7250 | ||
cd0f67f3 | 7251 | static struct breakpoint * |
346774a9 | 7252 | set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 7253 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7254 | const struct breakpoint_ops *ops) |
346774a9 | 7255 | { |
3b0871f4 | 7256 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7257 | |
3b0871f4 | 7258 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7259 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7260 | } |
7261 | ||
53a5351d | 7262 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7263 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7264 | initiated the operation. */ | |
c906108c SS |
7265 | |
7266 | void | |
186c406b | 7267 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7268 | { |
5d5658a1 | 7269 | int thread = tp->global_num; |
0fd8e87f UW |
7270 | |
7271 | /* To avoid having to rescan all objfile symbols at every step, | |
7272 | we maintain a list of continually-inserted but always disabled | |
7273 | longjmp "master" breakpoints. Here, we simply create momentary | |
7274 | clones of those and enable them for the requested thread. */ | |
1428b37a | 7275 | for (breakpoint *b : all_breakpoints_safe ()) |
6c95b8df | 7276 | if (b->pspace == current_program_space |
186c406b TT |
7277 | && (b->type == bp_longjmp_master |
7278 | || b->type == bp_exception_master)) | |
0fd8e87f | 7279 | { |
06edf0c0 PA |
7280 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7281 | struct breakpoint *clone; | |
cc59ec59 | 7282 | |
e2e4d78b JK |
7283 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7284 | after their removal. */ | |
06edf0c0 | 7285 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7286 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7287 | clone->thread = thread; |
7288 | } | |
186c406b TT |
7289 | |
7290 | tp->initiating_frame = frame; | |
c906108c SS |
7291 | } |
7292 | ||
611c83ae | 7293 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7294 | void |
611c83ae | 7295 | delete_longjmp_breakpoint (int thread) |
c906108c | 7296 | { |
1428b37a | 7297 | for (breakpoint *b : all_breakpoints_safe ()) |
186c406b | 7298 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7299 | { |
7300 | if (b->thread == thread) | |
7301 | delete_breakpoint (b); | |
7302 | } | |
c906108c SS |
7303 | } |
7304 | ||
f59f708a PA |
7305 | void |
7306 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7307 | { | |
1428b37a | 7308 | for (breakpoint *b : all_breakpoints_safe ()) |
f59f708a PA |
7309 | if (b->type == bp_longjmp || b->type == bp_exception) |
7310 | { | |
7311 | if (b->thread == thread) | |
7312 | b->disposition = disp_del_at_next_stop; | |
7313 | } | |
7314 | } | |
7315 | ||
e2e4d78b JK |
7316 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7317 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7318 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7319 | breakpoints. */ | |
7320 | ||
7321 | struct breakpoint * | |
7322 | set_longjmp_breakpoint_for_call_dummy (void) | |
7323 | { | |
43892fdf | 7324 | breakpoint *retval = nullptr; |
e2e4d78b | 7325 | |
43892fdf | 7326 | for (breakpoint *b : all_breakpoints ()) |
e2e4d78b JK |
7327 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) |
7328 | { | |
7329 | struct breakpoint *new_b; | |
7330 | ||
7331 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7332 | &momentary_breakpoint_ops, |
7333 | 1); | |
00431a78 | 7334 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7335 | |
7336 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7337 | ||
7338 | gdb_assert (new_b->related_breakpoint == new_b); | |
7339 | if (retval == NULL) | |
7340 | retval = new_b; | |
7341 | new_b->related_breakpoint = retval; | |
7342 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7343 | retval = retval->related_breakpoint; | |
7344 | retval->related_breakpoint = new_b; | |
7345 | } | |
7346 | ||
7347 | return retval; | |
7348 | } | |
7349 | ||
7350 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7351 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7352 | stack. |
7353 | ||
b4b3e2de AB |
7354 | If the unwind fails then there is not sufficient information to discard |
7355 | dummy frames. In this case, elide the clean up and the dummy frames will | |
7356 | be cleaned up next time this function is called from a location where | |
7357 | unwinding is possible. */ | |
e2e4d78b JK |
7358 | |
7359 | void | |
b67a2c6f | 7360 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7361 | { |
7362 | struct breakpoint *b, *b_tmp; | |
7363 | ||
7364 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7365 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7366 | { |
7367 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7368 | ||
b4b3e2de AB |
7369 | /* Find the bp_call_dummy breakpoint in the list of breakpoints |
7370 | chained off b->related_breakpoint. */ | |
e2e4d78b JK |
7371 | while (dummy_b != b && dummy_b->type != bp_call_dummy) |
7372 | dummy_b = dummy_b->related_breakpoint; | |
b4b3e2de AB |
7373 | |
7374 | /* If there was no bp_call_dummy breakpoint then there's nothing | |
7375 | more to do. Or, if the dummy frame associated with the | |
7376 | bp_call_dummy is still on the stack then we need to leave this | |
7377 | bp_call_dummy in place. */ | |
e2e4d78b JK |
7378 | if (dummy_b->type != bp_call_dummy |
7379 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7380 | continue; | |
b4b3e2de AB |
7381 | |
7382 | /* We didn't find the dummy frame on the stack, this could be | |
7383 | because we have longjmp'd to a stack frame that is previous to | |
7384 | the dummy frame, or it could be because the stack unwind is | |
7385 | broken at some point between the longjmp frame and the dummy | |
7386 | frame. | |
7387 | ||
7388 | Next we figure out why the stack unwind stopped. If it looks | |
7389 | like the unwind is complete then we assume the dummy frame has | |
7390 | been jumped over, however, if the unwind stopped for an | |
7391 | unexpected reason then we assume the stack unwind is currently | |
7392 | broken, and that we will (eventually) return to the dummy | |
7393 | frame. | |
7394 | ||
7395 | It might be tempting to consider using frame_id_inner here, but | |
7396 | that is not safe. There is no guarantee that the stack frames | |
7397 | we are looking at here are even on the same stack as the | |
7398 | original dummy frame, hence frame_id_inner can't be used. See | |
7399 | the comments on frame_id_inner for more details. */ | |
7400 | bool unwind_finished_unexpectedly = false; | |
7401 | for (struct frame_info *fi = get_current_frame (); fi != nullptr; ) | |
7402 | { | |
7403 | struct frame_info *prev = get_prev_frame (fi); | |
7404 | if (prev == nullptr) | |
7405 | { | |
7406 | /* FI is the last stack frame. Why did this frame not | |
7407 | unwind further? */ | |
7408 | auto stop_reason = get_frame_unwind_stop_reason (fi); | |
7409 | if (stop_reason != UNWIND_NO_REASON | |
7410 | && stop_reason != UNWIND_OUTERMOST) | |
7411 | unwind_finished_unexpectedly = true; | |
7412 | } | |
7413 | fi = prev; | |
7414 | } | |
7415 | if (unwind_finished_unexpectedly) | |
7416 | continue; | |
7417 | ||
00431a78 | 7418 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7419 | |
7420 | while (b->related_breakpoint != b) | |
7421 | { | |
7422 | if (b_tmp == b->related_breakpoint) | |
7423 | b_tmp = b->related_breakpoint->next; | |
7424 | delete_breakpoint (b->related_breakpoint); | |
7425 | } | |
7426 | delete_breakpoint (b); | |
7427 | } | |
7428 | } | |
7429 | ||
1900040c MS |
7430 | void |
7431 | enable_overlay_breakpoints (void) | |
7432 | { | |
43892fdf | 7433 | for (breakpoint *b : all_breakpoints ()) |
1900040c | 7434 | if (b->type == bp_overlay_event) |
01add95b SM |
7435 | { |
7436 | b->enable_state = bp_enabled; | |
7437 | update_global_location_list (UGLL_MAY_INSERT); | |
7438 | overlay_events_enabled = 1; | |
7439 | } | |
1900040c MS |
7440 | } |
7441 | ||
7442 | void | |
7443 | disable_overlay_breakpoints (void) | |
7444 | { | |
43892fdf | 7445 | for (breakpoint *b : all_breakpoints ()) |
1900040c | 7446 | if (b->type == bp_overlay_event) |
01add95b SM |
7447 | { |
7448 | b->enable_state = bp_disabled; | |
7449 | update_global_location_list (UGLL_DONT_INSERT); | |
7450 | overlay_events_enabled = 0; | |
7451 | } | |
1900040c MS |
7452 | } |
7453 | ||
aa7d318d TT |
7454 | /* Set an active std::terminate breakpoint for each std::terminate |
7455 | master breakpoint. */ | |
7456 | void | |
7457 | set_std_terminate_breakpoint (void) | |
7458 | { | |
1428b37a | 7459 | for (breakpoint *b : all_breakpoints_safe ()) |
aa7d318d TT |
7460 | if (b->pspace == current_program_space |
7461 | && b->type == bp_std_terminate_master) | |
7462 | { | |
06edf0c0 | 7463 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7464 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7465 | } |
7466 | } | |
7467 | ||
7468 | /* Delete all the std::terminate breakpoints. */ | |
7469 | void | |
7470 | delete_std_terminate_breakpoint (void) | |
7471 | { | |
1428b37a | 7472 | for (breakpoint *b : all_breakpoints_safe ()) |
aa7d318d TT |
7473 | if (b->type == bp_std_terminate) |
7474 | delete_breakpoint (b); | |
7475 | } | |
7476 | ||
c4093a6a | 7477 | struct breakpoint * |
a6d9a66e | 7478 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7479 | { |
7480 | struct breakpoint *b; | |
c4093a6a | 7481 | |
06edf0c0 PA |
7482 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7483 | &internal_breakpoint_ops); | |
7484 | ||
b5de0fa7 | 7485 | b->enable_state = bp_enabled; |
f00aae0f | 7486 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7487 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7488 | |
44702360 | 7489 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7490 | |
c4093a6a JM |
7491 | return b; |
7492 | } | |
7493 | ||
0101ce28 JJ |
7494 | struct lang_and_radix |
7495 | { | |
7496 | enum language lang; | |
7497 | int radix; | |
7498 | }; | |
7499 | ||
4efc6507 DE |
7500 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7501 | ||
7502 | struct breakpoint * | |
7503 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7504 | { | |
2a7f3dff PA |
7505 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7506 | &internal_breakpoint_ops); | |
4efc6507 | 7507 | } |
0101ce28 | 7508 | |
03673fc7 PP |
7509 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7510 | ||
7511 | void | |
7512 | remove_jit_event_breakpoints (void) | |
7513 | { | |
1428b37a | 7514 | for (breakpoint *b : all_breakpoints_safe ()) |
03673fc7 PP |
7515 | if (b->type == bp_jit_event |
7516 | && b->loc->pspace == current_program_space) | |
7517 | delete_breakpoint (b); | |
7518 | } | |
7519 | ||
cae688ec JJ |
7520 | void |
7521 | remove_solib_event_breakpoints (void) | |
7522 | { | |
1428b37a | 7523 | for (breakpoint *b : all_breakpoints_safe ()) |
6c95b8df PA |
7524 | if (b->type == bp_shlib_event |
7525 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7526 | delete_breakpoint (b); |
7527 | } | |
7528 | ||
f37f681c PA |
7529 | /* See breakpoint.h. */ |
7530 | ||
7531 | void | |
7532 | remove_solib_event_breakpoints_at_next_stop (void) | |
7533 | { | |
1428b37a | 7534 | for (breakpoint *b : all_breakpoints_safe ()) |
f37f681c PA |
7535 | if (b->type == bp_shlib_event |
7536 | && b->loc->pspace == current_program_space) | |
7537 | b->disposition = disp_del_at_next_stop; | |
7538 | } | |
7539 | ||
04086b45 PA |
7540 | /* Helper for create_solib_event_breakpoint / |
7541 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7542 | INSERT_MODE to pass through to update_global_location_list. */ | |
7543 | ||
7544 | static struct breakpoint * | |
7545 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7546 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7547 | { |
7548 | struct breakpoint *b; | |
7549 | ||
06edf0c0 PA |
7550 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7551 | &internal_breakpoint_ops); | |
04086b45 | 7552 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7553 | return b; |
7554 | } | |
7555 | ||
04086b45 PA |
7556 | struct breakpoint * |
7557 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7558 | { | |
7559 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7560 | } | |
7561 | ||
f37f681c PA |
7562 | /* See breakpoint.h. */ |
7563 | ||
7564 | struct breakpoint * | |
7565 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7566 | { | |
7567 | struct breakpoint *b; | |
7568 | ||
04086b45 PA |
7569 | /* Explicitly tell update_global_location_list to insert |
7570 | locations. */ | |
7571 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7572 | if (!b->loc->inserted) |
7573 | { | |
7574 | delete_breakpoint (b); | |
7575 | return NULL; | |
7576 | } | |
7577 | return b; | |
7578 | } | |
7579 | ||
cae688ec JJ |
7580 | /* Disable any breakpoints that are on code in shared libraries. Only |
7581 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7582 | ||
7583 | void | |
cb851954 | 7584 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7585 | { |
48d7020b | 7586 | for (bp_location *loc : all_bp_locations ()) |
01add95b SM |
7587 | { |
7588 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ | |
7589 | struct breakpoint *b = loc->owner; | |
7590 | ||
7591 | /* We apply the check to all breakpoints, including disabled for | |
7592 | those with loc->duplicate set. This is so that when breakpoint | |
7593 | becomes enabled, or the duplicate is removed, gdb will try to | |
7594 | insert all breakpoints. If we don't set shlib_disabled here, | |
7595 | we'll try to insert those breakpoints and fail. */ | |
7596 | if (((b->type == bp_breakpoint) | |
7597 | || (b->type == bp_jit_event) | |
7598 | || (b->type == bp_hardware_breakpoint) | |
7599 | || (is_tracepoint (b))) | |
7600 | && loc->pspace == current_program_space | |
7601 | && !loc->shlib_disabled | |
7602 | && solib_name_from_address (loc->pspace, loc->address) | |
7603 | ) | |
7604 | { | |
7605 | loc->shlib_disabled = 1; | |
7606 | } | |
7607 | } | |
cae688ec JJ |
7608 | } |
7609 | ||
63644780 NB |
7610 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7611 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7612 | disabled ones can just stay disabled. */ | |
84acb35a | 7613 | |
75149521 | 7614 | static void |
84acb35a JJ |
7615 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7616 | { | |
84acb35a JJ |
7617 | int disabled_shlib_breaks = 0; |
7618 | ||
48d7020b | 7619 | for (bp_location *loc : all_bp_locations ()) |
01add95b SM |
7620 | { |
7621 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ | |
7622 | struct breakpoint *b = loc->owner; | |
7623 | ||
7624 | if (solib->pspace == loc->pspace | |
7625 | && !loc->shlib_disabled | |
7626 | && (((b->type == bp_breakpoint | |
7627 | || b->type == bp_jit_event | |
7628 | || b->type == bp_hardware_breakpoint) | |
7629 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7630 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7631 | || is_tracepoint (b)) | |
7632 | && solib_contains_address_p (solib, loc->address)) | |
7633 | { | |
7634 | loc->shlib_disabled = 1; | |
7635 | /* At this point, we cannot rely on remove_breakpoint | |
7636 | succeeding so we must mark the breakpoint as not inserted | |
7637 | to prevent future errors occurring in remove_breakpoints. */ | |
7638 | loc->inserted = 0; | |
7639 | ||
7640 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7641 | gdb::observers::breakpoint_modified.notify (b); | |
7642 | ||
7643 | if (!disabled_shlib_breaks) | |
7644 | { | |
7645 | target_terminal::ours_for_output (); | |
7646 | warning (_("Temporarily disabling breakpoints " | |
7647 | "for unloaded shared library \"%s\""), | |
7648 | solib->so_name); | |
7649 | } | |
7650 | disabled_shlib_breaks = 1; | |
7651 | } | |
7652 | } | |
84acb35a JJ |
7653 | } |
7654 | ||
63644780 NB |
7655 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7656 | notification of free_objfile. Only apply to enabled breakpoints, | |
7657 | disabled ones can just stay disabled. */ | |
7658 | ||
7659 | static void | |
7660 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7661 | { | |
63644780 NB |
7662 | if (objfile == NULL) |
7663 | return; | |
7664 | ||
d03de421 PA |
7665 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7666 | managed by the user with add-symbol-file/remove-symbol-file. | |
7667 | Similarly to how breakpoints in shared libraries are handled in | |
7668 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7669 | shlib_disabled so they end up uninserted on the next global |
7670 | location list update. Shared libraries not loaded by the user | |
7671 | aren't handled here -- they're already handled in | |
7672 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7673 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7674 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7675 | main objfile). */ | |
7676 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7677 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7678 | return; |
7679 | ||
43892fdf | 7680 | for (breakpoint *b : all_breakpoints ()) |
63644780 | 7681 | { |
63644780 NB |
7682 | int bp_modified = 0; |
7683 | ||
7684 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7685 | continue; | |
7686 | ||
40cb8ca5 | 7687 | for (bp_location *loc : b->locations ()) |
63644780 NB |
7688 | { |
7689 | CORE_ADDR loc_addr = loc->address; | |
7690 | ||
7691 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7692 | && loc->loc_type != bp_loc_software_breakpoint) | |
7693 | continue; | |
7694 | ||
7695 | if (loc->shlib_disabled != 0) | |
7696 | continue; | |
7697 | ||
7698 | if (objfile->pspace != loc->pspace) | |
7699 | continue; | |
7700 | ||
7701 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7702 | && loc->loc_type != bp_loc_software_breakpoint) | |
7703 | continue; | |
7704 | ||
7705 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7706 | { | |
7707 | loc->shlib_disabled = 1; | |
08351840 PA |
7708 | /* At this point, we don't know whether the object was |
7709 | unmapped from the inferior or not, so leave the | |
7710 | inserted flag alone. We'll handle failure to | |
7711 | uninsert quietly, in case the object was indeed | |
7712 | unmapped. */ | |
63644780 NB |
7713 | |
7714 | mark_breakpoint_location_modified (loc); | |
7715 | ||
7716 | bp_modified = 1; | |
7717 | } | |
7718 | } | |
7719 | ||
7720 | if (bp_modified) | |
76727919 | 7721 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7722 | } |
7723 | } | |
7724 | ||
edcc5120 | 7725 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 7726 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
7727 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
7728 | ||
c1fc2657 | 7729 | struct solib_catchpoint : public breakpoint |
edcc5120 | 7730 | { |
edcc5120 | 7731 | /* True for "catch load", false for "catch unload". */ |
b650a282 | 7732 | bool is_load; |
edcc5120 TT |
7733 | |
7734 | /* Regular expression to match, if any. COMPILED is only valid when | |
7735 | REGEX is non-NULL. */ | |
b00577cd | 7736 | gdb::unique_xmalloc_ptr<char> regex; |
2d7cc5c7 | 7737 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
7738 | }; |
7739 | ||
edcc5120 TT |
7740 | static int |
7741 | insert_catch_solib (struct bp_location *ignore) | |
7742 | { | |
7743 | return 0; | |
7744 | } | |
7745 | ||
7746 | static int | |
73971819 | 7747 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
7748 | { |
7749 | return 0; | |
7750 | } | |
7751 | ||
7752 | static int | |
7753 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 7754 | const address_space *aspace, |
edcc5120 | 7755 | CORE_ADDR bp_addr, |
c272a98c | 7756 | const target_waitstatus &ws) |
edcc5120 TT |
7757 | { |
7758 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
edcc5120 | 7759 | |
c272a98c | 7760 | if (ws.kind () == TARGET_WAITKIND_LOADED) |
edcc5120 TT |
7761 | return 1; |
7762 | ||
43892fdf | 7763 | for (breakpoint *other : all_breakpoints ()) |
01add95b SM |
7764 | { |
7765 | if (other == bl->owner) | |
7766 | continue; | |
edcc5120 | 7767 | |
01add95b SM |
7768 | if (other->type != bp_shlib_event) |
7769 | continue; | |
edcc5120 | 7770 | |
01add95b SM |
7771 | if (self->pspace != NULL && other->pspace != self->pspace) |
7772 | continue; | |
edcc5120 | 7773 | |
01add95b SM |
7774 | for (bp_location *other_bl : other->locations ()) |
7775 | { | |
7776 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7777 | return 1; | |
7778 | } | |
7779 | } | |
edcc5120 TT |
7780 | |
7781 | return 0; | |
7782 | } | |
7783 | ||
7784 | static void | |
313f3b21 | 7785 | check_status_catch_solib (struct bpstat *bs) |
edcc5120 TT |
7786 | { |
7787 | struct solib_catchpoint *self | |
7788 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
edcc5120 TT |
7789 | |
7790 | if (self->is_load) | |
7791 | { | |
52941706 | 7792 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 TT |
7793 | { |
7794 | if (!self->regex | |
2d7cc5c7 | 7795 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
7796 | return; |
7797 | } | |
7798 | } | |
7799 | else | |
7800 | { | |
6fb16ce6 | 7801 | for (const std::string &iter : current_program_space->deleted_solibs) |
edcc5120 TT |
7802 | { |
7803 | if (!self->regex | |
6fb16ce6 | 7804 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
edcc5120 TT |
7805 | return; |
7806 | } | |
7807 | } | |
7808 | ||
7809 | bs->stop = 0; | |
7810 | bs->print_it = print_it_noop; | |
7811 | } | |
7812 | ||
7813 | static enum print_stop_action | |
313f3b21 | 7814 | print_it_catch_solib (bpstat *bs) |
edcc5120 TT |
7815 | { |
7816 | struct breakpoint *b = bs->breakpoint_at; | |
7817 | struct ui_out *uiout = current_uiout; | |
7818 | ||
7819 | annotate_catchpoint (b->number); | |
f303dbd6 | 7820 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 7821 | if (b->disposition == disp_del) |
112e8700 | 7822 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 7823 | else |
112e8700 | 7824 | uiout->text ("Catchpoint "); |
381befee | 7825 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
7826 | uiout->text ("\n"); |
7827 | if (uiout->is_mi_like_p ()) | |
7828 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
7829 | print_solib_event (1); |
7830 | return PRINT_SRC_AND_LOC; | |
7831 | } | |
7832 | ||
7833 | static void | |
7834 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7835 | { | |
7836 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7837 | struct value_print_options opts; | |
7838 | struct ui_out *uiout = current_uiout; | |
edcc5120 TT |
7839 | |
7840 | get_user_print_options (&opts); | |
7841 | /* Field 4, the address, is omitted (which makes the columns not | |
7842 | line up too nicely with the headers, but the effect is relatively | |
7843 | readable). */ | |
7844 | if (opts.addressprint) | |
7845 | { | |
7846 | annotate_field (4); | |
112e8700 | 7847 | uiout->field_skip ("addr"); |
edcc5120 TT |
7848 | } |
7849 | ||
528e1572 | 7850 | std::string msg; |
edcc5120 TT |
7851 | annotate_field (5); |
7852 | if (self->is_load) | |
7853 | { | |
7854 | if (self->regex) | |
b00577cd TT |
7855 | msg = string_printf (_("load of library matching %s"), |
7856 | self->regex.get ()); | |
edcc5120 | 7857 | else |
528e1572 | 7858 | msg = _("load of library"); |
edcc5120 TT |
7859 | } |
7860 | else | |
7861 | { | |
7862 | if (self->regex) | |
b00577cd TT |
7863 | msg = string_printf (_("unload of library matching %s"), |
7864 | self->regex.get ()); | |
edcc5120 | 7865 | else |
528e1572 | 7866 | msg = _("unload of library"); |
edcc5120 | 7867 | } |
112e8700 | 7868 | uiout->field_string ("what", msg); |
8ac3646f | 7869 | |
112e8700 SM |
7870 | if (uiout->is_mi_like_p ()) |
7871 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
7872 | } |
7873 | ||
7874 | static void | |
7875 | print_mention_catch_solib (struct breakpoint *b) | |
7876 | { | |
7877 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7878 | ||
7879 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
7880 | self->is_load ? "load" : "unload"); | |
7881 | } | |
7882 | ||
7883 | static void | |
7884 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
7885 | { | |
7886 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7887 | ||
7888 | fprintf_unfiltered (fp, "%s %s", | |
7889 | b->disposition == disp_del ? "tcatch" : "catch", | |
7890 | self->is_load ? "load" : "unload"); | |
7891 | if (self->regex) | |
b00577cd | 7892 | fprintf_unfiltered (fp, " %s", self->regex.get ()); |
edcc5120 TT |
7893 | fprintf_unfiltered (fp, "\n"); |
7894 | } | |
7895 | ||
7896 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
7897 | ||
b650a282 | 7898 | /* See breakpoint.h. */ |
edcc5120 | 7899 | |
91985142 | 7900 | void |
b650a282 | 7901 | add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled) |
edcc5120 | 7902 | { |
edcc5120 | 7903 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 7904 | |
edcc5120 TT |
7905 | if (!arg) |
7906 | arg = ""; | |
f1735a53 | 7907 | arg = skip_spaces (arg); |
edcc5120 | 7908 | |
36bd8eaa | 7909 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
7910 | |
7911 | if (*arg != '\0') | |
7912 | { | |
2d7cc5c7 PA |
7913 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
7914 | _("Invalid regexp"))); | |
b00577cd | 7915 | c->regex = make_unique_xstrdup (arg); |
edcc5120 TT |
7916 | } |
7917 | ||
7918 | c->is_load = is_load; | |
36bd8eaa | 7919 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
7920 | &catch_solib_breakpoint_ops); |
7921 | ||
c1fc2657 | 7922 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 7923 | |
b270e6f9 | 7924 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
7925 | } |
7926 | ||
91985142 MG |
7927 | /* A helper function that does all the work for "catch load" and |
7928 | "catch unload". */ | |
7929 | ||
7930 | static void | |
eb4c3f4a | 7931 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
7932 | struct cmd_list_element *command) |
7933 | { | |
91985142 | 7934 | const int enabled = 1; |
0f8e2034 | 7935 | bool temp = command->context () == CATCH_TEMPORARY; |
91985142 | 7936 | |
b650a282 | 7937 | add_solib_catchpoint (arg, is_load, temp, enabled); |
91985142 MG |
7938 | } |
7939 | ||
edcc5120 | 7940 | static void |
eb4c3f4a | 7941 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
7942 | struct cmd_list_element *command) |
7943 | { | |
7944 | catch_load_or_unload (arg, from_tty, 1, command); | |
7945 | } | |
7946 | ||
7947 | static void | |
eb4c3f4a | 7948 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
7949 | struct cmd_list_element *command) |
7950 | { | |
7951 | catch_load_or_unload (arg, from_tty, 0, command); | |
7952 | } | |
7953 | ||
b650a282 | 7954 | /* See breakpoint.h. */ |
ce78b96d | 7955 | |
ab04a2af | 7956 | void |
346774a9 | 7957 | init_catchpoint (struct breakpoint *b, |
b650a282 | 7958 | struct gdbarch *gdbarch, bool temp, |
63160a43 | 7959 | const char *cond_string, |
c0a91b2b | 7960 | const struct breakpoint_ops *ops) |
c906108c | 7961 | { |
51abb421 | 7962 | symtab_and_line sal; |
6c95b8df | 7963 | sal.pspace = current_program_space; |
c5aa993b | 7964 | |
28010a5d | 7965 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 7966 | |
6f781ee3 TT |
7967 | if (cond_string == nullptr) |
7968 | b->cond_string.reset (); | |
7969 | else | |
7970 | b->cond_string = make_unique_xstrdup (cond_string); | |
b650a282 | 7971 | b->disposition = temp ? disp_del : disp_donttouch; |
346774a9 PA |
7972 | } |
7973 | ||
28010a5d | 7974 | void |
b270e6f9 | 7975 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 7976 | { |
b270e6f9 | 7977 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 7978 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
7979 | if (is_tracepoint (b)) |
7980 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
7981 | if (!internal) |
7982 | mention (b); | |
76727919 | 7983 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
7984 | |
7985 | if (update_gll) | |
44702360 | 7986 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
7987 | } |
7988 | ||
c906108c | 7989 | static int |
fba45db2 | 7990 | hw_breakpoint_used_count (void) |
c906108c | 7991 | { |
c906108c SS |
7992 | int i = 0; |
7993 | ||
43892fdf | 7994 | for (breakpoint *b : all_breakpoints ()) |
d6b74ac4 | 7995 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
40cb8ca5 | 7996 | for (bp_location *bl : b->locations ()) |
f1310107 TJB |
7997 | { |
7998 | /* Special types of hardware breakpoints may use more than | |
7999 | one register. */ | |
348d480f | 8000 | i += b->ops->resources_needed (bl); |
f1310107 | 8001 | } |
c906108c SS |
8002 | |
8003 | return i; | |
8004 | } | |
8005 | ||
a1398e0c PA |
8006 | /* Returns the resources B would use if it were a hardware |
8007 | watchpoint. */ | |
8008 | ||
c906108c | 8009 | static int |
a1398e0c | 8010 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8011 | { |
c906108c SS |
8012 | int i = 0; |
8013 | ||
a1398e0c PA |
8014 | if (!breakpoint_enabled (b)) |
8015 | return 0; | |
8016 | ||
40cb8ca5 | 8017 | for (bp_location *bl : b->locations ()) |
a1398e0c PA |
8018 | { |
8019 | /* Special types of hardware watchpoints may use more than | |
8020 | one register. */ | |
8021 | i += b->ops->resources_needed (bl); | |
8022 | } | |
8023 | ||
8024 | return i; | |
8025 | } | |
8026 | ||
8027 | /* Returns the sum the used resources of all hardware watchpoints of | |
8028 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8029 | the sum of the used resources of all hardware watchpoints of other | |
8030 | types _not_ TYPE. */ | |
8031 | ||
8032 | static int | |
8033 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8034 | enum bptype type, int *other_type_used) | |
8035 | { | |
8036 | int i = 0; | |
a1398e0c | 8037 | |
c906108c | 8038 | *other_type_used = 0; |
43892fdf | 8039 | for (breakpoint *b : all_breakpoints ()) |
e09342b5 | 8040 | { |
a1398e0c PA |
8041 | if (b == except) |
8042 | continue; | |
e09342b5 TJB |
8043 | if (!breakpoint_enabled (b)) |
8044 | continue; | |
8045 | ||
a1398e0c PA |
8046 | if (b->type == type) |
8047 | i += hw_watchpoint_use_count (b); | |
8048 | else if (is_hardware_watchpoint (b)) | |
8049 | *other_type_used = 1; | |
e09342b5 TJB |
8050 | } |
8051 | ||
c906108c SS |
8052 | return i; |
8053 | } | |
8054 | ||
c906108c | 8055 | void |
fba45db2 | 8056 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8057 | { |
43892fdf | 8058 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 8059 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8060 | { |
b5de0fa7 | 8061 | b->enable_state = bp_call_disabled; |
44702360 | 8062 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b | 8063 | } |
c906108c SS |
8064 | } |
8065 | ||
8066 | void | |
fba45db2 | 8067 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8068 | { |
43892fdf | 8069 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 8070 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8071 | { |
b5de0fa7 | 8072 | b->enable_state = bp_enabled; |
44702360 | 8073 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b | 8074 | } |
c906108c SS |
8075 | } |
8076 | ||
8bea4e01 UW |
8077 | void |
8078 | disable_breakpoints_before_startup (void) | |
8079 | { | |
6c95b8df | 8080 | current_program_space->executing_startup = 1; |
44702360 | 8081 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8082 | } |
8083 | ||
8084 | void | |
8085 | enable_breakpoints_after_startup (void) | |
8086 | { | |
6c95b8df | 8087 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8088 | breakpoint_re_set (); |
8bea4e01 UW |
8089 | } |
8090 | ||
7c16b83e PA |
8091 | /* Create a new single-step breakpoint for thread THREAD, with no |
8092 | locations. */ | |
c906108c | 8093 | |
7c16b83e PA |
8094 | static struct breakpoint * |
8095 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8096 | { | |
b270e6f9 | 8097 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8098 | |
b270e6f9 | 8099 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8100 | &momentary_breakpoint_ops); |
8101 | ||
8102 | b->disposition = disp_donttouch; | |
8103 | b->frame_id = null_frame_id; | |
8104 | ||
8105 | b->thread = thread; | |
8106 | gdb_assert (b->thread != 0); | |
8107 | ||
b270e6f9 | 8108 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8109 | } |
8110 | ||
8111 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8112 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8113 | frame. */ | |
c906108c | 8114 | |
454dafbd | 8115 | breakpoint_up |
a6d9a66e UW |
8116 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8117 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8118 | { |
52f0bd74 | 8119 | struct breakpoint *b; |
edb3359d | 8120 | |
193facb3 JK |
8121 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8122 | tail-called one. */ | |
8123 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8124 | |
06edf0c0 | 8125 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8126 | b->enable_state = bp_enabled; |
8127 | b->disposition = disp_donttouch; | |
818dd999 | 8128 | b->frame_id = frame_id; |
c906108c | 8129 | |
00431a78 | 8130 | b->thread = inferior_thread ()->global_num; |
c906108c | 8131 | |
44702360 | 8132 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8133 | |
454dafbd | 8134 | return breakpoint_up (b); |
c906108c | 8135 | } |
611c83ae | 8136 | |
06edf0c0 | 8137 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8138 | The new breakpoint will have type TYPE, use OPS as its |
8139 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8140 | |
06edf0c0 PA |
8141 | static struct breakpoint * |
8142 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8143 | enum bptype type, | |
a1aa2221 LM |
8144 | const struct breakpoint_ops *ops, |
8145 | int loc_enabled) | |
e58b0e63 PA |
8146 | { |
8147 | struct breakpoint *copy; | |
8148 | ||
06edf0c0 | 8149 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8150 | copy->loc = allocate_bp_location (copy); |
0ba852ab | 8151 | set_breakpoint_location_function (copy->loc); |
e58b0e63 | 8152 | |
a6d9a66e | 8153 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8154 | copy->loc->requested_address = orig->loc->requested_address; |
8155 | copy->loc->address = orig->loc->address; | |
8156 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8157 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8158 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8159 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8160 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8161 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8162 | copy->frame_id = orig->frame_id; |
8163 | copy->thread = orig->thread; | |
6c95b8df | 8164 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8165 | |
8166 | copy->enable_state = bp_enabled; | |
8167 | copy->disposition = disp_donttouch; | |
8168 | copy->number = internal_breakpoint_number--; | |
8169 | ||
44702360 | 8170 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8171 | return copy; |
8172 | } | |
8173 | ||
06edf0c0 PA |
8174 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8175 | ORIG is NULL. */ | |
8176 | ||
8177 | struct breakpoint * | |
8178 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8179 | { | |
8180 | /* If there's nothing to clone, then return nothing. */ | |
8181 | if (orig == NULL) | |
8182 | return NULL; | |
8183 | ||
a1aa2221 | 8184 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8185 | } |
8186 | ||
454dafbd | 8187 | breakpoint_up |
a6d9a66e UW |
8188 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8189 | enum bptype type) | |
611c83ae PA |
8190 | { |
8191 | struct symtab_and_line sal; | |
8192 | ||
8193 | sal = find_pc_line (pc, 0); | |
8194 | sal.pc = pc; | |
8195 | sal.section = find_pc_overlay (pc); | |
8196 | sal.explicit_pc = 1; | |
8197 | ||
a6d9a66e | 8198 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8199 | } |
c906108c | 8200 | \f |
c5aa993b | 8201 | |
c906108c SS |
8202 | /* Tell the user we have just set a breakpoint B. */ |
8203 | ||
8204 | static void | |
fba45db2 | 8205 | mention (struct breakpoint *b) |
c906108c | 8206 | { |
348d480f | 8207 | b->ops->print_mention (b); |
2d33446d | 8208 | current_uiout->text ("\n"); |
c906108c | 8209 | } |
c906108c | 8210 | \f |
c5aa993b | 8211 | |
5133a315 | 8212 | static bool bp_loc_is_permanent (struct bp_location *loc); |
1a853c52 | 8213 | |
7f32a4d5 PA |
8214 | /* Handle "set breakpoint auto-hw on". |
8215 | ||
8216 | If the explicitly specified breakpoint type is not hardware | |
8217 | breakpoint, check the memory map to see whether the breakpoint | |
8218 | address is in read-only memory. | |
8219 | ||
8220 | - location type is not hardware breakpoint, memory is read-only. | |
8221 | We change the type of the location to hardware breakpoint. | |
8222 | ||
8223 | - location type is hardware breakpoint, memory is read-write. This | |
8224 | means we've previously made the location hardware one, but then the | |
8225 | memory map changed, so we undo. | |
8226 | */ | |
8227 | ||
8228 | static void | |
8229 | handle_automatic_hardware_breakpoints (bp_location *bl) | |
8230 | { | |
8231 | if (automatic_hardware_breakpoints | |
8232 | && bl->owner->type != bp_hardware_breakpoint | |
8233 | && (bl->loc_type == bp_loc_software_breakpoint | |
8234 | || bl->loc_type == bp_loc_hardware_breakpoint)) | |
8235 | { | |
8236 | /* When breakpoints are removed, remove_breakpoints will use | |
8237 | location types we've just set here, the only possible problem | |
8238 | is that memory map has changed during running program, but | |
8239 | it's not going to work anyway with current gdb. */ | |
8240 | mem_region *mr = lookup_mem_region (bl->address); | |
8241 | ||
8242 | if (mr != nullptr) | |
8243 | { | |
8244 | enum bp_loc_type new_type; | |
8245 | ||
8246 | if (mr->attrib.mode != MEM_RW) | |
8247 | new_type = bp_loc_hardware_breakpoint; | |
8248 | else | |
8249 | new_type = bp_loc_software_breakpoint; | |
8250 | ||
8251 | if (new_type != bl->loc_type) | |
8252 | { | |
8253 | static bool said = false; | |
8254 | ||
8255 | bl->loc_type = new_type; | |
8256 | if (!said) | |
8257 | { | |
d4396e0e TT |
8258 | printf_filtered (_("Note: automatically using " |
8259 | "hardware breakpoints for " | |
8260 | "read-only addresses.\n")); | |
7f32a4d5 PA |
8261 | said = true; |
8262 | } | |
8263 | } | |
8264 | } | |
8265 | } | |
8266 | } | |
8267 | ||
0d381245 | 8268 | static struct bp_location * |
39d61571 | 8269 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8270 | const struct symtab_and_line *sal) |
8271 | { | |
8272 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8273 | CORE_ADDR adjusted_address; |
8274 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8275 | ||
8276 | if (loc_gdbarch == NULL) | |
8277 | loc_gdbarch = b->gdbarch; | |
8278 | ||
8279 | /* Adjust the breakpoint's address prior to allocating a location. | |
8280 | Once we call allocate_bp_location(), that mostly uninitialized | |
8281 | location will be placed on the location chain. Adjustment of the | |
8282 | breakpoint may cause target_read_memory() to be called and we do | |
8283 | not want its scan of the location chain to find a breakpoint and | |
8284 | location that's only been partially initialized. */ | |
8285 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8286 | sal->pc, b->type); | |
0d381245 | 8287 | |
d30113d4 | 8288 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8289 | loc = allocate_bp_location (b); |
d30113d4 JK |
8290 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8291 | tmp = &((*tmp)->next)) | |
0d381245 | 8292 | ; |
d30113d4 | 8293 | loc->next = *tmp; |
0d381245 | 8294 | *tmp = loc; |
3742cc8b | 8295 | |
0d381245 | 8296 | loc->requested_address = sal->pc; |
3742cc8b | 8297 | loc->address = adjusted_address; |
6c95b8df | 8298 | loc->pspace = sal->pspace; |
935676c9 | 8299 | loc->probe.prob = sal->prob; |
729662a5 | 8300 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8301 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8302 | loc->section = sal->section; |
3742cc8b | 8303 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8304 | loc->line_number = sal->line; |
2f202fde | 8305 | loc->symtab = sal->symtab; |
4a27f119 | 8306 | loc->symbol = sal->symbol; |
3467ec66 PA |
8307 | loc->msymbol = sal->msymbol; |
8308 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8309 | |
0ba852ab | 8310 | set_breakpoint_location_function (loc); |
1a853c52 | 8311 | |
6ae88661 LM |
8312 | /* While by definition, permanent breakpoints are already present in the |
8313 | code, we don't mark the location as inserted. Normally one would expect | |
8314 | that GDB could rely on that breakpoint instruction to stop the program, | |
8315 | thus removing the need to insert its own breakpoint, except that executing | |
8316 | the breakpoint instruction can kill the target instead of reporting a | |
8317 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8318 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8319 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8320 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8321 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8322 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8323 | it manually increments the PC, thus avoiding executing the breakpoint | |
8324 | instruction.) */ | |
1a853c52 | 8325 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8326 | loc->permanent = 1; |
1a853c52 | 8327 | |
0d381245 VP |
8328 | return loc; |
8329 | } | |
514f746b AR |
8330 | \f |
8331 | ||
5133a315 LM |
8332 | /* Return true if LOC is pointing to a permanent breakpoint, |
8333 | return false otherwise. */ | |
1cf4d951 | 8334 | |
5133a315 | 8335 | static bool |
1cf4d951 PA |
8336 | bp_loc_is_permanent (struct bp_location *loc) |
8337 | { | |
514f746b AR |
8338 | gdb_assert (loc != NULL); |
8339 | ||
cb1e4e32 PA |
8340 | /* If we have a non-breakpoint-backed catchpoint or a software |
8341 | watchpoint, just return 0. We should not attempt to read from | |
8342 | the addresses the locations of these breakpoint types point to. | |
5133a315 | 8343 | gdbarch_program_breakpoint_here_p, below, will attempt to read |
244558af | 8344 | memory. */ |
cb1e4e32 | 8345 | if (!bl_address_is_meaningful (loc)) |
5133a315 | 8346 | return false; |
244558af | 8347 | |
5ed8105e | 8348 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8349 | switch_to_program_space_and_thread (loc->pspace); |
5133a315 | 8350 | return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8351 | } |
8352 | ||
e7e0cddf SS |
8353 | /* Build a command list for the dprintf corresponding to the current |
8354 | settings of the dprintf style options. */ | |
8355 | ||
8356 | static void | |
8357 | update_dprintf_command_list (struct breakpoint *b) | |
8358 | { | |
6f781ee3 | 8359 | const char *dprintf_args = b->extra_string.get (); |
8579fd13 | 8360 | gdb::unique_xmalloc_ptr<char> printf_line = nullptr; |
e7e0cddf SS |
8361 | |
8362 | if (!dprintf_args) | |
8363 | return; | |
8364 | ||
8365 | dprintf_args = skip_spaces (dprintf_args); | |
8366 | ||
8367 | /* Allow a comma, as it may have terminated a location, but don't | |
8368 | insist on it. */ | |
8369 | if (*dprintf_args == ',') | |
8370 | ++dprintf_args; | |
8371 | dprintf_args = skip_spaces (dprintf_args); | |
8372 | ||
8373 | if (*dprintf_args != '"') | |
8374 | error (_("Bad format string, missing '\"'.")); | |
8375 | ||
d3ce09f5 | 8376 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8377 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8378 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf | 8379 | { |
e0700ba4 | 8380 | if (dprintf_function.empty ()) |
e7e0cddf SS |
8381 | error (_("No function supplied for dprintf call")); |
8382 | ||
e0700ba4 | 8383 | if (!dprintf_channel.empty ()) |
e7e0cddf | 8384 | printf_line = xstrprintf ("call (void) %s (%s,%s)", |
e0700ba4 SM |
8385 | dprintf_function.c_str (), |
8386 | dprintf_channel.c_str (), | |
e7e0cddf SS |
8387 | dprintf_args); |
8388 | else | |
8389 | printf_line = xstrprintf ("call (void) %s (%s)", | |
e0700ba4 | 8390 | dprintf_function.c_str (), |
e7e0cddf SS |
8391 | dprintf_args); |
8392 | } | |
d3ce09f5 SS |
8393 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8394 | { | |
8395 | if (target_can_run_breakpoint_commands ()) | |
8396 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8397 | else | |
8398 | { | |
8399 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8400 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8401 | } | |
8402 | } | |
e7e0cddf SS |
8403 | else |
8404 | internal_error (__FILE__, __LINE__, | |
8405 | _("Invalid dprintf style.")); | |
8406 | ||
f28045c2 | 8407 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8408 | |
12973681 TT |
8409 | /* Manufacture a printf sequence. */ |
8410 | struct command_line *printf_cmd_line | |
8579fd13 | 8411 | = new struct command_line (simple_control, printf_line.release ()); |
12973681 TT |
8412 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, |
8413 | command_lines_deleter ())); | |
e7e0cddf SS |
8414 | } |
8415 | ||
8416 | /* Update all dprintf commands, making their command lists reflect | |
8417 | current style settings. */ | |
8418 | ||
8419 | static void | |
eb4c3f4a | 8420 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8421 | struct cmd_list_element *c) |
8422 | { | |
43892fdf SM |
8423 | for (breakpoint *b : all_breakpoints ()) |
8424 | if (b->type == bp_dprintf) | |
e7e0cddf | 8425 | update_dprintf_command_list (b); |
e7e0cddf | 8426 | } |
c3f6f71d | 8427 | |
f00aae0f KS |
8428 | /* Create a breakpoint with SAL as location. Use LOCATION |
8429 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8430 | as condition expression. If LOCATION is NULL then create an |
8431 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8432 | |
8433 | static void | |
d9b3f62e | 8434 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8435 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8436 | event_location_up &&location, |
e1e01040 PA |
8437 | gdb::unique_xmalloc_ptr<char> filter, |
8438 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8439 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8440 | enum bptype type, enum bpdisp disposition, |
8441 | int thread, int task, int ignore_count, | |
c0a91b2b | 8442 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8443 | int enabled, int internal, unsigned flags, |
8444 | int display_canonical) | |
018d34a4 | 8445 | { |
0d381245 | 8446 | int i; |
018d34a4 VP |
8447 | |
8448 | if (type == bp_hardware_breakpoint) | |
8449 | { | |
fbbd034e AS |
8450 | int target_resources_ok; |
8451 | ||
8452 | i = hw_breakpoint_used_count (); | |
8453 | target_resources_ok = | |
8454 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8455 | i + 1, 0); |
8456 | if (target_resources_ok == 0) | |
8457 | error (_("No hardware breakpoint support in the target.")); | |
8458 | else if (target_resources_ok < 0) | |
8459 | error (_("Hardware breakpoints used exceeds limit.")); | |
8460 | } | |
8461 | ||
6c5b2ebe | 8462 | gdb_assert (!sals.empty ()); |
6c95b8df | 8463 | |
6c5b2ebe | 8464 | for (const auto &sal : sals) |
0d381245 | 8465 | { |
0d381245 VP |
8466 | struct bp_location *loc; |
8467 | ||
8468 | if (from_tty) | |
5af949e3 UW |
8469 | { |
8470 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8471 | if (!loc_gdbarch) | |
8472 | loc_gdbarch = gdbarch; | |
8473 | ||
8474 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8475 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8476 | } |
0d381245 | 8477 | |
6c5b2ebe | 8478 | if (&sal == &sals[0]) |
0d381245 | 8479 | { |
d9b3f62e | 8480 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8481 | b->thread = thread; |
4a306c9a | 8482 | b->task = task; |
855a6e68 | 8483 | |
6f781ee3 TT |
8484 | b->cond_string = std::move (cond_string); |
8485 | b->extra_string = std::move (extra_string); | |
0d381245 | 8486 | b->ignore_count = ignore_count; |
41447f92 | 8487 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8488 | b->disposition = disposition; |
6c95b8df | 8489 | |
44f238bb PA |
8490 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8491 | b->loc->inserted = 1; | |
8492 | ||
0fb4aa4b PA |
8493 | if (type == bp_static_tracepoint) |
8494 | { | |
d9b3f62e | 8495 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8496 | struct static_tracepoint_marker marker; |
8497 | ||
983af33b | 8498 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8499 | { |
8500 | /* We already know the marker exists, otherwise, we | |
8501 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8502 | const char *p |
8503 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8504 | const char *endp; |
0fb4aa4b | 8505 | |
f1735a53 | 8506 | p = skip_spaces (p); |
0fb4aa4b | 8507 | |
f1735a53 | 8508 | endp = skip_to_space (p); |
0fb4aa4b | 8509 | |
5d9310c4 | 8510 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8511 | |
3e43a32a MS |
8512 | printf_filtered (_("Probed static tracepoint " |
8513 | "marker \"%s\"\n"), | |
5d9310c4 | 8514 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8515 | } |
8516 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8517 | { | |
5d9310c4 | 8518 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8519 | |
3e43a32a MS |
8520 | printf_filtered (_("Probed static tracepoint " |
8521 | "marker \"%s\"\n"), | |
5d9310c4 | 8522 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8523 | } |
8524 | else | |
3e43a32a MS |
8525 | warning (_("Couldn't determine the static " |
8526 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8527 | } |
8528 | ||
0d381245 VP |
8529 | loc = b->loc; |
8530 | } | |
8531 | else | |
018d34a4 | 8532 | { |
39d61571 | 8533 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8534 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8535 | loc->inserted = 1; | |
0d381245 VP |
8536 | } |
8537 | ||
b5fa468f TBA |
8538 | /* Do not set breakpoint locations conditions yet. As locations |
8539 | are inserted, they get sorted based on their addresses. Let | |
8540 | the list stabilize to have reliable location numbers. */ | |
e7e0cddf SS |
8541 | |
8542 | /* Dynamic printf requires and uses additional arguments on the | |
8543 | command line, otherwise it's an error. */ | |
8544 | if (type == bp_dprintf) | |
8545 | { | |
8546 | if (b->extra_string) | |
8547 | update_dprintf_command_list (b); | |
8548 | else | |
8549 | error (_("Format string required")); | |
8550 | } | |
8551 | else if (b->extra_string) | |
6f781ee3 | 8552 | error (_("Garbage '%s' at end of command"), b->extra_string.get ()); |
855a6e68 | 8553 | } |
018d34a4 | 8554 | |
b5fa468f TBA |
8555 | |
8556 | /* The order of the locations is now stable. Set the location | |
8557 | condition using the location's number. */ | |
8558 | int loc_num = 1; | |
40cb8ca5 | 8559 | for (bp_location *loc : b->locations ()) |
b5fa468f TBA |
8560 | { |
8561 | if (b->cond_string != nullptr) | |
6f781ee3 TT |
8562 | set_breakpoint_location_condition (b->cond_string.get (), loc, |
8563 | b->number, loc_num); | |
b5fa468f TBA |
8564 | |
8565 | ++loc_num; | |
8566 | } | |
8567 | ||
56435ebe | 8568 | b->display_canonical = display_canonical; |
f00aae0f | 8569 | if (location != NULL) |
d28cd78a | 8570 | b->location = std::move (location); |
018d34a4 | 8571 | else |
d28cd78a | 8572 | b->location = new_address_location (b->loc->address, NULL, 0); |
c0e8dcd8 | 8573 | b->filter = std::move (filter); |
d9b3f62e | 8574 | } |
018d34a4 | 8575 | |
d9b3f62e PA |
8576 | static void |
8577 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 8578 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8579 | event_location_up &&location, |
e1e01040 PA |
8580 | gdb::unique_xmalloc_ptr<char> filter, |
8581 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8582 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8583 | enum bptype type, enum bpdisp disposition, |
8584 | int thread, int task, int ignore_count, | |
c0a91b2b | 8585 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8586 | int enabled, int internal, unsigned flags, |
8587 | int display_canonical) | |
d9b3f62e | 8588 | { |
a5e364af | 8589 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 8590 | |
a5e364af | 8591 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 8592 | sals, std::move (location), |
e1e01040 PA |
8593 | std::move (filter), |
8594 | std::move (cond_string), | |
8595 | std::move (extra_string), | |
d9b3f62e PA |
8596 | type, disposition, |
8597 | thread, task, ignore_count, | |
8598 | ops, from_tty, | |
44f238bb PA |
8599 | enabled, internal, flags, |
8600 | display_canonical); | |
d9b3f62e | 8601 | |
b270e6f9 | 8602 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
8603 | } |
8604 | ||
8605 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8606 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8607 | value. COND_STRING, if not NULL, specified the condition to be | |
8608 | used for all breakpoints. Essentially the only case where | |
8609 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8610 | function. In that case, it's still not possible to specify | |
8611 | separate conditions for different overloaded functions, so | |
8612 | we take just a single condition string. | |
8613 | ||
c3f6f71d | 8614 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8615 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8616 | array contents). If the function fails (error() is called), the |
8617 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8618 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8619 | |
8620 | static void | |
8cdf0e15 | 8621 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8622 | struct linespec_result *canonical, |
e1e01040 PA |
8623 | gdb::unique_xmalloc_ptr<char> cond_string, |
8624 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
8625 | enum bptype type, enum bpdisp disposition, |
8626 | int thread, int task, int ignore_count, | |
c0a91b2b | 8627 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8628 | int enabled, int internal, unsigned flags) |
c906108c | 8629 | { |
f8eba3c6 | 8630 | if (canonical->pre_expanded) |
6c5b2ebe | 8631 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 8632 | |
6c5b2ebe | 8633 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 8634 | { |
f00aae0f | 8635 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 8636 | 'break', without arguments. */ |
ffc2605c | 8637 | event_location_up location |
f00aae0f | 8638 | = (canonical->location != NULL |
8e9e35b1 | 8639 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 8640 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 8641 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 8642 | |
6c5b2ebe | 8643 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 8644 | std::move (location), |
e1e01040 PA |
8645 | std::move (filter_string), |
8646 | std::move (cond_string), | |
8647 | std::move (extra_string), | |
e7e0cddf | 8648 | type, disposition, |
84f4c1fe | 8649 | thread, task, ignore_count, ops, |
44f238bb | 8650 | from_tty, enabled, internal, flags, |
56435ebe | 8651 | canonical->special_display); |
c3f6f71d | 8652 | } |
c3f6f71d | 8653 | } |
c906108c | 8654 | |
f00aae0f | 8655 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 8656 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
8657 | addresses found. LOCATION points to the end of the SAL (for |
8658 | linespec locations). | |
9998af43 TJB |
8659 | |
8660 | The array and the line spec strings are allocated on the heap, it is | |
8661 | the caller's responsibility to free them. */ | |
c906108c | 8662 | |
b9362cc7 | 8663 | static void |
626d2320 | 8664 | parse_breakpoint_sals (struct event_location *location, |
58438ac1 | 8665 | struct linespec_result *canonical) |
c3f6f71d | 8666 | { |
f00aae0f KS |
8667 | struct symtab_and_line cursal; |
8668 | ||
8669 | if (event_location_type (location) == LINESPEC_LOCATION) | |
8670 | { | |
a20714ff | 8671 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 8672 | |
a20714ff | 8673 | if (spec == NULL) |
f00aae0f KS |
8674 | { |
8675 | /* The last displayed codepoint, if it's valid, is our default | |
8676 | breakpoint address. */ | |
8677 | if (last_displayed_sal_is_valid ()) | |
8678 | { | |
f00aae0f KS |
8679 | /* Set sal's pspace, pc, symtab, and line to the values |
8680 | corresponding to the last call to print_frame_info. | |
8681 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
8682 | as the breakpoint line number is inappropriate otherwise. | |
8683 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
8684 | symtab_and_line sal = get_last_displayed_sal (); |
8685 | CORE_ADDR pc = sal.pc; | |
8686 | ||
f00aae0f KS |
8687 | sal = find_pc_line (pc, 0); |
8688 | ||
8689 | /* "break" without arguments is equivalent to "break *PC" | |
8690 | where PC is the last displayed codepoint's address. So | |
8691 | make sure to set sal.explicit_pc to prevent GDB from | |
8692 | trying to expand the list of sals to include all other | |
8693 | instances with the same symtab and line. */ | |
8694 | sal.pc = pc; | |
8695 | sal.explicit_pc = 1; | |
8696 | ||
6c5b2ebe PA |
8697 | struct linespec_sals lsal; |
8698 | lsal.sals = {sal}; | |
f00aae0f KS |
8699 | lsal.canonical = NULL; |
8700 | ||
6c5b2ebe | 8701 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
8702 | return; |
8703 | } | |
8704 | else | |
8705 | error (_("No default breakpoint address now.")); | |
c906108c | 8706 | } |
c906108c | 8707 | } |
f00aae0f KS |
8708 | |
8709 | /* Force almost all breakpoints to be in terms of the | |
8710 | current_source_symtab (which is decode_line_1's default). | |
8711 | This should produce the results we want almost all of the | |
8712 | time while leaving default_breakpoint_* alone. | |
8713 | ||
8714 | ObjC: However, don't match an Objective-C method name which | |
8715 | may have a '+' or '-' succeeded by a '['. */ | |
8716 | cursal = get_current_source_symtab_and_line (); | |
8717 | if (last_displayed_sal_is_valid ()) | |
c906108c | 8718 | { |
a20714ff | 8719 | const char *spec = NULL; |
cc80f267 | 8720 | |
f00aae0f | 8721 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 8722 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 8723 | |
f00aae0f | 8724 | if (!cursal.symtab |
a20714ff PA |
8725 | || (spec != NULL |
8726 | && strchr ("+-", spec[0]) != NULL | |
8727 | && spec[1] != '[')) | |
f00aae0f | 8728 | { |
c2f4122d | 8729 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
8730 | get_last_displayed_symtab (), |
8731 | get_last_displayed_line (), | |
8732 | canonical, NULL, NULL); | |
8733 | return; | |
8734 | } | |
c906108c | 8735 | } |
f00aae0f | 8736 | |
c2f4122d | 8737 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 8738 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 8739 | } |
c906108c | 8740 | |
c906108c | 8741 | |
c3f6f71d | 8742 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 8743 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 8744 | |
b9362cc7 | 8745 | static void |
6c5b2ebe | 8746 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 8747 | { |
6c5b2ebe PA |
8748 | for (auto &sal : sals) |
8749 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
8750 | } |
8751 | ||
7a697b8d SS |
8752 | /* Fast tracepoints may have restrictions on valid locations. For |
8753 | instance, a fast tracepoint using a jump instead of a trap will | |
8754 | likely have to overwrite more bytes than a trap would, and so can | |
8755 | only be placed where the instruction is longer than the jump, or a | |
8756 | multi-instruction sequence does not have a jump into the middle of | |
8757 | it, etc. */ | |
8758 | ||
8759 | static void | |
8760 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 8761 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 8762 | { |
6c5b2ebe | 8763 | for (const auto &sal : sals) |
7a697b8d | 8764 | { |
f8eba3c6 TT |
8765 | struct gdbarch *sarch; |
8766 | ||
6c5b2ebe | 8767 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
8768 | /* We fall back to GDBARCH if there is no architecture |
8769 | associated with SAL. */ | |
8770 | if (sarch == NULL) | |
8771 | sarch = gdbarch; | |
281d762b TT |
8772 | std::string msg; |
8773 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 8774 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 8775 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
8776 | } |
8777 | } | |
8778 | ||
018d34a4 VP |
8779 | /* Given TOK, a string specification of condition and thread, as |
8780 | accepted by the 'break' command, extract the condition | |
8781 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 8782 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
8783 | If no condition is found, *COND_STRING is set to NULL. |
8784 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
8785 | |
8786 | static void | |
bbc13ae3 | 8787 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
6f781ee3 TT |
8788 | gdb::unique_xmalloc_ptr<char> *cond_string, |
8789 | int *thread, int *task, | |
8790 | gdb::unique_xmalloc_ptr<char> *rest) | |
018d34a4 | 8791 | { |
6f781ee3 | 8792 | cond_string->reset (); |
018d34a4 | 8793 | *thread = -1; |
ed1d1739 | 8794 | *task = 0; |
6f781ee3 | 8795 | rest->reset (); |
733d554a | 8796 | bool force = false; |
ed1d1739 | 8797 | |
018d34a4 VP |
8798 | while (tok && *tok) |
8799 | { | |
bbc13ae3 | 8800 | const char *end_tok; |
018d34a4 | 8801 | int toklen; |
bbc13ae3 KS |
8802 | const char *cond_start = NULL; |
8803 | const char *cond_end = NULL; | |
cc59ec59 | 8804 | |
f1735a53 | 8805 | tok = skip_spaces (tok); |
e7e0cddf SS |
8806 | |
8807 | if ((*tok == '"' || *tok == ',') && rest) | |
8808 | { | |
6f781ee3 | 8809 | rest->reset (savestring (tok, strlen (tok))); |
e7e0cddf SS |
8810 | return; |
8811 | } | |
8812 | ||
f1735a53 | 8813 | end_tok = skip_to_space (tok); |
d634f2de | 8814 | |
018d34a4 | 8815 | toklen = end_tok - tok; |
d634f2de | 8816 | |
018d34a4 VP |
8817 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
8818 | { | |
8819 | tok = cond_start = end_tok + 1; | |
733d554a TBA |
8820 | try |
8821 | { | |
8822 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); | |
8823 | } | |
8824 | catch (const gdb_exception_error &) | |
8825 | { | |
8826 | if (!force) | |
8827 | throw; | |
8828 | else | |
8829 | tok = tok + strlen (tok); | |
8830 | } | |
018d34a4 | 8831 | cond_end = tok; |
6f781ee3 | 8832 | cond_string->reset (savestring (cond_start, cond_end - cond_start)); |
018d34a4 | 8833 | } |
733d554a TBA |
8834 | else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0) |
8835 | { | |
5759831a | 8836 | tok = tok + toklen; |
733d554a TBA |
8837 | force = true; |
8838 | } | |
018d34a4 VP |
8839 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
8840 | { | |
5d5658a1 PA |
8841 | const char *tmptok; |
8842 | struct thread_info *thr; | |
d634f2de | 8843 | |
018d34a4 | 8844 | tok = end_tok + 1; |
5d5658a1 | 8845 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
8846 | if (tok == tmptok) |
8847 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 8848 | *thread = thr->global_num; |
bbc13ae3 | 8849 | tok = tmptok; |
018d34a4 | 8850 | } |
4a306c9a JB |
8851 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
8852 | { | |
8853 | char *tmptok; | |
8854 | ||
8855 | tok = end_tok + 1; | |
bbc13ae3 | 8856 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
8857 | if (tok == tmptok) |
8858 | error (_("Junk after task keyword.")); | |
8859 | if (!valid_task_id (*task)) | |
b6199126 | 8860 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 8861 | tok = tmptok; |
4a306c9a | 8862 | } |
e7e0cddf SS |
8863 | else if (rest) |
8864 | { | |
6f781ee3 | 8865 | rest->reset (savestring (tok, strlen (tok))); |
ccab2054 | 8866 | return; |
e7e0cddf | 8867 | } |
018d34a4 VP |
8868 | else |
8869 | error (_("Junk at end of arguments.")); | |
8870 | } | |
8871 | } | |
8872 | ||
b5fa468f TBA |
8873 | /* Call 'find_condition_and_thread' for each sal in SALS until a parse |
8874 | succeeds. The parsed values are written to COND_STRING, THREAD, | |
8875 | TASK, and REST. See the comment of 'find_condition_and_thread' | |
8876 | for the description of these parameters and INPUT. */ | |
8877 | ||
8878 | static void | |
8879 | find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals, | |
6f781ee3 TT |
8880 | const char *input, |
8881 | gdb::unique_xmalloc_ptr<char> *cond_string, | |
8882 | int *thread, int *task, | |
8883 | gdb::unique_xmalloc_ptr<char> *rest) | |
b5fa468f TBA |
8884 | { |
8885 | int num_failures = 0; | |
8886 | for (auto &sal : sals) | |
8887 | { | |
6f781ee3 | 8888 | gdb::unique_xmalloc_ptr<char> cond; |
b5fa468f TBA |
8889 | int thread_id = 0; |
8890 | int task_id = 0; | |
6f781ee3 | 8891 | gdb::unique_xmalloc_ptr<char> remaining; |
b5fa468f TBA |
8892 | |
8893 | /* Here we want to parse 'arg' to separate condition from thread | |
8894 | number. But because parsing happens in a context and the | |
8895 | contexts of sals might be different, try each until there is | |
8896 | success. Finding one successful parse is sufficient for our | |
8897 | goal. When setting the breakpoint we'll re-parse the | |
8898 | condition in the context of each sal. */ | |
8899 | try | |
8900 | { | |
8901 | find_condition_and_thread (input, sal.pc, &cond, &thread_id, | |
8902 | &task_id, &remaining); | |
6f781ee3 | 8903 | *cond_string = std::move (cond); |
b5fa468f TBA |
8904 | *thread = thread_id; |
8905 | *task = task_id; | |
6f781ee3 | 8906 | *rest = std::move (remaining); |
b5fa468f TBA |
8907 | break; |
8908 | } | |
8909 | catch (const gdb_exception_error &e) | |
8910 | { | |
8911 | num_failures++; | |
8912 | /* If no sal remains, do not continue. */ | |
8913 | if (num_failures == sals.size ()) | |
8914 | throw; | |
8915 | } | |
8916 | } | |
8917 | } | |
8918 | ||
0fb4aa4b PA |
8919 | /* Decode a static tracepoint marker spec. */ |
8920 | ||
6c5b2ebe | 8921 | static std::vector<symtab_and_line> |
f00aae0f | 8922 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 8923 | { |
f00aae0f KS |
8924 | const char *p = &(*arg_p)[3]; |
8925 | const char *endp; | |
0fb4aa4b | 8926 | |
f1735a53 | 8927 | p = skip_spaces (p); |
0fb4aa4b | 8928 | |
f1735a53 | 8929 | endp = skip_to_space (p); |
0fb4aa4b | 8930 | |
81b1e71c | 8931 | std::string marker_str (p, endp - p); |
0fb4aa4b | 8932 | |
5d9310c4 SM |
8933 | std::vector<static_tracepoint_marker> markers |
8934 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
8935 | if (markers.empty ()) | |
81b1e71c TT |
8936 | error (_("No known static tracepoint marker named %s"), |
8937 | marker_str.c_str ()); | |
0fb4aa4b | 8938 | |
6c5b2ebe | 8939 | std::vector<symtab_and_line> sals; |
5d9310c4 | 8940 | sals.reserve (markers.size ()); |
0fb4aa4b | 8941 | |
5d9310c4 | 8942 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 8943 | { |
5d9310c4 SM |
8944 | symtab_and_line sal = find_pc_line (marker.address, 0); |
8945 | sal.pc = marker.address; | |
6c5b2ebe | 8946 | sals.push_back (sal); |
5d9310c4 | 8947 | } |
0fb4aa4b | 8948 | |
0fb4aa4b PA |
8949 | *arg_p = endp; |
8950 | return sals; | |
8951 | } | |
8952 | ||
bac7c5cf GB |
8953 | /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and |
8954 | according to IS_TRACEPOINT. */ | |
8955 | ||
8956 | static const struct breakpoint_ops * | |
8957 | breakpoint_ops_for_event_location_type (enum event_location_type location_type, | |
8958 | bool is_tracepoint) | |
8959 | { | |
8960 | if (is_tracepoint) | |
8961 | { | |
8962 | if (location_type == PROBE_LOCATION) | |
8963 | return &tracepoint_probe_breakpoint_ops; | |
8964 | else | |
8965 | return &tracepoint_breakpoint_ops; | |
8966 | } | |
8967 | else | |
8968 | { | |
8969 | if (location_type == PROBE_LOCATION) | |
8970 | return &bkpt_probe_breakpoint_ops; | |
8971 | else | |
8972 | return &bkpt_breakpoint_ops; | |
8973 | } | |
8974 | } | |
8975 | ||
8976 | /* See breakpoint.h. */ | |
8977 | ||
8978 | const struct breakpoint_ops * | |
8979 | breakpoint_ops_for_event_location (const struct event_location *location, | |
8980 | bool is_tracepoint) | |
8981 | { | |
8982 | if (location != nullptr) | |
8983 | return breakpoint_ops_for_event_location_type | |
8984 | (event_location_type (location), is_tracepoint); | |
8985 | return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; | |
8986 | } | |
8987 | ||
f00aae0f | 8988 | /* See breakpoint.h. */ |
0101ce28 | 8989 | |
8cdf0e15 VP |
8990 | int |
8991 | create_breakpoint (struct gdbarch *gdbarch, | |
626d2320 | 8992 | struct event_location *location, |
e1e01040 PA |
8993 | const char *cond_string, |
8994 | int thread, const char *extra_string, | |
10a636cc | 8995 | bool force_condition, int parse_extra, |
0fb4aa4b | 8996 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
8997 | int ignore_count, |
8998 | enum auto_boolean pending_break_support, | |
c0a91b2b | 8999 | const struct breakpoint_ops *ops, |
44f238bb PA |
9000 | int from_tty, int enabled, int internal, |
9001 | unsigned flags) | |
c3f6f71d | 9002 | { |
7efd8fc2 | 9003 | struct linespec_result canonical; |
0101ce28 | 9004 | int pending = 0; |
4a306c9a | 9005 | int task = 0; |
86b17b60 | 9006 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9007 | |
348d480f PA |
9008 | gdb_assert (ops != NULL); |
9009 | ||
f00aae0f KS |
9010 | /* If extra_string isn't useful, set it to NULL. */ |
9011 | if (extra_string != NULL && *extra_string == '\0') | |
9012 | extra_string = NULL; | |
9013 | ||
a70b8144 | 9014 | try |
b78a6381 | 9015 | { |
f00aae0f | 9016 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9017 | } |
230d2906 | 9018 | catch (const gdb_exception_error &e) |
0101ce28 | 9019 | { |
492d29ea PA |
9020 | /* If caller is interested in rc value from parse, set |
9021 | value. */ | |
9022 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9023 | { |
05ff989b AC |
9024 | /* If pending breakpoint support is turned off, throw |
9025 | error. */ | |
fa8d40ab JJ |
9026 | |
9027 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 9028 | throw; |
723a2275 VP |
9029 | |
9030 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9031 | |
dda83cd7 | 9032 | /* If pending breakpoint support is auto query and the user |
05ff989b | 9033 | selects no, then simply return the error code. */ |
059fb39f | 9034 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9035 | && !nquery (_("Make %s pending on future shared library load? "), |
9036 | bptype_string (type_wanted))) | |
fd9b8c24 | 9037 | return 0; |
fa8d40ab | 9038 | |
05ff989b AC |
9039 | /* At this point, either the user was queried about setting |
9040 | a pending breakpoint and selected yes, or pending | |
9041 | breakpoint behavior is on and thus a pending breakpoint | |
9042 | is defaulted on behalf of the user. */ | |
f00aae0f | 9043 | pending = 1; |
0101ce28 | 9044 | } |
492d29ea | 9045 | else |
eedc3f4f | 9046 | throw; |
0101ce28 | 9047 | } |
492d29ea | 9048 | |
6c5b2ebe | 9049 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9050 | return 0; |
c3f6f71d | 9051 | |
c3f6f71d JM |
9052 | /* Resolve all line numbers to PC's and verify that the addresses |
9053 | are ok for the target. */ | |
0101ce28 | 9054 | if (!pending) |
f8eba3c6 | 9055 | { |
6c5b2ebe PA |
9056 | for (auto &lsal : canonical.lsals) |
9057 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9058 | } |
c3f6f71d | 9059 | |
7a697b8d | 9060 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9061 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9062 | { |
6c5b2ebe PA |
9063 | for (const auto &lsal : canonical.lsals) |
9064 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9065 | } |
7a697b8d | 9066 | |
c3f6f71d JM |
9067 | /* Verify that condition can be parsed, before setting any |
9068 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9069 | breakpoint. */ |
0101ce28 | 9070 | if (!pending) |
c3f6f71d | 9071 | { |
e1e01040 PA |
9072 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9073 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9074 | ||
f00aae0f | 9075 | if (parse_extra) |
dda83cd7 | 9076 | { |
6f781ee3 TT |
9077 | gdb::unique_xmalloc_ptr<char> rest; |
9078 | gdb::unique_xmalloc_ptr<char> cond; | |
52d361e1 | 9079 | |
6c5b2ebe | 9080 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9081 | |
b5fa468f TBA |
9082 | find_condition_and_thread_for_sals (lsal.sals, extra_string, |
9083 | &cond, &thread, &task, &rest); | |
6f781ee3 TT |
9084 | cond_string_copy = std::move (cond); |
9085 | extra_string_copy = std::move (rest); | |
dda83cd7 | 9086 | } |
2f069f6f | 9087 | else |
dda83cd7 | 9088 | { |
f00aae0f KS |
9089 | if (type_wanted != bp_dprintf |
9090 | && extra_string != NULL && *extra_string != '\0') | |
9091 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa | 9092 | |
10a636cc TBA |
9093 | /* Check the validity of the condition. We should error out |
9094 | if the condition is invalid at all of the locations and | |
9095 | if it is not forced. In the PARSE_EXTRA case above, this | |
9096 | check is done when parsing the EXTRA_STRING. */ | |
9097 | if (cond_string != nullptr && !force_condition) | |
9098 | { | |
9099 | int num_failures = 0; | |
9100 | const linespec_sals &lsal = canonical.lsals[0]; | |
9101 | for (const auto &sal : lsal.sals) | |
9102 | { | |
9103 | const char *cond = cond_string; | |
9104 | try | |
9105 | { | |
9106 | parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0); | |
9107 | /* One success is sufficient to keep going. */ | |
9108 | break; | |
9109 | } | |
9110 | catch (const gdb_exception_error &) | |
9111 | { | |
9112 | num_failures++; | |
9113 | /* If this is the last sal, error out. */ | |
9114 | if (num_failures == lsal.sals.size ()) | |
9115 | throw; | |
9116 | } | |
9117 | } | |
9118 | } | |
9119 | ||
0878d0fa YQ |
9120 | /* Create a private copy of condition string. */ |
9121 | if (cond_string) | |
e1e01040 | 9122 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9123 | /* Create a private copy of any extra string. */ |
9124 | if (extra_string) | |
e1e01040 | 9125 | extra_string_copy.reset (xstrdup (extra_string)); |
dda83cd7 | 9126 | } |
0fb4aa4b | 9127 | |
52d361e1 | 9128 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9129 | std::move (cond_string_copy), |
9130 | std::move (extra_string_copy), | |
9131 | type_wanted, | |
d9b3f62e PA |
9132 | tempflag ? disp_del : disp_donttouch, |
9133 | thread, task, ignore_count, ops, | |
44f238bb | 9134 | from_tty, enabled, internal, flags); |
c906108c | 9135 | } |
0101ce28 JJ |
9136 | else |
9137 | { | |
a5e364af | 9138 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9139 | |
a5e364af | 9140 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9141 | b->location = copy_event_location (location); |
bfccc43c | 9142 | |
f00aae0f KS |
9143 | if (parse_extra) |
9144 | b->cond_string = NULL; | |
e12c7713 MK |
9145 | else |
9146 | { | |
9147 | /* Create a private copy of condition string. */ | |
6f781ee3 TT |
9148 | b->cond_string.reset (cond_string != NULL |
9149 | ? xstrdup (cond_string) | |
9150 | : NULL); | |
15630549 | 9151 | b->thread = thread; |
e12c7713 | 9152 | } |
f00aae0f KS |
9153 | |
9154 | /* Create a private copy of any extra string. */ | |
6f781ee3 TT |
9155 | b->extra_string.reset (extra_string != NULL |
9156 | ? xstrdup (extra_string) | |
9157 | : NULL); | |
0101ce28 | 9158 | b->ignore_count = ignore_count; |
0101ce28 | 9159 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9160 | b->condition_not_parsed = 1; |
41447f92 | 9161 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 | 9162 | if ((type_wanted != bp_breakpoint |
dda83cd7 | 9163 | && type_wanted != bp_hardware_breakpoint) || thread != -1) |
f8eba3c6 | 9164 | b->pspace = current_program_space; |
8bea4e01 | 9165 | |
b270e6f9 | 9166 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9167 | } |
9168 | ||
6c5b2ebe | 9169 | if (canonical.lsals.size () > 1) |
95a42b64 | 9170 | { |
3e43a32a MS |
9171 | warning (_("Multiple breakpoints were set.\nUse the " |
9172 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9173 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9174 | } |
9175 | ||
44702360 | 9176 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9177 | |
9178 | return 1; | |
c3f6f71d | 9179 | } |
c906108c | 9180 | |
348d480f | 9181 | /* Set a breakpoint. |
72b2ff0e VP |
9182 | ARG is a string describing breakpoint address, |
9183 | condition, and thread. | |
9184 | FLAG specifies if a breakpoint is hardware on, | |
9185 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9186 | and BP_TEMPFLAG. */ | |
348d480f | 9187 | |
98deb0da | 9188 | static void |
f2fc3015 | 9189 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9190 | { |
72b2ff0e | 9191 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9192 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9193 | ? bp_hardware_breakpoint | |
9194 | : bp_breakpoint); | |
f00aae0f | 9195 | |
ffc2605c | 9196 | event_location_up location = string_to_event_location (&arg, current_language); |
bac7c5cf GB |
9197 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
9198 | (location.get (), false /* is_tracepoint */); | |
c3f6f71d | 9199 | |
8cdf0e15 | 9200 | create_breakpoint (get_current_arch (), |
ffc2605c | 9201 | location.get (), |
10a636cc | 9202 | NULL, 0, arg, false, 1 /* parse arg */, |
0fb4aa4b | 9203 | tempflag, type_wanted, |
8cdf0e15 VP |
9204 | 0 /* Ignore count */, |
9205 | pending_break_support, | |
55aa24fb | 9206 | ops, |
8cdf0e15 | 9207 | from_tty, |
84f4c1fe | 9208 | 1 /* enabled */, |
44f238bb PA |
9209 | 0 /* internal */, |
9210 | 0); | |
c906108c SS |
9211 | } |
9212 | ||
c906108c SS |
9213 | /* Helper function for break_command_1 and disassemble_command. */ |
9214 | ||
9215 | void | |
fba45db2 | 9216 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9217 | { |
9218 | CORE_ADDR pc; | |
9219 | ||
9220 | if (sal->pc == 0 && sal->symtab != NULL) | |
9221 | { | |
9222 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9223 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9224 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9225 | sal->pc = pc; |
6a048695 | 9226 | |
4a64f543 | 9227 | /* If this SAL corresponds to a breakpoint inserted using a line |
dda83cd7 | 9228 | number, then skip the function prologue if necessary. */ |
6a048695 | 9229 | if (sal->explicit_line) |
059acae7 | 9230 | skip_prologue_sal (sal); |
c906108c SS |
9231 | } |
9232 | ||
9233 | if (sal->section == 0 && sal->symtab != NULL) | |
9234 | { | |
346d1dfe | 9235 | const struct blockvector *bv; |
3977b71f | 9236 | const struct block *b; |
c5aa993b | 9237 | struct symbol *sym; |
c906108c | 9238 | |
43f3e411 DE |
9239 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9240 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9241 | if (bv != NULL) |
9242 | { | |
7f0df278 | 9243 | sym = block_linkage_function (b); |
c906108c SS |
9244 | if (sym != NULL) |
9245 | { | |
eb822aa6 | 9246 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
ebbc3a7d | 9247 | sal->section = sym->obj_section (SYMTAB_OBJFILE (sal->symtab)); |
c906108c SS |
9248 | } |
9249 | else | |
9250 | { | |
4a64f543 | 9251 | /* It really is worthwhile to have the section, so we'll |
dda83cd7 SM |
9252 | just have to look harder. This case can be executed |
9253 | if we have line numbers but no functions (as can | |
9254 | happen in assembly source). */ | |
c906108c | 9255 | |
5ed8105e | 9256 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9257 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9258 | |
5ed8105e | 9259 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9260 | if (msym.minsym) |
1db66e34 | 9261 | sal->section = msym.obj_section (); |
c906108c SS |
9262 | } |
9263 | } | |
9264 | } | |
9265 | } | |
9266 | ||
9267 | void | |
0b39b52e | 9268 | break_command (const char *arg, int from_tty) |
c906108c | 9269 | { |
db107f19 | 9270 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9271 | } |
9272 | ||
c906108c | 9273 | void |
0b39b52e | 9274 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9275 | { |
db107f19 | 9276 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9277 | } |
9278 | ||
c906108c | 9279 | static void |
0b39b52e | 9280 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9281 | { |
db107f19 | 9282 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9283 | } |
9284 | ||
9285 | static void | |
0b39b52e | 9286 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9287 | { |
db107f19 | 9288 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9289 | } |
9290 | ||
9291 | static void | |
ee7ddd71 | 9292 | stop_command (const char *arg, int from_tty) |
c906108c | 9293 | { |
a3f17187 | 9294 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9295 | Usage: stop in <function | address>\n\ |
a3f17187 | 9296 | stop at <line>\n")); |
c906108c SS |
9297 | } |
9298 | ||
9299 | static void | |
4495129a | 9300 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9301 | { |
9302 | int badInput = 0; | |
9303 | ||
cafb3438 | 9304 | if (arg == NULL) |
c906108c SS |
9305 | badInput = 1; |
9306 | else if (*arg != '*') | |
9307 | { | |
4495129a | 9308 | const char *argptr = arg; |
c906108c SS |
9309 | int hasColon = 0; |
9310 | ||
4a64f543 | 9311 | /* Look for a ':'. If this is a line number specification, then |
dda83cd7 SM |
9312 | say it is bad, otherwise, it should be an address or |
9313 | function/method name. */ | |
c906108c | 9314 | while (*argptr && !hasColon) |
c5aa993b JM |
9315 | { |
9316 | hasColon = (*argptr == ':'); | |
9317 | argptr++; | |
9318 | } | |
c906108c SS |
9319 | |
9320 | if (hasColon) | |
c5aa993b | 9321 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9322 | else |
c5aa993b | 9323 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9324 | } |
9325 | ||
9326 | if (badInput) | |
a3f17187 | 9327 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9328 | else |
db107f19 | 9329 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9330 | } |
9331 | ||
9332 | static void | |
4495129a | 9333 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9334 | { |
9335 | int badInput = 0; | |
9336 | ||
cafb3438 | 9337 | if (arg == NULL || *arg == '*') /* no line number */ |
c906108c SS |
9338 | badInput = 1; |
9339 | else | |
9340 | { | |
4495129a | 9341 | const char *argptr = arg; |
c906108c SS |
9342 | int hasColon = 0; |
9343 | ||
4a64f543 | 9344 | /* Look for a ':'. If there is a '::' then get out, otherwise |
dda83cd7 | 9345 | it is probably a line number. */ |
c906108c | 9346 | while (*argptr && !hasColon) |
c5aa993b JM |
9347 | { |
9348 | hasColon = (*argptr == ':'); | |
9349 | argptr++; | |
9350 | } | |
c906108c SS |
9351 | |
9352 | if (hasColon) | |
c5aa993b | 9353 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9354 | else |
c5aa993b | 9355 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9356 | } |
9357 | ||
9358 | if (badInput) | |
65e65158 | 9359 | printf_filtered (_("Usage: stop at LINE\n")); |
c906108c | 9360 | else |
db107f19 | 9361 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9362 | } |
9363 | ||
e7e0cddf SS |
9364 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9365 | with a prewired command list consisting of a single output command, | |
9366 | built from extra arguments supplied on the dprintf command | |
9367 | line. */ | |
9368 | ||
da821c7b | 9369 | static void |
0b39b52e | 9370 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9371 | { |
ffc2605c | 9372 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9373 | |
9374 | /* If non-NULL, ARG should have been advanced past the location; | |
9375 | the next character must be ','. */ | |
9376 | if (arg != NULL) | |
9377 | { | |
9378 | if (arg[0] != ',' || arg[1] == '\0') | |
9379 | error (_("Format string required")); | |
9380 | else | |
9381 | { | |
9382 | /* Skip the comma. */ | |
9383 | ++arg; | |
9384 | } | |
9385 | } | |
9386 | ||
e7e0cddf | 9387 | create_breakpoint (get_current_arch (), |
ffc2605c | 9388 | location.get (), |
10a636cc | 9389 | NULL, 0, arg, false, 1 /* parse arg */, |
e7e0cddf SS |
9390 | 0, bp_dprintf, |
9391 | 0 /* Ignore count */, | |
9392 | pending_break_support, | |
9393 | &dprintf_breakpoint_ops, | |
9394 | from_tty, | |
9395 | 1 /* enabled */, | |
9396 | 0 /* internal */, | |
9397 | 0); | |
9398 | } | |
9399 | ||
d3ce09f5 | 9400 | static void |
0b39b52e | 9401 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9402 | { |
9403 | error (_("May only run agent-printf on the target")); | |
9404 | } | |
9405 | ||
f1310107 TJB |
9406 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9407 | ranged breakpoints. */ | |
9408 | ||
9409 | static int | |
9410 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9411 | const address_space *aspace, |
09ac7c10 | 9412 | CORE_ADDR bp_addr, |
c272a98c | 9413 | const target_waitstatus &ws) |
f1310107 | 9414 | { |
c272a98c SM |
9415 | if (ws.kind () != TARGET_WAITKIND_STOPPED |
9416 | || ws.sig () != GDB_SIGNAL_TRAP) | |
09ac7c10 TT |
9417 | return 0; |
9418 | ||
f1310107 TJB |
9419 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9420 | bl->length, aspace, bp_addr); | |
9421 | } | |
9422 | ||
9423 | /* Implement the "resources_needed" breakpoint_ops method for | |
9424 | ranged breakpoints. */ | |
9425 | ||
9426 | static int | |
9427 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9428 | { | |
9429 | return target_ranged_break_num_registers (); | |
9430 | } | |
9431 | ||
9432 | /* Implement the "print_it" breakpoint_ops method for | |
9433 | ranged breakpoints. */ | |
9434 | ||
9435 | static enum print_stop_action | |
313f3b21 | 9436 | print_it_ranged_breakpoint (bpstat *bs) |
f1310107 | 9437 | { |
348d480f | 9438 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9439 | struct bp_location *bl = b->loc; |
79a45e25 | 9440 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9441 | |
9442 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9443 | ||
9444 | /* Ranged breakpoints have only one location. */ | |
9445 | gdb_assert (bl && bl->next == NULL); | |
9446 | ||
9447 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9448 | |
9449 | maybe_print_thread_hit_breakpoint (uiout); | |
9450 | ||
f1310107 | 9451 | if (b->disposition == disp_del) |
112e8700 | 9452 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9453 | else |
112e8700 SM |
9454 | uiout->text ("Ranged breakpoint "); |
9455 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9456 | { |
112e8700 | 9457 | uiout->field_string ("reason", |
f1310107 | 9458 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9459 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9460 | } |
381befee | 9461 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 9462 | uiout->text (", "); |
f1310107 TJB |
9463 | |
9464 | return PRINT_SRC_AND_LOC; | |
9465 | } | |
9466 | ||
9467 | /* Implement the "print_one" breakpoint_ops method for | |
9468 | ranged breakpoints. */ | |
9469 | ||
9470 | static void | |
9471 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9472 | struct bp_location **last_loc) | |
9473 | { | |
9474 | struct bp_location *bl = b->loc; | |
9475 | struct value_print_options opts; | |
79a45e25 | 9476 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9477 | |
9478 | /* Ranged breakpoints have only one location. */ | |
9479 | gdb_assert (bl && bl->next == NULL); | |
9480 | ||
9481 | get_user_print_options (&opts); | |
9482 | ||
9483 | if (opts.addressprint) | |
9484 | /* We don't print the address range here, it will be printed later | |
9485 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9486 | uiout->field_skip ("addr"); |
f1310107 TJB |
9487 | annotate_field (5); |
9488 | print_breakpoint_location (b, bl); | |
9489 | *last_loc = bl; | |
9490 | } | |
9491 | ||
9492 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9493 | ranged breakpoints. */ | |
9494 | ||
9495 | static void | |
9496 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9497 | struct ui_out *uiout) | |
9498 | { | |
9499 | CORE_ADDR address_start, address_end; | |
9500 | struct bp_location *bl = b->loc; | |
d7e74731 | 9501 | string_file stb; |
f1310107 TJB |
9502 | |
9503 | gdb_assert (bl); | |
9504 | ||
9505 | address_start = bl->address; | |
9506 | address_end = address_start + bl->length - 1; | |
9507 | ||
112e8700 | 9508 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9509 | stb.printf ("[%s, %s]", |
9510 | print_core_address (bl->gdbarch, address_start), | |
9511 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9512 | uiout->field_stream ("addr", stb); |
9513 | uiout->text ("\n"); | |
f1310107 TJB |
9514 | } |
9515 | ||
9516 | /* Implement the "print_mention" breakpoint_ops method for | |
9517 | ranged breakpoints. */ | |
9518 | ||
9519 | static void | |
9520 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9521 | { | |
9522 | struct bp_location *bl = b->loc; | |
79a45e25 | 9523 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9524 | |
9525 | gdb_assert (bl); | |
9526 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9527 | ||
2d33446d TT |
9528 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
9529 | b->number, paddress (bl->gdbarch, bl->address), | |
9530 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
f1310107 TJB |
9531 | } |
9532 | ||
9533 | /* Implement the "print_recreate" breakpoint_ops method for | |
9534 | ranged breakpoints. */ | |
9535 | ||
9536 | static void | |
9537 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9538 | { | |
f00aae0f | 9539 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9540 | event_location_to_string (b->location.get ()), |
9541 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9542 | print_recreate_thread (b, fp); |
f1310107 TJB |
9543 | } |
9544 | ||
9545 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9546 | ||
2060206e | 9547 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9548 | |
9549 | /* Find the address where the end of the breakpoint range should be | |
9550 | placed, given the SAL of the end of the range. This is so that if | |
9551 | the user provides a line number, the end of the range is set to the | |
9552 | last instruction of the given line. */ | |
9553 | ||
9554 | static CORE_ADDR | |
9555 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9556 | { | |
9557 | CORE_ADDR end; | |
9558 | ||
9559 | /* If the user provided a PC value, use it. Otherwise, | |
9560 | find the address of the end of the given location. */ | |
9561 | if (sal.explicit_pc) | |
9562 | end = sal.pc; | |
9563 | else | |
9564 | { | |
9565 | int ret; | |
9566 | CORE_ADDR start; | |
9567 | ||
9568 | ret = find_line_pc_range (sal, &start, &end); | |
9569 | if (!ret) | |
9570 | error (_("Could not find location of the end of the range.")); | |
9571 | ||
9572 | /* find_line_pc_range returns the start of the next line. */ | |
9573 | end--; | |
9574 | } | |
9575 | ||
9576 | return end; | |
9577 | } | |
9578 | ||
9579 | /* Implement the "break-range" CLI command. */ | |
9580 | ||
9581 | static void | |
0b39b52e | 9582 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9583 | { |
f2fc3015 | 9584 | const char *arg_start; |
f1310107 TJB |
9585 | struct linespec_result canonical_start, canonical_end; |
9586 | int bp_count, can_use_bp, length; | |
9587 | CORE_ADDR end; | |
9588 | struct breakpoint *b; | |
f1310107 TJB |
9589 | |
9590 | /* We don't support software ranged breakpoints. */ | |
9591 | if (target_ranged_break_num_registers () < 0) | |
9592 | error (_("This target does not support hardware ranged breakpoints.")); | |
9593 | ||
9594 | bp_count = hw_breakpoint_used_count (); | |
9595 | bp_count += target_ranged_break_num_registers (); | |
9596 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9597 | bp_count, 0); | |
9598 | if (can_use_bp < 0) | |
9599 | error (_("Hardware breakpoints used exceeds limit.")); | |
9600 | ||
f8eba3c6 | 9601 | arg = skip_spaces (arg); |
f1310107 TJB |
9602 | if (arg == NULL || arg[0] == '\0') |
9603 | error(_("No address range specified.")); | |
9604 | ||
f8eba3c6 | 9605 | arg_start = arg; |
ffc2605c TT |
9606 | event_location_up start_location = string_to_event_location (&arg, |
9607 | current_language); | |
9608 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
9609 | |
9610 | if (arg[0] != ',') | |
9611 | error (_("Too few arguments.")); | |
6c5b2ebe | 9612 | else if (canonical_start.lsals.empty ()) |
f1310107 | 9613 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 9614 | |
6c5b2ebe | 9615 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 9616 | |
6c5b2ebe PA |
9617 | if (canonical_start.lsals.size () > 1 |
9618 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
9619 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9620 | ||
6c5b2ebe | 9621 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 9622 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
9623 | |
9624 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9625 | arg = skip_spaces (arg); |
f1310107 TJB |
9626 | |
9627 | /* Parse the end location. */ | |
9628 | ||
f1310107 TJB |
9629 | arg_start = arg; |
9630 | ||
f8eba3c6 | 9631 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9632 | parse_breakpoint_sals because we need to specify the start location's |
9633 | symtab and line as the default symtab and line for the end of the | |
9634 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9635 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
9636 | event_location_up end_location = string_to_event_location (&arg, |
9637 | current_language); | |
9638 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
9639 | sal_start.symtab, sal_start.line, |
9640 | &canonical_end, NULL, NULL); | |
9641 | ||
6c5b2ebe | 9642 | if (canonical_end.lsals.empty ()) |
f1310107 | 9643 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 9644 | |
6c5b2ebe PA |
9645 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
9646 | if (canonical_end.lsals.size () > 1 | |
9647 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
9648 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9649 | ||
6c5b2ebe | 9650 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
9651 | |
9652 | end = find_breakpoint_range_end (sal_end); | |
9653 | if (sal_start.pc > end) | |
177b42fe | 9654 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9655 | |
9656 | length = end - sal_start.pc + 1; | |
9657 | if (length < 0) | |
9658 | /* Length overflowed. */ | |
9659 | error (_("Address range too large.")); | |
9660 | else if (length == 1) | |
9661 | { | |
9662 | /* This range is simple enough to be handled by | |
9663 | the `hbreak' command. */ | |
81b1e71c | 9664 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
9665 | |
9666 | return; | |
9667 | } | |
9668 | ||
9669 | /* Now set up the breakpoint. */ | |
9670 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9671 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9672 | set_breakpoint_count (breakpoint_count + 1); |
9673 | b->number = breakpoint_count; | |
9674 | b->disposition = disp_donttouch; | |
d28cd78a TT |
9675 | b->location = std::move (start_location); |
9676 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
9677 | b->loc->length = length; |
9678 | ||
f1310107 | 9679 | mention (b); |
76727919 | 9680 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 9681 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
9682 | } |
9683 | ||
4a64f543 MS |
9684 | /* Return non-zero if EXP is verified as constant. Returned zero |
9685 | means EXP is variable. Also the constant detection may fail for | |
9686 | some constant expressions and in such case still falsely return | |
9687 | zero. */ | |
2e6e3d9c | 9688 | |
dab72643 | 9689 | static bool |
65d79d4b SDJ |
9690 | watchpoint_exp_is_const (const struct expression *exp) |
9691 | { | |
1eaebe02 | 9692 | return exp->op->constant_p (); |
65d79d4b SDJ |
9693 | } |
9694 | ||
348d480f PA |
9695 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
9696 | ||
9697 | static void | |
9698 | re_set_watchpoint (struct breakpoint *b) | |
9699 | { | |
3a5c3e22 PA |
9700 | struct watchpoint *w = (struct watchpoint *) b; |
9701 | ||
348d480f PA |
9702 | /* Watchpoint can be either on expression using entirely global |
9703 | variables, or it can be on local variables. | |
9704 | ||
9705 | Watchpoints of the first kind are never auto-deleted, and even | |
9706 | persist across program restarts. Since they can use variables | |
9707 | from shared libraries, we need to reparse expression as libraries | |
9708 | are loaded and unloaded. | |
9709 | ||
9710 | Watchpoints on local variables can also change meaning as result | |
9711 | of solib event. For example, if a watchpoint uses both a local | |
9712 | and a global variables in expression, it's a local watchpoint, | |
9713 | but unloading of a shared library will make the expression | |
9714 | invalid. This is not a very common use case, but we still | |
9715 | re-evaluate expression, to avoid surprises to the user. | |
9716 | ||
9717 | Note that for local watchpoints, we re-evaluate it only if | |
9718 | watchpoints frame id is still valid. If it's not, it means the | |
9719 | watchpoint is out of scope and will be deleted soon. In fact, | |
9720 | I'm not sure we'll ever be called in this case. | |
9721 | ||
9722 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 9723 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 9724 | |
3a5c3e22 PA |
9725 | Don't do anything about disabled watchpoints, since they will be |
9726 | reevaluated again when enabled. */ | |
9727 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
9728 | } |
9729 | ||
77b06cd7 TJB |
9730 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
9731 | ||
9732 | static int | |
9733 | insert_watchpoint (struct bp_location *bl) | |
9734 | { | |
3a5c3e22 PA |
9735 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9736 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
9737 | |
9738 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 9739 | w->cond_exp.get ()); |
77b06cd7 TJB |
9740 | } |
9741 | ||
9742 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
9743 | ||
9744 | static int | |
73971819 | 9745 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 9746 | { |
3a5c3e22 PA |
9747 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9748 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
9749 | |
9750 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 9751 | w->cond_exp.get ()); |
e09342b5 TJB |
9752 | } |
9753 | ||
e09342b5 | 9754 | static int |
348d480f | 9755 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 9756 | const address_space *aspace, CORE_ADDR bp_addr, |
c272a98c | 9757 | const target_waitstatus &ws) |
e09342b5 | 9758 | { |
348d480f | 9759 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 9760 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 9761 | |
348d480f PA |
9762 | /* Continuable hardware watchpoints are treated as non-existent if the |
9763 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
9764 | some data address). Otherwise gdb won't stop on a break instruction | |
9765 | in the code (not from a breakpoint) when a hardware watchpoint has | |
9766 | been defined. Also skip watchpoints which we know did not trigger | |
9767 | (did not match the data address). */ | |
9768 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 9769 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 9770 | return 0; |
9c06b0b4 | 9771 | |
348d480f | 9772 | return 1; |
9c06b0b4 TJB |
9773 | } |
9774 | ||
348d480f | 9775 | static void |
313f3b21 | 9776 | check_status_watchpoint (bpstat *bs) |
9c06b0b4 | 9777 | { |
348d480f | 9778 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 9779 | |
348d480f | 9780 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
9781 | } |
9782 | ||
9783 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 9784 | hardware watchpoints. */ |
9c06b0b4 TJB |
9785 | |
9786 | static int | |
348d480f | 9787 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 9788 | { |
3a5c3e22 PA |
9789 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9790 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
9791 | |
9792 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
9793 | } |
9794 | ||
9795 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 9796 | hardware watchpoints. */ |
9c06b0b4 TJB |
9797 | |
9798 | static int | |
348d480f | 9799 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 9800 | { |
efa80663 PA |
9801 | /* Read and access watchpoints only work with hardware support. */ |
9802 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
9803 | } |
9804 | ||
9c06b0b4 | 9805 | static enum print_stop_action |
313f3b21 | 9806 | print_it_watchpoint (bpstat *bs) |
9c06b0b4 | 9807 | { |
348d480f | 9808 | struct breakpoint *b; |
348d480f | 9809 | enum print_stop_action result; |
3a5c3e22 | 9810 | struct watchpoint *w; |
79a45e25 | 9811 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9812 | |
9813 | gdb_assert (bs->bp_location_at != NULL); | |
9814 | ||
348d480f | 9815 | b = bs->breakpoint_at; |
3a5c3e22 | 9816 | w = (struct watchpoint *) b; |
348d480f | 9817 | |
f303dbd6 PA |
9818 | annotate_watchpoint (b->number); |
9819 | maybe_print_thread_hit_breakpoint (uiout); | |
9820 | ||
d7e74731 PA |
9821 | string_file stb; |
9822 | ||
76f9c9cf | 9823 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
9824 | switch (b->type) |
9825 | { | |
348d480f | 9826 | case bp_watchpoint: |
9c06b0b4 | 9827 | case bp_hardware_watchpoint: |
112e8700 SM |
9828 | if (uiout->is_mi_like_p ()) |
9829 | uiout->field_string | |
9830 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 9831 | mention (b); |
76f9c9cf | 9832 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 9833 | uiout->text ("\nOld value = "); |
850645cf | 9834 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
9835 | uiout->field_stream ("old", stb); |
9836 | uiout->text ("\nNew value = "); | |
850645cf | 9837 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
9838 | uiout->field_stream ("new", stb); |
9839 | uiout->text ("\n"); | |
348d480f PA |
9840 | /* More than one watchpoint may have been triggered. */ |
9841 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9842 | break; |
9843 | ||
9844 | case bp_read_watchpoint: | |
112e8700 SM |
9845 | if (uiout->is_mi_like_p ()) |
9846 | uiout->field_string | |
9847 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 9848 | mention (b); |
76f9c9cf | 9849 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 9850 | uiout->text ("\nValue = "); |
850645cf | 9851 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
9852 | uiout->field_stream ("value", stb); |
9853 | uiout->text ("\n"); | |
348d480f | 9854 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9855 | break; |
9856 | ||
9857 | case bp_access_watchpoint: | |
348d480f PA |
9858 | if (bs->old_val != NULL) |
9859 | { | |
112e8700 SM |
9860 | if (uiout->is_mi_like_p ()) |
9861 | uiout->field_string | |
9862 | ("reason", | |
348d480f PA |
9863 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
9864 | mention (b); | |
76f9c9cf | 9865 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 9866 | uiout->text ("\nOld value = "); |
850645cf | 9867 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
9868 | uiout->field_stream ("old", stb); |
9869 | uiout->text ("\nNew value = "); | |
348d480f PA |
9870 | } |
9871 | else | |
9872 | { | |
9873 | mention (b); | |
112e8700 SM |
9874 | if (uiout->is_mi_like_p ()) |
9875 | uiout->field_string | |
9876 | ("reason", | |
348d480f | 9877 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 9878 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 9879 | uiout->text ("\nValue = "); |
348d480f | 9880 | } |
850645cf | 9881 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
9882 | uiout->field_stream ("new", stb); |
9883 | uiout->text ("\n"); | |
348d480f | 9884 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9885 | break; |
9886 | default: | |
348d480f | 9887 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9888 | } |
9889 | ||
348d480f PA |
9890 | return result; |
9891 | } | |
9892 | ||
9893 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
9894 | watchpoints. */ | |
9895 | ||
9896 | static void | |
9897 | print_mention_watchpoint (struct breakpoint *b) | |
9898 | { | |
3a5c3e22 | 9899 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 9900 | struct ui_out *uiout = current_uiout; |
46b9c129 | 9901 | const char *tuple_name; |
348d480f PA |
9902 | |
9903 | switch (b->type) | |
9904 | { | |
9905 | case bp_watchpoint: | |
112e8700 | 9906 | uiout->text ("Watchpoint "); |
46b9c129 | 9907 | tuple_name = "wpt"; |
348d480f PA |
9908 | break; |
9909 | case bp_hardware_watchpoint: | |
112e8700 | 9910 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 9911 | tuple_name = "wpt"; |
348d480f PA |
9912 | break; |
9913 | case bp_read_watchpoint: | |
112e8700 | 9914 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 9915 | tuple_name = "hw-rwpt"; |
348d480f PA |
9916 | break; |
9917 | case bp_access_watchpoint: | |
112e8700 | 9918 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 9919 | tuple_name = "hw-awpt"; |
348d480f PA |
9920 | break; |
9921 | default: | |
9922 | internal_error (__FILE__, __LINE__, | |
9923 | _("Invalid hardware watchpoint type.")); | |
9924 | } | |
9925 | ||
46b9c129 | 9926 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 9927 | uiout->field_signed ("number", b->number); |
112e8700 | 9928 | uiout->text (": "); |
a4c50be3 | 9929 | uiout->field_string ("exp", w->exp_string.get ()); |
348d480f PA |
9930 | } |
9931 | ||
9932 | /* Implement the "print_recreate" breakpoint_ops method for | |
9933 | watchpoints. */ | |
9934 | ||
9935 | static void | |
9936 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9937 | { | |
3a5c3e22 PA |
9938 | struct watchpoint *w = (struct watchpoint *) b; |
9939 | ||
348d480f PA |
9940 | switch (b->type) |
9941 | { | |
9942 | case bp_watchpoint: | |
9943 | case bp_hardware_watchpoint: | |
9944 | fprintf_unfiltered (fp, "watch"); | |
9945 | break; | |
9946 | case bp_read_watchpoint: | |
9947 | fprintf_unfiltered (fp, "rwatch"); | |
9948 | break; | |
9949 | case bp_access_watchpoint: | |
9950 | fprintf_unfiltered (fp, "awatch"); | |
9951 | break; | |
9952 | default: | |
9953 | internal_error (__FILE__, __LINE__, | |
9954 | _("Invalid watchpoint type.")); | |
9955 | } | |
9956 | ||
a4c50be3 | 9957 | fprintf_unfiltered (fp, " %s", w->exp_string.get ()); |
d9b3f62e | 9958 | print_recreate_thread (b, fp); |
348d480f PA |
9959 | } |
9960 | ||
427cd150 TT |
9961 | /* Implement the "explains_signal" breakpoint_ops method for |
9962 | watchpoints. */ | |
9963 | ||
47591c29 | 9964 | static int |
427cd150 TT |
9965 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
9966 | { | |
9967 | /* A software watchpoint cannot cause a signal other than | |
9968 | GDB_SIGNAL_TRAP. */ | |
9969 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 9970 | return 0; |
427cd150 | 9971 | |
47591c29 | 9972 | return 1; |
427cd150 TT |
9973 | } |
9974 | ||
348d480f PA |
9975 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
9976 | ||
2060206e | 9977 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
9978 | |
9979 | /* Implement the "insert" breakpoint_ops method for | |
9980 | masked hardware watchpoints. */ | |
9981 | ||
9982 | static int | |
9983 | insert_masked_watchpoint (struct bp_location *bl) | |
9984 | { | |
3a5c3e22 PA |
9985 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9986 | ||
9987 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
9988 | bl->watchpoint_type); |
9989 | } | |
9990 | ||
9991 | /* Implement the "remove" breakpoint_ops method for | |
9992 | masked hardware watchpoints. */ | |
9993 | ||
9994 | static int | |
73971819 | 9995 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 9996 | { |
3a5c3e22 PA |
9997 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
9998 | ||
9999 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
dda83cd7 | 10000 | bl->watchpoint_type); |
348d480f PA |
10001 | } |
10002 | ||
10003 | /* Implement the "resources_needed" breakpoint_ops method for | |
10004 | masked hardware watchpoints. */ | |
10005 | ||
10006 | static int | |
10007 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10008 | { | |
3a5c3e22 PA |
10009 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10010 | ||
10011 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10012 | } |
10013 | ||
10014 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10015 | masked hardware watchpoints. */ | |
10016 | ||
10017 | static int | |
10018 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10019 | { | |
10020 | return 0; | |
10021 | } | |
10022 | ||
10023 | /* Implement the "print_it" breakpoint_ops method for | |
10024 | masked hardware watchpoints. */ | |
10025 | ||
10026 | static enum print_stop_action | |
313f3b21 | 10027 | print_it_masked_watchpoint (bpstat *bs) |
348d480f PA |
10028 | { |
10029 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10030 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10031 | |
10032 | /* Masked watchpoints have only one location. */ | |
10033 | gdb_assert (b->loc && b->loc->next == NULL); | |
10034 | ||
f303dbd6 PA |
10035 | annotate_watchpoint (b->number); |
10036 | maybe_print_thread_hit_breakpoint (uiout); | |
10037 | ||
348d480f PA |
10038 | switch (b->type) |
10039 | { | |
10040 | case bp_hardware_watchpoint: | |
112e8700 SM |
10041 | if (uiout->is_mi_like_p ()) |
10042 | uiout->field_string | |
10043 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10044 | break; |
10045 | ||
10046 | case bp_read_watchpoint: | |
112e8700 SM |
10047 | if (uiout->is_mi_like_p ()) |
10048 | uiout->field_string | |
10049 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10050 | break; |
10051 | ||
10052 | case bp_access_watchpoint: | |
112e8700 SM |
10053 | if (uiout->is_mi_like_p ()) |
10054 | uiout->field_string | |
10055 | ("reason", | |
348d480f PA |
10056 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10057 | break; | |
10058 | default: | |
10059 | internal_error (__FILE__, __LINE__, | |
10060 | _("Invalid hardware watchpoint type.")); | |
10061 | } | |
10062 | ||
10063 | mention (b); | |
112e8700 | 10064 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10065 | Check the underlying instruction at PC for the memory\n\ |
10066 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10067 | uiout->text ("\n"); |
9c06b0b4 TJB |
10068 | |
10069 | /* More than one watchpoint may have been triggered. */ | |
10070 | return PRINT_UNKNOWN; | |
10071 | } | |
10072 | ||
10073 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10074 | masked hardware watchpoints. */ | |
10075 | ||
10076 | static void | |
10077 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10078 | struct ui_out *uiout) | |
10079 | { | |
3a5c3e22 PA |
10080 | struct watchpoint *w = (struct watchpoint *) b; |
10081 | ||
9c06b0b4 TJB |
10082 | /* Masked watchpoints have only one location. */ |
10083 | gdb_assert (b->loc && b->loc->next == NULL); | |
10084 | ||
112e8700 SM |
10085 | uiout->text ("\tmask "); |
10086 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10087 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10088 | } |
10089 | ||
10090 | /* Implement the "print_mention" breakpoint_ops method for | |
10091 | masked hardware watchpoints. */ | |
10092 | ||
10093 | static void | |
10094 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10095 | { | |
3a5c3e22 | 10096 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10097 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10098 | const char *tuple_name; |
9c06b0b4 TJB |
10099 | |
10100 | switch (b->type) | |
10101 | { | |
10102 | case bp_hardware_watchpoint: | |
112e8700 | 10103 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10104 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10105 | break; |
10106 | case bp_read_watchpoint: | |
112e8700 | 10107 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10108 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10109 | break; |
10110 | case bp_access_watchpoint: | |
112e8700 | 10111 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10112 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10113 | break; |
10114 | default: | |
10115 | internal_error (__FILE__, __LINE__, | |
10116 | _("Invalid hardware watchpoint type.")); | |
10117 | } | |
10118 | ||
46b9c129 | 10119 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10120 | uiout->field_signed ("number", b->number); |
112e8700 | 10121 | uiout->text (": "); |
a4c50be3 | 10122 | uiout->field_string ("exp", w->exp_string.get ()); |
9c06b0b4 TJB |
10123 | } |
10124 | ||
10125 | /* Implement the "print_recreate" breakpoint_ops method for | |
10126 | masked hardware watchpoints. */ | |
10127 | ||
10128 | static void | |
10129 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10130 | { | |
3a5c3e22 | 10131 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10132 | |
10133 | switch (b->type) | |
10134 | { | |
10135 | case bp_hardware_watchpoint: | |
10136 | fprintf_unfiltered (fp, "watch"); | |
10137 | break; | |
10138 | case bp_read_watchpoint: | |
10139 | fprintf_unfiltered (fp, "rwatch"); | |
10140 | break; | |
10141 | case bp_access_watchpoint: | |
10142 | fprintf_unfiltered (fp, "awatch"); | |
10143 | break; | |
10144 | default: | |
10145 | internal_error (__FILE__, __LINE__, | |
10146 | _("Invalid hardware watchpoint type.")); | |
10147 | } | |
10148 | ||
a4c50be3 | 10149 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string.get (), |
53807e9f | 10150 | phex (w->hw_wp_mask, sizeof (CORE_ADDR))); |
d9b3f62e | 10151 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10152 | } |
10153 | ||
10154 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10155 | ||
2060206e | 10156 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10157 | |
10158 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10159 | ||
f2478a7e | 10160 | static bool |
9c06b0b4 TJB |
10161 | is_masked_watchpoint (const struct breakpoint *b) |
10162 | { | |
10163 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10164 | } | |
10165 | ||
53a5351d | 10166 | /* accessflag: hw_write: watch write, |
dda83cd7 | 10167 | hw_read: watch read, |
53a5351d | 10168 | hw_access: watch access (read or write) */ |
c906108c | 10169 | static void |
bbc13ae3 | 10170 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
2e362716 | 10171 | bool just_location, bool internal) |
c906108c | 10172 | { |
c1fc2657 | 10173 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10174 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 10175 | struct value *result; |
bb9d5f81 | 10176 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10177 | const char *exp_start = NULL; |
10178 | const char *exp_end = NULL; | |
10179 | const char *tok, *end_tok; | |
9c06b0b4 | 10180 | int toklen = -1; |
bbc13ae3 KS |
10181 | const char *cond_start = NULL; |
10182 | const char *cond_end = NULL; | |
c906108c | 10183 | enum bptype bp_type; |
37e4754d | 10184 | int thread = -1; |
9c06b0b4 TJB |
10185 | /* Flag to indicate whether we are going to use masks for |
10186 | the hardware watchpoint. */ | |
2e362716 | 10187 | bool use_mask = false; |
9c06b0b4 | 10188 | CORE_ADDR mask = 0; |
8a18382f | 10189 | int task = 0; |
c906108c | 10190 | |
37e4754d LM |
10191 | /* Make sure that we actually have parameters to parse. */ |
10192 | if (arg != NULL && arg[0] != '\0') | |
10193 | { | |
bbc13ae3 KS |
10194 | const char *value_start; |
10195 | ||
10196 | exp_end = arg + strlen (arg); | |
37e4754d | 10197 | |
9c06b0b4 TJB |
10198 | /* Look for "parameter value" pairs at the end |
10199 | of the arguments string. */ | |
bbc13ae3 | 10200 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10201 | { |
10202 | /* Skip whitespace at the end of the argument list. */ | |
10203 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10204 | tok--; | |
10205 | ||
10206 | /* Find the beginning of the last token. | |
10207 | This is the value of the parameter. */ | |
10208 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10209 | tok--; | |
10210 | value_start = tok + 1; | |
10211 | ||
10212 | /* Skip whitespace. */ | |
10213 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10214 | tok--; | |
10215 | ||
10216 | end_tok = tok; | |
10217 | ||
10218 | /* Find the beginning of the second to last token. | |
10219 | This is the parameter itself. */ | |
10220 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10221 | tok--; | |
10222 | tok++; | |
10223 | toklen = end_tok - tok + 1; | |
10224 | ||
61012eef | 10225 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10226 | { |
5d5658a1 | 10227 | struct thread_info *thr; |
9c06b0b4 TJB |
10228 | /* At this point we've found a "thread" token, which means |
10229 | the user is trying to set a watchpoint that triggers | |
10230 | only in a specific thread. */ | |
5d5658a1 | 10231 | const char *endp; |
37e4754d | 10232 | |
9c06b0b4 TJB |
10233 | if (thread != -1) |
10234 | error(_("You can specify only one thread.")); | |
37e4754d | 10235 | |
9c06b0b4 | 10236 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10237 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10238 | |
5d5658a1 | 10239 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10240 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10241 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10242 | |
5d5658a1 | 10243 | thread = thr->global_num; |
9c06b0b4 | 10244 | } |
8a18382f TT |
10245 | else if (toklen == 4 && startswith (tok, "task")) |
10246 | { | |
10247 | char *tmp; | |
10248 | ||
10249 | task = strtol (value_start, &tmp, 0); | |
10250 | if (tmp == value_start) | |
10251 | error (_("Junk after task keyword.")); | |
10252 | if (!valid_task_id (task)) | |
10253 | error (_("Unknown task %d."), task); | |
10254 | } | |
61012eef | 10255 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10256 | { |
10257 | /* We've found a "mask" token, which means the user wants to | |
10258 | create a hardware watchpoint that is going to have the mask | |
10259 | facility. */ | |
10260 | struct value *mask_value, *mark; | |
37e4754d | 10261 | |
9c06b0b4 TJB |
10262 | if (use_mask) |
10263 | error(_("You can specify only one mask.")); | |
37e4754d | 10264 | |
2e362716 | 10265 | use_mask = just_location = true; |
37e4754d | 10266 | |
9c06b0b4 TJB |
10267 | mark = value_mark (); |
10268 | mask_value = parse_to_comma_and_eval (&value_start); | |
10269 | mask = value_as_address (mask_value); | |
10270 | value_free_to_mark (mark); | |
10271 | } | |
10272 | else | |
10273 | /* We didn't recognize what we found. We should stop here. */ | |
10274 | break; | |
37e4754d | 10275 | |
9c06b0b4 TJB |
10276 | /* Truncate the string and get rid of the "parameter value" pair before |
10277 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10278 | exp_end = tok; |
9c06b0b4 | 10279 | } |
37e4754d | 10280 | } |
bbc13ae3 KS |
10281 | else |
10282 | exp_end = arg; | |
37e4754d | 10283 | |
bbc13ae3 KS |
10284 | /* Parse the rest of the arguments. From here on out, everything |
10285 | is in terms of a newly allocated string instead of the original | |
10286 | ARG. */ | |
81b1e71c TT |
10287 | std::string expression (arg, exp_end - arg); |
10288 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10289 | innermost_block_tracker tracker; |
10290 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10291 | exp_end = arg; |
fa8a61dc TT |
10292 | /* Remove trailing whitespace from the expression before saving it. |
10293 | This makes the eventual display of the expression string a bit | |
10294 | prettier. */ | |
10295 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10296 | --exp_end; | |
10297 | ||
65d79d4b | 10298 | /* Checking if the expression is not constant. */ |
4d01a485 | 10299 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10300 | { |
10301 | int len; | |
10302 | ||
10303 | len = exp_end - exp_start; | |
10304 | while (len > 0 && isspace (exp_start[len - 1])) | |
10305 | len--; | |
10306 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10307 | } | |
10308 | ||
699bd4cf | 10309 | exp_valid_block = tracker.block (); |
b926417a | 10310 | struct value *mark = value_mark (); |
850645cf | 10311 | struct value *val_as_value = nullptr; |
1eaebe02 TT |
10312 | fetch_subexp_value (exp.get (), exp->op.get (), &val_as_value, &result, NULL, |
10313 | just_location); | |
06a64a0b | 10314 | |
850645cf | 10315 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10316 | { |
850645cf TT |
10317 | saved_bitpos = value_bitpos (val_as_value); |
10318 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10319 | } |
10320 | ||
850645cf | 10321 | value_ref_ptr val; |
06a64a0b TT |
10322 | if (just_location) |
10323 | { | |
9c06b0b4 TJB |
10324 | int ret; |
10325 | ||
06a64a0b | 10326 | exp_valid_block = NULL; |
850645cf | 10327 | val = release_value (value_addr (result)); |
06a64a0b | 10328 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10329 | |
10330 | if (use_mask) | |
10331 | { | |
850645cf | 10332 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10333 | mask); |
10334 | if (ret == -1) | |
10335 | error (_("This target does not support masked watchpoints.")); | |
10336 | else if (ret == -2) | |
10337 | error (_("Invalid mask or memory region.")); | |
10338 | } | |
06a64a0b | 10339 | } |
850645cf TT |
10340 | else if (val_as_value != NULL) |
10341 | val = release_value (val_as_value); | |
c906108c | 10342 | |
f1735a53 TT |
10343 | tok = skip_spaces (arg); |
10344 | end_tok = skip_to_space (tok); | |
c906108c SS |
10345 | |
10346 | toklen = end_tok - tok; | |
10347 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10348 | { | |
10349 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10350 | innermost_block_tracker if_tracker; |
10351 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10352 | |
10353 | /* The watchpoint expression may not be local, but the condition | |
10354 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10355 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10356 | |
c906108c SS |
10357 | cond_end = tok; |
10358 | } | |
10359 | if (*tok) | |
8a3fe4f8 | 10360 | error (_("Junk at end of command.")); |
c906108c | 10361 | |
441d7c93 PA |
10362 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10363 | ||
10364 | /* Save this because create_internal_breakpoint below invalidates | |
10365 | 'wp_frame'. */ | |
10366 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10367 | |
10368 | /* If the expression is "local", then set up a "watchpoint scope" | |
10369 | breakpoint at the point where we've left the scope of the watchpoint | |
10370 | expression. Create the scope breakpoint before the watchpoint, so | |
10371 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10372 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10373 | { |
441d7c93 PA |
10374 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10375 | ||
10376 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10377 | { |
441d7c93 PA |
10378 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10379 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10380 | ||
24b21115 | 10381 | scope_breakpoint |
441d7c93 | 10382 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10383 | bp_watchpoint_scope, |
10384 | &momentary_breakpoint_ops); | |
d983da9c | 10385 | |
441d7c93 PA |
10386 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10387 | wp_frame = NULL; | |
10388 | ||
edb3359d | 10389 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10390 | |
edb3359d DJ |
10391 | /* Automatically delete the breakpoint when it hits. */ |
10392 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10393 | |
edb3359d | 10394 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10395 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10396 | |
edb3359d | 10397 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10398 | scope_breakpoint->loc->gdbarch = caller_arch; |
10399 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10400 | scope_breakpoint->loc->address |
a6d9a66e UW |
10401 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10402 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10403 | scope_breakpoint->type); |
10404 | } | |
d983da9c DJ |
10405 | } |
10406 | ||
e8369a73 AB |
10407 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10408 | watchpoints here even if hardware watchpoints are turned off, a call | |
10409 | to update_watchpoint later in this function will cause the type to | |
10410 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10411 | ||
10412 | if (accessflag == hw_read) | |
10413 | bp_type = bp_read_watchpoint; | |
10414 | else if (accessflag == hw_access) | |
10415 | bp_type = bp_access_watchpoint; | |
10416 | else | |
10417 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10418 | |
b270e6f9 | 10419 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10420 | |
348d480f | 10421 | if (use_mask) |
b270e6f9 | 10422 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10423 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10424 | else |
b270e6f9 | 10425 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10426 | &watchpoint_breakpoint_ops); |
c1fc2657 | 10427 | w->thread = thread; |
8a18382f | 10428 | w->task = task; |
c1fc2657 SM |
10429 | w->disposition = disp_donttouch; |
10430 | w->pspace = current_program_space; | |
b22e99fd | 10431 | w->exp = std::move (exp); |
3a5c3e22 PA |
10432 | w->exp_valid_block = exp_valid_block; |
10433 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10434 | if (just_location) |
10435 | { | |
850645cf TT |
10436 | struct type *t = value_type (val.get ()); |
10437 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10438 | |
43cc5389 | 10439 | w->exp_string_reparse |
a4c50be3 | 10440 | = current_language->watch_location_expression (t, addr); |
06a64a0b | 10441 | |
8579fd13 AB |
10442 | w->exp_string = xstrprintf ("-location %.*s", |
10443 | (int) (exp_end - exp_start), exp_start); | |
06a64a0b TT |
10444 | } |
10445 | else | |
a4c50be3 | 10446 | w->exp_string.reset (savestring (exp_start, exp_end - exp_start)); |
9c06b0b4 TJB |
10447 | |
10448 | if (use_mask) | |
10449 | { | |
3a5c3e22 | 10450 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10451 | } |
10452 | else | |
10453 | { | |
3a5c3e22 | 10454 | w->val = val; |
bb9d5f81 PP |
10455 | w->val_bitpos = saved_bitpos; |
10456 | w->val_bitsize = saved_bitsize; | |
4c1d86d9 | 10457 | w->val_valid = true; |
9c06b0b4 | 10458 | } |
77b06cd7 | 10459 | |
c906108c | 10460 | if (cond_start) |
6f781ee3 | 10461 | w->cond_string.reset (savestring (cond_start, cond_end - cond_start)); |
c906108c | 10462 | else |
c1fc2657 | 10463 | w->cond_string = 0; |
c5aa993b | 10464 | |
441d7c93 | 10465 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10466 | { |
441d7c93 | 10467 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10468 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10469 | } |
c906108c | 10470 | else |
f6bc2008 | 10471 | { |
3a5c3e22 PA |
10472 | w->watchpoint_frame = null_frame_id; |
10473 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10474 | } |
c906108c | 10475 | |
d983da9c | 10476 | if (scope_breakpoint != NULL) |
c906108c | 10477 | { |
d983da9c DJ |
10478 | /* The scope breakpoint is related to the watchpoint. We will |
10479 | need to act on them together. */ | |
c1fc2657 | 10480 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10481 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10482 | } |
d983da9c | 10483 | |
06a64a0b TT |
10484 | if (!just_location) |
10485 | value_free_to_mark (mark); | |
2d134ed3 | 10486 | |
b270e6f9 TT |
10487 | /* Finally update the new watchpoint. This creates the locations |
10488 | that should be inserted. */ | |
10489 | update_watchpoint (w.get (), 1); | |
a9634178 | 10490 | |
b270e6f9 | 10491 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10492 | } |
10493 | ||
e09342b5 | 10494 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10495 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10496 | |
c906108c | 10497 | static int |
a6535de1 | 10498 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
10499 | { |
10500 | int found_memory_cnt = 0; | |
10501 | ||
10502 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10503 | if (!can_use_hw_watchpoints) |
c906108c | 10504 | return 0; |
c5aa993b | 10505 | |
a6535de1 TT |
10506 | gdb_assert (!vals.empty ()); |
10507 | struct value *head = vals[0].get (); | |
10508 | ||
5c44784c JM |
10509 | /* Make sure that the value of the expression depends only upon |
10510 | memory contents, and values computed from them within GDB. If we | |
10511 | find any register references or function calls, we can't use a | |
10512 | hardware watchpoint. | |
10513 | ||
10514 | The idea here is that evaluating an expression generates a series | |
10515 | of values, one holding the value of every subexpression. (The | |
10516 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10517 | a*b+c.) GDB's values hold almost enough information to establish | |
10518 | the criteria given above --- they identify memory lvalues, | |
10519 | register lvalues, computed values, etcetera. So we can evaluate | |
10520 | the expression, and then scan the chain of values that leaves | |
10521 | behind to decide whether we can detect any possible change to the | |
10522 | expression's final value using only hardware watchpoints. | |
10523 | ||
10524 | However, I don't think that the values returned by inferior | |
10525 | function calls are special in any way. So this function may not | |
10526 | notice that an expression involving an inferior function call | |
10527 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 10528 | for (const value_ref_ptr &iter : vals) |
c906108c | 10529 | { |
a6535de1 TT |
10530 | struct value *v = iter.get (); |
10531 | ||
5c44784c | 10532 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10533 | { |
8464be76 DJ |
10534 | if (v != head && value_lazy (v)) |
10535 | /* A lazy memory lvalue in the chain is one that GDB never | |
10536 | needed to fetch; we either just used its address (e.g., | |
10537 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10538 | in `a,b'). This doesn't apply to HEAD; if that is | |
10539 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10540 | ; |
53a5351d | 10541 | else |
5c44784c JM |
10542 | { |
10543 | /* Ahh, memory we actually used! Check if we can cover | |
dda83cd7 | 10544 | it with hardware watchpoints. */ |
df407dfe | 10545 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10546 | |
10547 | /* We only watch structs and arrays if user asked for it | |
10548 | explicitly, never if they just happen to appear in a | |
10549 | middle of some value chain. */ | |
10550 | if (v == head | |
78134374 SM |
10551 | || (vtype->code () != TYPE_CODE_STRUCT |
10552 | && vtype->code () != TYPE_CODE_ARRAY)) | |
2e70b7b9 | 10553 | { |
42ae5230 | 10554 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10555 | int len; |
10556 | int num_regs; | |
10557 | ||
a9634178 | 10558 | len = (target_exact_watchpoints |
e09342b5 TJB |
10559 | && is_scalar_type_recursive (vtype))? |
10560 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10561 | |
e09342b5 TJB |
10562 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10563 | if (!num_regs) | |
2e70b7b9 MS |
10564 | return 0; |
10565 | else | |
e09342b5 | 10566 | found_memory_cnt += num_regs; |
2e70b7b9 | 10567 | } |
5c44784c | 10568 | } |
c5aa993b | 10569 | } |
5086187c AC |
10570 | else if (VALUE_LVAL (v) != not_lval |
10571 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10572 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10573 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10574 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10575 | } |
10576 | ||
10577 | /* The expression itself looks suitable for using a hardware | |
10578 | watchpoint, but give the target machine a chance to reject it. */ | |
10579 | return found_memory_cnt; | |
10580 | } | |
10581 | ||
8b93c638 | 10582 | void |
2e362716 | 10583 | watch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 10584 | { |
84f4c1fe | 10585 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10586 | } |
10587 | ||
a15a5258 AB |
10588 | /* Options for the watch, awatch, and rwatch commands. */ |
10589 | ||
10590 | struct watch_options | |
10591 | { | |
10592 | /* For -location. */ | |
10593 | bool location = false; | |
10594 | }; | |
10595 | ||
10596 | /* Definitions of options for the "watch", "awatch", and "rwatch" commands. | |
10597 | ||
10598 | Historically GDB always accepted both '-location' and '-l' flags for | |
10599 | these commands (both flags being synonyms). When converting to the | |
10600 | newer option scheme only '-location' is added here. That's fine (for | |
10601 | backward compatibility) as any non-ambiguous prefix of a flag will be | |
10602 | accepted, so '-l', '-loc', are now all accepted. | |
10603 | ||
10604 | What this means is that, if in the future, we add any new flag here | |
10605 | that starts with '-l' then this will break backward compatibility, so | |
10606 | please, don't do that! */ | |
10607 | ||
10608 | static const gdb::option::option_def watch_option_defs[] = { | |
10609 | gdb::option::flag_option_def<watch_options> { | |
10610 | "location", | |
10611 | [] (watch_options *opt) { return &opt->location; }, | |
10612 | N_("\ | |
10613 | This evaluates EXPRESSION and watches the memory to which is refers.\n\ | |
10614 | -l can be used as a short form of -location."), | |
10615 | }, | |
10616 | }; | |
10617 | ||
10618 | /* Returns the option group used by 'watch', 'awatch', and 'rwatch' | |
10619 | commands. */ | |
10620 | ||
10621 | static gdb::option::option_def_group | |
10622 | make_watch_options_def_group (watch_options *opts) | |
10623 | { | |
10624 | return {{watch_option_defs}, opts}; | |
10625 | } | |
10626 | ||
06a64a0b TT |
10627 | /* A helper function that looks for the "-location" argument and then |
10628 | calls watch_command_1. */ | |
10629 | ||
10630 | static void | |
0b39b52e | 10631 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b | 10632 | { |
a15a5258 AB |
10633 | watch_options opts; |
10634 | auto grp = make_watch_options_def_group (&opts); | |
10635 | gdb::option::process_options | |
10636 | (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp); | |
10637 | if (arg != nullptr && *arg == '\0') | |
10638 | arg = nullptr; | |
10639 | ||
10640 | watch_command_1 (arg, accessflag, from_tty, opts.location, false); | |
10641 | } | |
06a64a0b | 10642 | |
a15a5258 AB |
10643 | /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */ |
10644 | static void | |
10645 | watch_command_completer (struct cmd_list_element *ignore, | |
10646 | completion_tracker &tracker, | |
10647 | const char *text, const char * /*word*/) | |
10648 | { | |
10649 | const auto group = make_watch_options_def_group (nullptr); | |
10650 | if (gdb::option::complete_options | |
10651 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group)) | |
10652 | return; | |
06a64a0b | 10653 | |
a15a5258 AB |
10654 | const char *word = advance_to_expression_complete_word_point (tracker, text); |
10655 | expression_completer (ignore, tracker, text, word); | |
8b93c638 | 10656 | } |
8926118c | 10657 | |
c5aa993b | 10658 | static void |
0b39b52e | 10659 | watch_command (const char *arg, int from_tty) |
c906108c | 10660 | { |
06a64a0b | 10661 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10662 | } |
10663 | ||
8b93c638 | 10664 | void |
2e362716 | 10665 | rwatch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 10666 | { |
84f4c1fe | 10667 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10668 | } |
8926118c | 10669 | |
c5aa993b | 10670 | static void |
0b39b52e | 10671 | rwatch_command (const char *arg, int from_tty) |
c906108c | 10672 | { |
06a64a0b | 10673 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10674 | } |
10675 | ||
8b93c638 | 10676 | void |
2e362716 | 10677 | awatch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 10678 | { |
84f4c1fe | 10679 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10680 | } |
8926118c | 10681 | |
c5aa993b | 10682 | static void |
0b39b52e | 10683 | awatch_command (const char *arg, int from_tty) |
c906108c | 10684 | { |
06a64a0b | 10685 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10686 | } |
c906108c | 10687 | \f |
c5aa993b | 10688 | |
cfc31633 PA |
10689 | /* Data for the FSM that manages the until(location)/advance commands |
10690 | in infcmd.c. Here because it uses the mechanisms of | |
10691 | breakpoints. */ | |
c906108c | 10692 | |
46e3ed7f | 10693 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 10694 | { |
46e3ed7f | 10695 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
10696 | int thread; |
10697 | ||
df631783 PA |
10698 | /* The breakpoint set at the return address in the caller frame, |
10699 | plus breakpoints at all the destination locations. */ | |
10700 | std::vector<breakpoint_up> breakpoints; | |
cfc31633 | 10701 | |
46e3ed7f | 10702 | until_break_fsm (struct interp *cmd_interp, int thread, |
df631783 | 10703 | std::vector<breakpoint_up> &&breakpoints) |
46e3ed7f TT |
10704 | : thread_fsm (cmd_interp), |
10705 | thread (thread), | |
df631783 | 10706 | breakpoints (std::move (breakpoints)) |
46e3ed7f TT |
10707 | { |
10708 | } | |
cfc31633 | 10709 | |
46e3ed7f TT |
10710 | void clean_up (struct thread_info *thread) override; |
10711 | bool should_stop (struct thread_info *thread) override; | |
10712 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
10713 | }; |
10714 | ||
cfc31633 PA |
10715 | /* Implementation of the 'should_stop' FSM method for the |
10716 | until(location)/advance commands. */ | |
10717 | ||
46e3ed7f TT |
10718 | bool |
10719 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 10720 | { |
df631783 PA |
10721 | for (const breakpoint_up &bp : breakpoints) |
10722 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
10723 | bp.get ()) != NULL) | |
10724 | { | |
10725 | set_finished (); | |
10726 | break; | |
10727 | } | |
cfc31633 | 10728 | |
46e3ed7f | 10729 | return true; |
cfc31633 PA |
10730 | } |
10731 | ||
10732 | /* Implementation of the 'clean_up' FSM method for the | |
10733 | until(location)/advance commands. */ | |
10734 | ||
46e3ed7f TT |
10735 | void |
10736 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 10737 | { |
cfc31633 | 10738 | /* Clean up our temporary breakpoints. */ |
df631783 | 10739 | breakpoints.clear (); |
46e3ed7f | 10740 | delete_longjmp_breakpoint (thread); |
cfc31633 PA |
10741 | } |
10742 | ||
10743 | /* Implementation of the 'async_reply_reason' FSM method for the | |
10744 | until(location)/advance commands. */ | |
10745 | ||
46e3ed7f TT |
10746 | enum async_reply_reason |
10747 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
10748 | { |
10749 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
10750 | } |
10751 | ||
c906108c | 10752 | void |
f2fc3015 | 10753 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 10754 | { |
8556afb4 PA |
10755 | struct frame_info *frame; |
10756 | struct gdbarch *frame_gdbarch; | |
10757 | struct frame_id stack_frame_id; | |
10758 | struct frame_id caller_frame_id; | |
186c406b TT |
10759 | int thread; |
10760 | struct thread_info *tp; | |
c906108c | 10761 | |
70509625 | 10762 | clear_proceed_status (0); |
c906108c SS |
10763 | |
10764 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 10765 | this function. */ |
c5aa993b | 10766 | |
ffc2605c | 10767 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 10768 | |
6c5b2ebe PA |
10769 | std::vector<symtab_and_line> sals |
10770 | = (last_displayed_sal_is_valid () | |
10771 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
10772 | get_last_displayed_symtab (), | |
10773 | get_last_displayed_line ()) | |
10774 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 10775 | NULL, NULL, 0)); |
c5aa993b | 10776 | |
df631783 | 10777 | if (sals.empty ()) |
8a3fe4f8 | 10778 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 10779 | |
c906108c | 10780 | if (*arg) |
8a3fe4f8 | 10781 | error (_("Junk at end of arguments.")); |
c5aa993b | 10782 | |
186c406b | 10783 | tp = inferior_thread (); |
5d5658a1 | 10784 | thread = tp->global_num; |
186c406b | 10785 | |
8556afb4 PA |
10786 | /* Note linespec handling above invalidates the frame chain. |
10787 | Installing a breakpoint also invalidates the frame chain (as it | |
10788 | may need to switch threads), so do any frame handling before | |
10789 | that. */ | |
10790 | ||
10791 | frame = get_selected_frame (NULL); | |
10792 | frame_gdbarch = get_frame_arch (frame); | |
10793 | stack_frame_id = get_stack_frame_id (frame); | |
10794 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 10795 | |
ae66c1fc EZ |
10796 | /* Keep within the current frame, or in frames called by the current |
10797 | one. */ | |
edb3359d | 10798 | |
df631783 | 10799 | std::vector<breakpoint_up> breakpoints; |
5419bdae TT |
10800 | |
10801 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
10802 | ||
883bc8d1 | 10803 | if (frame_id_p (caller_frame_id)) |
c906108c | 10804 | { |
883bc8d1 | 10805 | struct symtab_and_line sal2; |
cfc31633 | 10806 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
10807 | |
10808 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
10809 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 | 10810 | caller_gdbarch = frame_unwind_caller_arch (frame); |
df631783 PA |
10811 | |
10812 | breakpoint_up caller_breakpoint | |
10813 | = set_momentary_breakpoint (caller_gdbarch, sal2, | |
10814 | caller_frame_id, bp_until); | |
10815 | breakpoints.emplace_back (std::move (caller_breakpoint)); | |
186c406b | 10816 | |
883bc8d1 | 10817 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 10818 | lj_deleter.emplace (thread); |
c906108c | 10819 | } |
c5aa993b | 10820 | |
c70a6932 JK |
10821 | /* set_momentary_breakpoint could invalidate FRAME. */ |
10822 | frame = NULL; | |
10823 | ||
df631783 PA |
10824 | /* If the user told us to continue until a specified location, we |
10825 | don't specify a frame at which we need to stop. Otherwise, | |
10826 | specify the selected frame, because we want to stop only at the | |
10827 | very same frame. */ | |
10828 | frame_id stop_frame_id = anywhere ? null_frame_id : stack_frame_id; | |
10829 | ||
10830 | for (symtab_and_line &sal : sals) | |
10831 | { | |
10832 | resolve_sal_pc (&sal); | |
10833 | ||
10834 | breakpoint_up location_breakpoint | |
10835 | = set_momentary_breakpoint (frame_gdbarch, sal, | |
10836 | stop_frame_id, bp_until); | |
10837 | breakpoints.emplace_back (std::move (location_breakpoint)); | |
10838 | } | |
883bc8d1 | 10839 | |
46e3ed7f | 10840 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
df631783 | 10841 | std::move (breakpoints)); |
f107f563 | 10842 | |
5419bdae TT |
10843 | if (lj_deleter) |
10844 | lj_deleter->release (); | |
f107f563 | 10845 | |
cfc31633 | 10846 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 10847 | } |
ae66c1fc | 10848 | |
9ac4176b | 10849 | void |
28010a5d PA |
10850 | init_ada_exception_breakpoint (struct breakpoint *b, |
10851 | struct gdbarch *gdbarch, | |
10852 | struct symtab_and_line sal, | |
f2fc3015 | 10853 | const char *addr_string, |
c0a91b2b | 10854 | const struct breakpoint_ops *ops, |
28010a5d | 10855 | int tempflag, |
349774ef | 10856 | int enabled, |
28010a5d | 10857 | int from_tty) |
f7f9143b | 10858 | { |
f7f9143b JB |
10859 | if (from_tty) |
10860 | { | |
5af949e3 UW |
10861 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
10862 | if (!loc_gdbarch) | |
10863 | loc_gdbarch = gdbarch; | |
10864 | ||
6c95b8df PA |
10865 | describe_other_breakpoints (loc_gdbarch, |
10866 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b | 10867 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
dda83cd7 SM |
10868 | version for exception catchpoints, because two catchpoints |
10869 | used for different exception names will use the same address. | |
10870 | In this case, a "breakpoint ... also set at..." warning is | |
10871 | unproductive. Besides, the warning phrasing is also a bit | |
10872 | inappropriate, we should use the word catchpoint, and tell | |
10873 | the user what type of catchpoint it is. The above is good | |
10874 | enough for now, though. */ | |
f7f9143b JB |
10875 | } |
10876 | ||
f06f1252 | 10877 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
f7f9143b | 10878 | |
349774ef | 10879 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 10880 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
10881 | b->location = string_to_event_location (&addr_string, |
10882 | language_def (language_ada)); | |
f7f9143b | 10883 | b->language = language_ada; |
f7f9143b JB |
10884 | } |
10885 | ||
c906108c SS |
10886 | \f |
10887 | ||
81b1e71c | 10888 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
10889 | |
10890 | static int | |
81b1e71c | 10891 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 10892 | { |
81b1e71c TT |
10893 | uintptr_t ua = (uintptr_t) a; |
10894 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 10895 | |
81b1e71c | 10896 | if (a->number < b->number) |
8a2c437b | 10897 | return -1; |
81b1e71c | 10898 | else if (a->number > b->number) |
8a2c437b TT |
10899 | return 1; |
10900 | ||
10901 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
10902 | the number 0. */ | |
10903 | if (ua < ub) | |
10904 | return -1; | |
94b0e70d | 10905 | return ua > ub ? 1 : 0; |
8a2c437b TT |
10906 | } |
10907 | ||
80f8a6eb | 10908 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10909 | |
10910 | static void | |
0b39b52e | 10911 | clear_command (const char *arg, int from_tty) |
c906108c | 10912 | { |
c906108c | 10913 | int default_match; |
c906108c | 10914 | |
6c5b2ebe PA |
10915 | std::vector<symtab_and_line> decoded_sals; |
10916 | symtab_and_line last_sal; | |
10917 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
10918 | if (arg) |
10919 | { | |
6c5b2ebe PA |
10920 | decoded_sals |
10921 | = decode_line_with_current_source (arg, | |
10922 | (DECODE_LINE_FUNFIRSTLINE | |
10923 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 10924 | default_match = 0; |
6c5b2ebe | 10925 | sals = decoded_sals; |
c906108c SS |
10926 | } |
10927 | else | |
10928 | { | |
1bfeeb0f JL |
10929 | /* Set sal's line, symtab, pc, and pspace to the values |
10930 | corresponding to the last call to print_frame_info. If the | |
10931 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 10932 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 10933 | if (last_sal.symtab == 0) |
8a3fe4f8 | 10934 | error (_("No source file specified.")); |
c906108c | 10935 | |
c906108c | 10936 | default_match = 1; |
6c5b2ebe | 10937 | sals = last_sal; |
c906108c SS |
10938 | } |
10939 | ||
4a64f543 MS |
10940 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10941 | seems, because all existing breakpoints typically have both | |
10942 | file/line and pc set. So, if clear is given file/line, we can | |
10943 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10944 | |
10945 | We only support clearing given the address explicitly | |
10946 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10947 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10948 | due to optimization, all in one block. |
4a64f543 MS |
10949 | |
10950 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10951 | PC corresponding to the same file:line, the breakpoint won't |
10952 | be cleared. We probably can still clear the breakpoint, but | |
10953 | since the other PC value is never presented to user, user | |
10954 | can only find it by guessing, and it does not seem important | |
10955 | to support that. */ | |
10956 | ||
4a64f543 MS |
10957 | /* For each line spec given, delete bps which correspond to it. Do |
10958 | it in two passes, solely to preserve the current behavior that | |
10959 | from_tty is forced true if we delete more than one | |
10960 | breakpoint. */ | |
c906108c | 10961 | |
81b1e71c | 10962 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 10963 | for (const auto &sal : sals) |
c906108c | 10964 | { |
05cba821 JK |
10965 | const char *sal_fullname; |
10966 | ||
c906108c | 10967 | /* If exact pc given, clear bpts at that pc. |
dda83cd7 SM |
10968 | If line given (pc == 0), clear all bpts on specified line. |
10969 | If defaulting, clear all bpts on default line | |
10970 | or at default pc. | |
c5aa993b | 10971 | |
dda83cd7 | 10972 | defaulting sal.pc != 0 tests to do |
c5aa993b | 10973 | |
dda83cd7 SM |
10974 | 0 1 pc |
10975 | 1 1 pc _and_ line | |
10976 | 0 0 line | |
10977 | 1 0 <can't happen> */ | |
c906108c | 10978 | |
05cba821 JK |
10979 | sal_fullname = (sal.symtab == NULL |
10980 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 10981 | |
4a64f543 | 10982 | /* Find all matching breakpoints and add them to 'found'. */ |
43892fdf | 10983 | for (breakpoint *b : all_breakpoints ()) |
c5aa993b | 10984 | { |
0d381245 | 10985 | int match = 0; |
4a64f543 | 10986 | /* Are we going to delete b? */ |
cc60f2e3 | 10987 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 | 10988 | { |
40cb8ca5 | 10989 | for (bp_location *loc : b->locations ()) |
0d381245 | 10990 | { |
f8eba3c6 TT |
10991 | /* If the user specified file:line, don't allow a PC |
10992 | match. This matches historical gdb behavior. */ | |
10993 | int pc_match = (!sal.explicit_line | |
10994 | && sal.pc | |
10995 | && (loc->pspace == sal.pspace) | |
10996 | && (loc->address == sal.pc) | |
10997 | && (!section_is_overlay (loc->section) | |
10998 | || loc->section == sal.section)); | |
4aac40c8 TT |
10999 | int line_match = 0; |
11000 | ||
11001 | if ((default_match || sal.explicit_line) | |
2f202fde | 11002 | && loc->symtab != NULL |
05cba821 | 11003 | && sal_fullname != NULL |
4aac40c8 | 11004 | && sal.pspace == loc->pspace |
05cba821 JK |
11005 | && loc->line_number == sal.line |
11006 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11007 | sal_fullname) == 0) | |
11008 | line_match = 1; | |
4aac40c8 | 11009 | |
0d381245 VP |
11010 | if (pc_match || line_match) |
11011 | { | |
11012 | match = 1; | |
11013 | break; | |
11014 | } | |
11015 | } | |
11016 | } | |
11017 | ||
11018 | if (match) | |
81b1e71c | 11019 | found.push_back (b); |
c906108c | 11020 | } |
80f8a6eb | 11021 | } |
8a2c437b | 11022 | |
80f8a6eb | 11023 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11024 | if (found.empty ()) |
80f8a6eb MS |
11025 | { |
11026 | if (arg) | |
8a3fe4f8 | 11027 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11028 | else |
8a3fe4f8 | 11029 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11030 | } |
c906108c | 11031 | |
8a2c437b | 11032 | /* Remove duplicates from the vec. */ |
81b1e71c | 11033 | std::sort (found.begin (), found.end (), |
b926417a | 11034 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11035 | { |
b926417a | 11036 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
11037 | }); |
11038 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 11039 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11040 | { |
b926417a | 11041 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
11042 | }), |
11043 | found.end ()); | |
8a2c437b | 11044 | |
81b1e71c | 11045 | if (found.size () > 1) |
4a64f543 | 11046 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11047 | if (from_tty) |
a3f17187 | 11048 | { |
81b1e71c | 11049 | if (found.size () == 1) |
b58f47ab | 11050 | printf_filtered (_("Deleted breakpoint ")); |
a3f17187 | 11051 | else |
b58f47ab | 11052 | printf_filtered (_("Deleted breakpoints ")); |
a3f17187 | 11053 | } |
d6e956e5 | 11054 | |
81b1e71c | 11055 | for (breakpoint *iter : found) |
80f8a6eb | 11056 | { |
c5aa993b | 11057 | if (from_tty) |
b58f47ab | 11058 | printf_filtered ("%d ", iter->number); |
81b1e71c | 11059 | delete_breakpoint (iter); |
c906108c | 11060 | } |
80f8a6eb | 11061 | if (from_tty) |
b58f47ab | 11062 | putchar_filtered ('\n'); |
c906108c SS |
11063 | } |
11064 | \f | |
11065 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11066 | all breakpoints that are marked for deletion, whether hit or not. | |
11067 | This is called after any breakpoint is hit, or after errors. */ | |
11068 | ||
11069 | void | |
313f3b21 | 11070 | breakpoint_auto_delete (bpstat *bs) |
c906108c | 11071 | { |
c906108c | 11072 | for (; bs; bs = bs->next) |
f431efe5 PA |
11073 | if (bs->breakpoint_at |
11074 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11075 | && bs->stop) |
f431efe5 | 11076 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11077 | |
1428b37a | 11078 | for (breakpoint *b : all_breakpoints_safe ()) |
b5de0fa7 | 11079 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b | 11080 | delete_breakpoint (b); |
c906108c SS |
11081 | } |
11082 | ||
4a64f543 | 11083 | /* A comparison function for bp_location AP and BP being interfaced to |
39ef2f62 | 11084 | std::sort. Sort elements primarily by their ADDRESS (no matter what |
cb1e4e32 PA |
11085 | bl_address_is_meaningful says), secondarily by ordering first |
11086 | permanent elements and terciarily just ensuring the array is sorted | |
39ef2f62 | 11087 | stable way despite std::sort being an unstable algorithm. */ |
876fa593 JK |
11088 | |
11089 | static int | |
39ef2f62 | 11090 | bp_location_is_less_than (const bp_location *a, const bp_location *b) |
876fa593 | 11091 | { |
876fa593 | 11092 | if (a->address != b->address) |
39ef2f62 | 11093 | return a->address < b->address; |
876fa593 | 11094 | |
dea2aa5f LM |
11095 | /* Sort locations at the same address by their pspace number, keeping |
11096 | locations of the same inferior (in a multi-inferior environment) | |
11097 | grouped. */ | |
11098 | ||
11099 | if (a->pspace->num != b->pspace->num) | |
39ef2f62 | 11100 | return a->pspace->num < b->pspace->num; |
dea2aa5f | 11101 | |
876fa593 | 11102 | /* Sort permanent breakpoints first. */ |
1a853c52 | 11103 | if (a->permanent != b->permanent) |
39ef2f62 | 11104 | return a->permanent > b->permanent; |
876fa593 | 11105 | |
7f32a4d5 PA |
11106 | /* Sort by type in order to make duplicate determination easier. |
11107 | See update_global_location_list. This is kept in sync with | |
11108 | breakpoint_locations_match. */ | |
11109 | if (a->loc_type < b->loc_type) | |
11110 | return true; | |
11111 | ||
11112 | /* Likewise, for range-breakpoints, sort by length. */ | |
11113 | if (a->loc_type == bp_loc_hardware_breakpoint | |
11114 | && b->loc_type == bp_loc_hardware_breakpoint | |
11115 | && a->length < b->length) | |
11116 | return true; | |
11117 | ||
c56a97f9 JK |
11118 | /* Make the internal GDB representation stable across GDB runs |
11119 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11120 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11121 | |
11122 | if (a->owner->number != b->owner->number) | |
39ef2f62 | 11123 | return a->owner->number < b->owner->number; |
876fa593 | 11124 | |
39ef2f62 | 11125 | return a < b; |
876fa593 JK |
11126 | } |
11127 | ||
f5336ca5 PA |
11128 | /* Set bp_locations_placed_address_before_address_max and |
11129 | bp_locations_shadow_len_after_address_max according to the current | |
11130 | content of the bp_locations array. */ | |
f7545552 TT |
11131 | |
11132 | static void | |
f5336ca5 | 11133 | bp_locations_target_extensions_update (void) |
f7545552 | 11134 | { |
f5336ca5 PA |
11135 | bp_locations_placed_address_before_address_max = 0; |
11136 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 | 11137 | |
48d7020b | 11138 | for (bp_location *bl : all_bp_locations ()) |
876fa593 JK |
11139 | { |
11140 | CORE_ADDR start, end, addr; | |
11141 | ||
11142 | if (!bp_location_has_shadow (bl)) | |
11143 | continue; | |
11144 | ||
11145 | start = bl->target_info.placed_address; | |
11146 | end = start + bl->target_info.shadow_len; | |
11147 | ||
11148 | gdb_assert (bl->address >= start); | |
11149 | addr = bl->address - start; | |
f5336ca5 PA |
11150 | if (addr > bp_locations_placed_address_before_address_max) |
11151 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11152 | |
11153 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11154 | ||
11155 | gdb_assert (bl->address < end); | |
11156 | addr = end - bl->address; | |
f5336ca5 PA |
11157 | if (addr > bp_locations_shadow_len_after_address_max) |
11158 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11159 | } |
f7545552 TT |
11160 | } |
11161 | ||
1e4d1764 YQ |
11162 | /* Download tracepoint locations if they haven't been. */ |
11163 | ||
11164 | static void | |
11165 | download_tracepoint_locations (void) | |
11166 | { | |
dd2e65cc | 11167 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11168 | |
5ed8105e | 11169 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11170 | |
f6d17b2b | 11171 | for (breakpoint *b : all_tracepoints ()) |
1e4d1764 YQ |
11172 | { |
11173 | struct tracepoint *t; | |
f2a8bc8a | 11174 | int bp_location_downloaded = 0; |
1e4d1764 | 11175 | |
7ed2c994 | 11176 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11177 | ? !may_insert_fast_tracepoints |
11178 | : !may_insert_tracepoints)) | |
11179 | continue; | |
11180 | ||
dd2e65cc YQ |
11181 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11182 | { | |
11183 | if (target_can_download_tracepoint ()) | |
11184 | can_download_tracepoint = TRIBOOL_TRUE; | |
11185 | else | |
11186 | can_download_tracepoint = TRIBOOL_FALSE; | |
11187 | } | |
11188 | ||
11189 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11190 | break; | |
11191 | ||
40cb8ca5 | 11192 | for (bp_location *bl : b->locations ()) |
7ed2c994 YQ |
11193 | { |
11194 | /* In tracepoint, locations are _never_ duplicated, so | |
11195 | should_be_inserted is equivalent to | |
11196 | unduplicated_should_be_inserted. */ | |
11197 | if (!should_be_inserted (bl) || bl->inserted) | |
11198 | continue; | |
1e4d1764 | 11199 | |
7ed2c994 | 11200 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11201 | |
7ed2c994 | 11202 | target_download_tracepoint (bl); |
1e4d1764 | 11203 | |
7ed2c994 | 11204 | bl->inserted = 1; |
f2a8bc8a | 11205 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11206 | } |
11207 | t = (struct tracepoint *) b; | |
11208 | t->number_on_target = b->number; | |
f2a8bc8a | 11209 | if (bp_location_downloaded) |
76727919 | 11210 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11211 | } |
1e4d1764 YQ |
11212 | } |
11213 | ||
934709f0 PW |
11214 | /* Swap the insertion/duplication state between two locations. */ |
11215 | ||
11216 | static void | |
11217 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11218 | { | |
11219 | const int left_inserted = left->inserted; | |
11220 | const int left_duplicate = left->duplicate; | |
b775012e | 11221 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11222 | const struct bp_target_info left_target_info = left->target_info; |
11223 | ||
1e4d1764 YQ |
11224 | /* Locations of tracepoints can never be duplicated. */ |
11225 | if (is_tracepoint (left->owner)) | |
11226 | gdb_assert (!left->duplicate); | |
11227 | if (is_tracepoint (right->owner)) | |
11228 | gdb_assert (!right->duplicate); | |
11229 | ||
934709f0 PW |
11230 | left->inserted = right->inserted; |
11231 | left->duplicate = right->duplicate; | |
b775012e | 11232 | left->needs_update = right->needs_update; |
934709f0 PW |
11233 | left->target_info = right->target_info; |
11234 | right->inserted = left_inserted; | |
11235 | right->duplicate = left_duplicate; | |
b775012e | 11236 | right->needs_update = left_needs_update; |
934709f0 PW |
11237 | right->target_info = left_target_info; |
11238 | } | |
11239 | ||
b775012e LM |
11240 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11241 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11242 | conditions on the target's side. Such conditions need to be updated on | |
11243 | the target. */ | |
11244 | ||
11245 | static void | |
11246 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11247 | { | |
b775012e LM |
11248 | CORE_ADDR address = 0; |
11249 | int pspace_num; | |
11250 | ||
11251 | address = bl->address; | |
11252 | pspace_num = bl->pspace->num; | |
11253 | ||
11254 | /* This is only meaningful if the target is | |
11255 | evaluating conditions and if the user has | |
11256 | opted for condition evaluation on the target's | |
11257 | side. */ | |
11258 | if (gdb_evaluates_breakpoint_condition_p () | |
11259 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11260 | return; | |
11261 | ||
11262 | /* Flag all breakpoint locations with this address and | |
11263 | the same program space as the location | |
11264 | as "its condition has changed". We need to | |
11265 | update the conditions on the target's side. */ | |
e0d9a270 | 11266 | for (bp_location *loc : all_bp_locations_at_addr (address)) |
b775012e | 11267 | { |
b775012e LM |
11268 | if (!is_breakpoint (loc->owner) |
11269 | || pspace_num != loc->pspace->num) | |
11270 | continue; | |
11271 | ||
11272 | /* Flag the location appropriately. We use a different state to | |
11273 | let everyone know that we already updated the set of locations | |
11274 | with addr bl->address and program space bl->pspace. This is so | |
11275 | we don't have to keep calling these functions just to mark locations | |
11276 | that have already been marked. */ | |
11277 | loc->condition_changed = condition_updated; | |
11278 | ||
11279 | /* Free the agent expression bytecode as well. We will compute | |
11280 | it later on. */ | |
833177a4 | 11281 | loc->cond_bytecode.reset (); |
b775012e LM |
11282 | } |
11283 | } | |
7f32a4d5 | 11284 | |
44702360 PA |
11285 | /* Called whether new breakpoints are created, or existing breakpoints |
11286 | deleted, to update the global location list and recompute which | |
11287 | locations are duplicate of which. | |
b775012e | 11288 | |
04086b45 PA |
11289 | The INSERT_MODE flag determines whether locations may not, may, or |
11290 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11291 | info. */ | |
b60e7edf | 11292 | |
0d381245 | 11293 | static void |
44702360 | 11294 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11295 | { |
b775012e LM |
11296 | /* Last breakpoint location address that was marked for update. */ |
11297 | CORE_ADDR last_addr = 0; | |
11298 | /* Last breakpoint location program space that was marked for update. */ | |
11299 | int last_pspace_num = -1; | |
f7545552 | 11300 | |
2d134ed3 PA |
11301 | /* Used in the duplicates detection below. When iterating over all |
11302 | bp_locations, points to the first bp_location of a given address. | |
11303 | Breakpoints and watchpoints of different types are never | |
11304 | duplicates of each other. Keep one pointer for each type of | |
11305 | breakpoint/watchpoint, so we only need to loop over all locations | |
11306 | once. */ | |
11307 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11308 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11309 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11310 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11311 | |
f5336ca5 PA |
11312 | /* Saved former bp_locations array which we compare against the newly |
11313 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
5d51cd5d SM |
11314 | std::vector<bp_location *> old_locations = std::move (bp_locations); |
11315 | bp_locations.clear (); | |
876fa593 | 11316 | |
43892fdf | 11317 | for (breakpoint *b : all_breakpoints ()) |
40cb8ca5 | 11318 | for (bp_location *loc : b->locations ()) |
5d51cd5d | 11319 | bp_locations.push_back (loc); |
7f32a4d5 PA |
11320 | |
11321 | /* See if we need to "upgrade" a software breakpoint to a hardware | |
11322 | breakpoint. Do this before deciding whether locations are | |
11323 | duplicates. Also do this before sorting because sorting order | |
11324 | depends on location type. */ | |
5d51cd5d SM |
11325 | for (bp_location *loc : bp_locations) |
11326 | if (!loc->inserted && should_be_inserted (loc)) | |
7f32a4d5 | 11327 | handle_automatic_hardware_breakpoints (loc); |
7f32a4d5 | 11328 | |
5d51cd5d | 11329 | std::sort (bp_locations.begin (), bp_locations.end (), |
39ef2f62 | 11330 | bp_location_is_less_than); |
876fa593 | 11331 | |
f5336ca5 | 11332 | bp_locations_target_extensions_update (); |
74960c60 | 11333 | |
4a64f543 MS |
11334 | /* Identify bp_location instances that are no longer present in the |
11335 | new list, and therefore should be freed. Note that it's not | |
11336 | necessary that those locations should be removed from inferior -- | |
11337 | if there's another location at the same address (previously | |
11338 | marked as duplicate), we don't need to remove/insert the | |
11339 | location. | |
876fa593 | 11340 | |
4a64f543 MS |
11341 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11342 | and former bp_location array state respectively. */ | |
876fa593 | 11343 | |
5d51cd5d SM |
11344 | size_t loc_i = 0; |
11345 | for (bp_location *old_loc : old_locations) | |
74960c60 | 11346 | { |
e5dd4106 | 11347 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11348 | not, we have to free it. */ |
c7d46a38 | 11349 | int found_object = 0; |
20874c92 VP |
11350 | /* Tells if the location should remain inserted in the target. */ |
11351 | int keep_in_target = 0; | |
11352 | int removed = 0; | |
876fa593 | 11353 | |
4a64f543 MS |
11354 | /* Skip LOCP entries which will definitely never be needed. |
11355 | Stop either at or being the one matching OLD_LOC. */ | |
5d51cd5d SM |
11356 | while (loc_i < bp_locations.size () |
11357 | && bp_locations[loc_i]->address < old_loc->address) | |
11358 | loc_i++; | |
c7d46a38 | 11359 | |
5d51cd5d SM |
11360 | for (size_t loc2_i = loc_i; |
11361 | (loc2_i < bp_locations.size () | |
11362 | && bp_locations[loc2_i]->address == old_loc->address); | |
11363 | loc2_i++) | |
c7d46a38 | 11364 | { |
b775012e LM |
11365 | /* Check if this is a new/duplicated location or a duplicated |
11366 | location that had its condition modified. If so, we want to send | |
11367 | its condition to the target if evaluation of conditions is taking | |
11368 | place there. */ | |
5d51cd5d | 11369 | if (bp_locations[loc2_i]->condition_changed == condition_modified |
b775012e LM |
11370 | && (last_addr != old_loc->address |
11371 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11372 | { |
5d51cd5d | 11373 | force_breakpoint_reinsertion (bp_locations[loc2_i]); |
b775012e | 11374 | last_pspace_num = old_loc->pspace->num; |
c7d46a38 | 11375 | } |
b775012e | 11376 | |
5d51cd5d | 11377 | if (bp_locations[loc2_i] == old_loc) |
b775012e | 11378 | found_object = 1; |
c7d46a38 | 11379 | } |
74960c60 | 11380 | |
b775012e LM |
11381 | /* We have already handled this address, update it so that we don't |
11382 | have to go through updates again. */ | |
11383 | last_addr = old_loc->address; | |
11384 | ||
11385 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11386 | if (!found_object) | |
11387 | force_breakpoint_reinsertion (old_loc); | |
11388 | ||
4a64f543 MS |
11389 | /* If this location is no longer present, and inserted, look if |
11390 | there's maybe a new location at the same address. If so, | |
11391 | mark that one inserted, and don't remove this one. This is | |
11392 | needed so that we don't have a time window where a breakpoint | |
11393 | at certain location is not inserted. */ | |
74960c60 | 11394 | |
876fa593 | 11395 | if (old_loc->inserted) |
0d381245 | 11396 | { |
4a64f543 MS |
11397 | /* If the location is inserted now, we might have to remove |
11398 | it. */ | |
74960c60 | 11399 | |
876fa593 | 11400 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11401 | { |
4a64f543 MS |
11402 | /* The location is still present in the location list, |
11403 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11404 | keep_in_target = 1; |
74960c60 VP |
11405 | } |
11406 | else | |
11407 | { | |
b775012e LM |
11408 | /* This location still exists, but it won't be kept in the |
11409 | target since it may have been disabled. We proceed to | |
11410 | remove its target-side condition. */ | |
11411 | ||
4a64f543 MS |
11412 | /* The location is either no longer present, or got |
11413 | disabled. See if there's another location at the | |
11414 | same address, in which case we don't need to remove | |
11415 | this one from the target. */ | |
876fa593 | 11416 | |
2bdf28a0 | 11417 | /* OLD_LOC comes from existing struct breakpoint. */ |
cb1e4e32 | 11418 | if (bl_address_is_meaningful (old_loc)) |
876fa593 | 11419 | { |
5d51cd5d SM |
11420 | for (size_t loc2_i = loc_i; |
11421 | (loc2_i < bp_locations.size () | |
11422 | && bp_locations[loc2_i]->address == old_loc->address); | |
11423 | loc2_i++) | |
876fa593 | 11424 | { |
5d51cd5d | 11425 | bp_location *loc2 = bp_locations[loc2_i]; |
876fa593 | 11426 | |
7f32a4d5 PA |
11427 | if (loc2 == old_loc) |
11428 | continue; | |
11429 | ||
2d134ed3 | 11430 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11431 | { |
85d721b8 PA |
11432 | /* Read watchpoint locations are switched to |
11433 | access watchpoints, if the former are not | |
11434 | supported, but the latter are. */ | |
11435 | if (is_hardware_watchpoint (old_loc->owner)) | |
11436 | { | |
11437 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11438 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11439 | } | |
11440 | ||
934709f0 PW |
11441 | /* loc2 is a duplicated location. We need to check |
11442 | if it should be inserted in case it will be | |
11443 | unduplicated. */ | |
7f32a4d5 | 11444 | if (unduplicated_should_be_inserted (loc2)) |
c7d46a38 | 11445 | { |
934709f0 | 11446 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11447 | keep_in_target = 1; |
11448 | break; | |
11449 | } | |
876fa593 JK |
11450 | } |
11451 | } | |
11452 | } | |
74960c60 VP |
11453 | } |
11454 | ||
20874c92 VP |
11455 | if (!keep_in_target) |
11456 | { | |
834c0d03 | 11457 | if (remove_breakpoint (old_loc)) |
20874c92 | 11458 | { |
4a64f543 MS |
11459 | /* This is just about all we can do. We could keep |
11460 | this location on the global list, and try to | |
11461 | remove it next time, but there's no particular | |
11462 | reason why we will succeed next time. | |
20874c92 | 11463 | |
4a64f543 MS |
11464 | Note that at this point, old_loc->owner is still |
11465 | valid, as delete_breakpoint frees the breakpoint | |
11466 | only after calling us. */ | |
3e43a32a MS |
11467 | printf_filtered (_("warning: Error removing " |
11468 | "breakpoint %d\n"), | |
876fa593 | 11469 | old_loc->owner->number); |
20874c92 VP |
11470 | } |
11471 | removed = 1; | |
11472 | } | |
0d381245 | 11473 | } |
74960c60 VP |
11474 | |
11475 | if (!found_object) | |
1c5cfe86 | 11476 | { |
fbea99ea | 11477 | if (removed && target_is_non_stop_p () |
1cf4d951 | 11478 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 11479 | { |
db82e815 PA |
11480 | /* This location was removed from the target. In |
11481 | non-stop mode, a race condition is possible where | |
11482 | we've removed a breakpoint, but stop events for that | |
11483 | breakpoint are already queued and will arrive later. | |
11484 | We apply an heuristic to be able to distinguish such | |
11485 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11486 | breakpoint location for a bit, and will retire it | |
11487 | after we see some number of events. The theory here | |
11488 | is that reporting of events should, "on the average", | |
11489 | be fair, so after a while we'll see events from all | |
11490 | threads that have anything of interest, and no longer | |
11491 | need to keep this breakpoint location around. We | |
11492 | don't hold locations forever so to reduce chances of | |
11493 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11494 | SIGTRAP. | |
11495 | ||
11496 | The heuristic failing can be disastrous on | |
11497 | decr_pc_after_break targets. | |
11498 | ||
11499 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11500 | if we fail to recognize a late breakpoint SIGTRAP, | |
11501 | because events_till_retirement has reached 0 too | |
11502 | soon, we'll fail to do the PC adjustment, and report | |
11503 | a random SIGTRAP to the user. When the user resumes | |
11504 | the inferior, it will most likely immediately crash | |
2dec564e | 11505 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11506 | corrupted, because of being resumed e.g., in the |
11507 | middle of a multi-byte instruction, or skipped a | |
11508 | one-byte instruction. This was actually seen happen | |
11509 | on native x86-linux, and should be less rare on | |
11510 | targets that do not support new thread events, like | |
11511 | remote, due to the heuristic depending on | |
11512 | thread_count. | |
11513 | ||
11514 | Mistaking a random SIGTRAP for a breakpoint trap | |
11515 | causes similar symptoms (PC adjustment applied when | |
11516 | it shouldn't), but then again, playing with SIGTRAPs | |
11517 | behind the debugger's back is asking for trouble. | |
11518 | ||
11519 | Since hardware watchpoint traps are always | |
11520 | distinguishable from other traps, so we don't need to | |
11521 | apply keep hardware watchpoint moribund locations | |
11522 | around. We simply always ignore hardware watchpoint | |
11523 | traps we can no longer explain. */ | |
11524 | ||
5b6d1e4f PA |
11525 | process_stratum_target *proc_target = nullptr; |
11526 | for (inferior *inf : all_inferiors ()) | |
11527 | if (inf->pspace == old_loc->pspace) | |
11528 | { | |
11529 | proc_target = inf->process_target (); | |
11530 | break; | |
11531 | } | |
11532 | if (proc_target != nullptr) | |
11533 | old_loc->events_till_retirement | |
11534 | = 3 * (thread_count (proc_target) + 1); | |
11535 | else | |
11536 | old_loc->events_till_retirement = 1; | |
876fa593 | 11537 | old_loc->owner = NULL; |
20874c92 | 11538 | |
1123588c | 11539 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
11540 | } |
11541 | else | |
f431efe5 PA |
11542 | { |
11543 | old_loc->owner = NULL; | |
11544 | decref_bp_location (&old_loc); | |
11545 | } | |
20874c92 | 11546 | } |
74960c60 | 11547 | } |
1c5cfe86 | 11548 | |
348d480f PA |
11549 | /* Rescan breakpoints at the same address and section, marking the |
11550 | first one as "first" and any others as "duplicates". This is so | |
11551 | that the bpt instruction is only inserted once. If we have a | |
11552 | permanent breakpoint at the same place as BPT, make that one the | |
11553 | official one, and the rest as duplicates. Permanent breakpoints | |
11554 | are sorted first for the same address. | |
11555 | ||
11556 | Do the same for hardware watchpoints, but also considering the | |
11557 | watchpoint's type (regular/access/read) and length. */ | |
11558 | ||
11559 | bp_loc_first = NULL; | |
11560 | wp_loc_first = NULL; | |
11561 | awp_loc_first = NULL; | |
11562 | rwp_loc_first = NULL; | |
40cb8ca5 | 11563 | |
48d7020b | 11564 | for (bp_location *loc : all_bp_locations ()) |
348d480f PA |
11565 | { |
11566 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11567 | non-NULL. */ | |
348d480f | 11568 | struct bp_location **loc_first_p; |
43892fdf | 11569 | breakpoint *b = loc->owner; |
348d480f | 11570 | |
6f380991 | 11571 | if (!unduplicated_should_be_inserted (loc) |
cb1e4e32 | 11572 | || !bl_address_is_meaningful (loc) |
1e4d1764 YQ |
11573 | /* Don't detect duplicate for tracepoint locations because they are |
11574 | never duplicated. See the comments in field `duplicate' of | |
11575 | `struct bp_location'. */ | |
348d480f | 11576 | || is_tracepoint (b)) |
b775012e LM |
11577 | { |
11578 | /* Clear the condition modification flag. */ | |
11579 | loc->condition_changed = condition_unchanged; | |
11580 | continue; | |
11581 | } | |
348d480f | 11582 | |
348d480f PA |
11583 | if (b->type == bp_hardware_watchpoint) |
11584 | loc_first_p = &wp_loc_first; | |
11585 | else if (b->type == bp_read_watchpoint) | |
11586 | loc_first_p = &rwp_loc_first; | |
11587 | else if (b->type == bp_access_watchpoint) | |
11588 | loc_first_p = &awp_loc_first; | |
11589 | else | |
11590 | loc_first_p = &bp_loc_first; | |
11591 | ||
11592 | if (*loc_first_p == NULL | |
11593 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11594 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11595 | { | |
11596 | *loc_first_p = loc; | |
11597 | loc->duplicate = 0; | |
b775012e LM |
11598 | |
11599 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11600 | { | |
11601 | loc->needs_update = 1; | |
11602 | /* Clear the condition modification flag. */ | |
11603 | loc->condition_changed = condition_unchanged; | |
11604 | } | |
348d480f PA |
11605 | continue; |
11606 | } | |
11607 | ||
934709f0 PW |
11608 | |
11609 | /* This and the above ensure the invariant that the first location | |
11610 | is not duplicated, and is the inserted one. | |
11611 | All following are marked as duplicated, and are not inserted. */ | |
11612 | if (loc->inserted) | |
11613 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11614 | loc->duplicate = 1; |
11615 | ||
b775012e LM |
11616 | /* Clear the condition modification flag. */ |
11617 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
11618 | } |
11619 | ||
a25a5a45 | 11620 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 11621 | { |
04086b45 | 11622 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
11623 | insert_breakpoint_locations (); |
11624 | else | |
11625 | { | |
44702360 PA |
11626 | /* Even though the caller told us to not insert new |
11627 | locations, we may still need to update conditions on the | |
11628 | target's side of breakpoints that were already inserted | |
11629 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
11630 | only update conditions for locations that are marked |
11631 | "needs_update". */ | |
11632 | update_inserted_breakpoint_locations (); | |
11633 | } | |
11634 | } | |
348d480f | 11635 | |
04086b45 | 11636 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 11637 | download_tracepoint_locations (); |
348d480f PA |
11638 | } |
11639 | ||
11640 | void | |
11641 | breakpoint_retire_moribund (void) | |
11642 | { | |
1123588c TT |
11643 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
11644 | { | |
11645 | struct bp_location *loc = moribund_locations[ix]; | |
11646 | if (--(loc->events_till_retirement) == 0) | |
11647 | { | |
11648 | decref_bp_location (&loc); | |
11649 | unordered_remove (moribund_locations, ix); | |
11650 | --ix; | |
11651 | } | |
11652 | } | |
348d480f PA |
11653 | } |
11654 | ||
11655 | static void | |
44702360 | 11656 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 11657 | { |
348d480f | 11658 | |
a70b8144 | 11659 | try |
492d29ea PA |
11660 | { |
11661 | update_global_location_list (insert_mode); | |
11662 | } | |
230d2906 | 11663 | catch (const gdb_exception_error &e) |
492d29ea PA |
11664 | { |
11665 | } | |
348d480f PA |
11666 | } |
11667 | ||
11668 | /* Clear BKP from a BPS. */ | |
11669 | ||
11670 | static void | |
313f3b21 | 11671 | bpstat_remove_bp_location (bpstat *bps, struct breakpoint *bpt) |
348d480f | 11672 | { |
313f3b21 | 11673 | bpstat *bs; |
348d480f PA |
11674 | |
11675 | for (bs = bps; bs; bs = bs->next) | |
11676 | if (bs->breakpoint_at == bpt) | |
11677 | { | |
11678 | bs->breakpoint_at = NULL; | |
11679 | bs->old_val = NULL; | |
11680 | /* bs->commands will be freed later. */ | |
11681 | } | |
11682 | } | |
11683 | ||
11684 | /* Callback for iterate_over_threads. */ | |
11685 | static int | |
11686 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
11687 | { | |
9a3c8263 | 11688 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
11689 | |
11690 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
11691 | return 0; | |
11692 | } | |
11693 | ||
11694 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
11695 | callbacks. */ | |
11696 | ||
11697 | static void | |
11698 | say_where (struct breakpoint *b) | |
11699 | { | |
11700 | struct value_print_options opts; | |
11701 | ||
11702 | get_user_print_options (&opts); | |
11703 | ||
11704 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
11705 | single string. */ | |
11706 | if (b->loc == NULL) | |
11707 | { | |
f00aae0f KS |
11708 | /* For pending locations, the output differs slightly based |
11709 | on b->extra_string. If this is non-NULL, it contains either | |
11710 | a condition or dprintf arguments. */ | |
11711 | if (b->extra_string == NULL) | |
11712 | { | |
11713 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 11714 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
11715 | } |
11716 | else if (b->type == bp_dprintf) | |
11717 | { | |
11718 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 11719 | event_location_to_string (b->location.get ()), |
6f781ee3 | 11720 | b->extra_string.get ()); |
f00aae0f KS |
11721 | } |
11722 | else | |
11723 | { | |
11724 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 11725 | event_location_to_string (b->location.get ()), |
6f781ee3 | 11726 | b->extra_string.get ()); |
f00aae0f | 11727 | } |
348d480f PA |
11728 | } |
11729 | else | |
11730 | { | |
2f202fde | 11731 | if (opts.addressprint || b->loc->symtab == NULL) |
6a831f06 PA |
11732 | printf_filtered (" at %ps", |
11733 | styled_string (address_style.style (), | |
11734 | paddress (b->loc->gdbarch, | |
11735 | b->loc->address))); | |
2f202fde | 11736 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
11737 | { |
11738 | /* If there is a single location, we can print the location | |
11739 | more nicely. */ | |
11740 | if (b->loc->next == NULL) | |
0bb296cb | 11741 | { |
6a831f06 PA |
11742 | const char *filename |
11743 | = symtab_to_filename_for_display (b->loc->symtab); | |
11744 | printf_filtered (": file %ps, line %d.", | |
11745 | styled_string (file_name_style.style (), | |
11746 | filename), | |
0bb296cb TT |
11747 | b->loc->line_number); |
11748 | } | |
f8eba3c6 TT |
11749 | else |
11750 | /* This is not ideal, but each location may have a | |
11751 | different file name, and this at least reflects the | |
11752 | real situation somewhat. */ | |
f00aae0f | 11753 | printf_filtered (": %s.", |
d28cd78a | 11754 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 11755 | } |
348d480f PA |
11756 | |
11757 | if (b->loc->next) | |
11758 | { | |
11759 | struct bp_location *loc = b->loc; | |
11760 | int n = 0; | |
11761 | for (; loc; loc = loc->next) | |
11762 | ++n; | |
11763 | printf_filtered (" (%d locations)", n); | |
11764 | } | |
11765 | } | |
11766 | } | |
11767 | ||
40cb8ca5 SM |
11768 | /* See breakpoint.h. */ |
11769 | ||
9be25986 | 11770 | bp_location_range breakpoint::locations () |
40cb8ca5 | 11771 | { |
9be25986 | 11772 | return bp_location_range (this->loc); |
40cb8ca5 SM |
11773 | } |
11774 | ||
2060206e PA |
11775 | static struct bp_location * |
11776 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 11777 | { |
5f486660 | 11778 | return new bp_location (self); |
348d480f PA |
11779 | } |
11780 | ||
2060206e PA |
11781 | static void |
11782 | base_breakpoint_re_set (struct breakpoint *b) | |
11783 | { | |
11784 | /* Nothing to re-set. */ | |
11785 | } | |
11786 | ||
11787 | #define internal_error_pure_virtual_called() \ | |
11788 | gdb_assert_not_reached ("pure virtual function called") | |
11789 | ||
11790 | static int | |
11791 | base_breakpoint_insert_location (struct bp_location *bl) | |
11792 | { | |
11793 | internal_error_pure_virtual_called (); | |
11794 | } | |
11795 | ||
11796 | static int | |
73971819 PA |
11797 | base_breakpoint_remove_location (struct bp_location *bl, |
11798 | enum remove_bp_reason reason) | |
2060206e PA |
11799 | { |
11800 | internal_error_pure_virtual_called (); | |
11801 | } | |
11802 | ||
11803 | static int | |
11804 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 11805 | const address_space *aspace, |
09ac7c10 | 11806 | CORE_ADDR bp_addr, |
c272a98c | 11807 | const target_waitstatus &ws) |
2060206e PA |
11808 | { |
11809 | internal_error_pure_virtual_called (); | |
11810 | } | |
11811 | ||
11812 | static void | |
313f3b21 | 11813 | base_breakpoint_check_status (bpstat *bs) |
2060206e PA |
11814 | { |
11815 | /* Always stop. */ | |
11816 | } | |
11817 | ||
11818 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
11819 | errors. */ | |
11820 | ||
11821 | static int | |
11822 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
11823 | { | |
11824 | internal_error_pure_virtual_called (); | |
11825 | } | |
11826 | ||
11827 | /* A "resources_needed" breakpoint_ops method that just internal | |
11828 | errors. */ | |
11829 | ||
11830 | static int | |
11831 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
11832 | { | |
11833 | internal_error_pure_virtual_called (); | |
11834 | } | |
11835 | ||
11836 | static enum print_stop_action | |
313f3b21 | 11837 | base_breakpoint_print_it (bpstat *bs) |
2060206e PA |
11838 | { |
11839 | internal_error_pure_virtual_called (); | |
11840 | } | |
11841 | ||
11842 | static void | |
11843 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
11844 | struct ui_out *uiout) | |
11845 | { | |
11846 | /* nothing */ | |
11847 | } | |
11848 | ||
11849 | static void | |
11850 | base_breakpoint_print_mention (struct breakpoint *b) | |
11851 | { | |
11852 | internal_error_pure_virtual_called (); | |
11853 | } | |
11854 | ||
11855 | static void | |
11856 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
11857 | { | |
11858 | internal_error_pure_virtual_called (); | |
11859 | } | |
11860 | ||
983af33b | 11861 | static void |
f00aae0f | 11862 | base_breakpoint_create_sals_from_location |
626d2320 | 11863 | (struct event_location *location, |
f00aae0f KS |
11864 | struct linespec_result *canonical, |
11865 | enum bptype type_wanted) | |
983af33b SDJ |
11866 | { |
11867 | internal_error_pure_virtual_called (); | |
11868 | } | |
11869 | ||
11870 | static void | |
11871 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
11872 | struct linespec_result *c, | |
e1e01040 PA |
11873 | gdb::unique_xmalloc_ptr<char> cond_string, |
11874 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
11875 | enum bptype type_wanted, |
11876 | enum bpdisp disposition, | |
11877 | int thread, | |
11878 | int task, int ignore_count, | |
11879 | const struct breakpoint_ops *o, | |
11880 | int from_tty, int enabled, | |
44f238bb | 11881 | int internal, unsigned flags) |
983af33b SDJ |
11882 | { |
11883 | internal_error_pure_virtual_called (); | |
11884 | } | |
11885 | ||
6c5b2ebe | 11886 | static std::vector<symtab_and_line> |
f00aae0f | 11887 | base_breakpoint_decode_location (struct breakpoint *b, |
626d2320 | 11888 | struct event_location *location, |
6c5b2ebe | 11889 | struct program_space *search_pspace) |
983af33b SDJ |
11890 | { |
11891 | internal_error_pure_virtual_called (); | |
11892 | } | |
11893 | ||
ab04a2af TT |
11894 | /* The default 'explains_signal' method. */ |
11895 | ||
47591c29 | 11896 | static int |
427cd150 | 11897 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 11898 | { |
47591c29 | 11899 | return 1; |
ab04a2af TT |
11900 | } |
11901 | ||
9d6e6e84 HZ |
11902 | /* The default "after_condition_true" method. */ |
11903 | ||
11904 | static void | |
313f3b21 | 11905 | base_breakpoint_after_condition_true (struct bpstat *bs) |
9d6e6e84 HZ |
11906 | { |
11907 | /* Nothing to do. */ | |
11908 | } | |
11909 | ||
ab04a2af | 11910 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 11911 | { |
2060206e PA |
11912 | base_breakpoint_allocate_location, |
11913 | base_breakpoint_re_set, | |
11914 | base_breakpoint_insert_location, | |
11915 | base_breakpoint_remove_location, | |
11916 | base_breakpoint_breakpoint_hit, | |
11917 | base_breakpoint_check_status, | |
11918 | base_breakpoint_resources_needed, | |
11919 | base_breakpoint_works_in_software_mode, | |
11920 | base_breakpoint_print_it, | |
11921 | NULL, | |
11922 | base_breakpoint_print_one_detail, | |
11923 | base_breakpoint_print_mention, | |
983af33b | 11924 | base_breakpoint_print_recreate, |
5f700d83 | 11925 | base_breakpoint_create_sals_from_location, |
983af33b | 11926 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 11927 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
11928 | base_breakpoint_explains_signal, |
11929 | base_breakpoint_after_condition_true, | |
2060206e PA |
11930 | }; |
11931 | ||
11932 | /* Default breakpoint_ops methods. */ | |
11933 | ||
11934 | static void | |
348d480f PA |
11935 | bkpt_re_set (struct breakpoint *b) |
11936 | { | |
06edf0c0 | 11937 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 11938 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 11939 | { |
f00aae0f | 11940 | /* Anything without a location can't be re-set. */ |
348d480f | 11941 | delete_breakpoint (b); |
06edf0c0 | 11942 | return; |
348d480f | 11943 | } |
06edf0c0 PA |
11944 | |
11945 | breakpoint_re_set_default (b); | |
348d480f PA |
11946 | } |
11947 | ||
2060206e | 11948 | static int |
348d480f PA |
11949 | bkpt_insert_location (struct bp_location *bl) |
11950 | { | |
cd6c3b4f YQ |
11951 | CORE_ADDR addr = bl->target_info.reqstd_address; |
11952 | ||
579c6ad9 | 11953 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
11954 | bl->target_info.placed_address = addr; |
11955 | ||
348d480f | 11956 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 11957 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 11958 | else |
7c16b83e | 11959 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
11960 | } |
11961 | ||
2060206e | 11962 | static int |
73971819 | 11963 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
11964 | { |
11965 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
11966 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
11967 | else | |
73971819 | 11968 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
11969 | } |
11970 | ||
2060206e | 11971 | static int |
348d480f | 11972 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 11973 | const address_space *aspace, CORE_ADDR bp_addr, |
c272a98c | 11974 | const target_waitstatus &ws) |
348d480f | 11975 | { |
c272a98c SM |
11976 | if (ws.kind () != TARGET_WAITKIND_STOPPED |
11977 | || ws.sig () != GDB_SIGNAL_TRAP) | |
09ac7c10 TT |
11978 | return 0; |
11979 | ||
348d480f PA |
11980 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
11981 | aspace, bp_addr)) | |
11982 | return 0; | |
11983 | ||
11984 | if (overlay_debugging /* unmapped overlay section */ | |
11985 | && section_is_overlay (bl->section) | |
11986 | && !section_is_mapped (bl->section)) | |
11987 | return 0; | |
11988 | ||
11989 | return 1; | |
11990 | } | |
11991 | ||
cd1608cc PA |
11992 | static int |
11993 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 11994 | const address_space *aspace, CORE_ADDR bp_addr, |
c272a98c | 11995 | const target_waitstatus &ws) |
cd1608cc PA |
11996 | { |
11997 | if (dprintf_style == dprintf_style_agent | |
11998 | && target_can_run_breakpoint_commands ()) | |
11999 | { | |
12000 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12001 | for this address it must be for a breakpoint that happens to | |
12002 | be set at the same address. */ | |
12003 | return 0; | |
12004 | } | |
12005 | ||
12006 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12007 | } | |
12008 | ||
2060206e | 12009 | static int |
348d480f PA |
12010 | bkpt_resources_needed (const struct bp_location *bl) |
12011 | { | |
12012 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12013 | ||
12014 | return 1; | |
12015 | } | |
12016 | ||
2060206e | 12017 | static enum print_stop_action |
313f3b21 | 12018 | bkpt_print_it (bpstat *bs) |
348d480f | 12019 | { |
348d480f PA |
12020 | struct breakpoint *b; |
12021 | const struct bp_location *bl; | |
001c8c33 | 12022 | int bp_temp; |
79a45e25 | 12023 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12024 | |
12025 | gdb_assert (bs->bp_location_at != NULL); | |
12026 | ||
b6433ede | 12027 | bl = bs->bp_location_at.get (); |
348d480f PA |
12028 | b = bs->breakpoint_at; |
12029 | ||
001c8c33 PA |
12030 | bp_temp = b->disposition == disp_del; |
12031 | if (bl->address != bl->requested_address) | |
12032 | breakpoint_adjustment_warning (bl->requested_address, | |
12033 | bl->address, | |
12034 | b->number, 1); | |
12035 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12036 | maybe_print_thread_hit_breakpoint (uiout); |
12037 | ||
112e8700 | 12038 | if (uiout->is_mi_like_p ()) |
348d480f | 12039 | { |
112e8700 | 12040 | uiout->field_string ("reason", |
001c8c33 | 12041 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12042 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12043 | } |
6a831f06 PA |
12044 | if (bp_temp) |
12045 | uiout->message ("Temporary breakpoint %pF, ", | |
12046 | signed_field ("bkptno", b->number)); | |
12047 | else | |
12048 | uiout->message ("Breakpoint %pF, ", | |
12049 | signed_field ("bkptno", b->number)); | |
06edf0c0 | 12050 | |
001c8c33 | 12051 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12052 | } |
12053 | ||
2060206e | 12054 | static void |
06edf0c0 PA |
12055 | bkpt_print_mention (struct breakpoint *b) |
12056 | { | |
112e8700 | 12057 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12058 | return; |
12059 | ||
12060 | switch (b->type) | |
12061 | { | |
12062 | case bp_breakpoint: | |
12063 | case bp_gnu_ifunc_resolver: | |
12064 | if (b->disposition == disp_del) | |
12065 | printf_filtered (_("Temporary breakpoint")); | |
12066 | else | |
12067 | printf_filtered (_("Breakpoint")); | |
12068 | printf_filtered (_(" %d"), b->number); | |
12069 | if (b->type == bp_gnu_ifunc_resolver) | |
12070 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12071 | break; | |
12072 | case bp_hardware_breakpoint: | |
12073 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12074 | break; | |
e7e0cddf SS |
12075 | case bp_dprintf: |
12076 | printf_filtered (_("Dprintf %d"), b->number); | |
12077 | break; | |
06edf0c0 PA |
12078 | } |
12079 | ||
12080 | say_where (b); | |
12081 | } | |
12082 | ||
2060206e | 12083 | static void |
06edf0c0 PA |
12084 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12085 | { | |
12086 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12087 | fprintf_unfiltered (fp, "tbreak"); | |
12088 | else if (tp->type == bp_breakpoint) | |
12089 | fprintf_unfiltered (fp, "break"); | |
12090 | else if (tp->type == bp_hardware_breakpoint | |
12091 | && tp->disposition == disp_del) | |
12092 | fprintf_unfiltered (fp, "thbreak"); | |
12093 | else if (tp->type == bp_hardware_breakpoint) | |
12094 | fprintf_unfiltered (fp, "hbreak"); | |
12095 | else | |
12096 | internal_error (__FILE__, __LINE__, | |
12097 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12098 | ||
f00aae0f | 12099 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12100 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12101 | |
12102 | /* Print out extra_string if this breakpoint is pending. It might | |
12103 | contain, for example, conditions that were set by the user. */ | |
12104 | if (tp->loc == NULL && tp->extra_string != NULL) | |
6f781ee3 | 12105 | fprintf_unfiltered (fp, " %s", tp->extra_string.get ()); |
f00aae0f | 12106 | |
dd11a36c | 12107 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12108 | } |
12109 | ||
983af33b | 12110 | static void |
626d2320 | 12111 | bkpt_create_sals_from_location (struct event_location *location, |
f00aae0f KS |
12112 | struct linespec_result *canonical, |
12113 | enum bptype type_wanted) | |
983af33b | 12114 | { |
f00aae0f | 12115 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12116 | } |
12117 | ||
12118 | static void | |
12119 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12120 | struct linespec_result *canonical, | |
e1e01040 PA |
12121 | gdb::unique_xmalloc_ptr<char> cond_string, |
12122 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12123 | enum bptype type_wanted, |
12124 | enum bpdisp disposition, | |
12125 | int thread, | |
12126 | int task, int ignore_count, | |
12127 | const struct breakpoint_ops *ops, | |
12128 | int from_tty, int enabled, | |
44f238bb | 12129 | int internal, unsigned flags) |
983af33b | 12130 | { |
023fa29b | 12131 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12132 | std::move (cond_string), |
12133 | std::move (extra_string), | |
e7e0cddf | 12134 | type_wanted, |
983af33b SDJ |
12135 | disposition, thread, task, |
12136 | ignore_count, ops, from_tty, | |
44f238bb | 12137 | enabled, internal, flags); |
983af33b SDJ |
12138 | } |
12139 | ||
6c5b2ebe | 12140 | static std::vector<symtab_and_line> |
f00aae0f | 12141 | bkpt_decode_location (struct breakpoint *b, |
626d2320 | 12142 | struct event_location *location, |
6c5b2ebe | 12143 | struct program_space *search_pspace) |
983af33b | 12144 | { |
6c5b2ebe | 12145 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12146 | } |
12147 | ||
06edf0c0 PA |
12148 | /* Virtual table for internal breakpoints. */ |
12149 | ||
12150 | static void | |
12151 | internal_bkpt_re_set (struct breakpoint *b) | |
12152 | { | |
12153 | switch (b->type) | |
12154 | { | |
12155 | /* Delete overlay event and longjmp master breakpoints; they | |
12156 | will be reset later by breakpoint_re_set. */ | |
12157 | case bp_overlay_event: | |
12158 | case bp_longjmp_master: | |
12159 | case bp_std_terminate_master: | |
12160 | case bp_exception_master: | |
12161 | delete_breakpoint (b); | |
12162 | break; | |
12163 | ||
12164 | /* This breakpoint is special, it's set up when the inferior | |
dda83cd7 | 12165 | starts and we really don't want to touch it. */ |
06edf0c0 PA |
12166 | case bp_shlib_event: |
12167 | ||
12168 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12169 | it is set up, we do not want to touch it. */ | |
12170 | case bp_thread_event: | |
12171 | break; | |
12172 | } | |
12173 | } | |
12174 | ||
12175 | static void | |
313f3b21 | 12176 | internal_bkpt_check_status (bpstat *bs) |
06edf0c0 | 12177 | { |
a9b3a50f PA |
12178 | if (bs->breakpoint_at->type == bp_shlib_event) |
12179 | { | |
12180 | /* If requested, stop when the dynamic linker notifies GDB of | |
12181 | events. This allows the user to get control and place | |
12182 | breakpoints in initializer routines for dynamically loaded | |
12183 | objects (among other things). */ | |
12184 | bs->stop = stop_on_solib_events; | |
12185 | bs->print = stop_on_solib_events; | |
12186 | } | |
12187 | else | |
12188 | bs->stop = 0; | |
06edf0c0 PA |
12189 | } |
12190 | ||
12191 | static enum print_stop_action | |
313f3b21 | 12192 | internal_bkpt_print_it (bpstat *bs) |
06edf0c0 | 12193 | { |
06edf0c0 | 12194 | struct breakpoint *b; |
06edf0c0 | 12195 | |
06edf0c0 PA |
12196 | b = bs->breakpoint_at; |
12197 | ||
06edf0c0 PA |
12198 | switch (b->type) |
12199 | { | |
348d480f PA |
12200 | case bp_shlib_event: |
12201 | /* Did we stop because the user set the stop_on_solib_events | |
12202 | variable? (If so, we report this as a generic, "Stopped due | |
12203 | to shlib event" message.) */ | |
edcc5120 | 12204 | print_solib_event (0); |
348d480f PA |
12205 | break; |
12206 | ||
12207 | case bp_thread_event: | |
12208 | /* Not sure how we will get here. | |
12209 | GDB should not stop for these breakpoints. */ | |
12210 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12211 | break; |
12212 | ||
12213 | case bp_overlay_event: | |
12214 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12215 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12216 | break; |
12217 | ||
12218 | case bp_longjmp_master: | |
12219 | /* These should never be enabled. */ | |
12220 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12221 | break; |
12222 | ||
12223 | case bp_std_terminate_master: | |
12224 | /* These should never be enabled. */ | |
12225 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12226 | "gdb should not stop!\n")); | |
348d480f PA |
12227 | break; |
12228 | ||
12229 | case bp_exception_master: | |
12230 | /* These should never be enabled. */ | |
12231 | printf_filtered (_("Exception Master Breakpoint: " | |
12232 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12233 | break; |
12234 | } | |
12235 | ||
001c8c33 | 12236 | return PRINT_NOTHING; |
06edf0c0 PA |
12237 | } |
12238 | ||
12239 | static void | |
12240 | internal_bkpt_print_mention (struct breakpoint *b) | |
12241 | { | |
12242 | /* Nothing to mention. These breakpoints are internal. */ | |
12243 | } | |
12244 | ||
06edf0c0 PA |
12245 | /* Virtual table for momentary breakpoints */ |
12246 | ||
12247 | static void | |
12248 | momentary_bkpt_re_set (struct breakpoint *b) | |
12249 | { | |
12250 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12251 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12252 | Otherwise these should have been blown away via the cleanup chain |
12253 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12254 | } | |
12255 | ||
12256 | static void | |
313f3b21 | 12257 | momentary_bkpt_check_status (bpstat *bs) |
06edf0c0 PA |
12258 | { |
12259 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12260 | } | |
12261 | ||
12262 | static enum print_stop_action | |
313f3b21 | 12263 | momentary_bkpt_print_it (bpstat *bs) |
06edf0c0 | 12264 | { |
001c8c33 | 12265 | return PRINT_UNKNOWN; |
348d480f PA |
12266 | } |
12267 | ||
06edf0c0 PA |
12268 | static void |
12269 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12270 | { |
06edf0c0 | 12271 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12272 | } |
12273 | ||
e2e4d78b JK |
12274 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12275 | ||
12276 | It gets cleared already on the removal of the first one of such placed | |
12277 | breakpoints. This is OK as they get all removed altogether. */ | |
12278 | ||
c1fc2657 | 12279 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12280 | { |
c1fc2657 | 12281 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12282 | |
c1fc2657 | 12283 | if (tp != NULL) |
e2e4d78b | 12284 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12285 | } |
12286 | ||
55aa24fb SDJ |
12287 | /* Specific methods for probe breakpoints. */ |
12288 | ||
12289 | static int | |
12290 | bkpt_probe_insert_location (struct bp_location *bl) | |
12291 | { | |
12292 | int v = bkpt_insert_location (bl); | |
12293 | ||
12294 | if (v == 0) | |
12295 | { | |
12296 | /* The insertion was successful, now let's set the probe's semaphore | |
12297 | if needed. */ | |
935676c9 | 12298 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12299 | } |
12300 | ||
12301 | return v; | |
12302 | } | |
12303 | ||
12304 | static int | |
73971819 PA |
12305 | bkpt_probe_remove_location (struct bp_location *bl, |
12306 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
12307 | { |
12308 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 12309 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 12310 | |
73971819 | 12311 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
12312 | } |
12313 | ||
12314 | static void | |
626d2320 | 12315 | bkpt_probe_create_sals_from_location (struct event_location *location, |
5f700d83 | 12316 | struct linespec_result *canonical, |
f00aae0f | 12317 | enum bptype type_wanted) |
55aa24fb SDJ |
12318 | { |
12319 | struct linespec_sals lsal; | |
12320 | ||
c2f4122d | 12321 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
12322 | lsal.canonical |
12323 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12324 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
12325 | } |
12326 | ||
6c5b2ebe | 12327 | static std::vector<symtab_and_line> |
f00aae0f | 12328 | bkpt_probe_decode_location (struct breakpoint *b, |
626d2320 | 12329 | struct event_location *location, |
6c5b2ebe | 12330 | struct program_space *search_pspace) |
55aa24fb | 12331 | { |
6c5b2ebe PA |
12332 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
12333 | if (sals.empty ()) | |
55aa24fb | 12334 | error (_("probe not found")); |
6c5b2ebe | 12335 | return sals; |
55aa24fb SDJ |
12336 | } |
12337 | ||
348d480f | 12338 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12339 | |
348d480f PA |
12340 | static void |
12341 | tracepoint_re_set (struct breakpoint *b) | |
12342 | { | |
12343 | breakpoint_re_set_default (b); | |
12344 | } | |
876fa593 | 12345 | |
348d480f PA |
12346 | static int |
12347 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12348 | const address_space *aspace, CORE_ADDR bp_addr, |
c272a98c | 12349 | const target_waitstatus &ws) |
348d480f PA |
12350 | { |
12351 | /* By definition, the inferior does not report stops at | |
12352 | tracepoints. */ | |
12353 | return 0; | |
74960c60 VP |
12354 | } |
12355 | ||
12356 | static void | |
348d480f PA |
12357 | tracepoint_print_one_detail (const struct breakpoint *self, |
12358 | struct ui_out *uiout) | |
74960c60 | 12359 | { |
d9b3f62e | 12360 | struct tracepoint *tp = (struct tracepoint *) self; |
5d9310c4 | 12361 | if (!tp->static_trace_marker_id.empty ()) |
348d480f PA |
12362 | { |
12363 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12364 | |
6a831f06 PA |
12365 | uiout->message ("\tmarker id is %pF\n", |
12366 | string_field ("static-tracepoint-marker-string-id", | |
12367 | tp->static_trace_marker_id.c_str ())); | |
348d480f | 12368 | } |
0d381245 VP |
12369 | } |
12370 | ||
a474d7c2 | 12371 | static void |
348d480f | 12372 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12373 | { |
112e8700 | 12374 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12375 | return; |
cc59ec59 | 12376 | |
348d480f PA |
12377 | switch (b->type) |
12378 | { | |
12379 | case bp_tracepoint: | |
12380 | printf_filtered (_("Tracepoint")); | |
12381 | printf_filtered (_(" %d"), b->number); | |
12382 | break; | |
12383 | case bp_fast_tracepoint: | |
12384 | printf_filtered (_("Fast tracepoint")); | |
12385 | printf_filtered (_(" %d"), b->number); | |
12386 | break; | |
12387 | case bp_static_tracepoint: | |
12388 | printf_filtered (_("Static tracepoint")); | |
12389 | printf_filtered (_(" %d"), b->number); | |
12390 | break; | |
12391 | default: | |
12392 | internal_error (__FILE__, __LINE__, | |
12393 | _("unhandled tracepoint type %d"), (int) b->type); | |
12394 | } | |
12395 | ||
12396 | say_where (b); | |
a474d7c2 PA |
12397 | } |
12398 | ||
348d480f | 12399 | static void |
d9b3f62e | 12400 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12401 | { |
d9b3f62e PA |
12402 | struct tracepoint *tp = (struct tracepoint *) self; |
12403 | ||
12404 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12405 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 12406 | else if (self->type == bp_static_tracepoint) |
348d480f | 12407 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12408 | else if (self->type == bp_tracepoint) |
348d480f PA |
12409 | fprintf_unfiltered (fp, "trace"); |
12410 | else | |
12411 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12412 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12413 | |
f00aae0f | 12414 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12415 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
12416 | print_recreate_thread (self, fp); |
12417 | ||
12418 | if (tp->pass_count) | |
12419 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12420 | } |
12421 | ||
983af33b | 12422 | static void |
626d2320 | 12423 | tracepoint_create_sals_from_location (struct event_location *location, |
f00aae0f KS |
12424 | struct linespec_result *canonical, |
12425 | enum bptype type_wanted) | |
983af33b | 12426 | { |
f00aae0f | 12427 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12428 | } |
12429 | ||
12430 | static void | |
12431 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12432 | struct linespec_result *canonical, | |
e1e01040 PA |
12433 | gdb::unique_xmalloc_ptr<char> cond_string, |
12434 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12435 | enum bptype type_wanted, |
12436 | enum bpdisp disposition, | |
12437 | int thread, | |
12438 | int task, int ignore_count, | |
12439 | const struct breakpoint_ops *ops, | |
12440 | int from_tty, int enabled, | |
44f238bb | 12441 | int internal, unsigned flags) |
983af33b | 12442 | { |
023fa29b | 12443 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12444 | std::move (cond_string), |
12445 | std::move (extra_string), | |
e7e0cddf | 12446 | type_wanted, |
983af33b SDJ |
12447 | disposition, thread, task, |
12448 | ignore_count, ops, from_tty, | |
44f238bb | 12449 | enabled, internal, flags); |
983af33b SDJ |
12450 | } |
12451 | ||
6c5b2ebe | 12452 | static std::vector<symtab_and_line> |
f00aae0f | 12453 | tracepoint_decode_location (struct breakpoint *b, |
626d2320 | 12454 | struct event_location *location, |
6c5b2ebe | 12455 | struct program_space *search_pspace) |
983af33b | 12456 | { |
6c5b2ebe | 12457 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12458 | } |
12459 | ||
2060206e | 12460 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12461 | |
bac7c5cf | 12462 | /* Virtual table for tracepoints on static probes. */ |
55aa24fb SDJ |
12463 | |
12464 | static void | |
f00aae0f | 12465 | tracepoint_probe_create_sals_from_location |
626d2320 | 12466 | (struct event_location *location, |
f00aae0f KS |
12467 | struct linespec_result *canonical, |
12468 | enum bptype type_wanted) | |
55aa24fb SDJ |
12469 | { |
12470 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 12471 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
12472 | } |
12473 | ||
6c5b2ebe | 12474 | static std::vector<symtab_and_line> |
f00aae0f | 12475 | tracepoint_probe_decode_location (struct breakpoint *b, |
626d2320 | 12476 | struct event_location *location, |
6c5b2ebe | 12477 | struct program_space *search_pspace) |
55aa24fb SDJ |
12478 | { |
12479 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 12480 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
12481 | } |
12482 | ||
5c2b4418 HZ |
12483 | /* Dprintf breakpoint_ops methods. */ |
12484 | ||
12485 | static void | |
12486 | dprintf_re_set (struct breakpoint *b) | |
12487 | { | |
12488 | breakpoint_re_set_default (b); | |
12489 | ||
f00aae0f KS |
12490 | /* extra_string should never be non-NULL for dprintf. */ |
12491 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
12492 | |
12493 | /* 1 - connect to target 1, that can run breakpoint commands. | |
12494 | 2 - create a dprintf, which resolves fine. | |
12495 | 3 - disconnect from target 1 | |
12496 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
12497 | ||
12498 | After steps #3/#4, you'll want the dprintf command list to | |
12499 | be updated, because target 1 and 2 may well return different | |
12500 | answers for target_can_run_breakpoint_commands(). | |
12501 | Given absence of finer grained resetting, we get to do | |
12502 | it all the time. */ | |
12503 | if (b->extra_string != NULL) | |
12504 | update_dprintf_command_list (b); | |
12505 | } | |
12506 | ||
2d9442cc HZ |
12507 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
12508 | ||
12509 | static void | |
12510 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
12511 | { | |
f00aae0f | 12512 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 12513 | event_location_to_string (tp->location.get ()), |
6f781ee3 | 12514 | tp->extra_string.get ()); |
2d9442cc HZ |
12515 | print_recreate_thread (tp, fp); |
12516 | } | |
12517 | ||
9d6e6e84 HZ |
12518 | /* Implement the "after_condition_true" breakpoint_ops method for |
12519 | dprintf. | |
12520 | ||
12521 | dprintf's are implemented with regular commands in their command | |
12522 | list, but we run the commands here instead of before presenting the | |
12523 | stop to the user, as dprintf's don't actually cause a stop. This | |
12524 | also makes it so that the commands of multiple dprintfs at the same | |
12525 | address are all handled. */ | |
12526 | ||
12527 | static void | |
313f3b21 | 12528 | dprintf_after_condition_true (struct bpstat *bs) |
9d6e6e84 | 12529 | { |
9d6e6e84 HZ |
12530 | /* dprintf's never cause a stop. This wasn't set in the |
12531 | check_status hook instead because that would make the dprintf's | |
12532 | condition not be evaluated. */ | |
12533 | bs->stop = 0; | |
12534 | ||
12535 | /* Run the command list here. Take ownership of it instead of | |
12536 | copying. We never want these commands to run later in | |
12537 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
12538 | be set at same address as this dprintf, or even if running the | |
12539 | commands here throws. */ | |
9c95aea1 KB |
12540 | counted_command_line cmds = std::move (bs->commands); |
12541 | gdb_assert (cmds != nullptr); | |
12542 | execute_control_commands (cmds.get (), 0); | |
9d6e6e84 HZ |
12543 | } |
12544 | ||
983af33b SDJ |
12545 | /* The breakpoint_ops structure to be used on static tracepoints with |
12546 | markers (`-m'). */ | |
12547 | ||
12548 | static void | |
626d2320 | 12549 | strace_marker_create_sals_from_location (struct event_location *location, |
5f700d83 | 12550 | struct linespec_result *canonical, |
f00aae0f | 12551 | enum bptype type_wanted) |
983af33b SDJ |
12552 | { |
12553 | struct linespec_sals lsal; | |
f00aae0f | 12554 | const char *arg_start, *arg; |
983af33b | 12555 | |
a20714ff | 12556 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 12557 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 12558 | |
f2fc3015 TT |
12559 | std::string str (arg_start, arg - arg_start); |
12560 | const char *ptr = str.c_str (); | |
a20714ff PA |
12561 | canonical->location |
12562 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 12563 | |
8e9e35b1 TT |
12564 | lsal.canonical |
12565 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12566 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
12567 | } |
12568 | ||
12569 | static void | |
12570 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12571 | struct linespec_result *canonical, | |
e1e01040 PA |
12572 | gdb::unique_xmalloc_ptr<char> cond_string, |
12573 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12574 | enum bptype type_wanted, |
12575 | enum bpdisp disposition, | |
12576 | int thread, | |
12577 | int task, int ignore_count, | |
12578 | const struct breakpoint_ops *ops, | |
12579 | int from_tty, int enabled, | |
44f238bb | 12580 | int internal, unsigned flags) |
983af33b | 12581 | { |
6c5b2ebe | 12582 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
12583 | |
12584 | /* If the user is creating a static tracepoint by marker id | |
12585 | (strace -m MARKER_ID), then store the sals index, so that | |
12586 | breakpoint_re_set can try to match up which of the newly | |
12587 | found markers corresponds to this one, and, don't try to | |
12588 | expand multiple locations for each sal, given than SALS | |
12589 | already should contain all sals for MARKER_ID. */ | |
12590 | ||
6c5b2ebe | 12591 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 12592 | { |
6c5b2ebe PA |
12593 | event_location_up location |
12594 | = copy_event_location (canonical->location.get ()); | |
983af33b | 12595 | |
b270e6f9 | 12596 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 12597 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 12598 | std::move (location), NULL, |
e1e01040 PA |
12599 | std::move (cond_string), |
12600 | std::move (extra_string), | |
e7e0cddf | 12601 | type_wanted, disposition, |
983af33b | 12602 | thread, task, ignore_count, ops, |
44f238bb | 12603 | from_tty, enabled, internal, flags, |
983af33b SDJ |
12604 | canonical->special_display); |
12605 | /* Given that its possible to have multiple markers with | |
12606 | the same string id, if the user is creating a static | |
12607 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
12608 | store the sals index, so that breakpoint_re_set can | |
12609 | try to match up which of the newly found markers | |
12610 | corresponds to this one */ | |
12611 | tp->static_trace_marker_id_idx = i; | |
12612 | ||
b270e6f9 | 12613 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
12614 | } |
12615 | } | |
12616 | ||
6c5b2ebe | 12617 | static std::vector<symtab_and_line> |
f00aae0f | 12618 | strace_marker_decode_location (struct breakpoint *b, |
626d2320 | 12619 | struct event_location *location, |
6c5b2ebe | 12620 | struct program_space *search_pspace) |
983af33b SDJ |
12621 | { |
12622 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 12623 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 12624 | |
6c5b2ebe PA |
12625 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
12626 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 12627 | { |
6c5b2ebe PA |
12628 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
12629 | sals.resize (1); | |
12630 | return sals; | |
983af33b SDJ |
12631 | } |
12632 | else | |
5d9310c4 | 12633 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
983af33b SDJ |
12634 | } |
12635 | ||
12636 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
12637 | ||
12638 | static int | |
12639 | strace_marker_p (struct breakpoint *b) | |
12640 | { | |
12641 | return b->ops == &strace_marker_breakpoint_ops; | |
12642 | } | |
12643 | ||
53a5351d | 12644 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 12645 | structures. */ |
c906108c SS |
12646 | |
12647 | void | |
fba45db2 | 12648 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 12649 | { |
8a3fe4f8 | 12650 | gdb_assert (bpt != NULL); |
c906108c | 12651 | |
4a64f543 MS |
12652 | /* Has this bp already been deleted? This can happen because |
12653 | multiple lists can hold pointers to bp's. bpstat lists are | |
12654 | especial culprits. | |
12655 | ||
12656 | One example of this happening is a watchpoint's scope bp. When | |
12657 | the scope bp triggers, we notice that the watchpoint is out of | |
12658 | scope, and delete it. We also delete its scope bp. But the | |
12659 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
12660 | That bpstat is then checked for auto-deleting bp's, which are | |
12661 | deleted. | |
12662 | ||
12663 | A real solution to this problem might involve reference counts in | |
12664 | bp's, and/or giving them pointers back to their referencing | |
12665 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
12666 | storage when no more references were extent. A cheaper bandaid | |
12667 | was chosen. */ | |
c906108c SS |
12668 | if (bpt->type == bp_none) |
12669 | return; | |
12670 | ||
4a64f543 MS |
12671 | /* At least avoid this stale reference until the reference counting |
12672 | of breakpoints gets resolved. */ | |
d0fb5eae | 12673 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 12674 | { |
d0fb5eae | 12675 | struct breakpoint *related; |
3a5c3e22 | 12676 | struct watchpoint *w; |
d0fb5eae JK |
12677 | |
12678 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 12679 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 12680 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
12681 | w = (struct watchpoint *) bpt; |
12682 | else | |
12683 | w = NULL; | |
12684 | if (w != NULL) | |
12685 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
12686 | |
12687 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
12688 | for (related = bpt; related->related_breakpoint != bpt; | |
12689 | related = related->related_breakpoint); | |
12690 | related->related_breakpoint = bpt->related_breakpoint; | |
12691 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
12692 | } |
12693 | ||
a9634178 TJB |
12694 | /* watch_command_1 creates a watchpoint but only sets its number if |
12695 | update_watchpoint succeeds in creating its bp_locations. If there's | |
12696 | a problem in that process, we'll be asked to delete the half-created | |
12697 | watchpoint. In that case, don't announce the deletion. */ | |
12698 | if (bpt->number) | |
76727919 | 12699 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 12700 | |
c906108c SS |
12701 | if (breakpoint_chain == bpt) |
12702 | breakpoint_chain = bpt->next; | |
12703 | ||
43892fdf | 12704 | for (breakpoint *b : all_breakpoints ()) |
c906108c | 12705 | if (b->next == bpt) |
01add95b SM |
12706 | { |
12707 | b->next = bpt->next; | |
12708 | break; | |
12709 | } | |
c906108c | 12710 | |
f431efe5 PA |
12711 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
12712 | been freed. */ | |
12713 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 12714 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
12715 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
12716 | commands are associated with the bpstat; if we remove it here, | |
12717 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
12718 | event-top.c won't do anything, and temporary breakpoints with | |
12719 | commands won't work. */ | |
12720 | ||
12721 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
12722 | ||
4a64f543 MS |
12723 | /* Now that breakpoint is removed from breakpoint list, update the |
12724 | global location list. This will remove locations that used to | |
12725 | belong to this breakpoint. Do this before freeing the breakpoint | |
12726 | itself, since remove_breakpoint looks at location's owner. It | |
12727 | might be better design to have location completely | |
12728 | self-contained, but it's not the case now. */ | |
44702360 | 12729 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 12730 | |
4a64f543 MS |
12731 | /* On the chance that someone will soon try again to delete this |
12732 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 12733 | bpt->type = bp_none; |
4d01a485 | 12734 | delete bpt; |
c906108c SS |
12735 | } |
12736 | ||
51be5b68 PA |
12737 | /* Iterator function to call a user-provided callback function once |
12738 | for each of B and its related breakpoints. */ | |
12739 | ||
12740 | static void | |
12741 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 12742 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
12743 | { |
12744 | struct breakpoint *related; | |
12745 | ||
12746 | related = b; | |
12747 | do | |
12748 | { | |
12749 | struct breakpoint *next; | |
12750 | ||
12751 | /* FUNCTION may delete RELATED. */ | |
12752 | next = related->related_breakpoint; | |
12753 | ||
12754 | if (next == related) | |
12755 | { | |
12756 | /* RELATED is the last ring entry. */ | |
48649e1b | 12757 | function (related); |
51be5b68 PA |
12758 | |
12759 | /* FUNCTION may have deleted it, so we'd never reach back to | |
12760 | B. There's nothing left to do anyway, so just break | |
12761 | out. */ | |
12762 | break; | |
12763 | } | |
12764 | else | |
48649e1b | 12765 | function (related); |
51be5b68 PA |
12766 | |
12767 | related = next; | |
12768 | } | |
12769 | while (related != b); | |
12770 | } | |
95a42b64 | 12771 | |
4495129a | 12772 | static void |
981a3fb3 | 12773 | delete_command (const char *arg, int from_tty) |
c906108c | 12774 | { |
ea9365bb TT |
12775 | dont_repeat (); |
12776 | ||
c906108c SS |
12777 | if (arg == 0) |
12778 | { | |
12779 | int breaks_to_delete = 0; | |
12780 | ||
46c6471b | 12781 | /* Delete all breakpoints if no argument. Do not delete |
dda83cd7 SM |
12782 | internal breakpoints, these have to be deleted with an |
12783 | explicit breakpoint number argument. */ | |
43892fdf | 12784 | for (breakpoint *b : all_breakpoints ()) |
46c6471b | 12785 | if (user_breakpoint_p (b)) |
973d738b DJ |
12786 | { |
12787 | breaks_to_delete = 1; | |
12788 | break; | |
12789 | } | |
c906108c SS |
12790 | |
12791 | /* Ask user only if there are some breakpoints to delete. */ | |
12792 | if (!from_tty | |
e2e0b3e5 | 12793 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
1428b37a SM |
12794 | for (breakpoint *b : all_breakpoints_safe ()) |
12795 | if (user_breakpoint_p (b)) | |
12796 | delete_breakpoint (b); | |
c906108c SS |
12797 | } |
12798 | else | |
48649e1b | 12799 | map_breakpoint_numbers |
b926417a | 12800 | (arg, [&] (breakpoint *br) |
48649e1b | 12801 | { |
b926417a | 12802 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 12803 | }); |
c906108c SS |
12804 | } |
12805 | ||
c2f4122d PA |
12806 | /* Return true if all locations of B bound to PSPACE are pending. If |
12807 | PSPACE is NULL, all locations of all program spaces are | |
12808 | considered. */ | |
12809 | ||
0d381245 | 12810 | static int |
c2f4122d | 12811 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 12812 | { |
40cb8ca5 | 12813 | for (bp_location *loc : b->locations ()) |
c2f4122d PA |
12814 | if ((pspace == NULL |
12815 | || loc->pspace == pspace) | |
12816 | && !loc->shlib_disabled | |
8645ff69 | 12817 | && !loc->pspace->executing_startup) |
0d381245 VP |
12818 | return 0; |
12819 | return 1; | |
fe3f5fa8 VP |
12820 | } |
12821 | ||
776592bf DE |
12822 | /* Subroutine of update_breakpoint_locations to simplify it. |
12823 | Return non-zero if multiple fns in list LOC have the same name. | |
12824 | Null names are ignored. */ | |
12825 | ||
12826 | static int | |
12827 | ambiguous_names_p (struct bp_location *loc) | |
12828 | { | |
12829 | struct bp_location *l; | |
2698f5ea | 12830 | htab_up htab (htab_create_alloc (13, htab_hash_string, htab_eq_string, NULL, |
c1fb9836 | 12831 | xcalloc, xfree)); |
776592bf DE |
12832 | |
12833 | for (l = loc; l != NULL; l = l->next) | |
12834 | { | |
12835 | const char **slot; | |
23d6ee64 | 12836 | const char *name = l->function_name.get (); |
776592bf DE |
12837 | |
12838 | /* Allow for some names to be NULL, ignore them. */ | |
12839 | if (name == NULL) | |
12840 | continue; | |
12841 | ||
c1fb9836 | 12842 | slot = (const char **) htab_find_slot (htab.get (), (const void *) name, |
776592bf | 12843 | INSERT); |
4a64f543 MS |
12844 | /* NOTE: We can assume slot != NULL here because xcalloc never |
12845 | returns NULL. */ | |
776592bf | 12846 | if (*slot != NULL) |
c1fb9836 | 12847 | return 1; |
776592bf DE |
12848 | *slot = name; |
12849 | } | |
12850 | ||
776592bf DE |
12851 | return 0; |
12852 | } | |
12853 | ||
0fb4aa4b PA |
12854 | /* When symbols change, it probably means the sources changed as well, |
12855 | and it might mean the static tracepoint markers are no longer at | |
12856 | the same address or line numbers they used to be at last we | |
12857 | checked. Losing your static tracepoints whenever you rebuild is | |
12858 | undesirable. This function tries to resync/rematch gdb static | |
12859 | tracepoints with the markers on the target, for static tracepoints | |
12860 | that have not been set by marker id. Static tracepoint that have | |
12861 | been set by marker id are reset by marker id in breakpoint_re_set. | |
12862 | The heuristic is: | |
12863 | ||
12864 | 1) For a tracepoint set at a specific address, look for a marker at | |
12865 | the old PC. If one is found there, assume to be the same marker. | |
12866 | If the name / string id of the marker found is different from the | |
12867 | previous known name, assume that means the user renamed the marker | |
12868 | in the sources, and output a warning. | |
12869 | ||
12870 | 2) For a tracepoint set at a given line number, look for a marker | |
12871 | at the new address of the old line number. If one is found there, | |
12872 | assume to be the same marker. If the name / string id of the | |
12873 | marker found is different from the previous known name, assume that | |
12874 | means the user renamed the marker in the sources, and output a | |
12875 | warning. | |
12876 | ||
12877 | 3) If a marker is no longer found at the same address or line, it | |
12878 | may mean the marker no longer exists. But it may also just mean | |
12879 | the code changed a bit. Maybe the user added a few lines of code | |
12880 | that made the marker move up or down (in line number terms). Ask | |
12881 | the target for info about the marker with the string id as we knew | |
12882 | it. If found, update line number and address in the matching | |
12883 | static tracepoint. This will get confused if there's more than one | |
12884 | marker with the same ID (possible in UST, although unadvised | |
12885 | precisely because it confuses tools). */ | |
12886 | ||
12887 | static struct symtab_and_line | |
12888 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
12889 | { | |
d9b3f62e | 12890 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
12891 | struct static_tracepoint_marker marker; |
12892 | CORE_ADDR pc; | |
0fb4aa4b PA |
12893 | |
12894 | pc = sal.pc; | |
12895 | if (sal.line) | |
12896 | find_line_pc (sal.symtab, sal.line, &pc); | |
12897 | ||
12898 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
12899 | { | |
5d9310c4 | 12900 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 12901 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
12902 | b->number, tp->static_trace_marker_id.c_str (), |
12903 | marker.str_id.c_str ()); | |
0fb4aa4b | 12904 | |
5d9310c4 | 12905 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
12906 | |
12907 | return sal; | |
12908 | } | |
12909 | ||
12910 | /* Old marker wasn't found on target at lineno. Try looking it up | |
12911 | by string ID. */ | |
12912 | if (!sal.explicit_pc | |
12913 | && sal.line != 0 | |
12914 | && sal.symtab != NULL | |
5d9310c4 | 12915 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 12916 | { |
5d9310c4 SM |
12917 | std::vector<static_tracepoint_marker> markers |
12918 | = target_static_tracepoint_markers_by_strid | |
12919 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 12920 | |
5d9310c4 | 12921 | if (!markers.empty ()) |
0fb4aa4b | 12922 | { |
0fb4aa4b | 12923 | struct symbol *sym; |
80e1d417 | 12924 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 12925 | struct ui_out *uiout = current_uiout; |
67994074 | 12926 | struct explicit_location explicit_loc; |
0fb4aa4b | 12927 | |
5d9310c4 | 12928 | tpmarker = &markers[0]; |
0fb4aa4b | 12929 | |
5d9310c4 | 12930 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
12931 | |
12932 | warning (_("marker for static tracepoint %d (%s) not " | |
12933 | "found at previous line number"), | |
5d9310c4 | 12934 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 12935 | |
51abb421 | 12936 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 12937 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 12938 | uiout->text ("Now in "); |
0fb4aa4b PA |
12939 | if (sym) |
12940 | { | |
987012b8 | 12941 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 12942 | function_name_style.style ()); |
112e8700 | 12943 | uiout->text (" at "); |
0fb4aa4b | 12944 | } |
112e8700 | 12945 | uiout->field_string ("file", |
cbe56571 | 12946 | symtab_to_filename_for_display (sal2.symtab), |
e43b10e1 | 12947 | file_name_style.style ()); |
112e8700 | 12948 | uiout->text (":"); |
0fb4aa4b | 12949 | |
112e8700 | 12950 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 12951 | { |
0b0865da | 12952 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 12953 | |
112e8700 | 12954 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
12955 | } |
12956 | ||
381befee | 12957 | uiout->field_signed ("line", sal2.line); |
112e8700 | 12958 | uiout->text ("\n"); |
0fb4aa4b | 12959 | |
80e1d417 | 12960 | b->loc->line_number = sal2.line; |
2f202fde | 12961 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 12962 | |
d28cd78a | 12963 | b->location.reset (NULL); |
67994074 KS |
12964 | initialize_explicit_location (&explicit_loc); |
12965 | explicit_loc.source_filename | |
00e52e53 | 12966 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
12967 | explicit_loc.line_offset.offset = b->loc->line_number; |
12968 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 12969 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
12970 | |
12971 | /* Might be nice to check if function changed, and warn if | |
12972 | so. */ | |
0fb4aa4b PA |
12973 | } |
12974 | } | |
12975 | return sal; | |
12976 | } | |
12977 | ||
8d3788bd VP |
12978 | /* Returns 1 iff locations A and B are sufficiently same that |
12979 | we don't need to report breakpoint as changed. */ | |
12980 | ||
12981 | static int | |
12982 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
12983 | { | |
12984 | while (a && b) | |
12985 | { | |
12986 | if (a->address != b->address) | |
12987 | return 0; | |
12988 | ||
12989 | if (a->shlib_disabled != b->shlib_disabled) | |
12990 | return 0; | |
12991 | ||
12992 | if (a->enabled != b->enabled) | |
12993 | return 0; | |
12994 | ||
b5fa468f TBA |
12995 | if (a->disabled_by_cond != b->disabled_by_cond) |
12996 | return 0; | |
12997 | ||
8d3788bd VP |
12998 | a = a->next; |
12999 | b = b->next; | |
13000 | } | |
13001 | ||
13002 | if ((a == NULL) != (b == NULL)) | |
13003 | return 0; | |
13004 | ||
13005 | return 1; | |
13006 | } | |
13007 | ||
c2f4122d PA |
13008 | /* Split all locations of B that are bound to PSPACE out of B's |
13009 | location list to a separate list and return that list's head. If | |
13010 | PSPACE is NULL, hoist out all locations of B. */ | |
13011 | ||
13012 | static struct bp_location * | |
13013 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13014 | { | |
13015 | struct bp_location head; | |
13016 | struct bp_location *i = b->loc; | |
13017 | struct bp_location **i_link = &b->loc; | |
13018 | struct bp_location *hoisted = &head; | |
13019 | ||
13020 | if (pspace == NULL) | |
13021 | { | |
13022 | i = b->loc; | |
13023 | b->loc = NULL; | |
13024 | return i; | |
13025 | } | |
13026 | ||
13027 | head.next = NULL; | |
13028 | ||
13029 | while (i != NULL) | |
13030 | { | |
13031 | if (i->pspace == pspace) | |
13032 | { | |
13033 | *i_link = i->next; | |
13034 | i->next = NULL; | |
13035 | hoisted->next = i; | |
13036 | hoisted = i; | |
13037 | } | |
13038 | else | |
13039 | i_link = &i->next; | |
13040 | i = *i_link; | |
13041 | } | |
13042 | ||
13043 | return head.next; | |
13044 | } | |
13045 | ||
13046 | /* Create new breakpoint locations for B (a hardware or software | |
13047 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13048 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13049 | FILTER_PSPACE. Locations of other program spaces are left | |
13050 | untouched. */ | |
f1310107 | 13051 | |
0e30163f | 13052 | void |
0d381245 | 13053 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13054 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13055 | gdb::array_view<const symtab_and_line> sals, |
13056 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13057 | { |
c2f4122d | 13058 | struct bp_location *existing_locations; |
0d381245 | 13059 | |
6c5b2ebe | 13060 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13061 | { |
13062 | /* Ranged breakpoints have only one start location and one end | |
13063 | location. */ | |
13064 | b->enable_state = bp_disabled; | |
1475b18b TT |
13065 | fprintf_unfiltered (gdb_stderr, |
13066 | _("Could not reset ranged breakpoint %d: " | |
13067 | "multiple locations found\n"), | |
13068 | b->number); | |
f8eba3c6 TT |
13069 | return; |
13070 | } | |
f1310107 | 13071 | |
4a64f543 MS |
13072 | /* If there's no new locations, and all existing locations are |
13073 | pending, don't do anything. This optimizes the common case where | |
13074 | all locations are in the same shared library, that was unloaded. | |
13075 | We'd like to retain the location, so that when the library is | |
13076 | loaded again, we don't loose the enabled/disabled status of the | |
13077 | individual locations. */ | |
6c5b2ebe | 13078 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13079 | return; |
13080 | ||
c2f4122d | 13081 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13082 | |
6c5b2ebe | 13083 | for (const auto &sal : sals) |
fe3f5fa8 | 13084 | { |
f8eba3c6 TT |
13085 | struct bp_location *new_loc; |
13086 | ||
6c5b2ebe | 13087 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13088 | |
6c5b2ebe | 13089 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13090 | |
0d381245 VP |
13091 | /* Reparse conditions, they might contain references to the |
13092 | old symtab. */ | |
13093 | if (b->cond_string != NULL) | |
13094 | { | |
bbc13ae3 | 13095 | const char *s; |
fe3f5fa8 | 13096 | |
6f781ee3 | 13097 | s = b->cond_string.get (); |
a70b8144 | 13098 | try |
0d381245 | 13099 | { |
6c5b2ebe PA |
13100 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13101 | block_for_pc (sal.pc), | |
0d381245 VP |
13102 | 0); |
13103 | } | |
230d2906 | 13104 | catch (const gdb_exception_error &e) |
0d381245 | 13105 | { |
b5fa468f | 13106 | new_loc->disabled_by_cond = true; |
0d381245 VP |
13107 | } |
13108 | } | |
fe3f5fa8 | 13109 | |
6c5b2ebe | 13110 | if (!sals_end.empty ()) |
f1310107 | 13111 | { |
6c5b2ebe | 13112 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13113 | |
6c5b2ebe | 13114 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13115 | } |
0d381245 | 13116 | } |
fe3f5fa8 | 13117 | |
4a64f543 MS |
13118 | /* If possible, carry over 'disable' status from existing |
13119 | breakpoints. */ | |
0d381245 VP |
13120 | { |
13121 | struct bp_location *e = existing_locations; | |
776592bf DE |
13122 | /* If there are multiple breakpoints with the same function name, |
13123 | e.g. for inline functions, comparing function names won't work. | |
13124 | Instead compare pc addresses; this is just a heuristic as things | |
13125 | may have moved, but in practice it gives the correct answer | |
13126 | often enough until a better solution is found. */ | |
13127 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13128 | ||
0d381245 VP |
13129 | for (; e; e = e->next) |
13130 | { | |
b5fa468f | 13131 | if ((!e->enabled || e->disabled_by_cond) && e->function_name) |
0d381245 | 13132 | { |
776592bf DE |
13133 | if (have_ambiguous_names) |
13134 | { | |
40cb8ca5 | 13135 | for (bp_location *l : b->locations ()) |
7f32a4d5 PA |
13136 | { |
13137 | /* Ignore software vs hardware location type at | |
13138 | this point, because with "set breakpoint | |
13139 | auto-hw", after a re-set, locations that were | |
13140 | hardware can end up as software, or vice versa. | |
13141 | As mentioned above, this is an heuristic and in | |
13142 | practice should give the correct answer often | |
13143 | enough. */ | |
13144 | if (breakpoint_locations_match (e, l, true)) | |
13145 | { | |
b5fa468f TBA |
13146 | l->enabled = e->enabled; |
13147 | l->disabled_by_cond = e->disabled_by_cond; | |
7f32a4d5 PA |
13148 | break; |
13149 | } | |
13150 | } | |
776592bf DE |
13151 | } |
13152 | else | |
13153 | { | |
40cb8ca5 | 13154 | for (bp_location *l : b->locations ()) |
776592bf | 13155 | if (l->function_name |
23d6ee64 TT |
13156 | && strcmp (e->function_name.get (), |
13157 | l->function_name.get ()) == 0) | |
776592bf | 13158 | { |
b5fa468f TBA |
13159 | l->enabled = e->enabled; |
13160 | l->disabled_by_cond = e->disabled_by_cond; | |
776592bf DE |
13161 | break; |
13162 | } | |
13163 | } | |
0d381245 VP |
13164 | } |
13165 | } | |
13166 | } | |
fe3f5fa8 | 13167 | |
8d3788bd | 13168 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 13169 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
13170 | } |
13171 | ||
f00aae0f | 13172 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13173 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13174 | ||
6c5b2ebe | 13175 | static std::vector<symtab_and_line> |
f00aae0f | 13176 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13177 | struct program_space *search_pspace, int *found) |
ef23e705 | 13178 | { |
cc06b668 | 13179 | struct gdb_exception exception; |
ef23e705 | 13180 | |
983af33b | 13181 | gdb_assert (b->ops != NULL); |
ef23e705 | 13182 | |
6c5b2ebe PA |
13183 | std::vector<symtab_and_line> sals; |
13184 | ||
a70b8144 | 13185 | try |
ef23e705 | 13186 | { |
6c5b2ebe | 13187 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13188 | } |
94aeb44b | 13189 | catch (gdb_exception_error &e) |
ef23e705 TJB |
13190 | { |
13191 | int not_found_and_ok = 0; | |
492d29ea | 13192 | |
ef23e705 TJB |
13193 | /* For pending breakpoints, it's expected that parsing will |
13194 | fail until the right shared library is loaded. User has | |
13195 | already told to create pending breakpoints and don't need | |
13196 | extra messages. If breakpoint is in bp_shlib_disabled | |
13197 | state, then user already saw the message about that | |
13198 | breakpoint being disabled, and don't want to see more | |
13199 | errors. */ | |
58438ac1 | 13200 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13201 | && (b->condition_not_parsed |
13202 | || (b->loc != NULL | |
13203 | && search_pspace != NULL | |
13204 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13205 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13206 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13207 | || b->enable_state == bp_disabled)) |
13208 | not_found_and_ok = 1; | |
13209 | ||
13210 | if (!not_found_and_ok) | |
13211 | { | |
13212 | /* We surely don't want to warn about the same breakpoint | |
13213 | 10 times. One solution, implemented here, is disable | |
13214 | the breakpoint on error. Another solution would be to | |
13215 | have separate 'warning emitted' flag. Since this | |
13216 | happens only when a binary has changed, I don't know | |
13217 | which approach is better. */ | |
13218 | b->enable_state = bp_disabled; | |
eedc3f4f | 13219 | throw; |
ef23e705 | 13220 | } |
94aeb44b TT |
13221 | |
13222 | exception = std::move (e); | |
ef23e705 TJB |
13223 | } |
13224 | ||
492d29ea | 13225 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13226 | { |
6c5b2ebe PA |
13227 | for (auto &sal : sals) |
13228 | resolve_sal_pc (&sal); | |
f00aae0f | 13229 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13230 | { |
6f781ee3 | 13231 | gdb::unique_xmalloc_ptr<char> cond_string, extra_string; |
ed1d1739 | 13232 | int thread, task; |
ef23e705 | 13233 | |
6f781ee3 | 13234 | find_condition_and_thread_for_sals (sals, b->extra_string.get (), |
b5fa468f TBA |
13235 | &cond_string, &thread, |
13236 | &task, &extra_string); | |
f00aae0f | 13237 | gdb_assert (b->cond_string == NULL); |
ef23e705 | 13238 | if (cond_string) |
6f781ee3 | 13239 | b->cond_string = std::move (cond_string); |
ef23e705 TJB |
13240 | b->thread = thread; |
13241 | b->task = task; | |
e7e0cddf | 13242 | if (extra_string) |
6f781ee3 | 13243 | b->extra_string = std::move (extra_string); |
ef23e705 TJB |
13244 | b->condition_not_parsed = 0; |
13245 | } | |
13246 | ||
983af33b | 13247 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13248 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13249 | |
58438ac1 TT |
13250 | *found = 1; |
13251 | } | |
13252 | else | |
13253 | *found = 0; | |
ef23e705 TJB |
13254 | |
13255 | return sals; | |
13256 | } | |
13257 | ||
348d480f PA |
13258 | /* The default re_set method, for typical hardware or software |
13259 | breakpoints. Reevaluate the breakpoint and recreate its | |
13260 | locations. */ | |
13261 | ||
13262 | static void | |
28010a5d | 13263 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13264 | { |
c2f4122d | 13265 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13266 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13267 | |
6c5b2ebe PA |
13268 | int found; |
13269 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13270 | filter_pspace, &found); | |
ef23e705 | 13271 | if (found) |
6c5b2ebe | 13272 | expanded = std::move (sals); |
ef23e705 | 13273 | |
f00aae0f | 13274 | if (b->location_range_end != NULL) |
f1310107 | 13275 | { |
6c5b2ebe PA |
13276 | std::vector<symtab_and_line> sals_end |
13277 | = location_to_sals (b, b->location_range_end.get (), | |
13278 | filter_pspace, &found); | |
f1310107 | 13279 | if (found) |
6c5b2ebe | 13280 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13281 | } |
13282 | ||
c2f4122d | 13283 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13284 | } |
13285 | ||
983af33b SDJ |
13286 | /* Default method for creating SALs from an address string. It basically |
13287 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13288 | ||
13289 | static void | |
626d2320 | 13290 | create_sals_from_location_default (struct event_location *location, |
f00aae0f KS |
13291 | struct linespec_result *canonical, |
13292 | enum bptype type_wanted) | |
983af33b | 13293 | { |
f00aae0f | 13294 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
13295 | } |
13296 | ||
13297 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13298 | function for the `create_breakpoints_sal' method of | |
13299 | breakpoint_ops. */ | |
13300 | ||
13301 | static void | |
13302 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13303 | struct linespec_result *canonical, | |
e1e01040 PA |
13304 | gdb::unique_xmalloc_ptr<char> cond_string, |
13305 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13306 | enum bptype type_wanted, |
13307 | enum bpdisp disposition, | |
13308 | int thread, | |
13309 | int task, int ignore_count, | |
13310 | const struct breakpoint_ops *ops, | |
13311 | int from_tty, int enabled, | |
44f238bb | 13312 | int internal, unsigned flags) |
983af33b | 13313 | { |
e1e01040 PA |
13314 | create_breakpoints_sal (gdbarch, canonical, |
13315 | std::move (cond_string), | |
13316 | std::move (extra_string), | |
983af33b SDJ |
13317 | type_wanted, disposition, |
13318 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13319 | enabled, internal, flags); |
983af33b SDJ |
13320 | } |
13321 | ||
13322 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 13323 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 13324 | |
6c5b2ebe | 13325 | static std::vector<symtab_and_line> |
f00aae0f | 13326 | decode_location_default (struct breakpoint *b, |
626d2320 | 13327 | struct event_location *location, |
6c5b2ebe | 13328 | struct program_space *search_pspace) |
983af33b SDJ |
13329 | { |
13330 | struct linespec_result canonical; | |
13331 | ||
c2f4122d | 13332 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 13333 | NULL, 0, &canonical, multiple_symbols_all, |
c0e8dcd8 | 13334 | b->filter.get ()); |
983af33b SDJ |
13335 | |
13336 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 13337 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 13338 | |
6c5b2ebe | 13339 | if (!canonical.lsals.empty ()) |
983af33b | 13340 | { |
6c5b2ebe PA |
13341 | const linespec_sals &lsal = canonical.lsals[0]; |
13342 | return std::move (lsal.sals); | |
983af33b | 13343 | } |
6c5b2ebe | 13344 | return {}; |
983af33b SDJ |
13345 | } |
13346 | ||
bf469271 | 13347 | /* Reset a breakpoint. */ |
c906108c | 13348 | |
bf469271 PA |
13349 | static void |
13350 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 13351 | { |
fdf44873 TT |
13352 | input_radix = b->input_radix; |
13353 | set_language (b->language); | |
c906108c | 13354 | |
348d480f | 13355 | b->ops->re_set (b); |
c906108c SS |
13356 | } |
13357 | ||
c2f4122d PA |
13358 | /* Re-set breakpoint locations for the current program space. |
13359 | Locations bound to other program spaces are left untouched. */ | |
13360 | ||
c906108c | 13361 | void |
69de3c6a | 13362 | breakpoint_re_set (void) |
c906108c | 13363 | { |
c5aa993b | 13364 | { |
fdf44873 TT |
13365 | scoped_restore_current_language save_language; |
13366 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 13367 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 13368 | |
8e817061 JB |
13369 | /* breakpoint_re_set_one sets the current_language to the language |
13370 | of the breakpoint it is resetting (see prepare_re_set_context) | |
13371 | before re-evaluating the breakpoint's location. This change can | |
13372 | unfortunately get undone by accident if the language_mode is set | |
13373 | to auto, and we either switch frames, or more likely in this context, | |
13374 | we select the current frame. | |
13375 | ||
13376 | We prevent this by temporarily turning the language_mode to | |
13377 | language_mode_manual. We restore it once all breakpoints | |
13378 | have been reset. */ | |
13379 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
13380 | language_mode = language_mode_manual; | |
13381 | ||
5ed8105e PA |
13382 | /* Note: we must not try to insert locations until after all |
13383 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
13384 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
13385 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 13386 | |
1428b37a | 13387 | for (breakpoint *b : all_breakpoints_safe ()) |
5ed8105e | 13388 | { |
a70b8144 | 13389 | try |
bf469271 PA |
13390 | { |
13391 | breakpoint_re_set_one (b); | |
13392 | } | |
230d2906 | 13393 | catch (const gdb_exception &ex) |
bf469271 PA |
13394 | { |
13395 | exception_fprintf (gdb_stderr, ex, | |
13396 | "Error in re-setting breakpoint %d: ", | |
13397 | b->number); | |
13398 | } | |
5ed8105e | 13399 | } |
5ed8105e PA |
13400 | |
13401 | jit_breakpoint_re_set (); | |
13402 | } | |
6c95b8df | 13403 | |
af02033e PP |
13404 | create_overlay_event_breakpoint (); |
13405 | create_longjmp_master_breakpoint (); | |
13406 | create_std_terminate_master_breakpoint (); | |
186c406b | 13407 | create_exception_master_breakpoint (); |
2a7f3dff PA |
13408 | |
13409 | /* Now we can insert. */ | |
13410 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
13411 | } |
13412 | \f | |
c906108c SS |
13413 | /* Reset the thread number of this breakpoint: |
13414 | ||
13415 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13416 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13417 | void |
fba45db2 | 13418 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13419 | { |
13420 | if (b->thread != -1) | |
13421 | { | |
00431a78 | 13422 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
13423 | |
13424 | /* We're being called after following a fork. The new fork is | |
13425 | selected as current, and unless this was a vfork will have a | |
13426 | different program space from the original thread. Reset that | |
13427 | as well. */ | |
13428 | b->loc->pspace = current_program_space; | |
c906108c SS |
13429 | } |
13430 | } | |
13431 | ||
03ac34d5 MS |
13432 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13433 | If from_tty is nonzero, it prints a message to that effect, | |
13434 | which ends with a period (no newline). */ | |
13435 | ||
c906108c | 13436 | void |
fba45db2 | 13437 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13438 | { |
c906108c SS |
13439 | if (count < 0) |
13440 | count = 0; | |
13441 | ||
43892fdf | 13442 | for (breakpoint *b : all_breakpoints ()) |
c906108c | 13443 | if (b->number == bptnum) |
01add95b SM |
13444 | { |
13445 | if (is_tracepoint (b)) | |
13446 | { | |
13447 | if (from_tty && count != 0) | |
13448 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13449 | bptnum); | |
13450 | return; | |
13451 | } | |
13452 | ||
13453 | b->ignore_count = count; | |
13454 | if (from_tty) | |
13455 | { | |
13456 | if (count == 0) | |
13457 | printf_filtered (_("Will stop next time " | |
13458 | "breakpoint %d is reached."), | |
13459 | bptnum); | |
13460 | else if (count == 1) | |
13461 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), | |
13462 | bptnum); | |
13463 | else | |
13464 | printf_filtered (_("Will ignore next %d " | |
13465 | "crossings of breakpoint %d."), | |
13466 | count, bptnum); | |
13467 | } | |
13468 | gdb::observers::breakpoint_modified.notify (b); | |
13469 | return; | |
13470 | } | |
c906108c | 13471 | |
8a3fe4f8 | 13472 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13473 | } |
13474 | ||
c906108c SS |
13475 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13476 | ||
13477 | static void | |
0b39b52e | 13478 | ignore_command (const char *args, int from_tty) |
c906108c | 13479 | { |
0b39b52e | 13480 | const char *p = args; |
52f0bd74 | 13481 | int num; |
c906108c SS |
13482 | |
13483 | if (p == 0) | |
e2e0b3e5 | 13484 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13485 | |
c906108c | 13486 | num = get_number (&p); |
5c44784c | 13487 | if (num == 0) |
8a3fe4f8 | 13488 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13489 | if (*p == 0) |
8a3fe4f8 | 13490 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13491 | |
13492 | set_ignore_count (num, | |
13493 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13494 | from_tty); | |
221ea385 KS |
13495 | if (from_tty) |
13496 | printf_filtered ("\n"); | |
c906108c SS |
13497 | } |
13498 | \f | |
d0fe4701 XR |
13499 | |
13500 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
13501 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
13502 | |
13503 | static void | |
d0fe4701 XR |
13504 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
13505 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 13506 | { |
d0fe4701 XR |
13507 | if (bp_num_range.first == 0) |
13508 | { | |
13509 | warning (_("bad breakpoint number at or near '%d'"), | |
13510 | bp_num_range.first); | |
13511 | } | |
13512 | else | |
c906108c | 13513 | { |
d0fe4701 | 13514 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 13515 | { |
d0fe4701 XR |
13516 | bool match = false; |
13517 | ||
1428b37a | 13518 | for (breakpoint *b : all_breakpoints_safe ()) |
d0fe4701 | 13519 | if (b->number == i) |
5c44784c | 13520 | { |
bfd28288 | 13521 | match = true; |
48649e1b | 13522 | function (b); |
11cf8741 | 13523 | break; |
5c44784c | 13524 | } |
bfd28288 | 13525 | if (!match) |
b58f47ab | 13526 | printf_filtered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 13527 | } |
c906108c SS |
13528 | } |
13529 | } | |
13530 | ||
d0fe4701 XR |
13531 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
13532 | ARGS. */ | |
13533 | ||
13534 | static void | |
13535 | map_breakpoint_numbers (const char *args, | |
13536 | gdb::function_view<void (breakpoint *)> function) | |
13537 | { | |
13538 | if (args == NULL || *args == '\0') | |
13539 | error_no_arg (_("one or more breakpoint numbers")); | |
13540 | ||
13541 | number_or_range_parser parser (args); | |
13542 | ||
13543 | while (!parser.finished ()) | |
13544 | { | |
13545 | int num = parser.get_number (); | |
13546 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
13547 | } | |
13548 | } | |
13549 | ||
13550 | /* Return the breakpoint location structure corresponding to the | |
13551 | BP_NUM and LOC_NUM values. */ | |
13552 | ||
0d381245 | 13553 | static struct bp_location * |
d0fe4701 | 13554 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 13555 | { |
43892fdf | 13556 | breakpoint *b = get_breakpoint (bp_num); |
0d381245 VP |
13557 | |
13558 | if (!b || b->number != bp_num) | |
d0fe4701 | 13559 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 13560 | |
0d381245 | 13561 | if (loc_num == 0) |
d0fe4701 | 13562 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 13563 | |
d0fe4701 | 13564 | int n = 0; |
40cb8ca5 | 13565 | for (bp_location *loc : b->locations ()) |
d0fe4701 XR |
13566 | if (++n == loc_num) |
13567 | return loc; | |
13568 | ||
13569 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
13570 | } |
13571 | ||
95e95a6d PA |
13572 | /* Modes of operation for extract_bp_num. */ |
13573 | enum class extract_bp_kind | |
13574 | { | |
13575 | /* Extracting a breakpoint number. */ | |
13576 | bp, | |
13577 | ||
13578 | /* Extracting a location number. */ | |
13579 | loc, | |
13580 | }; | |
13581 | ||
13582 | /* Extract a breakpoint or location number (as determined by KIND) | |
13583 | from the string starting at START. TRAILER is a character which | |
13584 | can be found after the number. If you don't want a trailer, use | |
13585 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
13586 | string. This always returns a positive integer. */ | |
13587 | ||
13588 | static int | |
13589 | extract_bp_num (extract_bp_kind kind, const char *start, | |
13590 | int trailer, const char **end_out = NULL) | |
13591 | { | |
13592 | const char *end = start; | |
13593 | int num = get_number_trailer (&end, trailer); | |
13594 | if (num < 0) | |
13595 | error (kind == extract_bp_kind::bp | |
13596 | ? _("Negative breakpoint number '%.*s'") | |
13597 | : _("Negative breakpoint location number '%.*s'"), | |
13598 | int (end - start), start); | |
13599 | if (num == 0) | |
13600 | error (kind == extract_bp_kind::bp | |
13601 | ? _("Bad breakpoint number '%.*s'") | |
13602 | : _("Bad breakpoint location number '%.*s'"), | |
13603 | int (end - start), start); | |
13604 | ||
13605 | if (end_out != NULL) | |
13606 | *end_out = end; | |
13607 | return num; | |
13608 | } | |
13609 | ||
13610 | /* Extract a breakpoint or location range (as determined by KIND) in | |
13611 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
13612 | representing the (inclusive) range. The returned pair's elements | |
13613 | are always positive integers. */ | |
13614 | ||
13615 | static std::pair<int, int> | |
13616 | extract_bp_or_bp_range (extract_bp_kind kind, | |
13617 | const std::string &arg, | |
13618 | std::string::size_type arg_offset) | |
13619 | { | |
13620 | std::pair<int, int> range; | |
13621 | const char *bp_loc = &arg[arg_offset]; | |
13622 | std::string::size_type dash = arg.find ('-', arg_offset); | |
13623 | if (dash != std::string::npos) | |
13624 | { | |
13625 | /* bp_loc is a range (x-z). */ | |
13626 | if (arg.length () == dash + 1) | |
13627 | error (kind == extract_bp_kind::bp | |
13628 | ? _("Bad breakpoint number at or near: '%s'") | |
13629 | : _("Bad breakpoint location number at or near: '%s'"), | |
13630 | bp_loc); | |
13631 | ||
13632 | const char *end; | |
13633 | const char *start_first = bp_loc; | |
13634 | const char *start_second = &arg[dash + 1]; | |
13635 | range.first = extract_bp_num (kind, start_first, '-'); | |
13636 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
13637 | ||
13638 | if (range.first > range.second) | |
13639 | error (kind == extract_bp_kind::bp | |
13640 | ? _("Inverted breakpoint range at '%.*s'") | |
13641 | : _("Inverted breakpoint location range at '%.*s'"), | |
13642 | int (end - start_first), start_first); | |
13643 | } | |
13644 | else | |
13645 | { | |
13646 | /* bp_loc is a single value. */ | |
13647 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
13648 | range.second = range.first; | |
13649 | } | |
13650 | return range; | |
13651 | } | |
13652 | ||
d0fe4701 XR |
13653 | /* Extract the breakpoint/location range specified by ARG. Returns |
13654 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
13655 | BP_LOC_RANGE. | |
13656 | ||
13657 | ARG may be in any of the following forms: | |
13658 | ||
13659 | x where 'x' is a breakpoint number. | |
13660 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
13661 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
13662 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
13663 | location number range. | |
13664 | */ | |
13665 | ||
cc638e86 | 13666 | static void |
d0fe4701 XR |
13667 | extract_bp_number_and_location (const std::string &arg, |
13668 | std::pair<int, int> &bp_num_range, | |
13669 | std::pair<int, int> &bp_loc_range) | |
13670 | { | |
13671 | std::string::size_type dot = arg.find ('.'); | |
13672 | ||
13673 | if (dot != std::string::npos) | |
13674 | { | |
13675 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
13676 | ||
13677 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 13678 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 13679 | |
95e95a6d PA |
13680 | bp_num_range.first |
13681 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
13682 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 13683 | |
95e95a6d PA |
13684 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
13685 | arg, dot + 1); | |
d0fe4701 XR |
13686 | } |
13687 | else | |
13688 | { | |
13689 | /* Handle x and x-y cases. */ | |
d0fe4701 | 13690 | |
95e95a6d | 13691 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
13692 | bp_loc_range.first = 0; |
13693 | bp_loc_range.second = 0; | |
13694 | } | |
d0fe4701 XR |
13695 | } |
13696 | ||
13697 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
13698 | specifies whether to enable or disable. */ | |
13699 | ||
13700 | static void | |
13701 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
13702 | { | |
13703 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
13704 | if (loc != NULL) | |
13705 | { | |
b5fa468f TBA |
13706 | if (loc->disabled_by_cond && enable) |
13707 | error (_("Breakpoint %d's condition is invalid at location %d, " | |
13708 | "cannot enable."), bp_num, loc_num); | |
13709 | ||
d0fe4701 XR |
13710 | if (loc->enabled != enable) |
13711 | { | |
13712 | loc->enabled = enable; | |
13713 | mark_breakpoint_location_modified (loc); | |
13714 | } | |
13715 | if (target_supports_enable_disable_tracepoint () | |
13716 | && current_trace_status ()->running && loc->owner | |
13717 | && is_tracepoint (loc->owner)) | |
13718 | target_disable_tracepoint (loc); | |
13719 | } | |
13720 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
13721 | |
13722 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
13723 | } |
13724 | ||
13725 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
13726 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
13727 | (inclusive) range of location numbers of that breakpoint to | |
13728 | enable/disable. ENABLE specifies whether to enable or disable the | |
13729 | location. */ | |
13730 | ||
13731 | static void | |
13732 | enable_disable_breakpoint_location_range (int bp_num, | |
13733 | std::pair<int, int> &bp_loc_range, | |
13734 | bool enable) | |
13735 | { | |
13736 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
13737 | enable_disable_bp_num_loc (bp_num, i, enable); | |
13738 | } | |
0d381245 | 13739 | |
1900040c MS |
13740 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13741 | If from_tty is nonzero, it prints a message to that effect, | |
13742 | which ends with a period (no newline). */ | |
13743 | ||
c906108c | 13744 | void |
fba45db2 | 13745 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
13746 | { |
13747 | /* Never disable a watchpoint scope breakpoint; we want to | |
13748 | hit them when we leave scope so we can delete both the | |
13749 | watchpoint and its scope breakpoint at that time. */ | |
13750 | if (bpt->type == bp_watchpoint_scope) | |
13751 | return; | |
13752 | ||
b5de0fa7 | 13753 | bpt->enable_state = bp_disabled; |
c906108c | 13754 | |
b775012e LM |
13755 | /* Mark breakpoint locations modified. */ |
13756 | mark_breakpoint_modified (bpt); | |
13757 | ||
d248b706 KY |
13758 | if (target_supports_enable_disable_tracepoint () |
13759 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13760 | { | |
40cb8ca5 | 13761 | for (bp_location *location : bpt->locations ()) |
d248b706 KY |
13762 | target_disable_tracepoint (location); |
13763 | } | |
13764 | ||
44702360 | 13765 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 13766 | |
76727919 | 13767 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
13768 | } |
13769 | ||
d0fe4701 XR |
13770 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
13771 | specified in ARGS. ARGS may be in any of the formats handled by | |
13772 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
13773 | or disable the breakpoints/locations. */ | |
13774 | ||
c906108c | 13775 | static void |
d0fe4701 | 13776 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 13777 | { |
c906108c | 13778 | if (args == 0) |
46c6471b | 13779 | { |
43892fdf | 13780 | for (breakpoint *bpt : all_breakpoints ()) |
46c6471b | 13781 | if (user_breakpoint_p (bpt)) |
d0fe4701 XR |
13782 | { |
13783 | if (enable) | |
13784 | enable_breakpoint (bpt); | |
13785 | else | |
13786 | disable_breakpoint (bpt); | |
13787 | } | |
46c6471b | 13788 | } |
9eaabc75 | 13789 | else |
0d381245 | 13790 | { |
cb791d59 | 13791 | std::string num = extract_arg (&args); |
9eaabc75 | 13792 | |
cb791d59 | 13793 | while (!num.empty ()) |
d248b706 | 13794 | { |
d0fe4701 | 13795 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 13796 | |
cc638e86 PA |
13797 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
13798 | ||
13799 | if (bp_loc_range.first == bp_loc_range.second | |
13800 | && bp_loc_range.first == 0) | |
d0fe4701 | 13801 | { |
cc638e86 PA |
13802 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
13803 | map_breakpoint_number_range (bp_num_range, | |
13804 | enable | |
13805 | ? enable_breakpoint | |
13806 | : disable_breakpoint); | |
13807 | } | |
13808 | else | |
13809 | { | |
13810 | /* Handle breakpoint ids with formats 'x.y' or | |
13811 | 'x.y-z'. */ | |
13812 | enable_disable_breakpoint_location_range | |
13813 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 13814 | } |
9eaabc75 | 13815 | num = extract_arg (&args); |
d248b706 | 13816 | } |
0d381245 | 13817 | } |
c906108c SS |
13818 | } |
13819 | ||
d0fe4701 XR |
13820 | /* The disable command disables the specified breakpoints/locations |
13821 | (or all defined breakpoints) so they're no longer effective in | |
13822 | stopping the inferior. ARGS may be in any of the forms defined in | |
13823 | extract_bp_number_and_location. */ | |
13824 | ||
13825 | static void | |
13826 | disable_command (const char *args, int from_tty) | |
13827 | { | |
13828 | enable_disable_command (args, from_tty, false); | |
13829 | } | |
13830 | ||
c906108c | 13831 | static void |
816338b5 SS |
13832 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
13833 | int count) | |
c906108c | 13834 | { |
afe38095 | 13835 | int target_resources_ok; |
c906108c SS |
13836 | |
13837 | if (bpt->type == bp_hardware_breakpoint) | |
13838 | { | |
13839 | int i; | |
c5aa993b | 13840 | i = hw_breakpoint_used_count (); |
53a5351d | 13841 | target_resources_ok = |
d92524f1 | 13842 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 13843 | i + 1, 0); |
c906108c | 13844 | if (target_resources_ok == 0) |
8a3fe4f8 | 13845 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 13846 | else if (target_resources_ok < 0) |
8a3fe4f8 | 13847 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
13848 | } |
13849 | ||
cc60f2e3 | 13850 | if (is_watchpoint (bpt)) |
c906108c | 13851 | { |
d07205c2 | 13852 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 13853 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 13854 | |
a70b8144 | 13855 | try |
c906108c | 13856 | { |
3a5c3e22 PA |
13857 | struct watchpoint *w = (struct watchpoint *) bpt; |
13858 | ||
1e718ff1 TJB |
13859 | orig_enable_state = bpt->enable_state; |
13860 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 13861 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 13862 | } |
230d2906 | 13863 | catch (const gdb_exception &e) |
c5aa993b | 13864 | { |
1e718ff1 | 13865 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
13866 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
13867 | bpt->number); | |
13868 | return; | |
c5aa993b | 13869 | } |
c906108c | 13870 | } |
0101ce28 | 13871 | |
b775012e LM |
13872 | bpt->enable_state = bp_enabled; |
13873 | ||
13874 | /* Mark breakpoint locations modified. */ | |
13875 | mark_breakpoint_modified (bpt); | |
13876 | ||
d248b706 KY |
13877 | if (target_supports_enable_disable_tracepoint () |
13878 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13879 | { | |
40cb8ca5 | 13880 | for (bp_location *location : bpt->locations ()) |
d248b706 KY |
13881 | target_enable_tracepoint (location); |
13882 | } | |
13883 | ||
b4c291bb | 13884 | bpt->disposition = disposition; |
816338b5 | 13885 | bpt->enable_count = count; |
44702360 | 13886 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 13887 | |
76727919 | 13888 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
13889 | } |
13890 | ||
fe3f5fa8 | 13891 | |
c906108c | 13892 | void |
fba45db2 | 13893 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 13894 | { |
816338b5 | 13895 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
13896 | } |
13897 | ||
d0fe4701 XR |
13898 | /* The enable command enables the specified breakpoints/locations (or |
13899 | all defined breakpoints) so they once again become (or continue to | |
13900 | be) effective in stopping the inferior. ARGS may be in any of the | |
13901 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 13902 | |
c906108c | 13903 | static void |
981a3fb3 | 13904 | enable_command (const char *args, int from_tty) |
c906108c | 13905 | { |
d0fe4701 | 13906 | enable_disable_command (args, from_tty, true); |
c906108c SS |
13907 | } |
13908 | ||
c906108c | 13909 | static void |
4495129a | 13910 | enable_once_command (const char *args, int from_tty) |
c906108c | 13911 | { |
48649e1b TT |
13912 | map_breakpoint_numbers |
13913 | (args, [&] (breakpoint *b) | |
13914 | { | |
13915 | iterate_over_related_breakpoints | |
13916 | (b, [&] (breakpoint *bpt) | |
13917 | { | |
13918 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
13919 | }); | |
13920 | }); | |
816338b5 SS |
13921 | } |
13922 | ||
13923 | static void | |
4495129a | 13924 | enable_count_command (const char *args, int from_tty) |
816338b5 | 13925 | { |
b9d61307 SM |
13926 | int count; |
13927 | ||
13928 | if (args == NULL) | |
13929 | error_no_arg (_("hit count")); | |
13930 | ||
13931 | count = get_number (&args); | |
816338b5 | 13932 | |
48649e1b TT |
13933 | map_breakpoint_numbers |
13934 | (args, [&] (breakpoint *b) | |
13935 | { | |
13936 | iterate_over_related_breakpoints | |
13937 | (b, [&] (breakpoint *bpt) | |
13938 | { | |
13939 | enable_breakpoint_disp (bpt, disp_disable, count); | |
13940 | }); | |
13941 | }); | |
c906108c SS |
13942 | } |
13943 | ||
c906108c | 13944 | static void |
4495129a | 13945 | enable_delete_command (const char *args, int from_tty) |
c906108c | 13946 | { |
48649e1b TT |
13947 | map_breakpoint_numbers |
13948 | (args, [&] (breakpoint *b) | |
13949 | { | |
13950 | iterate_over_related_breakpoints | |
13951 | (b, [&] (breakpoint *bpt) | |
13952 | { | |
13953 | enable_breakpoint_disp (bpt, disp_del, 1); | |
13954 | }); | |
13955 | }); | |
c906108c SS |
13956 | } |
13957 | \f | |
1f3b5d1b PP |
13958 | /* Invalidate last known value of any hardware watchpoint if |
13959 | the memory which that value represents has been written to by | |
13960 | GDB itself. */ | |
13961 | ||
13962 | static void | |
8de0566d YQ |
13963 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
13964 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
13965 | const bfd_byte *data) |
13966 | { | |
43892fdf | 13967 | for (breakpoint *bp : all_breakpoints ()) |
1f3b5d1b | 13968 | if (bp->enable_state == bp_enabled |
3a5c3e22 | 13969 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 13970 | { |
3a5c3e22 | 13971 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 13972 | |
850645cf | 13973 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 | 13974 | { |
40cb8ca5 | 13975 | for (bp_location *loc : bp->locations ()) |
3a5c3e22 PA |
13976 | if (loc->loc_type == bp_loc_hardware_watchpoint |
13977 | && loc->address + loc->length > addr | |
13978 | && addr + len > loc->address) | |
13979 | { | |
3a5c3e22 | 13980 | wp->val = NULL; |
4c1d86d9 | 13981 | wp->val_valid = false; |
3a5c3e22 PA |
13982 | } |
13983 | } | |
1f3b5d1b PP |
13984 | } |
13985 | } | |
13986 | ||
8181d85f DJ |
13987 | /* Create and insert a breakpoint for software single step. */ |
13988 | ||
13989 | void | |
6c95b8df | 13990 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 13991 | const address_space *aspace, |
4a64f543 | 13992 | CORE_ADDR next_pc) |
8181d85f | 13993 | { |
7c16b83e PA |
13994 | struct thread_info *tp = inferior_thread (); |
13995 | struct symtab_and_line sal; | |
13996 | CORE_ADDR pc = next_pc; | |
8181d85f | 13997 | |
34b7e8a6 PA |
13998 | if (tp->control.single_step_breakpoints == NULL) |
13999 | { | |
14000 | tp->control.single_step_breakpoints | |
5d5658a1 | 14001 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14002 | } |
8181d85f | 14003 | |
7c16b83e PA |
14004 | sal = find_pc_line (pc, 0); |
14005 | sal.pc = pc; | |
14006 | sal.section = find_pc_overlay (pc); | |
14007 | sal.explicit_pc = 1; | |
34b7e8a6 | 14008 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14009 | |
7c16b83e | 14010 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14011 | } |
14012 | ||
93f9a11f YQ |
14013 | /* Insert single step breakpoints according to the current state. */ |
14014 | ||
14015 | int | |
14016 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14017 | { | |
f5ea389a | 14018 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14019 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14020 | |
f5ea389a | 14021 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14022 | |
a0ff9e1a | 14023 | if (!next_pcs.empty ()) |
93f9a11f | 14024 | { |
f5ea389a | 14025 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14026 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14027 | |
a0ff9e1a | 14028 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14029 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14030 | ||
93f9a11f YQ |
14031 | return 1; |
14032 | } | |
14033 | else | |
14034 | return 0; | |
14035 | } | |
14036 | ||
34b7e8a6 | 14037 | /* See breakpoint.h. */ |
f02253f1 HZ |
14038 | |
14039 | int | |
7c16b83e | 14040 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14041 | const address_space *aspace, |
7c16b83e | 14042 | CORE_ADDR pc) |
1aafd4da | 14043 | { |
40cb8ca5 | 14044 | for (bp_location *loc : bp->locations ()) |
7c16b83e PA |
14045 | if (loc->inserted |
14046 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14047 | return 1; | |
1aafd4da | 14048 | |
7c16b83e | 14049 | return 0; |
ef370185 JB |
14050 | } |
14051 | ||
14052 | /* Check whether a software single-step breakpoint is inserted at | |
14053 | PC. */ | |
14054 | ||
14055 | int | |
accd0bcd | 14056 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14057 | CORE_ADDR pc) |
14058 | { | |
43892fdf | 14059 | for (breakpoint *bpt : all_breakpoints ()) |
34b7e8a6 PA |
14060 | { |
14061 | if (bpt->type == bp_single_step | |
14062 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14063 | return 1; | |
14064 | } | |
14065 | return 0; | |
1aafd4da UW |
14066 | } |
14067 | ||
1042e4c0 SS |
14068 | /* Tracepoint-specific operations. */ |
14069 | ||
14070 | /* Set tracepoint count to NUM. */ | |
14071 | static void | |
14072 | set_tracepoint_count (int num) | |
14073 | { | |
14074 | tracepoint_count = num; | |
4fa62494 | 14075 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14076 | } |
14077 | ||
70221824 | 14078 | static void |
0b39b52e | 14079 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14080 | { |
ffc2605c TT |
14081 | event_location_up location = string_to_event_location (&arg, |
14082 | current_language); | |
bac7c5cf GB |
14083 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
14084 | (location.get (), true /* is_tracepoint */); | |
55aa24fb | 14085 | |
558a9d82 | 14086 | create_breakpoint (get_current_arch (), |
ffc2605c | 14087 | location.get (), |
10a636cc | 14088 | NULL, 0, arg, false, 1 /* parse arg */, |
558a9d82 YQ |
14089 | 0 /* tempflag */, |
14090 | bp_tracepoint /* type_wanted */, | |
14091 | 0 /* Ignore count */, | |
14092 | pending_break_support, | |
14093 | ops, | |
14094 | from_tty, | |
14095 | 1 /* enabled */, | |
14096 | 0 /* internal */, 0); | |
1042e4c0 SS |
14097 | } |
14098 | ||
70221824 | 14099 | static void |
0b39b52e | 14100 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14101 | { |
ffc2605c TT |
14102 | event_location_up location = string_to_event_location (&arg, |
14103 | current_language); | |
558a9d82 | 14104 | create_breakpoint (get_current_arch (), |
ffc2605c | 14105 | location.get (), |
10a636cc | 14106 | NULL, 0, arg, false, 1 /* parse arg */, |
558a9d82 YQ |
14107 | 0 /* tempflag */, |
14108 | bp_fast_tracepoint /* type_wanted */, | |
14109 | 0 /* Ignore count */, | |
14110 | pending_break_support, | |
14111 | &tracepoint_breakpoint_ops, | |
14112 | from_tty, | |
14113 | 1 /* enabled */, | |
14114 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14115 | } |
14116 | ||
14117 | /* strace command implementation. Creates a static tracepoint. */ | |
14118 | ||
70221824 | 14119 | static void |
0b39b52e | 14120 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14121 | { |
983af33b | 14122 | struct breakpoint_ops *ops; |
ffc2605c | 14123 | event_location_up location; |
983af33b SDJ |
14124 | |
14125 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14126 | or with a normal static tracepoint. */ | |
61012eef | 14127 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14128 | { |
14129 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14130 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14131 | } |
983af33b | 14132 | else |
f00aae0f KS |
14133 | { |
14134 | ops = &tracepoint_breakpoint_ops; | |
14135 | location = string_to_event_location (&arg, current_language); | |
14136 | } | |
983af33b | 14137 | |
558a9d82 | 14138 | create_breakpoint (get_current_arch (), |
ffc2605c | 14139 | location.get (), |
10a636cc | 14140 | NULL, 0, arg, false, 1 /* parse arg */, |
558a9d82 YQ |
14141 | 0 /* tempflag */, |
14142 | bp_static_tracepoint /* type_wanted */, | |
14143 | 0 /* Ignore count */, | |
14144 | pending_break_support, | |
14145 | ops, | |
14146 | from_tty, | |
14147 | 1 /* enabled */, | |
14148 | 0 /* internal */, 0); | |
7a697b8d SS |
14149 | } |
14150 | ||
409873ef SS |
14151 | /* Set up a fake reader function that gets command lines from a linked |
14152 | list that was acquired during tracepoint uploading. */ | |
14153 | ||
14154 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14155 | static int next_cmd; |
409873ef SS |
14156 | |
14157 | static char * | |
14158 | read_uploaded_action (void) | |
14159 | { | |
a18ba4e4 | 14160 | char *rslt = nullptr; |
409873ef | 14161 | |
a18ba4e4 SM |
14162 | if (next_cmd < this_utp->cmd_strings.size ()) |
14163 | { | |
67aa1f3c | 14164 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
14165 | next_cmd++; |
14166 | } | |
409873ef SS |
14167 | |
14168 | return rslt; | |
14169 | } | |
14170 | ||
00bf0b85 SS |
14171 | /* Given information about a tracepoint as recorded on a target (which |
14172 | can be either a live system or a trace file), attempt to create an | |
14173 | equivalent GDB tracepoint. This is not a reliable process, since | |
14174 | the target does not necessarily have all the information used when | |
14175 | the tracepoint was originally defined. */ | |
14176 | ||
d9b3f62e | 14177 | struct tracepoint * |
00bf0b85 | 14178 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14179 | { |
f2fc3015 TT |
14180 | const char *addr_str; |
14181 | char small_buf[100]; | |
d9b3f62e | 14182 | struct tracepoint *tp; |
fd9b8c24 | 14183 | |
409873ef | 14184 | if (utp->at_string) |
67aa1f3c | 14185 | addr_str = utp->at_string.get (); |
409873ef SS |
14186 | else |
14187 | { | |
14188 | /* In the absence of a source location, fall back to raw | |
14189 | address. Since there is no way to confirm that the address | |
14190 | means the same thing as when the trace was started, warn the | |
14191 | user. */ | |
3e43a32a MS |
14192 | warning (_("Uploaded tracepoint %d has no " |
14193 | "source location, using raw address"), | |
409873ef | 14194 | utp->number); |
8c042590 | 14195 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14196 | addr_str = small_buf; |
14197 | } | |
14198 | ||
14199 | /* There's not much we can do with a sequence of bytecodes. */ | |
14200 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14201 | warning (_("Uploaded tracepoint %d condition " |
14202 | "has no source form, ignoring it"), | |
409873ef | 14203 | utp->number); |
d5551862 | 14204 | |
ffc2605c TT |
14205 | event_location_up location = string_to_event_location (&addr_str, |
14206 | current_language); | |
8cdf0e15 | 14207 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14208 | location.get (), |
67aa1f3c | 14209 | utp->cond_string.get (), -1, addr_str, |
10a636cc | 14210 | false /* force_condition */, |
e7e0cddf | 14211 | 0 /* parse cond/thread */, |
8cdf0e15 | 14212 | 0 /* tempflag */, |
0fb4aa4b | 14213 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14214 | 0 /* Ignore count */, |
14215 | pending_break_support, | |
348d480f | 14216 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14217 | 0 /* from_tty */, |
84f4c1fe | 14218 | utp->enabled /* enabled */, |
44f238bb PA |
14219 | 0 /* internal */, |
14220 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14221 | return NULL; |
fd9b8c24 | 14222 | |
409873ef | 14223 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14224 | tp = get_tracepoint (tracepoint_count); |
14225 | gdb_assert (tp != NULL); | |
d5551862 | 14226 | |
00bf0b85 SS |
14227 | if (utp->pass > 0) |
14228 | { | |
8c042590 | 14229 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14230 | tp->number); |
00bf0b85 | 14231 | |
409873ef | 14232 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14233 | } |
14234 | ||
409873ef SS |
14235 | /* If we have uploaded versions of the original commands, set up a |
14236 | special-purpose "reader" function and call the usual command line | |
14237 | reader, then pass the result to the breakpoint command-setting | |
14238 | function. */ | |
a18ba4e4 | 14239 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 14240 | { |
12973681 | 14241 | counted_command_line cmd_list; |
00bf0b85 | 14242 | |
409873ef | 14243 | this_utp = utp; |
3149d8c1 | 14244 | next_cmd = 0; |
d5551862 | 14245 | |
60b3cef2 | 14246 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 14247 | |
c1fc2657 | 14248 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14249 | } |
a18ba4e4 SM |
14250 | else if (!utp->actions.empty () |
14251 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
14252 | warning (_("Uploaded tracepoint %d actions " |
14253 | "have no source form, ignoring them"), | |
409873ef | 14254 | utp->number); |
00bf0b85 | 14255 | |
f196051f | 14256 | /* Copy any status information that might be available. */ |
c1fc2657 | 14257 | tp->hit_count = utp->hit_count; |
f196051f SS |
14258 | tp->traceframe_usage = utp->traceframe_usage; |
14259 | ||
00bf0b85 | 14260 | return tp; |
d9b3f62e | 14261 | } |
00bf0b85 | 14262 | |
1042e4c0 SS |
14263 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14264 | omitted. */ | |
14265 | ||
14266 | static void | |
1d12d88f | 14267 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 14268 | { |
79a45e25 | 14269 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14270 | int num_printed; |
1042e4c0 | 14271 | |
5c458ae8 | 14272 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
d77f58be SS |
14273 | |
14274 | if (num_printed == 0) | |
1042e4c0 | 14275 | { |
e5a67952 | 14276 | if (args == NULL || *args == '\0') |
112e8700 | 14277 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14278 | else |
112e8700 | 14279 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14280 | } |
ad443146 SS |
14281 | |
14282 | default_collect_info (); | |
1042e4c0 SS |
14283 | } |
14284 | ||
4a64f543 | 14285 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14286 | Not supported by all targets. */ |
14287 | static void | |
5fed81ff | 14288 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14289 | { |
14290 | enable_command (args, from_tty); | |
14291 | } | |
14292 | ||
4a64f543 | 14293 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14294 | Not supported by all targets. */ |
14295 | static void | |
5fed81ff | 14296 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14297 | { |
14298 | disable_command (args, from_tty); | |
14299 | } | |
14300 | ||
4a64f543 | 14301 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14302 | static void |
4495129a | 14303 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14304 | { |
1042e4c0 SS |
14305 | dont_repeat (); |
14306 | ||
14307 | if (arg == 0) | |
14308 | { | |
14309 | int breaks_to_delete = 0; | |
14310 | ||
14311 | /* Delete all breakpoints if no argument. | |
dda83cd7 SM |
14312 | Do not delete internal or call-dummy breakpoints, these |
14313 | have to be deleted with an explicit breakpoint number | |
4a64f543 | 14314 | argument. */ |
f6d17b2b | 14315 | for (breakpoint *tp : all_tracepoints ()) |
1428b37a | 14316 | if (is_tracepoint (tp) && user_breakpoint_p (tp)) |
1042e4c0 SS |
14317 | { |
14318 | breaks_to_delete = 1; | |
14319 | break; | |
14320 | } | |
1042e4c0 SS |
14321 | |
14322 | /* Ask user only if there are some breakpoints to delete. */ | |
14323 | if (!from_tty | |
14324 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14325 | { | |
1428b37a | 14326 | for (breakpoint *b : all_breakpoints_safe ()) |
46c6471b | 14327 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14328 | delete_breakpoint (b); |
1042e4c0 SS |
14329 | } |
14330 | } | |
14331 | else | |
48649e1b | 14332 | map_breakpoint_numbers |
b926417a | 14333 | (arg, [&] (breakpoint *br) |
48649e1b | 14334 | { |
b926417a | 14335 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 14336 | }); |
1042e4c0 SS |
14337 | } |
14338 | ||
197f0a60 TT |
14339 | /* Helper function for trace_pass_command. */ |
14340 | ||
14341 | static void | |
d9b3f62e | 14342 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14343 | { |
d9b3f62e | 14344 | tp->pass_count = count; |
76727919 | 14345 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 TT |
14346 | if (from_tty) |
14347 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 14348 | tp->number, count); |
197f0a60 TT |
14349 | } |
14350 | ||
1042e4c0 SS |
14351 | /* Set passcount for tracepoint. |
14352 | ||
14353 | First command argument is passcount, second is tracepoint number. | |
14354 | If tracepoint number omitted, apply to most recently defined. | |
14355 | Also accepts special argument "all". */ | |
14356 | ||
14357 | static void | |
0b39b52e | 14358 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 14359 | { |
d9b3f62e | 14360 | struct tracepoint *t1; |
0b39b52e | 14361 | ULONGEST count; |
1042e4c0 SS |
14362 | |
14363 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14364 | error (_("passcount command requires an " |
14365 | "argument (count + optional TP num)")); | |
1042e4c0 | 14366 | |
0b39b52e | 14367 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 14368 | |
529480d0 | 14369 | args = skip_spaces (args); |
1042e4c0 SS |
14370 | if (*args && strncasecmp (args, "all", 3) == 0) |
14371 | { | |
14372 | args += 3; /* Skip special argument "all". */ | |
1042e4c0 SS |
14373 | if (*args) |
14374 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14375 | |
f6d17b2b | 14376 | for (breakpoint *b : all_tracepoints ()) |
01add95b SM |
14377 | { |
14378 | t1 = (struct tracepoint *) b; | |
14379 | trace_pass_set_count (t1, count, from_tty); | |
14380 | } | |
197f0a60 TT |
14381 | } |
14382 | else if (*args == '\0') | |
1042e4c0 | 14383 | { |
5fa1d40e | 14384 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 14385 | if (t1) |
197f0a60 TT |
14386 | trace_pass_set_count (t1, count, from_tty); |
14387 | } | |
14388 | else | |
14389 | { | |
bfd28288 PA |
14390 | number_or_range_parser parser (args); |
14391 | while (!parser.finished ()) | |
1042e4c0 | 14392 | { |
bfd28288 | 14393 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
14394 | if (t1) |
14395 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14396 | } |
14397 | } | |
1042e4c0 SS |
14398 | } |
14399 | ||
d9b3f62e | 14400 | struct tracepoint * |
1042e4c0 SS |
14401 | get_tracepoint (int num) |
14402 | { | |
f6d17b2b | 14403 | for (breakpoint *t : all_tracepoints ()) |
1042e4c0 | 14404 | if (t->number == num) |
d9b3f62e | 14405 | return (struct tracepoint *) t; |
1042e4c0 SS |
14406 | |
14407 | return NULL; | |
14408 | } | |
14409 | ||
d5551862 SS |
14410 | /* Find the tracepoint with the given target-side number (which may be |
14411 | different from the tracepoint number after disconnecting and | |
14412 | reconnecting). */ | |
14413 | ||
d9b3f62e | 14414 | struct tracepoint * |
d5551862 SS |
14415 | get_tracepoint_by_number_on_target (int num) |
14416 | { | |
f6d17b2b | 14417 | for (breakpoint *b : all_tracepoints ()) |
d9b3f62e PA |
14418 | { |
14419 | struct tracepoint *t = (struct tracepoint *) b; | |
14420 | ||
14421 | if (t->number_on_target == num) | |
14422 | return t; | |
14423 | } | |
d5551862 SS |
14424 | |
14425 | return NULL; | |
14426 | } | |
14427 | ||
1042e4c0 | 14428 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 14429 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
14430 | If the argument is missing, the most recent tracepoint |
14431 | (tracepoint_count) is returned. */ | |
14432 | ||
d9b3f62e | 14433 | struct tracepoint * |
0b39b52e | 14434 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 14435 | number_or_range_parser *parser) |
1042e4c0 | 14436 | { |
1042e4c0 | 14437 | int tpnum; |
0b39b52e | 14438 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 14439 | |
bfd28288 | 14440 | if (parser != NULL) |
197f0a60 | 14441 | { |
bfd28288 PA |
14442 | gdb_assert (!parser->finished ()); |
14443 | tpnum = parser->get_number (); | |
197f0a60 TT |
14444 | } |
14445 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 14446 | tpnum = tracepoint_count; |
1042e4c0 | 14447 | else |
197f0a60 | 14448 | tpnum = get_number (arg); |
1042e4c0 SS |
14449 | |
14450 | if (tpnum <= 0) | |
14451 | { | |
14452 | if (instring && *instring) | |
14453 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14454 | instring); | |
14455 | else | |
5fa1d40e | 14456 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
14457 | return NULL; |
14458 | } | |
14459 | ||
f6d17b2b | 14460 | for (breakpoint *t : all_tracepoints ()) |
1042e4c0 | 14461 | if (t->number == tpnum) |
d9b3f62e | 14462 | return (struct tracepoint *) t; |
1042e4c0 | 14463 | |
b58f47ab | 14464 | printf_filtered ("No tracepoint number %d.\n", tpnum); |
1042e4c0 SS |
14465 | return NULL; |
14466 | } | |
14467 | ||
d9b3f62e PA |
14468 | void |
14469 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14470 | { | |
14471 | if (b->thread != -1) | |
14472 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14473 | ||
14474 | if (b->task != 0) | |
14475 | fprintf_unfiltered (fp, " task %d", b->task); | |
14476 | ||
14477 | fprintf_unfiltered (fp, "\n"); | |
14478 | } | |
14479 | ||
6149aea9 PA |
14480 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14481 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14482 | on each breakpoint and only include the ones for which it returns | |
f2478a7e | 14483 | true. */ |
6149aea9 | 14484 | |
1042e4c0 | 14485 | static void |
4495129a | 14486 | save_breakpoints (const char *filename, int from_tty, |
f2478a7e | 14487 | bool (*filter) (const struct breakpoint *)) |
1042e4c0 | 14488 | { |
6149aea9 | 14489 | int any = 0; |
6149aea9 | 14490 | int extra_trace_bits = 0; |
1042e4c0 | 14491 | |
6149aea9 PA |
14492 | if (filename == 0 || *filename == 0) |
14493 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14494 | |
14495 | /* See if we have anything to save. */ | |
43892fdf | 14496 | for (breakpoint *tp : all_breakpoints ()) |
01add95b SM |
14497 | { |
14498 | /* Skip internal and momentary breakpoints. */ | |
14499 | if (!user_breakpoint_p (tp)) | |
14500 | continue; | |
6149aea9 | 14501 | |
01add95b SM |
14502 | /* If we have a filter, only save the breakpoints it accepts. */ |
14503 | if (filter && !filter (tp)) | |
14504 | continue; | |
6149aea9 | 14505 | |
01add95b | 14506 | any = 1; |
6149aea9 | 14507 | |
01add95b SM |
14508 | if (is_tracepoint (tp)) |
14509 | { | |
14510 | extra_trace_bits = 1; | |
6149aea9 | 14511 | |
01add95b SM |
14512 | /* We can stop searching. */ |
14513 | break; | |
14514 | } | |
14515 | } | |
6149aea9 PA |
14516 | |
14517 | if (!any) | |
1042e4c0 | 14518 | { |
6149aea9 | 14519 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14520 | return; |
14521 | } | |
14522 | ||
ee0c3293 | 14523 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
14524 | |
14525 | stdio_file fp; | |
14526 | ||
ee0c3293 | 14527 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 14528 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 14529 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 14530 | |
6149aea9 | 14531 | if (extra_trace_bits) |
d7e74731 | 14532 | save_trace_state_variables (&fp); |
8bf6485c | 14533 | |
43892fdf | 14534 | for (breakpoint *tp : all_breakpoints ()) |
01add95b SM |
14535 | { |
14536 | /* Skip internal and momentary breakpoints. */ | |
14537 | if (!user_breakpoint_p (tp)) | |
14538 | continue; | |
8bf6485c | 14539 | |
01add95b SM |
14540 | /* If we have a filter, only save the breakpoints it accepts. */ |
14541 | if (filter && !filter (tp)) | |
14542 | continue; | |
6149aea9 | 14543 | |
01add95b | 14544 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 14545 | |
01add95b SM |
14546 | /* Note, we can't rely on tp->number for anything, as we can't |
14547 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14548 | instead. */ | |
6149aea9 | 14549 | |
01add95b | 14550 | if (tp->cond_string) |
6f781ee3 | 14551 | fp.printf (" condition $bpnum %s\n", tp->cond_string.get ()); |
6149aea9 | 14552 | |
01add95b SM |
14553 | if (tp->ignore_count) |
14554 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); | |
6149aea9 | 14555 | |
01add95b SM |
14556 | if (tp->type != bp_dprintf && tp->commands) |
14557 | { | |
14558 | fp.puts (" commands\n"); | |
1042e4c0 | 14559 | |
01add95b SM |
14560 | current_uiout->redirect (&fp); |
14561 | try | |
14562 | { | |
14563 | print_command_lines (current_uiout, tp->commands.get (), 2); | |
14564 | } | |
14565 | catch (const gdb_exception &ex) | |
14566 | { | |
14567 | current_uiout->redirect (NULL); | |
14568 | throw; | |
14569 | } | |
6149aea9 | 14570 | |
01add95b SM |
14571 | current_uiout->redirect (NULL); |
14572 | fp.puts (" end\n"); | |
14573 | } | |
6149aea9 | 14574 | |
01add95b SM |
14575 | if (tp->enable_state == bp_disabled) |
14576 | fp.puts ("disable $bpnum\n"); | |
6149aea9 | 14577 | |
01add95b SM |
14578 | /* If this is a multi-location breakpoint, check if the locations |
14579 | should be individually disabled. Watchpoint locations are | |
14580 | special, and not user visible. */ | |
14581 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
14582 | { | |
14583 | int n = 1; | |
40cb8ca5 | 14584 | |
01add95b SM |
14585 | for (bp_location *loc : tp->locations ()) |
14586 | { | |
14587 | if (!loc->enabled) | |
14588 | fp.printf ("disable $bpnum.%d\n", n); | |
14589 | ||
14590 | n++; | |
14591 | } | |
14592 | } | |
14593 | } | |
8bf6485c | 14594 | |
e0700ba4 SM |
14595 | if (extra_trace_bits && !default_collect.empty ()) |
14596 | fp.printf ("set default-collect %s\n", default_collect.c_str ()); | |
8bf6485c | 14597 | |
1042e4c0 | 14598 | if (from_tty) |
ee0c3293 | 14599 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
14600 | } |
14601 | ||
14602 | /* The `save breakpoints' command. */ | |
14603 | ||
14604 | static void | |
4495129a | 14605 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
14606 | { |
14607 | save_breakpoints (args, from_tty, NULL); | |
14608 | } | |
14609 | ||
14610 | /* The `save tracepoints' command. */ | |
14611 | ||
14612 | static void | |
4495129a | 14613 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
14614 | { |
14615 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
14616 | } |
14617 | ||
c906108c | 14618 | \f |
629500fa KS |
14619 | /* This help string is used to consolidate all the help string for specifying |
14620 | locations used by several commands. */ | |
14621 | ||
14622 | #define LOCATION_HELP_STRING \ | |
14623 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
14624 | source filename, function name, label name, and line number.\n\ | |
14625 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
14626 | function \"fact\" in the file \"factorial.c\", use\n\ | |
14627 | \"factorial.c:fact:the_top\".\n\ | |
14628 | \n\ | |
14629 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
14630 | program. Example: To specify the fourth byte past the start function\n\ | |
14631 | \"main\", use \"*main + 4\".\n\ | |
14632 | \n\ | |
14633 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
14634 | syntax to specify location parameters.\n\ | |
14635 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
14636 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
14637 | -function fact -label the_top\".\n\ |
14638 | \n\ | |
14639 | By default, a specified function is matched against the program's\n\ | |
14640 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
14641 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
14642 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
14643 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 14644 | specified name as a complete fully-qualified name instead." |
629500fa | 14645 | |
4a64f543 MS |
14646 | /* This help string is used for the break, hbreak, tbreak and thbreak |
14647 | commands. It is defined as a macro to prevent duplication. | |
14648 | COMMAND should be a string constant containing the name of the | |
14649 | command. */ | |
629500fa | 14650 | |
31e2b00f | 14651 | #define BREAK_ARGS_HELP(command) \ |
733d554a TBA |
14652 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\ |
14653 | \t[-force-condition] [if CONDITION]\n\ | |
fb7b5af4 SDJ |
14654 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ |
14655 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
14656 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
14657 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
14658 | LOCATION may be a linespec, address, or explicit location as described\n\ |
14659 | below.\n\ | |
14660 | \n\ | |
dc10affe PA |
14661 | With no LOCATION, uses current execution address of the selected\n\ |
14662 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
14663 | \n\ |
14664 | THREADNUM is the number from \"info threads\".\n\ | |
14665 | CONDITION is a boolean expression.\n\ | |
733d554a TBA |
14666 | \n\ |
14667 | With the \"-force-condition\" flag, the condition is defined even when\n\ | |
14668 | it is invalid for all current locations.\n\ | |
89549d7f | 14669 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
14670 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
14671 | conditions are different.\n\ | |
31e2b00f AS |
14672 | \n\ |
14673 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
14674 | ||
44feb3ce TT |
14675 | /* List of subcommands for "catch". */ |
14676 | static struct cmd_list_element *catch_cmdlist; | |
14677 | ||
14678 | /* List of subcommands for "tcatch". */ | |
14679 | static struct cmd_list_element *tcatch_cmdlist; | |
14680 | ||
9ac4176b | 14681 | void |
a121b7c1 | 14682 | add_catch_command (const char *name, const char *docstring, |
5538b03c | 14683 | cmd_func_ftype *func, |
625e8578 | 14684 | completer_ftype *completer, |
44feb3ce TT |
14685 | void *user_data_catch, |
14686 | void *user_data_tcatch) | |
14687 | { | |
14688 | struct cmd_list_element *command; | |
14689 | ||
0450cc4c | 14690 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce | 14691 | &catch_cmdlist); |
5538b03c | 14692 | command->func = func; |
0f8e2034 | 14693 | command->set_context (user_data_catch); |
a96d9b2e | 14694 | set_cmd_completer (command, completer); |
44feb3ce | 14695 | |
0450cc4c | 14696 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce | 14697 | &tcatch_cmdlist); |
5538b03c | 14698 | command->func = func; |
0f8e2034 | 14699 | command->set_context (user_data_tcatch); |
a96d9b2e | 14700 | set_cmd_completer (command, completer); |
44feb3ce TT |
14701 | } |
14702 | ||
0574c78f GB |
14703 | /* Zero if any of the breakpoint's locations could be a location where |
14704 | functions have been inlined, nonzero otherwise. */ | |
14705 | ||
14706 | static int | |
14707 | is_non_inline_function (struct breakpoint *b) | |
14708 | { | |
14709 | /* The shared library event breakpoint is set on the address of a | |
14710 | non-inline function. */ | |
14711 | if (b->type == bp_shlib_event) | |
14712 | return 1; | |
14713 | ||
14714 | return 0; | |
14715 | } | |
14716 | ||
14717 | /* Nonzero if the specified PC cannot be a location where functions | |
14718 | have been inlined. */ | |
14719 | ||
14720 | int | |
accd0bcd | 14721 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
c272a98c | 14722 | const target_waitstatus &ws) |
0574c78f | 14723 | { |
43892fdf | 14724 | for (breakpoint *b : all_breakpoints ()) |
0574c78f GB |
14725 | { |
14726 | if (!is_non_inline_function (b)) | |
14727 | continue; | |
14728 | ||
40cb8ca5 | 14729 | for (bp_location *bl : b->locations ()) |
0574c78f GB |
14730 | { |
14731 | if (!bl->shlib_disabled | |
09ac7c10 | 14732 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
14733 | return 1; |
14734 | } | |
14735 | } | |
14736 | ||
14737 | return 0; | |
14738 | } | |
14739 | ||
2f202fde JK |
14740 | /* Remove any references to OBJFILE which is going to be freed. */ |
14741 | ||
14742 | void | |
14743 | breakpoint_free_objfile (struct objfile *objfile) | |
14744 | { | |
48d7020b | 14745 | for (bp_location *loc : all_bp_locations ()) |
eb822aa6 | 14746 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
14747 | loc->symtab = NULL; |
14748 | } | |
14749 | ||
2060206e PA |
14750 | void |
14751 | initialize_breakpoint_ops (void) | |
14752 | { | |
14753 | static int initialized = 0; | |
14754 | ||
14755 | struct breakpoint_ops *ops; | |
14756 | ||
14757 | if (initialized) | |
14758 | return; | |
14759 | initialized = 1; | |
14760 | ||
14761 | /* The breakpoint_ops structure to be inherit by all kinds of | |
14762 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
14763 | internal and momentary breakpoints, etc.). */ | |
14764 | ops = &bkpt_base_breakpoint_ops; | |
14765 | *ops = base_breakpoint_ops; | |
14766 | ops->re_set = bkpt_re_set; | |
14767 | ops->insert_location = bkpt_insert_location; | |
14768 | ops->remove_location = bkpt_remove_location; | |
14769 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 14770 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 14771 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 14772 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
14773 | |
14774 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
14775 | ops = &bkpt_breakpoint_ops; | |
14776 | *ops = bkpt_base_breakpoint_ops; | |
14777 | ops->re_set = bkpt_re_set; | |
14778 | ops->resources_needed = bkpt_resources_needed; | |
14779 | ops->print_it = bkpt_print_it; | |
14780 | ops->print_mention = bkpt_print_mention; | |
14781 | ops->print_recreate = bkpt_print_recreate; | |
14782 | ||
14783 | /* Ranged breakpoints. */ | |
14784 | ops = &ranged_breakpoint_ops; | |
14785 | *ops = bkpt_breakpoint_ops; | |
14786 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
14787 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
14788 | ops->print_it = print_it_ranged_breakpoint; | |
14789 | ops->print_one = print_one_ranged_breakpoint; | |
14790 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
14791 | ops->print_mention = print_mention_ranged_breakpoint; | |
14792 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
14793 | ||
14794 | /* Internal breakpoints. */ | |
14795 | ops = &internal_breakpoint_ops; | |
14796 | *ops = bkpt_base_breakpoint_ops; | |
14797 | ops->re_set = internal_bkpt_re_set; | |
14798 | ops->check_status = internal_bkpt_check_status; | |
14799 | ops->print_it = internal_bkpt_print_it; | |
14800 | ops->print_mention = internal_bkpt_print_mention; | |
14801 | ||
14802 | /* Momentary breakpoints. */ | |
14803 | ops = &momentary_breakpoint_ops; | |
14804 | *ops = bkpt_base_breakpoint_ops; | |
14805 | ops->re_set = momentary_bkpt_re_set; | |
14806 | ops->check_status = momentary_bkpt_check_status; | |
14807 | ops->print_it = momentary_bkpt_print_it; | |
14808 | ops->print_mention = momentary_bkpt_print_mention; | |
14809 | ||
55aa24fb SDJ |
14810 | /* Probe breakpoints. */ |
14811 | ops = &bkpt_probe_breakpoint_ops; | |
14812 | *ops = bkpt_breakpoint_ops; | |
14813 | ops->insert_location = bkpt_probe_insert_location; | |
14814 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
14815 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
14816 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 14817 | |
2060206e PA |
14818 | /* Watchpoints. */ |
14819 | ops = &watchpoint_breakpoint_ops; | |
14820 | *ops = base_breakpoint_ops; | |
14821 | ops->re_set = re_set_watchpoint; | |
14822 | ops->insert_location = insert_watchpoint; | |
14823 | ops->remove_location = remove_watchpoint; | |
14824 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
14825 | ops->check_status = check_status_watchpoint; | |
14826 | ops->resources_needed = resources_needed_watchpoint; | |
14827 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
14828 | ops->print_it = print_it_watchpoint; | |
14829 | ops->print_mention = print_mention_watchpoint; | |
14830 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 14831 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
14832 | |
14833 | /* Masked watchpoints. */ | |
14834 | ops = &masked_watchpoint_breakpoint_ops; | |
14835 | *ops = watchpoint_breakpoint_ops; | |
14836 | ops->insert_location = insert_masked_watchpoint; | |
14837 | ops->remove_location = remove_masked_watchpoint; | |
14838 | ops->resources_needed = resources_needed_masked_watchpoint; | |
14839 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
14840 | ops->print_it = print_it_masked_watchpoint; | |
14841 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
14842 | ops->print_mention = print_mention_masked_watchpoint; | |
14843 | ops->print_recreate = print_recreate_masked_watchpoint; | |
14844 | ||
14845 | /* Tracepoints. */ | |
14846 | ops = &tracepoint_breakpoint_ops; | |
14847 | *ops = base_breakpoint_ops; | |
14848 | ops->re_set = tracepoint_re_set; | |
14849 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
14850 | ops->print_one_detail = tracepoint_print_one_detail; | |
14851 | ops->print_mention = tracepoint_print_mention; | |
14852 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 14853 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 14854 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 14855 | ops->decode_location = tracepoint_decode_location; |
983af33b | 14856 | |
55aa24fb SDJ |
14857 | /* Probe tracepoints. */ |
14858 | ops = &tracepoint_probe_breakpoint_ops; | |
14859 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
14860 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
14861 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 14862 | |
983af33b SDJ |
14863 | /* Static tracepoints with marker (`-m'). */ |
14864 | ops = &strace_marker_breakpoint_ops; | |
14865 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 14866 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 14867 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 14868 | ops->decode_location = strace_marker_decode_location; |
2060206e | 14869 | |
edcc5120 TT |
14870 | /* Solib-related catchpoints. */ |
14871 | ops = &catch_solib_breakpoint_ops; | |
14872 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
14873 | ops->insert_location = insert_catch_solib; |
14874 | ops->remove_location = remove_catch_solib; | |
14875 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
14876 | ops->check_status = check_status_catch_solib; | |
14877 | ops->print_it = print_it_catch_solib; | |
14878 | ops->print_one = print_one_catch_solib; | |
14879 | ops->print_mention = print_mention_catch_solib; | |
14880 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
14881 | |
14882 | ops = &dprintf_breakpoint_ops; | |
14883 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 14884 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
14885 | ops->resources_needed = bkpt_resources_needed; |
14886 | ops->print_it = bkpt_print_it; | |
14887 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 14888 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 14889 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 14890 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
14891 | } |
14892 | ||
8bfd80db YQ |
14893 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
14894 | ||
14895 | static struct cmd_list_element *enablebreaklist = NULL; | |
14896 | ||
8588b356 SM |
14897 | /* See breakpoint.h. */ |
14898 | ||
14899 | cmd_list_element *commands_cmd_element = nullptr; | |
14900 | ||
6c265988 | 14901 | void _initialize_breakpoint (); |
c906108c | 14902 | void |
6c265988 | 14903 | _initialize_breakpoint () |
c906108c SS |
14904 | { |
14905 | struct cmd_list_element *c; | |
14906 | ||
2060206e PA |
14907 | initialize_breakpoint_ops (); |
14908 | ||
c90e7d63 SM |
14909 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib, |
14910 | "breakpoint"); | |
14911 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile, | |
14912 | "breakpoint"); | |
14913 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change, | |
14914 | "breakpoint"); | |
84acb35a | 14915 | |
c906108c SS |
14916 | breakpoint_chain = 0; |
14917 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
14918 | before a breakpoint is set. */ | |
14919 | breakpoint_count = 0; | |
14920 | ||
1042e4c0 SS |
14921 | tracepoint_count = 0; |
14922 | ||
1bedd215 AC |
14923 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
14924 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
14925 | Usage is `ignore N COUNT'.")); | |
c906108c | 14926 | |
8588b356 SM |
14927 | commands_cmd_element = add_com ("commands", class_breakpoint, |
14928 | commands_command, _("\ | |
18da0c51 MG |
14929 | Set commands to be executed when the given breakpoints are hit.\n\ |
14930 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
14931 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
14932 | (e.g. `5-7').\n\ | |
c906108c SS |
14933 | With no argument, the targeted breakpoint is the last one set.\n\ |
14934 | The commands themselves follow starting on the next line.\n\ | |
14935 | Type a line containing \"end\" to indicate the end of them.\n\ | |
14936 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 14937 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 14938 | |
b1d4d8d1 TBA |
14939 | const auto cc_opts = make_condition_command_options_def_group (nullptr); |
14940 | static std::string condition_command_help | |
14941 | = gdb::option::build_help (_("\ | |
1bedd215 | 14942 | Specify breakpoint number N to break only if COND is true.\n\ |
b1d4d8d1 | 14943 | Usage is `condition [OPTION] N COND', where N is an integer and COND\n\ |
733d554a | 14944 | is an expression to be evaluated whenever breakpoint N is reached.\n\ |
b1d4d8d1 TBA |
14945 | \n\ |
14946 | Options:\n\ | |
14947 | %OPTIONS%"), cc_opts); | |
14948 | ||
14949 | c = add_com ("condition", class_breakpoint, condition_command, | |
14950 | condition_command_help.c_str ()); | |
14951 | set_cmd_completer_handle_brkchars (c, condition_completer); | |
c906108c | 14952 | |
1bedd215 | 14953 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 14954 | Set a temporary breakpoint.\n\ |
c906108c SS |
14955 | Like \"break\" except the breakpoint is only temporary,\n\ |
14956 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
14957 | by using \"enable delete\" on the breakpoint number.\n\ |
14958 | \n" | |
14959 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 14960 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 14961 | |
1bedd215 | 14962 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 14963 | Set a hardware assisted breakpoint.\n\ |
c906108c | 14964 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
14965 | some target hardware may not have this support.\n\ |
14966 | \n" | |
14967 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 14968 | set_cmd_completer (c, location_completer); |
c906108c | 14969 | |
1bedd215 | 14970 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 14971 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 14972 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
14973 | so it will be deleted when hit.\n\ |
14974 | \n" | |
14975 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 14976 | set_cmd_completer (c, location_completer); |
c906108c | 14977 | |
3947f654 SM |
14978 | cmd_list_element *enable_cmd |
14979 | = add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ | |
590042fc PW |
14980 | Enable all or some breakpoints.\n\ |
14981 | Usage: enable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
14982 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
14983 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
14984 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 14985 | With a subcommand you can enable temporarily."), |
3947f654 | 14986 | &enablelist, 1, &cmdlist); |
c906108c | 14987 | |
3947f654 | 14988 | add_com_alias ("en", enable_cmd, class_breakpoint, 1); |
c906108c | 14989 | |
84951ab5 | 14990 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
590042fc PW |
14991 | Enable all or some breakpoints.\n\ |
14992 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
14993 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
14994 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 14995 | May be abbreviated to simply \"enable\"."), |
2f822da5 | 14996 | &enablebreaklist, 1, &enablelist); |
c906108c | 14997 | |
1a966eab | 14998 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
14999 | Enable some breakpoints for one hit.\n\ |
15000 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ | |
1a966eab | 15001 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
c906108c SS |
15002 | &enablebreaklist); |
15003 | ||
1a966eab | 15004 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15005 | Enable some breakpoints and delete when hit.\n\ |
15006 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ | |
1a966eab | 15007 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15008 | &enablebreaklist); |
15009 | ||
816338b5 | 15010 | add_cmd ("count", no_class, enable_count_command, _("\ |
590042fc PW |
15011 | Enable some breakpoints for COUNT hits.\n\ |
15012 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15013 | If a breakpoint is hit while enabled in this fashion,\n\ |
15014 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15015 | &enablebreaklist); | |
15016 | ||
1a966eab | 15017 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15018 | Enable some breakpoints and delete when hit.\n\ |
15019 | Usage: enable delete BREAKPOINTNUM...\n\ | |
1a966eab | 15020 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15021 | &enablelist); |
15022 | ||
1a966eab | 15023 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15024 | Enable some breakpoints for one hit.\n\ |
15025 | Usage: enable once BREAKPOINTNUM...\n\ | |
1a966eab | 15026 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
816338b5 SS |
15027 | &enablelist); |
15028 | ||
15029 | add_cmd ("count", no_class, enable_count_command, _("\ | |
590042fc PW |
15030 | Enable some breakpoints for COUNT hits.\n\ |
15031 | Usage: enable count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15032 | If a breakpoint is hit while enabled in this fashion,\n\ |
15033 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15034 | &enablelist); |
15035 | ||
3947f654 SM |
15036 | cmd_list_element *disable_cmd |
15037 | = add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ | |
590042fc PW |
15038 | Disable all or some breakpoints.\n\ |
15039 | Usage: disable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15040 | Arguments are breakpoint numbers with spaces in between.\n\ |
15041 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15042 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
3947f654 SM |
15043 | &disablelist, 1, &cmdlist); |
15044 | add_com_alias ("dis", disable_cmd, class_breakpoint, 1); | |
15045 | add_com_alias ("disa", disable_cmd, class_breakpoint, 1); | |
c906108c | 15046 | |
57b4f16e | 15047 | add_cmd ("breakpoints", class_breakpoint, disable_command, _("\ |
590042fc PW |
15048 | Disable all or some breakpoints.\n\ |
15049 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15050 | Arguments are breakpoint numbers with spaces in between.\n\ |
15051 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15052 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15053 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15054 | &disablelist); |
15055 | ||
3947f654 SM |
15056 | cmd_list_element *delete_cmd |
15057 | = add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ | |
590042fc PW |
15058 | Delete all or some breakpoints.\n\ |
15059 | Usage: delete [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15060 | Arguments are breakpoint numbers with spaces in between.\n\ |
15061 | To delete all breakpoints, give no argument.\n\ | |
15062 | \n\ | |
590042fc | 15063 | Also a prefix command for deletion of other GDB objects."), |
3947f654 SM |
15064 | &deletelist, 1, &cmdlist); |
15065 | add_com_alias ("d", delete_cmd, class_breakpoint, 1); | |
15066 | add_com_alias ("del", delete_cmd, class_breakpoint, 1); | |
c906108c | 15067 | |
57b4f16e | 15068 | add_cmd ("breakpoints", class_breakpoint, delete_command, _("\ |
590042fc PW |
15069 | Delete all or some breakpoints or auto-display expressions.\n\ |
15070 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15071 | Arguments are breakpoint numbers with spaces in between.\n\ |
15072 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15073 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15074 | &deletelist); |
15075 | ||
3947f654 SM |
15076 | cmd_list_element *clear_cmd |
15077 | = add_com ("clear", class_breakpoint, clear_command, _("\ | |
629500fa KS |
15078 | Clear breakpoint at specified location.\n\ |
15079 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15080 | \n\ |
15081 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 15082 | is executing in.\n" |
89549d7f | 15083 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 15084 | See also the \"delete\" command which clears breakpoints by number.")); |
3947f654 | 15085 | add_com_alias ("cl", clear_cmd, class_breakpoint, 1); |
c906108c | 15086 | |
3947f654 SM |
15087 | cmd_list_element *break_cmd |
15088 | = add_com ("break", class_breakpoint, break_command, _("\ | |
629500fa | 15089 | Set breakpoint at specified location.\n" |
31e2b00f | 15090 | BREAK_ARGS_HELP ("break"))); |
3947f654 | 15091 | set_cmd_completer (break_cmd, location_completer); |
c94fdfd0 | 15092 | |
3947f654 SM |
15093 | add_com_alias ("b", break_cmd, class_run, 1); |
15094 | add_com_alias ("br", break_cmd, class_run, 1); | |
15095 | add_com_alias ("bre", break_cmd, class_run, 1); | |
15096 | add_com_alias ("brea", break_cmd, class_run, 1); | |
c906108c | 15097 | |
c906108c SS |
15098 | if (dbx_commands) |
15099 | { | |
1bedd215 AC |
15100 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15101 | Break in function/address or break at a line in the current file."), | |
2f822da5 | 15102 | &stoplist, 1, &cmdlist); |
c5aa993b | 15103 | add_cmd ("in", class_breakpoint, stopin_command, |
1a966eab | 15104 | _("Break in function or address."), &stoplist); |
c5aa993b | 15105 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15106 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15107 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15108 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15109 | The \"Type\" column indicates one of:\n\ |
15110 | \tbreakpoint - normal breakpoint\n\ | |
15111 | \twatchpoint - watchpoint\n\ | |
15112 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15113 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15114 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15115 | address and file/line number respectively.\n\ |
15116 | \n\ | |
15117 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15118 | are set to the address of the last breakpoint listed unless the command\n\ |
15119 | is prefixed with \"server \".\n\n\ | |
c906108c | 15120 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15121 | breakpoint set.")); |
c906108c SS |
15122 | } |
15123 | ||
e0f25bd9 SM |
15124 | cmd_list_element *info_breakpoints_cmd |
15125 | = add_info ("breakpoints", info_breakpoints_command, _("\ | |
e5a67952 | 15126 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15127 | The \"Type\" column indicates one of:\n\ |
15128 | \tbreakpoint - normal breakpoint\n\ | |
15129 | \twatchpoint - watchpoint\n\ | |
15130 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15131 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15132 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15133 | address and file/line number respectively.\n\ |
15134 | \n\ | |
15135 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15136 | are set to the address of the last breakpoint listed unless the command\n\ |
15137 | is prefixed with \"server \".\n\n\ | |
c906108c | 15138 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15139 | breakpoint set.")); |
c906108c | 15140 | |
e0f25bd9 | 15141 | add_info_alias ("b", info_breakpoints_cmd, 1); |
6b04bdb7 | 15142 | |
1a966eab AC |
15143 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15144 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15145 | The \"Type\" column indicates one of:\n\ |
15146 | \tbreakpoint - normal breakpoint\n\ | |
15147 | \twatchpoint - watchpoint\n\ | |
15148 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15149 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15150 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15151 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15152 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15153 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15154 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15155 | address and file/line number respectively.\n\ |
15156 | \n\ | |
15157 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15158 | are set to the address of the last breakpoint listed unless the command\n\ |
15159 | is prefixed with \"server \".\n\n\ | |
c906108c | 15160 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15161 | breakpoint set."), |
c906108c SS |
15162 | &maintenanceinfolist); |
15163 | ||
3b6acaee | 15164 | add_basic_prefix_cmd ("catch", class_breakpoint, _("\ |
44feb3ce | 15165 | Set catchpoints to catch events."), |
2f822da5 | 15166 | &catch_cmdlist, |
3b6acaee | 15167 | 0/*allow-unknown*/, &cmdlist); |
44feb3ce | 15168 | |
3b6acaee | 15169 | add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\ |
44feb3ce | 15170 | Set temporary catchpoints to catch events."), |
2f822da5 | 15171 | &tcatch_cmdlist, |
3b6acaee | 15172 | 0/*allow-unknown*/, &cmdlist); |
44feb3ce | 15173 | |
edcc5120 TT |
15174 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15175 | Usage: catch load [REGEX]\n\ | |
15176 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15177 | catch_load_command_1, | |
15178 | NULL, | |
15179 | CATCH_PERMANENT, | |
15180 | CATCH_TEMPORARY); | |
15181 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15182 | Usage: catch unload [REGEX]\n\ | |
15183 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15184 | catch_unload_command_1, | |
15185 | NULL, | |
15186 | CATCH_PERMANENT, | |
15187 | CATCH_TEMPORARY); | |
c5aa993b | 15188 | |
a15a5258 AB |
15189 | const auto opts = make_watch_options_def_group (nullptr); |
15190 | ||
15191 | static const std::string watch_help = gdb::option::build_help (_("\ | |
15192 | Set a watchpoint for EXPRESSION.\n\ | |
15193 | Usage: watch [-location] EXPRESSION\n\ | |
15194 | \n\ | |
15195 | Options:\n\ | |
15196 | %OPTIONS%\n\ | |
15197 | \n\ | |
c906108c | 15198 | A watchpoint stops execution of your program whenever the value of\n\ |
a15a5258 AB |
15199 | an expression changes."), opts); |
15200 | c = add_com ("watch", class_breakpoint, watch_command, | |
15201 | watch_help.c_str ()); | |
15202 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
15203 | ||
15204 | static const std::string rwatch_help = gdb::option::build_help (_("\ | |
15205 | Set a read watchpoint for EXPRESSION.\n\ | |
15206 | Usage: rwatch [-location] EXPRESSION\n\ | |
15207 | \n\ | |
15208 | Options:\n\ | |
15209 | %OPTIONS%\n\ | |
15210 | \n\ | |
15211 | A read watchpoint stops execution of your program whenever the value of\n\ | |
15212 | an expression is read."), opts); | |
15213 | c = add_com ("rwatch", class_breakpoint, rwatch_command, | |
15214 | rwatch_help.c_str ()); | |
15215 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
15216 | ||
15217 | static const std::string awatch_help = gdb::option::build_help (_("\ | |
15218 | Set an access watchpoint for EXPRESSION.\n\ | |
15219 | Usage: awatch [-location] EXPRESSION\n\ | |
15220 | \n\ | |
15221 | Options:\n\ | |
15222 | %OPTIONS%\n\ | |
15223 | \n\ | |
15224 | An access watchpoint stops execution of your program whenever the value\n\ | |
15225 | of an expression is either read or written."), opts); | |
15226 | c = add_com ("awatch", class_breakpoint, awatch_command, | |
15227 | awatch_help.c_str ()); | |
15228 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
c906108c | 15229 | |
11db9430 | 15230 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15231 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15232 | |
920d2a44 AC |
15233 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15234 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15235 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15236 | &can_use_hw_watchpoints, _("\ | |
15237 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15238 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15239 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15240 | such is available. (However, any hardware watchpoints that were\n\ | |
15241 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15242 | hardware.)"), |
15243 | NULL, | |
920d2a44 | 15244 | show_can_use_hw_watchpoints, |
85c07804 | 15245 | &setlist, &showlist); |
c906108c SS |
15246 | |
15247 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15248 | |
1042e4c0 SS |
15249 | /* Tracepoint manipulation commands. */ |
15250 | ||
3947f654 SM |
15251 | cmd_list_element *trace_cmd |
15252 | = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15253 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15254 | \n" |
15255 | BREAK_ARGS_HELP ("trace") "\n\ | |
15256 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
3947f654 | 15257 | set_cmd_completer (trace_cmd, location_completer); |
1042e4c0 | 15258 | |
3947f654 SM |
15259 | add_com_alias ("tp", trace_cmd, class_breakpoint, 0); |
15260 | add_com_alias ("tr", trace_cmd, class_breakpoint, 1); | |
15261 | add_com_alias ("tra", trace_cmd, class_breakpoint, 1); | |
15262 | add_com_alias ("trac", trace_cmd, class_breakpoint, 1); | |
1042e4c0 | 15263 | |
7a697b8d | 15264 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15265 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15266 | \n" |
15267 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15268 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15269 | set_cmd_completer (c, location_completer); | |
15270 | ||
0fb4aa4b | 15271 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15272 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15273 | \n\ |
15274 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15275 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15276 | or -m MARKER_ID.\n\n\ | |
15277 | If a marker id is specified, probe the marker with that name. With\n\ | |
15278 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15279 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15280 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15281 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15282 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15283 | \n\ | |
15284 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15285 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15286 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15287 | conditions are different.\n\ | |
0fb4aa4b PA |
15288 | \n\ |
15289 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15290 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15291 | set_cmd_completer (c, location_completer); | |
15292 | ||
e0f25bd9 SM |
15293 | cmd_list_element *info_tracepoints_cmd |
15294 | = add_info ("tracepoints", info_tracepoints_command, _("\ | |
e5a67952 | 15295 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15296 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15297 | last tracepoint set.")); | |
15298 | ||
e0f25bd9 | 15299 | add_info_alias ("tp", info_tracepoints_cmd, 1); |
1042e4c0 | 15300 | |
5e84b7ee SM |
15301 | cmd_list_element *delete_tracepoints_cmd |
15302 | = add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
1042e4c0 SS |
15303 | Delete specified tracepoints.\n\ |
15304 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15305 | No argument means delete all tracepoints."), | |
15306 | &deletelist); | |
5e84b7ee | 15307 | add_alias_cmd ("tr", delete_tracepoints_cmd, class_trace, 1, &deletelist); |
1042e4c0 SS |
15308 | |
15309 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15310 | Disable specified tracepoints.\n\ | |
15311 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15312 | No argument means disable all tracepoints."), | |
15313 | &disablelist); | |
15314 | deprecate_cmd (c, "disable"); | |
15315 | ||
15316 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15317 | Enable specified tracepoints.\n\ | |
15318 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15319 | No argument means enable all tracepoints."), | |
15320 | &enablelist); | |
15321 | deprecate_cmd (c, "enable"); | |
15322 | ||
15323 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15324 | Set the passcount for a tracepoint.\n\ | |
15325 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15326 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15327 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15328 | ||
0743fc83 TT |
15329 | add_basic_prefix_cmd ("save", class_breakpoint, |
15330 | _("Save breakpoint definitions as a script."), | |
2f822da5 | 15331 | &save_cmdlist, |
0743fc83 | 15332 | 0/*allow-unknown*/, &cmdlist); |
6149aea9 PA |
15333 | |
15334 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15335 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15336 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15337 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15338 | session to restore them."), | |
15339 | &save_cmdlist); | |
15340 | set_cmd_completer (c, filename_completer); | |
15341 | ||
3947f654 SM |
15342 | cmd_list_element *save_tracepoints_cmd |
15343 | = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15344 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15345 | Use the 'source' command in another debug session to restore them."), |
15346 | &save_cmdlist); | |
3947f654 | 15347 | set_cmd_completer (save_tracepoints_cmd, filename_completer); |
1042e4c0 | 15348 | |
3947f654 | 15349 | c = add_com_alias ("save-tracepoints", save_tracepoints_cmd, class_trace, 0); |
6149aea9 PA |
15350 | deprecate_cmd (c, "save tracepoints"); |
15351 | ||
f54bdb6d SM |
15352 | add_setshow_prefix_cmd ("breakpoint", class_maintenance, |
15353 | _("\ | |
590042fc | 15354 | Breakpoint specific settings.\n\ |
fa8d40ab | 15355 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15356 | pending breakpoint behavior."), |
f54bdb6d | 15357 | _("\ |
590042fc | 15358 | Breakpoint specific settings.\n\ |
fa8d40ab | 15359 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15360 | pending breakpoint behavior."), |
f54bdb6d SM |
15361 | &breakpoint_set_cmdlist, &breakpoint_show_cmdlist, |
15362 | &setlist, &showlist); | |
fa8d40ab | 15363 | |
7915a72c AC |
15364 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15365 | &pending_break_support, _("\ | |
15366 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15367 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15368 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15369 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15370 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15371 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15372 | NULL, |
920d2a44 | 15373 | show_pending_break_support, |
6e1d7d6c AC |
15374 | &breakpoint_set_cmdlist, |
15375 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15376 | |
15377 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15378 | |
15379 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15380 | &automatic_hardware_breakpoints, _("\ | |
15381 | Set automatic usage of hardware breakpoints."), _("\ | |
15382 | Show automatic usage of hardware breakpoints."), _("\ | |
15383 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15384 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15385 | a warning will be emitted for such breakpoints."), | |
15386 | NULL, | |
15387 | show_automatic_hardware_breakpoints, | |
15388 | &breakpoint_set_cmdlist, | |
15389 | &breakpoint_show_cmdlist); | |
74960c60 | 15390 | |
a25a5a45 PA |
15391 | add_setshow_boolean_cmd ("always-inserted", class_support, |
15392 | &always_inserted_mode, _("\ | |
74960c60 VP |
15393 | Set mode for inserting breakpoints."), _("\ |
15394 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
15395 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
15396 | they're created, kept inserted even when execution stops, and removed\n\ | |
15397 | only when the user deletes them. When this mode is off (the default),\n\ | |
15398 | breakpoints are inserted only when execution continues, and removed\n\ | |
15399 | when execution stops."), | |
72d0e2c5 YQ |
15400 | NULL, |
15401 | &show_always_inserted_mode, | |
15402 | &breakpoint_set_cmdlist, | |
15403 | &breakpoint_show_cmdlist); | |
f1310107 | 15404 | |
b775012e LM |
15405 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15406 | condition_evaluation_enums, | |
15407 | &condition_evaluation_mode_1, _("\ | |
15408 | Set mode of breakpoint condition evaluation."), _("\ | |
15409 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 15410 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
15411 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
15412 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15413 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15414 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15415 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
7a4e8e7d | 15416 | be set to \"host\"."), |
b775012e LM |
15417 | &set_condition_evaluation_mode, |
15418 | &show_condition_evaluation_mode, | |
15419 | &breakpoint_set_cmdlist, | |
15420 | &breakpoint_show_cmdlist); | |
15421 | ||
f1310107 TJB |
15422 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15423 | Set a breakpoint for an address range.\n\ | |
15424 | break-range START-LOCATION, END-LOCATION\n\ | |
15425 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15426 | LINENUM, for that line in the current file,\n\ | |
15427 | FILE:LINENUM, for that line in that file,\n\ | |
15428 | +OFFSET, for that number of lines after the current line\n\ | |
dda83cd7 | 15429 | or the start of the range\n\ |
f1310107 TJB |
15430 | FUNCTION, for the first line in that function,\n\ |
15431 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15432 | *ADDRESS, for the instruction at that address.\n\ | |
15433 | \n\ | |
15434 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15435 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15436 | range (including START-LOCATION and END-LOCATION).")); | |
15437 | ||
e7e0cddf | 15438 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 15439 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 15440 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
15441 | location may be a linespec, explicit, or address location.\n" |
15442 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
15443 | set_cmd_completer (c, location_completer); |
15444 | ||
15445 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
15446 | dprintf_style_enums, &dprintf_style, _("\ | |
15447 | Set the style of usage for dynamic printf."), _("\ | |
15448 | Show the style of usage for dynamic printf."), _("\ | |
15449 | This setting chooses how GDB will do a dynamic printf.\n\ | |
15450 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
15451 | console, as with the \"printf\" command.\n\ | |
15452 | If the value is \"call\", the print is done by calling a function in your\n\ | |
15453 | program; by default printf(), but you can choose a different function or\n\ | |
15454 | output stream by setting dprintf-function and dprintf-channel."), | |
15455 | update_dprintf_commands, NULL, | |
15456 | &setlist, &showlist); | |
15457 | ||
e7e0cddf SS |
15458 | add_setshow_string_cmd ("dprintf-function", class_support, |
15459 | &dprintf_function, _("\ | |
590042fc PW |
15460 | Set the function to use for dynamic printf."), _("\ |
15461 | Show the function to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15462 | update_dprintf_commands, NULL, |
15463 | &setlist, &showlist); | |
15464 | ||
e7e0cddf SS |
15465 | add_setshow_string_cmd ("dprintf-channel", class_support, |
15466 | &dprintf_channel, _("\ | |
590042fc PW |
15467 | Set the channel to use for dynamic printf."), _("\ |
15468 | Show the channel to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15469 | update_dprintf_commands, NULL, |
15470 | &setlist, &showlist); | |
15471 | ||
d3ce09f5 SS |
15472 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
15473 | &disconnected_dprintf, _("\ | |
15474 | Set whether dprintf continues after GDB disconnects."), _("\ | |
15475 | Show whether dprintf continues after GDB disconnects."), _("\ | |
15476 | Use this to let dprintf commands continue to hit and produce output\n\ | |
15477 | even if GDB disconnects or detaches from the target."), | |
15478 | NULL, | |
15479 | NULL, | |
15480 | &setlist, &showlist); | |
15481 | ||
15482 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
590042fc PW |
15483 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
15484 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
15485 | This supports most C printf format specifications, like %s, %d, etc.\n\ | |
15486 | This is useful for formatted output in user-defined commands.")); | |
d3ce09f5 | 15487 | |
491144b5 | 15488 | automatic_hardware_breakpoints = true; |
f3b1572e | 15489 | |
c90e7d63 SM |
15490 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed, |
15491 | "breakpoint"); | |
15492 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints, | |
15493 | "breakpoint"); | |
c906108c | 15494 | } |