]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
3666a048 | 3 | Copyright (C) 1986-2021 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
d55e5aa6 | 21 | #include "arch-utils.h" |
4de283e4 TT |
22 | #include <ctype.h> |
23 | #include "hashtab.h" | |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
c906108c | 26 | #include "breakpoint.h" |
4de283e4 TT |
27 | #include "tracepoint.h" |
28 | #include "gdbtypes.h" | |
c906108c | 29 | #include "expression.h" |
d55e5aa6 | 30 | #include "gdbcore.h" |
4de283e4 TT |
31 | #include "gdbcmd.h" |
32 | #include "value.h" | |
33 | #include "command.h" | |
c906108c | 34 | #include "inferior.h" |
45741a9c | 35 | #include "infrun.h" |
4de283e4 TT |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
c906108c | 38 | #include "language.h" |
4de283e4 TT |
39 | #include "gdb-demangle.h" |
40 | #include "filenames.h" | |
41 | #include "annotate.h" | |
42 | #include "symfile.h" | |
d55e5aa6 | 43 | #include "objfiles.h" |
4de283e4 TT |
44 | #include "source.h" |
45 | #include "linespec.h" | |
46 | #include "completer.h" | |
47 | #include "ui-out.h" | |
48 | #include "cli/cli-script.h" | |
49 | #include "block.h" | |
50 | #include "solib.h" | |
51 | #include "solist.h" | |
d55e5aa6 | 52 | #include "observable.h" |
4de283e4 TT |
53 | #include "memattr.h" |
54 | #include "ada-lang.h" | |
55 | #include "top.h" | |
56 | #include "valprint.h" | |
57 | #include "jit.h" | |
65d79d4b | 58 | #include "parser-defs.h" |
4de283e4 | 59 | #include "gdb_regex.h" |
55aa24fb | 60 | #include "probe.h" |
4de283e4 | 61 | #include "cli/cli-utils.h" |
d55e5aa6 | 62 | #include "stack.h" |
4de283e4 TT |
63 | #include "ax-gdb.h" |
64 | #include "dummy-frame.h" | |
65 | #include "interps.h" | |
268a13a5 | 66 | #include "gdbsupport/format.h" |
cfc31633 | 67 | #include "thread-fsm.h" |
5d5658a1 | 68 | #include "tid-parse.h" |
4de283e4 | 69 | #include "cli/cli-style.h" |
d3ce09f5 | 70 | |
1042e4c0 | 71 | /* readline include files */ |
073bbbb0 | 72 | #include "readline/tilde.h" |
1042e4c0 SS |
73 | |
74 | /* readline defines this. */ | |
75 | #undef savestring | |
76 | ||
034dad6f | 77 | #include "mi/mi-common.h" |
6dddc817 | 78 | #include "extension.h" |
325fac50 | 79 | #include <algorithm> |
5ed8105e | 80 | #include "progspace-and-thread.h" |
268a13a5 TT |
81 | #include "gdbsupport/array-view.h" |
82 | #include "gdbsupport/gdb_optional.h" | |
104c1213 | 83 | |
4a64f543 | 84 | /* Prototypes for local functions. */ |
c906108c | 85 | |
896b6bda | 86 | static void map_breakpoint_numbers (const char *, |
48649e1b | 87 | gdb::function_view<void (breakpoint *)>); |
c906108c | 88 | |
348d480f PA |
89 | static void breakpoint_re_set_default (struct breakpoint *); |
90 | ||
f00aae0f | 91 | static void |
626d2320 | 92 | create_sals_from_location_default (struct event_location *location, |
f00aae0f KS |
93 | struct linespec_result *canonical, |
94 | enum bptype type_wanted); | |
983af33b SDJ |
95 | |
96 | static void create_breakpoints_sal_default (struct gdbarch *, | |
97 | struct linespec_result *, | |
e1e01040 PA |
98 | gdb::unique_xmalloc_ptr<char>, |
99 | gdb::unique_xmalloc_ptr<char>, | |
100 | enum bptype, | |
983af33b SDJ |
101 | enum bpdisp, int, int, |
102 | int, | |
103 | const struct breakpoint_ops *, | |
44f238bb | 104 | int, int, int, unsigned); |
983af33b | 105 | |
6c5b2ebe | 106 | static std::vector<symtab_and_line> decode_location_default |
626d2320 | 107 | (struct breakpoint *b, struct event_location *location, |
6c5b2ebe | 108 | struct program_space *search_pspace); |
983af33b | 109 | |
a6535de1 TT |
110 | static int can_use_hardware_watchpoint |
111 | (const std::vector<value_ref_ptr> &vals); | |
c906108c | 112 | |
a14ed312 | 113 | static void mention (struct breakpoint *); |
c906108c | 114 | |
348d480f PA |
115 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
116 | enum bptype, | |
c0a91b2b | 117 | const struct breakpoint_ops *); |
3742cc8b YQ |
118 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
119 | const struct symtab_and_line *); | |
120 | ||
4a64f543 MS |
121 | /* This function is used in gdbtk sources and thus can not be made |
122 | static. */ | |
63c252f8 | 123 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 124 | struct symtab_and_line, |
c0a91b2b TT |
125 | enum bptype, |
126 | const struct breakpoint_ops *); | |
c906108c | 127 | |
06edf0c0 PA |
128 | static struct breakpoint * |
129 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
130 | enum bptype type, | |
a1aa2221 LM |
131 | const struct breakpoint_ops *ops, |
132 | int loc_enabled); | |
06edf0c0 | 133 | |
76897487 KB |
134 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
135 | ||
a6d9a66e UW |
136 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
137 | CORE_ADDR bpaddr, | |
dda83cd7 | 138 | enum bptype bptype); |
76897487 | 139 | |
6c95b8df PA |
140 | static void describe_other_breakpoints (struct gdbarch *, |
141 | struct program_space *, CORE_ADDR, | |
5af949e3 | 142 | struct obj_section *, int); |
c906108c | 143 | |
85d721b8 PA |
144 | static int watchpoint_locations_match (struct bp_location *loc1, |
145 | struct bp_location *loc2); | |
146 | ||
7f32a4d5 PA |
147 | static int breakpoint_locations_match (struct bp_location *loc1, |
148 | struct bp_location *loc2, | |
149 | bool sw_hw_bps_match = false); | |
150 | ||
f1310107 | 151 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 152 | const struct address_space *aspace, |
f1310107 TJB |
153 | CORE_ADDR addr); |
154 | ||
d35ae833 | 155 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 156 | const address_space *, |
d35ae833 PA |
157 | CORE_ADDR, int); |
158 | ||
834c0d03 | 159 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 160 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 161 | |
e514a9d6 | 162 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 163 | |
a14ed312 | 164 | static int hw_breakpoint_used_count (void); |
c906108c | 165 | |
a1398e0c PA |
166 | static int hw_watchpoint_use_count (struct breakpoint *); |
167 | ||
168 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
169 | enum bptype type, | |
170 | int *other_type_used); | |
c906108c | 171 | |
816338b5 SS |
172 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
173 | int count); | |
c906108c | 174 | |
f431efe5 | 175 | static void decref_bp_location (struct bp_location **loc); |
fe3f5fa8 | 176 | |
39d61571 | 177 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 178 | |
44702360 PA |
179 | /* update_global_location_list's modes of operation wrt to whether to |
180 | insert locations now. */ | |
181 | enum ugll_insert_mode | |
182 | { | |
183 | /* Don't insert any breakpoint locations into the inferior, only | |
184 | remove already-inserted locations that no longer should be | |
185 | inserted. Functions that delete a breakpoint or breakpoints | |
186 | should specify this mode, so that deleting a breakpoint doesn't | |
187 | have the side effect of inserting the locations of other | |
188 | breakpoints that are marked not-inserted, but should_be_inserted | |
189 | returns true on them. | |
190 | ||
191 | This behavior is useful is situations close to tear-down -- e.g., | |
192 | after an exec, while the target still has execution, but | |
193 | breakpoint shadows of the previous executable image should *NOT* | |
194 | be restored to the new image; or before detaching, where the | |
195 | target still has execution and wants to delete breakpoints from | |
196 | GDB's lists, and all breakpoints had already been removed from | |
197 | the inferior. */ | |
198 | UGLL_DONT_INSERT, | |
199 | ||
a25a5a45 PA |
200 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
201 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
202 | UGLL_MAY_INSERT, |
203 | ||
a25a5a45 PA |
204 | /* Insert locations now, irrespective of |
205 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
206 | stopped right now, and the user did "continue". We need to | |
207 | insert breakpoints _before_ resuming the target, but | |
208 | UGLL_MAY_INSERT wouldn't insert them, because | |
209 | breakpoints_should_be_inserted_now returns false at that point, | |
210 | as no thread is running yet. */ | |
04086b45 | 211 | UGLL_INSERT |
44702360 PA |
212 | }; |
213 | ||
214 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 215 | |
44702360 | 216 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 217 | |
74960c60 | 218 | static void insert_breakpoint_locations (void); |
a5606eee | 219 | |
0b39b52e | 220 | static void trace_pass_command (const char *, int); |
1042e4c0 | 221 | |
558a9d82 YQ |
222 | static void set_tracepoint_count (int num); |
223 | ||
f2478a7e | 224 | static bool is_masked_watchpoint (const struct breakpoint *b); |
9c06b0b4 | 225 | |
b775012e LM |
226 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
227 | ||
983af33b SDJ |
228 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
229 | otherwise. */ | |
230 | ||
231 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 232 | |
2060206e PA |
233 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
234 | that are implemented on top of software or hardware breakpoints | |
235 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
236 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
237 | ||
238 | /* Internal breakpoints class type. */ | |
06edf0c0 | 239 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
240 | |
241 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
242 | static struct breakpoint_ops momentary_breakpoint_ops; |
243 | ||
2060206e PA |
244 | /* The breakpoint_ops structure to be used in regular user created |
245 | breakpoints. */ | |
246 | struct breakpoint_ops bkpt_breakpoint_ops; | |
247 | ||
55aa24fb SDJ |
248 | /* Breakpoints set on probes. */ |
249 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
250 | ||
bac7c5cf GB |
251 | /* Tracepoints set on probes. */ |
252 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
253 | ||
e7e0cddf | 254 | /* Dynamic printf class type. */ |
c5867ab6 | 255 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 256 | |
d3ce09f5 SS |
257 | /* The style in which to perform a dynamic printf. This is a user |
258 | option because different output options have different tradeoffs; | |
259 | if GDB does the printing, there is better error handling if there | |
260 | is a problem with any of the arguments, but using an inferior | |
261 | function lets you have special-purpose printers and sending of | |
262 | output to the same place as compiled-in print functions. */ | |
263 | ||
264 | static const char dprintf_style_gdb[] = "gdb"; | |
265 | static const char dprintf_style_call[] = "call"; | |
266 | static const char dprintf_style_agent[] = "agent"; | |
267 | static const char *const dprintf_style_enums[] = { | |
268 | dprintf_style_gdb, | |
269 | dprintf_style_call, | |
270 | dprintf_style_agent, | |
271 | NULL | |
272 | }; | |
273 | static const char *dprintf_style = dprintf_style_gdb; | |
274 | ||
275 | /* The function to use for dynamic printf if the preferred style is to | |
276 | call into the inferior. The value is simply a string that is | |
277 | copied into the command, so it can be anything that GDB can | |
278 | evaluate to a callable address, not necessarily a function name. */ | |
279 | ||
bde6261a | 280 | static char *dprintf_function; |
d3ce09f5 SS |
281 | |
282 | /* The channel to use for dynamic printf if the preferred style is to | |
283 | call into the inferior; if a nonempty string, it will be passed to | |
284 | the call as the first argument, with the format string as the | |
285 | second. As with the dprintf function, this can be anything that | |
286 | GDB knows how to evaluate, so in addition to common choices like | |
287 | "stderr", this could be an app-specific expression like | |
288 | "mystreams[curlogger]". */ | |
289 | ||
bde6261a | 290 | static char *dprintf_channel; |
d3ce09f5 SS |
291 | |
292 | /* True if dprintf commands should continue to operate even if GDB | |
293 | has disconnected. */ | |
491144b5 | 294 | static bool disconnected_dprintf = true; |
d3ce09f5 | 295 | |
5cea2a26 PA |
296 | struct command_line * |
297 | breakpoint_commands (struct breakpoint *b) | |
298 | { | |
d1b0a7bf | 299 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 300 | } |
3daf8fe5 | 301 | |
f3b1572e PA |
302 | /* Flag indicating that a command has proceeded the inferior past the |
303 | current breakpoint. */ | |
304 | ||
491144b5 | 305 | static bool breakpoint_proceeded; |
f3b1572e | 306 | |
956a9fb9 | 307 | const char * |
2cec12e5 AR |
308 | bpdisp_text (enum bpdisp disp) |
309 | { | |
4a64f543 MS |
310 | /* NOTE: the following values are a part of MI protocol and |
311 | represent values of 'disp' field returned when inferior stops at | |
312 | a breakpoint. */ | |
bc043ef3 | 313 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 314 | |
2cec12e5 AR |
315 | return bpdisps[(int) disp]; |
316 | } | |
c906108c | 317 | |
4a64f543 | 318 | /* Prototypes for exported functions. */ |
c906108c | 319 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 320 | if such is available. */ |
c906108c SS |
321 | static int can_use_hw_watchpoints; |
322 | ||
920d2a44 AC |
323 | static void |
324 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
325 | struct cmd_list_element *c, | |
326 | const char *value) | |
327 | { | |
3e43a32a MS |
328 | fprintf_filtered (file, |
329 | _("Debugger's willingness to use " | |
330 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
331 | value); |
332 | } | |
333 | ||
fa8d40ab JJ |
334 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
335 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 336 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
337 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
338 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
339 | static void |
340 | show_pending_break_support (struct ui_file *file, int from_tty, | |
341 | struct cmd_list_element *c, | |
342 | const char *value) | |
343 | { | |
3e43a32a MS |
344 | fprintf_filtered (file, |
345 | _("Debugger's behavior regarding " | |
346 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
347 | value); |
348 | } | |
fa8d40ab | 349 | |
491144b5 | 350 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 351 | set with "break" but falling in read-only memory. |
491144b5 | 352 | If false, gdb will warn about such breakpoints, but won't automatically |
765dc015 | 353 | use hardware breakpoints. */ |
491144b5 | 354 | static bool automatic_hardware_breakpoints; |
765dc015 VP |
355 | static void |
356 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
357 | struct cmd_list_element *c, | |
358 | const char *value) | |
359 | { | |
3e43a32a MS |
360 | fprintf_filtered (file, |
361 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
362 | value); |
363 | } | |
364 | ||
a25a5a45 PA |
365 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
366 | stopped, and immediately inserts any new breakpoints as soon as | |
367 | they're created. If off (default), GDB keeps breakpoints off of | |
368 | the target as long as possible. That is, it delays inserting | |
369 | breakpoints until the next resume, and removes them again when the | |
370 | target fully stops. This is a bit safer in case GDB crashes while | |
371 | processing user input. */ | |
491144b5 | 372 | static bool always_inserted_mode = false; |
72d0e2c5 | 373 | |
33e5cbd6 | 374 | static void |
74960c60 | 375 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 376 | struct cmd_list_element *c, const char *value) |
74960c60 | 377 | { |
a25a5a45 PA |
378 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
379 | value); | |
74960c60 VP |
380 | } |
381 | ||
b57bacec PA |
382 | /* See breakpoint.h. */ |
383 | ||
33e5cbd6 | 384 | int |
a25a5a45 | 385 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 386 | { |
a25a5a45 PA |
387 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
388 | { | |
389 | /* If breakpoints are global, they should be inserted even if no | |
390 | thread under gdb's control is running, or even if there are | |
391 | no threads under GDB's control yet. */ | |
392 | return 1; | |
393 | } | |
5b6d1e4f | 394 | else |
a25a5a45 | 395 | { |
a25a5a45 PA |
396 | if (always_inserted_mode) |
397 | { | |
398 | /* The user wants breakpoints inserted even if all threads | |
399 | are stopped. */ | |
400 | return 1; | |
401 | } | |
402 | ||
5b6d1e4f PA |
403 | for (inferior *inf : all_inferiors ()) |
404 | if (inf->has_execution () | |
405 | && threads_are_executing (inf->process_target ())) | |
406 | return 1; | |
372316f1 PA |
407 | |
408 | /* Don't remove breakpoints yet if, even though all threads are | |
409 | stopped, we still have events to process. */ | |
08036331 | 410 | for (thread_info *tp : all_non_exited_threads ()) |
372316f1 PA |
411 | if (tp->resumed |
412 | && tp->suspend.waitstatus_pending_p) | |
413 | return 1; | |
a25a5a45 PA |
414 | } |
415 | return 0; | |
33e5cbd6 | 416 | } |
765dc015 | 417 | |
b775012e LM |
418 | static const char condition_evaluation_both[] = "host or target"; |
419 | ||
420 | /* Modes for breakpoint condition evaluation. */ | |
421 | static const char condition_evaluation_auto[] = "auto"; | |
422 | static const char condition_evaluation_host[] = "host"; | |
423 | static const char condition_evaluation_target[] = "target"; | |
424 | static const char *const condition_evaluation_enums[] = { | |
425 | condition_evaluation_auto, | |
426 | condition_evaluation_host, | |
427 | condition_evaluation_target, | |
428 | NULL | |
429 | }; | |
430 | ||
431 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
432 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
433 | ||
434 | /* Global that we use to display information to the user (gets its value from | |
435 | condition_evaluation_mode_1. */ | |
436 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
437 | ||
438 | /* Translate a condition evaluation mode MODE into either "host" | |
439 | or "target". This is used mostly to translate from "auto" to the | |
440 | real setting that is being used. It returns the translated | |
441 | evaluation mode. */ | |
442 | ||
443 | static const char * | |
444 | translate_condition_evaluation_mode (const char *mode) | |
445 | { | |
446 | if (mode == condition_evaluation_auto) | |
447 | { | |
448 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
449 | return condition_evaluation_target; | |
450 | else | |
451 | return condition_evaluation_host; | |
452 | } | |
453 | else | |
454 | return mode; | |
455 | } | |
456 | ||
457 | /* Discovers what condition_evaluation_auto translates to. */ | |
458 | ||
459 | static const char * | |
460 | breakpoint_condition_evaluation_mode (void) | |
461 | { | |
462 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
463 | } | |
464 | ||
465 | /* Return true if GDB should evaluate breakpoint conditions or false | |
466 | otherwise. */ | |
467 | ||
468 | static int | |
469 | gdb_evaluates_breakpoint_condition_p (void) | |
470 | { | |
471 | const char *mode = breakpoint_condition_evaluation_mode (); | |
472 | ||
473 | return (mode == condition_evaluation_host); | |
474 | } | |
475 | ||
c906108c SS |
476 | /* Are we executing breakpoint commands? */ |
477 | static int executing_breakpoint_commands; | |
478 | ||
c02f5703 MS |
479 | /* Are overlay event breakpoints enabled? */ |
480 | static int overlay_events_enabled; | |
481 | ||
e09342b5 | 482 | /* See description in breakpoint.h. */ |
491144b5 | 483 | bool target_exact_watchpoints = false; |
e09342b5 | 484 | |
c906108c | 485 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 486 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 487 | current breakpoint. */ |
c906108c | 488 | |
5c44784c | 489 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 490 | |
5c44784c JM |
491 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
492 | for (B = breakpoint_chain; \ | |
493 | B ? (TMP=B->next, 1): 0; \ | |
494 | B = TMP) | |
c906108c | 495 | |
4a64f543 MS |
496 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
497 | not provided so update_global_location_list must not be called | |
498 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 499 | |
876fa593 | 500 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
501 | for (BP_TMP = bp_locations; \ |
502 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 503 | BP_TMP++) |
7cc221ef | 504 | |
b775012e LM |
505 | /* Iterates through locations with address ADDRESS for the currently selected |
506 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
507 | to where the loop should start from. | |
508 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
509 | appropriate location to start with. */ | |
510 | ||
511 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
512 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
513 | BP_LOCP_TMP = BP_LOCP_START; \ | |
514 | BP_LOCP_START \ | |
f5336ca5 | 515 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
516 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
517 | BP_LOCP_TMP++) | |
518 | ||
1042e4c0 SS |
519 | /* Iterator for tracepoints only. */ |
520 | ||
521 | #define ALL_TRACEPOINTS(B) \ | |
522 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 523 | if (is_tracepoint (B)) |
1042e4c0 | 524 | |
7cc221ef | 525 | /* Chains of all breakpoints defined. */ |
c906108c | 526 | |
81e6b8eb | 527 | static struct breakpoint *breakpoint_chain; |
c906108c | 528 | |
39ef2f62 | 529 | /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ |
876fa593 | 530 | |
f5336ca5 | 531 | static struct bp_location **bp_locations; |
876fa593 | 532 | |
f5336ca5 | 533 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 534 | |
f5336ca5 | 535 | static unsigned bp_locations_count; |
876fa593 | 536 | |
4a64f543 | 537 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 538 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 539 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 540 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 541 | an address you need to read. */ |
876fa593 | 542 | |
f5336ca5 | 543 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 544 | |
4a64f543 MS |
545 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
546 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
547 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
548 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 549 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 550 | |
f5336ca5 | 551 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 552 | |
4a64f543 | 553 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
554 | from the bp_locations array, but for which a hit may still be |
555 | reported by a target. */ | |
1123588c | 556 | static std::vector<bp_location *> moribund_locations; |
20874c92 | 557 | |
c906108c SS |
558 | /* Number of last breakpoint made. */ |
559 | ||
95a42b64 TT |
560 | static int breakpoint_count; |
561 | ||
86b17b60 PA |
562 | /* The value of `breakpoint_count' before the last command that |
563 | created breakpoints. If the last (break-like) command created more | |
564 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
565 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
566 | static int prev_breakpoint_count; | |
c906108c | 567 | |
1042e4c0 SS |
568 | /* Number of last tracepoint made. */ |
569 | ||
95a42b64 | 570 | static int tracepoint_count; |
1042e4c0 | 571 | |
6149aea9 PA |
572 | static struct cmd_list_element *breakpoint_set_cmdlist; |
573 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 574 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 575 | |
badd37ce SDJ |
576 | /* See declaration at breakpoint.h. */ |
577 | ||
578 | struct breakpoint * | |
579 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
580 | void *user_data) | |
581 | { | |
582 | struct breakpoint *b = NULL; | |
583 | ||
584 | ALL_BREAKPOINTS (b) | |
585 | { | |
586 | if (func (b, user_data) != 0) | |
587 | break; | |
588 | } | |
589 | ||
590 | return b; | |
591 | } | |
592 | ||
468d015d JJ |
593 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
594 | static int | |
595 | breakpoint_enabled (struct breakpoint *b) | |
596 | { | |
0d381245 | 597 | return (b->enable_state == bp_enabled); |
468d015d JJ |
598 | } |
599 | ||
c906108c SS |
600 | /* Set breakpoint count to NUM. */ |
601 | ||
95a42b64 | 602 | static void |
fba45db2 | 603 | set_breakpoint_count (int num) |
c906108c | 604 | { |
86b17b60 | 605 | prev_breakpoint_count = breakpoint_count; |
c906108c | 606 | breakpoint_count = num; |
4fa62494 | 607 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
608 | } |
609 | ||
86b17b60 PA |
610 | /* Used by `start_rbreak_breakpoints' below, to record the current |
611 | breakpoint count before "rbreak" creates any breakpoint. */ | |
612 | static int rbreak_start_breakpoint_count; | |
613 | ||
95a42b64 TT |
614 | /* Called at the start an "rbreak" command to record the first |
615 | breakpoint made. */ | |
86b17b60 | 616 | |
c80049d3 | 617 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 618 | { |
86b17b60 | 619 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
620 | } |
621 | ||
622 | /* Called at the end of an "rbreak" command to record the last | |
623 | breakpoint made. */ | |
86b17b60 | 624 | |
c80049d3 | 625 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 626 | { |
86b17b60 | 627 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
628 | } |
629 | ||
4a64f543 | 630 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
631 | |
632 | void | |
fba45db2 | 633 | clear_breakpoint_hit_counts (void) |
c906108c SS |
634 | { |
635 | struct breakpoint *b; | |
636 | ||
637 | ALL_BREAKPOINTS (b) | |
638 | b->hit_count = 0; | |
639 | } | |
640 | ||
c906108c | 641 | \f |
48cb2d85 VP |
642 | /* Return the breakpoint with the specified number, or NULL |
643 | if the number does not refer to an existing breakpoint. */ | |
644 | ||
645 | struct breakpoint * | |
646 | get_breakpoint (int num) | |
647 | { | |
648 | struct breakpoint *b; | |
649 | ||
650 | ALL_BREAKPOINTS (b) | |
651 | if (b->number == num) | |
652 | return b; | |
653 | ||
654 | return NULL; | |
655 | } | |
5c44784c | 656 | |
c906108c | 657 | \f |
adc36818 | 658 | |
b775012e LM |
659 | /* Mark locations as "conditions have changed" in case the target supports |
660 | evaluating conditions on its side. */ | |
661 | ||
662 | static void | |
663 | mark_breakpoint_modified (struct breakpoint *b) | |
664 | { | |
665 | struct bp_location *loc; | |
666 | ||
667 | /* This is only meaningful if the target is | |
668 | evaluating conditions and if the user has | |
669 | opted for condition evaluation on the target's | |
670 | side. */ | |
671 | if (gdb_evaluates_breakpoint_condition_p () | |
672 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
673 | return; | |
674 | ||
675 | if (!is_breakpoint (b)) | |
676 | return; | |
677 | ||
678 | for (loc = b->loc; loc; loc = loc->next) | |
679 | loc->condition_changed = condition_modified; | |
680 | } | |
681 | ||
682 | /* Mark location as "conditions have changed" in case the target supports | |
683 | evaluating conditions on its side. */ | |
684 | ||
685 | static void | |
686 | mark_breakpoint_location_modified (struct bp_location *loc) | |
687 | { | |
688 | /* This is only meaningful if the target is | |
689 | evaluating conditions and if the user has | |
690 | opted for condition evaluation on the target's | |
691 | side. */ | |
692 | if (gdb_evaluates_breakpoint_condition_p () | |
693 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
694 | ||
695 | return; | |
696 | ||
697 | if (!is_breakpoint (loc->owner)) | |
698 | return; | |
699 | ||
700 | loc->condition_changed = condition_modified; | |
701 | } | |
702 | ||
703 | /* Sets the condition-evaluation mode using the static global | |
704 | condition_evaluation_mode. */ | |
705 | ||
706 | static void | |
eb4c3f4a | 707 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
708 | struct cmd_list_element *c) |
709 | { | |
b775012e LM |
710 | const char *old_mode, *new_mode; |
711 | ||
712 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
713 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
714 | { | |
715 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
716 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
717 | "Using host evaluation mode instead.")); | |
718 | return; | |
719 | } | |
720 | ||
721 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
722 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
723 | ||
abf1152a JK |
724 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
725 | settings was "auto". */ | |
726 | condition_evaluation_mode = condition_evaluation_mode_1; | |
727 | ||
b775012e LM |
728 | /* Only update the mode if the user picked a different one. */ |
729 | if (new_mode != old_mode) | |
730 | { | |
731 | struct bp_location *loc, **loc_tmp; | |
732 | /* If the user switched to a different evaluation mode, we | |
733 | need to synch the changes with the target as follows: | |
734 | ||
735 | "host" -> "target": Send all (valid) conditions to the target. | |
736 | "target" -> "host": Remove all the conditions from the target. | |
737 | */ | |
738 | ||
b775012e LM |
739 | if (new_mode == condition_evaluation_target) |
740 | { | |
741 | /* Mark everything modified and synch conditions with the | |
742 | target. */ | |
743 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
744 | mark_breakpoint_location_modified (loc); | |
745 | } | |
746 | else | |
747 | { | |
748 | /* Manually mark non-duplicate locations to synch conditions | |
749 | with the target. We do this to remove all the conditions the | |
750 | target knows about. */ | |
751 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
752 | if (is_breakpoint (loc->owner) && loc->inserted) | |
753 | loc->needs_update = 1; | |
754 | } | |
755 | ||
756 | /* Do the update. */ | |
44702360 | 757 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
758 | } |
759 | ||
760 | return; | |
761 | } | |
762 | ||
763 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
764 | what "auto" is translating to. */ | |
765 | ||
766 | static void | |
767 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
768 | struct cmd_list_element *c, const char *value) | |
769 | { | |
770 | if (condition_evaluation_mode == condition_evaluation_auto) | |
771 | fprintf_filtered (file, | |
772 | _("Breakpoint condition evaluation " | |
773 | "mode is %s (currently %s).\n"), | |
774 | value, | |
775 | breakpoint_condition_evaluation_mode ()); | |
776 | else | |
777 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
778 | value); | |
779 | } | |
780 | ||
781 | /* A comparison function for bp_location AP and BP that is used by | |
782 | bsearch. This comparison function only cares about addresses, unlike | |
39ef2f62 | 783 | the more general bp_location_is_less_than function. */ |
b775012e LM |
784 | |
785 | static int | |
f5336ca5 | 786 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 787 | { |
9a3c8263 SM |
788 | const struct bp_location *a = *(const struct bp_location **) ap; |
789 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
790 | |
791 | if (a->address == b->address) | |
792 | return 0; | |
793 | else | |
794 | return ((a->address > b->address) - (a->address < b->address)); | |
795 | } | |
796 | ||
797 | /* Helper function to skip all bp_locations with addresses | |
798 | less than ADDRESS. It returns the first bp_location that | |
799 | is greater than or equal to ADDRESS. If none is found, just | |
800 | return NULL. */ | |
801 | ||
802 | static struct bp_location ** | |
803 | get_first_locp_gte_addr (CORE_ADDR address) | |
804 | { | |
805 | struct bp_location dummy_loc; | |
806 | struct bp_location *dummy_locp = &dummy_loc; | |
807 | struct bp_location **locp_found = NULL; | |
808 | ||
809 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
810 | dummy_loc.address = address; |
811 | ||
812 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 813 | locp_found = ((struct bp_location **) |
f5336ca5 | 814 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 815 | sizeof (struct bp_location **), |
f5336ca5 | 816 | bp_locations_compare_addrs)); |
b775012e LM |
817 | |
818 | /* Nothing was found, nothing left to do. */ | |
819 | if (locp_found == NULL) | |
820 | return NULL; | |
821 | ||
822 | /* We may have found a location that is at ADDRESS but is not the first in the | |
823 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 824 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
825 | && (*(locp_found - 1))->address == address) |
826 | locp_found--; | |
827 | ||
828 | return locp_found; | |
829 | } | |
830 | ||
b5fa468f TBA |
831 | /* Parse COND_STRING in the context of LOC and set as the condition |
832 | expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is | |
833 | the number of LOC within its owner. In case of parsing error, mark | |
834 | LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */ | |
835 | ||
836 | static void | |
837 | set_breakpoint_location_condition (const char *cond_string, bp_location *loc, | |
838 | int bp_num, int loc_num) | |
839 | { | |
840 | bool has_junk = false; | |
841 | try | |
842 | { | |
843 | expression_up new_exp = parse_exp_1 (&cond_string, loc->address, | |
844 | block_for_pc (loc->address), 0); | |
845 | if (*cond_string != 0) | |
846 | has_junk = true; | |
847 | else | |
848 | { | |
849 | loc->cond = std::move (new_exp); | |
850 | if (loc->disabled_by_cond && loc->enabled) | |
851 | printf_filtered (_("Breakpoint %d's condition is now valid at " | |
852 | "location %d, enabling.\n"), | |
853 | bp_num, loc_num); | |
854 | ||
855 | loc->disabled_by_cond = false; | |
856 | } | |
857 | } | |
858 | catch (const gdb_exception_error &e) | |
859 | { | |
860 | if (loc->enabled) | |
861 | { | |
862 | /* Warn if a user-enabled location is now becoming disabled-by-cond. | |
863 | BP_NUM is 0 if the breakpoint is being defined for the first | |
864 | time using the "break ... if ..." command, and non-zero if | |
865 | already defined. */ | |
866 | if (bp_num != 0) | |
867 | warning (_("failed to validate condition at location %d.%d, " | |
868 | "disabling:\n %s"), bp_num, loc_num, e.what ()); | |
869 | else | |
870 | warning (_("failed to validate condition at location %d, " | |
871 | "disabling:\n %s"), loc_num, e.what ()); | |
872 | } | |
873 | ||
874 | loc->disabled_by_cond = true; | |
875 | } | |
876 | ||
877 | if (has_junk) | |
878 | error (_("Garbage '%s' follows condition"), cond_string); | |
879 | } | |
880 | ||
adc36818 | 881 | void |
7a26bd4d | 882 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
733d554a | 883 | int from_tty, bool force) |
adc36818 | 884 | { |
4c55e970 | 885 | if (*exp == 0) |
3a5c3e22 | 886 | { |
4c55e970 TBA |
887 | xfree (b->cond_string); |
888 | b->cond_string = nullptr; | |
3a5c3e22 | 889 | |
4c55e970 | 890 | if (is_watchpoint (b)) |
78319c15 | 891 | static_cast<watchpoint *> (b)->cond_exp.reset (); |
4c55e970 TBA |
892 | else |
893 | { | |
b5fa468f | 894 | int loc_num = 1; |
78319c15 | 895 | for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) |
4c55e970 TBA |
896 | { |
897 | loc->cond.reset (); | |
b5fa468f TBA |
898 | if (loc->disabled_by_cond && loc->enabled) |
899 | printf_filtered (_("Breakpoint %d's condition is now valid at " | |
900 | "location %d, enabling.\n"), | |
901 | b->number, loc_num); | |
902 | loc->disabled_by_cond = false; | |
903 | loc_num++; | |
4c55e970 TBA |
904 | |
905 | /* No need to free the condition agent expression | |
906 | bytecode (if we have one). We will handle this | |
907 | when we go through update_global_location_list. */ | |
908 | } | |
909 | } | |
1e620590 | 910 | |
adc36818 PM |
911 | if (from_tty) |
912 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
913 | } | |
914 | else | |
915 | { | |
adc36818 PM |
916 | if (is_watchpoint (b)) |
917 | { | |
699bd4cf | 918 | innermost_block_tracker tracker; |
78319c15 | 919 | const char *arg = exp; |
4c55e970 | 920 | expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
78319c15 | 921 | if (*arg != 0) |
adc36818 | 922 | error (_("Junk at end of expression")); |
78319c15 | 923 | watchpoint *w = static_cast<watchpoint *> (b); |
4c55e970 | 924 | w->cond_exp = std::move (new_exp); |
699bd4cf | 925 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
926 | } |
927 | else | |
928 | { | |
4c55e970 TBA |
929 | /* Parse and set condition expressions. We make two passes. |
930 | In the first, we parse the condition string to see if it | |
b5fa468f TBA |
931 | is valid in at least one location. If so, the condition |
932 | would be accepted. So we go ahead and set the locations' | |
933 | conditions. In case no valid case is found, we throw | |
4c55e970 TBA |
934 | the error and the condition string will be rejected. |
935 | This two-pass approach is taken to avoid setting the | |
936 | state of locations in case of a reject. */ | |
78319c15 | 937 | for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) |
4c55e970 | 938 | { |
b5fa468f TBA |
939 | try |
940 | { | |
941 | const char *arg = exp; | |
942 | parse_exp_1 (&arg, loc->address, | |
943 | block_for_pc (loc->address), 0); | |
944 | if (*arg != 0) | |
945 | error (_("Junk at end of expression")); | |
946 | break; | |
947 | } | |
948 | catch (const gdb_exception_error &e) | |
949 | { | |
950 | /* Condition string is invalid. If this happens to | |
733d554a TBA |
951 | be the last loc, abandon (if not forced) or continue |
952 | (if forced). */ | |
953 | if (loc->next == nullptr && !force) | |
b5fa468f TBA |
954 | throw; |
955 | } | |
4c55e970 TBA |
956 | } |
957 | ||
b5fa468f | 958 | /* If we reach here, the condition is valid at some locations. */ |
dda83cd7 SM |
959 | int loc_num = 1; |
960 | for (bp_location *loc = b->loc; loc != nullptr; | |
961 | loc = loc->next, loc_num++) | |
962 | set_breakpoint_location_condition (exp, loc, b->number, loc_num); | |
adc36818 | 963 | } |
1e620590 TBA |
964 | |
965 | /* We know that the new condition parsed successfully. The | |
966 | condition string of the breakpoint can be safely updated. */ | |
967 | xfree (b->cond_string); | |
968 | b->cond_string = xstrdup (exp); | |
969 | b->condition_not_parsed = 0; | |
adc36818 | 970 | } |
b775012e LM |
971 | mark_breakpoint_modified (b); |
972 | ||
76727919 | 973 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
974 | } |
975 | ||
b1d4d8d1 TBA |
976 | /* The options for the "condition" command. */ |
977 | ||
978 | struct condition_command_opts | |
979 | { | |
980 | /* For "-force". */ | |
981 | bool force_condition = false; | |
982 | }; | |
983 | ||
984 | static const gdb::option::option_def condition_command_option_defs[] = { | |
985 | ||
986 | gdb::option::flag_option_def<condition_command_opts> { | |
987 | "force", | |
988 | [] (condition_command_opts *opts) { return &opts->force_condition; }, | |
989 | N_("Set the condition even if it is invalid for all current locations."), | |
990 | }, | |
991 | ||
992 | }; | |
993 | ||
994 | /* Create an option_def_group for the "condition" options, with | |
995 | CC_OPTS as context. */ | |
996 | ||
997 | static inline gdb::option::option_def_group | |
998 | make_condition_command_options_def_group (condition_command_opts *cc_opts) | |
999 | { | |
1000 | return {{condition_command_option_defs}, cc_opts}; | |
1001 | } | |
1002 | ||
d55637df TT |
1003 | /* Completion for the "condition" command. */ |
1004 | ||
eb3ff9a5 | 1005 | static void |
6f937416 | 1006 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 1007 | completion_tracker &tracker, |
b1d4d8d1 | 1008 | const char *text, const char * /*word*/) |
d55637df | 1009 | { |
b1d4d8d1 TBA |
1010 | bool has_no_arguments = (*text == '\0'); |
1011 | condition_command_opts cc_opts; | |
1012 | const auto group = make_condition_command_options_def_group (&cc_opts); | |
1013 | if (gdb::option::complete_options | |
1014 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group)) | |
1015 | return; | |
d55637df | 1016 | |
f1735a53 | 1017 | text = skip_spaces (text); |
b1d4d8d1 | 1018 | const char *space = skip_to_space (text); |
d55637df TT |
1019 | if (*space == '\0') |
1020 | { | |
1021 | int len; | |
1022 | struct breakpoint *b; | |
d55637df TT |
1023 | |
1024 | if (text[0] == '$') | |
1025 | { | |
b1d4d8d1 | 1026 | tracker.advance_custom_word_point_by (1); |
d55637df | 1027 | /* We don't support completion of history indices. */ |
eb3ff9a5 PA |
1028 | if (!isdigit (text[1])) |
1029 | complete_internalvar (tracker, &text[1]); | |
1030 | return; | |
d55637df TT |
1031 | } |
1032 | ||
b1d4d8d1 TBA |
1033 | /* Suggest the "-force" flag if no arguments are given. If |
1034 | arguments were passed, they either already include the flag, | |
1035 | or we are beyond the point of suggesting it because it's | |
1036 | positionally the first argument. */ | |
1037 | if (has_no_arguments) | |
1038 | gdb::option::complete_on_all_options (tracker, group); | |
1039 | ||
d55637df TT |
1040 | /* We're completing the breakpoint number. */ |
1041 | len = strlen (text); | |
1042 | ||
1043 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1044 | { |
1045 | char number[50]; | |
1046 | ||
1047 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1048 | ||
1049 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 1050 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 1051 | } |
d55637df | 1052 | |
eb3ff9a5 | 1053 | return; |
d55637df TT |
1054 | } |
1055 | ||
b1d4d8d1 TBA |
1056 | /* We're completing the expression part. Skip the breakpoint num. */ |
1057 | const char *exp_start = skip_spaces (space); | |
1058 | tracker.advance_custom_word_point_by (exp_start - text); | |
1059 | text = exp_start; | |
1060 | const char *word = advance_to_expression_complete_word_point (tracker, text); | |
eb3ff9a5 | 1061 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
1062 | } |
1063 | ||
c906108c SS |
1064 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1065 | ||
1066 | static void | |
0b39b52e | 1067 | condition_command (const char *arg, int from_tty) |
c906108c | 1068 | { |
52f0bd74 | 1069 | struct breakpoint *b; |
0b39b52e | 1070 | const char *p; |
52f0bd74 | 1071 | int bnum; |
c906108c SS |
1072 | |
1073 | if (arg == 0) | |
e2e0b3e5 | 1074 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1075 | |
1076 | p = arg; | |
733d554a TBA |
1077 | |
1078 | /* Check if the "-force" flag was passed. */ | |
b1d4d8d1 TBA |
1079 | condition_command_opts cc_opts; |
1080 | const auto group = make_condition_command_options_def_group (&cc_opts); | |
1081 | gdb::option::process_options | |
1082 | (&p, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group); | |
733d554a | 1083 | |
c906108c | 1084 | bnum = get_number (&p); |
5c44784c | 1085 | if (bnum == 0) |
8a3fe4f8 | 1086 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1087 | |
1088 | ALL_BREAKPOINTS (b) | |
1089 | if (b->number == bnum) | |
2f069f6f | 1090 | { |
6dddc817 DE |
1091 | /* Check if this breakpoint has a "stop" method implemented in an |
1092 | extension language. This method and conditions entered into GDB | |
1093 | from the CLI are mutually exclusive. */ | |
1094 | const struct extension_language_defn *extlang | |
1095 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1096 | ||
1097 | if (extlang != NULL) | |
1098 | { | |
1099 | error (_("Only one stop condition allowed. There is currently" | |
1100 | " a %s stop condition defined for this breakpoint."), | |
1101 | ext_lang_capitalized_name (extlang)); | |
1102 | } | |
b1d4d8d1 | 1103 | set_breakpoint_condition (b, p, from_tty, cc_opts.force_condition); |
b775012e LM |
1104 | |
1105 | if (is_breakpoint (b)) | |
44702360 | 1106 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1107 | |
2f069f6f JB |
1108 | return; |
1109 | } | |
c906108c | 1110 | |
8a3fe4f8 | 1111 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1112 | } |
1113 | ||
a7bdde9e VP |
1114 | /* Check that COMMAND do not contain commands that are suitable |
1115 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1116 | Throw if any such commands is found. */ |
1117 | ||
a7bdde9e VP |
1118 | static void |
1119 | check_no_tracepoint_commands (struct command_line *commands) | |
1120 | { | |
1121 | struct command_line *c; | |
cc59ec59 | 1122 | |
a7bdde9e VP |
1123 | for (c = commands; c; c = c->next) |
1124 | { | |
a7bdde9e | 1125 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
1126 | error (_("The 'while-stepping' command can " |
1127 | "only be used for tracepoints")); | |
a7bdde9e | 1128 | |
12973681 TT |
1129 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1130 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1131 | |
1132 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1133 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1134 | command directly. */ |
1135 | if (strstr (c->line, "collect ") == c->line) | |
1136 | error (_("The 'collect' command can only be used for tracepoints")); | |
1137 | ||
51661e93 VP |
1138 | if (strstr (c->line, "teval ") == c->line) |
1139 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1140 | } |
1141 | } | |
1142 | ||
c1fc2657 | 1143 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1144 | { |
c1fc2657 | 1145 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1146 | }; |
1147 | ||
d77f58be SS |
1148 | /* Encapsulate tests for different types of tracepoints. */ |
1149 | ||
3b0871f4 SM |
1150 | static bool |
1151 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1152 | { |
1153 | return (type == bp_tracepoint | |
1154 | || type == bp_fast_tracepoint | |
1155 | || type == bp_static_tracepoint); | |
1156 | } | |
1157 | ||
3b0871f4 SM |
1158 | static bool |
1159 | is_longjmp_type (bptype type) | |
1160 | { | |
1161 | return type == bp_longjmp || type == bp_exception; | |
1162 | } | |
1163 | ||
f2478a7e SM |
1164 | /* See breakpoint.h. */ |
1165 | ||
1166 | bool | |
d77f58be | 1167 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1168 | { |
d9b3f62e | 1169 | return is_tracepoint_type (b->type); |
a7bdde9e | 1170 | } |
d9b3f62e | 1171 | |
a5e364af SM |
1172 | /* Factory function to create an appropriate instance of breakpoint given |
1173 | TYPE. */ | |
1174 | ||
1175 | static std::unique_ptr<breakpoint> | |
1176 | new_breakpoint_from_type (bptype type) | |
1177 | { | |
1178 | breakpoint *b; | |
1179 | ||
1180 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1181 | b = new tracepoint (); |
3b0871f4 | 1182 | else if (is_longjmp_type (type)) |
c1fc2657 | 1183 | b = new longjmp_breakpoint (); |
a5e364af SM |
1184 | else |
1185 | b = new breakpoint (); | |
1186 | ||
1187 | return std::unique_ptr<breakpoint> (b); | |
1188 | } | |
1189 | ||
e5dd4106 | 1190 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1191 | breakpoint. This function will throw an exception if a problem is |
1192 | found. */ | |
48cb2d85 | 1193 | |
95a42b64 TT |
1194 | static void |
1195 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1196 | struct command_line *commands) | |
48cb2d85 | 1197 | { |
d77f58be | 1198 | if (is_tracepoint (b)) |
a7bdde9e | 1199 | { |
c9a6ce02 | 1200 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1201 | struct command_line *c; |
1202 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1203 | |
1204 | /* Reset the while-stepping step count. The previous commands | |
dda83cd7 SM |
1205 | might have included a while-stepping action, while the new |
1206 | ones might not. */ | |
c9a6ce02 PA |
1207 | t->step_count = 0; |
1208 | ||
1209 | /* We need to verify that each top-level element of commands is | |
1210 | valid for tracepoints, that there's at most one | |
1211 | while-stepping element, and that the while-stepping's body | |
1212 | has valid tracing commands excluding nested while-stepping. | |
1213 | We also need to validate the tracepoint action line in the | |
1214 | context of the tracepoint --- validate_actionline actually | |
1215 | has side effects, like setting the tracepoint's | |
1216 | while-stepping STEP_COUNT, in addition to checking if the | |
1217 | collect/teval actions parse and make sense in the | |
1218 | tracepoint's context. */ | |
a7bdde9e VP |
1219 | for (c = commands; c; c = c->next) |
1220 | { | |
a7bdde9e VP |
1221 | if (c->control_type == while_stepping_control) |
1222 | { | |
1223 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1224 | error (_("The 'while-stepping' command " |
1225 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1226 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1227 | error (_("The 'while-stepping' command " |
1228 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1229 | |
1230 | if (while_stepping) | |
3e43a32a MS |
1231 | error (_("The 'while-stepping' command " |
1232 | "can be used only once")); | |
a7bdde9e VP |
1233 | else |
1234 | while_stepping = c; | |
1235 | } | |
c9a6ce02 PA |
1236 | |
1237 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1238 | } |
1239 | if (while_stepping) | |
1240 | { | |
1241 | struct command_line *c2; | |
1242 | ||
12973681 TT |
1243 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1244 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1245 | for (; c2; c2 = c2->next) |
1246 | { | |
a7bdde9e VP |
1247 | if (c2->control_type == while_stepping_control) |
1248 | error (_("The 'while-stepping' command cannot be nested")); | |
1249 | } | |
1250 | } | |
1251 | } | |
1252 | else | |
1253 | { | |
1254 | check_no_tracepoint_commands (commands); | |
1255 | } | |
95a42b64 TT |
1256 | } |
1257 | ||
0fb4aa4b PA |
1258 | /* Return a vector of all the static tracepoints set at ADDR. The |
1259 | caller is responsible for releasing the vector. */ | |
1260 | ||
f51e0e20 | 1261 | std::vector<breakpoint *> |
0fb4aa4b PA |
1262 | static_tracepoints_here (CORE_ADDR addr) |
1263 | { | |
1264 | struct breakpoint *b; | |
f51e0e20 | 1265 | std::vector<breakpoint *> found; |
0fb4aa4b PA |
1266 | struct bp_location *loc; |
1267 | ||
1268 | ALL_BREAKPOINTS (b) | |
1269 | if (b->type == bp_static_tracepoint) | |
1270 | { | |
1271 | for (loc = b->loc; loc; loc = loc->next) | |
1272 | if (loc->address == addr) | |
f51e0e20 | 1273 | found.push_back (b); |
0fb4aa4b PA |
1274 | } |
1275 | ||
1276 | return found; | |
1277 | } | |
1278 | ||
95a42b64 | 1279 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1280 | validate that only allowed commands are included. */ |
95a42b64 TT |
1281 | |
1282 | void | |
4a64f543 | 1283 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1284 | counted_command_line &&commands) |
95a42b64 | 1285 | { |
93921405 | 1286 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1287 | |
d1b0a7bf | 1288 | b->commands = std::move (commands); |
76727919 | 1289 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1290 | } |
1291 | ||
45a43567 TT |
1292 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1293 | is not the same as the "silent" that may appear in the breakpoint's | |
1294 | commands. */ | |
1295 | ||
1296 | void | |
1297 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1298 | { | |
1299 | int old_silent = b->silent; | |
1300 | ||
1301 | b->silent = silent; | |
1302 | if (old_silent != silent) | |
76727919 | 1303 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1304 | } |
1305 | ||
1306 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1307 | breakpoint work for any thread. */ | |
1308 | ||
1309 | void | |
1310 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1311 | { | |
1312 | int old_thread = b->thread; | |
1313 | ||
1314 | b->thread = thread; | |
1315 | if (old_thread != thread) | |
76727919 | 1316 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1317 | } |
1318 | ||
1319 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1320 | breakpoint work for any task. */ | |
1321 | ||
1322 | void | |
1323 | breakpoint_set_task (struct breakpoint *b, int task) | |
1324 | { | |
1325 | int old_task = b->task; | |
1326 | ||
1327 | b->task = task; | |
1328 | if (old_task != task) | |
76727919 | 1329 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1330 | } |
1331 | ||
95a42b64 | 1332 | static void |
896b6bda | 1333 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1334 | struct command_line *control) |
95a42b64 | 1335 | { |
d1b0a7bf | 1336 | counted_command_line cmd; |
999700cd PW |
1337 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1338 | NULL after the call to read_command_lines if the user provides an empty | |
1339 | list of command by just typing "end". */ | |
1340 | bool cmd_read = false; | |
95a42b64 | 1341 | |
896b6bda PA |
1342 | std::string new_arg; |
1343 | ||
95a42b64 TT |
1344 | if (arg == NULL || !*arg) |
1345 | { | |
da1df1db | 1346 | /* Argument not explicitly given. Synthesize it. */ |
86b17b60 | 1347 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1348 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1349 | breakpoint_count); | |
95a42b64 | 1350 | else if (breakpoint_count > 0) |
896b6bda | 1351 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b | 1352 | } |
da1df1db TBA |
1353 | else |
1354 | { | |
1355 | /* Create a copy of ARG. This is needed because the "commands" | |
1356 | command may be coming from a script. In that case, the read | |
1357 | line buffer is going to be overwritten in the lambda of | |
1358 | 'map_breakpoint_numbers' below when reading the next line | |
1359 | before we are are done parsing the breakpoint numbers. */ | |
1360 | new_arg = arg; | |
1361 | } | |
1362 | arg = new_arg.c_str (); | |
48649e1b TT |
1363 | |
1364 | map_breakpoint_numbers | |
1365 | (arg, [&] (breakpoint *b) | |
1366 | { | |
999700cd | 1367 | if (!cmd_read) |
48649e1b | 1368 | { |
999700cd | 1369 | gdb_assert (cmd == NULL); |
48649e1b | 1370 | if (control != NULL) |
12973681 | 1371 | cmd = control->body_list_0; |
48649e1b TT |
1372 | else |
1373 | { | |
81b1e71c TT |
1374 | std::string str |
1375 | = string_printf (_("Type commands for breakpoint(s) " | |
1376 | "%s, one per line."), | |
1377 | arg); | |
48649e1b | 1378 | |
60b3cef2 TT |
1379 | auto do_validate = [=] (const char *line) |
1380 | { | |
1381 | validate_actionline (line, b); | |
1382 | }; | |
1383 | gdb::function_view<void (const char *)> validator; | |
1384 | if (is_tracepoint (b)) | |
1385 | validator = do_validate; | |
1386 | ||
1387 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1388 | } |
999700cd | 1389 | cmd_read = true; |
48649e1b TT |
1390 | } |
1391 | ||
1392 | /* If a breakpoint was on the list more than once, we don't need to | |
1393 | do anything. */ | |
1394 | if (b->commands != cmd) | |
1395 | { | |
d1b0a7bf | 1396 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1397 | b->commands = cmd; |
76727919 | 1398 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1399 | } |
1400 | }); | |
95a42b64 TT |
1401 | } |
1402 | ||
1403 | static void | |
0b39b52e | 1404 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1405 | { |
1406 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1407 | } |
40c03ae8 EZ |
1408 | |
1409 | /* Like commands_command, but instead of reading the commands from | |
1410 | input stream, takes them from an already parsed command structure. | |
1411 | ||
1412 | This is used by cli-script.c to DTRT with breakpoint commands | |
1413 | that are part of if and while bodies. */ | |
1414 | enum command_control_type | |
896b6bda | 1415 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1416 | { |
95a42b64 TT |
1417 | commands_command_1 (arg, 0, cmd); |
1418 | return simple_control; | |
40c03ae8 | 1419 | } |
876fa593 JK |
1420 | |
1421 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1422 | ||
1423 | static int | |
1424 | bp_location_has_shadow (struct bp_location *bl) | |
1425 | { | |
1426 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1427 | return 0; | |
1428 | if (!bl->inserted) | |
1429 | return 0; | |
1430 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1431 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1432 | return 0; |
1433 | return 1; | |
1434 | } | |
1435 | ||
9d497a19 PA |
1436 | /* Update BUF, which is LEN bytes read from the target address |
1437 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1438 | contents. | |
1439 | ||
1440 | If READBUF is not NULL, this buffer must not overlap with the of | |
1441 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1442 | failed assertion internal error will be raised. */ | |
1443 | ||
1444 | static void | |
1445 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1446 | const gdb_byte *writebuf_org, | |
1447 | ULONGEST memaddr, LONGEST len, | |
1448 | struct bp_target_info *target_info, | |
1449 | struct gdbarch *gdbarch) | |
1450 | { | |
1451 | /* Now do full processing of the found relevant range of elements. */ | |
1452 | CORE_ADDR bp_addr = 0; | |
1453 | int bp_size = 0; | |
1454 | int bptoffset = 0; | |
1455 | ||
1456 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1457 | current_program_space->aspace, 0)) | |
1458 | { | |
1459 | /* The breakpoint is inserted in a different address space. */ | |
1460 | return; | |
1461 | } | |
1462 | ||
1463 | /* Addresses and length of the part of the breakpoint that | |
1464 | we need to copy. */ | |
1465 | bp_addr = target_info->placed_address; | |
1466 | bp_size = target_info->shadow_len; | |
1467 | ||
1468 | if (bp_addr + bp_size <= memaddr) | |
1469 | { | |
1470 | /* The breakpoint is entirely before the chunk of memory we are | |
1471 | reading. */ | |
1472 | return; | |
1473 | } | |
1474 | ||
1475 | if (bp_addr >= memaddr + len) | |
1476 | { | |
1477 | /* The breakpoint is entirely after the chunk of memory we are | |
1478 | reading. */ | |
1479 | return; | |
1480 | } | |
1481 | ||
1482 | /* Offset within shadow_contents. */ | |
1483 | if (bp_addr < memaddr) | |
1484 | { | |
1485 | /* Only copy the second part of the breakpoint. */ | |
1486 | bp_size -= memaddr - bp_addr; | |
1487 | bptoffset = memaddr - bp_addr; | |
1488 | bp_addr = memaddr; | |
1489 | } | |
1490 | ||
1491 | if (bp_addr + bp_size > memaddr + len) | |
1492 | { | |
1493 | /* Only copy the first part of the breakpoint. */ | |
1494 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1495 | } | |
1496 | ||
1497 | if (readbuf != NULL) | |
1498 | { | |
1499 | /* Verify that the readbuf buffer does not overlap with the | |
1500 | shadow_contents buffer. */ | |
1501 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1502 | || readbuf >= (target_info->shadow_contents | |
1503 | + target_info->shadow_len)); | |
1504 | ||
1505 | /* Update the read buffer with this inserted breakpoint's | |
1506 | shadow. */ | |
1507 | memcpy (readbuf + bp_addr - memaddr, | |
1508 | target_info->shadow_contents + bptoffset, bp_size); | |
1509 | } | |
1510 | else | |
1511 | { | |
1512 | const unsigned char *bp; | |
0d5ed153 MR |
1513 | CORE_ADDR addr = target_info->reqstd_address; |
1514 | int placed_size; | |
9d497a19 PA |
1515 | |
1516 | /* Update the shadow with what we want to write to memory. */ | |
1517 | memcpy (target_info->shadow_contents + bptoffset, | |
1518 | writebuf_org + bp_addr - memaddr, bp_size); | |
1519 | ||
1520 | /* Determine appropriate breakpoint contents and size for this | |
1521 | address. */ | |
0d5ed153 | 1522 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1523 | |
1524 | /* Update the final write buffer with this inserted | |
1525 | breakpoint's INSN. */ | |
1526 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1527 | } | |
1528 | } | |
1529 | ||
8defab1a | 1530 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1531 | by replacing any memory breakpoints with their shadowed contents. |
1532 | ||
35c63cd8 JB |
1533 | If READBUF is not NULL, this buffer must not overlap with any of |
1534 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1535 | a failed assertion internal error will be raised. | |
1536 | ||
876fa593 | 1537 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1538 | bl->address - bp_locations_placed_address_before_address_max |
1539 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1540 | The range we were requested to resolve shadows for is: |
1541 | memaddr ... memaddr + len | |
1542 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1543 | memaddr + len <= (bl->address |
f5336ca5 | 1544 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1545 | and: |
f5336ca5 | 1546 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1547 | |
8defab1a | 1548 | void |
f0ba3972 PA |
1549 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1550 | const gdb_byte *writebuf_org, | |
1551 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1552 | { |
4a64f543 MS |
1553 | /* Left boundary, right boundary and median element of our binary |
1554 | search. */ | |
876fa593 JK |
1555 | unsigned bc_l, bc_r, bc; |
1556 | ||
4a64f543 MS |
1557 | /* Find BC_L which is a leftmost element which may affect BUF |
1558 | content. It is safe to report lower value but a failure to | |
1559 | report higher one. */ | |
876fa593 JK |
1560 | |
1561 | bc_l = 0; | |
f5336ca5 | 1562 | bc_r = bp_locations_count; |
876fa593 JK |
1563 | while (bc_l + 1 < bc_r) |
1564 | { | |
35df4500 | 1565 | struct bp_location *bl; |
876fa593 JK |
1566 | |
1567 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1568 | bl = bp_locations[bc]; |
876fa593 | 1569 | |
4a64f543 MS |
1570 | /* Check first BL->ADDRESS will not overflow due to the added |
1571 | constant. Then advance the left boundary only if we are sure | |
1572 | the BC element can in no way affect the BUF content (MEMADDR | |
1573 | to MEMADDR + LEN range). | |
876fa593 | 1574 | |
f5336ca5 | 1575 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1576 | offset so that we cannot miss a breakpoint with its shadow |
1577 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1578 | |
f5336ca5 | 1579 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1580 | >= bl->address) |
f5336ca5 | 1581 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1582 | <= memaddr)) |
876fa593 JK |
1583 | bc_l = bc; |
1584 | else | |
1585 | bc_r = bc; | |
1586 | } | |
1587 | ||
128070bb PA |
1588 | /* Due to the binary search above, we need to make sure we pick the |
1589 | first location that's at BC_L's address. E.g., if there are | |
1590 | multiple locations at the same address, BC_L may end up pointing | |
1591 | at a duplicate location, and miss the "master"/"inserted" | |
1592 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1593 | B: | |
1594 | ||
1595 | L1@A, L2@A, L3@B, ... | |
1596 | ||
1597 | BC_L could end up pointing at location L2, while the "master" | |
1598 | location could be L1. Since the `loc->inserted' flag is only set | |
1599 | on "master" locations, we'd forget to restore the shadow of L1 | |
1600 | and L2. */ | |
1601 | while (bc_l > 0 | |
f5336ca5 | 1602 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1603 | bc_l--; |
1604 | ||
876fa593 JK |
1605 | /* Now do full processing of the found relevant range of elements. */ |
1606 | ||
f5336ca5 | 1607 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1608 | { |
f5336ca5 | 1609 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1610 | |
35df4500 TJB |
1611 | /* bp_location array has BL->OWNER always non-NULL. */ |
1612 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1613 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1614 | bl->owner->number); |
ffce0d52 | 1615 | |
e5dd4106 | 1616 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1617 | content. */ |
1618 | ||
f5336ca5 PA |
1619 | if (bl->address >= bp_locations_placed_address_before_address_max |
1620 | && memaddr + len <= (bl->address | |
1621 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1622 | break; |
1623 | ||
35df4500 | 1624 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1625 | continue; |
6c95b8df | 1626 | |
9d497a19 PA |
1627 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1628 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1629 | } | |
c906108c | 1630 | } |
9d497a19 | 1631 | |
f2478a7e | 1632 | /* See breakpoint.h. */ |
b775012e | 1633 | |
f2478a7e | 1634 | bool |
b775012e LM |
1635 | is_breakpoint (const struct breakpoint *bpt) |
1636 | { | |
1637 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1638 | || bpt->type == bp_hardware_breakpoint |
1639 | || bpt->type == bp_dprintf); | |
b775012e LM |
1640 | } |
1641 | ||
60e1c644 PA |
1642 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1643 | ||
f2478a7e | 1644 | static bool |
d77f58be | 1645 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1646 | { |
1647 | return (bpt->type == bp_hardware_watchpoint | |
1648 | || bpt->type == bp_read_watchpoint | |
1649 | || bpt->type == bp_access_watchpoint); | |
1650 | } | |
7270d8f2 | 1651 | |
f2478a7e | 1652 | /* See breakpoint.h. */ |
60e1c644 | 1653 | |
f2478a7e | 1654 | bool |
d77f58be | 1655 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1656 | { |
1657 | return (is_hardware_watchpoint (bpt) | |
1658 | || bpt->type == bp_watchpoint); | |
1659 | } | |
1660 | ||
3a5c3e22 PA |
1661 | /* Returns true if the current thread and its running state are safe |
1662 | to evaluate or update watchpoint B. Watchpoints on local | |
1663 | expressions need to be evaluated in the context of the thread that | |
1664 | was current when the watchpoint was created, and, that thread needs | |
1665 | to be stopped to be able to select the correct frame context. | |
1666 | Watchpoints on global expressions can be evaluated on any thread, | |
1667 | and in any state. It is presently left to the target allowing | |
1668 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1669 | |
1670 | static int | |
3a5c3e22 | 1671 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1672 | { |
c1fc2657 | 1673 | return (b->pspace == current_program_space |
d7e15655 TT |
1674 | && (b->watchpoint_thread == null_ptid |
1675 | || (inferior_ptid == b->watchpoint_thread | |
00431a78 | 1676 | && !inferior_thread ()->executing))); |
f6bc2008 PA |
1677 | } |
1678 | ||
d0fb5eae JK |
1679 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1680 | associated bp_watchpoint_scope breakpoint. */ | |
1681 | ||
1682 | static void | |
3a5c3e22 | 1683 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1684 | { |
c1fc2657 | 1685 | if (w->related_breakpoint != w) |
d0fb5eae | 1686 | { |
c1fc2657 SM |
1687 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1688 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1689 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1690 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1691 | w->related_breakpoint = w; | |
d0fb5eae | 1692 | } |
c1fc2657 | 1693 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1694 | } |
1695 | ||
bb9d5f81 PP |
1696 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1697 | watchpoint W. */ | |
1698 | ||
1699 | static struct value * | |
1700 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1701 | { | |
1702 | struct value *bit_val; | |
1703 | ||
1704 | if (val == NULL) | |
1705 | return NULL; | |
1706 | ||
1707 | bit_val = allocate_value (value_type (val)); | |
1708 | ||
1709 | unpack_value_bitfield (bit_val, | |
1710 | w->val_bitpos, | |
1711 | w->val_bitsize, | |
1712 | value_contents_for_printing (val), | |
1713 | value_offset (val), | |
1714 | val); | |
1715 | ||
1716 | return bit_val; | |
1717 | } | |
1718 | ||
c6d81124 PA |
1719 | /* Allocate a dummy location and add it to B, which must be a software |
1720 | watchpoint. This is required because even if a software watchpoint | |
1721 | is not watching any memory, bpstat_stop_status requires a location | |
1722 | to be able to report stops. */ | |
1723 | ||
1724 | static void | |
1725 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1726 | struct program_space *pspace) | |
1727 | { | |
1728 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1729 | ||
1730 | b->loc = allocate_bp_location (b); | |
1731 | b->loc->pspace = pspace; | |
1732 | b->loc->address = -1; | |
1733 | b->loc->length = -1; | |
1734 | } | |
1735 | ||
1736 | /* Returns true if B is a software watchpoint that is not watching any | |
1737 | memory (e.g., "watch $pc"). */ | |
1738 | ||
f2478a7e | 1739 | static bool |
c6d81124 PA |
1740 | is_no_memory_software_watchpoint (struct breakpoint *b) |
1741 | { | |
1742 | return (b->type == bp_watchpoint | |
1743 | && b->loc != NULL | |
1744 | && b->loc->next == NULL | |
1745 | && b->loc->address == -1 | |
1746 | && b->loc->length == -1); | |
1747 | } | |
1748 | ||
567e1b4e JB |
1749 | /* Assuming that B is a watchpoint: |
1750 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1751 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1752 | - Evaluate the condition if there is one, and store the result |
1753 | in b->loc->cond. | |
a5606eee VP |
1754 | - Update the list of values that must be watched in B->loc. |
1755 | ||
4a64f543 MS |
1756 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1757 | nothing. If this is local watchpoint that is out of scope, delete | |
1758 | it. | |
1759 | ||
1760 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1761 | removed + inserted on each stop here. Normal breakpoints must | |
1762 | never be removed because they might be missed by a running thread | |
1763 | when debugging in non-stop mode. On the other hand, hardware | |
1764 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1765 | to each LWP since they are stored in each LWP's hardware debug | |
1766 | registers. Therefore, such LWP must be stopped first in order to | |
1767 | be able to modify its hardware watchpoints. | |
1768 | ||
1769 | Hardware watchpoints must be reset exactly once after being | |
1770 | presented to the user. It cannot be done sooner, because it would | |
1771 | reset the data used to present the watchpoint hit to the user. And | |
1772 | it must not be done later because it could display the same single | |
1773 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1774 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1775 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1776 | not user-visible - its hit is suppressed if the memory content has | |
1777 | not changed. | |
1778 | ||
1779 | The following constraints influence the location where we can reset | |
1780 | hardware watchpoints: | |
1781 | ||
1782 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1783 | called several times when GDB stops. | |
1784 | ||
1785 | [linux] | |
1786 | * Multiple hardware watchpoints can be hit at the same time, | |
1787 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1788 | hit at a time as the reason for stopping, and all the other hits | |
1789 | are presented later, one after the other, each time the user | |
1790 | requests the execution to be resumed. Execution is not resumed | |
1791 | for the threads still having pending hit event stored in | |
1792 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1793 | the inferior on the first stop the thread hit event is kept being | |
1794 | reported from its cached value by linux_nat_stopped_data_address | |
1795 | until the real thread resume happens after the watchpoint gets | |
1796 | presented and thus its LWP_INFO->STATUS gets reset. | |
1797 | ||
1798 | Therefore the hardware watchpoint hit can get safely reset on the | |
1799 | watchpoint removal from inferior. */ | |
a79d3c27 | 1800 | |
b40ce68a | 1801 | static void |
3a5c3e22 | 1802 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1803 | { |
a5606eee | 1804 | int within_current_scope; |
a5606eee | 1805 | struct frame_id saved_frame_id; |
66076460 | 1806 | int frame_saved; |
a5606eee | 1807 | |
f6bc2008 PA |
1808 | /* If this is a local watchpoint, we only want to check if the |
1809 | watchpoint frame is in scope if the current thread is the thread | |
1810 | that was used to create the watchpoint. */ | |
1811 | if (!watchpoint_in_thread_scope (b)) | |
1812 | return; | |
1813 | ||
c1fc2657 | 1814 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1815 | return; |
1816 | ||
66076460 | 1817 | frame_saved = 0; |
a5606eee VP |
1818 | |
1819 | /* Determine if the watchpoint is within scope. */ | |
1820 | if (b->exp_valid_block == NULL) | |
1821 | within_current_scope = 1; | |
1822 | else | |
1823 | { | |
b5db5dfc UW |
1824 | struct frame_info *fi = get_current_frame (); |
1825 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1826 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1827 | ||
c9cf6e20 MG |
1828 | /* If we're at a point where the stack has been destroyed |
1829 | (e.g. in a function epilogue), unwinding may not work | |
1830 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1831 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1832 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1833 | return; |
66076460 DJ |
1834 | |
1835 | /* Save the current frame's ID so we can restore it after | |
dda83cd7 | 1836 | evaluating the watchpoint expression on its own frame. */ |
66076460 | 1837 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
dda83cd7 SM |
1838 | took a frame parameter, so that we didn't have to change the |
1839 | selected frame. */ | |
66076460 DJ |
1840 | frame_saved = 1; |
1841 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1842 | ||
a5606eee VP |
1843 | fi = frame_find_by_id (b->watchpoint_frame); |
1844 | within_current_scope = (fi != NULL); | |
1845 | if (within_current_scope) | |
1846 | select_frame (fi); | |
1847 | } | |
1848 | ||
b5db5dfc UW |
1849 | /* We don't free locations. They are stored in the bp_location array |
1850 | and update_global_location_list will eventually delete them and | |
1851 | remove breakpoints if needed. */ | |
c1fc2657 | 1852 | b->loc = NULL; |
b5db5dfc | 1853 | |
a5606eee VP |
1854 | if (within_current_scope && reparse) |
1855 | { | |
bbc13ae3 | 1856 | const char *s; |
d63d0675 | 1857 | |
4d01a485 | 1858 | b->exp.reset (); |
d63d0675 | 1859 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1860 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1861 | /* If the meaning of expression itself changed, the old value is |
1862 | no longer relevant. We don't want to report a watchpoint hit | |
1863 | to the user when the old value and the new value may actually | |
1864 | be completely different objects. */ | |
fa4727a6 | 1865 | b->val = NULL; |
4c1d86d9 | 1866 | b->val_valid = false; |
60e1c644 PA |
1867 | |
1868 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1869 | expression is stored in the breakpoint object, not in the | |
1870 | locations (re)created below. */ | |
c1fc2657 | 1871 | if (b->cond_string != NULL) |
60e1c644 | 1872 | { |
4d01a485 | 1873 | b->cond_exp.reset (); |
60e1c644 | 1874 | |
c1fc2657 | 1875 | s = b->cond_string; |
1bb9788d | 1876 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1877 | } |
a5606eee | 1878 | } |
a5606eee VP |
1879 | |
1880 | /* If we failed to parse the expression, for example because | |
1881 | it refers to a global variable in a not-yet-loaded shared library, | |
1882 | don't try to insert watchpoint. We don't automatically delete | |
1883 | such watchpoint, though, since failure to parse expression | |
1884 | is different from out-of-scope watchpoint. */ | |
55f6301a | 1885 | if (!target_has_execution ()) |
2d134ed3 PA |
1886 | { |
1887 | /* Without execution, memory can't change. No use to try and | |
1888 | set watchpoint locations. The watchpoint will be reset when | |
1889 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1890 | if (!can_use_hw_watchpoints) |
1891 | { | |
c1fc2657 SM |
1892 | if (b->ops->works_in_software_mode (b)) |
1893 | b->type = bp_watchpoint; | |
e8369a73 | 1894 | else |
638aa5a1 AB |
1895 | error (_("Can't set read/access watchpoint when " |
1896 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1897 | } |
2d134ed3 PA |
1898 | } |
1899 | else if (within_current_scope && b->exp) | |
a5606eee | 1900 | { |
0cf6dd15 | 1901 | int pc = 0; |
a6535de1 | 1902 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 1903 | struct value *v, *result; |
2d134ed3 | 1904 | struct program_space *frame_pspace; |
a5606eee | 1905 | |
2e362716 | 1906 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, false); |
a5606eee | 1907 | |
a5606eee VP |
1908 | /* Avoid setting b->val if it's already set. The meaning of |
1909 | b->val is 'the last value' user saw, and we should update | |
1910 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1911 | happens, the code that reports it updates b->val directly. |
1912 | We don't keep track of the memory value for masked | |
1913 | watchpoints. */ | |
c1fc2657 | 1914 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1915 | { |
bb9d5f81 | 1916 | if (b->val_bitsize != 0) |
850645cf TT |
1917 | v = extract_bitfield_from_watchpoint_value (b, v); |
1918 | b->val = release_value (v); | |
4c1d86d9 | 1919 | b->val_valid = true; |
fa4727a6 | 1920 | } |
a5606eee | 1921 | |
2d134ed3 PA |
1922 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1923 | ||
a5606eee | 1924 | /* Look at each value on the value chain. */ |
a6535de1 TT |
1925 | gdb_assert (!val_chain.empty ()); |
1926 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 1927 | { |
a6535de1 TT |
1928 | v = iter.get (); |
1929 | ||
a5606eee VP |
1930 | /* If it's a memory location, and GDB actually needed |
1931 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1932 | must watch it. If the first value returned is |
1933 | still lazy, that means an error occurred reading it; | |
1934 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1935 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 1936 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
1937 | { |
1938 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1939 | |
a5606eee VP |
1940 | /* We only watch structs and arrays if user asked |
1941 | for it explicitly, never if they just happen to | |
1942 | appear in the middle of some value chain. */ | |
fa4727a6 | 1943 | if (v == result |
78134374 SM |
1944 | || (vtype->code () != TYPE_CODE_STRUCT |
1945 | && vtype->code () != TYPE_CODE_ARRAY)) | |
a5606eee VP |
1946 | { |
1947 | CORE_ADDR addr; | |
f486487f | 1948 | enum target_hw_bp_type type; |
a5606eee | 1949 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1950 | int bitpos = 0, bitsize = 0; |
1951 | ||
1952 | if (value_bitsize (v) != 0) | |
1953 | { | |
1954 | /* Extract the bit parameters out from the bitfield | |
1955 | sub-expression. */ | |
1956 | bitpos = value_bitpos (v); | |
1957 | bitsize = value_bitsize (v); | |
1958 | } | |
1959 | else if (v == result && b->val_bitsize != 0) | |
1960 | { | |
1961 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1962 | lvalue whose bit parameters are saved in the fields | |
1963 | VAL_BITPOS and VAL_BITSIZE. */ | |
1964 | bitpos = b->val_bitpos; | |
1965 | bitsize = b->val_bitsize; | |
1966 | } | |
a5606eee | 1967 | |
42ae5230 | 1968 | addr = value_address (v); |
bb9d5f81 PP |
1969 | if (bitsize != 0) |
1970 | { | |
1971 | /* Skip the bytes that don't contain the bitfield. */ | |
1972 | addr += bitpos / 8; | |
1973 | } | |
1974 | ||
a5606eee | 1975 | type = hw_write; |
c1fc2657 | 1976 | if (b->type == bp_read_watchpoint) |
a5606eee | 1977 | type = hw_read; |
c1fc2657 | 1978 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1979 | type = hw_access; |
3a5c3e22 | 1980 | |
c1fc2657 SM |
1981 | loc = allocate_bp_location (b); |
1982 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1983 | ; |
1984 | *tmp = loc; | |
8ee511af | 1985 | loc->gdbarch = value_type (v)->arch (); |
6c95b8df PA |
1986 | |
1987 | loc->pspace = frame_pspace; | |
f17d9474 | 1988 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
1989 | |
1990 | if (bitsize != 0) | |
1991 | { | |
1992 | /* Just cover the bytes that make up the bitfield. */ | |
1993 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1994 | } | |
1995 | else | |
1996 | loc->length = TYPE_LENGTH (value_type (v)); | |
1997 | ||
a5606eee VP |
1998 | loc->watchpoint_type = type; |
1999 | } | |
2000 | } | |
9fa40276 TJB |
2001 | } |
2002 | ||
2003 | /* Change the type of breakpoint between hardware assisted or | |
2004 | an ordinary watchpoint depending on the hardware support | |
2005 | and free hardware slots. REPARSE is set when the inferior | |
2006 | is started. */ | |
a9634178 | 2007 | if (reparse) |
9fa40276 | 2008 | { |
e09342b5 | 2009 | int reg_cnt; |
9fa40276 TJB |
2010 | enum bp_loc_type loc_type; |
2011 | struct bp_location *bl; | |
a5606eee | 2012 | |
a9634178 | 2013 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2014 | |
2015 | if (reg_cnt) | |
9fa40276 TJB |
2016 | { |
2017 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2018 | enum bptype type; |
9fa40276 | 2019 | |
a9634178 TJB |
2020 | /* Use an exact watchpoint when there's only one memory region to be |
2021 | watched, and only one debug register is needed to watch it. */ | |
2022 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2023 | ||
9fa40276 | 2024 | /* We need to determine how many resources are already |
e09342b5 TJB |
2025 | used for all other hardware watchpoints plus this one |
2026 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2027 | this watchpoint in as well. */ |
2028 | ||
2029 | /* If this is a software watchpoint, we try to turn it | |
2030 | to a hardware one -- count resources as if B was of | |
2031 | hardware watchpoint type. */ | |
c1fc2657 | 2032 | type = b->type; |
a1398e0c PA |
2033 | if (type == bp_watchpoint) |
2034 | type = bp_hardware_watchpoint; | |
2035 | ||
2036 | /* This watchpoint may or may not have been placed on | |
2037 | the list yet at this point (it won't be in the list | |
2038 | if we're trying to create it for the first time, | |
2039 | through watch_command), so always account for it | |
2040 | manually. */ | |
2041 | ||
2042 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 2043 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
2044 | |
2045 | /* Add in the resources needed for B. */ | |
c1fc2657 | 2046 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
2047 | |
2048 | target_resources_ok | |
2049 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2050 | if (target_resources_ok <= 0) |
a9634178 | 2051 | { |
c1fc2657 | 2052 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
2053 | |
2054 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2055 | error (_("Target does not support this type of " |
2056 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2057 | else if (target_resources_ok < 0 && !sw_mode) |
2058 | error (_("There are not enough available hardware " | |
2059 | "resources for this watchpoint.")); | |
a1398e0c PA |
2060 | |
2061 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 2062 | b->type = bp_watchpoint; |
a1398e0c PA |
2063 | } |
2064 | else | |
2065 | { | |
2066 | /* If this was a software watchpoint, we've just | |
2067 | found we have enough resources to turn it to a | |
2068 | hardware watchpoint. Otherwise, this is a | |
2069 | nop. */ | |
c1fc2657 | 2070 | b->type = type; |
a9634178 | 2071 | } |
9fa40276 | 2072 | } |
c1fc2657 | 2073 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
2074 | { |
2075 | if (!can_use_hw_watchpoints) | |
2076 | error (_("Can't set read/access watchpoint when " | |
2077 | "hardware watchpoints are disabled.")); | |
2078 | else | |
2079 | error (_("Expression cannot be implemented with " | |
2080 | "read/access watchpoint.")); | |
2081 | } | |
9fa40276 | 2082 | else |
c1fc2657 | 2083 | b->type = bp_watchpoint; |
9fa40276 | 2084 | |
c1fc2657 | 2085 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2086 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 2087 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
2088 | bl->loc_type = loc_type; |
2089 | } | |
2090 | ||
c7437ca6 PA |
2091 | /* If a software watchpoint is not watching any memory, then the |
2092 | above left it without any location set up. But, | |
2093 | bpstat_stop_status requires a location to be able to report | |
2094 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2095 | if (b->type == bp_watchpoint && b->loc == NULL) |
2096 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2097 | } |
2098 | else if (!within_current_scope) | |
7270d8f2 | 2099 | { |
ac74f770 MS |
2100 | printf_filtered (_("\ |
2101 | Watchpoint %d deleted because the program has left the block\n\ | |
2102 | in which its expression is valid.\n"), | |
c1fc2657 | 2103 | b->number); |
d0fb5eae | 2104 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2105 | } |
a5606eee VP |
2106 | |
2107 | /* Restore the selected frame. */ | |
66076460 DJ |
2108 | if (frame_saved) |
2109 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2110 | } |
2111 | ||
a5606eee | 2112 | |
74960c60 | 2113 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2114 | inserted in the inferior. We don't differentiate the type of BL's owner |
2115 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2116 | breakpoint_ops is not defined, because in insert_bp_location, | |
2117 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2118 | static int |
35df4500 | 2119 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2120 | { |
35df4500 | 2121 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2122 | return 0; |
2123 | ||
35df4500 | 2124 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2125 | return 0; |
2126 | ||
b5fa468f TBA |
2127 | if (!bl->enabled || bl->disabled_by_cond |
2128 | || bl->shlib_disabled || bl->duplicate) | |
74960c60 VP |
2129 | return 0; |
2130 | ||
f8eba3c6 TT |
2131 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2132 | return 0; | |
2133 | ||
56710373 PA |
2134 | /* This is set for example, when we're attached to the parent of a |
2135 | vfork, and have detached from the child. The child is running | |
2136 | free, and we expect it to do an exec or exit, at which point the | |
2137 | OS makes the parent schedulable again (and the target reports | |
2138 | that the vfork is done). Until the child is done with the shared | |
2139 | memory region, do not insert breakpoints in the parent, otherwise | |
2140 | the child could still trip on the parent's breakpoints. Since | |
2141 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2142 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2143 | return 0; |
2144 | ||
31e77af2 | 2145 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2146 | location, except if the breakpoint is a single-step breakpoint, |
2147 | and the breakpoint's thread is the thread which is stepping past | |
2148 | a breakpoint. */ | |
31e77af2 PA |
2149 | if ((bl->loc_type == bp_loc_software_breakpoint |
2150 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2151 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2152 | bl->address) |
2153 | /* The single-step breakpoint may be inserted at the location | |
2154 | we're trying to step if the instruction branches to itself. | |
2155 | However, the instruction won't be executed at all and it may | |
2156 | break the semantics of the instruction, for example, the | |
2157 | instruction is a conditional branch or updates some flags. | |
2158 | We can't fix it unless GDB is able to emulate the instruction | |
2159 | or switch to displaced stepping. */ | |
2160 | && !(bl->owner->type == bp_single_step | |
2161 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 | 2162 | { |
1eb8556f SM |
2163 | infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s", |
2164 | paddress (bl->gdbarch, bl->address)); | |
e558d7c1 PA |
2165 | return 0; |
2166 | } | |
31e77af2 | 2167 | |
963f9c80 PA |
2168 | /* Don't insert watchpoints if we're trying to step past the |
2169 | instruction that triggered one. */ | |
2170 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2171 | && stepping_past_nonsteppable_watchpoint ()) | |
2172 | { | |
1eb8556f | 2173 | infrun_debug_printf ("stepping past non-steppable watchpoint. " |
ae1f4d2d | 2174 | "skipping watchpoint at %s:%d", |
1eb8556f | 2175 | paddress (bl->gdbarch, bl->address), bl->length); |
963f9c80 PA |
2176 | return 0; |
2177 | } | |
2178 | ||
74960c60 VP |
2179 | return 1; |
2180 | } | |
2181 | ||
934709f0 PW |
2182 | /* Same as should_be_inserted but does the check assuming |
2183 | that the location is not duplicated. */ | |
2184 | ||
2185 | static int | |
2186 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2187 | { | |
2188 | int result; | |
2189 | const int save_duplicate = bl->duplicate; | |
2190 | ||
2191 | bl->duplicate = 0; | |
2192 | result = should_be_inserted (bl); | |
2193 | bl->duplicate = save_duplicate; | |
2194 | return result; | |
2195 | } | |
2196 | ||
b775012e LM |
2197 | /* Parses a conditional described by an expression COND into an |
2198 | agent expression bytecode suitable for evaluation | |
2199 | by the bytecode interpreter. Return NULL if there was | |
2200 | any error during parsing. */ | |
2201 | ||
833177a4 | 2202 | static agent_expr_up |
b775012e LM |
2203 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2204 | { | |
833177a4 | 2205 | if (cond == NULL) |
b775012e LM |
2206 | return NULL; |
2207 | ||
833177a4 PA |
2208 | agent_expr_up aexpr; |
2209 | ||
b775012e LM |
2210 | /* We don't want to stop processing, so catch any errors |
2211 | that may show up. */ | |
a70b8144 | 2212 | try |
b775012e | 2213 | { |
036e657b | 2214 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2215 | } |
2216 | ||
230d2906 | 2217 | catch (const gdb_exception_error &ex) |
b775012e LM |
2218 | { |
2219 | /* If we got here, it means the condition could not be parsed to a valid | |
2220 | bytecode expression and thus can't be evaluated on the target's side. | |
2221 | It's no use iterating through the conditions. */ | |
b775012e LM |
2222 | } |
2223 | ||
2224 | /* We have a valid agent expression. */ | |
2225 | return aexpr; | |
2226 | } | |
2227 | ||
2228 | /* Based on location BL, create a list of breakpoint conditions to be | |
2229 | passed on to the target. If we have duplicated locations with different | |
2230 | conditions, we will add such conditions to the list. The idea is that the | |
2231 | target will evaluate the list of conditions and will only notify GDB when | |
2232 | one of them is true. */ | |
2233 | ||
2234 | static void | |
2235 | build_target_condition_list (struct bp_location *bl) | |
2236 | { | |
2237 | struct bp_location **locp = NULL, **loc2p; | |
2238 | int null_condition_or_parse_error = 0; | |
2239 | int modified = bl->needs_update; | |
2240 | struct bp_location *loc; | |
2241 | ||
8b4f3082 | 2242 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2243 | bl->target_info.conditions.clear (); |
8b4f3082 | 2244 | |
b775012e LM |
2245 | /* This is only meaningful if the target is |
2246 | evaluating conditions and if the user has | |
2247 | opted for condition evaluation on the target's | |
2248 | side. */ | |
2249 | if (gdb_evaluates_breakpoint_condition_p () | |
2250 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2251 | return; | |
2252 | ||
2253 | /* Do a first pass to check for locations with no assigned | |
7f32a4d5 PA |
2254 | conditions or conditions that fail to parse to a valid agent |
2255 | expression bytecode. If any of these happen, then it's no use to | |
2256 | send conditions to the target since this location will always | |
2257 | trigger and generate a response back to GDB. Note we consider | |
2258 | all locations at the same address irrespective of type, i.e., | |
2259 | even if the locations aren't considered duplicates (e.g., | |
2260 | software breakpoint and hardware breakpoint at the same | |
2261 | address). */ | |
b775012e LM |
2262 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2263 | { | |
2264 | loc = (*loc2p); | |
2265 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2266 | { | |
2267 | if (modified) | |
2268 | { | |
b775012e LM |
2269 | /* Re-parse the conditions since something changed. In that |
2270 | case we already freed the condition bytecodes (see | |
2271 | force_breakpoint_reinsertion). We just | |
2272 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2273 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2274 | loc->cond.get ()); | |
b775012e LM |
2275 | } |
2276 | ||
2277 | /* If we have a NULL bytecode expression, it means something | |
2278 | went wrong or we have a null condition expression. */ | |
2279 | if (!loc->cond_bytecode) | |
2280 | { | |
2281 | null_condition_or_parse_error = 1; | |
2282 | break; | |
2283 | } | |
2284 | } | |
2285 | } | |
2286 | ||
2287 | /* If any of these happened, it means we will have to evaluate the conditions | |
2288 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2289 | for all the other duplicate locations, thus we free all of them here. | |
2290 | ||
2291 | This is so we have a finer control over which locations' conditions are | |
2292 | being evaluated by GDB or the remote stub. */ | |
2293 | if (null_condition_or_parse_error) | |
2294 | { | |
2295 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2296 | { | |
2297 | loc = (*loc2p); | |
2298 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2299 | { | |
2300 | /* Only go as far as the first NULL bytecode is | |
2301 | located. */ | |
2302 | if (!loc->cond_bytecode) | |
2303 | return; | |
2304 | ||
833177a4 | 2305 | loc->cond_bytecode.reset (); |
b775012e LM |
2306 | } |
2307 | } | |
2308 | } | |
2309 | ||
7f32a4d5 PA |
2310 | /* No NULL conditions or failed bytecode generation. Build a |
2311 | condition list for this location's address. If we have software | |
2312 | and hardware locations at the same address, they aren't | |
2313 | considered duplicates, but we still marge all the conditions | |
2314 | anyway, as it's simpler, and doesn't really make a practical | |
2315 | difference. */ | |
b775012e LM |
2316 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2317 | { | |
2318 | loc = (*loc2p); | |
2319 | if (loc->cond | |
2320 | && is_breakpoint (loc->owner) | |
2321 | && loc->pspace->num == bl->pspace->num | |
2322 | && loc->owner->enable_state == bp_enabled | |
b5fa468f TBA |
2323 | && loc->enabled |
2324 | && !loc->disabled_by_cond) | |
3cde5c42 PA |
2325 | { |
2326 | /* Add the condition to the vector. This will be used later | |
2327 | to send the conditions to the target. */ | |
2328 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2329 | } | |
b775012e LM |
2330 | } |
2331 | ||
2332 | return; | |
2333 | } | |
2334 | ||
d3ce09f5 SS |
2335 | /* Parses a command described by string CMD into an agent expression |
2336 | bytecode suitable for evaluation by the bytecode interpreter. | |
2337 | Return NULL if there was any error during parsing. */ | |
2338 | ||
833177a4 | 2339 | static agent_expr_up |
d3ce09f5 SS |
2340 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2341 | { | |
bbc13ae3 KS |
2342 | const char *cmdrest; |
2343 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2344 | struct gdbarch *gdbarch = get_current_arch (); |
2345 | ||
833177a4 | 2346 | if (cmd == NULL) |
d3ce09f5 SS |
2347 | return NULL; |
2348 | ||
2349 | cmdrest = cmd; | |
2350 | ||
2351 | if (*cmdrest == ',') | |
2352 | ++cmdrest; | |
f1735a53 | 2353 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2354 | |
2355 | if (*cmdrest++ != '"') | |
2356 | error (_("No format string following the location")); | |
2357 | ||
2358 | format_start = cmdrest; | |
2359 | ||
8e481c3b | 2360 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2361 | |
2362 | format_end = cmdrest; | |
2363 | ||
2364 | if (*cmdrest++ != '"') | |
2365 | error (_("Bad format string, non-terminated '\"'.")); | |
2366 | ||
f1735a53 | 2367 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2368 | |
2369 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2370 | error (_("Invalid argument syntax")); | |
2371 | ||
2372 | if (*cmdrest == ',') | |
2373 | cmdrest++; | |
f1735a53 | 2374 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2375 | |
2376 | /* For each argument, make an expression. */ | |
2377 | ||
8e481c3b | 2378 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2379 | while (*cmdrest != '\0') |
2380 | { | |
bbc13ae3 | 2381 | const char *cmd1; |
d3ce09f5 SS |
2382 | |
2383 | cmd1 = cmdrest; | |
4d01a485 | 2384 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2385 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2386 | cmdrest = cmd1; |
2387 | if (*cmdrest == ',') | |
2388 | ++cmdrest; | |
2389 | } | |
2390 | ||
833177a4 PA |
2391 | agent_expr_up aexpr; |
2392 | ||
d3ce09f5 SS |
2393 | /* We don't want to stop processing, so catch any errors |
2394 | that may show up. */ | |
a70b8144 | 2395 | try |
d3ce09f5 | 2396 | { |
036e657b JB |
2397 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2398 | format_start, format_end - format_start, | |
8e481c3b | 2399 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2400 | } |
230d2906 | 2401 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2402 | { |
2403 | /* If we got here, it means the command could not be parsed to a valid | |
2404 | bytecode expression and thus can't be evaluated on the target's side. | |
2405 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2406 | } |
492d29ea | 2407 | |
d3ce09f5 SS |
2408 | /* We have a valid agent expression, return it. */ |
2409 | return aexpr; | |
2410 | } | |
2411 | ||
2412 | /* Based on location BL, create a list of breakpoint commands to be | |
2413 | passed on to the target. If we have duplicated locations with | |
2414 | different commands, we will add any such to the list. */ | |
2415 | ||
2416 | static void | |
2417 | build_target_command_list (struct bp_location *bl) | |
2418 | { | |
2419 | struct bp_location **locp = NULL, **loc2p; | |
2420 | int null_command_or_parse_error = 0; | |
2421 | int modified = bl->needs_update; | |
2422 | struct bp_location *loc; | |
2423 | ||
3cde5c42 PA |
2424 | /* Clear commands left over from a previous insert. */ |
2425 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2426 | |
41fac0cf | 2427 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2428 | return; |
2429 | ||
41fac0cf PA |
2430 | /* For now, limit to agent-style dprintf breakpoints. */ |
2431 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2432 | return; |
2433 | ||
7f32a4d5 PA |
2434 | /* For now, if we have any location at the same address that isn't a |
2435 | dprintf, don't install the target-side commands, as that would | |
2436 | make the breakpoint not be reported to the core, and we'd lose | |
41fac0cf PA |
2437 | control. */ |
2438 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2439 | { | |
2440 | loc = (*loc2p); | |
2441 | if (is_breakpoint (loc->owner) | |
2442 | && loc->pspace->num == bl->pspace->num | |
2443 | && loc->owner->type != bp_dprintf) | |
2444 | return; | |
2445 | } | |
2446 | ||
d3ce09f5 SS |
2447 | /* Do a first pass to check for locations with no assigned |
2448 | conditions or conditions that fail to parse to a valid agent expression | |
2449 | bytecode. If any of these happen, then it's no use to send conditions | |
2450 | to the target since this location will always trigger and generate a | |
2451 | response back to GDB. */ | |
2452 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2453 | { | |
2454 | loc = (*loc2p); | |
2455 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2456 | { | |
2457 | if (modified) | |
2458 | { | |
d3ce09f5 SS |
2459 | /* Re-parse the commands since something changed. In that |
2460 | case we already freed the command bytecodes (see | |
2461 | force_breakpoint_reinsertion). We just | |
2462 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2463 | loc->cmd_bytecode |
2464 | = parse_cmd_to_aexpr (bl->address, | |
2465 | loc->owner->extra_string); | |
d3ce09f5 SS |
2466 | } |
2467 | ||
2468 | /* If we have a NULL bytecode expression, it means something | |
2469 | went wrong or we have a null command expression. */ | |
2470 | if (!loc->cmd_bytecode) | |
2471 | { | |
2472 | null_command_or_parse_error = 1; | |
2473 | break; | |
2474 | } | |
2475 | } | |
2476 | } | |
2477 | ||
2478 | /* If anything failed, then we're not doing target-side commands, | |
2479 | and so clean up. */ | |
2480 | if (null_command_or_parse_error) | |
2481 | { | |
2482 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2483 | { | |
2484 | loc = (*loc2p); | |
2485 | if (is_breakpoint (loc->owner) | |
2486 | && loc->pspace->num == bl->pspace->num) | |
2487 | { | |
2488 | /* Only go as far as the first NULL bytecode is | |
2489 | located. */ | |
40fb6c5e | 2490 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2491 | return; |
2492 | ||
833177a4 | 2493 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2494 | } |
2495 | } | |
2496 | } | |
2497 | ||
7f32a4d5 PA |
2498 | /* No NULL commands or failed bytecode generation. Build a command |
2499 | list for all duplicate locations at this location's address. | |
2500 | Note that here we must care for whether the breakpoint location | |
2501 | types are considered duplicates, otherwise, say, if we have a | |
2502 | software and hardware location at the same address, the target | |
2503 | could end up running the commands twice. For the moment, we only | |
2504 | support targets-side commands with dprintf, but it doesn't hurt | |
2505 | to be pedantically correct in case that changes. */ | |
d3ce09f5 SS |
2506 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
2507 | { | |
2508 | loc = (*loc2p); | |
7f32a4d5 PA |
2509 | if (breakpoint_locations_match (bl, loc) |
2510 | && loc->owner->extra_string | |
d3ce09f5 SS |
2511 | && is_breakpoint (loc->owner) |
2512 | && loc->pspace->num == bl->pspace->num | |
2513 | && loc->owner->enable_state == bp_enabled | |
b5fa468f TBA |
2514 | && loc->enabled |
2515 | && !loc->disabled_by_cond) | |
3cde5c42 PA |
2516 | { |
2517 | /* Add the command to the vector. This will be used later | |
2518 | to send the commands to the target. */ | |
2519 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2520 | } | |
d3ce09f5 SS |
2521 | } |
2522 | ||
2523 | bl->target_info.persist = 0; | |
2524 | /* Maybe flag this location as persistent. */ | |
2525 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2526 | bl->target_info.persist = 1; | |
2527 | } | |
2528 | ||
833b7ab5 YQ |
2529 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2530 | of breakpoint according to ADDR except single-step breakpoint. | |
2531 | Get the kind of single-step breakpoint according to the current | |
2532 | registers state. */ | |
cd6c3b4f YQ |
2533 | |
2534 | static int | |
2535 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2536 | { | |
833b7ab5 YQ |
2537 | if (bl->owner->type == bp_single_step) |
2538 | { | |
2539 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2540 | struct regcache *regcache; | |
2541 | ||
00431a78 | 2542 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2543 | |
2544 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2545 | regcache, addr); | |
2546 | } | |
2547 | else | |
2548 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2549 | } |
2550 | ||
35df4500 TJB |
2551 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2552 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2553 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2554 | Returns 0 for success, 1 if the bp_location type is not supported or |
2555 | -1 for failure. | |
879bfdc2 | 2556 | |
4a64f543 MS |
2557 | NOTE drow/2003-09-09: This routine could be broken down to an |
2558 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2559 | static int |
35df4500 | 2560 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2561 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2562 | int *disabled_breaks, |
dd61ec5c MW |
2563 | int *hw_breakpoint_error, |
2564 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2565 | { |
cc06b668 | 2566 | gdb_exception bp_excpt; |
879bfdc2 | 2567 | |
b775012e | 2568 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2569 | return 0; |
2570 | ||
35c63cd8 JB |
2571 | /* Note we don't initialize bl->target_info, as that wipes out |
2572 | the breakpoint location's shadow_contents if the breakpoint | |
2573 | is still inserted at that location. This in turn breaks | |
2574 | target_read_memory which depends on these buffers when | |
2575 | a memory read is requested at the breakpoint location: | |
2576 | Once the target_info has been wiped, we fail to see that | |
2577 | we have a breakpoint inserted at that address and thus | |
2578 | read the breakpoint instead of returning the data saved in | |
2579 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2580 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2581 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2582 | bl->target_info.length = bl->length; |
8181d85f | 2583 | |
b775012e LM |
2584 | /* When working with target-side conditions, we must pass all the conditions |
2585 | for the same breakpoint address down to the target since GDB will not | |
2586 | insert those locations. With a list of breakpoint conditions, the target | |
2587 | can decide when to stop and notify GDB. */ | |
2588 | ||
2589 | if (is_breakpoint (bl->owner)) | |
2590 | { | |
2591 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2592 | build_target_command_list (bl); |
2593 | /* Reset the modification marker. */ | |
b775012e LM |
2594 | bl->needs_update = 0; |
2595 | } | |
2596 | ||
7f32a4d5 PA |
2597 | /* If "set breakpoint auto-hw" is "on" and a software breakpoint was |
2598 | set at a read-only address, then a breakpoint location will have | |
2599 | been changed to hardware breakpoint before we get here. If it is | |
2600 | "off" however, error out before actually trying to insert the | |
2601 | breakpoint, with a nicer error message. */ | |
35df4500 | 2602 | if (bl->loc_type == bp_loc_software_breakpoint |
7f32a4d5 | 2603 | && !automatic_hardware_breakpoints) |
879bfdc2 | 2604 | { |
7f32a4d5 | 2605 | mem_region *mr = lookup_mem_region (bl->address); |
cc59ec59 | 2606 | |
7f32a4d5 PA |
2607 | if (mr != nullptr && mr->attrib.mode != MEM_RW) |
2608 | { | |
2609 | fprintf_unfiltered (tmp_error_stream, | |
2610 | _("Cannot insert breakpoint %d.\n" | |
2611 | "Cannot set software breakpoint " | |
2612 | "at read-only address %s\n"), | |
2613 | bl->owner->number, | |
2614 | paddress (bl->gdbarch, bl->address)); | |
2615 | return 1; | |
765dc015 | 2616 | } |
7f32a4d5 PA |
2617 | } |
2618 | ||
2619 | if (bl->loc_type == bp_loc_software_breakpoint | |
2620 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2621 | { | |
879bfdc2 DJ |
2622 | /* First check to see if we have to handle an overlay. */ |
2623 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2624 | || bl->section == NULL |
2625 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2626 | { |
2627 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2628 | try |
dd61ec5c | 2629 | { |
0000e5cc PA |
2630 | int val; |
2631 | ||
dd61ec5c | 2632 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2633 | if (val) |
688fca4f | 2634 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2635 | } |
94aeb44b | 2636 | catch (gdb_exception &e) |
dd61ec5c | 2637 | { |
94aeb44b | 2638 | bp_excpt = std::move (e); |
dd61ec5c | 2639 | } |
879bfdc2 DJ |
2640 | } |
2641 | else | |
2642 | { | |
4a64f543 | 2643 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2644 | Shall we set a breakpoint at the LMA? */ |
2645 | if (!overlay_events_enabled) | |
2646 | { | |
2647 | /* Yes -- overlay event support is not active, | |
2648 | so we must try to set a breakpoint at the LMA. | |
2649 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2650 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2651 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2652 | bl->owner->number); |
879bfdc2 DJ |
2653 | else |
2654 | { | |
35df4500 TJB |
2655 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2656 | bl->section); | |
879bfdc2 | 2657 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2658 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2659 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2660 | |
2661 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2662 | try |
0000e5cc PA |
2663 | { |
2664 | int val; | |
2665 | ||
579c6ad9 | 2666 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2667 | = breakpoint_kind (bl, &addr); |
2668 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2669 | val = target_insert_breakpoint (bl->gdbarch, |
2670 | &bl->overlay_target_info); | |
2671 | if (val) | |
688fca4f PA |
2672 | bp_excpt |
2673 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2674 | } |
94aeb44b | 2675 | catch (gdb_exception &e) |
0000e5cc | 2676 | { |
94aeb44b | 2677 | bp_excpt = std::move (e); |
0000e5cc PA |
2678 | } |
2679 | ||
688fca4f | 2680 | if (bp_excpt.reason != 0) |
99361f52 | 2681 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2682 | "Overlay breakpoint %d " |
2683 | "failed: in ROM?\n", | |
35df4500 | 2684 | bl->owner->number); |
879bfdc2 DJ |
2685 | } |
2686 | } | |
2687 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2688 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2689 | { |
2690 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2691 | try |
dda83cd7 | 2692 | { |
0000e5cc PA |
2693 | int val; |
2694 | ||
dda83cd7 | 2695 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2696 | if (val) |
688fca4f | 2697 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dda83cd7 | 2698 | } |
94aeb44b | 2699 | catch (gdb_exception &e) |
dda83cd7 | 2700 | { |
94aeb44b | 2701 | bp_excpt = std::move (e); |
dda83cd7 | 2702 | } |
879bfdc2 DJ |
2703 | } |
2704 | else | |
2705 | { | |
2706 | /* No. This breakpoint will not be inserted. | |
2707 | No error, but do not mark the bp as 'inserted'. */ | |
2708 | return 0; | |
2709 | } | |
2710 | } | |
2711 | ||
688fca4f | 2712 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2713 | { |
2714 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2715 | |
2716 | /* In some cases, we might not be able to insert a | |
2717 | breakpoint in a shared library that has already been | |
2718 | removed, but we have not yet processed the shlib unload | |
2719 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2720 | breakpoint insertion themselves can't tell why the |
2721 | breakpoint insertion failed (e.g., the remote target | |
2722 | doesn't define error codes), so we must treat generic | |
2723 | errors as memory errors. */ | |
688fca4f PA |
2724 | if (bp_excpt.reason == RETURN_ERROR |
2725 | && (bp_excpt.error == GENERIC_ERROR | |
2726 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2727 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2728 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2729 | || shared_objfile_contains_address_p (bl->pspace, |
2730 | bl->address))) | |
879bfdc2 | 2731 | { |
4a64f543 | 2732 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2733 | bl->shlib_disabled = 1; |
76727919 | 2734 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2735 | if (!*disabled_breaks) |
2736 | { | |
2737 | fprintf_unfiltered (tmp_error_stream, | |
2738 | "Cannot insert breakpoint %d.\n", | |
2739 | bl->owner->number); | |
2740 | fprintf_unfiltered (tmp_error_stream, | |
2741 | "Temporarily disabling shared " | |
2742 | "library breakpoints:\n"); | |
2743 | } | |
2744 | *disabled_breaks = 1; | |
879bfdc2 | 2745 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2746 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2747 | return 0; |
879bfdc2 DJ |
2748 | } |
2749 | else | |
879bfdc2 | 2750 | { |
35df4500 | 2751 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2752 | { |
0000e5cc | 2753 | *hw_breakpoint_error = 1; |
688fca4f | 2754 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dda83cd7 SM |
2755 | fprintf_unfiltered (tmp_error_stream, |
2756 | "Cannot insert hardware breakpoint %d%s", | |
2757 | bl->owner->number, | |
688fca4f | 2758 | bp_excpt.message ? ":" : ".\n"); |
dda83cd7 SM |
2759 | if (bp_excpt.message != NULL) |
2760 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
3d6e9d23 | 2761 | bp_excpt.what ()); |
879bfdc2 DJ |
2762 | } |
2763 | else | |
2764 | { | |
688fca4f | 2765 | if (bp_excpt.message == NULL) |
0000e5cc | 2766 | { |
1ccbe998 | 2767 | std::string message |
0000e5cc PA |
2768 | = memory_error_message (TARGET_XFER_E_IO, |
2769 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2770 | |
2771 | fprintf_unfiltered (tmp_error_stream, | |
2772 | "Cannot insert breakpoint %d.\n" | |
2773 | "%s\n", | |
1ccbe998 | 2774 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2775 | } |
2776 | else | |
2777 | { | |
2778 | fprintf_unfiltered (tmp_error_stream, | |
2779 | "Cannot insert breakpoint %d: %s\n", | |
2780 | bl->owner->number, | |
3d6e9d23 | 2781 | bp_excpt.what ()); |
0000e5cc | 2782 | } |
879bfdc2 | 2783 | } |
0000e5cc | 2784 | return 1; |
879bfdc2 DJ |
2785 | |
2786 | } | |
2787 | } | |
2788 | else | |
35df4500 | 2789 | bl->inserted = 1; |
879bfdc2 | 2790 | |
0000e5cc | 2791 | return 0; |
879bfdc2 DJ |
2792 | } |
2793 | ||
35df4500 | 2794 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2795 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2796 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2797 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2798 | { |
0000e5cc PA |
2799 | int val; |
2800 | ||
77b06cd7 TJB |
2801 | gdb_assert (bl->owner->ops != NULL |
2802 | && bl->owner->ops->insert_location != NULL); | |
2803 | ||
2804 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2805 | |
2806 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2807 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2808 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2809 | { |
2810 | struct bp_location *loc, **loc_temp; | |
2811 | ||
2812 | /* But don't try to insert it, if there's already another | |
2813 | hw_access location that would be considered a duplicate | |
2814 | of this one. */ | |
2815 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2816 | if (loc != bl |
85d721b8 | 2817 | && loc->watchpoint_type == hw_access |
35df4500 | 2818 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2819 | { |
35df4500 TJB |
2820 | bl->duplicate = 1; |
2821 | bl->inserted = 1; | |
2822 | bl->target_info = loc->target_info; | |
2823 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2824 | val = 0; |
2825 | break; | |
2826 | } | |
2827 | ||
2828 | if (val == 1) | |
2829 | { | |
77b06cd7 TJB |
2830 | bl->watchpoint_type = hw_access; |
2831 | val = bl->owner->ops->insert_location (bl); | |
2832 | ||
2833 | if (val) | |
2834 | /* Back to the original value. */ | |
2835 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2836 | } |
2837 | } | |
2838 | ||
35df4500 | 2839 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2840 | } |
2841 | ||
35df4500 | 2842 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2843 | { |
0000e5cc PA |
2844 | int val; |
2845 | ||
77b06cd7 TJB |
2846 | gdb_assert (bl->owner->ops != NULL |
2847 | && bl->owner->ops->insert_location != NULL); | |
2848 | ||
2849 | val = bl->owner->ops->insert_location (bl); | |
2850 | if (val) | |
2851 | { | |
2852 | bl->owner->enable_state = bp_disabled; | |
2853 | ||
2854 | if (val == 1) | |
2855 | warning (_("\ | |
2856 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2857 | of catchpoint."), bl->owner->number); | |
2858 | else | |
2859 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2860 | } | |
2861 | ||
2862 | bl->inserted = (val == 0); | |
1640b821 DJ |
2863 | |
2864 | /* We've already printed an error message if there was a problem | |
2865 | inserting this catchpoint, and we've disabled the catchpoint, | |
2866 | so just return success. */ | |
2867 | return 0; | |
879bfdc2 DJ |
2868 | } |
2869 | ||
2870 | return 0; | |
2871 | } | |
2872 | ||
6c95b8df PA |
2873 | /* This function is called when program space PSPACE is about to be |
2874 | deleted. It takes care of updating breakpoints to not reference | |
2875 | PSPACE anymore. */ | |
2876 | ||
2877 | void | |
2878 | breakpoint_program_space_exit (struct program_space *pspace) | |
2879 | { | |
2880 | struct breakpoint *b, *b_temp; | |
876fa593 | 2881 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2882 | |
2883 | /* Remove any breakpoint that was set through this program space. */ | |
2884 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2885 | { | |
2886 | if (b->pspace == pspace) | |
2887 | delete_breakpoint (b); | |
2888 | } | |
2889 | ||
2890 | /* Breakpoints set through other program spaces could have locations | |
2891 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2892 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2893 | { |
2894 | struct bp_location *tmp; | |
2895 | ||
2896 | if (loc->pspace == pspace) | |
2897 | { | |
2bdf28a0 | 2898 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2899 | if (loc->owner->loc == loc) |
2900 | loc->owner->loc = loc->next; | |
2901 | else | |
2902 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2903 | if (tmp->next == loc) | |
2904 | { | |
2905 | tmp->next = loc->next; | |
2906 | break; | |
2907 | } | |
2908 | } | |
2909 | } | |
2910 | ||
2911 | /* Now update the global location list to permanently delete the | |
2912 | removed locations above. */ | |
44702360 | 2913 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2914 | } |
2915 | ||
74960c60 VP |
2916 | /* Make sure all breakpoints are inserted in inferior. |
2917 | Throws exception on any error. | |
2918 | A breakpoint that is already inserted won't be inserted | |
2919 | again, so calling this function twice is safe. */ | |
2920 | void | |
2921 | insert_breakpoints (void) | |
2922 | { | |
2923 | struct breakpoint *bpt; | |
2924 | ||
2925 | ALL_BREAKPOINTS (bpt) | |
2926 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2927 | { |
2928 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2929 | ||
2930 | update_watchpoint (w, 0 /* don't reparse. */); | |
2931 | } | |
74960c60 | 2932 | |
04086b45 PA |
2933 | /* Updating watchpoints creates new locations, so update the global |
2934 | location list. Explicitly tell ugll to insert locations and | |
7f32a4d5 PA |
2935 | ignore breakpoints_always_inserted_mode. Also, |
2936 | update_global_location_list tries to "upgrade" software | |
2937 | breakpoints to hardware breakpoints to handle "set breakpoint | |
2938 | auto-hw", so we need to call it even if we don't have new | |
2939 | locations. */ | |
04086b45 | 2940 | update_global_location_list (UGLL_INSERT); |
74960c60 VP |
2941 | } |
2942 | ||
20388dd6 YQ |
2943 | /* Invoke CALLBACK for each of bp_location. */ |
2944 | ||
2945 | void | |
2946 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2947 | { | |
2948 | struct bp_location *loc, **loc_tmp; | |
2949 | ||
2950 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2951 | { | |
2952 | callback (loc, NULL); | |
2953 | } | |
2954 | } | |
2955 | ||
b775012e LM |
2956 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2957 | target. It is the case with deleting and disabling of breakpoints when using | |
2958 | always-inserted mode. */ | |
2959 | ||
2960 | static void | |
2961 | update_inserted_breakpoint_locations (void) | |
2962 | { | |
2963 | struct bp_location *bl, **blp_tmp; | |
2964 | int error_flag = 0; | |
2965 | int val = 0; | |
2966 | int disabled_breaks = 0; | |
2967 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2968 | int hw_bp_details_reported = 0; |
b775012e | 2969 | |
d7e74731 | 2970 | string_file tmp_error_stream; |
b775012e LM |
2971 | |
2972 | /* Explicitly mark the warning -- this will only be printed if | |
2973 | there was an error. */ | |
d7e74731 | 2974 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2975 | |
5ed8105e | 2976 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2977 | |
2978 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2979 | { | |
2980 | /* We only want to update software breakpoints and hardware | |
2981 | breakpoints. */ | |
2982 | if (!is_breakpoint (bl->owner)) | |
2983 | continue; | |
2984 | ||
2985 | /* We only want to update locations that are already inserted | |
2986 | and need updating. This is to avoid unwanted insertion during | |
2987 | deletion of breakpoints. */ | |
4daf1902 | 2988 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
2989 | continue; |
2990 | ||
2991 | switch_to_program_space_and_thread (bl->pspace); | |
2992 | ||
2993 | /* For targets that support global breakpoints, there's no need | |
2994 | to select an inferior to insert breakpoint to. In fact, even | |
2995 | if we aren't attached to any process yet, we should still | |
2996 | insert breakpoints. */ | |
f5656ead | 2997 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
55f6301a | 2998 | && (inferior_ptid == null_ptid || !target_has_execution ())) |
b775012e LM |
2999 | continue; |
3000 | ||
d7e74731 | 3001 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3002 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3003 | if (val) |
3004 | error_flag = val; | |
3005 | } | |
3006 | ||
3007 | if (error_flag) | |
3008 | { | |
223ffa71 | 3009 | target_terminal::ours_for_output (); |
b775012e LM |
3010 | error_stream (tmp_error_stream); |
3011 | } | |
b775012e LM |
3012 | } |
3013 | ||
c30eee59 | 3014 | /* Used when starting or continuing the program. */ |
c906108c | 3015 | |
74960c60 VP |
3016 | static void |
3017 | insert_breakpoint_locations (void) | |
c906108c | 3018 | { |
a5606eee | 3019 | struct breakpoint *bpt; |
35df4500 | 3020 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3021 | int error_flag = 0; |
c906108c | 3022 | int val = 0; |
3fbb6ffa | 3023 | int disabled_breaks = 0; |
81d0cc19 | 3024 | int hw_breakpoint_error = 0; |
dd61ec5c | 3025 | int hw_bp_error_explained_already = 0; |
c906108c | 3026 | |
d7e74731 PA |
3027 | string_file tmp_error_stream; |
3028 | ||
81d0cc19 GS |
3029 | /* Explicitly mark the warning -- this will only be printed if |
3030 | there was an error. */ | |
d7e74731 | 3031 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3032 | |
5ed8105e | 3033 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3034 | |
35df4500 | 3035 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3036 | { |
b775012e | 3037 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3038 | continue; |
3039 | ||
4a64f543 MS |
3040 | /* There is no point inserting thread-specific breakpoints if |
3041 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3042 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3043 | if (bl->owner->thread != -1 |
5d5658a1 | 3044 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3045 | continue; |
3046 | ||
35df4500 | 3047 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3048 | |
3049 | /* For targets that support global breakpoints, there's no need | |
3050 | to select an inferior to insert breakpoint to. In fact, even | |
3051 | if we aren't attached to any process yet, we should still | |
3052 | insert breakpoints. */ | |
f5656ead | 3053 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
55f6301a | 3054 | && (inferior_ptid == null_ptid || !target_has_execution ())) |
6c95b8df PA |
3055 | continue; |
3056 | ||
d7e74731 | 3057 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3058 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3059 | if (val) |
eacd795a | 3060 | error_flag = val; |
879bfdc2 | 3061 | } |
c906108c | 3062 | |
4a64f543 MS |
3063 | /* If we failed to insert all locations of a watchpoint, remove |
3064 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3065 | ALL_BREAKPOINTS (bpt) |
3066 | { | |
3067 | int some_failed = 0; | |
3068 | struct bp_location *loc; | |
3069 | ||
3070 | if (!is_hardware_watchpoint (bpt)) | |
3071 | continue; | |
3072 | ||
d6b74ac4 | 3073 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3074 | continue; |
74960c60 VP |
3075 | |
3076 | if (bpt->disposition == disp_del_at_next_stop) | |
3077 | continue; | |
a5606eee VP |
3078 | |
3079 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3080 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3081 | { |
3082 | some_failed = 1; | |
3083 | break; | |
3084 | } | |
3085 | if (some_failed) | |
3086 | { | |
3087 | for (loc = bpt->loc; loc; loc = loc->next) | |
3088 | if (loc->inserted) | |
834c0d03 | 3089 | remove_breakpoint (loc); |
a5606eee VP |
3090 | |
3091 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3092 | tmp_error_stream.printf ("Could not insert " |
3093 | "hardware watchpoint %d.\n", | |
3094 | bpt->number); | |
eacd795a | 3095 | error_flag = -1; |
a5606eee VP |
3096 | } |
3097 | } | |
3098 | ||
eacd795a | 3099 | if (error_flag) |
81d0cc19 GS |
3100 | { |
3101 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
dda83cd7 | 3102 | message about possibly exhausted resources. */ |
dd61ec5c | 3103 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3104 | { |
d7e74731 | 3105 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3106 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3107 | } |
223ffa71 | 3108 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3109 | error_stream (tmp_error_stream); |
3110 | } | |
c906108c SS |
3111 | } |
3112 | ||
c30eee59 TJB |
3113 | /* Used when the program stops. |
3114 | Returns zero if successful, or non-zero if there was a problem | |
3115 | removing a breakpoint location. */ | |
3116 | ||
c906108c | 3117 | int |
fba45db2 | 3118 | remove_breakpoints (void) |
c906108c | 3119 | { |
35df4500 | 3120 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3121 | int val = 0; |
c906108c | 3122 | |
35df4500 | 3123 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3124 | { |
1e4d1764 | 3125 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3126 | val |= remove_breakpoint (bl); |
c5aa993b | 3127 | } |
3a1bae8e | 3128 | return val; |
c906108c SS |
3129 | } |
3130 | ||
49fa26b0 PA |
3131 | /* When a thread exits, remove breakpoints that are related to |
3132 | that thread. */ | |
3133 | ||
3134 | static void | |
3135 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3136 | { | |
3137 | struct breakpoint *b, *b_tmp; | |
3138 | ||
3139 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3140 | { | |
5d5658a1 | 3141 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3142 | { |
3143 | b->disposition = disp_del_at_next_stop; | |
3144 | ||
3145 | printf_filtered (_("\ | |
43792cf0 PA |
3146 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3147 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3148 | |
3149 | /* Hide it from the user. */ | |
3150 | b->number = 0; | |
3151 | } | |
3152 | } | |
3153 | } | |
3154 | ||
f3869b1a | 3155 | /* See breakpoint.h. */ |
6c95b8df | 3156 | |
f3869b1a | 3157 | void |
00431a78 | 3158 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3159 | { |
35df4500 | 3160 | struct bp_location *bl, **blp_tmp; |
6c95b8df | 3161 | int val; |
6c95b8df | 3162 | |
35df4500 | 3163 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3164 | { |
35df4500 | 3165 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3166 | continue; |
3167 | ||
fc126975 | 3168 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3169 | { |
834c0d03 | 3170 | val = remove_breakpoint (bl); |
6c95b8df | 3171 | if (val != 0) |
f3869b1a | 3172 | return; |
6c95b8df PA |
3173 | } |
3174 | } | |
6c95b8df PA |
3175 | } |
3176 | ||
e58b0e63 PA |
3177 | static int internal_breakpoint_number = -1; |
3178 | ||
84f4c1fe PM |
3179 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3180 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3181 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3182 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3183 | breakpoint_count and that value incremented. Internal breakpoints |
3184 | do not set the internal var bpnum. */ | |
3185 | static void | |
3186 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3187 | { | |
3188 | if (internal) | |
3189 | b->number = internal_breakpoint_number--; | |
3190 | else | |
3191 | { | |
3192 | set_breakpoint_count (breakpoint_count + 1); | |
3193 | b->number = breakpoint_count; | |
3194 | } | |
3195 | } | |
3196 | ||
e62c965a | 3197 | static struct breakpoint * |
a6d9a66e | 3198 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3199 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3200 | const struct breakpoint_ops *ops) |
e62c965a | 3201 | { |
51abb421 | 3202 | symtab_and_line sal; |
e62c965a PP |
3203 | sal.pc = address; |
3204 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3205 | sal.pspace = current_program_space; |
e62c965a | 3206 | |
51abb421 | 3207 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3208 | b->number = internal_breakpoint_number--; |
3209 | b->disposition = disp_donttouch; | |
3210 | ||
3211 | return b; | |
3212 | } | |
3213 | ||
17450429 PP |
3214 | static const char *const longjmp_names[] = |
3215 | { | |
3216 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3217 | }; | |
3218 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3219 | ||
3220 | /* Per-objfile data private to breakpoint.c. */ | |
3221 | struct breakpoint_objfile_data | |
3222 | { | |
3223 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3224 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3225 | |
3226 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3227 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3228 | |
28106bc2 | 3229 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3230 | int longjmp_searched = 0; |
28106bc2 | 3231 | |
45461e0d SM |
3232 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3233 | references. */ | |
3234 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3235 | |
17450429 | 3236 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3237 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3238 | |
3239 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3240 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3241 | |
3242 | /* True if we have looked for exception probes. */ | |
43dce439 | 3243 | int exception_searched = 0; |
28106bc2 | 3244 | |
45461e0d SM |
3245 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3246 | references. */ | |
3247 | std::vector<probe *> exception_probes; | |
17450429 PP |
3248 | }; |
3249 | ||
51d3063a TT |
3250 | static const struct objfile_key<breakpoint_objfile_data> |
3251 | breakpoint_objfile_key; | |
17450429 PP |
3252 | |
3253 | /* Minimal symbol not found sentinel. */ | |
3254 | static struct minimal_symbol msym_not_found; | |
3255 | ||
3256 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3257 | ||
3258 | static int | |
3259 | msym_not_found_p (const struct minimal_symbol *msym) | |
3260 | { | |
3261 | return msym == &msym_not_found; | |
3262 | } | |
3263 | ||
3264 | /* Return per-objfile data needed by breakpoint.c. | |
3265 | Allocate the data if necessary. */ | |
3266 | ||
3267 | static struct breakpoint_objfile_data * | |
3268 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3269 | { | |
3270 | struct breakpoint_objfile_data *bp_objfile_data; | |
3271 | ||
51d3063a | 3272 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3273 | if (bp_objfile_data == NULL) |
51d3063a | 3274 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3275 | return bp_objfile_data; |
3276 | } | |
3277 | ||
e62c965a | 3278 | static void |
af02033e | 3279 | create_overlay_event_breakpoint (void) |
e62c965a | 3280 | { |
af02033e | 3281 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3282 | |
2030c079 | 3283 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3284 | { |
3285 | struct breakpoint *b; | |
17450429 PP |
3286 | struct breakpoint_objfile_data *bp_objfile_data; |
3287 | CORE_ADDR addr; | |
67994074 | 3288 | struct explicit_location explicit_loc; |
69de3c6a | 3289 | |
17450429 PP |
3290 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3291 | ||
3b7344d5 | 3292 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3293 | continue; |
3294 | ||
3b7344d5 | 3295 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3296 | { |
3b7344d5 | 3297 | struct bound_minimal_symbol m; |
17450429 PP |
3298 | |
3299 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3300 | if (m.minsym == NULL) |
17450429 PP |
3301 | { |
3302 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3303 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3304 | continue; |
3305 | } | |
3306 | bp_objfile_data->overlay_msym = m; | |
3307 | } | |
e62c965a | 3308 | |
77e371c0 | 3309 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
08feed99 | 3310 | b = create_internal_breakpoint (objfile->arch (), addr, |
dda83cd7 | 3311 | bp_overlay_event, |
06edf0c0 | 3312 | &internal_breakpoint_ops); |
67994074 KS |
3313 | initialize_explicit_location (&explicit_loc); |
3314 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3315 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3316 | |
69de3c6a | 3317 | if (overlay_debugging == ovly_auto) |
dda83cd7 SM |
3318 | { |
3319 | b->enable_state = bp_enabled; | |
3320 | overlay_events_enabled = 1; | |
3321 | } | |
69de3c6a PP |
3322 | else |
3323 | { | |
dda83cd7 SM |
3324 | b->enable_state = bp_disabled; |
3325 | overlay_events_enabled = 0; | |
69de3c6a | 3326 | } |
e62c965a | 3327 | } |
e62c965a PP |
3328 | } |
3329 | ||
2a7f6487 TV |
3330 | /* Install a master longjmp breakpoint for OBJFILE using a probe. Return |
3331 | true if a breakpoint was installed. */ | |
3332 | ||
3333 | static bool | |
3334 | create_longjmp_master_breakpoint_probe (objfile *objfile) | |
0fd8e87f | 3335 | { |
2a7f6487 TV |
3336 | struct gdbarch *gdbarch = objfile->arch (); |
3337 | struct breakpoint_objfile_data *bp_objfile_data | |
3338 | = get_breakpoint_objfile_data (objfile); | |
0fd8e87f | 3339 | |
2a7f6487 | 3340 | if (!bp_objfile_data->longjmp_searched) |
94c93c35 | 3341 | { |
2a7f6487 TV |
3342 | std::vector<probe *> ret |
3343 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
af02033e | 3344 | |
2a7f6487 | 3345 | if (!ret.empty ()) |
94c93c35 | 3346 | { |
2a7f6487 TV |
3347 | /* We are only interested in checking one element. */ |
3348 | probe *p = ret[0]; | |
0fd8e87f | 3349 | |
2a7f6487 TV |
3350 | if (!p->can_evaluate_arguments ()) |
3351 | { | |
3352 | /* We cannot use the probe interface here, | |
3353 | because it does not know how to evaluate | |
3354 | arguments. */ | |
3355 | ret.clear (); | |
3356 | } | |
3357 | } | |
3358 | bp_objfile_data->longjmp_probes = ret; | |
3359 | bp_objfile_data->longjmp_searched = 1; | |
3360 | } | |
0fd8e87f | 3361 | |
2a7f6487 TV |
3362 | if (bp_objfile_data->longjmp_probes.empty ()) |
3363 | return false; | |
17450429 | 3364 | |
2a7f6487 TV |
3365 | for (probe *p : bp_objfile_data->longjmp_probes) |
3366 | { | |
3367 | struct breakpoint *b; | |
25f9533e | 3368 | |
2a7f6487 TV |
3369 | b = create_internal_breakpoint (gdbarch, |
3370 | p->get_relocated_address (objfile), | |
3371 | bp_longjmp_master, | |
3372 | &internal_breakpoint_ops); | |
3373 | b->location = new_probe_location ("-probe-stap libc:longjmp"); | |
3374 | b->enable_state = bp_disabled; | |
3375 | } | |
aed57c53 | 3376 | |
2a7f6487 TV |
3377 | return true; |
3378 | } | |
25f9533e | 3379 | |
2a7f6487 TV |
3380 | /* Install master longjmp breakpoints for OBJFILE using longjmp_names. |
3381 | Return true if at least one breakpoint was installed. */ | |
3382 | ||
3383 | static bool | |
3384 | create_longjmp_master_breakpoint_names (objfile *objfile) | |
3385 | { | |
3386 | struct gdbarch *gdbarch = objfile->arch (); | |
3387 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
3388 | return false; | |
3389 | ||
3390 | struct breakpoint_objfile_data *bp_objfile_data | |
3391 | = get_breakpoint_objfile_data (objfile); | |
3392 | unsigned int installed_bp = 0; | |
3393 | ||
3394 | for (int i = 0; i < NUM_LONGJMP_NAMES; i++) | |
3395 | { | |
3396 | struct breakpoint *b; | |
3397 | const char *func_name; | |
3398 | CORE_ADDR addr; | |
3399 | struct explicit_location explicit_loc; | |
3400 | ||
3401 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) | |
3402 | continue; | |
28106bc2 | 3403 | |
2a7f6487 TV |
3404 | func_name = longjmp_names[i]; |
3405 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3406 | { | |
3407 | struct bound_minimal_symbol m; | |
3408 | ||
3409 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3410 | if (m.minsym == NULL) | |
3411 | { | |
3412 | /* Prevent future lookups in this objfile. */ | |
3413 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
94c93c35 TT |
3414 | continue; |
3415 | } | |
2a7f6487 TV |
3416 | bp_objfile_data->longjmp_msym[i] = m; |
3417 | } | |
28106bc2 | 3418 | |
2a7f6487 TV |
3419 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
3420 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, | |
3421 | &internal_breakpoint_ops); | |
3422 | initialize_explicit_location (&explicit_loc); | |
3423 | explicit_loc.function_name = ASTRDUP (func_name); | |
3424 | b->location = new_explicit_location (&explicit_loc); | |
3425 | b->enable_state = bp_disabled; | |
3426 | installed_bp++; | |
3427 | } | |
28106bc2 | 3428 | |
2a7f6487 TV |
3429 | return installed_bp > 0; |
3430 | } | |
0fd8e87f | 3431 | |
2a7f6487 | 3432 | /* Create a master longjmp breakpoint. */ |
17450429 | 3433 | |
2a7f6487 TV |
3434 | static void |
3435 | create_longjmp_master_breakpoint (void) | |
3436 | { | |
3437 | scoped_restore_current_program_space restore_pspace; | |
aed57c53 | 3438 | |
2a7f6487 TV |
3439 | for (struct program_space *pspace : program_spaces) |
3440 | { | |
3441 | set_current_program_space (pspace); | |
17450429 | 3442 | |
2a7f6487 TV |
3443 | for (objfile *obj : current_program_space->objfiles ()) |
3444 | { | |
3445 | /* Skip separate debug object, it's handled in the loop below. */ | |
3446 | if (obj->separate_debug_objfile_backlink != nullptr) | |
3447 | continue; | |
3448 | ||
3449 | /* Try a probe kind breakpoint on main objfile. */ | |
3450 | if (create_longjmp_master_breakpoint_probe (obj)) | |
3451 | continue; | |
3452 | ||
3453 | /* Try longjmp_names kind breakpoints on main and separate_debug | |
3454 | objfiles. */ | |
3455 | for (objfile *debug_objfile : obj->separate_debug_objfiles ()) | |
3456 | if (create_longjmp_master_breakpoint_names (debug_objfile)) | |
3457 | break; | |
94c93c35 TT |
3458 | } |
3459 | } | |
0fd8e87f UW |
3460 | } |
3461 | ||
af02033e | 3462 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3463 | static void |
af02033e | 3464 | create_std_terminate_master_breakpoint (void) |
aa7d318d | 3465 | { |
af02033e | 3466 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3467 | |
5ed8105e | 3468 | scoped_restore_current_program_space restore_pspace; |
aa7d318d | 3469 | |
94c93c35 TT |
3470 | for (struct program_space *pspace : program_spaces) |
3471 | { | |
3472 | CORE_ADDR addr; | |
17450429 | 3473 | |
94c93c35 | 3474 | set_current_program_space (pspace); |
17450429 | 3475 | |
94c93c35 TT |
3476 | for (objfile *objfile : current_program_space->objfiles ()) |
3477 | { | |
3478 | struct breakpoint *b; | |
3479 | struct breakpoint_objfile_data *bp_objfile_data; | |
3480 | struct explicit_location explicit_loc; | |
aa7d318d | 3481 | |
94c93c35 | 3482 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3483 | |
94c93c35 TT |
3484 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3485 | continue; | |
17450429 | 3486 | |
94c93c35 TT |
3487 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3488 | { | |
3489 | struct bound_minimal_symbol m; | |
17450429 | 3490 | |
94c93c35 TT |
3491 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
3492 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text | |
3493 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
3494 | { | |
3495 | /* Prevent future lookups in this objfile. */ | |
3496 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3497 | continue; | |
3498 | } | |
3499 | bp_objfile_data->terminate_msym = m; | |
3500 | } | |
aa7d318d | 3501 | |
94c93c35 TT |
3502 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3503 | b = create_internal_breakpoint (objfile->arch (), addr, | |
3504 | bp_std_terminate_master, | |
3505 | &internal_breakpoint_ops); | |
3506 | initialize_explicit_location (&explicit_loc); | |
3507 | explicit_loc.function_name = ASTRDUP (func_name); | |
3508 | b->location = new_explicit_location (&explicit_loc); | |
3509 | b->enable_state = bp_disabled; | |
3510 | } | |
3511 | } | |
aa7d318d TT |
3512 | } |
3513 | ||
1940319c TV |
3514 | /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a |
3515 | probe. Return true if a breakpoint was installed. */ | |
186c406b | 3516 | |
1940319c TV |
3517 | static bool |
3518 | create_exception_master_breakpoint_probe (objfile *objfile) | |
186c406b | 3519 | { |
1940319c TV |
3520 | struct breakpoint *b; |
3521 | struct gdbarch *gdbarch; | |
3522 | struct breakpoint_objfile_data *bp_objfile_data; | |
186c406b | 3523 | |
1940319c | 3524 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3525 | |
1940319c TV |
3526 | /* We prefer the SystemTap probe point if it exists. */ |
3527 | if (!bp_objfile_data->exception_searched) | |
3528 | { | |
3529 | std::vector<probe *> ret | |
3530 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
17450429 | 3531 | |
1940319c | 3532 | if (!ret.empty ()) |
28106bc2 | 3533 | { |
1940319c TV |
3534 | /* We are only interested in checking one element. */ |
3535 | probe *p = ret[0]; | |
25f9533e | 3536 | |
1940319c | 3537 | if (!p->can_evaluate_arguments ()) |
25f9533e | 3538 | { |
1940319c TV |
3539 | /* We cannot use the probe interface here, because it does |
3540 | not know how to evaluate arguments. */ | |
3541 | ret.clear (); | |
25f9533e | 3542 | } |
28106bc2 | 3543 | } |
1940319c TV |
3544 | bp_objfile_data->exception_probes = ret; |
3545 | bp_objfile_data->exception_searched = 1; | |
3546 | } | |
28106bc2 | 3547 | |
1940319c TV |
3548 | if (bp_objfile_data->exception_probes.empty ()) |
3549 | return false; | |
45461e0d | 3550 | |
1940319c | 3551 | gdbarch = objfile->arch (); |
28106bc2 | 3552 | |
1940319c TV |
3553 | for (probe *p : bp_objfile_data->exception_probes) |
3554 | { | |
3555 | b = create_internal_breakpoint (gdbarch, | |
3556 | p->get_relocated_address (objfile), | |
3557 | bp_exception_master, | |
3558 | &internal_breakpoint_ops); | |
3559 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); | |
3560 | b->enable_state = bp_disabled; | |
3561 | } | |
28106bc2 | 3562 | |
1940319c TV |
3563 | return true; |
3564 | } | |
28106bc2 | 3565 | |
1940319c TV |
3566 | /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using |
3567 | _Unwind_DebugHook. Return true if a breakpoint was installed. */ | |
17450429 | 3568 | |
1940319c TV |
3569 | static bool |
3570 | create_exception_master_breakpoint_hook (objfile *objfile) | |
3571 | { | |
3572 | const char *const func_name = "_Unwind_DebugHook"; | |
3573 | struct breakpoint *b; | |
3574 | struct gdbarch *gdbarch; | |
3575 | struct breakpoint_objfile_data *bp_objfile_data; | |
3576 | CORE_ADDR addr; | |
3577 | struct explicit_location explicit_loc; | |
186c406b | 3578 | |
1940319c | 3579 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
186c406b | 3580 | |
1940319c TV |
3581 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
3582 | return false; | |
17450429 | 3583 | |
1940319c TV |
3584 | gdbarch = objfile->arch (); |
3585 | ||
3586 | if (bp_objfile_data->exception_msym.minsym == NULL) | |
3587 | { | |
3588 | struct bound_minimal_symbol debug_hook; | |
3589 | ||
3590 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); | |
3591 | if (debug_hook.minsym == NULL) | |
3592 | { | |
3593 | bp_objfile_data->exception_msym.minsym = &msym_not_found; | |
3594 | return false; | |
186c406b | 3595 | } |
17450429 | 3596 | |
1940319c TV |
3597 | bp_objfile_data->exception_msym = debug_hook; |
3598 | } | |
3599 | ||
3600 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
3601 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
3602 | current_top_target ()); | |
3603 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, | |
3604 | &internal_breakpoint_ops); | |
3605 | initialize_explicit_location (&explicit_loc); | |
3606 | explicit_loc.function_name = ASTRDUP (func_name); | |
3607 | b->location = new_explicit_location (&explicit_loc); | |
3608 | b->enable_state = bp_disabled; | |
3609 | ||
3610 | return true; | |
3611 | } | |
3612 | ||
3613 | /* Install a master breakpoint on the unwinder's debug hook. */ | |
3614 | ||
3615 | static void | |
3616 | create_exception_master_breakpoint (void) | |
3617 | { | |
3618 | for (objfile *obj : current_program_space->objfiles ()) | |
3619 | { | |
3620 | /* Skip separate debug object. */ | |
3621 | if (obj->separate_debug_objfile_backlink) | |
3622 | continue; | |
3623 | ||
3624 | /* Try a probe kind breakpoint. */ | |
3625 | if (create_exception_master_breakpoint_probe (obj)) | |
3626 | continue; | |
3627 | ||
3628 | /* Iterate over separate debug objects and try an _Unwind_DebugHook | |
3629 | kind breakpoint. */ | |
3630 | for (objfile *sepdebug = obj->separate_debug_objfile; | |
3631 | sepdebug != nullptr; sepdebug = sepdebug->separate_debug_objfile) | |
3632 | if (create_exception_master_breakpoint_hook (sepdebug)) | |
3633 | break; | |
186c406b | 3634 | } |
186c406b TT |
3635 | } |
3636 | ||
9ef9e6a6 KS |
3637 | /* Does B have a location spec? */ |
3638 | ||
3639 | static int | |
3640 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3641 | { | |
d28cd78a | 3642 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3643 | } |
3644 | ||
c906108c | 3645 | void |
fba45db2 | 3646 | update_breakpoints_after_exec (void) |
c906108c | 3647 | { |
35df4500 | 3648 | struct breakpoint *b, *b_tmp; |
876fa593 | 3649 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3650 | |
25b22b0a PA |
3651 | /* We're about to delete breakpoints from GDB's lists. If the |
3652 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3653 | writing the breakpoints' "shadow contents" back into memory. The | |
3654 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3655 | do that. Instead, the target is responsible from marking | |
3656 | breakpoints out as soon as it detects an exec. We don't do that | |
3657 | here instead, because there may be other attempts to delete | |
3658 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3659 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3660 | if (bploc->pspace == current_program_space) |
3661 | gdb_assert (!bploc->inserted); | |
c906108c | 3662 | |
35df4500 | 3663 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3664 | { |
6c95b8df PA |
3665 | if (b->pspace != current_program_space) |
3666 | continue; | |
3667 | ||
4a64f543 | 3668 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3669 | if (b->type == bp_shlib_event) |
3670 | { | |
3671 | delete_breakpoint (b); | |
3672 | continue; | |
3673 | } | |
c906108c | 3674 | |
4a64f543 | 3675 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3676 | if (b->type == bp_jit_event) |
3677 | { | |
3678 | delete_breakpoint (b); | |
3679 | continue; | |
3680 | } | |
3681 | ||
1900040c | 3682 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3683 | as must overlay event and longjmp master breakpoints. */ |
3684 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3685 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3686 | || b->type == bp_exception_master) | |
c4093a6a JM |
3687 | { |
3688 | delete_breakpoint (b); | |
3689 | continue; | |
3690 | } | |
3691 | ||
4a64f543 | 3692 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3693 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3694 | { |
3695 | delete_breakpoint (b); | |
3696 | continue; | |
3697 | } | |
3698 | ||
7c16b83e PA |
3699 | /* Just like single-step breakpoints. */ |
3700 | if (b->type == bp_single_step) | |
3701 | { | |
3702 | delete_breakpoint (b); | |
3703 | continue; | |
3704 | } | |
3705 | ||
611c83ae PA |
3706 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3707 | after an exec. */ | |
186c406b | 3708 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3709 | || b->type == bp_longjmp_call_dummy |
186c406b | 3710 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3711 | { |
3712 | delete_breakpoint (b); | |
3713 | continue; | |
3714 | } | |
3715 | ||
ce78b96d JB |
3716 | if (b->type == bp_catchpoint) |
3717 | { | |
dda83cd7 SM |
3718 | /* For now, none of the bp_catchpoint breakpoints need to |
3719 | do anything at this point. In the future, if some of | |
3720 | the catchpoints need to something, we will need to add | |
3721 | a new method, and call this method from here. */ | |
3722 | continue; | |
ce78b96d JB |
3723 | } |
3724 | ||
c5aa993b JM |
3725 | /* bp_finish is a special case. The only way we ought to be able |
3726 | to see one of these when an exec() has happened, is if the user | |
3727 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3728 | carries them to the call-site of the current callee, by setting | |
3729 | a temporary bp there and resuming. But in this case, the finish | |
3730 | will carry them entirely through the vfork & exec. | |
3731 | ||
3732 | We don't want to allow a bp_finish to remain inserted now. But | |
3733 | we can't safely delete it, 'cause finish_command has a handle to | |
3734 | the bp on a bpstat, and will later want to delete it. There's a | |
3735 | chance (and I've seen it happen) that if we delete the bp_finish | |
3736 | here, that its storage will get reused by the time finish_command | |
3737 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3738 | We really must allow finish_command to delete a bp_finish. | |
3739 | ||
e5dd4106 | 3740 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3741 | it's safe to delete something others may have handles to?" |
3742 | problem, what we'll do here is just uninsert the bp_finish, and | |
3743 | let finish_command delete it. | |
3744 | ||
3745 | (We know the bp_finish is "doomed" in the sense that it's | |
3746 | momentary, and will be deleted as soon as finish_command sees | |
3747 | the inferior stopped. So it doesn't matter that the bp's | |
3748 | address is probably bogus in the new a.out, unlike e.g., the | |
3749 | solib breakpoints.) */ | |
c5aa993b | 3750 | |
c5aa993b JM |
3751 | if (b->type == bp_finish) |
3752 | { | |
3753 | continue; | |
3754 | } | |
3755 | ||
3756 | /* Without a symbolic address, we have little hope of the | |
3757 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3758 | a.out. */ |
9ef9e6a6 | 3759 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3760 | { |
3761 | delete_breakpoint (b); | |
3762 | continue; | |
3763 | } | |
c5aa993b | 3764 | } |
c906108c SS |
3765 | } |
3766 | ||
3767 | int | |
d80ee84f | 3768 | detach_breakpoints (ptid_t ptid) |
c906108c | 3769 | { |
35df4500 | 3770 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3771 | int val = 0; |
2989a365 | 3772 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3773 | struct inferior *inf = current_inferior (); |
c5aa993b | 3774 | |
e99b03dc | 3775 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3776 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3777 | |
6c95b8df | 3778 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3779 | inferior_ptid = ptid; |
35df4500 | 3780 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3781 | { |
35df4500 | 3782 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3783 | continue; |
3784 | ||
bd9673a4 PW |
3785 | /* This function must physically remove breakpoints locations |
3786 | from the specified ptid, without modifying the breakpoint | |
3787 | package's state. Locations of type bp_loc_other are only | |
3788 | maintained at GDB side. So, there is no need to remove | |
3789 | these bp_loc_other locations. Moreover, removing these | |
3790 | would modify the breakpoint package's state. */ | |
3791 | if (bl->loc_type == bp_loc_other) | |
3792 | continue; | |
3793 | ||
35df4500 | 3794 | if (bl->inserted) |
b2b6a7da | 3795 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3796 | } |
d03285ec | 3797 | |
3a1bae8e | 3798 | return val; |
c906108c SS |
3799 | } |
3800 | ||
35df4500 | 3801 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3802 | Note that this is used to detach breakpoints from a child fork. |
3803 | When we get here, the child isn't in the inferior list, and neither | |
3804 | do we have objects to represent its address space --- we should | |
35df4500 | 3805 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3806 | |
c906108c | 3807 | static int |
b2b6a7da | 3808 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3809 | { |
3810 | int val; | |
c5aa993b | 3811 | |
35df4500 TJB |
3812 | /* BL is never in moribund_locations by our callers. */ |
3813 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3814 | |
74960c60 VP |
3815 | /* The type of none suggests that owner is actually deleted. |
3816 | This should not ever happen. */ | |
35df4500 | 3817 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3818 | |
35df4500 TJB |
3819 | if (bl->loc_type == bp_loc_software_breakpoint |
3820 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3821 | { |
c02f5703 MS |
3822 | /* "Normal" instruction breakpoint: either the standard |
3823 | trap-instruction bp (bp_breakpoint), or a | |
3824 | bp_hardware_breakpoint. */ | |
3825 | ||
3826 | /* First check to see if we have to handle an overlay. */ | |
3827 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3828 | || bl->section == NULL |
3829 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3830 | { |
3831 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3832 | |
3833 | /* If we're trying to uninsert a memory breakpoint that we | |
3834 | know is set in a dynamic object that is marked | |
3835 | shlib_disabled, then either the dynamic object was | |
3836 | removed with "remove-symbol-file" or with | |
3837 | "nosharedlibrary". In the former case, we don't know | |
3838 | whether another dynamic object might have loaded over the | |
3839 | breakpoint's address -- the user might well let us know | |
3840 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3841 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3842 | list of dynamically loaded objects). If we have the |
3843 | breakpoint's shadow memory, that is, this is a software | |
3844 | breakpoint managed by GDB, check whether the breakpoint | |
3845 | is still inserted in memory, to avoid overwriting wrong | |
3846 | code with stale saved shadow contents. Note that HW | |
3847 | breakpoints don't have shadow memory, as they're | |
3848 | implemented using a mechanism that is not dependent on | |
3849 | being able to modify the target's memory, and as such | |
3850 | they should always be removed. */ | |
3851 | if (bl->shlib_disabled | |
3852 | && bl->target_info.shadow_len != 0 | |
3853 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3854 | val = 0; | |
3855 | else | |
73971819 | 3856 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3857 | } |
c906108c SS |
3858 | else |
3859 | { | |
4a64f543 | 3860 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3861 | Did we set a breakpoint at the LMA? */ |
3862 | if (!overlay_events_enabled) | |
3863 | { | |
3864 | /* Yes -- overlay event support is not active, so we | |
3865 | should have set a breakpoint at the LMA. Remove it. | |
3866 | */ | |
c02f5703 MS |
3867 | /* Ignore any failures: if the LMA is in ROM, we will |
3868 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3869 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3870 | target_remove_hw_breakpoint (bl->gdbarch, | |
3871 | &bl->overlay_target_info); | |
c02f5703 | 3872 | else |
35df4500 | 3873 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3874 | &bl->overlay_target_info, |
3875 | reason); | |
c02f5703 MS |
3876 | } |
3877 | /* Did we set a breakpoint at the VMA? | |
3878 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3879 | if (bl->inserted) |
c906108c | 3880 | { |
c02f5703 MS |
3881 | /* Yes -- remove it. Previously we did not bother to |
3882 | remove the breakpoint if the section had been | |
3883 | unmapped, but let's not rely on that being safe. We | |
3884 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3885 | |
3886 | /* However, we should remove *software* breakpoints only | |
3887 | if the section is still mapped, or else we overwrite | |
3888 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3889 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3890 | || section_is_mapped (bl->section)) | |
73971819 | 3891 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3892 | else |
3893 | val = 0; | |
c906108c | 3894 | } |
c02f5703 MS |
3895 | else |
3896 | { | |
3897 | /* No -- not inserted, so no need to remove. No error. */ | |
3898 | val = 0; | |
3899 | } | |
c906108c | 3900 | } |
879d1e6b | 3901 | |
08351840 PA |
3902 | /* In some cases, we might not be able to remove a breakpoint in |
3903 | a shared library that has already been removed, but we have | |
3904 | not yet processed the shlib unload event. Similarly for an | |
3905 | unloaded add-symbol-file object - the user might not yet have | |
3906 | had the chance to remove-symbol-file it. shlib_disabled will | |
3907 | be set if the library/object has already been removed, but | |
3908 | the breakpoint hasn't been uninserted yet, e.g., after | |
3909 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3910 | always-inserted mode. */ | |
076855f9 | 3911 | if (val |
08351840 PA |
3912 | && (bl->loc_type == bp_loc_software_breakpoint |
3913 | && (bl->shlib_disabled | |
3914 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3915 | || shared_objfile_contains_address_p (bl->pspace, |
3916 | bl->address)))) | |
879d1e6b UW |
3917 | val = 0; |
3918 | ||
c906108c SS |
3919 | if (val) |
3920 | return val; | |
b2b6a7da | 3921 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3922 | } |
35df4500 | 3923 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3924 | { |
77b06cd7 TJB |
3925 | gdb_assert (bl->owner->ops != NULL |
3926 | && bl->owner->ops->remove_location != NULL); | |
3927 | ||
b2b6a7da | 3928 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3929 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3930 | |
c906108c | 3931 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3932 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3933 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3934 | bl->owner->number); |
c906108c | 3935 | } |
35df4500 | 3936 | else if (bl->owner->type == bp_catchpoint |
dda83cd7 SM |
3937 | && breakpoint_enabled (bl->owner) |
3938 | && !bl->duplicate) | |
ce78b96d | 3939 | { |
77b06cd7 TJB |
3940 | gdb_assert (bl->owner->ops != NULL |
3941 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3942 | |
73971819 | 3943 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3944 | if (val) |
3945 | return val; | |
77b06cd7 | 3946 | |
b2b6a7da | 3947 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3948 | } |
c906108c SS |
3949 | |
3950 | return 0; | |
3951 | } | |
3952 | ||
6c95b8df | 3953 | static int |
834c0d03 | 3954 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3955 | { |
35df4500 TJB |
3956 | /* BL is never in moribund_locations by our callers. */ |
3957 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3958 | |
6c95b8df PA |
3959 | /* The type of none suggests that owner is actually deleted. |
3960 | This should not ever happen. */ | |
35df4500 | 3961 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3962 | |
5ed8105e | 3963 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3964 | |
35df4500 | 3965 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3966 | |
5ed8105e | 3967 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3968 | } |
3969 | ||
c906108c SS |
3970 | /* Clear the "inserted" flag in all breakpoints. */ |
3971 | ||
25b22b0a | 3972 | void |
fba45db2 | 3973 | mark_breakpoints_out (void) |
c906108c | 3974 | { |
35df4500 | 3975 | struct bp_location *bl, **blp_tmp; |
c906108c | 3976 | |
35df4500 | 3977 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3978 | if (bl->pspace == current_program_space) |
35df4500 | 3979 | bl->inserted = 0; |
c906108c SS |
3980 | } |
3981 | ||
53a5351d JM |
3982 | /* Clear the "inserted" flag in all breakpoints and delete any |
3983 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3984 | |
3985 | Plus other such housekeeping that has to be done for breakpoints | |
3986 | between runs. | |
3987 | ||
53a5351d JM |
3988 | Note: this function gets called at the end of a run (by |
3989 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3990 | init_wait_for_inferior). */ |
c906108c SS |
3991 | |
3992 | ||
3993 | ||
3994 | void | |
fba45db2 | 3995 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3996 | { |
35df4500 | 3997 | struct breakpoint *b, *b_tmp; |
6c95b8df | 3998 | struct program_space *pspace = current_program_space; |
c906108c | 3999 | |
50c71eaf PA |
4000 | /* If breakpoint locations are shared across processes, then there's |
4001 | nothing to do. */ | |
f5656ead | 4002 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4003 | return; |
4004 | ||
1a853c52 | 4005 | mark_breakpoints_out (); |
075f6582 | 4006 | |
35df4500 | 4007 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4008 | { |
6c95b8df PA |
4009 | if (b->loc && b->loc->pspace != pspace) |
4010 | continue; | |
4011 | ||
c5aa993b JM |
4012 | switch (b->type) |
4013 | { | |
4014 | case bp_call_dummy: | |
e2e4d78b | 4015 | case bp_longjmp_call_dummy: |
c906108c | 4016 | |
c5aa993b | 4017 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4018 | cause problems when the inferior is rerun, so we better get |
4019 | rid of it. */ | |
4020 | ||
4021 | case bp_watchpoint_scope: | |
4022 | ||
4023 | /* Also get rid of scope breakpoints. */ | |
4024 | ||
4025 | case bp_shlib_event: | |
4026 | ||
4027 | /* Also remove solib event breakpoints. Their addresses may | |
4028 | have changed since the last time we ran the program. | |
4029 | Actually we may now be debugging against different target; | |
4030 | and so the solib backend that installed this breakpoint may | |
4031 | not be used in by the target. E.g., | |
4032 | ||
4033 | (gdb) file prog-linux | |
4034 | (gdb) run # native linux target | |
4035 | ... | |
4036 | (gdb) kill | |
4037 | (gdb) file prog-win.exe | |
4038 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4039 | */ | |
c906108c | 4040 | |
f59f708a PA |
4041 | case bp_step_resume: |
4042 | ||
4043 | /* Also remove step-resume breakpoints. */ | |
4044 | ||
7c16b83e PA |
4045 | case bp_single_step: |
4046 | ||
4047 | /* Also remove single-step breakpoints. */ | |
4048 | ||
c5aa993b JM |
4049 | delete_breakpoint (b); |
4050 | break; | |
c906108c | 4051 | |
c5aa993b JM |
4052 | case bp_watchpoint: |
4053 | case bp_hardware_watchpoint: | |
4054 | case bp_read_watchpoint: | |
4055 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4056 | { |
4057 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4058 | |
3a5c3e22 PA |
4059 | /* Likewise for watchpoints on local expressions. */ |
4060 | if (w->exp_valid_block != NULL) | |
4061 | delete_breakpoint (b); | |
63000888 | 4062 | else |
3a5c3e22 | 4063 | { |
63000888 PA |
4064 | /* Get rid of existing locations, which are no longer |
4065 | valid. New ones will be created in | |
4066 | update_watchpoint, when the inferior is restarted. | |
4067 | The next update_global_location_list call will | |
4068 | garbage collect them. */ | |
4069 | b->loc = NULL; | |
4070 | ||
4071 | if (context == inf_starting) | |
4072 | { | |
4073 | /* Reset val field to force reread of starting value in | |
4074 | insert_breakpoints. */ | |
850645cf | 4075 | w->val.reset (nullptr); |
4c1d86d9 | 4076 | w->val_valid = false; |
63000888 PA |
4077 | } |
4078 | } | |
3a5c3e22 | 4079 | } |
c5aa993b JM |
4080 | break; |
4081 | default: | |
c5aa993b JM |
4082 | break; |
4083 | } | |
4084 | } | |
1c5cfe86 PA |
4085 | |
4086 | /* Get rid of the moribund locations. */ | |
1123588c | 4087 | for (bp_location *bl : moribund_locations) |
35df4500 | 4088 | decref_bp_location (&bl); |
1123588c | 4089 | moribund_locations.clear (); |
c906108c SS |
4090 | } |
4091 | ||
6c95b8df PA |
4092 | /* These functions concern about actual breakpoints inserted in the |
4093 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4094 | we need to hop over the bkpt --- so we check for address space | |
4095 | match, not program space. */ | |
4096 | ||
c2c6d25f JM |
4097 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4098 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4099 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4100 | permanent breakpoint. | |
4101 | - When continuing from a location with an ordinary breakpoint, we | |
4102 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4103 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4104 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4105 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4106 | |
c2c6d25f | 4107 | enum breakpoint_here |
accd0bcd | 4108 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4109 | { |
35df4500 | 4110 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4111 | int any_breakpoint_here = 0; |
c906108c | 4112 | |
35df4500 | 4113 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4114 | { |
35df4500 TJB |
4115 | if (bl->loc_type != bp_loc_software_breakpoint |
4116 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4117 | continue; |
4118 | ||
f1310107 | 4119 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4120 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4121 | || bl->permanent) |
f1310107 | 4122 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4123 | { |
4124 | if (overlay_debugging | |
35df4500 TJB |
4125 | && section_is_overlay (bl->section) |
4126 | && !section_is_mapped (bl->section)) | |
075f6582 | 4127 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4128 | else if (bl->permanent) |
075f6582 DJ |
4129 | return permanent_breakpoint_here; |
4130 | else | |
4131 | any_breakpoint_here = 1; | |
4132 | } | |
4133 | } | |
c906108c | 4134 | |
f486487f | 4135 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4136 | } |
4137 | ||
d35ae833 PA |
4138 | /* See breakpoint.h. */ |
4139 | ||
4140 | int | |
accd0bcd | 4141 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
4142 | CORE_ADDR addr, ULONGEST len) |
4143 | { | |
4144 | struct bp_location *bl, **blp_tmp; | |
4145 | ||
4146 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4147 | { | |
4148 | if (bl->loc_type != bp_loc_software_breakpoint | |
4149 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4150 | continue; | |
4151 | ||
4152 | if ((breakpoint_enabled (bl->owner) | |
4153 | || bl->permanent) | |
4154 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4155 | addr, len)) | |
4156 | { | |
4157 | if (overlay_debugging | |
4158 | && section_is_overlay (bl->section) | |
4159 | && !section_is_mapped (bl->section)) | |
4160 | { | |
4161 | /* Unmapped overlay -- can't be a match. */ | |
4162 | continue; | |
4163 | } | |
4164 | ||
4165 | return 1; | |
4166 | } | |
4167 | } | |
4168 | ||
4169 | return 0; | |
4170 | } | |
4171 | ||
1c5cfe86 PA |
4172 | /* Return true if there's a moribund breakpoint at PC. */ |
4173 | ||
4174 | int | |
accd0bcd | 4175 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 4176 | { |
1123588c | 4177 | for (bp_location *loc : moribund_locations) |
f1310107 | 4178 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4179 | return 1; |
4180 | ||
4181 | return 0; | |
4182 | } | |
c2c6d25f | 4183 | |
f7ce857f PA |
4184 | /* Returns non-zero iff BL is inserted at PC, in address space |
4185 | ASPACE. */ | |
4186 | ||
4187 | static int | |
4188 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4189 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4190 | { |
4191 | if (bl->inserted | |
4192 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4193 | aspace, pc)) | |
4194 | { | |
4195 | if (overlay_debugging | |
4196 | && section_is_overlay (bl->section) | |
4197 | && !section_is_mapped (bl->section)) | |
4198 | return 0; /* unmapped overlay -- can't be a match */ | |
4199 | else | |
4200 | return 1; | |
4201 | } | |
4202 | return 0; | |
4203 | } | |
4204 | ||
a1fd2fa5 | 4205 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4206 | |
4207 | int | |
accd0bcd | 4208 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4209 | { |
f7ce857f | 4210 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4211 | |
f7ce857f | 4212 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4213 | { |
f7ce857f PA |
4214 | struct bp_location *bl = *blp; |
4215 | ||
35df4500 TJB |
4216 | if (bl->loc_type != bp_loc_software_breakpoint |
4217 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4218 | continue; |
4219 | ||
f7ce857f PA |
4220 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4221 | return 1; | |
c5aa993b | 4222 | } |
c36b740a VP |
4223 | return 0; |
4224 | } | |
4225 | ||
a1fd2fa5 PA |
4226 | /* This function returns non-zero iff there is a software breakpoint |
4227 | inserted at PC. */ | |
c36b740a VP |
4228 | |
4229 | int | |
accd0bcd | 4230 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4231 | CORE_ADDR pc) |
4fa8626c | 4232 | { |
f7ce857f | 4233 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4234 | |
f7ce857f | 4235 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4236 | { |
f7ce857f PA |
4237 | struct bp_location *bl = *blp; |
4238 | ||
35df4500 | 4239 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4240 | continue; |
4241 | ||
f7ce857f PA |
4242 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4243 | return 1; | |
4fa8626c DJ |
4244 | } |
4245 | ||
4246 | return 0; | |
9c02b525 PA |
4247 | } |
4248 | ||
4249 | /* See breakpoint.h. */ | |
4250 | ||
4251 | int | |
accd0bcd | 4252 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4253 | CORE_ADDR pc) |
4254 | { | |
4255 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4256 | |
4257 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4258 | { | |
4259 | struct bp_location *bl = *blp; | |
4260 | ||
4261 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4262 | continue; | |
4263 | ||
4264 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4265 | return 1; | |
4266 | } | |
4267 | ||
4268 | return 0; | |
4fa8626c DJ |
4269 | } |
4270 | ||
9093389c | 4271 | int |
accd0bcd | 4272 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4273 | CORE_ADDR addr, ULONGEST len) |
4274 | { | |
4275 | struct breakpoint *bpt; | |
4276 | ||
4277 | ALL_BREAKPOINTS (bpt) | |
4278 | { | |
4279 | struct bp_location *loc; | |
4280 | ||
4281 | if (bpt->type != bp_hardware_watchpoint | |
4282 | && bpt->type != bp_access_watchpoint) | |
4283 | continue; | |
4284 | ||
4285 | if (!breakpoint_enabled (bpt)) | |
4286 | continue; | |
4287 | ||
4288 | for (loc = bpt->loc; loc; loc = loc->next) | |
4289 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4290 | { | |
4291 | CORE_ADDR l, h; | |
4292 | ||
4293 | /* Check for intersection. */ | |
768adc05 PA |
4294 | l = std::max<CORE_ADDR> (loc->address, addr); |
4295 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4296 | if (l < h) |
4297 | return 1; | |
4298 | } | |
4299 | } | |
4300 | return 0; | |
4301 | } | |
c5aa993b | 4302 | |
f2478a7e | 4303 | /* See breakpoint.h. */ |
c906108c | 4304 | |
f2478a7e SM |
4305 | bool |
4306 | is_catchpoint (struct breakpoint *b) | |
c906108c | 4307 | { |
f2478a7e | 4308 | return (b->type == bp_catchpoint); |
c906108c SS |
4309 | } |
4310 | ||
c906108c SS |
4311 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4312 | Also free any storage that is part of a bpstat. */ | |
4313 | ||
4314 | void | |
fba45db2 | 4315 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4316 | { |
4317 | bpstat p; | |
4318 | bpstat q; | |
4319 | ||
4320 | if (bsp == 0) | |
4321 | return; | |
4322 | p = *bsp; | |
4323 | while (p != NULL) | |
4324 | { | |
4325 | q = p->next; | |
04afa70c | 4326 | delete p; |
c906108c SS |
4327 | p = q; |
4328 | } | |
4329 | *bsp = NULL; | |
4330 | } | |
4331 | ||
04afa70c TT |
4332 | bpstats::bpstats (const bpstats &other) |
4333 | : next (NULL), | |
4334 | bp_location_at (other.bp_location_at), | |
4335 | breakpoint_at (other.breakpoint_at), | |
4336 | commands (other.commands), | |
04afa70c TT |
4337 | print (other.print), |
4338 | stop (other.stop), | |
4339 | print_it (other.print_it) | |
4340 | { | |
850645cf TT |
4341 | if (other.old_val != NULL) |
4342 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c TT |
4343 | } |
4344 | ||
c906108c SS |
4345 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4346 | is part of the bpstat is copied as well. */ | |
4347 | ||
4348 | bpstat | |
fba45db2 | 4349 | bpstat_copy (bpstat bs) |
c906108c SS |
4350 | { |
4351 | bpstat p = NULL; | |
4352 | bpstat tmp; | |
4353 | bpstat retval = NULL; | |
4354 | ||
4355 | if (bs == NULL) | |
4356 | return bs; | |
4357 | ||
4358 | for (; bs != NULL; bs = bs->next) | |
4359 | { | |
04afa70c | 4360 | tmp = new bpstats (*bs); |
31cc81e9 | 4361 | |
c906108c SS |
4362 | if (p == NULL) |
4363 | /* This is the first thing in the chain. */ | |
4364 | retval = tmp; | |
4365 | else | |
4366 | p->next = tmp; | |
4367 | p = tmp; | |
4368 | } | |
4369 | p->next = NULL; | |
4370 | return retval; | |
4371 | } | |
4372 | ||
4a64f543 | 4373 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4374 | |
4375 | bpstat | |
fba45db2 | 4376 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4377 | { |
c5aa993b JM |
4378 | if (bsp == NULL) |
4379 | return NULL; | |
c906108c | 4380 | |
c5aa993b JM |
4381 | for (; bsp != NULL; bsp = bsp->next) |
4382 | { | |
f431efe5 | 4383 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4384 | return bsp; |
4385 | } | |
c906108c SS |
4386 | return NULL; |
4387 | } | |
4388 | ||
ab04a2af TT |
4389 | /* See breakpoint.h. */ |
4390 | ||
4c462cb0 | 4391 | bool |
427cd150 | 4392 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4393 | { |
ab04a2af TT |
4394 | for (; bsp != NULL; bsp = bsp->next) |
4395 | { | |
427cd150 TT |
4396 | if (bsp->breakpoint_at == NULL) |
4397 | { | |
4398 | /* A moribund location can never explain a signal other than | |
4399 | GDB_SIGNAL_TRAP. */ | |
4400 | if (sig == GDB_SIGNAL_TRAP) | |
4c462cb0 | 4401 | return true; |
427cd150 TT |
4402 | } |
4403 | else | |
47591c29 PA |
4404 | { |
4405 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4406 | sig)) | |
4c462cb0 | 4407 | return true; |
47591c29 | 4408 | } |
ab04a2af TT |
4409 | } |
4410 | ||
4c462cb0 | 4411 | return false; |
ab04a2af TT |
4412 | } |
4413 | ||
4a64f543 MS |
4414 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4415 | stopped at. *BSP upon return is a bpstat which points to the | |
4416 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4417 | good for anything but further calls to bpstat_num). | |
4418 | ||
8671a17b PA |
4419 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4420 | Return -1 if stopped at a breakpoint that has been deleted since | |
4421 | we set it. | |
4422 | Return 1 otherwise. */ | |
c906108c SS |
4423 | |
4424 | int | |
8671a17b | 4425 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4426 | { |
4427 | struct breakpoint *b; | |
4428 | ||
4429 | if ((*bsp) == NULL) | |
4430 | return 0; /* No more breakpoint values */ | |
8671a17b | 4431 | |
4a64f543 MS |
4432 | /* We assume we'll never have several bpstats that correspond to a |
4433 | single breakpoint -- otherwise, this function might return the | |
4434 | same number more than once and this will look ugly. */ | |
f431efe5 | 4435 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4436 | *bsp = (*bsp)->next; |
4437 | if (b == NULL) | |
4438 | return -1; /* breakpoint that's been deleted since */ | |
4439 | ||
4440 | *num = b->number; /* We have its number */ | |
4441 | return 1; | |
c906108c SS |
4442 | } |
4443 | ||
e93ca019 | 4444 | /* See breakpoint.h. */ |
c906108c SS |
4445 | |
4446 | void | |
e93ca019 | 4447 | bpstat_clear_actions (void) |
c906108c | 4448 | { |
e93ca019 JK |
4449 | bpstat bs; |
4450 | ||
00431a78 | 4451 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4452 | return; |
4453 | ||
00431a78 | 4454 | thread_info *tp = inferior_thread (); |
e93ca019 | 4455 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4456 | { |
d1b0a7bf | 4457 | bs->commands = NULL; |
850645cf | 4458 | bs->old_val.reset (nullptr); |
c906108c SS |
4459 | } |
4460 | } | |
4461 | ||
f3b1572e PA |
4462 | /* Called when a command is about to proceed the inferior. */ |
4463 | ||
4464 | static void | |
4465 | breakpoint_about_to_proceed (void) | |
4466 | { | |
d7e15655 | 4467 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4468 | { |
4469 | struct thread_info *tp = inferior_thread (); | |
4470 | ||
4471 | /* Allow inferior function calls in breakpoint commands to not | |
4472 | interrupt the command list. When the call finishes | |
4473 | successfully, the inferior will be standing at the same | |
4474 | breakpoint as if nothing happened. */ | |
16c381f0 | 4475 | if (tp->control.in_infcall) |
f3b1572e PA |
4476 | return; |
4477 | } | |
4478 | ||
4479 | breakpoint_proceeded = 1; | |
4480 | } | |
4481 | ||
abf85f46 JK |
4482 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4483 | or its equivalent. */ | |
4484 | ||
4485 | static int | |
4486 | command_line_is_silent (struct command_line *cmd) | |
4487 | { | |
4f45d445 | 4488 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4489 | } |
4490 | ||
4a64f543 MS |
4491 | /* Execute all the commands associated with all the breakpoints at |
4492 | this location. Any of these commands could cause the process to | |
4493 | proceed beyond this point, etc. We look out for such changes by | |
4494 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4495 | |
347bddb7 PA |
4496 | Returns true if a breakpoint command resumed the inferior. In that |
4497 | case, it is the caller's responsibility to recall it again with the | |
4498 | bpstat of the current thread. */ | |
4499 | ||
4500 | static int | |
4501 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4502 | { |
4503 | bpstat bs; | |
347bddb7 | 4504 | int again = 0; |
c906108c SS |
4505 | |
4506 | /* Avoid endless recursion if a `source' command is contained | |
4507 | in bs->commands. */ | |
4508 | if (executing_breakpoint_commands) | |
347bddb7 | 4509 | return 0; |
c906108c | 4510 | |
81b1e71c TT |
4511 | scoped_restore save_executing |
4512 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4513 | |
1ac32117 | 4514 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4515 | |
4a64f543 | 4516 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4517 | bs = *bsp; |
4518 | ||
4519 | breakpoint_proceeded = 0; | |
4520 | for (; bs != NULL; bs = bs->next) | |
4521 | { | |
d1b0a7bf | 4522 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4523 | |
4524 | /* Take ownership of the BSP's command tree, if it has one. | |
4525 | ||
dda83cd7 SM |
4526 | The command tree could legitimately contain commands like |
4527 | 'step' and 'next', which call clear_proceed_status, which | |
4528 | frees stop_bpstat's command tree. To make sure this doesn't | |
4529 | free the tree we're executing out from under us, we need to | |
4530 | take ownership of the tree ourselves. Since a given bpstat's | |
4531 | commands are only executed once, we don't need to copy it; we | |
4532 | can clear the pointer in the bpstat, and make sure we free | |
4533 | the tree when we're done. */ | |
d1b0a7bf | 4534 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4535 | bs->commands = NULL; |
d1b0a7bf TT |
4536 | if (ccmd != NULL) |
4537 | cmd = ccmd.get (); | |
abf85f46 JK |
4538 | if (command_line_is_silent (cmd)) |
4539 | { | |
4540 | /* The action has been already done by bpstat_stop_status. */ | |
4541 | cmd = cmd->next; | |
4542 | } | |
6c50ab1c | 4543 | |
c906108c SS |
4544 | while (cmd != NULL) |
4545 | { | |
4546 | execute_control_command (cmd); | |
4547 | ||
4548 | if (breakpoint_proceeded) | |
4549 | break; | |
4550 | else | |
4551 | cmd = cmd->next; | |
4552 | } | |
6c50ab1c | 4553 | |
c906108c | 4554 | if (breakpoint_proceeded) |
32c1e744 | 4555 | { |
cb814510 | 4556 | if (current_ui->async) |
347bddb7 PA |
4557 | /* If we are in async mode, then the target might be still |
4558 | running, not stopped at any breakpoint, so nothing for | |
4559 | us to do here -- just return to the event loop. */ | |
4560 | ; | |
32c1e744 VP |
4561 | else |
4562 | /* In sync mode, when execute_control_command returns | |
4563 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4564 | Breakpoint commands for that stop were not run, since |
4565 | execute_command does not run breakpoint commands -- | |
4566 | only command_line_handler does, but that one is not | |
4567 | involved in execution of breakpoint commands. So, we | |
4568 | can now execute breakpoint commands. It should be | |
4569 | noted that making execute_command do bpstat actions is | |
4570 | not an option -- in this case we'll have recursive | |
4571 | invocation of bpstat for each breakpoint with a | |
4572 | command, and can easily blow up GDB stack. Instead, we | |
4573 | return true, which will trigger the caller to recall us | |
4574 | with the new stop_bpstat. */ | |
4575 | again = 1; | |
4576 | break; | |
32c1e744 | 4577 | } |
c906108c | 4578 | } |
347bddb7 PA |
4579 | return again; |
4580 | } | |
4581 | ||
00431a78 PA |
4582 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4583 | one, is alive and has execution. Return NULL otherwise. */ | |
4584 | ||
4585 | static thread_info * | |
4586 | get_bpstat_thread () | |
4587 | { | |
55f6301a | 4588 | if (inferior_ptid == null_ptid || !target_has_execution ()) |
00431a78 PA |
4589 | return NULL; |
4590 | ||
4591 | thread_info *tp = inferior_thread (); | |
4592 | if (tp->state == THREAD_EXITED || tp->executing) | |
4593 | return NULL; | |
4594 | return tp; | |
4595 | } | |
4596 | ||
347bddb7 PA |
4597 | void |
4598 | bpstat_do_actions (void) | |
4599 | { | |
694c6bf5 | 4600 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4601 | thread_info *tp; |
353d1d73 | 4602 | |
347bddb7 | 4603 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4604 | while ((tp = get_bpstat_thread ()) != NULL) |
4605 | { | |
4606 | /* Since in sync mode, bpstat_do_actions may resume the | |
4607 | inferior, and only return when it is stopped at the next | |
4608 | breakpoint, we keep doing breakpoint actions until it returns | |
4609 | false to indicate the inferior was not resumed. */ | |
4610 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4611 | break; | |
4612 | } | |
353d1d73 | 4613 | |
694c6bf5 | 4614 | cleanup_if_error.release (); |
c906108c SS |
4615 | } |
4616 | ||
fa4727a6 DJ |
4617 | /* Print out the (old or new) value associated with a watchpoint. */ |
4618 | ||
4619 | static void | |
4620 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4621 | { | |
4622 | if (val == NULL) | |
7f6aba03 | 4623 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
fa4727a6 | 4624 | else |
79a45b7d TT |
4625 | { |
4626 | struct value_print_options opts; | |
4627 | get_user_print_options (&opts); | |
4628 | value_print (val, stream, &opts); | |
4629 | } | |
fa4727a6 DJ |
4630 | } |
4631 | ||
f303dbd6 PA |
4632 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4633 | debugging multiple threads. */ | |
4634 | ||
4635 | void | |
4636 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4637 | { | |
112e8700 | 4638 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4639 | return; |
4640 | ||
112e8700 | 4641 | uiout->text ("\n"); |
f303dbd6 PA |
4642 | |
4643 | if (show_thread_that_caused_stop ()) | |
4644 | { | |
4645 | const char *name; | |
4646 | struct thread_info *thr = inferior_thread (); | |
4647 | ||
112e8700 | 4648 | uiout->text ("Thread "); |
33eca680 | 4649 | uiout->field_string ("thread-id", print_thread_id (thr)); |
f303dbd6 PA |
4650 | |
4651 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4652 | if (name != NULL) | |
4653 | { | |
112e8700 | 4654 | uiout->text (" \""); |
33eca680 | 4655 | uiout->field_string ("name", name); |
112e8700 | 4656 | uiout->text ("\""); |
f303dbd6 PA |
4657 | } |
4658 | ||
112e8700 | 4659 | uiout->text (" hit "); |
f303dbd6 PA |
4660 | } |
4661 | } | |
4662 | ||
e514a9d6 | 4663 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4664 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4665 | 'print_it' in the bpstat structure. Under some circumstances we |
4666 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4667 | normal_stop(). */ |
e514a9d6 JM |
4668 | |
4669 | static enum print_stop_action | |
4670 | print_bp_stop_message (bpstat bs) | |
4671 | { | |
4672 | switch (bs->print_it) | |
4673 | { | |
4674 | case print_it_noop: | |
4a64f543 | 4675 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4676 | return PRINT_UNKNOWN; |
4677 | break; | |
4678 | ||
4679 | case print_it_done: | |
4680 | /* We still want to print the frame, but we already printed the | |
dda83cd7 | 4681 | relevant messages. */ |
e514a9d6 JM |
4682 | return PRINT_SRC_AND_LOC; |
4683 | break; | |
4684 | ||
4685 | case print_it_normal: | |
4f8d1dc6 | 4686 | { |
f431efe5 PA |
4687 | struct breakpoint *b = bs->breakpoint_at; |
4688 | ||
1a6a67de TJB |
4689 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4690 | which has since been deleted. */ | |
4691 | if (b == NULL) | |
4692 | return PRINT_UNKNOWN; | |
4693 | ||
348d480f PA |
4694 | /* Normal case. Call the breakpoint's print_it method. */ |
4695 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4696 | } |
348d480f | 4697 | break; |
3086aeae | 4698 | |
e514a9d6 | 4699 | default: |
8e65ff28 | 4700 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4701 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4702 | break; |
c906108c | 4703 | } |
c906108c SS |
4704 | } |
4705 | ||
edcc5120 TT |
4706 | /* A helper function that prints a shared library stopped event. */ |
4707 | ||
4708 | static void | |
4709 | print_solib_event (int is_catchpoint) | |
4710 | { | |
6fb16ce6 | 4711 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4712 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4713 | |
4714 | if (!is_catchpoint) | |
4715 | { | |
4716 | if (any_added || any_deleted) | |
112e8700 | 4717 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4718 | else |
112e8700 SM |
4719 | current_uiout->text (_("Stopped due to shared library event (no " |
4720 | "libraries added or removed)\n")); | |
edcc5120 TT |
4721 | } |
4722 | ||
112e8700 SM |
4723 | if (current_uiout->is_mi_like_p ()) |
4724 | current_uiout->field_string ("reason", | |
4725 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4726 | |
4727 | if (any_deleted) | |
4728 | { | |
112e8700 | 4729 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4730 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4731 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4732 | { |
6fb16ce6 SM |
4733 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4734 | ||
edcc5120 | 4735 | if (ix > 0) |
112e8700 SM |
4736 | current_uiout->text (" "); |
4737 | current_uiout->field_string ("library", name); | |
4738 | current_uiout->text ("\n"); | |
edcc5120 | 4739 | } |
edcc5120 TT |
4740 | } |
4741 | ||
4742 | if (any_added) | |
4743 | { | |
112e8700 | 4744 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4745 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4746 | bool first = true; |
52941706 | 4747 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4748 | { |
bcb430e4 | 4749 | if (!first) |
112e8700 | 4750 | current_uiout->text (" "); |
bcb430e4 | 4751 | first = false; |
112e8700 SM |
4752 | current_uiout->field_string ("library", iter->so_name); |
4753 | current_uiout->text ("\n"); | |
edcc5120 | 4754 | } |
edcc5120 TT |
4755 | } |
4756 | } | |
4757 | ||
e514a9d6 JM |
4758 | /* Print a message indicating what happened. This is called from |
4759 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4760 | list - a list of the eventpoints that caused this stop. KIND is |
4761 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4762 | routine calls the generic print routine for printing a message |
4763 | about reasons for stopping. This will print (for example) the | |
4764 | "Breakpoint n," part of the output. The return value of this | |
4765 | routine is one of: | |
c906108c | 4766 | |
4a64f543 | 4767 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4768 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4769 | code to print the location. An example is |
c5aa993b JM |
4770 | "Breakpoint 1, " which should be followed by |
4771 | the location. | |
917317f4 | 4772 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4773 | to also print the location part of the message. |
4774 | An example is the catch/throw messages, which | |
4a64f543 | 4775 | don't require a location appended to the end. |
917317f4 | 4776 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4777 | further info to be printed. */ |
c906108c | 4778 | |
917317f4 | 4779 | enum print_stop_action |
36dfb11c | 4780 | bpstat_print (bpstat bs, int kind) |
c906108c | 4781 | { |
f486487f | 4782 | enum print_stop_action val; |
c5aa993b | 4783 | |
c906108c | 4784 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4785 | (Currently all watchpoints go on the bpstat whether hit or not. |
4786 | That probably could (should) be changed, provided care is taken | |
c906108c | 4787 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4788 | for (; bs; bs = bs->next) |
4789 | { | |
4790 | val = print_bp_stop_message (bs); | |
4791 | if (val == PRINT_SRC_ONLY | |
4792 | || val == PRINT_SRC_AND_LOC | |
4793 | || val == PRINT_NOTHING) | |
4794 | return val; | |
4795 | } | |
c906108c | 4796 | |
36dfb11c TT |
4797 | /* If we had hit a shared library event breakpoint, |
4798 | print_bp_stop_message would print out this message. If we hit an | |
4799 | OS-level shared library event, do the same thing. */ | |
4800 | if (kind == TARGET_WAITKIND_LOADED) | |
4801 | { | |
edcc5120 | 4802 | print_solib_event (0); |
36dfb11c TT |
4803 | return PRINT_NOTHING; |
4804 | } | |
4805 | ||
e514a9d6 | 4806 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4807 | with and nothing was printed. */ |
917317f4 | 4808 | return PRINT_UNKNOWN; |
c906108c SS |
4809 | } |
4810 | ||
bf469271 | 4811 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4812 | |
bf469271 PA |
4813 | static bool |
4814 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4815 | { |
278cd55f | 4816 | struct value *mark = value_mark (); |
bf469271 | 4817 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4818 | |
c906108c | 4819 | value_free_to_mark (mark); |
bf469271 | 4820 | return res; |
c906108c SS |
4821 | } |
4822 | ||
5760d0ab | 4823 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4824 | |
04afa70c TT |
4825 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4826 | : next (NULL), | |
b6433ede | 4827 | bp_location_at (bp_location_ref_ptr::new_reference (bl)), |
04afa70c TT |
4828 | breakpoint_at (bl->owner), |
4829 | commands (NULL), | |
04afa70c TT |
4830 | print (0), |
4831 | stop (0), | |
4832 | print_it (print_it_normal) | |
c906108c | 4833 | { |
04afa70c TT |
4834 | **bs_link_pointer = this; |
4835 | *bs_link_pointer = &next; | |
4836 | } | |
4837 | ||
4838 | bpstats::bpstats () | |
4839 | : next (NULL), | |
04afa70c TT |
4840 | breakpoint_at (NULL), |
4841 | commands (NULL), | |
04afa70c TT |
4842 | print (0), |
4843 | stop (0), | |
4844 | print_it (print_it_normal) | |
4845 | { | |
c906108c SS |
4846 | } |
4847 | \f | |
d983da9c DJ |
4848 | /* The target has stopped with waitstatus WS. Check if any hardware |
4849 | watchpoints have triggered, according to the target. */ | |
4850 | ||
4851 | int | |
4852 | watchpoints_triggered (struct target_waitstatus *ws) | |
4853 | { | |
57810aa7 | 4854 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4855 | CORE_ADDR addr; |
4856 | struct breakpoint *b; | |
4857 | ||
4858 | if (!stopped_by_watchpoint) | |
4859 | { | |
4860 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4861 | as not triggered. */ | |
4862 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4863 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4864 | { |
4865 | struct watchpoint *w = (struct watchpoint *) b; | |
4866 | ||
4867 | w->watchpoint_triggered = watch_triggered_no; | |
4868 | } | |
d983da9c DJ |
4869 | |
4870 | return 0; | |
4871 | } | |
4872 | ||
8b88a78e | 4873 | if (!target_stopped_data_address (current_top_target (), &addr)) |
d983da9c DJ |
4874 | { |
4875 | /* We were stopped by a watchpoint, but we don't know where. | |
4876 | Mark all watchpoints as unknown. */ | |
4877 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4878 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4879 | { |
4880 | struct watchpoint *w = (struct watchpoint *) b; | |
4881 | ||
4882 | w->watchpoint_triggered = watch_triggered_unknown; | |
4883 | } | |
d983da9c | 4884 | |
3c4797ba | 4885 | return 1; |
d983da9c DJ |
4886 | } |
4887 | ||
4888 | /* The target could report the data address. Mark watchpoints | |
4889 | affected by this data address as triggered, and all others as not | |
4890 | triggered. */ | |
4891 | ||
4892 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4893 | if (is_hardware_watchpoint (b)) |
d983da9c | 4894 | { |
3a5c3e22 | 4895 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4896 | struct bp_location *loc; |
d983da9c | 4897 | |
3a5c3e22 | 4898 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4899 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4900 | { |
3a5c3e22 | 4901 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4902 | { |
3a5c3e22 PA |
4903 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4904 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4905 | |
4906 | if (newaddr == start) | |
4907 | { | |
3a5c3e22 | 4908 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4909 | break; |
4910 | } | |
4911 | } | |
4912 | /* Exact match not required. Within range is sufficient. */ | |
8b88a78e | 4913 | else if (target_watchpoint_addr_within_range (current_top_target (), |
9c06b0b4 TJB |
4914 | addr, loc->address, |
4915 | loc->length)) | |
4916 | { | |
3a5c3e22 | 4917 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4918 | break; |
4919 | } | |
4920 | } | |
d983da9c DJ |
4921 | } |
4922 | ||
4923 | return 1; | |
4924 | } | |
4925 | ||
bf469271 PA |
4926 | /* Possible return values for watchpoint_check. */ |
4927 | enum wp_check_result | |
4928 | { | |
4929 | /* The watchpoint has been deleted. */ | |
4930 | WP_DELETED = 1, | |
4931 | ||
4932 | /* The value has changed. */ | |
4933 | WP_VALUE_CHANGED = 2, | |
4934 | ||
4935 | /* The value has not changed. */ | |
4936 | WP_VALUE_NOT_CHANGED = 3, | |
4937 | ||
4938 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4939 | WP_IGNORE = 4, | |
4940 | }; | |
c906108c SS |
4941 | |
4942 | #define BP_TEMPFLAG 1 | |
4943 | #define BP_HARDWAREFLAG 2 | |
4944 | ||
4a64f543 | 4945 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4946 | changed. */ |
553e4c11 | 4947 | |
bf469271 PA |
4948 | static wp_check_result |
4949 | watchpoint_check (bpstat bs) | |
c906108c | 4950 | { |
3a5c3e22 | 4951 | struct watchpoint *b; |
c906108c SS |
4952 | struct frame_info *fr; |
4953 | int within_current_scope; | |
4954 | ||
f431efe5 | 4955 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4956 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4957 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4958 | |
f6bc2008 PA |
4959 | /* If this is a local watchpoint, we only want to check if the |
4960 | watchpoint frame is in scope if the current thread is the thread | |
4961 | that was used to create the watchpoint. */ | |
4962 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4963 | return WP_IGNORE; |
f6bc2008 | 4964 | |
c906108c SS |
4965 | if (b->exp_valid_block == NULL) |
4966 | within_current_scope = 1; | |
4967 | else | |
4968 | { | |
edb3359d DJ |
4969 | struct frame_info *frame = get_current_frame (); |
4970 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4971 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4972 | ||
c9cf6e20 | 4973 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4974 | still in the function but the stack frame has already been |
4975 | invalidated. Since we can't rely on the values of local | |
4976 | variables after the stack has been destroyed, we are treating | |
4977 | the watchpoint in that state as `not changed' without further | |
4978 | checking. Don't mark watchpoints as changed if the current | |
4979 | frame is in an epilogue - even if they are in some other | |
4980 | frame, our view of the stack is likely to be wrong and | |
4981 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4982 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4983 | return WP_IGNORE; |
a0f49112 | 4984 | |
101dcfbe | 4985 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4986 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4987 | |
4988 | /* If we've gotten confused in the unwinder, we might have | |
4989 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4990 | if (within_current_scope) |
4991 | { | |
4992 | struct symbol *function; | |
4993 | ||
4994 | function = get_frame_function (fr); | |
4995 | if (function == NULL | |
4996 | || !contained_in (b->exp_valid_block, | |
4997 | SYMBOL_BLOCK_VALUE (function))) | |
4998 | within_current_scope = 0; | |
4999 | } | |
69fbadd5 | 5000 | |
edb3359d | 5001 | if (within_current_scope) |
c906108c SS |
5002 | /* If we end up stopping, the current frame will get selected |
5003 | in normal_stop. So this call to select_frame won't affect | |
5004 | the user. */ | |
0f7d239c | 5005 | select_frame (fr); |
c906108c | 5006 | } |
c5aa993b | 5007 | |
c906108c SS |
5008 | if (within_current_scope) |
5009 | { | |
4a64f543 | 5010 | /* We use value_{,free_to_}mark because it could be a *long* |
dda83cd7 SM |
5011 | time before we return to the command level and call |
5012 | free_all_values. We can't call free_all_values because we | |
5013 | might be in the middle of evaluating a function call. */ | |
c906108c | 5014 | |
0cf6dd15 | 5015 | int pc = 0; |
9c06b0b4 | 5016 | struct value *mark; |
fa4727a6 DJ |
5017 | struct value *new_val; |
5018 | ||
c1fc2657 | 5019 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
5020 | /* Since we don't know the exact trigger address (from |
5021 | stopped_data_address), just tell the user we've triggered | |
5022 | a mask watchpoint. */ | |
5023 | return WP_VALUE_CHANGED; | |
5024 | ||
5025 | mark = value_mark (); | |
2e362716 | 5026 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, false); |
218d2fc6 | 5027 | |
bb9d5f81 PP |
5028 | if (b->val_bitsize != 0) |
5029 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5030 | ||
4a64f543 MS |
5031 | /* We use value_equal_contents instead of value_equal because |
5032 | the latter coerces an array to a pointer, thus comparing just | |
5033 | the address of the array instead of its contents. This is | |
5034 | not what we want. */ | |
fa4727a6 | 5035 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
5036 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
5037 | new_val))) | |
c906108c | 5038 | { |
c906108c | 5039 | bs->old_val = b->val; |
850645cf | 5040 | b->val = release_value (new_val); |
4c1d86d9 | 5041 | b->val_valid = true; |
850645cf TT |
5042 | if (new_val != NULL) |
5043 | value_free_to_mark (mark); | |
c906108c SS |
5044 | return WP_VALUE_CHANGED; |
5045 | } | |
5046 | else | |
5047 | { | |
60e1c644 | 5048 | /* Nothing changed. */ |
c906108c | 5049 | value_free_to_mark (mark); |
c906108c SS |
5050 | return WP_VALUE_NOT_CHANGED; |
5051 | } | |
5052 | } | |
5053 | else | |
5054 | { | |
5055 | /* This seems like the only logical thing to do because | |
dda83cd7 SM |
5056 | if we temporarily ignored the watchpoint, then when |
5057 | we reenter the block in which it is valid it contains | |
5058 | garbage (in the case of a function, it may have two | |
5059 | garbage values, one before and one after the prologue). | |
5060 | So we can't even detect the first assignment to it and | |
5061 | watch after that (since the garbage may or may not equal | |
5062 | the first value assigned). */ | |
348d480f PA |
5063 | /* We print all the stop information in |
5064 | breakpoint_ops->print_it, but in this case, by the time we | |
5065 | call breakpoint_ops->print_it this bp will be deleted | |
5066 | already. So we have no choice but print the information | |
5067 | here. */ | |
468afe6c | 5068 | |
0e454242 | 5069 | SWITCH_THRU_ALL_UIS () |
dda83cd7 | 5070 | { |
468afe6c PA |
5071 | struct ui_out *uiout = current_uiout; |
5072 | ||
112e8700 SM |
5073 | if (uiout->is_mi_like_p ()) |
5074 | uiout->field_string | |
5075 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
6a831f06 PA |
5076 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
5077 | "left the block in\n" | |
5078 | "which its expression is valid.\n", | |
5079 | signed_field ("wpnum", b->number)); | |
468afe6c | 5080 | } |
4ce44c66 | 5081 | |
cdac0397 | 5082 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 5083 | b->commands = NULL; |
d0fb5eae | 5084 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5085 | |
5086 | return WP_DELETED; | |
5087 | } | |
5088 | } | |
5089 | ||
18a18393 | 5090 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5091 | breakpoint location BL. This function does not check if we should |
5092 | stop, only if BL explains the stop. */ | |
5093 | ||
18a18393 | 5094 | static int |
6c95b8df | 5095 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 5096 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5097 | const struct target_waitstatus *ws) |
18a18393 VP |
5098 | { |
5099 | struct breakpoint *b = bl->owner; | |
5100 | ||
348d480f | 5101 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5102 | gdb_assert (b != NULL); |
5103 | ||
bd522513 | 5104 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5105 | } |
5106 | ||
3a5c3e22 PA |
5107 | /* Determine if the watched values have actually changed, and we |
5108 | should stop. If not, set BS->stop to 0. */ | |
5109 | ||
18a18393 VP |
5110 | static void |
5111 | bpstat_check_watchpoint (bpstat bs) | |
5112 | { | |
2bdf28a0 | 5113 | const struct bp_location *bl; |
3a5c3e22 | 5114 | struct watchpoint *b; |
2bdf28a0 JK |
5115 | |
5116 | /* BS is built for existing struct breakpoint. */ | |
b6433ede | 5117 | bl = bs->bp_location_at.get (); |
2bdf28a0 | 5118 | gdb_assert (bl != NULL); |
3a5c3e22 | 5119 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5120 | gdb_assert (b != NULL); |
18a18393 | 5121 | |
18a18393 | 5122 | { |
18a18393 VP |
5123 | int must_check_value = 0; |
5124 | ||
c1fc2657 | 5125 | if (b->type == bp_watchpoint) |
18a18393 VP |
5126 | /* For a software watchpoint, we must always check the |
5127 | watched value. */ | |
5128 | must_check_value = 1; | |
5129 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5130 | /* We have a hardware watchpoint (read, write, or access) | |
5131 | and the target earlier reported an address watched by | |
5132 | this watchpoint. */ | |
5133 | must_check_value = 1; | |
5134 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5135 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5136 | /* We were stopped by a hardware watchpoint, but the target could |
5137 | not report the data address. We must check the watchpoint's | |
5138 | value. Access and read watchpoints are out of luck; without | |
5139 | a data address, we can't figure it out. */ | |
5140 | must_check_value = 1; | |
3a5c3e22 | 5141 | |
18a18393 VP |
5142 | if (must_check_value) |
5143 | { | |
bf469271 PA |
5144 | wp_check_result e; |
5145 | ||
a70b8144 | 5146 | try |
bf469271 PA |
5147 | { |
5148 | e = watchpoint_check (bs); | |
5149 | } | |
230d2906 | 5150 | catch (const gdb_exception &ex) |
bf469271 PA |
5151 | { |
5152 | exception_fprintf (gdb_stderr, ex, | |
5153 | "Error evaluating expression " | |
5154 | "for watchpoint %d\n", | |
5155 | b->number); | |
5156 | ||
5157 | SWITCH_THRU_ALL_UIS () | |
5158 | { | |
5159 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5160 | b->number); | |
5161 | } | |
5162 | watchpoint_del_at_next_stop (b); | |
5163 | e = WP_DELETED; | |
5164 | } | |
bf469271 | 5165 | |
18a18393 VP |
5166 | switch (e) |
5167 | { | |
5168 | case WP_DELETED: | |
5169 | /* We've already printed what needs to be printed. */ | |
5170 | bs->print_it = print_it_done; | |
5171 | /* Stop. */ | |
5172 | break; | |
60e1c644 PA |
5173 | case WP_IGNORE: |
5174 | bs->print_it = print_it_noop; | |
5175 | bs->stop = 0; | |
5176 | break; | |
18a18393 | 5177 | case WP_VALUE_CHANGED: |
c1fc2657 | 5178 | if (b->type == bp_read_watchpoint) |
18a18393 | 5179 | { |
85d721b8 PA |
5180 | /* There are two cases to consider here: |
5181 | ||
4a64f543 | 5182 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5183 | In that case, trust the target, and always report |
5184 | the watchpoint hit to the user. Even though | |
5185 | reads don't cause value changes, the value may | |
5186 | have changed since the last time it was read, and | |
5187 | since we're not trapping writes, we will not see | |
5188 | those, and as such we should ignore our notion of | |
5189 | old value. | |
5190 | ||
4a64f543 | 5191 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5192 | reads and writes. There are two ways this may |
5193 | happen: | |
5194 | ||
4a64f543 | 5195 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5196 | reads only, but can break on accesses (reads or |
5197 | writes), such as e.g., x86. We detect this case | |
5198 | at the time we try to insert read watchpoints. | |
5199 | ||
4a64f543 | 5200 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5201 | watchpoints, but, the user set an access or write |
5202 | watchpoint watching the same memory as this read | |
5203 | watchpoint. | |
5204 | ||
5205 | If we're watching memory writes as well as reads, | |
5206 | ignore watchpoint hits when we find that the | |
5207 | value hasn't changed, as reads don't cause | |
5208 | changes. This still gives false positives when | |
5209 | the program writes the same value to memory as | |
5210 | what there was already in memory (we will confuse | |
5211 | it for a read), but it's much better than | |
5212 | nothing. */ | |
5213 | ||
5214 | int other_write_watchpoint = 0; | |
5215 | ||
5216 | if (bl->watchpoint_type == hw_read) | |
5217 | { | |
5218 | struct breakpoint *other_b; | |
5219 | ||
5220 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5221 | if (other_b->type == bp_hardware_watchpoint |
5222 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5223 | { |
3a5c3e22 PA |
5224 | struct watchpoint *other_w = |
5225 | (struct watchpoint *) other_b; | |
5226 | ||
5227 | if (other_w->watchpoint_triggered | |
5228 | == watch_triggered_yes) | |
5229 | { | |
5230 | other_write_watchpoint = 1; | |
5231 | break; | |
5232 | } | |
85d721b8 PA |
5233 | } |
5234 | } | |
5235 | ||
5236 | if (other_write_watchpoint | |
5237 | || bl->watchpoint_type == hw_access) | |
5238 | { | |
5239 | /* We're watching the same memory for writes, | |
5240 | and the value changed since the last time we | |
5241 | updated it, so this trap must be for a write. | |
5242 | Ignore it. */ | |
5243 | bs->print_it = print_it_noop; | |
5244 | bs->stop = 0; | |
5245 | } | |
18a18393 VP |
5246 | } |
5247 | break; | |
5248 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5249 | if (b->type == bp_hardware_watchpoint |
5250 | || b->type == bp_watchpoint) | |
18a18393 VP |
5251 | { |
5252 | /* Don't stop: write watchpoints shouldn't fire if | |
5253 | the value hasn't changed. */ | |
5254 | bs->print_it = print_it_noop; | |
5255 | bs->stop = 0; | |
5256 | } | |
5257 | /* Stop. */ | |
5258 | break; | |
5259 | default: | |
5260 | /* Can't happen. */ | |
18a18393 VP |
5261 | break; |
5262 | } | |
5263 | } | |
5264 | else /* must_check_value == 0 */ | |
5265 | { | |
5266 | /* This is a case where some watchpoint(s) triggered, but | |
5267 | not at the address of this watchpoint, or else no | |
5268 | watchpoint triggered after all. So don't print | |
5269 | anything for this watchpoint. */ | |
5270 | bs->print_it = print_it_noop; | |
5271 | bs->stop = 0; | |
5272 | } | |
5273 | } | |
5274 | } | |
5275 | ||
7d4df6a4 DE |
5276 | /* For breakpoints that are currently marked as telling gdb to stop, |
5277 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5278 | of breakpoint referred to by BS. If we should not stop for this |
5279 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5280 | |
18a18393 | 5281 | static void |
00431a78 | 5282 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
18a18393 | 5283 | { |
2bdf28a0 JK |
5284 | const struct bp_location *bl; |
5285 | struct breakpoint *b; | |
bf469271 PA |
5286 | /* Assume stop. */ |
5287 | bool condition_result = true; | |
7d4df6a4 DE |
5288 | struct expression *cond; |
5289 | ||
5290 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5291 | |
5292 | /* BS is built for existing struct breakpoint. */ | |
b6433ede | 5293 | bl = bs->bp_location_at.get (); |
2bdf28a0 | 5294 | gdb_assert (bl != NULL); |
f431efe5 | 5295 | b = bs->breakpoint_at; |
2bdf28a0 | 5296 | gdb_assert (b != NULL); |
18a18393 | 5297 | |
b775012e LM |
5298 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5299 | need to do so again since GDB does not know if we stopped due to a | |
5300 | breakpoint or a single step breakpoint. */ | |
5301 | ||
18a18393 | 5302 | if (frame_id_p (b->frame_id) |
edb3359d | 5303 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5304 | { |
7d4df6a4 DE |
5305 | bs->stop = 0; |
5306 | return; | |
5307 | } | |
60e1c644 | 5308 | |
12ab52e9 PA |
5309 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5310 | evaluating the condition if this isn't the specified | |
5311 | thread/task. */ | |
00431a78 PA |
5312 | if ((b->thread != -1 && b->thread != thread->global_num) |
5313 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5314 | { |
5315 | bs->stop = 0; | |
5316 | return; | |
5317 | } | |
5318 | ||
6dddc817 DE |
5319 | /* Evaluate extension language breakpoints that have a "stop" method |
5320 | implemented. */ | |
5321 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5322 | |
7d4df6a4 DE |
5323 | if (is_watchpoint (b)) |
5324 | { | |
5325 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5326 | |
4d01a485 | 5327 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5328 | } |
5329 | else | |
4d01a485 | 5330 | cond = bl->cond.get (); |
60e1c644 | 5331 | |
7d4df6a4 DE |
5332 | if (cond && b->disposition != disp_del_at_next_stop) |
5333 | { | |
5334 | int within_current_scope = 1; | |
5335 | struct watchpoint * w; | |
60e1c644 | 5336 | |
7d4df6a4 DE |
5337 | /* We use value_mark and value_free_to_mark because it could |
5338 | be a long time before we return to the command level and | |
5339 | call free_all_values. We can't call free_all_values | |
5340 | because we might be in the middle of evaluating a | |
5341 | function call. */ | |
5342 | struct value *mark = value_mark (); | |
5343 | ||
5344 | if (is_watchpoint (b)) | |
5345 | w = (struct watchpoint *) b; | |
5346 | else | |
5347 | w = NULL; | |
5348 | ||
5349 | /* Need to select the frame, with all that implies so that | |
5350 | the conditions will have the right context. Because we | |
5351 | use the frame, we will not see an inlined function's | |
5352 | variables when we arrive at a breakpoint at the start | |
5353 | of the inlined function; the current frame will be the | |
5354 | call site. */ | |
5355 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5356 | select_frame (get_current_frame ()); | |
5357 | else | |
18a18393 | 5358 | { |
7d4df6a4 DE |
5359 | struct frame_info *frame; |
5360 | ||
5361 | /* For local watchpoint expressions, which particular | |
5362 | instance of a local is being watched matters, so we | |
5363 | keep track of the frame to evaluate the expression | |
5364 | in. To evaluate the condition however, it doesn't | |
5365 | really matter which instantiation of the function | |
5366 | where the condition makes sense triggers the | |
5367 | watchpoint. This allows an expression like "watch | |
5368 | global if q > 10" set in `func', catch writes to | |
5369 | global on all threads that call `func', or catch | |
5370 | writes on all recursive calls of `func' by a single | |
5371 | thread. We simply always evaluate the condition in | |
5372 | the innermost frame that's executing where it makes | |
5373 | sense to evaluate the condition. It seems | |
5374 | intuitive. */ | |
5375 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5376 | if (frame != NULL) | |
5377 | select_frame (frame); | |
5378 | else | |
5379 | within_current_scope = 0; | |
18a18393 | 5380 | } |
7d4df6a4 | 5381 | if (within_current_scope) |
bf469271 | 5382 | { |
a70b8144 | 5383 | try |
bf469271 PA |
5384 | { |
5385 | condition_result = breakpoint_cond_eval (cond); | |
5386 | } | |
230d2906 | 5387 | catch (const gdb_exception &ex) |
bf469271 PA |
5388 | { |
5389 | exception_fprintf (gdb_stderr, ex, | |
5390 | "Error in testing breakpoint condition:\n"); | |
5391 | } | |
bf469271 | 5392 | } |
7d4df6a4 | 5393 | else |
18a18393 | 5394 | { |
7d4df6a4 DE |
5395 | warning (_("Watchpoint condition cannot be tested " |
5396 | "in the current scope")); | |
5397 | /* If we failed to set the right context for this | |
5398 | watchpoint, unconditionally report it. */ | |
18a18393 | 5399 | } |
7d4df6a4 DE |
5400 | /* FIXME-someday, should give breakpoint #. */ |
5401 | value_free_to_mark (mark); | |
18a18393 | 5402 | } |
7d4df6a4 | 5403 | |
bf469271 | 5404 | if (cond && !condition_result) |
7d4df6a4 DE |
5405 | { |
5406 | bs->stop = 0; | |
5407 | } | |
7d4df6a4 DE |
5408 | else if (b->ignore_count > 0) |
5409 | { | |
5410 | b->ignore_count--; | |
5411 | bs->stop = 0; | |
5412 | /* Increase the hit count even though we don't stop. */ | |
5413 | ++(b->hit_count); | |
76727919 | 5414 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5415 | } |
18a18393 VP |
5416 | } |
5417 | ||
1cf4d951 PA |
5418 | /* Returns true if we need to track moribund locations of LOC's type |
5419 | on the current target. */ | |
5420 | ||
5421 | static int | |
5422 | need_moribund_for_location_type (struct bp_location *loc) | |
5423 | { | |
5424 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5425 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5426 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5427 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5428 | } | |
5429 | ||
ddfe970e | 5430 | /* See breakpoint.h. */ |
c906108c SS |
5431 | |
5432 | bpstat | |
ddfe970e | 5433 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5434 | const struct target_waitstatus *ws) |
c906108c | 5435 | { |
ddfe970e | 5436 | struct breakpoint *b; |
5760d0ab | 5437 | bpstat bs_head = NULL, *bs_link = &bs_head; |
c5aa993b | 5438 | |
429374b8 JK |
5439 | ALL_BREAKPOINTS (b) |
5440 | { | |
1a853c52 | 5441 | if (!breakpoint_enabled (b)) |
429374b8 | 5442 | continue; |
a5606eee | 5443 | |
ddfe970e | 5444 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
429374b8 | 5445 | { |
4a64f543 MS |
5446 | /* For hardware watchpoints, we look only at the first |
5447 | location. The watchpoint_check function will work on the | |
5448 | entire expression, not the individual locations. For | |
5449 | read watchpoints, the watchpoints_triggered function has | |
5450 | checked all locations already. */ | |
429374b8 JK |
5451 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5452 | break; | |
18a18393 | 5453 | |
b5fa468f | 5454 | if (!bl->enabled || bl->disabled_by_cond || bl->shlib_disabled) |
429374b8 | 5455 | continue; |
c5aa993b | 5456 | |
09ac7c10 | 5457 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5458 | continue; |
c5aa993b | 5459 | |
4a64f543 MS |
5460 | /* Come here if it's a watchpoint, or if the break address |
5461 | matches. */ | |
c5aa993b | 5462 | |
ddfe970e KS |
5463 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
5464 | explain stop. */ | |
c5aa993b | 5465 | |
f431efe5 PA |
5466 | /* Assume we stop. Should we find a watchpoint that is not |
5467 | actually triggered, or if the condition of the breakpoint | |
5468 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5469 | bs->stop = 1; |
5470 | bs->print = 1; | |
d983da9c | 5471 | |
f431efe5 PA |
5472 | /* If this is a scope breakpoint, mark the associated |
5473 | watchpoint as triggered so that we will handle the | |
5474 | out-of-scope event. We'll get to the watchpoint next | |
5475 | iteration. */ | |
d0fb5eae | 5476 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5477 | { |
5478 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5479 | ||
5480 | w->watchpoint_triggered = watch_triggered_yes; | |
5481 | } | |
f431efe5 PA |
5482 | } |
5483 | } | |
5484 | ||
7c16b83e | 5485 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5486 | if (!target_supports_stopped_by_sw_breakpoint () |
5487 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5488 | { |
1123588c | 5489 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5490 | { |
1cf4d951 PA |
5491 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5492 | && need_moribund_for_location_type (loc)) | |
5493 | { | |
ddfe970e | 5494 | bpstat bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5495 | /* For hits of moribund locations, we should just proceed. */ |
5496 | bs->stop = 0; | |
5497 | bs->print = 0; | |
5498 | bs->print_it = print_it_noop; | |
5499 | } | |
f431efe5 PA |
5500 | } |
5501 | } | |
5502 | ||
ddfe970e KS |
5503 | return bs_head; |
5504 | } | |
5505 | ||
5506 | /* See breakpoint.h. */ | |
5507 | ||
5508 | bpstat | |
5509 | bpstat_stop_status (const address_space *aspace, | |
00431a78 | 5510 | CORE_ADDR bp_addr, thread_info *thread, |
ddfe970e KS |
5511 | const struct target_waitstatus *ws, |
5512 | bpstat stop_chain) | |
5513 | { | |
5514 | struct breakpoint *b = NULL; | |
5515 | /* First item of allocated bpstat's. */ | |
5516 | bpstat bs_head = stop_chain; | |
5517 | bpstat bs; | |
5518 | int need_remove_insert; | |
5519 | int removed_any; | |
5520 | ||
5521 | /* First, build the bpstat chain with locations that explain a | |
5522 | target stop, while being careful to not set the target running, | |
5523 | as that may invalidate locations (in particular watchpoint | |
5524 | locations are recreated). Resuming will happen here with | |
5525 | breakpoint conditions or watchpoint expressions that include | |
5526 | inferior function calls. */ | |
5527 | if (bs_head == NULL) | |
5528 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5529 | ||
edcc5120 TT |
5530 | /* A bit of special processing for shlib breakpoints. We need to |
5531 | process solib loading here, so that the lists of loaded and | |
5532 | unloaded libraries are correct before we handle "catch load" and | |
5533 | "catch unload". */ | |
5534 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5535 | { | |
5d268276 | 5536 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5537 | { |
5538 | handle_solib_event (); | |
5539 | break; | |
5540 | } | |
5541 | } | |
5542 | ||
f431efe5 PA |
5543 | /* Now go through the locations that caused the target to stop, and |
5544 | check whether we're interested in reporting this stop to higher | |
5545 | layers, or whether we should resume the target transparently. */ | |
5546 | ||
5547 | removed_any = 0; | |
5548 | ||
5760d0ab | 5549 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5550 | { |
5551 | if (!bs->stop) | |
5552 | continue; | |
5553 | ||
f431efe5 | 5554 | b = bs->breakpoint_at; |
348d480f PA |
5555 | b->ops->check_status (bs); |
5556 | if (bs->stop) | |
28010a5d | 5557 | { |
00431a78 | 5558 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5559 | |
429374b8 JK |
5560 | if (bs->stop) |
5561 | { | |
5562 | ++(b->hit_count); | |
76727919 | 5563 | gdb::observers::breakpoint_modified.notify (b); |
c906108c | 5564 | |
4a64f543 | 5565 | /* We will stop here. */ |
429374b8 JK |
5566 | if (b->disposition == disp_disable) |
5567 | { | |
816338b5 | 5568 | --(b->enable_count); |
1a853c52 | 5569 | if (b->enable_count <= 0) |
429374b8 | 5570 | b->enable_state = bp_disabled; |
f431efe5 | 5571 | removed_any = 1; |
429374b8 JK |
5572 | } |
5573 | if (b->silent) | |
5574 | bs->print = 0; | |
5575 | bs->commands = b->commands; | |
abf85f46 | 5576 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5577 | ? bs->commands.get () : NULL)) |
abf85f46 | 5578 | bs->print = 0; |
9d6e6e84 HZ |
5579 | |
5580 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5581 | } |
5582 | ||
348d480f | 5583 | } |
a9b3a50f PA |
5584 | |
5585 | /* Print nothing for this entry if we don't stop or don't | |
5586 | print. */ | |
5587 | if (!bs->stop || !bs->print) | |
5588 | bs->print_it = print_it_noop; | |
429374b8 | 5589 | } |
876fa593 | 5590 | |
d983da9c DJ |
5591 | /* If we aren't stopping, the value of some hardware watchpoint may |
5592 | not have changed, but the intermediate memory locations we are | |
5593 | watching may have. Don't bother if we're stopping; this will get | |
5594 | done later. */ | |
d832cb68 | 5595 | need_remove_insert = 0; |
5760d0ab JK |
5596 | if (! bpstat_causes_stop (bs_head)) |
5597 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5598 | if (!bs->stop |
f431efe5 PA |
5599 | && bs->breakpoint_at |
5600 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5601 | { |
3a5c3e22 PA |
5602 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5603 | ||
5604 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5605 | need_remove_insert = 1; |
d983da9c DJ |
5606 | } |
5607 | ||
d832cb68 | 5608 | if (need_remove_insert) |
44702360 | 5609 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5610 | else if (removed_any) |
44702360 | 5611 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5612 | |
5760d0ab | 5613 | return bs_head; |
c906108c | 5614 | } |
628fe4e4 JK |
5615 | |
5616 | static void | |
61c26be8 | 5617 | handle_jit_event (CORE_ADDR address) |
628fe4e4 | 5618 | { |
628fe4e4 JK |
5619 | struct gdbarch *gdbarch; |
5620 | ||
1eb8556f | 5621 | infrun_debug_printf ("handling bp_jit_event"); |
243a9253 | 5622 | |
628fe4e4 JK |
5623 | /* Switch terminal for any messages produced by |
5624 | breakpoint_re_set. */ | |
223ffa71 | 5625 | target_terminal::ours_for_output (); |
628fe4e4 | 5626 | |
61c26be8 MS |
5627 | gdbarch = get_frame_arch (get_current_frame ()); |
5628 | /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`, | |
5629 | thus it is expected that its objectfile can be found through | |
5630 | minimal symbol lookup. If it doesn't work (and assert fails), it | |
5631 | most likely means that `jit_breakpoint_re_set` was changes and this | |
5632 | function needs to be updated too. */ | |
5633 | bound_minimal_symbol jit_bp_sym = lookup_minimal_symbol_by_pc (address); | |
5634 | gdb_assert (jit_bp_sym.objfile != nullptr); | |
5635 | jit_event_handler (gdbarch, jit_bp_sym.objfile); | |
628fe4e4 | 5636 | |
223ffa71 | 5637 | target_terminal::inferior (); |
628fe4e4 JK |
5638 | } |
5639 | ||
5640 | /* Prepare WHAT final decision for infrun. */ | |
5641 | ||
5642 | /* Decide what infrun needs to do with this bpstat. */ | |
5643 | ||
c906108c | 5644 | struct bpstat_what |
0e30163f | 5645 | bpstat_what (bpstat bs_head) |
c906108c | 5646 | { |
c906108c | 5647 | struct bpstat_what retval; |
0e30163f | 5648 | bpstat bs; |
c906108c | 5649 | |
628fe4e4 | 5650 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5651 | retval.call_dummy = STOP_NONE; |
e2d0f980 | 5652 | retval.is_longjmp = false; |
628fe4e4 | 5653 | |
0e30163f | 5654 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5655 | { |
628fe4e4 JK |
5656 | /* Extract this BS's action. After processing each BS, we check |
5657 | if its action overrides all we've seem so far. */ | |
5658 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5659 | enum bptype bptype; | |
5660 | ||
c906108c | 5661 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5662 | { |
5663 | /* I suspect this can happen if it was a momentary | |
5664 | breakpoint which has since been deleted. */ | |
5665 | bptype = bp_none; | |
5666 | } | |
20874c92 | 5667 | else |
f431efe5 | 5668 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5669 | |
5670 | switch (bptype) | |
c906108c SS |
5671 | { |
5672 | case bp_none: | |
628fe4e4 | 5673 | break; |
c906108c SS |
5674 | case bp_breakpoint: |
5675 | case bp_hardware_breakpoint: | |
7c16b83e | 5676 | case bp_single_step: |
c906108c SS |
5677 | case bp_until: |
5678 | case bp_finish: | |
a9b3a50f | 5679 | case bp_shlib_event: |
c906108c SS |
5680 | if (bs->stop) |
5681 | { | |
5682 | if (bs->print) | |
628fe4e4 | 5683 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5684 | else |
628fe4e4 | 5685 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5686 | } |
5687 | else | |
628fe4e4 | 5688 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5689 | break; |
5690 | case bp_watchpoint: | |
5691 | case bp_hardware_watchpoint: | |
5692 | case bp_read_watchpoint: | |
5693 | case bp_access_watchpoint: | |
5694 | if (bs->stop) | |
5695 | { | |
5696 | if (bs->print) | |
628fe4e4 | 5697 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5698 | else |
628fe4e4 | 5699 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5700 | } |
5701 | else | |
628fe4e4 JK |
5702 | { |
5703 | /* There was a watchpoint, but we're not stopping. | |
5704 | This requires no further action. */ | |
5705 | } | |
c906108c SS |
5706 | break; |
5707 | case bp_longjmp: | |
e2e4d78b | 5708 | case bp_longjmp_call_dummy: |
186c406b | 5709 | case bp_exception: |
0a39bb32 PA |
5710 | if (bs->stop) |
5711 | { | |
5712 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5713 | retval.is_longjmp = bptype != bp_exception; | |
5714 | } | |
5715 | else | |
5716 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5717 | break; |
5718 | case bp_longjmp_resume: | |
186c406b | 5719 | case bp_exception_resume: |
0a39bb32 PA |
5720 | if (bs->stop) |
5721 | { | |
5722 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5723 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5724 | } | |
5725 | else | |
5726 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5727 | break; |
5728 | case bp_step_resume: | |
5729 | if (bs->stop) | |
628fe4e4 JK |
5730 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5731 | else | |
c906108c | 5732 | { |
628fe4e4 JK |
5733 | /* It is for the wrong frame. */ |
5734 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5735 | } |
c906108c | 5736 | break; |
2c03e5be PA |
5737 | case bp_hp_step_resume: |
5738 | if (bs->stop) | |
5739 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5740 | else | |
5741 | { | |
5742 | /* It is for the wrong frame. */ | |
5743 | this_action = BPSTAT_WHAT_SINGLE; | |
5744 | } | |
5745 | break; | |
c906108c | 5746 | case bp_watchpoint_scope: |
c4093a6a | 5747 | case bp_thread_event: |
1900040c | 5748 | case bp_overlay_event: |
0fd8e87f | 5749 | case bp_longjmp_master: |
aa7d318d | 5750 | case bp_std_terminate_master: |
186c406b | 5751 | case bp_exception_master: |
628fe4e4 | 5752 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5753 | break; |
ce78b96d | 5754 | case bp_catchpoint: |
c5aa993b JM |
5755 | if (bs->stop) |
5756 | { | |
5757 | if (bs->print) | |
628fe4e4 | 5758 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5759 | else |
628fe4e4 | 5760 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5761 | } |
5762 | else | |
628fe4e4 | 5763 | { |
cb1e4e32 PA |
5764 | /* Some catchpoints are implemented with breakpoints. |
5765 | For those, we need to step over the breakpoint. */ | |
5766 | if (bs->bp_location_at->loc_type != bp_loc_other) | |
5767 | this_action = BPSTAT_WHAT_SINGLE; | |
628fe4e4 JK |
5768 | } |
5769 | break; | |
628fe4e4 | 5770 | case bp_jit_event: |
628fe4e4 | 5771 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5772 | break; |
c906108c | 5773 | case bp_call_dummy: |
53a5351d JM |
5774 | /* Make sure the action is stop (silent or noisy), |
5775 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5776 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5777 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5778 | break; |
5779 | case bp_std_terminate: | |
5780 | /* Make sure the action is stop (silent or noisy), | |
5781 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5782 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5783 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5784 | break; |
1042e4c0 | 5785 | case bp_tracepoint: |
7a697b8d | 5786 | case bp_fast_tracepoint: |
0fb4aa4b | 5787 | case bp_static_tracepoint: |
1042e4c0 SS |
5788 | /* Tracepoint hits should not be reported back to GDB, and |
5789 | if one got through somehow, it should have been filtered | |
5790 | out already. */ | |
5791 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5792 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5793 | break; |
5794 | case bp_gnu_ifunc_resolver: | |
5795 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5796 | this_action = BPSTAT_WHAT_SINGLE; | |
5797 | break; | |
5798 | case bp_gnu_ifunc_resolver_return: | |
5799 | /* The breakpoint will be removed, execution will restart from the | |
5800 | PC of the former breakpoint. */ | |
5801 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5802 | break; | |
e7e0cddf SS |
5803 | |
5804 | case bp_dprintf: | |
a11cfd87 HZ |
5805 | if (bs->stop) |
5806 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5807 | else | |
5808 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5809 | break; |
5810 | ||
628fe4e4 JK |
5811 | default: |
5812 | internal_error (__FILE__, __LINE__, | |
5813 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5814 | } |
628fe4e4 | 5815 | |
325fac50 | 5816 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5817 | } |
628fe4e4 | 5818 | |
243a9253 PA |
5819 | return retval; |
5820 | } | |
628fe4e4 | 5821 | |
243a9253 PA |
5822 | void |
5823 | bpstat_run_callbacks (bpstat bs_head) | |
5824 | { | |
5825 | bpstat bs; | |
628fe4e4 | 5826 | |
0e30163f JK |
5827 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5828 | { | |
5829 | struct breakpoint *b = bs->breakpoint_at; | |
5830 | ||
5831 | if (b == NULL) | |
5832 | continue; | |
5833 | switch (b->type) | |
5834 | { | |
243a9253 | 5835 | case bp_jit_event: |
61c26be8 | 5836 | handle_jit_event (bs->bp_location_at->address); |
243a9253 | 5837 | break; |
0e30163f JK |
5838 | case bp_gnu_ifunc_resolver: |
5839 | gnu_ifunc_resolver_stop (b); | |
5840 | break; | |
5841 | case bp_gnu_ifunc_resolver_return: | |
5842 | gnu_ifunc_resolver_return_stop (b); | |
5843 | break; | |
5844 | } | |
5845 | } | |
c906108c SS |
5846 | } |
5847 | ||
4c462cb0 | 5848 | /* See breakpoint.h. */ |
c906108c | 5849 | |
4c462cb0 SM |
5850 | bool |
5851 | bpstat_should_step () | |
c906108c SS |
5852 | { |
5853 | struct breakpoint *b; | |
cc59ec59 | 5854 | |
c906108c | 5855 | ALL_BREAKPOINTS (b) |
717a8278 | 5856 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
4c462cb0 SM |
5857 | return true; |
5858 | return false; | |
c906108c SS |
5859 | } |
5860 | ||
4c462cb0 SM |
5861 | /* See breakpoint.h. */ |
5862 | ||
5863 | bool | |
67822962 PA |
5864 | bpstat_causes_stop (bpstat bs) |
5865 | { | |
5866 | for (; bs != NULL; bs = bs->next) | |
5867 | if (bs->stop) | |
4c462cb0 | 5868 | return true; |
67822962 | 5869 | |
4c462cb0 | 5870 | return false; |
67822962 PA |
5871 | } |
5872 | ||
c906108c | 5873 | \f |
c5aa993b | 5874 | |
170b53b2 UW |
5875 | /* Compute a string of spaces suitable to indent the next line |
5876 | so it starts at the position corresponding to the table column | |
5877 | named COL_NAME in the currently active table of UIOUT. */ | |
5878 | ||
5879 | static char * | |
5880 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5881 | { | |
5882 | static char wrap_indent[80]; | |
5883 | int i, total_width, width, align; | |
c5209615 | 5884 | const char *text; |
170b53b2 UW |
5885 | |
5886 | total_width = 0; | |
112e8700 | 5887 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5888 | { |
5889 | if (strcmp (text, col_name) == 0) | |
5890 | { | |
5891 | gdb_assert (total_width < sizeof wrap_indent); | |
5892 | memset (wrap_indent, ' ', total_width); | |
5893 | wrap_indent[total_width] = 0; | |
5894 | ||
5895 | return wrap_indent; | |
5896 | } | |
5897 | ||
5898 | total_width += width + 1; | |
5899 | } | |
5900 | ||
5901 | return NULL; | |
5902 | } | |
5903 | ||
b775012e LM |
5904 | /* Determine if the locations of this breakpoint will have their conditions |
5905 | evaluated by the target, host or a mix of both. Returns the following: | |
5906 | ||
5907 | "host": Host evals condition. | |
5908 | "host or target": Host or Target evals condition. | |
5909 | "target": Target evals condition. | |
5910 | */ | |
5911 | ||
5912 | static const char * | |
5913 | bp_condition_evaluator (struct breakpoint *b) | |
5914 | { | |
5915 | struct bp_location *bl; | |
5916 | char host_evals = 0; | |
5917 | char target_evals = 0; | |
5918 | ||
5919 | if (!b) | |
5920 | return NULL; | |
5921 | ||
5922 | if (!is_breakpoint (b)) | |
5923 | return NULL; | |
5924 | ||
5925 | if (gdb_evaluates_breakpoint_condition_p () | |
5926 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5927 | return condition_evaluation_host; | |
5928 | ||
5929 | for (bl = b->loc; bl; bl = bl->next) | |
5930 | { | |
5931 | if (bl->cond_bytecode) | |
5932 | target_evals++; | |
5933 | else | |
5934 | host_evals++; | |
5935 | } | |
5936 | ||
5937 | if (host_evals && target_evals) | |
5938 | return condition_evaluation_both; | |
5939 | else if (target_evals) | |
5940 | return condition_evaluation_target; | |
5941 | else | |
5942 | return condition_evaluation_host; | |
5943 | } | |
5944 | ||
5945 | /* Determine the breakpoint location's condition evaluator. This is | |
5946 | similar to bp_condition_evaluator, but for locations. */ | |
5947 | ||
5948 | static const char * | |
5949 | bp_location_condition_evaluator (struct bp_location *bl) | |
5950 | { | |
5951 | if (bl && !is_breakpoint (bl->owner)) | |
5952 | return NULL; | |
5953 | ||
5954 | if (gdb_evaluates_breakpoint_condition_p () | |
5955 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5956 | return condition_evaluation_host; | |
5957 | ||
5958 | if (bl && bl->cond_bytecode) | |
5959 | return condition_evaluation_target; | |
5960 | else | |
5961 | return condition_evaluation_host; | |
5962 | } | |
5963 | ||
859825b8 JK |
5964 | /* Print the LOC location out of the list of B->LOC locations. */ |
5965 | ||
170b53b2 UW |
5966 | static void |
5967 | print_breakpoint_location (struct breakpoint *b, | |
5968 | struct bp_location *loc) | |
0d381245 | 5969 | { |
79a45e25 | 5970 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5971 | |
5972 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5973 | |
859825b8 JK |
5974 | if (loc != NULL && loc->shlib_disabled) |
5975 | loc = NULL; | |
5976 | ||
6c95b8df PA |
5977 | if (loc != NULL) |
5978 | set_current_program_space (loc->pspace); | |
5979 | ||
56435ebe | 5980 | if (b->display_canonical) |
d28cd78a | 5981 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5982 | else if (loc && loc->symtab) |
0d381245 | 5983 | { |
4a27f119 KS |
5984 | const struct symbol *sym = loc->symbol; |
5985 | ||
0d381245 VP |
5986 | if (sym) |
5987 | { | |
112e8700 | 5988 | uiout->text ("in "); |
987012b8 | 5989 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 5990 | function_name_style.style ()); |
112e8700 SM |
5991 | uiout->text (" "); |
5992 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5993 | uiout->text ("at "); | |
0d381245 | 5994 | } |
112e8700 | 5995 | uiout->field_string ("file", |
cbe56571 | 5996 | symtab_to_filename_for_display (loc->symtab), |
e43b10e1 | 5997 | file_name_style.style ()); |
112e8700 | 5998 | uiout->text (":"); |
05cba821 | 5999 | |
112e8700 SM |
6000 | if (uiout->is_mi_like_p ()) |
6001 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6002 | |
381befee | 6003 | uiout->field_signed ("line", loc->line_number); |
0d381245 | 6004 | } |
859825b8 | 6005 | else if (loc) |
0d381245 | 6006 | { |
d7e74731 | 6007 | string_file stb; |
170b53b2 | 6008 | |
d7e74731 | 6009 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6010 | demangle, ""); |
112e8700 | 6011 | uiout->field_stream ("at", stb); |
0d381245 | 6012 | } |
859825b8 | 6013 | else |
f00aae0f | 6014 | { |
d28cd78a TT |
6015 | uiout->field_string ("pending", |
6016 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
6017 | /* If extra_string is available, it could be holding a condition |
6018 | or dprintf arguments. In either case, make sure it is printed, | |
6019 | too, but only for non-MI streams. */ | |
112e8700 | 6020 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6021 | { |
6022 | if (b->type == bp_dprintf) | |
112e8700 | 6023 | uiout->text (","); |
f00aae0f | 6024 | else |
112e8700 SM |
6025 | uiout->text (" "); |
6026 | uiout->text (b->extra_string); | |
f00aae0f KS |
6027 | } |
6028 | } | |
6c95b8df | 6029 | |
b775012e LM |
6030 | if (loc && is_breakpoint (b) |
6031 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6032 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6033 | { | |
112e8700 SM |
6034 | uiout->text (" ("); |
6035 | uiout->field_string ("evaluated-by", | |
b775012e | 6036 | bp_location_condition_evaluator (loc)); |
112e8700 | 6037 | uiout->text (")"); |
b775012e | 6038 | } |
0d381245 VP |
6039 | } |
6040 | ||
269b11a2 PA |
6041 | static const char * |
6042 | bptype_string (enum bptype type) | |
c906108c | 6043 | { |
c4093a6a JM |
6044 | struct ep_type_description |
6045 | { | |
6046 | enum bptype type; | |
a121b7c1 | 6047 | const char *description; |
c4093a6a JM |
6048 | }; |
6049 | static struct ep_type_description bptypes[] = | |
c906108c | 6050 | { |
c5aa993b JM |
6051 | {bp_none, "?deleted?"}, |
6052 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6053 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6054 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6055 | {bp_until, "until"}, |
6056 | {bp_finish, "finish"}, | |
6057 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6058 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6059 | {bp_read_watchpoint, "read watchpoint"}, |
6060 | {bp_access_watchpoint, "acc watchpoint"}, | |
6061 | {bp_longjmp, "longjmp"}, | |
6062 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6063 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6064 | {bp_exception, "exception"}, |
6065 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6066 | {bp_step_resume, "step resume"}, |
2c03e5be | 6067 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6068 | {bp_watchpoint_scope, "watchpoint scope"}, |
6069 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6070 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6071 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6072 | {bp_thread_event, "thread events"}, |
1900040c | 6073 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6074 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6075 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6076 | {bp_exception_master, "exception master"}, |
ce78b96d | 6077 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6078 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6079 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6080 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6081 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6082 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6083 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6084 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6085 | }; |
269b11a2 PA |
6086 | |
6087 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6088 | || ((int) type != bptypes[(int) type].type)) | |
6089 | internal_error (__FILE__, __LINE__, | |
6090 | _("bptypes table does not describe type #%d."), | |
6091 | (int) type); | |
6092 | ||
6093 | return bptypes[(int) type].description; | |
6094 | } | |
6095 | ||
998580f1 MK |
6096 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6097 | For CLI, prefix the list with the string 'inf'. */ | |
6098 | ||
6099 | static void | |
6100 | output_thread_groups (struct ui_out *uiout, | |
6101 | const char *field_name, | |
5c632425 | 6102 | const std::vector<int> &inf_nums, |
998580f1 MK |
6103 | int mi_only) |
6104 | { | |
112e8700 | 6105 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6106 | |
6107 | /* For backward compatibility, don't display inferiors in CLI unless | |
6108 | there are several. Always display them for MI. */ | |
6109 | if (!is_mi && mi_only) | |
6110 | return; | |
6111 | ||
10f489e5 | 6112 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6113 | |
5c632425 | 6114 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
6115 | { |
6116 | if (is_mi) | |
6117 | { | |
6118 | char mi_group[10]; | |
6119 | ||
5c632425 | 6120 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 6121 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6122 | } |
6123 | else | |
6124 | { | |
6125 | if (i == 0) | |
112e8700 | 6126 | uiout->text (" inf "); |
998580f1 | 6127 | else |
112e8700 | 6128 | uiout->text (", "); |
998580f1 | 6129 | |
5c632425 | 6130 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
6131 | } |
6132 | } | |
998580f1 MK |
6133 | } |
6134 | ||
a38118e5 PA |
6135 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
6136 | instead of going via breakpoint_ops::print_one. This makes "maint | |
6137 | info breakpoints" show the software breakpoint locations of | |
6138 | catchpoints, which are considered internal implementation | |
6139 | detail. */ | |
269b11a2 PA |
6140 | |
6141 | static void | |
6142 | print_one_breakpoint_location (struct breakpoint *b, | |
6143 | struct bp_location *loc, | |
6144 | int loc_number, | |
6145 | struct bp_location **last_loc, | |
a38118e5 | 6146 | int allflag, bool raw_loc) |
269b11a2 PA |
6147 | { |
6148 | struct command_line *l; | |
c2c6d25f | 6149 | static char bpenables[] = "nynny"; |
c906108c | 6150 | |
79a45e25 | 6151 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6152 | int header_of_multiple = 0; |
6153 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6154 | struct value_print_options opts; |
6155 | ||
6156 | get_user_print_options (&opts); | |
0d381245 VP |
6157 | |
6158 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6159 | /* See comment in print_one_breakpoint concerning treatment of |
6160 | breakpoints with single disabled location. */ | |
0d381245 VP |
6161 | if (loc == NULL |
6162 | && (b->loc != NULL | |
b5fa468f TBA |
6163 | && (b->loc->next != NULL |
6164 | || !b->loc->enabled || b->loc->disabled_by_cond))) | |
0d381245 VP |
6165 | header_of_multiple = 1; |
6166 | if (loc == NULL) | |
6167 | loc = b->loc; | |
6168 | ||
c4093a6a JM |
6169 | annotate_record (); |
6170 | ||
6171 | /* 1 */ | |
6172 | annotate_field (0); | |
0d381245 | 6173 | if (part_of_multiple) |
528e1572 | 6174 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
0d381245 | 6175 | else |
381befee | 6176 | uiout->field_signed ("number", b->number); |
c4093a6a JM |
6177 | |
6178 | /* 2 */ | |
6179 | annotate_field (1); | |
0d381245 | 6180 | if (part_of_multiple) |
112e8700 | 6181 | uiout->field_skip ("type"); |
269b11a2 | 6182 | else |
112e8700 | 6183 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6184 | |
6185 | /* 3 */ | |
6186 | annotate_field (2); | |
0d381245 | 6187 | if (part_of_multiple) |
112e8700 | 6188 | uiout->field_skip ("disp"); |
0d381245 | 6189 | else |
112e8700 | 6190 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6191 | |
c4093a6a JM |
6192 | /* 4 */ |
6193 | annotate_field (3); | |
0d381245 | 6194 | if (part_of_multiple) |
b5fa468f TBA |
6195 | uiout->field_string ("enabled", (loc->disabled_by_cond ? "N*" |
6196 | : (loc->enabled ? "y" : "n"))); | |
0d381245 | 6197 | else |
112e8700 | 6198 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
0d381245 | 6199 | |
c4093a6a | 6200 | /* 5 and 6 */ |
a38118e5 | 6201 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
b58a68fe | 6202 | b->ops->print_one (b, last_loc); |
3086aeae | 6203 | else |
a38118e5 PA |
6204 | { |
6205 | if (is_watchpoint (b)) | |
3a5c3e22 PA |
6206 | { |
6207 | struct watchpoint *w = (struct watchpoint *) b; | |
6208 | ||
6209 | /* Field 4, the address, is omitted (which makes the columns | |
6210 | not line up too nicely with the headers, but the effect | |
6211 | is relatively readable). */ | |
6212 | if (opts.addressprint) | |
112e8700 | 6213 | uiout->field_skip ("addr"); |
3a5c3e22 | 6214 | annotate_field (5); |
112e8700 | 6215 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6216 | } |
f06f1252 TT |
6217 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
6218 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6219 | { |
6220 | if (opts.addressprint) | |
6221 | { | |
6222 | annotate_field (4); | |
6223 | if (header_of_multiple) | |
7f6aba03 TT |
6224 | uiout->field_string ("addr", "<MULTIPLE>", |
6225 | metadata_style.style ()); | |
a38118e5 | 6226 | else if (b->loc == NULL || loc->shlib_disabled) |
7f6aba03 TT |
6227 | uiout->field_string ("addr", "<PENDING>", |
6228 | metadata_style.style ()); | |
a38118e5 PA |
6229 | else |
6230 | uiout->field_core_addr ("addr", | |
6231 | loc->gdbarch, loc->address); | |
6232 | } | |
6233 | annotate_field (5); | |
6234 | if (!header_of_multiple) | |
6235 | print_breakpoint_location (b, loc); | |
6236 | if (b->loc) | |
6237 | *last_loc = b->loc; | |
6238 | } | |
6239 | } | |
6c95b8df | 6240 | |
998580f1 | 6241 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6242 | { |
5c632425 | 6243 | std::vector<int> inf_nums; |
998580f1 | 6244 | int mi_only = 1; |
6c95b8df | 6245 | |
08036331 | 6246 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6247 | { |
6248 | if (inf->pspace == loc->pspace) | |
5c632425 | 6249 | inf_nums.push_back (inf->num); |
6c95b8df | 6250 | } |
998580f1 | 6251 | |
dda83cd7 | 6252 | /* For backward compatibility, don't display inferiors in CLI unless |
998580f1 MK |
6253 | there are several. Always display for MI. */ |
6254 | if (allflag | |
6255 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
94c93c35 | 6256 | && (program_spaces.size () > 1 |
998580f1 MK |
6257 | || number_of_inferiors () > 1) |
6258 | /* LOC is for existing B, it cannot be in | |
6259 | moribund_locations and thus having NULL OWNER. */ | |
6260 | && loc->owner->type != bp_catchpoint)) | |
6261 | mi_only = 0; | |
5c632425 | 6262 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6263 | } |
6264 | ||
4a306c9a | 6265 | if (!part_of_multiple) |
c4093a6a | 6266 | { |
4a306c9a JB |
6267 | if (b->thread != -1) |
6268 | { | |
6269 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6270 | "stop only in" line a little further down. */ |
112e8700 | 6271 | uiout->text (" thread "); |
381befee | 6272 | uiout->field_signed ("thread", b->thread); |
4a306c9a JB |
6273 | } |
6274 | else if (b->task != 0) | |
6275 | { | |
112e8700 | 6276 | uiout->text (" task "); |
381befee | 6277 | uiout->field_signed ("task", b->task); |
4a306c9a | 6278 | } |
c4093a6a | 6279 | } |
f1310107 | 6280 | |
112e8700 | 6281 | uiout->text ("\n"); |
f1310107 | 6282 | |
348d480f | 6283 | if (!part_of_multiple) |
f1310107 TJB |
6284 | b->ops->print_one_detail (b, uiout); |
6285 | ||
0d381245 | 6286 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6287 | { |
6288 | annotate_field (6); | |
112e8700 | 6289 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6290 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
dda83cd7 | 6291 | the frame ID. */ |
112e8700 | 6292 | uiout->field_core_addr ("frame", |
5af949e3 | 6293 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6294 | uiout->text ("\n"); |
c4093a6a JM |
6295 | } |
6296 | ||
28010a5d | 6297 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6298 | { |
6299 | annotate_field (7); | |
d77f58be | 6300 | if (is_tracepoint (b)) |
112e8700 | 6301 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6302 | else |
112e8700 SM |
6303 | uiout->text ("\tstop only if "); |
6304 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6305 | |
6306 | /* Print whether the target is doing the breakpoint's condition | |
6307 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6308 | if (is_breakpoint (b) | |
6309 | && breakpoint_condition_evaluation_mode () | |
6310 | == condition_evaluation_target) | |
6311 | { | |
6a831f06 PA |
6312 | uiout->message (" (%pF evals)", |
6313 | string_field ("evaluated-by", | |
6314 | bp_condition_evaluator (b))); | |
b775012e | 6315 | } |
112e8700 | 6316 | uiout->text ("\n"); |
0101ce28 JJ |
6317 | } |
6318 | ||
0d381245 | 6319 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6320 | { |
4a64f543 | 6321 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6322 | uiout->text ("\tstop only in thread "); |
6323 | if (uiout->is_mi_like_p ()) | |
381befee | 6324 | uiout->field_signed ("thread", b->thread); |
5d5658a1 PA |
6325 | else |
6326 | { | |
6327 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6328 | ||
112e8700 | 6329 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6330 | } |
112e8700 | 6331 | uiout->text ("\n"); |
c4093a6a JM |
6332 | } |
6333 | ||
556ec64d YQ |
6334 | if (!part_of_multiple) |
6335 | { | |
6336 | if (b->hit_count) | |
31f56a27 YQ |
6337 | { |
6338 | /* FIXME should make an annotation for this. */ | |
6339 | if (is_catchpoint (b)) | |
112e8700 | 6340 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6341 | else if (is_tracepoint (b)) |
112e8700 | 6342 | uiout->text ("\ttracepoint"); |
31f56a27 | 6343 | else |
112e8700 SM |
6344 | uiout->text ("\tbreakpoint"); |
6345 | uiout->text (" already hit "); | |
381befee | 6346 | uiout->field_signed ("times", b->hit_count); |
31f56a27 | 6347 | if (b->hit_count == 1) |
112e8700 | 6348 | uiout->text (" time\n"); |
31f56a27 | 6349 | else |
112e8700 | 6350 | uiout->text (" times\n"); |
31f56a27 | 6351 | } |
556ec64d YQ |
6352 | else |
6353 | { | |
31f56a27 | 6354 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 | 6355 | if (uiout->is_mi_like_p ()) |
381befee | 6356 | uiout->field_signed ("times", b->hit_count); |
556ec64d YQ |
6357 | } |
6358 | } | |
8b93c638 | 6359 | |
0d381245 | 6360 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6361 | { |
6362 | annotate_field (8); | |
6a831f06 PA |
6363 | uiout->message ("\tignore next %pF hits\n", |
6364 | signed_field ("ignore", b->ignore_count)); | |
c4093a6a | 6365 | } |
059fb39f | 6366 | |
816338b5 SS |
6367 | /* Note that an enable count of 1 corresponds to "enable once" |
6368 | behavior, which is reported by the combination of enablement and | |
6369 | disposition, so we don't need to mention it here. */ | |
6370 | if (!part_of_multiple && b->enable_count > 1) | |
6371 | { | |
6372 | annotate_field (8); | |
112e8700 | 6373 | uiout->text ("\tdisable after "); |
816338b5 SS |
6374 | /* Tweak the wording to clarify that ignore and enable counts |
6375 | are distinct, and have additive effect. */ | |
6376 | if (b->ignore_count) | |
112e8700 | 6377 | uiout->text ("additional "); |
816338b5 | 6378 | else |
112e8700 | 6379 | uiout->text ("next "); |
381befee | 6380 | uiout->field_signed ("enable", b->enable_count); |
112e8700 | 6381 | uiout->text (" hits\n"); |
816338b5 SS |
6382 | } |
6383 | ||
f196051f SS |
6384 | if (!part_of_multiple && is_tracepoint (b)) |
6385 | { | |
6386 | struct tracepoint *tp = (struct tracepoint *) b; | |
6387 | ||
6388 | if (tp->traceframe_usage) | |
6389 | { | |
112e8700 | 6390 | uiout->text ("\ttrace buffer usage "); |
381befee | 6391 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
112e8700 | 6392 | uiout->text (" bytes\n"); |
f196051f SS |
6393 | } |
6394 | } | |
d3ce09f5 | 6395 | |
d1b0a7bf | 6396 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6397 | if (!part_of_multiple && l) |
c4093a6a JM |
6398 | { |
6399 | annotate_field (9); | |
2e783024 | 6400 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6401 | print_command_lines (uiout, l, 4); |
c4093a6a | 6402 | } |
d24317b4 | 6403 | |
d9b3f62e | 6404 | if (is_tracepoint (b)) |
1042e4c0 | 6405 | { |
d9b3f62e PA |
6406 | struct tracepoint *t = (struct tracepoint *) b; |
6407 | ||
6408 | if (!part_of_multiple && t->pass_count) | |
6409 | { | |
6410 | annotate_field (10); | |
112e8700 | 6411 | uiout->text ("\tpass count "); |
381befee | 6412 | uiout->field_signed ("pass", t->pass_count); |
112e8700 | 6413 | uiout->text (" \n"); |
d9b3f62e | 6414 | } |
f2a8bc8a YQ |
6415 | |
6416 | /* Don't display it when tracepoint or tracepoint location is | |
6417 | pending. */ | |
6418 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6419 | { | |
6420 | annotate_field (11); | |
6421 | ||
112e8700 SM |
6422 | if (uiout->is_mi_like_p ()) |
6423 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6424 | loc->inserted ? "y" : "n"); |
6425 | else | |
6426 | { | |
6427 | if (loc->inserted) | |
112e8700 | 6428 | uiout->text ("\t"); |
f2a8bc8a | 6429 | else |
112e8700 SM |
6430 | uiout->text ("\tnot "); |
6431 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6432 | } |
6433 | } | |
1042e4c0 SS |
6434 | } |
6435 | ||
112e8700 | 6436 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6437 | { |
3a5c3e22 PA |
6438 | if (is_watchpoint (b)) |
6439 | { | |
6440 | struct watchpoint *w = (struct watchpoint *) b; | |
6441 | ||
112e8700 | 6442 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6443 | } |
f00aae0f | 6444 | else if (b->location != NULL |
d28cd78a | 6445 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6446 | uiout->field_string ("original-location", |
d28cd78a | 6447 | event_location_to_string (b->location.get ())); |
d24317b4 | 6448 | } |
c4093a6a | 6449 | } |
c5aa993b | 6450 | |
13674803 SM |
6451 | /* See breakpoint.h. */ |
6452 | ||
6453 | bool fix_multi_location_breakpoint_output_globally = false; | |
6454 | ||
0d381245 VP |
6455 | static void |
6456 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6457 | struct bp_location **last_loc, |
6c95b8df | 6458 | int allflag) |
0d381245 | 6459 | { |
79a45e25 | 6460 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6461 | bool use_fixed_output |
6462 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6463 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6464 | |
b4be1b06 | 6465 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
a38118e5 | 6466 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
8d3788bd | 6467 | |
b4be1b06 SM |
6468 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6469 | are outside. */ | |
6470 | if (!use_fixed_output) | |
6471 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6472 | |
6473 | /* If this breakpoint has custom print function, | |
6474 | it's already printed. Otherwise, print individual | |
6475 | locations, if any. */ | |
a38118e5 PA |
6476 | if (b->ops == NULL |
6477 | || b->ops->print_one == NULL | |
6478 | || allflag) | |
0d381245 | 6479 | { |
4a64f543 MS |
6480 | /* If breakpoint has a single location that is disabled, we |
6481 | print it as if it had several locations, since otherwise it's | |
6482 | hard to represent "breakpoint enabled, location disabled" | |
6483 | situation. | |
6484 | ||
6485 | Note that while hardware watchpoints have several locations | |
a38118e5 PA |
6486 | internally, that's not a property exposed to users. |
6487 | ||
6488 | Likewise, while catchpoints may be implemented with | |
6489 | breakpoints (e.g., catch throw), that's not a property | |
6490 | exposed to users. We do however display the internal | |
6491 | breakpoint locations with "maint info breakpoints". */ | |
6492 | if (!is_hardware_watchpoint (b) | |
f06f1252 TT |
6493 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
6494 | || is_ada_exception_catchpoint (b)) | |
a38118e5 | 6495 | && (allflag |
b5fa468f TBA |
6496 | || (b->loc && (b->loc->next |
6497 | || !b->loc->enabled | |
6498 | || b->loc->disabled_by_cond)))) | |
0d381245 | 6499 | { |
b4be1b06 SM |
6500 | gdb::optional<ui_out_emit_list> locations_list; |
6501 | ||
6502 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6503 | MI record. For later versions, place breakpoint locations in a | |
6504 | list. */ | |
6505 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6506 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6507 | |
b4be1b06 SM |
6508 | int n = 1; |
6509 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) | |
8d3788bd | 6510 | { |
b4be1b06 | 6511 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
a38118e5 PA |
6512 | print_one_breakpoint_location (b, loc, n, last_loc, |
6513 | allflag, allflag); | |
8d3788bd | 6514 | } |
0d381245 VP |
6515 | } |
6516 | } | |
6517 | } | |
6518 | ||
a6d9a66e UW |
6519 | static int |
6520 | breakpoint_address_bits (struct breakpoint *b) | |
6521 | { | |
6522 | int print_address_bits = 0; | |
6523 | struct bp_location *loc; | |
6524 | ||
c6d81124 PA |
6525 | /* Software watchpoints that aren't watching memory don't have an |
6526 | address to print. */ | |
6527 | if (is_no_memory_software_watchpoint (b)) | |
6528 | return 0; | |
6529 | ||
a6d9a66e UW |
6530 | for (loc = b->loc; loc; loc = loc->next) |
6531 | { | |
c7437ca6 PA |
6532 | int addr_bit; |
6533 | ||
c7437ca6 | 6534 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6535 | if (addr_bit > print_address_bits) |
6536 | print_address_bits = addr_bit; | |
6537 | } | |
6538 | ||
6539 | return print_address_bits; | |
6540 | } | |
0d381245 | 6541 | |
65630365 | 6542 | /* See breakpoint.h. */ |
c5aa993b | 6543 | |
65630365 PA |
6544 | void |
6545 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6546 | { |
a6d9a66e | 6547 | struct bp_location *dummy_loc = NULL; |
65630365 | 6548 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6549 | } |
c5aa993b | 6550 | |
09d682a4 TT |
6551 | /* Return true if this breakpoint was set by the user, false if it is |
6552 | internal or momentary. */ | |
6553 | ||
6554 | int | |
6555 | user_breakpoint_p (struct breakpoint *b) | |
6556 | { | |
46c6471b | 6557 | return b->number > 0; |
09d682a4 TT |
6558 | } |
6559 | ||
93daf339 TT |
6560 | /* See breakpoint.h. */ |
6561 | ||
6562 | int | |
6563 | pending_breakpoint_p (struct breakpoint *b) | |
6564 | { | |
6565 | return b->loc == NULL; | |
6566 | } | |
6567 | ||
5c458ae8 SM |
6568 | /* Print information on breakpoints (including watchpoints and tracepoints). |
6569 | ||
6570 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as | |
6571 | understood by number_or_range_parser. Only breakpoints included in this | |
6572 | list are then printed. | |
6573 | ||
6574 | If SHOW_INTERNAL is true, print internal breakpoints. | |
6575 | ||
6576 | If FILTER is non-NULL, call it on each breakpoint and only include the | |
6577 | ones for which it returns true. | |
6578 | ||
6579 | Return the total number of breakpoints listed. */ | |
c906108c | 6580 | |
d77f58be | 6581 | static int |
5c458ae8 | 6582 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
f2478a7e | 6583 | bool (*filter) (const struct breakpoint *)) |
c4093a6a | 6584 | { |
52f0bd74 | 6585 | struct breakpoint *b; |
a6d9a66e | 6586 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6587 | int nr_printable_breakpoints; |
79a45b7d | 6588 | struct value_print_options opts; |
a6d9a66e | 6589 | int print_address_bits = 0; |
269b11a2 | 6590 | int print_type_col_width = 14; |
79a45e25 | 6591 | struct ui_out *uiout = current_uiout; |
b5fa468f | 6592 | bool has_disabled_by_cond_location = false; |
269b11a2 | 6593 | |
79a45b7d TT |
6594 | get_user_print_options (&opts); |
6595 | ||
4a64f543 MS |
6596 | /* Compute the number of rows in the table, as well as the size |
6597 | required for address fields. */ | |
7f3b0473 AC |
6598 | nr_printable_breakpoints = 0; |
6599 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6600 | { |
6601 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6602 | if (filter && !filter (b)) | |
6603 | continue; | |
6604 | ||
5c458ae8 | 6605 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
e5a67952 | 6606 | accept. Skip the others. */ |
5c458ae8 | 6607 | if (bp_num_list != NULL && *bp_num_list != '\0') |
e5a67952 | 6608 | { |
5c458ae8 | 6609 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
e5a67952 | 6610 | continue; |
5c458ae8 | 6611 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
e5a67952 MS |
6612 | continue; |
6613 | } | |
269b11a2 | 6614 | |
5c458ae8 | 6615 | if (show_internal || user_breakpoint_p (b)) |
e5a67952 MS |
6616 | { |
6617 | int addr_bit, type_len; | |
a6d9a66e | 6618 | |
e5a67952 MS |
6619 | addr_bit = breakpoint_address_bits (b); |
6620 | if (addr_bit > print_address_bits) | |
6621 | print_address_bits = addr_bit; | |
269b11a2 | 6622 | |
e5a67952 MS |
6623 | type_len = strlen (bptype_string (b->type)); |
6624 | if (type_len > print_type_col_width) | |
6625 | print_type_col_width = type_len; | |
6626 | ||
6627 | nr_printable_breakpoints++; | |
6628 | } | |
6629 | } | |
7f3b0473 | 6630 | |
4a2b031d TT |
6631 | { |
6632 | ui_out_emit_table table_emitter (uiout, | |
6633 | opts.addressprint ? 6 : 5, | |
6634 | nr_printable_breakpoints, | |
6635 | "BreakpointTable"); | |
6636 | ||
6637 | if (nr_printable_breakpoints > 0) | |
6638 | annotate_breakpoints_headers (); | |
6639 | if (nr_printable_breakpoints > 0) | |
6640 | annotate_field (0); | |
6641 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6642 | if (nr_printable_breakpoints > 0) | |
6643 | annotate_field (1); | |
6644 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6645 | if (nr_printable_breakpoints > 0) | |
6646 | annotate_field (2); | |
6647 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6648 | if (nr_printable_breakpoints > 0) | |
6649 | annotate_field (3); | |
6650 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6651 | if (opts.addressprint) | |
6652 | { | |
6653 | if (nr_printable_breakpoints > 0) | |
6654 | annotate_field (4); | |
6655 | if (print_address_bits <= 32) | |
6656 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6657 | else | |
6658 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6659 | } | |
6660 | if (nr_printable_breakpoints > 0) | |
6661 | annotate_field (5); | |
6662 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6663 | uiout->table_body (); | |
6664 | if (nr_printable_breakpoints > 0) | |
6665 | annotate_breakpoints_table (); | |
6666 | ||
6667 | ALL_BREAKPOINTS (b) | |
6668 | { | |
6669 | QUIT; | |
6670 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6671 | if (filter && !filter (b)) | |
6672 | continue; | |
e5a67952 | 6673 | |
5c458ae8 | 6674 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
4a2b031d | 6675 | accept. Skip the others. */ |
e5a67952 | 6676 | |
5c458ae8 | 6677 | if (bp_num_list != NULL && *bp_num_list != '\0') |
4a2b031d | 6678 | { |
5c458ae8 | 6679 | if (show_internal) /* maintenance info breakpoint */ |
4a2b031d | 6680 | { |
5c458ae8 | 6681 | if (parse_and_eval_long (bp_num_list) != b->number) |
4a2b031d TT |
6682 | continue; |
6683 | } | |
6684 | else /* all others */ | |
6685 | { | |
5c458ae8 | 6686 | if (!number_is_in_list (bp_num_list, b->number)) |
4a2b031d TT |
6687 | continue; |
6688 | } | |
6689 | } | |
6690 | /* We only print out user settable breakpoints unless the | |
5c458ae8 SM |
6691 | show_internal is set. */ |
6692 | if (show_internal || user_breakpoint_p (b)) | |
b5fa468f TBA |
6693 | { |
6694 | print_one_breakpoint (b, &last_loc, show_internal); | |
6695 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
6696 | if (loc->disabled_by_cond) | |
6697 | has_disabled_by_cond_location = true; | |
6698 | } | |
4a2b031d TT |
6699 | } |
6700 | } | |
698384cd | 6701 | |
7f3b0473 | 6702 | if (nr_printable_breakpoints == 0) |
c906108c | 6703 | { |
4a64f543 MS |
6704 | /* If there's a filter, let the caller decide how to report |
6705 | empty list. */ | |
d77f58be SS |
6706 | if (!filter) |
6707 | { | |
5c458ae8 | 6708 | if (bp_num_list == NULL || *bp_num_list == '\0') |
112e8700 | 6709 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6710 | else |
112e8700 | 6711 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
5c458ae8 | 6712 | bp_num_list); |
d77f58be | 6713 | } |
c906108c SS |
6714 | } |
6715 | else | |
c4093a6a | 6716 | { |
a6d9a66e UW |
6717 | if (last_loc && !server_command) |
6718 | set_next_address (last_loc->gdbarch, last_loc->address); | |
b5fa468f TBA |
6719 | |
6720 | if (has_disabled_by_cond_location) | |
6721 | uiout->message (_("(*): Breakpoint condition is invalid at this " | |
6722 | "location.\n")); | |
c4093a6a | 6723 | } |
c906108c | 6724 | |
4a64f543 | 6725 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6726 | there have been breakpoints? */ |
c906108c | 6727 | annotate_breakpoints_table_end (); |
d77f58be SS |
6728 | |
6729 | return nr_printable_breakpoints; | |
c906108c SS |
6730 | } |
6731 | ||
ad443146 SS |
6732 | /* Display the value of default-collect in a way that is generally |
6733 | compatible with the breakpoint list. */ | |
6734 | ||
6735 | static void | |
6736 | default_collect_info (void) | |
6737 | { | |
79a45e25 PA |
6738 | struct ui_out *uiout = current_uiout; |
6739 | ||
ad443146 SS |
6740 | /* If it has no value (which is frequently the case), say nothing; a |
6741 | message like "No default-collect." gets in user's face when it's | |
6742 | not wanted. */ | |
6743 | if (!*default_collect) | |
6744 | return; | |
6745 | ||
6746 | /* The following phrase lines up nicely with per-tracepoint collect | |
6747 | actions. */ | |
112e8700 SM |
6748 | uiout->text ("default collect "); |
6749 | uiout->field_string ("default-collect", default_collect); | |
6750 | uiout->text (" \n"); | |
ad443146 SS |
6751 | } |
6752 | ||
c906108c | 6753 | static void |
0b39b52e | 6754 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6755 | { |
5c458ae8 | 6756 | breakpoint_1 (args, false, NULL); |
ad443146 SS |
6757 | |
6758 | default_collect_info (); | |
d77f58be SS |
6759 | } |
6760 | ||
6761 | static void | |
1d12d88f | 6762 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6763 | { |
5c458ae8 | 6764 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
79a45e25 | 6765 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6766 | |
6767 | if (num_printed == 0) | |
6768 | { | |
e5a67952 | 6769 | if (args == NULL || *args == '\0') |
112e8700 | 6770 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6771 | else |
112e8700 | 6772 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6773 | } |
c906108c SS |
6774 | } |
6775 | ||
7a292a7a | 6776 | static void |
4495129a | 6777 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6778 | { |
5c458ae8 | 6779 | breakpoint_1 (args, true, NULL); |
ad443146 SS |
6780 | |
6781 | default_collect_info (); | |
c906108c SS |
6782 | } |
6783 | ||
0d381245 | 6784 | static int |
714835d5 | 6785 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6786 | struct program_space *pspace, |
714835d5 | 6787 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6788 | { |
6789 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6790 | |
0d381245 VP |
6791 | for (; bl; bl = bl->next) |
6792 | { | |
6c95b8df PA |
6793 | if (bl->pspace == pspace |
6794 | && bl->address == pc | |
0d381245 VP |
6795 | && (!overlay_debugging || bl->section == section)) |
6796 | return 1; | |
6797 | } | |
6798 | return 0; | |
6799 | } | |
6800 | ||
672f9b60 | 6801 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6802 | concerns with logical breakpoints, so we match program spaces, not |
6803 | address spaces. */ | |
c906108c SS |
6804 | |
6805 | static void | |
6c95b8df PA |
6806 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6807 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6808 | struct obj_section *section, int thread) |
c906108c | 6809 | { |
52f0bd74 AC |
6810 | int others = 0; |
6811 | struct breakpoint *b; | |
c906108c SS |
6812 | |
6813 | ALL_BREAKPOINTS (b) | |
672f9b60 | 6814 | others += (user_breakpoint_p (b) |
dda83cd7 | 6815 | && breakpoint_has_pc (b, pspace, pc, section)); |
c906108c SS |
6816 | if (others > 0) |
6817 | { | |
a3f17187 AC |
6818 | if (others == 1) |
6819 | printf_filtered (_("Note: breakpoint ")); | |
6820 | else /* if (others == ???) */ | |
6821 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6822 | ALL_BREAKPOINTS (b) |
672f9b60 | 6823 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6824 | { |
6825 | others--; | |
6826 | printf_filtered ("%d", b->number); | |
6827 | if (b->thread == -1 && thread != -1) | |
6828 | printf_filtered (" (all threads)"); | |
6829 | else if (b->thread != -1) | |
6830 | printf_filtered (" (thread %d)", b->thread); | |
6831 | printf_filtered ("%s%s ", | |
059fb39f | 6832 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6833 | || b->enable_state == bp_call_disabled) |
0d381245 | 6834 | ? " (disabled)" |
0d381245 VP |
6835 | : ""), |
6836 | (others > 1) ? "," | |
6837 | : ((others == 1) ? " and" : "")); | |
6838 | } | |
6a831f06 PA |
6839 | current_uiout->message (_("also set at pc %ps.\n"), |
6840 | styled_string (address_style.style (), | |
6841 | paddress (gdbarch, pc))); | |
c906108c SS |
6842 | } |
6843 | } | |
6844 | \f | |
c906108c | 6845 | |
cb1e4e32 PA |
6846 | /* Return true iff it is meaningful to use the address member of LOC. |
6847 | For some breakpoint types, the locations' address members are | |
6848 | irrelevant and it makes no sense to attempt to compare them to | |
6849 | other addresses (or use them for any other purpose either). | |
2d134ed3 | 6850 | |
cb1e4e32 PA |
6851 | More specifically, software watchpoints and catchpoints that are |
6852 | not backed by breakpoints always have a zero valued location | |
6853 | address and we don't want to mark breakpoints of any of these types | |
6854 | to be a duplicate of an actual breakpoint location at address | |
6855 | zero. */ | |
e4f237da | 6856 | |
cb1e4e32 PA |
6857 | static bool |
6858 | bl_address_is_meaningful (bp_location *loc) | |
e4f237da | 6859 | { |
cb1e4e32 | 6860 | return loc->loc_type != bp_loc_other; |
2d134ed3 PA |
6861 | } |
6862 | ||
6863 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6864 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6865 | ||
6866 | static int | |
4a64f543 MS |
6867 | watchpoint_locations_match (struct bp_location *loc1, |
6868 | struct bp_location *loc2) | |
2d134ed3 | 6869 | { |
3a5c3e22 PA |
6870 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6871 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6872 | ||
6873 | /* Both of them must exist. */ | |
6874 | gdb_assert (w1 != NULL); | |
6875 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6876 | |
4a64f543 MS |
6877 | /* If the target can evaluate the condition expression in hardware, |
6878 | then we we need to insert both watchpoints even if they are at | |
6879 | the same place. Otherwise the watchpoint will only trigger when | |
6880 | the condition of whichever watchpoint was inserted evaluates to | |
6881 | true, not giving a chance for GDB to check the condition of the | |
6882 | other watchpoint. */ | |
3a5c3e22 | 6883 | if ((w1->cond_exp |
4a64f543 MS |
6884 | && target_can_accel_watchpoint_condition (loc1->address, |
6885 | loc1->length, | |
0cf6dd15 | 6886 | loc1->watchpoint_type, |
4d01a485 | 6887 | w1->cond_exp.get ())) |
3a5c3e22 | 6888 | || (w2->cond_exp |
4a64f543 MS |
6889 | && target_can_accel_watchpoint_condition (loc2->address, |
6890 | loc2->length, | |
0cf6dd15 | 6891 | loc2->watchpoint_type, |
4d01a485 | 6892 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6893 | return 0; |
6894 | ||
85d721b8 PA |
6895 | /* Note that this checks the owner's type, not the location's. In |
6896 | case the target does not support read watchpoints, but does | |
6897 | support access watchpoints, we'll have bp_read_watchpoint | |
6898 | watchpoints with hw_access locations. Those should be considered | |
6899 | duplicates of hw_read locations. The hw_read locations will | |
6900 | become hw_access locations later. */ | |
2d134ed3 PA |
6901 | return (loc1->owner->type == loc2->owner->type |
6902 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6903 | && loc1->address == loc2->address | |
6904 | && loc1->length == loc2->length); | |
e4f237da KB |
6905 | } |
6906 | ||
31e77af2 | 6907 | /* See breakpoint.h. */ |
6c95b8df | 6908 | |
31e77af2 | 6909 | int |
accd0bcd YQ |
6910 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6911 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6912 | { |
f5656ead | 6913 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6914 | || aspace1 == aspace2) |
6915 | && addr1 == addr2); | |
6916 | } | |
6917 | ||
f1310107 TJB |
6918 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6919 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6920 | matches ASPACE2. On targets that have global breakpoints, the address | |
6921 | space doesn't really matter. */ | |
6922 | ||
6923 | static int | |
accd0bcd YQ |
6924 | breakpoint_address_match_range (const address_space *aspace1, |
6925 | CORE_ADDR addr1, | |
6926 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6927 | CORE_ADDR addr2) |
6928 | { | |
f5656ead | 6929 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6930 | || aspace1 == aspace2) |
6931 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6932 | } | |
6933 | ||
6934 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6935 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6936 | matches the breakpoint's address space. On targets that have global | |
6937 | breakpoints, the address space doesn't really matter. */ | |
6938 | ||
6939 | static int | |
6940 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6941 | const address_space *aspace, |
f1310107 TJB |
6942 | CORE_ADDR addr) |
6943 | { | |
6944 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6945 | aspace, addr) | |
6946 | || (bl->length | |
6947 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6948 | bl->address, bl->length, | |
6949 | aspace, addr))); | |
6950 | } | |
6951 | ||
d35ae833 PA |
6952 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6953 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6954 | match happens only if ASPACE matches the breakpoint's address | |
6955 | space. On targets that have global breakpoints, the address space | |
6956 | doesn't really matter. */ | |
6957 | ||
6958 | static int | |
6959 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6960 | const address_space *aspace, |
d35ae833 PA |
6961 | CORE_ADDR addr, int len) |
6962 | { | |
6963 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6964 | || bl->pspace->aspace == aspace) | |
6965 | { | |
6966 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6967 | ||
6968 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6969 | return 1; | |
6970 | } | |
6971 | return 0; | |
6972 | } | |
6973 | ||
1e4d1764 YQ |
6974 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6975 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6976 | true, otherwise returns false. */ | |
6977 | ||
6978 | static int | |
6979 | tracepoint_locations_match (struct bp_location *loc1, | |
6980 | struct bp_location *loc2) | |
6981 | { | |
6982 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6983 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6984 | locations at the same address of different tracepoints are regarded as | |
6985 | different locations. */ | |
6986 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6987 | else | |
6988 | return 0; | |
6989 | } | |
6990 | ||
2d134ed3 | 6991 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
cb1e4e32 | 6992 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
7f32a4d5 PA |
6993 | the same location. If SW_HW_BPS_MATCH is true, then software |
6994 | breakpoint locations and hardware breakpoint locations match, | |
6995 | otherwise they don't. */ | |
2d134ed3 PA |
6996 | |
6997 | static int | |
7f32a4d5 PA |
6998 | breakpoint_locations_match (struct bp_location *loc1, |
6999 | struct bp_location *loc2, | |
7000 | bool sw_hw_bps_match) | |
2d134ed3 | 7001 | { |
2bdf28a0 JK |
7002 | int hw_point1, hw_point2; |
7003 | ||
7004 | /* Both of them must not be in moribund_locations. */ | |
7005 | gdb_assert (loc1->owner != NULL); | |
7006 | gdb_assert (loc2->owner != NULL); | |
7007 | ||
7008 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7009 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7010 | |
7011 | if (hw_point1 != hw_point2) | |
7012 | return 0; | |
7013 | else if (hw_point1) | |
7014 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7015 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7016 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7017 | else |
7f32a4d5 PA |
7018 | /* We compare bp_location.length in order to cover ranged |
7019 | breakpoints. Keep this in sync with | |
7020 | bp_location_is_less_than. */ | |
f1310107 TJB |
7021 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
7022 | loc2->pspace->aspace, loc2->address) | |
7f32a4d5 | 7023 | && (loc1->loc_type == loc2->loc_type || sw_hw_bps_match) |
f1310107 | 7024 | && loc1->length == loc2->length); |
2d134ed3 PA |
7025 | } |
7026 | ||
76897487 KB |
7027 | static void |
7028 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
dda83cd7 | 7029 | int bnum, int have_bnum) |
76897487 | 7030 | { |
f63fbe86 MS |
7031 | /* The longest string possibly returned by hex_string_custom |
7032 | is 50 chars. These must be at least that big for safety. */ | |
7033 | char astr1[64]; | |
7034 | char astr2[64]; | |
76897487 | 7035 | |
bb599908 PH |
7036 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7037 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7038 | if (have_bnum) |
8a3fe4f8 | 7039 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
dda83cd7 | 7040 | bnum, astr1, astr2); |
76897487 | 7041 | else |
8a3fe4f8 | 7042 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7043 | } |
7044 | ||
4a64f543 MS |
7045 | /* Adjust a breakpoint's address to account for architectural |
7046 | constraints on breakpoint placement. Return the adjusted address. | |
7047 | Note: Very few targets require this kind of adjustment. For most | |
7048 | targets, this function is simply the identity function. */ | |
76897487 KB |
7049 | |
7050 | static CORE_ADDR | |
a6d9a66e UW |
7051 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7052 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7053 | { |
a0de8c21 YQ |
7054 | if (bptype == bp_watchpoint |
7055 | || bptype == bp_hardware_watchpoint | |
7056 | || bptype == bp_read_watchpoint | |
7057 | || bptype == bp_access_watchpoint | |
7058 | || bptype == bp_catchpoint) | |
88f7da05 KB |
7059 | { |
7060 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
dda83cd7 | 7061 | have their addresses modified. */ |
88f7da05 KB |
7062 | return bpaddr; |
7063 | } | |
7c16b83e PA |
7064 | else if (bptype == bp_single_step) |
7065 | { | |
7066 | /* Single-step breakpoints should not have their addresses | |
7067 | modified. If there's any architectural constrain that | |
7068 | applies to this address, then it should have already been | |
7069 | taken into account when the breakpoint was created in the | |
7070 | first place. If we didn't do this, stepping through e.g., | |
7071 | Thumb-2 IT blocks would break. */ | |
7072 | return bpaddr; | |
7073 | } | |
76897487 KB |
7074 | else |
7075 | { | |
a0de8c21 YQ |
7076 | CORE_ADDR adjusted_bpaddr = bpaddr; |
7077 | ||
7078 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
7079 | { | |
7080 | /* Some targets have architectural constraints on the placement | |
7081 | of breakpoint instructions. Obtain the adjusted address. */ | |
7082 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
7083 | } | |
76897487 | 7084 | |
a0de8c21 | 7085 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
7086 | |
7087 | /* An adjusted breakpoint address can significantly alter | |
dda83cd7 | 7088 | a user's expectations. Print a warning if an adjustment |
76897487 KB |
7089 | is required. */ |
7090 | if (adjusted_bpaddr != bpaddr) | |
7091 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7092 | ||
7093 | return adjusted_bpaddr; | |
7094 | } | |
7095 | } | |
7096 | ||
cb1e4e32 PA |
7097 | static bp_loc_type |
7098 | bp_location_from_bp_type (bptype type) | |
7cc221ef | 7099 | { |
cb1e4e32 | 7100 | switch (type) |
e049a4b5 DJ |
7101 | { |
7102 | case bp_breakpoint: | |
7c16b83e | 7103 | case bp_single_step: |
e049a4b5 DJ |
7104 | case bp_until: |
7105 | case bp_finish: | |
7106 | case bp_longjmp: | |
7107 | case bp_longjmp_resume: | |
e2e4d78b | 7108 | case bp_longjmp_call_dummy: |
186c406b TT |
7109 | case bp_exception: |
7110 | case bp_exception_resume: | |
e049a4b5 | 7111 | case bp_step_resume: |
2c03e5be | 7112 | case bp_hp_step_resume: |
e049a4b5 DJ |
7113 | case bp_watchpoint_scope: |
7114 | case bp_call_dummy: | |
aa7d318d | 7115 | case bp_std_terminate: |
e049a4b5 DJ |
7116 | case bp_shlib_event: |
7117 | case bp_thread_event: | |
7118 | case bp_overlay_event: | |
4efc6507 | 7119 | case bp_jit_event: |
0fd8e87f | 7120 | case bp_longjmp_master: |
aa7d318d | 7121 | case bp_std_terminate_master: |
186c406b | 7122 | case bp_exception_master: |
0e30163f JK |
7123 | case bp_gnu_ifunc_resolver: |
7124 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7125 | case bp_dprintf: |
cb1e4e32 | 7126 | return bp_loc_software_breakpoint; |
e049a4b5 | 7127 | case bp_hardware_breakpoint: |
cb1e4e32 | 7128 | return bp_loc_hardware_breakpoint; |
e049a4b5 DJ |
7129 | case bp_hardware_watchpoint: |
7130 | case bp_read_watchpoint: | |
7131 | case bp_access_watchpoint: | |
cb1e4e32 | 7132 | return bp_loc_hardware_watchpoint; |
e049a4b5 | 7133 | case bp_watchpoint: |
ce78b96d | 7134 | case bp_catchpoint: |
15c3d785 PA |
7135 | case bp_tracepoint: |
7136 | case bp_fast_tracepoint: | |
0fb4aa4b | 7137 | case bp_static_tracepoint: |
cb1e4e32 | 7138 | return bp_loc_other; |
e049a4b5 | 7139 | default: |
e2e0b3e5 | 7140 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 | 7141 | } |
cb1e4e32 PA |
7142 | } |
7143 | ||
7144 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) | |
7145 | { | |
7146 | this->owner = owner; | |
7147 | this->cond_bytecode = NULL; | |
7148 | this->shlib_disabled = 0; | |
7149 | this->enabled = 1; | |
b5fa468f | 7150 | this->disabled_by_cond = false; |
cb1e4e32 PA |
7151 | |
7152 | this->loc_type = type; | |
e049a4b5 | 7153 | |
cb1e4e32 PA |
7154 | if (this->loc_type == bp_loc_software_breakpoint |
7155 | || this->loc_type == bp_loc_hardware_breakpoint) | |
7156 | mark_breakpoint_location_modified (this); | |
7157 | ||
b6433ede | 7158 | incref (); |
cb1e4e32 PA |
7159 | } |
7160 | ||
7161 | bp_location::bp_location (breakpoint *owner) | |
7162 | : bp_location::bp_location (owner, | |
7163 | bp_location_from_bp_type (owner->type)) | |
7164 | { | |
28010a5d PA |
7165 | } |
7166 | ||
7167 | /* Allocate a struct bp_location. */ | |
7168 | ||
7169 | static struct bp_location * | |
7170 | allocate_bp_location (struct breakpoint *bpt) | |
7171 | { | |
348d480f PA |
7172 | return bpt->ops->allocate_location (bpt); |
7173 | } | |
7cc221ef | 7174 | |
f431efe5 PA |
7175 | /* Decrement reference count. If the reference count reaches 0, |
7176 | destroy the bp_location. Sets *BLP to NULL. */ | |
7177 | ||
7178 | static void | |
7179 | decref_bp_location (struct bp_location **blp) | |
7180 | { | |
b6433ede | 7181 | bp_location_ref_policy::decref (*blp); |
f431efe5 PA |
7182 | *blp = NULL; |
7183 | } | |
7184 | ||
346774a9 | 7185 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7186 | |
b270e6f9 TT |
7187 | static breakpoint * |
7188 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7189 | { |
346774a9 | 7190 | struct breakpoint *b1; |
b270e6f9 | 7191 | struct breakpoint *result = b.get (); |
c906108c | 7192 | |
346774a9 PA |
7193 | /* Add this breakpoint to the end of the chain so that a list of |
7194 | breakpoints will come out in order of increasing numbers. */ | |
7195 | ||
7196 | b1 = breakpoint_chain; | |
7197 | if (b1 == 0) | |
b270e6f9 | 7198 | breakpoint_chain = b.release (); |
346774a9 PA |
7199 | else |
7200 | { | |
7201 | while (b1->next) | |
7202 | b1 = b1->next; | |
b270e6f9 | 7203 | b1->next = b.release (); |
346774a9 | 7204 | } |
b270e6f9 TT |
7205 | |
7206 | return result; | |
346774a9 PA |
7207 | } |
7208 | ||
7209 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7210 | ||
7211 | static void | |
7212 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7213 | struct gdbarch *gdbarch, | |
28010a5d | 7214 | enum bptype bptype, |
c0a91b2b | 7215 | const struct breakpoint_ops *ops) |
346774a9 | 7216 | { |
348d480f PA |
7217 | gdb_assert (ops != NULL); |
7218 | ||
28010a5d | 7219 | b->ops = ops; |
4d28f7a8 | 7220 | b->type = bptype; |
a6d9a66e | 7221 | b->gdbarch = gdbarch; |
c906108c SS |
7222 | b->language = current_language->la_language; |
7223 | b->input_radix = input_radix; | |
d0fb5eae | 7224 | b->related_breakpoint = b; |
346774a9 PA |
7225 | } |
7226 | ||
7227 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7228 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7229 | |
7230 | static struct breakpoint * | |
7231 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7232 | enum bptype bptype, |
c0a91b2b | 7233 | const struct breakpoint_ops *ops) |
346774a9 | 7234 | { |
3b0871f4 | 7235 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7236 | |
3b0871f4 | 7237 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7238 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7239 | } |
7240 | ||
0ba852ab | 7241 | /* Initialize loc->function_name. */ |
0e30163f | 7242 | |
0d381245 | 7243 | static void |
0ba852ab | 7244 | set_breakpoint_location_function (struct bp_location *loc) |
0d381245 | 7245 | { |
2bdf28a0 JK |
7246 | gdb_assert (loc->owner != NULL); |
7247 | ||
0d381245 | 7248 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7249 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7250 | || is_tracepoint (loc->owner)) |
0d381245 | 7251 | { |
2c02bd72 | 7252 | const char *function_name; |
0e30163f | 7253 | |
3467ec66 | 7254 | if (loc->msymbol != NULL |
f50776aa | 7255 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
0ba852ab | 7256 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
0e30163f JK |
7257 | { |
7258 | struct breakpoint *b = loc->owner; | |
7259 | ||
c9d95fa3 | 7260 | function_name = loc->msymbol->linkage_name (); |
3467ec66 PA |
7261 | |
7262 | if (b->type == bp_breakpoint && b->loc == loc | |
7263 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7264 | { |
7265 | /* Create only the whole new breakpoint of this type but do not | |
7266 | mess more complicated breakpoints with multiple locations. */ | |
7267 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b | 7268 | /* Remember the resolver's address for use by the return |
dda83cd7 | 7269 | breakpoint. */ |
3467ec66 | 7270 | loc->related_address = loc->address; |
0e30163f JK |
7271 | } |
7272 | } | |
3467ec66 PA |
7273 | else |
7274 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7275 | |
2c02bd72 DE |
7276 | if (function_name) |
7277 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7278 | } |
7279 | } | |
7280 | ||
a6d9a66e | 7281 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7282 | struct gdbarch * |
a6d9a66e UW |
7283 | get_sal_arch (struct symtab_and_line sal) |
7284 | { | |
7285 | if (sal.section) | |
08feed99 | 7286 | return sal.section->objfile->arch (); |
a6d9a66e | 7287 | if (sal.symtab) |
08feed99 | 7288 | return SYMTAB_OBJFILE (sal.symtab)->arch (); |
a6d9a66e UW |
7289 | |
7290 | return NULL; | |
7291 | } | |
7292 | ||
346774a9 PA |
7293 | /* Low level routine for partially initializing a breakpoint of type |
7294 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7295 | file name, and line number are provided by SAL. |
0d381245 VP |
7296 | |
7297 | It is expected that the caller will complete the initialization of | |
7298 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7299 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7300 | |
346774a9 PA |
7301 | static void |
7302 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7303 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7304 | const struct breakpoint_ops *ops) |
0d381245 | 7305 | { |
28010a5d | 7306 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7307 | |
3742cc8b | 7308 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7309 | |
6c95b8df PA |
7310 | if (bptype != bp_catchpoint) |
7311 | gdb_assert (sal.pspace != NULL); | |
7312 | ||
f8eba3c6 TT |
7313 | /* Store the program space that was used to set the breakpoint, |
7314 | except for ordinary breakpoints, which are independent of the | |
7315 | program space. */ | |
7316 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7317 | b->pspace = sal.pspace; | |
346774a9 | 7318 | } |
c906108c | 7319 | |
346774a9 PA |
7320 | /* set_raw_breakpoint is a low level routine for allocating and |
7321 | partially initializing a breakpoint of type BPTYPE. The newly | |
7322 | created breakpoint's address, section, source file name, and line | |
7323 | number are provided by SAL. The newly created and partially | |
7324 | initialized breakpoint is added to the breakpoint chain and | |
7325 | is also returned as the value of this function. | |
7326 | ||
7327 | It is expected that the caller will complete the initialization of | |
7328 | the newly created breakpoint struct as well as output any status | |
7329 | information regarding the creation of a new breakpoint. In | |
7330 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7331 | number! Care should be taken to not allow an error to occur | |
7332 | prior to completing the initialization of the breakpoint. If this | |
7333 | should happen, a bogus breakpoint will be left on the chain. */ | |
7334 | ||
7335 | struct breakpoint * | |
7336 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7337 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7338 | const struct breakpoint_ops *ops) |
346774a9 | 7339 | { |
3b0871f4 | 7340 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7341 | |
3b0871f4 | 7342 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7343 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7344 | } |
7345 | ||
53a5351d | 7346 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7347 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7348 | initiated the operation. */ | |
c906108c SS |
7349 | |
7350 | void | |
186c406b | 7351 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7352 | { |
35df4500 | 7353 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7354 | int thread = tp->global_num; |
0fd8e87f UW |
7355 | |
7356 | /* To avoid having to rescan all objfile symbols at every step, | |
7357 | we maintain a list of continually-inserted but always disabled | |
7358 | longjmp "master" breakpoints. Here, we simply create momentary | |
7359 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7360 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7361 | if (b->pspace == current_program_space |
186c406b TT |
7362 | && (b->type == bp_longjmp_master |
7363 | || b->type == bp_exception_master)) | |
0fd8e87f | 7364 | { |
06edf0c0 PA |
7365 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7366 | struct breakpoint *clone; | |
cc59ec59 | 7367 | |
e2e4d78b JK |
7368 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7369 | after their removal. */ | |
06edf0c0 | 7370 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7371 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7372 | clone->thread = thread; |
7373 | } | |
186c406b TT |
7374 | |
7375 | tp->initiating_frame = frame; | |
c906108c SS |
7376 | } |
7377 | ||
611c83ae | 7378 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7379 | void |
611c83ae | 7380 | delete_longjmp_breakpoint (int thread) |
c906108c | 7381 | { |
35df4500 | 7382 | struct breakpoint *b, *b_tmp; |
c906108c | 7383 | |
35df4500 | 7384 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7385 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7386 | { |
7387 | if (b->thread == thread) | |
7388 | delete_breakpoint (b); | |
7389 | } | |
c906108c SS |
7390 | } |
7391 | ||
f59f708a PA |
7392 | void |
7393 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7394 | { | |
7395 | struct breakpoint *b, *b_tmp; | |
7396 | ||
7397 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7398 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7399 | { | |
7400 | if (b->thread == thread) | |
7401 | b->disposition = disp_del_at_next_stop; | |
7402 | } | |
7403 | } | |
7404 | ||
e2e4d78b JK |
7405 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7406 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7407 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7408 | breakpoints. */ | |
7409 | ||
7410 | struct breakpoint * | |
7411 | set_longjmp_breakpoint_for_call_dummy (void) | |
7412 | { | |
7413 | struct breakpoint *b, *retval = NULL; | |
7414 | ||
7415 | ALL_BREAKPOINTS (b) | |
7416 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7417 | { | |
7418 | struct breakpoint *new_b; | |
7419 | ||
7420 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7421 | &momentary_breakpoint_ops, |
7422 | 1); | |
00431a78 | 7423 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7424 | |
7425 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7426 | ||
7427 | gdb_assert (new_b->related_breakpoint == new_b); | |
7428 | if (retval == NULL) | |
7429 | retval = new_b; | |
7430 | new_b->related_breakpoint = retval; | |
7431 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7432 | retval = retval->related_breakpoint; | |
7433 | retval->related_breakpoint = new_b; | |
7434 | } | |
7435 | ||
7436 | return retval; | |
7437 | } | |
7438 | ||
7439 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7440 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7441 | stack. |
7442 | ||
7443 | You should call this function only at places where it is safe to currently | |
7444 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7445 | frames. */ | |
7446 | ||
7447 | void | |
b67a2c6f | 7448 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7449 | { |
7450 | struct breakpoint *b, *b_tmp; | |
7451 | ||
7452 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7453 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7454 | { |
7455 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7456 | ||
7457 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7458 | dummy_b = dummy_b->related_breakpoint; | |
7459 | if (dummy_b->type != bp_call_dummy | |
7460 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7461 | continue; | |
7462 | ||
00431a78 | 7463 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7464 | |
7465 | while (b->related_breakpoint != b) | |
7466 | { | |
7467 | if (b_tmp == b->related_breakpoint) | |
7468 | b_tmp = b->related_breakpoint->next; | |
7469 | delete_breakpoint (b->related_breakpoint); | |
7470 | } | |
7471 | delete_breakpoint (b); | |
7472 | } | |
7473 | } | |
7474 | ||
1900040c MS |
7475 | void |
7476 | enable_overlay_breakpoints (void) | |
7477 | { | |
52f0bd74 | 7478 | struct breakpoint *b; |
1900040c MS |
7479 | |
7480 | ALL_BREAKPOINTS (b) | |
7481 | if (b->type == bp_overlay_event) | |
7482 | { | |
7483 | b->enable_state = bp_enabled; | |
44702360 | 7484 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7485 | overlay_events_enabled = 1; |
1900040c MS |
7486 | } |
7487 | } | |
7488 | ||
7489 | void | |
7490 | disable_overlay_breakpoints (void) | |
7491 | { | |
52f0bd74 | 7492 | struct breakpoint *b; |
1900040c MS |
7493 | |
7494 | ALL_BREAKPOINTS (b) | |
7495 | if (b->type == bp_overlay_event) | |
7496 | { | |
7497 | b->enable_state = bp_disabled; | |
44702360 | 7498 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7499 | overlay_events_enabled = 0; |
1900040c MS |
7500 | } |
7501 | } | |
7502 | ||
aa7d318d TT |
7503 | /* Set an active std::terminate breakpoint for each std::terminate |
7504 | master breakpoint. */ | |
7505 | void | |
7506 | set_std_terminate_breakpoint (void) | |
7507 | { | |
35df4500 | 7508 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7509 | |
35df4500 | 7510 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7511 | if (b->pspace == current_program_space |
7512 | && b->type == bp_std_terminate_master) | |
7513 | { | |
06edf0c0 | 7514 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7515 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7516 | } |
7517 | } | |
7518 | ||
7519 | /* Delete all the std::terminate breakpoints. */ | |
7520 | void | |
7521 | delete_std_terminate_breakpoint (void) | |
7522 | { | |
35df4500 | 7523 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7524 | |
35df4500 | 7525 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7526 | if (b->type == bp_std_terminate) |
7527 | delete_breakpoint (b); | |
7528 | } | |
7529 | ||
c4093a6a | 7530 | struct breakpoint * |
a6d9a66e | 7531 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7532 | { |
7533 | struct breakpoint *b; | |
c4093a6a | 7534 | |
06edf0c0 PA |
7535 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7536 | &internal_breakpoint_ops); | |
7537 | ||
b5de0fa7 | 7538 | b->enable_state = bp_enabled; |
f00aae0f | 7539 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7540 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7541 | |
44702360 | 7542 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7543 | |
c4093a6a JM |
7544 | return b; |
7545 | } | |
7546 | ||
0101ce28 JJ |
7547 | struct lang_and_radix |
7548 | { | |
7549 | enum language lang; | |
7550 | int radix; | |
7551 | }; | |
7552 | ||
4efc6507 DE |
7553 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7554 | ||
7555 | struct breakpoint * | |
7556 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7557 | { | |
2a7f3dff PA |
7558 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7559 | &internal_breakpoint_ops); | |
4efc6507 | 7560 | } |
0101ce28 | 7561 | |
03673fc7 PP |
7562 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7563 | ||
7564 | void | |
7565 | remove_jit_event_breakpoints (void) | |
7566 | { | |
7567 | struct breakpoint *b, *b_tmp; | |
7568 | ||
7569 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7570 | if (b->type == bp_jit_event | |
7571 | && b->loc->pspace == current_program_space) | |
7572 | delete_breakpoint (b); | |
7573 | } | |
7574 | ||
cae688ec JJ |
7575 | void |
7576 | remove_solib_event_breakpoints (void) | |
7577 | { | |
35df4500 | 7578 | struct breakpoint *b, *b_tmp; |
cae688ec | 7579 | |
35df4500 | 7580 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7581 | if (b->type == bp_shlib_event |
7582 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7583 | delete_breakpoint (b); |
7584 | } | |
7585 | ||
f37f681c PA |
7586 | /* See breakpoint.h. */ |
7587 | ||
7588 | void | |
7589 | remove_solib_event_breakpoints_at_next_stop (void) | |
7590 | { | |
7591 | struct breakpoint *b, *b_tmp; | |
7592 | ||
7593 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7594 | if (b->type == bp_shlib_event | |
7595 | && b->loc->pspace == current_program_space) | |
7596 | b->disposition = disp_del_at_next_stop; | |
7597 | } | |
7598 | ||
04086b45 PA |
7599 | /* Helper for create_solib_event_breakpoint / |
7600 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7601 | INSERT_MODE to pass through to update_global_location_list. */ | |
7602 | ||
7603 | static struct breakpoint * | |
7604 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7605 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7606 | { |
7607 | struct breakpoint *b; | |
7608 | ||
06edf0c0 PA |
7609 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7610 | &internal_breakpoint_ops); | |
04086b45 | 7611 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7612 | return b; |
7613 | } | |
7614 | ||
04086b45 PA |
7615 | struct breakpoint * |
7616 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7617 | { | |
7618 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7619 | } | |
7620 | ||
f37f681c PA |
7621 | /* See breakpoint.h. */ |
7622 | ||
7623 | struct breakpoint * | |
7624 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7625 | { | |
7626 | struct breakpoint *b; | |
7627 | ||
04086b45 PA |
7628 | /* Explicitly tell update_global_location_list to insert |
7629 | locations. */ | |
7630 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7631 | if (!b->loc->inserted) |
7632 | { | |
7633 | delete_breakpoint (b); | |
7634 | return NULL; | |
7635 | } | |
7636 | return b; | |
7637 | } | |
7638 | ||
cae688ec JJ |
7639 | /* Disable any breakpoints that are on code in shared libraries. Only |
7640 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7641 | ||
7642 | void | |
cb851954 | 7643 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7644 | { |
876fa593 | 7645 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7646 | |
876fa593 | 7647 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7648 | { |
2bdf28a0 | 7649 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7650 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7651 | |
4a64f543 MS |
7652 | /* We apply the check to all breakpoints, including disabled for |
7653 | those with loc->duplicate set. This is so that when breakpoint | |
7654 | becomes enabled, or the duplicate is removed, gdb will try to | |
7655 | insert all breakpoints. If we don't set shlib_disabled here, | |
7656 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7657 | if (((b->type == bp_breakpoint) |
508ccb1f | 7658 | || (b->type == bp_jit_event) |
1042e4c0 | 7659 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7660 | || (is_tracepoint (b))) |
6c95b8df | 7661 | && loc->pspace == current_program_space |
0d381245 | 7662 | && !loc->shlib_disabled |
6c95b8df | 7663 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7664 | ) |
0d381245 VP |
7665 | { |
7666 | loc->shlib_disabled = 1; | |
7667 | } | |
cae688ec JJ |
7668 | } |
7669 | } | |
7670 | ||
63644780 NB |
7671 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7672 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7673 | disabled ones can just stay disabled. */ | |
84acb35a | 7674 | |
75149521 | 7675 | static void |
84acb35a JJ |
7676 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7677 | { | |
876fa593 | 7678 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7679 | int disabled_shlib_breaks = 0; |
7680 | ||
876fa593 | 7681 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7682 | { |
2bdf28a0 | 7683 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7684 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7685 | |
1e4d1764 | 7686 | if (solib->pspace == loc->pspace |
e2dd7057 | 7687 | && !loc->shlib_disabled |
1e4d1764 YQ |
7688 | && (((b->type == bp_breakpoint |
7689 | || b->type == bp_jit_event | |
7690 | || b->type == bp_hardware_breakpoint) | |
7691 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7692 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7693 | || is_tracepoint (b)) | |
e2dd7057 | 7694 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7695 | { |
e2dd7057 PP |
7696 | loc->shlib_disabled = 1; |
7697 | /* At this point, we cannot rely on remove_breakpoint | |
7698 | succeeding so we must mark the breakpoint as not inserted | |
7699 | to prevent future errors occurring in remove_breakpoints. */ | |
7700 | loc->inserted = 0; | |
8d3788bd VP |
7701 | |
7702 | /* This may cause duplicate notifications for the same breakpoint. */ | |
76727919 | 7703 | gdb::observers::breakpoint_modified.notify (b); |
8d3788bd | 7704 | |
e2dd7057 PP |
7705 | if (!disabled_shlib_breaks) |
7706 | { | |
223ffa71 | 7707 | target_terminal::ours_for_output (); |
3e43a32a MS |
7708 | warning (_("Temporarily disabling breakpoints " |
7709 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7710 | solib->so_name); |
84acb35a | 7711 | } |
e2dd7057 | 7712 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7713 | } |
7714 | } | |
84acb35a JJ |
7715 | } |
7716 | ||
63644780 NB |
7717 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7718 | notification of free_objfile. Only apply to enabled breakpoints, | |
7719 | disabled ones can just stay disabled. */ | |
7720 | ||
7721 | static void | |
7722 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7723 | { | |
7724 | struct breakpoint *b; | |
7725 | ||
7726 | if (objfile == NULL) | |
7727 | return; | |
7728 | ||
d03de421 PA |
7729 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7730 | managed by the user with add-symbol-file/remove-symbol-file. | |
7731 | Similarly to how breakpoints in shared libraries are handled in | |
7732 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7733 | shlib_disabled so they end up uninserted on the next global |
7734 | location list update. Shared libraries not loaded by the user | |
7735 | aren't handled here -- they're already handled in | |
7736 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7737 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7738 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7739 | main objfile). */ | |
7740 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7741 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7742 | return; |
7743 | ||
7744 | ALL_BREAKPOINTS (b) | |
7745 | { | |
7746 | struct bp_location *loc; | |
7747 | int bp_modified = 0; | |
7748 | ||
7749 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7750 | continue; | |
7751 | ||
7752 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7753 | { | |
7754 | CORE_ADDR loc_addr = loc->address; | |
7755 | ||
7756 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7757 | && loc->loc_type != bp_loc_software_breakpoint) | |
7758 | continue; | |
7759 | ||
7760 | if (loc->shlib_disabled != 0) | |
7761 | continue; | |
7762 | ||
7763 | if (objfile->pspace != loc->pspace) | |
7764 | continue; | |
7765 | ||
7766 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7767 | && loc->loc_type != bp_loc_software_breakpoint) | |
7768 | continue; | |
7769 | ||
7770 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7771 | { | |
7772 | loc->shlib_disabled = 1; | |
08351840 PA |
7773 | /* At this point, we don't know whether the object was |
7774 | unmapped from the inferior or not, so leave the | |
7775 | inserted flag alone. We'll handle failure to | |
7776 | uninsert quietly, in case the object was indeed | |
7777 | unmapped. */ | |
63644780 NB |
7778 | |
7779 | mark_breakpoint_location_modified (loc); | |
7780 | ||
7781 | bp_modified = 1; | |
7782 | } | |
7783 | } | |
7784 | ||
7785 | if (bp_modified) | |
76727919 | 7786 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7787 | } |
7788 | } | |
7789 | ||
ce78b96d JB |
7790 | /* FORK & VFORK catchpoints. */ |
7791 | ||
e29a4733 | 7792 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7793 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7794 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7795 | |
c1fc2657 | 7796 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7797 | { |
e29a4733 PA |
7798 | /* Process id of a child process whose forking triggered this |
7799 | catchpoint. This field is only valid immediately after this | |
7800 | catchpoint has triggered. */ | |
7801 | ptid_t forked_inferior_pid; | |
7802 | }; | |
7803 | ||
4a64f543 MS |
7804 | /* Implement the "insert" breakpoint_ops method for fork |
7805 | catchpoints. */ | |
ce78b96d | 7806 | |
77b06cd7 TJB |
7807 | static int |
7808 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7809 | { |
e99b03dc | 7810 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7811 | } |
7812 | ||
4a64f543 MS |
7813 | /* Implement the "remove" breakpoint_ops method for fork |
7814 | catchpoints. */ | |
ce78b96d JB |
7815 | |
7816 | static int | |
73971819 | 7817 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7818 | { |
e99b03dc | 7819 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7820 | } |
7821 | ||
7822 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7823 | catchpoints. */ | |
7824 | ||
7825 | static int | |
f1310107 | 7826 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
bd522513 | 7827 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7828 | const struct target_waitstatus *ws) |
ce78b96d | 7829 | { |
e29a4733 PA |
7830 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7831 | ||
f90263c1 TT |
7832 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7833 | return 0; | |
7834 | ||
7835 | c->forked_inferior_pid = ws->value.related_pid; | |
7836 | return 1; | |
ce78b96d JB |
7837 | } |
7838 | ||
4a64f543 MS |
7839 | /* Implement the "print_it" breakpoint_ops method for fork |
7840 | catchpoints. */ | |
ce78b96d JB |
7841 | |
7842 | static enum print_stop_action | |
348d480f | 7843 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7844 | { |
36dfb11c | 7845 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7846 | struct breakpoint *b = bs->breakpoint_at; |
7847 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7848 | |
ce78b96d | 7849 | annotate_catchpoint (b->number); |
f303dbd6 | 7850 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7851 | if (b->disposition == disp_del) |
112e8700 | 7852 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7853 | else |
112e8700 SM |
7854 | uiout->text ("Catchpoint "); |
7855 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7856 | { |
112e8700 SM |
7857 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7858 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7859 | } |
381befee | 7860 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7861 | uiout->text (" (forked process "); |
381befee | 7862 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7863 | uiout->text ("), "); |
ce78b96d JB |
7864 | return PRINT_SRC_AND_LOC; |
7865 | } | |
7866 | ||
4a64f543 MS |
7867 | /* Implement the "print_one" breakpoint_ops method for fork |
7868 | catchpoints. */ | |
ce78b96d JB |
7869 | |
7870 | static void | |
a6d9a66e | 7871 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7872 | { |
e29a4733 | 7873 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7874 | struct value_print_options opts; |
79a45e25 | 7875 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7876 | |
7877 | get_user_print_options (&opts); | |
7878 | ||
4a64f543 MS |
7879 | /* Field 4, the address, is omitted (which makes the columns not |
7880 | line up too nicely with the headers, but the effect is relatively | |
7881 | readable). */ | |
79a45b7d | 7882 | if (opts.addressprint) |
112e8700 | 7883 | uiout->field_skip ("addr"); |
ce78b96d | 7884 | annotate_field (5); |
112e8700 | 7885 | uiout->text ("fork"); |
d7e15655 | 7886 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7887 | { |
112e8700 | 7888 | uiout->text (", process "); |
381befee | 7889 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7890 | uiout->spaces (1); |
ce78b96d | 7891 | } |
8ac3646f | 7892 | |
112e8700 SM |
7893 | if (uiout->is_mi_like_p ()) |
7894 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7895 | } |
7896 | ||
7897 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7898 | catchpoints. */ | |
7899 | ||
7900 | static void | |
7901 | print_mention_catch_fork (struct breakpoint *b) | |
7902 | { | |
7903 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7904 | } | |
7905 | ||
6149aea9 PA |
7906 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7907 | catchpoints. */ | |
7908 | ||
7909 | static void | |
7910 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7911 | { | |
7912 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7913 | print_recreate_thread (b, fp); |
6149aea9 PA |
7914 | } |
7915 | ||
ce78b96d JB |
7916 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7917 | ||
2060206e | 7918 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7919 | |
4a64f543 MS |
7920 | /* Implement the "insert" breakpoint_ops method for vfork |
7921 | catchpoints. */ | |
ce78b96d | 7922 | |
77b06cd7 TJB |
7923 | static int |
7924 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7925 | { |
e99b03dc | 7926 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7927 | } |
7928 | ||
4a64f543 MS |
7929 | /* Implement the "remove" breakpoint_ops method for vfork |
7930 | catchpoints. */ | |
ce78b96d JB |
7931 | |
7932 | static int | |
73971819 | 7933 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7934 | { |
e99b03dc | 7935 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7936 | } |
7937 | ||
7938 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7939 | catchpoints. */ | |
7940 | ||
7941 | static int | |
f1310107 | 7942 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
bd522513 | 7943 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7944 | const struct target_waitstatus *ws) |
ce78b96d | 7945 | { |
e29a4733 PA |
7946 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7947 | ||
f90263c1 TT |
7948 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7949 | return 0; | |
7950 | ||
7951 | c->forked_inferior_pid = ws->value.related_pid; | |
7952 | return 1; | |
ce78b96d JB |
7953 | } |
7954 | ||
4a64f543 MS |
7955 | /* Implement the "print_it" breakpoint_ops method for vfork |
7956 | catchpoints. */ | |
ce78b96d JB |
7957 | |
7958 | static enum print_stop_action | |
348d480f | 7959 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7960 | { |
36dfb11c | 7961 | struct ui_out *uiout = current_uiout; |
348d480f | 7962 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7963 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7964 | ||
ce78b96d | 7965 | annotate_catchpoint (b->number); |
f303dbd6 | 7966 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7967 | if (b->disposition == disp_del) |
112e8700 | 7968 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7969 | else |
112e8700 SM |
7970 | uiout->text ("Catchpoint "); |
7971 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7972 | { |
112e8700 SM |
7973 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
7974 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7975 | } |
381befee | 7976 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7977 | uiout->text (" (vforked process "); |
381befee | 7978 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7979 | uiout->text ("), "); |
ce78b96d JB |
7980 | return PRINT_SRC_AND_LOC; |
7981 | } | |
7982 | ||
4a64f543 MS |
7983 | /* Implement the "print_one" breakpoint_ops method for vfork |
7984 | catchpoints. */ | |
ce78b96d JB |
7985 | |
7986 | static void | |
a6d9a66e | 7987 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7988 | { |
e29a4733 | 7989 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7990 | struct value_print_options opts; |
79a45e25 | 7991 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7992 | |
7993 | get_user_print_options (&opts); | |
4a64f543 MS |
7994 | /* Field 4, the address, is omitted (which makes the columns not |
7995 | line up too nicely with the headers, but the effect is relatively | |
7996 | readable). */ | |
79a45b7d | 7997 | if (opts.addressprint) |
112e8700 | 7998 | uiout->field_skip ("addr"); |
ce78b96d | 7999 | annotate_field (5); |
112e8700 | 8000 | uiout->text ("vfork"); |
d7e15655 | 8001 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 8002 | { |
112e8700 | 8003 | uiout->text (", process "); |
381befee | 8004 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 8005 | uiout->spaces (1); |
ce78b96d | 8006 | } |
8ac3646f | 8007 | |
112e8700 SM |
8008 | if (uiout->is_mi_like_p ()) |
8009 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
8010 | } |
8011 | ||
8012 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8013 | catchpoints. */ | |
8014 | ||
8015 | static void | |
8016 | print_mention_catch_vfork (struct breakpoint *b) | |
8017 | { | |
8018 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8019 | } | |
8020 | ||
6149aea9 PA |
8021 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8022 | catchpoints. */ | |
8023 | ||
8024 | static void | |
8025 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8026 | { | |
8027 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8028 | print_recreate_thread (b, fp); |
6149aea9 PA |
8029 | } |
8030 | ||
ce78b96d JB |
8031 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8032 | ||
2060206e | 8033 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8034 | |
edcc5120 | 8035 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 8036 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
8037 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
8038 | ||
c1fc2657 | 8039 | struct solib_catchpoint : public breakpoint |
edcc5120 | 8040 | { |
c1fc2657 | 8041 | ~solib_catchpoint () override; |
edcc5120 TT |
8042 | |
8043 | /* True for "catch load", false for "catch unload". */ | |
b650a282 | 8044 | bool is_load; |
edcc5120 TT |
8045 | |
8046 | /* Regular expression to match, if any. COMPILED is only valid when | |
8047 | REGEX is non-NULL. */ | |
8048 | char *regex; | |
2d7cc5c7 | 8049 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
8050 | }; |
8051 | ||
c1fc2657 | 8052 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 8053 | { |
c1fc2657 | 8054 | xfree (this->regex); |
edcc5120 TT |
8055 | } |
8056 | ||
8057 | static int | |
8058 | insert_catch_solib (struct bp_location *ignore) | |
8059 | { | |
8060 | return 0; | |
8061 | } | |
8062 | ||
8063 | static int | |
73971819 | 8064 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8065 | { |
8066 | return 0; | |
8067 | } | |
8068 | ||
8069 | static int | |
8070 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 8071 | const address_space *aspace, |
edcc5120 TT |
8072 | CORE_ADDR bp_addr, |
8073 | const struct target_waitstatus *ws) | |
8074 | { | |
8075 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8076 | struct breakpoint *other; | |
8077 | ||
8078 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8079 | return 1; | |
8080 | ||
8081 | ALL_BREAKPOINTS (other) | |
8082 | { | |
8083 | struct bp_location *other_bl; | |
8084 | ||
8085 | if (other == bl->owner) | |
8086 | continue; | |
8087 | ||
8088 | if (other->type != bp_shlib_event) | |
8089 | continue; | |
8090 | ||
c1fc2657 | 8091 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
8092 | continue; |
8093 | ||
8094 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8095 | { | |
8096 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8097 | return 1; | |
8098 | } | |
8099 | } | |
8100 | ||
8101 | return 0; | |
8102 | } | |
8103 | ||
8104 | static void | |
8105 | check_status_catch_solib (struct bpstats *bs) | |
8106 | { | |
8107 | struct solib_catchpoint *self | |
8108 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
edcc5120 TT |
8109 | |
8110 | if (self->is_load) | |
8111 | { | |
52941706 | 8112 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 TT |
8113 | { |
8114 | if (!self->regex | |
2d7cc5c7 | 8115 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
8116 | return; |
8117 | } | |
8118 | } | |
8119 | else | |
8120 | { | |
6fb16ce6 | 8121 | for (const std::string &iter : current_program_space->deleted_solibs) |
edcc5120 TT |
8122 | { |
8123 | if (!self->regex | |
6fb16ce6 | 8124 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
edcc5120 TT |
8125 | return; |
8126 | } | |
8127 | } | |
8128 | ||
8129 | bs->stop = 0; | |
8130 | bs->print_it = print_it_noop; | |
8131 | } | |
8132 | ||
8133 | static enum print_stop_action | |
8134 | print_it_catch_solib (bpstat bs) | |
8135 | { | |
8136 | struct breakpoint *b = bs->breakpoint_at; | |
8137 | struct ui_out *uiout = current_uiout; | |
8138 | ||
8139 | annotate_catchpoint (b->number); | |
f303dbd6 | 8140 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8141 | if (b->disposition == disp_del) |
112e8700 | 8142 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8143 | else |
112e8700 | 8144 | uiout->text ("Catchpoint "); |
381befee | 8145 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
8146 | uiout->text ("\n"); |
8147 | if (uiout->is_mi_like_p ()) | |
8148 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8149 | print_solib_event (1); |
8150 | return PRINT_SRC_AND_LOC; | |
8151 | } | |
8152 | ||
8153 | static void | |
8154 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8155 | { | |
8156 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8157 | struct value_print_options opts; | |
8158 | struct ui_out *uiout = current_uiout; | |
edcc5120 TT |
8159 | |
8160 | get_user_print_options (&opts); | |
8161 | /* Field 4, the address, is omitted (which makes the columns not | |
8162 | line up too nicely with the headers, but the effect is relatively | |
8163 | readable). */ | |
8164 | if (opts.addressprint) | |
8165 | { | |
8166 | annotate_field (4); | |
112e8700 | 8167 | uiout->field_skip ("addr"); |
edcc5120 TT |
8168 | } |
8169 | ||
528e1572 | 8170 | std::string msg; |
edcc5120 TT |
8171 | annotate_field (5); |
8172 | if (self->is_load) | |
8173 | { | |
8174 | if (self->regex) | |
528e1572 | 8175 | msg = string_printf (_("load of library matching %s"), self->regex); |
edcc5120 | 8176 | else |
528e1572 | 8177 | msg = _("load of library"); |
edcc5120 TT |
8178 | } |
8179 | else | |
8180 | { | |
8181 | if (self->regex) | |
528e1572 | 8182 | msg = string_printf (_("unload of library matching %s"), self->regex); |
edcc5120 | 8183 | else |
528e1572 | 8184 | msg = _("unload of library"); |
edcc5120 | 8185 | } |
112e8700 | 8186 | uiout->field_string ("what", msg); |
8ac3646f | 8187 | |
112e8700 SM |
8188 | if (uiout->is_mi_like_p ()) |
8189 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8190 | } |
8191 | ||
8192 | static void | |
8193 | print_mention_catch_solib (struct breakpoint *b) | |
8194 | { | |
8195 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8196 | ||
8197 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8198 | self->is_load ? "load" : "unload"); | |
8199 | } | |
8200 | ||
8201 | static void | |
8202 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8203 | { | |
8204 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8205 | ||
8206 | fprintf_unfiltered (fp, "%s %s", | |
8207 | b->disposition == disp_del ? "tcatch" : "catch", | |
8208 | self->is_load ? "load" : "unload"); | |
8209 | if (self->regex) | |
8210 | fprintf_unfiltered (fp, " %s", self->regex); | |
8211 | fprintf_unfiltered (fp, "\n"); | |
8212 | } | |
8213 | ||
8214 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8215 | ||
b650a282 | 8216 | /* See breakpoint.h. */ |
edcc5120 | 8217 | |
91985142 | 8218 | void |
b650a282 | 8219 | add_solib_catchpoint (const char *arg, bool is_load, bool is_temp, bool enabled) |
edcc5120 | 8220 | { |
edcc5120 | 8221 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8222 | |
edcc5120 TT |
8223 | if (!arg) |
8224 | arg = ""; | |
f1735a53 | 8225 | arg = skip_spaces (arg); |
edcc5120 | 8226 | |
36bd8eaa | 8227 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8228 | |
8229 | if (*arg != '\0') | |
8230 | { | |
2d7cc5c7 PA |
8231 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8232 | _("Invalid regexp"))); | |
edcc5120 TT |
8233 | c->regex = xstrdup (arg); |
8234 | } | |
8235 | ||
8236 | c->is_load = is_load; | |
36bd8eaa | 8237 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8238 | &catch_solib_breakpoint_ops); |
8239 | ||
c1fc2657 | 8240 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8241 | |
b270e6f9 | 8242 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8243 | } |
8244 | ||
91985142 MG |
8245 | /* A helper function that does all the work for "catch load" and |
8246 | "catch unload". */ | |
8247 | ||
8248 | static void | |
eb4c3f4a | 8249 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
8250 | struct cmd_list_element *command) |
8251 | { | |
91985142 | 8252 | const int enabled = 1; |
b650a282 | 8253 | bool temp = get_cmd_context (command) == CATCH_TEMPORARY; |
91985142 | 8254 | |
b650a282 | 8255 | add_solib_catchpoint (arg, is_load, temp, enabled); |
91985142 MG |
8256 | } |
8257 | ||
edcc5120 | 8258 | static void |
eb4c3f4a | 8259 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8260 | struct cmd_list_element *command) |
8261 | { | |
8262 | catch_load_or_unload (arg, from_tty, 1, command); | |
8263 | } | |
8264 | ||
8265 | static void | |
eb4c3f4a | 8266 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8267 | struct cmd_list_element *command) |
8268 | { | |
8269 | catch_load_or_unload (arg, from_tty, 0, command); | |
8270 | } | |
8271 | ||
b650a282 | 8272 | /* See breakpoint.h. */ |
ce78b96d | 8273 | |
ab04a2af | 8274 | void |
346774a9 | 8275 | init_catchpoint (struct breakpoint *b, |
b650a282 | 8276 | struct gdbarch *gdbarch, bool temp, |
63160a43 | 8277 | const char *cond_string, |
c0a91b2b | 8278 | const struct breakpoint_ops *ops) |
c906108c | 8279 | { |
51abb421 | 8280 | symtab_and_line sal; |
6c95b8df | 8281 | sal.pspace = current_program_space; |
c5aa993b | 8282 | |
28010a5d | 8283 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8284 | |
1b36a34b | 8285 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b650a282 | 8286 | b->disposition = temp ? disp_del : disp_donttouch; |
346774a9 PA |
8287 | } |
8288 | ||
28010a5d | 8289 | void |
b270e6f9 | 8290 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8291 | { |
b270e6f9 | 8292 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8293 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8294 | if (is_tracepoint (b)) |
8295 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8296 | if (!internal) |
8297 | mention (b); | |
76727919 | 8298 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
8299 | |
8300 | if (update_gll) | |
44702360 | 8301 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8302 | } |
8303 | ||
9b70b993 | 8304 | static void |
a6d9a66e | 8305 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
b650a282 | 8306 | bool temp, const char *cond_string, |
dda83cd7 | 8307 | const struct breakpoint_ops *ops) |
c906108c | 8308 | { |
b270e6f9 | 8309 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8310 | |
b650a282 | 8311 | init_catchpoint (c.get (), gdbarch, temp, cond_string, ops); |
e29a4733 PA |
8312 | |
8313 | c->forked_inferior_pid = null_ptid; | |
8314 | ||
b270e6f9 | 8315 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8316 | } |
8317 | ||
fe798b75 JB |
8318 | /* Exec catchpoints. */ |
8319 | ||
b4d90040 | 8320 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8321 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8322 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8323 | ||
c1fc2657 | 8324 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8325 | { |
c1fc2657 | 8326 | ~exec_catchpoint () override; |
b4d90040 PA |
8327 | |
8328 | /* Filename of a program whose exec triggered this catchpoint. | |
8329 | This field is only valid immediately after this catchpoint has | |
8330 | triggered. */ | |
8331 | char *exec_pathname; | |
8332 | }; | |
8333 | ||
c1fc2657 | 8334 | /* Exec catchpoint destructor. */ |
b4d90040 | 8335 | |
c1fc2657 | 8336 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8337 | { |
c1fc2657 | 8338 | xfree (this->exec_pathname); |
b4d90040 PA |
8339 | } |
8340 | ||
77b06cd7 TJB |
8341 | static int |
8342 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8343 | { |
e99b03dc | 8344 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8345 | } |
c906108c | 8346 | |
fe798b75 | 8347 | static int |
73971819 | 8348 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8349 | { |
e99b03dc | 8350 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8351 | } |
c906108c | 8352 | |
fe798b75 | 8353 | static int |
f1310107 | 8354 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
bd522513 | 8355 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 8356 | const struct target_waitstatus *ws) |
fe798b75 | 8357 | { |
b4d90040 PA |
8358 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8359 | ||
f90263c1 TT |
8360 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8361 | return 0; | |
8362 | ||
8363 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8364 | return 1; | |
fe798b75 | 8365 | } |
c906108c | 8366 | |
fe798b75 | 8367 | static enum print_stop_action |
348d480f | 8368 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8369 | { |
36dfb11c | 8370 | struct ui_out *uiout = current_uiout; |
348d480f | 8371 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8372 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8373 | ||
fe798b75 | 8374 | annotate_catchpoint (b->number); |
f303dbd6 | 8375 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8376 | if (b->disposition == disp_del) |
112e8700 | 8377 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8378 | else |
112e8700 SM |
8379 | uiout->text ("Catchpoint "); |
8380 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8381 | { |
112e8700 SM |
8382 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8383 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8384 | } |
381befee | 8385 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
8386 | uiout->text (" (exec'd "); |
8387 | uiout->field_string ("new-exec", c->exec_pathname); | |
8388 | uiout->text ("), "); | |
36dfb11c | 8389 | |
fe798b75 | 8390 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8391 | } |
8392 | ||
fe798b75 | 8393 | static void |
a6d9a66e | 8394 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8395 | { |
b4d90040 | 8396 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8397 | struct value_print_options opts; |
79a45e25 | 8398 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8399 | |
8400 | get_user_print_options (&opts); | |
8401 | ||
8402 | /* Field 4, the address, is omitted (which makes the columns | |
8403 | not line up too nicely with the headers, but the effect | |
8404 | is relatively readable). */ | |
8405 | if (opts.addressprint) | |
112e8700 | 8406 | uiout->field_skip ("addr"); |
fe798b75 | 8407 | annotate_field (5); |
112e8700 | 8408 | uiout->text ("exec"); |
b4d90040 | 8409 | if (c->exec_pathname != NULL) |
fe798b75 | 8410 | { |
112e8700 SM |
8411 | uiout->text (", program \""); |
8412 | uiout->field_string ("what", c->exec_pathname); | |
8413 | uiout->text ("\" "); | |
fe798b75 | 8414 | } |
8ac3646f | 8415 | |
112e8700 SM |
8416 | if (uiout->is_mi_like_p ()) |
8417 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8418 | } |
8419 | ||
8420 | static void | |
8421 | print_mention_catch_exec (struct breakpoint *b) | |
8422 | { | |
8423 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8424 | } | |
8425 | ||
6149aea9 PA |
8426 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8427 | catchpoints. */ | |
8428 | ||
8429 | static void | |
8430 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8431 | { | |
8432 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8433 | print_recreate_thread (b, fp); |
6149aea9 PA |
8434 | } |
8435 | ||
2060206e | 8436 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8437 | |
c906108c | 8438 | static int |
fba45db2 | 8439 | hw_breakpoint_used_count (void) |
c906108c | 8440 | { |
c906108c | 8441 | int i = 0; |
f1310107 TJB |
8442 | struct breakpoint *b; |
8443 | struct bp_location *bl; | |
c906108c SS |
8444 | |
8445 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8446 | { |
d6b74ac4 | 8447 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8448 | for (bl = b->loc; bl; bl = bl->next) |
8449 | { | |
8450 | /* Special types of hardware breakpoints may use more than | |
8451 | one register. */ | |
348d480f | 8452 | i += b->ops->resources_needed (bl); |
f1310107 | 8453 | } |
c5aa993b | 8454 | } |
c906108c SS |
8455 | |
8456 | return i; | |
8457 | } | |
8458 | ||
a1398e0c PA |
8459 | /* Returns the resources B would use if it were a hardware |
8460 | watchpoint. */ | |
8461 | ||
c906108c | 8462 | static int |
a1398e0c | 8463 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8464 | { |
c906108c | 8465 | int i = 0; |
e09342b5 | 8466 | struct bp_location *bl; |
c906108c | 8467 | |
a1398e0c PA |
8468 | if (!breakpoint_enabled (b)) |
8469 | return 0; | |
8470 | ||
8471 | for (bl = b->loc; bl; bl = bl->next) | |
8472 | { | |
8473 | /* Special types of hardware watchpoints may use more than | |
8474 | one register. */ | |
8475 | i += b->ops->resources_needed (bl); | |
8476 | } | |
8477 | ||
8478 | return i; | |
8479 | } | |
8480 | ||
8481 | /* Returns the sum the used resources of all hardware watchpoints of | |
8482 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8483 | the sum of the used resources of all hardware watchpoints of other | |
8484 | types _not_ TYPE. */ | |
8485 | ||
8486 | static int | |
8487 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8488 | enum bptype type, int *other_type_used) | |
8489 | { | |
8490 | int i = 0; | |
8491 | struct breakpoint *b; | |
8492 | ||
c906108c SS |
8493 | *other_type_used = 0; |
8494 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8495 | { |
a1398e0c PA |
8496 | if (b == except) |
8497 | continue; | |
e09342b5 TJB |
8498 | if (!breakpoint_enabled (b)) |
8499 | continue; | |
8500 | ||
a1398e0c PA |
8501 | if (b->type == type) |
8502 | i += hw_watchpoint_use_count (b); | |
8503 | else if (is_hardware_watchpoint (b)) | |
8504 | *other_type_used = 1; | |
e09342b5 TJB |
8505 | } |
8506 | ||
c906108c SS |
8507 | return i; |
8508 | } | |
8509 | ||
c906108c | 8510 | void |
fba45db2 | 8511 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8512 | { |
c5aa993b | 8513 | struct breakpoint *b; |
c906108c SS |
8514 | |
8515 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8516 | { |
cc60f2e3 | 8517 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8518 | { |
b5de0fa7 | 8519 | b->enable_state = bp_call_disabled; |
44702360 | 8520 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8521 | } |
8522 | } | |
c906108c SS |
8523 | } |
8524 | ||
8525 | void | |
fba45db2 | 8526 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8527 | { |
c5aa993b | 8528 | struct breakpoint *b; |
c906108c SS |
8529 | |
8530 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8531 | { |
cc60f2e3 | 8532 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8533 | { |
b5de0fa7 | 8534 | b->enable_state = bp_enabled; |
44702360 | 8535 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8536 | } |
8537 | } | |
c906108c SS |
8538 | } |
8539 | ||
8bea4e01 UW |
8540 | void |
8541 | disable_breakpoints_before_startup (void) | |
8542 | { | |
6c95b8df | 8543 | current_program_space->executing_startup = 1; |
44702360 | 8544 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8545 | } |
8546 | ||
8547 | void | |
8548 | enable_breakpoints_after_startup (void) | |
8549 | { | |
6c95b8df | 8550 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8551 | breakpoint_re_set (); |
8bea4e01 UW |
8552 | } |
8553 | ||
7c16b83e PA |
8554 | /* Create a new single-step breakpoint for thread THREAD, with no |
8555 | locations. */ | |
c906108c | 8556 | |
7c16b83e PA |
8557 | static struct breakpoint * |
8558 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8559 | { | |
b270e6f9 | 8560 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8561 | |
b270e6f9 | 8562 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8563 | &momentary_breakpoint_ops); |
8564 | ||
8565 | b->disposition = disp_donttouch; | |
8566 | b->frame_id = null_frame_id; | |
8567 | ||
8568 | b->thread = thread; | |
8569 | gdb_assert (b->thread != 0); | |
8570 | ||
b270e6f9 | 8571 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8572 | } |
8573 | ||
8574 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8575 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8576 | frame. */ | |
c906108c | 8577 | |
454dafbd | 8578 | breakpoint_up |
a6d9a66e UW |
8579 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8580 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8581 | { |
52f0bd74 | 8582 | struct breakpoint *b; |
edb3359d | 8583 | |
193facb3 JK |
8584 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8585 | tail-called one. */ | |
8586 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8587 | |
06edf0c0 | 8588 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8589 | b->enable_state = bp_enabled; |
8590 | b->disposition = disp_donttouch; | |
818dd999 | 8591 | b->frame_id = frame_id; |
c906108c | 8592 | |
00431a78 | 8593 | b->thread = inferior_thread ()->global_num; |
c906108c | 8594 | |
44702360 | 8595 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8596 | |
454dafbd | 8597 | return breakpoint_up (b); |
c906108c | 8598 | } |
611c83ae | 8599 | |
06edf0c0 | 8600 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8601 | The new breakpoint will have type TYPE, use OPS as its |
8602 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8603 | |
06edf0c0 PA |
8604 | static struct breakpoint * |
8605 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8606 | enum bptype type, | |
a1aa2221 LM |
8607 | const struct breakpoint_ops *ops, |
8608 | int loc_enabled) | |
e58b0e63 PA |
8609 | { |
8610 | struct breakpoint *copy; | |
8611 | ||
06edf0c0 | 8612 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8613 | copy->loc = allocate_bp_location (copy); |
0ba852ab | 8614 | set_breakpoint_location_function (copy->loc); |
e58b0e63 | 8615 | |
a6d9a66e | 8616 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8617 | copy->loc->requested_address = orig->loc->requested_address; |
8618 | copy->loc->address = orig->loc->address; | |
8619 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8620 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8621 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8622 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8623 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8624 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8625 | copy->frame_id = orig->frame_id; |
8626 | copy->thread = orig->thread; | |
6c95b8df | 8627 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8628 | |
8629 | copy->enable_state = bp_enabled; | |
8630 | copy->disposition = disp_donttouch; | |
8631 | copy->number = internal_breakpoint_number--; | |
8632 | ||
44702360 | 8633 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8634 | return copy; |
8635 | } | |
8636 | ||
06edf0c0 PA |
8637 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8638 | ORIG is NULL. */ | |
8639 | ||
8640 | struct breakpoint * | |
8641 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8642 | { | |
8643 | /* If there's nothing to clone, then return nothing. */ | |
8644 | if (orig == NULL) | |
8645 | return NULL; | |
8646 | ||
a1aa2221 | 8647 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8648 | } |
8649 | ||
454dafbd | 8650 | breakpoint_up |
a6d9a66e UW |
8651 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8652 | enum bptype type) | |
611c83ae PA |
8653 | { |
8654 | struct symtab_and_line sal; | |
8655 | ||
8656 | sal = find_pc_line (pc, 0); | |
8657 | sal.pc = pc; | |
8658 | sal.section = find_pc_overlay (pc); | |
8659 | sal.explicit_pc = 1; | |
8660 | ||
a6d9a66e | 8661 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8662 | } |
c906108c | 8663 | \f |
c5aa993b | 8664 | |
c906108c SS |
8665 | /* Tell the user we have just set a breakpoint B. */ |
8666 | ||
8667 | static void | |
fba45db2 | 8668 | mention (struct breakpoint *b) |
c906108c | 8669 | { |
348d480f | 8670 | b->ops->print_mention (b); |
2d33446d | 8671 | current_uiout->text ("\n"); |
c906108c | 8672 | } |
c906108c | 8673 | \f |
c5aa993b | 8674 | |
5133a315 | 8675 | static bool bp_loc_is_permanent (struct bp_location *loc); |
1a853c52 | 8676 | |
7f32a4d5 PA |
8677 | /* Handle "set breakpoint auto-hw on". |
8678 | ||
8679 | If the explicitly specified breakpoint type is not hardware | |
8680 | breakpoint, check the memory map to see whether the breakpoint | |
8681 | address is in read-only memory. | |
8682 | ||
8683 | - location type is not hardware breakpoint, memory is read-only. | |
8684 | We change the type of the location to hardware breakpoint. | |
8685 | ||
8686 | - location type is hardware breakpoint, memory is read-write. This | |
8687 | means we've previously made the location hardware one, but then the | |
8688 | memory map changed, so we undo. | |
8689 | */ | |
8690 | ||
8691 | static void | |
8692 | handle_automatic_hardware_breakpoints (bp_location *bl) | |
8693 | { | |
8694 | if (automatic_hardware_breakpoints | |
8695 | && bl->owner->type != bp_hardware_breakpoint | |
8696 | && (bl->loc_type == bp_loc_software_breakpoint | |
8697 | || bl->loc_type == bp_loc_hardware_breakpoint)) | |
8698 | { | |
8699 | /* When breakpoints are removed, remove_breakpoints will use | |
8700 | location types we've just set here, the only possible problem | |
8701 | is that memory map has changed during running program, but | |
8702 | it's not going to work anyway with current gdb. */ | |
8703 | mem_region *mr = lookup_mem_region (bl->address); | |
8704 | ||
8705 | if (mr != nullptr) | |
8706 | { | |
8707 | enum bp_loc_type new_type; | |
8708 | ||
8709 | if (mr->attrib.mode != MEM_RW) | |
8710 | new_type = bp_loc_hardware_breakpoint; | |
8711 | else | |
8712 | new_type = bp_loc_software_breakpoint; | |
8713 | ||
8714 | if (new_type != bl->loc_type) | |
8715 | { | |
8716 | static bool said = false; | |
8717 | ||
8718 | bl->loc_type = new_type; | |
8719 | if (!said) | |
8720 | { | |
8721 | fprintf_filtered (gdb_stdout, | |
8722 | _("Note: automatically using " | |
8723 | "hardware breakpoints for " | |
8724 | "read-only addresses.\n")); | |
8725 | said = true; | |
8726 | } | |
8727 | } | |
8728 | } | |
8729 | } | |
8730 | } | |
8731 | ||
0d381245 | 8732 | static struct bp_location * |
39d61571 | 8733 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8734 | const struct symtab_and_line *sal) |
8735 | { | |
8736 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8737 | CORE_ADDR adjusted_address; |
8738 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8739 | ||
8740 | if (loc_gdbarch == NULL) | |
8741 | loc_gdbarch = b->gdbarch; | |
8742 | ||
8743 | /* Adjust the breakpoint's address prior to allocating a location. | |
8744 | Once we call allocate_bp_location(), that mostly uninitialized | |
8745 | location will be placed on the location chain. Adjustment of the | |
8746 | breakpoint may cause target_read_memory() to be called and we do | |
8747 | not want its scan of the location chain to find a breakpoint and | |
8748 | location that's only been partially initialized. */ | |
8749 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8750 | sal->pc, b->type); | |
0d381245 | 8751 | |
d30113d4 | 8752 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8753 | loc = allocate_bp_location (b); |
d30113d4 JK |
8754 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8755 | tmp = &((*tmp)->next)) | |
0d381245 | 8756 | ; |
d30113d4 | 8757 | loc->next = *tmp; |
0d381245 | 8758 | *tmp = loc; |
3742cc8b | 8759 | |
0d381245 | 8760 | loc->requested_address = sal->pc; |
3742cc8b | 8761 | loc->address = adjusted_address; |
6c95b8df | 8762 | loc->pspace = sal->pspace; |
935676c9 | 8763 | loc->probe.prob = sal->prob; |
729662a5 | 8764 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8765 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8766 | loc->section = sal->section; |
3742cc8b | 8767 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8768 | loc->line_number = sal->line; |
2f202fde | 8769 | loc->symtab = sal->symtab; |
4a27f119 | 8770 | loc->symbol = sal->symbol; |
3467ec66 PA |
8771 | loc->msymbol = sal->msymbol; |
8772 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8773 | |
0ba852ab | 8774 | set_breakpoint_location_function (loc); |
1a853c52 | 8775 | |
6ae88661 LM |
8776 | /* While by definition, permanent breakpoints are already present in the |
8777 | code, we don't mark the location as inserted. Normally one would expect | |
8778 | that GDB could rely on that breakpoint instruction to stop the program, | |
8779 | thus removing the need to insert its own breakpoint, except that executing | |
8780 | the breakpoint instruction can kill the target instead of reporting a | |
8781 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8782 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8783 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8784 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8785 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8786 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8787 | it manually increments the PC, thus avoiding executing the breakpoint | |
8788 | instruction.) */ | |
1a853c52 | 8789 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8790 | loc->permanent = 1; |
1a853c52 | 8791 | |
0d381245 VP |
8792 | return loc; |
8793 | } | |
514f746b AR |
8794 | \f |
8795 | ||
5133a315 LM |
8796 | /* Return true if LOC is pointing to a permanent breakpoint, |
8797 | return false otherwise. */ | |
1cf4d951 | 8798 | |
5133a315 | 8799 | static bool |
1cf4d951 PA |
8800 | bp_loc_is_permanent (struct bp_location *loc) |
8801 | { | |
514f746b AR |
8802 | gdb_assert (loc != NULL); |
8803 | ||
cb1e4e32 PA |
8804 | /* If we have a non-breakpoint-backed catchpoint or a software |
8805 | watchpoint, just return 0. We should not attempt to read from | |
8806 | the addresses the locations of these breakpoint types point to. | |
5133a315 | 8807 | gdbarch_program_breakpoint_here_p, below, will attempt to read |
244558af | 8808 | memory. */ |
cb1e4e32 | 8809 | if (!bl_address_is_meaningful (loc)) |
5133a315 | 8810 | return false; |
244558af | 8811 | |
5ed8105e | 8812 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8813 | switch_to_program_space_and_thread (loc->pspace); |
5133a315 | 8814 | return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8815 | } |
8816 | ||
e7e0cddf SS |
8817 | /* Build a command list for the dprintf corresponding to the current |
8818 | settings of the dprintf style options. */ | |
8819 | ||
8820 | static void | |
8821 | update_dprintf_command_list (struct breakpoint *b) | |
8822 | { | |
8823 | char *dprintf_args = b->extra_string; | |
8824 | char *printf_line = NULL; | |
8825 | ||
8826 | if (!dprintf_args) | |
8827 | return; | |
8828 | ||
8829 | dprintf_args = skip_spaces (dprintf_args); | |
8830 | ||
8831 | /* Allow a comma, as it may have terminated a location, but don't | |
8832 | insist on it. */ | |
8833 | if (*dprintf_args == ',') | |
8834 | ++dprintf_args; | |
8835 | dprintf_args = skip_spaces (dprintf_args); | |
8836 | ||
8837 | if (*dprintf_args != '"') | |
8838 | error (_("Bad format string, missing '\"'.")); | |
8839 | ||
d3ce09f5 | 8840 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8841 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8842 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8843 | { |
8844 | if (!dprintf_function) | |
8845 | error (_("No function supplied for dprintf call")); | |
8846 | ||
8847 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8848 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8849 | dprintf_function, | |
8850 | dprintf_channel, | |
8851 | dprintf_args); | |
8852 | else | |
8853 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8854 | dprintf_function, | |
8855 | dprintf_args); | |
8856 | } | |
d3ce09f5 SS |
8857 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8858 | { | |
8859 | if (target_can_run_breakpoint_commands ()) | |
8860 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8861 | else | |
8862 | { | |
8863 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8864 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8865 | } | |
8866 | } | |
e7e0cddf SS |
8867 | else |
8868 | internal_error (__FILE__, __LINE__, | |
8869 | _("Invalid dprintf style.")); | |
8870 | ||
f28045c2 | 8871 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8872 | |
12973681 TT |
8873 | /* Manufacture a printf sequence. */ |
8874 | struct command_line *printf_cmd_line | |
8875 | = new struct command_line (simple_control, printf_line); | |
8876 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, | |
8877 | command_lines_deleter ())); | |
e7e0cddf SS |
8878 | } |
8879 | ||
8880 | /* Update all dprintf commands, making their command lists reflect | |
8881 | current style settings. */ | |
8882 | ||
8883 | static void | |
eb4c3f4a | 8884 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8885 | struct cmd_list_element *c) |
8886 | { | |
8887 | struct breakpoint *b; | |
8888 | ||
8889 | ALL_BREAKPOINTS (b) | |
8890 | { | |
8891 | if (b->type == bp_dprintf) | |
8892 | update_dprintf_command_list (b); | |
8893 | } | |
8894 | } | |
c3f6f71d | 8895 | |
f00aae0f KS |
8896 | /* Create a breakpoint with SAL as location. Use LOCATION |
8897 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8898 | as condition expression. If LOCATION is NULL then create an |
8899 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8900 | |
8901 | static void | |
d9b3f62e | 8902 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8903 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8904 | event_location_up &&location, |
e1e01040 PA |
8905 | gdb::unique_xmalloc_ptr<char> filter, |
8906 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8907 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8908 | enum bptype type, enum bpdisp disposition, |
8909 | int thread, int task, int ignore_count, | |
c0a91b2b | 8910 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8911 | int enabled, int internal, unsigned flags, |
8912 | int display_canonical) | |
018d34a4 | 8913 | { |
0d381245 | 8914 | int i; |
018d34a4 VP |
8915 | |
8916 | if (type == bp_hardware_breakpoint) | |
8917 | { | |
fbbd034e AS |
8918 | int target_resources_ok; |
8919 | ||
8920 | i = hw_breakpoint_used_count (); | |
8921 | target_resources_ok = | |
8922 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8923 | i + 1, 0); |
8924 | if (target_resources_ok == 0) | |
8925 | error (_("No hardware breakpoint support in the target.")); | |
8926 | else if (target_resources_ok < 0) | |
8927 | error (_("Hardware breakpoints used exceeds limit.")); | |
8928 | } | |
8929 | ||
6c5b2ebe | 8930 | gdb_assert (!sals.empty ()); |
6c95b8df | 8931 | |
6c5b2ebe | 8932 | for (const auto &sal : sals) |
0d381245 | 8933 | { |
0d381245 VP |
8934 | struct bp_location *loc; |
8935 | ||
8936 | if (from_tty) | |
5af949e3 UW |
8937 | { |
8938 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8939 | if (!loc_gdbarch) | |
8940 | loc_gdbarch = gdbarch; | |
8941 | ||
8942 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8943 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8944 | } |
0d381245 | 8945 | |
6c5b2ebe | 8946 | if (&sal == &sals[0]) |
0d381245 | 8947 | { |
d9b3f62e | 8948 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8949 | b->thread = thread; |
4a306c9a | 8950 | b->task = task; |
855a6e68 | 8951 | |
e1e01040 PA |
8952 | b->cond_string = cond_string.release (); |
8953 | b->extra_string = extra_string.release (); | |
0d381245 | 8954 | b->ignore_count = ignore_count; |
41447f92 | 8955 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8956 | b->disposition = disposition; |
6c95b8df | 8957 | |
44f238bb PA |
8958 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8959 | b->loc->inserted = 1; | |
8960 | ||
0fb4aa4b PA |
8961 | if (type == bp_static_tracepoint) |
8962 | { | |
d9b3f62e | 8963 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8964 | struct static_tracepoint_marker marker; |
8965 | ||
983af33b | 8966 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8967 | { |
8968 | /* We already know the marker exists, otherwise, we | |
8969 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8970 | const char *p |
8971 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8972 | const char *endp; |
0fb4aa4b | 8973 | |
f1735a53 | 8974 | p = skip_spaces (p); |
0fb4aa4b | 8975 | |
f1735a53 | 8976 | endp = skip_to_space (p); |
0fb4aa4b | 8977 | |
5d9310c4 | 8978 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8979 | |
3e43a32a MS |
8980 | printf_filtered (_("Probed static tracepoint " |
8981 | "marker \"%s\"\n"), | |
5d9310c4 | 8982 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8983 | } |
8984 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8985 | { | |
5d9310c4 | 8986 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8987 | |
3e43a32a MS |
8988 | printf_filtered (_("Probed static tracepoint " |
8989 | "marker \"%s\"\n"), | |
5d9310c4 | 8990 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8991 | } |
8992 | else | |
3e43a32a MS |
8993 | warning (_("Couldn't determine the static " |
8994 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8995 | } |
8996 | ||
0d381245 VP |
8997 | loc = b->loc; |
8998 | } | |
8999 | else | |
018d34a4 | 9000 | { |
39d61571 | 9001 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9002 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9003 | loc->inserted = 1; | |
0d381245 VP |
9004 | } |
9005 | ||
b5fa468f TBA |
9006 | /* Do not set breakpoint locations conditions yet. As locations |
9007 | are inserted, they get sorted based on their addresses. Let | |
9008 | the list stabilize to have reliable location numbers. */ | |
e7e0cddf SS |
9009 | |
9010 | /* Dynamic printf requires and uses additional arguments on the | |
9011 | command line, otherwise it's an error. */ | |
9012 | if (type == bp_dprintf) | |
9013 | { | |
9014 | if (b->extra_string) | |
9015 | update_dprintf_command_list (b); | |
9016 | else | |
9017 | error (_("Format string required")); | |
9018 | } | |
9019 | else if (b->extra_string) | |
588ae58c | 9020 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9021 | } |
018d34a4 | 9022 | |
b5fa468f TBA |
9023 | |
9024 | /* The order of the locations is now stable. Set the location | |
9025 | condition using the location's number. */ | |
9026 | int loc_num = 1; | |
9027 | for (bp_location *loc = b->loc; loc != nullptr; loc = loc->next) | |
9028 | { | |
9029 | if (b->cond_string != nullptr) | |
9030 | set_breakpoint_location_condition (b->cond_string, loc, b->number, | |
9031 | loc_num); | |
9032 | ||
9033 | ++loc_num; | |
9034 | } | |
9035 | ||
56435ebe | 9036 | b->display_canonical = display_canonical; |
f00aae0f | 9037 | if (location != NULL) |
d28cd78a | 9038 | b->location = std::move (location); |
018d34a4 | 9039 | else |
d28cd78a | 9040 | b->location = new_address_location (b->loc->address, NULL, 0); |
c0e8dcd8 | 9041 | b->filter = std::move (filter); |
d9b3f62e | 9042 | } |
018d34a4 | 9043 | |
d9b3f62e PA |
9044 | static void |
9045 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 9046 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9047 | event_location_up &&location, |
e1e01040 PA |
9048 | gdb::unique_xmalloc_ptr<char> filter, |
9049 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9050 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9051 | enum bptype type, enum bpdisp disposition, |
9052 | int thread, int task, int ignore_count, | |
c0a91b2b | 9053 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9054 | int enabled, int internal, unsigned flags, |
9055 | int display_canonical) | |
d9b3f62e | 9056 | { |
a5e364af | 9057 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 9058 | |
a5e364af | 9059 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 9060 | sals, std::move (location), |
e1e01040 PA |
9061 | std::move (filter), |
9062 | std::move (cond_string), | |
9063 | std::move (extra_string), | |
d9b3f62e PA |
9064 | type, disposition, |
9065 | thread, task, ignore_count, | |
9066 | ops, from_tty, | |
44f238bb PA |
9067 | enabled, internal, flags, |
9068 | display_canonical); | |
d9b3f62e | 9069 | |
b270e6f9 | 9070 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
9071 | } |
9072 | ||
9073 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9074 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9075 | value. COND_STRING, if not NULL, specified the condition to be | |
9076 | used for all breakpoints. Essentially the only case where | |
9077 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9078 | function. In that case, it's still not possible to specify | |
9079 | separate conditions for different overloaded functions, so | |
9080 | we take just a single condition string. | |
9081 | ||
c3f6f71d | 9082 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9083 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9084 | array contents). If the function fails (error() is called), the |
9085 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9086 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9087 | |
9088 | static void | |
8cdf0e15 | 9089 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9090 | struct linespec_result *canonical, |
e1e01040 PA |
9091 | gdb::unique_xmalloc_ptr<char> cond_string, |
9092 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
9093 | enum bptype type, enum bpdisp disposition, |
9094 | int thread, int task, int ignore_count, | |
c0a91b2b | 9095 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9096 | int enabled, int internal, unsigned flags) |
c906108c | 9097 | { |
f8eba3c6 | 9098 | if (canonical->pre_expanded) |
6c5b2ebe | 9099 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 9100 | |
6c5b2ebe | 9101 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 9102 | { |
f00aae0f | 9103 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9104 | 'break', without arguments. */ |
ffc2605c | 9105 | event_location_up location |
f00aae0f | 9106 | = (canonical->location != NULL |
8e9e35b1 | 9107 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 9108 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 9109 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 9110 | |
6c5b2ebe | 9111 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 9112 | std::move (location), |
e1e01040 PA |
9113 | std::move (filter_string), |
9114 | std::move (cond_string), | |
9115 | std::move (extra_string), | |
e7e0cddf | 9116 | type, disposition, |
84f4c1fe | 9117 | thread, task, ignore_count, ops, |
44f238bb | 9118 | from_tty, enabled, internal, flags, |
56435ebe | 9119 | canonical->special_display); |
c3f6f71d | 9120 | } |
c3f6f71d | 9121 | } |
c906108c | 9122 | |
f00aae0f | 9123 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9124 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9125 | addresses found. LOCATION points to the end of the SAL (for |
9126 | linespec locations). | |
9998af43 TJB |
9127 | |
9128 | The array and the line spec strings are allocated on the heap, it is | |
9129 | the caller's responsibility to free them. */ | |
c906108c | 9130 | |
b9362cc7 | 9131 | static void |
626d2320 | 9132 | parse_breakpoint_sals (struct event_location *location, |
58438ac1 | 9133 | struct linespec_result *canonical) |
c3f6f71d | 9134 | { |
f00aae0f KS |
9135 | struct symtab_and_line cursal; |
9136 | ||
9137 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9138 | { | |
a20714ff | 9139 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 9140 | |
a20714ff | 9141 | if (spec == NULL) |
f00aae0f KS |
9142 | { |
9143 | /* The last displayed codepoint, if it's valid, is our default | |
9144 | breakpoint address. */ | |
9145 | if (last_displayed_sal_is_valid ()) | |
9146 | { | |
f00aae0f KS |
9147 | /* Set sal's pspace, pc, symtab, and line to the values |
9148 | corresponding to the last call to print_frame_info. | |
9149 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9150 | as the breakpoint line number is inappropriate otherwise. | |
9151 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
9152 | symtab_and_line sal = get_last_displayed_sal (); |
9153 | CORE_ADDR pc = sal.pc; | |
9154 | ||
f00aae0f KS |
9155 | sal = find_pc_line (pc, 0); |
9156 | ||
9157 | /* "break" without arguments is equivalent to "break *PC" | |
9158 | where PC is the last displayed codepoint's address. So | |
9159 | make sure to set sal.explicit_pc to prevent GDB from | |
9160 | trying to expand the list of sals to include all other | |
9161 | instances with the same symtab and line. */ | |
9162 | sal.pc = pc; | |
9163 | sal.explicit_pc = 1; | |
9164 | ||
6c5b2ebe PA |
9165 | struct linespec_sals lsal; |
9166 | lsal.sals = {sal}; | |
f00aae0f KS |
9167 | lsal.canonical = NULL; |
9168 | ||
6c5b2ebe | 9169 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
9170 | return; |
9171 | } | |
9172 | else | |
9173 | error (_("No default breakpoint address now.")); | |
c906108c | 9174 | } |
c906108c | 9175 | } |
f00aae0f KS |
9176 | |
9177 | /* Force almost all breakpoints to be in terms of the | |
9178 | current_source_symtab (which is decode_line_1's default). | |
9179 | This should produce the results we want almost all of the | |
9180 | time while leaving default_breakpoint_* alone. | |
9181 | ||
9182 | ObjC: However, don't match an Objective-C method name which | |
9183 | may have a '+' or '-' succeeded by a '['. */ | |
9184 | cursal = get_current_source_symtab_and_line (); | |
9185 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9186 | { |
a20714ff | 9187 | const char *spec = NULL; |
cc80f267 | 9188 | |
f00aae0f | 9189 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 9190 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 9191 | |
f00aae0f | 9192 | if (!cursal.symtab |
a20714ff PA |
9193 | || (spec != NULL |
9194 | && strchr ("+-", spec[0]) != NULL | |
9195 | && spec[1] != '[')) | |
f00aae0f | 9196 | { |
c2f4122d | 9197 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9198 | get_last_displayed_symtab (), |
9199 | get_last_displayed_line (), | |
9200 | canonical, NULL, NULL); | |
9201 | return; | |
9202 | } | |
c906108c | 9203 | } |
f00aae0f | 9204 | |
c2f4122d | 9205 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9206 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9207 | } |
c906108c | 9208 | |
c906108c | 9209 | |
c3f6f71d | 9210 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9211 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9212 | |
b9362cc7 | 9213 | static void |
6c5b2ebe | 9214 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9215 | { |
6c5b2ebe PA |
9216 | for (auto &sal : sals) |
9217 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9218 | } |
9219 | ||
7a697b8d SS |
9220 | /* Fast tracepoints may have restrictions on valid locations. For |
9221 | instance, a fast tracepoint using a jump instead of a trap will | |
9222 | likely have to overwrite more bytes than a trap would, and so can | |
9223 | only be placed where the instruction is longer than the jump, or a | |
9224 | multi-instruction sequence does not have a jump into the middle of | |
9225 | it, etc. */ | |
9226 | ||
9227 | static void | |
9228 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9229 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9230 | { |
6c5b2ebe | 9231 | for (const auto &sal : sals) |
7a697b8d | 9232 | { |
f8eba3c6 TT |
9233 | struct gdbarch *sarch; |
9234 | ||
6c5b2ebe | 9235 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9236 | /* We fall back to GDBARCH if there is no architecture |
9237 | associated with SAL. */ | |
9238 | if (sarch == NULL) | |
9239 | sarch = gdbarch; | |
281d762b TT |
9240 | std::string msg; |
9241 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 9242 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 9243 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
9244 | } |
9245 | } | |
9246 | ||
018d34a4 VP |
9247 | /* Given TOK, a string specification of condition and thread, as |
9248 | accepted by the 'break' command, extract the condition | |
9249 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9250 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9251 | If no condition is found, *COND_STRING is set to NULL. |
9252 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9253 | |
9254 | static void | |
bbc13ae3 | 9255 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9256 | char **cond_string, int *thread, int *task, |
9257 | char **rest) | |
018d34a4 VP |
9258 | { |
9259 | *cond_string = NULL; | |
9260 | *thread = -1; | |
ed1d1739 KS |
9261 | *task = 0; |
9262 | *rest = NULL; | |
733d554a | 9263 | bool force = false; |
ed1d1739 | 9264 | |
018d34a4 VP |
9265 | while (tok && *tok) |
9266 | { | |
bbc13ae3 | 9267 | const char *end_tok; |
018d34a4 | 9268 | int toklen; |
bbc13ae3 KS |
9269 | const char *cond_start = NULL; |
9270 | const char *cond_end = NULL; | |
cc59ec59 | 9271 | |
f1735a53 | 9272 | tok = skip_spaces (tok); |
e7e0cddf SS |
9273 | |
9274 | if ((*tok == '"' || *tok == ',') && rest) | |
9275 | { | |
9276 | *rest = savestring (tok, strlen (tok)); | |
9277 | return; | |
9278 | } | |
9279 | ||
f1735a53 | 9280 | end_tok = skip_to_space (tok); |
d634f2de | 9281 | |
018d34a4 | 9282 | toklen = end_tok - tok; |
d634f2de | 9283 | |
018d34a4 VP |
9284 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9285 | { | |
9286 | tok = cond_start = end_tok + 1; | |
733d554a TBA |
9287 | try |
9288 | { | |
9289 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); | |
9290 | } | |
9291 | catch (const gdb_exception_error &) | |
9292 | { | |
9293 | if (!force) | |
9294 | throw; | |
9295 | else | |
9296 | tok = tok + strlen (tok); | |
9297 | } | |
018d34a4 | 9298 | cond_end = tok; |
d634f2de | 9299 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 | 9300 | } |
733d554a TBA |
9301 | else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0) |
9302 | { | |
5759831a | 9303 | tok = tok + toklen; |
733d554a TBA |
9304 | force = true; |
9305 | } | |
018d34a4 VP |
9306 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
9307 | { | |
5d5658a1 PA |
9308 | const char *tmptok; |
9309 | struct thread_info *thr; | |
d634f2de | 9310 | |
018d34a4 | 9311 | tok = end_tok + 1; |
5d5658a1 | 9312 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9313 | if (tok == tmptok) |
9314 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9315 | *thread = thr->global_num; |
bbc13ae3 | 9316 | tok = tmptok; |
018d34a4 | 9317 | } |
4a306c9a JB |
9318 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9319 | { | |
9320 | char *tmptok; | |
9321 | ||
9322 | tok = end_tok + 1; | |
bbc13ae3 | 9323 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9324 | if (tok == tmptok) |
9325 | error (_("Junk after task keyword.")); | |
9326 | if (!valid_task_id (*task)) | |
b6199126 | 9327 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9328 | tok = tmptok; |
4a306c9a | 9329 | } |
e7e0cddf SS |
9330 | else if (rest) |
9331 | { | |
9332 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9333 | return; |
e7e0cddf | 9334 | } |
018d34a4 VP |
9335 | else |
9336 | error (_("Junk at end of arguments.")); | |
9337 | } | |
9338 | } | |
9339 | ||
b5fa468f TBA |
9340 | /* Call 'find_condition_and_thread' for each sal in SALS until a parse |
9341 | succeeds. The parsed values are written to COND_STRING, THREAD, | |
9342 | TASK, and REST. See the comment of 'find_condition_and_thread' | |
9343 | for the description of these parameters and INPUT. */ | |
9344 | ||
9345 | static void | |
9346 | find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals, | |
9347 | const char *input, char **cond_string, | |
9348 | int *thread, int *task, char **rest) | |
9349 | { | |
9350 | int num_failures = 0; | |
9351 | for (auto &sal : sals) | |
9352 | { | |
9353 | char *cond = nullptr; | |
9354 | int thread_id = 0; | |
9355 | int task_id = 0; | |
9356 | char *remaining = nullptr; | |
9357 | ||
9358 | /* Here we want to parse 'arg' to separate condition from thread | |
9359 | number. But because parsing happens in a context and the | |
9360 | contexts of sals might be different, try each until there is | |
9361 | success. Finding one successful parse is sufficient for our | |
9362 | goal. When setting the breakpoint we'll re-parse the | |
9363 | condition in the context of each sal. */ | |
9364 | try | |
9365 | { | |
9366 | find_condition_and_thread (input, sal.pc, &cond, &thread_id, | |
9367 | &task_id, &remaining); | |
9368 | *cond_string = cond; | |
9369 | *thread = thread_id; | |
9370 | *task = task_id; | |
9371 | *rest = remaining; | |
9372 | break; | |
9373 | } | |
9374 | catch (const gdb_exception_error &e) | |
9375 | { | |
9376 | num_failures++; | |
9377 | /* If no sal remains, do not continue. */ | |
9378 | if (num_failures == sals.size ()) | |
9379 | throw; | |
9380 | } | |
9381 | } | |
9382 | } | |
9383 | ||
0fb4aa4b PA |
9384 | /* Decode a static tracepoint marker spec. */ |
9385 | ||
6c5b2ebe | 9386 | static std::vector<symtab_and_line> |
f00aae0f | 9387 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 9388 | { |
f00aae0f KS |
9389 | const char *p = &(*arg_p)[3]; |
9390 | const char *endp; | |
0fb4aa4b | 9391 | |
f1735a53 | 9392 | p = skip_spaces (p); |
0fb4aa4b | 9393 | |
f1735a53 | 9394 | endp = skip_to_space (p); |
0fb4aa4b | 9395 | |
81b1e71c | 9396 | std::string marker_str (p, endp - p); |
0fb4aa4b | 9397 | |
5d9310c4 SM |
9398 | std::vector<static_tracepoint_marker> markers |
9399 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
9400 | if (markers.empty ()) | |
81b1e71c TT |
9401 | error (_("No known static tracepoint marker named %s"), |
9402 | marker_str.c_str ()); | |
0fb4aa4b | 9403 | |
6c5b2ebe | 9404 | std::vector<symtab_and_line> sals; |
5d9310c4 | 9405 | sals.reserve (markers.size ()); |
0fb4aa4b | 9406 | |
5d9310c4 | 9407 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 9408 | { |
5d9310c4 SM |
9409 | symtab_and_line sal = find_pc_line (marker.address, 0); |
9410 | sal.pc = marker.address; | |
6c5b2ebe | 9411 | sals.push_back (sal); |
5d9310c4 | 9412 | } |
0fb4aa4b | 9413 | |
0fb4aa4b PA |
9414 | *arg_p = endp; |
9415 | return sals; | |
9416 | } | |
9417 | ||
bac7c5cf GB |
9418 | /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and |
9419 | according to IS_TRACEPOINT. */ | |
9420 | ||
9421 | static const struct breakpoint_ops * | |
9422 | breakpoint_ops_for_event_location_type (enum event_location_type location_type, | |
9423 | bool is_tracepoint) | |
9424 | { | |
9425 | if (is_tracepoint) | |
9426 | { | |
9427 | if (location_type == PROBE_LOCATION) | |
9428 | return &tracepoint_probe_breakpoint_ops; | |
9429 | else | |
9430 | return &tracepoint_breakpoint_ops; | |
9431 | } | |
9432 | else | |
9433 | { | |
9434 | if (location_type == PROBE_LOCATION) | |
9435 | return &bkpt_probe_breakpoint_ops; | |
9436 | else | |
9437 | return &bkpt_breakpoint_ops; | |
9438 | } | |
9439 | } | |
9440 | ||
9441 | /* See breakpoint.h. */ | |
9442 | ||
9443 | const struct breakpoint_ops * | |
9444 | breakpoint_ops_for_event_location (const struct event_location *location, | |
9445 | bool is_tracepoint) | |
9446 | { | |
9447 | if (location != nullptr) | |
9448 | return breakpoint_ops_for_event_location_type | |
9449 | (event_location_type (location), is_tracepoint); | |
9450 | return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; | |
9451 | } | |
9452 | ||
f00aae0f | 9453 | /* See breakpoint.h. */ |
0101ce28 | 9454 | |
8cdf0e15 VP |
9455 | int |
9456 | create_breakpoint (struct gdbarch *gdbarch, | |
626d2320 | 9457 | struct event_location *location, |
e1e01040 PA |
9458 | const char *cond_string, |
9459 | int thread, const char *extra_string, | |
f00aae0f | 9460 | int parse_extra, |
0fb4aa4b | 9461 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9462 | int ignore_count, |
9463 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9464 | const struct breakpoint_ops *ops, |
44f238bb PA |
9465 | int from_tty, int enabled, int internal, |
9466 | unsigned flags) | |
c3f6f71d | 9467 | { |
7efd8fc2 | 9468 | struct linespec_result canonical; |
0101ce28 | 9469 | int pending = 0; |
4a306c9a | 9470 | int task = 0; |
86b17b60 | 9471 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9472 | |
348d480f PA |
9473 | gdb_assert (ops != NULL); |
9474 | ||
f00aae0f KS |
9475 | /* If extra_string isn't useful, set it to NULL. */ |
9476 | if (extra_string != NULL && *extra_string == '\0') | |
9477 | extra_string = NULL; | |
9478 | ||
a70b8144 | 9479 | try |
b78a6381 | 9480 | { |
f00aae0f | 9481 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9482 | } |
230d2906 | 9483 | catch (const gdb_exception_error &e) |
0101ce28 | 9484 | { |
492d29ea PA |
9485 | /* If caller is interested in rc value from parse, set |
9486 | value. */ | |
9487 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9488 | { |
05ff989b AC |
9489 | /* If pending breakpoint support is turned off, throw |
9490 | error. */ | |
fa8d40ab JJ |
9491 | |
9492 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 9493 | throw; |
723a2275 VP |
9494 | |
9495 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9496 | |
dda83cd7 | 9497 | /* If pending breakpoint support is auto query and the user |
05ff989b | 9498 | selects no, then simply return the error code. */ |
059fb39f | 9499 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9500 | && !nquery (_("Make %s pending on future shared library load? "), |
9501 | bptype_string (type_wanted))) | |
fd9b8c24 | 9502 | return 0; |
fa8d40ab | 9503 | |
05ff989b AC |
9504 | /* At this point, either the user was queried about setting |
9505 | a pending breakpoint and selected yes, or pending | |
9506 | breakpoint behavior is on and thus a pending breakpoint | |
9507 | is defaulted on behalf of the user. */ | |
f00aae0f | 9508 | pending = 1; |
0101ce28 | 9509 | } |
492d29ea | 9510 | else |
eedc3f4f | 9511 | throw; |
0101ce28 | 9512 | } |
492d29ea | 9513 | |
6c5b2ebe | 9514 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9515 | return 0; |
c3f6f71d | 9516 | |
c3f6f71d JM |
9517 | /* Resolve all line numbers to PC's and verify that the addresses |
9518 | are ok for the target. */ | |
0101ce28 | 9519 | if (!pending) |
f8eba3c6 | 9520 | { |
6c5b2ebe PA |
9521 | for (auto &lsal : canonical.lsals) |
9522 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9523 | } |
c3f6f71d | 9524 | |
7a697b8d | 9525 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9526 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9527 | { |
6c5b2ebe PA |
9528 | for (const auto &lsal : canonical.lsals) |
9529 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9530 | } |
7a697b8d | 9531 | |
c3f6f71d JM |
9532 | /* Verify that condition can be parsed, before setting any |
9533 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9534 | breakpoint. */ |
0101ce28 | 9535 | if (!pending) |
c3f6f71d | 9536 | { |
e1e01040 PA |
9537 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9538 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9539 | ||
f00aae0f | 9540 | if (parse_extra) |
dda83cd7 | 9541 | { |
0878d0fa | 9542 | char *rest; |
e1e01040 | 9543 | char *cond; |
52d361e1 | 9544 | |
6c5b2ebe | 9545 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9546 | |
b5fa468f TBA |
9547 | find_condition_and_thread_for_sals (lsal.sals, extra_string, |
9548 | &cond, &thread, &task, &rest); | |
e1e01040 PA |
9549 | cond_string_copy.reset (cond); |
9550 | extra_string_copy.reset (rest); | |
dda83cd7 | 9551 | } |
2f069f6f | 9552 | else |
dda83cd7 | 9553 | { |
f00aae0f KS |
9554 | if (type_wanted != bp_dprintf |
9555 | && extra_string != NULL && *extra_string != '\0') | |
9556 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9557 | |
9558 | /* Create a private copy of condition string. */ | |
9559 | if (cond_string) | |
e1e01040 | 9560 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9561 | /* Create a private copy of any extra string. */ |
9562 | if (extra_string) | |
e1e01040 | 9563 | extra_string_copy.reset (xstrdup (extra_string)); |
dda83cd7 | 9564 | } |
0fb4aa4b | 9565 | |
52d361e1 | 9566 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9567 | std::move (cond_string_copy), |
9568 | std::move (extra_string_copy), | |
9569 | type_wanted, | |
d9b3f62e PA |
9570 | tempflag ? disp_del : disp_donttouch, |
9571 | thread, task, ignore_count, ops, | |
44f238bb | 9572 | from_tty, enabled, internal, flags); |
c906108c | 9573 | } |
0101ce28 JJ |
9574 | else |
9575 | { | |
a5e364af | 9576 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9577 | |
a5e364af | 9578 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9579 | b->location = copy_event_location (location); |
bfccc43c | 9580 | |
f00aae0f KS |
9581 | if (parse_extra) |
9582 | b->cond_string = NULL; | |
e12c7713 MK |
9583 | else |
9584 | { | |
9585 | /* Create a private copy of condition string. */ | |
e1e01040 | 9586 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9587 | b->thread = thread; |
e12c7713 | 9588 | } |
f00aae0f KS |
9589 | |
9590 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9591 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9592 | b->ignore_count = ignore_count; |
0101ce28 | 9593 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9594 | b->condition_not_parsed = 1; |
41447f92 | 9595 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 | 9596 | if ((type_wanted != bp_breakpoint |
dda83cd7 | 9597 | && type_wanted != bp_hardware_breakpoint) || thread != -1) |
f8eba3c6 | 9598 | b->pspace = current_program_space; |
8bea4e01 | 9599 | |
b270e6f9 | 9600 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9601 | } |
9602 | ||
6c5b2ebe | 9603 | if (canonical.lsals.size () > 1) |
95a42b64 | 9604 | { |
3e43a32a MS |
9605 | warning (_("Multiple breakpoints were set.\nUse the " |
9606 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9607 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9608 | } |
9609 | ||
44702360 | 9610 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9611 | |
9612 | return 1; | |
c3f6f71d | 9613 | } |
c906108c | 9614 | |
348d480f | 9615 | /* Set a breakpoint. |
72b2ff0e VP |
9616 | ARG is a string describing breakpoint address, |
9617 | condition, and thread. | |
9618 | FLAG specifies if a breakpoint is hardware on, | |
9619 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9620 | and BP_TEMPFLAG. */ | |
348d480f | 9621 | |
98deb0da | 9622 | static void |
f2fc3015 | 9623 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9624 | { |
72b2ff0e | 9625 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9626 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9627 | ? bp_hardware_breakpoint | |
9628 | : bp_breakpoint); | |
f00aae0f | 9629 | |
ffc2605c | 9630 | event_location_up location = string_to_event_location (&arg, current_language); |
bac7c5cf GB |
9631 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
9632 | (location.get (), false /* is_tracepoint */); | |
c3f6f71d | 9633 | |
8cdf0e15 | 9634 | create_breakpoint (get_current_arch (), |
ffc2605c | 9635 | location.get (), |
f00aae0f | 9636 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9637 | tempflag, type_wanted, |
8cdf0e15 VP |
9638 | 0 /* Ignore count */, |
9639 | pending_break_support, | |
55aa24fb | 9640 | ops, |
8cdf0e15 | 9641 | from_tty, |
84f4c1fe | 9642 | 1 /* enabled */, |
44f238bb PA |
9643 | 0 /* internal */, |
9644 | 0); | |
c906108c SS |
9645 | } |
9646 | ||
c906108c SS |
9647 | /* Helper function for break_command_1 and disassemble_command. */ |
9648 | ||
9649 | void | |
fba45db2 | 9650 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9651 | { |
9652 | CORE_ADDR pc; | |
9653 | ||
9654 | if (sal->pc == 0 && sal->symtab != NULL) | |
9655 | { | |
9656 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9657 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9658 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9659 | sal->pc = pc; |
6a048695 | 9660 | |
4a64f543 | 9661 | /* If this SAL corresponds to a breakpoint inserted using a line |
dda83cd7 | 9662 | number, then skip the function prologue if necessary. */ |
6a048695 | 9663 | if (sal->explicit_line) |
059acae7 | 9664 | skip_prologue_sal (sal); |
c906108c SS |
9665 | } |
9666 | ||
9667 | if (sal->section == 0 && sal->symtab != NULL) | |
9668 | { | |
346d1dfe | 9669 | const struct blockvector *bv; |
3977b71f | 9670 | const struct block *b; |
c5aa993b | 9671 | struct symbol *sym; |
c906108c | 9672 | |
43f3e411 DE |
9673 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9674 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9675 | if (bv != NULL) |
9676 | { | |
7f0df278 | 9677 | sym = block_linkage_function (b); |
c906108c SS |
9678 | if (sym != NULL) |
9679 | { | |
eb822aa6 DE |
9680 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9681 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9682 | sym); | |
c906108c SS |
9683 | } |
9684 | else | |
9685 | { | |
4a64f543 | 9686 | /* It really is worthwhile to have the section, so we'll |
dda83cd7 SM |
9687 | just have to look harder. This case can be executed |
9688 | if we have line numbers but no functions (as can | |
9689 | happen in assembly source). */ | |
c906108c | 9690 | |
5ed8105e | 9691 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9692 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9693 | |
5ed8105e | 9694 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9695 | if (msym.minsym) |
efd66ac6 | 9696 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9697 | } |
9698 | } | |
9699 | } | |
9700 | } | |
9701 | ||
9702 | void | |
0b39b52e | 9703 | break_command (const char *arg, int from_tty) |
c906108c | 9704 | { |
db107f19 | 9705 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9706 | } |
9707 | ||
c906108c | 9708 | void |
0b39b52e | 9709 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9710 | { |
db107f19 | 9711 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9712 | } |
9713 | ||
c906108c | 9714 | static void |
0b39b52e | 9715 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9716 | { |
db107f19 | 9717 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9718 | } |
9719 | ||
9720 | static void | |
0b39b52e | 9721 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9722 | { |
db107f19 | 9723 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9724 | } |
9725 | ||
9726 | static void | |
ee7ddd71 | 9727 | stop_command (const char *arg, int from_tty) |
c906108c | 9728 | { |
a3f17187 | 9729 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9730 | Usage: stop in <function | address>\n\ |
a3f17187 | 9731 | stop at <line>\n")); |
c906108c SS |
9732 | } |
9733 | ||
9734 | static void | |
4495129a | 9735 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9736 | { |
9737 | int badInput = 0; | |
9738 | ||
cafb3438 | 9739 | if (arg == NULL) |
c906108c SS |
9740 | badInput = 1; |
9741 | else if (*arg != '*') | |
9742 | { | |
4495129a | 9743 | const char *argptr = arg; |
c906108c SS |
9744 | int hasColon = 0; |
9745 | ||
4a64f543 | 9746 | /* Look for a ':'. If this is a line number specification, then |
dda83cd7 SM |
9747 | say it is bad, otherwise, it should be an address or |
9748 | function/method name. */ | |
c906108c | 9749 | while (*argptr && !hasColon) |
c5aa993b JM |
9750 | { |
9751 | hasColon = (*argptr == ':'); | |
9752 | argptr++; | |
9753 | } | |
c906108c SS |
9754 | |
9755 | if (hasColon) | |
c5aa993b | 9756 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9757 | else |
c5aa993b | 9758 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9759 | } |
9760 | ||
9761 | if (badInput) | |
a3f17187 | 9762 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9763 | else |
db107f19 | 9764 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9765 | } |
9766 | ||
9767 | static void | |
4495129a | 9768 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9769 | { |
9770 | int badInput = 0; | |
9771 | ||
cafb3438 | 9772 | if (arg == NULL || *arg == '*') /* no line number */ |
c906108c SS |
9773 | badInput = 1; |
9774 | else | |
9775 | { | |
4495129a | 9776 | const char *argptr = arg; |
c906108c SS |
9777 | int hasColon = 0; |
9778 | ||
4a64f543 | 9779 | /* Look for a ':'. If there is a '::' then get out, otherwise |
dda83cd7 | 9780 | it is probably a line number. */ |
c906108c | 9781 | while (*argptr && !hasColon) |
c5aa993b JM |
9782 | { |
9783 | hasColon = (*argptr == ':'); | |
9784 | argptr++; | |
9785 | } | |
c906108c SS |
9786 | |
9787 | if (hasColon) | |
c5aa993b | 9788 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9789 | else |
c5aa993b | 9790 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9791 | } |
9792 | ||
9793 | if (badInput) | |
65e65158 | 9794 | printf_filtered (_("Usage: stop at LINE\n")); |
c906108c | 9795 | else |
db107f19 | 9796 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9797 | } |
9798 | ||
e7e0cddf SS |
9799 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9800 | with a prewired command list consisting of a single output command, | |
9801 | built from extra arguments supplied on the dprintf command | |
9802 | line. */ | |
9803 | ||
da821c7b | 9804 | static void |
0b39b52e | 9805 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9806 | { |
ffc2605c | 9807 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9808 | |
9809 | /* If non-NULL, ARG should have been advanced past the location; | |
9810 | the next character must be ','. */ | |
9811 | if (arg != NULL) | |
9812 | { | |
9813 | if (arg[0] != ',' || arg[1] == '\0') | |
9814 | error (_("Format string required")); | |
9815 | else | |
9816 | { | |
9817 | /* Skip the comma. */ | |
9818 | ++arg; | |
9819 | } | |
9820 | } | |
9821 | ||
e7e0cddf | 9822 | create_breakpoint (get_current_arch (), |
ffc2605c | 9823 | location.get (), |
f00aae0f | 9824 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9825 | 0, bp_dprintf, |
9826 | 0 /* Ignore count */, | |
9827 | pending_break_support, | |
9828 | &dprintf_breakpoint_ops, | |
9829 | from_tty, | |
9830 | 1 /* enabled */, | |
9831 | 0 /* internal */, | |
9832 | 0); | |
9833 | } | |
9834 | ||
d3ce09f5 | 9835 | static void |
0b39b52e | 9836 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9837 | { |
9838 | error (_("May only run agent-printf on the target")); | |
9839 | } | |
9840 | ||
f1310107 TJB |
9841 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9842 | ranged breakpoints. */ | |
9843 | ||
9844 | static int | |
9845 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9846 | const address_space *aspace, |
09ac7c10 TT |
9847 | CORE_ADDR bp_addr, |
9848 | const struct target_waitstatus *ws) | |
f1310107 | 9849 | { |
09ac7c10 | 9850 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9851 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9852 | return 0; |
9853 | ||
f1310107 TJB |
9854 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9855 | bl->length, aspace, bp_addr); | |
9856 | } | |
9857 | ||
9858 | /* Implement the "resources_needed" breakpoint_ops method for | |
9859 | ranged breakpoints. */ | |
9860 | ||
9861 | static int | |
9862 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9863 | { | |
9864 | return target_ranged_break_num_registers (); | |
9865 | } | |
9866 | ||
9867 | /* Implement the "print_it" breakpoint_ops method for | |
9868 | ranged breakpoints. */ | |
9869 | ||
9870 | static enum print_stop_action | |
348d480f | 9871 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9872 | { |
348d480f | 9873 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9874 | struct bp_location *bl = b->loc; |
79a45e25 | 9875 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9876 | |
9877 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9878 | ||
9879 | /* Ranged breakpoints have only one location. */ | |
9880 | gdb_assert (bl && bl->next == NULL); | |
9881 | ||
9882 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9883 | |
9884 | maybe_print_thread_hit_breakpoint (uiout); | |
9885 | ||
f1310107 | 9886 | if (b->disposition == disp_del) |
112e8700 | 9887 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9888 | else |
112e8700 SM |
9889 | uiout->text ("Ranged breakpoint "); |
9890 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9891 | { |
112e8700 | 9892 | uiout->field_string ("reason", |
f1310107 | 9893 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9894 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9895 | } |
381befee | 9896 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 9897 | uiout->text (", "); |
f1310107 TJB |
9898 | |
9899 | return PRINT_SRC_AND_LOC; | |
9900 | } | |
9901 | ||
9902 | /* Implement the "print_one" breakpoint_ops method for | |
9903 | ranged breakpoints. */ | |
9904 | ||
9905 | static void | |
9906 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9907 | struct bp_location **last_loc) | |
9908 | { | |
9909 | struct bp_location *bl = b->loc; | |
9910 | struct value_print_options opts; | |
79a45e25 | 9911 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9912 | |
9913 | /* Ranged breakpoints have only one location. */ | |
9914 | gdb_assert (bl && bl->next == NULL); | |
9915 | ||
9916 | get_user_print_options (&opts); | |
9917 | ||
9918 | if (opts.addressprint) | |
9919 | /* We don't print the address range here, it will be printed later | |
9920 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9921 | uiout->field_skip ("addr"); |
f1310107 TJB |
9922 | annotate_field (5); |
9923 | print_breakpoint_location (b, bl); | |
9924 | *last_loc = bl; | |
9925 | } | |
9926 | ||
9927 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9928 | ranged breakpoints. */ | |
9929 | ||
9930 | static void | |
9931 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9932 | struct ui_out *uiout) | |
9933 | { | |
9934 | CORE_ADDR address_start, address_end; | |
9935 | struct bp_location *bl = b->loc; | |
d7e74731 | 9936 | string_file stb; |
f1310107 TJB |
9937 | |
9938 | gdb_assert (bl); | |
9939 | ||
9940 | address_start = bl->address; | |
9941 | address_end = address_start + bl->length - 1; | |
9942 | ||
112e8700 | 9943 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9944 | stb.printf ("[%s, %s]", |
9945 | print_core_address (bl->gdbarch, address_start), | |
9946 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9947 | uiout->field_stream ("addr", stb); |
9948 | uiout->text ("\n"); | |
f1310107 TJB |
9949 | } |
9950 | ||
9951 | /* Implement the "print_mention" breakpoint_ops method for | |
9952 | ranged breakpoints. */ | |
9953 | ||
9954 | static void | |
9955 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9956 | { | |
9957 | struct bp_location *bl = b->loc; | |
79a45e25 | 9958 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9959 | |
9960 | gdb_assert (bl); | |
9961 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9962 | ||
2d33446d TT |
9963 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
9964 | b->number, paddress (bl->gdbarch, bl->address), | |
9965 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
f1310107 TJB |
9966 | } |
9967 | ||
9968 | /* Implement the "print_recreate" breakpoint_ops method for | |
9969 | ranged breakpoints. */ | |
9970 | ||
9971 | static void | |
9972 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9973 | { | |
f00aae0f | 9974 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9975 | event_location_to_string (b->location.get ()), |
9976 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9977 | print_recreate_thread (b, fp); |
f1310107 TJB |
9978 | } |
9979 | ||
9980 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9981 | ||
2060206e | 9982 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9983 | |
9984 | /* Find the address where the end of the breakpoint range should be | |
9985 | placed, given the SAL of the end of the range. This is so that if | |
9986 | the user provides a line number, the end of the range is set to the | |
9987 | last instruction of the given line. */ | |
9988 | ||
9989 | static CORE_ADDR | |
9990 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9991 | { | |
9992 | CORE_ADDR end; | |
9993 | ||
9994 | /* If the user provided a PC value, use it. Otherwise, | |
9995 | find the address of the end of the given location. */ | |
9996 | if (sal.explicit_pc) | |
9997 | end = sal.pc; | |
9998 | else | |
9999 | { | |
10000 | int ret; | |
10001 | CORE_ADDR start; | |
10002 | ||
10003 | ret = find_line_pc_range (sal, &start, &end); | |
10004 | if (!ret) | |
10005 | error (_("Could not find location of the end of the range.")); | |
10006 | ||
10007 | /* find_line_pc_range returns the start of the next line. */ | |
10008 | end--; | |
10009 | } | |
10010 | ||
10011 | return end; | |
10012 | } | |
10013 | ||
10014 | /* Implement the "break-range" CLI command. */ | |
10015 | ||
10016 | static void | |
0b39b52e | 10017 | break_range_command (const char *arg, int from_tty) |
f1310107 | 10018 | { |
f2fc3015 | 10019 | const char *arg_start; |
f1310107 TJB |
10020 | struct linespec_result canonical_start, canonical_end; |
10021 | int bp_count, can_use_bp, length; | |
10022 | CORE_ADDR end; | |
10023 | struct breakpoint *b; | |
f1310107 TJB |
10024 | |
10025 | /* We don't support software ranged breakpoints. */ | |
10026 | if (target_ranged_break_num_registers () < 0) | |
10027 | error (_("This target does not support hardware ranged breakpoints.")); | |
10028 | ||
10029 | bp_count = hw_breakpoint_used_count (); | |
10030 | bp_count += target_ranged_break_num_registers (); | |
10031 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10032 | bp_count, 0); | |
10033 | if (can_use_bp < 0) | |
10034 | error (_("Hardware breakpoints used exceeds limit.")); | |
10035 | ||
f8eba3c6 | 10036 | arg = skip_spaces (arg); |
f1310107 TJB |
10037 | if (arg == NULL || arg[0] == '\0') |
10038 | error(_("No address range specified.")); | |
10039 | ||
f8eba3c6 | 10040 | arg_start = arg; |
ffc2605c TT |
10041 | event_location_up start_location = string_to_event_location (&arg, |
10042 | current_language); | |
10043 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
10044 | |
10045 | if (arg[0] != ',') | |
10046 | error (_("Too few arguments.")); | |
6c5b2ebe | 10047 | else if (canonical_start.lsals.empty ()) |
f1310107 | 10048 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 10049 | |
6c5b2ebe | 10050 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 10051 | |
6c5b2ebe PA |
10052 | if (canonical_start.lsals.size () > 1 |
10053 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
10054 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10055 | ||
6c5b2ebe | 10056 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 10057 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
10058 | |
10059 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10060 | arg = skip_spaces (arg); |
f1310107 TJB |
10061 | |
10062 | /* Parse the end location. */ | |
10063 | ||
f1310107 TJB |
10064 | arg_start = arg; |
10065 | ||
f8eba3c6 | 10066 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10067 | parse_breakpoint_sals because we need to specify the start location's |
10068 | symtab and line as the default symtab and line for the end of the | |
10069 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10070 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10071 | event_location_up end_location = string_to_event_location (&arg, |
10072 | current_language); | |
10073 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10074 | sal_start.symtab, sal_start.line, |
10075 | &canonical_end, NULL, NULL); | |
10076 | ||
6c5b2ebe | 10077 | if (canonical_end.lsals.empty ()) |
f1310107 | 10078 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 10079 | |
6c5b2ebe PA |
10080 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
10081 | if (canonical_end.lsals.size () > 1 | |
10082 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
10083 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10084 | ||
6c5b2ebe | 10085 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
10086 | |
10087 | end = find_breakpoint_range_end (sal_end); | |
10088 | if (sal_start.pc > end) | |
177b42fe | 10089 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10090 | |
10091 | length = end - sal_start.pc + 1; | |
10092 | if (length < 0) | |
10093 | /* Length overflowed. */ | |
10094 | error (_("Address range too large.")); | |
10095 | else if (length == 1) | |
10096 | { | |
10097 | /* This range is simple enough to be handled by | |
10098 | the `hbreak' command. */ | |
81b1e71c | 10099 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
10100 | |
10101 | return; | |
10102 | } | |
10103 | ||
10104 | /* Now set up the breakpoint. */ | |
10105 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10106 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10107 | set_breakpoint_count (breakpoint_count + 1); |
10108 | b->number = breakpoint_count; | |
10109 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10110 | b->location = std::move (start_location); |
10111 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10112 | b->loc->length = length; |
10113 | ||
f1310107 | 10114 | mention (b); |
76727919 | 10115 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 10116 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10117 | } |
10118 | ||
4a64f543 MS |
10119 | /* Return non-zero if EXP is verified as constant. Returned zero |
10120 | means EXP is variable. Also the constant detection may fail for | |
10121 | some constant expressions and in such case still falsely return | |
10122 | zero. */ | |
2e6e3d9c | 10123 | |
dab72643 | 10124 | static bool |
65d79d4b SDJ |
10125 | watchpoint_exp_is_const (const struct expression *exp) |
10126 | { | |
10127 | int i = exp->nelts; | |
10128 | ||
10129 | while (i > 0) | |
10130 | { | |
10131 | int oplenp, argsp; | |
10132 | ||
10133 | /* We are only interested in the descriptor of each element. */ | |
10134 | operator_length (exp, i, &oplenp, &argsp); | |
10135 | i -= oplenp; | |
10136 | ||
10137 | switch (exp->elts[i].opcode) | |
10138 | { | |
10139 | case BINOP_ADD: | |
10140 | case BINOP_SUB: | |
10141 | case BINOP_MUL: | |
10142 | case BINOP_DIV: | |
10143 | case BINOP_REM: | |
10144 | case BINOP_MOD: | |
10145 | case BINOP_LSH: | |
10146 | case BINOP_RSH: | |
10147 | case BINOP_LOGICAL_AND: | |
10148 | case BINOP_LOGICAL_OR: | |
10149 | case BINOP_BITWISE_AND: | |
10150 | case BINOP_BITWISE_IOR: | |
10151 | case BINOP_BITWISE_XOR: | |
10152 | case BINOP_EQUAL: | |
10153 | case BINOP_NOTEQUAL: | |
10154 | case BINOP_LESS: | |
10155 | case BINOP_GTR: | |
10156 | case BINOP_LEQ: | |
10157 | case BINOP_GEQ: | |
10158 | case BINOP_REPEAT: | |
10159 | case BINOP_COMMA: | |
10160 | case BINOP_EXP: | |
10161 | case BINOP_MIN: | |
10162 | case BINOP_MAX: | |
10163 | case BINOP_INTDIV: | |
10164 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10165 | case TERNOP_COND: |
10166 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10167 | |
10168 | case OP_LONG: | |
edd079d9 | 10169 | case OP_FLOAT: |
65d79d4b SDJ |
10170 | case OP_LAST: |
10171 | case OP_COMPLEX: | |
10172 | case OP_STRING: | |
65d79d4b SDJ |
10173 | case OP_ARRAY: |
10174 | case OP_TYPE: | |
608b4967 TT |
10175 | case OP_TYPEOF: |
10176 | case OP_DECLTYPE: | |
6e72ca20 | 10177 | case OP_TYPEID: |
65d79d4b SDJ |
10178 | case OP_NAME: |
10179 | case OP_OBJC_NSSTRING: | |
10180 | ||
10181 | case UNOP_NEG: | |
10182 | case UNOP_LOGICAL_NOT: | |
10183 | case UNOP_COMPLEMENT: | |
10184 | case UNOP_ADDR: | |
10185 | case UNOP_HIGH: | |
aeaa2474 | 10186 | case UNOP_CAST: |
9eaf6705 TT |
10187 | |
10188 | case UNOP_CAST_TYPE: | |
10189 | case UNOP_REINTERPRET_CAST: | |
10190 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10191 | /* Unary, binary and ternary operators: We have to check |
10192 | their operands. If they are constant, then so is the | |
10193 | result of that operation. For instance, if A and B are | |
10194 | determined to be constants, then so is "A + B". | |
10195 | ||
10196 | UNOP_IND is one exception to the rule above, because the | |
10197 | value of *ADDR is not necessarily a constant, even when | |
10198 | ADDR is. */ | |
65d79d4b SDJ |
10199 | break; |
10200 | ||
10201 | case OP_VAR_VALUE: | |
10202 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10203 | |
65d79d4b | 10204 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10205 | possible that a buggy compiler could mark a variable as |
10206 | constant even when it is not, and TYPE_CONST would return | |
10207 | true in this case, while SYMBOL_CLASS wouldn't. | |
10208 | ||
10209 | We also have to check for function symbols because they | |
10210 | are always constant. */ | |
65d79d4b SDJ |
10211 | { |
10212 | struct symbol *s = exp->elts[i + 2].symbol; | |
10213 | ||
10214 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10215 | && SYMBOL_CLASS (s) != LOC_CONST | |
10216 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
dab72643 | 10217 | return false; |
65d79d4b SDJ |
10218 | break; |
10219 | } | |
10220 | ||
10221 | /* The default action is to return 0 because we are using | |
10222 | the optimistic approach here: If we don't know something, | |
10223 | then it is not a constant. */ | |
10224 | default: | |
dab72643 | 10225 | return false; |
65d79d4b SDJ |
10226 | } |
10227 | } | |
10228 | ||
dab72643 | 10229 | return true; |
65d79d4b SDJ |
10230 | } |
10231 | ||
c1fc2657 | 10232 | /* Watchpoint destructor. */ |
3a5c3e22 | 10233 | |
c1fc2657 | 10234 | watchpoint::~watchpoint () |
3a5c3e22 | 10235 | { |
c1fc2657 SM |
10236 | xfree (this->exp_string); |
10237 | xfree (this->exp_string_reparse); | |
3a5c3e22 PA |
10238 | } |
10239 | ||
348d480f PA |
10240 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10241 | ||
10242 | static void | |
10243 | re_set_watchpoint (struct breakpoint *b) | |
10244 | { | |
3a5c3e22 PA |
10245 | struct watchpoint *w = (struct watchpoint *) b; |
10246 | ||
348d480f PA |
10247 | /* Watchpoint can be either on expression using entirely global |
10248 | variables, or it can be on local variables. | |
10249 | ||
10250 | Watchpoints of the first kind are never auto-deleted, and even | |
10251 | persist across program restarts. Since they can use variables | |
10252 | from shared libraries, we need to reparse expression as libraries | |
10253 | are loaded and unloaded. | |
10254 | ||
10255 | Watchpoints on local variables can also change meaning as result | |
10256 | of solib event. For example, if a watchpoint uses both a local | |
10257 | and a global variables in expression, it's a local watchpoint, | |
10258 | but unloading of a shared library will make the expression | |
10259 | invalid. This is not a very common use case, but we still | |
10260 | re-evaluate expression, to avoid surprises to the user. | |
10261 | ||
10262 | Note that for local watchpoints, we re-evaluate it only if | |
10263 | watchpoints frame id is still valid. If it's not, it means the | |
10264 | watchpoint is out of scope and will be deleted soon. In fact, | |
10265 | I'm not sure we'll ever be called in this case. | |
10266 | ||
10267 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10268 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10269 | |
3a5c3e22 PA |
10270 | Don't do anything about disabled watchpoints, since they will be |
10271 | reevaluated again when enabled. */ | |
10272 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10273 | } |
10274 | ||
77b06cd7 TJB |
10275 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10276 | ||
10277 | static int | |
10278 | insert_watchpoint (struct bp_location *bl) | |
10279 | { | |
3a5c3e22 PA |
10280 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10281 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10282 | |
10283 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10284 | w->cond_exp.get ()); |
77b06cd7 TJB |
10285 | } |
10286 | ||
10287 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10288 | ||
10289 | static int | |
73971819 | 10290 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10291 | { |
3a5c3e22 PA |
10292 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10293 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10294 | |
10295 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10296 | w->cond_exp.get ()); |
e09342b5 TJB |
10297 | } |
10298 | ||
e09342b5 | 10299 | static int |
348d480f | 10300 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 10301 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 10302 | const struct target_waitstatus *ws) |
e09342b5 | 10303 | { |
348d480f | 10304 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10305 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10306 | |
348d480f PA |
10307 | /* Continuable hardware watchpoints are treated as non-existent if the |
10308 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10309 | some data address). Otherwise gdb won't stop on a break instruction | |
10310 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10311 | been defined. Also skip watchpoints which we know did not trigger | |
10312 | (did not match the data address). */ | |
10313 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10314 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10315 | return 0; |
9c06b0b4 | 10316 | |
348d480f | 10317 | return 1; |
9c06b0b4 TJB |
10318 | } |
10319 | ||
348d480f PA |
10320 | static void |
10321 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10322 | { |
348d480f | 10323 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10324 | |
348d480f | 10325 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10326 | } |
10327 | ||
10328 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10329 | hardware watchpoints. */ |
9c06b0b4 TJB |
10330 | |
10331 | static int | |
348d480f | 10332 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10333 | { |
3a5c3e22 PA |
10334 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10335 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10336 | |
10337 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10338 | } |
10339 | ||
10340 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10341 | hardware watchpoints. */ |
9c06b0b4 TJB |
10342 | |
10343 | static int | |
348d480f | 10344 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10345 | { |
efa80663 PA |
10346 | /* Read and access watchpoints only work with hardware support. */ |
10347 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10348 | } |
10349 | ||
9c06b0b4 | 10350 | static enum print_stop_action |
348d480f | 10351 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10352 | { |
348d480f | 10353 | struct breakpoint *b; |
348d480f | 10354 | enum print_stop_action result; |
3a5c3e22 | 10355 | struct watchpoint *w; |
79a45e25 | 10356 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10357 | |
10358 | gdb_assert (bs->bp_location_at != NULL); | |
10359 | ||
348d480f | 10360 | b = bs->breakpoint_at; |
3a5c3e22 | 10361 | w = (struct watchpoint *) b; |
348d480f | 10362 | |
f303dbd6 PA |
10363 | annotate_watchpoint (b->number); |
10364 | maybe_print_thread_hit_breakpoint (uiout); | |
10365 | ||
d7e74731 PA |
10366 | string_file stb; |
10367 | ||
76f9c9cf | 10368 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10369 | switch (b->type) |
10370 | { | |
348d480f | 10371 | case bp_watchpoint: |
9c06b0b4 | 10372 | case bp_hardware_watchpoint: |
112e8700 SM |
10373 | if (uiout->is_mi_like_p ()) |
10374 | uiout->field_string | |
10375 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10376 | mention (b); |
76f9c9cf | 10377 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10378 | uiout->text ("\nOld value = "); |
850645cf | 10379 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10380 | uiout->field_stream ("old", stb); |
10381 | uiout->text ("\nNew value = "); | |
850645cf | 10382 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10383 | uiout->field_stream ("new", stb); |
10384 | uiout->text ("\n"); | |
348d480f PA |
10385 | /* More than one watchpoint may have been triggered. */ |
10386 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10387 | break; |
10388 | ||
10389 | case bp_read_watchpoint: | |
112e8700 SM |
10390 | if (uiout->is_mi_like_p ()) |
10391 | uiout->field_string | |
10392 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10393 | mention (b); |
76f9c9cf | 10394 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10395 | uiout->text ("\nValue = "); |
850645cf | 10396 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10397 | uiout->field_stream ("value", stb); |
10398 | uiout->text ("\n"); | |
348d480f | 10399 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10400 | break; |
10401 | ||
10402 | case bp_access_watchpoint: | |
348d480f PA |
10403 | if (bs->old_val != NULL) |
10404 | { | |
112e8700 SM |
10405 | if (uiout->is_mi_like_p ()) |
10406 | uiout->field_string | |
10407 | ("reason", | |
348d480f PA |
10408 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10409 | mention (b); | |
76f9c9cf | 10410 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10411 | uiout->text ("\nOld value = "); |
850645cf | 10412 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10413 | uiout->field_stream ("old", stb); |
10414 | uiout->text ("\nNew value = "); | |
348d480f PA |
10415 | } |
10416 | else | |
10417 | { | |
10418 | mention (b); | |
112e8700 SM |
10419 | if (uiout->is_mi_like_p ()) |
10420 | uiout->field_string | |
10421 | ("reason", | |
348d480f | 10422 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10423 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10424 | uiout->text ("\nValue = "); |
348d480f | 10425 | } |
850645cf | 10426 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10427 | uiout->field_stream ("new", stb); |
10428 | uiout->text ("\n"); | |
348d480f | 10429 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10430 | break; |
10431 | default: | |
348d480f | 10432 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10433 | } |
10434 | ||
348d480f PA |
10435 | return result; |
10436 | } | |
10437 | ||
10438 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10439 | watchpoints. */ | |
10440 | ||
10441 | static void | |
10442 | print_mention_watchpoint (struct breakpoint *b) | |
10443 | { | |
3a5c3e22 | 10444 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10445 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10446 | const char *tuple_name; |
348d480f PA |
10447 | |
10448 | switch (b->type) | |
10449 | { | |
10450 | case bp_watchpoint: | |
112e8700 | 10451 | uiout->text ("Watchpoint "); |
46b9c129 | 10452 | tuple_name = "wpt"; |
348d480f PA |
10453 | break; |
10454 | case bp_hardware_watchpoint: | |
112e8700 | 10455 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10456 | tuple_name = "wpt"; |
348d480f PA |
10457 | break; |
10458 | case bp_read_watchpoint: | |
112e8700 | 10459 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10460 | tuple_name = "hw-rwpt"; |
348d480f PA |
10461 | break; |
10462 | case bp_access_watchpoint: | |
112e8700 | 10463 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10464 | tuple_name = "hw-awpt"; |
348d480f PA |
10465 | break; |
10466 | default: | |
10467 | internal_error (__FILE__, __LINE__, | |
10468 | _("Invalid hardware watchpoint type.")); | |
10469 | } | |
10470 | ||
46b9c129 | 10471 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10472 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10473 | uiout->text (": "); |
10474 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10475 | } |
10476 | ||
10477 | /* Implement the "print_recreate" breakpoint_ops method for | |
10478 | watchpoints. */ | |
10479 | ||
10480 | static void | |
10481 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10482 | { | |
3a5c3e22 PA |
10483 | struct watchpoint *w = (struct watchpoint *) b; |
10484 | ||
348d480f PA |
10485 | switch (b->type) |
10486 | { | |
10487 | case bp_watchpoint: | |
10488 | case bp_hardware_watchpoint: | |
10489 | fprintf_unfiltered (fp, "watch"); | |
10490 | break; | |
10491 | case bp_read_watchpoint: | |
10492 | fprintf_unfiltered (fp, "rwatch"); | |
10493 | break; | |
10494 | case bp_access_watchpoint: | |
10495 | fprintf_unfiltered (fp, "awatch"); | |
10496 | break; | |
10497 | default: | |
10498 | internal_error (__FILE__, __LINE__, | |
10499 | _("Invalid watchpoint type.")); | |
10500 | } | |
10501 | ||
3a5c3e22 | 10502 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10503 | print_recreate_thread (b, fp); |
348d480f PA |
10504 | } |
10505 | ||
427cd150 TT |
10506 | /* Implement the "explains_signal" breakpoint_ops method for |
10507 | watchpoints. */ | |
10508 | ||
47591c29 | 10509 | static int |
427cd150 TT |
10510 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10511 | { | |
10512 | /* A software watchpoint cannot cause a signal other than | |
10513 | GDB_SIGNAL_TRAP. */ | |
10514 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10515 | return 0; |
427cd150 | 10516 | |
47591c29 | 10517 | return 1; |
427cd150 TT |
10518 | } |
10519 | ||
348d480f PA |
10520 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10521 | ||
2060206e | 10522 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10523 | |
10524 | /* Implement the "insert" breakpoint_ops method for | |
10525 | masked hardware watchpoints. */ | |
10526 | ||
10527 | static int | |
10528 | insert_masked_watchpoint (struct bp_location *bl) | |
10529 | { | |
3a5c3e22 PA |
10530 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10531 | ||
10532 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10533 | bl->watchpoint_type); |
10534 | } | |
10535 | ||
10536 | /* Implement the "remove" breakpoint_ops method for | |
10537 | masked hardware watchpoints. */ | |
10538 | ||
10539 | static int | |
73971819 | 10540 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10541 | { |
3a5c3e22 PA |
10542 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10543 | ||
10544 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
dda83cd7 | 10545 | bl->watchpoint_type); |
348d480f PA |
10546 | } |
10547 | ||
10548 | /* Implement the "resources_needed" breakpoint_ops method for | |
10549 | masked hardware watchpoints. */ | |
10550 | ||
10551 | static int | |
10552 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10553 | { | |
3a5c3e22 PA |
10554 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10555 | ||
10556 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10557 | } |
10558 | ||
10559 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10560 | masked hardware watchpoints. */ | |
10561 | ||
10562 | static int | |
10563 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10564 | { | |
10565 | return 0; | |
10566 | } | |
10567 | ||
10568 | /* Implement the "print_it" breakpoint_ops method for | |
10569 | masked hardware watchpoints. */ | |
10570 | ||
10571 | static enum print_stop_action | |
10572 | print_it_masked_watchpoint (bpstat bs) | |
10573 | { | |
10574 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10575 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10576 | |
10577 | /* Masked watchpoints have only one location. */ | |
10578 | gdb_assert (b->loc && b->loc->next == NULL); | |
10579 | ||
f303dbd6 PA |
10580 | annotate_watchpoint (b->number); |
10581 | maybe_print_thread_hit_breakpoint (uiout); | |
10582 | ||
348d480f PA |
10583 | switch (b->type) |
10584 | { | |
10585 | case bp_hardware_watchpoint: | |
112e8700 SM |
10586 | if (uiout->is_mi_like_p ()) |
10587 | uiout->field_string | |
10588 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10589 | break; |
10590 | ||
10591 | case bp_read_watchpoint: | |
112e8700 SM |
10592 | if (uiout->is_mi_like_p ()) |
10593 | uiout->field_string | |
10594 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10595 | break; |
10596 | ||
10597 | case bp_access_watchpoint: | |
112e8700 SM |
10598 | if (uiout->is_mi_like_p ()) |
10599 | uiout->field_string | |
10600 | ("reason", | |
348d480f PA |
10601 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10602 | break; | |
10603 | default: | |
10604 | internal_error (__FILE__, __LINE__, | |
10605 | _("Invalid hardware watchpoint type.")); | |
10606 | } | |
10607 | ||
10608 | mention (b); | |
112e8700 | 10609 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10610 | Check the underlying instruction at PC for the memory\n\ |
10611 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10612 | uiout->text ("\n"); |
9c06b0b4 TJB |
10613 | |
10614 | /* More than one watchpoint may have been triggered. */ | |
10615 | return PRINT_UNKNOWN; | |
10616 | } | |
10617 | ||
10618 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10619 | masked hardware watchpoints. */ | |
10620 | ||
10621 | static void | |
10622 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10623 | struct ui_out *uiout) | |
10624 | { | |
3a5c3e22 PA |
10625 | struct watchpoint *w = (struct watchpoint *) b; |
10626 | ||
9c06b0b4 TJB |
10627 | /* Masked watchpoints have only one location. */ |
10628 | gdb_assert (b->loc && b->loc->next == NULL); | |
10629 | ||
112e8700 SM |
10630 | uiout->text ("\tmask "); |
10631 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10632 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10633 | } |
10634 | ||
10635 | /* Implement the "print_mention" breakpoint_ops method for | |
10636 | masked hardware watchpoints. */ | |
10637 | ||
10638 | static void | |
10639 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10640 | { | |
3a5c3e22 | 10641 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10642 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10643 | const char *tuple_name; |
9c06b0b4 TJB |
10644 | |
10645 | switch (b->type) | |
10646 | { | |
10647 | case bp_hardware_watchpoint: | |
112e8700 | 10648 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10649 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10650 | break; |
10651 | case bp_read_watchpoint: | |
112e8700 | 10652 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10653 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10654 | break; |
10655 | case bp_access_watchpoint: | |
112e8700 | 10656 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10657 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10658 | break; |
10659 | default: | |
10660 | internal_error (__FILE__, __LINE__, | |
10661 | _("Invalid hardware watchpoint type.")); | |
10662 | } | |
10663 | ||
46b9c129 | 10664 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10665 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10666 | uiout->text (": "); |
10667 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10668 | } |
10669 | ||
10670 | /* Implement the "print_recreate" breakpoint_ops method for | |
10671 | masked hardware watchpoints. */ | |
10672 | ||
10673 | static void | |
10674 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10675 | { | |
3a5c3e22 | 10676 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10677 | |
10678 | switch (b->type) | |
10679 | { | |
10680 | case bp_hardware_watchpoint: | |
10681 | fprintf_unfiltered (fp, "watch"); | |
10682 | break; | |
10683 | case bp_read_watchpoint: | |
10684 | fprintf_unfiltered (fp, "rwatch"); | |
10685 | break; | |
10686 | case bp_access_watchpoint: | |
10687 | fprintf_unfiltered (fp, "awatch"); | |
10688 | break; | |
10689 | default: | |
10690 | internal_error (__FILE__, __LINE__, | |
10691 | _("Invalid hardware watchpoint type.")); | |
10692 | } | |
10693 | ||
53807e9f TT |
10694 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, |
10695 | phex (w->hw_wp_mask, sizeof (CORE_ADDR))); | |
d9b3f62e | 10696 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10697 | } |
10698 | ||
10699 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10700 | ||
2060206e | 10701 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10702 | |
10703 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10704 | ||
f2478a7e | 10705 | static bool |
9c06b0b4 TJB |
10706 | is_masked_watchpoint (const struct breakpoint *b) |
10707 | { | |
10708 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10709 | } | |
10710 | ||
53a5351d | 10711 | /* accessflag: hw_write: watch write, |
dda83cd7 | 10712 | hw_read: watch read, |
53a5351d | 10713 | hw_access: watch access (read or write) */ |
c906108c | 10714 | static void |
bbc13ae3 | 10715 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
2e362716 | 10716 | bool just_location, bool internal) |
c906108c | 10717 | { |
c1fc2657 | 10718 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10719 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 10720 | struct value *result; |
bb9d5f81 | 10721 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10722 | const char *exp_start = NULL; |
10723 | const char *exp_end = NULL; | |
10724 | const char *tok, *end_tok; | |
9c06b0b4 | 10725 | int toklen = -1; |
bbc13ae3 KS |
10726 | const char *cond_start = NULL; |
10727 | const char *cond_end = NULL; | |
c906108c | 10728 | enum bptype bp_type; |
37e4754d | 10729 | int thread = -1; |
0cf6dd15 | 10730 | int pc = 0; |
9c06b0b4 TJB |
10731 | /* Flag to indicate whether we are going to use masks for |
10732 | the hardware watchpoint. */ | |
2e362716 | 10733 | bool use_mask = false; |
9c06b0b4 | 10734 | CORE_ADDR mask = 0; |
c906108c | 10735 | |
37e4754d LM |
10736 | /* Make sure that we actually have parameters to parse. */ |
10737 | if (arg != NULL && arg[0] != '\0') | |
10738 | { | |
bbc13ae3 KS |
10739 | const char *value_start; |
10740 | ||
10741 | exp_end = arg + strlen (arg); | |
37e4754d | 10742 | |
9c06b0b4 TJB |
10743 | /* Look for "parameter value" pairs at the end |
10744 | of the arguments string. */ | |
bbc13ae3 | 10745 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10746 | { |
10747 | /* Skip whitespace at the end of the argument list. */ | |
10748 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10749 | tok--; | |
10750 | ||
10751 | /* Find the beginning of the last token. | |
10752 | This is the value of the parameter. */ | |
10753 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10754 | tok--; | |
10755 | value_start = tok + 1; | |
10756 | ||
10757 | /* Skip whitespace. */ | |
10758 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10759 | tok--; | |
10760 | ||
10761 | end_tok = tok; | |
10762 | ||
10763 | /* Find the beginning of the second to last token. | |
10764 | This is the parameter itself. */ | |
10765 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10766 | tok--; | |
10767 | tok++; | |
10768 | toklen = end_tok - tok + 1; | |
10769 | ||
61012eef | 10770 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10771 | { |
5d5658a1 | 10772 | struct thread_info *thr; |
9c06b0b4 TJB |
10773 | /* At this point we've found a "thread" token, which means |
10774 | the user is trying to set a watchpoint that triggers | |
10775 | only in a specific thread. */ | |
5d5658a1 | 10776 | const char *endp; |
37e4754d | 10777 | |
9c06b0b4 TJB |
10778 | if (thread != -1) |
10779 | error(_("You can specify only one thread.")); | |
37e4754d | 10780 | |
9c06b0b4 | 10781 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10782 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10783 | |
5d5658a1 | 10784 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10785 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10786 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10787 | |
5d5658a1 | 10788 | thread = thr->global_num; |
9c06b0b4 | 10789 | } |
61012eef | 10790 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10791 | { |
10792 | /* We've found a "mask" token, which means the user wants to | |
10793 | create a hardware watchpoint that is going to have the mask | |
10794 | facility. */ | |
10795 | struct value *mask_value, *mark; | |
37e4754d | 10796 | |
9c06b0b4 TJB |
10797 | if (use_mask) |
10798 | error(_("You can specify only one mask.")); | |
37e4754d | 10799 | |
2e362716 | 10800 | use_mask = just_location = true; |
37e4754d | 10801 | |
9c06b0b4 TJB |
10802 | mark = value_mark (); |
10803 | mask_value = parse_to_comma_and_eval (&value_start); | |
10804 | mask = value_as_address (mask_value); | |
10805 | value_free_to_mark (mark); | |
10806 | } | |
10807 | else | |
10808 | /* We didn't recognize what we found. We should stop here. */ | |
10809 | break; | |
37e4754d | 10810 | |
9c06b0b4 TJB |
10811 | /* Truncate the string and get rid of the "parameter value" pair before |
10812 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10813 | exp_end = tok; |
9c06b0b4 | 10814 | } |
37e4754d | 10815 | } |
bbc13ae3 KS |
10816 | else |
10817 | exp_end = arg; | |
37e4754d | 10818 | |
bbc13ae3 KS |
10819 | /* Parse the rest of the arguments. From here on out, everything |
10820 | is in terms of a newly allocated string instead of the original | |
10821 | ARG. */ | |
81b1e71c TT |
10822 | std::string expression (arg, exp_end - arg); |
10823 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10824 | innermost_block_tracker tracker; |
10825 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10826 | exp_end = arg; |
fa8a61dc TT |
10827 | /* Remove trailing whitespace from the expression before saving it. |
10828 | This makes the eventual display of the expression string a bit | |
10829 | prettier. */ | |
10830 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10831 | --exp_end; | |
10832 | ||
65d79d4b | 10833 | /* Checking if the expression is not constant. */ |
4d01a485 | 10834 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10835 | { |
10836 | int len; | |
10837 | ||
10838 | len = exp_end - exp_start; | |
10839 | while (len > 0 && isspace (exp_start[len - 1])) | |
10840 | len--; | |
10841 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10842 | } | |
10843 | ||
699bd4cf | 10844 | exp_valid_block = tracker.block (); |
b926417a | 10845 | struct value *mark = value_mark (); |
850645cf TT |
10846 | struct value *val_as_value = nullptr; |
10847 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, | |
10848 | just_location); | |
06a64a0b | 10849 | |
850645cf | 10850 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10851 | { |
850645cf TT |
10852 | saved_bitpos = value_bitpos (val_as_value); |
10853 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10854 | } |
10855 | ||
850645cf | 10856 | value_ref_ptr val; |
06a64a0b TT |
10857 | if (just_location) |
10858 | { | |
9c06b0b4 TJB |
10859 | int ret; |
10860 | ||
06a64a0b | 10861 | exp_valid_block = NULL; |
850645cf | 10862 | val = release_value (value_addr (result)); |
06a64a0b | 10863 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10864 | |
10865 | if (use_mask) | |
10866 | { | |
850645cf | 10867 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10868 | mask); |
10869 | if (ret == -1) | |
10870 | error (_("This target does not support masked watchpoints.")); | |
10871 | else if (ret == -2) | |
10872 | error (_("Invalid mask or memory region.")); | |
10873 | } | |
06a64a0b | 10874 | } |
850645cf TT |
10875 | else if (val_as_value != NULL) |
10876 | val = release_value (val_as_value); | |
c906108c | 10877 | |
f1735a53 TT |
10878 | tok = skip_spaces (arg); |
10879 | end_tok = skip_to_space (tok); | |
c906108c SS |
10880 | |
10881 | toklen = end_tok - tok; | |
10882 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10883 | { | |
10884 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10885 | innermost_block_tracker if_tracker; |
10886 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10887 | |
10888 | /* The watchpoint expression may not be local, but the condition | |
10889 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10890 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10891 | |
c906108c SS |
10892 | cond_end = tok; |
10893 | } | |
10894 | if (*tok) | |
8a3fe4f8 | 10895 | error (_("Junk at end of command.")); |
c906108c | 10896 | |
441d7c93 PA |
10897 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10898 | ||
10899 | /* Save this because create_internal_breakpoint below invalidates | |
10900 | 'wp_frame'. */ | |
10901 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10902 | |
10903 | /* If the expression is "local", then set up a "watchpoint scope" | |
10904 | breakpoint at the point where we've left the scope of the watchpoint | |
10905 | expression. Create the scope breakpoint before the watchpoint, so | |
10906 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10907 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10908 | { |
441d7c93 PA |
10909 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10910 | ||
10911 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10912 | { |
441d7c93 PA |
10913 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10914 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10915 | ||
edb3359d | 10916 | scope_breakpoint |
441d7c93 | 10917 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10918 | bp_watchpoint_scope, |
10919 | &momentary_breakpoint_ops); | |
d983da9c | 10920 | |
441d7c93 PA |
10921 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10922 | wp_frame = NULL; | |
10923 | ||
edb3359d | 10924 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10925 | |
edb3359d DJ |
10926 | /* Automatically delete the breakpoint when it hits. */ |
10927 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10928 | |
edb3359d | 10929 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10930 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10931 | |
edb3359d | 10932 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10933 | scope_breakpoint->loc->gdbarch = caller_arch; |
10934 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10935 | scope_breakpoint->loc->address |
a6d9a66e UW |
10936 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10937 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10938 | scope_breakpoint->type); |
10939 | } | |
d983da9c DJ |
10940 | } |
10941 | ||
e8369a73 AB |
10942 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10943 | watchpoints here even if hardware watchpoints are turned off, a call | |
10944 | to update_watchpoint later in this function will cause the type to | |
10945 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10946 | ||
10947 | if (accessflag == hw_read) | |
10948 | bp_type = bp_read_watchpoint; | |
10949 | else if (accessflag == hw_access) | |
10950 | bp_type = bp_access_watchpoint; | |
10951 | else | |
10952 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10953 | |
b270e6f9 | 10954 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10955 | |
348d480f | 10956 | if (use_mask) |
b270e6f9 | 10957 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10958 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10959 | else |
b270e6f9 | 10960 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10961 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10962 | w->thread = thread; |
10963 | w->disposition = disp_donttouch; | |
10964 | w->pspace = current_program_space; | |
b22e99fd | 10965 | w->exp = std::move (exp); |
3a5c3e22 PA |
10966 | w->exp_valid_block = exp_valid_block; |
10967 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10968 | if (just_location) |
10969 | { | |
850645cf TT |
10970 | struct type *t = value_type (val.get ()); |
10971 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10972 | |
43cc5389 | 10973 | w->exp_string_reparse |
f16a9f57 | 10974 | = current_language->watch_location_expression (t, addr).release (); |
06a64a0b | 10975 | |
3a5c3e22 | 10976 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 10977 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
10978 | } |
10979 | else | |
3a5c3e22 | 10980 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10981 | |
10982 | if (use_mask) | |
10983 | { | |
3a5c3e22 | 10984 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10985 | } |
10986 | else | |
10987 | { | |
3a5c3e22 | 10988 | w->val = val; |
bb9d5f81 PP |
10989 | w->val_bitpos = saved_bitpos; |
10990 | w->val_bitsize = saved_bitsize; | |
4c1d86d9 | 10991 | w->val_valid = true; |
9c06b0b4 | 10992 | } |
77b06cd7 | 10993 | |
c906108c | 10994 | if (cond_start) |
c1fc2657 | 10995 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 10996 | else |
c1fc2657 | 10997 | w->cond_string = 0; |
c5aa993b | 10998 | |
441d7c93 | 10999 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 11000 | { |
441d7c93 | 11001 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 11002 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 11003 | } |
c906108c | 11004 | else |
f6bc2008 | 11005 | { |
3a5c3e22 PA |
11006 | w->watchpoint_frame = null_frame_id; |
11007 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11008 | } |
c906108c | 11009 | |
d983da9c | 11010 | if (scope_breakpoint != NULL) |
c906108c | 11011 | { |
d983da9c DJ |
11012 | /* The scope breakpoint is related to the watchpoint. We will |
11013 | need to act on them together. */ | |
c1fc2657 | 11014 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 11015 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 11016 | } |
d983da9c | 11017 | |
06a64a0b TT |
11018 | if (!just_location) |
11019 | value_free_to_mark (mark); | |
2d134ed3 | 11020 | |
b270e6f9 TT |
11021 | /* Finally update the new watchpoint. This creates the locations |
11022 | that should be inserted. */ | |
11023 | update_watchpoint (w.get (), 1); | |
a9634178 | 11024 | |
b270e6f9 | 11025 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
11026 | } |
11027 | ||
e09342b5 | 11028 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11029 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11030 | |
c906108c | 11031 | static int |
a6535de1 | 11032 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
11033 | { |
11034 | int found_memory_cnt = 0; | |
11035 | ||
11036 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11037 | if (!can_use_hw_watchpoints) |
c906108c | 11038 | return 0; |
c5aa993b | 11039 | |
a6535de1 TT |
11040 | gdb_assert (!vals.empty ()); |
11041 | struct value *head = vals[0].get (); | |
11042 | ||
5c44784c JM |
11043 | /* Make sure that the value of the expression depends only upon |
11044 | memory contents, and values computed from them within GDB. If we | |
11045 | find any register references or function calls, we can't use a | |
11046 | hardware watchpoint. | |
11047 | ||
11048 | The idea here is that evaluating an expression generates a series | |
11049 | of values, one holding the value of every subexpression. (The | |
11050 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11051 | a*b+c.) GDB's values hold almost enough information to establish | |
11052 | the criteria given above --- they identify memory lvalues, | |
11053 | register lvalues, computed values, etcetera. So we can evaluate | |
11054 | the expression, and then scan the chain of values that leaves | |
11055 | behind to decide whether we can detect any possible change to the | |
11056 | expression's final value using only hardware watchpoints. | |
11057 | ||
11058 | However, I don't think that the values returned by inferior | |
11059 | function calls are special in any way. So this function may not | |
11060 | notice that an expression involving an inferior function call | |
11061 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 11062 | for (const value_ref_ptr &iter : vals) |
c906108c | 11063 | { |
a6535de1 TT |
11064 | struct value *v = iter.get (); |
11065 | ||
5c44784c | 11066 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11067 | { |
8464be76 DJ |
11068 | if (v != head && value_lazy (v)) |
11069 | /* A lazy memory lvalue in the chain is one that GDB never | |
11070 | needed to fetch; we either just used its address (e.g., | |
11071 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11072 | in `a,b'). This doesn't apply to HEAD; if that is | |
11073 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11074 | ; |
53a5351d | 11075 | else |
5c44784c JM |
11076 | { |
11077 | /* Ahh, memory we actually used! Check if we can cover | |
dda83cd7 | 11078 | it with hardware watchpoints. */ |
df407dfe | 11079 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11080 | |
11081 | /* We only watch structs and arrays if user asked for it | |
11082 | explicitly, never if they just happen to appear in a | |
11083 | middle of some value chain. */ | |
11084 | if (v == head | |
78134374 SM |
11085 | || (vtype->code () != TYPE_CODE_STRUCT |
11086 | && vtype->code () != TYPE_CODE_ARRAY)) | |
2e70b7b9 | 11087 | { |
42ae5230 | 11088 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11089 | int len; |
11090 | int num_regs; | |
11091 | ||
a9634178 | 11092 | len = (target_exact_watchpoints |
e09342b5 TJB |
11093 | && is_scalar_type_recursive (vtype))? |
11094 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11095 | |
e09342b5 TJB |
11096 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11097 | if (!num_regs) | |
2e70b7b9 MS |
11098 | return 0; |
11099 | else | |
e09342b5 | 11100 | found_memory_cnt += num_regs; |
2e70b7b9 | 11101 | } |
5c44784c | 11102 | } |
c5aa993b | 11103 | } |
5086187c AC |
11104 | else if (VALUE_LVAL (v) != not_lval |
11105 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11106 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11107 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11108 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11109 | } |
11110 | ||
11111 | /* The expression itself looks suitable for using a hardware | |
11112 | watchpoint, but give the target machine a chance to reject it. */ | |
11113 | return found_memory_cnt; | |
11114 | } | |
11115 | ||
8b93c638 | 11116 | void |
2e362716 | 11117 | watch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 11118 | { |
84f4c1fe | 11119 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11120 | } |
11121 | ||
a15a5258 AB |
11122 | /* Options for the watch, awatch, and rwatch commands. */ |
11123 | ||
11124 | struct watch_options | |
11125 | { | |
11126 | /* For -location. */ | |
11127 | bool location = false; | |
11128 | }; | |
11129 | ||
11130 | /* Definitions of options for the "watch", "awatch", and "rwatch" commands. | |
11131 | ||
11132 | Historically GDB always accepted both '-location' and '-l' flags for | |
11133 | these commands (both flags being synonyms). When converting to the | |
11134 | newer option scheme only '-location' is added here. That's fine (for | |
11135 | backward compatibility) as any non-ambiguous prefix of a flag will be | |
11136 | accepted, so '-l', '-loc', are now all accepted. | |
11137 | ||
11138 | What this means is that, if in the future, we add any new flag here | |
11139 | that starts with '-l' then this will break backward compatibility, so | |
11140 | please, don't do that! */ | |
11141 | ||
11142 | static const gdb::option::option_def watch_option_defs[] = { | |
11143 | gdb::option::flag_option_def<watch_options> { | |
11144 | "location", | |
11145 | [] (watch_options *opt) { return &opt->location; }, | |
11146 | N_("\ | |
11147 | This evaluates EXPRESSION and watches the memory to which is refers.\n\ | |
11148 | -l can be used as a short form of -location."), | |
11149 | }, | |
11150 | }; | |
11151 | ||
11152 | /* Returns the option group used by 'watch', 'awatch', and 'rwatch' | |
11153 | commands. */ | |
11154 | ||
11155 | static gdb::option::option_def_group | |
11156 | make_watch_options_def_group (watch_options *opts) | |
11157 | { | |
11158 | return {{watch_option_defs}, opts}; | |
11159 | } | |
11160 | ||
06a64a0b TT |
11161 | /* A helper function that looks for the "-location" argument and then |
11162 | calls watch_command_1. */ | |
11163 | ||
11164 | static void | |
0b39b52e | 11165 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b | 11166 | { |
a15a5258 AB |
11167 | watch_options opts; |
11168 | auto grp = make_watch_options_def_group (&opts); | |
11169 | gdb::option::process_options | |
11170 | (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp); | |
11171 | if (arg != nullptr && *arg == '\0') | |
11172 | arg = nullptr; | |
11173 | ||
11174 | watch_command_1 (arg, accessflag, from_tty, opts.location, false); | |
11175 | } | |
06a64a0b | 11176 | |
a15a5258 AB |
11177 | /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */ |
11178 | static void | |
11179 | watch_command_completer (struct cmd_list_element *ignore, | |
11180 | completion_tracker &tracker, | |
11181 | const char *text, const char * /*word*/) | |
11182 | { | |
11183 | const auto group = make_watch_options_def_group (nullptr); | |
11184 | if (gdb::option::complete_options | |
11185 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group)) | |
11186 | return; | |
06a64a0b | 11187 | |
a15a5258 AB |
11188 | const char *word = advance_to_expression_complete_word_point (tracker, text); |
11189 | expression_completer (ignore, tracker, text, word); | |
8b93c638 | 11190 | } |
8926118c | 11191 | |
c5aa993b | 11192 | static void |
0b39b52e | 11193 | watch_command (const char *arg, int from_tty) |
c906108c | 11194 | { |
06a64a0b | 11195 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11196 | } |
11197 | ||
8b93c638 | 11198 | void |
2e362716 | 11199 | rwatch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 11200 | { |
84f4c1fe | 11201 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11202 | } |
8926118c | 11203 | |
c5aa993b | 11204 | static void |
0b39b52e | 11205 | rwatch_command (const char *arg, int from_tty) |
c906108c | 11206 | { |
06a64a0b | 11207 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11208 | } |
11209 | ||
8b93c638 | 11210 | void |
2e362716 | 11211 | awatch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 11212 | { |
84f4c1fe | 11213 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11214 | } |
8926118c | 11215 | |
c5aa993b | 11216 | static void |
0b39b52e | 11217 | awatch_command (const char *arg, int from_tty) |
c906108c | 11218 | { |
06a64a0b | 11219 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11220 | } |
c906108c | 11221 | \f |
c5aa993b | 11222 | |
cfc31633 PA |
11223 | /* Data for the FSM that manages the until(location)/advance commands |
11224 | in infcmd.c. Here because it uses the mechanisms of | |
11225 | breakpoints. */ | |
c906108c | 11226 | |
46e3ed7f | 11227 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 11228 | { |
46e3ed7f | 11229 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
11230 | int thread; |
11231 | ||
df631783 PA |
11232 | /* The breakpoint set at the return address in the caller frame, |
11233 | plus breakpoints at all the destination locations. */ | |
11234 | std::vector<breakpoint_up> breakpoints; | |
cfc31633 | 11235 | |
46e3ed7f | 11236 | until_break_fsm (struct interp *cmd_interp, int thread, |
df631783 | 11237 | std::vector<breakpoint_up> &&breakpoints) |
46e3ed7f TT |
11238 | : thread_fsm (cmd_interp), |
11239 | thread (thread), | |
df631783 | 11240 | breakpoints (std::move (breakpoints)) |
46e3ed7f TT |
11241 | { |
11242 | } | |
cfc31633 | 11243 | |
46e3ed7f TT |
11244 | void clean_up (struct thread_info *thread) override; |
11245 | bool should_stop (struct thread_info *thread) override; | |
11246 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
11247 | }; |
11248 | ||
cfc31633 PA |
11249 | /* Implementation of the 'should_stop' FSM method for the |
11250 | until(location)/advance commands. */ | |
11251 | ||
46e3ed7f TT |
11252 | bool |
11253 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 11254 | { |
df631783 PA |
11255 | for (const breakpoint_up &bp : breakpoints) |
11256 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11257 | bp.get ()) != NULL) | |
11258 | { | |
11259 | set_finished (); | |
11260 | break; | |
11261 | } | |
cfc31633 | 11262 | |
46e3ed7f | 11263 | return true; |
cfc31633 PA |
11264 | } |
11265 | ||
11266 | /* Implementation of the 'clean_up' FSM method for the | |
11267 | until(location)/advance commands. */ | |
11268 | ||
46e3ed7f TT |
11269 | void |
11270 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 11271 | { |
cfc31633 | 11272 | /* Clean up our temporary breakpoints. */ |
df631783 | 11273 | breakpoints.clear (); |
46e3ed7f | 11274 | delete_longjmp_breakpoint (thread); |
cfc31633 PA |
11275 | } |
11276 | ||
11277 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11278 | until(location)/advance commands. */ | |
11279 | ||
46e3ed7f TT |
11280 | enum async_reply_reason |
11281 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
11282 | { |
11283 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11284 | } |
11285 | ||
c906108c | 11286 | void |
f2fc3015 | 11287 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 11288 | { |
8556afb4 PA |
11289 | struct frame_info *frame; |
11290 | struct gdbarch *frame_gdbarch; | |
11291 | struct frame_id stack_frame_id; | |
11292 | struct frame_id caller_frame_id; | |
186c406b TT |
11293 | int thread; |
11294 | struct thread_info *tp; | |
c906108c | 11295 | |
70509625 | 11296 | clear_proceed_status (0); |
c906108c SS |
11297 | |
11298 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11299 | this function. */ |
c5aa993b | 11300 | |
ffc2605c | 11301 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11302 | |
6c5b2ebe PA |
11303 | std::vector<symtab_and_line> sals |
11304 | = (last_displayed_sal_is_valid () | |
11305 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11306 | get_last_displayed_symtab (), | |
11307 | get_last_displayed_line ()) | |
11308 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 11309 | NULL, NULL, 0)); |
c5aa993b | 11310 | |
df631783 | 11311 | if (sals.empty ()) |
8a3fe4f8 | 11312 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11313 | |
c906108c | 11314 | if (*arg) |
8a3fe4f8 | 11315 | error (_("Junk at end of arguments.")); |
c5aa993b | 11316 | |
186c406b | 11317 | tp = inferior_thread (); |
5d5658a1 | 11318 | thread = tp->global_num; |
186c406b | 11319 | |
8556afb4 PA |
11320 | /* Note linespec handling above invalidates the frame chain. |
11321 | Installing a breakpoint also invalidates the frame chain (as it | |
11322 | may need to switch threads), so do any frame handling before | |
11323 | that. */ | |
11324 | ||
11325 | frame = get_selected_frame (NULL); | |
11326 | frame_gdbarch = get_frame_arch (frame); | |
11327 | stack_frame_id = get_stack_frame_id (frame); | |
11328 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11329 | |
ae66c1fc EZ |
11330 | /* Keep within the current frame, or in frames called by the current |
11331 | one. */ | |
edb3359d | 11332 | |
df631783 | 11333 | std::vector<breakpoint_up> breakpoints; |
5419bdae TT |
11334 | |
11335 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
11336 | ||
883bc8d1 | 11337 | if (frame_id_p (caller_frame_id)) |
c906108c | 11338 | { |
883bc8d1 | 11339 | struct symtab_and_line sal2; |
cfc31633 | 11340 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11341 | |
11342 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11343 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 | 11344 | caller_gdbarch = frame_unwind_caller_arch (frame); |
df631783 PA |
11345 | |
11346 | breakpoint_up caller_breakpoint | |
11347 | = set_momentary_breakpoint (caller_gdbarch, sal2, | |
11348 | caller_frame_id, bp_until); | |
11349 | breakpoints.emplace_back (std::move (caller_breakpoint)); | |
186c406b | 11350 | |
883bc8d1 | 11351 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 11352 | lj_deleter.emplace (thread); |
c906108c | 11353 | } |
c5aa993b | 11354 | |
c70a6932 JK |
11355 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11356 | frame = NULL; | |
11357 | ||
df631783 PA |
11358 | /* If the user told us to continue until a specified location, we |
11359 | don't specify a frame at which we need to stop. Otherwise, | |
11360 | specify the selected frame, because we want to stop only at the | |
11361 | very same frame. */ | |
11362 | frame_id stop_frame_id = anywhere ? null_frame_id : stack_frame_id; | |
11363 | ||
11364 | for (symtab_and_line &sal : sals) | |
11365 | { | |
11366 | resolve_sal_pc (&sal); | |
11367 | ||
11368 | breakpoint_up location_breakpoint | |
11369 | = set_momentary_breakpoint (frame_gdbarch, sal, | |
11370 | stop_frame_id, bp_until); | |
11371 | breakpoints.emplace_back (std::move (location_breakpoint)); | |
11372 | } | |
883bc8d1 | 11373 | |
46e3ed7f | 11374 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
df631783 | 11375 | std::move (breakpoints)); |
f107f563 | 11376 | |
5419bdae TT |
11377 | if (lj_deleter) |
11378 | lj_deleter->release (); | |
f107f563 | 11379 | |
cfc31633 | 11380 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11381 | } |
ae66c1fc | 11382 | |
c906108c SS |
11383 | /* This function attempts to parse an optional "if <cond>" clause |
11384 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11385 | |
c906108c SS |
11386 | Else, it returns a pointer to the condition string. (It does not |
11387 | attempt to evaluate the string against a particular block.) And, | |
11388 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11389 | if clause in the arg string. */ |
53a5351d | 11390 | |
63160a43 PA |
11391 | const char * |
11392 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11393 | { |
63160a43 | 11394 | const char *cond_string; |
c5aa993b JM |
11395 | |
11396 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11397 | return NULL; |
c5aa993b | 11398 | |
4a64f543 | 11399 | /* Skip the "if" keyword. */ |
c906108c | 11400 | (*arg) += 2; |
c5aa993b | 11401 | |
c906108c | 11402 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11403 | condition string. */ |
f1735a53 | 11404 | *arg = skip_spaces (*arg); |
c906108c | 11405 | cond_string = *arg; |
c5aa993b | 11406 | |
4a64f543 MS |
11407 | /* Assume that the condition occupies the remainder of the arg |
11408 | string. */ | |
c906108c | 11409 | (*arg) += strlen (cond_string); |
c5aa993b | 11410 | |
c906108c SS |
11411 | return cond_string; |
11412 | } | |
c5aa993b | 11413 | |
c906108c SS |
11414 | /* Commands to deal with catching events, such as signals, exceptions, |
11415 | process start/exit, etc. */ | |
c5aa993b JM |
11416 | |
11417 | typedef enum | |
11418 | { | |
44feb3ce TT |
11419 | catch_fork_temporary, catch_vfork_temporary, |
11420 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11421 | } |
11422 | catch_fork_kind; | |
11423 | ||
c906108c | 11424 | static void |
eb4c3f4a | 11425 | catch_fork_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11426 | struct cmd_list_element *command) |
c906108c | 11427 | { |
a6d9a66e | 11428 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11429 | const char *cond_string = NULL; |
44feb3ce | 11430 | catch_fork_kind fork_kind; |
44feb3ce TT |
11431 | |
11432 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
b650a282 SM |
11433 | bool temp = (fork_kind == catch_fork_temporary |
11434 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11435 | |
44feb3ce TT |
11436 | if (!arg) |
11437 | arg = ""; | |
f1735a53 | 11438 | arg = skip_spaces (arg); |
c5aa993b | 11439 | |
c906108c | 11440 | /* The allowed syntax is: |
c5aa993b JM |
11441 | catch [v]fork |
11442 | catch [v]fork if <cond> | |
11443 | ||
4a64f543 | 11444 | First, check if there's an if clause. */ |
c906108c | 11445 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11446 | |
c906108c | 11447 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11448 | error (_("Junk at end of arguments.")); |
c5aa993b | 11449 | |
c906108c | 11450 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11451 | and enable reporting of such events. */ |
c5aa993b JM |
11452 | switch (fork_kind) |
11453 | { | |
44feb3ce TT |
11454 | case catch_fork_temporary: |
11455 | case catch_fork_permanent: | |
b650a282 | 11456 | create_fork_vfork_event_catchpoint (gdbarch, temp, cond_string, |
dda83cd7 | 11457 | &catch_fork_breakpoint_ops); |
c906108c | 11458 | break; |
44feb3ce TT |
11459 | case catch_vfork_temporary: |
11460 | case catch_vfork_permanent: | |
b650a282 | 11461 | create_fork_vfork_event_catchpoint (gdbarch, temp, cond_string, |
dda83cd7 | 11462 | &catch_vfork_breakpoint_ops); |
c906108c | 11463 | break; |
c5aa993b | 11464 | default: |
8a3fe4f8 | 11465 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11466 | break; |
c5aa993b | 11467 | } |
c906108c SS |
11468 | } |
11469 | ||
11470 | static void | |
eb4c3f4a | 11471 | catch_exec_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11472 | struct cmd_list_element *command) |
c906108c | 11473 | { |
a6d9a66e | 11474 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11475 | const char *cond_string = NULL; |
b650a282 | 11476 | bool temp = get_cmd_context (command) == CATCH_TEMPORARY; |
44feb3ce TT |
11477 | |
11478 | if (!arg) | |
11479 | arg = ""; | |
f1735a53 | 11480 | arg = skip_spaces (arg); |
c906108c SS |
11481 | |
11482 | /* The allowed syntax is: | |
c5aa993b JM |
11483 | catch exec |
11484 | catch exec if <cond> | |
c906108c | 11485 | |
4a64f543 | 11486 | First, check if there's an if clause. */ |
c906108c SS |
11487 | cond_string = ep_parse_optional_if_clause (&arg); |
11488 | ||
11489 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11490 | error (_("Junk at end of arguments.")); |
c906108c | 11491 | |
b270e6f9 | 11492 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
b650a282 | 11493 | init_catchpoint (c.get (), gdbarch, temp, cond_string, |
b4d90040 PA |
11494 | &catch_exec_breakpoint_ops); |
11495 | c->exec_pathname = NULL; | |
11496 | ||
b270e6f9 | 11497 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11498 | } |
c5aa993b | 11499 | |
9ac4176b | 11500 | void |
28010a5d PA |
11501 | init_ada_exception_breakpoint (struct breakpoint *b, |
11502 | struct gdbarch *gdbarch, | |
11503 | struct symtab_and_line sal, | |
f2fc3015 | 11504 | const char *addr_string, |
c0a91b2b | 11505 | const struct breakpoint_ops *ops, |
28010a5d | 11506 | int tempflag, |
349774ef | 11507 | int enabled, |
28010a5d | 11508 | int from_tty) |
f7f9143b | 11509 | { |
f7f9143b JB |
11510 | if (from_tty) |
11511 | { | |
5af949e3 UW |
11512 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11513 | if (!loc_gdbarch) | |
11514 | loc_gdbarch = gdbarch; | |
11515 | ||
6c95b8df PA |
11516 | describe_other_breakpoints (loc_gdbarch, |
11517 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b | 11518 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
dda83cd7 SM |
11519 | version for exception catchpoints, because two catchpoints |
11520 | used for different exception names will use the same address. | |
11521 | In this case, a "breakpoint ... also set at..." warning is | |
11522 | unproductive. Besides, the warning phrasing is also a bit | |
11523 | inappropriate, we should use the word catchpoint, and tell | |
11524 | the user what type of catchpoint it is. The above is good | |
11525 | enough for now, though. */ | |
f7f9143b JB |
11526 | } |
11527 | ||
f06f1252 | 11528 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
f7f9143b | 11529 | |
349774ef | 11530 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11531 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11532 | b->location = string_to_event_location (&addr_string, |
11533 | language_def (language_ada)); | |
f7f9143b | 11534 | b->language = language_ada; |
f7f9143b JB |
11535 | } |
11536 | ||
c906108c SS |
11537 | \f |
11538 | ||
81b1e71c | 11539 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
11540 | |
11541 | static int | |
81b1e71c | 11542 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 11543 | { |
81b1e71c TT |
11544 | uintptr_t ua = (uintptr_t) a; |
11545 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 11546 | |
81b1e71c | 11547 | if (a->number < b->number) |
8a2c437b | 11548 | return -1; |
81b1e71c | 11549 | else if (a->number > b->number) |
8a2c437b TT |
11550 | return 1; |
11551 | ||
11552 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11553 | the number 0. */ | |
11554 | if (ua < ub) | |
11555 | return -1; | |
94b0e70d | 11556 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11557 | } |
11558 | ||
80f8a6eb | 11559 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11560 | |
11561 | static void | |
0b39b52e | 11562 | clear_command (const char *arg, int from_tty) |
c906108c | 11563 | { |
81b1e71c | 11564 | struct breakpoint *b; |
c906108c | 11565 | int default_match; |
c906108c | 11566 | |
6c5b2ebe PA |
11567 | std::vector<symtab_and_line> decoded_sals; |
11568 | symtab_and_line last_sal; | |
11569 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11570 | if (arg) |
11571 | { | |
6c5b2ebe PA |
11572 | decoded_sals |
11573 | = decode_line_with_current_source (arg, | |
11574 | (DECODE_LINE_FUNFIRSTLINE | |
11575 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11576 | default_match = 0; |
6c5b2ebe | 11577 | sals = decoded_sals; |
c906108c SS |
11578 | } |
11579 | else | |
11580 | { | |
1bfeeb0f JL |
11581 | /* Set sal's line, symtab, pc, and pspace to the values |
11582 | corresponding to the last call to print_frame_info. If the | |
11583 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11584 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11585 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11586 | error (_("No source file specified.")); |
c906108c | 11587 | |
c906108c | 11588 | default_match = 1; |
6c5b2ebe | 11589 | sals = last_sal; |
c906108c SS |
11590 | } |
11591 | ||
4a64f543 MS |
11592 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11593 | seems, because all existing breakpoints typically have both | |
11594 | file/line and pc set. So, if clear is given file/line, we can | |
11595 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11596 | |
11597 | We only support clearing given the address explicitly | |
11598 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11599 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11600 | due to optimization, all in one block. |
4a64f543 MS |
11601 | |
11602 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11603 | PC corresponding to the same file:line, the breakpoint won't |
11604 | be cleared. We probably can still clear the breakpoint, but | |
11605 | since the other PC value is never presented to user, user | |
11606 | can only find it by guessing, and it does not seem important | |
11607 | to support that. */ | |
11608 | ||
4a64f543 MS |
11609 | /* For each line spec given, delete bps which correspond to it. Do |
11610 | it in two passes, solely to preserve the current behavior that | |
11611 | from_tty is forced true if we delete more than one | |
11612 | breakpoint. */ | |
c906108c | 11613 | |
81b1e71c | 11614 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 11615 | for (const auto &sal : sals) |
c906108c | 11616 | { |
05cba821 JK |
11617 | const char *sal_fullname; |
11618 | ||
c906108c | 11619 | /* If exact pc given, clear bpts at that pc. |
dda83cd7 SM |
11620 | If line given (pc == 0), clear all bpts on specified line. |
11621 | If defaulting, clear all bpts on default line | |
11622 | or at default pc. | |
c5aa993b | 11623 | |
dda83cd7 | 11624 | defaulting sal.pc != 0 tests to do |
c5aa993b | 11625 | |
dda83cd7 SM |
11626 | 0 1 pc |
11627 | 1 1 pc _and_ line | |
11628 | 0 0 line | |
11629 | 1 0 <can't happen> */ | |
c906108c | 11630 | |
05cba821 JK |
11631 | sal_fullname = (sal.symtab == NULL |
11632 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11633 | |
4a64f543 | 11634 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11635 | ALL_BREAKPOINTS (b) |
c5aa993b | 11636 | { |
0d381245 | 11637 | int match = 0; |
4a64f543 | 11638 | /* Are we going to delete b? */ |
cc60f2e3 | 11639 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11640 | { |
11641 | struct bp_location *loc = b->loc; | |
11642 | for (; loc; loc = loc->next) | |
11643 | { | |
f8eba3c6 TT |
11644 | /* If the user specified file:line, don't allow a PC |
11645 | match. This matches historical gdb behavior. */ | |
11646 | int pc_match = (!sal.explicit_line | |
11647 | && sal.pc | |
11648 | && (loc->pspace == sal.pspace) | |
11649 | && (loc->address == sal.pc) | |
11650 | && (!section_is_overlay (loc->section) | |
11651 | || loc->section == sal.section)); | |
4aac40c8 TT |
11652 | int line_match = 0; |
11653 | ||
11654 | if ((default_match || sal.explicit_line) | |
2f202fde | 11655 | && loc->symtab != NULL |
05cba821 | 11656 | && sal_fullname != NULL |
4aac40c8 | 11657 | && sal.pspace == loc->pspace |
05cba821 JK |
11658 | && loc->line_number == sal.line |
11659 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11660 | sal_fullname) == 0) | |
11661 | line_match = 1; | |
4aac40c8 | 11662 | |
0d381245 VP |
11663 | if (pc_match || line_match) |
11664 | { | |
11665 | match = 1; | |
11666 | break; | |
11667 | } | |
11668 | } | |
11669 | } | |
11670 | ||
11671 | if (match) | |
81b1e71c | 11672 | found.push_back (b); |
c906108c | 11673 | } |
80f8a6eb | 11674 | } |
8a2c437b | 11675 | |
80f8a6eb | 11676 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11677 | if (found.empty ()) |
80f8a6eb MS |
11678 | { |
11679 | if (arg) | |
8a3fe4f8 | 11680 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11681 | else |
8a3fe4f8 | 11682 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11683 | } |
c906108c | 11684 | |
8a2c437b | 11685 | /* Remove duplicates from the vec. */ |
81b1e71c | 11686 | std::sort (found.begin (), found.end (), |
b926417a | 11687 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11688 | { |
b926417a | 11689 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
11690 | }); |
11691 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 11692 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11693 | { |
b926417a | 11694 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
11695 | }), |
11696 | found.end ()); | |
8a2c437b | 11697 | |
81b1e71c | 11698 | if (found.size () > 1) |
4a64f543 | 11699 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11700 | if (from_tty) |
a3f17187 | 11701 | { |
81b1e71c | 11702 | if (found.size () == 1) |
a3f17187 AC |
11703 | printf_unfiltered (_("Deleted breakpoint ")); |
11704 | else | |
11705 | printf_unfiltered (_("Deleted breakpoints ")); | |
11706 | } | |
d6e956e5 | 11707 | |
81b1e71c | 11708 | for (breakpoint *iter : found) |
80f8a6eb | 11709 | { |
c5aa993b | 11710 | if (from_tty) |
81b1e71c TT |
11711 | printf_unfiltered ("%d ", iter->number); |
11712 | delete_breakpoint (iter); | |
c906108c | 11713 | } |
80f8a6eb MS |
11714 | if (from_tty) |
11715 | putchar_unfiltered ('\n'); | |
c906108c SS |
11716 | } |
11717 | \f | |
11718 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11719 | all breakpoints that are marked for deletion, whether hit or not. | |
11720 | This is called after any breakpoint is hit, or after errors. */ | |
11721 | ||
11722 | void | |
fba45db2 | 11723 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11724 | { |
35df4500 | 11725 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11726 | |
11727 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11728 | if (bs->breakpoint_at |
11729 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11730 | && bs->stop) |
f431efe5 | 11731 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11732 | |
35df4500 | 11733 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11734 | { |
b5de0fa7 | 11735 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11736 | delete_breakpoint (b); |
11737 | } | |
c906108c SS |
11738 | } |
11739 | ||
4a64f543 | 11740 | /* A comparison function for bp_location AP and BP being interfaced to |
39ef2f62 | 11741 | std::sort. Sort elements primarily by their ADDRESS (no matter what |
cb1e4e32 PA |
11742 | bl_address_is_meaningful says), secondarily by ordering first |
11743 | permanent elements and terciarily just ensuring the array is sorted | |
39ef2f62 | 11744 | stable way despite std::sort being an unstable algorithm. */ |
876fa593 JK |
11745 | |
11746 | static int | |
39ef2f62 | 11747 | bp_location_is_less_than (const bp_location *a, const bp_location *b) |
876fa593 | 11748 | { |
876fa593 | 11749 | if (a->address != b->address) |
39ef2f62 | 11750 | return a->address < b->address; |
876fa593 | 11751 | |
dea2aa5f LM |
11752 | /* Sort locations at the same address by their pspace number, keeping |
11753 | locations of the same inferior (in a multi-inferior environment) | |
11754 | grouped. */ | |
11755 | ||
11756 | if (a->pspace->num != b->pspace->num) | |
39ef2f62 | 11757 | return a->pspace->num < b->pspace->num; |
dea2aa5f | 11758 | |
876fa593 | 11759 | /* Sort permanent breakpoints first. */ |
1a853c52 | 11760 | if (a->permanent != b->permanent) |
39ef2f62 | 11761 | return a->permanent > b->permanent; |
876fa593 | 11762 | |
7f32a4d5 PA |
11763 | /* Sort by type in order to make duplicate determination easier. |
11764 | See update_global_location_list. This is kept in sync with | |
11765 | breakpoint_locations_match. */ | |
11766 | if (a->loc_type < b->loc_type) | |
11767 | return true; | |
11768 | ||
11769 | /* Likewise, for range-breakpoints, sort by length. */ | |
11770 | if (a->loc_type == bp_loc_hardware_breakpoint | |
11771 | && b->loc_type == bp_loc_hardware_breakpoint | |
11772 | && a->length < b->length) | |
11773 | return true; | |
11774 | ||
c56a97f9 JK |
11775 | /* Make the internal GDB representation stable across GDB runs |
11776 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11777 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11778 | |
11779 | if (a->owner->number != b->owner->number) | |
39ef2f62 | 11780 | return a->owner->number < b->owner->number; |
876fa593 | 11781 | |
39ef2f62 | 11782 | return a < b; |
876fa593 JK |
11783 | } |
11784 | ||
f5336ca5 PA |
11785 | /* Set bp_locations_placed_address_before_address_max and |
11786 | bp_locations_shadow_len_after_address_max according to the current | |
11787 | content of the bp_locations array. */ | |
f7545552 TT |
11788 | |
11789 | static void | |
f5336ca5 | 11790 | bp_locations_target_extensions_update (void) |
f7545552 | 11791 | { |
876fa593 JK |
11792 | struct bp_location *bl, **blp_tmp; |
11793 | ||
f5336ca5 PA |
11794 | bp_locations_placed_address_before_address_max = 0; |
11795 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11796 | |
11797 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11798 | { | |
11799 | CORE_ADDR start, end, addr; | |
11800 | ||
11801 | if (!bp_location_has_shadow (bl)) | |
11802 | continue; | |
11803 | ||
11804 | start = bl->target_info.placed_address; | |
11805 | end = start + bl->target_info.shadow_len; | |
11806 | ||
11807 | gdb_assert (bl->address >= start); | |
11808 | addr = bl->address - start; | |
f5336ca5 PA |
11809 | if (addr > bp_locations_placed_address_before_address_max) |
11810 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11811 | |
11812 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11813 | ||
11814 | gdb_assert (bl->address < end); | |
11815 | addr = end - bl->address; | |
f5336ca5 PA |
11816 | if (addr > bp_locations_shadow_len_after_address_max) |
11817 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11818 | } |
f7545552 TT |
11819 | } |
11820 | ||
1e4d1764 YQ |
11821 | /* Download tracepoint locations if they haven't been. */ |
11822 | ||
11823 | static void | |
11824 | download_tracepoint_locations (void) | |
11825 | { | |
7ed2c994 | 11826 | struct breakpoint *b; |
dd2e65cc | 11827 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11828 | |
5ed8105e | 11829 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11830 | |
7ed2c994 | 11831 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11832 | { |
7ed2c994 | 11833 | struct bp_location *bl; |
1e4d1764 | 11834 | struct tracepoint *t; |
f2a8bc8a | 11835 | int bp_location_downloaded = 0; |
1e4d1764 | 11836 | |
7ed2c994 | 11837 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11838 | ? !may_insert_fast_tracepoints |
11839 | : !may_insert_tracepoints)) | |
11840 | continue; | |
11841 | ||
dd2e65cc YQ |
11842 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11843 | { | |
11844 | if (target_can_download_tracepoint ()) | |
11845 | can_download_tracepoint = TRIBOOL_TRUE; | |
11846 | else | |
11847 | can_download_tracepoint = TRIBOOL_FALSE; | |
11848 | } | |
11849 | ||
11850 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11851 | break; | |
11852 | ||
7ed2c994 YQ |
11853 | for (bl = b->loc; bl; bl = bl->next) |
11854 | { | |
11855 | /* In tracepoint, locations are _never_ duplicated, so | |
11856 | should_be_inserted is equivalent to | |
11857 | unduplicated_should_be_inserted. */ | |
11858 | if (!should_be_inserted (bl) || bl->inserted) | |
11859 | continue; | |
1e4d1764 | 11860 | |
7ed2c994 | 11861 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11862 | |
7ed2c994 | 11863 | target_download_tracepoint (bl); |
1e4d1764 | 11864 | |
7ed2c994 | 11865 | bl->inserted = 1; |
f2a8bc8a | 11866 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11867 | } |
11868 | t = (struct tracepoint *) b; | |
11869 | t->number_on_target = b->number; | |
f2a8bc8a | 11870 | if (bp_location_downloaded) |
76727919 | 11871 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11872 | } |
1e4d1764 YQ |
11873 | } |
11874 | ||
934709f0 PW |
11875 | /* Swap the insertion/duplication state between two locations. */ |
11876 | ||
11877 | static void | |
11878 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11879 | { | |
11880 | const int left_inserted = left->inserted; | |
11881 | const int left_duplicate = left->duplicate; | |
b775012e | 11882 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11883 | const struct bp_target_info left_target_info = left->target_info; |
11884 | ||
1e4d1764 YQ |
11885 | /* Locations of tracepoints can never be duplicated. */ |
11886 | if (is_tracepoint (left->owner)) | |
11887 | gdb_assert (!left->duplicate); | |
11888 | if (is_tracepoint (right->owner)) | |
11889 | gdb_assert (!right->duplicate); | |
11890 | ||
934709f0 PW |
11891 | left->inserted = right->inserted; |
11892 | left->duplicate = right->duplicate; | |
b775012e | 11893 | left->needs_update = right->needs_update; |
934709f0 PW |
11894 | left->target_info = right->target_info; |
11895 | right->inserted = left_inserted; | |
11896 | right->duplicate = left_duplicate; | |
b775012e | 11897 | right->needs_update = left_needs_update; |
934709f0 PW |
11898 | right->target_info = left_target_info; |
11899 | } | |
11900 | ||
b775012e LM |
11901 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11902 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11903 | conditions on the target's side. Such conditions need to be updated on | |
11904 | the target. */ | |
11905 | ||
11906 | static void | |
11907 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11908 | { | |
11909 | struct bp_location **locp = NULL, **loc2p; | |
11910 | struct bp_location *loc; | |
11911 | CORE_ADDR address = 0; | |
11912 | int pspace_num; | |
11913 | ||
11914 | address = bl->address; | |
11915 | pspace_num = bl->pspace->num; | |
11916 | ||
11917 | /* This is only meaningful if the target is | |
11918 | evaluating conditions and if the user has | |
11919 | opted for condition evaluation on the target's | |
11920 | side. */ | |
11921 | if (gdb_evaluates_breakpoint_condition_p () | |
11922 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11923 | return; | |
11924 | ||
11925 | /* Flag all breakpoint locations with this address and | |
11926 | the same program space as the location | |
11927 | as "its condition has changed". We need to | |
11928 | update the conditions on the target's side. */ | |
11929 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11930 | { | |
11931 | loc = *loc2p; | |
11932 | ||
11933 | if (!is_breakpoint (loc->owner) | |
11934 | || pspace_num != loc->pspace->num) | |
11935 | continue; | |
11936 | ||
11937 | /* Flag the location appropriately. We use a different state to | |
11938 | let everyone know that we already updated the set of locations | |
11939 | with addr bl->address and program space bl->pspace. This is so | |
11940 | we don't have to keep calling these functions just to mark locations | |
11941 | that have already been marked. */ | |
11942 | loc->condition_changed = condition_updated; | |
11943 | ||
11944 | /* Free the agent expression bytecode as well. We will compute | |
11945 | it later on. */ | |
833177a4 | 11946 | loc->cond_bytecode.reset (); |
b775012e LM |
11947 | } |
11948 | } | |
7f32a4d5 | 11949 | |
44702360 PA |
11950 | /* Called whether new breakpoints are created, or existing breakpoints |
11951 | deleted, to update the global location list and recompute which | |
11952 | locations are duplicate of which. | |
b775012e | 11953 | |
04086b45 PA |
11954 | The INSERT_MODE flag determines whether locations may not, may, or |
11955 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11956 | info. */ | |
b60e7edf | 11957 | |
0d381245 | 11958 | static void |
44702360 | 11959 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11960 | { |
74960c60 | 11961 | struct breakpoint *b; |
876fa593 | 11962 | struct bp_location **locp, *loc; |
b775012e LM |
11963 | /* Last breakpoint location address that was marked for update. */ |
11964 | CORE_ADDR last_addr = 0; | |
11965 | /* Last breakpoint location program space that was marked for update. */ | |
11966 | int last_pspace_num = -1; | |
f7545552 | 11967 | |
2d134ed3 PA |
11968 | /* Used in the duplicates detection below. When iterating over all |
11969 | bp_locations, points to the first bp_location of a given address. | |
11970 | Breakpoints and watchpoints of different types are never | |
11971 | duplicates of each other. Keep one pointer for each type of | |
11972 | breakpoint/watchpoint, so we only need to loop over all locations | |
11973 | once. */ | |
11974 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11975 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11976 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11977 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11978 | |
f5336ca5 PA |
11979 | /* Saved former bp_locations array which we compare against the newly |
11980 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
81b1e71c | 11981 | struct bp_location **old_locp; |
f5336ca5 | 11982 | unsigned old_locations_count; |
81b1e71c | 11983 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
876fa593 | 11984 | |
f5336ca5 PA |
11985 | old_locations_count = bp_locations_count; |
11986 | bp_locations = NULL; | |
11987 | bp_locations_count = 0; | |
0d381245 | 11988 | |
74960c60 | 11989 | ALL_BREAKPOINTS (b) |
876fa593 | 11990 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 11991 | bp_locations_count++; |
876fa593 | 11992 | |
f5336ca5 PA |
11993 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
11994 | locp = bp_locations; | |
876fa593 JK |
11995 | ALL_BREAKPOINTS (b) |
11996 | for (loc = b->loc; loc; loc = loc->next) | |
11997 | *locp++ = loc; | |
7f32a4d5 PA |
11998 | |
11999 | /* See if we need to "upgrade" a software breakpoint to a hardware | |
12000 | breakpoint. Do this before deciding whether locations are | |
12001 | duplicates. Also do this before sorting because sorting order | |
12002 | depends on location type. */ | |
12003 | for (locp = bp_locations; | |
12004 | locp < bp_locations + bp_locations_count; | |
12005 | locp++) | |
12006 | { | |
12007 | loc = *locp; | |
12008 | if (!loc->inserted && should_be_inserted (loc)) | |
12009 | handle_automatic_hardware_breakpoints (loc); | |
12010 | } | |
12011 | ||
39ef2f62 CB |
12012 | std::sort (bp_locations, bp_locations + bp_locations_count, |
12013 | bp_location_is_less_than); | |
876fa593 | 12014 | |
f5336ca5 | 12015 | bp_locations_target_extensions_update (); |
74960c60 | 12016 | |
4a64f543 MS |
12017 | /* Identify bp_location instances that are no longer present in the |
12018 | new list, and therefore should be freed. Note that it's not | |
12019 | necessary that those locations should be removed from inferior -- | |
12020 | if there's another location at the same address (previously | |
12021 | marked as duplicate), we don't need to remove/insert the | |
12022 | location. | |
876fa593 | 12023 | |
4a64f543 MS |
12024 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12025 | and former bp_location array state respectively. */ | |
876fa593 | 12026 | |
f5336ca5 | 12027 | locp = bp_locations; |
81b1e71c TT |
12028 | for (old_locp = old_locations.get (); |
12029 | old_locp < old_locations.get () + old_locations_count; | |
876fa593 | 12030 | old_locp++) |
74960c60 | 12031 | { |
876fa593 | 12032 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12033 | struct bp_location **loc2p; |
876fa593 | 12034 | |
e5dd4106 | 12035 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12036 | not, we have to free it. */ |
c7d46a38 | 12037 | int found_object = 0; |
20874c92 VP |
12038 | /* Tells if the location should remain inserted in the target. */ |
12039 | int keep_in_target = 0; | |
12040 | int removed = 0; | |
876fa593 | 12041 | |
4a64f543 MS |
12042 | /* Skip LOCP entries which will definitely never be needed. |
12043 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 12044 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 12045 | && (*locp)->address < old_loc->address) |
876fa593 | 12046 | locp++; |
c7d46a38 PA |
12047 | |
12048 | for (loc2p = locp; | |
f5336ca5 | 12049 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
12050 | && (*loc2p)->address == old_loc->address); |
12051 | loc2p++) | |
12052 | { | |
b775012e LM |
12053 | /* Check if this is a new/duplicated location or a duplicated |
12054 | location that had its condition modified. If so, we want to send | |
12055 | its condition to the target if evaluation of conditions is taking | |
12056 | place there. */ | |
12057 | if ((*loc2p)->condition_changed == condition_modified | |
12058 | && (last_addr != old_loc->address | |
12059 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12060 | { |
b775012e LM |
12061 | force_breakpoint_reinsertion (*loc2p); |
12062 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12063 | } |
b775012e LM |
12064 | |
12065 | if (*loc2p == old_loc) | |
12066 | found_object = 1; | |
c7d46a38 | 12067 | } |
74960c60 | 12068 | |
b775012e LM |
12069 | /* We have already handled this address, update it so that we don't |
12070 | have to go through updates again. */ | |
12071 | last_addr = old_loc->address; | |
12072 | ||
12073 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12074 | if (!found_object) | |
12075 | force_breakpoint_reinsertion (old_loc); | |
12076 | ||
4a64f543 MS |
12077 | /* If this location is no longer present, and inserted, look if |
12078 | there's maybe a new location at the same address. If so, | |
12079 | mark that one inserted, and don't remove this one. This is | |
12080 | needed so that we don't have a time window where a breakpoint | |
12081 | at certain location is not inserted. */ | |
74960c60 | 12082 | |
876fa593 | 12083 | if (old_loc->inserted) |
0d381245 | 12084 | { |
4a64f543 MS |
12085 | /* If the location is inserted now, we might have to remove |
12086 | it. */ | |
74960c60 | 12087 | |
876fa593 | 12088 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12089 | { |
4a64f543 MS |
12090 | /* The location is still present in the location list, |
12091 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12092 | keep_in_target = 1; |
74960c60 VP |
12093 | } |
12094 | else | |
12095 | { | |
b775012e LM |
12096 | /* This location still exists, but it won't be kept in the |
12097 | target since it may have been disabled. We proceed to | |
12098 | remove its target-side condition. */ | |
12099 | ||
4a64f543 MS |
12100 | /* The location is either no longer present, or got |
12101 | disabled. See if there's another location at the | |
12102 | same address, in which case we don't need to remove | |
12103 | this one from the target. */ | |
876fa593 | 12104 | |
2bdf28a0 | 12105 | /* OLD_LOC comes from existing struct breakpoint. */ |
cb1e4e32 | 12106 | if (bl_address_is_meaningful (old_loc)) |
876fa593 | 12107 | { |
876fa593 | 12108 | for (loc2p = locp; |
f5336ca5 | 12109 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12110 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12111 | loc2p++) |
12112 | { | |
12113 | struct bp_location *loc2 = *loc2p; | |
12114 | ||
7f32a4d5 PA |
12115 | if (loc2 == old_loc) |
12116 | continue; | |
12117 | ||
2d134ed3 | 12118 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12119 | { |
85d721b8 PA |
12120 | /* Read watchpoint locations are switched to |
12121 | access watchpoints, if the former are not | |
12122 | supported, but the latter are. */ | |
12123 | if (is_hardware_watchpoint (old_loc->owner)) | |
12124 | { | |
12125 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12126 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12127 | } | |
12128 | ||
934709f0 PW |
12129 | /* loc2 is a duplicated location. We need to check |
12130 | if it should be inserted in case it will be | |
12131 | unduplicated. */ | |
7f32a4d5 | 12132 | if (unduplicated_should_be_inserted (loc2)) |
c7d46a38 | 12133 | { |
934709f0 | 12134 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12135 | keep_in_target = 1; |
12136 | break; | |
12137 | } | |
876fa593 JK |
12138 | } |
12139 | } | |
12140 | } | |
74960c60 VP |
12141 | } |
12142 | ||
20874c92 VP |
12143 | if (!keep_in_target) |
12144 | { | |
834c0d03 | 12145 | if (remove_breakpoint (old_loc)) |
20874c92 | 12146 | { |
4a64f543 MS |
12147 | /* This is just about all we can do. We could keep |
12148 | this location on the global list, and try to | |
12149 | remove it next time, but there's no particular | |
12150 | reason why we will succeed next time. | |
20874c92 | 12151 | |
4a64f543 MS |
12152 | Note that at this point, old_loc->owner is still |
12153 | valid, as delete_breakpoint frees the breakpoint | |
12154 | only after calling us. */ | |
3e43a32a MS |
12155 | printf_filtered (_("warning: Error removing " |
12156 | "breakpoint %d\n"), | |
876fa593 | 12157 | old_loc->owner->number); |
20874c92 VP |
12158 | } |
12159 | removed = 1; | |
12160 | } | |
0d381245 | 12161 | } |
74960c60 VP |
12162 | |
12163 | if (!found_object) | |
1c5cfe86 | 12164 | { |
fbea99ea | 12165 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12166 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12167 | { |
db82e815 PA |
12168 | /* This location was removed from the target. In |
12169 | non-stop mode, a race condition is possible where | |
12170 | we've removed a breakpoint, but stop events for that | |
12171 | breakpoint are already queued and will arrive later. | |
12172 | We apply an heuristic to be able to distinguish such | |
12173 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12174 | breakpoint location for a bit, and will retire it | |
12175 | after we see some number of events. The theory here | |
12176 | is that reporting of events should, "on the average", | |
12177 | be fair, so after a while we'll see events from all | |
12178 | threads that have anything of interest, and no longer | |
12179 | need to keep this breakpoint location around. We | |
12180 | don't hold locations forever so to reduce chances of | |
12181 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12182 | SIGTRAP. | |
12183 | ||
12184 | The heuristic failing can be disastrous on | |
12185 | decr_pc_after_break targets. | |
12186 | ||
12187 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12188 | if we fail to recognize a late breakpoint SIGTRAP, | |
12189 | because events_till_retirement has reached 0 too | |
12190 | soon, we'll fail to do the PC adjustment, and report | |
12191 | a random SIGTRAP to the user. When the user resumes | |
12192 | the inferior, it will most likely immediately crash | |
2dec564e | 12193 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12194 | corrupted, because of being resumed e.g., in the |
12195 | middle of a multi-byte instruction, or skipped a | |
12196 | one-byte instruction. This was actually seen happen | |
12197 | on native x86-linux, and should be less rare on | |
12198 | targets that do not support new thread events, like | |
12199 | remote, due to the heuristic depending on | |
12200 | thread_count. | |
12201 | ||
12202 | Mistaking a random SIGTRAP for a breakpoint trap | |
12203 | causes similar symptoms (PC adjustment applied when | |
12204 | it shouldn't), but then again, playing with SIGTRAPs | |
12205 | behind the debugger's back is asking for trouble. | |
12206 | ||
12207 | Since hardware watchpoint traps are always | |
12208 | distinguishable from other traps, so we don't need to | |
12209 | apply keep hardware watchpoint moribund locations | |
12210 | around. We simply always ignore hardware watchpoint | |
12211 | traps we can no longer explain. */ | |
12212 | ||
5b6d1e4f PA |
12213 | process_stratum_target *proc_target = nullptr; |
12214 | for (inferior *inf : all_inferiors ()) | |
12215 | if (inf->pspace == old_loc->pspace) | |
12216 | { | |
12217 | proc_target = inf->process_target (); | |
12218 | break; | |
12219 | } | |
12220 | if (proc_target != nullptr) | |
12221 | old_loc->events_till_retirement | |
12222 | = 3 * (thread_count (proc_target) + 1); | |
12223 | else | |
12224 | old_loc->events_till_retirement = 1; | |
876fa593 | 12225 | old_loc->owner = NULL; |
20874c92 | 12226 | |
1123588c | 12227 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
12228 | } |
12229 | else | |
f431efe5 PA |
12230 | { |
12231 | old_loc->owner = NULL; | |
12232 | decref_bp_location (&old_loc); | |
12233 | } | |
20874c92 | 12234 | } |
74960c60 | 12235 | } |
1c5cfe86 | 12236 | |
348d480f PA |
12237 | /* Rescan breakpoints at the same address and section, marking the |
12238 | first one as "first" and any others as "duplicates". This is so | |
12239 | that the bpt instruction is only inserted once. If we have a | |
12240 | permanent breakpoint at the same place as BPT, make that one the | |
12241 | official one, and the rest as duplicates. Permanent breakpoints | |
12242 | are sorted first for the same address. | |
12243 | ||
12244 | Do the same for hardware watchpoints, but also considering the | |
12245 | watchpoint's type (regular/access/read) and length. */ | |
12246 | ||
12247 | bp_loc_first = NULL; | |
12248 | wp_loc_first = NULL; | |
12249 | awp_loc_first = NULL; | |
12250 | rwp_loc_first = NULL; | |
12251 | ALL_BP_LOCATIONS (loc, locp) | |
12252 | { | |
12253 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12254 | non-NULL. */ | |
348d480f | 12255 | struct bp_location **loc_first_p; |
d3fbdd86 | 12256 | b = loc->owner; |
348d480f | 12257 | |
6f380991 | 12258 | if (!unduplicated_should_be_inserted (loc) |
cb1e4e32 | 12259 | || !bl_address_is_meaningful (loc) |
1e4d1764 YQ |
12260 | /* Don't detect duplicate for tracepoint locations because they are |
12261 | never duplicated. See the comments in field `duplicate' of | |
12262 | `struct bp_location'. */ | |
348d480f | 12263 | || is_tracepoint (b)) |
b775012e LM |
12264 | { |
12265 | /* Clear the condition modification flag. */ | |
12266 | loc->condition_changed = condition_unchanged; | |
12267 | continue; | |
12268 | } | |
348d480f | 12269 | |
348d480f PA |
12270 | if (b->type == bp_hardware_watchpoint) |
12271 | loc_first_p = &wp_loc_first; | |
12272 | else if (b->type == bp_read_watchpoint) | |
12273 | loc_first_p = &rwp_loc_first; | |
12274 | else if (b->type == bp_access_watchpoint) | |
12275 | loc_first_p = &awp_loc_first; | |
12276 | else | |
12277 | loc_first_p = &bp_loc_first; | |
12278 | ||
12279 | if (*loc_first_p == NULL | |
12280 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12281 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12282 | { | |
12283 | *loc_first_p = loc; | |
12284 | loc->duplicate = 0; | |
b775012e LM |
12285 | |
12286 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12287 | { | |
12288 | loc->needs_update = 1; | |
12289 | /* Clear the condition modification flag. */ | |
12290 | loc->condition_changed = condition_unchanged; | |
12291 | } | |
348d480f PA |
12292 | continue; |
12293 | } | |
12294 | ||
934709f0 PW |
12295 | |
12296 | /* This and the above ensure the invariant that the first location | |
12297 | is not duplicated, and is the inserted one. | |
12298 | All following are marked as duplicated, and are not inserted. */ | |
12299 | if (loc->inserted) | |
12300 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12301 | loc->duplicate = 1; |
12302 | ||
b775012e LM |
12303 | /* Clear the condition modification flag. */ |
12304 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12305 | } |
12306 | ||
a25a5a45 | 12307 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12308 | { |
04086b45 | 12309 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12310 | insert_breakpoint_locations (); |
12311 | else | |
12312 | { | |
44702360 PA |
12313 | /* Even though the caller told us to not insert new |
12314 | locations, we may still need to update conditions on the | |
12315 | target's side of breakpoints that were already inserted | |
12316 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12317 | only update conditions for locations that are marked |
12318 | "needs_update". */ | |
12319 | update_inserted_breakpoint_locations (); | |
12320 | } | |
12321 | } | |
348d480f | 12322 | |
04086b45 | 12323 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 12324 | download_tracepoint_locations (); |
348d480f PA |
12325 | } |
12326 | ||
12327 | void | |
12328 | breakpoint_retire_moribund (void) | |
12329 | { | |
1123588c TT |
12330 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
12331 | { | |
12332 | struct bp_location *loc = moribund_locations[ix]; | |
12333 | if (--(loc->events_till_retirement) == 0) | |
12334 | { | |
12335 | decref_bp_location (&loc); | |
12336 | unordered_remove (moribund_locations, ix); | |
12337 | --ix; | |
12338 | } | |
12339 | } | |
348d480f PA |
12340 | } |
12341 | ||
12342 | static void | |
44702360 | 12343 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12344 | { |
348d480f | 12345 | |
a70b8144 | 12346 | try |
492d29ea PA |
12347 | { |
12348 | update_global_location_list (insert_mode); | |
12349 | } | |
230d2906 | 12350 | catch (const gdb_exception_error &e) |
492d29ea PA |
12351 | { |
12352 | } | |
348d480f PA |
12353 | } |
12354 | ||
12355 | /* Clear BKP from a BPS. */ | |
12356 | ||
12357 | static void | |
12358 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12359 | { | |
12360 | bpstat bs; | |
12361 | ||
12362 | for (bs = bps; bs; bs = bs->next) | |
12363 | if (bs->breakpoint_at == bpt) | |
12364 | { | |
12365 | bs->breakpoint_at = NULL; | |
12366 | bs->old_val = NULL; | |
12367 | /* bs->commands will be freed later. */ | |
12368 | } | |
12369 | } | |
12370 | ||
12371 | /* Callback for iterate_over_threads. */ | |
12372 | static int | |
12373 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12374 | { | |
9a3c8263 | 12375 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12376 | |
12377 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12378 | return 0; | |
12379 | } | |
12380 | ||
12381 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12382 | callbacks. */ | |
12383 | ||
12384 | static void | |
12385 | say_where (struct breakpoint *b) | |
12386 | { | |
12387 | struct value_print_options opts; | |
12388 | ||
12389 | get_user_print_options (&opts); | |
12390 | ||
12391 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12392 | single string. */ | |
12393 | if (b->loc == NULL) | |
12394 | { | |
f00aae0f KS |
12395 | /* For pending locations, the output differs slightly based |
12396 | on b->extra_string. If this is non-NULL, it contains either | |
12397 | a condition or dprintf arguments. */ | |
12398 | if (b->extra_string == NULL) | |
12399 | { | |
12400 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12401 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12402 | } |
12403 | else if (b->type == bp_dprintf) | |
12404 | { | |
12405 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12406 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12407 | b->extra_string); |
12408 | } | |
12409 | else | |
12410 | { | |
12411 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12412 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12413 | b->extra_string); |
12414 | } | |
348d480f PA |
12415 | } |
12416 | else | |
12417 | { | |
2f202fde | 12418 | if (opts.addressprint || b->loc->symtab == NULL) |
6a831f06 PA |
12419 | printf_filtered (" at %ps", |
12420 | styled_string (address_style.style (), | |
12421 | paddress (b->loc->gdbarch, | |
12422 | b->loc->address))); | |
2f202fde | 12423 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12424 | { |
12425 | /* If there is a single location, we can print the location | |
12426 | more nicely. */ | |
12427 | if (b->loc->next == NULL) | |
0bb296cb | 12428 | { |
6a831f06 PA |
12429 | const char *filename |
12430 | = symtab_to_filename_for_display (b->loc->symtab); | |
12431 | printf_filtered (": file %ps, line %d.", | |
12432 | styled_string (file_name_style.style (), | |
12433 | filename), | |
0bb296cb TT |
12434 | b->loc->line_number); |
12435 | } | |
f8eba3c6 TT |
12436 | else |
12437 | /* This is not ideal, but each location may have a | |
12438 | different file name, and this at least reflects the | |
12439 | real situation somewhat. */ | |
f00aae0f | 12440 | printf_filtered (": %s.", |
d28cd78a | 12441 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12442 | } |
348d480f PA |
12443 | |
12444 | if (b->loc->next) | |
12445 | { | |
12446 | struct bp_location *loc = b->loc; | |
12447 | int n = 0; | |
12448 | for (; loc; loc = loc->next) | |
12449 | ++n; | |
12450 | printf_filtered (" (%d locations)", n); | |
12451 | } | |
12452 | } | |
12453 | } | |
12454 | ||
5f486660 | 12455 | bp_location::~bp_location () |
348d480f | 12456 | { |
5f486660 | 12457 | xfree (function_name); |
348d480f PA |
12458 | } |
12459 | ||
c1fc2657 | 12460 | /* Destructor for the breakpoint base class. */ |
348d480f | 12461 | |
c1fc2657 | 12462 | breakpoint::~breakpoint () |
348d480f | 12463 | { |
c1fc2657 SM |
12464 | xfree (this->cond_string); |
12465 | xfree (this->extra_string); | |
348d480f PA |
12466 | } |
12467 | ||
2060206e PA |
12468 | static struct bp_location * |
12469 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12470 | { |
5f486660 | 12471 | return new bp_location (self); |
348d480f PA |
12472 | } |
12473 | ||
2060206e PA |
12474 | static void |
12475 | base_breakpoint_re_set (struct breakpoint *b) | |
12476 | { | |
12477 | /* Nothing to re-set. */ | |
12478 | } | |
12479 | ||
12480 | #define internal_error_pure_virtual_called() \ | |
12481 | gdb_assert_not_reached ("pure virtual function called") | |
12482 | ||
12483 | static int | |
12484 | base_breakpoint_insert_location (struct bp_location *bl) | |
12485 | { | |
12486 | internal_error_pure_virtual_called (); | |
12487 | } | |
12488 | ||
12489 | static int | |
73971819 PA |
12490 | base_breakpoint_remove_location (struct bp_location *bl, |
12491 | enum remove_bp_reason reason) | |
2060206e PA |
12492 | { |
12493 | internal_error_pure_virtual_called (); | |
12494 | } | |
12495 | ||
12496 | static int | |
12497 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12498 | const address_space *aspace, |
09ac7c10 TT |
12499 | CORE_ADDR bp_addr, |
12500 | const struct target_waitstatus *ws) | |
2060206e PA |
12501 | { |
12502 | internal_error_pure_virtual_called (); | |
12503 | } | |
12504 | ||
12505 | static void | |
12506 | base_breakpoint_check_status (bpstat bs) | |
12507 | { | |
12508 | /* Always stop. */ | |
12509 | } | |
12510 | ||
12511 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12512 | errors. */ | |
12513 | ||
12514 | static int | |
12515 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12516 | { | |
12517 | internal_error_pure_virtual_called (); | |
12518 | } | |
12519 | ||
12520 | /* A "resources_needed" breakpoint_ops method that just internal | |
12521 | errors. */ | |
12522 | ||
12523 | static int | |
12524 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12525 | { | |
12526 | internal_error_pure_virtual_called (); | |
12527 | } | |
12528 | ||
12529 | static enum print_stop_action | |
12530 | base_breakpoint_print_it (bpstat bs) | |
12531 | { | |
12532 | internal_error_pure_virtual_called (); | |
12533 | } | |
12534 | ||
12535 | static void | |
12536 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12537 | struct ui_out *uiout) | |
12538 | { | |
12539 | /* nothing */ | |
12540 | } | |
12541 | ||
12542 | static void | |
12543 | base_breakpoint_print_mention (struct breakpoint *b) | |
12544 | { | |
12545 | internal_error_pure_virtual_called (); | |
12546 | } | |
12547 | ||
12548 | static void | |
12549 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12550 | { | |
12551 | internal_error_pure_virtual_called (); | |
12552 | } | |
12553 | ||
983af33b | 12554 | static void |
f00aae0f | 12555 | base_breakpoint_create_sals_from_location |
626d2320 | 12556 | (struct event_location *location, |
f00aae0f KS |
12557 | struct linespec_result *canonical, |
12558 | enum bptype type_wanted) | |
983af33b SDJ |
12559 | { |
12560 | internal_error_pure_virtual_called (); | |
12561 | } | |
12562 | ||
12563 | static void | |
12564 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12565 | struct linespec_result *c, | |
e1e01040 PA |
12566 | gdb::unique_xmalloc_ptr<char> cond_string, |
12567 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12568 | enum bptype type_wanted, |
12569 | enum bpdisp disposition, | |
12570 | int thread, | |
12571 | int task, int ignore_count, | |
12572 | const struct breakpoint_ops *o, | |
12573 | int from_tty, int enabled, | |
44f238bb | 12574 | int internal, unsigned flags) |
983af33b SDJ |
12575 | { |
12576 | internal_error_pure_virtual_called (); | |
12577 | } | |
12578 | ||
6c5b2ebe | 12579 | static std::vector<symtab_and_line> |
f00aae0f | 12580 | base_breakpoint_decode_location (struct breakpoint *b, |
626d2320 | 12581 | struct event_location *location, |
6c5b2ebe | 12582 | struct program_space *search_pspace) |
983af33b SDJ |
12583 | { |
12584 | internal_error_pure_virtual_called (); | |
12585 | } | |
12586 | ||
ab04a2af TT |
12587 | /* The default 'explains_signal' method. */ |
12588 | ||
47591c29 | 12589 | static int |
427cd150 | 12590 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12591 | { |
47591c29 | 12592 | return 1; |
ab04a2af TT |
12593 | } |
12594 | ||
9d6e6e84 HZ |
12595 | /* The default "after_condition_true" method. */ |
12596 | ||
12597 | static void | |
12598 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12599 | { | |
12600 | /* Nothing to do. */ | |
12601 | } | |
12602 | ||
ab04a2af | 12603 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12604 | { |
2060206e PA |
12605 | base_breakpoint_allocate_location, |
12606 | base_breakpoint_re_set, | |
12607 | base_breakpoint_insert_location, | |
12608 | base_breakpoint_remove_location, | |
12609 | base_breakpoint_breakpoint_hit, | |
12610 | base_breakpoint_check_status, | |
12611 | base_breakpoint_resources_needed, | |
12612 | base_breakpoint_works_in_software_mode, | |
12613 | base_breakpoint_print_it, | |
12614 | NULL, | |
12615 | base_breakpoint_print_one_detail, | |
12616 | base_breakpoint_print_mention, | |
983af33b | 12617 | base_breakpoint_print_recreate, |
5f700d83 | 12618 | base_breakpoint_create_sals_from_location, |
983af33b | 12619 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12620 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12621 | base_breakpoint_explains_signal, |
12622 | base_breakpoint_after_condition_true, | |
2060206e PA |
12623 | }; |
12624 | ||
12625 | /* Default breakpoint_ops methods. */ | |
12626 | ||
12627 | static void | |
348d480f PA |
12628 | bkpt_re_set (struct breakpoint *b) |
12629 | { | |
06edf0c0 | 12630 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12631 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12632 | { |
f00aae0f | 12633 | /* Anything without a location can't be re-set. */ |
348d480f | 12634 | delete_breakpoint (b); |
06edf0c0 | 12635 | return; |
348d480f | 12636 | } |
06edf0c0 PA |
12637 | |
12638 | breakpoint_re_set_default (b); | |
348d480f PA |
12639 | } |
12640 | ||
2060206e | 12641 | static int |
348d480f PA |
12642 | bkpt_insert_location (struct bp_location *bl) |
12643 | { | |
cd6c3b4f YQ |
12644 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12645 | ||
579c6ad9 | 12646 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12647 | bl->target_info.placed_address = addr; |
12648 | ||
348d480f | 12649 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12650 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12651 | else |
7c16b83e | 12652 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12653 | } |
12654 | ||
2060206e | 12655 | static int |
73971819 | 12656 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12657 | { |
12658 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12659 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12660 | else | |
73971819 | 12661 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12662 | } |
12663 | ||
2060206e | 12664 | static int |
348d480f | 12665 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 12666 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12667 | const struct target_waitstatus *ws) |
348d480f | 12668 | { |
09ac7c10 | 12669 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12670 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12671 | return 0; |
12672 | ||
348d480f PA |
12673 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12674 | aspace, bp_addr)) | |
12675 | return 0; | |
12676 | ||
12677 | if (overlay_debugging /* unmapped overlay section */ | |
12678 | && section_is_overlay (bl->section) | |
12679 | && !section_is_mapped (bl->section)) | |
12680 | return 0; | |
12681 | ||
12682 | return 1; | |
12683 | } | |
12684 | ||
cd1608cc PA |
12685 | static int |
12686 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12687 | const address_space *aspace, CORE_ADDR bp_addr, |
cd1608cc PA |
12688 | const struct target_waitstatus *ws) |
12689 | { | |
12690 | if (dprintf_style == dprintf_style_agent | |
12691 | && target_can_run_breakpoint_commands ()) | |
12692 | { | |
12693 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12694 | for this address it must be for a breakpoint that happens to | |
12695 | be set at the same address. */ | |
12696 | return 0; | |
12697 | } | |
12698 | ||
12699 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12700 | } | |
12701 | ||
2060206e | 12702 | static int |
348d480f PA |
12703 | bkpt_resources_needed (const struct bp_location *bl) |
12704 | { | |
12705 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12706 | ||
12707 | return 1; | |
12708 | } | |
12709 | ||
2060206e | 12710 | static enum print_stop_action |
348d480f PA |
12711 | bkpt_print_it (bpstat bs) |
12712 | { | |
348d480f PA |
12713 | struct breakpoint *b; |
12714 | const struct bp_location *bl; | |
001c8c33 | 12715 | int bp_temp; |
79a45e25 | 12716 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12717 | |
12718 | gdb_assert (bs->bp_location_at != NULL); | |
12719 | ||
b6433ede | 12720 | bl = bs->bp_location_at.get (); |
348d480f PA |
12721 | b = bs->breakpoint_at; |
12722 | ||
001c8c33 PA |
12723 | bp_temp = b->disposition == disp_del; |
12724 | if (bl->address != bl->requested_address) | |
12725 | breakpoint_adjustment_warning (bl->requested_address, | |
12726 | bl->address, | |
12727 | b->number, 1); | |
12728 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12729 | maybe_print_thread_hit_breakpoint (uiout); |
12730 | ||
112e8700 | 12731 | if (uiout->is_mi_like_p ()) |
348d480f | 12732 | { |
112e8700 | 12733 | uiout->field_string ("reason", |
001c8c33 | 12734 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12735 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12736 | } |
6a831f06 PA |
12737 | if (bp_temp) |
12738 | uiout->message ("Temporary breakpoint %pF, ", | |
12739 | signed_field ("bkptno", b->number)); | |
12740 | else | |
12741 | uiout->message ("Breakpoint %pF, ", | |
12742 | signed_field ("bkptno", b->number)); | |
06edf0c0 | 12743 | |
001c8c33 | 12744 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12745 | } |
12746 | ||
2060206e | 12747 | static void |
06edf0c0 PA |
12748 | bkpt_print_mention (struct breakpoint *b) |
12749 | { | |
112e8700 | 12750 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12751 | return; |
12752 | ||
12753 | switch (b->type) | |
12754 | { | |
12755 | case bp_breakpoint: | |
12756 | case bp_gnu_ifunc_resolver: | |
12757 | if (b->disposition == disp_del) | |
12758 | printf_filtered (_("Temporary breakpoint")); | |
12759 | else | |
12760 | printf_filtered (_("Breakpoint")); | |
12761 | printf_filtered (_(" %d"), b->number); | |
12762 | if (b->type == bp_gnu_ifunc_resolver) | |
12763 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12764 | break; | |
12765 | case bp_hardware_breakpoint: | |
12766 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12767 | break; | |
e7e0cddf SS |
12768 | case bp_dprintf: |
12769 | printf_filtered (_("Dprintf %d"), b->number); | |
12770 | break; | |
06edf0c0 PA |
12771 | } |
12772 | ||
12773 | say_where (b); | |
12774 | } | |
12775 | ||
2060206e | 12776 | static void |
06edf0c0 PA |
12777 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12778 | { | |
12779 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12780 | fprintf_unfiltered (fp, "tbreak"); | |
12781 | else if (tp->type == bp_breakpoint) | |
12782 | fprintf_unfiltered (fp, "break"); | |
12783 | else if (tp->type == bp_hardware_breakpoint | |
12784 | && tp->disposition == disp_del) | |
12785 | fprintf_unfiltered (fp, "thbreak"); | |
12786 | else if (tp->type == bp_hardware_breakpoint) | |
12787 | fprintf_unfiltered (fp, "hbreak"); | |
12788 | else | |
12789 | internal_error (__FILE__, __LINE__, | |
12790 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12791 | ||
f00aae0f | 12792 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12793 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12794 | |
12795 | /* Print out extra_string if this breakpoint is pending. It might | |
12796 | contain, for example, conditions that were set by the user. */ | |
12797 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12798 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12799 | ||
dd11a36c | 12800 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12801 | } |
12802 | ||
983af33b | 12803 | static void |
626d2320 | 12804 | bkpt_create_sals_from_location (struct event_location *location, |
f00aae0f KS |
12805 | struct linespec_result *canonical, |
12806 | enum bptype type_wanted) | |
983af33b | 12807 | { |
f00aae0f | 12808 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12809 | } |
12810 | ||
12811 | static void | |
12812 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12813 | struct linespec_result *canonical, | |
e1e01040 PA |
12814 | gdb::unique_xmalloc_ptr<char> cond_string, |
12815 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12816 | enum bptype type_wanted, |
12817 | enum bpdisp disposition, | |
12818 | int thread, | |
12819 | int task, int ignore_count, | |
12820 | const struct breakpoint_ops *ops, | |
12821 | int from_tty, int enabled, | |
44f238bb | 12822 | int internal, unsigned flags) |
983af33b | 12823 | { |
023fa29b | 12824 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12825 | std::move (cond_string), |
12826 | std::move (extra_string), | |
e7e0cddf | 12827 | type_wanted, |
983af33b SDJ |
12828 | disposition, thread, task, |
12829 | ignore_count, ops, from_tty, | |
44f238bb | 12830 | enabled, internal, flags); |
983af33b SDJ |
12831 | } |
12832 | ||
6c5b2ebe | 12833 | static std::vector<symtab_and_line> |
f00aae0f | 12834 | bkpt_decode_location (struct breakpoint *b, |
626d2320 | 12835 | struct event_location *location, |
6c5b2ebe | 12836 | struct program_space *search_pspace) |
983af33b | 12837 | { |
6c5b2ebe | 12838 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12839 | } |
12840 | ||
06edf0c0 PA |
12841 | /* Virtual table for internal breakpoints. */ |
12842 | ||
12843 | static void | |
12844 | internal_bkpt_re_set (struct breakpoint *b) | |
12845 | { | |
12846 | switch (b->type) | |
12847 | { | |
12848 | /* Delete overlay event and longjmp master breakpoints; they | |
12849 | will be reset later by breakpoint_re_set. */ | |
12850 | case bp_overlay_event: | |
12851 | case bp_longjmp_master: | |
12852 | case bp_std_terminate_master: | |
12853 | case bp_exception_master: | |
12854 | delete_breakpoint (b); | |
12855 | break; | |
12856 | ||
12857 | /* This breakpoint is special, it's set up when the inferior | |
dda83cd7 | 12858 | starts and we really don't want to touch it. */ |
06edf0c0 PA |
12859 | case bp_shlib_event: |
12860 | ||
12861 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12862 | it is set up, we do not want to touch it. */ | |
12863 | case bp_thread_event: | |
12864 | break; | |
12865 | } | |
12866 | } | |
12867 | ||
12868 | static void | |
12869 | internal_bkpt_check_status (bpstat bs) | |
12870 | { | |
a9b3a50f PA |
12871 | if (bs->breakpoint_at->type == bp_shlib_event) |
12872 | { | |
12873 | /* If requested, stop when the dynamic linker notifies GDB of | |
12874 | events. This allows the user to get control and place | |
12875 | breakpoints in initializer routines for dynamically loaded | |
12876 | objects (among other things). */ | |
12877 | bs->stop = stop_on_solib_events; | |
12878 | bs->print = stop_on_solib_events; | |
12879 | } | |
12880 | else | |
12881 | bs->stop = 0; | |
06edf0c0 PA |
12882 | } |
12883 | ||
12884 | static enum print_stop_action | |
12885 | internal_bkpt_print_it (bpstat bs) | |
12886 | { | |
06edf0c0 | 12887 | struct breakpoint *b; |
06edf0c0 | 12888 | |
06edf0c0 PA |
12889 | b = bs->breakpoint_at; |
12890 | ||
06edf0c0 PA |
12891 | switch (b->type) |
12892 | { | |
348d480f PA |
12893 | case bp_shlib_event: |
12894 | /* Did we stop because the user set the stop_on_solib_events | |
12895 | variable? (If so, we report this as a generic, "Stopped due | |
12896 | to shlib event" message.) */ | |
edcc5120 | 12897 | print_solib_event (0); |
348d480f PA |
12898 | break; |
12899 | ||
12900 | case bp_thread_event: | |
12901 | /* Not sure how we will get here. | |
12902 | GDB should not stop for these breakpoints. */ | |
12903 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12904 | break; |
12905 | ||
12906 | case bp_overlay_event: | |
12907 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12908 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12909 | break; |
12910 | ||
12911 | case bp_longjmp_master: | |
12912 | /* These should never be enabled. */ | |
12913 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12914 | break; |
12915 | ||
12916 | case bp_std_terminate_master: | |
12917 | /* These should never be enabled. */ | |
12918 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12919 | "gdb should not stop!\n")); | |
348d480f PA |
12920 | break; |
12921 | ||
12922 | case bp_exception_master: | |
12923 | /* These should never be enabled. */ | |
12924 | printf_filtered (_("Exception Master Breakpoint: " | |
12925 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12926 | break; |
12927 | } | |
12928 | ||
001c8c33 | 12929 | return PRINT_NOTHING; |
06edf0c0 PA |
12930 | } |
12931 | ||
12932 | static void | |
12933 | internal_bkpt_print_mention (struct breakpoint *b) | |
12934 | { | |
12935 | /* Nothing to mention. These breakpoints are internal. */ | |
12936 | } | |
12937 | ||
06edf0c0 PA |
12938 | /* Virtual table for momentary breakpoints */ |
12939 | ||
12940 | static void | |
12941 | momentary_bkpt_re_set (struct breakpoint *b) | |
12942 | { | |
12943 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12944 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12945 | Otherwise these should have been blown away via the cleanup chain |
12946 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12947 | } | |
12948 | ||
12949 | static void | |
12950 | momentary_bkpt_check_status (bpstat bs) | |
12951 | { | |
12952 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12953 | } | |
12954 | ||
12955 | static enum print_stop_action | |
12956 | momentary_bkpt_print_it (bpstat bs) | |
12957 | { | |
001c8c33 | 12958 | return PRINT_UNKNOWN; |
348d480f PA |
12959 | } |
12960 | ||
06edf0c0 PA |
12961 | static void |
12962 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12963 | { |
06edf0c0 | 12964 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12965 | } |
12966 | ||
e2e4d78b JK |
12967 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12968 | ||
12969 | It gets cleared already on the removal of the first one of such placed | |
12970 | breakpoints. This is OK as they get all removed altogether. */ | |
12971 | ||
c1fc2657 | 12972 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12973 | { |
c1fc2657 | 12974 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12975 | |
c1fc2657 | 12976 | if (tp != NULL) |
e2e4d78b | 12977 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12978 | } |
12979 | ||
55aa24fb SDJ |
12980 | /* Specific methods for probe breakpoints. */ |
12981 | ||
12982 | static int | |
12983 | bkpt_probe_insert_location (struct bp_location *bl) | |
12984 | { | |
12985 | int v = bkpt_insert_location (bl); | |
12986 | ||
12987 | if (v == 0) | |
12988 | { | |
12989 | /* The insertion was successful, now let's set the probe's semaphore | |
12990 | if needed. */ | |
935676c9 | 12991 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12992 | } |
12993 | ||
12994 | return v; | |
12995 | } | |
12996 | ||
12997 | static int | |
73971819 PA |
12998 | bkpt_probe_remove_location (struct bp_location *bl, |
12999 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13000 | { |
13001 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 13002 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 13003 | |
73971819 | 13004 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13005 | } |
13006 | ||
13007 | static void | |
626d2320 | 13008 | bkpt_probe_create_sals_from_location (struct event_location *location, |
5f700d83 | 13009 | struct linespec_result *canonical, |
f00aae0f | 13010 | enum bptype type_wanted) |
55aa24fb SDJ |
13011 | { |
13012 | struct linespec_sals lsal; | |
13013 | ||
c2f4122d | 13014 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
13015 | lsal.canonical |
13016 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13017 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
13018 | } |
13019 | ||
6c5b2ebe | 13020 | static std::vector<symtab_and_line> |
f00aae0f | 13021 | bkpt_probe_decode_location (struct breakpoint *b, |
626d2320 | 13022 | struct event_location *location, |
6c5b2ebe | 13023 | struct program_space *search_pspace) |
55aa24fb | 13024 | { |
6c5b2ebe PA |
13025 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
13026 | if (sals.empty ()) | |
55aa24fb | 13027 | error (_("probe not found")); |
6c5b2ebe | 13028 | return sals; |
55aa24fb SDJ |
13029 | } |
13030 | ||
348d480f | 13031 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13032 | |
348d480f PA |
13033 | static void |
13034 | tracepoint_re_set (struct breakpoint *b) | |
13035 | { | |
13036 | breakpoint_re_set_default (b); | |
13037 | } | |
876fa593 | 13038 | |
348d480f PA |
13039 | static int |
13040 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 13041 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 13042 | const struct target_waitstatus *ws) |
348d480f PA |
13043 | { |
13044 | /* By definition, the inferior does not report stops at | |
13045 | tracepoints. */ | |
13046 | return 0; | |
74960c60 VP |
13047 | } |
13048 | ||
13049 | static void | |
348d480f PA |
13050 | tracepoint_print_one_detail (const struct breakpoint *self, |
13051 | struct ui_out *uiout) | |
74960c60 | 13052 | { |
d9b3f62e | 13053 | struct tracepoint *tp = (struct tracepoint *) self; |
5d9310c4 | 13054 | if (!tp->static_trace_marker_id.empty ()) |
348d480f PA |
13055 | { |
13056 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13057 | |
6a831f06 PA |
13058 | uiout->message ("\tmarker id is %pF\n", |
13059 | string_field ("static-tracepoint-marker-string-id", | |
13060 | tp->static_trace_marker_id.c_str ())); | |
348d480f | 13061 | } |
0d381245 VP |
13062 | } |
13063 | ||
a474d7c2 | 13064 | static void |
348d480f | 13065 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13066 | { |
112e8700 | 13067 | if (current_uiout->is_mi_like_p ()) |
348d480f | 13068 | return; |
cc59ec59 | 13069 | |
348d480f PA |
13070 | switch (b->type) |
13071 | { | |
13072 | case bp_tracepoint: | |
13073 | printf_filtered (_("Tracepoint")); | |
13074 | printf_filtered (_(" %d"), b->number); | |
13075 | break; | |
13076 | case bp_fast_tracepoint: | |
13077 | printf_filtered (_("Fast tracepoint")); | |
13078 | printf_filtered (_(" %d"), b->number); | |
13079 | break; | |
13080 | case bp_static_tracepoint: | |
13081 | printf_filtered (_("Static tracepoint")); | |
13082 | printf_filtered (_(" %d"), b->number); | |
13083 | break; | |
13084 | default: | |
13085 | internal_error (__FILE__, __LINE__, | |
13086 | _("unhandled tracepoint type %d"), (int) b->type); | |
13087 | } | |
13088 | ||
13089 | say_where (b); | |
a474d7c2 PA |
13090 | } |
13091 | ||
348d480f | 13092 | static void |
d9b3f62e | 13093 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13094 | { |
d9b3f62e PA |
13095 | struct tracepoint *tp = (struct tracepoint *) self; |
13096 | ||
13097 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13098 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13099 | else if (self->type == bp_static_tracepoint) |
348d480f | 13100 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13101 | else if (self->type == bp_tracepoint) |
348d480f PA |
13102 | fprintf_unfiltered (fp, "trace"); |
13103 | else | |
13104 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13105 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13106 | |
f00aae0f | 13107 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13108 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
13109 | print_recreate_thread (self, fp); |
13110 | ||
13111 | if (tp->pass_count) | |
13112 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13113 | } |
13114 | ||
983af33b | 13115 | static void |
626d2320 | 13116 | tracepoint_create_sals_from_location (struct event_location *location, |
f00aae0f KS |
13117 | struct linespec_result *canonical, |
13118 | enum bptype type_wanted) | |
983af33b | 13119 | { |
f00aae0f | 13120 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13121 | } |
13122 | ||
13123 | static void | |
13124 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13125 | struct linespec_result *canonical, | |
e1e01040 PA |
13126 | gdb::unique_xmalloc_ptr<char> cond_string, |
13127 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13128 | enum bptype type_wanted, |
13129 | enum bpdisp disposition, | |
13130 | int thread, | |
13131 | int task, int ignore_count, | |
13132 | const struct breakpoint_ops *ops, | |
13133 | int from_tty, int enabled, | |
44f238bb | 13134 | int internal, unsigned flags) |
983af33b | 13135 | { |
023fa29b | 13136 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13137 | std::move (cond_string), |
13138 | std::move (extra_string), | |
e7e0cddf | 13139 | type_wanted, |
983af33b SDJ |
13140 | disposition, thread, task, |
13141 | ignore_count, ops, from_tty, | |
44f238bb | 13142 | enabled, internal, flags); |
983af33b SDJ |
13143 | } |
13144 | ||
6c5b2ebe | 13145 | static std::vector<symtab_and_line> |
f00aae0f | 13146 | tracepoint_decode_location (struct breakpoint *b, |
626d2320 | 13147 | struct event_location *location, |
6c5b2ebe | 13148 | struct program_space *search_pspace) |
983af33b | 13149 | { |
6c5b2ebe | 13150 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13151 | } |
13152 | ||
2060206e | 13153 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13154 | |
bac7c5cf | 13155 | /* Virtual table for tracepoints on static probes. */ |
55aa24fb SDJ |
13156 | |
13157 | static void | |
f00aae0f | 13158 | tracepoint_probe_create_sals_from_location |
626d2320 | 13159 | (struct event_location *location, |
f00aae0f KS |
13160 | struct linespec_result *canonical, |
13161 | enum bptype type_wanted) | |
55aa24fb SDJ |
13162 | { |
13163 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13164 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13165 | } |
13166 | ||
6c5b2ebe | 13167 | static std::vector<symtab_and_line> |
f00aae0f | 13168 | tracepoint_probe_decode_location (struct breakpoint *b, |
626d2320 | 13169 | struct event_location *location, |
6c5b2ebe | 13170 | struct program_space *search_pspace) |
55aa24fb SDJ |
13171 | { |
13172 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 13173 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
13174 | } |
13175 | ||
5c2b4418 HZ |
13176 | /* Dprintf breakpoint_ops methods. */ |
13177 | ||
13178 | static void | |
13179 | dprintf_re_set (struct breakpoint *b) | |
13180 | { | |
13181 | breakpoint_re_set_default (b); | |
13182 | ||
f00aae0f KS |
13183 | /* extra_string should never be non-NULL for dprintf. */ |
13184 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13185 | |
13186 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13187 | 2 - create a dprintf, which resolves fine. | |
13188 | 3 - disconnect from target 1 | |
13189 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13190 | ||
13191 | After steps #3/#4, you'll want the dprintf command list to | |
13192 | be updated, because target 1 and 2 may well return different | |
13193 | answers for target_can_run_breakpoint_commands(). | |
13194 | Given absence of finer grained resetting, we get to do | |
13195 | it all the time. */ | |
13196 | if (b->extra_string != NULL) | |
13197 | update_dprintf_command_list (b); | |
13198 | } | |
13199 | ||
2d9442cc HZ |
13200 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13201 | ||
13202 | static void | |
13203 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13204 | { | |
f00aae0f | 13205 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13206 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13207 | tp->extra_string); |
13208 | print_recreate_thread (tp, fp); | |
13209 | } | |
13210 | ||
9d6e6e84 HZ |
13211 | /* Implement the "after_condition_true" breakpoint_ops method for |
13212 | dprintf. | |
13213 | ||
13214 | dprintf's are implemented with regular commands in their command | |
13215 | list, but we run the commands here instead of before presenting the | |
13216 | stop to the user, as dprintf's don't actually cause a stop. This | |
13217 | also makes it so that the commands of multiple dprintfs at the same | |
13218 | address are all handled. */ | |
13219 | ||
13220 | static void | |
13221 | dprintf_after_condition_true (struct bpstats *bs) | |
13222 | { | |
04afa70c | 13223 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
13224 | struct bpstats *tmp_bs_p = &tmp_bs; |
13225 | ||
13226 | /* dprintf's never cause a stop. This wasn't set in the | |
13227 | check_status hook instead because that would make the dprintf's | |
13228 | condition not be evaluated. */ | |
13229 | bs->stop = 0; | |
13230 | ||
13231 | /* Run the command list here. Take ownership of it instead of | |
13232 | copying. We never want these commands to run later in | |
13233 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13234 | be set at same address as this dprintf, or even if running the | |
13235 | commands here throws. */ | |
13236 | tmp_bs.commands = bs->commands; | |
13237 | bs->commands = NULL; | |
9d6e6e84 HZ |
13238 | |
13239 | bpstat_do_actions_1 (&tmp_bs_p); | |
13240 | ||
13241 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13242 | bpstat_do_actions_1 may return early without processing the whole | |
13243 | list. */ | |
9d6e6e84 HZ |
13244 | } |
13245 | ||
983af33b SDJ |
13246 | /* The breakpoint_ops structure to be used on static tracepoints with |
13247 | markers (`-m'). */ | |
13248 | ||
13249 | static void | |
626d2320 | 13250 | strace_marker_create_sals_from_location (struct event_location *location, |
5f700d83 | 13251 | struct linespec_result *canonical, |
f00aae0f | 13252 | enum bptype type_wanted) |
983af33b SDJ |
13253 | { |
13254 | struct linespec_sals lsal; | |
f00aae0f | 13255 | const char *arg_start, *arg; |
983af33b | 13256 | |
a20714ff | 13257 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 13258 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 13259 | |
f2fc3015 TT |
13260 | std::string str (arg_start, arg - arg_start); |
13261 | const char *ptr = str.c_str (); | |
a20714ff PA |
13262 | canonical->location |
13263 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 13264 | |
8e9e35b1 TT |
13265 | lsal.canonical |
13266 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13267 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
13268 | } |
13269 | ||
13270 | static void | |
13271 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13272 | struct linespec_result *canonical, | |
e1e01040 PA |
13273 | gdb::unique_xmalloc_ptr<char> cond_string, |
13274 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13275 | enum bptype type_wanted, |
13276 | enum bpdisp disposition, | |
13277 | int thread, | |
13278 | int task, int ignore_count, | |
13279 | const struct breakpoint_ops *ops, | |
13280 | int from_tty, int enabled, | |
44f238bb | 13281 | int internal, unsigned flags) |
983af33b | 13282 | { |
6c5b2ebe | 13283 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
13284 | |
13285 | /* If the user is creating a static tracepoint by marker id | |
13286 | (strace -m MARKER_ID), then store the sals index, so that | |
13287 | breakpoint_re_set can try to match up which of the newly | |
13288 | found markers corresponds to this one, and, don't try to | |
13289 | expand multiple locations for each sal, given than SALS | |
13290 | already should contain all sals for MARKER_ID. */ | |
13291 | ||
6c5b2ebe | 13292 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 13293 | { |
6c5b2ebe PA |
13294 | event_location_up location |
13295 | = copy_event_location (canonical->location.get ()); | |
983af33b | 13296 | |
b270e6f9 | 13297 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 13298 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 13299 | std::move (location), NULL, |
e1e01040 PA |
13300 | std::move (cond_string), |
13301 | std::move (extra_string), | |
e7e0cddf | 13302 | type_wanted, disposition, |
983af33b | 13303 | thread, task, ignore_count, ops, |
44f238bb | 13304 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13305 | canonical->special_display); |
13306 | /* Given that its possible to have multiple markers with | |
13307 | the same string id, if the user is creating a static | |
13308 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13309 | store the sals index, so that breakpoint_re_set can | |
13310 | try to match up which of the newly found markers | |
13311 | corresponds to this one */ | |
13312 | tp->static_trace_marker_id_idx = i; | |
13313 | ||
b270e6f9 | 13314 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13315 | } |
13316 | } | |
13317 | ||
6c5b2ebe | 13318 | static std::vector<symtab_and_line> |
f00aae0f | 13319 | strace_marker_decode_location (struct breakpoint *b, |
626d2320 | 13320 | struct event_location *location, |
6c5b2ebe | 13321 | struct program_space *search_pspace) |
983af33b SDJ |
13322 | { |
13323 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 13324 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 13325 | |
6c5b2ebe PA |
13326 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13327 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13328 | { |
6c5b2ebe PA |
13329 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13330 | sals.resize (1); | |
13331 | return sals; | |
983af33b SDJ |
13332 | } |
13333 | else | |
5d9310c4 | 13334 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
983af33b SDJ |
13335 | } |
13336 | ||
13337 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13338 | ||
13339 | static int | |
13340 | strace_marker_p (struct breakpoint *b) | |
13341 | { | |
13342 | return b->ops == &strace_marker_breakpoint_ops; | |
13343 | } | |
13344 | ||
53a5351d | 13345 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13346 | structures. */ |
c906108c SS |
13347 | |
13348 | void | |
fba45db2 | 13349 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13350 | { |
52f0bd74 | 13351 | struct breakpoint *b; |
c906108c | 13352 | |
8a3fe4f8 | 13353 | gdb_assert (bpt != NULL); |
c906108c | 13354 | |
4a64f543 MS |
13355 | /* Has this bp already been deleted? This can happen because |
13356 | multiple lists can hold pointers to bp's. bpstat lists are | |
13357 | especial culprits. | |
13358 | ||
13359 | One example of this happening is a watchpoint's scope bp. When | |
13360 | the scope bp triggers, we notice that the watchpoint is out of | |
13361 | scope, and delete it. We also delete its scope bp. But the | |
13362 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13363 | That bpstat is then checked for auto-deleting bp's, which are | |
13364 | deleted. | |
13365 | ||
13366 | A real solution to this problem might involve reference counts in | |
13367 | bp's, and/or giving them pointers back to their referencing | |
13368 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13369 | storage when no more references were extent. A cheaper bandaid | |
13370 | was chosen. */ | |
c906108c SS |
13371 | if (bpt->type == bp_none) |
13372 | return; | |
13373 | ||
4a64f543 MS |
13374 | /* At least avoid this stale reference until the reference counting |
13375 | of breakpoints gets resolved. */ | |
d0fb5eae | 13376 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13377 | { |
d0fb5eae | 13378 | struct breakpoint *related; |
3a5c3e22 | 13379 | struct watchpoint *w; |
d0fb5eae JK |
13380 | |
13381 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13382 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13383 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13384 | w = (struct watchpoint *) bpt; |
13385 | else | |
13386 | w = NULL; | |
13387 | if (w != NULL) | |
13388 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13389 | |
13390 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13391 | for (related = bpt; related->related_breakpoint != bpt; | |
13392 | related = related->related_breakpoint); | |
13393 | related->related_breakpoint = bpt->related_breakpoint; | |
13394 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13395 | } |
13396 | ||
a9634178 TJB |
13397 | /* watch_command_1 creates a watchpoint but only sets its number if |
13398 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13399 | a problem in that process, we'll be asked to delete the half-created | |
13400 | watchpoint. In that case, don't announce the deletion. */ | |
13401 | if (bpt->number) | |
76727919 | 13402 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 13403 | |
c906108c SS |
13404 | if (breakpoint_chain == bpt) |
13405 | breakpoint_chain = bpt->next; | |
13406 | ||
c906108c SS |
13407 | ALL_BREAKPOINTS (b) |
13408 | if (b->next == bpt) | |
c5aa993b JM |
13409 | { |
13410 | b->next = bpt->next; | |
13411 | break; | |
13412 | } | |
c906108c | 13413 | |
f431efe5 PA |
13414 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13415 | been freed. */ | |
13416 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13417 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13418 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13419 | commands are associated with the bpstat; if we remove it here, | |
13420 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13421 | event-top.c won't do anything, and temporary breakpoints with | |
13422 | commands won't work. */ | |
13423 | ||
13424 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13425 | ||
4a64f543 MS |
13426 | /* Now that breakpoint is removed from breakpoint list, update the |
13427 | global location list. This will remove locations that used to | |
13428 | belong to this breakpoint. Do this before freeing the breakpoint | |
13429 | itself, since remove_breakpoint looks at location's owner. It | |
13430 | might be better design to have location completely | |
13431 | self-contained, but it's not the case now. */ | |
44702360 | 13432 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13433 | |
4a64f543 MS |
13434 | /* On the chance that someone will soon try again to delete this |
13435 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13436 | bpt->type = bp_none; |
4d01a485 | 13437 | delete bpt; |
c906108c SS |
13438 | } |
13439 | ||
51be5b68 PA |
13440 | /* Iterator function to call a user-provided callback function once |
13441 | for each of B and its related breakpoints. */ | |
13442 | ||
13443 | static void | |
13444 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13445 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13446 | { |
13447 | struct breakpoint *related; | |
13448 | ||
13449 | related = b; | |
13450 | do | |
13451 | { | |
13452 | struct breakpoint *next; | |
13453 | ||
13454 | /* FUNCTION may delete RELATED. */ | |
13455 | next = related->related_breakpoint; | |
13456 | ||
13457 | if (next == related) | |
13458 | { | |
13459 | /* RELATED is the last ring entry. */ | |
48649e1b | 13460 | function (related); |
51be5b68 PA |
13461 | |
13462 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13463 | B. There's nothing left to do anyway, so just break | |
13464 | out. */ | |
13465 | break; | |
13466 | } | |
13467 | else | |
48649e1b | 13468 | function (related); |
51be5b68 PA |
13469 | |
13470 | related = next; | |
13471 | } | |
13472 | while (related != b); | |
13473 | } | |
95a42b64 | 13474 | |
4495129a | 13475 | static void |
981a3fb3 | 13476 | delete_command (const char *arg, int from_tty) |
c906108c | 13477 | { |
35df4500 | 13478 | struct breakpoint *b, *b_tmp; |
c906108c | 13479 | |
ea9365bb TT |
13480 | dont_repeat (); |
13481 | ||
c906108c SS |
13482 | if (arg == 0) |
13483 | { | |
13484 | int breaks_to_delete = 0; | |
13485 | ||
46c6471b | 13486 | /* Delete all breakpoints if no argument. Do not delete |
dda83cd7 SM |
13487 | internal breakpoints, these have to be deleted with an |
13488 | explicit breakpoint number argument. */ | |
c5aa993b | 13489 | ALL_BREAKPOINTS (b) |
46c6471b | 13490 | if (user_breakpoint_p (b)) |
973d738b DJ |
13491 | { |
13492 | breaks_to_delete = 1; | |
13493 | break; | |
13494 | } | |
c906108c SS |
13495 | |
13496 | /* Ask user only if there are some breakpoints to delete. */ | |
13497 | if (!from_tty | |
e2e0b3e5 | 13498 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13499 | { |
35df4500 | 13500 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13501 | if (user_breakpoint_p (b)) |
c5aa993b | 13502 | delete_breakpoint (b); |
c906108c SS |
13503 | } |
13504 | } | |
13505 | else | |
48649e1b | 13506 | map_breakpoint_numbers |
b926417a | 13507 | (arg, [&] (breakpoint *br) |
48649e1b | 13508 | { |
b926417a | 13509 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 13510 | }); |
c906108c SS |
13511 | } |
13512 | ||
c2f4122d PA |
13513 | /* Return true if all locations of B bound to PSPACE are pending. If |
13514 | PSPACE is NULL, all locations of all program spaces are | |
13515 | considered. */ | |
13516 | ||
0d381245 | 13517 | static int |
c2f4122d | 13518 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13519 | { |
c2f4122d PA |
13520 | struct bp_location *loc; |
13521 | ||
13522 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13523 | if ((pspace == NULL | |
13524 | || loc->pspace == pspace) | |
13525 | && !loc->shlib_disabled | |
8645ff69 | 13526 | && !loc->pspace->executing_startup) |
0d381245 VP |
13527 | return 0; |
13528 | return 1; | |
fe3f5fa8 VP |
13529 | } |
13530 | ||
776592bf DE |
13531 | /* Subroutine of update_breakpoint_locations to simplify it. |
13532 | Return non-zero if multiple fns in list LOC have the same name. | |
13533 | Null names are ignored. */ | |
13534 | ||
13535 | static int | |
13536 | ambiguous_names_p (struct bp_location *loc) | |
13537 | { | |
13538 | struct bp_location *l; | |
c1fb9836 TT |
13539 | htab_up htab (htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
13540 | xcalloc, xfree)); | |
776592bf DE |
13541 | |
13542 | for (l = loc; l != NULL; l = l->next) | |
13543 | { | |
13544 | const char **slot; | |
13545 | const char *name = l->function_name; | |
13546 | ||
13547 | /* Allow for some names to be NULL, ignore them. */ | |
13548 | if (name == NULL) | |
13549 | continue; | |
13550 | ||
c1fb9836 | 13551 | slot = (const char **) htab_find_slot (htab.get (), (const void *) name, |
776592bf | 13552 | INSERT); |
4a64f543 MS |
13553 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13554 | returns NULL. */ | |
776592bf | 13555 | if (*slot != NULL) |
c1fb9836 | 13556 | return 1; |
776592bf DE |
13557 | *slot = name; |
13558 | } | |
13559 | ||
776592bf DE |
13560 | return 0; |
13561 | } | |
13562 | ||
0fb4aa4b PA |
13563 | /* When symbols change, it probably means the sources changed as well, |
13564 | and it might mean the static tracepoint markers are no longer at | |
13565 | the same address or line numbers they used to be at last we | |
13566 | checked. Losing your static tracepoints whenever you rebuild is | |
13567 | undesirable. This function tries to resync/rematch gdb static | |
13568 | tracepoints with the markers on the target, for static tracepoints | |
13569 | that have not been set by marker id. Static tracepoint that have | |
13570 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13571 | The heuristic is: | |
13572 | ||
13573 | 1) For a tracepoint set at a specific address, look for a marker at | |
13574 | the old PC. If one is found there, assume to be the same marker. | |
13575 | If the name / string id of the marker found is different from the | |
13576 | previous known name, assume that means the user renamed the marker | |
13577 | in the sources, and output a warning. | |
13578 | ||
13579 | 2) For a tracepoint set at a given line number, look for a marker | |
13580 | at the new address of the old line number. If one is found there, | |
13581 | assume to be the same marker. If the name / string id of the | |
13582 | marker found is different from the previous known name, assume that | |
13583 | means the user renamed the marker in the sources, and output a | |
13584 | warning. | |
13585 | ||
13586 | 3) If a marker is no longer found at the same address or line, it | |
13587 | may mean the marker no longer exists. But it may also just mean | |
13588 | the code changed a bit. Maybe the user added a few lines of code | |
13589 | that made the marker move up or down (in line number terms). Ask | |
13590 | the target for info about the marker with the string id as we knew | |
13591 | it. If found, update line number and address in the matching | |
13592 | static tracepoint. This will get confused if there's more than one | |
13593 | marker with the same ID (possible in UST, although unadvised | |
13594 | precisely because it confuses tools). */ | |
13595 | ||
13596 | static struct symtab_and_line | |
13597 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13598 | { | |
d9b3f62e | 13599 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13600 | struct static_tracepoint_marker marker; |
13601 | CORE_ADDR pc; | |
0fb4aa4b PA |
13602 | |
13603 | pc = sal.pc; | |
13604 | if (sal.line) | |
13605 | find_line_pc (sal.symtab, sal.line, &pc); | |
13606 | ||
13607 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13608 | { | |
5d9310c4 | 13609 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 13610 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
13611 | b->number, tp->static_trace_marker_id.c_str (), |
13612 | marker.str_id.c_str ()); | |
0fb4aa4b | 13613 | |
5d9310c4 | 13614 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
13615 | |
13616 | return sal; | |
13617 | } | |
13618 | ||
13619 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13620 | by string ID. */ | |
13621 | if (!sal.explicit_pc | |
13622 | && sal.line != 0 | |
13623 | && sal.symtab != NULL | |
5d9310c4 | 13624 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 13625 | { |
5d9310c4 SM |
13626 | std::vector<static_tracepoint_marker> markers |
13627 | = target_static_tracepoint_markers_by_strid | |
13628 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 13629 | |
5d9310c4 | 13630 | if (!markers.empty ()) |
0fb4aa4b | 13631 | { |
0fb4aa4b | 13632 | struct symbol *sym; |
80e1d417 | 13633 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13634 | struct ui_out *uiout = current_uiout; |
67994074 | 13635 | struct explicit_location explicit_loc; |
0fb4aa4b | 13636 | |
5d9310c4 | 13637 | tpmarker = &markers[0]; |
0fb4aa4b | 13638 | |
5d9310c4 | 13639 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
13640 | |
13641 | warning (_("marker for static tracepoint %d (%s) not " | |
13642 | "found at previous line number"), | |
5d9310c4 | 13643 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 13644 | |
51abb421 | 13645 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13646 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13647 | uiout->text ("Now in "); |
0fb4aa4b PA |
13648 | if (sym) |
13649 | { | |
987012b8 | 13650 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 13651 | function_name_style.style ()); |
112e8700 | 13652 | uiout->text (" at "); |
0fb4aa4b | 13653 | } |
112e8700 | 13654 | uiout->field_string ("file", |
cbe56571 | 13655 | symtab_to_filename_for_display (sal2.symtab), |
e43b10e1 | 13656 | file_name_style.style ()); |
112e8700 | 13657 | uiout->text (":"); |
0fb4aa4b | 13658 | |
112e8700 | 13659 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13660 | { |
0b0865da | 13661 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13662 | |
112e8700 | 13663 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13664 | } |
13665 | ||
381befee | 13666 | uiout->field_signed ("line", sal2.line); |
112e8700 | 13667 | uiout->text ("\n"); |
0fb4aa4b | 13668 | |
80e1d417 | 13669 | b->loc->line_number = sal2.line; |
2f202fde | 13670 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13671 | |
d28cd78a | 13672 | b->location.reset (NULL); |
67994074 KS |
13673 | initialize_explicit_location (&explicit_loc); |
13674 | explicit_loc.source_filename | |
00e52e53 | 13675 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13676 | explicit_loc.line_offset.offset = b->loc->line_number; |
13677 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13678 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13679 | |
13680 | /* Might be nice to check if function changed, and warn if | |
13681 | so. */ | |
0fb4aa4b PA |
13682 | } |
13683 | } | |
13684 | return sal; | |
13685 | } | |
13686 | ||
8d3788bd VP |
13687 | /* Returns 1 iff locations A and B are sufficiently same that |
13688 | we don't need to report breakpoint as changed. */ | |
13689 | ||
13690 | static int | |
13691 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13692 | { | |
13693 | while (a && b) | |
13694 | { | |
13695 | if (a->address != b->address) | |
13696 | return 0; | |
13697 | ||
13698 | if (a->shlib_disabled != b->shlib_disabled) | |
13699 | return 0; | |
13700 | ||
13701 | if (a->enabled != b->enabled) | |
13702 | return 0; | |
13703 | ||
b5fa468f TBA |
13704 | if (a->disabled_by_cond != b->disabled_by_cond) |
13705 | return 0; | |
13706 | ||
8d3788bd VP |
13707 | a = a->next; |
13708 | b = b->next; | |
13709 | } | |
13710 | ||
13711 | if ((a == NULL) != (b == NULL)) | |
13712 | return 0; | |
13713 | ||
13714 | return 1; | |
13715 | } | |
13716 | ||
c2f4122d PA |
13717 | /* Split all locations of B that are bound to PSPACE out of B's |
13718 | location list to a separate list and return that list's head. If | |
13719 | PSPACE is NULL, hoist out all locations of B. */ | |
13720 | ||
13721 | static struct bp_location * | |
13722 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13723 | { | |
13724 | struct bp_location head; | |
13725 | struct bp_location *i = b->loc; | |
13726 | struct bp_location **i_link = &b->loc; | |
13727 | struct bp_location *hoisted = &head; | |
13728 | ||
13729 | if (pspace == NULL) | |
13730 | { | |
13731 | i = b->loc; | |
13732 | b->loc = NULL; | |
13733 | return i; | |
13734 | } | |
13735 | ||
13736 | head.next = NULL; | |
13737 | ||
13738 | while (i != NULL) | |
13739 | { | |
13740 | if (i->pspace == pspace) | |
13741 | { | |
13742 | *i_link = i->next; | |
13743 | i->next = NULL; | |
13744 | hoisted->next = i; | |
13745 | hoisted = i; | |
13746 | } | |
13747 | else | |
13748 | i_link = &i->next; | |
13749 | i = *i_link; | |
13750 | } | |
13751 | ||
13752 | return head.next; | |
13753 | } | |
13754 | ||
13755 | /* Create new breakpoint locations for B (a hardware or software | |
13756 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13757 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13758 | FILTER_PSPACE. Locations of other program spaces are left | |
13759 | untouched. */ | |
f1310107 | 13760 | |
0e30163f | 13761 | void |
0d381245 | 13762 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13763 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13764 | gdb::array_view<const symtab_and_line> sals, |
13765 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13766 | { |
c2f4122d | 13767 | struct bp_location *existing_locations; |
0d381245 | 13768 | |
6c5b2ebe | 13769 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13770 | { |
13771 | /* Ranged breakpoints have only one start location and one end | |
13772 | location. */ | |
13773 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13774 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13775 | "multiple locations found\n"), | |
13776 | b->number); | |
13777 | return; | |
13778 | } | |
f1310107 | 13779 | |
4a64f543 MS |
13780 | /* If there's no new locations, and all existing locations are |
13781 | pending, don't do anything. This optimizes the common case where | |
13782 | all locations are in the same shared library, that was unloaded. | |
13783 | We'd like to retain the location, so that when the library is | |
13784 | loaded again, we don't loose the enabled/disabled status of the | |
13785 | individual locations. */ | |
6c5b2ebe | 13786 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13787 | return; |
13788 | ||
c2f4122d | 13789 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13790 | |
6c5b2ebe | 13791 | for (const auto &sal : sals) |
fe3f5fa8 | 13792 | { |
f8eba3c6 TT |
13793 | struct bp_location *new_loc; |
13794 | ||
6c5b2ebe | 13795 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13796 | |
6c5b2ebe | 13797 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13798 | |
0d381245 VP |
13799 | /* Reparse conditions, they might contain references to the |
13800 | old symtab. */ | |
13801 | if (b->cond_string != NULL) | |
13802 | { | |
bbc13ae3 | 13803 | const char *s; |
fe3f5fa8 | 13804 | |
0d381245 | 13805 | s = b->cond_string; |
a70b8144 | 13806 | try |
0d381245 | 13807 | { |
6c5b2ebe PA |
13808 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13809 | block_for_pc (sal.pc), | |
0d381245 VP |
13810 | 0); |
13811 | } | |
230d2906 | 13812 | catch (const gdb_exception_error &e) |
0d381245 | 13813 | { |
b5fa468f | 13814 | new_loc->disabled_by_cond = true; |
0d381245 VP |
13815 | } |
13816 | } | |
fe3f5fa8 | 13817 | |
6c5b2ebe | 13818 | if (!sals_end.empty ()) |
f1310107 | 13819 | { |
6c5b2ebe | 13820 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13821 | |
6c5b2ebe | 13822 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13823 | } |
0d381245 | 13824 | } |
fe3f5fa8 | 13825 | |
4a64f543 MS |
13826 | /* If possible, carry over 'disable' status from existing |
13827 | breakpoints. */ | |
0d381245 VP |
13828 | { |
13829 | struct bp_location *e = existing_locations; | |
776592bf DE |
13830 | /* If there are multiple breakpoints with the same function name, |
13831 | e.g. for inline functions, comparing function names won't work. | |
13832 | Instead compare pc addresses; this is just a heuristic as things | |
13833 | may have moved, but in practice it gives the correct answer | |
13834 | often enough until a better solution is found. */ | |
13835 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13836 | ||
0d381245 VP |
13837 | for (; e; e = e->next) |
13838 | { | |
b5fa468f | 13839 | if ((!e->enabled || e->disabled_by_cond) && e->function_name) |
0d381245 VP |
13840 | { |
13841 | struct bp_location *l = b->loc; | |
776592bf DE |
13842 | if (have_ambiguous_names) |
13843 | { | |
13844 | for (; l; l = l->next) | |
7f32a4d5 PA |
13845 | { |
13846 | /* Ignore software vs hardware location type at | |
13847 | this point, because with "set breakpoint | |
13848 | auto-hw", after a re-set, locations that were | |
13849 | hardware can end up as software, or vice versa. | |
13850 | As mentioned above, this is an heuristic and in | |
13851 | practice should give the correct answer often | |
13852 | enough. */ | |
13853 | if (breakpoint_locations_match (e, l, true)) | |
13854 | { | |
b5fa468f TBA |
13855 | l->enabled = e->enabled; |
13856 | l->disabled_by_cond = e->disabled_by_cond; | |
7f32a4d5 PA |
13857 | break; |
13858 | } | |
13859 | } | |
776592bf DE |
13860 | } |
13861 | else | |
13862 | { | |
13863 | for (; l; l = l->next) | |
13864 | if (l->function_name | |
13865 | && strcmp (e->function_name, l->function_name) == 0) | |
13866 | { | |
b5fa468f TBA |
13867 | l->enabled = e->enabled; |
13868 | l->disabled_by_cond = e->disabled_by_cond; | |
776592bf DE |
13869 | break; |
13870 | } | |
13871 | } | |
0d381245 VP |
13872 | } |
13873 | } | |
13874 | } | |
fe3f5fa8 | 13875 | |
8d3788bd | 13876 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 13877 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
13878 | } |
13879 | ||
f00aae0f | 13880 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13881 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13882 | ||
6c5b2ebe | 13883 | static std::vector<symtab_and_line> |
f00aae0f | 13884 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13885 | struct program_space *search_pspace, int *found) |
ef23e705 | 13886 | { |
cc06b668 | 13887 | struct gdb_exception exception; |
ef23e705 | 13888 | |
983af33b | 13889 | gdb_assert (b->ops != NULL); |
ef23e705 | 13890 | |
6c5b2ebe PA |
13891 | std::vector<symtab_and_line> sals; |
13892 | ||
a70b8144 | 13893 | try |
ef23e705 | 13894 | { |
6c5b2ebe | 13895 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13896 | } |
94aeb44b | 13897 | catch (gdb_exception_error &e) |
ef23e705 TJB |
13898 | { |
13899 | int not_found_and_ok = 0; | |
492d29ea | 13900 | |
ef23e705 TJB |
13901 | /* For pending breakpoints, it's expected that parsing will |
13902 | fail until the right shared library is loaded. User has | |
13903 | already told to create pending breakpoints and don't need | |
13904 | extra messages. If breakpoint is in bp_shlib_disabled | |
13905 | state, then user already saw the message about that | |
13906 | breakpoint being disabled, and don't want to see more | |
13907 | errors. */ | |
58438ac1 | 13908 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13909 | && (b->condition_not_parsed |
13910 | || (b->loc != NULL | |
13911 | && search_pspace != NULL | |
13912 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13913 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13914 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13915 | || b->enable_state == bp_disabled)) |
13916 | not_found_and_ok = 1; | |
13917 | ||
13918 | if (!not_found_and_ok) | |
13919 | { | |
13920 | /* We surely don't want to warn about the same breakpoint | |
13921 | 10 times. One solution, implemented here, is disable | |
13922 | the breakpoint on error. Another solution would be to | |
13923 | have separate 'warning emitted' flag. Since this | |
13924 | happens only when a binary has changed, I don't know | |
13925 | which approach is better. */ | |
13926 | b->enable_state = bp_disabled; | |
eedc3f4f | 13927 | throw; |
ef23e705 | 13928 | } |
94aeb44b TT |
13929 | |
13930 | exception = std::move (e); | |
ef23e705 TJB |
13931 | } |
13932 | ||
492d29ea | 13933 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13934 | { |
6c5b2ebe PA |
13935 | for (auto &sal : sals) |
13936 | resolve_sal_pc (&sal); | |
f00aae0f | 13937 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13938 | { |
ed1d1739 KS |
13939 | char *cond_string, *extra_string; |
13940 | int thread, task; | |
ef23e705 | 13941 | |
b5fa468f TBA |
13942 | find_condition_and_thread_for_sals (sals, b->extra_string, |
13943 | &cond_string, &thread, | |
13944 | &task, &extra_string); | |
f00aae0f | 13945 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13946 | if (cond_string) |
13947 | b->cond_string = cond_string; | |
13948 | b->thread = thread; | |
13949 | b->task = task; | |
e7e0cddf | 13950 | if (extra_string) |
f00aae0f KS |
13951 | { |
13952 | xfree (b->extra_string); | |
13953 | b->extra_string = extra_string; | |
13954 | } | |
ef23e705 TJB |
13955 | b->condition_not_parsed = 0; |
13956 | } | |
13957 | ||
983af33b | 13958 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13959 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13960 | |
58438ac1 TT |
13961 | *found = 1; |
13962 | } | |
13963 | else | |
13964 | *found = 0; | |
ef23e705 TJB |
13965 | |
13966 | return sals; | |
13967 | } | |
13968 | ||
348d480f PA |
13969 | /* The default re_set method, for typical hardware or software |
13970 | breakpoints. Reevaluate the breakpoint and recreate its | |
13971 | locations. */ | |
13972 | ||
13973 | static void | |
28010a5d | 13974 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13975 | { |
c2f4122d | 13976 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13977 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13978 | |
6c5b2ebe PA |
13979 | int found; |
13980 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13981 | filter_pspace, &found); | |
ef23e705 | 13982 | if (found) |
6c5b2ebe | 13983 | expanded = std::move (sals); |
ef23e705 | 13984 | |
f00aae0f | 13985 | if (b->location_range_end != NULL) |
f1310107 | 13986 | { |
6c5b2ebe PA |
13987 | std::vector<symtab_and_line> sals_end |
13988 | = location_to_sals (b, b->location_range_end.get (), | |
13989 | filter_pspace, &found); | |
f1310107 | 13990 | if (found) |
6c5b2ebe | 13991 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13992 | } |
13993 | ||
c2f4122d | 13994 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13995 | } |
13996 | ||
983af33b SDJ |
13997 | /* Default method for creating SALs from an address string. It basically |
13998 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13999 | ||
14000 | static void | |
626d2320 | 14001 | create_sals_from_location_default (struct event_location *location, |
f00aae0f KS |
14002 | struct linespec_result *canonical, |
14003 | enum bptype type_wanted) | |
983af33b | 14004 | { |
f00aae0f | 14005 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14006 | } |
14007 | ||
14008 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14009 | function for the `create_breakpoints_sal' method of | |
14010 | breakpoint_ops. */ | |
14011 | ||
14012 | static void | |
14013 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14014 | struct linespec_result *canonical, | |
e1e01040 PA |
14015 | gdb::unique_xmalloc_ptr<char> cond_string, |
14016 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
14017 | enum bptype type_wanted, |
14018 | enum bpdisp disposition, | |
14019 | int thread, | |
14020 | int task, int ignore_count, | |
14021 | const struct breakpoint_ops *ops, | |
14022 | int from_tty, int enabled, | |
44f238bb | 14023 | int internal, unsigned flags) |
983af33b | 14024 | { |
e1e01040 PA |
14025 | create_breakpoints_sal (gdbarch, canonical, |
14026 | std::move (cond_string), | |
14027 | std::move (extra_string), | |
983af33b SDJ |
14028 | type_wanted, disposition, |
14029 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14030 | enabled, internal, flags); |
983af33b SDJ |
14031 | } |
14032 | ||
14033 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14034 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 14035 | |
6c5b2ebe | 14036 | static std::vector<symtab_and_line> |
f00aae0f | 14037 | decode_location_default (struct breakpoint *b, |
626d2320 | 14038 | struct event_location *location, |
6c5b2ebe | 14039 | struct program_space *search_pspace) |
983af33b SDJ |
14040 | { |
14041 | struct linespec_result canonical; | |
14042 | ||
c2f4122d | 14043 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 14044 | NULL, 0, &canonical, multiple_symbols_all, |
c0e8dcd8 | 14045 | b->filter.get ()); |
983af33b SDJ |
14046 | |
14047 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 14048 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 14049 | |
6c5b2ebe | 14050 | if (!canonical.lsals.empty ()) |
983af33b | 14051 | { |
6c5b2ebe PA |
14052 | const linespec_sals &lsal = canonical.lsals[0]; |
14053 | return std::move (lsal.sals); | |
983af33b | 14054 | } |
6c5b2ebe | 14055 | return {}; |
983af33b SDJ |
14056 | } |
14057 | ||
bf469271 | 14058 | /* Reset a breakpoint. */ |
c906108c | 14059 | |
bf469271 PA |
14060 | static void |
14061 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 14062 | { |
fdf44873 TT |
14063 | input_radix = b->input_radix; |
14064 | set_language (b->language); | |
c906108c | 14065 | |
348d480f | 14066 | b->ops->re_set (b); |
c906108c SS |
14067 | } |
14068 | ||
c2f4122d PA |
14069 | /* Re-set breakpoint locations for the current program space. |
14070 | Locations bound to other program spaces are left untouched. */ | |
14071 | ||
c906108c | 14072 | void |
69de3c6a | 14073 | breakpoint_re_set (void) |
c906108c | 14074 | { |
35df4500 | 14075 | struct breakpoint *b, *b_tmp; |
2a7f3dff | 14076 | |
c5aa993b | 14077 | { |
fdf44873 TT |
14078 | scoped_restore_current_language save_language; |
14079 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 14080 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 14081 | |
8e817061 JB |
14082 | /* breakpoint_re_set_one sets the current_language to the language |
14083 | of the breakpoint it is resetting (see prepare_re_set_context) | |
14084 | before re-evaluating the breakpoint's location. This change can | |
14085 | unfortunately get undone by accident if the language_mode is set | |
14086 | to auto, and we either switch frames, or more likely in this context, | |
14087 | we select the current frame. | |
14088 | ||
14089 | We prevent this by temporarily turning the language_mode to | |
14090 | language_mode_manual. We restore it once all breakpoints | |
14091 | have been reset. */ | |
14092 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
14093 | language_mode = language_mode_manual; | |
14094 | ||
5ed8105e PA |
14095 | /* Note: we must not try to insert locations until after all |
14096 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14097 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14098 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 14099 | |
5ed8105e PA |
14100 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
14101 | { | |
a70b8144 | 14102 | try |
bf469271 PA |
14103 | { |
14104 | breakpoint_re_set_one (b); | |
14105 | } | |
230d2906 | 14106 | catch (const gdb_exception &ex) |
bf469271 PA |
14107 | { |
14108 | exception_fprintf (gdb_stderr, ex, | |
14109 | "Error in re-setting breakpoint %d: ", | |
14110 | b->number); | |
14111 | } | |
5ed8105e | 14112 | } |
5ed8105e PA |
14113 | |
14114 | jit_breakpoint_re_set (); | |
14115 | } | |
6c95b8df | 14116 | |
af02033e PP |
14117 | create_overlay_event_breakpoint (); |
14118 | create_longjmp_master_breakpoint (); | |
14119 | create_std_terminate_master_breakpoint (); | |
186c406b | 14120 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14121 | |
14122 | /* Now we can insert. */ | |
14123 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14124 | } |
14125 | \f | |
c906108c SS |
14126 | /* Reset the thread number of this breakpoint: |
14127 | ||
14128 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14129 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14130 | void |
fba45db2 | 14131 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14132 | { |
14133 | if (b->thread != -1) | |
14134 | { | |
00431a78 | 14135 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
14136 | |
14137 | /* We're being called after following a fork. The new fork is | |
14138 | selected as current, and unless this was a vfork will have a | |
14139 | different program space from the original thread. Reset that | |
14140 | as well. */ | |
14141 | b->loc->pspace = current_program_space; | |
c906108c SS |
14142 | } |
14143 | } | |
14144 | ||
03ac34d5 MS |
14145 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14146 | If from_tty is nonzero, it prints a message to that effect, | |
14147 | which ends with a period (no newline). */ | |
14148 | ||
c906108c | 14149 | void |
fba45db2 | 14150 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14151 | { |
52f0bd74 | 14152 | struct breakpoint *b; |
c906108c SS |
14153 | |
14154 | if (count < 0) | |
14155 | count = 0; | |
14156 | ||
14157 | ALL_BREAKPOINTS (b) | |
14158 | if (b->number == bptnum) | |
c5aa993b | 14159 | { |
d77f58be SS |
14160 | if (is_tracepoint (b)) |
14161 | { | |
14162 | if (from_tty && count != 0) | |
14163 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14164 | bptnum); | |
14165 | return; | |
14166 | } | |
14167 | ||
c5aa993b | 14168 | b->ignore_count = count; |
221ea385 KS |
14169 | if (from_tty) |
14170 | { | |
14171 | if (count == 0) | |
3e43a32a MS |
14172 | printf_filtered (_("Will stop next time " |
14173 | "breakpoint %d is reached."), | |
221ea385 KS |
14174 | bptnum); |
14175 | else if (count == 1) | |
a3f17187 | 14176 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14177 | bptnum); |
14178 | else | |
3e43a32a MS |
14179 | printf_filtered (_("Will ignore next %d " |
14180 | "crossings of breakpoint %d."), | |
221ea385 KS |
14181 | count, bptnum); |
14182 | } | |
76727919 | 14183 | gdb::observers::breakpoint_modified.notify (b); |
c5aa993b JM |
14184 | return; |
14185 | } | |
c906108c | 14186 | |
8a3fe4f8 | 14187 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14188 | } |
14189 | ||
c906108c SS |
14190 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14191 | ||
14192 | static void | |
0b39b52e | 14193 | ignore_command (const char *args, int from_tty) |
c906108c | 14194 | { |
0b39b52e | 14195 | const char *p = args; |
52f0bd74 | 14196 | int num; |
c906108c SS |
14197 | |
14198 | if (p == 0) | |
e2e0b3e5 | 14199 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14200 | |
c906108c | 14201 | num = get_number (&p); |
5c44784c | 14202 | if (num == 0) |
8a3fe4f8 | 14203 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14204 | if (*p == 0) |
8a3fe4f8 | 14205 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14206 | |
14207 | set_ignore_count (num, | |
14208 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14209 | from_tty); | |
221ea385 KS |
14210 | if (from_tty) |
14211 | printf_filtered ("\n"); | |
c906108c SS |
14212 | } |
14213 | \f | |
d0fe4701 XR |
14214 | |
14215 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
14216 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
14217 | |
14218 | static void | |
d0fe4701 XR |
14219 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
14220 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 14221 | { |
d0fe4701 XR |
14222 | if (bp_num_range.first == 0) |
14223 | { | |
14224 | warning (_("bad breakpoint number at or near '%d'"), | |
14225 | bp_num_range.first); | |
14226 | } | |
14227 | else | |
c906108c | 14228 | { |
d0fe4701 | 14229 | struct breakpoint *b, *tmp; |
197f0a60 | 14230 | |
d0fe4701 | 14231 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 14232 | { |
d0fe4701 XR |
14233 | bool match = false; |
14234 | ||
5c44784c | 14235 | ALL_BREAKPOINTS_SAFE (b, tmp) |
d0fe4701 | 14236 | if (b->number == i) |
5c44784c | 14237 | { |
bfd28288 | 14238 | match = true; |
48649e1b | 14239 | function (b); |
11cf8741 | 14240 | break; |
5c44784c | 14241 | } |
bfd28288 | 14242 | if (!match) |
d0fe4701 | 14243 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 14244 | } |
c906108c SS |
14245 | } |
14246 | } | |
14247 | ||
d0fe4701 XR |
14248 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
14249 | ARGS. */ | |
14250 | ||
14251 | static void | |
14252 | map_breakpoint_numbers (const char *args, | |
14253 | gdb::function_view<void (breakpoint *)> function) | |
14254 | { | |
14255 | if (args == NULL || *args == '\0') | |
14256 | error_no_arg (_("one or more breakpoint numbers")); | |
14257 | ||
14258 | number_or_range_parser parser (args); | |
14259 | ||
14260 | while (!parser.finished ()) | |
14261 | { | |
14262 | int num = parser.get_number (); | |
14263 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
14264 | } | |
14265 | } | |
14266 | ||
14267 | /* Return the breakpoint location structure corresponding to the | |
14268 | BP_NUM and LOC_NUM values. */ | |
14269 | ||
0d381245 | 14270 | static struct bp_location * |
d0fe4701 | 14271 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 14272 | { |
0d381245 | 14273 | struct breakpoint *b; |
0d381245 VP |
14274 | |
14275 | ALL_BREAKPOINTS (b) | |
14276 | if (b->number == bp_num) | |
14277 | { | |
14278 | break; | |
14279 | } | |
14280 | ||
14281 | if (!b || b->number != bp_num) | |
d0fe4701 | 14282 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 14283 | |
0d381245 | 14284 | if (loc_num == 0) |
d0fe4701 | 14285 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 14286 | |
d0fe4701 XR |
14287 | int n = 0; |
14288 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
14289 | if (++n == loc_num) | |
14290 | return loc; | |
14291 | ||
14292 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
14293 | } |
14294 | ||
95e95a6d PA |
14295 | /* Modes of operation for extract_bp_num. */ |
14296 | enum class extract_bp_kind | |
14297 | { | |
14298 | /* Extracting a breakpoint number. */ | |
14299 | bp, | |
14300 | ||
14301 | /* Extracting a location number. */ | |
14302 | loc, | |
14303 | }; | |
14304 | ||
14305 | /* Extract a breakpoint or location number (as determined by KIND) | |
14306 | from the string starting at START. TRAILER is a character which | |
14307 | can be found after the number. If you don't want a trailer, use | |
14308 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
14309 | string. This always returns a positive integer. */ | |
14310 | ||
14311 | static int | |
14312 | extract_bp_num (extract_bp_kind kind, const char *start, | |
14313 | int trailer, const char **end_out = NULL) | |
14314 | { | |
14315 | const char *end = start; | |
14316 | int num = get_number_trailer (&end, trailer); | |
14317 | if (num < 0) | |
14318 | error (kind == extract_bp_kind::bp | |
14319 | ? _("Negative breakpoint number '%.*s'") | |
14320 | : _("Negative breakpoint location number '%.*s'"), | |
14321 | int (end - start), start); | |
14322 | if (num == 0) | |
14323 | error (kind == extract_bp_kind::bp | |
14324 | ? _("Bad breakpoint number '%.*s'") | |
14325 | : _("Bad breakpoint location number '%.*s'"), | |
14326 | int (end - start), start); | |
14327 | ||
14328 | if (end_out != NULL) | |
14329 | *end_out = end; | |
14330 | return num; | |
14331 | } | |
14332 | ||
14333 | /* Extract a breakpoint or location range (as determined by KIND) in | |
14334 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
14335 | representing the (inclusive) range. The returned pair's elements | |
14336 | are always positive integers. */ | |
14337 | ||
14338 | static std::pair<int, int> | |
14339 | extract_bp_or_bp_range (extract_bp_kind kind, | |
14340 | const std::string &arg, | |
14341 | std::string::size_type arg_offset) | |
14342 | { | |
14343 | std::pair<int, int> range; | |
14344 | const char *bp_loc = &arg[arg_offset]; | |
14345 | std::string::size_type dash = arg.find ('-', arg_offset); | |
14346 | if (dash != std::string::npos) | |
14347 | { | |
14348 | /* bp_loc is a range (x-z). */ | |
14349 | if (arg.length () == dash + 1) | |
14350 | error (kind == extract_bp_kind::bp | |
14351 | ? _("Bad breakpoint number at or near: '%s'") | |
14352 | : _("Bad breakpoint location number at or near: '%s'"), | |
14353 | bp_loc); | |
14354 | ||
14355 | const char *end; | |
14356 | const char *start_first = bp_loc; | |
14357 | const char *start_second = &arg[dash + 1]; | |
14358 | range.first = extract_bp_num (kind, start_first, '-'); | |
14359 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
14360 | ||
14361 | if (range.first > range.second) | |
14362 | error (kind == extract_bp_kind::bp | |
14363 | ? _("Inverted breakpoint range at '%.*s'") | |
14364 | : _("Inverted breakpoint location range at '%.*s'"), | |
14365 | int (end - start_first), start_first); | |
14366 | } | |
14367 | else | |
14368 | { | |
14369 | /* bp_loc is a single value. */ | |
14370 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
14371 | range.second = range.first; | |
14372 | } | |
14373 | return range; | |
14374 | } | |
14375 | ||
d0fe4701 XR |
14376 | /* Extract the breakpoint/location range specified by ARG. Returns |
14377 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
14378 | BP_LOC_RANGE. | |
14379 | ||
14380 | ARG may be in any of the following forms: | |
14381 | ||
14382 | x where 'x' is a breakpoint number. | |
14383 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
14384 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
14385 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
14386 | location number range. | |
14387 | */ | |
14388 | ||
cc638e86 | 14389 | static void |
d0fe4701 XR |
14390 | extract_bp_number_and_location (const std::string &arg, |
14391 | std::pair<int, int> &bp_num_range, | |
14392 | std::pair<int, int> &bp_loc_range) | |
14393 | { | |
14394 | std::string::size_type dot = arg.find ('.'); | |
14395 | ||
14396 | if (dot != std::string::npos) | |
14397 | { | |
14398 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
14399 | ||
14400 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 14401 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 14402 | |
95e95a6d PA |
14403 | bp_num_range.first |
14404 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
14405 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 14406 | |
95e95a6d PA |
14407 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
14408 | arg, dot + 1); | |
d0fe4701 XR |
14409 | } |
14410 | else | |
14411 | { | |
14412 | /* Handle x and x-y cases. */ | |
d0fe4701 | 14413 | |
95e95a6d | 14414 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
14415 | bp_loc_range.first = 0; |
14416 | bp_loc_range.second = 0; | |
14417 | } | |
d0fe4701 XR |
14418 | } |
14419 | ||
14420 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
14421 | specifies whether to enable or disable. */ | |
14422 | ||
14423 | static void | |
14424 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
14425 | { | |
14426 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
14427 | if (loc != NULL) | |
14428 | { | |
b5fa468f TBA |
14429 | if (loc->disabled_by_cond && enable) |
14430 | error (_("Breakpoint %d's condition is invalid at location %d, " | |
14431 | "cannot enable."), bp_num, loc_num); | |
14432 | ||
d0fe4701 XR |
14433 | if (loc->enabled != enable) |
14434 | { | |
14435 | loc->enabled = enable; | |
14436 | mark_breakpoint_location_modified (loc); | |
14437 | } | |
14438 | if (target_supports_enable_disable_tracepoint () | |
14439 | && current_trace_status ()->running && loc->owner | |
14440 | && is_tracepoint (loc->owner)) | |
14441 | target_disable_tracepoint (loc); | |
14442 | } | |
14443 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
14444 | |
14445 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
14446 | } |
14447 | ||
14448 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
14449 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
14450 | (inclusive) range of location numbers of that breakpoint to | |
14451 | enable/disable. ENABLE specifies whether to enable or disable the | |
14452 | location. */ | |
14453 | ||
14454 | static void | |
14455 | enable_disable_breakpoint_location_range (int bp_num, | |
14456 | std::pair<int, int> &bp_loc_range, | |
14457 | bool enable) | |
14458 | { | |
14459 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
14460 | enable_disable_bp_num_loc (bp_num, i, enable); | |
14461 | } | |
0d381245 | 14462 | |
1900040c MS |
14463 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14464 | If from_tty is nonzero, it prints a message to that effect, | |
14465 | which ends with a period (no newline). */ | |
14466 | ||
c906108c | 14467 | void |
fba45db2 | 14468 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14469 | { |
14470 | /* Never disable a watchpoint scope breakpoint; we want to | |
14471 | hit them when we leave scope so we can delete both the | |
14472 | watchpoint and its scope breakpoint at that time. */ | |
14473 | if (bpt->type == bp_watchpoint_scope) | |
14474 | return; | |
14475 | ||
b5de0fa7 | 14476 | bpt->enable_state = bp_disabled; |
c906108c | 14477 | |
b775012e LM |
14478 | /* Mark breakpoint locations modified. */ |
14479 | mark_breakpoint_modified (bpt); | |
14480 | ||
d248b706 KY |
14481 | if (target_supports_enable_disable_tracepoint () |
14482 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14483 | { | |
14484 | struct bp_location *location; | |
14485 | ||
14486 | for (location = bpt->loc; location; location = location->next) | |
14487 | target_disable_tracepoint (location); | |
14488 | } | |
14489 | ||
44702360 | 14490 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14491 | |
76727919 | 14492 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14493 | } |
14494 | ||
d0fe4701 XR |
14495 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
14496 | specified in ARGS. ARGS may be in any of the formats handled by | |
14497 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
14498 | or disable the breakpoints/locations. */ | |
14499 | ||
c906108c | 14500 | static void |
d0fe4701 | 14501 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 14502 | { |
c906108c | 14503 | if (args == 0) |
46c6471b PA |
14504 | { |
14505 | struct breakpoint *bpt; | |
14506 | ||
14507 | ALL_BREAKPOINTS (bpt) | |
14508 | if (user_breakpoint_p (bpt)) | |
d0fe4701 XR |
14509 | { |
14510 | if (enable) | |
14511 | enable_breakpoint (bpt); | |
14512 | else | |
14513 | disable_breakpoint (bpt); | |
14514 | } | |
46c6471b | 14515 | } |
9eaabc75 | 14516 | else |
0d381245 | 14517 | { |
cb791d59 | 14518 | std::string num = extract_arg (&args); |
9eaabc75 | 14519 | |
cb791d59 | 14520 | while (!num.empty ()) |
d248b706 | 14521 | { |
d0fe4701 | 14522 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 14523 | |
cc638e86 PA |
14524 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
14525 | ||
14526 | if (bp_loc_range.first == bp_loc_range.second | |
14527 | && bp_loc_range.first == 0) | |
d0fe4701 | 14528 | { |
cc638e86 PA |
14529 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
14530 | map_breakpoint_number_range (bp_num_range, | |
14531 | enable | |
14532 | ? enable_breakpoint | |
14533 | : disable_breakpoint); | |
14534 | } | |
14535 | else | |
14536 | { | |
14537 | /* Handle breakpoint ids with formats 'x.y' or | |
14538 | 'x.y-z'. */ | |
14539 | enable_disable_breakpoint_location_range | |
14540 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 14541 | } |
9eaabc75 | 14542 | num = extract_arg (&args); |
d248b706 | 14543 | } |
0d381245 | 14544 | } |
c906108c SS |
14545 | } |
14546 | ||
d0fe4701 XR |
14547 | /* The disable command disables the specified breakpoints/locations |
14548 | (or all defined breakpoints) so they're no longer effective in | |
14549 | stopping the inferior. ARGS may be in any of the forms defined in | |
14550 | extract_bp_number_and_location. */ | |
14551 | ||
14552 | static void | |
14553 | disable_command (const char *args, int from_tty) | |
14554 | { | |
14555 | enable_disable_command (args, from_tty, false); | |
14556 | } | |
14557 | ||
c906108c | 14558 | static void |
816338b5 SS |
14559 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14560 | int count) | |
c906108c | 14561 | { |
afe38095 | 14562 | int target_resources_ok; |
c906108c SS |
14563 | |
14564 | if (bpt->type == bp_hardware_breakpoint) | |
14565 | { | |
14566 | int i; | |
c5aa993b | 14567 | i = hw_breakpoint_used_count (); |
53a5351d | 14568 | target_resources_ok = |
d92524f1 | 14569 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14570 | i + 1, 0); |
c906108c | 14571 | if (target_resources_ok == 0) |
8a3fe4f8 | 14572 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14573 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14574 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14575 | } |
14576 | ||
cc60f2e3 | 14577 | if (is_watchpoint (bpt)) |
c906108c | 14578 | { |
d07205c2 | 14579 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14580 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14581 | |
a70b8144 | 14582 | try |
c906108c | 14583 | { |
3a5c3e22 PA |
14584 | struct watchpoint *w = (struct watchpoint *) bpt; |
14585 | ||
1e718ff1 TJB |
14586 | orig_enable_state = bpt->enable_state; |
14587 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14588 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14589 | } |
230d2906 | 14590 | catch (const gdb_exception &e) |
c5aa993b | 14591 | { |
1e718ff1 | 14592 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14593 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14594 | bpt->number); | |
14595 | return; | |
c5aa993b | 14596 | } |
c906108c | 14597 | } |
0101ce28 | 14598 | |
b775012e LM |
14599 | bpt->enable_state = bp_enabled; |
14600 | ||
14601 | /* Mark breakpoint locations modified. */ | |
14602 | mark_breakpoint_modified (bpt); | |
14603 | ||
d248b706 KY |
14604 | if (target_supports_enable_disable_tracepoint () |
14605 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14606 | { | |
14607 | struct bp_location *location; | |
14608 | ||
14609 | for (location = bpt->loc; location; location = location->next) | |
14610 | target_enable_tracepoint (location); | |
14611 | } | |
14612 | ||
b4c291bb | 14613 | bpt->disposition = disposition; |
816338b5 | 14614 | bpt->enable_count = count; |
44702360 | 14615 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14616 | |
76727919 | 14617 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14618 | } |
14619 | ||
fe3f5fa8 | 14620 | |
c906108c | 14621 | void |
fba45db2 | 14622 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14623 | { |
816338b5 | 14624 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14625 | } |
14626 | ||
d0fe4701 XR |
14627 | /* The enable command enables the specified breakpoints/locations (or |
14628 | all defined breakpoints) so they once again become (or continue to | |
14629 | be) effective in stopping the inferior. ARGS may be in any of the | |
14630 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 14631 | |
c906108c | 14632 | static void |
981a3fb3 | 14633 | enable_command (const char *args, int from_tty) |
c906108c | 14634 | { |
d0fe4701 | 14635 | enable_disable_command (args, from_tty, true); |
c906108c SS |
14636 | } |
14637 | ||
c906108c | 14638 | static void |
4495129a | 14639 | enable_once_command (const char *args, int from_tty) |
c906108c | 14640 | { |
48649e1b TT |
14641 | map_breakpoint_numbers |
14642 | (args, [&] (breakpoint *b) | |
14643 | { | |
14644 | iterate_over_related_breakpoints | |
14645 | (b, [&] (breakpoint *bpt) | |
14646 | { | |
14647 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14648 | }); | |
14649 | }); | |
816338b5 SS |
14650 | } |
14651 | ||
14652 | static void | |
4495129a | 14653 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14654 | { |
b9d61307 SM |
14655 | int count; |
14656 | ||
14657 | if (args == NULL) | |
14658 | error_no_arg (_("hit count")); | |
14659 | ||
14660 | count = get_number (&args); | |
816338b5 | 14661 | |
48649e1b TT |
14662 | map_breakpoint_numbers |
14663 | (args, [&] (breakpoint *b) | |
14664 | { | |
14665 | iterate_over_related_breakpoints | |
14666 | (b, [&] (breakpoint *bpt) | |
14667 | { | |
14668 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14669 | }); | |
14670 | }); | |
c906108c SS |
14671 | } |
14672 | ||
c906108c | 14673 | static void |
4495129a | 14674 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14675 | { |
48649e1b TT |
14676 | map_breakpoint_numbers |
14677 | (args, [&] (breakpoint *b) | |
14678 | { | |
14679 | iterate_over_related_breakpoints | |
14680 | (b, [&] (breakpoint *bpt) | |
14681 | { | |
14682 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14683 | }); | |
14684 | }); | |
c906108c SS |
14685 | } |
14686 | \f | |
1f3b5d1b PP |
14687 | /* Invalidate last known value of any hardware watchpoint if |
14688 | the memory which that value represents has been written to by | |
14689 | GDB itself. */ | |
14690 | ||
14691 | static void | |
8de0566d YQ |
14692 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14693 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14694 | const bfd_byte *data) |
14695 | { | |
14696 | struct breakpoint *bp; | |
14697 | ||
14698 | ALL_BREAKPOINTS (bp) | |
14699 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14700 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14701 | { |
3a5c3e22 | 14702 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14703 | |
850645cf | 14704 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 PA |
14705 | { |
14706 | struct bp_location *loc; | |
14707 | ||
14708 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14709 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14710 | && loc->address + loc->length > addr | |
14711 | && addr + len > loc->address) | |
14712 | { | |
3a5c3e22 | 14713 | wp->val = NULL; |
4c1d86d9 | 14714 | wp->val_valid = false; |
3a5c3e22 PA |
14715 | } |
14716 | } | |
1f3b5d1b PP |
14717 | } |
14718 | } | |
14719 | ||
8181d85f DJ |
14720 | /* Create and insert a breakpoint for software single step. */ |
14721 | ||
14722 | void | |
6c95b8df | 14723 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 14724 | const address_space *aspace, |
4a64f543 | 14725 | CORE_ADDR next_pc) |
8181d85f | 14726 | { |
7c16b83e PA |
14727 | struct thread_info *tp = inferior_thread (); |
14728 | struct symtab_and_line sal; | |
14729 | CORE_ADDR pc = next_pc; | |
8181d85f | 14730 | |
34b7e8a6 PA |
14731 | if (tp->control.single_step_breakpoints == NULL) |
14732 | { | |
14733 | tp->control.single_step_breakpoints | |
5d5658a1 | 14734 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14735 | } |
8181d85f | 14736 | |
7c16b83e PA |
14737 | sal = find_pc_line (pc, 0); |
14738 | sal.pc = pc; | |
14739 | sal.section = find_pc_overlay (pc); | |
14740 | sal.explicit_pc = 1; | |
34b7e8a6 | 14741 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14742 | |
7c16b83e | 14743 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14744 | } |
14745 | ||
93f9a11f YQ |
14746 | /* Insert single step breakpoints according to the current state. */ |
14747 | ||
14748 | int | |
14749 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14750 | { | |
f5ea389a | 14751 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14752 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14753 | |
f5ea389a | 14754 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14755 | |
a0ff9e1a | 14756 | if (!next_pcs.empty ()) |
93f9a11f | 14757 | { |
f5ea389a | 14758 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14759 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14760 | |
a0ff9e1a | 14761 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14762 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14763 | ||
93f9a11f YQ |
14764 | return 1; |
14765 | } | |
14766 | else | |
14767 | return 0; | |
14768 | } | |
14769 | ||
34b7e8a6 | 14770 | /* See breakpoint.h. */ |
f02253f1 HZ |
14771 | |
14772 | int | |
7c16b83e | 14773 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14774 | const address_space *aspace, |
7c16b83e | 14775 | CORE_ADDR pc) |
1aafd4da | 14776 | { |
7c16b83e | 14777 | struct bp_location *loc; |
1aafd4da | 14778 | |
7c16b83e PA |
14779 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14780 | if (loc->inserted | |
14781 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14782 | return 1; | |
1aafd4da | 14783 | |
7c16b83e | 14784 | return 0; |
ef370185 JB |
14785 | } |
14786 | ||
14787 | /* Check whether a software single-step breakpoint is inserted at | |
14788 | PC. */ | |
14789 | ||
14790 | int | |
accd0bcd | 14791 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14792 | CORE_ADDR pc) |
14793 | { | |
34b7e8a6 PA |
14794 | struct breakpoint *bpt; |
14795 | ||
14796 | ALL_BREAKPOINTS (bpt) | |
14797 | { | |
14798 | if (bpt->type == bp_single_step | |
14799 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14800 | return 1; | |
14801 | } | |
14802 | return 0; | |
1aafd4da UW |
14803 | } |
14804 | ||
1042e4c0 SS |
14805 | /* Tracepoint-specific operations. */ |
14806 | ||
14807 | /* Set tracepoint count to NUM. */ | |
14808 | static void | |
14809 | set_tracepoint_count (int num) | |
14810 | { | |
14811 | tracepoint_count = num; | |
4fa62494 | 14812 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14813 | } |
14814 | ||
70221824 | 14815 | static void |
0b39b52e | 14816 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14817 | { |
ffc2605c TT |
14818 | event_location_up location = string_to_event_location (&arg, |
14819 | current_language); | |
bac7c5cf GB |
14820 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
14821 | (location.get (), true /* is_tracepoint */); | |
55aa24fb | 14822 | |
558a9d82 | 14823 | create_breakpoint (get_current_arch (), |
ffc2605c | 14824 | location.get (), |
f00aae0f | 14825 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14826 | 0 /* tempflag */, |
14827 | bp_tracepoint /* type_wanted */, | |
14828 | 0 /* Ignore count */, | |
14829 | pending_break_support, | |
14830 | ops, | |
14831 | from_tty, | |
14832 | 1 /* enabled */, | |
14833 | 0 /* internal */, 0); | |
1042e4c0 SS |
14834 | } |
14835 | ||
70221824 | 14836 | static void |
0b39b52e | 14837 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14838 | { |
ffc2605c TT |
14839 | event_location_up location = string_to_event_location (&arg, |
14840 | current_language); | |
558a9d82 | 14841 | create_breakpoint (get_current_arch (), |
ffc2605c | 14842 | location.get (), |
f00aae0f | 14843 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14844 | 0 /* tempflag */, |
14845 | bp_fast_tracepoint /* type_wanted */, | |
14846 | 0 /* Ignore count */, | |
14847 | pending_break_support, | |
14848 | &tracepoint_breakpoint_ops, | |
14849 | from_tty, | |
14850 | 1 /* enabled */, | |
14851 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14852 | } |
14853 | ||
14854 | /* strace command implementation. Creates a static tracepoint. */ | |
14855 | ||
70221824 | 14856 | static void |
0b39b52e | 14857 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14858 | { |
983af33b | 14859 | struct breakpoint_ops *ops; |
ffc2605c | 14860 | event_location_up location; |
983af33b SDJ |
14861 | |
14862 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14863 | or with a normal static tracepoint. */ | |
61012eef | 14864 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14865 | { |
14866 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14867 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14868 | } |
983af33b | 14869 | else |
f00aae0f KS |
14870 | { |
14871 | ops = &tracepoint_breakpoint_ops; | |
14872 | location = string_to_event_location (&arg, current_language); | |
14873 | } | |
983af33b | 14874 | |
558a9d82 | 14875 | create_breakpoint (get_current_arch (), |
ffc2605c | 14876 | location.get (), |
f00aae0f | 14877 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14878 | 0 /* tempflag */, |
14879 | bp_static_tracepoint /* type_wanted */, | |
14880 | 0 /* Ignore count */, | |
14881 | pending_break_support, | |
14882 | ops, | |
14883 | from_tty, | |
14884 | 1 /* enabled */, | |
14885 | 0 /* internal */, 0); | |
7a697b8d SS |
14886 | } |
14887 | ||
409873ef SS |
14888 | /* Set up a fake reader function that gets command lines from a linked |
14889 | list that was acquired during tracepoint uploading. */ | |
14890 | ||
14891 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14892 | static int next_cmd; |
409873ef SS |
14893 | |
14894 | static char * | |
14895 | read_uploaded_action (void) | |
14896 | { | |
a18ba4e4 | 14897 | char *rslt = nullptr; |
409873ef | 14898 | |
a18ba4e4 SM |
14899 | if (next_cmd < this_utp->cmd_strings.size ()) |
14900 | { | |
67aa1f3c | 14901 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
14902 | next_cmd++; |
14903 | } | |
409873ef SS |
14904 | |
14905 | return rslt; | |
14906 | } | |
14907 | ||
00bf0b85 SS |
14908 | /* Given information about a tracepoint as recorded on a target (which |
14909 | can be either a live system or a trace file), attempt to create an | |
14910 | equivalent GDB tracepoint. This is not a reliable process, since | |
14911 | the target does not necessarily have all the information used when | |
14912 | the tracepoint was originally defined. */ | |
14913 | ||
d9b3f62e | 14914 | struct tracepoint * |
00bf0b85 | 14915 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14916 | { |
f2fc3015 TT |
14917 | const char *addr_str; |
14918 | char small_buf[100]; | |
d9b3f62e | 14919 | struct tracepoint *tp; |
fd9b8c24 | 14920 | |
409873ef | 14921 | if (utp->at_string) |
67aa1f3c | 14922 | addr_str = utp->at_string.get (); |
409873ef SS |
14923 | else |
14924 | { | |
14925 | /* In the absence of a source location, fall back to raw | |
14926 | address. Since there is no way to confirm that the address | |
14927 | means the same thing as when the trace was started, warn the | |
14928 | user. */ | |
3e43a32a MS |
14929 | warning (_("Uploaded tracepoint %d has no " |
14930 | "source location, using raw address"), | |
409873ef | 14931 | utp->number); |
8c042590 | 14932 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14933 | addr_str = small_buf; |
14934 | } | |
14935 | ||
14936 | /* There's not much we can do with a sequence of bytecodes. */ | |
14937 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14938 | warning (_("Uploaded tracepoint %d condition " |
14939 | "has no source form, ignoring it"), | |
409873ef | 14940 | utp->number); |
d5551862 | 14941 | |
ffc2605c TT |
14942 | event_location_up location = string_to_event_location (&addr_str, |
14943 | current_language); | |
8cdf0e15 | 14944 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14945 | location.get (), |
67aa1f3c | 14946 | utp->cond_string.get (), -1, addr_str, |
e7e0cddf | 14947 | 0 /* parse cond/thread */, |
8cdf0e15 | 14948 | 0 /* tempflag */, |
0fb4aa4b | 14949 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14950 | 0 /* Ignore count */, |
14951 | pending_break_support, | |
348d480f | 14952 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14953 | 0 /* from_tty */, |
84f4c1fe | 14954 | utp->enabled /* enabled */, |
44f238bb PA |
14955 | 0 /* internal */, |
14956 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14957 | return NULL; |
fd9b8c24 | 14958 | |
409873ef | 14959 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14960 | tp = get_tracepoint (tracepoint_count); |
14961 | gdb_assert (tp != NULL); | |
d5551862 | 14962 | |
00bf0b85 SS |
14963 | if (utp->pass > 0) |
14964 | { | |
8c042590 | 14965 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14966 | tp->number); |
00bf0b85 | 14967 | |
409873ef | 14968 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14969 | } |
14970 | ||
409873ef SS |
14971 | /* If we have uploaded versions of the original commands, set up a |
14972 | special-purpose "reader" function and call the usual command line | |
14973 | reader, then pass the result to the breakpoint command-setting | |
14974 | function. */ | |
a18ba4e4 | 14975 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 14976 | { |
12973681 | 14977 | counted_command_line cmd_list; |
00bf0b85 | 14978 | |
409873ef | 14979 | this_utp = utp; |
3149d8c1 | 14980 | next_cmd = 0; |
d5551862 | 14981 | |
60b3cef2 | 14982 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 14983 | |
c1fc2657 | 14984 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14985 | } |
a18ba4e4 SM |
14986 | else if (!utp->actions.empty () |
14987 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
14988 | warning (_("Uploaded tracepoint %d actions " |
14989 | "have no source form, ignoring them"), | |
409873ef | 14990 | utp->number); |
00bf0b85 | 14991 | |
f196051f | 14992 | /* Copy any status information that might be available. */ |
c1fc2657 | 14993 | tp->hit_count = utp->hit_count; |
f196051f SS |
14994 | tp->traceframe_usage = utp->traceframe_usage; |
14995 | ||
00bf0b85 | 14996 | return tp; |
d9b3f62e | 14997 | } |
00bf0b85 | 14998 | |
1042e4c0 SS |
14999 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15000 | omitted. */ | |
15001 | ||
15002 | static void | |
1d12d88f | 15003 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 15004 | { |
79a45e25 | 15005 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15006 | int num_printed; |
1042e4c0 | 15007 | |
5c458ae8 | 15008 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
d77f58be SS |
15009 | |
15010 | if (num_printed == 0) | |
1042e4c0 | 15011 | { |
e5a67952 | 15012 | if (args == NULL || *args == '\0') |
112e8700 | 15013 | uiout->message ("No tracepoints.\n"); |
d77f58be | 15014 | else |
112e8700 | 15015 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15016 | } |
ad443146 SS |
15017 | |
15018 | default_collect_info (); | |
1042e4c0 SS |
15019 | } |
15020 | ||
4a64f543 | 15021 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15022 | Not supported by all targets. */ |
15023 | static void | |
5fed81ff | 15024 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
15025 | { |
15026 | enable_command (args, from_tty); | |
15027 | } | |
15028 | ||
4a64f543 | 15029 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15030 | Not supported by all targets. */ |
15031 | static void | |
5fed81ff | 15032 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
15033 | { |
15034 | disable_command (args, from_tty); | |
15035 | } | |
15036 | ||
4a64f543 | 15037 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 15038 | static void |
4495129a | 15039 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 15040 | { |
35df4500 | 15041 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15042 | |
15043 | dont_repeat (); | |
15044 | ||
15045 | if (arg == 0) | |
15046 | { | |
15047 | int breaks_to_delete = 0; | |
15048 | ||
15049 | /* Delete all breakpoints if no argument. | |
dda83cd7 SM |
15050 | Do not delete internal or call-dummy breakpoints, these |
15051 | have to be deleted with an explicit breakpoint number | |
4a64f543 | 15052 | argument. */ |
1042e4c0 | 15053 | ALL_TRACEPOINTS (b) |
46c6471b | 15054 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15055 | { |
15056 | breaks_to_delete = 1; | |
15057 | break; | |
15058 | } | |
1042e4c0 SS |
15059 | |
15060 | /* Ask user only if there are some breakpoints to delete. */ | |
15061 | if (!from_tty | |
15062 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15063 | { | |
35df4500 | 15064 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15065 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15066 | delete_breakpoint (b); |
1042e4c0 SS |
15067 | } |
15068 | } | |
15069 | else | |
48649e1b | 15070 | map_breakpoint_numbers |
b926417a | 15071 | (arg, [&] (breakpoint *br) |
48649e1b | 15072 | { |
b926417a | 15073 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 15074 | }); |
1042e4c0 SS |
15075 | } |
15076 | ||
197f0a60 TT |
15077 | /* Helper function for trace_pass_command. */ |
15078 | ||
15079 | static void | |
d9b3f62e | 15080 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15081 | { |
d9b3f62e | 15082 | tp->pass_count = count; |
76727919 | 15083 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 TT |
15084 | if (from_tty) |
15085 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 15086 | tp->number, count); |
197f0a60 TT |
15087 | } |
15088 | ||
1042e4c0 SS |
15089 | /* Set passcount for tracepoint. |
15090 | ||
15091 | First command argument is passcount, second is tracepoint number. | |
15092 | If tracepoint number omitted, apply to most recently defined. | |
15093 | Also accepts special argument "all". */ | |
15094 | ||
15095 | static void | |
0b39b52e | 15096 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 15097 | { |
d9b3f62e | 15098 | struct tracepoint *t1; |
0b39b52e | 15099 | ULONGEST count; |
1042e4c0 SS |
15100 | |
15101 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15102 | error (_("passcount command requires an " |
15103 | "argument (count + optional TP num)")); | |
1042e4c0 | 15104 | |
0b39b52e | 15105 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15106 | |
529480d0 | 15107 | args = skip_spaces (args); |
1042e4c0 SS |
15108 | if (*args && strncasecmp (args, "all", 3) == 0) |
15109 | { | |
d9b3f62e PA |
15110 | struct breakpoint *b; |
15111 | ||
1042e4c0 | 15112 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15113 | if (*args) |
15114 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15115 | |
d9b3f62e | 15116 | ALL_TRACEPOINTS (b) |
197f0a60 | 15117 | { |
d9b3f62e | 15118 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15119 | trace_pass_set_count (t1, count, from_tty); |
15120 | } | |
15121 | } | |
15122 | else if (*args == '\0') | |
1042e4c0 | 15123 | { |
5fa1d40e | 15124 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15125 | if (t1) |
197f0a60 TT |
15126 | trace_pass_set_count (t1, count, from_tty); |
15127 | } | |
15128 | else | |
15129 | { | |
bfd28288 PA |
15130 | number_or_range_parser parser (args); |
15131 | while (!parser.finished ()) | |
1042e4c0 | 15132 | { |
bfd28288 | 15133 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15134 | if (t1) |
15135 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15136 | } |
15137 | } | |
1042e4c0 SS |
15138 | } |
15139 | ||
d9b3f62e | 15140 | struct tracepoint * |
1042e4c0 SS |
15141 | get_tracepoint (int num) |
15142 | { | |
15143 | struct breakpoint *t; | |
15144 | ||
15145 | ALL_TRACEPOINTS (t) | |
15146 | if (t->number == num) | |
d9b3f62e | 15147 | return (struct tracepoint *) t; |
1042e4c0 SS |
15148 | |
15149 | return NULL; | |
15150 | } | |
15151 | ||
d5551862 SS |
15152 | /* Find the tracepoint with the given target-side number (which may be |
15153 | different from the tracepoint number after disconnecting and | |
15154 | reconnecting). */ | |
15155 | ||
d9b3f62e | 15156 | struct tracepoint * |
d5551862 SS |
15157 | get_tracepoint_by_number_on_target (int num) |
15158 | { | |
d9b3f62e | 15159 | struct breakpoint *b; |
d5551862 | 15160 | |
d9b3f62e PA |
15161 | ALL_TRACEPOINTS (b) |
15162 | { | |
15163 | struct tracepoint *t = (struct tracepoint *) b; | |
15164 | ||
15165 | if (t->number_on_target == num) | |
15166 | return t; | |
15167 | } | |
d5551862 SS |
15168 | |
15169 | return NULL; | |
15170 | } | |
15171 | ||
1042e4c0 | 15172 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15173 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15174 | If the argument is missing, the most recent tracepoint |
15175 | (tracepoint_count) is returned. */ | |
15176 | ||
d9b3f62e | 15177 | struct tracepoint * |
0b39b52e | 15178 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 15179 | number_or_range_parser *parser) |
1042e4c0 | 15180 | { |
1042e4c0 SS |
15181 | struct breakpoint *t; |
15182 | int tpnum; | |
0b39b52e | 15183 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 15184 | |
bfd28288 | 15185 | if (parser != NULL) |
197f0a60 | 15186 | { |
bfd28288 PA |
15187 | gdb_assert (!parser->finished ()); |
15188 | tpnum = parser->get_number (); | |
197f0a60 TT |
15189 | } |
15190 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15191 | tpnum = tracepoint_count; |
1042e4c0 | 15192 | else |
197f0a60 | 15193 | tpnum = get_number (arg); |
1042e4c0 SS |
15194 | |
15195 | if (tpnum <= 0) | |
15196 | { | |
15197 | if (instring && *instring) | |
15198 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15199 | instring); | |
15200 | else | |
5fa1d40e | 15201 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15202 | return NULL; |
15203 | } | |
15204 | ||
15205 | ALL_TRACEPOINTS (t) | |
15206 | if (t->number == tpnum) | |
15207 | { | |
d9b3f62e | 15208 | return (struct tracepoint *) t; |
1042e4c0 SS |
15209 | } |
15210 | ||
1042e4c0 SS |
15211 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15212 | return NULL; | |
15213 | } | |
15214 | ||
d9b3f62e PA |
15215 | void |
15216 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15217 | { | |
15218 | if (b->thread != -1) | |
15219 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15220 | ||
15221 | if (b->task != 0) | |
15222 | fprintf_unfiltered (fp, " task %d", b->task); | |
15223 | ||
15224 | fprintf_unfiltered (fp, "\n"); | |
15225 | } | |
15226 | ||
6149aea9 PA |
15227 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15228 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15229 | on each breakpoint and only include the ones for which it returns | |
f2478a7e | 15230 | true. */ |
6149aea9 | 15231 | |
1042e4c0 | 15232 | static void |
4495129a | 15233 | save_breakpoints (const char *filename, int from_tty, |
f2478a7e | 15234 | bool (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
15235 | { |
15236 | struct breakpoint *tp; | |
6149aea9 | 15237 | int any = 0; |
6149aea9 | 15238 | int extra_trace_bits = 0; |
1042e4c0 | 15239 | |
6149aea9 PA |
15240 | if (filename == 0 || *filename == 0) |
15241 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15242 | |
15243 | /* See if we have anything to save. */ | |
6149aea9 | 15244 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15245 | { |
6149aea9 | 15246 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15247 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15248 | continue; |
15249 | ||
15250 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15251 | if (filter && !filter (tp)) | |
15252 | continue; | |
15253 | ||
15254 | any = 1; | |
15255 | ||
15256 | if (is_tracepoint (tp)) | |
15257 | { | |
15258 | extra_trace_bits = 1; | |
15259 | ||
15260 | /* We can stop searching. */ | |
15261 | break; | |
15262 | } | |
1042e4c0 | 15263 | } |
6149aea9 PA |
15264 | |
15265 | if (!any) | |
1042e4c0 | 15266 | { |
6149aea9 | 15267 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15268 | return; |
15269 | } | |
15270 | ||
ee0c3293 | 15271 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
15272 | |
15273 | stdio_file fp; | |
15274 | ||
ee0c3293 | 15275 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 15276 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 15277 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 15278 | |
6149aea9 | 15279 | if (extra_trace_bits) |
d7e74731 | 15280 | save_trace_state_variables (&fp); |
8bf6485c | 15281 | |
6149aea9 | 15282 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15283 | { |
6149aea9 | 15284 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15285 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15286 | continue; |
8bf6485c | 15287 | |
6149aea9 PA |
15288 | /* If we have a filter, only save the breakpoints it accepts. */ |
15289 | if (filter && !filter (tp)) | |
15290 | continue; | |
15291 | ||
d7e74731 | 15292 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15293 | |
6149aea9 PA |
15294 | /* Note, we can't rely on tp->number for anything, as we can't |
15295 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15296 | instead. */ | |
15297 | ||
15298 | if (tp->cond_string) | |
d7e74731 | 15299 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15300 | |
15301 | if (tp->ignore_count) | |
d7e74731 | 15302 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15303 | |
2d9442cc | 15304 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15305 | { |
d7e74731 | 15306 | fp.puts (" commands\n"); |
a7bdde9e | 15307 | |
d7e74731 | 15308 | current_uiout->redirect (&fp); |
a70b8144 | 15309 | try |
1042e4c0 | 15310 | { |
d1b0a7bf | 15311 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 15312 | } |
230d2906 | 15313 | catch (const gdb_exception &ex) |
492d29ea | 15314 | { |
112e8700 | 15315 | current_uiout->redirect (NULL); |
eedc3f4f | 15316 | throw; |
492d29ea | 15317 | } |
1042e4c0 | 15318 | |
112e8700 | 15319 | current_uiout->redirect (NULL); |
d7e74731 | 15320 | fp.puts (" end\n"); |
1042e4c0 | 15321 | } |
6149aea9 PA |
15322 | |
15323 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15324 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15325 | |
15326 | /* If this is a multi-location breakpoint, check if the locations | |
15327 | should be individually disabled. Watchpoint locations are | |
15328 | special, and not user visible. */ | |
15329 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15330 | { | |
15331 | struct bp_location *loc; | |
15332 | int n = 1; | |
15333 | ||
15334 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15335 | if (!loc->enabled) | |
d7e74731 | 15336 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15337 | } |
1042e4c0 | 15338 | } |
8bf6485c | 15339 | |
6149aea9 | 15340 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15341 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15342 | |
1042e4c0 | 15343 | if (from_tty) |
ee0c3293 | 15344 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15345 | } |
15346 | ||
15347 | /* The `save breakpoints' command. */ | |
15348 | ||
15349 | static void | |
4495129a | 15350 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15351 | { |
15352 | save_breakpoints (args, from_tty, NULL); | |
15353 | } | |
15354 | ||
15355 | /* The `save tracepoints' command. */ | |
15356 | ||
15357 | static void | |
4495129a | 15358 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15359 | { |
15360 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15361 | } |
15362 | ||
15363 | /* Create a vector of all tracepoints. */ | |
15364 | ||
f51e0e20 | 15365 | std::vector<breakpoint *> |
eeae04df | 15366 | all_tracepoints (void) |
1042e4c0 | 15367 | { |
f51e0e20 | 15368 | std::vector<breakpoint *> tp_vec; |
1042e4c0 SS |
15369 | struct breakpoint *tp; |
15370 | ||
15371 | ALL_TRACEPOINTS (tp) | |
15372 | { | |
f51e0e20 | 15373 | tp_vec.push_back (tp); |
1042e4c0 SS |
15374 | } |
15375 | ||
15376 | return tp_vec; | |
15377 | } | |
15378 | ||
c906108c | 15379 | \f |
629500fa KS |
15380 | /* This help string is used to consolidate all the help string for specifying |
15381 | locations used by several commands. */ | |
15382 | ||
15383 | #define LOCATION_HELP_STRING \ | |
15384 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15385 | source filename, function name, label name, and line number.\n\ | |
15386 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15387 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15388 | \"factorial.c:fact:the_top\".\n\ | |
15389 | \n\ | |
15390 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15391 | program. Example: To specify the fourth byte past the start function\n\ | |
15392 | \"main\", use \"*main + 4\".\n\ | |
15393 | \n\ | |
15394 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15395 | syntax to specify location parameters.\n\ | |
15396 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15397 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
15398 | -function fact -label the_top\".\n\ |
15399 | \n\ | |
15400 | By default, a specified function is matched against the program's\n\ | |
15401 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
15402 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
15403 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
15404 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 15405 | specified name as a complete fully-qualified name instead." |
629500fa | 15406 | |
4a64f543 MS |
15407 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15408 | commands. It is defined as a macro to prevent duplication. | |
15409 | COMMAND should be a string constant containing the name of the | |
15410 | command. */ | |
629500fa | 15411 | |
31e2b00f | 15412 | #define BREAK_ARGS_HELP(command) \ |
733d554a TBA |
15413 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\ |
15414 | \t[-force-condition] [if CONDITION]\n\ | |
fb7b5af4 SDJ |
15415 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ |
15416 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15417 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15418 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15419 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15420 | below.\n\ | |
15421 | \n\ | |
dc10affe PA |
15422 | With no LOCATION, uses current execution address of the selected\n\ |
15423 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15424 | \n\ |
15425 | THREADNUM is the number from \"info threads\".\n\ | |
15426 | CONDITION is a boolean expression.\n\ | |
733d554a TBA |
15427 | \n\ |
15428 | With the \"-force-condition\" flag, the condition is defined even when\n\ | |
15429 | it is invalid for all current locations.\n\ | |
89549d7f | 15430 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15431 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15432 | conditions are different.\n\ | |
31e2b00f AS |
15433 | \n\ |
15434 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15435 | ||
44feb3ce TT |
15436 | /* List of subcommands for "catch". */ |
15437 | static struct cmd_list_element *catch_cmdlist; | |
15438 | ||
15439 | /* List of subcommands for "tcatch". */ | |
15440 | static struct cmd_list_element *tcatch_cmdlist; | |
15441 | ||
9ac4176b | 15442 | void |
a121b7c1 | 15443 | add_catch_command (const char *name, const char *docstring, |
eb4c3f4a | 15444 | cmd_const_sfunc_ftype *sfunc, |
625e8578 | 15445 | completer_ftype *completer, |
44feb3ce TT |
15446 | void *user_data_catch, |
15447 | void *user_data_tcatch) | |
15448 | { | |
15449 | struct cmd_list_element *command; | |
15450 | ||
0450cc4c | 15451 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15452 | &catch_cmdlist); |
15453 | set_cmd_sfunc (command, sfunc); | |
15454 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15455 | set_cmd_completer (command, completer); |
44feb3ce | 15456 | |
0450cc4c | 15457 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15458 | &tcatch_cmdlist); |
15459 | set_cmd_sfunc (command, sfunc); | |
15460 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15461 | set_cmd_completer (command, completer); |
44feb3ce TT |
15462 | } |
15463 | ||
84f4c1fe | 15464 | struct breakpoint * |
95da600f | 15465 | iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback) |
84f4c1fe | 15466 | { |
35df4500 | 15467 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15468 | |
35df4500 | 15469 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe | 15470 | { |
95da600f | 15471 | if (callback (b)) |
84f4c1fe PM |
15472 | return b; |
15473 | } | |
15474 | ||
15475 | return NULL; | |
15476 | } | |
15477 | ||
0574c78f GB |
15478 | /* Zero if any of the breakpoint's locations could be a location where |
15479 | functions have been inlined, nonzero otherwise. */ | |
15480 | ||
15481 | static int | |
15482 | is_non_inline_function (struct breakpoint *b) | |
15483 | { | |
15484 | /* The shared library event breakpoint is set on the address of a | |
15485 | non-inline function. */ | |
15486 | if (b->type == bp_shlib_event) | |
15487 | return 1; | |
15488 | ||
15489 | return 0; | |
15490 | } | |
15491 | ||
15492 | /* Nonzero if the specified PC cannot be a location where functions | |
15493 | have been inlined. */ | |
15494 | ||
15495 | int | |
accd0bcd | 15496 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
09ac7c10 | 15497 | const struct target_waitstatus *ws) |
0574c78f GB |
15498 | { |
15499 | struct breakpoint *b; | |
15500 | struct bp_location *bl; | |
15501 | ||
15502 | ALL_BREAKPOINTS (b) | |
15503 | { | |
15504 | if (!is_non_inline_function (b)) | |
15505 | continue; | |
15506 | ||
15507 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15508 | { | |
15509 | if (!bl->shlib_disabled | |
09ac7c10 | 15510 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15511 | return 1; |
15512 | } | |
15513 | } | |
15514 | ||
15515 | return 0; | |
15516 | } | |
15517 | ||
2f202fde JK |
15518 | /* Remove any references to OBJFILE which is going to be freed. */ |
15519 | ||
15520 | void | |
15521 | breakpoint_free_objfile (struct objfile *objfile) | |
15522 | { | |
15523 | struct bp_location **locp, *loc; | |
15524 | ||
15525 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15526 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15527 | loc->symtab = NULL; |
15528 | } | |
15529 | ||
2060206e PA |
15530 | void |
15531 | initialize_breakpoint_ops (void) | |
15532 | { | |
15533 | static int initialized = 0; | |
15534 | ||
15535 | struct breakpoint_ops *ops; | |
15536 | ||
15537 | if (initialized) | |
15538 | return; | |
15539 | initialized = 1; | |
15540 | ||
15541 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15542 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15543 | internal and momentary breakpoints, etc.). */ | |
15544 | ops = &bkpt_base_breakpoint_ops; | |
15545 | *ops = base_breakpoint_ops; | |
15546 | ops->re_set = bkpt_re_set; | |
15547 | ops->insert_location = bkpt_insert_location; | |
15548 | ops->remove_location = bkpt_remove_location; | |
15549 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15550 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15551 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15552 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15553 | |
15554 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15555 | ops = &bkpt_breakpoint_ops; | |
15556 | *ops = bkpt_base_breakpoint_ops; | |
15557 | ops->re_set = bkpt_re_set; | |
15558 | ops->resources_needed = bkpt_resources_needed; | |
15559 | ops->print_it = bkpt_print_it; | |
15560 | ops->print_mention = bkpt_print_mention; | |
15561 | ops->print_recreate = bkpt_print_recreate; | |
15562 | ||
15563 | /* Ranged breakpoints. */ | |
15564 | ops = &ranged_breakpoint_ops; | |
15565 | *ops = bkpt_breakpoint_ops; | |
15566 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15567 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15568 | ops->print_it = print_it_ranged_breakpoint; | |
15569 | ops->print_one = print_one_ranged_breakpoint; | |
15570 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15571 | ops->print_mention = print_mention_ranged_breakpoint; | |
15572 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15573 | ||
15574 | /* Internal breakpoints. */ | |
15575 | ops = &internal_breakpoint_ops; | |
15576 | *ops = bkpt_base_breakpoint_ops; | |
15577 | ops->re_set = internal_bkpt_re_set; | |
15578 | ops->check_status = internal_bkpt_check_status; | |
15579 | ops->print_it = internal_bkpt_print_it; | |
15580 | ops->print_mention = internal_bkpt_print_mention; | |
15581 | ||
15582 | /* Momentary breakpoints. */ | |
15583 | ops = &momentary_breakpoint_ops; | |
15584 | *ops = bkpt_base_breakpoint_ops; | |
15585 | ops->re_set = momentary_bkpt_re_set; | |
15586 | ops->check_status = momentary_bkpt_check_status; | |
15587 | ops->print_it = momentary_bkpt_print_it; | |
15588 | ops->print_mention = momentary_bkpt_print_mention; | |
15589 | ||
55aa24fb SDJ |
15590 | /* Probe breakpoints. */ |
15591 | ops = &bkpt_probe_breakpoint_ops; | |
15592 | *ops = bkpt_breakpoint_ops; | |
15593 | ops->insert_location = bkpt_probe_insert_location; | |
15594 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15595 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15596 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15597 | |
2060206e PA |
15598 | /* Watchpoints. */ |
15599 | ops = &watchpoint_breakpoint_ops; | |
15600 | *ops = base_breakpoint_ops; | |
15601 | ops->re_set = re_set_watchpoint; | |
15602 | ops->insert_location = insert_watchpoint; | |
15603 | ops->remove_location = remove_watchpoint; | |
15604 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15605 | ops->check_status = check_status_watchpoint; | |
15606 | ops->resources_needed = resources_needed_watchpoint; | |
15607 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15608 | ops->print_it = print_it_watchpoint; | |
15609 | ops->print_mention = print_mention_watchpoint; | |
15610 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15611 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15612 | |
15613 | /* Masked watchpoints. */ | |
15614 | ops = &masked_watchpoint_breakpoint_ops; | |
15615 | *ops = watchpoint_breakpoint_ops; | |
15616 | ops->insert_location = insert_masked_watchpoint; | |
15617 | ops->remove_location = remove_masked_watchpoint; | |
15618 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15619 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15620 | ops->print_it = print_it_masked_watchpoint; | |
15621 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15622 | ops->print_mention = print_mention_masked_watchpoint; | |
15623 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15624 | ||
15625 | /* Tracepoints. */ | |
15626 | ops = &tracepoint_breakpoint_ops; | |
15627 | *ops = base_breakpoint_ops; | |
15628 | ops->re_set = tracepoint_re_set; | |
15629 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15630 | ops->print_one_detail = tracepoint_print_one_detail; | |
15631 | ops->print_mention = tracepoint_print_mention; | |
15632 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15633 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15634 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15635 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15636 | |
55aa24fb SDJ |
15637 | /* Probe tracepoints. */ |
15638 | ops = &tracepoint_probe_breakpoint_ops; | |
15639 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15640 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15641 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15642 | |
983af33b SDJ |
15643 | /* Static tracepoints with marker (`-m'). */ |
15644 | ops = &strace_marker_breakpoint_ops; | |
15645 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15646 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15647 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15648 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15649 | |
15650 | /* Fork catchpoints. */ | |
15651 | ops = &catch_fork_breakpoint_ops; | |
15652 | *ops = base_breakpoint_ops; | |
15653 | ops->insert_location = insert_catch_fork; | |
15654 | ops->remove_location = remove_catch_fork; | |
15655 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15656 | ops->print_it = print_it_catch_fork; | |
15657 | ops->print_one = print_one_catch_fork; | |
15658 | ops->print_mention = print_mention_catch_fork; | |
15659 | ops->print_recreate = print_recreate_catch_fork; | |
15660 | ||
15661 | /* Vfork catchpoints. */ | |
15662 | ops = &catch_vfork_breakpoint_ops; | |
15663 | *ops = base_breakpoint_ops; | |
15664 | ops->insert_location = insert_catch_vfork; | |
15665 | ops->remove_location = remove_catch_vfork; | |
15666 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15667 | ops->print_it = print_it_catch_vfork; | |
15668 | ops->print_one = print_one_catch_vfork; | |
15669 | ops->print_mention = print_mention_catch_vfork; | |
15670 | ops->print_recreate = print_recreate_catch_vfork; | |
15671 | ||
15672 | /* Exec catchpoints. */ | |
15673 | ops = &catch_exec_breakpoint_ops; | |
15674 | *ops = base_breakpoint_ops; | |
2060206e PA |
15675 | ops->insert_location = insert_catch_exec; |
15676 | ops->remove_location = remove_catch_exec; | |
15677 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15678 | ops->print_it = print_it_catch_exec; | |
15679 | ops->print_one = print_one_catch_exec; | |
15680 | ops->print_mention = print_mention_catch_exec; | |
15681 | ops->print_recreate = print_recreate_catch_exec; | |
15682 | ||
edcc5120 TT |
15683 | /* Solib-related catchpoints. */ |
15684 | ops = &catch_solib_breakpoint_ops; | |
15685 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15686 | ops->insert_location = insert_catch_solib; |
15687 | ops->remove_location = remove_catch_solib; | |
15688 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15689 | ops->check_status = check_status_catch_solib; | |
15690 | ops->print_it = print_it_catch_solib; | |
15691 | ops->print_one = print_one_catch_solib; | |
15692 | ops->print_mention = print_mention_catch_solib; | |
15693 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15694 | |
15695 | ops = &dprintf_breakpoint_ops; | |
15696 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15697 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15698 | ops->resources_needed = bkpt_resources_needed; |
15699 | ops->print_it = bkpt_print_it; | |
15700 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15701 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15702 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15703 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15704 | } |
15705 | ||
8bfd80db YQ |
15706 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15707 | ||
15708 | static struct cmd_list_element *enablebreaklist = NULL; | |
15709 | ||
8588b356 SM |
15710 | /* See breakpoint.h. */ |
15711 | ||
15712 | cmd_list_element *commands_cmd_element = nullptr; | |
15713 | ||
6c265988 | 15714 | void _initialize_breakpoint (); |
c906108c | 15715 | void |
6c265988 | 15716 | _initialize_breakpoint () |
c906108c SS |
15717 | { |
15718 | struct cmd_list_element *c; | |
15719 | ||
2060206e PA |
15720 | initialize_breakpoint_ops (); |
15721 | ||
76727919 TT |
15722 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
15723 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); | |
15724 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); | |
84acb35a | 15725 | |
c906108c SS |
15726 | breakpoint_chain = 0; |
15727 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15728 | before a breakpoint is set. */ | |
15729 | breakpoint_count = 0; | |
15730 | ||
1042e4c0 SS |
15731 | tracepoint_count = 0; |
15732 | ||
1bedd215 AC |
15733 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15734 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15735 | Usage is `ignore N COUNT'.")); | |
c906108c | 15736 | |
8588b356 SM |
15737 | commands_cmd_element = add_com ("commands", class_breakpoint, |
15738 | commands_command, _("\ | |
18da0c51 MG |
15739 | Set commands to be executed when the given breakpoints are hit.\n\ |
15740 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15741 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15742 | (e.g. `5-7').\n\ | |
c906108c SS |
15743 | With no argument, the targeted breakpoint is the last one set.\n\ |
15744 | The commands themselves follow starting on the next line.\n\ | |
15745 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15746 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15747 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15748 | |
b1d4d8d1 TBA |
15749 | const auto cc_opts = make_condition_command_options_def_group (nullptr); |
15750 | static std::string condition_command_help | |
15751 | = gdb::option::build_help (_("\ | |
1bedd215 | 15752 | Specify breakpoint number N to break only if COND is true.\n\ |
b1d4d8d1 | 15753 | Usage is `condition [OPTION] N COND', where N is an integer and COND\n\ |
733d554a | 15754 | is an expression to be evaluated whenever breakpoint N is reached.\n\ |
b1d4d8d1 TBA |
15755 | \n\ |
15756 | Options:\n\ | |
15757 | %OPTIONS%"), cc_opts); | |
15758 | ||
15759 | c = add_com ("condition", class_breakpoint, condition_command, | |
15760 | condition_command_help.c_str ()); | |
15761 | set_cmd_completer_handle_brkchars (c, condition_completer); | |
c906108c | 15762 | |
1bedd215 | 15763 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15764 | Set a temporary breakpoint.\n\ |
c906108c SS |
15765 | Like \"break\" except the breakpoint is only temporary,\n\ |
15766 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15767 | by using \"enable delete\" on the breakpoint number.\n\ |
15768 | \n" | |
15769 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15770 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15771 | |
1bedd215 | 15772 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15773 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15774 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15775 | some target hardware may not have this support.\n\ |
15776 | \n" | |
15777 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15778 | set_cmd_completer (c, location_completer); |
c906108c | 15779 | |
1bedd215 | 15780 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15781 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15782 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15783 | so it will be deleted when hit.\n\ |
15784 | \n" | |
15785 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15786 | set_cmd_completer (c, location_completer); |
c906108c | 15787 | |
1bedd215 | 15788 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
590042fc PW |
15789 | Enable all or some breakpoints.\n\ |
15790 | Usage: enable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15791 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15792 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15793 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15794 | With a subcommand you can enable temporarily."), |
c906108c | 15795 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15796 | |
15797 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15798 | ||
84951ab5 | 15799 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
590042fc PW |
15800 | Enable all or some breakpoints.\n\ |
15801 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15802 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15803 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 15804 | May be abbreviated to simply \"enable\"."), |
c5aa993b | 15805 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15806 | |
1a966eab | 15807 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15808 | Enable some breakpoints for one hit.\n\ |
15809 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ | |
1a966eab | 15810 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
c906108c SS |
15811 | &enablebreaklist); |
15812 | ||
1a966eab | 15813 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15814 | Enable some breakpoints and delete when hit.\n\ |
15815 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ | |
1a966eab | 15816 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15817 | &enablebreaklist); |
15818 | ||
816338b5 | 15819 | add_cmd ("count", no_class, enable_count_command, _("\ |
590042fc PW |
15820 | Enable some breakpoints for COUNT hits.\n\ |
15821 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15822 | If a breakpoint is hit while enabled in this fashion,\n\ |
15823 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15824 | &enablebreaklist); | |
15825 | ||
1a966eab | 15826 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15827 | Enable some breakpoints and delete when hit.\n\ |
15828 | Usage: enable delete BREAKPOINTNUM...\n\ | |
1a966eab | 15829 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15830 | &enablelist); |
15831 | ||
1a966eab | 15832 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15833 | Enable some breakpoints for one hit.\n\ |
15834 | Usage: enable once BREAKPOINTNUM...\n\ | |
1a966eab | 15835 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
816338b5 SS |
15836 | &enablelist); |
15837 | ||
15838 | add_cmd ("count", no_class, enable_count_command, _("\ | |
590042fc PW |
15839 | Enable some breakpoints for COUNT hits.\n\ |
15840 | Usage: enable count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15841 | If a breakpoint is hit while enabled in this fashion,\n\ |
15842 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15843 | &enablelist); |
15844 | ||
1bedd215 | 15845 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
590042fc PW |
15846 | Disable all or some breakpoints.\n\ |
15847 | Usage: disable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15848 | Arguments are breakpoint numbers with spaces in between.\n\ |
15849 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15850 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15851 | &disablelist, "disable ", 1, &cmdlist); |
15852 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15853 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15854 | |
57b4f16e | 15855 | add_cmd ("breakpoints", class_breakpoint, disable_command, _("\ |
590042fc PW |
15856 | Disable all or some breakpoints.\n\ |
15857 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15858 | Arguments are breakpoint numbers with spaces in between.\n\ |
15859 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15860 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15861 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15862 | &disablelist); |
15863 | ||
1bedd215 | 15864 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
590042fc PW |
15865 | Delete all or some breakpoints.\n\ |
15866 | Usage: delete [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15867 | Arguments are breakpoint numbers with spaces in between.\n\ |
15868 | To delete all breakpoints, give no argument.\n\ | |
15869 | \n\ | |
590042fc | 15870 | Also a prefix command for deletion of other GDB objects."), |
c906108c SS |
15871 | &deletelist, "delete ", 1, &cmdlist); |
15872 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15873 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15874 | |
57b4f16e | 15875 | add_cmd ("breakpoints", class_breakpoint, delete_command, _("\ |
590042fc PW |
15876 | Delete all or some breakpoints or auto-display expressions.\n\ |
15877 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15878 | Arguments are breakpoint numbers with spaces in between.\n\ |
15879 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15880 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15881 | &deletelist); |
15882 | ||
1bedd215 | 15883 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15884 | Clear breakpoint at specified location.\n\ |
15885 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15886 | \n\ |
15887 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 15888 | is executing in.\n" |
89549d7f | 15889 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 15890 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15891 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15892 | |
1bedd215 | 15893 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15894 | Set breakpoint at specified location.\n" |
31e2b00f | 15895 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15896 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15897 | |
c906108c SS |
15898 | add_com_alias ("b", "break", class_run, 1); |
15899 | add_com_alias ("br", "break", class_run, 1); | |
15900 | add_com_alias ("bre", "break", class_run, 1); | |
15901 | add_com_alias ("brea", "break", class_run, 1); | |
15902 | ||
c906108c SS |
15903 | if (dbx_commands) |
15904 | { | |
1bedd215 AC |
15905 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15906 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15907 | &stoplist, "stop ", 1, &cmdlist); |
15908 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15909 | _("Break in function or address."), &stoplist); |
c5aa993b | 15910 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15911 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15912 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15913 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15914 | The \"Type\" column indicates one of:\n\ |
15915 | \tbreakpoint - normal breakpoint\n\ | |
15916 | \twatchpoint - watchpoint\n\ | |
15917 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15918 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15919 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15920 | address and file/line number respectively.\n\ |
15921 | \n\ | |
15922 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15923 | are set to the address of the last breakpoint listed unless the command\n\ |
15924 | is prefixed with \"server \".\n\n\ | |
c906108c | 15925 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15926 | breakpoint set.")); |
c906108c SS |
15927 | } |
15928 | ||
11db9430 | 15929 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15930 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15931 | The \"Type\" column indicates one of:\n\ |
15932 | \tbreakpoint - normal breakpoint\n\ | |
15933 | \twatchpoint - watchpoint\n\ | |
15934 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15935 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15936 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15937 | address and file/line number respectively.\n\ |
15938 | \n\ | |
15939 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15940 | are set to the address of the last breakpoint listed unless the command\n\ |
15941 | is prefixed with \"server \".\n\n\ | |
c906108c | 15942 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15943 | breakpoint set.")); |
c906108c | 15944 | |
6b04bdb7 MS |
15945 | add_info_alias ("b", "breakpoints", 1); |
15946 | ||
1a966eab AC |
15947 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15948 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15949 | The \"Type\" column indicates one of:\n\ |
15950 | \tbreakpoint - normal breakpoint\n\ | |
15951 | \twatchpoint - watchpoint\n\ | |
15952 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15953 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15954 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15955 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15956 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15957 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15958 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15959 | address and file/line number respectively.\n\ |
15960 | \n\ | |
15961 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15962 | are set to the address of the last breakpoint listed unless the command\n\ |
15963 | is prefixed with \"server \".\n\n\ | |
c906108c | 15964 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15965 | breakpoint set."), |
c906108c SS |
15966 | &maintenanceinfolist); |
15967 | ||
3b6acaee | 15968 | add_basic_prefix_cmd ("catch", class_breakpoint, _("\ |
44feb3ce | 15969 | Set catchpoints to catch events."), |
3b6acaee TT |
15970 | &catch_cmdlist, "catch ", |
15971 | 0/*allow-unknown*/, &cmdlist); | |
44feb3ce | 15972 | |
3b6acaee | 15973 | add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\ |
44feb3ce | 15974 | Set temporary catchpoints to catch events."), |
3b6acaee TT |
15975 | &tcatch_cmdlist, "tcatch ", |
15976 | 0/*allow-unknown*/, &cmdlist); | |
44feb3ce | 15977 | |
44feb3ce TT |
15978 | add_catch_command ("fork", _("Catch calls to fork."), |
15979 | catch_fork_command_1, | |
dda83cd7 | 15980 | NULL, |
44feb3ce TT |
15981 | (void *) (uintptr_t) catch_fork_permanent, |
15982 | (void *) (uintptr_t) catch_fork_temporary); | |
15983 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15984 | catch_fork_command_1, | |
dda83cd7 | 15985 | NULL, |
44feb3ce TT |
15986 | (void *) (uintptr_t) catch_vfork_permanent, |
15987 | (void *) (uintptr_t) catch_vfork_temporary); | |
15988 | add_catch_command ("exec", _("Catch calls to exec."), | |
15989 | catch_exec_command_1, | |
dda83cd7 | 15990 | NULL, |
a96d9b2e SDJ |
15991 | CATCH_PERMANENT, |
15992 | CATCH_TEMPORARY); | |
edcc5120 TT |
15993 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15994 | Usage: catch load [REGEX]\n\ | |
15995 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15996 | catch_load_command_1, | |
15997 | NULL, | |
15998 | CATCH_PERMANENT, | |
15999 | CATCH_TEMPORARY); | |
16000 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16001 | Usage: catch unload [REGEX]\n\ | |
16002 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16003 | catch_unload_command_1, | |
16004 | NULL, | |
16005 | CATCH_PERMANENT, | |
16006 | CATCH_TEMPORARY); | |
c5aa993b | 16007 | |
a15a5258 AB |
16008 | const auto opts = make_watch_options_def_group (nullptr); |
16009 | ||
16010 | static const std::string watch_help = gdb::option::build_help (_("\ | |
16011 | Set a watchpoint for EXPRESSION.\n\ | |
16012 | Usage: watch [-location] EXPRESSION\n\ | |
16013 | \n\ | |
16014 | Options:\n\ | |
16015 | %OPTIONS%\n\ | |
16016 | \n\ | |
c906108c | 16017 | A watchpoint stops execution of your program whenever the value of\n\ |
a15a5258 AB |
16018 | an expression changes."), opts); |
16019 | c = add_com ("watch", class_breakpoint, watch_command, | |
16020 | watch_help.c_str ()); | |
16021 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
16022 | ||
16023 | static const std::string rwatch_help = gdb::option::build_help (_("\ | |
16024 | Set a read watchpoint for EXPRESSION.\n\ | |
16025 | Usage: rwatch [-location] EXPRESSION\n\ | |
16026 | \n\ | |
16027 | Options:\n\ | |
16028 | %OPTIONS%\n\ | |
16029 | \n\ | |
16030 | A read watchpoint stops execution of your program whenever the value of\n\ | |
16031 | an expression is read."), opts); | |
16032 | c = add_com ("rwatch", class_breakpoint, rwatch_command, | |
16033 | rwatch_help.c_str ()); | |
16034 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
16035 | ||
16036 | static const std::string awatch_help = gdb::option::build_help (_("\ | |
16037 | Set an access watchpoint for EXPRESSION.\n\ | |
16038 | Usage: awatch [-location] EXPRESSION\n\ | |
16039 | \n\ | |
16040 | Options:\n\ | |
16041 | %OPTIONS%\n\ | |
16042 | \n\ | |
16043 | An access watchpoint stops execution of your program whenever the value\n\ | |
16044 | of an expression is either read or written."), opts); | |
16045 | c = add_com ("awatch", class_breakpoint, awatch_command, | |
16046 | awatch_help.c_str ()); | |
16047 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
c906108c | 16048 | |
11db9430 | 16049 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 16050 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16051 | |
920d2a44 AC |
16052 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16053 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16054 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16055 | &can_use_hw_watchpoints, _("\ | |
16056 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16057 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16058 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16059 | such is available. (However, any hardware watchpoints that were\n\ | |
16060 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16061 | hardware.)"), |
16062 | NULL, | |
920d2a44 | 16063 | show_can_use_hw_watchpoints, |
85c07804 | 16064 | &setlist, &showlist); |
c906108c SS |
16065 | |
16066 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16067 | |
1042e4c0 SS |
16068 | /* Tracepoint manipulation commands. */ |
16069 | ||
16070 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16071 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16072 | \n" |
16073 | BREAK_ARGS_HELP ("trace") "\n\ | |
16074 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16075 | set_cmd_completer (c, location_completer); | |
16076 | ||
57b4f16e PW |
16077 | add_com_alias ("tp", "trace", class_breakpoint, 0); |
16078 | add_com_alias ("tr", "trace", class_breakpoint, 1); | |
16079 | add_com_alias ("tra", "trace", class_breakpoint, 1); | |
16080 | add_com_alias ("trac", "trace", class_breakpoint, 1); | |
1042e4c0 | 16081 | |
7a697b8d | 16082 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16083 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16084 | \n" |
16085 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16086 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16087 | set_cmd_completer (c, location_completer); | |
16088 | ||
0fb4aa4b | 16089 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16090 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16091 | \n\ |
16092 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16093 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16094 | or -m MARKER_ID.\n\n\ | |
16095 | If a marker id is specified, probe the marker with that name. With\n\ | |
16096 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16097 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16098 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16099 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16100 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16101 | \n\ | |
16102 | CONDITION is a boolean expression.\n\ | |
89549d7f | 16103 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
16104 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16105 | conditions are different.\n\ | |
0fb4aa4b PA |
16106 | \n\ |
16107 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16108 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16109 | set_cmd_completer (c, location_completer); | |
16110 | ||
11db9430 | 16111 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 16112 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16113 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16114 | last tracepoint set.")); | |
16115 | ||
16116 | add_info_alias ("tp", "tracepoints", 1); | |
16117 | ||
16118 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16119 | Delete specified tracepoints.\n\ | |
16120 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16121 | No argument means delete all tracepoints."), | |
16122 | &deletelist); | |
7e20dfcd | 16123 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16124 | |
16125 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16126 | Disable specified tracepoints.\n\ | |
16127 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16128 | No argument means disable all tracepoints."), | |
16129 | &disablelist); | |
16130 | deprecate_cmd (c, "disable"); | |
16131 | ||
16132 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16133 | Enable specified tracepoints.\n\ | |
16134 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16135 | No argument means enable all tracepoints."), | |
16136 | &enablelist); | |
16137 | deprecate_cmd (c, "enable"); | |
16138 | ||
16139 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16140 | Set the passcount for a tracepoint.\n\ | |
16141 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16142 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16143 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16144 | ||
0743fc83 TT |
16145 | add_basic_prefix_cmd ("save", class_breakpoint, |
16146 | _("Save breakpoint definitions as a script."), | |
16147 | &save_cmdlist, "save ", | |
16148 | 0/*allow-unknown*/, &cmdlist); | |
6149aea9 PA |
16149 | |
16150 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16151 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16152 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16153 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16154 | session to restore them."), | |
16155 | &save_cmdlist); | |
16156 | set_cmd_completer (c, filename_completer); | |
16157 | ||
16158 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16159 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16160 | Use the 'source' command in another debug session to restore them."), |
16161 | &save_cmdlist); | |
1042e4c0 SS |
16162 | set_cmd_completer (c, filename_completer); |
16163 | ||
6149aea9 PA |
16164 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16165 | deprecate_cmd (c, "save tracepoints"); | |
16166 | ||
3b6acaee | 16167 | add_basic_prefix_cmd ("breakpoint", class_maintenance, _("\ |
590042fc | 16168 | Breakpoint specific settings.\n\ |
fa8d40ab | 16169 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 16170 | pending breakpoint behavior."), |
3b6acaee TT |
16171 | &breakpoint_set_cmdlist, "set breakpoint ", |
16172 | 0/*allow-unknown*/, &setlist); | |
16173 | add_show_prefix_cmd ("breakpoint", class_maintenance, _("\ | |
590042fc | 16174 | Breakpoint specific settings.\n\ |
fa8d40ab | 16175 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 16176 | pending breakpoint behavior."), |
3b6acaee TT |
16177 | &breakpoint_show_cmdlist, "show breakpoint ", |
16178 | 0/*allow-unknown*/, &showlist); | |
fa8d40ab | 16179 | |
7915a72c AC |
16180 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16181 | &pending_break_support, _("\ | |
16182 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16183 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16184 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16185 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16186 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16187 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16188 | NULL, |
920d2a44 | 16189 | show_pending_break_support, |
6e1d7d6c AC |
16190 | &breakpoint_set_cmdlist, |
16191 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16192 | |
16193 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16194 | |
16195 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16196 | &automatic_hardware_breakpoints, _("\ | |
16197 | Set automatic usage of hardware breakpoints."), _("\ | |
16198 | Show automatic usage of hardware breakpoints."), _("\ | |
16199 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16200 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16201 | a warning will be emitted for such breakpoints."), | |
16202 | NULL, | |
16203 | show_automatic_hardware_breakpoints, | |
16204 | &breakpoint_set_cmdlist, | |
16205 | &breakpoint_show_cmdlist); | |
74960c60 | 16206 | |
a25a5a45 PA |
16207 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16208 | &always_inserted_mode, _("\ | |
74960c60 VP |
16209 | Set mode for inserting breakpoints."), _("\ |
16210 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16211 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16212 | they're created, kept inserted even when execution stops, and removed\n\ | |
16213 | only when the user deletes them. When this mode is off (the default),\n\ | |
16214 | breakpoints are inserted only when execution continues, and removed\n\ | |
16215 | when execution stops."), | |
72d0e2c5 YQ |
16216 | NULL, |
16217 | &show_always_inserted_mode, | |
16218 | &breakpoint_set_cmdlist, | |
16219 | &breakpoint_show_cmdlist); | |
f1310107 | 16220 | |
b775012e LM |
16221 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16222 | condition_evaluation_enums, | |
16223 | &condition_evaluation_mode_1, _("\ | |
16224 | Set mode of breakpoint condition evaluation."), _("\ | |
16225 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16226 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16227 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16228 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16229 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16230 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16231 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
7a4e8e7d | 16232 | be set to \"host\"."), |
b775012e LM |
16233 | &set_condition_evaluation_mode, |
16234 | &show_condition_evaluation_mode, | |
16235 | &breakpoint_set_cmdlist, | |
16236 | &breakpoint_show_cmdlist); | |
16237 | ||
f1310107 TJB |
16238 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16239 | Set a breakpoint for an address range.\n\ | |
16240 | break-range START-LOCATION, END-LOCATION\n\ | |
16241 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16242 | LINENUM, for that line in the current file,\n\ | |
16243 | FILE:LINENUM, for that line in that file,\n\ | |
16244 | +OFFSET, for that number of lines after the current line\n\ | |
dda83cd7 | 16245 | or the start of the range\n\ |
f1310107 TJB |
16246 | FUNCTION, for the first line in that function,\n\ |
16247 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16248 | *ADDRESS, for the instruction at that address.\n\ | |
16249 | \n\ | |
16250 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16251 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16252 | range (including START-LOCATION and END-LOCATION).")); | |
16253 | ||
e7e0cddf | 16254 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16255 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16256 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16257 | location may be a linespec, explicit, or address location.\n" |
16258 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16259 | set_cmd_completer (c, location_completer); |
16260 | ||
16261 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16262 | dprintf_style_enums, &dprintf_style, _("\ | |
16263 | Set the style of usage for dynamic printf."), _("\ | |
16264 | Show the style of usage for dynamic printf."), _("\ | |
16265 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16266 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16267 | console, as with the \"printf\" command.\n\ | |
16268 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16269 | program; by default printf(), but you can choose a different function or\n\ | |
16270 | output stream by setting dprintf-function and dprintf-channel."), | |
16271 | update_dprintf_commands, NULL, | |
16272 | &setlist, &showlist); | |
16273 | ||
16274 | dprintf_function = xstrdup ("printf"); | |
16275 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16276 | &dprintf_function, _("\ | |
590042fc PW |
16277 | Set the function to use for dynamic printf."), _("\ |
16278 | Show the function to use for dynamic printf."), NULL, | |
e7e0cddf SS |
16279 | update_dprintf_commands, NULL, |
16280 | &setlist, &showlist); | |
16281 | ||
16282 | dprintf_channel = xstrdup (""); | |
16283 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16284 | &dprintf_channel, _("\ | |
590042fc PW |
16285 | Set the channel to use for dynamic printf."), _("\ |
16286 | Show the channel to use for dynamic printf."), NULL, | |
e7e0cddf SS |
16287 | update_dprintf_commands, NULL, |
16288 | &setlist, &showlist); | |
16289 | ||
d3ce09f5 SS |
16290 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16291 | &disconnected_dprintf, _("\ | |
16292 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16293 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16294 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16295 | even if GDB disconnects or detaches from the target."), | |
16296 | NULL, | |
16297 | NULL, | |
16298 | &setlist, &showlist); | |
16299 | ||
16300 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
590042fc PW |
16301 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
16302 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
16303 | This supports most C printf format specifications, like %s, %d, etc.\n\ | |
16304 | This is useful for formatted output in user-defined commands.")); | |
d3ce09f5 | 16305 | |
491144b5 | 16306 | automatic_hardware_breakpoints = true; |
f3b1572e | 16307 | |
76727919 TT |
16308 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
16309 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); | |
c906108c | 16310 | } |