]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
42a4f53d | 3 | Copyright (C) 1986-2019 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
d55e5aa6 | 21 | #include "arch-utils.h" |
4de283e4 TT |
22 | #include <ctype.h> |
23 | #include "hashtab.h" | |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
c906108c | 26 | #include "breakpoint.h" |
4de283e4 TT |
27 | #include "tracepoint.h" |
28 | #include "gdbtypes.h" | |
c906108c | 29 | #include "expression.h" |
d55e5aa6 | 30 | #include "gdbcore.h" |
4de283e4 TT |
31 | #include "gdbcmd.h" |
32 | #include "value.h" | |
33 | #include "command.h" | |
c906108c | 34 | #include "inferior.h" |
45741a9c | 35 | #include "infrun.h" |
4de283e4 TT |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
c906108c | 38 | #include "language.h" |
4de283e4 TT |
39 | #include "gdb-demangle.h" |
40 | #include "filenames.h" | |
41 | #include "annotate.h" | |
42 | #include "symfile.h" | |
d55e5aa6 | 43 | #include "objfiles.h" |
4de283e4 TT |
44 | #include "source.h" |
45 | #include "linespec.h" | |
46 | #include "completer.h" | |
47 | #include "ui-out.h" | |
48 | #include "cli/cli-script.h" | |
49 | #include "block.h" | |
50 | #include "solib.h" | |
51 | #include "solist.h" | |
d55e5aa6 | 52 | #include "observable.h" |
4de283e4 TT |
53 | #include "memattr.h" |
54 | #include "ada-lang.h" | |
55 | #include "top.h" | |
56 | #include "valprint.h" | |
57 | #include "jit.h" | |
65d79d4b | 58 | #include "parser-defs.h" |
4de283e4 | 59 | #include "gdb_regex.h" |
55aa24fb | 60 | #include "probe.h" |
4de283e4 TT |
61 | #include "cli/cli-utils.h" |
62 | #include "continuations.h" | |
d55e5aa6 | 63 | #include "stack.h" |
4de283e4 TT |
64 | #include "skip.h" |
65 | #include "ax-gdb.h" | |
66 | #include "dummy-frame.h" | |
67 | #include "interps.h" | |
68 | #include "common/format.h" | |
cfc31633 | 69 | #include "thread-fsm.h" |
5d5658a1 | 70 | #include "tid-parse.h" |
4de283e4 TT |
71 | #include "cli/cli-style.h" |
72 | #include "mi/mi-main.h" | |
d3ce09f5 | 73 | |
1042e4c0 SS |
74 | /* readline include files */ |
75 | #include "readline/readline.h" | |
76 | #include "readline/history.h" | |
77 | ||
78 | /* readline defines this. */ | |
79 | #undef savestring | |
80 | ||
034dad6f | 81 | #include "mi/mi-common.h" |
6dddc817 | 82 | #include "extension.h" |
325fac50 | 83 | #include <algorithm> |
5ed8105e | 84 | #include "progspace-and-thread.h" |
6c5b2ebe | 85 | #include "common/array-view.h" |
76f9c9cf | 86 | #include "common/gdb_optional.h" |
104c1213 | 87 | |
4a64f543 | 88 | /* Prototypes for local functions. */ |
c906108c | 89 | |
896b6bda | 90 | static void map_breakpoint_numbers (const char *, |
48649e1b | 91 | gdb::function_view<void (breakpoint *)>); |
c906108c | 92 | |
348d480f PA |
93 | static void breakpoint_re_set_default (struct breakpoint *); |
94 | ||
f00aae0f KS |
95 | static void |
96 | create_sals_from_location_default (const struct event_location *location, | |
97 | struct linespec_result *canonical, | |
98 | enum bptype type_wanted); | |
983af33b SDJ |
99 | |
100 | static void create_breakpoints_sal_default (struct gdbarch *, | |
101 | struct linespec_result *, | |
e1e01040 PA |
102 | gdb::unique_xmalloc_ptr<char>, |
103 | gdb::unique_xmalloc_ptr<char>, | |
104 | enum bptype, | |
983af33b SDJ |
105 | enum bpdisp, int, int, |
106 | int, | |
107 | const struct breakpoint_ops *, | |
44f238bb | 108 | int, int, int, unsigned); |
983af33b | 109 | |
6c5b2ebe PA |
110 | static std::vector<symtab_and_line> decode_location_default |
111 | (struct breakpoint *b, const struct event_location *location, | |
112 | struct program_space *search_pspace); | |
983af33b | 113 | |
a6535de1 TT |
114 | static int can_use_hardware_watchpoint |
115 | (const std::vector<value_ref_ptr> &vals); | |
c906108c | 116 | |
a14ed312 | 117 | static void mention (struct breakpoint *); |
c906108c | 118 | |
348d480f PA |
119 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
120 | enum bptype, | |
c0a91b2b | 121 | const struct breakpoint_ops *); |
3742cc8b YQ |
122 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
123 | const struct symtab_and_line *); | |
124 | ||
4a64f543 MS |
125 | /* This function is used in gdbtk sources and thus can not be made |
126 | static. */ | |
63c252f8 | 127 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 128 | struct symtab_and_line, |
c0a91b2b TT |
129 | enum bptype, |
130 | const struct breakpoint_ops *); | |
c906108c | 131 | |
06edf0c0 PA |
132 | static struct breakpoint * |
133 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
134 | enum bptype type, | |
a1aa2221 LM |
135 | const struct breakpoint_ops *ops, |
136 | int loc_enabled); | |
06edf0c0 | 137 | |
76897487 KB |
138 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
139 | ||
a6d9a66e UW |
140 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
141 | CORE_ADDR bpaddr, | |
88f7da05 | 142 | enum bptype bptype); |
76897487 | 143 | |
6c95b8df PA |
144 | static void describe_other_breakpoints (struct gdbarch *, |
145 | struct program_space *, CORE_ADDR, | |
5af949e3 | 146 | struct obj_section *, int); |
c906108c | 147 | |
85d721b8 PA |
148 | static int watchpoint_locations_match (struct bp_location *loc1, |
149 | struct bp_location *loc2); | |
150 | ||
f1310107 | 151 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 152 | const struct address_space *aspace, |
f1310107 TJB |
153 | CORE_ADDR addr); |
154 | ||
d35ae833 | 155 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 156 | const address_space *, |
d35ae833 PA |
157 | CORE_ADDR, int); |
158 | ||
834c0d03 | 159 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 160 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 161 | |
e514a9d6 | 162 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 163 | |
a14ed312 | 164 | static int hw_breakpoint_used_count (void); |
c906108c | 165 | |
a1398e0c PA |
166 | static int hw_watchpoint_use_count (struct breakpoint *); |
167 | ||
168 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
169 | enum bptype type, | |
170 | int *other_type_used); | |
c906108c | 171 | |
816338b5 SS |
172 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
173 | int count); | |
c906108c | 174 | |
fe3f5fa8 | 175 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
176 | static void incref_bp_location (struct bp_location *loc); |
177 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 178 | |
39d61571 | 179 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 180 | |
44702360 PA |
181 | /* update_global_location_list's modes of operation wrt to whether to |
182 | insert locations now. */ | |
183 | enum ugll_insert_mode | |
184 | { | |
185 | /* Don't insert any breakpoint locations into the inferior, only | |
186 | remove already-inserted locations that no longer should be | |
187 | inserted. Functions that delete a breakpoint or breakpoints | |
188 | should specify this mode, so that deleting a breakpoint doesn't | |
189 | have the side effect of inserting the locations of other | |
190 | breakpoints that are marked not-inserted, but should_be_inserted | |
191 | returns true on them. | |
192 | ||
193 | This behavior is useful is situations close to tear-down -- e.g., | |
194 | after an exec, while the target still has execution, but | |
195 | breakpoint shadows of the previous executable image should *NOT* | |
196 | be restored to the new image; or before detaching, where the | |
197 | target still has execution and wants to delete breakpoints from | |
198 | GDB's lists, and all breakpoints had already been removed from | |
199 | the inferior. */ | |
200 | UGLL_DONT_INSERT, | |
201 | ||
a25a5a45 PA |
202 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
203 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
204 | UGLL_MAY_INSERT, |
205 | ||
a25a5a45 PA |
206 | /* Insert locations now, irrespective of |
207 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
208 | stopped right now, and the user did "continue". We need to | |
209 | insert breakpoints _before_ resuming the target, but | |
210 | UGLL_MAY_INSERT wouldn't insert them, because | |
211 | breakpoints_should_be_inserted_now returns false at that point, | |
212 | as no thread is running yet. */ | |
04086b45 | 213 | UGLL_INSERT |
44702360 PA |
214 | }; |
215 | ||
216 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 217 | |
44702360 | 218 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 219 | |
d77f58be | 220 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
221 | |
222 | static void insert_breakpoint_locations (void); | |
a5606eee | 223 | |
0b39b52e | 224 | static void trace_pass_command (const char *, int); |
1042e4c0 | 225 | |
558a9d82 YQ |
226 | static void set_tracepoint_count (int num); |
227 | ||
9c06b0b4 TJB |
228 | static int is_masked_watchpoint (const struct breakpoint *b); |
229 | ||
b775012e LM |
230 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
231 | ||
983af33b SDJ |
232 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
233 | otherwise. */ | |
234 | ||
235 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 236 | |
2060206e PA |
237 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
238 | that are implemented on top of software or hardware breakpoints | |
239 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
240 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
241 | ||
242 | /* Internal breakpoints class type. */ | |
06edf0c0 | 243 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
244 | |
245 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
246 | static struct breakpoint_ops momentary_breakpoint_ops; |
247 | ||
2060206e PA |
248 | /* The breakpoint_ops structure to be used in regular user created |
249 | breakpoints. */ | |
250 | struct breakpoint_ops bkpt_breakpoint_ops; | |
251 | ||
55aa24fb SDJ |
252 | /* Breakpoints set on probes. */ |
253 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
254 | ||
e7e0cddf | 255 | /* Dynamic printf class type. */ |
c5867ab6 | 256 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 257 | |
d3ce09f5 SS |
258 | /* The style in which to perform a dynamic printf. This is a user |
259 | option because different output options have different tradeoffs; | |
260 | if GDB does the printing, there is better error handling if there | |
261 | is a problem with any of the arguments, but using an inferior | |
262 | function lets you have special-purpose printers and sending of | |
263 | output to the same place as compiled-in print functions. */ | |
264 | ||
265 | static const char dprintf_style_gdb[] = "gdb"; | |
266 | static const char dprintf_style_call[] = "call"; | |
267 | static const char dprintf_style_agent[] = "agent"; | |
268 | static const char *const dprintf_style_enums[] = { | |
269 | dprintf_style_gdb, | |
270 | dprintf_style_call, | |
271 | dprintf_style_agent, | |
272 | NULL | |
273 | }; | |
274 | static const char *dprintf_style = dprintf_style_gdb; | |
275 | ||
276 | /* The function to use for dynamic printf if the preferred style is to | |
277 | call into the inferior. The value is simply a string that is | |
278 | copied into the command, so it can be anything that GDB can | |
279 | evaluate to a callable address, not necessarily a function name. */ | |
280 | ||
bde6261a | 281 | static char *dprintf_function; |
d3ce09f5 SS |
282 | |
283 | /* The channel to use for dynamic printf if the preferred style is to | |
284 | call into the inferior; if a nonempty string, it will be passed to | |
285 | the call as the first argument, with the format string as the | |
286 | second. As with the dprintf function, this can be anything that | |
287 | GDB knows how to evaluate, so in addition to common choices like | |
288 | "stderr", this could be an app-specific expression like | |
289 | "mystreams[curlogger]". */ | |
290 | ||
bde6261a | 291 | static char *dprintf_channel; |
d3ce09f5 SS |
292 | |
293 | /* True if dprintf commands should continue to operate even if GDB | |
294 | has disconnected. */ | |
295 | static int disconnected_dprintf = 1; | |
296 | ||
5cea2a26 PA |
297 | struct command_line * |
298 | breakpoint_commands (struct breakpoint *b) | |
299 | { | |
d1b0a7bf | 300 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 301 | } |
3daf8fe5 | 302 | |
f3b1572e PA |
303 | /* Flag indicating that a command has proceeded the inferior past the |
304 | current breakpoint. */ | |
305 | ||
306 | static int breakpoint_proceeded; | |
307 | ||
956a9fb9 | 308 | const char * |
2cec12e5 AR |
309 | bpdisp_text (enum bpdisp disp) |
310 | { | |
4a64f543 MS |
311 | /* NOTE: the following values are a part of MI protocol and |
312 | represent values of 'disp' field returned when inferior stops at | |
313 | a breakpoint. */ | |
bc043ef3 | 314 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 315 | |
2cec12e5 AR |
316 | return bpdisps[(int) disp]; |
317 | } | |
c906108c | 318 | |
4a64f543 | 319 | /* Prototypes for exported functions. */ |
c906108c | 320 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 321 | if such is available. */ |
c906108c SS |
322 | static int can_use_hw_watchpoints; |
323 | ||
920d2a44 AC |
324 | static void |
325 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
326 | struct cmd_list_element *c, | |
327 | const char *value) | |
328 | { | |
3e43a32a MS |
329 | fprintf_filtered (file, |
330 | _("Debugger's willingness to use " | |
331 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
332 | value); |
333 | } | |
334 | ||
fa8d40ab JJ |
335 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
336 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 337 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
338 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
339 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
340 | static void |
341 | show_pending_break_support (struct ui_file *file, int from_tty, | |
342 | struct cmd_list_element *c, | |
343 | const char *value) | |
344 | { | |
3e43a32a MS |
345 | fprintf_filtered (file, |
346 | _("Debugger's behavior regarding " | |
347 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
348 | value); |
349 | } | |
fa8d40ab | 350 | |
765dc015 | 351 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 352 | set with "break" but falling in read-only memory. |
765dc015 VP |
353 | If 0, gdb will warn about such breakpoints, but won't automatically |
354 | use hardware breakpoints. */ | |
355 | static int automatic_hardware_breakpoints; | |
356 | static void | |
357 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
358 | struct cmd_list_element *c, | |
359 | const char *value) | |
360 | { | |
3e43a32a MS |
361 | fprintf_filtered (file, |
362 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
363 | value); |
364 | } | |
365 | ||
a25a5a45 PA |
366 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
367 | stopped, and immediately inserts any new breakpoints as soon as | |
368 | they're created. If off (default), GDB keeps breakpoints off of | |
369 | the target as long as possible. That is, it delays inserting | |
370 | breakpoints until the next resume, and removes them again when the | |
371 | target fully stops. This is a bit safer in case GDB crashes while | |
372 | processing user input. */ | |
373 | static int always_inserted_mode = 0; | |
72d0e2c5 | 374 | |
33e5cbd6 | 375 | static void |
74960c60 | 376 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 377 | struct cmd_list_element *c, const char *value) |
74960c60 | 378 | { |
a25a5a45 PA |
379 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
380 | value); | |
74960c60 VP |
381 | } |
382 | ||
b57bacec PA |
383 | /* See breakpoint.h. */ |
384 | ||
33e5cbd6 | 385 | int |
a25a5a45 | 386 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 387 | { |
a25a5a45 PA |
388 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
389 | { | |
390 | /* If breakpoints are global, they should be inserted even if no | |
391 | thread under gdb's control is running, or even if there are | |
392 | no threads under GDB's control yet. */ | |
393 | return 1; | |
394 | } | |
395 | else if (target_has_execution) | |
396 | { | |
a25a5a45 PA |
397 | if (always_inserted_mode) |
398 | { | |
399 | /* The user wants breakpoints inserted even if all threads | |
400 | are stopped. */ | |
401 | return 1; | |
402 | } | |
403 | ||
b57bacec PA |
404 | if (threads_are_executing ()) |
405 | return 1; | |
372316f1 PA |
406 | |
407 | /* Don't remove breakpoints yet if, even though all threads are | |
408 | stopped, we still have events to process. */ | |
08036331 | 409 | for (thread_info *tp : all_non_exited_threads ()) |
372316f1 PA |
410 | if (tp->resumed |
411 | && tp->suspend.waitstatus_pending_p) | |
412 | return 1; | |
a25a5a45 PA |
413 | } |
414 | return 0; | |
33e5cbd6 | 415 | } |
765dc015 | 416 | |
b775012e LM |
417 | static const char condition_evaluation_both[] = "host or target"; |
418 | ||
419 | /* Modes for breakpoint condition evaluation. */ | |
420 | static const char condition_evaluation_auto[] = "auto"; | |
421 | static const char condition_evaluation_host[] = "host"; | |
422 | static const char condition_evaluation_target[] = "target"; | |
423 | static const char *const condition_evaluation_enums[] = { | |
424 | condition_evaluation_auto, | |
425 | condition_evaluation_host, | |
426 | condition_evaluation_target, | |
427 | NULL | |
428 | }; | |
429 | ||
430 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
431 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
432 | ||
433 | /* Global that we use to display information to the user (gets its value from | |
434 | condition_evaluation_mode_1. */ | |
435 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
436 | ||
437 | /* Translate a condition evaluation mode MODE into either "host" | |
438 | or "target". This is used mostly to translate from "auto" to the | |
439 | real setting that is being used. It returns the translated | |
440 | evaluation mode. */ | |
441 | ||
442 | static const char * | |
443 | translate_condition_evaluation_mode (const char *mode) | |
444 | { | |
445 | if (mode == condition_evaluation_auto) | |
446 | { | |
447 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
448 | return condition_evaluation_target; | |
449 | else | |
450 | return condition_evaluation_host; | |
451 | } | |
452 | else | |
453 | return mode; | |
454 | } | |
455 | ||
456 | /* Discovers what condition_evaluation_auto translates to. */ | |
457 | ||
458 | static const char * | |
459 | breakpoint_condition_evaluation_mode (void) | |
460 | { | |
461 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
462 | } | |
463 | ||
464 | /* Return true if GDB should evaluate breakpoint conditions or false | |
465 | otherwise. */ | |
466 | ||
467 | static int | |
468 | gdb_evaluates_breakpoint_condition_p (void) | |
469 | { | |
470 | const char *mode = breakpoint_condition_evaluation_mode (); | |
471 | ||
472 | return (mode == condition_evaluation_host); | |
473 | } | |
474 | ||
c906108c SS |
475 | /* Are we executing breakpoint commands? */ |
476 | static int executing_breakpoint_commands; | |
477 | ||
c02f5703 MS |
478 | /* Are overlay event breakpoints enabled? */ |
479 | static int overlay_events_enabled; | |
480 | ||
e09342b5 TJB |
481 | /* See description in breakpoint.h. */ |
482 | int target_exact_watchpoints = 0; | |
483 | ||
c906108c | 484 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 485 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 486 | current breakpoint. */ |
c906108c | 487 | |
5c44784c | 488 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 489 | |
5c44784c JM |
490 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
491 | for (B = breakpoint_chain; \ | |
492 | B ? (TMP=B->next, 1): 0; \ | |
493 | B = TMP) | |
c906108c | 494 | |
4a64f543 MS |
495 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
496 | not provided so update_global_location_list must not be called | |
497 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 498 | |
876fa593 | 499 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
500 | for (BP_TMP = bp_locations; \ |
501 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 502 | BP_TMP++) |
7cc221ef | 503 | |
b775012e LM |
504 | /* Iterates through locations with address ADDRESS for the currently selected |
505 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
506 | to where the loop should start from. | |
507 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
508 | appropriate location to start with. */ | |
509 | ||
510 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
511 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
512 | BP_LOCP_TMP = BP_LOCP_START; \ | |
513 | BP_LOCP_START \ | |
f5336ca5 | 514 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
515 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
516 | BP_LOCP_TMP++) | |
517 | ||
1042e4c0 SS |
518 | /* Iterator for tracepoints only. */ |
519 | ||
520 | #define ALL_TRACEPOINTS(B) \ | |
521 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 522 | if (is_tracepoint (B)) |
1042e4c0 | 523 | |
7cc221ef | 524 | /* Chains of all breakpoints defined. */ |
c906108c SS |
525 | |
526 | struct breakpoint *breakpoint_chain; | |
527 | ||
f5336ca5 | 528 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 529 | |
f5336ca5 | 530 | static struct bp_location **bp_locations; |
876fa593 | 531 | |
f5336ca5 | 532 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 533 | |
f5336ca5 | 534 | static unsigned bp_locations_count; |
876fa593 | 535 | |
4a64f543 | 536 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 537 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 538 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 539 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 540 | an address you need to read. */ |
876fa593 | 541 | |
f5336ca5 | 542 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 543 | |
4a64f543 MS |
544 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
545 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
546 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
547 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 548 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 549 | |
f5336ca5 | 550 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 551 | |
4a64f543 | 552 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
553 | from the bp_locations array, but for which a hit may still be |
554 | reported by a target. */ | |
1123588c | 555 | static std::vector<bp_location *> moribund_locations; |
20874c92 | 556 | |
c906108c SS |
557 | /* Number of last breakpoint made. */ |
558 | ||
95a42b64 TT |
559 | static int breakpoint_count; |
560 | ||
86b17b60 PA |
561 | /* The value of `breakpoint_count' before the last command that |
562 | created breakpoints. If the last (break-like) command created more | |
563 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
564 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
565 | static int prev_breakpoint_count; | |
c906108c | 566 | |
1042e4c0 SS |
567 | /* Number of last tracepoint made. */ |
568 | ||
95a42b64 | 569 | static int tracepoint_count; |
1042e4c0 | 570 | |
6149aea9 PA |
571 | static struct cmd_list_element *breakpoint_set_cmdlist; |
572 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 573 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 574 | |
badd37ce SDJ |
575 | /* See declaration at breakpoint.h. */ |
576 | ||
577 | struct breakpoint * | |
578 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
579 | void *user_data) | |
580 | { | |
581 | struct breakpoint *b = NULL; | |
582 | ||
583 | ALL_BREAKPOINTS (b) | |
584 | { | |
585 | if (func (b, user_data) != 0) | |
586 | break; | |
587 | } | |
588 | ||
589 | return b; | |
590 | } | |
591 | ||
468d015d JJ |
592 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
593 | static int | |
594 | breakpoint_enabled (struct breakpoint *b) | |
595 | { | |
0d381245 | 596 | return (b->enable_state == bp_enabled); |
468d015d JJ |
597 | } |
598 | ||
c906108c SS |
599 | /* Set breakpoint count to NUM. */ |
600 | ||
95a42b64 | 601 | static void |
fba45db2 | 602 | set_breakpoint_count (int num) |
c906108c | 603 | { |
86b17b60 | 604 | prev_breakpoint_count = breakpoint_count; |
c906108c | 605 | breakpoint_count = num; |
4fa62494 | 606 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
607 | } |
608 | ||
86b17b60 PA |
609 | /* Used by `start_rbreak_breakpoints' below, to record the current |
610 | breakpoint count before "rbreak" creates any breakpoint. */ | |
611 | static int rbreak_start_breakpoint_count; | |
612 | ||
95a42b64 TT |
613 | /* Called at the start an "rbreak" command to record the first |
614 | breakpoint made. */ | |
86b17b60 | 615 | |
c80049d3 | 616 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 617 | { |
86b17b60 | 618 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
619 | } |
620 | ||
621 | /* Called at the end of an "rbreak" command to record the last | |
622 | breakpoint made. */ | |
86b17b60 | 623 | |
c80049d3 | 624 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 625 | { |
86b17b60 | 626 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
627 | } |
628 | ||
4a64f543 | 629 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
630 | |
631 | void | |
fba45db2 | 632 | clear_breakpoint_hit_counts (void) |
c906108c SS |
633 | { |
634 | struct breakpoint *b; | |
635 | ||
636 | ALL_BREAKPOINTS (b) | |
637 | b->hit_count = 0; | |
638 | } | |
639 | ||
c906108c | 640 | \f |
48cb2d85 VP |
641 | /* Return the breakpoint with the specified number, or NULL |
642 | if the number does not refer to an existing breakpoint. */ | |
643 | ||
644 | struct breakpoint * | |
645 | get_breakpoint (int num) | |
646 | { | |
647 | struct breakpoint *b; | |
648 | ||
649 | ALL_BREAKPOINTS (b) | |
650 | if (b->number == num) | |
651 | return b; | |
652 | ||
653 | return NULL; | |
654 | } | |
5c44784c | 655 | |
c906108c | 656 | \f |
adc36818 | 657 | |
b775012e LM |
658 | /* Mark locations as "conditions have changed" in case the target supports |
659 | evaluating conditions on its side. */ | |
660 | ||
661 | static void | |
662 | mark_breakpoint_modified (struct breakpoint *b) | |
663 | { | |
664 | struct bp_location *loc; | |
665 | ||
666 | /* This is only meaningful if the target is | |
667 | evaluating conditions and if the user has | |
668 | opted for condition evaluation on the target's | |
669 | side. */ | |
670 | if (gdb_evaluates_breakpoint_condition_p () | |
671 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
672 | return; | |
673 | ||
674 | if (!is_breakpoint (b)) | |
675 | return; | |
676 | ||
677 | for (loc = b->loc; loc; loc = loc->next) | |
678 | loc->condition_changed = condition_modified; | |
679 | } | |
680 | ||
681 | /* Mark location as "conditions have changed" in case the target supports | |
682 | evaluating conditions on its side. */ | |
683 | ||
684 | static void | |
685 | mark_breakpoint_location_modified (struct bp_location *loc) | |
686 | { | |
687 | /* This is only meaningful if the target is | |
688 | evaluating conditions and if the user has | |
689 | opted for condition evaluation on the target's | |
690 | side. */ | |
691 | if (gdb_evaluates_breakpoint_condition_p () | |
692 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
693 | ||
694 | return; | |
695 | ||
696 | if (!is_breakpoint (loc->owner)) | |
697 | return; | |
698 | ||
699 | loc->condition_changed = condition_modified; | |
700 | } | |
701 | ||
702 | /* Sets the condition-evaluation mode using the static global | |
703 | condition_evaluation_mode. */ | |
704 | ||
705 | static void | |
eb4c3f4a | 706 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
707 | struct cmd_list_element *c) |
708 | { | |
b775012e LM |
709 | const char *old_mode, *new_mode; |
710 | ||
711 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
712 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
713 | { | |
714 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
715 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
716 | "Using host evaluation mode instead.")); | |
717 | return; | |
718 | } | |
719 | ||
720 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
721 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
722 | ||
abf1152a JK |
723 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
724 | settings was "auto". */ | |
725 | condition_evaluation_mode = condition_evaluation_mode_1; | |
726 | ||
b775012e LM |
727 | /* Only update the mode if the user picked a different one. */ |
728 | if (new_mode != old_mode) | |
729 | { | |
730 | struct bp_location *loc, **loc_tmp; | |
731 | /* If the user switched to a different evaluation mode, we | |
732 | need to synch the changes with the target as follows: | |
733 | ||
734 | "host" -> "target": Send all (valid) conditions to the target. | |
735 | "target" -> "host": Remove all the conditions from the target. | |
736 | */ | |
737 | ||
b775012e LM |
738 | if (new_mode == condition_evaluation_target) |
739 | { | |
740 | /* Mark everything modified and synch conditions with the | |
741 | target. */ | |
742 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
743 | mark_breakpoint_location_modified (loc); | |
744 | } | |
745 | else | |
746 | { | |
747 | /* Manually mark non-duplicate locations to synch conditions | |
748 | with the target. We do this to remove all the conditions the | |
749 | target knows about. */ | |
750 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
751 | if (is_breakpoint (loc->owner) && loc->inserted) | |
752 | loc->needs_update = 1; | |
753 | } | |
754 | ||
755 | /* Do the update. */ | |
44702360 | 756 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
757 | } |
758 | ||
759 | return; | |
760 | } | |
761 | ||
762 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
763 | what "auto" is translating to. */ | |
764 | ||
765 | static void | |
766 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
767 | struct cmd_list_element *c, const char *value) | |
768 | { | |
769 | if (condition_evaluation_mode == condition_evaluation_auto) | |
770 | fprintf_filtered (file, | |
771 | _("Breakpoint condition evaluation " | |
772 | "mode is %s (currently %s).\n"), | |
773 | value, | |
774 | breakpoint_condition_evaluation_mode ()); | |
775 | else | |
776 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
777 | value); | |
778 | } | |
779 | ||
780 | /* A comparison function for bp_location AP and BP that is used by | |
781 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 782 | the more general bp_locations_compare function. */ |
b775012e LM |
783 | |
784 | static int | |
f5336ca5 | 785 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 786 | { |
9a3c8263 SM |
787 | const struct bp_location *a = *(const struct bp_location **) ap; |
788 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
789 | |
790 | if (a->address == b->address) | |
791 | return 0; | |
792 | else | |
793 | return ((a->address > b->address) - (a->address < b->address)); | |
794 | } | |
795 | ||
796 | /* Helper function to skip all bp_locations with addresses | |
797 | less than ADDRESS. It returns the first bp_location that | |
798 | is greater than or equal to ADDRESS. If none is found, just | |
799 | return NULL. */ | |
800 | ||
801 | static struct bp_location ** | |
802 | get_first_locp_gte_addr (CORE_ADDR address) | |
803 | { | |
804 | struct bp_location dummy_loc; | |
805 | struct bp_location *dummy_locp = &dummy_loc; | |
806 | struct bp_location **locp_found = NULL; | |
807 | ||
808 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
809 | dummy_loc.address = address; |
810 | ||
811 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 812 | locp_found = ((struct bp_location **) |
f5336ca5 | 813 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 814 | sizeof (struct bp_location **), |
f5336ca5 | 815 | bp_locations_compare_addrs)); |
b775012e LM |
816 | |
817 | /* Nothing was found, nothing left to do. */ | |
818 | if (locp_found == NULL) | |
819 | return NULL; | |
820 | ||
821 | /* We may have found a location that is at ADDRESS but is not the first in the | |
822 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 823 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
824 | && (*(locp_found - 1))->address == address) |
825 | locp_found--; | |
826 | ||
827 | return locp_found; | |
828 | } | |
829 | ||
adc36818 | 830 | void |
7a26bd4d | 831 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
832 | int from_tty) |
833 | { | |
3a5c3e22 PA |
834 | xfree (b->cond_string); |
835 | b->cond_string = NULL; | |
adc36818 | 836 | |
3a5c3e22 | 837 | if (is_watchpoint (b)) |
adc36818 | 838 | { |
3a5c3e22 PA |
839 | struct watchpoint *w = (struct watchpoint *) b; |
840 | ||
4d01a485 | 841 | w->cond_exp.reset (); |
3a5c3e22 PA |
842 | } |
843 | else | |
844 | { | |
845 | struct bp_location *loc; | |
846 | ||
847 | for (loc = b->loc; loc; loc = loc->next) | |
848 | { | |
4d01a485 | 849 | loc->cond.reset (); |
b775012e LM |
850 | |
851 | /* No need to free the condition agent expression | |
852 | bytecode (if we have one). We will handle this | |
853 | when we go through update_global_location_list. */ | |
3a5c3e22 | 854 | } |
adc36818 | 855 | } |
adc36818 PM |
856 | |
857 | if (*exp == 0) | |
858 | { | |
859 | if (from_tty) | |
860 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
861 | } | |
862 | else | |
863 | { | |
bbc13ae3 | 864 | const char *arg = exp; |
cc59ec59 | 865 | |
adc36818 PM |
866 | /* I don't know if it matters whether this is the string the user |
867 | typed in or the decompiled expression. */ | |
868 | b->cond_string = xstrdup (arg); | |
869 | b->condition_not_parsed = 0; | |
870 | ||
871 | if (is_watchpoint (b)) | |
872 | { | |
3a5c3e22 PA |
873 | struct watchpoint *w = (struct watchpoint *) b; |
874 | ||
699bd4cf | 875 | innermost_block_tracker tracker; |
adc36818 | 876 | arg = exp; |
699bd4cf | 877 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
adc36818 PM |
878 | if (*arg) |
879 | error (_("Junk at end of expression")); | |
699bd4cf | 880 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
881 | } |
882 | else | |
883 | { | |
3a5c3e22 PA |
884 | struct bp_location *loc; |
885 | ||
adc36818 PM |
886 | for (loc = b->loc; loc; loc = loc->next) |
887 | { | |
888 | arg = exp; | |
889 | loc->cond = | |
1bb9788d TT |
890 | parse_exp_1 (&arg, loc->address, |
891 | block_for_pc (loc->address), 0); | |
adc36818 PM |
892 | if (*arg) |
893 | error (_("Junk at end of expression")); | |
894 | } | |
895 | } | |
896 | } | |
b775012e LM |
897 | mark_breakpoint_modified (b); |
898 | ||
76727919 | 899 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
900 | } |
901 | ||
d55637df TT |
902 | /* Completion for the "condition" command. */ |
903 | ||
eb3ff9a5 | 904 | static void |
6f937416 | 905 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 906 | completion_tracker &tracker, |
6f937416 | 907 | const char *text, const char *word) |
d55637df | 908 | { |
6f937416 | 909 | const char *space; |
d55637df | 910 | |
f1735a53 TT |
911 | text = skip_spaces (text); |
912 | space = skip_to_space (text); | |
d55637df TT |
913 | if (*space == '\0') |
914 | { | |
915 | int len; | |
916 | struct breakpoint *b; | |
d55637df TT |
917 | |
918 | if (text[0] == '$') | |
919 | { | |
920 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
921 | if (!isdigit (text[1])) |
922 | complete_internalvar (tracker, &text[1]); | |
923 | return; | |
d55637df TT |
924 | } |
925 | ||
926 | /* We're completing the breakpoint number. */ | |
927 | len = strlen (text); | |
928 | ||
929 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
930 | { |
931 | char number[50]; | |
932 | ||
933 | xsnprintf (number, sizeof (number), "%d", b->number); | |
934 | ||
935 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 936 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 937 | } |
d55637df | 938 | |
eb3ff9a5 | 939 | return; |
d55637df TT |
940 | } |
941 | ||
942 | /* We're completing the expression part. */ | |
f1735a53 | 943 | text = skip_spaces (space); |
eb3ff9a5 | 944 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
945 | } |
946 | ||
c906108c SS |
947 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
948 | ||
949 | static void | |
0b39b52e | 950 | condition_command (const char *arg, int from_tty) |
c906108c | 951 | { |
52f0bd74 | 952 | struct breakpoint *b; |
0b39b52e | 953 | const char *p; |
52f0bd74 | 954 | int bnum; |
c906108c SS |
955 | |
956 | if (arg == 0) | |
e2e0b3e5 | 957 | error_no_arg (_("breakpoint number")); |
c906108c SS |
958 | |
959 | p = arg; | |
960 | bnum = get_number (&p); | |
5c44784c | 961 | if (bnum == 0) |
8a3fe4f8 | 962 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
963 | |
964 | ALL_BREAKPOINTS (b) | |
965 | if (b->number == bnum) | |
2f069f6f | 966 | { |
6dddc817 DE |
967 | /* Check if this breakpoint has a "stop" method implemented in an |
968 | extension language. This method and conditions entered into GDB | |
969 | from the CLI are mutually exclusive. */ | |
970 | const struct extension_language_defn *extlang | |
971 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
972 | ||
973 | if (extlang != NULL) | |
974 | { | |
975 | error (_("Only one stop condition allowed. There is currently" | |
976 | " a %s stop condition defined for this breakpoint."), | |
977 | ext_lang_capitalized_name (extlang)); | |
978 | } | |
2566ad2d | 979 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
980 | |
981 | if (is_breakpoint (b)) | |
44702360 | 982 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 983 | |
2f069f6f JB |
984 | return; |
985 | } | |
c906108c | 986 | |
8a3fe4f8 | 987 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
988 | } |
989 | ||
a7bdde9e VP |
990 | /* Check that COMMAND do not contain commands that are suitable |
991 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
992 | Throw if any such commands is found. */ |
993 | ||
a7bdde9e VP |
994 | static void |
995 | check_no_tracepoint_commands (struct command_line *commands) | |
996 | { | |
997 | struct command_line *c; | |
cc59ec59 | 998 | |
a7bdde9e VP |
999 | for (c = commands; c; c = c->next) |
1000 | { | |
a7bdde9e | 1001 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
1002 | error (_("The 'while-stepping' command can " |
1003 | "only be used for tracepoints")); | |
a7bdde9e | 1004 | |
12973681 TT |
1005 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1006 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1007 | |
1008 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1009 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1010 | command directly. */ |
1011 | if (strstr (c->line, "collect ") == c->line) | |
1012 | error (_("The 'collect' command can only be used for tracepoints")); | |
1013 | ||
51661e93 VP |
1014 | if (strstr (c->line, "teval ") == c->line) |
1015 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1016 | } |
1017 | } | |
1018 | ||
c1fc2657 | 1019 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1020 | { |
c1fc2657 | 1021 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1022 | }; |
1023 | ||
d77f58be SS |
1024 | /* Encapsulate tests for different types of tracepoints. */ |
1025 | ||
3b0871f4 SM |
1026 | static bool |
1027 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1028 | { |
1029 | return (type == bp_tracepoint | |
1030 | || type == bp_fast_tracepoint | |
1031 | || type == bp_static_tracepoint); | |
1032 | } | |
1033 | ||
3b0871f4 SM |
1034 | static bool |
1035 | is_longjmp_type (bptype type) | |
1036 | { | |
1037 | return type == bp_longjmp || type == bp_exception; | |
1038 | } | |
1039 | ||
a7bdde9e | 1040 | int |
d77f58be | 1041 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1042 | { |
d9b3f62e | 1043 | return is_tracepoint_type (b->type); |
a7bdde9e | 1044 | } |
d9b3f62e | 1045 | |
a5e364af SM |
1046 | /* Factory function to create an appropriate instance of breakpoint given |
1047 | TYPE. */ | |
1048 | ||
1049 | static std::unique_ptr<breakpoint> | |
1050 | new_breakpoint_from_type (bptype type) | |
1051 | { | |
1052 | breakpoint *b; | |
1053 | ||
1054 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1055 | b = new tracepoint (); |
3b0871f4 | 1056 | else if (is_longjmp_type (type)) |
c1fc2657 | 1057 | b = new longjmp_breakpoint (); |
a5e364af SM |
1058 | else |
1059 | b = new breakpoint (); | |
1060 | ||
1061 | return std::unique_ptr<breakpoint> (b); | |
1062 | } | |
1063 | ||
e5dd4106 | 1064 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1065 | breakpoint. This function will throw an exception if a problem is |
1066 | found. */ | |
48cb2d85 | 1067 | |
95a42b64 TT |
1068 | static void |
1069 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1070 | struct command_line *commands) | |
48cb2d85 | 1071 | { |
d77f58be | 1072 | if (is_tracepoint (b)) |
a7bdde9e | 1073 | { |
c9a6ce02 | 1074 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1075 | struct command_line *c; |
1076 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1077 | |
1078 | /* Reset the while-stepping step count. The previous commands | |
1079 | might have included a while-stepping action, while the new | |
1080 | ones might not. */ | |
1081 | t->step_count = 0; | |
1082 | ||
1083 | /* We need to verify that each top-level element of commands is | |
1084 | valid for tracepoints, that there's at most one | |
1085 | while-stepping element, and that the while-stepping's body | |
1086 | has valid tracing commands excluding nested while-stepping. | |
1087 | We also need to validate the tracepoint action line in the | |
1088 | context of the tracepoint --- validate_actionline actually | |
1089 | has side effects, like setting the tracepoint's | |
1090 | while-stepping STEP_COUNT, in addition to checking if the | |
1091 | collect/teval actions parse and make sense in the | |
1092 | tracepoint's context. */ | |
a7bdde9e VP |
1093 | for (c = commands; c; c = c->next) |
1094 | { | |
a7bdde9e VP |
1095 | if (c->control_type == while_stepping_control) |
1096 | { | |
1097 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1098 | error (_("The 'while-stepping' command " |
1099 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1100 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1101 | error (_("The 'while-stepping' command " |
1102 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1103 | |
1104 | if (while_stepping) | |
3e43a32a MS |
1105 | error (_("The 'while-stepping' command " |
1106 | "can be used only once")); | |
a7bdde9e VP |
1107 | else |
1108 | while_stepping = c; | |
1109 | } | |
c9a6ce02 PA |
1110 | |
1111 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1112 | } |
1113 | if (while_stepping) | |
1114 | { | |
1115 | struct command_line *c2; | |
1116 | ||
12973681 TT |
1117 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1118 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1119 | for (; c2; c2 = c2->next) |
1120 | { | |
a7bdde9e VP |
1121 | if (c2->control_type == while_stepping_control) |
1122 | error (_("The 'while-stepping' command cannot be nested")); | |
1123 | } | |
1124 | } | |
1125 | } | |
1126 | else | |
1127 | { | |
1128 | check_no_tracepoint_commands (commands); | |
1129 | } | |
95a42b64 TT |
1130 | } |
1131 | ||
0fb4aa4b PA |
1132 | /* Return a vector of all the static tracepoints set at ADDR. The |
1133 | caller is responsible for releasing the vector. */ | |
1134 | ||
f51e0e20 | 1135 | std::vector<breakpoint *> |
0fb4aa4b PA |
1136 | static_tracepoints_here (CORE_ADDR addr) |
1137 | { | |
1138 | struct breakpoint *b; | |
f51e0e20 | 1139 | std::vector<breakpoint *> found; |
0fb4aa4b PA |
1140 | struct bp_location *loc; |
1141 | ||
1142 | ALL_BREAKPOINTS (b) | |
1143 | if (b->type == bp_static_tracepoint) | |
1144 | { | |
1145 | for (loc = b->loc; loc; loc = loc->next) | |
1146 | if (loc->address == addr) | |
f51e0e20 | 1147 | found.push_back (b); |
0fb4aa4b PA |
1148 | } |
1149 | ||
1150 | return found; | |
1151 | } | |
1152 | ||
95a42b64 | 1153 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1154 | validate that only allowed commands are included. */ |
95a42b64 TT |
1155 | |
1156 | void | |
4a64f543 | 1157 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1158 | counted_command_line &&commands) |
95a42b64 | 1159 | { |
93921405 | 1160 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1161 | |
d1b0a7bf | 1162 | b->commands = std::move (commands); |
76727919 | 1163 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1164 | } |
1165 | ||
45a43567 TT |
1166 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1167 | is not the same as the "silent" that may appear in the breakpoint's | |
1168 | commands. */ | |
1169 | ||
1170 | void | |
1171 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1172 | { | |
1173 | int old_silent = b->silent; | |
1174 | ||
1175 | b->silent = silent; | |
1176 | if (old_silent != silent) | |
76727919 | 1177 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1178 | } |
1179 | ||
1180 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1181 | breakpoint work for any thread. */ | |
1182 | ||
1183 | void | |
1184 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1185 | { | |
1186 | int old_thread = b->thread; | |
1187 | ||
1188 | b->thread = thread; | |
1189 | if (old_thread != thread) | |
76727919 | 1190 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1191 | } |
1192 | ||
1193 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1194 | breakpoint work for any task. */ | |
1195 | ||
1196 | void | |
1197 | breakpoint_set_task (struct breakpoint *b, int task) | |
1198 | { | |
1199 | int old_task = b->task; | |
1200 | ||
1201 | b->task = task; | |
1202 | if (old_task != task) | |
76727919 | 1203 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1204 | } |
1205 | ||
95a42b64 | 1206 | static void |
896b6bda | 1207 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1208 | struct command_line *control) |
95a42b64 | 1209 | { |
d1b0a7bf | 1210 | counted_command_line cmd; |
999700cd PW |
1211 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1212 | NULL after the call to read_command_lines if the user provides an empty | |
1213 | list of command by just typing "end". */ | |
1214 | bool cmd_read = false; | |
95a42b64 | 1215 | |
896b6bda PA |
1216 | std::string new_arg; |
1217 | ||
95a42b64 TT |
1218 | if (arg == NULL || !*arg) |
1219 | { | |
86b17b60 | 1220 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1221 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1222 | breakpoint_count); | |
95a42b64 | 1223 | else if (breakpoint_count > 0) |
896b6bda | 1224 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1225 | arg = new_arg.c_str (); |
1226 | } | |
1227 | ||
1228 | map_breakpoint_numbers | |
1229 | (arg, [&] (breakpoint *b) | |
1230 | { | |
999700cd | 1231 | if (!cmd_read) |
48649e1b | 1232 | { |
999700cd | 1233 | gdb_assert (cmd == NULL); |
48649e1b | 1234 | if (control != NULL) |
12973681 | 1235 | cmd = control->body_list_0; |
48649e1b TT |
1236 | else |
1237 | { | |
81b1e71c TT |
1238 | std::string str |
1239 | = string_printf (_("Type commands for breakpoint(s) " | |
1240 | "%s, one per line."), | |
1241 | arg); | |
48649e1b | 1242 | |
60b3cef2 TT |
1243 | auto do_validate = [=] (const char *line) |
1244 | { | |
1245 | validate_actionline (line, b); | |
1246 | }; | |
1247 | gdb::function_view<void (const char *)> validator; | |
1248 | if (is_tracepoint (b)) | |
1249 | validator = do_validate; | |
1250 | ||
1251 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1252 | } |
999700cd | 1253 | cmd_read = true; |
48649e1b TT |
1254 | } |
1255 | ||
1256 | /* If a breakpoint was on the list more than once, we don't need to | |
1257 | do anything. */ | |
1258 | if (b->commands != cmd) | |
1259 | { | |
d1b0a7bf | 1260 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1261 | b->commands = cmd; |
76727919 | 1262 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1263 | } |
1264 | }); | |
95a42b64 TT |
1265 | } |
1266 | ||
1267 | static void | |
0b39b52e | 1268 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1269 | { |
1270 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1271 | } |
40c03ae8 EZ |
1272 | |
1273 | /* Like commands_command, but instead of reading the commands from | |
1274 | input stream, takes them from an already parsed command structure. | |
1275 | ||
1276 | This is used by cli-script.c to DTRT with breakpoint commands | |
1277 | that are part of if and while bodies. */ | |
1278 | enum command_control_type | |
896b6bda | 1279 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1280 | { |
95a42b64 TT |
1281 | commands_command_1 (arg, 0, cmd); |
1282 | return simple_control; | |
40c03ae8 | 1283 | } |
876fa593 JK |
1284 | |
1285 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1286 | ||
1287 | static int | |
1288 | bp_location_has_shadow (struct bp_location *bl) | |
1289 | { | |
1290 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1291 | return 0; | |
1292 | if (!bl->inserted) | |
1293 | return 0; | |
1294 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1295 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1296 | return 0; |
1297 | return 1; | |
1298 | } | |
1299 | ||
9d497a19 PA |
1300 | /* Update BUF, which is LEN bytes read from the target address |
1301 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1302 | contents. | |
1303 | ||
1304 | If READBUF is not NULL, this buffer must not overlap with the of | |
1305 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1306 | failed assertion internal error will be raised. */ | |
1307 | ||
1308 | static void | |
1309 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1310 | const gdb_byte *writebuf_org, | |
1311 | ULONGEST memaddr, LONGEST len, | |
1312 | struct bp_target_info *target_info, | |
1313 | struct gdbarch *gdbarch) | |
1314 | { | |
1315 | /* Now do full processing of the found relevant range of elements. */ | |
1316 | CORE_ADDR bp_addr = 0; | |
1317 | int bp_size = 0; | |
1318 | int bptoffset = 0; | |
1319 | ||
1320 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1321 | current_program_space->aspace, 0)) | |
1322 | { | |
1323 | /* The breakpoint is inserted in a different address space. */ | |
1324 | return; | |
1325 | } | |
1326 | ||
1327 | /* Addresses and length of the part of the breakpoint that | |
1328 | we need to copy. */ | |
1329 | bp_addr = target_info->placed_address; | |
1330 | bp_size = target_info->shadow_len; | |
1331 | ||
1332 | if (bp_addr + bp_size <= memaddr) | |
1333 | { | |
1334 | /* The breakpoint is entirely before the chunk of memory we are | |
1335 | reading. */ | |
1336 | return; | |
1337 | } | |
1338 | ||
1339 | if (bp_addr >= memaddr + len) | |
1340 | { | |
1341 | /* The breakpoint is entirely after the chunk of memory we are | |
1342 | reading. */ | |
1343 | return; | |
1344 | } | |
1345 | ||
1346 | /* Offset within shadow_contents. */ | |
1347 | if (bp_addr < memaddr) | |
1348 | { | |
1349 | /* Only copy the second part of the breakpoint. */ | |
1350 | bp_size -= memaddr - bp_addr; | |
1351 | bptoffset = memaddr - bp_addr; | |
1352 | bp_addr = memaddr; | |
1353 | } | |
1354 | ||
1355 | if (bp_addr + bp_size > memaddr + len) | |
1356 | { | |
1357 | /* Only copy the first part of the breakpoint. */ | |
1358 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1359 | } | |
1360 | ||
1361 | if (readbuf != NULL) | |
1362 | { | |
1363 | /* Verify that the readbuf buffer does not overlap with the | |
1364 | shadow_contents buffer. */ | |
1365 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1366 | || readbuf >= (target_info->shadow_contents | |
1367 | + target_info->shadow_len)); | |
1368 | ||
1369 | /* Update the read buffer with this inserted breakpoint's | |
1370 | shadow. */ | |
1371 | memcpy (readbuf + bp_addr - memaddr, | |
1372 | target_info->shadow_contents + bptoffset, bp_size); | |
1373 | } | |
1374 | else | |
1375 | { | |
1376 | const unsigned char *bp; | |
0d5ed153 MR |
1377 | CORE_ADDR addr = target_info->reqstd_address; |
1378 | int placed_size; | |
9d497a19 PA |
1379 | |
1380 | /* Update the shadow with what we want to write to memory. */ | |
1381 | memcpy (target_info->shadow_contents + bptoffset, | |
1382 | writebuf_org + bp_addr - memaddr, bp_size); | |
1383 | ||
1384 | /* Determine appropriate breakpoint contents and size for this | |
1385 | address. */ | |
0d5ed153 | 1386 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1387 | |
1388 | /* Update the final write buffer with this inserted | |
1389 | breakpoint's INSN. */ | |
1390 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1391 | } | |
1392 | } | |
1393 | ||
8defab1a | 1394 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1395 | by replacing any memory breakpoints with their shadowed contents. |
1396 | ||
35c63cd8 JB |
1397 | If READBUF is not NULL, this buffer must not overlap with any of |
1398 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1399 | a failed assertion internal error will be raised. | |
1400 | ||
876fa593 | 1401 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1402 | bl->address - bp_locations_placed_address_before_address_max |
1403 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1404 | The range we were requested to resolve shadows for is: |
1405 | memaddr ... memaddr + len | |
1406 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1407 | memaddr + len <= (bl->address |
f5336ca5 | 1408 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1409 | and: |
f5336ca5 | 1410 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1411 | |
8defab1a | 1412 | void |
f0ba3972 PA |
1413 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1414 | const gdb_byte *writebuf_org, | |
1415 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1416 | { |
4a64f543 MS |
1417 | /* Left boundary, right boundary and median element of our binary |
1418 | search. */ | |
876fa593 JK |
1419 | unsigned bc_l, bc_r, bc; |
1420 | ||
4a64f543 MS |
1421 | /* Find BC_L which is a leftmost element which may affect BUF |
1422 | content. It is safe to report lower value but a failure to | |
1423 | report higher one. */ | |
876fa593 JK |
1424 | |
1425 | bc_l = 0; | |
f5336ca5 | 1426 | bc_r = bp_locations_count; |
876fa593 JK |
1427 | while (bc_l + 1 < bc_r) |
1428 | { | |
35df4500 | 1429 | struct bp_location *bl; |
876fa593 JK |
1430 | |
1431 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1432 | bl = bp_locations[bc]; |
876fa593 | 1433 | |
4a64f543 MS |
1434 | /* Check first BL->ADDRESS will not overflow due to the added |
1435 | constant. Then advance the left boundary only if we are sure | |
1436 | the BC element can in no way affect the BUF content (MEMADDR | |
1437 | to MEMADDR + LEN range). | |
876fa593 | 1438 | |
f5336ca5 | 1439 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1440 | offset so that we cannot miss a breakpoint with its shadow |
1441 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1442 | |
f5336ca5 | 1443 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1444 | >= bl->address) |
f5336ca5 | 1445 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1446 | <= memaddr)) |
876fa593 JK |
1447 | bc_l = bc; |
1448 | else | |
1449 | bc_r = bc; | |
1450 | } | |
1451 | ||
128070bb PA |
1452 | /* Due to the binary search above, we need to make sure we pick the |
1453 | first location that's at BC_L's address. E.g., if there are | |
1454 | multiple locations at the same address, BC_L may end up pointing | |
1455 | at a duplicate location, and miss the "master"/"inserted" | |
1456 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1457 | B: | |
1458 | ||
1459 | L1@A, L2@A, L3@B, ... | |
1460 | ||
1461 | BC_L could end up pointing at location L2, while the "master" | |
1462 | location could be L1. Since the `loc->inserted' flag is only set | |
1463 | on "master" locations, we'd forget to restore the shadow of L1 | |
1464 | and L2. */ | |
1465 | while (bc_l > 0 | |
f5336ca5 | 1466 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1467 | bc_l--; |
1468 | ||
876fa593 JK |
1469 | /* Now do full processing of the found relevant range of elements. */ |
1470 | ||
f5336ca5 | 1471 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1472 | { |
f5336ca5 | 1473 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1474 | |
35df4500 TJB |
1475 | /* bp_location array has BL->OWNER always non-NULL. */ |
1476 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1477 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1478 | bl->owner->number); |
ffce0d52 | 1479 | |
e5dd4106 | 1480 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1481 | content. */ |
1482 | ||
f5336ca5 PA |
1483 | if (bl->address >= bp_locations_placed_address_before_address_max |
1484 | && memaddr + len <= (bl->address | |
1485 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1486 | break; |
1487 | ||
35df4500 | 1488 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1489 | continue; |
6c95b8df | 1490 | |
9d497a19 PA |
1491 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1492 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1493 | } | |
c906108c | 1494 | } |
9d497a19 | 1495 | |
c906108c | 1496 | \f |
c5aa993b | 1497 | |
b775012e LM |
1498 | /* Return true if BPT is either a software breakpoint or a hardware |
1499 | breakpoint. */ | |
1500 | ||
1501 | int | |
1502 | is_breakpoint (const struct breakpoint *bpt) | |
1503 | { | |
1504 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1505 | || bpt->type == bp_hardware_breakpoint |
1506 | || bpt->type == bp_dprintf); | |
b775012e LM |
1507 | } |
1508 | ||
60e1c644 PA |
1509 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1510 | ||
a5606eee | 1511 | static int |
d77f58be | 1512 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1513 | { |
1514 | return (bpt->type == bp_hardware_watchpoint | |
1515 | || bpt->type == bp_read_watchpoint | |
1516 | || bpt->type == bp_access_watchpoint); | |
1517 | } | |
7270d8f2 | 1518 | |
60e1c644 PA |
1519 | /* Return true if BPT is of any watchpoint kind, hardware or |
1520 | software. */ | |
1521 | ||
3a5c3e22 | 1522 | int |
d77f58be | 1523 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1524 | { |
1525 | return (is_hardware_watchpoint (bpt) | |
1526 | || bpt->type == bp_watchpoint); | |
1527 | } | |
1528 | ||
3a5c3e22 PA |
1529 | /* Returns true if the current thread and its running state are safe |
1530 | to evaluate or update watchpoint B. Watchpoints on local | |
1531 | expressions need to be evaluated in the context of the thread that | |
1532 | was current when the watchpoint was created, and, that thread needs | |
1533 | to be stopped to be able to select the correct frame context. | |
1534 | Watchpoints on global expressions can be evaluated on any thread, | |
1535 | and in any state. It is presently left to the target allowing | |
1536 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1537 | |
1538 | static int | |
3a5c3e22 | 1539 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1540 | { |
c1fc2657 | 1541 | return (b->pspace == current_program_space |
d7e15655 TT |
1542 | && (b->watchpoint_thread == null_ptid |
1543 | || (inferior_ptid == b->watchpoint_thread | |
00431a78 | 1544 | && !inferior_thread ()->executing))); |
f6bc2008 PA |
1545 | } |
1546 | ||
d0fb5eae JK |
1547 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1548 | associated bp_watchpoint_scope breakpoint. */ | |
1549 | ||
1550 | static void | |
3a5c3e22 | 1551 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1552 | { |
c1fc2657 | 1553 | if (w->related_breakpoint != w) |
d0fb5eae | 1554 | { |
c1fc2657 SM |
1555 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1556 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1557 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1558 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1559 | w->related_breakpoint = w; | |
d0fb5eae | 1560 | } |
c1fc2657 | 1561 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1562 | } |
1563 | ||
bb9d5f81 PP |
1564 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1565 | watchpoint W. */ | |
1566 | ||
1567 | static struct value * | |
1568 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1569 | { | |
1570 | struct value *bit_val; | |
1571 | ||
1572 | if (val == NULL) | |
1573 | return NULL; | |
1574 | ||
1575 | bit_val = allocate_value (value_type (val)); | |
1576 | ||
1577 | unpack_value_bitfield (bit_val, | |
1578 | w->val_bitpos, | |
1579 | w->val_bitsize, | |
1580 | value_contents_for_printing (val), | |
1581 | value_offset (val), | |
1582 | val); | |
1583 | ||
1584 | return bit_val; | |
1585 | } | |
1586 | ||
c6d81124 PA |
1587 | /* Allocate a dummy location and add it to B, which must be a software |
1588 | watchpoint. This is required because even if a software watchpoint | |
1589 | is not watching any memory, bpstat_stop_status requires a location | |
1590 | to be able to report stops. */ | |
1591 | ||
1592 | static void | |
1593 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1594 | struct program_space *pspace) | |
1595 | { | |
1596 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1597 | ||
1598 | b->loc = allocate_bp_location (b); | |
1599 | b->loc->pspace = pspace; | |
1600 | b->loc->address = -1; | |
1601 | b->loc->length = -1; | |
1602 | } | |
1603 | ||
1604 | /* Returns true if B is a software watchpoint that is not watching any | |
1605 | memory (e.g., "watch $pc"). */ | |
1606 | ||
1607 | static int | |
1608 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1609 | { | |
1610 | return (b->type == bp_watchpoint | |
1611 | && b->loc != NULL | |
1612 | && b->loc->next == NULL | |
1613 | && b->loc->address == -1 | |
1614 | && b->loc->length == -1); | |
1615 | } | |
1616 | ||
567e1b4e JB |
1617 | /* Assuming that B is a watchpoint: |
1618 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1619 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1620 | - Evaluate the condition if there is one, and store the result |
1621 | in b->loc->cond. | |
a5606eee VP |
1622 | - Update the list of values that must be watched in B->loc. |
1623 | ||
4a64f543 MS |
1624 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1625 | nothing. If this is local watchpoint that is out of scope, delete | |
1626 | it. | |
1627 | ||
1628 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1629 | removed + inserted on each stop here. Normal breakpoints must | |
1630 | never be removed because they might be missed by a running thread | |
1631 | when debugging in non-stop mode. On the other hand, hardware | |
1632 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1633 | to each LWP since they are stored in each LWP's hardware debug | |
1634 | registers. Therefore, such LWP must be stopped first in order to | |
1635 | be able to modify its hardware watchpoints. | |
1636 | ||
1637 | Hardware watchpoints must be reset exactly once after being | |
1638 | presented to the user. It cannot be done sooner, because it would | |
1639 | reset the data used to present the watchpoint hit to the user. And | |
1640 | it must not be done later because it could display the same single | |
1641 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1642 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1643 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1644 | not user-visible - its hit is suppressed if the memory content has | |
1645 | not changed. | |
1646 | ||
1647 | The following constraints influence the location where we can reset | |
1648 | hardware watchpoints: | |
1649 | ||
1650 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1651 | called several times when GDB stops. | |
1652 | ||
1653 | [linux] | |
1654 | * Multiple hardware watchpoints can be hit at the same time, | |
1655 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1656 | hit at a time as the reason for stopping, and all the other hits | |
1657 | are presented later, one after the other, each time the user | |
1658 | requests the execution to be resumed. Execution is not resumed | |
1659 | for the threads still having pending hit event stored in | |
1660 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1661 | the inferior on the first stop the thread hit event is kept being | |
1662 | reported from its cached value by linux_nat_stopped_data_address | |
1663 | until the real thread resume happens after the watchpoint gets | |
1664 | presented and thus its LWP_INFO->STATUS gets reset. | |
1665 | ||
1666 | Therefore the hardware watchpoint hit can get safely reset on the | |
1667 | watchpoint removal from inferior. */ | |
a79d3c27 | 1668 | |
b40ce68a | 1669 | static void |
3a5c3e22 | 1670 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1671 | { |
a5606eee | 1672 | int within_current_scope; |
a5606eee | 1673 | struct frame_id saved_frame_id; |
66076460 | 1674 | int frame_saved; |
a5606eee | 1675 | |
f6bc2008 PA |
1676 | /* If this is a local watchpoint, we only want to check if the |
1677 | watchpoint frame is in scope if the current thread is the thread | |
1678 | that was used to create the watchpoint. */ | |
1679 | if (!watchpoint_in_thread_scope (b)) | |
1680 | return; | |
1681 | ||
c1fc2657 | 1682 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1683 | return; |
1684 | ||
66076460 | 1685 | frame_saved = 0; |
a5606eee VP |
1686 | |
1687 | /* Determine if the watchpoint is within scope. */ | |
1688 | if (b->exp_valid_block == NULL) | |
1689 | within_current_scope = 1; | |
1690 | else | |
1691 | { | |
b5db5dfc UW |
1692 | struct frame_info *fi = get_current_frame (); |
1693 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1694 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1695 | ||
c9cf6e20 MG |
1696 | /* If we're at a point where the stack has been destroyed |
1697 | (e.g. in a function epilogue), unwinding may not work | |
1698 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1699 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1700 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1701 | return; |
66076460 DJ |
1702 | |
1703 | /* Save the current frame's ID so we can restore it after | |
1704 | evaluating the watchpoint expression on its own frame. */ | |
1705 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1706 | took a frame parameter, so that we didn't have to change the | |
1707 | selected frame. */ | |
1708 | frame_saved = 1; | |
1709 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1710 | ||
a5606eee VP |
1711 | fi = frame_find_by_id (b->watchpoint_frame); |
1712 | within_current_scope = (fi != NULL); | |
1713 | if (within_current_scope) | |
1714 | select_frame (fi); | |
1715 | } | |
1716 | ||
b5db5dfc UW |
1717 | /* We don't free locations. They are stored in the bp_location array |
1718 | and update_global_location_list will eventually delete them and | |
1719 | remove breakpoints if needed. */ | |
c1fc2657 | 1720 | b->loc = NULL; |
b5db5dfc | 1721 | |
a5606eee VP |
1722 | if (within_current_scope && reparse) |
1723 | { | |
bbc13ae3 | 1724 | const char *s; |
d63d0675 | 1725 | |
4d01a485 | 1726 | b->exp.reset (); |
d63d0675 | 1727 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1728 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1729 | /* If the meaning of expression itself changed, the old value is |
1730 | no longer relevant. We don't want to report a watchpoint hit | |
1731 | to the user when the old value and the new value may actually | |
1732 | be completely different objects. */ | |
fa4727a6 DJ |
1733 | b->val = NULL; |
1734 | b->val_valid = 0; | |
60e1c644 PA |
1735 | |
1736 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1737 | expression is stored in the breakpoint object, not in the | |
1738 | locations (re)created below. */ | |
c1fc2657 | 1739 | if (b->cond_string != NULL) |
60e1c644 | 1740 | { |
4d01a485 | 1741 | b->cond_exp.reset (); |
60e1c644 | 1742 | |
c1fc2657 | 1743 | s = b->cond_string; |
1bb9788d | 1744 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1745 | } |
a5606eee | 1746 | } |
a5606eee VP |
1747 | |
1748 | /* If we failed to parse the expression, for example because | |
1749 | it refers to a global variable in a not-yet-loaded shared library, | |
1750 | don't try to insert watchpoint. We don't automatically delete | |
1751 | such watchpoint, though, since failure to parse expression | |
1752 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1753 | if (!target_has_execution) |
2d134ed3 PA |
1754 | { |
1755 | /* Without execution, memory can't change. No use to try and | |
1756 | set watchpoint locations. The watchpoint will be reset when | |
1757 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1758 | if (!can_use_hw_watchpoints) |
1759 | { | |
c1fc2657 SM |
1760 | if (b->ops->works_in_software_mode (b)) |
1761 | b->type = bp_watchpoint; | |
e8369a73 | 1762 | else |
638aa5a1 AB |
1763 | error (_("Can't set read/access watchpoint when " |
1764 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1765 | } |
2d134ed3 PA |
1766 | } |
1767 | else if (within_current_scope && b->exp) | |
a5606eee | 1768 | { |
0cf6dd15 | 1769 | int pc = 0; |
a6535de1 | 1770 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 1771 | struct value *v, *result; |
2d134ed3 | 1772 | struct program_space *frame_pspace; |
a5606eee | 1773 | |
4d01a485 | 1774 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1775 | |
a5606eee VP |
1776 | /* Avoid setting b->val if it's already set. The meaning of |
1777 | b->val is 'the last value' user saw, and we should update | |
1778 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1779 | happens, the code that reports it updates b->val directly. |
1780 | We don't keep track of the memory value for masked | |
1781 | watchpoints. */ | |
c1fc2657 | 1782 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1783 | { |
bb9d5f81 | 1784 | if (b->val_bitsize != 0) |
850645cf TT |
1785 | v = extract_bitfield_from_watchpoint_value (b, v); |
1786 | b->val = release_value (v); | |
fa4727a6 DJ |
1787 | b->val_valid = 1; |
1788 | } | |
a5606eee | 1789 | |
2d134ed3 PA |
1790 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1791 | ||
a5606eee | 1792 | /* Look at each value on the value chain. */ |
a6535de1 TT |
1793 | gdb_assert (!val_chain.empty ()); |
1794 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 1795 | { |
a6535de1 TT |
1796 | v = iter.get (); |
1797 | ||
a5606eee VP |
1798 | /* If it's a memory location, and GDB actually needed |
1799 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1800 | must watch it. If the first value returned is |
1801 | still lazy, that means an error occurred reading it; | |
1802 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1803 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 1804 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
1805 | { |
1806 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1807 | |
a5606eee VP |
1808 | /* We only watch structs and arrays if user asked |
1809 | for it explicitly, never if they just happen to | |
1810 | appear in the middle of some value chain. */ | |
fa4727a6 | 1811 | if (v == result |
a5606eee VP |
1812 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1813 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1814 | { | |
1815 | CORE_ADDR addr; | |
f486487f | 1816 | enum target_hw_bp_type type; |
a5606eee | 1817 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1818 | int bitpos = 0, bitsize = 0; |
1819 | ||
1820 | if (value_bitsize (v) != 0) | |
1821 | { | |
1822 | /* Extract the bit parameters out from the bitfield | |
1823 | sub-expression. */ | |
1824 | bitpos = value_bitpos (v); | |
1825 | bitsize = value_bitsize (v); | |
1826 | } | |
1827 | else if (v == result && b->val_bitsize != 0) | |
1828 | { | |
1829 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1830 | lvalue whose bit parameters are saved in the fields | |
1831 | VAL_BITPOS and VAL_BITSIZE. */ | |
1832 | bitpos = b->val_bitpos; | |
1833 | bitsize = b->val_bitsize; | |
1834 | } | |
a5606eee | 1835 | |
42ae5230 | 1836 | addr = value_address (v); |
bb9d5f81 PP |
1837 | if (bitsize != 0) |
1838 | { | |
1839 | /* Skip the bytes that don't contain the bitfield. */ | |
1840 | addr += bitpos / 8; | |
1841 | } | |
1842 | ||
a5606eee | 1843 | type = hw_write; |
c1fc2657 | 1844 | if (b->type == bp_read_watchpoint) |
a5606eee | 1845 | type = hw_read; |
c1fc2657 | 1846 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1847 | type = hw_access; |
3a5c3e22 | 1848 | |
c1fc2657 SM |
1849 | loc = allocate_bp_location (b); |
1850 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1851 | ; |
1852 | *tmp = loc; | |
a6d9a66e | 1853 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1854 | |
1855 | loc->pspace = frame_pspace; | |
f17d9474 | 1856 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
1857 | |
1858 | if (bitsize != 0) | |
1859 | { | |
1860 | /* Just cover the bytes that make up the bitfield. */ | |
1861 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1862 | } | |
1863 | else | |
1864 | loc->length = TYPE_LENGTH (value_type (v)); | |
1865 | ||
a5606eee VP |
1866 | loc->watchpoint_type = type; |
1867 | } | |
1868 | } | |
9fa40276 TJB |
1869 | } |
1870 | ||
1871 | /* Change the type of breakpoint between hardware assisted or | |
1872 | an ordinary watchpoint depending on the hardware support | |
1873 | and free hardware slots. REPARSE is set when the inferior | |
1874 | is started. */ | |
a9634178 | 1875 | if (reparse) |
9fa40276 | 1876 | { |
e09342b5 | 1877 | int reg_cnt; |
9fa40276 TJB |
1878 | enum bp_loc_type loc_type; |
1879 | struct bp_location *bl; | |
a5606eee | 1880 | |
a9634178 | 1881 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1882 | |
1883 | if (reg_cnt) | |
9fa40276 TJB |
1884 | { |
1885 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1886 | enum bptype type; |
9fa40276 | 1887 | |
a9634178 TJB |
1888 | /* Use an exact watchpoint when there's only one memory region to be |
1889 | watched, and only one debug register is needed to watch it. */ | |
1890 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1891 | ||
9fa40276 | 1892 | /* We need to determine how many resources are already |
e09342b5 TJB |
1893 | used for all other hardware watchpoints plus this one |
1894 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1895 | this watchpoint in as well. */ |
1896 | ||
1897 | /* If this is a software watchpoint, we try to turn it | |
1898 | to a hardware one -- count resources as if B was of | |
1899 | hardware watchpoint type. */ | |
c1fc2657 | 1900 | type = b->type; |
a1398e0c PA |
1901 | if (type == bp_watchpoint) |
1902 | type = bp_hardware_watchpoint; | |
1903 | ||
1904 | /* This watchpoint may or may not have been placed on | |
1905 | the list yet at this point (it won't be in the list | |
1906 | if we're trying to create it for the first time, | |
1907 | through watch_command), so always account for it | |
1908 | manually. */ | |
1909 | ||
1910 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 1911 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
1912 | |
1913 | /* Add in the resources needed for B. */ | |
c1fc2657 | 1914 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
1915 | |
1916 | target_resources_ok | |
1917 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1918 | if (target_resources_ok <= 0) |
a9634178 | 1919 | { |
c1fc2657 | 1920 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
1921 | |
1922 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1923 | error (_("Target does not support this type of " |
1924 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1925 | else if (target_resources_ok < 0 && !sw_mode) |
1926 | error (_("There are not enough available hardware " | |
1927 | "resources for this watchpoint.")); | |
a1398e0c PA |
1928 | |
1929 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 1930 | b->type = bp_watchpoint; |
a1398e0c PA |
1931 | } |
1932 | else | |
1933 | { | |
1934 | /* If this was a software watchpoint, we've just | |
1935 | found we have enough resources to turn it to a | |
1936 | hardware watchpoint. Otherwise, this is a | |
1937 | nop. */ | |
c1fc2657 | 1938 | b->type = type; |
a9634178 | 1939 | } |
9fa40276 | 1940 | } |
c1fc2657 | 1941 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
1942 | { |
1943 | if (!can_use_hw_watchpoints) | |
1944 | error (_("Can't set read/access watchpoint when " | |
1945 | "hardware watchpoints are disabled.")); | |
1946 | else | |
1947 | error (_("Expression cannot be implemented with " | |
1948 | "read/access watchpoint.")); | |
1949 | } | |
9fa40276 | 1950 | else |
c1fc2657 | 1951 | b->type = bp_watchpoint; |
9fa40276 | 1952 | |
c1fc2657 | 1953 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 1954 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 1955 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
1956 | bl->loc_type = loc_type; |
1957 | } | |
1958 | ||
c7437ca6 PA |
1959 | /* If a software watchpoint is not watching any memory, then the |
1960 | above left it without any location set up. But, | |
1961 | bpstat_stop_status requires a location to be able to report | |
1962 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
1963 | if (b->type == bp_watchpoint && b->loc == NULL) |
1964 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
1965 | } |
1966 | else if (!within_current_scope) | |
7270d8f2 | 1967 | { |
ac74f770 MS |
1968 | printf_filtered (_("\ |
1969 | Watchpoint %d deleted because the program has left the block\n\ | |
1970 | in which its expression is valid.\n"), | |
c1fc2657 | 1971 | b->number); |
d0fb5eae | 1972 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1973 | } |
a5606eee VP |
1974 | |
1975 | /* Restore the selected frame. */ | |
66076460 DJ |
1976 | if (frame_saved) |
1977 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1978 | } |
1979 | ||
a5606eee | 1980 | |
74960c60 | 1981 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1982 | inserted in the inferior. We don't differentiate the type of BL's owner |
1983 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1984 | breakpoint_ops is not defined, because in insert_bp_location, | |
1985 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1986 | static int |
35df4500 | 1987 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1988 | { |
35df4500 | 1989 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1990 | return 0; |
1991 | ||
35df4500 | 1992 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1993 | return 0; |
1994 | ||
35df4500 | 1995 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1996 | return 0; |
1997 | ||
f8eba3c6 TT |
1998 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1999 | return 0; | |
2000 | ||
56710373 PA |
2001 | /* This is set for example, when we're attached to the parent of a |
2002 | vfork, and have detached from the child. The child is running | |
2003 | free, and we expect it to do an exec or exit, at which point the | |
2004 | OS makes the parent schedulable again (and the target reports | |
2005 | that the vfork is done). Until the child is done with the shared | |
2006 | memory region, do not insert breakpoints in the parent, otherwise | |
2007 | the child could still trip on the parent's breakpoints. Since | |
2008 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2009 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2010 | return 0; |
2011 | ||
31e77af2 | 2012 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2013 | location, except if the breakpoint is a single-step breakpoint, |
2014 | and the breakpoint's thread is the thread which is stepping past | |
2015 | a breakpoint. */ | |
31e77af2 PA |
2016 | if ((bl->loc_type == bp_loc_software_breakpoint |
2017 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2018 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2019 | bl->address) |
2020 | /* The single-step breakpoint may be inserted at the location | |
2021 | we're trying to step if the instruction branches to itself. | |
2022 | However, the instruction won't be executed at all and it may | |
2023 | break the semantics of the instruction, for example, the | |
2024 | instruction is a conditional branch or updates some flags. | |
2025 | We can't fix it unless GDB is able to emulate the instruction | |
2026 | or switch to displaced stepping. */ | |
2027 | && !(bl->owner->type == bp_single_step | |
2028 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2029 | { |
2030 | if (debug_infrun) | |
2031 | { | |
2032 | fprintf_unfiltered (gdb_stdlog, | |
2033 | "infrun: skipping breakpoint: " | |
2034 | "stepping past insn at: %s\n", | |
2035 | paddress (bl->gdbarch, bl->address)); | |
2036 | } | |
2037 | return 0; | |
2038 | } | |
31e77af2 | 2039 | |
963f9c80 PA |
2040 | /* Don't insert watchpoints if we're trying to step past the |
2041 | instruction that triggered one. */ | |
2042 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2043 | && stepping_past_nonsteppable_watchpoint ()) | |
2044 | { | |
2045 | if (debug_infrun) | |
2046 | { | |
2047 | fprintf_unfiltered (gdb_stdlog, | |
2048 | "infrun: stepping past non-steppable watchpoint. " | |
2049 | "skipping watchpoint at %s:%d\n", | |
2050 | paddress (bl->gdbarch, bl->address), | |
2051 | bl->length); | |
2052 | } | |
2053 | return 0; | |
2054 | } | |
2055 | ||
74960c60 VP |
2056 | return 1; |
2057 | } | |
2058 | ||
934709f0 PW |
2059 | /* Same as should_be_inserted but does the check assuming |
2060 | that the location is not duplicated. */ | |
2061 | ||
2062 | static int | |
2063 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2064 | { | |
2065 | int result; | |
2066 | const int save_duplicate = bl->duplicate; | |
2067 | ||
2068 | bl->duplicate = 0; | |
2069 | result = should_be_inserted (bl); | |
2070 | bl->duplicate = save_duplicate; | |
2071 | return result; | |
2072 | } | |
2073 | ||
b775012e LM |
2074 | /* Parses a conditional described by an expression COND into an |
2075 | agent expression bytecode suitable for evaluation | |
2076 | by the bytecode interpreter. Return NULL if there was | |
2077 | any error during parsing. */ | |
2078 | ||
833177a4 | 2079 | static agent_expr_up |
b775012e LM |
2080 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2081 | { | |
833177a4 | 2082 | if (cond == NULL) |
b775012e LM |
2083 | return NULL; |
2084 | ||
833177a4 PA |
2085 | agent_expr_up aexpr; |
2086 | ||
b775012e LM |
2087 | /* We don't want to stop processing, so catch any errors |
2088 | that may show up. */ | |
a70b8144 | 2089 | try |
b775012e | 2090 | { |
036e657b | 2091 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2092 | } |
2093 | ||
230d2906 | 2094 | catch (const gdb_exception_error &ex) |
b775012e LM |
2095 | { |
2096 | /* If we got here, it means the condition could not be parsed to a valid | |
2097 | bytecode expression and thus can't be evaluated on the target's side. | |
2098 | It's no use iterating through the conditions. */ | |
b775012e LM |
2099 | } |
2100 | ||
2101 | /* We have a valid agent expression. */ | |
2102 | return aexpr; | |
2103 | } | |
2104 | ||
2105 | /* Based on location BL, create a list of breakpoint conditions to be | |
2106 | passed on to the target. If we have duplicated locations with different | |
2107 | conditions, we will add such conditions to the list. The idea is that the | |
2108 | target will evaluate the list of conditions and will only notify GDB when | |
2109 | one of them is true. */ | |
2110 | ||
2111 | static void | |
2112 | build_target_condition_list (struct bp_location *bl) | |
2113 | { | |
2114 | struct bp_location **locp = NULL, **loc2p; | |
2115 | int null_condition_or_parse_error = 0; | |
2116 | int modified = bl->needs_update; | |
2117 | struct bp_location *loc; | |
2118 | ||
8b4f3082 | 2119 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2120 | bl->target_info.conditions.clear (); |
8b4f3082 | 2121 | |
b775012e LM |
2122 | /* This is only meaningful if the target is |
2123 | evaluating conditions and if the user has | |
2124 | opted for condition evaluation on the target's | |
2125 | side. */ | |
2126 | if (gdb_evaluates_breakpoint_condition_p () | |
2127 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2128 | return; | |
2129 | ||
2130 | /* Do a first pass to check for locations with no assigned | |
2131 | conditions or conditions that fail to parse to a valid agent expression | |
2132 | bytecode. If any of these happen, then it's no use to send conditions | |
2133 | to the target since this location will always trigger and generate a | |
2134 | response back to GDB. */ | |
2135 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2136 | { | |
2137 | loc = (*loc2p); | |
2138 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2139 | { | |
2140 | if (modified) | |
2141 | { | |
b775012e LM |
2142 | /* Re-parse the conditions since something changed. In that |
2143 | case we already freed the condition bytecodes (see | |
2144 | force_breakpoint_reinsertion). We just | |
2145 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2146 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2147 | loc->cond.get ()); | |
b775012e LM |
2148 | } |
2149 | ||
2150 | /* If we have a NULL bytecode expression, it means something | |
2151 | went wrong or we have a null condition expression. */ | |
2152 | if (!loc->cond_bytecode) | |
2153 | { | |
2154 | null_condition_or_parse_error = 1; | |
2155 | break; | |
2156 | } | |
2157 | } | |
2158 | } | |
2159 | ||
2160 | /* If any of these happened, it means we will have to evaluate the conditions | |
2161 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2162 | for all the other duplicate locations, thus we free all of them here. | |
2163 | ||
2164 | This is so we have a finer control over which locations' conditions are | |
2165 | being evaluated by GDB or the remote stub. */ | |
2166 | if (null_condition_or_parse_error) | |
2167 | { | |
2168 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2169 | { | |
2170 | loc = (*loc2p); | |
2171 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2172 | { | |
2173 | /* Only go as far as the first NULL bytecode is | |
2174 | located. */ | |
2175 | if (!loc->cond_bytecode) | |
2176 | return; | |
2177 | ||
833177a4 | 2178 | loc->cond_bytecode.reset (); |
b775012e LM |
2179 | } |
2180 | } | |
2181 | } | |
2182 | ||
2183 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2184 | for this location's address. */ | |
2185 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2186 | { | |
2187 | loc = (*loc2p); | |
2188 | if (loc->cond | |
2189 | && is_breakpoint (loc->owner) | |
2190 | && loc->pspace->num == bl->pspace->num | |
2191 | && loc->owner->enable_state == bp_enabled | |
2192 | && loc->enabled) | |
3cde5c42 PA |
2193 | { |
2194 | /* Add the condition to the vector. This will be used later | |
2195 | to send the conditions to the target. */ | |
2196 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2197 | } | |
b775012e LM |
2198 | } |
2199 | ||
2200 | return; | |
2201 | } | |
2202 | ||
d3ce09f5 SS |
2203 | /* Parses a command described by string CMD into an agent expression |
2204 | bytecode suitable for evaluation by the bytecode interpreter. | |
2205 | Return NULL if there was any error during parsing. */ | |
2206 | ||
833177a4 | 2207 | static agent_expr_up |
d3ce09f5 SS |
2208 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2209 | { | |
bbc13ae3 KS |
2210 | const char *cmdrest; |
2211 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2212 | struct gdbarch *gdbarch = get_current_arch (); |
2213 | ||
833177a4 | 2214 | if (cmd == NULL) |
d3ce09f5 SS |
2215 | return NULL; |
2216 | ||
2217 | cmdrest = cmd; | |
2218 | ||
2219 | if (*cmdrest == ',') | |
2220 | ++cmdrest; | |
f1735a53 | 2221 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2222 | |
2223 | if (*cmdrest++ != '"') | |
2224 | error (_("No format string following the location")); | |
2225 | ||
2226 | format_start = cmdrest; | |
2227 | ||
8e481c3b | 2228 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2229 | |
2230 | format_end = cmdrest; | |
2231 | ||
2232 | if (*cmdrest++ != '"') | |
2233 | error (_("Bad format string, non-terminated '\"'.")); | |
2234 | ||
f1735a53 | 2235 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2236 | |
2237 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2238 | error (_("Invalid argument syntax")); | |
2239 | ||
2240 | if (*cmdrest == ',') | |
2241 | cmdrest++; | |
f1735a53 | 2242 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2243 | |
2244 | /* For each argument, make an expression. */ | |
2245 | ||
8e481c3b | 2246 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2247 | while (*cmdrest != '\0') |
2248 | { | |
bbc13ae3 | 2249 | const char *cmd1; |
d3ce09f5 SS |
2250 | |
2251 | cmd1 = cmdrest; | |
4d01a485 | 2252 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2253 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2254 | cmdrest = cmd1; |
2255 | if (*cmdrest == ',') | |
2256 | ++cmdrest; | |
2257 | } | |
2258 | ||
833177a4 PA |
2259 | agent_expr_up aexpr; |
2260 | ||
d3ce09f5 SS |
2261 | /* We don't want to stop processing, so catch any errors |
2262 | that may show up. */ | |
a70b8144 | 2263 | try |
d3ce09f5 | 2264 | { |
036e657b JB |
2265 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2266 | format_start, format_end - format_start, | |
8e481c3b | 2267 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2268 | } |
230d2906 | 2269 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2270 | { |
2271 | /* If we got here, it means the command could not be parsed to a valid | |
2272 | bytecode expression and thus can't be evaluated on the target's side. | |
2273 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2274 | } |
492d29ea | 2275 | |
d3ce09f5 SS |
2276 | /* We have a valid agent expression, return it. */ |
2277 | return aexpr; | |
2278 | } | |
2279 | ||
2280 | /* Based on location BL, create a list of breakpoint commands to be | |
2281 | passed on to the target. If we have duplicated locations with | |
2282 | different commands, we will add any such to the list. */ | |
2283 | ||
2284 | static void | |
2285 | build_target_command_list (struct bp_location *bl) | |
2286 | { | |
2287 | struct bp_location **locp = NULL, **loc2p; | |
2288 | int null_command_or_parse_error = 0; | |
2289 | int modified = bl->needs_update; | |
2290 | struct bp_location *loc; | |
2291 | ||
3cde5c42 PA |
2292 | /* Clear commands left over from a previous insert. */ |
2293 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2294 | |
41fac0cf | 2295 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2296 | return; |
2297 | ||
41fac0cf PA |
2298 | /* For now, limit to agent-style dprintf breakpoints. */ |
2299 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2300 | return; |
2301 | ||
41fac0cf PA |
2302 | /* For now, if we have any duplicate location that isn't a dprintf, |
2303 | don't install the target-side commands, as that would make the | |
2304 | breakpoint not be reported to the core, and we'd lose | |
2305 | control. */ | |
2306 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2307 | { | |
2308 | loc = (*loc2p); | |
2309 | if (is_breakpoint (loc->owner) | |
2310 | && loc->pspace->num == bl->pspace->num | |
2311 | && loc->owner->type != bp_dprintf) | |
2312 | return; | |
2313 | } | |
2314 | ||
d3ce09f5 SS |
2315 | /* Do a first pass to check for locations with no assigned |
2316 | conditions or conditions that fail to parse to a valid agent expression | |
2317 | bytecode. If any of these happen, then it's no use to send conditions | |
2318 | to the target since this location will always trigger and generate a | |
2319 | response back to GDB. */ | |
2320 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2321 | { | |
2322 | loc = (*loc2p); | |
2323 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2324 | { | |
2325 | if (modified) | |
2326 | { | |
d3ce09f5 SS |
2327 | /* Re-parse the commands since something changed. In that |
2328 | case we already freed the command bytecodes (see | |
2329 | force_breakpoint_reinsertion). We just | |
2330 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2331 | loc->cmd_bytecode |
2332 | = parse_cmd_to_aexpr (bl->address, | |
2333 | loc->owner->extra_string); | |
d3ce09f5 SS |
2334 | } |
2335 | ||
2336 | /* If we have a NULL bytecode expression, it means something | |
2337 | went wrong or we have a null command expression. */ | |
2338 | if (!loc->cmd_bytecode) | |
2339 | { | |
2340 | null_command_or_parse_error = 1; | |
2341 | break; | |
2342 | } | |
2343 | } | |
2344 | } | |
2345 | ||
2346 | /* If anything failed, then we're not doing target-side commands, | |
2347 | and so clean up. */ | |
2348 | if (null_command_or_parse_error) | |
2349 | { | |
2350 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2351 | { | |
2352 | loc = (*loc2p); | |
2353 | if (is_breakpoint (loc->owner) | |
2354 | && loc->pspace->num == bl->pspace->num) | |
2355 | { | |
2356 | /* Only go as far as the first NULL bytecode is | |
2357 | located. */ | |
40fb6c5e | 2358 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2359 | return; |
2360 | ||
833177a4 | 2361 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2362 | } |
2363 | } | |
2364 | } | |
2365 | ||
2366 | /* No NULL commands or failed bytecode generation. Build a command list | |
2367 | for this location's address. */ | |
2368 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2369 | { | |
2370 | loc = (*loc2p); | |
2371 | if (loc->owner->extra_string | |
2372 | && is_breakpoint (loc->owner) | |
2373 | && loc->pspace->num == bl->pspace->num | |
2374 | && loc->owner->enable_state == bp_enabled | |
2375 | && loc->enabled) | |
3cde5c42 PA |
2376 | { |
2377 | /* Add the command to the vector. This will be used later | |
2378 | to send the commands to the target. */ | |
2379 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2380 | } | |
d3ce09f5 SS |
2381 | } |
2382 | ||
2383 | bl->target_info.persist = 0; | |
2384 | /* Maybe flag this location as persistent. */ | |
2385 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2386 | bl->target_info.persist = 1; | |
2387 | } | |
2388 | ||
833b7ab5 YQ |
2389 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2390 | of breakpoint according to ADDR except single-step breakpoint. | |
2391 | Get the kind of single-step breakpoint according to the current | |
2392 | registers state. */ | |
cd6c3b4f YQ |
2393 | |
2394 | static int | |
2395 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2396 | { | |
833b7ab5 YQ |
2397 | if (bl->owner->type == bp_single_step) |
2398 | { | |
2399 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2400 | struct regcache *regcache; | |
2401 | ||
00431a78 | 2402 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2403 | |
2404 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2405 | regcache, addr); | |
2406 | } | |
2407 | else | |
2408 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2409 | } |
2410 | ||
35df4500 TJB |
2411 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2412 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2413 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2414 | Returns 0 for success, 1 if the bp_location type is not supported or |
2415 | -1 for failure. | |
879bfdc2 | 2416 | |
4a64f543 MS |
2417 | NOTE drow/2003-09-09: This routine could be broken down to an |
2418 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2419 | static int |
35df4500 | 2420 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2421 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2422 | int *disabled_breaks, |
dd61ec5c MW |
2423 | int *hw_breakpoint_error, |
2424 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2425 | { |
cc06b668 | 2426 | gdb_exception bp_excpt; |
879bfdc2 | 2427 | |
b775012e | 2428 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2429 | return 0; |
2430 | ||
35c63cd8 JB |
2431 | /* Note we don't initialize bl->target_info, as that wipes out |
2432 | the breakpoint location's shadow_contents if the breakpoint | |
2433 | is still inserted at that location. This in turn breaks | |
2434 | target_read_memory which depends on these buffers when | |
2435 | a memory read is requested at the breakpoint location: | |
2436 | Once the target_info has been wiped, we fail to see that | |
2437 | we have a breakpoint inserted at that address and thus | |
2438 | read the breakpoint instead of returning the data saved in | |
2439 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2440 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2441 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2442 | bl->target_info.length = bl->length; |
8181d85f | 2443 | |
b775012e LM |
2444 | /* When working with target-side conditions, we must pass all the conditions |
2445 | for the same breakpoint address down to the target since GDB will not | |
2446 | insert those locations. With a list of breakpoint conditions, the target | |
2447 | can decide when to stop and notify GDB. */ | |
2448 | ||
2449 | if (is_breakpoint (bl->owner)) | |
2450 | { | |
2451 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2452 | build_target_command_list (bl); |
2453 | /* Reset the modification marker. */ | |
b775012e LM |
2454 | bl->needs_update = 0; |
2455 | } | |
2456 | ||
35df4500 TJB |
2457 | if (bl->loc_type == bp_loc_software_breakpoint |
2458 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2459 | { |
35df4500 | 2460 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2461 | { |
2462 | /* If the explicitly specified breakpoint type | |
2463 | is not hardware breakpoint, check the memory map to see | |
2464 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2465 | |
765dc015 VP |
2466 | Two important cases are: |
2467 | - location type is not hardware breakpoint, memory | |
2468 | is readonly. We change the type of the location to | |
2469 | hardware breakpoint. | |
4a64f543 MS |
2470 | - location type is hardware breakpoint, memory is |
2471 | read-write. This means we've previously made the | |
2472 | location hardware one, but then the memory map changed, | |
2473 | so we undo. | |
765dc015 | 2474 | |
4a64f543 MS |
2475 | When breakpoints are removed, remove_breakpoints will use |
2476 | location types we've just set here, the only possible | |
2477 | problem is that memory map has changed during running | |
2478 | program, but it's not going to work anyway with current | |
2479 | gdb. */ | |
765dc015 | 2480 | struct mem_region *mr |
0d5ed153 | 2481 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2482 | |
2483 | if (mr) | |
2484 | { | |
2485 | if (automatic_hardware_breakpoints) | |
2486 | { | |
765dc015 VP |
2487 | enum bp_loc_type new_type; |
2488 | ||
2489 | if (mr->attrib.mode != MEM_RW) | |
2490 | new_type = bp_loc_hardware_breakpoint; | |
2491 | else | |
2492 | new_type = bp_loc_software_breakpoint; | |
2493 | ||
35df4500 | 2494 | if (new_type != bl->loc_type) |
765dc015 VP |
2495 | { |
2496 | static int said = 0; | |
cc59ec59 | 2497 | |
35df4500 | 2498 | bl->loc_type = new_type; |
765dc015 VP |
2499 | if (!said) |
2500 | { | |
3e43a32a MS |
2501 | fprintf_filtered (gdb_stdout, |
2502 | _("Note: automatically using " | |
2503 | "hardware breakpoints for " | |
2504 | "read-only addresses.\n")); | |
765dc015 VP |
2505 | said = 1; |
2506 | } | |
2507 | } | |
2508 | } | |
35df4500 | 2509 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2510 | && mr->attrib.mode != MEM_RW) |
2511 | { | |
2512 | fprintf_unfiltered (tmp_error_stream, | |
2513 | _("Cannot insert breakpoint %d.\n" | |
2514 | "Cannot set software breakpoint " | |
2515 | "at read-only address %s\n"), | |
2516 | bl->owner->number, | |
2517 | paddress (bl->gdbarch, bl->address)); | |
2518 | return 1; | |
2519 | } | |
765dc015 VP |
2520 | } |
2521 | } | |
2522 | ||
879bfdc2 DJ |
2523 | /* First check to see if we have to handle an overlay. */ |
2524 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2525 | || bl->section == NULL |
2526 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2527 | { |
2528 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2529 | try |
dd61ec5c | 2530 | { |
0000e5cc PA |
2531 | int val; |
2532 | ||
dd61ec5c | 2533 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2534 | if (val) |
688fca4f | 2535 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2536 | } |
94aeb44b | 2537 | catch (gdb_exception &e) |
dd61ec5c | 2538 | { |
94aeb44b | 2539 | bp_excpt = std::move (e); |
dd61ec5c | 2540 | } |
879bfdc2 DJ |
2541 | } |
2542 | else | |
2543 | { | |
4a64f543 | 2544 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2545 | Shall we set a breakpoint at the LMA? */ |
2546 | if (!overlay_events_enabled) | |
2547 | { | |
2548 | /* Yes -- overlay event support is not active, | |
2549 | so we must try to set a breakpoint at the LMA. | |
2550 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2551 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2552 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2553 | bl->owner->number); |
879bfdc2 DJ |
2554 | else |
2555 | { | |
35df4500 TJB |
2556 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2557 | bl->section); | |
879bfdc2 | 2558 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2559 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2560 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2561 | |
2562 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2563 | try |
0000e5cc PA |
2564 | { |
2565 | int val; | |
2566 | ||
579c6ad9 | 2567 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2568 | = breakpoint_kind (bl, &addr); |
2569 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2570 | val = target_insert_breakpoint (bl->gdbarch, |
2571 | &bl->overlay_target_info); | |
2572 | if (val) | |
688fca4f PA |
2573 | bp_excpt |
2574 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2575 | } |
94aeb44b | 2576 | catch (gdb_exception &e) |
0000e5cc | 2577 | { |
94aeb44b | 2578 | bp_excpt = std::move (e); |
0000e5cc PA |
2579 | } |
2580 | ||
688fca4f | 2581 | if (bp_excpt.reason != 0) |
99361f52 | 2582 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2583 | "Overlay breakpoint %d " |
2584 | "failed: in ROM?\n", | |
35df4500 | 2585 | bl->owner->number); |
879bfdc2 DJ |
2586 | } |
2587 | } | |
2588 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2589 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2590 | { |
2591 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2592 | try |
dd61ec5c | 2593 | { |
0000e5cc PA |
2594 | int val; |
2595 | ||
dd61ec5c | 2596 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2597 | if (val) |
688fca4f | 2598 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2599 | } |
94aeb44b | 2600 | catch (gdb_exception &e) |
dd61ec5c | 2601 | { |
94aeb44b | 2602 | bp_excpt = std::move (e); |
dd61ec5c | 2603 | } |
879bfdc2 DJ |
2604 | } |
2605 | else | |
2606 | { | |
2607 | /* No. This breakpoint will not be inserted. | |
2608 | No error, but do not mark the bp as 'inserted'. */ | |
2609 | return 0; | |
2610 | } | |
2611 | } | |
2612 | ||
688fca4f | 2613 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2614 | { |
2615 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2616 | |
2617 | /* In some cases, we might not be able to insert a | |
2618 | breakpoint in a shared library that has already been | |
2619 | removed, but we have not yet processed the shlib unload | |
2620 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2621 | breakpoint insertion themselves can't tell why the |
2622 | breakpoint insertion failed (e.g., the remote target | |
2623 | doesn't define error codes), so we must treat generic | |
2624 | errors as memory errors. */ | |
688fca4f PA |
2625 | if (bp_excpt.reason == RETURN_ERROR |
2626 | && (bp_excpt.error == GENERIC_ERROR | |
2627 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2628 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2629 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2630 | || shared_objfile_contains_address_p (bl->pspace, |
2631 | bl->address))) | |
879bfdc2 | 2632 | { |
4a64f543 | 2633 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2634 | bl->shlib_disabled = 1; |
76727919 | 2635 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2636 | if (!*disabled_breaks) |
2637 | { | |
2638 | fprintf_unfiltered (tmp_error_stream, | |
2639 | "Cannot insert breakpoint %d.\n", | |
2640 | bl->owner->number); | |
2641 | fprintf_unfiltered (tmp_error_stream, | |
2642 | "Temporarily disabling shared " | |
2643 | "library breakpoints:\n"); | |
2644 | } | |
2645 | *disabled_breaks = 1; | |
879bfdc2 | 2646 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2647 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2648 | return 0; |
879bfdc2 DJ |
2649 | } |
2650 | else | |
879bfdc2 | 2651 | { |
35df4500 | 2652 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2653 | { |
0000e5cc | 2654 | *hw_breakpoint_error = 1; |
688fca4f | 2655 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dd61ec5c MW |
2656 | fprintf_unfiltered (tmp_error_stream, |
2657 | "Cannot insert hardware breakpoint %d%s", | |
688fca4f PA |
2658 | bl->owner->number, |
2659 | bp_excpt.message ? ":" : ".\n"); | |
2660 | if (bp_excpt.message != NULL) | |
2661 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
3d6e9d23 | 2662 | bp_excpt.what ()); |
879bfdc2 DJ |
2663 | } |
2664 | else | |
2665 | { | |
688fca4f | 2666 | if (bp_excpt.message == NULL) |
0000e5cc | 2667 | { |
1ccbe998 | 2668 | std::string message |
0000e5cc PA |
2669 | = memory_error_message (TARGET_XFER_E_IO, |
2670 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2671 | |
2672 | fprintf_unfiltered (tmp_error_stream, | |
2673 | "Cannot insert breakpoint %d.\n" | |
2674 | "%s\n", | |
1ccbe998 | 2675 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2676 | } |
2677 | else | |
2678 | { | |
2679 | fprintf_unfiltered (tmp_error_stream, | |
2680 | "Cannot insert breakpoint %d: %s\n", | |
2681 | bl->owner->number, | |
3d6e9d23 | 2682 | bp_excpt.what ()); |
0000e5cc | 2683 | } |
879bfdc2 | 2684 | } |
0000e5cc | 2685 | return 1; |
879bfdc2 DJ |
2686 | |
2687 | } | |
2688 | } | |
2689 | else | |
35df4500 | 2690 | bl->inserted = 1; |
879bfdc2 | 2691 | |
0000e5cc | 2692 | return 0; |
879bfdc2 DJ |
2693 | } |
2694 | ||
35df4500 | 2695 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2696 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2697 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2698 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2699 | { |
0000e5cc PA |
2700 | int val; |
2701 | ||
77b06cd7 TJB |
2702 | gdb_assert (bl->owner->ops != NULL |
2703 | && bl->owner->ops->insert_location != NULL); | |
2704 | ||
2705 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2706 | |
2707 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2708 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2709 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2710 | { |
2711 | struct bp_location *loc, **loc_temp; | |
2712 | ||
2713 | /* But don't try to insert it, if there's already another | |
2714 | hw_access location that would be considered a duplicate | |
2715 | of this one. */ | |
2716 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2717 | if (loc != bl |
85d721b8 | 2718 | && loc->watchpoint_type == hw_access |
35df4500 | 2719 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2720 | { |
35df4500 TJB |
2721 | bl->duplicate = 1; |
2722 | bl->inserted = 1; | |
2723 | bl->target_info = loc->target_info; | |
2724 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2725 | val = 0; |
2726 | break; | |
2727 | } | |
2728 | ||
2729 | if (val == 1) | |
2730 | { | |
77b06cd7 TJB |
2731 | bl->watchpoint_type = hw_access; |
2732 | val = bl->owner->ops->insert_location (bl); | |
2733 | ||
2734 | if (val) | |
2735 | /* Back to the original value. */ | |
2736 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2737 | } |
2738 | } | |
2739 | ||
35df4500 | 2740 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2741 | } |
2742 | ||
35df4500 | 2743 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2744 | { |
0000e5cc PA |
2745 | int val; |
2746 | ||
77b06cd7 TJB |
2747 | gdb_assert (bl->owner->ops != NULL |
2748 | && bl->owner->ops->insert_location != NULL); | |
2749 | ||
2750 | val = bl->owner->ops->insert_location (bl); | |
2751 | if (val) | |
2752 | { | |
2753 | bl->owner->enable_state = bp_disabled; | |
2754 | ||
2755 | if (val == 1) | |
2756 | warning (_("\ | |
2757 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2758 | of catchpoint."), bl->owner->number); | |
2759 | else | |
2760 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2761 | } | |
2762 | ||
2763 | bl->inserted = (val == 0); | |
1640b821 DJ |
2764 | |
2765 | /* We've already printed an error message if there was a problem | |
2766 | inserting this catchpoint, and we've disabled the catchpoint, | |
2767 | so just return success. */ | |
2768 | return 0; | |
879bfdc2 DJ |
2769 | } |
2770 | ||
2771 | return 0; | |
2772 | } | |
2773 | ||
6c95b8df PA |
2774 | /* This function is called when program space PSPACE is about to be |
2775 | deleted. It takes care of updating breakpoints to not reference | |
2776 | PSPACE anymore. */ | |
2777 | ||
2778 | void | |
2779 | breakpoint_program_space_exit (struct program_space *pspace) | |
2780 | { | |
2781 | struct breakpoint *b, *b_temp; | |
876fa593 | 2782 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2783 | |
2784 | /* Remove any breakpoint that was set through this program space. */ | |
2785 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2786 | { | |
2787 | if (b->pspace == pspace) | |
2788 | delete_breakpoint (b); | |
2789 | } | |
2790 | ||
2791 | /* Breakpoints set through other program spaces could have locations | |
2792 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2793 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2794 | { |
2795 | struct bp_location *tmp; | |
2796 | ||
2797 | if (loc->pspace == pspace) | |
2798 | { | |
2bdf28a0 | 2799 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2800 | if (loc->owner->loc == loc) |
2801 | loc->owner->loc = loc->next; | |
2802 | else | |
2803 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2804 | if (tmp->next == loc) | |
2805 | { | |
2806 | tmp->next = loc->next; | |
2807 | break; | |
2808 | } | |
2809 | } | |
2810 | } | |
2811 | ||
2812 | /* Now update the global location list to permanently delete the | |
2813 | removed locations above. */ | |
44702360 | 2814 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2815 | } |
2816 | ||
74960c60 VP |
2817 | /* Make sure all breakpoints are inserted in inferior. |
2818 | Throws exception on any error. | |
2819 | A breakpoint that is already inserted won't be inserted | |
2820 | again, so calling this function twice is safe. */ | |
2821 | void | |
2822 | insert_breakpoints (void) | |
2823 | { | |
2824 | struct breakpoint *bpt; | |
2825 | ||
2826 | ALL_BREAKPOINTS (bpt) | |
2827 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2828 | { |
2829 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2830 | ||
2831 | update_watchpoint (w, 0 /* don't reparse. */); | |
2832 | } | |
74960c60 | 2833 | |
04086b45 PA |
2834 | /* Updating watchpoints creates new locations, so update the global |
2835 | location list. Explicitly tell ugll to insert locations and | |
2836 | ignore breakpoints_always_inserted_mode. */ | |
2837 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2838 | } |
2839 | ||
20388dd6 YQ |
2840 | /* Invoke CALLBACK for each of bp_location. */ |
2841 | ||
2842 | void | |
2843 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2844 | { | |
2845 | struct bp_location *loc, **loc_tmp; | |
2846 | ||
2847 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2848 | { | |
2849 | callback (loc, NULL); | |
2850 | } | |
2851 | } | |
2852 | ||
b775012e LM |
2853 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2854 | target. It is the case with deleting and disabling of breakpoints when using | |
2855 | always-inserted mode. */ | |
2856 | ||
2857 | static void | |
2858 | update_inserted_breakpoint_locations (void) | |
2859 | { | |
2860 | struct bp_location *bl, **blp_tmp; | |
2861 | int error_flag = 0; | |
2862 | int val = 0; | |
2863 | int disabled_breaks = 0; | |
2864 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2865 | int hw_bp_details_reported = 0; |
b775012e | 2866 | |
d7e74731 | 2867 | string_file tmp_error_stream; |
b775012e LM |
2868 | |
2869 | /* Explicitly mark the warning -- this will only be printed if | |
2870 | there was an error. */ | |
d7e74731 | 2871 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2872 | |
5ed8105e | 2873 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2874 | |
2875 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2876 | { | |
2877 | /* We only want to update software breakpoints and hardware | |
2878 | breakpoints. */ | |
2879 | if (!is_breakpoint (bl->owner)) | |
2880 | continue; | |
2881 | ||
2882 | /* We only want to update locations that are already inserted | |
2883 | and need updating. This is to avoid unwanted insertion during | |
2884 | deletion of breakpoints. */ | |
4daf1902 | 2885 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
2886 | continue; |
2887 | ||
2888 | switch_to_program_space_and_thread (bl->pspace); | |
2889 | ||
2890 | /* For targets that support global breakpoints, there's no need | |
2891 | to select an inferior to insert breakpoint to. In fact, even | |
2892 | if we aren't attached to any process yet, we should still | |
2893 | insert breakpoints. */ | |
f5656ead | 2894 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
d7e15655 | 2895 | && inferior_ptid == null_ptid) |
b775012e LM |
2896 | continue; |
2897 | ||
d7e74731 | 2898 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2899 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2900 | if (val) |
2901 | error_flag = val; | |
2902 | } | |
2903 | ||
2904 | if (error_flag) | |
2905 | { | |
223ffa71 | 2906 | target_terminal::ours_for_output (); |
b775012e LM |
2907 | error_stream (tmp_error_stream); |
2908 | } | |
b775012e LM |
2909 | } |
2910 | ||
c30eee59 | 2911 | /* Used when starting or continuing the program. */ |
c906108c | 2912 | |
74960c60 VP |
2913 | static void |
2914 | insert_breakpoint_locations (void) | |
c906108c | 2915 | { |
a5606eee | 2916 | struct breakpoint *bpt; |
35df4500 | 2917 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2918 | int error_flag = 0; |
c906108c | 2919 | int val = 0; |
3fbb6ffa | 2920 | int disabled_breaks = 0; |
81d0cc19 | 2921 | int hw_breakpoint_error = 0; |
dd61ec5c | 2922 | int hw_bp_error_explained_already = 0; |
c906108c | 2923 | |
d7e74731 PA |
2924 | string_file tmp_error_stream; |
2925 | ||
81d0cc19 GS |
2926 | /* Explicitly mark the warning -- this will only be printed if |
2927 | there was an error. */ | |
d7e74731 | 2928 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 2929 | |
5ed8105e | 2930 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 2931 | |
35df4500 | 2932 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2933 | { |
b775012e | 2934 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2935 | continue; |
2936 | ||
4a64f543 MS |
2937 | /* There is no point inserting thread-specific breakpoints if |
2938 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2939 | has BL->OWNER always non-NULL. */ | |
35df4500 | 2940 | if (bl->owner->thread != -1 |
5d5658a1 | 2941 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
2942 | continue; |
2943 | ||
35df4500 | 2944 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2945 | |
2946 | /* For targets that support global breakpoints, there's no need | |
2947 | to select an inferior to insert breakpoint to. In fact, even | |
2948 | if we aren't attached to any process yet, we should still | |
2949 | insert breakpoints. */ | |
f5656ead | 2950 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
d7e15655 | 2951 | && inferior_ptid == null_ptid) |
6c95b8df PA |
2952 | continue; |
2953 | ||
d7e74731 | 2954 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2955 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2956 | if (val) |
eacd795a | 2957 | error_flag = val; |
879bfdc2 | 2958 | } |
c906108c | 2959 | |
4a64f543 MS |
2960 | /* If we failed to insert all locations of a watchpoint, remove |
2961 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2962 | ALL_BREAKPOINTS (bpt) |
2963 | { | |
2964 | int some_failed = 0; | |
2965 | struct bp_location *loc; | |
2966 | ||
2967 | if (!is_hardware_watchpoint (bpt)) | |
2968 | continue; | |
2969 | ||
d6b74ac4 | 2970 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2971 | continue; |
74960c60 VP |
2972 | |
2973 | if (bpt->disposition == disp_del_at_next_stop) | |
2974 | continue; | |
a5606eee VP |
2975 | |
2976 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2977 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2978 | { |
2979 | some_failed = 1; | |
2980 | break; | |
2981 | } | |
2982 | if (some_failed) | |
2983 | { | |
2984 | for (loc = bpt->loc; loc; loc = loc->next) | |
2985 | if (loc->inserted) | |
834c0d03 | 2986 | remove_breakpoint (loc); |
a5606eee VP |
2987 | |
2988 | hw_breakpoint_error = 1; | |
d7e74731 PA |
2989 | tmp_error_stream.printf ("Could not insert " |
2990 | "hardware watchpoint %d.\n", | |
2991 | bpt->number); | |
eacd795a | 2992 | error_flag = -1; |
a5606eee VP |
2993 | } |
2994 | } | |
2995 | ||
eacd795a | 2996 | if (error_flag) |
81d0cc19 GS |
2997 | { |
2998 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2999 | message about possibly exhausted resources. */ | |
dd61ec5c | 3000 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3001 | { |
d7e74731 | 3002 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3003 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3004 | } |
223ffa71 | 3005 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3006 | error_stream (tmp_error_stream); |
3007 | } | |
c906108c SS |
3008 | } |
3009 | ||
c30eee59 TJB |
3010 | /* Used when the program stops. |
3011 | Returns zero if successful, or non-zero if there was a problem | |
3012 | removing a breakpoint location. */ | |
3013 | ||
c906108c | 3014 | int |
fba45db2 | 3015 | remove_breakpoints (void) |
c906108c | 3016 | { |
35df4500 | 3017 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3018 | int val = 0; |
c906108c | 3019 | |
35df4500 | 3020 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3021 | { |
1e4d1764 | 3022 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3023 | val |= remove_breakpoint (bl); |
c5aa993b | 3024 | } |
3a1bae8e | 3025 | return val; |
c906108c SS |
3026 | } |
3027 | ||
49fa26b0 PA |
3028 | /* When a thread exits, remove breakpoints that are related to |
3029 | that thread. */ | |
3030 | ||
3031 | static void | |
3032 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3033 | { | |
3034 | struct breakpoint *b, *b_tmp; | |
3035 | ||
3036 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3037 | { | |
5d5658a1 | 3038 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3039 | { |
3040 | b->disposition = disp_del_at_next_stop; | |
3041 | ||
3042 | printf_filtered (_("\ | |
43792cf0 PA |
3043 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3044 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3045 | |
3046 | /* Hide it from the user. */ | |
3047 | b->number = 0; | |
3048 | } | |
3049 | } | |
3050 | } | |
3051 | ||
00431a78 | 3052 | /* Remove breakpoints of inferior INF. */ |
6c95b8df PA |
3053 | |
3054 | int | |
00431a78 | 3055 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3056 | { |
35df4500 | 3057 | struct bp_location *bl, **blp_tmp; |
6c95b8df | 3058 | int val; |
6c95b8df | 3059 | |
35df4500 | 3060 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3061 | { |
35df4500 | 3062 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3063 | continue; |
3064 | ||
fc126975 | 3065 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3066 | { |
834c0d03 | 3067 | val = remove_breakpoint (bl); |
6c95b8df PA |
3068 | if (val != 0) |
3069 | return val; | |
3070 | } | |
3071 | } | |
3072 | return 0; | |
3073 | } | |
3074 | ||
e58b0e63 PA |
3075 | static int internal_breakpoint_number = -1; |
3076 | ||
84f4c1fe PM |
3077 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3078 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3079 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3080 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3081 | breakpoint_count and that value incremented. Internal breakpoints |
3082 | do not set the internal var bpnum. */ | |
3083 | static void | |
3084 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3085 | { | |
3086 | if (internal) | |
3087 | b->number = internal_breakpoint_number--; | |
3088 | else | |
3089 | { | |
3090 | set_breakpoint_count (breakpoint_count + 1); | |
3091 | b->number = breakpoint_count; | |
3092 | } | |
3093 | } | |
3094 | ||
e62c965a | 3095 | static struct breakpoint * |
a6d9a66e | 3096 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3097 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3098 | const struct breakpoint_ops *ops) |
e62c965a | 3099 | { |
51abb421 | 3100 | symtab_and_line sal; |
e62c965a PP |
3101 | sal.pc = address; |
3102 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3103 | sal.pspace = current_program_space; |
e62c965a | 3104 | |
51abb421 | 3105 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3106 | b->number = internal_breakpoint_number--; |
3107 | b->disposition = disp_donttouch; | |
3108 | ||
3109 | return b; | |
3110 | } | |
3111 | ||
17450429 PP |
3112 | static const char *const longjmp_names[] = |
3113 | { | |
3114 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3115 | }; | |
3116 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3117 | ||
3118 | /* Per-objfile data private to breakpoint.c. */ | |
3119 | struct breakpoint_objfile_data | |
3120 | { | |
3121 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3122 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3123 | |
3124 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3125 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3126 | |
28106bc2 | 3127 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3128 | int longjmp_searched = 0; |
28106bc2 | 3129 | |
45461e0d SM |
3130 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3131 | references. */ | |
3132 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3133 | |
17450429 | 3134 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3135 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3136 | |
3137 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3138 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3139 | |
3140 | /* True if we have looked for exception probes. */ | |
43dce439 | 3141 | int exception_searched = 0; |
28106bc2 | 3142 | |
45461e0d SM |
3143 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3144 | references. */ | |
3145 | std::vector<probe *> exception_probes; | |
17450429 PP |
3146 | }; |
3147 | ||
51d3063a TT |
3148 | static const struct objfile_key<breakpoint_objfile_data> |
3149 | breakpoint_objfile_key; | |
17450429 PP |
3150 | |
3151 | /* Minimal symbol not found sentinel. */ | |
3152 | static struct minimal_symbol msym_not_found; | |
3153 | ||
3154 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3155 | ||
3156 | static int | |
3157 | msym_not_found_p (const struct minimal_symbol *msym) | |
3158 | { | |
3159 | return msym == &msym_not_found; | |
3160 | } | |
3161 | ||
3162 | /* Return per-objfile data needed by breakpoint.c. | |
3163 | Allocate the data if necessary. */ | |
3164 | ||
3165 | static struct breakpoint_objfile_data * | |
3166 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3167 | { | |
3168 | struct breakpoint_objfile_data *bp_objfile_data; | |
3169 | ||
51d3063a | 3170 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3171 | if (bp_objfile_data == NULL) |
51d3063a | 3172 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3173 | return bp_objfile_data; |
3174 | } | |
3175 | ||
e62c965a | 3176 | static void |
af02033e | 3177 | create_overlay_event_breakpoint (void) |
e62c965a | 3178 | { |
af02033e | 3179 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3180 | |
2030c079 | 3181 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3182 | { |
3183 | struct breakpoint *b; | |
17450429 PP |
3184 | struct breakpoint_objfile_data *bp_objfile_data; |
3185 | CORE_ADDR addr; | |
67994074 | 3186 | struct explicit_location explicit_loc; |
69de3c6a | 3187 | |
17450429 PP |
3188 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3189 | ||
3b7344d5 | 3190 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3191 | continue; |
3192 | ||
3b7344d5 | 3193 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3194 | { |
3b7344d5 | 3195 | struct bound_minimal_symbol m; |
17450429 PP |
3196 | |
3197 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3198 | if (m.minsym == NULL) |
17450429 PP |
3199 | { |
3200 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3201 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3202 | continue; |
3203 | } | |
3204 | bp_objfile_data->overlay_msym = m; | |
3205 | } | |
e62c965a | 3206 | |
77e371c0 | 3207 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3208 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3209 | bp_overlay_event, |
3210 | &internal_breakpoint_ops); | |
67994074 KS |
3211 | initialize_explicit_location (&explicit_loc); |
3212 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3213 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3214 | |
69de3c6a PP |
3215 | if (overlay_debugging == ovly_auto) |
3216 | { | |
3217 | b->enable_state = bp_enabled; | |
3218 | overlay_events_enabled = 1; | |
3219 | } | |
3220 | else | |
3221 | { | |
3222 | b->enable_state = bp_disabled; | |
3223 | overlay_events_enabled = 0; | |
3224 | } | |
e62c965a | 3225 | } |
e62c965a PP |
3226 | } |
3227 | ||
0fd8e87f | 3228 | static void |
af02033e | 3229 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3230 | { |
6c95b8df | 3231 | struct program_space *pspace; |
6c95b8df | 3232 | |
5ed8105e | 3233 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3234 | |
6c95b8df | 3235 | ALL_PSPACES (pspace) |
af02033e | 3236 | { |
af02033e PP |
3237 | set_current_program_space (pspace); |
3238 | ||
2030c079 | 3239 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
3240 | { |
3241 | int i; | |
3242 | struct gdbarch *gdbarch; | |
3243 | struct breakpoint_objfile_data *bp_objfile_data; | |
0fd8e87f | 3244 | |
aed57c53 | 3245 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3246 | |
aed57c53 | 3247 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3248 | |
aed57c53 TT |
3249 | if (!bp_objfile_data->longjmp_searched) |
3250 | { | |
3251 | std::vector<probe *> ret | |
3252 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
25f9533e | 3253 | |
aed57c53 TT |
3254 | if (!ret.empty ()) |
3255 | { | |
3256 | /* We are only interested in checking one element. */ | |
3257 | probe *p = ret[0]; | |
3258 | ||
3259 | if (!p->can_evaluate_arguments ()) | |
3260 | { | |
3261 | /* We cannot use the probe interface here, because it does | |
3262 | not know how to evaluate arguments. */ | |
3263 | ret.clear (); | |
3264 | } | |
3265 | } | |
3266 | bp_objfile_data->longjmp_probes = ret; | |
3267 | bp_objfile_data->longjmp_searched = 1; | |
3268 | } | |
25f9533e | 3269 | |
aed57c53 TT |
3270 | if (!bp_objfile_data->longjmp_probes.empty ()) |
3271 | { | |
3272 | for (probe *p : bp_objfile_data->longjmp_probes) | |
3273 | { | |
3274 | struct breakpoint *b; | |
3275 | ||
3276 | b = create_internal_breakpoint (gdbarch, | |
3277 | p->get_relocated_address (objfile), | |
3278 | bp_longjmp_master, | |
3279 | &internal_breakpoint_ops); | |
3280 | b->location = new_probe_location ("-probe-stap libc:longjmp"); | |
3281 | b->enable_state = bp_disabled; | |
3282 | } | |
28106bc2 | 3283 | |
aed57c53 TT |
3284 | continue; |
3285 | } | |
28106bc2 | 3286 | |
aed57c53 | 3287 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
28106bc2 | 3288 | continue; |
28106bc2 | 3289 | |
aed57c53 TT |
3290 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
3291 | { | |
3292 | struct breakpoint *b; | |
3293 | const char *func_name; | |
3294 | CORE_ADDR addr; | |
3295 | struct explicit_location explicit_loc; | |
0fd8e87f | 3296 | |
aed57c53 TT |
3297 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
3298 | continue; | |
17450429 | 3299 | |
aed57c53 TT |
3300 | func_name = longjmp_names[i]; |
3301 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3302 | { | |
3303 | struct bound_minimal_symbol m; | |
3304 | ||
3305 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3306 | if (m.minsym == NULL) | |
3307 | { | |
3308 | /* Prevent future lookups in this objfile. */ | |
3309 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
3310 | continue; | |
3311 | } | |
3312 | bp_objfile_data->longjmp_msym[i] = m; | |
3313 | } | |
17450429 | 3314 | |
aed57c53 TT |
3315 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
3316 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, | |
3317 | &internal_breakpoint_ops); | |
3318 | initialize_explicit_location (&explicit_loc); | |
3319 | explicit_loc.function_name = ASTRDUP (func_name); | |
3320 | b->location = new_explicit_location (&explicit_loc); | |
3321 | b->enable_state = bp_disabled; | |
3322 | } | |
3323 | } | |
af02033e | 3324 | } |
0fd8e87f UW |
3325 | } |
3326 | ||
af02033e | 3327 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3328 | static void |
af02033e | 3329 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3330 | { |
3331 | struct program_space *pspace; | |
af02033e | 3332 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3333 | |
5ed8105e | 3334 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3335 | |
3336 | ALL_PSPACES (pspace) | |
17450429 | 3337 | { |
17450429 PP |
3338 | CORE_ADDR addr; |
3339 | ||
3340 | set_current_program_space (pspace); | |
3341 | ||
2030c079 | 3342 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
3343 | { |
3344 | struct breakpoint *b; | |
3345 | struct breakpoint_objfile_data *bp_objfile_data; | |
3346 | struct explicit_location explicit_loc; | |
aa7d318d | 3347 | |
aed57c53 | 3348 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3349 | |
aed57c53 TT |
3350 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3351 | continue; | |
17450429 | 3352 | |
aed57c53 TT |
3353 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3354 | { | |
3355 | struct bound_minimal_symbol m; | |
17450429 | 3356 | |
aed57c53 TT |
3357 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
3358 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text | |
3359 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
3360 | { | |
3361 | /* Prevent future lookups in this objfile. */ | |
3362 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3363 | continue; | |
3364 | } | |
3365 | bp_objfile_data->terminate_msym = m; | |
3366 | } | |
aa7d318d | 3367 | |
aed57c53 TT |
3368 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3369 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
3370 | bp_std_terminate_master, | |
3371 | &internal_breakpoint_ops); | |
3372 | initialize_explicit_location (&explicit_loc); | |
3373 | explicit_loc.function_name = ASTRDUP (func_name); | |
3374 | b->location = new_explicit_location (&explicit_loc); | |
3375 | b->enable_state = bp_disabled; | |
3376 | } | |
17450429 | 3377 | } |
aa7d318d TT |
3378 | } |
3379 | ||
186c406b TT |
3380 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3381 | ||
70221824 | 3382 | static void |
186c406b TT |
3383 | create_exception_master_breakpoint (void) |
3384 | { | |
17450429 | 3385 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b | 3386 | |
2030c079 | 3387 | for (objfile *objfile : current_program_space->objfiles ()) |
186c406b | 3388 | { |
17450429 PP |
3389 | struct breakpoint *b; |
3390 | struct gdbarch *gdbarch; | |
3391 | struct breakpoint_objfile_data *bp_objfile_data; | |
3392 | CORE_ADDR addr; | |
67994074 | 3393 | struct explicit_location explicit_loc; |
17450429 PP |
3394 | |
3395 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3396 | ||
28106bc2 SDJ |
3397 | /* We prefer the SystemTap probe point if it exists. */ |
3398 | if (!bp_objfile_data->exception_searched) | |
3399 | { | |
45461e0d SM |
3400 | std::vector<probe *> ret |
3401 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
25f9533e | 3402 | |
45461e0d | 3403 | if (!ret.empty ()) |
25f9533e SDJ |
3404 | { |
3405 | /* We are only interested in checking one element. */ | |
45461e0d | 3406 | probe *p = ret[0]; |
25f9533e | 3407 | |
935676c9 | 3408 | if (!p->can_evaluate_arguments ()) |
25f9533e SDJ |
3409 | { |
3410 | /* We cannot use the probe interface here, because it does | |
3411 | not know how to evaluate arguments. */ | |
45461e0d | 3412 | ret.clear (); |
25f9533e SDJ |
3413 | } |
3414 | } | |
3415 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3416 | bp_objfile_data->exception_searched = 1; |
3417 | } | |
3418 | ||
45461e0d | 3419 | if (!bp_objfile_data->exception_probes.empty ()) |
28106bc2 | 3420 | { |
b926417a | 3421 | gdbarch = get_objfile_arch (objfile); |
45461e0d SM |
3422 | |
3423 | for (probe *p : bp_objfile_data->exception_probes) | |
28106bc2 | 3424 | { |
729662a5 | 3425 | b = create_internal_breakpoint (gdbarch, |
935676c9 | 3426 | p->get_relocated_address (objfile), |
28106bc2 SDJ |
3427 | bp_exception_master, |
3428 | &internal_breakpoint_ops); | |
d28cd78a | 3429 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3430 | b->enable_state = bp_disabled; |
3431 | } | |
3432 | ||
3433 | continue; | |
3434 | } | |
3435 | ||
3436 | /* Otherwise, try the hook function. */ | |
3437 | ||
3b7344d5 | 3438 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3439 | continue; |
3440 | ||
3441 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3442 | |
3b7344d5 | 3443 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3444 | { |
3b7344d5 | 3445 | struct bound_minimal_symbol debug_hook; |
186c406b | 3446 | |
17450429 | 3447 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3448 | if (debug_hook.minsym == NULL) |
17450429 | 3449 | { |
3b7344d5 | 3450 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3451 | continue; |
3452 | } | |
3453 | ||
3454 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3455 | } |
17450429 | 3456 | |
77e371c0 | 3457 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
8b88a78e PA |
3458 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3459 | current_top_target ()); | |
06edf0c0 PA |
3460 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3461 | &internal_breakpoint_ops); | |
67994074 KS |
3462 | initialize_explicit_location (&explicit_loc); |
3463 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3464 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3465 | b->enable_state = bp_disabled; |
186c406b | 3466 | } |
186c406b TT |
3467 | } |
3468 | ||
9ef9e6a6 KS |
3469 | /* Does B have a location spec? */ |
3470 | ||
3471 | static int | |
3472 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3473 | { | |
d28cd78a | 3474 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3475 | } |
3476 | ||
c906108c | 3477 | void |
fba45db2 | 3478 | update_breakpoints_after_exec (void) |
c906108c | 3479 | { |
35df4500 | 3480 | struct breakpoint *b, *b_tmp; |
876fa593 | 3481 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3482 | |
25b22b0a PA |
3483 | /* We're about to delete breakpoints from GDB's lists. If the |
3484 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3485 | writing the breakpoints' "shadow contents" back into memory. The | |
3486 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3487 | do that. Instead, the target is responsible from marking | |
3488 | breakpoints out as soon as it detects an exec. We don't do that | |
3489 | here instead, because there may be other attempts to delete | |
3490 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3491 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3492 | if (bploc->pspace == current_program_space) |
3493 | gdb_assert (!bploc->inserted); | |
c906108c | 3494 | |
35df4500 | 3495 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3496 | { |
6c95b8df PA |
3497 | if (b->pspace != current_program_space) |
3498 | continue; | |
3499 | ||
4a64f543 | 3500 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3501 | if (b->type == bp_shlib_event) |
3502 | { | |
3503 | delete_breakpoint (b); | |
3504 | continue; | |
3505 | } | |
c906108c | 3506 | |
4a64f543 | 3507 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3508 | if (b->type == bp_jit_event) |
3509 | { | |
3510 | delete_breakpoint (b); | |
3511 | continue; | |
3512 | } | |
3513 | ||
1900040c | 3514 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3515 | as must overlay event and longjmp master breakpoints. */ |
3516 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3517 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3518 | || b->type == bp_exception_master) | |
c4093a6a JM |
3519 | { |
3520 | delete_breakpoint (b); | |
3521 | continue; | |
3522 | } | |
3523 | ||
4a64f543 | 3524 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3525 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3526 | { |
3527 | delete_breakpoint (b); | |
3528 | continue; | |
3529 | } | |
3530 | ||
7c16b83e PA |
3531 | /* Just like single-step breakpoints. */ |
3532 | if (b->type == bp_single_step) | |
3533 | { | |
3534 | delete_breakpoint (b); | |
3535 | continue; | |
3536 | } | |
3537 | ||
611c83ae PA |
3538 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3539 | after an exec. */ | |
186c406b | 3540 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3541 | || b->type == bp_longjmp_call_dummy |
186c406b | 3542 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3543 | { |
3544 | delete_breakpoint (b); | |
3545 | continue; | |
3546 | } | |
3547 | ||
ce78b96d JB |
3548 | if (b->type == bp_catchpoint) |
3549 | { | |
3550 | /* For now, none of the bp_catchpoint breakpoints need to | |
3551 | do anything at this point. In the future, if some of | |
3552 | the catchpoints need to something, we will need to add | |
3553 | a new method, and call this method from here. */ | |
3554 | continue; | |
3555 | } | |
3556 | ||
c5aa993b JM |
3557 | /* bp_finish is a special case. The only way we ought to be able |
3558 | to see one of these when an exec() has happened, is if the user | |
3559 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3560 | carries them to the call-site of the current callee, by setting | |
3561 | a temporary bp there and resuming. But in this case, the finish | |
3562 | will carry them entirely through the vfork & exec. | |
3563 | ||
3564 | We don't want to allow a bp_finish to remain inserted now. But | |
3565 | we can't safely delete it, 'cause finish_command has a handle to | |
3566 | the bp on a bpstat, and will later want to delete it. There's a | |
3567 | chance (and I've seen it happen) that if we delete the bp_finish | |
3568 | here, that its storage will get reused by the time finish_command | |
3569 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3570 | We really must allow finish_command to delete a bp_finish. | |
3571 | ||
e5dd4106 | 3572 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3573 | it's safe to delete something others may have handles to?" |
3574 | problem, what we'll do here is just uninsert the bp_finish, and | |
3575 | let finish_command delete it. | |
3576 | ||
3577 | (We know the bp_finish is "doomed" in the sense that it's | |
3578 | momentary, and will be deleted as soon as finish_command sees | |
3579 | the inferior stopped. So it doesn't matter that the bp's | |
3580 | address is probably bogus in the new a.out, unlike e.g., the | |
3581 | solib breakpoints.) */ | |
c5aa993b | 3582 | |
c5aa993b JM |
3583 | if (b->type == bp_finish) |
3584 | { | |
3585 | continue; | |
3586 | } | |
3587 | ||
3588 | /* Without a symbolic address, we have little hope of the | |
3589 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3590 | a.out. */ |
9ef9e6a6 | 3591 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3592 | { |
3593 | delete_breakpoint (b); | |
3594 | continue; | |
3595 | } | |
c5aa993b | 3596 | } |
c906108c SS |
3597 | } |
3598 | ||
3599 | int | |
d80ee84f | 3600 | detach_breakpoints (ptid_t ptid) |
c906108c | 3601 | { |
35df4500 | 3602 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3603 | int val = 0; |
2989a365 | 3604 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3605 | struct inferior *inf = current_inferior (); |
c5aa993b | 3606 | |
e99b03dc | 3607 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3608 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3609 | |
6c95b8df | 3610 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3611 | inferior_ptid = ptid; |
35df4500 | 3612 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3613 | { |
35df4500 | 3614 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3615 | continue; |
3616 | ||
bd9673a4 PW |
3617 | /* This function must physically remove breakpoints locations |
3618 | from the specified ptid, without modifying the breakpoint | |
3619 | package's state. Locations of type bp_loc_other are only | |
3620 | maintained at GDB side. So, there is no need to remove | |
3621 | these bp_loc_other locations. Moreover, removing these | |
3622 | would modify the breakpoint package's state. */ | |
3623 | if (bl->loc_type == bp_loc_other) | |
3624 | continue; | |
3625 | ||
35df4500 | 3626 | if (bl->inserted) |
b2b6a7da | 3627 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3628 | } |
d03285ec | 3629 | |
3a1bae8e | 3630 | return val; |
c906108c SS |
3631 | } |
3632 | ||
35df4500 | 3633 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3634 | Note that this is used to detach breakpoints from a child fork. |
3635 | When we get here, the child isn't in the inferior list, and neither | |
3636 | do we have objects to represent its address space --- we should | |
35df4500 | 3637 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3638 | |
c906108c | 3639 | static int |
b2b6a7da | 3640 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3641 | { |
3642 | int val; | |
c5aa993b | 3643 | |
35df4500 TJB |
3644 | /* BL is never in moribund_locations by our callers. */ |
3645 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3646 | |
74960c60 VP |
3647 | /* The type of none suggests that owner is actually deleted. |
3648 | This should not ever happen. */ | |
35df4500 | 3649 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3650 | |
35df4500 TJB |
3651 | if (bl->loc_type == bp_loc_software_breakpoint |
3652 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3653 | { |
c02f5703 MS |
3654 | /* "Normal" instruction breakpoint: either the standard |
3655 | trap-instruction bp (bp_breakpoint), or a | |
3656 | bp_hardware_breakpoint. */ | |
3657 | ||
3658 | /* First check to see if we have to handle an overlay. */ | |
3659 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3660 | || bl->section == NULL |
3661 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3662 | { |
3663 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3664 | |
3665 | /* If we're trying to uninsert a memory breakpoint that we | |
3666 | know is set in a dynamic object that is marked | |
3667 | shlib_disabled, then either the dynamic object was | |
3668 | removed with "remove-symbol-file" or with | |
3669 | "nosharedlibrary". In the former case, we don't know | |
3670 | whether another dynamic object might have loaded over the | |
3671 | breakpoint's address -- the user might well let us know | |
3672 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3673 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3674 | list of dynamically loaded objects). If we have the |
3675 | breakpoint's shadow memory, that is, this is a software | |
3676 | breakpoint managed by GDB, check whether the breakpoint | |
3677 | is still inserted in memory, to avoid overwriting wrong | |
3678 | code with stale saved shadow contents. Note that HW | |
3679 | breakpoints don't have shadow memory, as they're | |
3680 | implemented using a mechanism that is not dependent on | |
3681 | being able to modify the target's memory, and as such | |
3682 | they should always be removed. */ | |
3683 | if (bl->shlib_disabled | |
3684 | && bl->target_info.shadow_len != 0 | |
3685 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3686 | val = 0; | |
3687 | else | |
73971819 | 3688 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3689 | } |
c906108c SS |
3690 | else |
3691 | { | |
4a64f543 | 3692 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3693 | Did we set a breakpoint at the LMA? */ |
3694 | if (!overlay_events_enabled) | |
3695 | { | |
3696 | /* Yes -- overlay event support is not active, so we | |
3697 | should have set a breakpoint at the LMA. Remove it. | |
3698 | */ | |
c02f5703 MS |
3699 | /* Ignore any failures: if the LMA is in ROM, we will |
3700 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3701 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3702 | target_remove_hw_breakpoint (bl->gdbarch, | |
3703 | &bl->overlay_target_info); | |
c02f5703 | 3704 | else |
35df4500 | 3705 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3706 | &bl->overlay_target_info, |
3707 | reason); | |
c02f5703 MS |
3708 | } |
3709 | /* Did we set a breakpoint at the VMA? | |
3710 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3711 | if (bl->inserted) |
c906108c | 3712 | { |
c02f5703 MS |
3713 | /* Yes -- remove it. Previously we did not bother to |
3714 | remove the breakpoint if the section had been | |
3715 | unmapped, but let's not rely on that being safe. We | |
3716 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3717 | |
3718 | /* However, we should remove *software* breakpoints only | |
3719 | if the section is still mapped, or else we overwrite | |
3720 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3721 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3722 | || section_is_mapped (bl->section)) | |
73971819 | 3723 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3724 | else |
3725 | val = 0; | |
c906108c | 3726 | } |
c02f5703 MS |
3727 | else |
3728 | { | |
3729 | /* No -- not inserted, so no need to remove. No error. */ | |
3730 | val = 0; | |
3731 | } | |
c906108c | 3732 | } |
879d1e6b | 3733 | |
08351840 PA |
3734 | /* In some cases, we might not be able to remove a breakpoint in |
3735 | a shared library that has already been removed, but we have | |
3736 | not yet processed the shlib unload event. Similarly for an | |
3737 | unloaded add-symbol-file object - the user might not yet have | |
3738 | had the chance to remove-symbol-file it. shlib_disabled will | |
3739 | be set if the library/object has already been removed, but | |
3740 | the breakpoint hasn't been uninserted yet, e.g., after | |
3741 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3742 | always-inserted mode. */ | |
076855f9 | 3743 | if (val |
08351840 PA |
3744 | && (bl->loc_type == bp_loc_software_breakpoint |
3745 | && (bl->shlib_disabled | |
3746 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3747 | || shared_objfile_contains_address_p (bl->pspace, |
3748 | bl->address)))) | |
879d1e6b UW |
3749 | val = 0; |
3750 | ||
c906108c SS |
3751 | if (val) |
3752 | return val; | |
b2b6a7da | 3753 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3754 | } |
35df4500 | 3755 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3756 | { |
77b06cd7 TJB |
3757 | gdb_assert (bl->owner->ops != NULL |
3758 | && bl->owner->ops->remove_location != NULL); | |
3759 | ||
b2b6a7da | 3760 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3761 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3762 | |
c906108c | 3763 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3764 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3765 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3766 | bl->owner->number); |
c906108c | 3767 | } |
35df4500 TJB |
3768 | else if (bl->owner->type == bp_catchpoint |
3769 | && breakpoint_enabled (bl->owner) | |
3770 | && !bl->duplicate) | |
ce78b96d | 3771 | { |
77b06cd7 TJB |
3772 | gdb_assert (bl->owner->ops != NULL |
3773 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3774 | |
73971819 | 3775 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3776 | if (val) |
3777 | return val; | |
77b06cd7 | 3778 | |
b2b6a7da | 3779 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3780 | } |
c906108c SS |
3781 | |
3782 | return 0; | |
3783 | } | |
3784 | ||
6c95b8df | 3785 | static int |
834c0d03 | 3786 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3787 | { |
35df4500 TJB |
3788 | /* BL is never in moribund_locations by our callers. */ |
3789 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3790 | |
6c95b8df PA |
3791 | /* The type of none suggests that owner is actually deleted. |
3792 | This should not ever happen. */ | |
35df4500 | 3793 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3794 | |
5ed8105e | 3795 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3796 | |
35df4500 | 3797 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3798 | |
5ed8105e | 3799 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3800 | } |
3801 | ||
c906108c SS |
3802 | /* Clear the "inserted" flag in all breakpoints. */ |
3803 | ||
25b22b0a | 3804 | void |
fba45db2 | 3805 | mark_breakpoints_out (void) |
c906108c | 3806 | { |
35df4500 | 3807 | struct bp_location *bl, **blp_tmp; |
c906108c | 3808 | |
35df4500 | 3809 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3810 | if (bl->pspace == current_program_space) |
35df4500 | 3811 | bl->inserted = 0; |
c906108c SS |
3812 | } |
3813 | ||
53a5351d JM |
3814 | /* Clear the "inserted" flag in all breakpoints and delete any |
3815 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3816 | |
3817 | Plus other such housekeeping that has to be done for breakpoints | |
3818 | between runs. | |
3819 | ||
53a5351d JM |
3820 | Note: this function gets called at the end of a run (by |
3821 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3822 | init_wait_for_inferior). */ |
c906108c SS |
3823 | |
3824 | ||
3825 | ||
3826 | void | |
fba45db2 | 3827 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3828 | { |
35df4500 | 3829 | struct breakpoint *b, *b_tmp; |
6c95b8df | 3830 | struct program_space *pspace = current_program_space; |
c906108c | 3831 | |
50c71eaf PA |
3832 | /* If breakpoint locations are shared across processes, then there's |
3833 | nothing to do. */ | |
f5656ead | 3834 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3835 | return; |
3836 | ||
1a853c52 | 3837 | mark_breakpoints_out (); |
075f6582 | 3838 | |
35df4500 | 3839 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3840 | { |
6c95b8df PA |
3841 | if (b->loc && b->loc->pspace != pspace) |
3842 | continue; | |
3843 | ||
c5aa993b JM |
3844 | switch (b->type) |
3845 | { | |
3846 | case bp_call_dummy: | |
e2e4d78b | 3847 | case bp_longjmp_call_dummy: |
c906108c | 3848 | |
c5aa993b | 3849 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3850 | cause problems when the inferior is rerun, so we better get |
3851 | rid of it. */ | |
3852 | ||
3853 | case bp_watchpoint_scope: | |
3854 | ||
3855 | /* Also get rid of scope breakpoints. */ | |
3856 | ||
3857 | case bp_shlib_event: | |
3858 | ||
3859 | /* Also remove solib event breakpoints. Their addresses may | |
3860 | have changed since the last time we ran the program. | |
3861 | Actually we may now be debugging against different target; | |
3862 | and so the solib backend that installed this breakpoint may | |
3863 | not be used in by the target. E.g., | |
3864 | ||
3865 | (gdb) file prog-linux | |
3866 | (gdb) run # native linux target | |
3867 | ... | |
3868 | (gdb) kill | |
3869 | (gdb) file prog-win.exe | |
3870 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3871 | */ | |
c906108c | 3872 | |
f59f708a PA |
3873 | case bp_step_resume: |
3874 | ||
3875 | /* Also remove step-resume breakpoints. */ | |
3876 | ||
7c16b83e PA |
3877 | case bp_single_step: |
3878 | ||
3879 | /* Also remove single-step breakpoints. */ | |
3880 | ||
c5aa993b JM |
3881 | delete_breakpoint (b); |
3882 | break; | |
c906108c | 3883 | |
c5aa993b JM |
3884 | case bp_watchpoint: |
3885 | case bp_hardware_watchpoint: | |
3886 | case bp_read_watchpoint: | |
3887 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3888 | { |
3889 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3890 | |
3a5c3e22 PA |
3891 | /* Likewise for watchpoints on local expressions. */ |
3892 | if (w->exp_valid_block != NULL) | |
3893 | delete_breakpoint (b); | |
63000888 | 3894 | else |
3a5c3e22 | 3895 | { |
63000888 PA |
3896 | /* Get rid of existing locations, which are no longer |
3897 | valid. New ones will be created in | |
3898 | update_watchpoint, when the inferior is restarted. | |
3899 | The next update_global_location_list call will | |
3900 | garbage collect them. */ | |
3901 | b->loc = NULL; | |
3902 | ||
3903 | if (context == inf_starting) | |
3904 | { | |
3905 | /* Reset val field to force reread of starting value in | |
3906 | insert_breakpoints. */ | |
850645cf | 3907 | w->val.reset (nullptr); |
63000888 PA |
3908 | w->val_valid = 0; |
3909 | } | |
3910 | } | |
3a5c3e22 | 3911 | } |
c5aa993b JM |
3912 | break; |
3913 | default: | |
c5aa993b JM |
3914 | break; |
3915 | } | |
3916 | } | |
1c5cfe86 PA |
3917 | |
3918 | /* Get rid of the moribund locations. */ | |
1123588c | 3919 | for (bp_location *bl : moribund_locations) |
35df4500 | 3920 | decref_bp_location (&bl); |
1123588c | 3921 | moribund_locations.clear (); |
c906108c SS |
3922 | } |
3923 | ||
6c95b8df PA |
3924 | /* These functions concern about actual breakpoints inserted in the |
3925 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3926 | we need to hop over the bkpt --- so we check for address space | |
3927 | match, not program space. */ | |
3928 | ||
c2c6d25f JM |
3929 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3930 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3931 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3932 | permanent breakpoint. | |
3933 | - When continuing from a location with an ordinary breakpoint, we | |
3934 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3935 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3936 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3937 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3938 | |
c2c6d25f | 3939 | enum breakpoint_here |
accd0bcd | 3940 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 3941 | { |
35df4500 | 3942 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3943 | int any_breakpoint_here = 0; |
c906108c | 3944 | |
35df4500 | 3945 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3946 | { |
35df4500 TJB |
3947 | if (bl->loc_type != bp_loc_software_breakpoint |
3948 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3949 | continue; |
3950 | ||
f1310107 | 3951 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 3952 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 3953 | || bl->permanent) |
f1310107 | 3954 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3955 | { |
3956 | if (overlay_debugging | |
35df4500 TJB |
3957 | && section_is_overlay (bl->section) |
3958 | && !section_is_mapped (bl->section)) | |
075f6582 | 3959 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 3960 | else if (bl->permanent) |
075f6582 DJ |
3961 | return permanent_breakpoint_here; |
3962 | else | |
3963 | any_breakpoint_here = 1; | |
3964 | } | |
3965 | } | |
c906108c | 3966 | |
f486487f | 3967 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
3968 | } |
3969 | ||
d35ae833 PA |
3970 | /* See breakpoint.h. */ |
3971 | ||
3972 | int | |
accd0bcd | 3973 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
3974 | CORE_ADDR addr, ULONGEST len) |
3975 | { | |
3976 | struct bp_location *bl, **blp_tmp; | |
3977 | ||
3978 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3979 | { | |
3980 | if (bl->loc_type != bp_loc_software_breakpoint | |
3981 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
3982 | continue; | |
3983 | ||
3984 | if ((breakpoint_enabled (bl->owner) | |
3985 | || bl->permanent) | |
3986 | && breakpoint_location_address_range_overlap (bl, aspace, | |
3987 | addr, len)) | |
3988 | { | |
3989 | if (overlay_debugging | |
3990 | && section_is_overlay (bl->section) | |
3991 | && !section_is_mapped (bl->section)) | |
3992 | { | |
3993 | /* Unmapped overlay -- can't be a match. */ | |
3994 | continue; | |
3995 | } | |
3996 | ||
3997 | return 1; | |
3998 | } | |
3999 | } | |
4000 | ||
4001 | return 0; | |
4002 | } | |
4003 | ||
1c5cfe86 PA |
4004 | /* Return true if there's a moribund breakpoint at PC. */ |
4005 | ||
4006 | int | |
accd0bcd | 4007 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 4008 | { |
1123588c | 4009 | for (bp_location *loc : moribund_locations) |
f1310107 | 4010 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4011 | return 1; |
4012 | ||
4013 | return 0; | |
4014 | } | |
c2c6d25f | 4015 | |
f7ce857f PA |
4016 | /* Returns non-zero iff BL is inserted at PC, in address space |
4017 | ASPACE. */ | |
4018 | ||
4019 | static int | |
4020 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4021 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4022 | { |
4023 | if (bl->inserted | |
4024 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4025 | aspace, pc)) | |
4026 | { | |
4027 | if (overlay_debugging | |
4028 | && section_is_overlay (bl->section) | |
4029 | && !section_is_mapped (bl->section)) | |
4030 | return 0; /* unmapped overlay -- can't be a match */ | |
4031 | else | |
4032 | return 1; | |
4033 | } | |
4034 | return 0; | |
4035 | } | |
4036 | ||
a1fd2fa5 | 4037 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4038 | |
4039 | int | |
accd0bcd | 4040 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4041 | { |
f7ce857f | 4042 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4043 | |
f7ce857f | 4044 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4045 | { |
f7ce857f PA |
4046 | struct bp_location *bl = *blp; |
4047 | ||
35df4500 TJB |
4048 | if (bl->loc_type != bp_loc_software_breakpoint |
4049 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4050 | continue; |
4051 | ||
f7ce857f PA |
4052 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4053 | return 1; | |
c5aa993b | 4054 | } |
c36b740a VP |
4055 | return 0; |
4056 | } | |
4057 | ||
a1fd2fa5 PA |
4058 | /* This function returns non-zero iff there is a software breakpoint |
4059 | inserted at PC. */ | |
c36b740a VP |
4060 | |
4061 | int | |
accd0bcd | 4062 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4063 | CORE_ADDR pc) |
4fa8626c | 4064 | { |
f7ce857f | 4065 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4066 | |
f7ce857f | 4067 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4068 | { |
f7ce857f PA |
4069 | struct bp_location *bl = *blp; |
4070 | ||
35df4500 | 4071 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4072 | continue; |
4073 | ||
f7ce857f PA |
4074 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4075 | return 1; | |
4fa8626c DJ |
4076 | } |
4077 | ||
4078 | return 0; | |
9c02b525 PA |
4079 | } |
4080 | ||
4081 | /* See breakpoint.h. */ | |
4082 | ||
4083 | int | |
accd0bcd | 4084 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4085 | CORE_ADDR pc) |
4086 | { | |
4087 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4088 | |
4089 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4090 | { | |
4091 | struct bp_location *bl = *blp; | |
4092 | ||
4093 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4094 | continue; | |
4095 | ||
4096 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4097 | return 1; | |
4098 | } | |
4099 | ||
4100 | return 0; | |
4fa8626c DJ |
4101 | } |
4102 | ||
9093389c | 4103 | int |
accd0bcd | 4104 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4105 | CORE_ADDR addr, ULONGEST len) |
4106 | { | |
4107 | struct breakpoint *bpt; | |
4108 | ||
4109 | ALL_BREAKPOINTS (bpt) | |
4110 | { | |
4111 | struct bp_location *loc; | |
4112 | ||
4113 | if (bpt->type != bp_hardware_watchpoint | |
4114 | && bpt->type != bp_access_watchpoint) | |
4115 | continue; | |
4116 | ||
4117 | if (!breakpoint_enabled (bpt)) | |
4118 | continue; | |
4119 | ||
4120 | for (loc = bpt->loc; loc; loc = loc->next) | |
4121 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4122 | { | |
4123 | CORE_ADDR l, h; | |
4124 | ||
4125 | /* Check for intersection. */ | |
768adc05 PA |
4126 | l = std::max<CORE_ADDR> (loc->address, addr); |
4127 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4128 | if (l < h) |
4129 | return 1; | |
4130 | } | |
4131 | } | |
4132 | return 0; | |
4133 | } | |
c906108c | 4134 | \f |
c5aa993b | 4135 | |
c906108c SS |
4136 | /* bpstat stuff. External routines' interfaces are documented |
4137 | in breakpoint.h. */ | |
4138 | ||
4139 | int | |
c326b90e | 4140 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4141 | { |
533be4dd | 4142 | return (ep->type == bp_catchpoint); |
c906108c SS |
4143 | } |
4144 | ||
f431efe5 PA |
4145 | /* Frees any storage that is part of a bpstat. Does not walk the |
4146 | 'next' chain. */ | |
4147 | ||
04afa70c | 4148 | bpstats::~bpstats () |
198757a8 | 4149 | { |
04afa70c TT |
4150 | if (bp_location_at != NULL) |
4151 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4152 | } |
4153 | ||
c906108c SS |
4154 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4155 | Also free any storage that is part of a bpstat. */ | |
4156 | ||
4157 | void | |
fba45db2 | 4158 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4159 | { |
4160 | bpstat p; | |
4161 | bpstat q; | |
4162 | ||
4163 | if (bsp == 0) | |
4164 | return; | |
4165 | p = *bsp; | |
4166 | while (p != NULL) | |
4167 | { | |
4168 | q = p->next; | |
04afa70c | 4169 | delete p; |
c906108c SS |
4170 | p = q; |
4171 | } | |
4172 | *bsp = NULL; | |
4173 | } | |
4174 | ||
04afa70c TT |
4175 | bpstats::bpstats (const bpstats &other) |
4176 | : next (NULL), | |
4177 | bp_location_at (other.bp_location_at), | |
4178 | breakpoint_at (other.breakpoint_at), | |
4179 | commands (other.commands), | |
04afa70c TT |
4180 | print (other.print), |
4181 | stop (other.stop), | |
4182 | print_it (other.print_it) | |
4183 | { | |
850645cf TT |
4184 | if (other.old_val != NULL) |
4185 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c | 4186 | incref_bp_location (bp_location_at); |
04afa70c TT |
4187 | } |
4188 | ||
c906108c SS |
4189 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4190 | is part of the bpstat is copied as well. */ | |
4191 | ||
4192 | bpstat | |
fba45db2 | 4193 | bpstat_copy (bpstat bs) |
c906108c SS |
4194 | { |
4195 | bpstat p = NULL; | |
4196 | bpstat tmp; | |
4197 | bpstat retval = NULL; | |
4198 | ||
4199 | if (bs == NULL) | |
4200 | return bs; | |
4201 | ||
4202 | for (; bs != NULL; bs = bs->next) | |
4203 | { | |
04afa70c | 4204 | tmp = new bpstats (*bs); |
31cc81e9 | 4205 | |
c906108c SS |
4206 | if (p == NULL) |
4207 | /* This is the first thing in the chain. */ | |
4208 | retval = tmp; | |
4209 | else | |
4210 | p->next = tmp; | |
4211 | p = tmp; | |
4212 | } | |
4213 | p->next = NULL; | |
4214 | return retval; | |
4215 | } | |
4216 | ||
4a64f543 | 4217 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4218 | |
4219 | bpstat | |
fba45db2 | 4220 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4221 | { |
c5aa993b JM |
4222 | if (bsp == NULL) |
4223 | return NULL; | |
c906108c | 4224 | |
c5aa993b JM |
4225 | for (; bsp != NULL; bsp = bsp->next) |
4226 | { | |
f431efe5 | 4227 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4228 | return bsp; |
4229 | } | |
c906108c SS |
4230 | return NULL; |
4231 | } | |
4232 | ||
ab04a2af TT |
4233 | /* See breakpoint.h. */ |
4234 | ||
47591c29 | 4235 | int |
427cd150 | 4236 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4237 | { |
ab04a2af TT |
4238 | for (; bsp != NULL; bsp = bsp->next) |
4239 | { | |
427cd150 TT |
4240 | if (bsp->breakpoint_at == NULL) |
4241 | { | |
4242 | /* A moribund location can never explain a signal other than | |
4243 | GDB_SIGNAL_TRAP. */ | |
4244 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4245 | return 1; |
427cd150 TT |
4246 | } |
4247 | else | |
47591c29 PA |
4248 | { |
4249 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4250 | sig)) | |
4251 | return 1; | |
4252 | } | |
ab04a2af TT |
4253 | } |
4254 | ||
47591c29 | 4255 | return 0; |
ab04a2af TT |
4256 | } |
4257 | ||
4a64f543 MS |
4258 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4259 | stopped at. *BSP upon return is a bpstat which points to the | |
4260 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4261 | good for anything but further calls to bpstat_num). | |
4262 | ||
8671a17b PA |
4263 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4264 | Return -1 if stopped at a breakpoint that has been deleted since | |
4265 | we set it. | |
4266 | Return 1 otherwise. */ | |
c906108c SS |
4267 | |
4268 | int | |
8671a17b | 4269 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4270 | { |
4271 | struct breakpoint *b; | |
4272 | ||
4273 | if ((*bsp) == NULL) | |
4274 | return 0; /* No more breakpoint values */ | |
8671a17b | 4275 | |
4a64f543 MS |
4276 | /* We assume we'll never have several bpstats that correspond to a |
4277 | single breakpoint -- otherwise, this function might return the | |
4278 | same number more than once and this will look ugly. */ | |
f431efe5 | 4279 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4280 | *bsp = (*bsp)->next; |
4281 | if (b == NULL) | |
4282 | return -1; /* breakpoint that's been deleted since */ | |
4283 | ||
4284 | *num = b->number; /* We have its number */ | |
4285 | return 1; | |
c906108c SS |
4286 | } |
4287 | ||
e93ca019 | 4288 | /* See breakpoint.h. */ |
c906108c SS |
4289 | |
4290 | void | |
e93ca019 | 4291 | bpstat_clear_actions (void) |
c906108c | 4292 | { |
e93ca019 JK |
4293 | bpstat bs; |
4294 | ||
00431a78 | 4295 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4296 | return; |
4297 | ||
00431a78 | 4298 | thread_info *tp = inferior_thread (); |
e93ca019 | 4299 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4300 | { |
d1b0a7bf | 4301 | bs->commands = NULL; |
850645cf | 4302 | bs->old_val.reset (nullptr); |
c906108c SS |
4303 | } |
4304 | } | |
4305 | ||
f3b1572e PA |
4306 | /* Called when a command is about to proceed the inferior. */ |
4307 | ||
4308 | static void | |
4309 | breakpoint_about_to_proceed (void) | |
4310 | { | |
d7e15655 | 4311 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4312 | { |
4313 | struct thread_info *tp = inferior_thread (); | |
4314 | ||
4315 | /* Allow inferior function calls in breakpoint commands to not | |
4316 | interrupt the command list. When the call finishes | |
4317 | successfully, the inferior will be standing at the same | |
4318 | breakpoint as if nothing happened. */ | |
16c381f0 | 4319 | if (tp->control.in_infcall) |
f3b1572e PA |
4320 | return; |
4321 | } | |
4322 | ||
4323 | breakpoint_proceeded = 1; | |
4324 | } | |
4325 | ||
abf85f46 JK |
4326 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4327 | or its equivalent. */ | |
4328 | ||
4329 | static int | |
4330 | command_line_is_silent (struct command_line *cmd) | |
4331 | { | |
4f45d445 | 4332 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4333 | } |
4334 | ||
4a64f543 MS |
4335 | /* Execute all the commands associated with all the breakpoints at |
4336 | this location. Any of these commands could cause the process to | |
4337 | proceed beyond this point, etc. We look out for such changes by | |
4338 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4339 | |
347bddb7 PA |
4340 | Returns true if a breakpoint command resumed the inferior. In that |
4341 | case, it is the caller's responsibility to recall it again with the | |
4342 | bpstat of the current thread. */ | |
4343 | ||
4344 | static int | |
4345 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4346 | { |
4347 | bpstat bs; | |
347bddb7 | 4348 | int again = 0; |
c906108c SS |
4349 | |
4350 | /* Avoid endless recursion if a `source' command is contained | |
4351 | in bs->commands. */ | |
4352 | if (executing_breakpoint_commands) | |
347bddb7 | 4353 | return 0; |
c906108c | 4354 | |
81b1e71c TT |
4355 | scoped_restore save_executing |
4356 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4357 | |
1ac32117 | 4358 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4359 | |
4a64f543 | 4360 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4361 | bs = *bsp; |
4362 | ||
4363 | breakpoint_proceeded = 0; | |
4364 | for (; bs != NULL; bs = bs->next) | |
4365 | { | |
d1b0a7bf | 4366 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4367 | |
4368 | /* Take ownership of the BSP's command tree, if it has one. | |
4369 | ||
4370 | The command tree could legitimately contain commands like | |
4371 | 'step' and 'next', which call clear_proceed_status, which | |
4372 | frees stop_bpstat's command tree. To make sure this doesn't | |
4373 | free the tree we're executing out from under us, we need to | |
4374 | take ownership of the tree ourselves. Since a given bpstat's | |
4375 | commands are only executed once, we don't need to copy it; we | |
4376 | can clear the pointer in the bpstat, and make sure we free | |
4377 | the tree when we're done. */ | |
d1b0a7bf | 4378 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4379 | bs->commands = NULL; |
d1b0a7bf TT |
4380 | if (ccmd != NULL) |
4381 | cmd = ccmd.get (); | |
abf85f46 JK |
4382 | if (command_line_is_silent (cmd)) |
4383 | { | |
4384 | /* The action has been already done by bpstat_stop_status. */ | |
4385 | cmd = cmd->next; | |
4386 | } | |
6c50ab1c | 4387 | |
c906108c SS |
4388 | while (cmd != NULL) |
4389 | { | |
4390 | execute_control_command (cmd); | |
4391 | ||
4392 | if (breakpoint_proceeded) | |
4393 | break; | |
4394 | else | |
4395 | cmd = cmd->next; | |
4396 | } | |
6c50ab1c | 4397 | |
c906108c | 4398 | if (breakpoint_proceeded) |
32c1e744 | 4399 | { |
cb814510 | 4400 | if (current_ui->async) |
347bddb7 PA |
4401 | /* If we are in async mode, then the target might be still |
4402 | running, not stopped at any breakpoint, so nothing for | |
4403 | us to do here -- just return to the event loop. */ | |
4404 | ; | |
32c1e744 VP |
4405 | else |
4406 | /* In sync mode, when execute_control_command returns | |
4407 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4408 | Breakpoint commands for that stop were not run, since |
4409 | execute_command does not run breakpoint commands -- | |
4410 | only command_line_handler does, but that one is not | |
4411 | involved in execution of breakpoint commands. So, we | |
4412 | can now execute breakpoint commands. It should be | |
4413 | noted that making execute_command do bpstat actions is | |
4414 | not an option -- in this case we'll have recursive | |
4415 | invocation of bpstat for each breakpoint with a | |
4416 | command, and can easily blow up GDB stack. Instead, we | |
4417 | return true, which will trigger the caller to recall us | |
4418 | with the new stop_bpstat. */ | |
4419 | again = 1; | |
4420 | break; | |
32c1e744 | 4421 | } |
c906108c | 4422 | } |
347bddb7 PA |
4423 | return again; |
4424 | } | |
4425 | ||
00431a78 PA |
4426 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4427 | one, is alive and has execution. Return NULL otherwise. */ | |
4428 | ||
4429 | static thread_info * | |
4430 | get_bpstat_thread () | |
4431 | { | |
4432 | if (inferior_ptid == null_ptid || !target_has_execution) | |
4433 | return NULL; | |
4434 | ||
4435 | thread_info *tp = inferior_thread (); | |
4436 | if (tp->state == THREAD_EXITED || tp->executing) | |
4437 | return NULL; | |
4438 | return tp; | |
4439 | } | |
4440 | ||
347bddb7 PA |
4441 | void |
4442 | bpstat_do_actions (void) | |
4443 | { | |
694c6bf5 | 4444 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4445 | thread_info *tp; |
353d1d73 | 4446 | |
347bddb7 | 4447 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4448 | while ((tp = get_bpstat_thread ()) != NULL) |
4449 | { | |
4450 | /* Since in sync mode, bpstat_do_actions may resume the | |
4451 | inferior, and only return when it is stopped at the next | |
4452 | breakpoint, we keep doing breakpoint actions until it returns | |
4453 | false to indicate the inferior was not resumed. */ | |
4454 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4455 | break; | |
4456 | } | |
353d1d73 | 4457 | |
694c6bf5 | 4458 | cleanup_if_error.release (); |
c906108c SS |
4459 | } |
4460 | ||
fa4727a6 DJ |
4461 | /* Print out the (old or new) value associated with a watchpoint. */ |
4462 | ||
4463 | static void | |
4464 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4465 | { | |
4466 | if (val == NULL) | |
4467 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4468 | else | |
79a45b7d TT |
4469 | { |
4470 | struct value_print_options opts; | |
4471 | get_user_print_options (&opts); | |
4472 | value_print (val, stream, &opts); | |
4473 | } | |
fa4727a6 DJ |
4474 | } |
4475 | ||
f303dbd6 PA |
4476 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4477 | debugging multiple threads. */ | |
4478 | ||
4479 | void | |
4480 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4481 | { | |
112e8700 | 4482 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4483 | return; |
4484 | ||
112e8700 | 4485 | uiout->text ("\n"); |
f303dbd6 PA |
4486 | |
4487 | if (show_thread_that_caused_stop ()) | |
4488 | { | |
4489 | const char *name; | |
4490 | struct thread_info *thr = inferior_thread (); | |
4491 | ||
112e8700 SM |
4492 | uiout->text ("Thread "); |
4493 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4494 | |
4495 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4496 | if (name != NULL) | |
4497 | { | |
112e8700 SM |
4498 | uiout->text (" \""); |
4499 | uiout->field_fmt ("name", "%s", name); | |
4500 | uiout->text ("\""); | |
f303dbd6 PA |
4501 | } |
4502 | ||
112e8700 | 4503 | uiout->text (" hit "); |
f303dbd6 PA |
4504 | } |
4505 | } | |
4506 | ||
e514a9d6 | 4507 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4508 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4509 | 'print_it' in the bpstat structure. Under some circumstances we |
4510 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4511 | normal_stop(). */ |
e514a9d6 JM |
4512 | |
4513 | static enum print_stop_action | |
4514 | print_bp_stop_message (bpstat bs) | |
4515 | { | |
4516 | switch (bs->print_it) | |
4517 | { | |
4518 | case print_it_noop: | |
4a64f543 | 4519 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4520 | return PRINT_UNKNOWN; |
4521 | break; | |
4522 | ||
4523 | case print_it_done: | |
4524 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4525 | relevant messages. */ |
e514a9d6 JM |
4526 | return PRINT_SRC_AND_LOC; |
4527 | break; | |
4528 | ||
4529 | case print_it_normal: | |
4f8d1dc6 | 4530 | { |
f431efe5 PA |
4531 | struct breakpoint *b = bs->breakpoint_at; |
4532 | ||
1a6a67de TJB |
4533 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4534 | which has since been deleted. */ | |
4535 | if (b == NULL) | |
4536 | return PRINT_UNKNOWN; | |
4537 | ||
348d480f PA |
4538 | /* Normal case. Call the breakpoint's print_it method. */ |
4539 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4540 | } |
348d480f | 4541 | break; |
3086aeae | 4542 | |
e514a9d6 | 4543 | default: |
8e65ff28 | 4544 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4545 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4546 | break; |
c906108c | 4547 | } |
c906108c SS |
4548 | } |
4549 | ||
edcc5120 TT |
4550 | /* A helper function that prints a shared library stopped event. */ |
4551 | ||
4552 | static void | |
4553 | print_solib_event (int is_catchpoint) | |
4554 | { | |
6fb16ce6 | 4555 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4556 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4557 | |
4558 | if (!is_catchpoint) | |
4559 | { | |
4560 | if (any_added || any_deleted) | |
112e8700 | 4561 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4562 | else |
112e8700 SM |
4563 | current_uiout->text (_("Stopped due to shared library event (no " |
4564 | "libraries added or removed)\n")); | |
edcc5120 TT |
4565 | } |
4566 | ||
112e8700 SM |
4567 | if (current_uiout->is_mi_like_p ()) |
4568 | current_uiout->field_string ("reason", | |
4569 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4570 | |
4571 | if (any_deleted) | |
4572 | { | |
112e8700 | 4573 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4574 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4575 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4576 | { |
6fb16ce6 SM |
4577 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4578 | ||
edcc5120 | 4579 | if (ix > 0) |
112e8700 SM |
4580 | current_uiout->text (" "); |
4581 | current_uiout->field_string ("library", name); | |
4582 | current_uiout->text ("\n"); | |
edcc5120 | 4583 | } |
edcc5120 TT |
4584 | } |
4585 | ||
4586 | if (any_added) | |
4587 | { | |
112e8700 | 4588 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4589 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4590 | bool first = true; |
52941706 | 4591 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4592 | { |
bcb430e4 | 4593 | if (!first) |
112e8700 | 4594 | current_uiout->text (" "); |
bcb430e4 | 4595 | first = false; |
112e8700 SM |
4596 | current_uiout->field_string ("library", iter->so_name); |
4597 | current_uiout->text ("\n"); | |
edcc5120 | 4598 | } |
edcc5120 TT |
4599 | } |
4600 | } | |
4601 | ||
e514a9d6 JM |
4602 | /* Print a message indicating what happened. This is called from |
4603 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4604 | list - a list of the eventpoints that caused this stop. KIND is |
4605 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4606 | routine calls the generic print routine for printing a message |
4607 | about reasons for stopping. This will print (for example) the | |
4608 | "Breakpoint n," part of the output. The return value of this | |
4609 | routine is one of: | |
c906108c | 4610 | |
4a64f543 | 4611 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4612 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4613 | code to print the location. An example is |
c5aa993b JM |
4614 | "Breakpoint 1, " which should be followed by |
4615 | the location. | |
917317f4 | 4616 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4617 | to also print the location part of the message. |
4618 | An example is the catch/throw messages, which | |
4a64f543 | 4619 | don't require a location appended to the end. |
917317f4 | 4620 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4621 | further info to be printed. */ |
c906108c | 4622 | |
917317f4 | 4623 | enum print_stop_action |
36dfb11c | 4624 | bpstat_print (bpstat bs, int kind) |
c906108c | 4625 | { |
f486487f | 4626 | enum print_stop_action val; |
c5aa993b | 4627 | |
c906108c | 4628 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4629 | (Currently all watchpoints go on the bpstat whether hit or not. |
4630 | That probably could (should) be changed, provided care is taken | |
c906108c | 4631 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4632 | for (; bs; bs = bs->next) |
4633 | { | |
4634 | val = print_bp_stop_message (bs); | |
4635 | if (val == PRINT_SRC_ONLY | |
4636 | || val == PRINT_SRC_AND_LOC | |
4637 | || val == PRINT_NOTHING) | |
4638 | return val; | |
4639 | } | |
c906108c | 4640 | |
36dfb11c TT |
4641 | /* If we had hit a shared library event breakpoint, |
4642 | print_bp_stop_message would print out this message. If we hit an | |
4643 | OS-level shared library event, do the same thing. */ | |
4644 | if (kind == TARGET_WAITKIND_LOADED) | |
4645 | { | |
edcc5120 | 4646 | print_solib_event (0); |
36dfb11c TT |
4647 | return PRINT_NOTHING; |
4648 | } | |
4649 | ||
e514a9d6 | 4650 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4651 | with and nothing was printed. */ |
917317f4 | 4652 | return PRINT_UNKNOWN; |
c906108c SS |
4653 | } |
4654 | ||
bf469271 | 4655 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4656 | |
bf469271 PA |
4657 | static bool |
4658 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4659 | { |
278cd55f | 4660 | struct value *mark = value_mark (); |
bf469271 | 4661 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4662 | |
c906108c | 4663 | value_free_to_mark (mark); |
bf469271 | 4664 | return res; |
c906108c SS |
4665 | } |
4666 | ||
5760d0ab | 4667 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4668 | |
04afa70c TT |
4669 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4670 | : next (NULL), | |
4671 | bp_location_at (bl), | |
4672 | breakpoint_at (bl->owner), | |
4673 | commands (NULL), | |
04afa70c TT |
4674 | print (0), |
4675 | stop (0), | |
4676 | print_it (print_it_normal) | |
c906108c | 4677 | { |
f431efe5 | 4678 | incref_bp_location (bl); |
04afa70c TT |
4679 | **bs_link_pointer = this; |
4680 | *bs_link_pointer = &next; | |
4681 | } | |
4682 | ||
4683 | bpstats::bpstats () | |
4684 | : next (NULL), | |
4685 | bp_location_at (NULL), | |
4686 | breakpoint_at (NULL), | |
4687 | commands (NULL), | |
04afa70c TT |
4688 | print (0), |
4689 | stop (0), | |
4690 | print_it (print_it_normal) | |
4691 | { | |
c906108c SS |
4692 | } |
4693 | \f | |
d983da9c DJ |
4694 | /* The target has stopped with waitstatus WS. Check if any hardware |
4695 | watchpoints have triggered, according to the target. */ | |
4696 | ||
4697 | int | |
4698 | watchpoints_triggered (struct target_waitstatus *ws) | |
4699 | { | |
57810aa7 | 4700 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4701 | CORE_ADDR addr; |
4702 | struct breakpoint *b; | |
4703 | ||
4704 | if (!stopped_by_watchpoint) | |
4705 | { | |
4706 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4707 | as not triggered. */ | |
4708 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4709 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4710 | { |
4711 | struct watchpoint *w = (struct watchpoint *) b; | |
4712 | ||
4713 | w->watchpoint_triggered = watch_triggered_no; | |
4714 | } | |
d983da9c DJ |
4715 | |
4716 | return 0; | |
4717 | } | |
4718 | ||
8b88a78e | 4719 | if (!target_stopped_data_address (current_top_target (), &addr)) |
d983da9c DJ |
4720 | { |
4721 | /* We were stopped by a watchpoint, but we don't know where. | |
4722 | Mark all watchpoints as unknown. */ | |
4723 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4724 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4725 | { |
4726 | struct watchpoint *w = (struct watchpoint *) b; | |
4727 | ||
4728 | w->watchpoint_triggered = watch_triggered_unknown; | |
4729 | } | |
d983da9c | 4730 | |
3c4797ba | 4731 | return 1; |
d983da9c DJ |
4732 | } |
4733 | ||
4734 | /* The target could report the data address. Mark watchpoints | |
4735 | affected by this data address as triggered, and all others as not | |
4736 | triggered. */ | |
4737 | ||
4738 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4739 | if (is_hardware_watchpoint (b)) |
d983da9c | 4740 | { |
3a5c3e22 | 4741 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4742 | struct bp_location *loc; |
d983da9c | 4743 | |
3a5c3e22 | 4744 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4745 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4746 | { |
3a5c3e22 | 4747 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4748 | { |
3a5c3e22 PA |
4749 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4750 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4751 | |
4752 | if (newaddr == start) | |
4753 | { | |
3a5c3e22 | 4754 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4755 | break; |
4756 | } | |
4757 | } | |
4758 | /* Exact match not required. Within range is sufficient. */ | |
8b88a78e | 4759 | else if (target_watchpoint_addr_within_range (current_top_target (), |
9c06b0b4 TJB |
4760 | addr, loc->address, |
4761 | loc->length)) | |
4762 | { | |
3a5c3e22 | 4763 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4764 | break; |
4765 | } | |
4766 | } | |
d983da9c DJ |
4767 | } |
4768 | ||
4769 | return 1; | |
4770 | } | |
4771 | ||
bf469271 PA |
4772 | /* Possible return values for watchpoint_check. */ |
4773 | enum wp_check_result | |
4774 | { | |
4775 | /* The watchpoint has been deleted. */ | |
4776 | WP_DELETED = 1, | |
4777 | ||
4778 | /* The value has changed. */ | |
4779 | WP_VALUE_CHANGED = 2, | |
4780 | ||
4781 | /* The value has not changed. */ | |
4782 | WP_VALUE_NOT_CHANGED = 3, | |
4783 | ||
4784 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4785 | WP_IGNORE = 4, | |
4786 | }; | |
c906108c SS |
4787 | |
4788 | #define BP_TEMPFLAG 1 | |
4789 | #define BP_HARDWAREFLAG 2 | |
4790 | ||
4a64f543 | 4791 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4792 | changed. */ |
553e4c11 | 4793 | |
bf469271 PA |
4794 | static wp_check_result |
4795 | watchpoint_check (bpstat bs) | |
c906108c | 4796 | { |
3a5c3e22 | 4797 | struct watchpoint *b; |
c906108c SS |
4798 | struct frame_info *fr; |
4799 | int within_current_scope; | |
4800 | ||
f431efe5 | 4801 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4802 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4803 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4804 | |
f6bc2008 PA |
4805 | /* If this is a local watchpoint, we only want to check if the |
4806 | watchpoint frame is in scope if the current thread is the thread | |
4807 | that was used to create the watchpoint. */ | |
4808 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4809 | return WP_IGNORE; |
f6bc2008 | 4810 | |
c906108c SS |
4811 | if (b->exp_valid_block == NULL) |
4812 | within_current_scope = 1; | |
4813 | else | |
4814 | { | |
edb3359d DJ |
4815 | struct frame_info *frame = get_current_frame (); |
4816 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4817 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4818 | ||
c9cf6e20 | 4819 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4820 | still in the function but the stack frame has already been |
4821 | invalidated. Since we can't rely on the values of local | |
4822 | variables after the stack has been destroyed, we are treating | |
4823 | the watchpoint in that state as `not changed' without further | |
4824 | checking. Don't mark watchpoints as changed if the current | |
4825 | frame is in an epilogue - even if they are in some other | |
4826 | frame, our view of the stack is likely to be wrong and | |
4827 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4828 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4829 | return WP_IGNORE; |
a0f49112 | 4830 | |
101dcfbe | 4831 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4832 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4833 | |
4834 | /* If we've gotten confused in the unwinder, we might have | |
4835 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4836 | if (within_current_scope) |
4837 | { | |
4838 | struct symbol *function; | |
4839 | ||
4840 | function = get_frame_function (fr); | |
4841 | if (function == NULL | |
4842 | || !contained_in (b->exp_valid_block, | |
4843 | SYMBOL_BLOCK_VALUE (function))) | |
4844 | within_current_scope = 0; | |
4845 | } | |
69fbadd5 | 4846 | |
edb3359d | 4847 | if (within_current_scope) |
c906108c SS |
4848 | /* If we end up stopping, the current frame will get selected |
4849 | in normal_stop. So this call to select_frame won't affect | |
4850 | the user. */ | |
0f7d239c | 4851 | select_frame (fr); |
c906108c | 4852 | } |
c5aa993b | 4853 | |
c906108c SS |
4854 | if (within_current_scope) |
4855 | { | |
4a64f543 MS |
4856 | /* We use value_{,free_to_}mark because it could be a *long* |
4857 | time before we return to the command level and call | |
4858 | free_all_values. We can't call free_all_values because we | |
4859 | might be in the middle of evaluating a function call. */ | |
c906108c | 4860 | |
0cf6dd15 | 4861 | int pc = 0; |
9c06b0b4 | 4862 | struct value *mark; |
fa4727a6 DJ |
4863 | struct value *new_val; |
4864 | ||
c1fc2657 | 4865 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
4866 | /* Since we don't know the exact trigger address (from |
4867 | stopped_data_address), just tell the user we've triggered | |
4868 | a mask watchpoint. */ | |
4869 | return WP_VALUE_CHANGED; | |
4870 | ||
4871 | mark = value_mark (); | |
4d01a485 | 4872 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4873 | |
bb9d5f81 PP |
4874 | if (b->val_bitsize != 0) |
4875 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
4876 | ||
4a64f543 MS |
4877 | /* We use value_equal_contents instead of value_equal because |
4878 | the latter coerces an array to a pointer, thus comparing just | |
4879 | the address of the array instead of its contents. This is | |
4880 | not what we want. */ | |
fa4727a6 | 4881 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
4882 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
4883 | new_val))) | |
c906108c | 4884 | { |
c906108c | 4885 | bs->old_val = b->val; |
850645cf | 4886 | b->val = release_value (new_val); |
fa4727a6 | 4887 | b->val_valid = 1; |
850645cf TT |
4888 | if (new_val != NULL) |
4889 | value_free_to_mark (mark); | |
c906108c SS |
4890 | return WP_VALUE_CHANGED; |
4891 | } | |
4892 | else | |
4893 | { | |
60e1c644 | 4894 | /* Nothing changed. */ |
c906108c | 4895 | value_free_to_mark (mark); |
c906108c SS |
4896 | return WP_VALUE_NOT_CHANGED; |
4897 | } | |
4898 | } | |
4899 | else | |
4900 | { | |
4901 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
4902 | if we temporarily ignored the watchpoint, then when |
4903 | we reenter the block in which it is valid it contains | |
4904 | garbage (in the case of a function, it may have two | |
4905 | garbage values, one before and one after the prologue). | |
4906 | So we can't even detect the first assignment to it and | |
4907 | watch after that (since the garbage may or may not equal | |
4908 | the first value assigned). */ | |
348d480f PA |
4909 | /* We print all the stop information in |
4910 | breakpoint_ops->print_it, but in this case, by the time we | |
4911 | call breakpoint_ops->print_it this bp will be deleted | |
4912 | already. So we have no choice but print the information | |
4913 | here. */ | |
468afe6c | 4914 | |
0e454242 | 4915 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
4916 | { |
4917 | struct ui_out *uiout = current_uiout; | |
4918 | ||
112e8700 SM |
4919 | if (uiout->is_mi_like_p ()) |
4920 | uiout->field_string | |
4921 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
4922 | uiout->text ("\nWatchpoint "); | |
c1fc2657 | 4923 | uiout->field_int ("wpnum", b->number); |
112e8700 | 4924 | uiout->text (" deleted because the program has left the block in\n" |
468afe6c PA |
4925 | "which its expression is valid.\n"); |
4926 | } | |
4ce44c66 | 4927 | |
cdac0397 | 4928 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 4929 | b->commands = NULL; |
d0fb5eae | 4930 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4931 | |
4932 | return WP_DELETED; | |
4933 | } | |
4934 | } | |
4935 | ||
18a18393 | 4936 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4937 | breakpoint location BL. This function does not check if we should |
4938 | stop, only if BL explains the stop. */ | |
4939 | ||
18a18393 | 4940 | static int |
6c95b8df | 4941 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 4942 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 4943 | const struct target_waitstatus *ws) |
18a18393 VP |
4944 | { |
4945 | struct breakpoint *b = bl->owner; | |
4946 | ||
348d480f | 4947 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4948 | gdb_assert (b != NULL); |
4949 | ||
bd522513 | 4950 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4951 | } |
4952 | ||
3a5c3e22 PA |
4953 | /* Determine if the watched values have actually changed, and we |
4954 | should stop. If not, set BS->stop to 0. */ | |
4955 | ||
18a18393 VP |
4956 | static void |
4957 | bpstat_check_watchpoint (bpstat bs) | |
4958 | { | |
2bdf28a0 | 4959 | const struct bp_location *bl; |
3a5c3e22 | 4960 | struct watchpoint *b; |
2bdf28a0 JK |
4961 | |
4962 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4963 | bl = bs->bp_location_at; |
2bdf28a0 | 4964 | gdb_assert (bl != NULL); |
3a5c3e22 | 4965 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4966 | gdb_assert (b != NULL); |
18a18393 | 4967 | |
18a18393 | 4968 | { |
18a18393 VP |
4969 | int must_check_value = 0; |
4970 | ||
c1fc2657 | 4971 | if (b->type == bp_watchpoint) |
18a18393 VP |
4972 | /* For a software watchpoint, we must always check the |
4973 | watched value. */ | |
4974 | must_check_value = 1; | |
4975 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4976 | /* We have a hardware watchpoint (read, write, or access) | |
4977 | and the target earlier reported an address watched by | |
4978 | this watchpoint. */ | |
4979 | must_check_value = 1; | |
4980 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 4981 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
4982 | /* We were stopped by a hardware watchpoint, but the target could |
4983 | not report the data address. We must check the watchpoint's | |
4984 | value. Access and read watchpoints are out of luck; without | |
4985 | a data address, we can't figure it out. */ | |
4986 | must_check_value = 1; | |
3a5c3e22 | 4987 | |
18a18393 VP |
4988 | if (must_check_value) |
4989 | { | |
bf469271 PA |
4990 | wp_check_result e; |
4991 | ||
a70b8144 | 4992 | try |
bf469271 PA |
4993 | { |
4994 | e = watchpoint_check (bs); | |
4995 | } | |
230d2906 | 4996 | catch (const gdb_exception &ex) |
bf469271 PA |
4997 | { |
4998 | exception_fprintf (gdb_stderr, ex, | |
4999 | "Error evaluating expression " | |
5000 | "for watchpoint %d\n", | |
5001 | b->number); | |
5002 | ||
5003 | SWITCH_THRU_ALL_UIS () | |
5004 | { | |
5005 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5006 | b->number); | |
5007 | } | |
5008 | watchpoint_del_at_next_stop (b); | |
5009 | e = WP_DELETED; | |
5010 | } | |
bf469271 | 5011 | |
18a18393 VP |
5012 | switch (e) |
5013 | { | |
5014 | case WP_DELETED: | |
5015 | /* We've already printed what needs to be printed. */ | |
5016 | bs->print_it = print_it_done; | |
5017 | /* Stop. */ | |
5018 | break; | |
60e1c644 PA |
5019 | case WP_IGNORE: |
5020 | bs->print_it = print_it_noop; | |
5021 | bs->stop = 0; | |
5022 | break; | |
18a18393 | 5023 | case WP_VALUE_CHANGED: |
c1fc2657 | 5024 | if (b->type == bp_read_watchpoint) |
18a18393 | 5025 | { |
85d721b8 PA |
5026 | /* There are two cases to consider here: |
5027 | ||
4a64f543 | 5028 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5029 | In that case, trust the target, and always report |
5030 | the watchpoint hit to the user. Even though | |
5031 | reads don't cause value changes, the value may | |
5032 | have changed since the last time it was read, and | |
5033 | since we're not trapping writes, we will not see | |
5034 | those, and as such we should ignore our notion of | |
5035 | old value. | |
5036 | ||
4a64f543 | 5037 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5038 | reads and writes. There are two ways this may |
5039 | happen: | |
5040 | ||
4a64f543 | 5041 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5042 | reads only, but can break on accesses (reads or |
5043 | writes), such as e.g., x86. We detect this case | |
5044 | at the time we try to insert read watchpoints. | |
5045 | ||
4a64f543 | 5046 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5047 | watchpoints, but, the user set an access or write |
5048 | watchpoint watching the same memory as this read | |
5049 | watchpoint. | |
5050 | ||
5051 | If we're watching memory writes as well as reads, | |
5052 | ignore watchpoint hits when we find that the | |
5053 | value hasn't changed, as reads don't cause | |
5054 | changes. This still gives false positives when | |
5055 | the program writes the same value to memory as | |
5056 | what there was already in memory (we will confuse | |
5057 | it for a read), but it's much better than | |
5058 | nothing. */ | |
5059 | ||
5060 | int other_write_watchpoint = 0; | |
5061 | ||
5062 | if (bl->watchpoint_type == hw_read) | |
5063 | { | |
5064 | struct breakpoint *other_b; | |
5065 | ||
5066 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5067 | if (other_b->type == bp_hardware_watchpoint |
5068 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5069 | { |
3a5c3e22 PA |
5070 | struct watchpoint *other_w = |
5071 | (struct watchpoint *) other_b; | |
5072 | ||
5073 | if (other_w->watchpoint_triggered | |
5074 | == watch_triggered_yes) | |
5075 | { | |
5076 | other_write_watchpoint = 1; | |
5077 | break; | |
5078 | } | |
85d721b8 PA |
5079 | } |
5080 | } | |
5081 | ||
5082 | if (other_write_watchpoint | |
5083 | || bl->watchpoint_type == hw_access) | |
5084 | { | |
5085 | /* We're watching the same memory for writes, | |
5086 | and the value changed since the last time we | |
5087 | updated it, so this trap must be for a write. | |
5088 | Ignore it. */ | |
5089 | bs->print_it = print_it_noop; | |
5090 | bs->stop = 0; | |
5091 | } | |
18a18393 VP |
5092 | } |
5093 | break; | |
5094 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5095 | if (b->type == bp_hardware_watchpoint |
5096 | || b->type == bp_watchpoint) | |
18a18393 VP |
5097 | { |
5098 | /* Don't stop: write watchpoints shouldn't fire if | |
5099 | the value hasn't changed. */ | |
5100 | bs->print_it = print_it_noop; | |
5101 | bs->stop = 0; | |
5102 | } | |
5103 | /* Stop. */ | |
5104 | break; | |
5105 | default: | |
5106 | /* Can't happen. */ | |
18a18393 VP |
5107 | break; |
5108 | } | |
5109 | } | |
5110 | else /* must_check_value == 0 */ | |
5111 | { | |
5112 | /* This is a case where some watchpoint(s) triggered, but | |
5113 | not at the address of this watchpoint, or else no | |
5114 | watchpoint triggered after all. So don't print | |
5115 | anything for this watchpoint. */ | |
5116 | bs->print_it = print_it_noop; | |
5117 | bs->stop = 0; | |
5118 | } | |
5119 | } | |
5120 | } | |
5121 | ||
7d4df6a4 DE |
5122 | /* For breakpoints that are currently marked as telling gdb to stop, |
5123 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5124 | of breakpoint referred to by BS. If we should not stop for this |
5125 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5126 | |
18a18393 | 5127 | static void |
00431a78 | 5128 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
18a18393 | 5129 | { |
2bdf28a0 JK |
5130 | const struct bp_location *bl; |
5131 | struct breakpoint *b; | |
bf469271 PA |
5132 | /* Assume stop. */ |
5133 | bool condition_result = true; | |
7d4df6a4 DE |
5134 | struct expression *cond; |
5135 | ||
5136 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5137 | |
5138 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5139 | bl = bs->bp_location_at; |
2bdf28a0 | 5140 | gdb_assert (bl != NULL); |
f431efe5 | 5141 | b = bs->breakpoint_at; |
2bdf28a0 | 5142 | gdb_assert (b != NULL); |
18a18393 | 5143 | |
b775012e LM |
5144 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5145 | need to do so again since GDB does not know if we stopped due to a | |
5146 | breakpoint or a single step breakpoint. */ | |
5147 | ||
18a18393 | 5148 | if (frame_id_p (b->frame_id) |
edb3359d | 5149 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5150 | { |
7d4df6a4 DE |
5151 | bs->stop = 0; |
5152 | return; | |
5153 | } | |
60e1c644 | 5154 | |
12ab52e9 PA |
5155 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5156 | evaluating the condition if this isn't the specified | |
5157 | thread/task. */ | |
00431a78 PA |
5158 | if ((b->thread != -1 && b->thread != thread->global_num) |
5159 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5160 | { |
5161 | bs->stop = 0; | |
5162 | return; | |
5163 | } | |
5164 | ||
6dddc817 DE |
5165 | /* Evaluate extension language breakpoints that have a "stop" method |
5166 | implemented. */ | |
5167 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5168 | |
7d4df6a4 DE |
5169 | if (is_watchpoint (b)) |
5170 | { | |
5171 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5172 | |
4d01a485 | 5173 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5174 | } |
5175 | else | |
4d01a485 | 5176 | cond = bl->cond.get (); |
60e1c644 | 5177 | |
7d4df6a4 DE |
5178 | if (cond && b->disposition != disp_del_at_next_stop) |
5179 | { | |
5180 | int within_current_scope = 1; | |
5181 | struct watchpoint * w; | |
60e1c644 | 5182 | |
7d4df6a4 DE |
5183 | /* We use value_mark and value_free_to_mark because it could |
5184 | be a long time before we return to the command level and | |
5185 | call free_all_values. We can't call free_all_values | |
5186 | because we might be in the middle of evaluating a | |
5187 | function call. */ | |
5188 | struct value *mark = value_mark (); | |
5189 | ||
5190 | if (is_watchpoint (b)) | |
5191 | w = (struct watchpoint *) b; | |
5192 | else | |
5193 | w = NULL; | |
5194 | ||
5195 | /* Need to select the frame, with all that implies so that | |
5196 | the conditions will have the right context. Because we | |
5197 | use the frame, we will not see an inlined function's | |
5198 | variables when we arrive at a breakpoint at the start | |
5199 | of the inlined function; the current frame will be the | |
5200 | call site. */ | |
5201 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5202 | select_frame (get_current_frame ()); | |
5203 | else | |
18a18393 | 5204 | { |
7d4df6a4 DE |
5205 | struct frame_info *frame; |
5206 | ||
5207 | /* For local watchpoint expressions, which particular | |
5208 | instance of a local is being watched matters, so we | |
5209 | keep track of the frame to evaluate the expression | |
5210 | in. To evaluate the condition however, it doesn't | |
5211 | really matter which instantiation of the function | |
5212 | where the condition makes sense triggers the | |
5213 | watchpoint. This allows an expression like "watch | |
5214 | global if q > 10" set in `func', catch writes to | |
5215 | global on all threads that call `func', or catch | |
5216 | writes on all recursive calls of `func' by a single | |
5217 | thread. We simply always evaluate the condition in | |
5218 | the innermost frame that's executing where it makes | |
5219 | sense to evaluate the condition. It seems | |
5220 | intuitive. */ | |
5221 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5222 | if (frame != NULL) | |
5223 | select_frame (frame); | |
5224 | else | |
5225 | within_current_scope = 0; | |
18a18393 | 5226 | } |
7d4df6a4 | 5227 | if (within_current_scope) |
bf469271 | 5228 | { |
a70b8144 | 5229 | try |
bf469271 PA |
5230 | { |
5231 | condition_result = breakpoint_cond_eval (cond); | |
5232 | } | |
230d2906 | 5233 | catch (const gdb_exception &ex) |
bf469271 PA |
5234 | { |
5235 | exception_fprintf (gdb_stderr, ex, | |
5236 | "Error in testing breakpoint condition:\n"); | |
5237 | } | |
bf469271 | 5238 | } |
7d4df6a4 | 5239 | else |
18a18393 | 5240 | { |
7d4df6a4 DE |
5241 | warning (_("Watchpoint condition cannot be tested " |
5242 | "in the current scope")); | |
5243 | /* If we failed to set the right context for this | |
5244 | watchpoint, unconditionally report it. */ | |
18a18393 | 5245 | } |
7d4df6a4 DE |
5246 | /* FIXME-someday, should give breakpoint #. */ |
5247 | value_free_to_mark (mark); | |
18a18393 | 5248 | } |
7d4df6a4 | 5249 | |
bf469271 | 5250 | if (cond && !condition_result) |
7d4df6a4 DE |
5251 | { |
5252 | bs->stop = 0; | |
5253 | } | |
7d4df6a4 DE |
5254 | else if (b->ignore_count > 0) |
5255 | { | |
5256 | b->ignore_count--; | |
5257 | bs->stop = 0; | |
5258 | /* Increase the hit count even though we don't stop. */ | |
5259 | ++(b->hit_count); | |
76727919 | 5260 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5261 | } |
18a18393 VP |
5262 | } |
5263 | ||
1cf4d951 PA |
5264 | /* Returns true if we need to track moribund locations of LOC's type |
5265 | on the current target. */ | |
5266 | ||
5267 | static int | |
5268 | need_moribund_for_location_type (struct bp_location *loc) | |
5269 | { | |
5270 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5271 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5272 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5273 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5274 | } | |
5275 | ||
ddfe970e | 5276 | /* See breakpoint.h. */ |
c906108c SS |
5277 | |
5278 | bpstat | |
ddfe970e | 5279 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5280 | const struct target_waitstatus *ws) |
c906108c | 5281 | { |
ddfe970e | 5282 | struct breakpoint *b; |
5760d0ab | 5283 | bpstat bs_head = NULL, *bs_link = &bs_head; |
c5aa993b | 5284 | |
429374b8 JK |
5285 | ALL_BREAKPOINTS (b) |
5286 | { | |
1a853c52 | 5287 | if (!breakpoint_enabled (b)) |
429374b8 | 5288 | continue; |
a5606eee | 5289 | |
ddfe970e | 5290 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
429374b8 | 5291 | { |
4a64f543 MS |
5292 | /* For hardware watchpoints, we look only at the first |
5293 | location. The watchpoint_check function will work on the | |
5294 | entire expression, not the individual locations. For | |
5295 | read watchpoints, the watchpoints_triggered function has | |
5296 | checked all locations already. */ | |
429374b8 JK |
5297 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5298 | break; | |
18a18393 | 5299 | |
f6592439 | 5300 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5301 | continue; |
c5aa993b | 5302 | |
09ac7c10 | 5303 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5304 | continue; |
c5aa993b | 5305 | |
4a64f543 MS |
5306 | /* Come here if it's a watchpoint, or if the break address |
5307 | matches. */ | |
c5aa993b | 5308 | |
ddfe970e KS |
5309 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
5310 | explain stop. */ | |
c5aa993b | 5311 | |
f431efe5 PA |
5312 | /* Assume we stop. Should we find a watchpoint that is not |
5313 | actually triggered, or if the condition of the breakpoint | |
5314 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5315 | bs->stop = 1; |
5316 | bs->print = 1; | |
d983da9c | 5317 | |
f431efe5 PA |
5318 | /* If this is a scope breakpoint, mark the associated |
5319 | watchpoint as triggered so that we will handle the | |
5320 | out-of-scope event. We'll get to the watchpoint next | |
5321 | iteration. */ | |
d0fb5eae | 5322 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5323 | { |
5324 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5325 | ||
5326 | w->watchpoint_triggered = watch_triggered_yes; | |
5327 | } | |
f431efe5 PA |
5328 | } |
5329 | } | |
5330 | ||
7c16b83e | 5331 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5332 | if (!target_supports_stopped_by_sw_breakpoint () |
5333 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5334 | { |
1123588c | 5335 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5336 | { |
1cf4d951 PA |
5337 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5338 | && need_moribund_for_location_type (loc)) | |
5339 | { | |
ddfe970e | 5340 | bpstat bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5341 | /* For hits of moribund locations, we should just proceed. */ |
5342 | bs->stop = 0; | |
5343 | bs->print = 0; | |
5344 | bs->print_it = print_it_noop; | |
5345 | } | |
f431efe5 PA |
5346 | } |
5347 | } | |
5348 | ||
ddfe970e KS |
5349 | return bs_head; |
5350 | } | |
5351 | ||
5352 | /* See breakpoint.h. */ | |
5353 | ||
5354 | bpstat | |
5355 | bpstat_stop_status (const address_space *aspace, | |
00431a78 | 5356 | CORE_ADDR bp_addr, thread_info *thread, |
ddfe970e KS |
5357 | const struct target_waitstatus *ws, |
5358 | bpstat stop_chain) | |
5359 | { | |
5360 | struct breakpoint *b = NULL; | |
5361 | /* First item of allocated bpstat's. */ | |
5362 | bpstat bs_head = stop_chain; | |
5363 | bpstat bs; | |
5364 | int need_remove_insert; | |
5365 | int removed_any; | |
5366 | ||
5367 | /* First, build the bpstat chain with locations that explain a | |
5368 | target stop, while being careful to not set the target running, | |
5369 | as that may invalidate locations (in particular watchpoint | |
5370 | locations are recreated). Resuming will happen here with | |
5371 | breakpoint conditions or watchpoint expressions that include | |
5372 | inferior function calls. */ | |
5373 | if (bs_head == NULL) | |
5374 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5375 | ||
edcc5120 TT |
5376 | /* A bit of special processing for shlib breakpoints. We need to |
5377 | process solib loading here, so that the lists of loaded and | |
5378 | unloaded libraries are correct before we handle "catch load" and | |
5379 | "catch unload". */ | |
5380 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5381 | { | |
5d268276 | 5382 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5383 | { |
5384 | handle_solib_event (); | |
5385 | break; | |
5386 | } | |
5387 | } | |
5388 | ||
f431efe5 PA |
5389 | /* Now go through the locations that caused the target to stop, and |
5390 | check whether we're interested in reporting this stop to higher | |
5391 | layers, or whether we should resume the target transparently. */ | |
5392 | ||
5393 | removed_any = 0; | |
5394 | ||
5760d0ab | 5395 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5396 | { |
5397 | if (!bs->stop) | |
5398 | continue; | |
5399 | ||
f431efe5 | 5400 | b = bs->breakpoint_at; |
348d480f PA |
5401 | b->ops->check_status (bs); |
5402 | if (bs->stop) | |
28010a5d | 5403 | { |
00431a78 | 5404 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5405 | |
429374b8 JK |
5406 | if (bs->stop) |
5407 | { | |
5408 | ++(b->hit_count); | |
76727919 | 5409 | gdb::observers::breakpoint_modified.notify (b); |
c906108c | 5410 | |
4a64f543 | 5411 | /* We will stop here. */ |
429374b8 JK |
5412 | if (b->disposition == disp_disable) |
5413 | { | |
816338b5 | 5414 | --(b->enable_count); |
1a853c52 | 5415 | if (b->enable_count <= 0) |
429374b8 | 5416 | b->enable_state = bp_disabled; |
f431efe5 | 5417 | removed_any = 1; |
429374b8 JK |
5418 | } |
5419 | if (b->silent) | |
5420 | bs->print = 0; | |
5421 | bs->commands = b->commands; | |
abf85f46 | 5422 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5423 | ? bs->commands.get () : NULL)) |
abf85f46 | 5424 | bs->print = 0; |
9d6e6e84 HZ |
5425 | |
5426 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5427 | } |
5428 | ||
348d480f | 5429 | } |
a9b3a50f PA |
5430 | |
5431 | /* Print nothing for this entry if we don't stop or don't | |
5432 | print. */ | |
5433 | if (!bs->stop || !bs->print) | |
5434 | bs->print_it = print_it_noop; | |
429374b8 | 5435 | } |
876fa593 | 5436 | |
d983da9c DJ |
5437 | /* If we aren't stopping, the value of some hardware watchpoint may |
5438 | not have changed, but the intermediate memory locations we are | |
5439 | watching may have. Don't bother if we're stopping; this will get | |
5440 | done later. */ | |
d832cb68 | 5441 | need_remove_insert = 0; |
5760d0ab JK |
5442 | if (! bpstat_causes_stop (bs_head)) |
5443 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5444 | if (!bs->stop |
f431efe5 PA |
5445 | && bs->breakpoint_at |
5446 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5447 | { |
3a5c3e22 PA |
5448 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5449 | ||
5450 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5451 | need_remove_insert = 1; |
d983da9c DJ |
5452 | } |
5453 | ||
d832cb68 | 5454 | if (need_remove_insert) |
44702360 | 5455 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5456 | else if (removed_any) |
44702360 | 5457 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5458 | |
5760d0ab | 5459 | return bs_head; |
c906108c | 5460 | } |
628fe4e4 JK |
5461 | |
5462 | static void | |
5463 | handle_jit_event (void) | |
5464 | { | |
5465 | struct frame_info *frame; | |
5466 | struct gdbarch *gdbarch; | |
5467 | ||
243a9253 PA |
5468 | if (debug_infrun) |
5469 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5470 | ||
628fe4e4 JK |
5471 | /* Switch terminal for any messages produced by |
5472 | breakpoint_re_set. */ | |
223ffa71 | 5473 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5474 | |
5475 | frame = get_current_frame (); | |
5476 | gdbarch = get_frame_arch (frame); | |
5477 | ||
5478 | jit_event_handler (gdbarch); | |
5479 | ||
223ffa71 | 5480 | target_terminal::inferior (); |
628fe4e4 JK |
5481 | } |
5482 | ||
5483 | /* Prepare WHAT final decision for infrun. */ | |
5484 | ||
5485 | /* Decide what infrun needs to do with this bpstat. */ | |
5486 | ||
c906108c | 5487 | struct bpstat_what |
0e30163f | 5488 | bpstat_what (bpstat bs_head) |
c906108c | 5489 | { |
c906108c | 5490 | struct bpstat_what retval; |
0e30163f | 5491 | bpstat bs; |
c906108c | 5492 | |
628fe4e4 | 5493 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5494 | retval.call_dummy = STOP_NONE; |
186c406b | 5495 | retval.is_longjmp = 0; |
628fe4e4 | 5496 | |
0e30163f | 5497 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5498 | { |
628fe4e4 JK |
5499 | /* Extract this BS's action. After processing each BS, we check |
5500 | if its action overrides all we've seem so far. */ | |
5501 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5502 | enum bptype bptype; | |
5503 | ||
c906108c | 5504 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5505 | { |
5506 | /* I suspect this can happen if it was a momentary | |
5507 | breakpoint which has since been deleted. */ | |
5508 | bptype = bp_none; | |
5509 | } | |
20874c92 | 5510 | else |
f431efe5 | 5511 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5512 | |
5513 | switch (bptype) | |
c906108c SS |
5514 | { |
5515 | case bp_none: | |
628fe4e4 | 5516 | break; |
c906108c SS |
5517 | case bp_breakpoint: |
5518 | case bp_hardware_breakpoint: | |
7c16b83e | 5519 | case bp_single_step: |
c906108c SS |
5520 | case bp_until: |
5521 | case bp_finish: | |
a9b3a50f | 5522 | case bp_shlib_event: |
c906108c SS |
5523 | if (bs->stop) |
5524 | { | |
5525 | if (bs->print) | |
628fe4e4 | 5526 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5527 | else |
628fe4e4 | 5528 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5529 | } |
5530 | else | |
628fe4e4 | 5531 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5532 | break; |
5533 | case bp_watchpoint: | |
5534 | case bp_hardware_watchpoint: | |
5535 | case bp_read_watchpoint: | |
5536 | case bp_access_watchpoint: | |
5537 | if (bs->stop) | |
5538 | { | |
5539 | if (bs->print) | |
628fe4e4 | 5540 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5541 | else |
628fe4e4 | 5542 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5543 | } |
5544 | else | |
628fe4e4 JK |
5545 | { |
5546 | /* There was a watchpoint, but we're not stopping. | |
5547 | This requires no further action. */ | |
5548 | } | |
c906108c SS |
5549 | break; |
5550 | case bp_longjmp: | |
e2e4d78b | 5551 | case bp_longjmp_call_dummy: |
186c406b | 5552 | case bp_exception: |
0a39bb32 PA |
5553 | if (bs->stop) |
5554 | { | |
5555 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5556 | retval.is_longjmp = bptype != bp_exception; | |
5557 | } | |
5558 | else | |
5559 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5560 | break; |
5561 | case bp_longjmp_resume: | |
186c406b | 5562 | case bp_exception_resume: |
0a39bb32 PA |
5563 | if (bs->stop) |
5564 | { | |
5565 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5566 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5567 | } | |
5568 | else | |
5569 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5570 | break; |
5571 | case bp_step_resume: | |
5572 | if (bs->stop) | |
628fe4e4 JK |
5573 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5574 | else | |
c906108c | 5575 | { |
628fe4e4 JK |
5576 | /* It is for the wrong frame. */ |
5577 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5578 | } |
c906108c | 5579 | break; |
2c03e5be PA |
5580 | case bp_hp_step_resume: |
5581 | if (bs->stop) | |
5582 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5583 | else | |
5584 | { | |
5585 | /* It is for the wrong frame. */ | |
5586 | this_action = BPSTAT_WHAT_SINGLE; | |
5587 | } | |
5588 | break; | |
c906108c | 5589 | case bp_watchpoint_scope: |
c4093a6a | 5590 | case bp_thread_event: |
1900040c | 5591 | case bp_overlay_event: |
0fd8e87f | 5592 | case bp_longjmp_master: |
aa7d318d | 5593 | case bp_std_terminate_master: |
186c406b | 5594 | case bp_exception_master: |
628fe4e4 | 5595 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5596 | break; |
ce78b96d | 5597 | case bp_catchpoint: |
c5aa993b JM |
5598 | if (bs->stop) |
5599 | { | |
5600 | if (bs->print) | |
628fe4e4 | 5601 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5602 | else |
628fe4e4 | 5603 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5604 | } |
5605 | else | |
628fe4e4 JK |
5606 | { |
5607 | /* There was a catchpoint, but we're not stopping. | |
5608 | This requires no further action. */ | |
5609 | } | |
5610 | break; | |
628fe4e4 | 5611 | case bp_jit_event: |
628fe4e4 | 5612 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5613 | break; |
c906108c | 5614 | case bp_call_dummy: |
53a5351d JM |
5615 | /* Make sure the action is stop (silent or noisy), |
5616 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5617 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5618 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5619 | break; |
5620 | case bp_std_terminate: | |
5621 | /* Make sure the action is stop (silent or noisy), | |
5622 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5623 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5624 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5625 | break; |
1042e4c0 | 5626 | case bp_tracepoint: |
7a697b8d | 5627 | case bp_fast_tracepoint: |
0fb4aa4b | 5628 | case bp_static_tracepoint: |
1042e4c0 SS |
5629 | /* Tracepoint hits should not be reported back to GDB, and |
5630 | if one got through somehow, it should have been filtered | |
5631 | out already. */ | |
5632 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5633 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5634 | break; |
5635 | case bp_gnu_ifunc_resolver: | |
5636 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5637 | this_action = BPSTAT_WHAT_SINGLE; | |
5638 | break; | |
5639 | case bp_gnu_ifunc_resolver_return: | |
5640 | /* The breakpoint will be removed, execution will restart from the | |
5641 | PC of the former breakpoint. */ | |
5642 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5643 | break; | |
e7e0cddf SS |
5644 | |
5645 | case bp_dprintf: | |
a11cfd87 HZ |
5646 | if (bs->stop) |
5647 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5648 | else | |
5649 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5650 | break; |
5651 | ||
628fe4e4 JK |
5652 | default: |
5653 | internal_error (__FILE__, __LINE__, | |
5654 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5655 | } |
628fe4e4 | 5656 | |
325fac50 | 5657 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5658 | } |
628fe4e4 | 5659 | |
243a9253 PA |
5660 | return retval; |
5661 | } | |
628fe4e4 | 5662 | |
243a9253 PA |
5663 | void |
5664 | bpstat_run_callbacks (bpstat bs_head) | |
5665 | { | |
5666 | bpstat bs; | |
628fe4e4 | 5667 | |
0e30163f JK |
5668 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5669 | { | |
5670 | struct breakpoint *b = bs->breakpoint_at; | |
5671 | ||
5672 | if (b == NULL) | |
5673 | continue; | |
5674 | switch (b->type) | |
5675 | { | |
243a9253 PA |
5676 | case bp_jit_event: |
5677 | handle_jit_event (); | |
5678 | break; | |
0e30163f JK |
5679 | case bp_gnu_ifunc_resolver: |
5680 | gnu_ifunc_resolver_stop (b); | |
5681 | break; | |
5682 | case bp_gnu_ifunc_resolver_return: | |
5683 | gnu_ifunc_resolver_return_stop (b); | |
5684 | break; | |
5685 | } | |
5686 | } | |
c906108c SS |
5687 | } |
5688 | ||
5689 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5690 | without hardware support). This isn't related to a specific bpstat, | |
5691 | just to things like whether watchpoints are set. */ | |
5692 | ||
c5aa993b | 5693 | int |
fba45db2 | 5694 | bpstat_should_step (void) |
c906108c SS |
5695 | { |
5696 | struct breakpoint *b; | |
cc59ec59 | 5697 | |
c906108c | 5698 | ALL_BREAKPOINTS (b) |
717a8278 | 5699 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5700 | return 1; |
c906108c SS |
5701 | return 0; |
5702 | } | |
5703 | ||
67822962 PA |
5704 | int |
5705 | bpstat_causes_stop (bpstat bs) | |
5706 | { | |
5707 | for (; bs != NULL; bs = bs->next) | |
5708 | if (bs->stop) | |
5709 | return 1; | |
5710 | ||
5711 | return 0; | |
5712 | } | |
5713 | ||
c906108c | 5714 | \f |
c5aa993b | 5715 | |
170b53b2 UW |
5716 | /* Compute a string of spaces suitable to indent the next line |
5717 | so it starts at the position corresponding to the table column | |
5718 | named COL_NAME in the currently active table of UIOUT. */ | |
5719 | ||
5720 | static char * | |
5721 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5722 | { | |
5723 | static char wrap_indent[80]; | |
5724 | int i, total_width, width, align; | |
c5209615 | 5725 | const char *text; |
170b53b2 UW |
5726 | |
5727 | total_width = 0; | |
112e8700 | 5728 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5729 | { |
5730 | if (strcmp (text, col_name) == 0) | |
5731 | { | |
5732 | gdb_assert (total_width < sizeof wrap_indent); | |
5733 | memset (wrap_indent, ' ', total_width); | |
5734 | wrap_indent[total_width] = 0; | |
5735 | ||
5736 | return wrap_indent; | |
5737 | } | |
5738 | ||
5739 | total_width += width + 1; | |
5740 | } | |
5741 | ||
5742 | return NULL; | |
5743 | } | |
5744 | ||
b775012e LM |
5745 | /* Determine if the locations of this breakpoint will have their conditions |
5746 | evaluated by the target, host or a mix of both. Returns the following: | |
5747 | ||
5748 | "host": Host evals condition. | |
5749 | "host or target": Host or Target evals condition. | |
5750 | "target": Target evals condition. | |
5751 | */ | |
5752 | ||
5753 | static const char * | |
5754 | bp_condition_evaluator (struct breakpoint *b) | |
5755 | { | |
5756 | struct bp_location *bl; | |
5757 | char host_evals = 0; | |
5758 | char target_evals = 0; | |
5759 | ||
5760 | if (!b) | |
5761 | return NULL; | |
5762 | ||
5763 | if (!is_breakpoint (b)) | |
5764 | return NULL; | |
5765 | ||
5766 | if (gdb_evaluates_breakpoint_condition_p () | |
5767 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5768 | return condition_evaluation_host; | |
5769 | ||
5770 | for (bl = b->loc; bl; bl = bl->next) | |
5771 | { | |
5772 | if (bl->cond_bytecode) | |
5773 | target_evals++; | |
5774 | else | |
5775 | host_evals++; | |
5776 | } | |
5777 | ||
5778 | if (host_evals && target_evals) | |
5779 | return condition_evaluation_both; | |
5780 | else if (target_evals) | |
5781 | return condition_evaluation_target; | |
5782 | else | |
5783 | return condition_evaluation_host; | |
5784 | } | |
5785 | ||
5786 | /* Determine the breakpoint location's condition evaluator. This is | |
5787 | similar to bp_condition_evaluator, but for locations. */ | |
5788 | ||
5789 | static const char * | |
5790 | bp_location_condition_evaluator (struct bp_location *bl) | |
5791 | { | |
5792 | if (bl && !is_breakpoint (bl->owner)) | |
5793 | return NULL; | |
5794 | ||
5795 | if (gdb_evaluates_breakpoint_condition_p () | |
5796 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5797 | return condition_evaluation_host; | |
5798 | ||
5799 | if (bl && bl->cond_bytecode) | |
5800 | return condition_evaluation_target; | |
5801 | else | |
5802 | return condition_evaluation_host; | |
5803 | } | |
5804 | ||
859825b8 JK |
5805 | /* Print the LOC location out of the list of B->LOC locations. */ |
5806 | ||
170b53b2 UW |
5807 | static void |
5808 | print_breakpoint_location (struct breakpoint *b, | |
5809 | struct bp_location *loc) | |
0d381245 | 5810 | { |
79a45e25 | 5811 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5812 | |
5813 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5814 | |
859825b8 JK |
5815 | if (loc != NULL && loc->shlib_disabled) |
5816 | loc = NULL; | |
5817 | ||
6c95b8df PA |
5818 | if (loc != NULL) |
5819 | set_current_program_space (loc->pspace); | |
5820 | ||
56435ebe | 5821 | if (b->display_canonical) |
d28cd78a | 5822 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5823 | else if (loc && loc->symtab) |
0d381245 | 5824 | { |
4a27f119 KS |
5825 | const struct symbol *sym = loc->symbol; |
5826 | ||
0d381245 VP |
5827 | if (sym) |
5828 | { | |
112e8700 | 5829 | uiout->text ("in "); |
cbe56571 TT |
5830 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym), |
5831 | ui_out_style_kind::FUNCTION); | |
112e8700 SM |
5832 | uiout->text (" "); |
5833 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5834 | uiout->text ("at "); | |
0d381245 | 5835 | } |
112e8700 | 5836 | uiout->field_string ("file", |
cbe56571 TT |
5837 | symtab_to_filename_for_display (loc->symtab), |
5838 | ui_out_style_kind::FILE); | |
112e8700 | 5839 | uiout->text (":"); |
05cba821 | 5840 | |
112e8700 SM |
5841 | if (uiout->is_mi_like_p ()) |
5842 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 5843 | |
112e8700 | 5844 | uiout->field_int ("line", loc->line_number); |
0d381245 | 5845 | } |
859825b8 | 5846 | else if (loc) |
0d381245 | 5847 | { |
d7e74731 | 5848 | string_file stb; |
170b53b2 | 5849 | |
d7e74731 | 5850 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 5851 | demangle, ""); |
112e8700 | 5852 | uiout->field_stream ("at", stb); |
0d381245 | 5853 | } |
859825b8 | 5854 | else |
f00aae0f | 5855 | { |
d28cd78a TT |
5856 | uiout->field_string ("pending", |
5857 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
5858 | /* If extra_string is available, it could be holding a condition |
5859 | or dprintf arguments. In either case, make sure it is printed, | |
5860 | too, but only for non-MI streams. */ | |
112e8700 | 5861 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
5862 | { |
5863 | if (b->type == bp_dprintf) | |
112e8700 | 5864 | uiout->text (","); |
f00aae0f | 5865 | else |
112e8700 SM |
5866 | uiout->text (" "); |
5867 | uiout->text (b->extra_string); | |
f00aae0f KS |
5868 | } |
5869 | } | |
6c95b8df | 5870 | |
b775012e LM |
5871 | if (loc && is_breakpoint (b) |
5872 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5873 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5874 | { | |
112e8700 SM |
5875 | uiout->text (" ("); |
5876 | uiout->field_string ("evaluated-by", | |
b775012e | 5877 | bp_location_condition_evaluator (loc)); |
112e8700 | 5878 | uiout->text (")"); |
b775012e | 5879 | } |
0d381245 VP |
5880 | } |
5881 | ||
269b11a2 PA |
5882 | static const char * |
5883 | bptype_string (enum bptype type) | |
c906108c | 5884 | { |
c4093a6a JM |
5885 | struct ep_type_description |
5886 | { | |
5887 | enum bptype type; | |
a121b7c1 | 5888 | const char *description; |
c4093a6a JM |
5889 | }; |
5890 | static struct ep_type_description bptypes[] = | |
c906108c | 5891 | { |
c5aa993b JM |
5892 | {bp_none, "?deleted?"}, |
5893 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5894 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 5895 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
5896 | {bp_until, "until"}, |
5897 | {bp_finish, "finish"}, | |
5898 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5899 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5900 | {bp_read_watchpoint, "read watchpoint"}, |
5901 | {bp_access_watchpoint, "acc watchpoint"}, | |
5902 | {bp_longjmp, "longjmp"}, | |
5903 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5904 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5905 | {bp_exception, "exception"}, |
5906 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5907 | {bp_step_resume, "step resume"}, |
2c03e5be | 5908 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5909 | {bp_watchpoint_scope, "watchpoint scope"}, |
5910 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5911 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5912 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5913 | {bp_thread_event, "thread events"}, |
1900040c | 5914 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5915 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5916 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5917 | {bp_exception_master, "exception master"}, |
ce78b96d | 5918 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5919 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5920 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5921 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5922 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5923 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5924 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5925 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5926 | }; |
269b11a2 PA |
5927 | |
5928 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5929 | || ((int) type != bptypes[(int) type].type)) | |
5930 | internal_error (__FILE__, __LINE__, | |
5931 | _("bptypes table does not describe type #%d."), | |
5932 | (int) type); | |
5933 | ||
5934 | return bptypes[(int) type].description; | |
5935 | } | |
5936 | ||
998580f1 MK |
5937 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5938 | For CLI, prefix the list with the string 'inf'. */ | |
5939 | ||
5940 | static void | |
5941 | output_thread_groups (struct ui_out *uiout, | |
5942 | const char *field_name, | |
5c632425 | 5943 | const std::vector<int> &inf_nums, |
998580f1 MK |
5944 | int mi_only) |
5945 | { | |
112e8700 | 5946 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
5947 | |
5948 | /* For backward compatibility, don't display inferiors in CLI unless | |
5949 | there are several. Always display them for MI. */ | |
5950 | if (!is_mi && mi_only) | |
5951 | return; | |
5952 | ||
10f489e5 | 5953 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 5954 | |
5c632425 | 5955 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
5956 | { |
5957 | if (is_mi) | |
5958 | { | |
5959 | char mi_group[10]; | |
5960 | ||
5c632425 | 5961 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 5962 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
5963 | } |
5964 | else | |
5965 | { | |
5966 | if (i == 0) | |
112e8700 | 5967 | uiout->text (" inf "); |
998580f1 | 5968 | else |
112e8700 | 5969 | uiout->text (", "); |
998580f1 | 5970 | |
5c632425 | 5971 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
5972 | } |
5973 | } | |
998580f1 MK |
5974 | } |
5975 | ||
269b11a2 PA |
5976 | /* Print B to gdb_stdout. */ |
5977 | ||
5978 | static void | |
5979 | print_one_breakpoint_location (struct breakpoint *b, | |
5980 | struct bp_location *loc, | |
5981 | int loc_number, | |
5982 | struct bp_location **last_loc, | |
269b11a2 PA |
5983 | int allflag) |
5984 | { | |
5985 | struct command_line *l; | |
c2c6d25f | 5986 | static char bpenables[] = "nynny"; |
c906108c | 5987 | |
79a45e25 | 5988 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
5989 | int header_of_multiple = 0; |
5990 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
5991 | struct value_print_options opts; |
5992 | ||
5993 | get_user_print_options (&opts); | |
0d381245 VP |
5994 | |
5995 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
5996 | /* See comment in print_one_breakpoint concerning treatment of |
5997 | breakpoints with single disabled location. */ | |
0d381245 VP |
5998 | if (loc == NULL |
5999 | && (b->loc != NULL | |
6000 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6001 | header_of_multiple = 1; | |
6002 | if (loc == NULL) | |
6003 | loc = b->loc; | |
6004 | ||
c4093a6a JM |
6005 | annotate_record (); |
6006 | ||
6007 | /* 1 */ | |
6008 | annotate_field (0); | |
0d381245 | 6009 | if (part_of_multiple) |
528e1572 | 6010 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
0d381245 | 6011 | else |
528e1572 | 6012 | uiout->field_int ("number", b->number); |
c4093a6a JM |
6013 | |
6014 | /* 2 */ | |
6015 | annotate_field (1); | |
0d381245 | 6016 | if (part_of_multiple) |
112e8700 | 6017 | uiout->field_skip ("type"); |
269b11a2 | 6018 | else |
112e8700 | 6019 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6020 | |
6021 | /* 3 */ | |
6022 | annotate_field (2); | |
0d381245 | 6023 | if (part_of_multiple) |
112e8700 | 6024 | uiout->field_skip ("disp"); |
0d381245 | 6025 | else |
112e8700 | 6026 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6027 | |
c4093a6a JM |
6028 | /* 4 */ |
6029 | annotate_field (3); | |
0d381245 | 6030 | if (part_of_multiple) |
112e8700 | 6031 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6032 | else |
112e8700 | 6033 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
0d381245 | 6034 | |
c4093a6a | 6035 | /* 5 and 6 */ |
3086aeae | 6036 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6037 | { |
4a64f543 MS |
6038 | /* Although the print_one can possibly print all locations, |
6039 | calling it here is not likely to get any nice result. So, | |
6040 | make sure there's just one location. */ | |
0d381245 | 6041 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6042 | b->ops->print_one (b, last_loc); |
0d381245 | 6043 | } |
3086aeae DJ |
6044 | else |
6045 | switch (b->type) | |
6046 | { | |
6047 | case bp_none: | |
6048 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6049 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6050 | break; |
c906108c | 6051 | |
3086aeae DJ |
6052 | case bp_watchpoint: |
6053 | case bp_hardware_watchpoint: | |
6054 | case bp_read_watchpoint: | |
6055 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6056 | { |
6057 | struct watchpoint *w = (struct watchpoint *) b; | |
6058 | ||
6059 | /* Field 4, the address, is omitted (which makes the columns | |
6060 | not line up too nicely with the headers, but the effect | |
6061 | is relatively readable). */ | |
6062 | if (opts.addressprint) | |
112e8700 | 6063 | uiout->field_skip ("addr"); |
3a5c3e22 | 6064 | annotate_field (5); |
112e8700 | 6065 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6066 | } |
3086aeae DJ |
6067 | break; |
6068 | ||
3086aeae DJ |
6069 | case bp_breakpoint: |
6070 | case bp_hardware_breakpoint: | |
7c16b83e | 6071 | case bp_single_step: |
3086aeae DJ |
6072 | case bp_until: |
6073 | case bp_finish: | |
6074 | case bp_longjmp: | |
6075 | case bp_longjmp_resume: | |
e2e4d78b | 6076 | case bp_longjmp_call_dummy: |
186c406b TT |
6077 | case bp_exception: |
6078 | case bp_exception_resume: | |
3086aeae | 6079 | case bp_step_resume: |
2c03e5be | 6080 | case bp_hp_step_resume: |
3086aeae DJ |
6081 | case bp_watchpoint_scope: |
6082 | case bp_call_dummy: | |
aa7d318d | 6083 | case bp_std_terminate: |
3086aeae DJ |
6084 | case bp_shlib_event: |
6085 | case bp_thread_event: | |
6086 | case bp_overlay_event: | |
0fd8e87f | 6087 | case bp_longjmp_master: |
aa7d318d | 6088 | case bp_std_terminate_master: |
186c406b | 6089 | case bp_exception_master: |
1042e4c0 | 6090 | case bp_tracepoint: |
7a697b8d | 6091 | case bp_fast_tracepoint: |
0fb4aa4b | 6092 | case bp_static_tracepoint: |
e7e0cddf | 6093 | case bp_dprintf: |
4efc6507 | 6094 | case bp_jit_event: |
0e30163f JK |
6095 | case bp_gnu_ifunc_resolver: |
6096 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6097 | if (opts.addressprint) |
3086aeae DJ |
6098 | { |
6099 | annotate_field (4); | |
54e52265 | 6100 | if (header_of_multiple) |
112e8700 | 6101 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6102 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6103 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6104 | else |
112e8700 | 6105 | uiout->field_core_addr ("addr", |
5af949e3 | 6106 | loc->gdbarch, loc->address); |
3086aeae DJ |
6107 | } |
6108 | annotate_field (5); | |
0d381245 | 6109 | if (!header_of_multiple) |
170b53b2 | 6110 | print_breakpoint_location (b, loc); |
0d381245 | 6111 | if (b->loc) |
a6d9a66e | 6112 | *last_loc = b->loc; |
3086aeae DJ |
6113 | break; |
6114 | } | |
c906108c | 6115 | |
6c95b8df | 6116 | |
998580f1 | 6117 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6118 | { |
5c632425 | 6119 | std::vector<int> inf_nums; |
998580f1 | 6120 | int mi_only = 1; |
6c95b8df | 6121 | |
08036331 | 6122 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6123 | { |
6124 | if (inf->pspace == loc->pspace) | |
5c632425 | 6125 | inf_nums.push_back (inf->num); |
6c95b8df | 6126 | } |
998580f1 MK |
6127 | |
6128 | /* For backward compatibility, don't display inferiors in CLI unless | |
6129 | there are several. Always display for MI. */ | |
6130 | if (allflag | |
6131 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6132 | && (number_of_program_spaces () > 1 | |
6133 | || number_of_inferiors () > 1) | |
6134 | /* LOC is for existing B, it cannot be in | |
6135 | moribund_locations and thus having NULL OWNER. */ | |
6136 | && loc->owner->type != bp_catchpoint)) | |
6137 | mi_only = 0; | |
5c632425 | 6138 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6139 | } |
6140 | ||
4a306c9a | 6141 | if (!part_of_multiple) |
c4093a6a | 6142 | { |
4a306c9a JB |
6143 | if (b->thread != -1) |
6144 | { | |
6145 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6146 | "stop only in" line a little further down. */ |
112e8700 SM |
6147 | uiout->text (" thread "); |
6148 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6149 | } |
6150 | else if (b->task != 0) | |
6151 | { | |
112e8700 SM |
6152 | uiout->text (" task "); |
6153 | uiout->field_int ("task", b->task); | |
4a306c9a | 6154 | } |
c4093a6a | 6155 | } |
f1310107 | 6156 | |
112e8700 | 6157 | uiout->text ("\n"); |
f1310107 | 6158 | |
348d480f | 6159 | if (!part_of_multiple) |
f1310107 TJB |
6160 | b->ops->print_one_detail (b, uiout); |
6161 | ||
0d381245 | 6162 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6163 | { |
6164 | annotate_field (6); | |
112e8700 | 6165 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6166 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6167 | the frame ID. */ |
112e8700 | 6168 | uiout->field_core_addr ("frame", |
5af949e3 | 6169 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6170 | uiout->text ("\n"); |
c4093a6a JM |
6171 | } |
6172 | ||
28010a5d | 6173 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6174 | { |
6175 | annotate_field (7); | |
d77f58be | 6176 | if (is_tracepoint (b)) |
112e8700 | 6177 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6178 | else |
112e8700 SM |
6179 | uiout->text ("\tstop only if "); |
6180 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6181 | |
6182 | /* Print whether the target is doing the breakpoint's condition | |
6183 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6184 | if (is_breakpoint (b) | |
6185 | && breakpoint_condition_evaluation_mode () | |
6186 | == condition_evaluation_target) | |
6187 | { | |
112e8700 SM |
6188 | uiout->text (" ("); |
6189 | uiout->field_string ("evaluated-by", | |
b775012e | 6190 | bp_condition_evaluator (b)); |
112e8700 | 6191 | uiout->text (" evals)"); |
b775012e | 6192 | } |
112e8700 | 6193 | uiout->text ("\n"); |
0101ce28 JJ |
6194 | } |
6195 | ||
0d381245 | 6196 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6197 | { |
4a64f543 | 6198 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6199 | uiout->text ("\tstop only in thread "); |
6200 | if (uiout->is_mi_like_p ()) | |
6201 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6202 | else |
6203 | { | |
6204 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6205 | ||
112e8700 | 6206 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6207 | } |
112e8700 | 6208 | uiout->text ("\n"); |
c4093a6a JM |
6209 | } |
6210 | ||
556ec64d YQ |
6211 | if (!part_of_multiple) |
6212 | { | |
6213 | if (b->hit_count) | |
31f56a27 YQ |
6214 | { |
6215 | /* FIXME should make an annotation for this. */ | |
6216 | if (is_catchpoint (b)) | |
112e8700 | 6217 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6218 | else if (is_tracepoint (b)) |
112e8700 | 6219 | uiout->text ("\ttracepoint"); |
31f56a27 | 6220 | else |
112e8700 SM |
6221 | uiout->text ("\tbreakpoint"); |
6222 | uiout->text (" already hit "); | |
6223 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6224 | if (b->hit_count == 1) |
112e8700 | 6225 | uiout->text (" time\n"); |
31f56a27 | 6226 | else |
112e8700 | 6227 | uiout->text (" times\n"); |
31f56a27 | 6228 | } |
556ec64d YQ |
6229 | else |
6230 | { | |
31f56a27 | 6231 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6232 | if (uiout->is_mi_like_p ()) |
6233 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6234 | } |
6235 | } | |
8b93c638 | 6236 | |
0d381245 | 6237 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6238 | { |
6239 | annotate_field (8); | |
112e8700 SM |
6240 | uiout->text ("\tignore next "); |
6241 | uiout->field_int ("ignore", b->ignore_count); | |
6242 | uiout->text (" hits\n"); | |
c4093a6a | 6243 | } |
059fb39f | 6244 | |
816338b5 SS |
6245 | /* Note that an enable count of 1 corresponds to "enable once" |
6246 | behavior, which is reported by the combination of enablement and | |
6247 | disposition, so we don't need to mention it here. */ | |
6248 | if (!part_of_multiple && b->enable_count > 1) | |
6249 | { | |
6250 | annotate_field (8); | |
112e8700 | 6251 | uiout->text ("\tdisable after "); |
816338b5 SS |
6252 | /* Tweak the wording to clarify that ignore and enable counts |
6253 | are distinct, and have additive effect. */ | |
6254 | if (b->ignore_count) | |
112e8700 | 6255 | uiout->text ("additional "); |
816338b5 | 6256 | else |
112e8700 SM |
6257 | uiout->text ("next "); |
6258 | uiout->field_int ("enable", b->enable_count); | |
6259 | uiout->text (" hits\n"); | |
816338b5 SS |
6260 | } |
6261 | ||
f196051f SS |
6262 | if (!part_of_multiple && is_tracepoint (b)) |
6263 | { | |
6264 | struct tracepoint *tp = (struct tracepoint *) b; | |
6265 | ||
6266 | if (tp->traceframe_usage) | |
6267 | { | |
112e8700 SM |
6268 | uiout->text ("\ttrace buffer usage "); |
6269 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6270 | uiout->text (" bytes\n"); | |
f196051f SS |
6271 | } |
6272 | } | |
d3ce09f5 | 6273 | |
d1b0a7bf | 6274 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6275 | if (!part_of_multiple && l) |
c4093a6a JM |
6276 | { |
6277 | annotate_field (9); | |
2e783024 | 6278 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6279 | print_command_lines (uiout, l, 4); |
c4093a6a | 6280 | } |
d24317b4 | 6281 | |
d9b3f62e | 6282 | if (is_tracepoint (b)) |
1042e4c0 | 6283 | { |
d9b3f62e PA |
6284 | struct tracepoint *t = (struct tracepoint *) b; |
6285 | ||
6286 | if (!part_of_multiple && t->pass_count) | |
6287 | { | |
6288 | annotate_field (10); | |
112e8700 SM |
6289 | uiout->text ("\tpass count "); |
6290 | uiout->field_int ("pass", t->pass_count); | |
6291 | uiout->text (" \n"); | |
d9b3f62e | 6292 | } |
f2a8bc8a YQ |
6293 | |
6294 | /* Don't display it when tracepoint or tracepoint location is | |
6295 | pending. */ | |
6296 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6297 | { | |
6298 | annotate_field (11); | |
6299 | ||
112e8700 SM |
6300 | if (uiout->is_mi_like_p ()) |
6301 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6302 | loc->inserted ? "y" : "n"); |
6303 | else | |
6304 | { | |
6305 | if (loc->inserted) | |
112e8700 | 6306 | uiout->text ("\t"); |
f2a8bc8a | 6307 | else |
112e8700 SM |
6308 | uiout->text ("\tnot "); |
6309 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6310 | } |
6311 | } | |
1042e4c0 SS |
6312 | } |
6313 | ||
112e8700 | 6314 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6315 | { |
3a5c3e22 PA |
6316 | if (is_watchpoint (b)) |
6317 | { | |
6318 | struct watchpoint *w = (struct watchpoint *) b; | |
6319 | ||
112e8700 | 6320 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6321 | } |
f00aae0f | 6322 | else if (b->location != NULL |
d28cd78a | 6323 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6324 | uiout->field_string ("original-location", |
d28cd78a | 6325 | event_location_to_string (b->location.get ())); |
d24317b4 | 6326 | } |
c4093a6a | 6327 | } |
c5aa993b | 6328 | |
13674803 SM |
6329 | /* See breakpoint.h. */ |
6330 | ||
6331 | bool fix_multi_location_breakpoint_output_globally = false; | |
6332 | ||
0d381245 VP |
6333 | static void |
6334 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6335 | struct bp_location **last_loc, |
6c95b8df | 6336 | int allflag) |
0d381245 | 6337 | { |
79a45e25 | 6338 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6339 | bool use_fixed_output |
6340 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6341 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6342 | |
b4be1b06 SM |
6343 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
6344 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); | |
8d3788bd | 6345 | |
b4be1b06 SM |
6346 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6347 | are outside. */ | |
6348 | if (!use_fixed_output) | |
6349 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6350 | |
6351 | /* If this breakpoint has custom print function, | |
6352 | it's already printed. Otherwise, print individual | |
6353 | locations, if any. */ | |
6354 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6355 | { | |
4a64f543 MS |
6356 | /* If breakpoint has a single location that is disabled, we |
6357 | print it as if it had several locations, since otherwise it's | |
6358 | hard to represent "breakpoint enabled, location disabled" | |
6359 | situation. | |
6360 | ||
6361 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6362 | internally, that's not a property exposed to user. */ |
0d381245 | 6363 | if (b->loc |
a5606eee | 6364 | && !is_hardware_watchpoint (b) |
8d3788bd | 6365 | && (b->loc->next || !b->loc->enabled)) |
0d381245 | 6366 | { |
b4be1b06 SM |
6367 | gdb::optional<ui_out_emit_list> locations_list; |
6368 | ||
6369 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6370 | MI record. For later versions, place breakpoint locations in a | |
6371 | list. */ | |
6372 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6373 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6374 | |
b4be1b06 SM |
6375 | int n = 1; |
6376 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) | |
8d3788bd | 6377 | { |
b4be1b06 | 6378 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
8d3788bd | 6379 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
8d3788bd | 6380 | } |
0d381245 VP |
6381 | } |
6382 | } | |
6383 | } | |
6384 | ||
a6d9a66e UW |
6385 | static int |
6386 | breakpoint_address_bits (struct breakpoint *b) | |
6387 | { | |
6388 | int print_address_bits = 0; | |
6389 | struct bp_location *loc; | |
6390 | ||
c6d81124 PA |
6391 | /* Software watchpoints that aren't watching memory don't have an |
6392 | address to print. */ | |
6393 | if (is_no_memory_software_watchpoint (b)) | |
6394 | return 0; | |
6395 | ||
a6d9a66e UW |
6396 | for (loc = b->loc; loc; loc = loc->next) |
6397 | { | |
c7437ca6 PA |
6398 | int addr_bit; |
6399 | ||
c7437ca6 | 6400 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6401 | if (addr_bit > print_address_bits) |
6402 | print_address_bits = addr_bit; | |
6403 | } | |
6404 | ||
6405 | return print_address_bits; | |
6406 | } | |
0d381245 | 6407 | |
65630365 | 6408 | /* See breakpoint.h. */ |
c5aa993b | 6409 | |
65630365 PA |
6410 | void |
6411 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6412 | { |
a6d9a66e | 6413 | struct bp_location *dummy_loc = NULL; |
65630365 | 6414 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6415 | } |
c5aa993b | 6416 | |
09d682a4 TT |
6417 | /* Return true if this breakpoint was set by the user, false if it is |
6418 | internal or momentary. */ | |
6419 | ||
6420 | int | |
6421 | user_breakpoint_p (struct breakpoint *b) | |
6422 | { | |
46c6471b | 6423 | return b->number > 0; |
09d682a4 TT |
6424 | } |
6425 | ||
93daf339 TT |
6426 | /* See breakpoint.h. */ |
6427 | ||
6428 | int | |
6429 | pending_breakpoint_p (struct breakpoint *b) | |
6430 | { | |
6431 | return b->loc == NULL; | |
6432 | } | |
6433 | ||
7f3b0473 | 6434 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6435 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6436 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6437 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6438 | ones for which it returns non-zero. Return the total number of | |
6439 | breakpoints listed. */ | |
c906108c | 6440 | |
d77f58be | 6441 | static int |
4495129a | 6442 | breakpoint_1 (const char *args, int allflag, |
4a64f543 | 6443 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6444 | { |
52f0bd74 | 6445 | struct breakpoint *b; |
a6d9a66e | 6446 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6447 | int nr_printable_breakpoints; |
79a45b7d | 6448 | struct value_print_options opts; |
a6d9a66e | 6449 | int print_address_bits = 0; |
269b11a2 | 6450 | int print_type_col_width = 14; |
79a45e25 | 6451 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6452 | |
79a45b7d TT |
6453 | get_user_print_options (&opts); |
6454 | ||
4a64f543 MS |
6455 | /* Compute the number of rows in the table, as well as the size |
6456 | required for address fields. */ | |
7f3b0473 AC |
6457 | nr_printable_breakpoints = 0; |
6458 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6459 | { |
6460 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6461 | if (filter && !filter (b)) | |
6462 | continue; | |
6463 | ||
6464 | /* If we have an "args" string, it is a list of breakpoints to | |
6465 | accept. Skip the others. */ | |
6466 | if (args != NULL && *args != '\0') | |
6467 | { | |
6468 | if (allflag && parse_and_eval_long (args) != b->number) | |
6469 | continue; | |
6470 | if (!allflag && !number_is_in_list (args, b->number)) | |
6471 | continue; | |
6472 | } | |
269b11a2 | 6473 | |
e5a67952 MS |
6474 | if (allflag || user_breakpoint_p (b)) |
6475 | { | |
6476 | int addr_bit, type_len; | |
a6d9a66e | 6477 | |
e5a67952 MS |
6478 | addr_bit = breakpoint_address_bits (b); |
6479 | if (addr_bit > print_address_bits) | |
6480 | print_address_bits = addr_bit; | |
269b11a2 | 6481 | |
e5a67952 MS |
6482 | type_len = strlen (bptype_string (b->type)); |
6483 | if (type_len > print_type_col_width) | |
6484 | print_type_col_width = type_len; | |
6485 | ||
6486 | nr_printable_breakpoints++; | |
6487 | } | |
6488 | } | |
7f3b0473 | 6489 | |
4a2b031d TT |
6490 | { |
6491 | ui_out_emit_table table_emitter (uiout, | |
6492 | opts.addressprint ? 6 : 5, | |
6493 | nr_printable_breakpoints, | |
6494 | "BreakpointTable"); | |
6495 | ||
6496 | if (nr_printable_breakpoints > 0) | |
6497 | annotate_breakpoints_headers (); | |
6498 | if (nr_printable_breakpoints > 0) | |
6499 | annotate_field (0); | |
6500 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6501 | if (nr_printable_breakpoints > 0) | |
6502 | annotate_field (1); | |
6503 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6504 | if (nr_printable_breakpoints > 0) | |
6505 | annotate_field (2); | |
6506 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6507 | if (nr_printable_breakpoints > 0) | |
6508 | annotate_field (3); | |
6509 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6510 | if (opts.addressprint) | |
6511 | { | |
6512 | if (nr_printable_breakpoints > 0) | |
6513 | annotate_field (4); | |
6514 | if (print_address_bits <= 32) | |
6515 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6516 | else | |
6517 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6518 | } | |
6519 | if (nr_printable_breakpoints > 0) | |
6520 | annotate_field (5); | |
6521 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6522 | uiout->table_body (); | |
6523 | if (nr_printable_breakpoints > 0) | |
6524 | annotate_breakpoints_table (); | |
6525 | ||
6526 | ALL_BREAKPOINTS (b) | |
6527 | { | |
6528 | QUIT; | |
6529 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6530 | if (filter && !filter (b)) | |
6531 | continue; | |
e5a67952 | 6532 | |
4a2b031d TT |
6533 | /* If we have an "args" string, it is a list of breakpoints to |
6534 | accept. Skip the others. */ | |
e5a67952 | 6535 | |
4a2b031d TT |
6536 | if (args != NULL && *args != '\0') |
6537 | { | |
6538 | if (allflag) /* maintenance info breakpoint */ | |
6539 | { | |
6540 | if (parse_and_eval_long (args) != b->number) | |
6541 | continue; | |
6542 | } | |
6543 | else /* all others */ | |
6544 | { | |
6545 | if (!number_is_in_list (args, b->number)) | |
6546 | continue; | |
6547 | } | |
6548 | } | |
6549 | /* We only print out user settable breakpoints unless the | |
6550 | allflag is set. */ | |
6551 | if (allflag || user_breakpoint_p (b)) | |
6552 | print_one_breakpoint (b, &last_loc, allflag); | |
6553 | } | |
6554 | } | |
698384cd | 6555 | |
7f3b0473 | 6556 | if (nr_printable_breakpoints == 0) |
c906108c | 6557 | { |
4a64f543 MS |
6558 | /* If there's a filter, let the caller decide how to report |
6559 | empty list. */ | |
d77f58be SS |
6560 | if (!filter) |
6561 | { | |
e5a67952 | 6562 | if (args == NULL || *args == '\0') |
112e8700 | 6563 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6564 | else |
112e8700 | 6565 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6566 | args); |
d77f58be | 6567 | } |
c906108c SS |
6568 | } |
6569 | else | |
c4093a6a | 6570 | { |
a6d9a66e UW |
6571 | if (last_loc && !server_command) |
6572 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6573 | } |
c906108c | 6574 | |
4a64f543 | 6575 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6576 | there have been breakpoints? */ |
c906108c | 6577 | annotate_breakpoints_table_end (); |
d77f58be SS |
6578 | |
6579 | return nr_printable_breakpoints; | |
c906108c SS |
6580 | } |
6581 | ||
ad443146 SS |
6582 | /* Display the value of default-collect in a way that is generally |
6583 | compatible with the breakpoint list. */ | |
6584 | ||
6585 | static void | |
6586 | default_collect_info (void) | |
6587 | { | |
79a45e25 PA |
6588 | struct ui_out *uiout = current_uiout; |
6589 | ||
ad443146 SS |
6590 | /* If it has no value (which is frequently the case), say nothing; a |
6591 | message like "No default-collect." gets in user's face when it's | |
6592 | not wanted. */ | |
6593 | if (!*default_collect) | |
6594 | return; | |
6595 | ||
6596 | /* The following phrase lines up nicely with per-tracepoint collect | |
6597 | actions. */ | |
112e8700 SM |
6598 | uiout->text ("default collect "); |
6599 | uiout->field_string ("default-collect", default_collect); | |
6600 | uiout->text (" \n"); | |
ad443146 SS |
6601 | } |
6602 | ||
c906108c | 6603 | static void |
0b39b52e | 6604 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6605 | { |
e5a67952 | 6606 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6607 | |
6608 | default_collect_info (); | |
d77f58be SS |
6609 | } |
6610 | ||
6611 | static void | |
1d12d88f | 6612 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6613 | { |
e5a67952 | 6614 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6615 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6616 | |
6617 | if (num_printed == 0) | |
6618 | { | |
e5a67952 | 6619 | if (args == NULL || *args == '\0') |
112e8700 | 6620 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6621 | else |
112e8700 | 6622 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6623 | } |
c906108c SS |
6624 | } |
6625 | ||
7a292a7a | 6626 | static void |
4495129a | 6627 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6628 | { |
e5a67952 | 6629 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6630 | |
6631 | default_collect_info (); | |
c906108c SS |
6632 | } |
6633 | ||
0d381245 | 6634 | static int |
714835d5 | 6635 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6636 | struct program_space *pspace, |
714835d5 | 6637 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6638 | { |
6639 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6640 | |
0d381245 VP |
6641 | for (; bl; bl = bl->next) |
6642 | { | |
6c95b8df PA |
6643 | if (bl->pspace == pspace |
6644 | && bl->address == pc | |
0d381245 VP |
6645 | && (!overlay_debugging || bl->section == section)) |
6646 | return 1; | |
6647 | } | |
6648 | return 0; | |
6649 | } | |
6650 | ||
672f9b60 | 6651 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6652 | concerns with logical breakpoints, so we match program spaces, not |
6653 | address spaces. */ | |
c906108c SS |
6654 | |
6655 | static void | |
6c95b8df PA |
6656 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6657 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6658 | struct obj_section *section, int thread) |
c906108c | 6659 | { |
52f0bd74 AC |
6660 | int others = 0; |
6661 | struct breakpoint *b; | |
c906108c SS |
6662 | |
6663 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6664 | others += (user_breakpoint_p (b) |
6665 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6666 | if (others > 0) |
6667 | { | |
a3f17187 AC |
6668 | if (others == 1) |
6669 | printf_filtered (_("Note: breakpoint ")); | |
6670 | else /* if (others == ???) */ | |
6671 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6672 | ALL_BREAKPOINTS (b) |
672f9b60 | 6673 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6674 | { |
6675 | others--; | |
6676 | printf_filtered ("%d", b->number); | |
6677 | if (b->thread == -1 && thread != -1) | |
6678 | printf_filtered (" (all threads)"); | |
6679 | else if (b->thread != -1) | |
6680 | printf_filtered (" (thread %d)", b->thread); | |
6681 | printf_filtered ("%s%s ", | |
059fb39f | 6682 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6683 | || b->enable_state == bp_call_disabled) |
0d381245 | 6684 | ? " (disabled)" |
0d381245 VP |
6685 | : ""), |
6686 | (others > 1) ? "," | |
6687 | : ((others == 1) ? " and" : "")); | |
6688 | } | |
a3f17187 | 6689 | printf_filtered (_("also set at pc ")); |
2636d81d | 6690 | fputs_styled (paddress (gdbarch, pc), address_style.style (), gdb_stdout); |
c906108c SS |
6691 | printf_filtered (".\n"); |
6692 | } | |
6693 | } | |
6694 | \f | |
c906108c | 6695 | |
e4f237da | 6696 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
6697 | BPT locations. For some breakpoint types, the locations' address members |
6698 | are irrelevant and it makes no sense to attempt to compare them to other | |
6699 | addresses (or use them for any other purpose either). | |
e4f237da | 6700 | |
4a64f543 | 6701 | More specifically, each of the following breakpoint types will |
244558af | 6702 | always have a zero valued location address and we don't want to mark |
4a64f543 | 6703 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 6704 | breakpoint location at address zero: |
e4f237da KB |
6705 | |
6706 | bp_watchpoint | |
2d134ed3 PA |
6707 | bp_catchpoint |
6708 | ||
6709 | */ | |
e4f237da KB |
6710 | |
6711 | static int | |
6712 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6713 | { | |
6714 | enum bptype type = bpt->type; | |
6715 | ||
2d134ed3 PA |
6716 | return (type != bp_watchpoint && type != bp_catchpoint); |
6717 | } | |
6718 | ||
6719 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6720 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6721 | ||
6722 | static int | |
4a64f543 MS |
6723 | watchpoint_locations_match (struct bp_location *loc1, |
6724 | struct bp_location *loc2) | |
2d134ed3 | 6725 | { |
3a5c3e22 PA |
6726 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6727 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6728 | ||
6729 | /* Both of them must exist. */ | |
6730 | gdb_assert (w1 != NULL); | |
6731 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6732 | |
4a64f543 MS |
6733 | /* If the target can evaluate the condition expression in hardware, |
6734 | then we we need to insert both watchpoints even if they are at | |
6735 | the same place. Otherwise the watchpoint will only trigger when | |
6736 | the condition of whichever watchpoint was inserted evaluates to | |
6737 | true, not giving a chance for GDB to check the condition of the | |
6738 | other watchpoint. */ | |
3a5c3e22 | 6739 | if ((w1->cond_exp |
4a64f543 MS |
6740 | && target_can_accel_watchpoint_condition (loc1->address, |
6741 | loc1->length, | |
0cf6dd15 | 6742 | loc1->watchpoint_type, |
4d01a485 | 6743 | w1->cond_exp.get ())) |
3a5c3e22 | 6744 | || (w2->cond_exp |
4a64f543 MS |
6745 | && target_can_accel_watchpoint_condition (loc2->address, |
6746 | loc2->length, | |
0cf6dd15 | 6747 | loc2->watchpoint_type, |
4d01a485 | 6748 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6749 | return 0; |
6750 | ||
85d721b8 PA |
6751 | /* Note that this checks the owner's type, not the location's. In |
6752 | case the target does not support read watchpoints, but does | |
6753 | support access watchpoints, we'll have bp_read_watchpoint | |
6754 | watchpoints with hw_access locations. Those should be considered | |
6755 | duplicates of hw_read locations. The hw_read locations will | |
6756 | become hw_access locations later. */ | |
2d134ed3 PA |
6757 | return (loc1->owner->type == loc2->owner->type |
6758 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6759 | && loc1->address == loc2->address | |
6760 | && loc1->length == loc2->length); | |
e4f237da KB |
6761 | } |
6762 | ||
31e77af2 | 6763 | /* See breakpoint.h. */ |
6c95b8df | 6764 | |
31e77af2 | 6765 | int |
accd0bcd YQ |
6766 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6767 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6768 | { |
f5656ead | 6769 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6770 | || aspace1 == aspace2) |
6771 | && addr1 == addr2); | |
6772 | } | |
6773 | ||
f1310107 TJB |
6774 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6775 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6776 | matches ASPACE2. On targets that have global breakpoints, the address | |
6777 | space doesn't really matter. */ | |
6778 | ||
6779 | static int | |
accd0bcd YQ |
6780 | breakpoint_address_match_range (const address_space *aspace1, |
6781 | CORE_ADDR addr1, | |
6782 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6783 | CORE_ADDR addr2) |
6784 | { | |
f5656ead | 6785 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6786 | || aspace1 == aspace2) |
6787 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6788 | } | |
6789 | ||
6790 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6791 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6792 | matches the breakpoint's address space. On targets that have global | |
6793 | breakpoints, the address space doesn't really matter. */ | |
6794 | ||
6795 | static int | |
6796 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6797 | const address_space *aspace, |
f1310107 TJB |
6798 | CORE_ADDR addr) |
6799 | { | |
6800 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6801 | aspace, addr) | |
6802 | || (bl->length | |
6803 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6804 | bl->address, bl->length, | |
6805 | aspace, addr))); | |
6806 | } | |
6807 | ||
d35ae833 PA |
6808 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6809 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6810 | match happens only if ASPACE matches the breakpoint's address | |
6811 | space. On targets that have global breakpoints, the address space | |
6812 | doesn't really matter. */ | |
6813 | ||
6814 | static int | |
6815 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6816 | const address_space *aspace, |
d35ae833 PA |
6817 | CORE_ADDR addr, int len) |
6818 | { | |
6819 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6820 | || bl->pspace->aspace == aspace) | |
6821 | { | |
6822 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6823 | ||
6824 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6825 | return 1; | |
6826 | } | |
6827 | return 0; | |
6828 | } | |
6829 | ||
1e4d1764 YQ |
6830 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6831 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6832 | true, otherwise returns false. */ | |
6833 | ||
6834 | static int | |
6835 | tracepoint_locations_match (struct bp_location *loc1, | |
6836 | struct bp_location *loc2) | |
6837 | { | |
6838 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6839 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6840 | locations at the same address of different tracepoints are regarded as | |
6841 | different locations. */ | |
6842 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6843 | else | |
6844 | return 0; | |
6845 | } | |
6846 | ||
2d134ed3 PA |
6847 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
6848 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
6849 | represent the same location. */ | |
6850 | ||
6851 | static int | |
4a64f543 MS |
6852 | breakpoint_locations_match (struct bp_location *loc1, |
6853 | struct bp_location *loc2) | |
2d134ed3 | 6854 | { |
2bdf28a0 JK |
6855 | int hw_point1, hw_point2; |
6856 | ||
6857 | /* Both of them must not be in moribund_locations. */ | |
6858 | gdb_assert (loc1->owner != NULL); | |
6859 | gdb_assert (loc2->owner != NULL); | |
6860 | ||
6861 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6862 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6863 | |
6864 | if (hw_point1 != hw_point2) | |
6865 | return 0; | |
6866 | else if (hw_point1) | |
6867 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6868 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6869 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6870 | else |
f1310107 TJB |
6871 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6872 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6873 | loc2->pspace->aspace, loc2->address) | |
6874 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6875 | } |
6876 | ||
76897487 KB |
6877 | static void |
6878 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6879 | int bnum, int have_bnum) | |
6880 | { | |
f63fbe86 MS |
6881 | /* The longest string possibly returned by hex_string_custom |
6882 | is 50 chars. These must be at least that big for safety. */ | |
6883 | char astr1[64]; | |
6884 | char astr2[64]; | |
76897487 | 6885 | |
bb599908 PH |
6886 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6887 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6888 | if (have_bnum) |
8a3fe4f8 | 6889 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6890 | bnum, astr1, astr2); |
6891 | else | |
8a3fe4f8 | 6892 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6893 | } |
6894 | ||
4a64f543 MS |
6895 | /* Adjust a breakpoint's address to account for architectural |
6896 | constraints on breakpoint placement. Return the adjusted address. | |
6897 | Note: Very few targets require this kind of adjustment. For most | |
6898 | targets, this function is simply the identity function. */ | |
76897487 KB |
6899 | |
6900 | static CORE_ADDR | |
a6d9a66e UW |
6901 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6902 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6903 | { |
a0de8c21 YQ |
6904 | if (bptype == bp_watchpoint |
6905 | || bptype == bp_hardware_watchpoint | |
6906 | || bptype == bp_read_watchpoint | |
6907 | || bptype == bp_access_watchpoint | |
6908 | || bptype == bp_catchpoint) | |
88f7da05 KB |
6909 | { |
6910 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6911 | have their addresses modified. */ | |
6912 | return bpaddr; | |
6913 | } | |
7c16b83e PA |
6914 | else if (bptype == bp_single_step) |
6915 | { | |
6916 | /* Single-step breakpoints should not have their addresses | |
6917 | modified. If there's any architectural constrain that | |
6918 | applies to this address, then it should have already been | |
6919 | taken into account when the breakpoint was created in the | |
6920 | first place. If we didn't do this, stepping through e.g., | |
6921 | Thumb-2 IT blocks would break. */ | |
6922 | return bpaddr; | |
6923 | } | |
76897487 KB |
6924 | else |
6925 | { | |
a0de8c21 YQ |
6926 | CORE_ADDR adjusted_bpaddr = bpaddr; |
6927 | ||
6928 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
6929 | { | |
6930 | /* Some targets have architectural constraints on the placement | |
6931 | of breakpoint instructions. Obtain the adjusted address. */ | |
6932 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
6933 | } | |
76897487 | 6934 | |
a0de8c21 | 6935 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
6936 | |
6937 | /* An adjusted breakpoint address can significantly alter | |
6938 | a user's expectations. Print a warning if an adjustment | |
6939 | is required. */ | |
6940 | if (adjusted_bpaddr != bpaddr) | |
6941 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6942 | ||
6943 | return adjusted_bpaddr; | |
6944 | } | |
6945 | } | |
6946 | ||
5f486660 | 6947 | bp_location::bp_location (breakpoint *owner) |
7cc221ef | 6948 | { |
5625a286 | 6949 | bp_location *loc = this; |
7cc221ef | 6950 | |
28010a5d | 6951 | loc->owner = owner; |
b775012e | 6952 | loc->cond_bytecode = NULL; |
0d381245 VP |
6953 | loc->shlib_disabled = 0; |
6954 | loc->enabled = 1; | |
e049a4b5 | 6955 | |
28010a5d | 6956 | switch (owner->type) |
e049a4b5 DJ |
6957 | { |
6958 | case bp_breakpoint: | |
7c16b83e | 6959 | case bp_single_step: |
e049a4b5 DJ |
6960 | case bp_until: |
6961 | case bp_finish: | |
6962 | case bp_longjmp: | |
6963 | case bp_longjmp_resume: | |
e2e4d78b | 6964 | case bp_longjmp_call_dummy: |
186c406b TT |
6965 | case bp_exception: |
6966 | case bp_exception_resume: | |
e049a4b5 | 6967 | case bp_step_resume: |
2c03e5be | 6968 | case bp_hp_step_resume: |
e049a4b5 DJ |
6969 | case bp_watchpoint_scope: |
6970 | case bp_call_dummy: | |
aa7d318d | 6971 | case bp_std_terminate: |
e049a4b5 DJ |
6972 | case bp_shlib_event: |
6973 | case bp_thread_event: | |
6974 | case bp_overlay_event: | |
4efc6507 | 6975 | case bp_jit_event: |
0fd8e87f | 6976 | case bp_longjmp_master: |
aa7d318d | 6977 | case bp_std_terminate_master: |
186c406b | 6978 | case bp_exception_master: |
0e30163f JK |
6979 | case bp_gnu_ifunc_resolver: |
6980 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6981 | case bp_dprintf: |
e049a4b5 | 6982 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 6983 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6984 | break; |
6985 | case bp_hardware_breakpoint: | |
6986 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 6987 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
6988 | break; |
6989 | case bp_hardware_watchpoint: | |
6990 | case bp_read_watchpoint: | |
6991 | case bp_access_watchpoint: | |
6992 | loc->loc_type = bp_loc_hardware_watchpoint; | |
6993 | break; | |
6994 | case bp_watchpoint: | |
ce78b96d | 6995 | case bp_catchpoint: |
15c3d785 PA |
6996 | case bp_tracepoint: |
6997 | case bp_fast_tracepoint: | |
0fb4aa4b | 6998 | case bp_static_tracepoint: |
e049a4b5 DJ |
6999 | loc->loc_type = bp_loc_other; |
7000 | break; | |
7001 | default: | |
e2e0b3e5 | 7002 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7003 | } |
7004 | ||
f431efe5 | 7005 | loc->refc = 1; |
28010a5d PA |
7006 | } |
7007 | ||
7008 | /* Allocate a struct bp_location. */ | |
7009 | ||
7010 | static struct bp_location * | |
7011 | allocate_bp_location (struct breakpoint *bpt) | |
7012 | { | |
348d480f PA |
7013 | return bpt->ops->allocate_location (bpt); |
7014 | } | |
7cc221ef | 7015 | |
f431efe5 PA |
7016 | static void |
7017 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7018 | { |
4d01a485 | 7019 | delete loc; |
fe3f5fa8 VP |
7020 | } |
7021 | ||
f431efe5 PA |
7022 | /* Increment reference count. */ |
7023 | ||
7024 | static void | |
7025 | incref_bp_location (struct bp_location *bl) | |
7026 | { | |
7027 | ++bl->refc; | |
7028 | } | |
7029 | ||
7030 | /* Decrement reference count. If the reference count reaches 0, | |
7031 | destroy the bp_location. Sets *BLP to NULL. */ | |
7032 | ||
7033 | static void | |
7034 | decref_bp_location (struct bp_location **blp) | |
7035 | { | |
0807b50c PA |
7036 | gdb_assert ((*blp)->refc > 0); |
7037 | ||
f431efe5 PA |
7038 | if (--(*blp)->refc == 0) |
7039 | free_bp_location (*blp); | |
7040 | *blp = NULL; | |
7041 | } | |
7042 | ||
346774a9 | 7043 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7044 | |
b270e6f9 TT |
7045 | static breakpoint * |
7046 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7047 | { |
346774a9 | 7048 | struct breakpoint *b1; |
b270e6f9 | 7049 | struct breakpoint *result = b.get (); |
c906108c | 7050 | |
346774a9 PA |
7051 | /* Add this breakpoint to the end of the chain so that a list of |
7052 | breakpoints will come out in order of increasing numbers. */ | |
7053 | ||
7054 | b1 = breakpoint_chain; | |
7055 | if (b1 == 0) | |
b270e6f9 | 7056 | breakpoint_chain = b.release (); |
346774a9 PA |
7057 | else |
7058 | { | |
7059 | while (b1->next) | |
7060 | b1 = b1->next; | |
b270e6f9 | 7061 | b1->next = b.release (); |
346774a9 | 7062 | } |
b270e6f9 TT |
7063 | |
7064 | return result; | |
346774a9 PA |
7065 | } |
7066 | ||
7067 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7068 | ||
7069 | static void | |
7070 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7071 | struct gdbarch *gdbarch, | |
28010a5d | 7072 | enum bptype bptype, |
c0a91b2b | 7073 | const struct breakpoint_ops *ops) |
346774a9 | 7074 | { |
348d480f PA |
7075 | gdb_assert (ops != NULL); |
7076 | ||
28010a5d | 7077 | b->ops = ops; |
4d28f7a8 | 7078 | b->type = bptype; |
a6d9a66e | 7079 | b->gdbarch = gdbarch; |
c906108c SS |
7080 | b->language = current_language->la_language; |
7081 | b->input_radix = input_radix; | |
d0fb5eae | 7082 | b->related_breakpoint = b; |
346774a9 PA |
7083 | } |
7084 | ||
7085 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7086 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7087 | |
7088 | static struct breakpoint * | |
7089 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7090 | enum bptype bptype, |
c0a91b2b | 7091 | const struct breakpoint_ops *ops) |
346774a9 | 7092 | { |
3b0871f4 | 7093 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7094 | |
3b0871f4 | 7095 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7096 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7097 | } |
7098 | ||
0e30163f JK |
7099 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7100 | resolutions should be made as the user specified the location explicitly | |
7101 | enough. */ | |
7102 | ||
0d381245 | 7103 | static void |
0e30163f | 7104 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7105 | { |
2bdf28a0 JK |
7106 | gdb_assert (loc->owner != NULL); |
7107 | ||
0d381245 | 7108 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7109 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7110 | || is_tracepoint (loc->owner)) |
0d381245 | 7111 | { |
2c02bd72 | 7112 | const char *function_name; |
0e30163f | 7113 | |
3467ec66 | 7114 | if (loc->msymbol != NULL |
f50776aa PA |
7115 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
7116 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc) | |
3467ec66 | 7117 | && !explicit_loc) |
0e30163f JK |
7118 | { |
7119 | struct breakpoint *b = loc->owner; | |
7120 | ||
3467ec66 PA |
7121 | function_name = MSYMBOL_LINKAGE_NAME (loc->msymbol); |
7122 | ||
7123 | if (b->type == bp_breakpoint && b->loc == loc | |
7124 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7125 | { |
7126 | /* Create only the whole new breakpoint of this type but do not | |
7127 | mess more complicated breakpoints with multiple locations. */ | |
7128 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7129 | /* Remember the resolver's address for use by the return |
7130 | breakpoint. */ | |
3467ec66 | 7131 | loc->related_address = loc->address; |
0e30163f JK |
7132 | } |
7133 | } | |
3467ec66 PA |
7134 | else |
7135 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7136 | |
2c02bd72 DE |
7137 | if (function_name) |
7138 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7139 | } |
7140 | } | |
7141 | ||
a6d9a66e | 7142 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7143 | struct gdbarch * |
a6d9a66e UW |
7144 | get_sal_arch (struct symtab_and_line sal) |
7145 | { | |
7146 | if (sal.section) | |
7147 | return get_objfile_arch (sal.section->objfile); | |
7148 | if (sal.symtab) | |
eb822aa6 | 7149 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7150 | |
7151 | return NULL; | |
7152 | } | |
7153 | ||
346774a9 PA |
7154 | /* Low level routine for partially initializing a breakpoint of type |
7155 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7156 | file name, and line number are provided by SAL. |
0d381245 VP |
7157 | |
7158 | It is expected that the caller will complete the initialization of | |
7159 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7160 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7161 | |
346774a9 PA |
7162 | static void |
7163 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7164 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7165 | const struct breakpoint_ops *ops) |
0d381245 | 7166 | { |
28010a5d | 7167 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7168 | |
3742cc8b | 7169 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7170 | |
6c95b8df PA |
7171 | if (bptype != bp_catchpoint) |
7172 | gdb_assert (sal.pspace != NULL); | |
7173 | ||
f8eba3c6 TT |
7174 | /* Store the program space that was used to set the breakpoint, |
7175 | except for ordinary breakpoints, which are independent of the | |
7176 | program space. */ | |
7177 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7178 | b->pspace = sal.pspace; | |
346774a9 | 7179 | } |
c906108c | 7180 | |
346774a9 PA |
7181 | /* set_raw_breakpoint is a low level routine for allocating and |
7182 | partially initializing a breakpoint of type BPTYPE. The newly | |
7183 | created breakpoint's address, section, source file name, and line | |
7184 | number are provided by SAL. The newly created and partially | |
7185 | initialized breakpoint is added to the breakpoint chain and | |
7186 | is also returned as the value of this function. | |
7187 | ||
7188 | It is expected that the caller will complete the initialization of | |
7189 | the newly created breakpoint struct as well as output any status | |
7190 | information regarding the creation of a new breakpoint. In | |
7191 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7192 | number! Care should be taken to not allow an error to occur | |
7193 | prior to completing the initialization of the breakpoint. If this | |
7194 | should happen, a bogus breakpoint will be left on the chain. */ | |
7195 | ||
7196 | struct breakpoint * | |
7197 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7198 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7199 | const struct breakpoint_ops *ops) |
346774a9 | 7200 | { |
3b0871f4 | 7201 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7202 | |
3b0871f4 | 7203 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7204 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7205 | } |
7206 | ||
53a5351d | 7207 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7208 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7209 | initiated the operation. */ | |
c906108c SS |
7210 | |
7211 | void | |
186c406b | 7212 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7213 | { |
35df4500 | 7214 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7215 | int thread = tp->global_num; |
0fd8e87f UW |
7216 | |
7217 | /* To avoid having to rescan all objfile symbols at every step, | |
7218 | we maintain a list of continually-inserted but always disabled | |
7219 | longjmp "master" breakpoints. Here, we simply create momentary | |
7220 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7221 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7222 | if (b->pspace == current_program_space |
186c406b TT |
7223 | && (b->type == bp_longjmp_master |
7224 | || b->type == bp_exception_master)) | |
0fd8e87f | 7225 | { |
06edf0c0 PA |
7226 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7227 | struct breakpoint *clone; | |
cc59ec59 | 7228 | |
e2e4d78b JK |
7229 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7230 | after their removal. */ | |
06edf0c0 | 7231 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7232 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7233 | clone->thread = thread; |
7234 | } | |
186c406b TT |
7235 | |
7236 | tp->initiating_frame = frame; | |
c906108c SS |
7237 | } |
7238 | ||
611c83ae | 7239 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7240 | void |
611c83ae | 7241 | delete_longjmp_breakpoint (int thread) |
c906108c | 7242 | { |
35df4500 | 7243 | struct breakpoint *b, *b_tmp; |
c906108c | 7244 | |
35df4500 | 7245 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7246 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7247 | { |
7248 | if (b->thread == thread) | |
7249 | delete_breakpoint (b); | |
7250 | } | |
c906108c SS |
7251 | } |
7252 | ||
f59f708a PA |
7253 | void |
7254 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7255 | { | |
7256 | struct breakpoint *b, *b_tmp; | |
7257 | ||
7258 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7259 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7260 | { | |
7261 | if (b->thread == thread) | |
7262 | b->disposition = disp_del_at_next_stop; | |
7263 | } | |
7264 | } | |
7265 | ||
e2e4d78b JK |
7266 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7267 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7268 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7269 | breakpoints. */ | |
7270 | ||
7271 | struct breakpoint * | |
7272 | set_longjmp_breakpoint_for_call_dummy (void) | |
7273 | { | |
7274 | struct breakpoint *b, *retval = NULL; | |
7275 | ||
7276 | ALL_BREAKPOINTS (b) | |
7277 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7278 | { | |
7279 | struct breakpoint *new_b; | |
7280 | ||
7281 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7282 | &momentary_breakpoint_ops, |
7283 | 1); | |
00431a78 | 7284 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7285 | |
7286 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7287 | ||
7288 | gdb_assert (new_b->related_breakpoint == new_b); | |
7289 | if (retval == NULL) | |
7290 | retval = new_b; | |
7291 | new_b->related_breakpoint = retval; | |
7292 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7293 | retval = retval->related_breakpoint; | |
7294 | retval->related_breakpoint = new_b; | |
7295 | } | |
7296 | ||
7297 | return retval; | |
7298 | } | |
7299 | ||
7300 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7301 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7302 | stack. |
7303 | ||
7304 | You should call this function only at places where it is safe to currently | |
7305 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7306 | frames. */ | |
7307 | ||
7308 | void | |
b67a2c6f | 7309 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7310 | { |
7311 | struct breakpoint *b, *b_tmp; | |
7312 | ||
7313 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7314 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7315 | { |
7316 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7317 | ||
7318 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7319 | dummy_b = dummy_b->related_breakpoint; | |
7320 | if (dummy_b->type != bp_call_dummy | |
7321 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7322 | continue; | |
7323 | ||
00431a78 | 7324 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7325 | |
7326 | while (b->related_breakpoint != b) | |
7327 | { | |
7328 | if (b_tmp == b->related_breakpoint) | |
7329 | b_tmp = b->related_breakpoint->next; | |
7330 | delete_breakpoint (b->related_breakpoint); | |
7331 | } | |
7332 | delete_breakpoint (b); | |
7333 | } | |
7334 | } | |
7335 | ||
1900040c MS |
7336 | void |
7337 | enable_overlay_breakpoints (void) | |
7338 | { | |
52f0bd74 | 7339 | struct breakpoint *b; |
1900040c MS |
7340 | |
7341 | ALL_BREAKPOINTS (b) | |
7342 | if (b->type == bp_overlay_event) | |
7343 | { | |
7344 | b->enable_state = bp_enabled; | |
44702360 | 7345 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7346 | overlay_events_enabled = 1; |
1900040c MS |
7347 | } |
7348 | } | |
7349 | ||
7350 | void | |
7351 | disable_overlay_breakpoints (void) | |
7352 | { | |
52f0bd74 | 7353 | struct breakpoint *b; |
1900040c MS |
7354 | |
7355 | ALL_BREAKPOINTS (b) | |
7356 | if (b->type == bp_overlay_event) | |
7357 | { | |
7358 | b->enable_state = bp_disabled; | |
44702360 | 7359 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7360 | overlay_events_enabled = 0; |
1900040c MS |
7361 | } |
7362 | } | |
7363 | ||
aa7d318d TT |
7364 | /* Set an active std::terminate breakpoint for each std::terminate |
7365 | master breakpoint. */ | |
7366 | void | |
7367 | set_std_terminate_breakpoint (void) | |
7368 | { | |
35df4500 | 7369 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7370 | |
35df4500 | 7371 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7372 | if (b->pspace == current_program_space |
7373 | && b->type == bp_std_terminate_master) | |
7374 | { | |
06edf0c0 | 7375 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7376 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7377 | } |
7378 | } | |
7379 | ||
7380 | /* Delete all the std::terminate breakpoints. */ | |
7381 | void | |
7382 | delete_std_terminate_breakpoint (void) | |
7383 | { | |
35df4500 | 7384 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7385 | |
35df4500 | 7386 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7387 | if (b->type == bp_std_terminate) |
7388 | delete_breakpoint (b); | |
7389 | } | |
7390 | ||
c4093a6a | 7391 | struct breakpoint * |
a6d9a66e | 7392 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7393 | { |
7394 | struct breakpoint *b; | |
c4093a6a | 7395 | |
06edf0c0 PA |
7396 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7397 | &internal_breakpoint_ops); | |
7398 | ||
b5de0fa7 | 7399 | b->enable_state = bp_enabled; |
f00aae0f | 7400 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7401 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7402 | |
44702360 | 7403 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7404 | |
c4093a6a JM |
7405 | return b; |
7406 | } | |
7407 | ||
0101ce28 JJ |
7408 | struct lang_and_radix |
7409 | { | |
7410 | enum language lang; | |
7411 | int radix; | |
7412 | }; | |
7413 | ||
4efc6507 DE |
7414 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7415 | ||
7416 | struct breakpoint * | |
7417 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7418 | { | |
2a7f3dff PA |
7419 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7420 | &internal_breakpoint_ops); | |
4efc6507 | 7421 | } |
0101ce28 | 7422 | |
03673fc7 PP |
7423 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7424 | ||
7425 | void | |
7426 | remove_jit_event_breakpoints (void) | |
7427 | { | |
7428 | struct breakpoint *b, *b_tmp; | |
7429 | ||
7430 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7431 | if (b->type == bp_jit_event | |
7432 | && b->loc->pspace == current_program_space) | |
7433 | delete_breakpoint (b); | |
7434 | } | |
7435 | ||
cae688ec JJ |
7436 | void |
7437 | remove_solib_event_breakpoints (void) | |
7438 | { | |
35df4500 | 7439 | struct breakpoint *b, *b_tmp; |
cae688ec | 7440 | |
35df4500 | 7441 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7442 | if (b->type == bp_shlib_event |
7443 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7444 | delete_breakpoint (b); |
7445 | } | |
7446 | ||
f37f681c PA |
7447 | /* See breakpoint.h. */ |
7448 | ||
7449 | void | |
7450 | remove_solib_event_breakpoints_at_next_stop (void) | |
7451 | { | |
7452 | struct breakpoint *b, *b_tmp; | |
7453 | ||
7454 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7455 | if (b->type == bp_shlib_event | |
7456 | && b->loc->pspace == current_program_space) | |
7457 | b->disposition = disp_del_at_next_stop; | |
7458 | } | |
7459 | ||
04086b45 PA |
7460 | /* Helper for create_solib_event_breakpoint / |
7461 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7462 | INSERT_MODE to pass through to update_global_location_list. */ | |
7463 | ||
7464 | static struct breakpoint * | |
7465 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7466 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7467 | { |
7468 | struct breakpoint *b; | |
7469 | ||
06edf0c0 PA |
7470 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7471 | &internal_breakpoint_ops); | |
04086b45 | 7472 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7473 | return b; |
7474 | } | |
7475 | ||
04086b45 PA |
7476 | struct breakpoint * |
7477 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7478 | { | |
7479 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7480 | } | |
7481 | ||
f37f681c PA |
7482 | /* See breakpoint.h. */ |
7483 | ||
7484 | struct breakpoint * | |
7485 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7486 | { | |
7487 | struct breakpoint *b; | |
7488 | ||
04086b45 PA |
7489 | /* Explicitly tell update_global_location_list to insert |
7490 | locations. */ | |
7491 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7492 | if (!b->loc->inserted) |
7493 | { | |
7494 | delete_breakpoint (b); | |
7495 | return NULL; | |
7496 | } | |
7497 | return b; | |
7498 | } | |
7499 | ||
cae688ec JJ |
7500 | /* Disable any breakpoints that are on code in shared libraries. Only |
7501 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7502 | ||
7503 | void | |
cb851954 | 7504 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7505 | { |
876fa593 | 7506 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7507 | |
876fa593 | 7508 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7509 | { |
2bdf28a0 | 7510 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7511 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7512 | |
4a64f543 MS |
7513 | /* We apply the check to all breakpoints, including disabled for |
7514 | those with loc->duplicate set. This is so that when breakpoint | |
7515 | becomes enabled, or the duplicate is removed, gdb will try to | |
7516 | insert all breakpoints. If we don't set shlib_disabled here, | |
7517 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7518 | if (((b->type == bp_breakpoint) |
508ccb1f | 7519 | || (b->type == bp_jit_event) |
1042e4c0 | 7520 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7521 | || (is_tracepoint (b))) |
6c95b8df | 7522 | && loc->pspace == current_program_space |
0d381245 | 7523 | && !loc->shlib_disabled |
6c95b8df | 7524 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7525 | ) |
0d381245 VP |
7526 | { |
7527 | loc->shlib_disabled = 1; | |
7528 | } | |
cae688ec JJ |
7529 | } |
7530 | } | |
7531 | ||
63644780 NB |
7532 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7533 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7534 | disabled ones can just stay disabled. */ | |
84acb35a | 7535 | |
75149521 | 7536 | static void |
84acb35a JJ |
7537 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7538 | { | |
876fa593 | 7539 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7540 | int disabled_shlib_breaks = 0; |
7541 | ||
876fa593 | 7542 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7543 | { |
2bdf28a0 | 7544 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7545 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7546 | |
1e4d1764 | 7547 | if (solib->pspace == loc->pspace |
e2dd7057 | 7548 | && !loc->shlib_disabled |
1e4d1764 YQ |
7549 | && (((b->type == bp_breakpoint |
7550 | || b->type == bp_jit_event | |
7551 | || b->type == bp_hardware_breakpoint) | |
7552 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7553 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7554 | || is_tracepoint (b)) | |
e2dd7057 | 7555 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7556 | { |
e2dd7057 PP |
7557 | loc->shlib_disabled = 1; |
7558 | /* At this point, we cannot rely on remove_breakpoint | |
7559 | succeeding so we must mark the breakpoint as not inserted | |
7560 | to prevent future errors occurring in remove_breakpoints. */ | |
7561 | loc->inserted = 0; | |
8d3788bd VP |
7562 | |
7563 | /* This may cause duplicate notifications for the same breakpoint. */ | |
76727919 | 7564 | gdb::observers::breakpoint_modified.notify (b); |
8d3788bd | 7565 | |
e2dd7057 PP |
7566 | if (!disabled_shlib_breaks) |
7567 | { | |
223ffa71 | 7568 | target_terminal::ours_for_output (); |
3e43a32a MS |
7569 | warning (_("Temporarily disabling breakpoints " |
7570 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7571 | solib->so_name); |
84acb35a | 7572 | } |
e2dd7057 | 7573 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7574 | } |
7575 | } | |
84acb35a JJ |
7576 | } |
7577 | ||
63644780 NB |
7578 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7579 | notification of free_objfile. Only apply to enabled breakpoints, | |
7580 | disabled ones can just stay disabled. */ | |
7581 | ||
7582 | static void | |
7583 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7584 | { | |
7585 | struct breakpoint *b; | |
7586 | ||
7587 | if (objfile == NULL) | |
7588 | return; | |
7589 | ||
d03de421 PA |
7590 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7591 | managed by the user with add-symbol-file/remove-symbol-file. | |
7592 | Similarly to how breakpoints in shared libraries are handled in | |
7593 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7594 | shlib_disabled so they end up uninserted on the next global |
7595 | location list update. Shared libraries not loaded by the user | |
7596 | aren't handled here -- they're already handled in | |
7597 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7598 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7599 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7600 | main objfile). */ | |
7601 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7602 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7603 | return; |
7604 | ||
7605 | ALL_BREAKPOINTS (b) | |
7606 | { | |
7607 | struct bp_location *loc; | |
7608 | int bp_modified = 0; | |
7609 | ||
7610 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7611 | continue; | |
7612 | ||
7613 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7614 | { | |
7615 | CORE_ADDR loc_addr = loc->address; | |
7616 | ||
7617 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7618 | && loc->loc_type != bp_loc_software_breakpoint) | |
7619 | continue; | |
7620 | ||
7621 | if (loc->shlib_disabled != 0) | |
7622 | continue; | |
7623 | ||
7624 | if (objfile->pspace != loc->pspace) | |
7625 | continue; | |
7626 | ||
7627 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7628 | && loc->loc_type != bp_loc_software_breakpoint) | |
7629 | continue; | |
7630 | ||
7631 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7632 | { | |
7633 | loc->shlib_disabled = 1; | |
08351840 PA |
7634 | /* At this point, we don't know whether the object was |
7635 | unmapped from the inferior or not, so leave the | |
7636 | inserted flag alone. We'll handle failure to | |
7637 | uninsert quietly, in case the object was indeed | |
7638 | unmapped. */ | |
63644780 NB |
7639 | |
7640 | mark_breakpoint_location_modified (loc); | |
7641 | ||
7642 | bp_modified = 1; | |
7643 | } | |
7644 | } | |
7645 | ||
7646 | if (bp_modified) | |
76727919 | 7647 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7648 | } |
7649 | } | |
7650 | ||
ce78b96d JB |
7651 | /* FORK & VFORK catchpoints. */ |
7652 | ||
e29a4733 | 7653 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7654 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7655 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7656 | |
c1fc2657 | 7657 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7658 | { |
e29a4733 PA |
7659 | /* Process id of a child process whose forking triggered this |
7660 | catchpoint. This field is only valid immediately after this | |
7661 | catchpoint has triggered. */ | |
7662 | ptid_t forked_inferior_pid; | |
7663 | }; | |
7664 | ||
4a64f543 MS |
7665 | /* Implement the "insert" breakpoint_ops method for fork |
7666 | catchpoints. */ | |
ce78b96d | 7667 | |
77b06cd7 TJB |
7668 | static int |
7669 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7670 | { |
e99b03dc | 7671 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7672 | } |
7673 | ||
4a64f543 MS |
7674 | /* Implement the "remove" breakpoint_ops method for fork |
7675 | catchpoints. */ | |
ce78b96d JB |
7676 | |
7677 | static int | |
73971819 | 7678 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7679 | { |
e99b03dc | 7680 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7681 | } |
7682 | ||
7683 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7684 | catchpoints. */ | |
7685 | ||
7686 | static int | |
f1310107 | 7687 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
bd522513 | 7688 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7689 | const struct target_waitstatus *ws) |
ce78b96d | 7690 | { |
e29a4733 PA |
7691 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7692 | ||
f90263c1 TT |
7693 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7694 | return 0; | |
7695 | ||
7696 | c->forked_inferior_pid = ws->value.related_pid; | |
7697 | return 1; | |
ce78b96d JB |
7698 | } |
7699 | ||
4a64f543 MS |
7700 | /* Implement the "print_it" breakpoint_ops method for fork |
7701 | catchpoints. */ | |
ce78b96d JB |
7702 | |
7703 | static enum print_stop_action | |
348d480f | 7704 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7705 | { |
36dfb11c | 7706 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7707 | struct breakpoint *b = bs->breakpoint_at; |
7708 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7709 | |
ce78b96d | 7710 | annotate_catchpoint (b->number); |
f303dbd6 | 7711 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7712 | if (b->disposition == disp_del) |
112e8700 | 7713 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7714 | else |
112e8700 SM |
7715 | uiout->text ("Catchpoint "); |
7716 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7717 | { |
112e8700 SM |
7718 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7719 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7720 | } |
112e8700 SM |
7721 | uiout->field_int ("bkptno", b->number); |
7722 | uiout->text (" (forked process "); | |
e99b03dc | 7723 | uiout->field_int ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7724 | uiout->text ("), "); |
ce78b96d JB |
7725 | return PRINT_SRC_AND_LOC; |
7726 | } | |
7727 | ||
4a64f543 MS |
7728 | /* Implement the "print_one" breakpoint_ops method for fork |
7729 | catchpoints. */ | |
ce78b96d JB |
7730 | |
7731 | static void | |
a6d9a66e | 7732 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7733 | { |
e29a4733 | 7734 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7735 | struct value_print_options opts; |
79a45e25 | 7736 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7737 | |
7738 | get_user_print_options (&opts); | |
7739 | ||
4a64f543 MS |
7740 | /* Field 4, the address, is omitted (which makes the columns not |
7741 | line up too nicely with the headers, but the effect is relatively | |
7742 | readable). */ | |
79a45b7d | 7743 | if (opts.addressprint) |
112e8700 | 7744 | uiout->field_skip ("addr"); |
ce78b96d | 7745 | annotate_field (5); |
112e8700 | 7746 | uiout->text ("fork"); |
d7e15655 | 7747 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7748 | { |
112e8700 | 7749 | uiout->text (", process "); |
e99b03dc | 7750 | uiout->field_int ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7751 | uiout->spaces (1); |
ce78b96d | 7752 | } |
8ac3646f | 7753 | |
112e8700 SM |
7754 | if (uiout->is_mi_like_p ()) |
7755 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7756 | } |
7757 | ||
7758 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7759 | catchpoints. */ | |
7760 | ||
7761 | static void | |
7762 | print_mention_catch_fork (struct breakpoint *b) | |
7763 | { | |
7764 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7765 | } | |
7766 | ||
6149aea9 PA |
7767 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7768 | catchpoints. */ | |
7769 | ||
7770 | static void | |
7771 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7772 | { | |
7773 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7774 | print_recreate_thread (b, fp); |
6149aea9 PA |
7775 | } |
7776 | ||
ce78b96d JB |
7777 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7778 | ||
2060206e | 7779 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7780 | |
4a64f543 MS |
7781 | /* Implement the "insert" breakpoint_ops method for vfork |
7782 | catchpoints. */ | |
ce78b96d | 7783 | |
77b06cd7 TJB |
7784 | static int |
7785 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7786 | { |
e99b03dc | 7787 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7788 | } |
7789 | ||
4a64f543 MS |
7790 | /* Implement the "remove" breakpoint_ops method for vfork |
7791 | catchpoints. */ | |
ce78b96d JB |
7792 | |
7793 | static int | |
73971819 | 7794 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7795 | { |
e99b03dc | 7796 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7797 | } |
7798 | ||
7799 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7800 | catchpoints. */ | |
7801 | ||
7802 | static int | |
f1310107 | 7803 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
bd522513 | 7804 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7805 | const struct target_waitstatus *ws) |
ce78b96d | 7806 | { |
e29a4733 PA |
7807 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7808 | ||
f90263c1 TT |
7809 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7810 | return 0; | |
7811 | ||
7812 | c->forked_inferior_pid = ws->value.related_pid; | |
7813 | return 1; | |
ce78b96d JB |
7814 | } |
7815 | ||
4a64f543 MS |
7816 | /* Implement the "print_it" breakpoint_ops method for vfork |
7817 | catchpoints. */ | |
ce78b96d JB |
7818 | |
7819 | static enum print_stop_action | |
348d480f | 7820 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7821 | { |
36dfb11c | 7822 | struct ui_out *uiout = current_uiout; |
348d480f | 7823 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7824 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7825 | ||
ce78b96d | 7826 | annotate_catchpoint (b->number); |
f303dbd6 | 7827 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7828 | if (b->disposition == disp_del) |
112e8700 | 7829 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7830 | else |
112e8700 SM |
7831 | uiout->text ("Catchpoint "); |
7832 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7833 | { |
112e8700 SM |
7834 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
7835 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7836 | } |
112e8700 SM |
7837 | uiout->field_int ("bkptno", b->number); |
7838 | uiout->text (" (vforked process "); | |
e99b03dc | 7839 | uiout->field_int ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7840 | uiout->text ("), "); |
ce78b96d JB |
7841 | return PRINT_SRC_AND_LOC; |
7842 | } | |
7843 | ||
4a64f543 MS |
7844 | /* Implement the "print_one" breakpoint_ops method for vfork |
7845 | catchpoints. */ | |
ce78b96d JB |
7846 | |
7847 | static void | |
a6d9a66e | 7848 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7849 | { |
e29a4733 | 7850 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7851 | struct value_print_options opts; |
79a45e25 | 7852 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7853 | |
7854 | get_user_print_options (&opts); | |
4a64f543 MS |
7855 | /* Field 4, the address, is omitted (which makes the columns not |
7856 | line up too nicely with the headers, but the effect is relatively | |
7857 | readable). */ | |
79a45b7d | 7858 | if (opts.addressprint) |
112e8700 | 7859 | uiout->field_skip ("addr"); |
ce78b96d | 7860 | annotate_field (5); |
112e8700 | 7861 | uiout->text ("vfork"); |
d7e15655 | 7862 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7863 | { |
112e8700 | 7864 | uiout->text (", process "); |
e99b03dc | 7865 | uiout->field_int ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7866 | uiout->spaces (1); |
ce78b96d | 7867 | } |
8ac3646f | 7868 | |
112e8700 SM |
7869 | if (uiout->is_mi_like_p ()) |
7870 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
7871 | } |
7872 | ||
7873 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7874 | catchpoints. */ | |
7875 | ||
7876 | static void | |
7877 | print_mention_catch_vfork (struct breakpoint *b) | |
7878 | { | |
7879 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7880 | } | |
7881 | ||
6149aea9 PA |
7882 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7883 | catchpoints. */ | |
7884 | ||
7885 | static void | |
7886 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7887 | { | |
7888 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7889 | print_recreate_thread (b, fp); |
6149aea9 PA |
7890 | } |
7891 | ||
ce78b96d JB |
7892 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7893 | ||
2060206e | 7894 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7895 | |
edcc5120 | 7896 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 7897 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
7898 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
7899 | ||
c1fc2657 | 7900 | struct solib_catchpoint : public breakpoint |
edcc5120 | 7901 | { |
c1fc2657 | 7902 | ~solib_catchpoint () override; |
edcc5120 TT |
7903 | |
7904 | /* True for "catch load", false for "catch unload". */ | |
7905 | unsigned char is_load; | |
7906 | ||
7907 | /* Regular expression to match, if any. COMPILED is only valid when | |
7908 | REGEX is non-NULL. */ | |
7909 | char *regex; | |
2d7cc5c7 | 7910 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
7911 | }; |
7912 | ||
c1fc2657 | 7913 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 7914 | { |
c1fc2657 | 7915 | xfree (this->regex); |
edcc5120 TT |
7916 | } |
7917 | ||
7918 | static int | |
7919 | insert_catch_solib (struct bp_location *ignore) | |
7920 | { | |
7921 | return 0; | |
7922 | } | |
7923 | ||
7924 | static int | |
73971819 | 7925 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
7926 | { |
7927 | return 0; | |
7928 | } | |
7929 | ||
7930 | static int | |
7931 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 7932 | const address_space *aspace, |
edcc5120 TT |
7933 | CORE_ADDR bp_addr, |
7934 | const struct target_waitstatus *ws) | |
7935 | { | |
7936 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7937 | struct breakpoint *other; | |
7938 | ||
7939 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7940 | return 1; | |
7941 | ||
7942 | ALL_BREAKPOINTS (other) | |
7943 | { | |
7944 | struct bp_location *other_bl; | |
7945 | ||
7946 | if (other == bl->owner) | |
7947 | continue; | |
7948 | ||
7949 | if (other->type != bp_shlib_event) | |
7950 | continue; | |
7951 | ||
c1fc2657 | 7952 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
7953 | continue; |
7954 | ||
7955 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7956 | { | |
7957 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7958 | return 1; | |
7959 | } | |
7960 | } | |
7961 | ||
7962 | return 0; | |
7963 | } | |
7964 | ||
7965 | static void | |
7966 | check_status_catch_solib (struct bpstats *bs) | |
7967 | { | |
7968 | struct solib_catchpoint *self | |
7969 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
edcc5120 TT |
7970 | |
7971 | if (self->is_load) | |
7972 | { | |
52941706 | 7973 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 TT |
7974 | { |
7975 | if (!self->regex | |
2d7cc5c7 | 7976 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
7977 | return; |
7978 | } | |
7979 | } | |
7980 | else | |
7981 | { | |
6fb16ce6 | 7982 | for (const std::string &iter : current_program_space->deleted_solibs) |
edcc5120 TT |
7983 | { |
7984 | if (!self->regex | |
6fb16ce6 | 7985 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
edcc5120 TT |
7986 | return; |
7987 | } | |
7988 | } | |
7989 | ||
7990 | bs->stop = 0; | |
7991 | bs->print_it = print_it_noop; | |
7992 | } | |
7993 | ||
7994 | static enum print_stop_action | |
7995 | print_it_catch_solib (bpstat bs) | |
7996 | { | |
7997 | struct breakpoint *b = bs->breakpoint_at; | |
7998 | struct ui_out *uiout = current_uiout; | |
7999 | ||
8000 | annotate_catchpoint (b->number); | |
f303dbd6 | 8001 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8002 | if (b->disposition == disp_del) |
112e8700 | 8003 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8004 | else |
112e8700 SM |
8005 | uiout->text ("Catchpoint "); |
8006 | uiout->field_int ("bkptno", b->number); | |
8007 | uiout->text ("\n"); | |
8008 | if (uiout->is_mi_like_p ()) | |
8009 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8010 | print_solib_event (1); |
8011 | return PRINT_SRC_AND_LOC; | |
8012 | } | |
8013 | ||
8014 | static void | |
8015 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8016 | { | |
8017 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8018 | struct value_print_options opts; | |
8019 | struct ui_out *uiout = current_uiout; | |
edcc5120 TT |
8020 | |
8021 | get_user_print_options (&opts); | |
8022 | /* Field 4, the address, is omitted (which makes the columns not | |
8023 | line up too nicely with the headers, but the effect is relatively | |
8024 | readable). */ | |
8025 | if (opts.addressprint) | |
8026 | { | |
8027 | annotate_field (4); | |
112e8700 | 8028 | uiout->field_skip ("addr"); |
edcc5120 TT |
8029 | } |
8030 | ||
528e1572 | 8031 | std::string msg; |
edcc5120 TT |
8032 | annotate_field (5); |
8033 | if (self->is_load) | |
8034 | { | |
8035 | if (self->regex) | |
528e1572 | 8036 | msg = string_printf (_("load of library matching %s"), self->regex); |
edcc5120 | 8037 | else |
528e1572 | 8038 | msg = _("load of library"); |
edcc5120 TT |
8039 | } |
8040 | else | |
8041 | { | |
8042 | if (self->regex) | |
528e1572 | 8043 | msg = string_printf (_("unload of library matching %s"), self->regex); |
edcc5120 | 8044 | else |
528e1572 | 8045 | msg = _("unload of library"); |
edcc5120 | 8046 | } |
112e8700 | 8047 | uiout->field_string ("what", msg); |
8ac3646f | 8048 | |
112e8700 SM |
8049 | if (uiout->is_mi_like_p ()) |
8050 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8051 | } |
8052 | ||
8053 | static void | |
8054 | print_mention_catch_solib (struct breakpoint *b) | |
8055 | { | |
8056 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8057 | ||
8058 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8059 | self->is_load ? "load" : "unload"); | |
8060 | } | |
8061 | ||
8062 | static void | |
8063 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8064 | { | |
8065 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8066 | ||
8067 | fprintf_unfiltered (fp, "%s %s", | |
8068 | b->disposition == disp_del ? "tcatch" : "catch", | |
8069 | self->is_load ? "load" : "unload"); | |
8070 | if (self->regex) | |
8071 | fprintf_unfiltered (fp, " %s", self->regex); | |
8072 | fprintf_unfiltered (fp, "\n"); | |
8073 | } | |
8074 | ||
8075 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8076 | ||
91985142 MG |
8077 | /* Shared helper function (MI and CLI) for creating and installing |
8078 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8079 | the events to be caught are load events, otherwise they are | |
8080 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8081 | temporary one. If ENABLED is non-zero the catchpoint is | |
8082 | created in an enabled state. */ | |
edcc5120 | 8083 | |
91985142 | 8084 | void |
a121b7c1 | 8085 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8086 | { |
edcc5120 | 8087 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8088 | |
edcc5120 TT |
8089 | if (!arg) |
8090 | arg = ""; | |
f1735a53 | 8091 | arg = skip_spaces (arg); |
edcc5120 | 8092 | |
36bd8eaa | 8093 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8094 | |
8095 | if (*arg != '\0') | |
8096 | { | |
2d7cc5c7 PA |
8097 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8098 | _("Invalid regexp"))); | |
edcc5120 TT |
8099 | c->regex = xstrdup (arg); |
8100 | } | |
8101 | ||
8102 | c->is_load = is_load; | |
36bd8eaa | 8103 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8104 | &catch_solib_breakpoint_ops); |
8105 | ||
c1fc2657 | 8106 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8107 | |
b270e6f9 | 8108 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8109 | } |
8110 | ||
91985142 MG |
8111 | /* A helper function that does all the work for "catch load" and |
8112 | "catch unload". */ | |
8113 | ||
8114 | static void | |
eb4c3f4a | 8115 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
8116 | struct cmd_list_element *command) |
8117 | { | |
8118 | int tempflag; | |
8119 | const int enabled = 1; | |
8120 | ||
8121 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8122 | ||
8123 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8124 | } | |
8125 | ||
edcc5120 | 8126 | static void |
eb4c3f4a | 8127 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8128 | struct cmd_list_element *command) |
8129 | { | |
8130 | catch_load_or_unload (arg, from_tty, 1, command); | |
8131 | } | |
8132 | ||
8133 | static void | |
eb4c3f4a | 8134 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8135 | struct cmd_list_element *command) |
8136 | { | |
8137 | catch_load_or_unload (arg, from_tty, 0, command); | |
8138 | } | |
8139 | ||
346774a9 PA |
8140 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8141 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8142 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8143 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8144 | |
ab04a2af | 8145 | void |
346774a9 PA |
8146 | init_catchpoint (struct breakpoint *b, |
8147 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8148 | const char *cond_string, |
c0a91b2b | 8149 | const struct breakpoint_ops *ops) |
c906108c | 8150 | { |
51abb421 | 8151 | symtab_and_line sal; |
6c95b8df | 8152 | sal.pspace = current_program_space; |
c5aa993b | 8153 | |
28010a5d | 8154 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8155 | |
1b36a34b | 8156 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8157 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8158 | } |
8159 | ||
28010a5d | 8160 | void |
b270e6f9 | 8161 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8162 | { |
b270e6f9 | 8163 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8164 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8165 | if (is_tracepoint (b)) |
8166 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8167 | if (!internal) |
8168 | mention (b); | |
76727919 | 8169 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
8170 | |
8171 | if (update_gll) | |
44702360 | 8172 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8173 | } |
8174 | ||
9b70b993 | 8175 | static void |
a6d9a66e | 8176 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8177 | int tempflag, const char *cond_string, |
c0a91b2b | 8178 | const struct breakpoint_ops *ops) |
c906108c | 8179 | { |
b270e6f9 | 8180 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8181 | |
b270e6f9 | 8182 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8183 | |
8184 | c->forked_inferior_pid = null_ptid; | |
8185 | ||
b270e6f9 | 8186 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8187 | } |
8188 | ||
fe798b75 JB |
8189 | /* Exec catchpoints. */ |
8190 | ||
b4d90040 | 8191 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8192 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8193 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8194 | ||
c1fc2657 | 8195 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8196 | { |
c1fc2657 | 8197 | ~exec_catchpoint () override; |
b4d90040 PA |
8198 | |
8199 | /* Filename of a program whose exec triggered this catchpoint. | |
8200 | This field is only valid immediately after this catchpoint has | |
8201 | triggered. */ | |
8202 | char *exec_pathname; | |
8203 | }; | |
8204 | ||
c1fc2657 | 8205 | /* Exec catchpoint destructor. */ |
b4d90040 | 8206 | |
c1fc2657 | 8207 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8208 | { |
c1fc2657 | 8209 | xfree (this->exec_pathname); |
b4d90040 PA |
8210 | } |
8211 | ||
77b06cd7 TJB |
8212 | static int |
8213 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8214 | { |
e99b03dc | 8215 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8216 | } |
c906108c | 8217 | |
fe798b75 | 8218 | static int |
73971819 | 8219 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8220 | { |
e99b03dc | 8221 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8222 | } |
c906108c | 8223 | |
fe798b75 | 8224 | static int |
f1310107 | 8225 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
bd522513 | 8226 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 8227 | const struct target_waitstatus *ws) |
fe798b75 | 8228 | { |
b4d90040 PA |
8229 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8230 | ||
f90263c1 TT |
8231 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8232 | return 0; | |
8233 | ||
8234 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8235 | return 1; | |
fe798b75 | 8236 | } |
c906108c | 8237 | |
fe798b75 | 8238 | static enum print_stop_action |
348d480f | 8239 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8240 | { |
36dfb11c | 8241 | struct ui_out *uiout = current_uiout; |
348d480f | 8242 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8243 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8244 | ||
fe798b75 | 8245 | annotate_catchpoint (b->number); |
f303dbd6 | 8246 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8247 | if (b->disposition == disp_del) |
112e8700 | 8248 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8249 | else |
112e8700 SM |
8250 | uiout->text ("Catchpoint "); |
8251 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8252 | { |
112e8700 SM |
8253 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8254 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8255 | } |
112e8700 SM |
8256 | uiout->field_int ("bkptno", b->number); |
8257 | uiout->text (" (exec'd "); | |
8258 | uiout->field_string ("new-exec", c->exec_pathname); | |
8259 | uiout->text ("), "); | |
36dfb11c | 8260 | |
fe798b75 | 8261 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8262 | } |
8263 | ||
fe798b75 | 8264 | static void |
a6d9a66e | 8265 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8266 | { |
b4d90040 | 8267 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8268 | struct value_print_options opts; |
79a45e25 | 8269 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8270 | |
8271 | get_user_print_options (&opts); | |
8272 | ||
8273 | /* Field 4, the address, is omitted (which makes the columns | |
8274 | not line up too nicely with the headers, but the effect | |
8275 | is relatively readable). */ | |
8276 | if (opts.addressprint) | |
112e8700 | 8277 | uiout->field_skip ("addr"); |
fe798b75 | 8278 | annotate_field (5); |
112e8700 | 8279 | uiout->text ("exec"); |
b4d90040 | 8280 | if (c->exec_pathname != NULL) |
fe798b75 | 8281 | { |
112e8700 SM |
8282 | uiout->text (", program \""); |
8283 | uiout->field_string ("what", c->exec_pathname); | |
8284 | uiout->text ("\" "); | |
fe798b75 | 8285 | } |
8ac3646f | 8286 | |
112e8700 SM |
8287 | if (uiout->is_mi_like_p ()) |
8288 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8289 | } |
8290 | ||
8291 | static void | |
8292 | print_mention_catch_exec (struct breakpoint *b) | |
8293 | { | |
8294 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8295 | } | |
8296 | ||
6149aea9 PA |
8297 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8298 | catchpoints. */ | |
8299 | ||
8300 | static void | |
8301 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8302 | { | |
8303 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8304 | print_recreate_thread (b, fp); |
6149aea9 PA |
8305 | } |
8306 | ||
2060206e | 8307 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8308 | |
c906108c | 8309 | static int |
fba45db2 | 8310 | hw_breakpoint_used_count (void) |
c906108c | 8311 | { |
c906108c | 8312 | int i = 0; |
f1310107 TJB |
8313 | struct breakpoint *b; |
8314 | struct bp_location *bl; | |
c906108c SS |
8315 | |
8316 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8317 | { |
d6b74ac4 | 8318 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8319 | for (bl = b->loc; bl; bl = bl->next) |
8320 | { | |
8321 | /* Special types of hardware breakpoints may use more than | |
8322 | one register. */ | |
348d480f | 8323 | i += b->ops->resources_needed (bl); |
f1310107 | 8324 | } |
c5aa993b | 8325 | } |
c906108c SS |
8326 | |
8327 | return i; | |
8328 | } | |
8329 | ||
a1398e0c PA |
8330 | /* Returns the resources B would use if it were a hardware |
8331 | watchpoint. */ | |
8332 | ||
c906108c | 8333 | static int |
a1398e0c | 8334 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8335 | { |
c906108c | 8336 | int i = 0; |
e09342b5 | 8337 | struct bp_location *bl; |
c906108c | 8338 | |
a1398e0c PA |
8339 | if (!breakpoint_enabled (b)) |
8340 | return 0; | |
8341 | ||
8342 | for (bl = b->loc; bl; bl = bl->next) | |
8343 | { | |
8344 | /* Special types of hardware watchpoints may use more than | |
8345 | one register. */ | |
8346 | i += b->ops->resources_needed (bl); | |
8347 | } | |
8348 | ||
8349 | return i; | |
8350 | } | |
8351 | ||
8352 | /* Returns the sum the used resources of all hardware watchpoints of | |
8353 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8354 | the sum of the used resources of all hardware watchpoints of other | |
8355 | types _not_ TYPE. */ | |
8356 | ||
8357 | static int | |
8358 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8359 | enum bptype type, int *other_type_used) | |
8360 | { | |
8361 | int i = 0; | |
8362 | struct breakpoint *b; | |
8363 | ||
c906108c SS |
8364 | *other_type_used = 0; |
8365 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8366 | { |
a1398e0c PA |
8367 | if (b == except) |
8368 | continue; | |
e09342b5 TJB |
8369 | if (!breakpoint_enabled (b)) |
8370 | continue; | |
8371 | ||
a1398e0c PA |
8372 | if (b->type == type) |
8373 | i += hw_watchpoint_use_count (b); | |
8374 | else if (is_hardware_watchpoint (b)) | |
8375 | *other_type_used = 1; | |
e09342b5 TJB |
8376 | } |
8377 | ||
c906108c SS |
8378 | return i; |
8379 | } | |
8380 | ||
c906108c | 8381 | void |
fba45db2 | 8382 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8383 | { |
c5aa993b | 8384 | struct breakpoint *b; |
c906108c SS |
8385 | |
8386 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8387 | { |
cc60f2e3 | 8388 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8389 | { |
b5de0fa7 | 8390 | b->enable_state = bp_call_disabled; |
44702360 | 8391 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8392 | } |
8393 | } | |
c906108c SS |
8394 | } |
8395 | ||
8396 | void | |
fba45db2 | 8397 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8398 | { |
c5aa993b | 8399 | struct breakpoint *b; |
c906108c SS |
8400 | |
8401 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8402 | { |
cc60f2e3 | 8403 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8404 | { |
b5de0fa7 | 8405 | b->enable_state = bp_enabled; |
44702360 | 8406 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8407 | } |
8408 | } | |
c906108c SS |
8409 | } |
8410 | ||
8bea4e01 UW |
8411 | void |
8412 | disable_breakpoints_before_startup (void) | |
8413 | { | |
6c95b8df | 8414 | current_program_space->executing_startup = 1; |
44702360 | 8415 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8416 | } |
8417 | ||
8418 | void | |
8419 | enable_breakpoints_after_startup (void) | |
8420 | { | |
6c95b8df | 8421 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8422 | breakpoint_re_set (); |
8bea4e01 UW |
8423 | } |
8424 | ||
7c16b83e PA |
8425 | /* Create a new single-step breakpoint for thread THREAD, with no |
8426 | locations. */ | |
c906108c | 8427 | |
7c16b83e PA |
8428 | static struct breakpoint * |
8429 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8430 | { | |
b270e6f9 | 8431 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8432 | |
b270e6f9 | 8433 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8434 | &momentary_breakpoint_ops); |
8435 | ||
8436 | b->disposition = disp_donttouch; | |
8437 | b->frame_id = null_frame_id; | |
8438 | ||
8439 | b->thread = thread; | |
8440 | gdb_assert (b->thread != 0); | |
8441 | ||
b270e6f9 | 8442 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8443 | } |
8444 | ||
8445 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8446 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8447 | frame. */ | |
c906108c | 8448 | |
454dafbd | 8449 | breakpoint_up |
a6d9a66e UW |
8450 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8451 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8452 | { |
52f0bd74 | 8453 | struct breakpoint *b; |
edb3359d | 8454 | |
193facb3 JK |
8455 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8456 | tail-called one. */ | |
8457 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8458 | |
06edf0c0 | 8459 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8460 | b->enable_state = bp_enabled; |
8461 | b->disposition = disp_donttouch; | |
818dd999 | 8462 | b->frame_id = frame_id; |
c906108c | 8463 | |
00431a78 | 8464 | b->thread = inferior_thread ()->global_num; |
c906108c | 8465 | |
44702360 | 8466 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8467 | |
454dafbd | 8468 | return breakpoint_up (b); |
c906108c | 8469 | } |
611c83ae | 8470 | |
06edf0c0 | 8471 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8472 | The new breakpoint will have type TYPE, use OPS as its |
8473 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8474 | |
06edf0c0 PA |
8475 | static struct breakpoint * |
8476 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8477 | enum bptype type, | |
a1aa2221 LM |
8478 | const struct breakpoint_ops *ops, |
8479 | int loc_enabled) | |
e58b0e63 PA |
8480 | { |
8481 | struct breakpoint *copy; | |
8482 | ||
06edf0c0 | 8483 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8484 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8485 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8486 | |
a6d9a66e | 8487 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8488 | copy->loc->requested_address = orig->loc->requested_address; |
8489 | copy->loc->address = orig->loc->address; | |
8490 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8491 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8492 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8493 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8494 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8495 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8496 | copy->frame_id = orig->frame_id; |
8497 | copy->thread = orig->thread; | |
6c95b8df | 8498 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8499 | |
8500 | copy->enable_state = bp_enabled; | |
8501 | copy->disposition = disp_donttouch; | |
8502 | copy->number = internal_breakpoint_number--; | |
8503 | ||
44702360 | 8504 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8505 | return copy; |
8506 | } | |
8507 | ||
06edf0c0 PA |
8508 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8509 | ORIG is NULL. */ | |
8510 | ||
8511 | struct breakpoint * | |
8512 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8513 | { | |
8514 | /* If there's nothing to clone, then return nothing. */ | |
8515 | if (orig == NULL) | |
8516 | return NULL; | |
8517 | ||
a1aa2221 | 8518 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8519 | } |
8520 | ||
454dafbd | 8521 | breakpoint_up |
a6d9a66e UW |
8522 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8523 | enum bptype type) | |
611c83ae PA |
8524 | { |
8525 | struct symtab_and_line sal; | |
8526 | ||
8527 | sal = find_pc_line (pc, 0); | |
8528 | sal.pc = pc; | |
8529 | sal.section = find_pc_overlay (pc); | |
8530 | sal.explicit_pc = 1; | |
8531 | ||
a6d9a66e | 8532 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8533 | } |
c906108c | 8534 | \f |
c5aa993b | 8535 | |
c906108c SS |
8536 | /* Tell the user we have just set a breakpoint B. */ |
8537 | ||
8538 | static void | |
fba45db2 | 8539 | mention (struct breakpoint *b) |
c906108c | 8540 | { |
348d480f | 8541 | b->ops->print_mention (b); |
2d33446d | 8542 | current_uiout->text ("\n"); |
c906108c | 8543 | } |
c906108c | 8544 | \f |
c5aa993b | 8545 | |
1a853c52 PA |
8546 | static int bp_loc_is_permanent (struct bp_location *loc); |
8547 | ||
0d381245 | 8548 | static struct bp_location * |
39d61571 | 8549 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8550 | const struct symtab_and_line *sal) |
8551 | { | |
8552 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8553 | CORE_ADDR adjusted_address; |
8554 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8555 | ||
8556 | if (loc_gdbarch == NULL) | |
8557 | loc_gdbarch = b->gdbarch; | |
8558 | ||
8559 | /* Adjust the breakpoint's address prior to allocating a location. | |
8560 | Once we call allocate_bp_location(), that mostly uninitialized | |
8561 | location will be placed on the location chain. Adjustment of the | |
8562 | breakpoint may cause target_read_memory() to be called and we do | |
8563 | not want its scan of the location chain to find a breakpoint and | |
8564 | location that's only been partially initialized. */ | |
8565 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8566 | sal->pc, b->type); | |
0d381245 | 8567 | |
d30113d4 | 8568 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8569 | loc = allocate_bp_location (b); |
d30113d4 JK |
8570 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8571 | tmp = &((*tmp)->next)) | |
0d381245 | 8572 | ; |
d30113d4 | 8573 | loc->next = *tmp; |
0d381245 | 8574 | *tmp = loc; |
3742cc8b | 8575 | |
0d381245 | 8576 | loc->requested_address = sal->pc; |
3742cc8b | 8577 | loc->address = adjusted_address; |
6c95b8df | 8578 | loc->pspace = sal->pspace; |
935676c9 | 8579 | loc->probe.prob = sal->prob; |
729662a5 | 8580 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8581 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8582 | loc->section = sal->section; |
3742cc8b | 8583 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8584 | loc->line_number = sal->line; |
2f202fde | 8585 | loc->symtab = sal->symtab; |
4a27f119 | 8586 | loc->symbol = sal->symbol; |
3467ec66 PA |
8587 | loc->msymbol = sal->msymbol; |
8588 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8589 | |
0e30163f JK |
8590 | set_breakpoint_location_function (loc, |
8591 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 8592 | |
6ae88661 LM |
8593 | /* While by definition, permanent breakpoints are already present in the |
8594 | code, we don't mark the location as inserted. Normally one would expect | |
8595 | that GDB could rely on that breakpoint instruction to stop the program, | |
8596 | thus removing the need to insert its own breakpoint, except that executing | |
8597 | the breakpoint instruction can kill the target instead of reporting a | |
8598 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8599 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8600 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8601 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8602 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8603 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8604 | it manually increments the PC, thus avoiding executing the breakpoint | |
8605 | instruction.) */ | |
1a853c52 | 8606 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8607 | loc->permanent = 1; |
1a853c52 | 8608 | |
0d381245 VP |
8609 | return loc; |
8610 | } | |
514f746b AR |
8611 | \f |
8612 | ||
1cf4d951 | 8613 | /* See breakpoint.h. */ |
514f746b | 8614 | |
1cf4d951 PA |
8615 | int |
8616 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8617 | { |
8618 | int len; | |
8619 | CORE_ADDR addr; | |
1afeeb75 | 8620 | const gdb_byte *bpoint; |
514f746b AR |
8621 | gdb_byte *target_mem; |
8622 | ||
1cf4d951 PA |
8623 | addr = address; |
8624 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8625 | ||
8626 | /* Software breakpoints unsupported? */ | |
8627 | if (bpoint == NULL) | |
8628 | return 0; | |
8629 | ||
224c3ddb | 8630 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
8631 | |
8632 | /* Enable the automatic memory restoration from breakpoints while | |
8633 | we read the memory. Otherwise we could say about our temporary | |
8634 | breakpoints they are permanent. */ | |
cb85b21b TT |
8635 | scoped_restore restore_memory |
8636 | = make_scoped_restore_show_memory_breakpoints (0); | |
1cf4d951 PA |
8637 | |
8638 | if (target_read_memory (address, target_mem, len) == 0 | |
8639 | && memcmp (target_mem, bpoint, len) == 0) | |
cb85b21b | 8640 | return 1; |
1cf4d951 | 8641 | |
cb85b21b | 8642 | return 0; |
1cf4d951 PA |
8643 | } |
8644 | ||
8645 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8646 | return 0 otherwise. */ | |
8647 | ||
8648 | static int | |
8649 | bp_loc_is_permanent (struct bp_location *loc) | |
8650 | { | |
514f746b AR |
8651 | gdb_assert (loc != NULL); |
8652 | ||
244558af LM |
8653 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
8654 | attempt to read from the addresses the locations of these breakpoint types | |
8655 | point to. program_breakpoint_here_p, below, will attempt to read | |
8656 | memory. */ | |
8657 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
8658 | return 0; | |
8659 | ||
5ed8105e | 8660 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8661 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 8662 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8663 | } |
8664 | ||
e7e0cddf SS |
8665 | /* Build a command list for the dprintf corresponding to the current |
8666 | settings of the dprintf style options. */ | |
8667 | ||
8668 | static void | |
8669 | update_dprintf_command_list (struct breakpoint *b) | |
8670 | { | |
8671 | char *dprintf_args = b->extra_string; | |
8672 | char *printf_line = NULL; | |
8673 | ||
8674 | if (!dprintf_args) | |
8675 | return; | |
8676 | ||
8677 | dprintf_args = skip_spaces (dprintf_args); | |
8678 | ||
8679 | /* Allow a comma, as it may have terminated a location, but don't | |
8680 | insist on it. */ | |
8681 | if (*dprintf_args == ',') | |
8682 | ++dprintf_args; | |
8683 | dprintf_args = skip_spaces (dprintf_args); | |
8684 | ||
8685 | if (*dprintf_args != '"') | |
8686 | error (_("Bad format string, missing '\"'.")); | |
8687 | ||
d3ce09f5 | 8688 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8689 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8690 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8691 | { |
8692 | if (!dprintf_function) | |
8693 | error (_("No function supplied for dprintf call")); | |
8694 | ||
8695 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8696 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8697 | dprintf_function, | |
8698 | dprintf_channel, | |
8699 | dprintf_args); | |
8700 | else | |
8701 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8702 | dprintf_function, | |
8703 | dprintf_args); | |
8704 | } | |
d3ce09f5 SS |
8705 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8706 | { | |
8707 | if (target_can_run_breakpoint_commands ()) | |
8708 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8709 | else | |
8710 | { | |
8711 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8712 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8713 | } | |
8714 | } | |
e7e0cddf SS |
8715 | else |
8716 | internal_error (__FILE__, __LINE__, | |
8717 | _("Invalid dprintf style.")); | |
8718 | ||
f28045c2 | 8719 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8720 | |
12973681 TT |
8721 | /* Manufacture a printf sequence. */ |
8722 | struct command_line *printf_cmd_line | |
8723 | = new struct command_line (simple_control, printf_line); | |
8724 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, | |
8725 | command_lines_deleter ())); | |
e7e0cddf SS |
8726 | } |
8727 | ||
8728 | /* Update all dprintf commands, making their command lists reflect | |
8729 | current style settings. */ | |
8730 | ||
8731 | static void | |
eb4c3f4a | 8732 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8733 | struct cmd_list_element *c) |
8734 | { | |
8735 | struct breakpoint *b; | |
8736 | ||
8737 | ALL_BREAKPOINTS (b) | |
8738 | { | |
8739 | if (b->type == bp_dprintf) | |
8740 | update_dprintf_command_list (b); | |
8741 | } | |
8742 | } | |
c3f6f71d | 8743 | |
f00aae0f KS |
8744 | /* Create a breakpoint with SAL as location. Use LOCATION |
8745 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8746 | as condition expression. If LOCATION is NULL then create an |
8747 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8748 | |
8749 | static void | |
d9b3f62e | 8750 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8751 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8752 | event_location_up &&location, |
e1e01040 PA |
8753 | gdb::unique_xmalloc_ptr<char> filter, |
8754 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8755 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8756 | enum bptype type, enum bpdisp disposition, |
8757 | int thread, int task, int ignore_count, | |
c0a91b2b | 8758 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8759 | int enabled, int internal, unsigned flags, |
8760 | int display_canonical) | |
018d34a4 | 8761 | { |
0d381245 | 8762 | int i; |
018d34a4 VP |
8763 | |
8764 | if (type == bp_hardware_breakpoint) | |
8765 | { | |
fbbd034e AS |
8766 | int target_resources_ok; |
8767 | ||
8768 | i = hw_breakpoint_used_count (); | |
8769 | target_resources_ok = | |
8770 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8771 | i + 1, 0); |
8772 | if (target_resources_ok == 0) | |
8773 | error (_("No hardware breakpoint support in the target.")); | |
8774 | else if (target_resources_ok < 0) | |
8775 | error (_("Hardware breakpoints used exceeds limit.")); | |
8776 | } | |
8777 | ||
6c5b2ebe | 8778 | gdb_assert (!sals.empty ()); |
6c95b8df | 8779 | |
6c5b2ebe | 8780 | for (const auto &sal : sals) |
0d381245 | 8781 | { |
0d381245 VP |
8782 | struct bp_location *loc; |
8783 | ||
8784 | if (from_tty) | |
5af949e3 UW |
8785 | { |
8786 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8787 | if (!loc_gdbarch) | |
8788 | loc_gdbarch = gdbarch; | |
8789 | ||
8790 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8791 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8792 | } |
0d381245 | 8793 | |
6c5b2ebe | 8794 | if (&sal == &sals[0]) |
0d381245 | 8795 | { |
d9b3f62e | 8796 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8797 | b->thread = thread; |
4a306c9a | 8798 | b->task = task; |
855a6e68 | 8799 | |
e1e01040 PA |
8800 | b->cond_string = cond_string.release (); |
8801 | b->extra_string = extra_string.release (); | |
0d381245 | 8802 | b->ignore_count = ignore_count; |
41447f92 | 8803 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8804 | b->disposition = disposition; |
6c95b8df | 8805 | |
44f238bb PA |
8806 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8807 | b->loc->inserted = 1; | |
8808 | ||
0fb4aa4b PA |
8809 | if (type == bp_static_tracepoint) |
8810 | { | |
d9b3f62e | 8811 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8812 | struct static_tracepoint_marker marker; |
8813 | ||
983af33b | 8814 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8815 | { |
8816 | /* We already know the marker exists, otherwise, we | |
8817 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8818 | const char *p |
8819 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8820 | const char *endp; |
0fb4aa4b | 8821 | |
f1735a53 | 8822 | p = skip_spaces (p); |
0fb4aa4b | 8823 | |
f1735a53 | 8824 | endp = skip_to_space (p); |
0fb4aa4b | 8825 | |
5d9310c4 | 8826 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8827 | |
3e43a32a MS |
8828 | printf_filtered (_("Probed static tracepoint " |
8829 | "marker \"%s\"\n"), | |
5d9310c4 | 8830 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8831 | } |
8832 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8833 | { | |
5d9310c4 | 8834 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8835 | |
3e43a32a MS |
8836 | printf_filtered (_("Probed static tracepoint " |
8837 | "marker \"%s\"\n"), | |
5d9310c4 | 8838 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8839 | } |
8840 | else | |
3e43a32a MS |
8841 | warning (_("Couldn't determine the static " |
8842 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8843 | } |
8844 | ||
0d381245 VP |
8845 | loc = b->loc; |
8846 | } | |
8847 | else | |
018d34a4 | 8848 | { |
39d61571 | 8849 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8850 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8851 | loc->inserted = 1; | |
0d381245 VP |
8852 | } |
8853 | ||
8854 | if (b->cond_string) | |
8855 | { | |
bbc13ae3 KS |
8856 | const char *arg = b->cond_string; |
8857 | ||
1bb9788d TT |
8858 | loc->cond = parse_exp_1 (&arg, loc->address, |
8859 | block_for_pc (loc->address), 0); | |
0d381245 | 8860 | if (*arg) |
588ae58c | 8861 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 8862 | } |
e7e0cddf SS |
8863 | |
8864 | /* Dynamic printf requires and uses additional arguments on the | |
8865 | command line, otherwise it's an error. */ | |
8866 | if (type == bp_dprintf) | |
8867 | { | |
8868 | if (b->extra_string) | |
8869 | update_dprintf_command_list (b); | |
8870 | else | |
8871 | error (_("Format string required")); | |
8872 | } | |
8873 | else if (b->extra_string) | |
588ae58c | 8874 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 8875 | } |
018d34a4 | 8876 | |
56435ebe | 8877 | b->display_canonical = display_canonical; |
f00aae0f | 8878 | if (location != NULL) |
d28cd78a | 8879 | b->location = std::move (location); |
018d34a4 | 8880 | else |
d28cd78a | 8881 | b->location = new_address_location (b->loc->address, NULL, 0); |
e1e01040 | 8882 | b->filter = filter.release (); |
d9b3f62e | 8883 | } |
018d34a4 | 8884 | |
d9b3f62e PA |
8885 | static void |
8886 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 8887 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8888 | event_location_up &&location, |
e1e01040 PA |
8889 | gdb::unique_xmalloc_ptr<char> filter, |
8890 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8891 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8892 | enum bptype type, enum bpdisp disposition, |
8893 | int thread, int task, int ignore_count, | |
c0a91b2b | 8894 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8895 | int enabled, int internal, unsigned flags, |
8896 | int display_canonical) | |
d9b3f62e | 8897 | { |
a5e364af | 8898 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 8899 | |
a5e364af | 8900 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 8901 | sals, std::move (location), |
e1e01040 PA |
8902 | std::move (filter), |
8903 | std::move (cond_string), | |
8904 | std::move (extra_string), | |
d9b3f62e PA |
8905 | type, disposition, |
8906 | thread, task, ignore_count, | |
8907 | ops, from_tty, | |
44f238bb PA |
8908 | enabled, internal, flags, |
8909 | display_canonical); | |
d9b3f62e | 8910 | |
b270e6f9 | 8911 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
8912 | } |
8913 | ||
8914 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8915 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8916 | value. COND_STRING, if not NULL, specified the condition to be | |
8917 | used for all breakpoints. Essentially the only case where | |
8918 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8919 | function. In that case, it's still not possible to specify | |
8920 | separate conditions for different overloaded functions, so | |
8921 | we take just a single condition string. | |
8922 | ||
c3f6f71d | 8923 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8924 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8925 | array contents). If the function fails (error() is called), the |
8926 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8927 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8928 | |
8929 | static void | |
8cdf0e15 | 8930 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8931 | struct linespec_result *canonical, |
e1e01040 PA |
8932 | gdb::unique_xmalloc_ptr<char> cond_string, |
8933 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
8934 | enum bptype type, enum bpdisp disposition, |
8935 | int thread, int task, int ignore_count, | |
c0a91b2b | 8936 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8937 | int enabled, int internal, unsigned flags) |
c906108c | 8938 | { |
f8eba3c6 | 8939 | if (canonical->pre_expanded) |
6c5b2ebe | 8940 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 8941 | |
6c5b2ebe | 8942 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 8943 | { |
f00aae0f | 8944 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 8945 | 'break', without arguments. */ |
ffc2605c | 8946 | event_location_up location |
f00aae0f | 8947 | = (canonical->location != NULL |
8e9e35b1 | 8948 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 8949 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 8950 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 8951 | |
6c5b2ebe | 8952 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 8953 | std::move (location), |
e1e01040 PA |
8954 | std::move (filter_string), |
8955 | std::move (cond_string), | |
8956 | std::move (extra_string), | |
e7e0cddf | 8957 | type, disposition, |
84f4c1fe | 8958 | thread, task, ignore_count, ops, |
44f238bb | 8959 | from_tty, enabled, internal, flags, |
56435ebe | 8960 | canonical->special_display); |
c3f6f71d | 8961 | } |
c3f6f71d | 8962 | } |
c906108c | 8963 | |
f00aae0f | 8964 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 8965 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
8966 | addresses found. LOCATION points to the end of the SAL (for |
8967 | linespec locations). | |
9998af43 TJB |
8968 | |
8969 | The array and the line spec strings are allocated on the heap, it is | |
8970 | the caller's responsibility to free them. */ | |
c906108c | 8971 | |
b9362cc7 | 8972 | static void |
f00aae0f | 8973 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 8974 | struct linespec_result *canonical) |
c3f6f71d | 8975 | { |
f00aae0f KS |
8976 | struct symtab_and_line cursal; |
8977 | ||
8978 | if (event_location_type (location) == LINESPEC_LOCATION) | |
8979 | { | |
a20714ff | 8980 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 8981 | |
a20714ff | 8982 | if (spec == NULL) |
f00aae0f KS |
8983 | { |
8984 | /* The last displayed codepoint, if it's valid, is our default | |
8985 | breakpoint address. */ | |
8986 | if (last_displayed_sal_is_valid ()) | |
8987 | { | |
f00aae0f KS |
8988 | /* Set sal's pspace, pc, symtab, and line to the values |
8989 | corresponding to the last call to print_frame_info. | |
8990 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
8991 | as the breakpoint line number is inappropriate otherwise. | |
8992 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
8993 | symtab_and_line sal = get_last_displayed_sal (); |
8994 | CORE_ADDR pc = sal.pc; | |
8995 | ||
f00aae0f KS |
8996 | sal = find_pc_line (pc, 0); |
8997 | ||
8998 | /* "break" without arguments is equivalent to "break *PC" | |
8999 | where PC is the last displayed codepoint's address. So | |
9000 | make sure to set sal.explicit_pc to prevent GDB from | |
9001 | trying to expand the list of sals to include all other | |
9002 | instances with the same symtab and line. */ | |
9003 | sal.pc = pc; | |
9004 | sal.explicit_pc = 1; | |
9005 | ||
6c5b2ebe PA |
9006 | struct linespec_sals lsal; |
9007 | lsal.sals = {sal}; | |
f00aae0f KS |
9008 | lsal.canonical = NULL; |
9009 | ||
6c5b2ebe | 9010 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
9011 | return; |
9012 | } | |
9013 | else | |
9014 | error (_("No default breakpoint address now.")); | |
c906108c | 9015 | } |
c906108c | 9016 | } |
f00aae0f KS |
9017 | |
9018 | /* Force almost all breakpoints to be in terms of the | |
9019 | current_source_symtab (which is decode_line_1's default). | |
9020 | This should produce the results we want almost all of the | |
9021 | time while leaving default_breakpoint_* alone. | |
9022 | ||
9023 | ObjC: However, don't match an Objective-C method name which | |
9024 | may have a '+' or '-' succeeded by a '['. */ | |
9025 | cursal = get_current_source_symtab_and_line (); | |
9026 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9027 | { |
a20714ff | 9028 | const char *spec = NULL; |
cc80f267 | 9029 | |
f00aae0f | 9030 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 9031 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 9032 | |
f00aae0f | 9033 | if (!cursal.symtab |
a20714ff PA |
9034 | || (spec != NULL |
9035 | && strchr ("+-", spec[0]) != NULL | |
9036 | && spec[1] != '[')) | |
f00aae0f | 9037 | { |
c2f4122d | 9038 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9039 | get_last_displayed_symtab (), |
9040 | get_last_displayed_line (), | |
9041 | canonical, NULL, NULL); | |
9042 | return; | |
9043 | } | |
c906108c | 9044 | } |
f00aae0f | 9045 | |
c2f4122d | 9046 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9047 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9048 | } |
c906108c | 9049 | |
c906108c | 9050 | |
c3f6f71d | 9051 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9052 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9053 | |
b9362cc7 | 9054 | static void |
6c5b2ebe | 9055 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9056 | { |
6c5b2ebe PA |
9057 | for (auto &sal : sals) |
9058 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9059 | } |
9060 | ||
7a697b8d SS |
9061 | /* Fast tracepoints may have restrictions on valid locations. For |
9062 | instance, a fast tracepoint using a jump instead of a trap will | |
9063 | likely have to overwrite more bytes than a trap would, and so can | |
9064 | only be placed where the instruction is longer than the jump, or a | |
9065 | multi-instruction sequence does not have a jump into the middle of | |
9066 | it, etc. */ | |
9067 | ||
9068 | static void | |
9069 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9070 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9071 | { |
6c5b2ebe | 9072 | for (const auto &sal : sals) |
7a697b8d | 9073 | { |
f8eba3c6 TT |
9074 | struct gdbarch *sarch; |
9075 | ||
6c5b2ebe | 9076 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9077 | /* We fall back to GDBARCH if there is no architecture |
9078 | associated with SAL. */ | |
9079 | if (sarch == NULL) | |
9080 | sarch = gdbarch; | |
281d762b TT |
9081 | std::string msg; |
9082 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 9083 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 9084 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
9085 | } |
9086 | } | |
9087 | ||
018d34a4 VP |
9088 | /* Given TOK, a string specification of condition and thread, as |
9089 | accepted by the 'break' command, extract the condition | |
9090 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9091 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9092 | If no condition is found, *COND_STRING is set to NULL. |
9093 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9094 | |
9095 | static void | |
bbc13ae3 | 9096 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9097 | char **cond_string, int *thread, int *task, |
9098 | char **rest) | |
018d34a4 VP |
9099 | { |
9100 | *cond_string = NULL; | |
9101 | *thread = -1; | |
ed1d1739 KS |
9102 | *task = 0; |
9103 | *rest = NULL; | |
9104 | ||
018d34a4 VP |
9105 | while (tok && *tok) |
9106 | { | |
bbc13ae3 | 9107 | const char *end_tok; |
018d34a4 | 9108 | int toklen; |
bbc13ae3 KS |
9109 | const char *cond_start = NULL; |
9110 | const char *cond_end = NULL; | |
cc59ec59 | 9111 | |
f1735a53 | 9112 | tok = skip_spaces (tok); |
e7e0cddf SS |
9113 | |
9114 | if ((*tok == '"' || *tok == ',') && rest) | |
9115 | { | |
9116 | *rest = savestring (tok, strlen (tok)); | |
9117 | return; | |
9118 | } | |
9119 | ||
f1735a53 | 9120 | end_tok = skip_to_space (tok); |
d634f2de | 9121 | |
018d34a4 | 9122 | toklen = end_tok - tok; |
d634f2de | 9123 | |
018d34a4 VP |
9124 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9125 | { | |
9126 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9127 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9128 | cond_end = tok; |
d634f2de | 9129 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9130 | } |
9131 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9132 | { | |
5d5658a1 PA |
9133 | const char *tmptok; |
9134 | struct thread_info *thr; | |
d634f2de | 9135 | |
018d34a4 | 9136 | tok = end_tok + 1; |
5d5658a1 | 9137 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9138 | if (tok == tmptok) |
9139 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9140 | *thread = thr->global_num; |
bbc13ae3 | 9141 | tok = tmptok; |
018d34a4 | 9142 | } |
4a306c9a JB |
9143 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9144 | { | |
9145 | char *tmptok; | |
9146 | ||
9147 | tok = end_tok + 1; | |
bbc13ae3 | 9148 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9149 | if (tok == tmptok) |
9150 | error (_("Junk after task keyword.")); | |
9151 | if (!valid_task_id (*task)) | |
b6199126 | 9152 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9153 | tok = tmptok; |
4a306c9a | 9154 | } |
e7e0cddf SS |
9155 | else if (rest) |
9156 | { | |
9157 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9158 | return; |
e7e0cddf | 9159 | } |
018d34a4 VP |
9160 | else |
9161 | error (_("Junk at end of arguments.")); | |
9162 | } | |
9163 | } | |
9164 | ||
0fb4aa4b PA |
9165 | /* Decode a static tracepoint marker spec. */ |
9166 | ||
6c5b2ebe | 9167 | static std::vector<symtab_and_line> |
f00aae0f | 9168 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 9169 | { |
f00aae0f KS |
9170 | const char *p = &(*arg_p)[3]; |
9171 | const char *endp; | |
0fb4aa4b | 9172 | |
f1735a53 | 9173 | p = skip_spaces (p); |
0fb4aa4b | 9174 | |
f1735a53 | 9175 | endp = skip_to_space (p); |
0fb4aa4b | 9176 | |
81b1e71c | 9177 | std::string marker_str (p, endp - p); |
0fb4aa4b | 9178 | |
5d9310c4 SM |
9179 | std::vector<static_tracepoint_marker> markers |
9180 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
9181 | if (markers.empty ()) | |
81b1e71c TT |
9182 | error (_("No known static tracepoint marker named %s"), |
9183 | marker_str.c_str ()); | |
0fb4aa4b | 9184 | |
6c5b2ebe | 9185 | std::vector<symtab_and_line> sals; |
5d9310c4 | 9186 | sals.reserve (markers.size ()); |
0fb4aa4b | 9187 | |
5d9310c4 | 9188 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 9189 | { |
5d9310c4 SM |
9190 | symtab_and_line sal = find_pc_line (marker.address, 0); |
9191 | sal.pc = marker.address; | |
6c5b2ebe | 9192 | sals.push_back (sal); |
5d9310c4 | 9193 | } |
0fb4aa4b | 9194 | |
0fb4aa4b PA |
9195 | *arg_p = endp; |
9196 | return sals; | |
9197 | } | |
9198 | ||
f00aae0f | 9199 | /* See breakpoint.h. */ |
0101ce28 | 9200 | |
8cdf0e15 VP |
9201 | int |
9202 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9203 | const struct event_location *location, |
9204 | const char *cond_string, | |
9205 | int thread, const char *extra_string, | |
f00aae0f | 9206 | int parse_extra, |
0fb4aa4b | 9207 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9208 | int ignore_count, |
9209 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9210 | const struct breakpoint_ops *ops, |
44f238bb PA |
9211 | int from_tty, int enabled, int internal, |
9212 | unsigned flags) | |
c3f6f71d | 9213 | { |
7efd8fc2 | 9214 | struct linespec_result canonical; |
0101ce28 | 9215 | int pending = 0; |
4a306c9a | 9216 | int task = 0; |
86b17b60 | 9217 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9218 | |
348d480f PA |
9219 | gdb_assert (ops != NULL); |
9220 | ||
f00aae0f KS |
9221 | /* If extra_string isn't useful, set it to NULL. */ |
9222 | if (extra_string != NULL && *extra_string == '\0') | |
9223 | extra_string = NULL; | |
9224 | ||
a70b8144 | 9225 | try |
b78a6381 | 9226 | { |
f00aae0f | 9227 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9228 | } |
230d2906 | 9229 | catch (const gdb_exception_error &e) |
0101ce28 | 9230 | { |
492d29ea PA |
9231 | /* If caller is interested in rc value from parse, set |
9232 | value. */ | |
9233 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9234 | { |
05ff989b AC |
9235 | /* If pending breakpoint support is turned off, throw |
9236 | error. */ | |
fa8d40ab JJ |
9237 | |
9238 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 9239 | throw; |
723a2275 VP |
9240 | |
9241 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9242 | |
05ff989b AC |
9243 | /* If pending breakpoint support is auto query and the user |
9244 | selects no, then simply return the error code. */ | |
059fb39f | 9245 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9246 | && !nquery (_("Make %s pending on future shared library load? "), |
9247 | bptype_string (type_wanted))) | |
fd9b8c24 | 9248 | return 0; |
fa8d40ab | 9249 | |
05ff989b AC |
9250 | /* At this point, either the user was queried about setting |
9251 | a pending breakpoint and selected yes, or pending | |
9252 | breakpoint behavior is on and thus a pending breakpoint | |
9253 | is defaulted on behalf of the user. */ | |
f00aae0f | 9254 | pending = 1; |
0101ce28 | 9255 | } |
492d29ea | 9256 | else |
eedc3f4f | 9257 | throw; |
0101ce28 | 9258 | } |
492d29ea | 9259 | |
6c5b2ebe | 9260 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9261 | return 0; |
c3f6f71d | 9262 | |
c3f6f71d JM |
9263 | /* Resolve all line numbers to PC's and verify that the addresses |
9264 | are ok for the target. */ | |
0101ce28 | 9265 | if (!pending) |
f8eba3c6 | 9266 | { |
6c5b2ebe PA |
9267 | for (auto &lsal : canonical.lsals) |
9268 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9269 | } |
c3f6f71d | 9270 | |
7a697b8d | 9271 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9272 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9273 | { |
6c5b2ebe PA |
9274 | for (const auto &lsal : canonical.lsals) |
9275 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9276 | } |
7a697b8d | 9277 | |
c3f6f71d JM |
9278 | /* Verify that condition can be parsed, before setting any |
9279 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9280 | breakpoint. */ |
0101ce28 | 9281 | if (!pending) |
c3f6f71d | 9282 | { |
e1e01040 PA |
9283 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9284 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9285 | ||
f00aae0f | 9286 | if (parse_extra) |
72b2ff0e | 9287 | { |
0878d0fa | 9288 | char *rest; |
e1e01040 | 9289 | char *cond; |
52d361e1 | 9290 | |
6c5b2ebe | 9291 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9292 | |
0878d0fa YQ |
9293 | /* Here we only parse 'arg' to separate condition |
9294 | from thread number, so parsing in context of first | |
9295 | sal is OK. When setting the breakpoint we'll | |
9296 | re-parse it in context of each sal. */ | |
9297 | ||
6c5b2ebe | 9298 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9299 | &cond, &thread, &task, &rest); |
9300 | cond_string_copy.reset (cond); | |
9301 | extra_string_copy.reset (rest); | |
72b2ff0e | 9302 | } |
2f069f6f | 9303 | else |
72b2ff0e | 9304 | { |
f00aae0f KS |
9305 | if (type_wanted != bp_dprintf |
9306 | && extra_string != NULL && *extra_string != '\0') | |
9307 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9308 | |
9309 | /* Create a private copy of condition string. */ | |
9310 | if (cond_string) | |
e1e01040 | 9311 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9312 | /* Create a private copy of any extra string. */ |
9313 | if (extra_string) | |
e1e01040 | 9314 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9315 | } |
0fb4aa4b | 9316 | |
52d361e1 | 9317 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9318 | std::move (cond_string_copy), |
9319 | std::move (extra_string_copy), | |
9320 | type_wanted, | |
d9b3f62e PA |
9321 | tempflag ? disp_del : disp_donttouch, |
9322 | thread, task, ignore_count, ops, | |
44f238bb | 9323 | from_tty, enabled, internal, flags); |
c906108c | 9324 | } |
0101ce28 JJ |
9325 | else |
9326 | { | |
a5e364af | 9327 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9328 | |
a5e364af | 9329 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9330 | b->location = copy_event_location (location); |
bfccc43c | 9331 | |
f00aae0f KS |
9332 | if (parse_extra) |
9333 | b->cond_string = NULL; | |
e12c7713 MK |
9334 | else |
9335 | { | |
9336 | /* Create a private copy of condition string. */ | |
e1e01040 | 9337 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9338 | b->thread = thread; |
e12c7713 | 9339 | } |
f00aae0f KS |
9340 | |
9341 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9342 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9343 | b->ignore_count = ignore_count; |
0101ce28 | 9344 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9345 | b->condition_not_parsed = 1; |
41447f92 | 9346 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9347 | if ((type_wanted != bp_breakpoint |
9348 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9349 | b->pspace = current_program_space; |
8bea4e01 | 9350 | |
b270e6f9 | 9351 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9352 | } |
9353 | ||
6c5b2ebe | 9354 | if (canonical.lsals.size () > 1) |
95a42b64 | 9355 | { |
3e43a32a MS |
9356 | warning (_("Multiple breakpoints were set.\nUse the " |
9357 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9358 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9359 | } |
9360 | ||
44702360 | 9361 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9362 | |
9363 | return 1; | |
c3f6f71d | 9364 | } |
c906108c | 9365 | |
348d480f | 9366 | /* Set a breakpoint. |
72b2ff0e VP |
9367 | ARG is a string describing breakpoint address, |
9368 | condition, and thread. | |
9369 | FLAG specifies if a breakpoint is hardware on, | |
9370 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9371 | and BP_TEMPFLAG. */ | |
348d480f | 9372 | |
98deb0da | 9373 | static void |
f2fc3015 | 9374 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9375 | { |
72b2ff0e | 9376 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9377 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9378 | ? bp_hardware_breakpoint | |
9379 | : bp_breakpoint); | |
55aa24fb | 9380 | struct breakpoint_ops *ops; |
f00aae0f | 9381 | |
ffc2605c | 9382 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9383 | |
9384 | /* Matching breakpoints on probes. */ | |
5b56227b | 9385 | if (location != NULL |
ffc2605c | 9386 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9387 | ops = &bkpt_probe_breakpoint_ops; |
9388 | else | |
9389 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9390 | |
8cdf0e15 | 9391 | create_breakpoint (get_current_arch (), |
ffc2605c | 9392 | location.get (), |
f00aae0f | 9393 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9394 | tempflag, type_wanted, |
8cdf0e15 VP |
9395 | 0 /* Ignore count */, |
9396 | pending_break_support, | |
55aa24fb | 9397 | ops, |
8cdf0e15 | 9398 | from_tty, |
84f4c1fe | 9399 | 1 /* enabled */, |
44f238bb PA |
9400 | 0 /* internal */, |
9401 | 0); | |
c906108c SS |
9402 | } |
9403 | ||
c906108c SS |
9404 | /* Helper function for break_command_1 and disassemble_command. */ |
9405 | ||
9406 | void | |
fba45db2 | 9407 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9408 | { |
9409 | CORE_ADDR pc; | |
9410 | ||
9411 | if (sal->pc == 0 && sal->symtab != NULL) | |
9412 | { | |
9413 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9414 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9415 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9416 | sal->pc = pc; |
6a048695 | 9417 | |
4a64f543 MS |
9418 | /* If this SAL corresponds to a breakpoint inserted using a line |
9419 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9420 | if (sal->explicit_line) |
059acae7 | 9421 | skip_prologue_sal (sal); |
c906108c SS |
9422 | } |
9423 | ||
9424 | if (sal->section == 0 && sal->symtab != NULL) | |
9425 | { | |
346d1dfe | 9426 | const struct blockvector *bv; |
3977b71f | 9427 | const struct block *b; |
c5aa993b | 9428 | struct symbol *sym; |
c906108c | 9429 | |
43f3e411 DE |
9430 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9431 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9432 | if (bv != NULL) |
9433 | { | |
7f0df278 | 9434 | sym = block_linkage_function (b); |
c906108c SS |
9435 | if (sym != NULL) |
9436 | { | |
eb822aa6 DE |
9437 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9438 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9439 | sym); | |
c906108c SS |
9440 | } |
9441 | else | |
9442 | { | |
4a64f543 MS |
9443 | /* It really is worthwhile to have the section, so we'll |
9444 | just have to look harder. This case can be executed | |
9445 | if we have line numbers but no functions (as can | |
9446 | happen in assembly source). */ | |
c906108c | 9447 | |
5ed8105e | 9448 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9449 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9450 | |
5ed8105e | 9451 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9452 | if (msym.minsym) |
efd66ac6 | 9453 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9454 | } |
9455 | } | |
9456 | } | |
9457 | } | |
9458 | ||
9459 | void | |
0b39b52e | 9460 | break_command (const char *arg, int from_tty) |
c906108c | 9461 | { |
db107f19 | 9462 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9463 | } |
9464 | ||
c906108c | 9465 | void |
0b39b52e | 9466 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9467 | { |
db107f19 | 9468 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9469 | } |
9470 | ||
c906108c | 9471 | static void |
0b39b52e | 9472 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9473 | { |
db107f19 | 9474 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9475 | } |
9476 | ||
9477 | static void | |
0b39b52e | 9478 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9479 | { |
db107f19 | 9480 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9481 | } |
9482 | ||
9483 | static void | |
ee7ddd71 | 9484 | stop_command (const char *arg, int from_tty) |
c906108c | 9485 | { |
a3f17187 | 9486 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9487 | Usage: stop in <function | address>\n\ |
a3f17187 | 9488 | stop at <line>\n")); |
c906108c SS |
9489 | } |
9490 | ||
9491 | static void | |
4495129a | 9492 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9493 | { |
9494 | int badInput = 0; | |
9495 | ||
cafb3438 | 9496 | if (arg == NULL) |
c906108c SS |
9497 | badInput = 1; |
9498 | else if (*arg != '*') | |
9499 | { | |
4495129a | 9500 | const char *argptr = arg; |
c906108c SS |
9501 | int hasColon = 0; |
9502 | ||
4a64f543 | 9503 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9504 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9505 | function/method name. */ |
c906108c | 9506 | while (*argptr && !hasColon) |
c5aa993b JM |
9507 | { |
9508 | hasColon = (*argptr == ':'); | |
9509 | argptr++; | |
9510 | } | |
c906108c SS |
9511 | |
9512 | if (hasColon) | |
c5aa993b | 9513 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9514 | else |
c5aa993b | 9515 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9516 | } |
9517 | ||
9518 | if (badInput) | |
a3f17187 | 9519 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9520 | else |
db107f19 | 9521 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9522 | } |
9523 | ||
9524 | static void | |
4495129a | 9525 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9526 | { |
9527 | int badInput = 0; | |
9528 | ||
cafb3438 | 9529 | if (arg == NULL || *arg == '*') /* no line number */ |
c906108c SS |
9530 | badInput = 1; |
9531 | else | |
9532 | { | |
4495129a | 9533 | const char *argptr = arg; |
c906108c SS |
9534 | int hasColon = 0; |
9535 | ||
4a64f543 MS |
9536 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9537 | it is probably a line number. */ | |
c906108c | 9538 | while (*argptr && !hasColon) |
c5aa993b JM |
9539 | { |
9540 | hasColon = (*argptr == ':'); | |
9541 | argptr++; | |
9542 | } | |
c906108c SS |
9543 | |
9544 | if (hasColon) | |
c5aa993b | 9545 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9546 | else |
c5aa993b | 9547 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9548 | } |
9549 | ||
9550 | if (badInput) | |
65e65158 | 9551 | printf_filtered (_("Usage: stop at LINE\n")); |
c906108c | 9552 | else |
db107f19 | 9553 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9554 | } |
9555 | ||
e7e0cddf SS |
9556 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9557 | with a prewired command list consisting of a single output command, | |
9558 | built from extra arguments supplied on the dprintf command | |
9559 | line. */ | |
9560 | ||
da821c7b | 9561 | static void |
0b39b52e | 9562 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9563 | { |
ffc2605c | 9564 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9565 | |
9566 | /* If non-NULL, ARG should have been advanced past the location; | |
9567 | the next character must be ','. */ | |
9568 | if (arg != NULL) | |
9569 | { | |
9570 | if (arg[0] != ',' || arg[1] == '\0') | |
9571 | error (_("Format string required")); | |
9572 | else | |
9573 | { | |
9574 | /* Skip the comma. */ | |
9575 | ++arg; | |
9576 | } | |
9577 | } | |
9578 | ||
e7e0cddf | 9579 | create_breakpoint (get_current_arch (), |
ffc2605c | 9580 | location.get (), |
f00aae0f | 9581 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9582 | 0, bp_dprintf, |
9583 | 0 /* Ignore count */, | |
9584 | pending_break_support, | |
9585 | &dprintf_breakpoint_ops, | |
9586 | from_tty, | |
9587 | 1 /* enabled */, | |
9588 | 0 /* internal */, | |
9589 | 0); | |
9590 | } | |
9591 | ||
d3ce09f5 | 9592 | static void |
0b39b52e | 9593 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9594 | { |
9595 | error (_("May only run agent-printf on the target")); | |
9596 | } | |
9597 | ||
f1310107 TJB |
9598 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9599 | ranged breakpoints. */ | |
9600 | ||
9601 | static int | |
9602 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9603 | const address_space *aspace, |
09ac7c10 TT |
9604 | CORE_ADDR bp_addr, |
9605 | const struct target_waitstatus *ws) | |
f1310107 | 9606 | { |
09ac7c10 | 9607 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9608 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9609 | return 0; |
9610 | ||
f1310107 TJB |
9611 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9612 | bl->length, aspace, bp_addr); | |
9613 | } | |
9614 | ||
9615 | /* Implement the "resources_needed" breakpoint_ops method for | |
9616 | ranged breakpoints. */ | |
9617 | ||
9618 | static int | |
9619 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9620 | { | |
9621 | return target_ranged_break_num_registers (); | |
9622 | } | |
9623 | ||
9624 | /* Implement the "print_it" breakpoint_ops method for | |
9625 | ranged breakpoints. */ | |
9626 | ||
9627 | static enum print_stop_action | |
348d480f | 9628 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9629 | { |
348d480f | 9630 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9631 | struct bp_location *bl = b->loc; |
79a45e25 | 9632 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9633 | |
9634 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9635 | ||
9636 | /* Ranged breakpoints have only one location. */ | |
9637 | gdb_assert (bl && bl->next == NULL); | |
9638 | ||
9639 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9640 | |
9641 | maybe_print_thread_hit_breakpoint (uiout); | |
9642 | ||
f1310107 | 9643 | if (b->disposition == disp_del) |
112e8700 | 9644 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9645 | else |
112e8700 SM |
9646 | uiout->text ("Ranged breakpoint "); |
9647 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9648 | { |
112e8700 | 9649 | uiout->field_string ("reason", |
f1310107 | 9650 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9651 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9652 | } |
112e8700 SM |
9653 | uiout->field_int ("bkptno", b->number); |
9654 | uiout->text (", "); | |
f1310107 TJB |
9655 | |
9656 | return PRINT_SRC_AND_LOC; | |
9657 | } | |
9658 | ||
9659 | /* Implement the "print_one" breakpoint_ops method for | |
9660 | ranged breakpoints. */ | |
9661 | ||
9662 | static void | |
9663 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9664 | struct bp_location **last_loc) | |
9665 | { | |
9666 | struct bp_location *bl = b->loc; | |
9667 | struct value_print_options opts; | |
79a45e25 | 9668 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9669 | |
9670 | /* Ranged breakpoints have only one location. */ | |
9671 | gdb_assert (bl && bl->next == NULL); | |
9672 | ||
9673 | get_user_print_options (&opts); | |
9674 | ||
9675 | if (opts.addressprint) | |
9676 | /* We don't print the address range here, it will be printed later | |
9677 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9678 | uiout->field_skip ("addr"); |
f1310107 TJB |
9679 | annotate_field (5); |
9680 | print_breakpoint_location (b, bl); | |
9681 | *last_loc = bl; | |
9682 | } | |
9683 | ||
9684 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9685 | ranged breakpoints. */ | |
9686 | ||
9687 | static void | |
9688 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9689 | struct ui_out *uiout) | |
9690 | { | |
9691 | CORE_ADDR address_start, address_end; | |
9692 | struct bp_location *bl = b->loc; | |
d7e74731 | 9693 | string_file stb; |
f1310107 TJB |
9694 | |
9695 | gdb_assert (bl); | |
9696 | ||
9697 | address_start = bl->address; | |
9698 | address_end = address_start + bl->length - 1; | |
9699 | ||
112e8700 | 9700 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9701 | stb.printf ("[%s, %s]", |
9702 | print_core_address (bl->gdbarch, address_start), | |
9703 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9704 | uiout->field_stream ("addr", stb); |
9705 | uiout->text ("\n"); | |
f1310107 TJB |
9706 | } |
9707 | ||
9708 | /* Implement the "print_mention" breakpoint_ops method for | |
9709 | ranged breakpoints. */ | |
9710 | ||
9711 | static void | |
9712 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9713 | { | |
9714 | struct bp_location *bl = b->loc; | |
79a45e25 | 9715 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9716 | |
9717 | gdb_assert (bl); | |
9718 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9719 | ||
2d33446d TT |
9720 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
9721 | b->number, paddress (bl->gdbarch, bl->address), | |
9722 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
f1310107 TJB |
9723 | } |
9724 | ||
9725 | /* Implement the "print_recreate" breakpoint_ops method for | |
9726 | ranged breakpoints. */ | |
9727 | ||
9728 | static void | |
9729 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9730 | { | |
f00aae0f | 9731 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9732 | event_location_to_string (b->location.get ()), |
9733 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9734 | print_recreate_thread (b, fp); |
f1310107 TJB |
9735 | } |
9736 | ||
9737 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9738 | ||
2060206e | 9739 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9740 | |
9741 | /* Find the address where the end of the breakpoint range should be | |
9742 | placed, given the SAL of the end of the range. This is so that if | |
9743 | the user provides a line number, the end of the range is set to the | |
9744 | last instruction of the given line. */ | |
9745 | ||
9746 | static CORE_ADDR | |
9747 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9748 | { | |
9749 | CORE_ADDR end; | |
9750 | ||
9751 | /* If the user provided a PC value, use it. Otherwise, | |
9752 | find the address of the end of the given location. */ | |
9753 | if (sal.explicit_pc) | |
9754 | end = sal.pc; | |
9755 | else | |
9756 | { | |
9757 | int ret; | |
9758 | CORE_ADDR start; | |
9759 | ||
9760 | ret = find_line_pc_range (sal, &start, &end); | |
9761 | if (!ret) | |
9762 | error (_("Could not find location of the end of the range.")); | |
9763 | ||
9764 | /* find_line_pc_range returns the start of the next line. */ | |
9765 | end--; | |
9766 | } | |
9767 | ||
9768 | return end; | |
9769 | } | |
9770 | ||
9771 | /* Implement the "break-range" CLI command. */ | |
9772 | ||
9773 | static void | |
0b39b52e | 9774 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9775 | { |
f2fc3015 | 9776 | const char *arg_start; |
f1310107 TJB |
9777 | struct linespec_result canonical_start, canonical_end; |
9778 | int bp_count, can_use_bp, length; | |
9779 | CORE_ADDR end; | |
9780 | struct breakpoint *b; | |
f1310107 TJB |
9781 | |
9782 | /* We don't support software ranged breakpoints. */ | |
9783 | if (target_ranged_break_num_registers () < 0) | |
9784 | error (_("This target does not support hardware ranged breakpoints.")); | |
9785 | ||
9786 | bp_count = hw_breakpoint_used_count (); | |
9787 | bp_count += target_ranged_break_num_registers (); | |
9788 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9789 | bp_count, 0); | |
9790 | if (can_use_bp < 0) | |
9791 | error (_("Hardware breakpoints used exceeds limit.")); | |
9792 | ||
f8eba3c6 | 9793 | arg = skip_spaces (arg); |
f1310107 TJB |
9794 | if (arg == NULL || arg[0] == '\0') |
9795 | error(_("No address range specified.")); | |
9796 | ||
f8eba3c6 | 9797 | arg_start = arg; |
ffc2605c TT |
9798 | event_location_up start_location = string_to_event_location (&arg, |
9799 | current_language); | |
9800 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
9801 | |
9802 | if (arg[0] != ',') | |
9803 | error (_("Too few arguments.")); | |
6c5b2ebe | 9804 | else if (canonical_start.lsals.empty ()) |
f1310107 | 9805 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 9806 | |
6c5b2ebe | 9807 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 9808 | |
6c5b2ebe PA |
9809 | if (canonical_start.lsals.size () > 1 |
9810 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
9811 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9812 | ||
6c5b2ebe | 9813 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 9814 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
9815 | |
9816 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9817 | arg = skip_spaces (arg); |
f1310107 TJB |
9818 | |
9819 | /* Parse the end location. */ | |
9820 | ||
f1310107 TJB |
9821 | arg_start = arg; |
9822 | ||
f8eba3c6 | 9823 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9824 | parse_breakpoint_sals because we need to specify the start location's |
9825 | symtab and line as the default symtab and line for the end of the | |
9826 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9827 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
9828 | event_location_up end_location = string_to_event_location (&arg, |
9829 | current_language); | |
9830 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
9831 | sal_start.symtab, sal_start.line, |
9832 | &canonical_end, NULL, NULL); | |
9833 | ||
6c5b2ebe | 9834 | if (canonical_end.lsals.empty ()) |
f1310107 | 9835 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 9836 | |
6c5b2ebe PA |
9837 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
9838 | if (canonical_end.lsals.size () > 1 | |
9839 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
9840 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9841 | ||
6c5b2ebe | 9842 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
9843 | |
9844 | end = find_breakpoint_range_end (sal_end); | |
9845 | if (sal_start.pc > end) | |
177b42fe | 9846 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9847 | |
9848 | length = end - sal_start.pc + 1; | |
9849 | if (length < 0) | |
9850 | /* Length overflowed. */ | |
9851 | error (_("Address range too large.")); | |
9852 | else if (length == 1) | |
9853 | { | |
9854 | /* This range is simple enough to be handled by | |
9855 | the `hbreak' command. */ | |
81b1e71c | 9856 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
9857 | |
9858 | return; | |
9859 | } | |
9860 | ||
9861 | /* Now set up the breakpoint. */ | |
9862 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9863 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9864 | set_breakpoint_count (breakpoint_count + 1); |
9865 | b->number = breakpoint_count; | |
9866 | b->disposition = disp_donttouch; | |
d28cd78a TT |
9867 | b->location = std::move (start_location); |
9868 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
9869 | b->loc->length = length; |
9870 | ||
f1310107 | 9871 | mention (b); |
76727919 | 9872 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 9873 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
9874 | } |
9875 | ||
4a64f543 MS |
9876 | /* Return non-zero if EXP is verified as constant. Returned zero |
9877 | means EXP is variable. Also the constant detection may fail for | |
9878 | some constant expressions and in such case still falsely return | |
9879 | zero. */ | |
2e6e3d9c | 9880 | |
65d79d4b SDJ |
9881 | static int |
9882 | watchpoint_exp_is_const (const struct expression *exp) | |
9883 | { | |
9884 | int i = exp->nelts; | |
9885 | ||
9886 | while (i > 0) | |
9887 | { | |
9888 | int oplenp, argsp; | |
9889 | ||
9890 | /* We are only interested in the descriptor of each element. */ | |
9891 | operator_length (exp, i, &oplenp, &argsp); | |
9892 | i -= oplenp; | |
9893 | ||
9894 | switch (exp->elts[i].opcode) | |
9895 | { | |
9896 | case BINOP_ADD: | |
9897 | case BINOP_SUB: | |
9898 | case BINOP_MUL: | |
9899 | case BINOP_DIV: | |
9900 | case BINOP_REM: | |
9901 | case BINOP_MOD: | |
9902 | case BINOP_LSH: | |
9903 | case BINOP_RSH: | |
9904 | case BINOP_LOGICAL_AND: | |
9905 | case BINOP_LOGICAL_OR: | |
9906 | case BINOP_BITWISE_AND: | |
9907 | case BINOP_BITWISE_IOR: | |
9908 | case BINOP_BITWISE_XOR: | |
9909 | case BINOP_EQUAL: | |
9910 | case BINOP_NOTEQUAL: | |
9911 | case BINOP_LESS: | |
9912 | case BINOP_GTR: | |
9913 | case BINOP_LEQ: | |
9914 | case BINOP_GEQ: | |
9915 | case BINOP_REPEAT: | |
9916 | case BINOP_COMMA: | |
9917 | case BINOP_EXP: | |
9918 | case BINOP_MIN: | |
9919 | case BINOP_MAX: | |
9920 | case BINOP_INTDIV: | |
9921 | case BINOP_CONCAT: | |
65d79d4b SDJ |
9922 | case TERNOP_COND: |
9923 | case TERNOP_SLICE: | |
65d79d4b SDJ |
9924 | |
9925 | case OP_LONG: | |
edd079d9 | 9926 | case OP_FLOAT: |
65d79d4b SDJ |
9927 | case OP_LAST: |
9928 | case OP_COMPLEX: | |
9929 | case OP_STRING: | |
65d79d4b SDJ |
9930 | case OP_ARRAY: |
9931 | case OP_TYPE: | |
608b4967 TT |
9932 | case OP_TYPEOF: |
9933 | case OP_DECLTYPE: | |
6e72ca20 | 9934 | case OP_TYPEID: |
65d79d4b SDJ |
9935 | case OP_NAME: |
9936 | case OP_OBJC_NSSTRING: | |
9937 | ||
9938 | case UNOP_NEG: | |
9939 | case UNOP_LOGICAL_NOT: | |
9940 | case UNOP_COMPLEMENT: | |
9941 | case UNOP_ADDR: | |
9942 | case UNOP_HIGH: | |
aeaa2474 | 9943 | case UNOP_CAST: |
9eaf6705 TT |
9944 | |
9945 | case UNOP_CAST_TYPE: | |
9946 | case UNOP_REINTERPRET_CAST: | |
9947 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
9948 | /* Unary, binary and ternary operators: We have to check |
9949 | their operands. If they are constant, then so is the | |
9950 | result of that operation. For instance, if A and B are | |
9951 | determined to be constants, then so is "A + B". | |
9952 | ||
9953 | UNOP_IND is one exception to the rule above, because the | |
9954 | value of *ADDR is not necessarily a constant, even when | |
9955 | ADDR is. */ | |
65d79d4b SDJ |
9956 | break; |
9957 | ||
9958 | case OP_VAR_VALUE: | |
9959 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 9960 | |
65d79d4b | 9961 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
9962 | possible that a buggy compiler could mark a variable as |
9963 | constant even when it is not, and TYPE_CONST would return | |
9964 | true in this case, while SYMBOL_CLASS wouldn't. | |
9965 | ||
9966 | We also have to check for function symbols because they | |
9967 | are always constant. */ | |
65d79d4b SDJ |
9968 | { |
9969 | struct symbol *s = exp->elts[i + 2].symbol; | |
9970 | ||
9971 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
9972 | && SYMBOL_CLASS (s) != LOC_CONST | |
9973 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
9974 | return 0; | |
9975 | break; | |
9976 | } | |
9977 | ||
9978 | /* The default action is to return 0 because we are using | |
9979 | the optimistic approach here: If we don't know something, | |
9980 | then it is not a constant. */ | |
9981 | default: | |
9982 | return 0; | |
9983 | } | |
9984 | } | |
9985 | ||
9986 | return 1; | |
9987 | } | |
9988 | ||
c1fc2657 | 9989 | /* Watchpoint destructor. */ |
3a5c3e22 | 9990 | |
c1fc2657 | 9991 | watchpoint::~watchpoint () |
3a5c3e22 | 9992 | { |
c1fc2657 SM |
9993 | xfree (this->exp_string); |
9994 | xfree (this->exp_string_reparse); | |
3a5c3e22 PA |
9995 | } |
9996 | ||
348d480f PA |
9997 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
9998 | ||
9999 | static void | |
10000 | re_set_watchpoint (struct breakpoint *b) | |
10001 | { | |
3a5c3e22 PA |
10002 | struct watchpoint *w = (struct watchpoint *) b; |
10003 | ||
348d480f PA |
10004 | /* Watchpoint can be either on expression using entirely global |
10005 | variables, or it can be on local variables. | |
10006 | ||
10007 | Watchpoints of the first kind are never auto-deleted, and even | |
10008 | persist across program restarts. Since they can use variables | |
10009 | from shared libraries, we need to reparse expression as libraries | |
10010 | are loaded and unloaded. | |
10011 | ||
10012 | Watchpoints on local variables can also change meaning as result | |
10013 | of solib event. For example, if a watchpoint uses both a local | |
10014 | and a global variables in expression, it's a local watchpoint, | |
10015 | but unloading of a shared library will make the expression | |
10016 | invalid. This is not a very common use case, but we still | |
10017 | re-evaluate expression, to avoid surprises to the user. | |
10018 | ||
10019 | Note that for local watchpoints, we re-evaluate it only if | |
10020 | watchpoints frame id is still valid. If it's not, it means the | |
10021 | watchpoint is out of scope and will be deleted soon. In fact, | |
10022 | I'm not sure we'll ever be called in this case. | |
10023 | ||
10024 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10025 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10026 | |
3a5c3e22 PA |
10027 | Don't do anything about disabled watchpoints, since they will be |
10028 | reevaluated again when enabled. */ | |
10029 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10030 | } |
10031 | ||
77b06cd7 TJB |
10032 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10033 | ||
10034 | static int | |
10035 | insert_watchpoint (struct bp_location *bl) | |
10036 | { | |
3a5c3e22 PA |
10037 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10038 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10039 | |
10040 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10041 | w->cond_exp.get ()); |
77b06cd7 TJB |
10042 | } |
10043 | ||
10044 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10045 | ||
10046 | static int | |
73971819 | 10047 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10048 | { |
3a5c3e22 PA |
10049 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10050 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10051 | |
10052 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10053 | w->cond_exp.get ()); |
e09342b5 TJB |
10054 | } |
10055 | ||
e09342b5 | 10056 | static int |
348d480f | 10057 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 10058 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 10059 | const struct target_waitstatus *ws) |
e09342b5 | 10060 | { |
348d480f | 10061 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10062 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10063 | |
348d480f PA |
10064 | /* Continuable hardware watchpoints are treated as non-existent if the |
10065 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10066 | some data address). Otherwise gdb won't stop on a break instruction | |
10067 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10068 | been defined. Also skip watchpoints which we know did not trigger | |
10069 | (did not match the data address). */ | |
10070 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10071 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10072 | return 0; |
9c06b0b4 | 10073 | |
348d480f | 10074 | return 1; |
9c06b0b4 TJB |
10075 | } |
10076 | ||
348d480f PA |
10077 | static void |
10078 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10079 | { |
348d480f | 10080 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10081 | |
348d480f | 10082 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10083 | } |
10084 | ||
10085 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10086 | hardware watchpoints. */ |
9c06b0b4 TJB |
10087 | |
10088 | static int | |
348d480f | 10089 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10090 | { |
3a5c3e22 PA |
10091 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10092 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10093 | |
10094 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10095 | } |
10096 | ||
10097 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10098 | hardware watchpoints. */ |
9c06b0b4 TJB |
10099 | |
10100 | static int | |
348d480f | 10101 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10102 | { |
efa80663 PA |
10103 | /* Read and access watchpoints only work with hardware support. */ |
10104 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10105 | } |
10106 | ||
9c06b0b4 | 10107 | static enum print_stop_action |
348d480f | 10108 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10109 | { |
348d480f | 10110 | struct breakpoint *b; |
348d480f | 10111 | enum print_stop_action result; |
3a5c3e22 | 10112 | struct watchpoint *w; |
79a45e25 | 10113 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10114 | |
10115 | gdb_assert (bs->bp_location_at != NULL); | |
10116 | ||
348d480f | 10117 | b = bs->breakpoint_at; |
3a5c3e22 | 10118 | w = (struct watchpoint *) b; |
348d480f | 10119 | |
f303dbd6 PA |
10120 | annotate_watchpoint (b->number); |
10121 | maybe_print_thread_hit_breakpoint (uiout); | |
10122 | ||
d7e74731 PA |
10123 | string_file stb; |
10124 | ||
76f9c9cf | 10125 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10126 | switch (b->type) |
10127 | { | |
348d480f | 10128 | case bp_watchpoint: |
9c06b0b4 | 10129 | case bp_hardware_watchpoint: |
112e8700 SM |
10130 | if (uiout->is_mi_like_p ()) |
10131 | uiout->field_string | |
10132 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10133 | mention (b); |
76f9c9cf | 10134 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10135 | uiout->text ("\nOld value = "); |
850645cf | 10136 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10137 | uiout->field_stream ("old", stb); |
10138 | uiout->text ("\nNew value = "); | |
850645cf | 10139 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10140 | uiout->field_stream ("new", stb); |
10141 | uiout->text ("\n"); | |
348d480f PA |
10142 | /* More than one watchpoint may have been triggered. */ |
10143 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10144 | break; |
10145 | ||
10146 | case bp_read_watchpoint: | |
112e8700 SM |
10147 | if (uiout->is_mi_like_p ()) |
10148 | uiout->field_string | |
10149 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10150 | mention (b); |
76f9c9cf | 10151 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10152 | uiout->text ("\nValue = "); |
850645cf | 10153 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10154 | uiout->field_stream ("value", stb); |
10155 | uiout->text ("\n"); | |
348d480f | 10156 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10157 | break; |
10158 | ||
10159 | case bp_access_watchpoint: | |
348d480f PA |
10160 | if (bs->old_val != NULL) |
10161 | { | |
112e8700 SM |
10162 | if (uiout->is_mi_like_p ()) |
10163 | uiout->field_string | |
10164 | ("reason", | |
348d480f PA |
10165 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10166 | mention (b); | |
76f9c9cf | 10167 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10168 | uiout->text ("\nOld value = "); |
850645cf | 10169 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10170 | uiout->field_stream ("old", stb); |
10171 | uiout->text ("\nNew value = "); | |
348d480f PA |
10172 | } |
10173 | else | |
10174 | { | |
10175 | mention (b); | |
112e8700 SM |
10176 | if (uiout->is_mi_like_p ()) |
10177 | uiout->field_string | |
10178 | ("reason", | |
348d480f | 10179 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10180 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10181 | uiout->text ("\nValue = "); |
348d480f | 10182 | } |
850645cf | 10183 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10184 | uiout->field_stream ("new", stb); |
10185 | uiout->text ("\n"); | |
348d480f | 10186 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10187 | break; |
10188 | default: | |
348d480f | 10189 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10190 | } |
10191 | ||
348d480f PA |
10192 | return result; |
10193 | } | |
10194 | ||
10195 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10196 | watchpoints. */ | |
10197 | ||
10198 | static void | |
10199 | print_mention_watchpoint (struct breakpoint *b) | |
10200 | { | |
3a5c3e22 | 10201 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10202 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10203 | const char *tuple_name; |
348d480f PA |
10204 | |
10205 | switch (b->type) | |
10206 | { | |
10207 | case bp_watchpoint: | |
112e8700 | 10208 | uiout->text ("Watchpoint "); |
46b9c129 | 10209 | tuple_name = "wpt"; |
348d480f PA |
10210 | break; |
10211 | case bp_hardware_watchpoint: | |
112e8700 | 10212 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10213 | tuple_name = "wpt"; |
348d480f PA |
10214 | break; |
10215 | case bp_read_watchpoint: | |
112e8700 | 10216 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10217 | tuple_name = "hw-rwpt"; |
348d480f PA |
10218 | break; |
10219 | case bp_access_watchpoint: | |
112e8700 | 10220 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10221 | tuple_name = "hw-awpt"; |
348d480f PA |
10222 | break; |
10223 | default: | |
10224 | internal_error (__FILE__, __LINE__, | |
10225 | _("Invalid hardware watchpoint type.")); | |
10226 | } | |
10227 | ||
46b9c129 | 10228 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10229 | uiout->field_int ("number", b->number); |
10230 | uiout->text (": "); | |
10231 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10232 | } |
10233 | ||
10234 | /* Implement the "print_recreate" breakpoint_ops method for | |
10235 | watchpoints. */ | |
10236 | ||
10237 | static void | |
10238 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10239 | { | |
3a5c3e22 PA |
10240 | struct watchpoint *w = (struct watchpoint *) b; |
10241 | ||
348d480f PA |
10242 | switch (b->type) |
10243 | { | |
10244 | case bp_watchpoint: | |
10245 | case bp_hardware_watchpoint: | |
10246 | fprintf_unfiltered (fp, "watch"); | |
10247 | break; | |
10248 | case bp_read_watchpoint: | |
10249 | fprintf_unfiltered (fp, "rwatch"); | |
10250 | break; | |
10251 | case bp_access_watchpoint: | |
10252 | fprintf_unfiltered (fp, "awatch"); | |
10253 | break; | |
10254 | default: | |
10255 | internal_error (__FILE__, __LINE__, | |
10256 | _("Invalid watchpoint type.")); | |
10257 | } | |
10258 | ||
3a5c3e22 | 10259 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10260 | print_recreate_thread (b, fp); |
348d480f PA |
10261 | } |
10262 | ||
427cd150 TT |
10263 | /* Implement the "explains_signal" breakpoint_ops method for |
10264 | watchpoints. */ | |
10265 | ||
47591c29 | 10266 | static int |
427cd150 TT |
10267 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10268 | { | |
10269 | /* A software watchpoint cannot cause a signal other than | |
10270 | GDB_SIGNAL_TRAP. */ | |
10271 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10272 | return 0; |
427cd150 | 10273 | |
47591c29 | 10274 | return 1; |
427cd150 TT |
10275 | } |
10276 | ||
348d480f PA |
10277 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10278 | ||
2060206e | 10279 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10280 | |
10281 | /* Implement the "insert" breakpoint_ops method for | |
10282 | masked hardware watchpoints. */ | |
10283 | ||
10284 | static int | |
10285 | insert_masked_watchpoint (struct bp_location *bl) | |
10286 | { | |
3a5c3e22 PA |
10287 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10288 | ||
10289 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10290 | bl->watchpoint_type); |
10291 | } | |
10292 | ||
10293 | /* Implement the "remove" breakpoint_ops method for | |
10294 | masked hardware watchpoints. */ | |
10295 | ||
10296 | static int | |
73971819 | 10297 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10298 | { |
3a5c3e22 PA |
10299 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10300 | ||
10301 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10302 | bl->watchpoint_type); |
10303 | } | |
10304 | ||
10305 | /* Implement the "resources_needed" breakpoint_ops method for | |
10306 | masked hardware watchpoints. */ | |
10307 | ||
10308 | static int | |
10309 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10310 | { | |
3a5c3e22 PA |
10311 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10312 | ||
10313 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10314 | } |
10315 | ||
10316 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10317 | masked hardware watchpoints. */ | |
10318 | ||
10319 | static int | |
10320 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10321 | { | |
10322 | return 0; | |
10323 | } | |
10324 | ||
10325 | /* Implement the "print_it" breakpoint_ops method for | |
10326 | masked hardware watchpoints. */ | |
10327 | ||
10328 | static enum print_stop_action | |
10329 | print_it_masked_watchpoint (bpstat bs) | |
10330 | { | |
10331 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10332 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10333 | |
10334 | /* Masked watchpoints have only one location. */ | |
10335 | gdb_assert (b->loc && b->loc->next == NULL); | |
10336 | ||
f303dbd6 PA |
10337 | annotate_watchpoint (b->number); |
10338 | maybe_print_thread_hit_breakpoint (uiout); | |
10339 | ||
348d480f PA |
10340 | switch (b->type) |
10341 | { | |
10342 | case bp_hardware_watchpoint: | |
112e8700 SM |
10343 | if (uiout->is_mi_like_p ()) |
10344 | uiout->field_string | |
10345 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10346 | break; |
10347 | ||
10348 | case bp_read_watchpoint: | |
112e8700 SM |
10349 | if (uiout->is_mi_like_p ()) |
10350 | uiout->field_string | |
10351 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10352 | break; |
10353 | ||
10354 | case bp_access_watchpoint: | |
112e8700 SM |
10355 | if (uiout->is_mi_like_p ()) |
10356 | uiout->field_string | |
10357 | ("reason", | |
348d480f PA |
10358 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10359 | break; | |
10360 | default: | |
10361 | internal_error (__FILE__, __LINE__, | |
10362 | _("Invalid hardware watchpoint type.")); | |
10363 | } | |
10364 | ||
10365 | mention (b); | |
112e8700 | 10366 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10367 | Check the underlying instruction at PC for the memory\n\ |
10368 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10369 | uiout->text ("\n"); |
9c06b0b4 TJB |
10370 | |
10371 | /* More than one watchpoint may have been triggered. */ | |
10372 | return PRINT_UNKNOWN; | |
10373 | } | |
10374 | ||
10375 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10376 | masked hardware watchpoints. */ | |
10377 | ||
10378 | static void | |
10379 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10380 | struct ui_out *uiout) | |
10381 | { | |
3a5c3e22 PA |
10382 | struct watchpoint *w = (struct watchpoint *) b; |
10383 | ||
9c06b0b4 TJB |
10384 | /* Masked watchpoints have only one location. */ |
10385 | gdb_assert (b->loc && b->loc->next == NULL); | |
10386 | ||
112e8700 SM |
10387 | uiout->text ("\tmask "); |
10388 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10389 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10390 | } |
10391 | ||
10392 | /* Implement the "print_mention" breakpoint_ops method for | |
10393 | masked hardware watchpoints. */ | |
10394 | ||
10395 | static void | |
10396 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10397 | { | |
3a5c3e22 | 10398 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10399 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10400 | const char *tuple_name; |
9c06b0b4 TJB |
10401 | |
10402 | switch (b->type) | |
10403 | { | |
10404 | case bp_hardware_watchpoint: | |
112e8700 | 10405 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10406 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10407 | break; |
10408 | case bp_read_watchpoint: | |
112e8700 | 10409 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10410 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10411 | break; |
10412 | case bp_access_watchpoint: | |
112e8700 | 10413 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10414 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10415 | break; |
10416 | default: | |
10417 | internal_error (__FILE__, __LINE__, | |
10418 | _("Invalid hardware watchpoint type.")); | |
10419 | } | |
10420 | ||
46b9c129 | 10421 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10422 | uiout->field_int ("number", b->number); |
10423 | uiout->text (": "); | |
10424 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10425 | } |
10426 | ||
10427 | /* Implement the "print_recreate" breakpoint_ops method for | |
10428 | masked hardware watchpoints. */ | |
10429 | ||
10430 | static void | |
10431 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10432 | { | |
3a5c3e22 | 10433 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10434 | char tmp[40]; |
10435 | ||
10436 | switch (b->type) | |
10437 | { | |
10438 | case bp_hardware_watchpoint: | |
10439 | fprintf_unfiltered (fp, "watch"); | |
10440 | break; | |
10441 | case bp_read_watchpoint: | |
10442 | fprintf_unfiltered (fp, "rwatch"); | |
10443 | break; | |
10444 | case bp_access_watchpoint: | |
10445 | fprintf_unfiltered (fp, "awatch"); | |
10446 | break; | |
10447 | default: | |
10448 | internal_error (__FILE__, __LINE__, | |
10449 | _("Invalid hardware watchpoint type.")); | |
10450 | } | |
10451 | ||
3a5c3e22 PA |
10452 | sprintf_vma (tmp, w->hw_wp_mask); |
10453 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10454 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10455 | } |
10456 | ||
10457 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10458 | ||
2060206e | 10459 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10460 | |
10461 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10462 | ||
10463 | static int | |
10464 | is_masked_watchpoint (const struct breakpoint *b) | |
10465 | { | |
10466 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10467 | } | |
10468 | ||
53a5351d JM |
10469 | /* accessflag: hw_write: watch write, |
10470 | hw_read: watch read, | |
10471 | hw_access: watch access (read or write) */ | |
c906108c | 10472 | static void |
bbc13ae3 | 10473 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10474 | int just_location, int internal) |
c906108c | 10475 | { |
c1fc2657 | 10476 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10477 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 10478 | struct value *result; |
bb9d5f81 | 10479 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10480 | const char *exp_start = NULL; |
10481 | const char *exp_end = NULL; | |
10482 | const char *tok, *end_tok; | |
9c06b0b4 | 10483 | int toklen = -1; |
bbc13ae3 KS |
10484 | const char *cond_start = NULL; |
10485 | const char *cond_end = NULL; | |
c906108c | 10486 | enum bptype bp_type; |
37e4754d | 10487 | int thread = -1; |
0cf6dd15 | 10488 | int pc = 0; |
9c06b0b4 TJB |
10489 | /* Flag to indicate whether we are going to use masks for |
10490 | the hardware watchpoint. */ | |
10491 | int use_mask = 0; | |
10492 | CORE_ADDR mask = 0; | |
c906108c | 10493 | |
37e4754d LM |
10494 | /* Make sure that we actually have parameters to parse. */ |
10495 | if (arg != NULL && arg[0] != '\0') | |
10496 | { | |
bbc13ae3 KS |
10497 | const char *value_start; |
10498 | ||
10499 | exp_end = arg + strlen (arg); | |
37e4754d | 10500 | |
9c06b0b4 TJB |
10501 | /* Look for "parameter value" pairs at the end |
10502 | of the arguments string. */ | |
bbc13ae3 | 10503 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10504 | { |
10505 | /* Skip whitespace at the end of the argument list. */ | |
10506 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10507 | tok--; | |
10508 | ||
10509 | /* Find the beginning of the last token. | |
10510 | This is the value of the parameter. */ | |
10511 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10512 | tok--; | |
10513 | value_start = tok + 1; | |
10514 | ||
10515 | /* Skip whitespace. */ | |
10516 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10517 | tok--; | |
10518 | ||
10519 | end_tok = tok; | |
10520 | ||
10521 | /* Find the beginning of the second to last token. | |
10522 | This is the parameter itself. */ | |
10523 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10524 | tok--; | |
10525 | tok++; | |
10526 | toklen = end_tok - tok + 1; | |
10527 | ||
61012eef | 10528 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10529 | { |
5d5658a1 | 10530 | struct thread_info *thr; |
9c06b0b4 TJB |
10531 | /* At this point we've found a "thread" token, which means |
10532 | the user is trying to set a watchpoint that triggers | |
10533 | only in a specific thread. */ | |
5d5658a1 | 10534 | const char *endp; |
37e4754d | 10535 | |
9c06b0b4 TJB |
10536 | if (thread != -1) |
10537 | error(_("You can specify only one thread.")); | |
37e4754d | 10538 | |
9c06b0b4 | 10539 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10540 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10541 | |
5d5658a1 | 10542 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10543 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10544 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10545 | |
5d5658a1 | 10546 | thread = thr->global_num; |
9c06b0b4 | 10547 | } |
61012eef | 10548 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10549 | { |
10550 | /* We've found a "mask" token, which means the user wants to | |
10551 | create a hardware watchpoint that is going to have the mask | |
10552 | facility. */ | |
10553 | struct value *mask_value, *mark; | |
37e4754d | 10554 | |
9c06b0b4 TJB |
10555 | if (use_mask) |
10556 | error(_("You can specify only one mask.")); | |
37e4754d | 10557 | |
9c06b0b4 | 10558 | use_mask = just_location = 1; |
37e4754d | 10559 | |
9c06b0b4 TJB |
10560 | mark = value_mark (); |
10561 | mask_value = parse_to_comma_and_eval (&value_start); | |
10562 | mask = value_as_address (mask_value); | |
10563 | value_free_to_mark (mark); | |
10564 | } | |
10565 | else | |
10566 | /* We didn't recognize what we found. We should stop here. */ | |
10567 | break; | |
37e4754d | 10568 | |
9c06b0b4 TJB |
10569 | /* Truncate the string and get rid of the "parameter value" pair before |
10570 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10571 | exp_end = tok; |
9c06b0b4 | 10572 | } |
37e4754d | 10573 | } |
bbc13ae3 KS |
10574 | else |
10575 | exp_end = arg; | |
37e4754d | 10576 | |
bbc13ae3 KS |
10577 | /* Parse the rest of the arguments. From here on out, everything |
10578 | is in terms of a newly allocated string instead of the original | |
10579 | ARG. */ | |
81b1e71c TT |
10580 | std::string expression (arg, exp_end - arg); |
10581 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10582 | innermost_block_tracker tracker; |
10583 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10584 | exp_end = arg; |
fa8a61dc TT |
10585 | /* Remove trailing whitespace from the expression before saving it. |
10586 | This makes the eventual display of the expression string a bit | |
10587 | prettier. */ | |
10588 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10589 | --exp_end; | |
10590 | ||
65d79d4b | 10591 | /* Checking if the expression is not constant. */ |
4d01a485 | 10592 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10593 | { |
10594 | int len; | |
10595 | ||
10596 | len = exp_end - exp_start; | |
10597 | while (len > 0 && isspace (exp_start[len - 1])) | |
10598 | len--; | |
10599 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10600 | } | |
10601 | ||
699bd4cf | 10602 | exp_valid_block = tracker.block (); |
b926417a | 10603 | struct value *mark = value_mark (); |
850645cf TT |
10604 | struct value *val_as_value = nullptr; |
10605 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, | |
10606 | just_location); | |
06a64a0b | 10607 | |
850645cf | 10608 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10609 | { |
850645cf TT |
10610 | saved_bitpos = value_bitpos (val_as_value); |
10611 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10612 | } |
10613 | ||
850645cf | 10614 | value_ref_ptr val; |
06a64a0b TT |
10615 | if (just_location) |
10616 | { | |
9c06b0b4 TJB |
10617 | int ret; |
10618 | ||
06a64a0b | 10619 | exp_valid_block = NULL; |
850645cf | 10620 | val = release_value (value_addr (result)); |
06a64a0b | 10621 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10622 | |
10623 | if (use_mask) | |
10624 | { | |
850645cf | 10625 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10626 | mask); |
10627 | if (ret == -1) | |
10628 | error (_("This target does not support masked watchpoints.")); | |
10629 | else if (ret == -2) | |
10630 | error (_("Invalid mask or memory region.")); | |
10631 | } | |
06a64a0b | 10632 | } |
850645cf TT |
10633 | else if (val_as_value != NULL) |
10634 | val = release_value (val_as_value); | |
c906108c | 10635 | |
f1735a53 TT |
10636 | tok = skip_spaces (arg); |
10637 | end_tok = skip_to_space (tok); | |
c906108c SS |
10638 | |
10639 | toklen = end_tok - tok; | |
10640 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10641 | { | |
10642 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10643 | innermost_block_tracker if_tracker; |
10644 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10645 | |
10646 | /* The watchpoint expression may not be local, but the condition | |
10647 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10648 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10649 | |
c906108c SS |
10650 | cond_end = tok; |
10651 | } | |
10652 | if (*tok) | |
8a3fe4f8 | 10653 | error (_("Junk at end of command.")); |
c906108c | 10654 | |
441d7c93 PA |
10655 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10656 | ||
10657 | /* Save this because create_internal_breakpoint below invalidates | |
10658 | 'wp_frame'. */ | |
10659 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10660 | |
10661 | /* If the expression is "local", then set up a "watchpoint scope" | |
10662 | breakpoint at the point where we've left the scope of the watchpoint | |
10663 | expression. Create the scope breakpoint before the watchpoint, so | |
10664 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10665 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10666 | { |
441d7c93 PA |
10667 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10668 | ||
10669 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10670 | { |
441d7c93 PA |
10671 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10672 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10673 | ||
edb3359d | 10674 | scope_breakpoint |
441d7c93 | 10675 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10676 | bp_watchpoint_scope, |
10677 | &momentary_breakpoint_ops); | |
d983da9c | 10678 | |
441d7c93 PA |
10679 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10680 | wp_frame = NULL; | |
10681 | ||
edb3359d | 10682 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10683 | |
edb3359d DJ |
10684 | /* Automatically delete the breakpoint when it hits. */ |
10685 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10686 | |
edb3359d | 10687 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10688 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10689 | |
edb3359d | 10690 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10691 | scope_breakpoint->loc->gdbarch = caller_arch; |
10692 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10693 | scope_breakpoint->loc->address |
a6d9a66e UW |
10694 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10695 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10696 | scope_breakpoint->type); |
10697 | } | |
d983da9c DJ |
10698 | } |
10699 | ||
e8369a73 AB |
10700 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10701 | watchpoints here even if hardware watchpoints are turned off, a call | |
10702 | to update_watchpoint later in this function will cause the type to | |
10703 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10704 | ||
10705 | if (accessflag == hw_read) | |
10706 | bp_type = bp_read_watchpoint; | |
10707 | else if (accessflag == hw_access) | |
10708 | bp_type = bp_access_watchpoint; | |
10709 | else | |
10710 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10711 | |
b270e6f9 | 10712 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10713 | |
348d480f | 10714 | if (use_mask) |
b270e6f9 | 10715 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10716 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10717 | else |
b270e6f9 | 10718 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10719 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10720 | w->thread = thread; |
10721 | w->disposition = disp_donttouch; | |
10722 | w->pspace = current_program_space; | |
b22e99fd | 10723 | w->exp = std::move (exp); |
3a5c3e22 PA |
10724 | w->exp_valid_block = exp_valid_block; |
10725 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10726 | if (just_location) |
10727 | { | |
850645cf TT |
10728 | struct type *t = value_type (val.get ()); |
10729 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10730 | |
43cc5389 TT |
10731 | w->exp_string_reparse |
10732 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 10733 | |
3a5c3e22 | 10734 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 10735 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
10736 | } |
10737 | else | |
3a5c3e22 | 10738 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10739 | |
10740 | if (use_mask) | |
10741 | { | |
3a5c3e22 | 10742 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10743 | } |
10744 | else | |
10745 | { | |
3a5c3e22 | 10746 | w->val = val; |
bb9d5f81 PP |
10747 | w->val_bitpos = saved_bitpos; |
10748 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 10749 | w->val_valid = 1; |
9c06b0b4 | 10750 | } |
77b06cd7 | 10751 | |
c906108c | 10752 | if (cond_start) |
c1fc2657 | 10753 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 10754 | else |
c1fc2657 | 10755 | w->cond_string = 0; |
c5aa993b | 10756 | |
441d7c93 | 10757 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10758 | { |
441d7c93 | 10759 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10760 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10761 | } |
c906108c | 10762 | else |
f6bc2008 | 10763 | { |
3a5c3e22 PA |
10764 | w->watchpoint_frame = null_frame_id; |
10765 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10766 | } |
c906108c | 10767 | |
d983da9c | 10768 | if (scope_breakpoint != NULL) |
c906108c | 10769 | { |
d983da9c DJ |
10770 | /* The scope breakpoint is related to the watchpoint. We will |
10771 | need to act on them together. */ | |
c1fc2657 | 10772 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10773 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10774 | } |
d983da9c | 10775 | |
06a64a0b TT |
10776 | if (!just_location) |
10777 | value_free_to_mark (mark); | |
2d134ed3 | 10778 | |
b270e6f9 TT |
10779 | /* Finally update the new watchpoint. This creates the locations |
10780 | that should be inserted. */ | |
10781 | update_watchpoint (w.get (), 1); | |
a9634178 | 10782 | |
b270e6f9 | 10783 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10784 | } |
10785 | ||
e09342b5 | 10786 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10787 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10788 | |
c906108c | 10789 | static int |
a6535de1 | 10790 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
10791 | { |
10792 | int found_memory_cnt = 0; | |
10793 | ||
10794 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10795 | if (!can_use_hw_watchpoints) |
c906108c | 10796 | return 0; |
c5aa993b | 10797 | |
a6535de1 TT |
10798 | gdb_assert (!vals.empty ()); |
10799 | struct value *head = vals[0].get (); | |
10800 | ||
5c44784c JM |
10801 | /* Make sure that the value of the expression depends only upon |
10802 | memory contents, and values computed from them within GDB. If we | |
10803 | find any register references or function calls, we can't use a | |
10804 | hardware watchpoint. | |
10805 | ||
10806 | The idea here is that evaluating an expression generates a series | |
10807 | of values, one holding the value of every subexpression. (The | |
10808 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10809 | a*b+c.) GDB's values hold almost enough information to establish | |
10810 | the criteria given above --- they identify memory lvalues, | |
10811 | register lvalues, computed values, etcetera. So we can evaluate | |
10812 | the expression, and then scan the chain of values that leaves | |
10813 | behind to decide whether we can detect any possible change to the | |
10814 | expression's final value using only hardware watchpoints. | |
10815 | ||
10816 | However, I don't think that the values returned by inferior | |
10817 | function calls are special in any way. So this function may not | |
10818 | notice that an expression involving an inferior function call | |
10819 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 10820 | for (const value_ref_ptr &iter : vals) |
c906108c | 10821 | { |
a6535de1 TT |
10822 | struct value *v = iter.get (); |
10823 | ||
5c44784c | 10824 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10825 | { |
8464be76 DJ |
10826 | if (v != head && value_lazy (v)) |
10827 | /* A lazy memory lvalue in the chain is one that GDB never | |
10828 | needed to fetch; we either just used its address (e.g., | |
10829 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10830 | in `a,b'). This doesn't apply to HEAD; if that is | |
10831 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10832 | ; |
53a5351d | 10833 | else |
5c44784c JM |
10834 | { |
10835 | /* Ahh, memory we actually used! Check if we can cover | |
10836 | it with hardware watchpoints. */ | |
df407dfe | 10837 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10838 | |
10839 | /* We only watch structs and arrays if user asked for it | |
10840 | explicitly, never if they just happen to appear in a | |
10841 | middle of some value chain. */ | |
10842 | if (v == head | |
10843 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
10844 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
10845 | { | |
42ae5230 | 10846 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10847 | int len; |
10848 | int num_regs; | |
10849 | ||
a9634178 | 10850 | len = (target_exact_watchpoints |
e09342b5 TJB |
10851 | && is_scalar_type_recursive (vtype))? |
10852 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10853 | |
e09342b5 TJB |
10854 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10855 | if (!num_regs) | |
2e70b7b9 MS |
10856 | return 0; |
10857 | else | |
e09342b5 | 10858 | found_memory_cnt += num_regs; |
2e70b7b9 | 10859 | } |
5c44784c | 10860 | } |
c5aa993b | 10861 | } |
5086187c AC |
10862 | else if (VALUE_LVAL (v) != not_lval |
10863 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10864 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10865 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10866 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10867 | } |
10868 | ||
10869 | /* The expression itself looks suitable for using a hardware | |
10870 | watchpoint, but give the target machine a chance to reject it. */ | |
10871 | return found_memory_cnt; | |
10872 | } | |
10873 | ||
8b93c638 | 10874 | void |
f2fc3015 | 10875 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10876 | { |
84f4c1fe | 10877 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10878 | } |
10879 | ||
06a64a0b TT |
10880 | /* A helper function that looks for the "-location" argument and then |
10881 | calls watch_command_1. */ | |
10882 | ||
10883 | static void | |
0b39b52e | 10884 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b TT |
10885 | { |
10886 | int just_location = 0; | |
10887 | ||
10888 | if (arg | |
10889 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
10890 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
cbba3ecd | 10891 | just_location = 1; |
06a64a0b | 10892 | |
84f4c1fe | 10893 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 10894 | } |
8926118c | 10895 | |
c5aa993b | 10896 | static void |
0b39b52e | 10897 | watch_command (const char *arg, int from_tty) |
c906108c | 10898 | { |
06a64a0b | 10899 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10900 | } |
10901 | ||
8b93c638 | 10902 | void |
f2fc3015 | 10903 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10904 | { |
84f4c1fe | 10905 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10906 | } |
8926118c | 10907 | |
c5aa993b | 10908 | static void |
0b39b52e | 10909 | rwatch_command (const char *arg, int from_tty) |
c906108c | 10910 | { |
06a64a0b | 10911 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10912 | } |
10913 | ||
8b93c638 | 10914 | void |
f2fc3015 | 10915 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10916 | { |
84f4c1fe | 10917 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10918 | } |
8926118c | 10919 | |
c5aa993b | 10920 | static void |
0b39b52e | 10921 | awatch_command (const char *arg, int from_tty) |
c906108c | 10922 | { |
06a64a0b | 10923 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10924 | } |
c906108c | 10925 | \f |
c5aa993b | 10926 | |
cfc31633 PA |
10927 | /* Data for the FSM that manages the until(location)/advance commands |
10928 | in infcmd.c. Here because it uses the mechanisms of | |
10929 | breakpoints. */ | |
c906108c | 10930 | |
46e3ed7f | 10931 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 10932 | { |
46e3ed7f | 10933 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
10934 | int thread; |
10935 | ||
10936 | /* The breakpoint set at the destination location. */ | |
46e3ed7f | 10937 | breakpoint_up location_breakpoint; |
cfc31633 PA |
10938 | |
10939 | /* Breakpoint set at the return address in the caller frame. May be | |
10940 | NULL. */ | |
46e3ed7f | 10941 | breakpoint_up caller_breakpoint; |
cfc31633 | 10942 | |
46e3ed7f TT |
10943 | until_break_fsm (struct interp *cmd_interp, int thread, |
10944 | breakpoint_up &&location_breakpoint, | |
10945 | breakpoint_up &&caller_breakpoint) | |
10946 | : thread_fsm (cmd_interp), | |
10947 | thread (thread), | |
10948 | location_breakpoint (std::move (location_breakpoint)), | |
10949 | caller_breakpoint (std::move (caller_breakpoint)) | |
10950 | { | |
10951 | } | |
cfc31633 | 10952 | |
46e3ed7f TT |
10953 | void clean_up (struct thread_info *thread) override; |
10954 | bool should_stop (struct thread_info *thread) override; | |
10955 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
10956 | }; |
10957 | ||
cfc31633 PA |
10958 | /* Implementation of the 'should_stop' FSM method for the |
10959 | until(location)/advance commands. */ | |
10960 | ||
46e3ed7f TT |
10961 | bool |
10962 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 10963 | { |
cfc31633 | 10964 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10965 | location_breakpoint.get ()) != NULL |
10966 | || (caller_breakpoint != NULL | |
cfc31633 | 10967 | && bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10968 | caller_breakpoint.get ()) != NULL)) |
10969 | set_finished (); | |
cfc31633 | 10970 | |
46e3ed7f | 10971 | return true; |
cfc31633 PA |
10972 | } |
10973 | ||
10974 | /* Implementation of the 'clean_up' FSM method for the | |
10975 | until(location)/advance commands. */ | |
10976 | ||
46e3ed7f TT |
10977 | void |
10978 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 10979 | { |
cfc31633 | 10980 | /* Clean up our temporary breakpoints. */ |
46e3ed7f TT |
10981 | location_breakpoint.reset (); |
10982 | caller_breakpoint.reset (); | |
10983 | delete_longjmp_breakpoint (thread); | |
cfc31633 PA |
10984 | } |
10985 | ||
10986 | /* Implementation of the 'async_reply_reason' FSM method for the | |
10987 | until(location)/advance commands. */ | |
10988 | ||
46e3ed7f TT |
10989 | enum async_reply_reason |
10990 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
10991 | { |
10992 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
10993 | } |
10994 | ||
c906108c | 10995 | void |
f2fc3015 | 10996 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 10997 | { |
8556afb4 PA |
10998 | struct frame_info *frame; |
10999 | struct gdbarch *frame_gdbarch; | |
11000 | struct frame_id stack_frame_id; | |
11001 | struct frame_id caller_frame_id; | |
186c406b TT |
11002 | int thread; |
11003 | struct thread_info *tp; | |
c906108c | 11004 | |
70509625 | 11005 | clear_proceed_status (0); |
c906108c SS |
11006 | |
11007 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11008 | this function. */ |
c5aa993b | 11009 | |
ffc2605c | 11010 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11011 | |
6c5b2ebe PA |
11012 | std::vector<symtab_and_line> sals |
11013 | = (last_displayed_sal_is_valid () | |
11014 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11015 | get_last_displayed_symtab (), | |
11016 | get_last_displayed_line ()) | |
11017 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 11018 | NULL, NULL, 0)); |
c5aa993b | 11019 | |
6c5b2ebe | 11020 | if (sals.size () != 1) |
8a3fe4f8 | 11021 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11022 | |
6c5b2ebe | 11023 | symtab_and_line &sal = sals[0]; |
c5aa993b | 11024 | |
c906108c | 11025 | if (*arg) |
8a3fe4f8 | 11026 | error (_("Junk at end of arguments.")); |
c5aa993b | 11027 | |
c906108c | 11028 | resolve_sal_pc (&sal); |
c5aa993b | 11029 | |
186c406b | 11030 | tp = inferior_thread (); |
5d5658a1 | 11031 | thread = tp->global_num; |
186c406b | 11032 | |
8556afb4 PA |
11033 | /* Note linespec handling above invalidates the frame chain. |
11034 | Installing a breakpoint also invalidates the frame chain (as it | |
11035 | may need to switch threads), so do any frame handling before | |
11036 | that. */ | |
11037 | ||
11038 | frame = get_selected_frame (NULL); | |
11039 | frame_gdbarch = get_frame_arch (frame); | |
11040 | stack_frame_id = get_stack_frame_id (frame); | |
11041 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11042 | |
ae66c1fc EZ |
11043 | /* Keep within the current frame, or in frames called by the current |
11044 | one. */ | |
edb3359d | 11045 | |
454dafbd | 11046 | breakpoint_up caller_breakpoint; |
5419bdae TT |
11047 | |
11048 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
11049 | ||
883bc8d1 | 11050 | if (frame_id_p (caller_frame_id)) |
c906108c | 11051 | { |
883bc8d1 | 11052 | struct symtab_and_line sal2; |
cfc31633 | 11053 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11054 | |
11055 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11056 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11057 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11058 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11059 | sal2, | |
11060 | caller_frame_id, | |
11061 | bp_until); | |
186c406b | 11062 | |
883bc8d1 | 11063 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 11064 | lj_deleter.emplace (thread); |
c906108c | 11065 | } |
c5aa993b | 11066 | |
c70a6932 JK |
11067 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11068 | frame = NULL; | |
11069 | ||
454dafbd | 11070 | breakpoint_up location_breakpoint; |
883bc8d1 PA |
11071 | if (anywhere) |
11072 | /* If the user told us to continue until a specified location, | |
11073 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11074 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11075 | null_frame_id, bp_until); | |
883bc8d1 PA |
11076 | else |
11077 | /* Otherwise, specify the selected frame, because we want to stop | |
11078 | only at the very same frame. */ | |
cfc31633 PA |
11079 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11080 | stack_frame_id, bp_until); | |
883bc8d1 | 11081 | |
46e3ed7f TT |
11082 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
11083 | std::move (location_breakpoint), | |
11084 | std::move (caller_breakpoint)); | |
f107f563 | 11085 | |
5419bdae TT |
11086 | if (lj_deleter) |
11087 | lj_deleter->release (); | |
f107f563 | 11088 | |
cfc31633 | 11089 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11090 | } |
ae66c1fc | 11091 | |
c906108c SS |
11092 | /* This function attempts to parse an optional "if <cond>" clause |
11093 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11094 | |
c906108c SS |
11095 | Else, it returns a pointer to the condition string. (It does not |
11096 | attempt to evaluate the string against a particular block.) And, | |
11097 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11098 | if clause in the arg string. */ |
53a5351d | 11099 | |
63160a43 PA |
11100 | const char * |
11101 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11102 | { |
63160a43 | 11103 | const char *cond_string; |
c5aa993b JM |
11104 | |
11105 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11106 | return NULL; |
c5aa993b | 11107 | |
4a64f543 | 11108 | /* Skip the "if" keyword. */ |
c906108c | 11109 | (*arg) += 2; |
c5aa993b | 11110 | |
c906108c | 11111 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11112 | condition string. */ |
f1735a53 | 11113 | *arg = skip_spaces (*arg); |
c906108c | 11114 | cond_string = *arg; |
c5aa993b | 11115 | |
4a64f543 MS |
11116 | /* Assume that the condition occupies the remainder of the arg |
11117 | string. */ | |
c906108c | 11118 | (*arg) += strlen (cond_string); |
c5aa993b | 11119 | |
c906108c SS |
11120 | return cond_string; |
11121 | } | |
c5aa993b | 11122 | |
c906108c SS |
11123 | /* Commands to deal with catching events, such as signals, exceptions, |
11124 | process start/exit, etc. */ | |
c5aa993b JM |
11125 | |
11126 | typedef enum | |
11127 | { | |
44feb3ce TT |
11128 | catch_fork_temporary, catch_vfork_temporary, |
11129 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11130 | } |
11131 | catch_fork_kind; | |
11132 | ||
c906108c | 11133 | static void |
eb4c3f4a | 11134 | catch_fork_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11135 | struct cmd_list_element *command) |
c906108c | 11136 | { |
a6d9a66e | 11137 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11138 | const char *cond_string = NULL; |
44feb3ce TT |
11139 | catch_fork_kind fork_kind; |
11140 | int tempflag; | |
11141 | ||
11142 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11143 | tempflag = (fork_kind == catch_fork_temporary | |
11144 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11145 | |
44feb3ce TT |
11146 | if (!arg) |
11147 | arg = ""; | |
f1735a53 | 11148 | arg = skip_spaces (arg); |
c5aa993b | 11149 | |
c906108c | 11150 | /* The allowed syntax is: |
c5aa993b JM |
11151 | catch [v]fork |
11152 | catch [v]fork if <cond> | |
11153 | ||
4a64f543 | 11154 | First, check if there's an if clause. */ |
c906108c | 11155 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11156 | |
c906108c | 11157 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11158 | error (_("Junk at end of arguments.")); |
c5aa993b | 11159 | |
c906108c | 11160 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11161 | and enable reporting of such events. */ |
c5aa993b JM |
11162 | switch (fork_kind) |
11163 | { | |
44feb3ce TT |
11164 | case catch_fork_temporary: |
11165 | case catch_fork_permanent: | |
a6d9a66e | 11166 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11167 | &catch_fork_breakpoint_ops); |
c906108c | 11168 | break; |
44feb3ce TT |
11169 | case catch_vfork_temporary: |
11170 | case catch_vfork_permanent: | |
a6d9a66e | 11171 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11172 | &catch_vfork_breakpoint_ops); |
c906108c | 11173 | break; |
c5aa993b | 11174 | default: |
8a3fe4f8 | 11175 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11176 | break; |
c5aa993b | 11177 | } |
c906108c SS |
11178 | } |
11179 | ||
11180 | static void | |
eb4c3f4a | 11181 | catch_exec_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11182 | struct cmd_list_element *command) |
c906108c | 11183 | { |
a6d9a66e | 11184 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11185 | int tempflag; |
63160a43 | 11186 | const char *cond_string = NULL; |
c906108c | 11187 | |
44feb3ce TT |
11188 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11189 | ||
11190 | if (!arg) | |
11191 | arg = ""; | |
f1735a53 | 11192 | arg = skip_spaces (arg); |
c906108c SS |
11193 | |
11194 | /* The allowed syntax is: | |
c5aa993b JM |
11195 | catch exec |
11196 | catch exec if <cond> | |
c906108c | 11197 | |
4a64f543 | 11198 | First, check if there's an if clause. */ |
c906108c SS |
11199 | cond_string = ep_parse_optional_if_clause (&arg); |
11200 | ||
11201 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11202 | error (_("Junk at end of arguments.")); |
c906108c | 11203 | |
b270e6f9 TT |
11204 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11205 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11206 | &catch_exec_breakpoint_ops); |
11207 | c->exec_pathname = NULL; | |
11208 | ||
b270e6f9 | 11209 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11210 | } |
c5aa993b | 11211 | |
9ac4176b | 11212 | void |
28010a5d PA |
11213 | init_ada_exception_breakpoint (struct breakpoint *b, |
11214 | struct gdbarch *gdbarch, | |
11215 | struct symtab_and_line sal, | |
f2fc3015 | 11216 | const char *addr_string, |
c0a91b2b | 11217 | const struct breakpoint_ops *ops, |
28010a5d | 11218 | int tempflag, |
349774ef | 11219 | int enabled, |
28010a5d | 11220 | int from_tty) |
f7f9143b | 11221 | { |
f7f9143b JB |
11222 | if (from_tty) |
11223 | { | |
5af949e3 UW |
11224 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11225 | if (!loc_gdbarch) | |
11226 | loc_gdbarch = gdbarch; | |
11227 | ||
6c95b8df PA |
11228 | describe_other_breakpoints (loc_gdbarch, |
11229 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11230 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11231 | version for exception catchpoints, because two catchpoints | |
11232 | used for different exception names will use the same address. | |
11233 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11234 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11235 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11236 | the user what type of catchpoint it is. The above is good |
11237 | enough for now, though. */ | |
11238 | } | |
11239 | ||
28010a5d | 11240 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11241 | |
349774ef | 11242 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11243 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11244 | b->location = string_to_event_location (&addr_string, |
11245 | language_def (language_ada)); | |
f7f9143b | 11246 | b->language = language_ada; |
f7f9143b JB |
11247 | } |
11248 | ||
c906108c | 11249 | static void |
981a3fb3 | 11250 | catch_command (const char *arg, int from_tty) |
c906108c | 11251 | { |
44feb3ce | 11252 | error (_("Catch requires an event name.")); |
c906108c SS |
11253 | } |
11254 | \f | |
11255 | ||
11256 | static void | |
981a3fb3 | 11257 | tcatch_command (const char *arg, int from_tty) |
c906108c | 11258 | { |
44feb3ce | 11259 | error (_("Catch requires an event name.")); |
c906108c SS |
11260 | } |
11261 | ||
81b1e71c | 11262 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
11263 | |
11264 | static int | |
81b1e71c | 11265 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 11266 | { |
81b1e71c TT |
11267 | uintptr_t ua = (uintptr_t) a; |
11268 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 11269 | |
81b1e71c | 11270 | if (a->number < b->number) |
8a2c437b | 11271 | return -1; |
81b1e71c | 11272 | else if (a->number > b->number) |
8a2c437b TT |
11273 | return 1; |
11274 | ||
11275 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11276 | the number 0. */ | |
11277 | if (ua < ub) | |
11278 | return -1; | |
94b0e70d | 11279 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11280 | } |
11281 | ||
80f8a6eb | 11282 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11283 | |
11284 | static void | |
0b39b52e | 11285 | clear_command (const char *arg, int from_tty) |
c906108c | 11286 | { |
81b1e71c | 11287 | struct breakpoint *b; |
c906108c | 11288 | int default_match; |
c906108c | 11289 | |
6c5b2ebe PA |
11290 | std::vector<symtab_and_line> decoded_sals; |
11291 | symtab_and_line last_sal; | |
11292 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11293 | if (arg) |
11294 | { | |
6c5b2ebe PA |
11295 | decoded_sals |
11296 | = decode_line_with_current_source (arg, | |
11297 | (DECODE_LINE_FUNFIRSTLINE | |
11298 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11299 | default_match = 0; |
6c5b2ebe | 11300 | sals = decoded_sals; |
c906108c SS |
11301 | } |
11302 | else | |
11303 | { | |
1bfeeb0f JL |
11304 | /* Set sal's line, symtab, pc, and pspace to the values |
11305 | corresponding to the last call to print_frame_info. If the | |
11306 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11307 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11308 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11309 | error (_("No source file specified.")); |
c906108c | 11310 | |
c906108c | 11311 | default_match = 1; |
6c5b2ebe | 11312 | sals = last_sal; |
c906108c SS |
11313 | } |
11314 | ||
4a64f543 MS |
11315 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11316 | seems, because all existing breakpoints typically have both | |
11317 | file/line and pc set. So, if clear is given file/line, we can | |
11318 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11319 | |
11320 | We only support clearing given the address explicitly | |
11321 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11322 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11323 | due to optimization, all in one block. |
4a64f543 MS |
11324 | |
11325 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11326 | PC corresponding to the same file:line, the breakpoint won't |
11327 | be cleared. We probably can still clear the breakpoint, but | |
11328 | since the other PC value is never presented to user, user | |
11329 | can only find it by guessing, and it does not seem important | |
11330 | to support that. */ | |
11331 | ||
4a64f543 MS |
11332 | /* For each line spec given, delete bps which correspond to it. Do |
11333 | it in two passes, solely to preserve the current behavior that | |
11334 | from_tty is forced true if we delete more than one | |
11335 | breakpoint. */ | |
c906108c | 11336 | |
81b1e71c | 11337 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 11338 | for (const auto &sal : sals) |
c906108c | 11339 | { |
05cba821 JK |
11340 | const char *sal_fullname; |
11341 | ||
c906108c | 11342 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11343 | If line given (pc == 0), clear all bpts on specified line. |
11344 | If defaulting, clear all bpts on default line | |
c906108c | 11345 | or at default pc. |
c5aa993b JM |
11346 | |
11347 | defaulting sal.pc != 0 tests to do | |
11348 | ||
11349 | 0 1 pc | |
11350 | 1 1 pc _and_ line | |
11351 | 0 0 line | |
11352 | 1 0 <can't happen> */ | |
c906108c | 11353 | |
05cba821 JK |
11354 | sal_fullname = (sal.symtab == NULL |
11355 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11356 | |
4a64f543 | 11357 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11358 | ALL_BREAKPOINTS (b) |
c5aa993b | 11359 | { |
0d381245 | 11360 | int match = 0; |
4a64f543 | 11361 | /* Are we going to delete b? */ |
cc60f2e3 | 11362 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11363 | { |
11364 | struct bp_location *loc = b->loc; | |
11365 | for (; loc; loc = loc->next) | |
11366 | { | |
f8eba3c6 TT |
11367 | /* If the user specified file:line, don't allow a PC |
11368 | match. This matches historical gdb behavior. */ | |
11369 | int pc_match = (!sal.explicit_line | |
11370 | && sal.pc | |
11371 | && (loc->pspace == sal.pspace) | |
11372 | && (loc->address == sal.pc) | |
11373 | && (!section_is_overlay (loc->section) | |
11374 | || loc->section == sal.section)); | |
4aac40c8 TT |
11375 | int line_match = 0; |
11376 | ||
11377 | if ((default_match || sal.explicit_line) | |
2f202fde | 11378 | && loc->symtab != NULL |
05cba821 | 11379 | && sal_fullname != NULL |
4aac40c8 | 11380 | && sal.pspace == loc->pspace |
05cba821 JK |
11381 | && loc->line_number == sal.line |
11382 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11383 | sal_fullname) == 0) | |
11384 | line_match = 1; | |
4aac40c8 | 11385 | |
0d381245 VP |
11386 | if (pc_match || line_match) |
11387 | { | |
11388 | match = 1; | |
11389 | break; | |
11390 | } | |
11391 | } | |
11392 | } | |
11393 | ||
11394 | if (match) | |
81b1e71c | 11395 | found.push_back (b); |
c906108c | 11396 | } |
80f8a6eb | 11397 | } |
8a2c437b | 11398 | |
80f8a6eb | 11399 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11400 | if (found.empty ()) |
80f8a6eb MS |
11401 | { |
11402 | if (arg) | |
8a3fe4f8 | 11403 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11404 | else |
8a3fe4f8 | 11405 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11406 | } |
c906108c | 11407 | |
8a2c437b | 11408 | /* Remove duplicates from the vec. */ |
81b1e71c | 11409 | std::sort (found.begin (), found.end (), |
b926417a | 11410 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11411 | { |
b926417a | 11412 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
11413 | }); |
11414 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 11415 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11416 | { |
b926417a | 11417 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
11418 | }), |
11419 | found.end ()); | |
8a2c437b | 11420 | |
81b1e71c | 11421 | if (found.size () > 1) |
4a64f543 | 11422 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11423 | if (from_tty) |
a3f17187 | 11424 | { |
81b1e71c | 11425 | if (found.size () == 1) |
a3f17187 AC |
11426 | printf_unfiltered (_("Deleted breakpoint ")); |
11427 | else | |
11428 | printf_unfiltered (_("Deleted breakpoints ")); | |
11429 | } | |
d6e956e5 | 11430 | |
81b1e71c | 11431 | for (breakpoint *iter : found) |
80f8a6eb | 11432 | { |
c5aa993b | 11433 | if (from_tty) |
81b1e71c TT |
11434 | printf_unfiltered ("%d ", iter->number); |
11435 | delete_breakpoint (iter); | |
c906108c | 11436 | } |
80f8a6eb MS |
11437 | if (from_tty) |
11438 | putchar_unfiltered ('\n'); | |
c906108c SS |
11439 | } |
11440 | \f | |
11441 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11442 | all breakpoints that are marked for deletion, whether hit or not. | |
11443 | This is called after any breakpoint is hit, or after errors. */ | |
11444 | ||
11445 | void | |
fba45db2 | 11446 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11447 | { |
35df4500 | 11448 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11449 | |
11450 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11451 | if (bs->breakpoint_at |
11452 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11453 | && bs->stop) |
f431efe5 | 11454 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11455 | |
35df4500 | 11456 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11457 | { |
b5de0fa7 | 11458 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11459 | delete_breakpoint (b); |
11460 | } | |
c906108c SS |
11461 | } |
11462 | ||
4a64f543 MS |
11463 | /* A comparison function for bp_location AP and BP being interfaced to |
11464 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11465 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 11466 | secondarily by ordering first permanent elements and |
4a64f543 | 11467 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 11468 | qsort being an unstable algorithm. */ |
876fa593 JK |
11469 | |
11470 | static int | |
f5336ca5 | 11471 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 11472 | { |
9a3c8263 SM |
11473 | const struct bp_location *a = *(const struct bp_location **) ap; |
11474 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
11475 | |
11476 | if (a->address != b->address) | |
11477 | return (a->address > b->address) - (a->address < b->address); | |
11478 | ||
dea2aa5f LM |
11479 | /* Sort locations at the same address by their pspace number, keeping |
11480 | locations of the same inferior (in a multi-inferior environment) | |
11481 | grouped. */ | |
11482 | ||
11483 | if (a->pspace->num != b->pspace->num) | |
11484 | return ((a->pspace->num > b->pspace->num) | |
11485 | - (a->pspace->num < b->pspace->num)); | |
11486 | ||
876fa593 | 11487 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11488 | if (a->permanent != b->permanent) |
11489 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11490 | |
c56a97f9 JK |
11491 | /* Make the internal GDB representation stable across GDB runs |
11492 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11493 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11494 | |
11495 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11496 | return ((a->owner->number > b->owner->number) |
11497 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11498 | |
11499 | return (a > b) - (a < b); | |
11500 | } | |
11501 | ||
f5336ca5 PA |
11502 | /* Set bp_locations_placed_address_before_address_max and |
11503 | bp_locations_shadow_len_after_address_max according to the current | |
11504 | content of the bp_locations array. */ | |
f7545552 TT |
11505 | |
11506 | static void | |
f5336ca5 | 11507 | bp_locations_target_extensions_update (void) |
f7545552 | 11508 | { |
876fa593 JK |
11509 | struct bp_location *bl, **blp_tmp; |
11510 | ||
f5336ca5 PA |
11511 | bp_locations_placed_address_before_address_max = 0; |
11512 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11513 | |
11514 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11515 | { | |
11516 | CORE_ADDR start, end, addr; | |
11517 | ||
11518 | if (!bp_location_has_shadow (bl)) | |
11519 | continue; | |
11520 | ||
11521 | start = bl->target_info.placed_address; | |
11522 | end = start + bl->target_info.shadow_len; | |
11523 | ||
11524 | gdb_assert (bl->address >= start); | |
11525 | addr = bl->address - start; | |
f5336ca5 PA |
11526 | if (addr > bp_locations_placed_address_before_address_max) |
11527 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11528 | |
11529 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11530 | ||
11531 | gdb_assert (bl->address < end); | |
11532 | addr = end - bl->address; | |
f5336ca5 PA |
11533 | if (addr > bp_locations_shadow_len_after_address_max) |
11534 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11535 | } |
f7545552 TT |
11536 | } |
11537 | ||
1e4d1764 YQ |
11538 | /* Download tracepoint locations if they haven't been. */ |
11539 | ||
11540 | static void | |
11541 | download_tracepoint_locations (void) | |
11542 | { | |
7ed2c994 | 11543 | struct breakpoint *b; |
dd2e65cc | 11544 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11545 | |
5ed8105e | 11546 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11547 | |
7ed2c994 | 11548 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11549 | { |
7ed2c994 | 11550 | struct bp_location *bl; |
1e4d1764 | 11551 | struct tracepoint *t; |
f2a8bc8a | 11552 | int bp_location_downloaded = 0; |
1e4d1764 | 11553 | |
7ed2c994 | 11554 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11555 | ? !may_insert_fast_tracepoints |
11556 | : !may_insert_tracepoints)) | |
11557 | continue; | |
11558 | ||
dd2e65cc YQ |
11559 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11560 | { | |
11561 | if (target_can_download_tracepoint ()) | |
11562 | can_download_tracepoint = TRIBOOL_TRUE; | |
11563 | else | |
11564 | can_download_tracepoint = TRIBOOL_FALSE; | |
11565 | } | |
11566 | ||
11567 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11568 | break; | |
11569 | ||
7ed2c994 YQ |
11570 | for (bl = b->loc; bl; bl = bl->next) |
11571 | { | |
11572 | /* In tracepoint, locations are _never_ duplicated, so | |
11573 | should_be_inserted is equivalent to | |
11574 | unduplicated_should_be_inserted. */ | |
11575 | if (!should_be_inserted (bl) || bl->inserted) | |
11576 | continue; | |
1e4d1764 | 11577 | |
7ed2c994 | 11578 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11579 | |
7ed2c994 | 11580 | target_download_tracepoint (bl); |
1e4d1764 | 11581 | |
7ed2c994 | 11582 | bl->inserted = 1; |
f2a8bc8a | 11583 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11584 | } |
11585 | t = (struct tracepoint *) b; | |
11586 | t->number_on_target = b->number; | |
f2a8bc8a | 11587 | if (bp_location_downloaded) |
76727919 | 11588 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11589 | } |
1e4d1764 YQ |
11590 | } |
11591 | ||
934709f0 PW |
11592 | /* Swap the insertion/duplication state between two locations. */ |
11593 | ||
11594 | static void | |
11595 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11596 | { | |
11597 | const int left_inserted = left->inserted; | |
11598 | const int left_duplicate = left->duplicate; | |
b775012e | 11599 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11600 | const struct bp_target_info left_target_info = left->target_info; |
11601 | ||
1e4d1764 YQ |
11602 | /* Locations of tracepoints can never be duplicated. */ |
11603 | if (is_tracepoint (left->owner)) | |
11604 | gdb_assert (!left->duplicate); | |
11605 | if (is_tracepoint (right->owner)) | |
11606 | gdb_assert (!right->duplicate); | |
11607 | ||
934709f0 PW |
11608 | left->inserted = right->inserted; |
11609 | left->duplicate = right->duplicate; | |
b775012e | 11610 | left->needs_update = right->needs_update; |
934709f0 PW |
11611 | left->target_info = right->target_info; |
11612 | right->inserted = left_inserted; | |
11613 | right->duplicate = left_duplicate; | |
b775012e | 11614 | right->needs_update = left_needs_update; |
934709f0 PW |
11615 | right->target_info = left_target_info; |
11616 | } | |
11617 | ||
b775012e LM |
11618 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11619 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11620 | conditions on the target's side. Such conditions need to be updated on | |
11621 | the target. */ | |
11622 | ||
11623 | static void | |
11624 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11625 | { | |
11626 | struct bp_location **locp = NULL, **loc2p; | |
11627 | struct bp_location *loc; | |
11628 | CORE_ADDR address = 0; | |
11629 | int pspace_num; | |
11630 | ||
11631 | address = bl->address; | |
11632 | pspace_num = bl->pspace->num; | |
11633 | ||
11634 | /* This is only meaningful if the target is | |
11635 | evaluating conditions and if the user has | |
11636 | opted for condition evaluation on the target's | |
11637 | side. */ | |
11638 | if (gdb_evaluates_breakpoint_condition_p () | |
11639 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11640 | return; | |
11641 | ||
11642 | /* Flag all breakpoint locations with this address and | |
11643 | the same program space as the location | |
11644 | as "its condition has changed". We need to | |
11645 | update the conditions on the target's side. */ | |
11646 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11647 | { | |
11648 | loc = *loc2p; | |
11649 | ||
11650 | if (!is_breakpoint (loc->owner) | |
11651 | || pspace_num != loc->pspace->num) | |
11652 | continue; | |
11653 | ||
11654 | /* Flag the location appropriately. We use a different state to | |
11655 | let everyone know that we already updated the set of locations | |
11656 | with addr bl->address and program space bl->pspace. This is so | |
11657 | we don't have to keep calling these functions just to mark locations | |
11658 | that have already been marked. */ | |
11659 | loc->condition_changed = condition_updated; | |
11660 | ||
11661 | /* Free the agent expression bytecode as well. We will compute | |
11662 | it later on. */ | |
833177a4 | 11663 | loc->cond_bytecode.reset (); |
b775012e LM |
11664 | } |
11665 | } | |
44702360 PA |
11666 | /* Called whether new breakpoints are created, or existing breakpoints |
11667 | deleted, to update the global location list and recompute which | |
11668 | locations are duplicate of which. | |
b775012e | 11669 | |
04086b45 PA |
11670 | The INSERT_MODE flag determines whether locations may not, may, or |
11671 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11672 | info. */ | |
b60e7edf | 11673 | |
0d381245 | 11674 | static void |
44702360 | 11675 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11676 | { |
74960c60 | 11677 | struct breakpoint *b; |
876fa593 | 11678 | struct bp_location **locp, *loc; |
b775012e LM |
11679 | /* Last breakpoint location address that was marked for update. */ |
11680 | CORE_ADDR last_addr = 0; | |
11681 | /* Last breakpoint location program space that was marked for update. */ | |
11682 | int last_pspace_num = -1; | |
f7545552 | 11683 | |
2d134ed3 PA |
11684 | /* Used in the duplicates detection below. When iterating over all |
11685 | bp_locations, points to the first bp_location of a given address. | |
11686 | Breakpoints and watchpoints of different types are never | |
11687 | duplicates of each other. Keep one pointer for each type of | |
11688 | breakpoint/watchpoint, so we only need to loop over all locations | |
11689 | once. */ | |
11690 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11691 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11692 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11693 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11694 | |
f5336ca5 PA |
11695 | /* Saved former bp_locations array which we compare against the newly |
11696 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
81b1e71c | 11697 | struct bp_location **old_locp; |
f5336ca5 | 11698 | unsigned old_locations_count; |
81b1e71c | 11699 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
876fa593 | 11700 | |
f5336ca5 PA |
11701 | old_locations_count = bp_locations_count; |
11702 | bp_locations = NULL; | |
11703 | bp_locations_count = 0; | |
0d381245 | 11704 | |
74960c60 | 11705 | ALL_BREAKPOINTS (b) |
876fa593 | 11706 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 11707 | bp_locations_count++; |
876fa593 | 11708 | |
f5336ca5 PA |
11709 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
11710 | locp = bp_locations; | |
876fa593 JK |
11711 | ALL_BREAKPOINTS (b) |
11712 | for (loc = b->loc; loc; loc = loc->next) | |
11713 | *locp++ = loc; | |
f5336ca5 PA |
11714 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
11715 | bp_locations_compare); | |
876fa593 | 11716 | |
f5336ca5 | 11717 | bp_locations_target_extensions_update (); |
74960c60 | 11718 | |
4a64f543 MS |
11719 | /* Identify bp_location instances that are no longer present in the |
11720 | new list, and therefore should be freed. Note that it's not | |
11721 | necessary that those locations should be removed from inferior -- | |
11722 | if there's another location at the same address (previously | |
11723 | marked as duplicate), we don't need to remove/insert the | |
11724 | location. | |
876fa593 | 11725 | |
4a64f543 MS |
11726 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11727 | and former bp_location array state respectively. */ | |
876fa593 | 11728 | |
f5336ca5 | 11729 | locp = bp_locations; |
81b1e71c TT |
11730 | for (old_locp = old_locations.get (); |
11731 | old_locp < old_locations.get () + old_locations_count; | |
876fa593 | 11732 | old_locp++) |
74960c60 | 11733 | { |
876fa593 | 11734 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11735 | struct bp_location **loc2p; |
876fa593 | 11736 | |
e5dd4106 | 11737 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11738 | not, we have to free it. */ |
c7d46a38 | 11739 | int found_object = 0; |
20874c92 VP |
11740 | /* Tells if the location should remain inserted in the target. */ |
11741 | int keep_in_target = 0; | |
11742 | int removed = 0; | |
876fa593 | 11743 | |
4a64f543 MS |
11744 | /* Skip LOCP entries which will definitely never be needed. |
11745 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 11746 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 11747 | && (*locp)->address < old_loc->address) |
876fa593 | 11748 | locp++; |
c7d46a38 PA |
11749 | |
11750 | for (loc2p = locp; | |
f5336ca5 | 11751 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
11752 | && (*loc2p)->address == old_loc->address); |
11753 | loc2p++) | |
11754 | { | |
b775012e LM |
11755 | /* Check if this is a new/duplicated location or a duplicated |
11756 | location that had its condition modified. If so, we want to send | |
11757 | its condition to the target if evaluation of conditions is taking | |
11758 | place there. */ | |
11759 | if ((*loc2p)->condition_changed == condition_modified | |
11760 | && (last_addr != old_loc->address | |
11761 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11762 | { |
b775012e LM |
11763 | force_breakpoint_reinsertion (*loc2p); |
11764 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11765 | } |
b775012e LM |
11766 | |
11767 | if (*loc2p == old_loc) | |
11768 | found_object = 1; | |
c7d46a38 | 11769 | } |
74960c60 | 11770 | |
b775012e LM |
11771 | /* We have already handled this address, update it so that we don't |
11772 | have to go through updates again. */ | |
11773 | last_addr = old_loc->address; | |
11774 | ||
11775 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11776 | if (!found_object) | |
11777 | force_breakpoint_reinsertion (old_loc); | |
11778 | ||
4a64f543 MS |
11779 | /* If this location is no longer present, and inserted, look if |
11780 | there's maybe a new location at the same address. If so, | |
11781 | mark that one inserted, and don't remove this one. This is | |
11782 | needed so that we don't have a time window where a breakpoint | |
11783 | at certain location is not inserted. */ | |
74960c60 | 11784 | |
876fa593 | 11785 | if (old_loc->inserted) |
0d381245 | 11786 | { |
4a64f543 MS |
11787 | /* If the location is inserted now, we might have to remove |
11788 | it. */ | |
74960c60 | 11789 | |
876fa593 | 11790 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11791 | { |
4a64f543 MS |
11792 | /* The location is still present in the location list, |
11793 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11794 | keep_in_target = 1; |
74960c60 VP |
11795 | } |
11796 | else | |
11797 | { | |
b775012e LM |
11798 | /* This location still exists, but it won't be kept in the |
11799 | target since it may have been disabled. We proceed to | |
11800 | remove its target-side condition. */ | |
11801 | ||
4a64f543 MS |
11802 | /* The location is either no longer present, or got |
11803 | disabled. See if there's another location at the | |
11804 | same address, in which case we don't need to remove | |
11805 | this one from the target. */ | |
876fa593 | 11806 | |
2bdf28a0 | 11807 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
11808 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
11809 | { | |
876fa593 | 11810 | for (loc2p = locp; |
f5336ca5 | 11811 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 11812 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
11813 | loc2p++) |
11814 | { | |
11815 | struct bp_location *loc2 = *loc2p; | |
11816 | ||
2d134ed3 | 11817 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11818 | { |
85d721b8 PA |
11819 | /* Read watchpoint locations are switched to |
11820 | access watchpoints, if the former are not | |
11821 | supported, but the latter are. */ | |
11822 | if (is_hardware_watchpoint (old_loc->owner)) | |
11823 | { | |
11824 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11825 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11826 | } | |
11827 | ||
934709f0 PW |
11828 | /* loc2 is a duplicated location. We need to check |
11829 | if it should be inserted in case it will be | |
11830 | unduplicated. */ | |
11831 | if (loc2 != old_loc | |
11832 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 11833 | { |
934709f0 | 11834 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11835 | keep_in_target = 1; |
11836 | break; | |
11837 | } | |
876fa593 JK |
11838 | } |
11839 | } | |
11840 | } | |
74960c60 VP |
11841 | } |
11842 | ||
20874c92 VP |
11843 | if (!keep_in_target) |
11844 | { | |
834c0d03 | 11845 | if (remove_breakpoint (old_loc)) |
20874c92 | 11846 | { |
4a64f543 MS |
11847 | /* This is just about all we can do. We could keep |
11848 | this location on the global list, and try to | |
11849 | remove it next time, but there's no particular | |
11850 | reason why we will succeed next time. | |
20874c92 | 11851 | |
4a64f543 MS |
11852 | Note that at this point, old_loc->owner is still |
11853 | valid, as delete_breakpoint frees the breakpoint | |
11854 | only after calling us. */ | |
3e43a32a MS |
11855 | printf_filtered (_("warning: Error removing " |
11856 | "breakpoint %d\n"), | |
876fa593 | 11857 | old_loc->owner->number); |
20874c92 VP |
11858 | } |
11859 | removed = 1; | |
11860 | } | |
0d381245 | 11861 | } |
74960c60 VP |
11862 | |
11863 | if (!found_object) | |
1c5cfe86 | 11864 | { |
fbea99ea | 11865 | if (removed && target_is_non_stop_p () |
1cf4d951 | 11866 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 11867 | { |
db82e815 PA |
11868 | /* This location was removed from the target. In |
11869 | non-stop mode, a race condition is possible where | |
11870 | we've removed a breakpoint, but stop events for that | |
11871 | breakpoint are already queued and will arrive later. | |
11872 | We apply an heuristic to be able to distinguish such | |
11873 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11874 | breakpoint location for a bit, and will retire it | |
11875 | after we see some number of events. The theory here | |
11876 | is that reporting of events should, "on the average", | |
11877 | be fair, so after a while we'll see events from all | |
11878 | threads that have anything of interest, and no longer | |
11879 | need to keep this breakpoint location around. We | |
11880 | don't hold locations forever so to reduce chances of | |
11881 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11882 | SIGTRAP. | |
11883 | ||
11884 | The heuristic failing can be disastrous on | |
11885 | decr_pc_after_break targets. | |
11886 | ||
11887 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11888 | if we fail to recognize a late breakpoint SIGTRAP, | |
11889 | because events_till_retirement has reached 0 too | |
11890 | soon, we'll fail to do the PC adjustment, and report | |
11891 | a random SIGTRAP to the user. When the user resumes | |
11892 | the inferior, it will most likely immediately crash | |
2dec564e | 11893 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11894 | corrupted, because of being resumed e.g., in the |
11895 | middle of a multi-byte instruction, or skipped a | |
11896 | one-byte instruction. This was actually seen happen | |
11897 | on native x86-linux, and should be less rare on | |
11898 | targets that do not support new thread events, like | |
11899 | remote, due to the heuristic depending on | |
11900 | thread_count. | |
11901 | ||
11902 | Mistaking a random SIGTRAP for a breakpoint trap | |
11903 | causes similar symptoms (PC adjustment applied when | |
11904 | it shouldn't), but then again, playing with SIGTRAPs | |
11905 | behind the debugger's back is asking for trouble. | |
11906 | ||
11907 | Since hardware watchpoint traps are always | |
11908 | distinguishable from other traps, so we don't need to | |
11909 | apply keep hardware watchpoint moribund locations | |
11910 | around. We simply always ignore hardware watchpoint | |
11911 | traps we can no longer explain. */ | |
11912 | ||
876fa593 JK |
11913 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
11914 | old_loc->owner = NULL; | |
20874c92 | 11915 | |
1123588c | 11916 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
11917 | } |
11918 | else | |
f431efe5 PA |
11919 | { |
11920 | old_loc->owner = NULL; | |
11921 | decref_bp_location (&old_loc); | |
11922 | } | |
20874c92 | 11923 | } |
74960c60 | 11924 | } |
1c5cfe86 | 11925 | |
348d480f PA |
11926 | /* Rescan breakpoints at the same address and section, marking the |
11927 | first one as "first" and any others as "duplicates". This is so | |
11928 | that the bpt instruction is only inserted once. If we have a | |
11929 | permanent breakpoint at the same place as BPT, make that one the | |
11930 | official one, and the rest as duplicates. Permanent breakpoints | |
11931 | are sorted first for the same address. | |
11932 | ||
11933 | Do the same for hardware watchpoints, but also considering the | |
11934 | watchpoint's type (regular/access/read) and length. */ | |
11935 | ||
11936 | bp_loc_first = NULL; | |
11937 | wp_loc_first = NULL; | |
11938 | awp_loc_first = NULL; | |
11939 | rwp_loc_first = NULL; | |
11940 | ALL_BP_LOCATIONS (loc, locp) | |
11941 | { | |
11942 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11943 | non-NULL. */ | |
348d480f | 11944 | struct bp_location **loc_first_p; |
d3fbdd86 | 11945 | b = loc->owner; |
348d480f | 11946 | |
6f380991 | 11947 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 11948 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
11949 | /* Don't detect duplicate for tracepoint locations because they are |
11950 | never duplicated. See the comments in field `duplicate' of | |
11951 | `struct bp_location'. */ | |
348d480f | 11952 | || is_tracepoint (b)) |
b775012e LM |
11953 | { |
11954 | /* Clear the condition modification flag. */ | |
11955 | loc->condition_changed = condition_unchanged; | |
11956 | continue; | |
11957 | } | |
348d480f | 11958 | |
348d480f PA |
11959 | if (b->type == bp_hardware_watchpoint) |
11960 | loc_first_p = &wp_loc_first; | |
11961 | else if (b->type == bp_read_watchpoint) | |
11962 | loc_first_p = &rwp_loc_first; | |
11963 | else if (b->type == bp_access_watchpoint) | |
11964 | loc_first_p = &awp_loc_first; | |
11965 | else | |
11966 | loc_first_p = &bp_loc_first; | |
11967 | ||
11968 | if (*loc_first_p == NULL | |
11969 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11970 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11971 | { | |
11972 | *loc_first_p = loc; | |
11973 | loc->duplicate = 0; | |
b775012e LM |
11974 | |
11975 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11976 | { | |
11977 | loc->needs_update = 1; | |
11978 | /* Clear the condition modification flag. */ | |
11979 | loc->condition_changed = condition_unchanged; | |
11980 | } | |
348d480f PA |
11981 | continue; |
11982 | } | |
11983 | ||
934709f0 PW |
11984 | |
11985 | /* This and the above ensure the invariant that the first location | |
11986 | is not duplicated, and is the inserted one. | |
11987 | All following are marked as duplicated, and are not inserted. */ | |
11988 | if (loc->inserted) | |
11989 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11990 | loc->duplicate = 1; |
11991 | ||
b775012e LM |
11992 | /* Clear the condition modification flag. */ |
11993 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
11994 | } |
11995 | ||
a25a5a45 | 11996 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 11997 | { |
04086b45 | 11998 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
11999 | insert_breakpoint_locations (); |
12000 | else | |
12001 | { | |
44702360 PA |
12002 | /* Even though the caller told us to not insert new |
12003 | locations, we may still need to update conditions on the | |
12004 | target's side of breakpoints that were already inserted | |
12005 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12006 | only update conditions for locations that are marked |
12007 | "needs_update". */ | |
12008 | update_inserted_breakpoint_locations (); | |
12009 | } | |
12010 | } | |
348d480f | 12011 | |
04086b45 | 12012 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 12013 | download_tracepoint_locations (); |
348d480f PA |
12014 | } |
12015 | ||
12016 | void | |
12017 | breakpoint_retire_moribund (void) | |
12018 | { | |
1123588c TT |
12019 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
12020 | { | |
12021 | struct bp_location *loc = moribund_locations[ix]; | |
12022 | if (--(loc->events_till_retirement) == 0) | |
12023 | { | |
12024 | decref_bp_location (&loc); | |
12025 | unordered_remove (moribund_locations, ix); | |
12026 | --ix; | |
12027 | } | |
12028 | } | |
348d480f PA |
12029 | } |
12030 | ||
12031 | static void | |
44702360 | 12032 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12033 | { |
348d480f | 12034 | |
a70b8144 | 12035 | try |
492d29ea PA |
12036 | { |
12037 | update_global_location_list (insert_mode); | |
12038 | } | |
230d2906 | 12039 | catch (const gdb_exception_error &e) |
492d29ea PA |
12040 | { |
12041 | } | |
348d480f PA |
12042 | } |
12043 | ||
12044 | /* Clear BKP from a BPS. */ | |
12045 | ||
12046 | static void | |
12047 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12048 | { | |
12049 | bpstat bs; | |
12050 | ||
12051 | for (bs = bps; bs; bs = bs->next) | |
12052 | if (bs->breakpoint_at == bpt) | |
12053 | { | |
12054 | bs->breakpoint_at = NULL; | |
12055 | bs->old_val = NULL; | |
12056 | /* bs->commands will be freed later. */ | |
12057 | } | |
12058 | } | |
12059 | ||
12060 | /* Callback for iterate_over_threads. */ | |
12061 | static int | |
12062 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12063 | { | |
9a3c8263 | 12064 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12065 | |
12066 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12067 | return 0; | |
12068 | } | |
12069 | ||
12070 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12071 | callbacks. */ | |
12072 | ||
12073 | static void | |
12074 | say_where (struct breakpoint *b) | |
12075 | { | |
12076 | struct value_print_options opts; | |
12077 | ||
12078 | get_user_print_options (&opts); | |
12079 | ||
12080 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12081 | single string. */ | |
12082 | if (b->loc == NULL) | |
12083 | { | |
f00aae0f KS |
12084 | /* For pending locations, the output differs slightly based |
12085 | on b->extra_string. If this is non-NULL, it contains either | |
12086 | a condition or dprintf arguments. */ | |
12087 | if (b->extra_string == NULL) | |
12088 | { | |
12089 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12090 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12091 | } |
12092 | else if (b->type == bp_dprintf) | |
12093 | { | |
12094 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12095 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12096 | b->extra_string); |
12097 | } | |
12098 | else | |
12099 | { | |
12100 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12101 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12102 | b->extra_string); |
12103 | } | |
348d480f PA |
12104 | } |
12105 | else | |
12106 | { | |
2f202fde | 12107 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12108 | { |
12109 | printf_filtered (" at "); | |
2636d81d PW |
12110 | fputs_styled (paddress (b->loc->gdbarch, b->loc->address), |
12111 | address_style.style (), | |
12112 | gdb_stdout); | |
348d480f | 12113 | } |
2f202fde | 12114 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12115 | { |
12116 | /* If there is a single location, we can print the location | |
12117 | more nicely. */ | |
12118 | if (b->loc->next == NULL) | |
0bb296cb TT |
12119 | { |
12120 | puts_filtered (": file "); | |
12121 | fputs_styled (symtab_to_filename_for_display (b->loc->symtab), | |
12122 | file_name_style.style (), | |
12123 | gdb_stdout); | |
12124 | printf_filtered (", line %d.", | |
12125 | b->loc->line_number); | |
12126 | } | |
f8eba3c6 TT |
12127 | else |
12128 | /* This is not ideal, but each location may have a | |
12129 | different file name, and this at least reflects the | |
12130 | real situation somewhat. */ | |
f00aae0f | 12131 | printf_filtered (": %s.", |
d28cd78a | 12132 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12133 | } |
348d480f PA |
12134 | |
12135 | if (b->loc->next) | |
12136 | { | |
12137 | struct bp_location *loc = b->loc; | |
12138 | int n = 0; | |
12139 | for (; loc; loc = loc->next) | |
12140 | ++n; | |
12141 | printf_filtered (" (%d locations)", n); | |
12142 | } | |
12143 | } | |
12144 | } | |
12145 | ||
5f486660 | 12146 | bp_location::~bp_location () |
348d480f | 12147 | { |
5f486660 | 12148 | xfree (function_name); |
348d480f PA |
12149 | } |
12150 | ||
c1fc2657 | 12151 | /* Destructor for the breakpoint base class. */ |
348d480f | 12152 | |
c1fc2657 | 12153 | breakpoint::~breakpoint () |
348d480f | 12154 | { |
c1fc2657 SM |
12155 | xfree (this->cond_string); |
12156 | xfree (this->extra_string); | |
12157 | xfree (this->filter); | |
348d480f PA |
12158 | } |
12159 | ||
2060206e PA |
12160 | static struct bp_location * |
12161 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12162 | { |
5f486660 | 12163 | return new bp_location (self); |
348d480f PA |
12164 | } |
12165 | ||
2060206e PA |
12166 | static void |
12167 | base_breakpoint_re_set (struct breakpoint *b) | |
12168 | { | |
12169 | /* Nothing to re-set. */ | |
12170 | } | |
12171 | ||
12172 | #define internal_error_pure_virtual_called() \ | |
12173 | gdb_assert_not_reached ("pure virtual function called") | |
12174 | ||
12175 | static int | |
12176 | base_breakpoint_insert_location (struct bp_location *bl) | |
12177 | { | |
12178 | internal_error_pure_virtual_called (); | |
12179 | } | |
12180 | ||
12181 | static int | |
73971819 PA |
12182 | base_breakpoint_remove_location (struct bp_location *bl, |
12183 | enum remove_bp_reason reason) | |
2060206e PA |
12184 | { |
12185 | internal_error_pure_virtual_called (); | |
12186 | } | |
12187 | ||
12188 | static int | |
12189 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12190 | const address_space *aspace, |
09ac7c10 TT |
12191 | CORE_ADDR bp_addr, |
12192 | const struct target_waitstatus *ws) | |
2060206e PA |
12193 | { |
12194 | internal_error_pure_virtual_called (); | |
12195 | } | |
12196 | ||
12197 | static void | |
12198 | base_breakpoint_check_status (bpstat bs) | |
12199 | { | |
12200 | /* Always stop. */ | |
12201 | } | |
12202 | ||
12203 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12204 | errors. */ | |
12205 | ||
12206 | static int | |
12207 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12208 | { | |
12209 | internal_error_pure_virtual_called (); | |
12210 | } | |
12211 | ||
12212 | /* A "resources_needed" breakpoint_ops method that just internal | |
12213 | errors. */ | |
12214 | ||
12215 | static int | |
12216 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12217 | { | |
12218 | internal_error_pure_virtual_called (); | |
12219 | } | |
12220 | ||
12221 | static enum print_stop_action | |
12222 | base_breakpoint_print_it (bpstat bs) | |
12223 | { | |
12224 | internal_error_pure_virtual_called (); | |
12225 | } | |
12226 | ||
12227 | static void | |
12228 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12229 | struct ui_out *uiout) | |
12230 | { | |
12231 | /* nothing */ | |
12232 | } | |
12233 | ||
12234 | static void | |
12235 | base_breakpoint_print_mention (struct breakpoint *b) | |
12236 | { | |
12237 | internal_error_pure_virtual_called (); | |
12238 | } | |
12239 | ||
12240 | static void | |
12241 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12242 | { | |
12243 | internal_error_pure_virtual_called (); | |
12244 | } | |
12245 | ||
983af33b | 12246 | static void |
f00aae0f KS |
12247 | base_breakpoint_create_sals_from_location |
12248 | (const struct event_location *location, | |
12249 | struct linespec_result *canonical, | |
12250 | enum bptype type_wanted) | |
983af33b SDJ |
12251 | { |
12252 | internal_error_pure_virtual_called (); | |
12253 | } | |
12254 | ||
12255 | static void | |
12256 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12257 | struct linespec_result *c, | |
e1e01040 PA |
12258 | gdb::unique_xmalloc_ptr<char> cond_string, |
12259 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12260 | enum bptype type_wanted, |
12261 | enum bpdisp disposition, | |
12262 | int thread, | |
12263 | int task, int ignore_count, | |
12264 | const struct breakpoint_ops *o, | |
12265 | int from_tty, int enabled, | |
44f238bb | 12266 | int internal, unsigned flags) |
983af33b SDJ |
12267 | { |
12268 | internal_error_pure_virtual_called (); | |
12269 | } | |
12270 | ||
6c5b2ebe | 12271 | static std::vector<symtab_and_line> |
f00aae0f KS |
12272 | base_breakpoint_decode_location (struct breakpoint *b, |
12273 | const struct event_location *location, | |
6c5b2ebe | 12274 | struct program_space *search_pspace) |
983af33b SDJ |
12275 | { |
12276 | internal_error_pure_virtual_called (); | |
12277 | } | |
12278 | ||
ab04a2af TT |
12279 | /* The default 'explains_signal' method. */ |
12280 | ||
47591c29 | 12281 | static int |
427cd150 | 12282 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12283 | { |
47591c29 | 12284 | return 1; |
ab04a2af TT |
12285 | } |
12286 | ||
9d6e6e84 HZ |
12287 | /* The default "after_condition_true" method. */ |
12288 | ||
12289 | static void | |
12290 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12291 | { | |
12292 | /* Nothing to do. */ | |
12293 | } | |
12294 | ||
ab04a2af | 12295 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12296 | { |
2060206e PA |
12297 | base_breakpoint_allocate_location, |
12298 | base_breakpoint_re_set, | |
12299 | base_breakpoint_insert_location, | |
12300 | base_breakpoint_remove_location, | |
12301 | base_breakpoint_breakpoint_hit, | |
12302 | base_breakpoint_check_status, | |
12303 | base_breakpoint_resources_needed, | |
12304 | base_breakpoint_works_in_software_mode, | |
12305 | base_breakpoint_print_it, | |
12306 | NULL, | |
12307 | base_breakpoint_print_one_detail, | |
12308 | base_breakpoint_print_mention, | |
983af33b | 12309 | base_breakpoint_print_recreate, |
5f700d83 | 12310 | base_breakpoint_create_sals_from_location, |
983af33b | 12311 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12312 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12313 | base_breakpoint_explains_signal, |
12314 | base_breakpoint_after_condition_true, | |
2060206e PA |
12315 | }; |
12316 | ||
12317 | /* Default breakpoint_ops methods. */ | |
12318 | ||
12319 | static void | |
348d480f PA |
12320 | bkpt_re_set (struct breakpoint *b) |
12321 | { | |
06edf0c0 | 12322 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12323 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12324 | { |
f00aae0f | 12325 | /* Anything without a location can't be re-set. */ |
348d480f | 12326 | delete_breakpoint (b); |
06edf0c0 | 12327 | return; |
348d480f | 12328 | } |
06edf0c0 PA |
12329 | |
12330 | breakpoint_re_set_default (b); | |
348d480f PA |
12331 | } |
12332 | ||
2060206e | 12333 | static int |
348d480f PA |
12334 | bkpt_insert_location (struct bp_location *bl) |
12335 | { | |
cd6c3b4f YQ |
12336 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12337 | ||
579c6ad9 | 12338 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12339 | bl->target_info.placed_address = addr; |
12340 | ||
348d480f | 12341 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12342 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12343 | else |
7c16b83e | 12344 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12345 | } |
12346 | ||
2060206e | 12347 | static int |
73971819 | 12348 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12349 | { |
12350 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12351 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12352 | else | |
73971819 | 12353 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12354 | } |
12355 | ||
2060206e | 12356 | static int |
348d480f | 12357 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 12358 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12359 | const struct target_waitstatus *ws) |
348d480f | 12360 | { |
09ac7c10 | 12361 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12362 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12363 | return 0; |
12364 | ||
348d480f PA |
12365 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12366 | aspace, bp_addr)) | |
12367 | return 0; | |
12368 | ||
12369 | if (overlay_debugging /* unmapped overlay section */ | |
12370 | && section_is_overlay (bl->section) | |
12371 | && !section_is_mapped (bl->section)) | |
12372 | return 0; | |
12373 | ||
12374 | return 1; | |
12375 | } | |
12376 | ||
cd1608cc PA |
12377 | static int |
12378 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12379 | const address_space *aspace, CORE_ADDR bp_addr, |
cd1608cc PA |
12380 | const struct target_waitstatus *ws) |
12381 | { | |
12382 | if (dprintf_style == dprintf_style_agent | |
12383 | && target_can_run_breakpoint_commands ()) | |
12384 | { | |
12385 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12386 | for this address it must be for a breakpoint that happens to | |
12387 | be set at the same address. */ | |
12388 | return 0; | |
12389 | } | |
12390 | ||
12391 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12392 | } | |
12393 | ||
2060206e | 12394 | static int |
348d480f PA |
12395 | bkpt_resources_needed (const struct bp_location *bl) |
12396 | { | |
12397 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12398 | ||
12399 | return 1; | |
12400 | } | |
12401 | ||
2060206e | 12402 | static enum print_stop_action |
348d480f PA |
12403 | bkpt_print_it (bpstat bs) |
12404 | { | |
348d480f PA |
12405 | struct breakpoint *b; |
12406 | const struct bp_location *bl; | |
001c8c33 | 12407 | int bp_temp; |
79a45e25 | 12408 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12409 | |
12410 | gdb_assert (bs->bp_location_at != NULL); | |
12411 | ||
12412 | bl = bs->bp_location_at; | |
12413 | b = bs->breakpoint_at; | |
12414 | ||
001c8c33 PA |
12415 | bp_temp = b->disposition == disp_del; |
12416 | if (bl->address != bl->requested_address) | |
12417 | breakpoint_adjustment_warning (bl->requested_address, | |
12418 | bl->address, | |
12419 | b->number, 1); | |
12420 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12421 | maybe_print_thread_hit_breakpoint (uiout); |
12422 | ||
001c8c33 | 12423 | if (bp_temp) |
112e8700 | 12424 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 12425 | else |
112e8700 SM |
12426 | uiout->text ("Breakpoint "); |
12427 | if (uiout->is_mi_like_p ()) | |
348d480f | 12428 | { |
112e8700 | 12429 | uiout->field_string ("reason", |
001c8c33 | 12430 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12431 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12432 | } |
112e8700 SM |
12433 | uiout->field_int ("bkptno", b->number); |
12434 | uiout->text (", "); | |
06edf0c0 | 12435 | |
001c8c33 | 12436 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12437 | } |
12438 | ||
2060206e | 12439 | static void |
06edf0c0 PA |
12440 | bkpt_print_mention (struct breakpoint *b) |
12441 | { | |
112e8700 | 12442 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12443 | return; |
12444 | ||
12445 | switch (b->type) | |
12446 | { | |
12447 | case bp_breakpoint: | |
12448 | case bp_gnu_ifunc_resolver: | |
12449 | if (b->disposition == disp_del) | |
12450 | printf_filtered (_("Temporary breakpoint")); | |
12451 | else | |
12452 | printf_filtered (_("Breakpoint")); | |
12453 | printf_filtered (_(" %d"), b->number); | |
12454 | if (b->type == bp_gnu_ifunc_resolver) | |
12455 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12456 | break; | |
12457 | case bp_hardware_breakpoint: | |
12458 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12459 | break; | |
e7e0cddf SS |
12460 | case bp_dprintf: |
12461 | printf_filtered (_("Dprintf %d"), b->number); | |
12462 | break; | |
06edf0c0 PA |
12463 | } |
12464 | ||
12465 | say_where (b); | |
12466 | } | |
12467 | ||
2060206e | 12468 | static void |
06edf0c0 PA |
12469 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12470 | { | |
12471 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12472 | fprintf_unfiltered (fp, "tbreak"); | |
12473 | else if (tp->type == bp_breakpoint) | |
12474 | fprintf_unfiltered (fp, "break"); | |
12475 | else if (tp->type == bp_hardware_breakpoint | |
12476 | && tp->disposition == disp_del) | |
12477 | fprintf_unfiltered (fp, "thbreak"); | |
12478 | else if (tp->type == bp_hardware_breakpoint) | |
12479 | fprintf_unfiltered (fp, "hbreak"); | |
12480 | else | |
12481 | internal_error (__FILE__, __LINE__, | |
12482 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12483 | ||
f00aae0f | 12484 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12485 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12486 | |
12487 | /* Print out extra_string if this breakpoint is pending. It might | |
12488 | contain, for example, conditions that were set by the user. */ | |
12489 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12490 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12491 | ||
dd11a36c | 12492 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12493 | } |
12494 | ||
983af33b | 12495 | static void |
f00aae0f KS |
12496 | bkpt_create_sals_from_location (const struct event_location *location, |
12497 | struct linespec_result *canonical, | |
12498 | enum bptype type_wanted) | |
983af33b | 12499 | { |
f00aae0f | 12500 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12501 | } |
12502 | ||
12503 | static void | |
12504 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12505 | struct linespec_result *canonical, | |
e1e01040 PA |
12506 | gdb::unique_xmalloc_ptr<char> cond_string, |
12507 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12508 | enum bptype type_wanted, |
12509 | enum bpdisp disposition, | |
12510 | int thread, | |
12511 | int task, int ignore_count, | |
12512 | const struct breakpoint_ops *ops, | |
12513 | int from_tty, int enabled, | |
44f238bb | 12514 | int internal, unsigned flags) |
983af33b | 12515 | { |
023fa29b | 12516 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12517 | std::move (cond_string), |
12518 | std::move (extra_string), | |
e7e0cddf | 12519 | type_wanted, |
983af33b SDJ |
12520 | disposition, thread, task, |
12521 | ignore_count, ops, from_tty, | |
44f238bb | 12522 | enabled, internal, flags); |
983af33b SDJ |
12523 | } |
12524 | ||
6c5b2ebe | 12525 | static std::vector<symtab_and_line> |
f00aae0f KS |
12526 | bkpt_decode_location (struct breakpoint *b, |
12527 | const struct event_location *location, | |
6c5b2ebe | 12528 | struct program_space *search_pspace) |
983af33b | 12529 | { |
6c5b2ebe | 12530 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12531 | } |
12532 | ||
06edf0c0 PA |
12533 | /* Virtual table for internal breakpoints. */ |
12534 | ||
12535 | static void | |
12536 | internal_bkpt_re_set (struct breakpoint *b) | |
12537 | { | |
12538 | switch (b->type) | |
12539 | { | |
12540 | /* Delete overlay event and longjmp master breakpoints; they | |
12541 | will be reset later by breakpoint_re_set. */ | |
12542 | case bp_overlay_event: | |
12543 | case bp_longjmp_master: | |
12544 | case bp_std_terminate_master: | |
12545 | case bp_exception_master: | |
12546 | delete_breakpoint (b); | |
12547 | break; | |
12548 | ||
12549 | /* This breakpoint is special, it's set up when the inferior | |
12550 | starts and we really don't want to touch it. */ | |
12551 | case bp_shlib_event: | |
12552 | ||
12553 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12554 | it is set up, we do not want to touch it. */ | |
12555 | case bp_thread_event: | |
12556 | break; | |
12557 | } | |
12558 | } | |
12559 | ||
12560 | static void | |
12561 | internal_bkpt_check_status (bpstat bs) | |
12562 | { | |
a9b3a50f PA |
12563 | if (bs->breakpoint_at->type == bp_shlib_event) |
12564 | { | |
12565 | /* If requested, stop when the dynamic linker notifies GDB of | |
12566 | events. This allows the user to get control and place | |
12567 | breakpoints in initializer routines for dynamically loaded | |
12568 | objects (among other things). */ | |
12569 | bs->stop = stop_on_solib_events; | |
12570 | bs->print = stop_on_solib_events; | |
12571 | } | |
12572 | else | |
12573 | bs->stop = 0; | |
06edf0c0 PA |
12574 | } |
12575 | ||
12576 | static enum print_stop_action | |
12577 | internal_bkpt_print_it (bpstat bs) | |
12578 | { | |
06edf0c0 | 12579 | struct breakpoint *b; |
06edf0c0 | 12580 | |
06edf0c0 PA |
12581 | b = bs->breakpoint_at; |
12582 | ||
06edf0c0 PA |
12583 | switch (b->type) |
12584 | { | |
348d480f PA |
12585 | case bp_shlib_event: |
12586 | /* Did we stop because the user set the stop_on_solib_events | |
12587 | variable? (If so, we report this as a generic, "Stopped due | |
12588 | to shlib event" message.) */ | |
edcc5120 | 12589 | print_solib_event (0); |
348d480f PA |
12590 | break; |
12591 | ||
12592 | case bp_thread_event: | |
12593 | /* Not sure how we will get here. | |
12594 | GDB should not stop for these breakpoints. */ | |
12595 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12596 | break; |
12597 | ||
12598 | case bp_overlay_event: | |
12599 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12600 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12601 | break; |
12602 | ||
12603 | case bp_longjmp_master: | |
12604 | /* These should never be enabled. */ | |
12605 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12606 | break; |
12607 | ||
12608 | case bp_std_terminate_master: | |
12609 | /* These should never be enabled. */ | |
12610 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12611 | "gdb should not stop!\n")); | |
348d480f PA |
12612 | break; |
12613 | ||
12614 | case bp_exception_master: | |
12615 | /* These should never be enabled. */ | |
12616 | printf_filtered (_("Exception Master Breakpoint: " | |
12617 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12618 | break; |
12619 | } | |
12620 | ||
001c8c33 | 12621 | return PRINT_NOTHING; |
06edf0c0 PA |
12622 | } |
12623 | ||
12624 | static void | |
12625 | internal_bkpt_print_mention (struct breakpoint *b) | |
12626 | { | |
12627 | /* Nothing to mention. These breakpoints are internal. */ | |
12628 | } | |
12629 | ||
06edf0c0 PA |
12630 | /* Virtual table for momentary breakpoints */ |
12631 | ||
12632 | static void | |
12633 | momentary_bkpt_re_set (struct breakpoint *b) | |
12634 | { | |
12635 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12636 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12637 | Otherwise these should have been blown away via the cleanup chain |
12638 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12639 | } | |
12640 | ||
12641 | static void | |
12642 | momentary_bkpt_check_status (bpstat bs) | |
12643 | { | |
12644 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12645 | } | |
12646 | ||
12647 | static enum print_stop_action | |
12648 | momentary_bkpt_print_it (bpstat bs) | |
12649 | { | |
001c8c33 | 12650 | return PRINT_UNKNOWN; |
348d480f PA |
12651 | } |
12652 | ||
06edf0c0 PA |
12653 | static void |
12654 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12655 | { |
06edf0c0 | 12656 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12657 | } |
12658 | ||
e2e4d78b JK |
12659 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12660 | ||
12661 | It gets cleared already on the removal of the first one of such placed | |
12662 | breakpoints. This is OK as they get all removed altogether. */ | |
12663 | ||
c1fc2657 | 12664 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12665 | { |
c1fc2657 | 12666 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12667 | |
c1fc2657 | 12668 | if (tp != NULL) |
e2e4d78b | 12669 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12670 | } |
12671 | ||
55aa24fb SDJ |
12672 | /* Specific methods for probe breakpoints. */ |
12673 | ||
12674 | static int | |
12675 | bkpt_probe_insert_location (struct bp_location *bl) | |
12676 | { | |
12677 | int v = bkpt_insert_location (bl); | |
12678 | ||
12679 | if (v == 0) | |
12680 | { | |
12681 | /* The insertion was successful, now let's set the probe's semaphore | |
12682 | if needed. */ | |
935676c9 | 12683 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12684 | } |
12685 | ||
12686 | return v; | |
12687 | } | |
12688 | ||
12689 | static int | |
73971819 PA |
12690 | bkpt_probe_remove_location (struct bp_location *bl, |
12691 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
12692 | { |
12693 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 12694 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 12695 | |
73971819 | 12696 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
12697 | } |
12698 | ||
12699 | static void | |
f00aae0f | 12700 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12701 | struct linespec_result *canonical, |
f00aae0f | 12702 | enum bptype type_wanted) |
55aa24fb SDJ |
12703 | { |
12704 | struct linespec_sals lsal; | |
12705 | ||
c2f4122d | 12706 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
12707 | lsal.canonical |
12708 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12709 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
12710 | } |
12711 | ||
6c5b2ebe | 12712 | static std::vector<symtab_and_line> |
f00aae0f KS |
12713 | bkpt_probe_decode_location (struct breakpoint *b, |
12714 | const struct event_location *location, | |
6c5b2ebe | 12715 | struct program_space *search_pspace) |
55aa24fb | 12716 | { |
6c5b2ebe PA |
12717 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
12718 | if (sals.empty ()) | |
55aa24fb | 12719 | error (_("probe not found")); |
6c5b2ebe | 12720 | return sals; |
55aa24fb SDJ |
12721 | } |
12722 | ||
348d480f | 12723 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12724 | |
348d480f PA |
12725 | static void |
12726 | tracepoint_re_set (struct breakpoint *b) | |
12727 | { | |
12728 | breakpoint_re_set_default (b); | |
12729 | } | |
876fa593 | 12730 | |
348d480f PA |
12731 | static int |
12732 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12733 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12734 | const struct target_waitstatus *ws) |
348d480f PA |
12735 | { |
12736 | /* By definition, the inferior does not report stops at | |
12737 | tracepoints. */ | |
12738 | return 0; | |
74960c60 VP |
12739 | } |
12740 | ||
12741 | static void | |
348d480f PA |
12742 | tracepoint_print_one_detail (const struct breakpoint *self, |
12743 | struct ui_out *uiout) | |
74960c60 | 12744 | { |
d9b3f62e | 12745 | struct tracepoint *tp = (struct tracepoint *) self; |
5d9310c4 | 12746 | if (!tp->static_trace_marker_id.empty ()) |
348d480f PA |
12747 | { |
12748 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12749 | |
112e8700 SM |
12750 | uiout->text ("\tmarker id is "); |
12751 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 12752 | tp->static_trace_marker_id); |
112e8700 | 12753 | uiout->text ("\n"); |
348d480f | 12754 | } |
0d381245 VP |
12755 | } |
12756 | ||
a474d7c2 | 12757 | static void |
348d480f | 12758 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12759 | { |
112e8700 | 12760 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12761 | return; |
cc59ec59 | 12762 | |
348d480f PA |
12763 | switch (b->type) |
12764 | { | |
12765 | case bp_tracepoint: | |
12766 | printf_filtered (_("Tracepoint")); | |
12767 | printf_filtered (_(" %d"), b->number); | |
12768 | break; | |
12769 | case bp_fast_tracepoint: | |
12770 | printf_filtered (_("Fast tracepoint")); | |
12771 | printf_filtered (_(" %d"), b->number); | |
12772 | break; | |
12773 | case bp_static_tracepoint: | |
12774 | printf_filtered (_("Static tracepoint")); | |
12775 | printf_filtered (_(" %d"), b->number); | |
12776 | break; | |
12777 | default: | |
12778 | internal_error (__FILE__, __LINE__, | |
12779 | _("unhandled tracepoint type %d"), (int) b->type); | |
12780 | } | |
12781 | ||
12782 | say_where (b); | |
a474d7c2 PA |
12783 | } |
12784 | ||
348d480f | 12785 | static void |
d9b3f62e | 12786 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12787 | { |
d9b3f62e PA |
12788 | struct tracepoint *tp = (struct tracepoint *) self; |
12789 | ||
12790 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12791 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 12792 | else if (self->type == bp_static_tracepoint) |
348d480f | 12793 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12794 | else if (self->type == bp_tracepoint) |
348d480f PA |
12795 | fprintf_unfiltered (fp, "trace"); |
12796 | else | |
12797 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12798 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12799 | |
f00aae0f | 12800 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12801 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
12802 | print_recreate_thread (self, fp); |
12803 | ||
12804 | if (tp->pass_count) | |
12805 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12806 | } |
12807 | ||
983af33b | 12808 | static void |
f00aae0f KS |
12809 | tracepoint_create_sals_from_location (const struct event_location *location, |
12810 | struct linespec_result *canonical, | |
12811 | enum bptype type_wanted) | |
983af33b | 12812 | { |
f00aae0f | 12813 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12814 | } |
12815 | ||
12816 | static void | |
12817 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12818 | struct linespec_result *canonical, | |
e1e01040 PA |
12819 | gdb::unique_xmalloc_ptr<char> cond_string, |
12820 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12821 | enum bptype type_wanted, |
12822 | enum bpdisp disposition, | |
12823 | int thread, | |
12824 | int task, int ignore_count, | |
12825 | const struct breakpoint_ops *ops, | |
12826 | int from_tty, int enabled, | |
44f238bb | 12827 | int internal, unsigned flags) |
983af33b | 12828 | { |
023fa29b | 12829 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12830 | std::move (cond_string), |
12831 | std::move (extra_string), | |
e7e0cddf | 12832 | type_wanted, |
983af33b SDJ |
12833 | disposition, thread, task, |
12834 | ignore_count, ops, from_tty, | |
44f238bb | 12835 | enabled, internal, flags); |
983af33b SDJ |
12836 | } |
12837 | ||
6c5b2ebe | 12838 | static std::vector<symtab_and_line> |
f00aae0f KS |
12839 | tracepoint_decode_location (struct breakpoint *b, |
12840 | const struct event_location *location, | |
6c5b2ebe | 12841 | struct program_space *search_pspace) |
983af33b | 12842 | { |
6c5b2ebe | 12843 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12844 | } |
12845 | ||
2060206e | 12846 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12847 | |
55aa24fb SDJ |
12848 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
12849 | static probe. */ | |
12850 | ||
12851 | static void | |
f00aae0f KS |
12852 | tracepoint_probe_create_sals_from_location |
12853 | (const struct event_location *location, | |
12854 | struct linespec_result *canonical, | |
12855 | enum bptype type_wanted) | |
55aa24fb SDJ |
12856 | { |
12857 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 12858 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
12859 | } |
12860 | ||
6c5b2ebe | 12861 | static std::vector<symtab_and_line> |
f00aae0f KS |
12862 | tracepoint_probe_decode_location (struct breakpoint *b, |
12863 | const struct event_location *location, | |
6c5b2ebe | 12864 | struct program_space *search_pspace) |
55aa24fb SDJ |
12865 | { |
12866 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 12867 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
12868 | } |
12869 | ||
12870 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
12871 | ||
5c2b4418 HZ |
12872 | /* Dprintf breakpoint_ops methods. */ |
12873 | ||
12874 | static void | |
12875 | dprintf_re_set (struct breakpoint *b) | |
12876 | { | |
12877 | breakpoint_re_set_default (b); | |
12878 | ||
f00aae0f KS |
12879 | /* extra_string should never be non-NULL for dprintf. */ |
12880 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
12881 | |
12882 | /* 1 - connect to target 1, that can run breakpoint commands. | |
12883 | 2 - create a dprintf, which resolves fine. | |
12884 | 3 - disconnect from target 1 | |
12885 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
12886 | ||
12887 | After steps #3/#4, you'll want the dprintf command list to | |
12888 | be updated, because target 1 and 2 may well return different | |
12889 | answers for target_can_run_breakpoint_commands(). | |
12890 | Given absence of finer grained resetting, we get to do | |
12891 | it all the time. */ | |
12892 | if (b->extra_string != NULL) | |
12893 | update_dprintf_command_list (b); | |
12894 | } | |
12895 | ||
2d9442cc HZ |
12896 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
12897 | ||
12898 | static void | |
12899 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
12900 | { | |
f00aae0f | 12901 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 12902 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
12903 | tp->extra_string); |
12904 | print_recreate_thread (tp, fp); | |
12905 | } | |
12906 | ||
9d6e6e84 HZ |
12907 | /* Implement the "after_condition_true" breakpoint_ops method for |
12908 | dprintf. | |
12909 | ||
12910 | dprintf's are implemented with regular commands in their command | |
12911 | list, but we run the commands here instead of before presenting the | |
12912 | stop to the user, as dprintf's don't actually cause a stop. This | |
12913 | also makes it so that the commands of multiple dprintfs at the same | |
12914 | address are all handled. */ | |
12915 | ||
12916 | static void | |
12917 | dprintf_after_condition_true (struct bpstats *bs) | |
12918 | { | |
04afa70c | 12919 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
12920 | struct bpstats *tmp_bs_p = &tmp_bs; |
12921 | ||
12922 | /* dprintf's never cause a stop. This wasn't set in the | |
12923 | check_status hook instead because that would make the dprintf's | |
12924 | condition not be evaluated. */ | |
12925 | bs->stop = 0; | |
12926 | ||
12927 | /* Run the command list here. Take ownership of it instead of | |
12928 | copying. We never want these commands to run later in | |
12929 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
12930 | be set at same address as this dprintf, or even if running the | |
12931 | commands here throws. */ | |
12932 | tmp_bs.commands = bs->commands; | |
12933 | bs->commands = NULL; | |
9d6e6e84 HZ |
12934 | |
12935 | bpstat_do_actions_1 (&tmp_bs_p); | |
12936 | ||
12937 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
12938 | bpstat_do_actions_1 may return early without processing the whole | |
12939 | list. */ | |
9d6e6e84 HZ |
12940 | } |
12941 | ||
983af33b SDJ |
12942 | /* The breakpoint_ops structure to be used on static tracepoints with |
12943 | markers (`-m'). */ | |
12944 | ||
12945 | static void | |
f00aae0f | 12946 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12947 | struct linespec_result *canonical, |
f00aae0f | 12948 | enum bptype type_wanted) |
983af33b SDJ |
12949 | { |
12950 | struct linespec_sals lsal; | |
f00aae0f | 12951 | const char *arg_start, *arg; |
983af33b | 12952 | |
a20714ff | 12953 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 12954 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 12955 | |
f2fc3015 TT |
12956 | std::string str (arg_start, arg - arg_start); |
12957 | const char *ptr = str.c_str (); | |
a20714ff PA |
12958 | canonical->location |
12959 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 12960 | |
8e9e35b1 TT |
12961 | lsal.canonical |
12962 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12963 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
12964 | } |
12965 | ||
12966 | static void | |
12967 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12968 | struct linespec_result *canonical, | |
e1e01040 PA |
12969 | gdb::unique_xmalloc_ptr<char> cond_string, |
12970 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12971 | enum bptype type_wanted, |
12972 | enum bpdisp disposition, | |
12973 | int thread, | |
12974 | int task, int ignore_count, | |
12975 | const struct breakpoint_ops *ops, | |
12976 | int from_tty, int enabled, | |
44f238bb | 12977 | int internal, unsigned flags) |
983af33b | 12978 | { |
6c5b2ebe | 12979 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
12980 | |
12981 | /* If the user is creating a static tracepoint by marker id | |
12982 | (strace -m MARKER_ID), then store the sals index, so that | |
12983 | breakpoint_re_set can try to match up which of the newly | |
12984 | found markers corresponds to this one, and, don't try to | |
12985 | expand multiple locations for each sal, given than SALS | |
12986 | already should contain all sals for MARKER_ID. */ | |
12987 | ||
6c5b2ebe | 12988 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 12989 | { |
6c5b2ebe PA |
12990 | event_location_up location |
12991 | = copy_event_location (canonical->location.get ()); | |
983af33b | 12992 | |
b270e6f9 | 12993 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 12994 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 12995 | std::move (location), NULL, |
e1e01040 PA |
12996 | std::move (cond_string), |
12997 | std::move (extra_string), | |
e7e0cddf | 12998 | type_wanted, disposition, |
983af33b | 12999 | thread, task, ignore_count, ops, |
44f238bb | 13000 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13001 | canonical->special_display); |
13002 | /* Given that its possible to have multiple markers with | |
13003 | the same string id, if the user is creating a static | |
13004 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13005 | store the sals index, so that breakpoint_re_set can | |
13006 | try to match up which of the newly found markers | |
13007 | corresponds to this one */ | |
13008 | tp->static_trace_marker_id_idx = i; | |
13009 | ||
b270e6f9 | 13010 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13011 | } |
13012 | } | |
13013 | ||
6c5b2ebe | 13014 | static std::vector<symtab_and_line> |
f00aae0f KS |
13015 | strace_marker_decode_location (struct breakpoint *b, |
13016 | const struct event_location *location, | |
6c5b2ebe | 13017 | struct program_space *search_pspace) |
983af33b SDJ |
13018 | { |
13019 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 13020 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 13021 | |
6c5b2ebe PA |
13022 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13023 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13024 | { |
6c5b2ebe PA |
13025 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13026 | sals.resize (1); | |
13027 | return sals; | |
983af33b SDJ |
13028 | } |
13029 | else | |
5d9310c4 | 13030 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
983af33b SDJ |
13031 | } |
13032 | ||
13033 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13034 | ||
13035 | static int | |
13036 | strace_marker_p (struct breakpoint *b) | |
13037 | { | |
13038 | return b->ops == &strace_marker_breakpoint_ops; | |
13039 | } | |
13040 | ||
53a5351d | 13041 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13042 | structures. */ |
c906108c SS |
13043 | |
13044 | void | |
fba45db2 | 13045 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13046 | { |
52f0bd74 | 13047 | struct breakpoint *b; |
c906108c | 13048 | |
8a3fe4f8 | 13049 | gdb_assert (bpt != NULL); |
c906108c | 13050 | |
4a64f543 MS |
13051 | /* Has this bp already been deleted? This can happen because |
13052 | multiple lists can hold pointers to bp's. bpstat lists are | |
13053 | especial culprits. | |
13054 | ||
13055 | One example of this happening is a watchpoint's scope bp. When | |
13056 | the scope bp triggers, we notice that the watchpoint is out of | |
13057 | scope, and delete it. We also delete its scope bp. But the | |
13058 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13059 | That bpstat is then checked for auto-deleting bp's, which are | |
13060 | deleted. | |
13061 | ||
13062 | A real solution to this problem might involve reference counts in | |
13063 | bp's, and/or giving them pointers back to their referencing | |
13064 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13065 | storage when no more references were extent. A cheaper bandaid | |
13066 | was chosen. */ | |
c906108c SS |
13067 | if (bpt->type == bp_none) |
13068 | return; | |
13069 | ||
4a64f543 MS |
13070 | /* At least avoid this stale reference until the reference counting |
13071 | of breakpoints gets resolved. */ | |
d0fb5eae | 13072 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13073 | { |
d0fb5eae | 13074 | struct breakpoint *related; |
3a5c3e22 | 13075 | struct watchpoint *w; |
d0fb5eae JK |
13076 | |
13077 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13078 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13079 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13080 | w = (struct watchpoint *) bpt; |
13081 | else | |
13082 | w = NULL; | |
13083 | if (w != NULL) | |
13084 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13085 | |
13086 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13087 | for (related = bpt; related->related_breakpoint != bpt; | |
13088 | related = related->related_breakpoint); | |
13089 | related->related_breakpoint = bpt->related_breakpoint; | |
13090 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13091 | } |
13092 | ||
a9634178 TJB |
13093 | /* watch_command_1 creates a watchpoint but only sets its number if |
13094 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13095 | a problem in that process, we'll be asked to delete the half-created | |
13096 | watchpoint. In that case, don't announce the deletion. */ | |
13097 | if (bpt->number) | |
76727919 | 13098 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 13099 | |
c906108c SS |
13100 | if (breakpoint_chain == bpt) |
13101 | breakpoint_chain = bpt->next; | |
13102 | ||
c906108c SS |
13103 | ALL_BREAKPOINTS (b) |
13104 | if (b->next == bpt) | |
c5aa993b JM |
13105 | { |
13106 | b->next = bpt->next; | |
13107 | break; | |
13108 | } | |
c906108c | 13109 | |
f431efe5 PA |
13110 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13111 | been freed. */ | |
13112 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13113 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13114 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13115 | commands are associated with the bpstat; if we remove it here, | |
13116 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13117 | event-top.c won't do anything, and temporary breakpoints with | |
13118 | commands won't work. */ | |
13119 | ||
13120 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13121 | ||
4a64f543 MS |
13122 | /* Now that breakpoint is removed from breakpoint list, update the |
13123 | global location list. This will remove locations that used to | |
13124 | belong to this breakpoint. Do this before freeing the breakpoint | |
13125 | itself, since remove_breakpoint looks at location's owner. It | |
13126 | might be better design to have location completely | |
13127 | self-contained, but it's not the case now. */ | |
44702360 | 13128 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13129 | |
4a64f543 MS |
13130 | /* On the chance that someone will soon try again to delete this |
13131 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13132 | bpt->type = bp_none; |
4d01a485 | 13133 | delete bpt; |
c906108c SS |
13134 | } |
13135 | ||
51be5b68 PA |
13136 | /* Iterator function to call a user-provided callback function once |
13137 | for each of B and its related breakpoints. */ | |
13138 | ||
13139 | static void | |
13140 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13141 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13142 | { |
13143 | struct breakpoint *related; | |
13144 | ||
13145 | related = b; | |
13146 | do | |
13147 | { | |
13148 | struct breakpoint *next; | |
13149 | ||
13150 | /* FUNCTION may delete RELATED. */ | |
13151 | next = related->related_breakpoint; | |
13152 | ||
13153 | if (next == related) | |
13154 | { | |
13155 | /* RELATED is the last ring entry. */ | |
48649e1b | 13156 | function (related); |
51be5b68 PA |
13157 | |
13158 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13159 | B. There's nothing left to do anyway, so just break | |
13160 | out. */ | |
13161 | break; | |
13162 | } | |
13163 | else | |
48649e1b | 13164 | function (related); |
51be5b68 PA |
13165 | |
13166 | related = next; | |
13167 | } | |
13168 | while (related != b); | |
13169 | } | |
95a42b64 | 13170 | |
4495129a | 13171 | static void |
981a3fb3 | 13172 | delete_command (const char *arg, int from_tty) |
c906108c | 13173 | { |
35df4500 | 13174 | struct breakpoint *b, *b_tmp; |
c906108c | 13175 | |
ea9365bb TT |
13176 | dont_repeat (); |
13177 | ||
c906108c SS |
13178 | if (arg == 0) |
13179 | { | |
13180 | int breaks_to_delete = 0; | |
13181 | ||
46c6471b PA |
13182 | /* Delete all breakpoints if no argument. Do not delete |
13183 | internal breakpoints, these have to be deleted with an | |
13184 | explicit breakpoint number argument. */ | |
c5aa993b | 13185 | ALL_BREAKPOINTS (b) |
46c6471b | 13186 | if (user_breakpoint_p (b)) |
973d738b DJ |
13187 | { |
13188 | breaks_to_delete = 1; | |
13189 | break; | |
13190 | } | |
c906108c SS |
13191 | |
13192 | /* Ask user only if there are some breakpoints to delete. */ | |
13193 | if (!from_tty | |
e2e0b3e5 | 13194 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13195 | { |
35df4500 | 13196 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13197 | if (user_breakpoint_p (b)) |
c5aa993b | 13198 | delete_breakpoint (b); |
c906108c SS |
13199 | } |
13200 | } | |
13201 | else | |
48649e1b | 13202 | map_breakpoint_numbers |
b926417a | 13203 | (arg, [&] (breakpoint *br) |
48649e1b | 13204 | { |
b926417a | 13205 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 13206 | }); |
c906108c SS |
13207 | } |
13208 | ||
c2f4122d PA |
13209 | /* Return true if all locations of B bound to PSPACE are pending. If |
13210 | PSPACE is NULL, all locations of all program spaces are | |
13211 | considered. */ | |
13212 | ||
0d381245 | 13213 | static int |
c2f4122d | 13214 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13215 | { |
c2f4122d PA |
13216 | struct bp_location *loc; |
13217 | ||
13218 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13219 | if ((pspace == NULL | |
13220 | || loc->pspace == pspace) | |
13221 | && !loc->shlib_disabled | |
8645ff69 | 13222 | && !loc->pspace->executing_startup) |
0d381245 VP |
13223 | return 0; |
13224 | return 1; | |
fe3f5fa8 VP |
13225 | } |
13226 | ||
776592bf DE |
13227 | /* Subroutine of update_breakpoint_locations to simplify it. |
13228 | Return non-zero if multiple fns in list LOC have the same name. | |
13229 | Null names are ignored. */ | |
13230 | ||
13231 | static int | |
13232 | ambiguous_names_p (struct bp_location *loc) | |
13233 | { | |
13234 | struct bp_location *l; | |
459a2e4c TT |
13235 | htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
13236 | xcalloc, xfree); | |
776592bf DE |
13237 | |
13238 | for (l = loc; l != NULL; l = l->next) | |
13239 | { | |
13240 | const char **slot; | |
13241 | const char *name = l->function_name; | |
13242 | ||
13243 | /* Allow for some names to be NULL, ignore them. */ | |
13244 | if (name == NULL) | |
13245 | continue; | |
13246 | ||
13247 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13248 | INSERT); | |
4a64f543 MS |
13249 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13250 | returns NULL. */ | |
776592bf DE |
13251 | if (*slot != NULL) |
13252 | { | |
13253 | htab_delete (htab); | |
13254 | return 1; | |
13255 | } | |
13256 | *slot = name; | |
13257 | } | |
13258 | ||
13259 | htab_delete (htab); | |
13260 | return 0; | |
13261 | } | |
13262 | ||
0fb4aa4b PA |
13263 | /* When symbols change, it probably means the sources changed as well, |
13264 | and it might mean the static tracepoint markers are no longer at | |
13265 | the same address or line numbers they used to be at last we | |
13266 | checked. Losing your static tracepoints whenever you rebuild is | |
13267 | undesirable. This function tries to resync/rematch gdb static | |
13268 | tracepoints with the markers on the target, for static tracepoints | |
13269 | that have not been set by marker id. Static tracepoint that have | |
13270 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13271 | The heuristic is: | |
13272 | ||
13273 | 1) For a tracepoint set at a specific address, look for a marker at | |
13274 | the old PC. If one is found there, assume to be the same marker. | |
13275 | If the name / string id of the marker found is different from the | |
13276 | previous known name, assume that means the user renamed the marker | |
13277 | in the sources, and output a warning. | |
13278 | ||
13279 | 2) For a tracepoint set at a given line number, look for a marker | |
13280 | at the new address of the old line number. If one is found there, | |
13281 | assume to be the same marker. If the name / string id of the | |
13282 | marker found is different from the previous known name, assume that | |
13283 | means the user renamed the marker in the sources, and output a | |
13284 | warning. | |
13285 | ||
13286 | 3) If a marker is no longer found at the same address or line, it | |
13287 | may mean the marker no longer exists. But it may also just mean | |
13288 | the code changed a bit. Maybe the user added a few lines of code | |
13289 | that made the marker move up or down (in line number terms). Ask | |
13290 | the target for info about the marker with the string id as we knew | |
13291 | it. If found, update line number and address in the matching | |
13292 | static tracepoint. This will get confused if there's more than one | |
13293 | marker with the same ID (possible in UST, although unadvised | |
13294 | precisely because it confuses tools). */ | |
13295 | ||
13296 | static struct symtab_and_line | |
13297 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13298 | { | |
d9b3f62e | 13299 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13300 | struct static_tracepoint_marker marker; |
13301 | CORE_ADDR pc; | |
0fb4aa4b PA |
13302 | |
13303 | pc = sal.pc; | |
13304 | if (sal.line) | |
13305 | find_line_pc (sal.symtab, sal.line, &pc); | |
13306 | ||
13307 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13308 | { | |
5d9310c4 | 13309 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 13310 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
13311 | b->number, tp->static_trace_marker_id.c_str (), |
13312 | marker.str_id.c_str ()); | |
0fb4aa4b | 13313 | |
5d9310c4 | 13314 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
13315 | |
13316 | return sal; | |
13317 | } | |
13318 | ||
13319 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13320 | by string ID. */ | |
13321 | if (!sal.explicit_pc | |
13322 | && sal.line != 0 | |
13323 | && sal.symtab != NULL | |
5d9310c4 | 13324 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 13325 | { |
5d9310c4 SM |
13326 | std::vector<static_tracepoint_marker> markers |
13327 | = target_static_tracepoint_markers_by_strid | |
13328 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 13329 | |
5d9310c4 | 13330 | if (!markers.empty ()) |
0fb4aa4b | 13331 | { |
0fb4aa4b | 13332 | struct symbol *sym; |
80e1d417 | 13333 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13334 | struct ui_out *uiout = current_uiout; |
67994074 | 13335 | struct explicit_location explicit_loc; |
0fb4aa4b | 13336 | |
5d9310c4 | 13337 | tpmarker = &markers[0]; |
0fb4aa4b | 13338 | |
5d9310c4 | 13339 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
13340 | |
13341 | warning (_("marker for static tracepoint %d (%s) not " | |
13342 | "found at previous line number"), | |
5d9310c4 | 13343 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 13344 | |
51abb421 | 13345 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13346 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13347 | uiout->text ("Now in "); |
0fb4aa4b PA |
13348 | if (sym) |
13349 | { | |
cbe56571 TT |
13350 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym), |
13351 | ui_out_style_kind::FUNCTION); | |
112e8700 | 13352 | uiout->text (" at "); |
0fb4aa4b | 13353 | } |
112e8700 | 13354 | uiout->field_string ("file", |
cbe56571 TT |
13355 | symtab_to_filename_for_display (sal2.symtab), |
13356 | ui_out_style_kind::FILE); | |
112e8700 | 13357 | uiout->text (":"); |
0fb4aa4b | 13358 | |
112e8700 | 13359 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13360 | { |
0b0865da | 13361 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13362 | |
112e8700 | 13363 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13364 | } |
13365 | ||
112e8700 SM |
13366 | uiout->field_int ("line", sal2.line); |
13367 | uiout->text ("\n"); | |
0fb4aa4b | 13368 | |
80e1d417 | 13369 | b->loc->line_number = sal2.line; |
2f202fde | 13370 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13371 | |
d28cd78a | 13372 | b->location.reset (NULL); |
67994074 KS |
13373 | initialize_explicit_location (&explicit_loc); |
13374 | explicit_loc.source_filename | |
00e52e53 | 13375 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13376 | explicit_loc.line_offset.offset = b->loc->line_number; |
13377 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13378 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13379 | |
13380 | /* Might be nice to check if function changed, and warn if | |
13381 | so. */ | |
0fb4aa4b PA |
13382 | } |
13383 | } | |
13384 | return sal; | |
13385 | } | |
13386 | ||
8d3788bd VP |
13387 | /* Returns 1 iff locations A and B are sufficiently same that |
13388 | we don't need to report breakpoint as changed. */ | |
13389 | ||
13390 | static int | |
13391 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13392 | { | |
13393 | while (a && b) | |
13394 | { | |
13395 | if (a->address != b->address) | |
13396 | return 0; | |
13397 | ||
13398 | if (a->shlib_disabled != b->shlib_disabled) | |
13399 | return 0; | |
13400 | ||
13401 | if (a->enabled != b->enabled) | |
13402 | return 0; | |
13403 | ||
13404 | a = a->next; | |
13405 | b = b->next; | |
13406 | } | |
13407 | ||
13408 | if ((a == NULL) != (b == NULL)) | |
13409 | return 0; | |
13410 | ||
13411 | return 1; | |
13412 | } | |
13413 | ||
c2f4122d PA |
13414 | /* Split all locations of B that are bound to PSPACE out of B's |
13415 | location list to a separate list and return that list's head. If | |
13416 | PSPACE is NULL, hoist out all locations of B. */ | |
13417 | ||
13418 | static struct bp_location * | |
13419 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13420 | { | |
13421 | struct bp_location head; | |
13422 | struct bp_location *i = b->loc; | |
13423 | struct bp_location **i_link = &b->loc; | |
13424 | struct bp_location *hoisted = &head; | |
13425 | ||
13426 | if (pspace == NULL) | |
13427 | { | |
13428 | i = b->loc; | |
13429 | b->loc = NULL; | |
13430 | return i; | |
13431 | } | |
13432 | ||
13433 | head.next = NULL; | |
13434 | ||
13435 | while (i != NULL) | |
13436 | { | |
13437 | if (i->pspace == pspace) | |
13438 | { | |
13439 | *i_link = i->next; | |
13440 | i->next = NULL; | |
13441 | hoisted->next = i; | |
13442 | hoisted = i; | |
13443 | } | |
13444 | else | |
13445 | i_link = &i->next; | |
13446 | i = *i_link; | |
13447 | } | |
13448 | ||
13449 | return head.next; | |
13450 | } | |
13451 | ||
13452 | /* Create new breakpoint locations for B (a hardware or software | |
13453 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13454 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13455 | FILTER_PSPACE. Locations of other program spaces are left | |
13456 | untouched. */ | |
f1310107 | 13457 | |
0e30163f | 13458 | void |
0d381245 | 13459 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13460 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13461 | gdb::array_view<const symtab_and_line> sals, |
13462 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13463 | { |
c2f4122d | 13464 | struct bp_location *existing_locations; |
0d381245 | 13465 | |
6c5b2ebe | 13466 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13467 | { |
13468 | /* Ranged breakpoints have only one start location and one end | |
13469 | location. */ | |
13470 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13471 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13472 | "multiple locations found\n"), | |
13473 | b->number); | |
13474 | return; | |
13475 | } | |
f1310107 | 13476 | |
4a64f543 MS |
13477 | /* If there's no new locations, and all existing locations are |
13478 | pending, don't do anything. This optimizes the common case where | |
13479 | all locations are in the same shared library, that was unloaded. | |
13480 | We'd like to retain the location, so that when the library is | |
13481 | loaded again, we don't loose the enabled/disabled status of the | |
13482 | individual locations. */ | |
6c5b2ebe | 13483 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13484 | return; |
13485 | ||
c2f4122d | 13486 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13487 | |
6c5b2ebe | 13488 | for (const auto &sal : sals) |
fe3f5fa8 | 13489 | { |
f8eba3c6 TT |
13490 | struct bp_location *new_loc; |
13491 | ||
6c5b2ebe | 13492 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13493 | |
6c5b2ebe | 13494 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13495 | |
0d381245 VP |
13496 | /* Reparse conditions, they might contain references to the |
13497 | old symtab. */ | |
13498 | if (b->cond_string != NULL) | |
13499 | { | |
bbc13ae3 | 13500 | const char *s; |
fe3f5fa8 | 13501 | |
0d381245 | 13502 | s = b->cond_string; |
a70b8144 | 13503 | try |
0d381245 | 13504 | { |
6c5b2ebe PA |
13505 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13506 | block_for_pc (sal.pc), | |
0d381245 VP |
13507 | 0); |
13508 | } | |
230d2906 | 13509 | catch (const gdb_exception_error &e) |
0d381245 | 13510 | { |
3e43a32a MS |
13511 | warning (_("failed to reevaluate condition " |
13512 | "for breakpoint %d: %s"), | |
3d6e9d23 | 13513 | b->number, e.what ()); |
0d381245 VP |
13514 | new_loc->enabled = 0; |
13515 | } | |
13516 | } | |
fe3f5fa8 | 13517 | |
6c5b2ebe | 13518 | if (!sals_end.empty ()) |
f1310107 | 13519 | { |
6c5b2ebe | 13520 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13521 | |
6c5b2ebe | 13522 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13523 | } |
0d381245 | 13524 | } |
fe3f5fa8 | 13525 | |
4a64f543 MS |
13526 | /* If possible, carry over 'disable' status from existing |
13527 | breakpoints. */ | |
0d381245 VP |
13528 | { |
13529 | struct bp_location *e = existing_locations; | |
776592bf DE |
13530 | /* If there are multiple breakpoints with the same function name, |
13531 | e.g. for inline functions, comparing function names won't work. | |
13532 | Instead compare pc addresses; this is just a heuristic as things | |
13533 | may have moved, but in practice it gives the correct answer | |
13534 | often enough until a better solution is found. */ | |
13535 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13536 | ||
0d381245 VP |
13537 | for (; e; e = e->next) |
13538 | { | |
13539 | if (!e->enabled && e->function_name) | |
13540 | { | |
13541 | struct bp_location *l = b->loc; | |
776592bf DE |
13542 | if (have_ambiguous_names) |
13543 | { | |
13544 | for (; l; l = l->next) | |
f1310107 | 13545 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13546 | { |
13547 | l->enabled = 0; | |
13548 | break; | |
13549 | } | |
13550 | } | |
13551 | else | |
13552 | { | |
13553 | for (; l; l = l->next) | |
13554 | if (l->function_name | |
13555 | && strcmp (e->function_name, l->function_name) == 0) | |
13556 | { | |
13557 | l->enabled = 0; | |
13558 | break; | |
13559 | } | |
13560 | } | |
0d381245 VP |
13561 | } |
13562 | } | |
13563 | } | |
fe3f5fa8 | 13564 | |
8d3788bd | 13565 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 13566 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
13567 | } |
13568 | ||
f00aae0f | 13569 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13570 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13571 | ||
6c5b2ebe | 13572 | static std::vector<symtab_and_line> |
f00aae0f | 13573 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13574 | struct program_space *search_pspace, int *found) |
ef23e705 | 13575 | { |
cc06b668 | 13576 | struct gdb_exception exception; |
ef23e705 | 13577 | |
983af33b | 13578 | gdb_assert (b->ops != NULL); |
ef23e705 | 13579 | |
6c5b2ebe PA |
13580 | std::vector<symtab_and_line> sals; |
13581 | ||
a70b8144 | 13582 | try |
ef23e705 | 13583 | { |
6c5b2ebe | 13584 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13585 | } |
94aeb44b | 13586 | catch (gdb_exception_error &e) |
ef23e705 TJB |
13587 | { |
13588 | int not_found_and_ok = 0; | |
492d29ea | 13589 | |
ef23e705 TJB |
13590 | /* For pending breakpoints, it's expected that parsing will |
13591 | fail until the right shared library is loaded. User has | |
13592 | already told to create pending breakpoints and don't need | |
13593 | extra messages. If breakpoint is in bp_shlib_disabled | |
13594 | state, then user already saw the message about that | |
13595 | breakpoint being disabled, and don't want to see more | |
13596 | errors. */ | |
58438ac1 | 13597 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13598 | && (b->condition_not_parsed |
13599 | || (b->loc != NULL | |
13600 | && search_pspace != NULL | |
13601 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13602 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13603 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13604 | || b->enable_state == bp_disabled)) |
13605 | not_found_and_ok = 1; | |
13606 | ||
13607 | if (!not_found_and_ok) | |
13608 | { | |
13609 | /* We surely don't want to warn about the same breakpoint | |
13610 | 10 times. One solution, implemented here, is disable | |
13611 | the breakpoint on error. Another solution would be to | |
13612 | have separate 'warning emitted' flag. Since this | |
13613 | happens only when a binary has changed, I don't know | |
13614 | which approach is better. */ | |
13615 | b->enable_state = bp_disabled; | |
eedc3f4f | 13616 | throw; |
ef23e705 | 13617 | } |
94aeb44b TT |
13618 | |
13619 | exception = std::move (e); | |
ef23e705 TJB |
13620 | } |
13621 | ||
492d29ea | 13622 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13623 | { |
6c5b2ebe PA |
13624 | for (auto &sal : sals) |
13625 | resolve_sal_pc (&sal); | |
f00aae0f | 13626 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13627 | { |
ed1d1739 KS |
13628 | char *cond_string, *extra_string; |
13629 | int thread, task; | |
ef23e705 | 13630 | |
6c5b2ebe | 13631 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
13632 | &cond_string, &thread, &task, |
13633 | &extra_string); | |
f00aae0f | 13634 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13635 | if (cond_string) |
13636 | b->cond_string = cond_string; | |
13637 | b->thread = thread; | |
13638 | b->task = task; | |
e7e0cddf | 13639 | if (extra_string) |
f00aae0f KS |
13640 | { |
13641 | xfree (b->extra_string); | |
13642 | b->extra_string = extra_string; | |
13643 | } | |
ef23e705 TJB |
13644 | b->condition_not_parsed = 0; |
13645 | } | |
13646 | ||
983af33b | 13647 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13648 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13649 | |
58438ac1 TT |
13650 | *found = 1; |
13651 | } | |
13652 | else | |
13653 | *found = 0; | |
ef23e705 TJB |
13654 | |
13655 | return sals; | |
13656 | } | |
13657 | ||
348d480f PA |
13658 | /* The default re_set method, for typical hardware or software |
13659 | breakpoints. Reevaluate the breakpoint and recreate its | |
13660 | locations. */ | |
13661 | ||
13662 | static void | |
28010a5d | 13663 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13664 | { |
c2f4122d | 13665 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13666 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13667 | |
6c5b2ebe PA |
13668 | int found; |
13669 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13670 | filter_pspace, &found); | |
ef23e705 | 13671 | if (found) |
6c5b2ebe | 13672 | expanded = std::move (sals); |
ef23e705 | 13673 | |
f00aae0f | 13674 | if (b->location_range_end != NULL) |
f1310107 | 13675 | { |
6c5b2ebe PA |
13676 | std::vector<symtab_and_line> sals_end |
13677 | = location_to_sals (b, b->location_range_end.get (), | |
13678 | filter_pspace, &found); | |
f1310107 | 13679 | if (found) |
6c5b2ebe | 13680 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13681 | } |
13682 | ||
c2f4122d | 13683 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13684 | } |
13685 | ||
983af33b SDJ |
13686 | /* Default method for creating SALs from an address string. It basically |
13687 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13688 | ||
13689 | static void | |
f00aae0f KS |
13690 | create_sals_from_location_default (const struct event_location *location, |
13691 | struct linespec_result *canonical, | |
13692 | enum bptype type_wanted) | |
983af33b | 13693 | { |
f00aae0f | 13694 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
13695 | } |
13696 | ||
13697 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13698 | function for the `create_breakpoints_sal' method of | |
13699 | breakpoint_ops. */ | |
13700 | ||
13701 | static void | |
13702 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13703 | struct linespec_result *canonical, | |
e1e01040 PA |
13704 | gdb::unique_xmalloc_ptr<char> cond_string, |
13705 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13706 | enum bptype type_wanted, |
13707 | enum bpdisp disposition, | |
13708 | int thread, | |
13709 | int task, int ignore_count, | |
13710 | const struct breakpoint_ops *ops, | |
13711 | int from_tty, int enabled, | |
44f238bb | 13712 | int internal, unsigned flags) |
983af33b | 13713 | { |
e1e01040 PA |
13714 | create_breakpoints_sal (gdbarch, canonical, |
13715 | std::move (cond_string), | |
13716 | std::move (extra_string), | |
983af33b SDJ |
13717 | type_wanted, disposition, |
13718 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13719 | enabled, internal, flags); |
983af33b SDJ |
13720 | } |
13721 | ||
13722 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 13723 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 13724 | |
6c5b2ebe | 13725 | static std::vector<symtab_and_line> |
f00aae0f KS |
13726 | decode_location_default (struct breakpoint *b, |
13727 | const struct event_location *location, | |
6c5b2ebe | 13728 | struct program_space *search_pspace) |
983af33b SDJ |
13729 | { |
13730 | struct linespec_result canonical; | |
13731 | ||
c2f4122d | 13732 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 13733 | NULL, 0, &canonical, multiple_symbols_all, |
983af33b SDJ |
13734 | b->filter); |
13735 | ||
13736 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 13737 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 13738 | |
6c5b2ebe | 13739 | if (!canonical.lsals.empty ()) |
983af33b | 13740 | { |
6c5b2ebe PA |
13741 | const linespec_sals &lsal = canonical.lsals[0]; |
13742 | return std::move (lsal.sals); | |
983af33b | 13743 | } |
6c5b2ebe | 13744 | return {}; |
983af33b SDJ |
13745 | } |
13746 | ||
bf469271 | 13747 | /* Reset a breakpoint. */ |
c906108c | 13748 | |
bf469271 PA |
13749 | static void |
13750 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 13751 | { |
fdf44873 TT |
13752 | input_radix = b->input_radix; |
13753 | set_language (b->language); | |
c906108c | 13754 | |
348d480f | 13755 | b->ops->re_set (b); |
c906108c SS |
13756 | } |
13757 | ||
c2f4122d PA |
13758 | /* Re-set breakpoint locations for the current program space. |
13759 | Locations bound to other program spaces are left untouched. */ | |
13760 | ||
c906108c | 13761 | void |
69de3c6a | 13762 | breakpoint_re_set (void) |
c906108c | 13763 | { |
35df4500 | 13764 | struct breakpoint *b, *b_tmp; |
2a7f3dff | 13765 | |
c5aa993b | 13766 | { |
fdf44873 TT |
13767 | scoped_restore_current_language save_language; |
13768 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 13769 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 13770 | |
8e817061 JB |
13771 | /* breakpoint_re_set_one sets the current_language to the language |
13772 | of the breakpoint it is resetting (see prepare_re_set_context) | |
13773 | before re-evaluating the breakpoint's location. This change can | |
13774 | unfortunately get undone by accident if the language_mode is set | |
13775 | to auto, and we either switch frames, or more likely in this context, | |
13776 | we select the current frame. | |
13777 | ||
13778 | We prevent this by temporarily turning the language_mode to | |
13779 | language_mode_manual. We restore it once all breakpoints | |
13780 | have been reset. */ | |
13781 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
13782 | language_mode = language_mode_manual; | |
13783 | ||
5ed8105e PA |
13784 | /* Note: we must not try to insert locations until after all |
13785 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
13786 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
13787 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 13788 | |
5ed8105e PA |
13789 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
13790 | { | |
a70b8144 | 13791 | try |
bf469271 PA |
13792 | { |
13793 | breakpoint_re_set_one (b); | |
13794 | } | |
230d2906 | 13795 | catch (const gdb_exception &ex) |
bf469271 PA |
13796 | { |
13797 | exception_fprintf (gdb_stderr, ex, | |
13798 | "Error in re-setting breakpoint %d: ", | |
13799 | b->number); | |
13800 | } | |
5ed8105e | 13801 | } |
5ed8105e PA |
13802 | |
13803 | jit_breakpoint_re_set (); | |
13804 | } | |
6c95b8df | 13805 | |
af02033e PP |
13806 | create_overlay_event_breakpoint (); |
13807 | create_longjmp_master_breakpoint (); | |
13808 | create_std_terminate_master_breakpoint (); | |
186c406b | 13809 | create_exception_master_breakpoint (); |
2a7f3dff PA |
13810 | |
13811 | /* Now we can insert. */ | |
13812 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
13813 | } |
13814 | \f | |
c906108c SS |
13815 | /* Reset the thread number of this breakpoint: |
13816 | ||
13817 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13818 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13819 | void |
fba45db2 | 13820 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13821 | { |
13822 | if (b->thread != -1) | |
13823 | { | |
00431a78 | 13824 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
13825 | |
13826 | /* We're being called after following a fork. The new fork is | |
13827 | selected as current, and unless this was a vfork will have a | |
13828 | different program space from the original thread. Reset that | |
13829 | as well. */ | |
13830 | b->loc->pspace = current_program_space; | |
c906108c SS |
13831 | } |
13832 | } | |
13833 | ||
03ac34d5 MS |
13834 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13835 | If from_tty is nonzero, it prints a message to that effect, | |
13836 | which ends with a period (no newline). */ | |
13837 | ||
c906108c | 13838 | void |
fba45db2 | 13839 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13840 | { |
52f0bd74 | 13841 | struct breakpoint *b; |
c906108c SS |
13842 | |
13843 | if (count < 0) | |
13844 | count = 0; | |
13845 | ||
13846 | ALL_BREAKPOINTS (b) | |
13847 | if (b->number == bptnum) | |
c5aa993b | 13848 | { |
d77f58be SS |
13849 | if (is_tracepoint (b)) |
13850 | { | |
13851 | if (from_tty && count != 0) | |
13852 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13853 | bptnum); | |
13854 | return; | |
13855 | } | |
13856 | ||
c5aa993b | 13857 | b->ignore_count = count; |
221ea385 KS |
13858 | if (from_tty) |
13859 | { | |
13860 | if (count == 0) | |
3e43a32a MS |
13861 | printf_filtered (_("Will stop next time " |
13862 | "breakpoint %d is reached."), | |
221ea385 KS |
13863 | bptnum); |
13864 | else if (count == 1) | |
a3f17187 | 13865 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
13866 | bptnum); |
13867 | else | |
3e43a32a MS |
13868 | printf_filtered (_("Will ignore next %d " |
13869 | "crossings of breakpoint %d."), | |
221ea385 KS |
13870 | count, bptnum); |
13871 | } | |
76727919 | 13872 | gdb::observers::breakpoint_modified.notify (b); |
c5aa993b JM |
13873 | return; |
13874 | } | |
c906108c | 13875 | |
8a3fe4f8 | 13876 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13877 | } |
13878 | ||
c906108c SS |
13879 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13880 | ||
13881 | static void | |
0b39b52e | 13882 | ignore_command (const char *args, int from_tty) |
c906108c | 13883 | { |
0b39b52e | 13884 | const char *p = args; |
52f0bd74 | 13885 | int num; |
c906108c SS |
13886 | |
13887 | if (p == 0) | |
e2e0b3e5 | 13888 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13889 | |
c906108c | 13890 | num = get_number (&p); |
5c44784c | 13891 | if (num == 0) |
8a3fe4f8 | 13892 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13893 | if (*p == 0) |
8a3fe4f8 | 13894 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13895 | |
13896 | set_ignore_count (num, | |
13897 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13898 | from_tty); | |
221ea385 KS |
13899 | if (from_tty) |
13900 | printf_filtered ("\n"); | |
c906108c SS |
13901 | } |
13902 | \f | |
d0fe4701 XR |
13903 | |
13904 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
13905 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
13906 | |
13907 | static void | |
d0fe4701 XR |
13908 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
13909 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 13910 | { |
d0fe4701 XR |
13911 | if (bp_num_range.first == 0) |
13912 | { | |
13913 | warning (_("bad breakpoint number at or near '%d'"), | |
13914 | bp_num_range.first); | |
13915 | } | |
13916 | else | |
c906108c | 13917 | { |
d0fe4701 | 13918 | struct breakpoint *b, *tmp; |
197f0a60 | 13919 | |
d0fe4701 | 13920 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 13921 | { |
d0fe4701 XR |
13922 | bool match = false; |
13923 | ||
5c44784c | 13924 | ALL_BREAKPOINTS_SAFE (b, tmp) |
d0fe4701 | 13925 | if (b->number == i) |
5c44784c | 13926 | { |
bfd28288 | 13927 | match = true; |
48649e1b | 13928 | function (b); |
11cf8741 | 13929 | break; |
5c44784c | 13930 | } |
bfd28288 | 13931 | if (!match) |
d0fe4701 | 13932 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 13933 | } |
c906108c SS |
13934 | } |
13935 | } | |
13936 | ||
d0fe4701 XR |
13937 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
13938 | ARGS. */ | |
13939 | ||
13940 | static void | |
13941 | map_breakpoint_numbers (const char *args, | |
13942 | gdb::function_view<void (breakpoint *)> function) | |
13943 | { | |
13944 | if (args == NULL || *args == '\0') | |
13945 | error_no_arg (_("one or more breakpoint numbers")); | |
13946 | ||
13947 | number_or_range_parser parser (args); | |
13948 | ||
13949 | while (!parser.finished ()) | |
13950 | { | |
13951 | int num = parser.get_number (); | |
13952 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
13953 | } | |
13954 | } | |
13955 | ||
13956 | /* Return the breakpoint location structure corresponding to the | |
13957 | BP_NUM and LOC_NUM values. */ | |
13958 | ||
0d381245 | 13959 | static struct bp_location * |
d0fe4701 | 13960 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 13961 | { |
0d381245 | 13962 | struct breakpoint *b; |
0d381245 VP |
13963 | |
13964 | ALL_BREAKPOINTS (b) | |
13965 | if (b->number == bp_num) | |
13966 | { | |
13967 | break; | |
13968 | } | |
13969 | ||
13970 | if (!b || b->number != bp_num) | |
d0fe4701 | 13971 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 13972 | |
0d381245 | 13973 | if (loc_num == 0) |
d0fe4701 | 13974 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 13975 | |
d0fe4701 XR |
13976 | int n = 0; |
13977 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
13978 | if (++n == loc_num) | |
13979 | return loc; | |
13980 | ||
13981 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
13982 | } |
13983 | ||
95e95a6d PA |
13984 | /* Modes of operation for extract_bp_num. */ |
13985 | enum class extract_bp_kind | |
13986 | { | |
13987 | /* Extracting a breakpoint number. */ | |
13988 | bp, | |
13989 | ||
13990 | /* Extracting a location number. */ | |
13991 | loc, | |
13992 | }; | |
13993 | ||
13994 | /* Extract a breakpoint or location number (as determined by KIND) | |
13995 | from the string starting at START. TRAILER is a character which | |
13996 | can be found after the number. If you don't want a trailer, use | |
13997 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
13998 | string. This always returns a positive integer. */ | |
13999 | ||
14000 | static int | |
14001 | extract_bp_num (extract_bp_kind kind, const char *start, | |
14002 | int trailer, const char **end_out = NULL) | |
14003 | { | |
14004 | const char *end = start; | |
14005 | int num = get_number_trailer (&end, trailer); | |
14006 | if (num < 0) | |
14007 | error (kind == extract_bp_kind::bp | |
14008 | ? _("Negative breakpoint number '%.*s'") | |
14009 | : _("Negative breakpoint location number '%.*s'"), | |
14010 | int (end - start), start); | |
14011 | if (num == 0) | |
14012 | error (kind == extract_bp_kind::bp | |
14013 | ? _("Bad breakpoint number '%.*s'") | |
14014 | : _("Bad breakpoint location number '%.*s'"), | |
14015 | int (end - start), start); | |
14016 | ||
14017 | if (end_out != NULL) | |
14018 | *end_out = end; | |
14019 | return num; | |
14020 | } | |
14021 | ||
14022 | /* Extract a breakpoint or location range (as determined by KIND) in | |
14023 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
14024 | representing the (inclusive) range. The returned pair's elements | |
14025 | are always positive integers. */ | |
14026 | ||
14027 | static std::pair<int, int> | |
14028 | extract_bp_or_bp_range (extract_bp_kind kind, | |
14029 | const std::string &arg, | |
14030 | std::string::size_type arg_offset) | |
14031 | { | |
14032 | std::pair<int, int> range; | |
14033 | const char *bp_loc = &arg[arg_offset]; | |
14034 | std::string::size_type dash = arg.find ('-', arg_offset); | |
14035 | if (dash != std::string::npos) | |
14036 | { | |
14037 | /* bp_loc is a range (x-z). */ | |
14038 | if (arg.length () == dash + 1) | |
14039 | error (kind == extract_bp_kind::bp | |
14040 | ? _("Bad breakpoint number at or near: '%s'") | |
14041 | : _("Bad breakpoint location number at or near: '%s'"), | |
14042 | bp_loc); | |
14043 | ||
14044 | const char *end; | |
14045 | const char *start_first = bp_loc; | |
14046 | const char *start_second = &arg[dash + 1]; | |
14047 | range.first = extract_bp_num (kind, start_first, '-'); | |
14048 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
14049 | ||
14050 | if (range.first > range.second) | |
14051 | error (kind == extract_bp_kind::bp | |
14052 | ? _("Inverted breakpoint range at '%.*s'") | |
14053 | : _("Inverted breakpoint location range at '%.*s'"), | |
14054 | int (end - start_first), start_first); | |
14055 | } | |
14056 | else | |
14057 | { | |
14058 | /* bp_loc is a single value. */ | |
14059 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
14060 | range.second = range.first; | |
14061 | } | |
14062 | return range; | |
14063 | } | |
14064 | ||
d0fe4701 XR |
14065 | /* Extract the breakpoint/location range specified by ARG. Returns |
14066 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
14067 | BP_LOC_RANGE. | |
14068 | ||
14069 | ARG may be in any of the following forms: | |
14070 | ||
14071 | x where 'x' is a breakpoint number. | |
14072 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
14073 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
14074 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
14075 | location number range. | |
14076 | */ | |
14077 | ||
cc638e86 | 14078 | static void |
d0fe4701 XR |
14079 | extract_bp_number_and_location (const std::string &arg, |
14080 | std::pair<int, int> &bp_num_range, | |
14081 | std::pair<int, int> &bp_loc_range) | |
14082 | { | |
14083 | std::string::size_type dot = arg.find ('.'); | |
14084 | ||
14085 | if (dot != std::string::npos) | |
14086 | { | |
14087 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
14088 | ||
14089 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 14090 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 14091 | |
95e95a6d PA |
14092 | bp_num_range.first |
14093 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
14094 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 14095 | |
95e95a6d PA |
14096 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
14097 | arg, dot + 1); | |
d0fe4701 XR |
14098 | } |
14099 | else | |
14100 | { | |
14101 | /* Handle x and x-y cases. */ | |
d0fe4701 | 14102 | |
95e95a6d | 14103 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
14104 | bp_loc_range.first = 0; |
14105 | bp_loc_range.second = 0; | |
14106 | } | |
d0fe4701 XR |
14107 | } |
14108 | ||
14109 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
14110 | specifies whether to enable or disable. */ | |
14111 | ||
14112 | static void | |
14113 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
14114 | { | |
14115 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
14116 | if (loc != NULL) | |
14117 | { | |
14118 | if (loc->enabled != enable) | |
14119 | { | |
14120 | loc->enabled = enable; | |
14121 | mark_breakpoint_location_modified (loc); | |
14122 | } | |
14123 | if (target_supports_enable_disable_tracepoint () | |
14124 | && current_trace_status ()->running && loc->owner | |
14125 | && is_tracepoint (loc->owner)) | |
14126 | target_disable_tracepoint (loc); | |
14127 | } | |
14128 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
14129 | |
14130 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
14131 | } |
14132 | ||
14133 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
14134 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
14135 | (inclusive) range of location numbers of that breakpoint to | |
14136 | enable/disable. ENABLE specifies whether to enable or disable the | |
14137 | location. */ | |
14138 | ||
14139 | static void | |
14140 | enable_disable_breakpoint_location_range (int bp_num, | |
14141 | std::pair<int, int> &bp_loc_range, | |
14142 | bool enable) | |
14143 | { | |
14144 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
14145 | enable_disable_bp_num_loc (bp_num, i, enable); | |
14146 | } | |
0d381245 | 14147 | |
1900040c MS |
14148 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14149 | If from_tty is nonzero, it prints a message to that effect, | |
14150 | which ends with a period (no newline). */ | |
14151 | ||
c906108c | 14152 | void |
fba45db2 | 14153 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14154 | { |
14155 | /* Never disable a watchpoint scope breakpoint; we want to | |
14156 | hit them when we leave scope so we can delete both the | |
14157 | watchpoint and its scope breakpoint at that time. */ | |
14158 | if (bpt->type == bp_watchpoint_scope) | |
14159 | return; | |
14160 | ||
b5de0fa7 | 14161 | bpt->enable_state = bp_disabled; |
c906108c | 14162 | |
b775012e LM |
14163 | /* Mark breakpoint locations modified. */ |
14164 | mark_breakpoint_modified (bpt); | |
14165 | ||
d248b706 KY |
14166 | if (target_supports_enable_disable_tracepoint () |
14167 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14168 | { | |
14169 | struct bp_location *location; | |
14170 | ||
14171 | for (location = bpt->loc; location; location = location->next) | |
14172 | target_disable_tracepoint (location); | |
14173 | } | |
14174 | ||
44702360 | 14175 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14176 | |
76727919 | 14177 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14178 | } |
14179 | ||
d0fe4701 XR |
14180 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
14181 | specified in ARGS. ARGS may be in any of the formats handled by | |
14182 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
14183 | or disable the breakpoints/locations. */ | |
14184 | ||
c906108c | 14185 | static void |
d0fe4701 | 14186 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 14187 | { |
c906108c | 14188 | if (args == 0) |
46c6471b PA |
14189 | { |
14190 | struct breakpoint *bpt; | |
14191 | ||
14192 | ALL_BREAKPOINTS (bpt) | |
14193 | if (user_breakpoint_p (bpt)) | |
d0fe4701 XR |
14194 | { |
14195 | if (enable) | |
14196 | enable_breakpoint (bpt); | |
14197 | else | |
14198 | disable_breakpoint (bpt); | |
14199 | } | |
46c6471b | 14200 | } |
9eaabc75 | 14201 | else |
0d381245 | 14202 | { |
cb791d59 | 14203 | std::string num = extract_arg (&args); |
9eaabc75 | 14204 | |
cb791d59 | 14205 | while (!num.empty ()) |
d248b706 | 14206 | { |
d0fe4701 | 14207 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 14208 | |
cc638e86 PA |
14209 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
14210 | ||
14211 | if (bp_loc_range.first == bp_loc_range.second | |
14212 | && bp_loc_range.first == 0) | |
d0fe4701 | 14213 | { |
cc638e86 PA |
14214 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
14215 | map_breakpoint_number_range (bp_num_range, | |
14216 | enable | |
14217 | ? enable_breakpoint | |
14218 | : disable_breakpoint); | |
14219 | } | |
14220 | else | |
14221 | { | |
14222 | /* Handle breakpoint ids with formats 'x.y' or | |
14223 | 'x.y-z'. */ | |
14224 | enable_disable_breakpoint_location_range | |
14225 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 14226 | } |
9eaabc75 | 14227 | num = extract_arg (&args); |
d248b706 | 14228 | } |
0d381245 | 14229 | } |
c906108c SS |
14230 | } |
14231 | ||
d0fe4701 XR |
14232 | /* The disable command disables the specified breakpoints/locations |
14233 | (or all defined breakpoints) so they're no longer effective in | |
14234 | stopping the inferior. ARGS may be in any of the forms defined in | |
14235 | extract_bp_number_and_location. */ | |
14236 | ||
14237 | static void | |
14238 | disable_command (const char *args, int from_tty) | |
14239 | { | |
14240 | enable_disable_command (args, from_tty, false); | |
14241 | } | |
14242 | ||
c906108c | 14243 | static void |
816338b5 SS |
14244 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14245 | int count) | |
c906108c | 14246 | { |
afe38095 | 14247 | int target_resources_ok; |
c906108c SS |
14248 | |
14249 | if (bpt->type == bp_hardware_breakpoint) | |
14250 | { | |
14251 | int i; | |
c5aa993b | 14252 | i = hw_breakpoint_used_count (); |
53a5351d | 14253 | target_resources_ok = |
d92524f1 | 14254 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14255 | i + 1, 0); |
c906108c | 14256 | if (target_resources_ok == 0) |
8a3fe4f8 | 14257 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14258 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14259 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14260 | } |
14261 | ||
cc60f2e3 | 14262 | if (is_watchpoint (bpt)) |
c906108c | 14263 | { |
d07205c2 | 14264 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14265 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14266 | |
a70b8144 | 14267 | try |
c906108c | 14268 | { |
3a5c3e22 PA |
14269 | struct watchpoint *w = (struct watchpoint *) bpt; |
14270 | ||
1e718ff1 TJB |
14271 | orig_enable_state = bpt->enable_state; |
14272 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14273 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14274 | } |
230d2906 | 14275 | catch (const gdb_exception &e) |
c5aa993b | 14276 | { |
1e718ff1 | 14277 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14278 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14279 | bpt->number); | |
14280 | return; | |
c5aa993b | 14281 | } |
c906108c | 14282 | } |
0101ce28 | 14283 | |
b775012e LM |
14284 | bpt->enable_state = bp_enabled; |
14285 | ||
14286 | /* Mark breakpoint locations modified. */ | |
14287 | mark_breakpoint_modified (bpt); | |
14288 | ||
d248b706 KY |
14289 | if (target_supports_enable_disable_tracepoint () |
14290 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14291 | { | |
14292 | struct bp_location *location; | |
14293 | ||
14294 | for (location = bpt->loc; location; location = location->next) | |
14295 | target_enable_tracepoint (location); | |
14296 | } | |
14297 | ||
b4c291bb | 14298 | bpt->disposition = disposition; |
816338b5 | 14299 | bpt->enable_count = count; |
44702360 | 14300 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14301 | |
76727919 | 14302 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14303 | } |
14304 | ||
fe3f5fa8 | 14305 | |
c906108c | 14306 | void |
fba45db2 | 14307 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14308 | { |
816338b5 | 14309 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14310 | } |
14311 | ||
d0fe4701 XR |
14312 | /* The enable command enables the specified breakpoints/locations (or |
14313 | all defined breakpoints) so they once again become (or continue to | |
14314 | be) effective in stopping the inferior. ARGS may be in any of the | |
14315 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 14316 | |
c906108c | 14317 | static void |
981a3fb3 | 14318 | enable_command (const char *args, int from_tty) |
c906108c | 14319 | { |
d0fe4701 | 14320 | enable_disable_command (args, from_tty, true); |
c906108c SS |
14321 | } |
14322 | ||
c906108c | 14323 | static void |
4495129a | 14324 | enable_once_command (const char *args, int from_tty) |
c906108c | 14325 | { |
48649e1b TT |
14326 | map_breakpoint_numbers |
14327 | (args, [&] (breakpoint *b) | |
14328 | { | |
14329 | iterate_over_related_breakpoints | |
14330 | (b, [&] (breakpoint *bpt) | |
14331 | { | |
14332 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14333 | }); | |
14334 | }); | |
816338b5 SS |
14335 | } |
14336 | ||
14337 | static void | |
4495129a | 14338 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14339 | { |
b9d61307 SM |
14340 | int count; |
14341 | ||
14342 | if (args == NULL) | |
14343 | error_no_arg (_("hit count")); | |
14344 | ||
14345 | count = get_number (&args); | |
816338b5 | 14346 | |
48649e1b TT |
14347 | map_breakpoint_numbers |
14348 | (args, [&] (breakpoint *b) | |
14349 | { | |
14350 | iterate_over_related_breakpoints | |
14351 | (b, [&] (breakpoint *bpt) | |
14352 | { | |
14353 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14354 | }); | |
14355 | }); | |
c906108c SS |
14356 | } |
14357 | ||
c906108c | 14358 | static void |
4495129a | 14359 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14360 | { |
48649e1b TT |
14361 | map_breakpoint_numbers |
14362 | (args, [&] (breakpoint *b) | |
14363 | { | |
14364 | iterate_over_related_breakpoints | |
14365 | (b, [&] (breakpoint *bpt) | |
14366 | { | |
14367 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14368 | }); | |
14369 | }); | |
c906108c SS |
14370 | } |
14371 | \f | |
fa8d40ab | 14372 | static void |
981a3fb3 | 14373 | set_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14374 | { |
14375 | } | |
14376 | ||
14377 | static void | |
981a3fb3 | 14378 | show_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14379 | { |
14380 | } | |
14381 | ||
1f3b5d1b PP |
14382 | /* Invalidate last known value of any hardware watchpoint if |
14383 | the memory which that value represents has been written to by | |
14384 | GDB itself. */ | |
14385 | ||
14386 | static void | |
8de0566d YQ |
14387 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14388 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14389 | const bfd_byte *data) |
14390 | { | |
14391 | struct breakpoint *bp; | |
14392 | ||
14393 | ALL_BREAKPOINTS (bp) | |
14394 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14395 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14396 | { |
3a5c3e22 | 14397 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14398 | |
850645cf | 14399 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 PA |
14400 | { |
14401 | struct bp_location *loc; | |
14402 | ||
14403 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14404 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14405 | && loc->address + loc->length > addr | |
14406 | && addr + len > loc->address) | |
14407 | { | |
3a5c3e22 PA |
14408 | wp->val = NULL; |
14409 | wp->val_valid = 0; | |
14410 | } | |
14411 | } | |
1f3b5d1b PP |
14412 | } |
14413 | } | |
14414 | ||
8181d85f DJ |
14415 | /* Create and insert a breakpoint for software single step. */ |
14416 | ||
14417 | void | |
6c95b8df | 14418 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 14419 | const address_space *aspace, |
4a64f543 | 14420 | CORE_ADDR next_pc) |
8181d85f | 14421 | { |
7c16b83e PA |
14422 | struct thread_info *tp = inferior_thread (); |
14423 | struct symtab_and_line sal; | |
14424 | CORE_ADDR pc = next_pc; | |
8181d85f | 14425 | |
34b7e8a6 PA |
14426 | if (tp->control.single_step_breakpoints == NULL) |
14427 | { | |
14428 | tp->control.single_step_breakpoints | |
5d5658a1 | 14429 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14430 | } |
8181d85f | 14431 | |
7c16b83e PA |
14432 | sal = find_pc_line (pc, 0); |
14433 | sal.pc = pc; | |
14434 | sal.section = find_pc_overlay (pc); | |
14435 | sal.explicit_pc = 1; | |
34b7e8a6 | 14436 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14437 | |
7c16b83e | 14438 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14439 | } |
14440 | ||
93f9a11f YQ |
14441 | /* Insert single step breakpoints according to the current state. */ |
14442 | ||
14443 | int | |
14444 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14445 | { | |
f5ea389a | 14446 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14447 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14448 | |
f5ea389a | 14449 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14450 | |
a0ff9e1a | 14451 | if (!next_pcs.empty ()) |
93f9a11f | 14452 | { |
f5ea389a | 14453 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14454 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14455 | |
a0ff9e1a | 14456 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14457 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14458 | ||
93f9a11f YQ |
14459 | return 1; |
14460 | } | |
14461 | else | |
14462 | return 0; | |
14463 | } | |
14464 | ||
34b7e8a6 | 14465 | /* See breakpoint.h. */ |
f02253f1 HZ |
14466 | |
14467 | int | |
7c16b83e | 14468 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14469 | const address_space *aspace, |
7c16b83e | 14470 | CORE_ADDR pc) |
1aafd4da | 14471 | { |
7c16b83e | 14472 | struct bp_location *loc; |
1aafd4da | 14473 | |
7c16b83e PA |
14474 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14475 | if (loc->inserted | |
14476 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14477 | return 1; | |
1aafd4da | 14478 | |
7c16b83e | 14479 | return 0; |
ef370185 JB |
14480 | } |
14481 | ||
14482 | /* Check whether a software single-step breakpoint is inserted at | |
14483 | PC. */ | |
14484 | ||
14485 | int | |
accd0bcd | 14486 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14487 | CORE_ADDR pc) |
14488 | { | |
34b7e8a6 PA |
14489 | struct breakpoint *bpt; |
14490 | ||
14491 | ALL_BREAKPOINTS (bpt) | |
14492 | { | |
14493 | if (bpt->type == bp_single_step | |
14494 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14495 | return 1; | |
14496 | } | |
14497 | return 0; | |
1aafd4da UW |
14498 | } |
14499 | ||
1042e4c0 SS |
14500 | /* Tracepoint-specific operations. */ |
14501 | ||
14502 | /* Set tracepoint count to NUM. */ | |
14503 | static void | |
14504 | set_tracepoint_count (int num) | |
14505 | { | |
14506 | tracepoint_count = num; | |
4fa62494 | 14507 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14508 | } |
14509 | ||
70221824 | 14510 | static void |
0b39b52e | 14511 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14512 | { |
55aa24fb | 14513 | struct breakpoint_ops *ops; |
55aa24fb | 14514 | |
ffc2605c TT |
14515 | event_location_up location = string_to_event_location (&arg, |
14516 | current_language); | |
5b56227b | 14517 | if (location != NULL |
ffc2605c | 14518 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
14519 | ops = &tracepoint_probe_breakpoint_ops; |
14520 | else | |
14521 | ops = &tracepoint_breakpoint_ops; | |
14522 | ||
558a9d82 | 14523 | create_breakpoint (get_current_arch (), |
ffc2605c | 14524 | location.get (), |
f00aae0f | 14525 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14526 | 0 /* tempflag */, |
14527 | bp_tracepoint /* type_wanted */, | |
14528 | 0 /* Ignore count */, | |
14529 | pending_break_support, | |
14530 | ops, | |
14531 | from_tty, | |
14532 | 1 /* enabled */, | |
14533 | 0 /* internal */, 0); | |
1042e4c0 SS |
14534 | } |
14535 | ||
70221824 | 14536 | static void |
0b39b52e | 14537 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14538 | { |
ffc2605c TT |
14539 | event_location_up location = string_to_event_location (&arg, |
14540 | current_language); | |
558a9d82 | 14541 | create_breakpoint (get_current_arch (), |
ffc2605c | 14542 | location.get (), |
f00aae0f | 14543 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14544 | 0 /* tempflag */, |
14545 | bp_fast_tracepoint /* type_wanted */, | |
14546 | 0 /* Ignore count */, | |
14547 | pending_break_support, | |
14548 | &tracepoint_breakpoint_ops, | |
14549 | from_tty, | |
14550 | 1 /* enabled */, | |
14551 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14552 | } |
14553 | ||
14554 | /* strace command implementation. Creates a static tracepoint. */ | |
14555 | ||
70221824 | 14556 | static void |
0b39b52e | 14557 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14558 | { |
983af33b | 14559 | struct breakpoint_ops *ops; |
ffc2605c | 14560 | event_location_up location; |
983af33b SDJ |
14561 | |
14562 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14563 | or with a normal static tracepoint. */ | |
61012eef | 14564 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14565 | { |
14566 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14567 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14568 | } |
983af33b | 14569 | else |
f00aae0f KS |
14570 | { |
14571 | ops = &tracepoint_breakpoint_ops; | |
14572 | location = string_to_event_location (&arg, current_language); | |
14573 | } | |
983af33b | 14574 | |
558a9d82 | 14575 | create_breakpoint (get_current_arch (), |
ffc2605c | 14576 | location.get (), |
f00aae0f | 14577 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14578 | 0 /* tempflag */, |
14579 | bp_static_tracepoint /* type_wanted */, | |
14580 | 0 /* Ignore count */, | |
14581 | pending_break_support, | |
14582 | ops, | |
14583 | from_tty, | |
14584 | 1 /* enabled */, | |
14585 | 0 /* internal */, 0); | |
7a697b8d SS |
14586 | } |
14587 | ||
409873ef SS |
14588 | /* Set up a fake reader function that gets command lines from a linked |
14589 | list that was acquired during tracepoint uploading. */ | |
14590 | ||
14591 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14592 | static int next_cmd; |
409873ef SS |
14593 | |
14594 | static char * | |
14595 | read_uploaded_action (void) | |
14596 | { | |
a18ba4e4 | 14597 | char *rslt = nullptr; |
409873ef | 14598 | |
a18ba4e4 SM |
14599 | if (next_cmd < this_utp->cmd_strings.size ()) |
14600 | { | |
67aa1f3c | 14601 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
14602 | next_cmd++; |
14603 | } | |
409873ef SS |
14604 | |
14605 | return rslt; | |
14606 | } | |
14607 | ||
00bf0b85 SS |
14608 | /* Given information about a tracepoint as recorded on a target (which |
14609 | can be either a live system or a trace file), attempt to create an | |
14610 | equivalent GDB tracepoint. This is not a reliable process, since | |
14611 | the target does not necessarily have all the information used when | |
14612 | the tracepoint was originally defined. */ | |
14613 | ||
d9b3f62e | 14614 | struct tracepoint * |
00bf0b85 | 14615 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14616 | { |
f2fc3015 TT |
14617 | const char *addr_str; |
14618 | char small_buf[100]; | |
d9b3f62e | 14619 | struct tracepoint *tp; |
fd9b8c24 | 14620 | |
409873ef | 14621 | if (utp->at_string) |
67aa1f3c | 14622 | addr_str = utp->at_string.get (); |
409873ef SS |
14623 | else |
14624 | { | |
14625 | /* In the absence of a source location, fall back to raw | |
14626 | address. Since there is no way to confirm that the address | |
14627 | means the same thing as when the trace was started, warn the | |
14628 | user. */ | |
3e43a32a MS |
14629 | warning (_("Uploaded tracepoint %d has no " |
14630 | "source location, using raw address"), | |
409873ef | 14631 | utp->number); |
8c042590 | 14632 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14633 | addr_str = small_buf; |
14634 | } | |
14635 | ||
14636 | /* There's not much we can do with a sequence of bytecodes. */ | |
14637 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14638 | warning (_("Uploaded tracepoint %d condition " |
14639 | "has no source form, ignoring it"), | |
409873ef | 14640 | utp->number); |
d5551862 | 14641 | |
ffc2605c TT |
14642 | event_location_up location = string_to_event_location (&addr_str, |
14643 | current_language); | |
8cdf0e15 | 14644 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14645 | location.get (), |
67aa1f3c | 14646 | utp->cond_string.get (), -1, addr_str, |
e7e0cddf | 14647 | 0 /* parse cond/thread */, |
8cdf0e15 | 14648 | 0 /* tempflag */, |
0fb4aa4b | 14649 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14650 | 0 /* Ignore count */, |
14651 | pending_break_support, | |
348d480f | 14652 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14653 | 0 /* from_tty */, |
84f4c1fe | 14654 | utp->enabled /* enabled */, |
44f238bb PA |
14655 | 0 /* internal */, |
14656 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14657 | return NULL; |
fd9b8c24 | 14658 | |
409873ef | 14659 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14660 | tp = get_tracepoint (tracepoint_count); |
14661 | gdb_assert (tp != NULL); | |
d5551862 | 14662 | |
00bf0b85 SS |
14663 | if (utp->pass > 0) |
14664 | { | |
8c042590 | 14665 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14666 | tp->number); |
00bf0b85 | 14667 | |
409873ef | 14668 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14669 | } |
14670 | ||
409873ef SS |
14671 | /* If we have uploaded versions of the original commands, set up a |
14672 | special-purpose "reader" function and call the usual command line | |
14673 | reader, then pass the result to the breakpoint command-setting | |
14674 | function. */ | |
a18ba4e4 | 14675 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 14676 | { |
12973681 | 14677 | counted_command_line cmd_list; |
00bf0b85 | 14678 | |
409873ef | 14679 | this_utp = utp; |
3149d8c1 | 14680 | next_cmd = 0; |
d5551862 | 14681 | |
60b3cef2 | 14682 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 14683 | |
c1fc2657 | 14684 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14685 | } |
a18ba4e4 SM |
14686 | else if (!utp->actions.empty () |
14687 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
14688 | warning (_("Uploaded tracepoint %d actions " |
14689 | "have no source form, ignoring them"), | |
409873ef | 14690 | utp->number); |
00bf0b85 | 14691 | |
f196051f | 14692 | /* Copy any status information that might be available. */ |
c1fc2657 | 14693 | tp->hit_count = utp->hit_count; |
f196051f SS |
14694 | tp->traceframe_usage = utp->traceframe_usage; |
14695 | ||
00bf0b85 | 14696 | return tp; |
d9b3f62e | 14697 | } |
00bf0b85 | 14698 | |
1042e4c0 SS |
14699 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14700 | omitted. */ | |
14701 | ||
14702 | static void | |
1d12d88f | 14703 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 14704 | { |
79a45e25 | 14705 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14706 | int num_printed; |
1042e4c0 | 14707 | |
e5a67952 | 14708 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
14709 | |
14710 | if (num_printed == 0) | |
1042e4c0 | 14711 | { |
e5a67952 | 14712 | if (args == NULL || *args == '\0') |
112e8700 | 14713 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14714 | else |
112e8700 | 14715 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14716 | } |
ad443146 SS |
14717 | |
14718 | default_collect_info (); | |
1042e4c0 SS |
14719 | } |
14720 | ||
4a64f543 | 14721 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14722 | Not supported by all targets. */ |
14723 | static void | |
5fed81ff | 14724 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14725 | { |
14726 | enable_command (args, from_tty); | |
14727 | } | |
14728 | ||
4a64f543 | 14729 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14730 | Not supported by all targets. */ |
14731 | static void | |
5fed81ff | 14732 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14733 | { |
14734 | disable_command (args, from_tty); | |
14735 | } | |
14736 | ||
4a64f543 | 14737 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14738 | static void |
4495129a | 14739 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14740 | { |
35df4500 | 14741 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14742 | |
14743 | dont_repeat (); | |
14744 | ||
14745 | if (arg == 0) | |
14746 | { | |
14747 | int breaks_to_delete = 0; | |
14748 | ||
14749 | /* Delete all breakpoints if no argument. | |
14750 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14751 | have to be deleted with an explicit breakpoint number |
14752 | argument. */ | |
1042e4c0 | 14753 | ALL_TRACEPOINTS (b) |
46c6471b | 14754 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14755 | { |
14756 | breaks_to_delete = 1; | |
14757 | break; | |
14758 | } | |
1042e4c0 SS |
14759 | |
14760 | /* Ask user only if there are some breakpoints to delete. */ | |
14761 | if (!from_tty | |
14762 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14763 | { | |
35df4500 | 14764 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14765 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14766 | delete_breakpoint (b); |
1042e4c0 SS |
14767 | } |
14768 | } | |
14769 | else | |
48649e1b | 14770 | map_breakpoint_numbers |
b926417a | 14771 | (arg, [&] (breakpoint *br) |
48649e1b | 14772 | { |
b926417a | 14773 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 14774 | }); |
1042e4c0 SS |
14775 | } |
14776 | ||
197f0a60 TT |
14777 | /* Helper function for trace_pass_command. */ |
14778 | ||
14779 | static void | |
d9b3f62e | 14780 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14781 | { |
d9b3f62e | 14782 | tp->pass_count = count; |
76727919 | 14783 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 TT |
14784 | if (from_tty) |
14785 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 14786 | tp->number, count); |
197f0a60 TT |
14787 | } |
14788 | ||
1042e4c0 SS |
14789 | /* Set passcount for tracepoint. |
14790 | ||
14791 | First command argument is passcount, second is tracepoint number. | |
14792 | If tracepoint number omitted, apply to most recently defined. | |
14793 | Also accepts special argument "all". */ | |
14794 | ||
14795 | static void | |
0b39b52e | 14796 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 14797 | { |
d9b3f62e | 14798 | struct tracepoint *t1; |
0b39b52e | 14799 | ULONGEST count; |
1042e4c0 SS |
14800 | |
14801 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14802 | error (_("passcount command requires an " |
14803 | "argument (count + optional TP num)")); | |
1042e4c0 | 14804 | |
0b39b52e | 14805 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 14806 | |
529480d0 | 14807 | args = skip_spaces (args); |
1042e4c0 SS |
14808 | if (*args && strncasecmp (args, "all", 3) == 0) |
14809 | { | |
d9b3f62e PA |
14810 | struct breakpoint *b; |
14811 | ||
1042e4c0 | 14812 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
14813 | if (*args) |
14814 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14815 | |
d9b3f62e | 14816 | ALL_TRACEPOINTS (b) |
197f0a60 | 14817 | { |
d9b3f62e | 14818 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
14819 | trace_pass_set_count (t1, count, from_tty); |
14820 | } | |
14821 | } | |
14822 | else if (*args == '\0') | |
1042e4c0 | 14823 | { |
5fa1d40e | 14824 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 14825 | if (t1) |
197f0a60 TT |
14826 | trace_pass_set_count (t1, count, from_tty); |
14827 | } | |
14828 | else | |
14829 | { | |
bfd28288 PA |
14830 | number_or_range_parser parser (args); |
14831 | while (!parser.finished ()) | |
1042e4c0 | 14832 | { |
bfd28288 | 14833 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
14834 | if (t1) |
14835 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14836 | } |
14837 | } | |
1042e4c0 SS |
14838 | } |
14839 | ||
d9b3f62e | 14840 | struct tracepoint * |
1042e4c0 SS |
14841 | get_tracepoint (int num) |
14842 | { | |
14843 | struct breakpoint *t; | |
14844 | ||
14845 | ALL_TRACEPOINTS (t) | |
14846 | if (t->number == num) | |
d9b3f62e | 14847 | return (struct tracepoint *) t; |
1042e4c0 SS |
14848 | |
14849 | return NULL; | |
14850 | } | |
14851 | ||
d5551862 SS |
14852 | /* Find the tracepoint with the given target-side number (which may be |
14853 | different from the tracepoint number after disconnecting and | |
14854 | reconnecting). */ | |
14855 | ||
d9b3f62e | 14856 | struct tracepoint * |
d5551862 SS |
14857 | get_tracepoint_by_number_on_target (int num) |
14858 | { | |
d9b3f62e | 14859 | struct breakpoint *b; |
d5551862 | 14860 | |
d9b3f62e PA |
14861 | ALL_TRACEPOINTS (b) |
14862 | { | |
14863 | struct tracepoint *t = (struct tracepoint *) b; | |
14864 | ||
14865 | if (t->number_on_target == num) | |
14866 | return t; | |
14867 | } | |
d5551862 SS |
14868 | |
14869 | return NULL; | |
14870 | } | |
14871 | ||
1042e4c0 | 14872 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 14873 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
14874 | If the argument is missing, the most recent tracepoint |
14875 | (tracepoint_count) is returned. */ | |
14876 | ||
d9b3f62e | 14877 | struct tracepoint * |
0b39b52e | 14878 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 14879 | number_or_range_parser *parser) |
1042e4c0 | 14880 | { |
1042e4c0 SS |
14881 | struct breakpoint *t; |
14882 | int tpnum; | |
0b39b52e | 14883 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 14884 | |
bfd28288 | 14885 | if (parser != NULL) |
197f0a60 | 14886 | { |
bfd28288 PA |
14887 | gdb_assert (!parser->finished ()); |
14888 | tpnum = parser->get_number (); | |
197f0a60 TT |
14889 | } |
14890 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 14891 | tpnum = tracepoint_count; |
1042e4c0 | 14892 | else |
197f0a60 | 14893 | tpnum = get_number (arg); |
1042e4c0 SS |
14894 | |
14895 | if (tpnum <= 0) | |
14896 | { | |
14897 | if (instring && *instring) | |
14898 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14899 | instring); | |
14900 | else | |
5fa1d40e | 14901 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
14902 | return NULL; |
14903 | } | |
14904 | ||
14905 | ALL_TRACEPOINTS (t) | |
14906 | if (t->number == tpnum) | |
14907 | { | |
d9b3f62e | 14908 | return (struct tracepoint *) t; |
1042e4c0 SS |
14909 | } |
14910 | ||
1042e4c0 SS |
14911 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
14912 | return NULL; | |
14913 | } | |
14914 | ||
d9b3f62e PA |
14915 | void |
14916 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14917 | { | |
14918 | if (b->thread != -1) | |
14919 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14920 | ||
14921 | if (b->task != 0) | |
14922 | fprintf_unfiltered (fp, " task %d", b->task); | |
14923 | ||
14924 | fprintf_unfiltered (fp, "\n"); | |
14925 | } | |
14926 | ||
6149aea9 PA |
14927 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14928 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14929 | on each breakpoint and only include the ones for which it returns | |
14930 | non-zero. */ | |
14931 | ||
1042e4c0 | 14932 | static void |
4495129a | 14933 | save_breakpoints (const char *filename, int from_tty, |
6149aea9 | 14934 | int (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
14935 | { |
14936 | struct breakpoint *tp; | |
6149aea9 | 14937 | int any = 0; |
6149aea9 | 14938 | int extra_trace_bits = 0; |
1042e4c0 | 14939 | |
6149aea9 PA |
14940 | if (filename == 0 || *filename == 0) |
14941 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14942 | |
14943 | /* See if we have anything to save. */ | |
6149aea9 | 14944 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14945 | { |
6149aea9 | 14946 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14947 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
14948 | continue; |
14949 | ||
14950 | /* If we have a filter, only save the breakpoints it accepts. */ | |
14951 | if (filter && !filter (tp)) | |
14952 | continue; | |
14953 | ||
14954 | any = 1; | |
14955 | ||
14956 | if (is_tracepoint (tp)) | |
14957 | { | |
14958 | extra_trace_bits = 1; | |
14959 | ||
14960 | /* We can stop searching. */ | |
14961 | break; | |
14962 | } | |
1042e4c0 | 14963 | } |
6149aea9 PA |
14964 | |
14965 | if (!any) | |
1042e4c0 | 14966 | { |
6149aea9 | 14967 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14968 | return; |
14969 | } | |
14970 | ||
ee0c3293 | 14971 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
14972 | |
14973 | stdio_file fp; | |
14974 | ||
ee0c3293 | 14975 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 14976 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 14977 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 14978 | |
6149aea9 | 14979 | if (extra_trace_bits) |
d7e74731 | 14980 | save_trace_state_variables (&fp); |
8bf6485c | 14981 | |
6149aea9 | 14982 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14983 | { |
6149aea9 | 14984 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14985 | if (!user_breakpoint_p (tp)) |
6149aea9 | 14986 | continue; |
8bf6485c | 14987 | |
6149aea9 PA |
14988 | /* If we have a filter, only save the breakpoints it accepts. */ |
14989 | if (filter && !filter (tp)) | |
14990 | continue; | |
14991 | ||
d7e74731 | 14992 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 14993 | |
6149aea9 PA |
14994 | /* Note, we can't rely on tp->number for anything, as we can't |
14995 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14996 | instead. */ | |
14997 | ||
14998 | if (tp->cond_string) | |
d7e74731 | 14999 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15000 | |
15001 | if (tp->ignore_count) | |
d7e74731 | 15002 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15003 | |
2d9442cc | 15004 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15005 | { |
d7e74731 | 15006 | fp.puts (" commands\n"); |
a7bdde9e | 15007 | |
d7e74731 | 15008 | current_uiout->redirect (&fp); |
a70b8144 | 15009 | try |
1042e4c0 | 15010 | { |
d1b0a7bf | 15011 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 15012 | } |
230d2906 | 15013 | catch (const gdb_exception &ex) |
492d29ea | 15014 | { |
112e8700 | 15015 | current_uiout->redirect (NULL); |
eedc3f4f | 15016 | throw; |
492d29ea | 15017 | } |
1042e4c0 | 15018 | |
112e8700 | 15019 | current_uiout->redirect (NULL); |
d7e74731 | 15020 | fp.puts (" end\n"); |
1042e4c0 | 15021 | } |
6149aea9 PA |
15022 | |
15023 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15024 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15025 | |
15026 | /* If this is a multi-location breakpoint, check if the locations | |
15027 | should be individually disabled. Watchpoint locations are | |
15028 | special, and not user visible. */ | |
15029 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15030 | { | |
15031 | struct bp_location *loc; | |
15032 | int n = 1; | |
15033 | ||
15034 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15035 | if (!loc->enabled) | |
d7e74731 | 15036 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15037 | } |
1042e4c0 | 15038 | } |
8bf6485c | 15039 | |
6149aea9 | 15040 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15041 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15042 | |
1042e4c0 | 15043 | if (from_tty) |
ee0c3293 | 15044 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15045 | } |
15046 | ||
15047 | /* The `save breakpoints' command. */ | |
15048 | ||
15049 | static void | |
4495129a | 15050 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15051 | { |
15052 | save_breakpoints (args, from_tty, NULL); | |
15053 | } | |
15054 | ||
15055 | /* The `save tracepoints' command. */ | |
15056 | ||
15057 | static void | |
4495129a | 15058 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15059 | { |
15060 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15061 | } |
15062 | ||
15063 | /* Create a vector of all tracepoints. */ | |
15064 | ||
f51e0e20 | 15065 | std::vector<breakpoint *> |
eeae04df | 15066 | all_tracepoints (void) |
1042e4c0 | 15067 | { |
f51e0e20 | 15068 | std::vector<breakpoint *> tp_vec; |
1042e4c0 SS |
15069 | struct breakpoint *tp; |
15070 | ||
15071 | ALL_TRACEPOINTS (tp) | |
15072 | { | |
f51e0e20 | 15073 | tp_vec.push_back (tp); |
1042e4c0 SS |
15074 | } |
15075 | ||
15076 | return tp_vec; | |
15077 | } | |
15078 | ||
c906108c | 15079 | \f |
629500fa KS |
15080 | /* This help string is used to consolidate all the help string for specifying |
15081 | locations used by several commands. */ | |
15082 | ||
15083 | #define LOCATION_HELP_STRING \ | |
15084 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15085 | source filename, function name, label name, and line number.\n\ | |
15086 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15087 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15088 | \"factorial.c:fact:the_top\".\n\ | |
15089 | \n\ | |
15090 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15091 | program. Example: To specify the fourth byte past the start function\n\ | |
15092 | \"main\", use \"*main + 4\".\n\ | |
15093 | \n\ | |
15094 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15095 | syntax to specify location parameters.\n\ | |
15096 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15097 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
15098 | -function fact -label the_top\".\n\ |
15099 | \n\ | |
15100 | By default, a specified function is matched against the program's\n\ | |
15101 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
15102 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
15103 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
15104 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 15105 | specified name as a complete fully-qualified name instead." |
629500fa | 15106 | |
4a64f543 MS |
15107 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15108 | commands. It is defined as a macro to prevent duplication. | |
15109 | COMMAND should be a string constant containing the name of the | |
15110 | command. */ | |
629500fa | 15111 | |
31e2b00f | 15112 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15113 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15114 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15115 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15116 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15117 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15118 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15119 | below.\n\ | |
15120 | \n\ | |
dc10affe PA |
15121 | With no LOCATION, uses current execution address of the selected\n\ |
15122 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15123 | \n\ |
15124 | THREADNUM is the number from \"info threads\".\n\ | |
15125 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15126 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15127 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15128 | conditions are different.\n\ | |
31e2b00f AS |
15129 | \n\ |
15130 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15131 | ||
44feb3ce TT |
15132 | /* List of subcommands for "catch". */ |
15133 | static struct cmd_list_element *catch_cmdlist; | |
15134 | ||
15135 | /* List of subcommands for "tcatch". */ | |
15136 | static struct cmd_list_element *tcatch_cmdlist; | |
15137 | ||
9ac4176b | 15138 | void |
a121b7c1 | 15139 | add_catch_command (const char *name, const char *docstring, |
eb4c3f4a | 15140 | cmd_const_sfunc_ftype *sfunc, |
625e8578 | 15141 | completer_ftype *completer, |
44feb3ce TT |
15142 | void *user_data_catch, |
15143 | void *user_data_tcatch) | |
15144 | { | |
15145 | struct cmd_list_element *command; | |
15146 | ||
0450cc4c | 15147 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15148 | &catch_cmdlist); |
15149 | set_cmd_sfunc (command, sfunc); | |
15150 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15151 | set_cmd_completer (command, completer); |
44feb3ce | 15152 | |
0450cc4c | 15153 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15154 | &tcatch_cmdlist); |
15155 | set_cmd_sfunc (command, sfunc); | |
15156 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15157 | set_cmd_completer (command, completer); |
44feb3ce TT |
15158 | } |
15159 | ||
6149aea9 | 15160 | static void |
981a3fb3 | 15161 | save_command (const char *arg, int from_tty) |
6149aea9 | 15162 | { |
3e43a32a MS |
15163 | printf_unfiltered (_("\"save\" must be followed by " |
15164 | "the name of a save subcommand.\n")); | |
635c7e8a | 15165 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15166 | } |
15167 | ||
84f4c1fe PM |
15168 | struct breakpoint * |
15169 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15170 | void *data) | |
15171 | { | |
35df4500 | 15172 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15173 | |
35df4500 | 15174 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15175 | { |
15176 | if ((*callback) (b, data)) | |
15177 | return b; | |
15178 | } | |
15179 | ||
15180 | return NULL; | |
15181 | } | |
15182 | ||
0574c78f GB |
15183 | /* Zero if any of the breakpoint's locations could be a location where |
15184 | functions have been inlined, nonzero otherwise. */ | |
15185 | ||
15186 | static int | |
15187 | is_non_inline_function (struct breakpoint *b) | |
15188 | { | |
15189 | /* The shared library event breakpoint is set on the address of a | |
15190 | non-inline function. */ | |
15191 | if (b->type == bp_shlib_event) | |
15192 | return 1; | |
15193 | ||
15194 | return 0; | |
15195 | } | |
15196 | ||
15197 | /* Nonzero if the specified PC cannot be a location where functions | |
15198 | have been inlined. */ | |
15199 | ||
15200 | int | |
accd0bcd | 15201 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
09ac7c10 | 15202 | const struct target_waitstatus *ws) |
0574c78f GB |
15203 | { |
15204 | struct breakpoint *b; | |
15205 | struct bp_location *bl; | |
15206 | ||
15207 | ALL_BREAKPOINTS (b) | |
15208 | { | |
15209 | if (!is_non_inline_function (b)) | |
15210 | continue; | |
15211 | ||
15212 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15213 | { | |
15214 | if (!bl->shlib_disabled | |
09ac7c10 | 15215 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15216 | return 1; |
15217 | } | |
15218 | } | |
15219 | ||
15220 | return 0; | |
15221 | } | |
15222 | ||
2f202fde JK |
15223 | /* Remove any references to OBJFILE which is going to be freed. */ |
15224 | ||
15225 | void | |
15226 | breakpoint_free_objfile (struct objfile *objfile) | |
15227 | { | |
15228 | struct bp_location **locp, *loc; | |
15229 | ||
15230 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15231 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15232 | loc->symtab = NULL; |
15233 | } | |
15234 | ||
2060206e PA |
15235 | void |
15236 | initialize_breakpoint_ops (void) | |
15237 | { | |
15238 | static int initialized = 0; | |
15239 | ||
15240 | struct breakpoint_ops *ops; | |
15241 | ||
15242 | if (initialized) | |
15243 | return; | |
15244 | initialized = 1; | |
15245 | ||
15246 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15247 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15248 | internal and momentary breakpoints, etc.). */ | |
15249 | ops = &bkpt_base_breakpoint_ops; | |
15250 | *ops = base_breakpoint_ops; | |
15251 | ops->re_set = bkpt_re_set; | |
15252 | ops->insert_location = bkpt_insert_location; | |
15253 | ops->remove_location = bkpt_remove_location; | |
15254 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15255 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15256 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15257 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15258 | |
15259 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15260 | ops = &bkpt_breakpoint_ops; | |
15261 | *ops = bkpt_base_breakpoint_ops; | |
15262 | ops->re_set = bkpt_re_set; | |
15263 | ops->resources_needed = bkpt_resources_needed; | |
15264 | ops->print_it = bkpt_print_it; | |
15265 | ops->print_mention = bkpt_print_mention; | |
15266 | ops->print_recreate = bkpt_print_recreate; | |
15267 | ||
15268 | /* Ranged breakpoints. */ | |
15269 | ops = &ranged_breakpoint_ops; | |
15270 | *ops = bkpt_breakpoint_ops; | |
15271 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15272 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15273 | ops->print_it = print_it_ranged_breakpoint; | |
15274 | ops->print_one = print_one_ranged_breakpoint; | |
15275 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15276 | ops->print_mention = print_mention_ranged_breakpoint; | |
15277 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15278 | ||
15279 | /* Internal breakpoints. */ | |
15280 | ops = &internal_breakpoint_ops; | |
15281 | *ops = bkpt_base_breakpoint_ops; | |
15282 | ops->re_set = internal_bkpt_re_set; | |
15283 | ops->check_status = internal_bkpt_check_status; | |
15284 | ops->print_it = internal_bkpt_print_it; | |
15285 | ops->print_mention = internal_bkpt_print_mention; | |
15286 | ||
15287 | /* Momentary breakpoints. */ | |
15288 | ops = &momentary_breakpoint_ops; | |
15289 | *ops = bkpt_base_breakpoint_ops; | |
15290 | ops->re_set = momentary_bkpt_re_set; | |
15291 | ops->check_status = momentary_bkpt_check_status; | |
15292 | ops->print_it = momentary_bkpt_print_it; | |
15293 | ops->print_mention = momentary_bkpt_print_mention; | |
15294 | ||
55aa24fb SDJ |
15295 | /* Probe breakpoints. */ |
15296 | ops = &bkpt_probe_breakpoint_ops; | |
15297 | *ops = bkpt_breakpoint_ops; | |
15298 | ops->insert_location = bkpt_probe_insert_location; | |
15299 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15300 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15301 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15302 | |
2060206e PA |
15303 | /* Watchpoints. */ |
15304 | ops = &watchpoint_breakpoint_ops; | |
15305 | *ops = base_breakpoint_ops; | |
15306 | ops->re_set = re_set_watchpoint; | |
15307 | ops->insert_location = insert_watchpoint; | |
15308 | ops->remove_location = remove_watchpoint; | |
15309 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15310 | ops->check_status = check_status_watchpoint; | |
15311 | ops->resources_needed = resources_needed_watchpoint; | |
15312 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15313 | ops->print_it = print_it_watchpoint; | |
15314 | ops->print_mention = print_mention_watchpoint; | |
15315 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15316 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15317 | |
15318 | /* Masked watchpoints. */ | |
15319 | ops = &masked_watchpoint_breakpoint_ops; | |
15320 | *ops = watchpoint_breakpoint_ops; | |
15321 | ops->insert_location = insert_masked_watchpoint; | |
15322 | ops->remove_location = remove_masked_watchpoint; | |
15323 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15324 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15325 | ops->print_it = print_it_masked_watchpoint; | |
15326 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15327 | ops->print_mention = print_mention_masked_watchpoint; | |
15328 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15329 | ||
15330 | /* Tracepoints. */ | |
15331 | ops = &tracepoint_breakpoint_ops; | |
15332 | *ops = base_breakpoint_ops; | |
15333 | ops->re_set = tracepoint_re_set; | |
15334 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15335 | ops->print_one_detail = tracepoint_print_one_detail; | |
15336 | ops->print_mention = tracepoint_print_mention; | |
15337 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15338 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15339 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15340 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15341 | |
55aa24fb SDJ |
15342 | /* Probe tracepoints. */ |
15343 | ops = &tracepoint_probe_breakpoint_ops; | |
15344 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15345 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15346 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15347 | |
983af33b SDJ |
15348 | /* Static tracepoints with marker (`-m'). */ |
15349 | ops = &strace_marker_breakpoint_ops; | |
15350 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15351 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15352 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15353 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15354 | |
15355 | /* Fork catchpoints. */ | |
15356 | ops = &catch_fork_breakpoint_ops; | |
15357 | *ops = base_breakpoint_ops; | |
15358 | ops->insert_location = insert_catch_fork; | |
15359 | ops->remove_location = remove_catch_fork; | |
15360 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15361 | ops->print_it = print_it_catch_fork; | |
15362 | ops->print_one = print_one_catch_fork; | |
15363 | ops->print_mention = print_mention_catch_fork; | |
15364 | ops->print_recreate = print_recreate_catch_fork; | |
15365 | ||
15366 | /* Vfork catchpoints. */ | |
15367 | ops = &catch_vfork_breakpoint_ops; | |
15368 | *ops = base_breakpoint_ops; | |
15369 | ops->insert_location = insert_catch_vfork; | |
15370 | ops->remove_location = remove_catch_vfork; | |
15371 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15372 | ops->print_it = print_it_catch_vfork; | |
15373 | ops->print_one = print_one_catch_vfork; | |
15374 | ops->print_mention = print_mention_catch_vfork; | |
15375 | ops->print_recreate = print_recreate_catch_vfork; | |
15376 | ||
15377 | /* Exec catchpoints. */ | |
15378 | ops = &catch_exec_breakpoint_ops; | |
15379 | *ops = base_breakpoint_ops; | |
2060206e PA |
15380 | ops->insert_location = insert_catch_exec; |
15381 | ops->remove_location = remove_catch_exec; | |
15382 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15383 | ops->print_it = print_it_catch_exec; | |
15384 | ops->print_one = print_one_catch_exec; | |
15385 | ops->print_mention = print_mention_catch_exec; | |
15386 | ops->print_recreate = print_recreate_catch_exec; | |
15387 | ||
edcc5120 TT |
15388 | /* Solib-related catchpoints. */ |
15389 | ops = &catch_solib_breakpoint_ops; | |
15390 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15391 | ops->insert_location = insert_catch_solib; |
15392 | ops->remove_location = remove_catch_solib; | |
15393 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15394 | ops->check_status = check_status_catch_solib; | |
15395 | ops->print_it = print_it_catch_solib; | |
15396 | ops->print_one = print_one_catch_solib; | |
15397 | ops->print_mention = print_mention_catch_solib; | |
15398 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15399 | |
15400 | ops = &dprintf_breakpoint_ops; | |
15401 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15402 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15403 | ops->resources_needed = bkpt_resources_needed; |
15404 | ops->print_it = bkpt_print_it; | |
15405 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15406 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15407 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15408 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15409 | } |
15410 | ||
8bfd80db YQ |
15411 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15412 | ||
15413 | static struct cmd_list_element *enablebreaklist = NULL; | |
15414 | ||
8588b356 SM |
15415 | /* See breakpoint.h. */ |
15416 | ||
15417 | cmd_list_element *commands_cmd_element = nullptr; | |
15418 | ||
c906108c | 15419 | void |
fba45db2 | 15420 | _initialize_breakpoint (void) |
c906108c SS |
15421 | { |
15422 | struct cmd_list_element *c; | |
15423 | ||
2060206e PA |
15424 | initialize_breakpoint_ops (); |
15425 | ||
76727919 TT |
15426 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
15427 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); | |
15428 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); | |
84acb35a | 15429 | |
c906108c SS |
15430 | breakpoint_chain = 0; |
15431 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15432 | before a breakpoint is set. */ | |
15433 | breakpoint_count = 0; | |
15434 | ||
1042e4c0 SS |
15435 | tracepoint_count = 0; |
15436 | ||
1bedd215 AC |
15437 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15438 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15439 | Usage is `ignore N COUNT'.")); | |
c906108c | 15440 | |
8588b356 SM |
15441 | commands_cmd_element = add_com ("commands", class_breakpoint, |
15442 | commands_command, _("\ | |
18da0c51 MG |
15443 | Set commands to be executed when the given breakpoints are hit.\n\ |
15444 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15445 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15446 | (e.g. `5-7').\n\ | |
c906108c SS |
15447 | With no argument, the targeted breakpoint is the last one set.\n\ |
15448 | The commands themselves follow starting on the next line.\n\ | |
15449 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15450 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15451 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15452 | |
d55637df | 15453 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15454 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15455 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15456 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15457 | set_cmd_completer (c, condition_completer); |
c906108c | 15458 | |
1bedd215 | 15459 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15460 | Set a temporary breakpoint.\n\ |
c906108c SS |
15461 | Like \"break\" except the breakpoint is only temporary,\n\ |
15462 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15463 | by using \"enable delete\" on the breakpoint number.\n\ |
15464 | \n" | |
15465 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15466 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15467 | |
1bedd215 | 15468 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15469 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15470 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15471 | some target hardware may not have this support.\n\ |
15472 | \n" | |
15473 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15474 | set_cmd_completer (c, location_completer); |
c906108c | 15475 | |
1bedd215 | 15476 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15477 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15478 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15479 | so it will be deleted when hit.\n\ |
15480 | \n" | |
15481 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15482 | set_cmd_completer (c, location_completer); |
c906108c | 15483 | |
1bedd215 AC |
15484 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15485 | Enable some breakpoints.\n\ | |
c906108c SS |
15486 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15487 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15488 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15489 | With a subcommand you can enable temporarily."), |
c906108c | 15490 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15491 | |
15492 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15493 | ||
84951ab5 | 15494 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15495 | Enable some breakpoints.\n\ |
c906108c SS |
15496 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15497 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 15498 | May be abbreviated to simply \"enable\"."), |
c5aa993b | 15499 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15500 | |
1a966eab AC |
15501 | add_cmd ("once", no_class, enable_once_command, _("\ |
15502 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15503 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15504 | &enablebreaklist); |
15505 | ||
1a966eab AC |
15506 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15507 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15508 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15509 | &enablebreaklist); |
15510 | ||
816338b5 SS |
15511 | add_cmd ("count", no_class, enable_count_command, _("\ |
15512 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15513 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15514 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15515 | &enablebreaklist); | |
15516 | ||
1a966eab AC |
15517 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15518 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15519 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15520 | &enablelist); |
15521 | ||
1a966eab AC |
15522 | add_cmd ("once", no_class, enable_once_command, _("\ |
15523 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15524 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15525 | &enablelist); |
15526 | ||
15527 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15528 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15529 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15530 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15531 | &enablelist); |
15532 | ||
1bedd215 AC |
15533 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15534 | Disable some breakpoints.\n\ | |
c906108c SS |
15535 | Arguments are breakpoint numbers with spaces in between.\n\ |
15536 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15537 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15538 | &disablelist, "disable ", 1, &cmdlist); |
15539 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15540 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15541 | |
1a966eab AC |
15542 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15543 | Disable some breakpoints.\n\ | |
c906108c SS |
15544 | Arguments are breakpoint numbers with spaces in between.\n\ |
15545 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15546 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15547 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15548 | &disablelist); |
15549 | ||
1bedd215 AC |
15550 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15551 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15552 | Arguments are breakpoint numbers with spaces in between.\n\ |
15553 | To delete all breakpoints, give no argument.\n\ | |
15554 | \n\ | |
15555 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15556 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15557 | &deletelist, "delete ", 1, &cmdlist); |
15558 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15559 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15560 | |
1a966eab AC |
15561 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15562 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15563 | Arguments are breakpoint numbers with spaces in between.\n\ |
15564 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15565 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15566 | &deletelist); |
15567 | ||
1bedd215 | 15568 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15569 | Clear breakpoint at specified location.\n\ |
15570 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15571 | \n\ |
15572 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 15573 | is executing in.\n" |
89549d7f | 15574 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 15575 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15576 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15577 | |
1bedd215 | 15578 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15579 | Set breakpoint at specified location.\n" |
31e2b00f | 15580 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15581 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15582 | |
c906108c SS |
15583 | add_com_alias ("b", "break", class_run, 1); |
15584 | add_com_alias ("br", "break", class_run, 1); | |
15585 | add_com_alias ("bre", "break", class_run, 1); | |
15586 | add_com_alias ("brea", "break", class_run, 1); | |
15587 | ||
c906108c SS |
15588 | if (dbx_commands) |
15589 | { | |
1bedd215 AC |
15590 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15591 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15592 | &stoplist, "stop ", 1, &cmdlist); |
15593 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15594 | _("Break in function or address."), &stoplist); |
c5aa993b | 15595 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15596 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15597 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15598 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15599 | The \"Type\" column indicates one of:\n\ |
15600 | \tbreakpoint - normal breakpoint\n\ | |
15601 | \twatchpoint - watchpoint\n\ | |
15602 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15603 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15604 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15605 | address and file/line number respectively.\n\ |
15606 | \n\ | |
15607 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15608 | are set to the address of the last breakpoint listed unless the command\n\ |
15609 | is prefixed with \"server \".\n\n\ | |
c906108c | 15610 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15611 | breakpoint set.")); |
c906108c SS |
15612 | } |
15613 | ||
11db9430 | 15614 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15615 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15616 | The \"Type\" column indicates one of:\n\ |
15617 | \tbreakpoint - normal breakpoint\n\ | |
15618 | \twatchpoint - watchpoint\n\ | |
15619 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15620 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15621 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15622 | address and file/line number respectively.\n\ |
15623 | \n\ | |
15624 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15625 | are set to the address of the last breakpoint listed unless the command\n\ |
15626 | is prefixed with \"server \".\n\n\ | |
c906108c | 15627 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15628 | breakpoint set.")); |
c906108c | 15629 | |
6b04bdb7 MS |
15630 | add_info_alias ("b", "breakpoints", 1); |
15631 | ||
1a966eab AC |
15632 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15633 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15634 | The \"Type\" column indicates one of:\n\ |
15635 | \tbreakpoint - normal breakpoint\n\ | |
15636 | \twatchpoint - watchpoint\n\ | |
15637 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15638 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15639 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15640 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15641 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15642 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15643 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15644 | address and file/line number respectively.\n\ |
15645 | \n\ | |
15646 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15647 | are set to the address of the last breakpoint listed unless the command\n\ |
15648 | is prefixed with \"server \".\n\n\ | |
c906108c | 15649 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15650 | breakpoint set."), |
c906108c SS |
15651 | &maintenanceinfolist); |
15652 | ||
44feb3ce TT |
15653 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15654 | Set catchpoints to catch events."), | |
15655 | &catch_cmdlist, "catch ", | |
15656 | 0/*allow-unknown*/, &cmdlist); | |
15657 | ||
15658 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15659 | Set temporary catchpoints to catch events."), | |
15660 | &tcatch_cmdlist, "tcatch ", | |
15661 | 0/*allow-unknown*/, &cmdlist); | |
15662 | ||
44feb3ce TT |
15663 | add_catch_command ("fork", _("Catch calls to fork."), |
15664 | catch_fork_command_1, | |
a96d9b2e | 15665 | NULL, |
44feb3ce TT |
15666 | (void *) (uintptr_t) catch_fork_permanent, |
15667 | (void *) (uintptr_t) catch_fork_temporary); | |
15668 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15669 | catch_fork_command_1, | |
a96d9b2e | 15670 | NULL, |
44feb3ce TT |
15671 | (void *) (uintptr_t) catch_vfork_permanent, |
15672 | (void *) (uintptr_t) catch_vfork_temporary); | |
15673 | add_catch_command ("exec", _("Catch calls to exec."), | |
15674 | catch_exec_command_1, | |
a96d9b2e SDJ |
15675 | NULL, |
15676 | CATCH_PERMANENT, | |
15677 | CATCH_TEMPORARY); | |
edcc5120 TT |
15678 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15679 | Usage: catch load [REGEX]\n\ | |
15680 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15681 | catch_load_command_1, | |
15682 | NULL, | |
15683 | CATCH_PERMANENT, | |
15684 | CATCH_TEMPORARY); | |
15685 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15686 | Usage: catch unload [REGEX]\n\ | |
15687 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15688 | catch_unload_command_1, | |
15689 | NULL, | |
15690 | CATCH_PERMANENT, | |
15691 | CATCH_TEMPORARY); | |
c5aa993b | 15692 | |
1bedd215 AC |
15693 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15694 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15695 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15696 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15697 | an expression changes.\n\ |
15698 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15699 | the memory to which it refers.")); | |
65d12d83 | 15700 | set_cmd_completer (c, expression_completer); |
c906108c | 15701 | |
1bedd215 AC |
15702 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15703 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15704 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15705 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15706 | an expression is read.\n\ |
15707 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15708 | the memory to which it refers.")); | |
65d12d83 | 15709 | set_cmd_completer (c, expression_completer); |
c906108c | 15710 | |
1bedd215 AC |
15711 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15712 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15713 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15714 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15715 | an expression is either read or written.\n\ |
15716 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15717 | the memory to which it refers.")); | |
65d12d83 | 15718 | set_cmd_completer (c, expression_completer); |
c906108c | 15719 | |
11db9430 | 15720 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15721 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15722 | |
920d2a44 AC |
15723 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15724 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15725 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15726 | &can_use_hw_watchpoints, _("\ | |
15727 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15728 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15729 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15730 | such is available. (However, any hardware watchpoints that were\n\ | |
15731 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15732 | hardware.)"), |
15733 | NULL, | |
920d2a44 | 15734 | show_can_use_hw_watchpoints, |
85c07804 | 15735 | &setlist, &showlist); |
c906108c SS |
15736 | |
15737 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15738 | |
1042e4c0 SS |
15739 | /* Tracepoint manipulation commands. */ |
15740 | ||
15741 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15742 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15743 | \n" |
15744 | BREAK_ARGS_HELP ("trace") "\n\ | |
15745 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15746 | set_cmd_completer (c, location_completer); | |
15747 | ||
15748 | add_com_alias ("tp", "trace", class_alias, 0); | |
15749 | add_com_alias ("tr", "trace", class_alias, 1); | |
15750 | add_com_alias ("tra", "trace", class_alias, 1); | |
15751 | add_com_alias ("trac", "trace", class_alias, 1); | |
15752 | ||
7a697b8d | 15753 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15754 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15755 | \n" |
15756 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15757 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15758 | set_cmd_completer (c, location_completer); | |
15759 | ||
0fb4aa4b | 15760 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15761 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15762 | \n\ |
15763 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15764 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15765 | or -m MARKER_ID.\n\n\ | |
15766 | If a marker id is specified, probe the marker with that name. With\n\ | |
15767 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15768 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15769 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15770 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15771 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15772 | \n\ | |
15773 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15774 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15775 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15776 | conditions are different.\n\ | |
0fb4aa4b PA |
15777 | \n\ |
15778 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15779 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15780 | set_cmd_completer (c, location_completer); | |
15781 | ||
11db9430 | 15782 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 15783 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15784 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15785 | last tracepoint set.")); | |
15786 | ||
15787 | add_info_alias ("tp", "tracepoints", 1); | |
15788 | ||
15789 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15790 | Delete specified tracepoints.\n\ | |
15791 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15792 | No argument means delete all tracepoints."), | |
15793 | &deletelist); | |
7e20dfcd | 15794 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
15795 | |
15796 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15797 | Disable specified tracepoints.\n\ | |
15798 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15799 | No argument means disable all tracepoints."), | |
15800 | &disablelist); | |
15801 | deprecate_cmd (c, "disable"); | |
15802 | ||
15803 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15804 | Enable specified tracepoints.\n\ | |
15805 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15806 | No argument means enable all tracepoints."), | |
15807 | &enablelist); | |
15808 | deprecate_cmd (c, "enable"); | |
15809 | ||
15810 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15811 | Set the passcount for a tracepoint.\n\ | |
15812 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15813 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15814 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15815 | ||
6149aea9 PA |
15816 | add_prefix_cmd ("save", class_breakpoint, save_command, |
15817 | _("Save breakpoint definitions as a script."), | |
15818 | &save_cmdlist, "save ", | |
15819 | 0/*allow-unknown*/, &cmdlist); | |
15820 | ||
15821 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15822 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15823 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15824 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15825 | session to restore them."), | |
15826 | &save_cmdlist); | |
15827 | set_cmd_completer (c, filename_completer); | |
15828 | ||
15829 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15830 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15831 | Use the 'source' command in another debug session to restore them."), |
15832 | &save_cmdlist); | |
1042e4c0 SS |
15833 | set_cmd_completer (c, filename_completer); |
15834 | ||
6149aea9 PA |
15835 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
15836 | deprecate_cmd (c, "save tracepoints"); | |
15837 | ||
1bedd215 | 15838 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
15839 | Breakpoint specific settings\n\ |
15840 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 15841 | pending breakpoint behavior"), |
fa8d40ab JJ |
15842 | &breakpoint_set_cmdlist, "set breakpoint ", |
15843 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 15844 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
15845 | Breakpoint specific settings\n\ |
15846 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 15847 | pending breakpoint behavior"), |
fa8d40ab JJ |
15848 | &breakpoint_show_cmdlist, "show breakpoint ", |
15849 | 0/*allow-unknown*/, &showlist); | |
15850 | ||
7915a72c AC |
15851 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15852 | &pending_break_support, _("\ | |
15853 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15854 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15855 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15856 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15857 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15858 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15859 | NULL, |
920d2a44 | 15860 | show_pending_break_support, |
6e1d7d6c AC |
15861 | &breakpoint_set_cmdlist, |
15862 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15863 | |
15864 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15865 | |
15866 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15867 | &automatic_hardware_breakpoints, _("\ | |
15868 | Set automatic usage of hardware breakpoints."), _("\ | |
15869 | Show automatic usage of hardware breakpoints."), _("\ | |
15870 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15871 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15872 | a warning will be emitted for such breakpoints."), | |
15873 | NULL, | |
15874 | show_automatic_hardware_breakpoints, | |
15875 | &breakpoint_set_cmdlist, | |
15876 | &breakpoint_show_cmdlist); | |
74960c60 | 15877 | |
a25a5a45 PA |
15878 | add_setshow_boolean_cmd ("always-inserted", class_support, |
15879 | &always_inserted_mode, _("\ | |
74960c60 VP |
15880 | Set mode for inserting breakpoints."), _("\ |
15881 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
15882 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
15883 | they're created, kept inserted even when execution stops, and removed\n\ | |
15884 | only when the user deletes them. When this mode is off (the default),\n\ | |
15885 | breakpoints are inserted only when execution continues, and removed\n\ | |
15886 | when execution stops."), | |
72d0e2c5 YQ |
15887 | NULL, |
15888 | &show_always_inserted_mode, | |
15889 | &breakpoint_set_cmdlist, | |
15890 | &breakpoint_show_cmdlist); | |
f1310107 | 15891 | |
b775012e LM |
15892 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15893 | condition_evaluation_enums, | |
15894 | &condition_evaluation_mode_1, _("\ | |
15895 | Set mode of breakpoint condition evaluation."), _("\ | |
15896 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 15897 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
15898 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
15899 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15900 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15901 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15902 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
15903 | be set to \"gdb\""), | |
15904 | &set_condition_evaluation_mode, | |
15905 | &show_condition_evaluation_mode, | |
15906 | &breakpoint_set_cmdlist, | |
15907 | &breakpoint_show_cmdlist); | |
15908 | ||
f1310107 TJB |
15909 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15910 | Set a breakpoint for an address range.\n\ | |
15911 | break-range START-LOCATION, END-LOCATION\n\ | |
15912 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15913 | LINENUM, for that line in the current file,\n\ | |
15914 | FILE:LINENUM, for that line in that file,\n\ | |
15915 | +OFFSET, for that number of lines after the current line\n\ | |
15916 | or the start of the range\n\ | |
15917 | FUNCTION, for the first line in that function,\n\ | |
15918 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15919 | *ADDRESS, for the instruction at that address.\n\ | |
15920 | \n\ | |
15921 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15922 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15923 | range (including START-LOCATION and END-LOCATION).")); | |
15924 | ||
e7e0cddf | 15925 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 15926 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 15927 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
15928 | location may be a linespec, explicit, or address location.\n" |
15929 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
15930 | set_cmd_completer (c, location_completer); |
15931 | ||
15932 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
15933 | dprintf_style_enums, &dprintf_style, _("\ | |
15934 | Set the style of usage for dynamic printf."), _("\ | |
15935 | Show the style of usage for dynamic printf."), _("\ | |
15936 | This setting chooses how GDB will do a dynamic printf.\n\ | |
15937 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
15938 | console, as with the \"printf\" command.\n\ | |
15939 | If the value is \"call\", the print is done by calling a function in your\n\ | |
15940 | program; by default printf(), but you can choose a different function or\n\ | |
15941 | output stream by setting dprintf-function and dprintf-channel."), | |
15942 | update_dprintf_commands, NULL, | |
15943 | &setlist, &showlist); | |
15944 | ||
15945 | dprintf_function = xstrdup ("printf"); | |
15946 | add_setshow_string_cmd ("dprintf-function", class_support, | |
15947 | &dprintf_function, _("\ | |
15948 | Set the function to use for dynamic printf"), _("\ | |
15949 | Show the function to use for dynamic printf"), NULL, | |
15950 | update_dprintf_commands, NULL, | |
15951 | &setlist, &showlist); | |
15952 | ||
15953 | dprintf_channel = xstrdup (""); | |
15954 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
15955 | &dprintf_channel, _("\ | |
15956 | Set the channel to use for dynamic printf"), _("\ | |
15957 | Show the channel to use for dynamic printf"), NULL, | |
15958 | update_dprintf_commands, NULL, | |
15959 | &setlist, &showlist); | |
15960 | ||
d3ce09f5 SS |
15961 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
15962 | &disconnected_dprintf, _("\ | |
15963 | Set whether dprintf continues after GDB disconnects."), _("\ | |
15964 | Show whether dprintf continues after GDB disconnects."), _("\ | |
15965 | Use this to let dprintf commands continue to hit and produce output\n\ | |
15966 | even if GDB disconnects or detaches from the target."), | |
15967 | NULL, | |
15968 | NULL, | |
15969 | &setlist, &showlist); | |
15970 | ||
15971 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
15972 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
15973 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
15974 | ||
765dc015 | 15975 | automatic_hardware_breakpoints = 1; |
f3b1572e | 15976 | |
76727919 TT |
15977 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
15978 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); | |
c906108c | 15979 | } |