Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
b811d2c2 | 3 | Copyright (C) 1986-2020 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
d55e5aa6 | 21 | #include "arch-utils.h" |
4de283e4 TT |
22 | #include <ctype.h> |
23 | #include "hashtab.h" | |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
c906108c | 26 | #include "breakpoint.h" |
4de283e4 TT |
27 | #include "tracepoint.h" |
28 | #include "gdbtypes.h" | |
c906108c | 29 | #include "expression.h" |
d55e5aa6 | 30 | #include "gdbcore.h" |
4de283e4 TT |
31 | #include "gdbcmd.h" |
32 | #include "value.h" | |
33 | #include "command.h" | |
c906108c | 34 | #include "inferior.h" |
45741a9c | 35 | #include "infrun.h" |
4de283e4 TT |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
c906108c | 38 | #include "language.h" |
4de283e4 TT |
39 | #include "gdb-demangle.h" |
40 | #include "filenames.h" | |
41 | #include "annotate.h" | |
42 | #include "symfile.h" | |
d55e5aa6 | 43 | #include "objfiles.h" |
4de283e4 TT |
44 | #include "source.h" |
45 | #include "linespec.h" | |
46 | #include "completer.h" | |
47 | #include "ui-out.h" | |
48 | #include "cli/cli-script.h" | |
49 | #include "block.h" | |
50 | #include "solib.h" | |
51 | #include "solist.h" | |
d55e5aa6 | 52 | #include "observable.h" |
4de283e4 TT |
53 | #include "memattr.h" |
54 | #include "ada-lang.h" | |
55 | #include "top.h" | |
56 | #include "valprint.h" | |
57 | #include "jit.h" | |
65d79d4b | 58 | #include "parser-defs.h" |
4de283e4 | 59 | #include "gdb_regex.h" |
55aa24fb | 60 | #include "probe.h" |
4de283e4 | 61 | #include "cli/cli-utils.h" |
d55e5aa6 | 62 | #include "stack.h" |
4de283e4 TT |
63 | #include "ax-gdb.h" |
64 | #include "dummy-frame.h" | |
65 | #include "interps.h" | |
268a13a5 | 66 | #include "gdbsupport/format.h" |
cfc31633 | 67 | #include "thread-fsm.h" |
5d5658a1 | 68 | #include "tid-parse.h" |
4de283e4 | 69 | #include "cli/cli-style.h" |
d3ce09f5 | 70 | |
1042e4c0 | 71 | /* readline include files */ |
073bbbb0 | 72 | #include "readline/tilde.h" |
1042e4c0 SS |
73 | |
74 | /* readline defines this. */ | |
75 | #undef savestring | |
76 | ||
034dad6f | 77 | #include "mi/mi-common.h" |
6dddc817 | 78 | #include "extension.h" |
325fac50 | 79 | #include <algorithm> |
5ed8105e | 80 | #include "progspace-and-thread.h" |
268a13a5 TT |
81 | #include "gdbsupport/array-view.h" |
82 | #include "gdbsupport/gdb_optional.h" | |
104c1213 | 83 | |
4a64f543 | 84 | /* Prototypes for local functions. */ |
c906108c | 85 | |
896b6bda | 86 | static void map_breakpoint_numbers (const char *, |
48649e1b | 87 | gdb::function_view<void (breakpoint *)>); |
c906108c | 88 | |
348d480f PA |
89 | static void breakpoint_re_set_default (struct breakpoint *); |
90 | ||
f00aae0f KS |
91 | static void |
92 | create_sals_from_location_default (const struct event_location *location, | |
93 | struct linespec_result *canonical, | |
94 | enum bptype type_wanted); | |
983af33b SDJ |
95 | |
96 | static void create_breakpoints_sal_default (struct gdbarch *, | |
97 | struct linespec_result *, | |
e1e01040 PA |
98 | gdb::unique_xmalloc_ptr<char>, |
99 | gdb::unique_xmalloc_ptr<char>, | |
100 | enum bptype, | |
983af33b SDJ |
101 | enum bpdisp, int, int, |
102 | int, | |
103 | const struct breakpoint_ops *, | |
44f238bb | 104 | int, int, int, unsigned); |
983af33b | 105 | |
6c5b2ebe PA |
106 | static std::vector<symtab_and_line> decode_location_default |
107 | (struct breakpoint *b, const struct event_location *location, | |
108 | struct program_space *search_pspace); | |
983af33b | 109 | |
a6535de1 TT |
110 | static int can_use_hardware_watchpoint |
111 | (const std::vector<value_ref_ptr> &vals); | |
c906108c | 112 | |
a14ed312 | 113 | static void mention (struct breakpoint *); |
c906108c | 114 | |
348d480f PA |
115 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
116 | enum bptype, | |
c0a91b2b | 117 | const struct breakpoint_ops *); |
3742cc8b YQ |
118 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
119 | const struct symtab_and_line *); | |
120 | ||
4a64f543 MS |
121 | /* This function is used in gdbtk sources and thus can not be made |
122 | static. */ | |
63c252f8 | 123 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 124 | struct symtab_and_line, |
c0a91b2b TT |
125 | enum bptype, |
126 | const struct breakpoint_ops *); | |
c906108c | 127 | |
06edf0c0 PA |
128 | static struct breakpoint * |
129 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
130 | enum bptype type, | |
a1aa2221 LM |
131 | const struct breakpoint_ops *ops, |
132 | int loc_enabled); | |
06edf0c0 | 133 | |
76897487 KB |
134 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
135 | ||
a6d9a66e UW |
136 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
137 | CORE_ADDR bpaddr, | |
88f7da05 | 138 | enum bptype bptype); |
76897487 | 139 | |
6c95b8df PA |
140 | static void describe_other_breakpoints (struct gdbarch *, |
141 | struct program_space *, CORE_ADDR, | |
5af949e3 | 142 | struct obj_section *, int); |
c906108c | 143 | |
85d721b8 PA |
144 | static int watchpoint_locations_match (struct bp_location *loc1, |
145 | struct bp_location *loc2); | |
146 | ||
f1310107 | 147 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 148 | const struct address_space *aspace, |
f1310107 TJB |
149 | CORE_ADDR addr); |
150 | ||
d35ae833 | 151 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 152 | const address_space *, |
d35ae833 PA |
153 | CORE_ADDR, int); |
154 | ||
834c0d03 | 155 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 156 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 157 | |
e514a9d6 | 158 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 159 | |
a14ed312 | 160 | static int hw_breakpoint_used_count (void); |
c906108c | 161 | |
a1398e0c PA |
162 | static int hw_watchpoint_use_count (struct breakpoint *); |
163 | ||
164 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
165 | enum bptype type, | |
166 | int *other_type_used); | |
c906108c | 167 | |
816338b5 SS |
168 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
169 | int count); | |
c906108c | 170 | |
fe3f5fa8 | 171 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
172 | static void incref_bp_location (struct bp_location *loc); |
173 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 174 | |
39d61571 | 175 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 176 | |
44702360 PA |
177 | /* update_global_location_list's modes of operation wrt to whether to |
178 | insert locations now. */ | |
179 | enum ugll_insert_mode | |
180 | { | |
181 | /* Don't insert any breakpoint locations into the inferior, only | |
182 | remove already-inserted locations that no longer should be | |
183 | inserted. Functions that delete a breakpoint or breakpoints | |
184 | should specify this mode, so that deleting a breakpoint doesn't | |
185 | have the side effect of inserting the locations of other | |
186 | breakpoints that are marked not-inserted, but should_be_inserted | |
187 | returns true on them. | |
188 | ||
189 | This behavior is useful is situations close to tear-down -- e.g., | |
190 | after an exec, while the target still has execution, but | |
191 | breakpoint shadows of the previous executable image should *NOT* | |
192 | be restored to the new image; or before detaching, where the | |
193 | target still has execution and wants to delete breakpoints from | |
194 | GDB's lists, and all breakpoints had already been removed from | |
195 | the inferior. */ | |
196 | UGLL_DONT_INSERT, | |
197 | ||
a25a5a45 PA |
198 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
199 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
200 | UGLL_MAY_INSERT, |
201 | ||
a25a5a45 PA |
202 | /* Insert locations now, irrespective of |
203 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
204 | stopped right now, and the user did "continue". We need to | |
205 | insert breakpoints _before_ resuming the target, but | |
206 | UGLL_MAY_INSERT wouldn't insert them, because | |
207 | breakpoints_should_be_inserted_now returns false at that point, | |
208 | as no thread is running yet. */ | |
04086b45 | 209 | UGLL_INSERT |
44702360 PA |
210 | }; |
211 | ||
212 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 213 | |
44702360 | 214 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 215 | |
74960c60 | 216 | static void insert_breakpoint_locations (void); |
a5606eee | 217 | |
0b39b52e | 218 | static void trace_pass_command (const char *, int); |
1042e4c0 | 219 | |
558a9d82 YQ |
220 | static void set_tracepoint_count (int num); |
221 | ||
f2478a7e | 222 | static bool is_masked_watchpoint (const struct breakpoint *b); |
9c06b0b4 | 223 | |
b775012e LM |
224 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
225 | ||
983af33b SDJ |
226 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
227 | otherwise. */ | |
228 | ||
229 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 230 | |
2060206e PA |
231 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
232 | that are implemented on top of software or hardware breakpoints | |
233 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
234 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
235 | ||
236 | /* Internal breakpoints class type. */ | |
06edf0c0 | 237 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
238 | |
239 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
240 | static struct breakpoint_ops momentary_breakpoint_ops; |
241 | ||
2060206e PA |
242 | /* The breakpoint_ops structure to be used in regular user created |
243 | breakpoints. */ | |
244 | struct breakpoint_ops bkpt_breakpoint_ops; | |
245 | ||
55aa24fb SDJ |
246 | /* Breakpoints set on probes. */ |
247 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
248 | ||
bac7c5cf GB |
249 | /* Tracepoints set on probes. */ |
250 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
251 | ||
e7e0cddf | 252 | /* Dynamic printf class type. */ |
c5867ab6 | 253 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 254 | |
d3ce09f5 SS |
255 | /* The style in which to perform a dynamic printf. This is a user |
256 | option because different output options have different tradeoffs; | |
257 | if GDB does the printing, there is better error handling if there | |
258 | is a problem with any of the arguments, but using an inferior | |
259 | function lets you have special-purpose printers and sending of | |
260 | output to the same place as compiled-in print functions. */ | |
261 | ||
262 | static const char dprintf_style_gdb[] = "gdb"; | |
263 | static const char dprintf_style_call[] = "call"; | |
264 | static const char dprintf_style_agent[] = "agent"; | |
265 | static const char *const dprintf_style_enums[] = { | |
266 | dprintf_style_gdb, | |
267 | dprintf_style_call, | |
268 | dprintf_style_agent, | |
269 | NULL | |
270 | }; | |
271 | static const char *dprintf_style = dprintf_style_gdb; | |
272 | ||
273 | /* The function to use for dynamic printf if the preferred style is to | |
274 | call into the inferior. The value is simply a string that is | |
275 | copied into the command, so it can be anything that GDB can | |
276 | evaluate to a callable address, not necessarily a function name. */ | |
277 | ||
bde6261a | 278 | static char *dprintf_function; |
d3ce09f5 SS |
279 | |
280 | /* The channel to use for dynamic printf if the preferred style is to | |
281 | call into the inferior; if a nonempty string, it will be passed to | |
282 | the call as the first argument, with the format string as the | |
283 | second. As with the dprintf function, this can be anything that | |
284 | GDB knows how to evaluate, so in addition to common choices like | |
285 | "stderr", this could be an app-specific expression like | |
286 | "mystreams[curlogger]". */ | |
287 | ||
bde6261a | 288 | static char *dprintf_channel; |
d3ce09f5 SS |
289 | |
290 | /* True if dprintf commands should continue to operate even if GDB | |
291 | has disconnected. */ | |
491144b5 | 292 | static bool disconnected_dprintf = true; |
d3ce09f5 | 293 | |
5cea2a26 PA |
294 | struct command_line * |
295 | breakpoint_commands (struct breakpoint *b) | |
296 | { | |
d1b0a7bf | 297 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 298 | } |
3daf8fe5 | 299 | |
f3b1572e PA |
300 | /* Flag indicating that a command has proceeded the inferior past the |
301 | current breakpoint. */ | |
302 | ||
491144b5 | 303 | static bool breakpoint_proceeded; |
f3b1572e | 304 | |
956a9fb9 | 305 | const char * |
2cec12e5 AR |
306 | bpdisp_text (enum bpdisp disp) |
307 | { | |
4a64f543 MS |
308 | /* NOTE: the following values are a part of MI protocol and |
309 | represent values of 'disp' field returned when inferior stops at | |
310 | a breakpoint. */ | |
bc043ef3 | 311 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 312 | |
2cec12e5 AR |
313 | return bpdisps[(int) disp]; |
314 | } | |
c906108c | 315 | |
4a64f543 | 316 | /* Prototypes for exported functions. */ |
c906108c | 317 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 318 | if such is available. */ |
c906108c SS |
319 | static int can_use_hw_watchpoints; |
320 | ||
920d2a44 AC |
321 | static void |
322 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
323 | struct cmd_list_element *c, | |
324 | const char *value) | |
325 | { | |
3e43a32a MS |
326 | fprintf_filtered (file, |
327 | _("Debugger's willingness to use " | |
328 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
329 | value); |
330 | } | |
331 | ||
fa8d40ab JJ |
332 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
333 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 334 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
335 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
336 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
337 | static void |
338 | show_pending_break_support (struct ui_file *file, int from_tty, | |
339 | struct cmd_list_element *c, | |
340 | const char *value) | |
341 | { | |
3e43a32a MS |
342 | fprintf_filtered (file, |
343 | _("Debugger's behavior regarding " | |
344 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
345 | value); |
346 | } | |
fa8d40ab | 347 | |
491144b5 | 348 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 349 | set with "break" but falling in read-only memory. |
491144b5 | 350 | If false, gdb will warn about such breakpoints, but won't automatically |
765dc015 | 351 | use hardware breakpoints. */ |
491144b5 | 352 | static bool automatic_hardware_breakpoints; |
765dc015 VP |
353 | static void |
354 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
355 | struct cmd_list_element *c, | |
356 | const char *value) | |
357 | { | |
3e43a32a MS |
358 | fprintf_filtered (file, |
359 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
360 | value); |
361 | } | |
362 | ||
a25a5a45 PA |
363 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
364 | stopped, and immediately inserts any new breakpoints as soon as | |
365 | they're created. If off (default), GDB keeps breakpoints off of | |
366 | the target as long as possible. That is, it delays inserting | |
367 | breakpoints until the next resume, and removes them again when the | |
368 | target fully stops. This is a bit safer in case GDB crashes while | |
369 | processing user input. */ | |
491144b5 | 370 | static bool always_inserted_mode = false; |
72d0e2c5 | 371 | |
33e5cbd6 | 372 | static void |
74960c60 | 373 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 374 | struct cmd_list_element *c, const char *value) |
74960c60 | 375 | { |
a25a5a45 PA |
376 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
377 | value); | |
74960c60 VP |
378 | } |
379 | ||
b57bacec PA |
380 | /* See breakpoint.h. */ |
381 | ||
33e5cbd6 | 382 | int |
a25a5a45 | 383 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 384 | { |
a25a5a45 PA |
385 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
386 | { | |
387 | /* If breakpoints are global, they should be inserted even if no | |
388 | thread under gdb's control is running, or even if there are | |
389 | no threads under GDB's control yet. */ | |
390 | return 1; | |
391 | } | |
5b6d1e4f | 392 | else |
a25a5a45 | 393 | { |
a25a5a45 PA |
394 | if (always_inserted_mode) |
395 | { | |
396 | /* The user wants breakpoints inserted even if all threads | |
397 | are stopped. */ | |
398 | return 1; | |
399 | } | |
400 | ||
5b6d1e4f PA |
401 | for (inferior *inf : all_inferiors ()) |
402 | if (inf->has_execution () | |
403 | && threads_are_executing (inf->process_target ())) | |
404 | return 1; | |
372316f1 PA |
405 | |
406 | /* Don't remove breakpoints yet if, even though all threads are | |
407 | stopped, we still have events to process. */ | |
08036331 | 408 | for (thread_info *tp : all_non_exited_threads ()) |
372316f1 PA |
409 | if (tp->resumed |
410 | && tp->suspend.waitstatus_pending_p) | |
411 | return 1; | |
a25a5a45 PA |
412 | } |
413 | return 0; | |
33e5cbd6 | 414 | } |
765dc015 | 415 | |
b775012e LM |
416 | static const char condition_evaluation_both[] = "host or target"; |
417 | ||
418 | /* Modes for breakpoint condition evaluation. */ | |
419 | static const char condition_evaluation_auto[] = "auto"; | |
420 | static const char condition_evaluation_host[] = "host"; | |
421 | static const char condition_evaluation_target[] = "target"; | |
422 | static const char *const condition_evaluation_enums[] = { | |
423 | condition_evaluation_auto, | |
424 | condition_evaluation_host, | |
425 | condition_evaluation_target, | |
426 | NULL | |
427 | }; | |
428 | ||
429 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
430 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
431 | ||
432 | /* Global that we use to display information to the user (gets its value from | |
433 | condition_evaluation_mode_1. */ | |
434 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
435 | ||
436 | /* Translate a condition evaluation mode MODE into either "host" | |
437 | or "target". This is used mostly to translate from "auto" to the | |
438 | real setting that is being used. It returns the translated | |
439 | evaluation mode. */ | |
440 | ||
441 | static const char * | |
442 | translate_condition_evaluation_mode (const char *mode) | |
443 | { | |
444 | if (mode == condition_evaluation_auto) | |
445 | { | |
446 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
447 | return condition_evaluation_target; | |
448 | else | |
449 | return condition_evaluation_host; | |
450 | } | |
451 | else | |
452 | return mode; | |
453 | } | |
454 | ||
455 | /* Discovers what condition_evaluation_auto translates to. */ | |
456 | ||
457 | static const char * | |
458 | breakpoint_condition_evaluation_mode (void) | |
459 | { | |
460 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
461 | } | |
462 | ||
463 | /* Return true if GDB should evaluate breakpoint conditions or false | |
464 | otherwise. */ | |
465 | ||
466 | static int | |
467 | gdb_evaluates_breakpoint_condition_p (void) | |
468 | { | |
469 | const char *mode = breakpoint_condition_evaluation_mode (); | |
470 | ||
471 | return (mode == condition_evaluation_host); | |
472 | } | |
473 | ||
c906108c SS |
474 | /* Are we executing breakpoint commands? */ |
475 | static int executing_breakpoint_commands; | |
476 | ||
c02f5703 MS |
477 | /* Are overlay event breakpoints enabled? */ |
478 | static int overlay_events_enabled; | |
479 | ||
e09342b5 | 480 | /* See description in breakpoint.h. */ |
491144b5 | 481 | bool target_exact_watchpoints = false; |
e09342b5 | 482 | |
c906108c | 483 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 484 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 485 | current breakpoint. */ |
c906108c | 486 | |
5c44784c | 487 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 488 | |
5c44784c JM |
489 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
490 | for (B = breakpoint_chain; \ | |
491 | B ? (TMP=B->next, 1): 0; \ | |
492 | B = TMP) | |
c906108c | 493 | |
4a64f543 MS |
494 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
495 | not provided so update_global_location_list must not be called | |
496 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 497 | |
876fa593 | 498 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
499 | for (BP_TMP = bp_locations; \ |
500 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 501 | BP_TMP++) |
7cc221ef | 502 | |
b775012e LM |
503 | /* Iterates through locations with address ADDRESS for the currently selected |
504 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
505 | to where the loop should start from. | |
506 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
507 | appropriate location to start with. */ | |
508 | ||
509 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
510 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
511 | BP_LOCP_TMP = BP_LOCP_START; \ | |
512 | BP_LOCP_START \ | |
f5336ca5 | 513 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
514 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
515 | BP_LOCP_TMP++) | |
516 | ||
1042e4c0 SS |
517 | /* Iterator for tracepoints only. */ |
518 | ||
519 | #define ALL_TRACEPOINTS(B) \ | |
520 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 521 | if (is_tracepoint (B)) |
1042e4c0 | 522 | |
7cc221ef | 523 | /* Chains of all breakpoints defined. */ |
c906108c | 524 | |
81e6b8eb | 525 | static struct breakpoint *breakpoint_chain; |
c906108c | 526 | |
39ef2f62 | 527 | /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ |
876fa593 | 528 | |
f5336ca5 | 529 | static struct bp_location **bp_locations; |
876fa593 | 530 | |
f5336ca5 | 531 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 532 | |
f5336ca5 | 533 | static unsigned bp_locations_count; |
876fa593 | 534 | |
4a64f543 | 535 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 536 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 537 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 538 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 539 | an address you need to read. */ |
876fa593 | 540 | |
f5336ca5 | 541 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 542 | |
4a64f543 MS |
543 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
544 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
545 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
546 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 547 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 548 | |
f5336ca5 | 549 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 550 | |
4a64f543 | 551 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
552 | from the bp_locations array, but for which a hit may still be |
553 | reported by a target. */ | |
1123588c | 554 | static std::vector<bp_location *> moribund_locations; |
20874c92 | 555 | |
c906108c SS |
556 | /* Number of last breakpoint made. */ |
557 | ||
95a42b64 TT |
558 | static int breakpoint_count; |
559 | ||
86b17b60 PA |
560 | /* The value of `breakpoint_count' before the last command that |
561 | created breakpoints. If the last (break-like) command created more | |
562 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
563 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
564 | static int prev_breakpoint_count; | |
c906108c | 565 | |
1042e4c0 SS |
566 | /* Number of last tracepoint made. */ |
567 | ||
95a42b64 | 568 | static int tracepoint_count; |
1042e4c0 | 569 | |
6149aea9 PA |
570 | static struct cmd_list_element *breakpoint_set_cmdlist; |
571 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 572 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 573 | |
badd37ce SDJ |
574 | /* See declaration at breakpoint.h. */ |
575 | ||
576 | struct breakpoint * | |
577 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
578 | void *user_data) | |
579 | { | |
580 | struct breakpoint *b = NULL; | |
581 | ||
582 | ALL_BREAKPOINTS (b) | |
583 | { | |
584 | if (func (b, user_data) != 0) | |
585 | break; | |
586 | } | |
587 | ||
588 | return b; | |
589 | } | |
590 | ||
468d015d JJ |
591 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
592 | static int | |
593 | breakpoint_enabled (struct breakpoint *b) | |
594 | { | |
0d381245 | 595 | return (b->enable_state == bp_enabled); |
468d015d JJ |
596 | } |
597 | ||
c906108c SS |
598 | /* Set breakpoint count to NUM. */ |
599 | ||
95a42b64 | 600 | static void |
fba45db2 | 601 | set_breakpoint_count (int num) |
c906108c | 602 | { |
86b17b60 | 603 | prev_breakpoint_count = breakpoint_count; |
c906108c | 604 | breakpoint_count = num; |
4fa62494 | 605 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
606 | } |
607 | ||
86b17b60 PA |
608 | /* Used by `start_rbreak_breakpoints' below, to record the current |
609 | breakpoint count before "rbreak" creates any breakpoint. */ | |
610 | static int rbreak_start_breakpoint_count; | |
611 | ||
95a42b64 TT |
612 | /* Called at the start an "rbreak" command to record the first |
613 | breakpoint made. */ | |
86b17b60 | 614 | |
c80049d3 | 615 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 616 | { |
86b17b60 | 617 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
618 | } |
619 | ||
620 | /* Called at the end of an "rbreak" command to record the last | |
621 | breakpoint made. */ | |
86b17b60 | 622 | |
c80049d3 | 623 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 624 | { |
86b17b60 | 625 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
626 | } |
627 | ||
4a64f543 | 628 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
629 | |
630 | void | |
fba45db2 | 631 | clear_breakpoint_hit_counts (void) |
c906108c SS |
632 | { |
633 | struct breakpoint *b; | |
634 | ||
635 | ALL_BREAKPOINTS (b) | |
636 | b->hit_count = 0; | |
637 | } | |
638 | ||
c906108c | 639 | \f |
48cb2d85 VP |
640 | /* Return the breakpoint with the specified number, or NULL |
641 | if the number does not refer to an existing breakpoint. */ | |
642 | ||
643 | struct breakpoint * | |
644 | get_breakpoint (int num) | |
645 | { | |
646 | struct breakpoint *b; | |
647 | ||
648 | ALL_BREAKPOINTS (b) | |
649 | if (b->number == num) | |
650 | return b; | |
651 | ||
652 | return NULL; | |
653 | } | |
5c44784c | 654 | |
c906108c | 655 | \f |
adc36818 | 656 | |
b775012e LM |
657 | /* Mark locations as "conditions have changed" in case the target supports |
658 | evaluating conditions on its side. */ | |
659 | ||
660 | static void | |
661 | mark_breakpoint_modified (struct breakpoint *b) | |
662 | { | |
663 | struct bp_location *loc; | |
664 | ||
665 | /* This is only meaningful if the target is | |
666 | evaluating conditions and if the user has | |
667 | opted for condition evaluation on the target's | |
668 | side. */ | |
669 | if (gdb_evaluates_breakpoint_condition_p () | |
670 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
671 | return; | |
672 | ||
673 | if (!is_breakpoint (b)) | |
674 | return; | |
675 | ||
676 | for (loc = b->loc; loc; loc = loc->next) | |
677 | loc->condition_changed = condition_modified; | |
678 | } | |
679 | ||
680 | /* Mark location as "conditions have changed" in case the target supports | |
681 | evaluating conditions on its side. */ | |
682 | ||
683 | static void | |
684 | mark_breakpoint_location_modified (struct bp_location *loc) | |
685 | { | |
686 | /* This is only meaningful if the target is | |
687 | evaluating conditions and if the user has | |
688 | opted for condition evaluation on the target's | |
689 | side. */ | |
690 | if (gdb_evaluates_breakpoint_condition_p () | |
691 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
692 | ||
693 | return; | |
694 | ||
695 | if (!is_breakpoint (loc->owner)) | |
696 | return; | |
697 | ||
698 | loc->condition_changed = condition_modified; | |
699 | } | |
700 | ||
701 | /* Sets the condition-evaluation mode using the static global | |
702 | condition_evaluation_mode. */ | |
703 | ||
704 | static void | |
eb4c3f4a | 705 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
706 | struct cmd_list_element *c) |
707 | { | |
b775012e LM |
708 | const char *old_mode, *new_mode; |
709 | ||
710 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
711 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
712 | { | |
713 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
714 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
715 | "Using host evaluation mode instead.")); | |
716 | return; | |
717 | } | |
718 | ||
719 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
720 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
721 | ||
abf1152a JK |
722 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
723 | settings was "auto". */ | |
724 | condition_evaluation_mode = condition_evaluation_mode_1; | |
725 | ||
b775012e LM |
726 | /* Only update the mode if the user picked a different one. */ |
727 | if (new_mode != old_mode) | |
728 | { | |
729 | struct bp_location *loc, **loc_tmp; | |
730 | /* If the user switched to a different evaluation mode, we | |
731 | need to synch the changes with the target as follows: | |
732 | ||
733 | "host" -> "target": Send all (valid) conditions to the target. | |
734 | "target" -> "host": Remove all the conditions from the target. | |
735 | */ | |
736 | ||
b775012e LM |
737 | if (new_mode == condition_evaluation_target) |
738 | { | |
739 | /* Mark everything modified and synch conditions with the | |
740 | target. */ | |
741 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
742 | mark_breakpoint_location_modified (loc); | |
743 | } | |
744 | else | |
745 | { | |
746 | /* Manually mark non-duplicate locations to synch conditions | |
747 | with the target. We do this to remove all the conditions the | |
748 | target knows about. */ | |
749 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
750 | if (is_breakpoint (loc->owner) && loc->inserted) | |
751 | loc->needs_update = 1; | |
752 | } | |
753 | ||
754 | /* Do the update. */ | |
44702360 | 755 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
756 | } |
757 | ||
758 | return; | |
759 | } | |
760 | ||
761 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
762 | what "auto" is translating to. */ | |
763 | ||
764 | static void | |
765 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
766 | struct cmd_list_element *c, const char *value) | |
767 | { | |
768 | if (condition_evaluation_mode == condition_evaluation_auto) | |
769 | fprintf_filtered (file, | |
770 | _("Breakpoint condition evaluation " | |
771 | "mode is %s (currently %s).\n"), | |
772 | value, | |
773 | breakpoint_condition_evaluation_mode ()); | |
774 | else | |
775 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
776 | value); | |
777 | } | |
778 | ||
779 | /* A comparison function for bp_location AP and BP that is used by | |
780 | bsearch. This comparison function only cares about addresses, unlike | |
39ef2f62 | 781 | the more general bp_location_is_less_than function. */ |
b775012e LM |
782 | |
783 | static int | |
f5336ca5 | 784 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 785 | { |
9a3c8263 SM |
786 | const struct bp_location *a = *(const struct bp_location **) ap; |
787 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
788 | |
789 | if (a->address == b->address) | |
790 | return 0; | |
791 | else | |
792 | return ((a->address > b->address) - (a->address < b->address)); | |
793 | } | |
794 | ||
795 | /* Helper function to skip all bp_locations with addresses | |
796 | less than ADDRESS. It returns the first bp_location that | |
797 | is greater than or equal to ADDRESS. If none is found, just | |
798 | return NULL. */ | |
799 | ||
800 | static struct bp_location ** | |
801 | get_first_locp_gte_addr (CORE_ADDR address) | |
802 | { | |
803 | struct bp_location dummy_loc; | |
804 | struct bp_location *dummy_locp = &dummy_loc; | |
805 | struct bp_location **locp_found = NULL; | |
806 | ||
807 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
808 | dummy_loc.address = address; |
809 | ||
810 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 811 | locp_found = ((struct bp_location **) |
f5336ca5 | 812 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 813 | sizeof (struct bp_location **), |
f5336ca5 | 814 | bp_locations_compare_addrs)); |
b775012e LM |
815 | |
816 | /* Nothing was found, nothing left to do. */ | |
817 | if (locp_found == NULL) | |
818 | return NULL; | |
819 | ||
820 | /* We may have found a location that is at ADDRESS but is not the first in the | |
821 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 822 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
823 | && (*(locp_found - 1))->address == address) |
824 | locp_found--; | |
825 | ||
826 | return locp_found; | |
827 | } | |
828 | ||
adc36818 | 829 | void |
7a26bd4d | 830 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
831 | int from_tty) |
832 | { | |
3a5c3e22 PA |
833 | xfree (b->cond_string); |
834 | b->cond_string = NULL; | |
adc36818 | 835 | |
3a5c3e22 | 836 | if (is_watchpoint (b)) |
adc36818 | 837 | { |
3a5c3e22 PA |
838 | struct watchpoint *w = (struct watchpoint *) b; |
839 | ||
4d01a485 | 840 | w->cond_exp.reset (); |
3a5c3e22 PA |
841 | } |
842 | else | |
843 | { | |
844 | struct bp_location *loc; | |
845 | ||
846 | for (loc = b->loc; loc; loc = loc->next) | |
847 | { | |
4d01a485 | 848 | loc->cond.reset (); |
b775012e LM |
849 | |
850 | /* No need to free the condition agent expression | |
851 | bytecode (if we have one). We will handle this | |
852 | when we go through update_global_location_list. */ | |
3a5c3e22 | 853 | } |
adc36818 | 854 | } |
adc36818 PM |
855 | |
856 | if (*exp == 0) | |
857 | { | |
858 | if (from_tty) | |
859 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
860 | } | |
861 | else | |
862 | { | |
bbc13ae3 | 863 | const char *arg = exp; |
cc59ec59 | 864 | |
adc36818 PM |
865 | /* I don't know if it matters whether this is the string the user |
866 | typed in or the decompiled expression. */ | |
867 | b->cond_string = xstrdup (arg); | |
868 | b->condition_not_parsed = 0; | |
869 | ||
870 | if (is_watchpoint (b)) | |
871 | { | |
3a5c3e22 PA |
872 | struct watchpoint *w = (struct watchpoint *) b; |
873 | ||
699bd4cf | 874 | innermost_block_tracker tracker; |
adc36818 | 875 | arg = exp; |
699bd4cf | 876 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
adc36818 PM |
877 | if (*arg) |
878 | error (_("Junk at end of expression")); | |
699bd4cf | 879 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
880 | } |
881 | else | |
882 | { | |
3a5c3e22 PA |
883 | struct bp_location *loc; |
884 | ||
adc36818 PM |
885 | for (loc = b->loc; loc; loc = loc->next) |
886 | { | |
887 | arg = exp; | |
888 | loc->cond = | |
1bb9788d TT |
889 | parse_exp_1 (&arg, loc->address, |
890 | block_for_pc (loc->address), 0); | |
adc36818 PM |
891 | if (*arg) |
892 | error (_("Junk at end of expression")); | |
893 | } | |
894 | } | |
895 | } | |
b775012e LM |
896 | mark_breakpoint_modified (b); |
897 | ||
76727919 | 898 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
899 | } |
900 | ||
d55637df TT |
901 | /* Completion for the "condition" command. */ |
902 | ||
eb3ff9a5 | 903 | static void |
6f937416 | 904 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 905 | completion_tracker &tracker, |
6f937416 | 906 | const char *text, const char *word) |
d55637df | 907 | { |
6f937416 | 908 | const char *space; |
d55637df | 909 | |
f1735a53 TT |
910 | text = skip_spaces (text); |
911 | space = skip_to_space (text); | |
d55637df TT |
912 | if (*space == '\0') |
913 | { | |
914 | int len; | |
915 | struct breakpoint *b; | |
d55637df TT |
916 | |
917 | if (text[0] == '$') | |
918 | { | |
919 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
920 | if (!isdigit (text[1])) |
921 | complete_internalvar (tracker, &text[1]); | |
922 | return; | |
d55637df TT |
923 | } |
924 | ||
925 | /* We're completing the breakpoint number. */ | |
926 | len = strlen (text); | |
927 | ||
928 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
929 | { |
930 | char number[50]; | |
931 | ||
932 | xsnprintf (number, sizeof (number), "%d", b->number); | |
933 | ||
934 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 935 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 936 | } |
d55637df | 937 | |
eb3ff9a5 | 938 | return; |
d55637df TT |
939 | } |
940 | ||
941 | /* We're completing the expression part. */ | |
f1735a53 | 942 | text = skip_spaces (space); |
eb3ff9a5 | 943 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
944 | } |
945 | ||
c906108c SS |
946 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
947 | ||
948 | static void | |
0b39b52e | 949 | condition_command (const char *arg, int from_tty) |
c906108c | 950 | { |
52f0bd74 | 951 | struct breakpoint *b; |
0b39b52e | 952 | const char *p; |
52f0bd74 | 953 | int bnum; |
c906108c SS |
954 | |
955 | if (arg == 0) | |
e2e0b3e5 | 956 | error_no_arg (_("breakpoint number")); |
c906108c SS |
957 | |
958 | p = arg; | |
959 | bnum = get_number (&p); | |
5c44784c | 960 | if (bnum == 0) |
8a3fe4f8 | 961 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
962 | |
963 | ALL_BREAKPOINTS (b) | |
964 | if (b->number == bnum) | |
2f069f6f | 965 | { |
6dddc817 DE |
966 | /* Check if this breakpoint has a "stop" method implemented in an |
967 | extension language. This method and conditions entered into GDB | |
968 | from the CLI are mutually exclusive. */ | |
969 | const struct extension_language_defn *extlang | |
970 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
971 | ||
972 | if (extlang != NULL) | |
973 | { | |
974 | error (_("Only one stop condition allowed. There is currently" | |
975 | " a %s stop condition defined for this breakpoint."), | |
976 | ext_lang_capitalized_name (extlang)); | |
977 | } | |
2566ad2d | 978 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
979 | |
980 | if (is_breakpoint (b)) | |
44702360 | 981 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 982 | |
2f069f6f JB |
983 | return; |
984 | } | |
c906108c | 985 | |
8a3fe4f8 | 986 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
987 | } |
988 | ||
a7bdde9e VP |
989 | /* Check that COMMAND do not contain commands that are suitable |
990 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
991 | Throw if any such commands is found. */ |
992 | ||
a7bdde9e VP |
993 | static void |
994 | check_no_tracepoint_commands (struct command_line *commands) | |
995 | { | |
996 | struct command_line *c; | |
cc59ec59 | 997 | |
a7bdde9e VP |
998 | for (c = commands; c; c = c->next) |
999 | { | |
a7bdde9e | 1000 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
1001 | error (_("The 'while-stepping' command can " |
1002 | "only be used for tracepoints")); | |
a7bdde9e | 1003 | |
12973681 TT |
1004 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1005 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1006 | |
1007 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1008 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1009 | command directly. */ |
1010 | if (strstr (c->line, "collect ") == c->line) | |
1011 | error (_("The 'collect' command can only be used for tracepoints")); | |
1012 | ||
51661e93 VP |
1013 | if (strstr (c->line, "teval ") == c->line) |
1014 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1015 | } |
1016 | } | |
1017 | ||
c1fc2657 | 1018 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1019 | { |
c1fc2657 | 1020 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1021 | }; |
1022 | ||
d77f58be SS |
1023 | /* Encapsulate tests for different types of tracepoints. */ |
1024 | ||
3b0871f4 SM |
1025 | static bool |
1026 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1027 | { |
1028 | return (type == bp_tracepoint | |
1029 | || type == bp_fast_tracepoint | |
1030 | || type == bp_static_tracepoint); | |
1031 | } | |
1032 | ||
3b0871f4 SM |
1033 | static bool |
1034 | is_longjmp_type (bptype type) | |
1035 | { | |
1036 | return type == bp_longjmp || type == bp_exception; | |
1037 | } | |
1038 | ||
f2478a7e SM |
1039 | /* See breakpoint.h. */ |
1040 | ||
1041 | bool | |
d77f58be | 1042 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1043 | { |
d9b3f62e | 1044 | return is_tracepoint_type (b->type); |
a7bdde9e | 1045 | } |
d9b3f62e | 1046 | |
a5e364af SM |
1047 | /* Factory function to create an appropriate instance of breakpoint given |
1048 | TYPE. */ | |
1049 | ||
1050 | static std::unique_ptr<breakpoint> | |
1051 | new_breakpoint_from_type (bptype type) | |
1052 | { | |
1053 | breakpoint *b; | |
1054 | ||
1055 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1056 | b = new tracepoint (); |
3b0871f4 | 1057 | else if (is_longjmp_type (type)) |
c1fc2657 | 1058 | b = new longjmp_breakpoint (); |
a5e364af SM |
1059 | else |
1060 | b = new breakpoint (); | |
1061 | ||
1062 | return std::unique_ptr<breakpoint> (b); | |
1063 | } | |
1064 | ||
e5dd4106 | 1065 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1066 | breakpoint. This function will throw an exception if a problem is |
1067 | found. */ | |
48cb2d85 | 1068 | |
95a42b64 TT |
1069 | static void |
1070 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1071 | struct command_line *commands) | |
48cb2d85 | 1072 | { |
d77f58be | 1073 | if (is_tracepoint (b)) |
a7bdde9e | 1074 | { |
c9a6ce02 | 1075 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1076 | struct command_line *c; |
1077 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1078 | |
1079 | /* Reset the while-stepping step count. The previous commands | |
1080 | might have included a while-stepping action, while the new | |
1081 | ones might not. */ | |
1082 | t->step_count = 0; | |
1083 | ||
1084 | /* We need to verify that each top-level element of commands is | |
1085 | valid for tracepoints, that there's at most one | |
1086 | while-stepping element, and that the while-stepping's body | |
1087 | has valid tracing commands excluding nested while-stepping. | |
1088 | We also need to validate the tracepoint action line in the | |
1089 | context of the tracepoint --- validate_actionline actually | |
1090 | has side effects, like setting the tracepoint's | |
1091 | while-stepping STEP_COUNT, in addition to checking if the | |
1092 | collect/teval actions parse and make sense in the | |
1093 | tracepoint's context. */ | |
a7bdde9e VP |
1094 | for (c = commands; c; c = c->next) |
1095 | { | |
a7bdde9e VP |
1096 | if (c->control_type == while_stepping_control) |
1097 | { | |
1098 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1099 | error (_("The 'while-stepping' command " |
1100 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1101 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1102 | error (_("The 'while-stepping' command " |
1103 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1104 | |
1105 | if (while_stepping) | |
3e43a32a MS |
1106 | error (_("The 'while-stepping' command " |
1107 | "can be used only once")); | |
a7bdde9e VP |
1108 | else |
1109 | while_stepping = c; | |
1110 | } | |
c9a6ce02 PA |
1111 | |
1112 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1113 | } |
1114 | if (while_stepping) | |
1115 | { | |
1116 | struct command_line *c2; | |
1117 | ||
12973681 TT |
1118 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1119 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1120 | for (; c2; c2 = c2->next) |
1121 | { | |
a7bdde9e VP |
1122 | if (c2->control_type == while_stepping_control) |
1123 | error (_("The 'while-stepping' command cannot be nested")); | |
1124 | } | |
1125 | } | |
1126 | } | |
1127 | else | |
1128 | { | |
1129 | check_no_tracepoint_commands (commands); | |
1130 | } | |
95a42b64 TT |
1131 | } |
1132 | ||
0fb4aa4b PA |
1133 | /* Return a vector of all the static tracepoints set at ADDR. The |
1134 | caller is responsible for releasing the vector. */ | |
1135 | ||
f51e0e20 | 1136 | std::vector<breakpoint *> |
0fb4aa4b PA |
1137 | static_tracepoints_here (CORE_ADDR addr) |
1138 | { | |
1139 | struct breakpoint *b; | |
f51e0e20 | 1140 | std::vector<breakpoint *> found; |
0fb4aa4b PA |
1141 | struct bp_location *loc; |
1142 | ||
1143 | ALL_BREAKPOINTS (b) | |
1144 | if (b->type == bp_static_tracepoint) | |
1145 | { | |
1146 | for (loc = b->loc; loc; loc = loc->next) | |
1147 | if (loc->address == addr) | |
f51e0e20 | 1148 | found.push_back (b); |
0fb4aa4b PA |
1149 | } |
1150 | ||
1151 | return found; | |
1152 | } | |
1153 | ||
95a42b64 | 1154 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1155 | validate that only allowed commands are included. */ |
95a42b64 TT |
1156 | |
1157 | void | |
4a64f543 | 1158 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1159 | counted_command_line &&commands) |
95a42b64 | 1160 | { |
93921405 | 1161 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1162 | |
d1b0a7bf | 1163 | b->commands = std::move (commands); |
76727919 | 1164 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1165 | } |
1166 | ||
45a43567 TT |
1167 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1168 | is not the same as the "silent" that may appear in the breakpoint's | |
1169 | commands. */ | |
1170 | ||
1171 | void | |
1172 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1173 | { | |
1174 | int old_silent = b->silent; | |
1175 | ||
1176 | b->silent = silent; | |
1177 | if (old_silent != silent) | |
76727919 | 1178 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1179 | } |
1180 | ||
1181 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1182 | breakpoint work for any thread. */ | |
1183 | ||
1184 | void | |
1185 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1186 | { | |
1187 | int old_thread = b->thread; | |
1188 | ||
1189 | b->thread = thread; | |
1190 | if (old_thread != thread) | |
76727919 | 1191 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1192 | } |
1193 | ||
1194 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1195 | breakpoint work for any task. */ | |
1196 | ||
1197 | void | |
1198 | breakpoint_set_task (struct breakpoint *b, int task) | |
1199 | { | |
1200 | int old_task = b->task; | |
1201 | ||
1202 | b->task = task; | |
1203 | if (old_task != task) | |
76727919 | 1204 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1205 | } |
1206 | ||
95a42b64 | 1207 | static void |
896b6bda | 1208 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1209 | struct command_line *control) |
95a42b64 | 1210 | { |
d1b0a7bf | 1211 | counted_command_line cmd; |
999700cd PW |
1212 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1213 | NULL after the call to read_command_lines if the user provides an empty | |
1214 | list of command by just typing "end". */ | |
1215 | bool cmd_read = false; | |
95a42b64 | 1216 | |
896b6bda PA |
1217 | std::string new_arg; |
1218 | ||
95a42b64 TT |
1219 | if (arg == NULL || !*arg) |
1220 | { | |
86b17b60 | 1221 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1222 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1223 | breakpoint_count); | |
95a42b64 | 1224 | else if (breakpoint_count > 0) |
896b6bda | 1225 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1226 | arg = new_arg.c_str (); |
1227 | } | |
1228 | ||
1229 | map_breakpoint_numbers | |
1230 | (arg, [&] (breakpoint *b) | |
1231 | { | |
999700cd | 1232 | if (!cmd_read) |
48649e1b | 1233 | { |
999700cd | 1234 | gdb_assert (cmd == NULL); |
48649e1b | 1235 | if (control != NULL) |
12973681 | 1236 | cmd = control->body_list_0; |
48649e1b TT |
1237 | else |
1238 | { | |
81b1e71c TT |
1239 | std::string str |
1240 | = string_printf (_("Type commands for breakpoint(s) " | |
1241 | "%s, one per line."), | |
1242 | arg); | |
48649e1b | 1243 | |
60b3cef2 TT |
1244 | auto do_validate = [=] (const char *line) |
1245 | { | |
1246 | validate_actionline (line, b); | |
1247 | }; | |
1248 | gdb::function_view<void (const char *)> validator; | |
1249 | if (is_tracepoint (b)) | |
1250 | validator = do_validate; | |
1251 | ||
1252 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1253 | } |
999700cd | 1254 | cmd_read = true; |
48649e1b TT |
1255 | } |
1256 | ||
1257 | /* If a breakpoint was on the list more than once, we don't need to | |
1258 | do anything. */ | |
1259 | if (b->commands != cmd) | |
1260 | { | |
d1b0a7bf | 1261 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1262 | b->commands = cmd; |
76727919 | 1263 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1264 | } |
1265 | }); | |
95a42b64 TT |
1266 | } |
1267 | ||
1268 | static void | |
0b39b52e | 1269 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1270 | { |
1271 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1272 | } |
40c03ae8 EZ |
1273 | |
1274 | /* Like commands_command, but instead of reading the commands from | |
1275 | input stream, takes them from an already parsed command structure. | |
1276 | ||
1277 | This is used by cli-script.c to DTRT with breakpoint commands | |
1278 | that are part of if and while bodies. */ | |
1279 | enum command_control_type | |
896b6bda | 1280 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1281 | { |
95a42b64 TT |
1282 | commands_command_1 (arg, 0, cmd); |
1283 | return simple_control; | |
40c03ae8 | 1284 | } |
876fa593 JK |
1285 | |
1286 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1287 | ||
1288 | static int | |
1289 | bp_location_has_shadow (struct bp_location *bl) | |
1290 | { | |
1291 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1292 | return 0; | |
1293 | if (!bl->inserted) | |
1294 | return 0; | |
1295 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1296 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1297 | return 0; |
1298 | return 1; | |
1299 | } | |
1300 | ||
9d497a19 PA |
1301 | /* Update BUF, which is LEN bytes read from the target address |
1302 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1303 | contents. | |
1304 | ||
1305 | If READBUF is not NULL, this buffer must not overlap with the of | |
1306 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1307 | failed assertion internal error will be raised. */ | |
1308 | ||
1309 | static void | |
1310 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1311 | const gdb_byte *writebuf_org, | |
1312 | ULONGEST memaddr, LONGEST len, | |
1313 | struct bp_target_info *target_info, | |
1314 | struct gdbarch *gdbarch) | |
1315 | { | |
1316 | /* Now do full processing of the found relevant range of elements. */ | |
1317 | CORE_ADDR bp_addr = 0; | |
1318 | int bp_size = 0; | |
1319 | int bptoffset = 0; | |
1320 | ||
1321 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1322 | current_program_space->aspace, 0)) | |
1323 | { | |
1324 | /* The breakpoint is inserted in a different address space. */ | |
1325 | return; | |
1326 | } | |
1327 | ||
1328 | /* Addresses and length of the part of the breakpoint that | |
1329 | we need to copy. */ | |
1330 | bp_addr = target_info->placed_address; | |
1331 | bp_size = target_info->shadow_len; | |
1332 | ||
1333 | if (bp_addr + bp_size <= memaddr) | |
1334 | { | |
1335 | /* The breakpoint is entirely before the chunk of memory we are | |
1336 | reading. */ | |
1337 | return; | |
1338 | } | |
1339 | ||
1340 | if (bp_addr >= memaddr + len) | |
1341 | { | |
1342 | /* The breakpoint is entirely after the chunk of memory we are | |
1343 | reading. */ | |
1344 | return; | |
1345 | } | |
1346 | ||
1347 | /* Offset within shadow_contents. */ | |
1348 | if (bp_addr < memaddr) | |
1349 | { | |
1350 | /* Only copy the second part of the breakpoint. */ | |
1351 | bp_size -= memaddr - bp_addr; | |
1352 | bptoffset = memaddr - bp_addr; | |
1353 | bp_addr = memaddr; | |
1354 | } | |
1355 | ||
1356 | if (bp_addr + bp_size > memaddr + len) | |
1357 | { | |
1358 | /* Only copy the first part of the breakpoint. */ | |
1359 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1360 | } | |
1361 | ||
1362 | if (readbuf != NULL) | |
1363 | { | |
1364 | /* Verify that the readbuf buffer does not overlap with the | |
1365 | shadow_contents buffer. */ | |
1366 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1367 | || readbuf >= (target_info->shadow_contents | |
1368 | + target_info->shadow_len)); | |
1369 | ||
1370 | /* Update the read buffer with this inserted breakpoint's | |
1371 | shadow. */ | |
1372 | memcpy (readbuf + bp_addr - memaddr, | |
1373 | target_info->shadow_contents + bptoffset, bp_size); | |
1374 | } | |
1375 | else | |
1376 | { | |
1377 | const unsigned char *bp; | |
0d5ed153 MR |
1378 | CORE_ADDR addr = target_info->reqstd_address; |
1379 | int placed_size; | |
9d497a19 PA |
1380 | |
1381 | /* Update the shadow with what we want to write to memory. */ | |
1382 | memcpy (target_info->shadow_contents + bptoffset, | |
1383 | writebuf_org + bp_addr - memaddr, bp_size); | |
1384 | ||
1385 | /* Determine appropriate breakpoint contents and size for this | |
1386 | address. */ | |
0d5ed153 | 1387 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1388 | |
1389 | /* Update the final write buffer with this inserted | |
1390 | breakpoint's INSN. */ | |
1391 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1392 | } | |
1393 | } | |
1394 | ||
8defab1a | 1395 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1396 | by replacing any memory breakpoints with their shadowed contents. |
1397 | ||
35c63cd8 JB |
1398 | If READBUF is not NULL, this buffer must not overlap with any of |
1399 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1400 | a failed assertion internal error will be raised. | |
1401 | ||
876fa593 | 1402 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1403 | bl->address - bp_locations_placed_address_before_address_max |
1404 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1405 | The range we were requested to resolve shadows for is: |
1406 | memaddr ... memaddr + len | |
1407 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1408 | memaddr + len <= (bl->address |
f5336ca5 | 1409 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1410 | and: |
f5336ca5 | 1411 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1412 | |
8defab1a | 1413 | void |
f0ba3972 PA |
1414 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1415 | const gdb_byte *writebuf_org, | |
1416 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1417 | { |
4a64f543 MS |
1418 | /* Left boundary, right boundary and median element of our binary |
1419 | search. */ | |
876fa593 JK |
1420 | unsigned bc_l, bc_r, bc; |
1421 | ||
4a64f543 MS |
1422 | /* Find BC_L which is a leftmost element which may affect BUF |
1423 | content. It is safe to report lower value but a failure to | |
1424 | report higher one. */ | |
876fa593 JK |
1425 | |
1426 | bc_l = 0; | |
f5336ca5 | 1427 | bc_r = bp_locations_count; |
876fa593 JK |
1428 | while (bc_l + 1 < bc_r) |
1429 | { | |
35df4500 | 1430 | struct bp_location *bl; |
876fa593 JK |
1431 | |
1432 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1433 | bl = bp_locations[bc]; |
876fa593 | 1434 | |
4a64f543 MS |
1435 | /* Check first BL->ADDRESS will not overflow due to the added |
1436 | constant. Then advance the left boundary only if we are sure | |
1437 | the BC element can in no way affect the BUF content (MEMADDR | |
1438 | to MEMADDR + LEN range). | |
876fa593 | 1439 | |
f5336ca5 | 1440 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1441 | offset so that we cannot miss a breakpoint with its shadow |
1442 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1443 | |
f5336ca5 | 1444 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1445 | >= bl->address) |
f5336ca5 | 1446 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1447 | <= memaddr)) |
876fa593 JK |
1448 | bc_l = bc; |
1449 | else | |
1450 | bc_r = bc; | |
1451 | } | |
1452 | ||
128070bb PA |
1453 | /* Due to the binary search above, we need to make sure we pick the |
1454 | first location that's at BC_L's address. E.g., if there are | |
1455 | multiple locations at the same address, BC_L may end up pointing | |
1456 | at a duplicate location, and miss the "master"/"inserted" | |
1457 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1458 | B: | |
1459 | ||
1460 | L1@A, L2@A, L3@B, ... | |
1461 | ||
1462 | BC_L could end up pointing at location L2, while the "master" | |
1463 | location could be L1. Since the `loc->inserted' flag is only set | |
1464 | on "master" locations, we'd forget to restore the shadow of L1 | |
1465 | and L2. */ | |
1466 | while (bc_l > 0 | |
f5336ca5 | 1467 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1468 | bc_l--; |
1469 | ||
876fa593 JK |
1470 | /* Now do full processing of the found relevant range of elements. */ |
1471 | ||
f5336ca5 | 1472 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1473 | { |
f5336ca5 | 1474 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1475 | |
35df4500 TJB |
1476 | /* bp_location array has BL->OWNER always non-NULL. */ |
1477 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1478 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1479 | bl->owner->number); |
ffce0d52 | 1480 | |
e5dd4106 | 1481 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1482 | content. */ |
1483 | ||
f5336ca5 PA |
1484 | if (bl->address >= bp_locations_placed_address_before_address_max |
1485 | && memaddr + len <= (bl->address | |
1486 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1487 | break; |
1488 | ||
35df4500 | 1489 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1490 | continue; |
6c95b8df | 1491 | |
9d497a19 PA |
1492 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1493 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1494 | } | |
c906108c | 1495 | } |
9d497a19 | 1496 | |
f2478a7e | 1497 | /* See breakpoint.h. */ |
b775012e | 1498 | |
f2478a7e | 1499 | bool |
b775012e LM |
1500 | is_breakpoint (const struct breakpoint *bpt) |
1501 | { | |
1502 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1503 | || bpt->type == bp_hardware_breakpoint |
1504 | || bpt->type == bp_dprintf); | |
b775012e LM |
1505 | } |
1506 | ||
60e1c644 PA |
1507 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1508 | ||
f2478a7e | 1509 | static bool |
d77f58be | 1510 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1511 | { |
1512 | return (bpt->type == bp_hardware_watchpoint | |
1513 | || bpt->type == bp_read_watchpoint | |
1514 | || bpt->type == bp_access_watchpoint); | |
1515 | } | |
7270d8f2 | 1516 | |
f2478a7e | 1517 | /* See breakpoint.h. */ |
60e1c644 | 1518 | |
f2478a7e | 1519 | bool |
d77f58be | 1520 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1521 | { |
1522 | return (is_hardware_watchpoint (bpt) | |
1523 | || bpt->type == bp_watchpoint); | |
1524 | } | |
1525 | ||
3a5c3e22 PA |
1526 | /* Returns true if the current thread and its running state are safe |
1527 | to evaluate or update watchpoint B. Watchpoints on local | |
1528 | expressions need to be evaluated in the context of the thread that | |
1529 | was current when the watchpoint was created, and, that thread needs | |
1530 | to be stopped to be able to select the correct frame context. | |
1531 | Watchpoints on global expressions can be evaluated on any thread, | |
1532 | and in any state. It is presently left to the target allowing | |
1533 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1534 | |
1535 | static int | |
3a5c3e22 | 1536 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1537 | { |
c1fc2657 | 1538 | return (b->pspace == current_program_space |
d7e15655 TT |
1539 | && (b->watchpoint_thread == null_ptid |
1540 | || (inferior_ptid == b->watchpoint_thread | |
00431a78 | 1541 | && !inferior_thread ()->executing))); |
f6bc2008 PA |
1542 | } |
1543 | ||
d0fb5eae JK |
1544 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1545 | associated bp_watchpoint_scope breakpoint. */ | |
1546 | ||
1547 | static void | |
3a5c3e22 | 1548 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1549 | { |
c1fc2657 | 1550 | if (w->related_breakpoint != w) |
d0fb5eae | 1551 | { |
c1fc2657 SM |
1552 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1553 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1554 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1555 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1556 | w->related_breakpoint = w; | |
d0fb5eae | 1557 | } |
c1fc2657 | 1558 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1559 | } |
1560 | ||
bb9d5f81 PP |
1561 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1562 | watchpoint W. */ | |
1563 | ||
1564 | static struct value * | |
1565 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1566 | { | |
1567 | struct value *bit_val; | |
1568 | ||
1569 | if (val == NULL) | |
1570 | return NULL; | |
1571 | ||
1572 | bit_val = allocate_value (value_type (val)); | |
1573 | ||
1574 | unpack_value_bitfield (bit_val, | |
1575 | w->val_bitpos, | |
1576 | w->val_bitsize, | |
1577 | value_contents_for_printing (val), | |
1578 | value_offset (val), | |
1579 | val); | |
1580 | ||
1581 | return bit_val; | |
1582 | } | |
1583 | ||
c6d81124 PA |
1584 | /* Allocate a dummy location and add it to B, which must be a software |
1585 | watchpoint. This is required because even if a software watchpoint | |
1586 | is not watching any memory, bpstat_stop_status requires a location | |
1587 | to be able to report stops. */ | |
1588 | ||
1589 | static void | |
1590 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1591 | struct program_space *pspace) | |
1592 | { | |
1593 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1594 | ||
1595 | b->loc = allocate_bp_location (b); | |
1596 | b->loc->pspace = pspace; | |
1597 | b->loc->address = -1; | |
1598 | b->loc->length = -1; | |
1599 | } | |
1600 | ||
1601 | /* Returns true if B is a software watchpoint that is not watching any | |
1602 | memory (e.g., "watch $pc"). */ | |
1603 | ||
f2478a7e | 1604 | static bool |
c6d81124 PA |
1605 | is_no_memory_software_watchpoint (struct breakpoint *b) |
1606 | { | |
1607 | return (b->type == bp_watchpoint | |
1608 | && b->loc != NULL | |
1609 | && b->loc->next == NULL | |
1610 | && b->loc->address == -1 | |
1611 | && b->loc->length == -1); | |
1612 | } | |
1613 | ||
567e1b4e JB |
1614 | /* Assuming that B is a watchpoint: |
1615 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1616 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1617 | - Evaluate the condition if there is one, and store the result |
1618 | in b->loc->cond. | |
a5606eee VP |
1619 | - Update the list of values that must be watched in B->loc. |
1620 | ||
4a64f543 MS |
1621 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1622 | nothing. If this is local watchpoint that is out of scope, delete | |
1623 | it. | |
1624 | ||
1625 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1626 | removed + inserted on each stop here. Normal breakpoints must | |
1627 | never be removed because they might be missed by a running thread | |
1628 | when debugging in non-stop mode. On the other hand, hardware | |
1629 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1630 | to each LWP since they are stored in each LWP's hardware debug | |
1631 | registers. Therefore, such LWP must be stopped first in order to | |
1632 | be able to modify its hardware watchpoints. | |
1633 | ||
1634 | Hardware watchpoints must be reset exactly once after being | |
1635 | presented to the user. It cannot be done sooner, because it would | |
1636 | reset the data used to present the watchpoint hit to the user. And | |
1637 | it must not be done later because it could display the same single | |
1638 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1639 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1640 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1641 | not user-visible - its hit is suppressed if the memory content has | |
1642 | not changed. | |
1643 | ||
1644 | The following constraints influence the location where we can reset | |
1645 | hardware watchpoints: | |
1646 | ||
1647 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1648 | called several times when GDB stops. | |
1649 | ||
1650 | [linux] | |
1651 | * Multiple hardware watchpoints can be hit at the same time, | |
1652 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1653 | hit at a time as the reason for stopping, and all the other hits | |
1654 | are presented later, one after the other, each time the user | |
1655 | requests the execution to be resumed. Execution is not resumed | |
1656 | for the threads still having pending hit event stored in | |
1657 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1658 | the inferior on the first stop the thread hit event is kept being | |
1659 | reported from its cached value by linux_nat_stopped_data_address | |
1660 | until the real thread resume happens after the watchpoint gets | |
1661 | presented and thus its LWP_INFO->STATUS gets reset. | |
1662 | ||
1663 | Therefore the hardware watchpoint hit can get safely reset on the | |
1664 | watchpoint removal from inferior. */ | |
a79d3c27 | 1665 | |
b40ce68a | 1666 | static void |
3a5c3e22 | 1667 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1668 | { |
a5606eee | 1669 | int within_current_scope; |
a5606eee | 1670 | struct frame_id saved_frame_id; |
66076460 | 1671 | int frame_saved; |
a5606eee | 1672 | |
f6bc2008 PA |
1673 | /* If this is a local watchpoint, we only want to check if the |
1674 | watchpoint frame is in scope if the current thread is the thread | |
1675 | that was used to create the watchpoint. */ | |
1676 | if (!watchpoint_in_thread_scope (b)) | |
1677 | return; | |
1678 | ||
c1fc2657 | 1679 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1680 | return; |
1681 | ||
66076460 | 1682 | frame_saved = 0; |
a5606eee VP |
1683 | |
1684 | /* Determine if the watchpoint is within scope. */ | |
1685 | if (b->exp_valid_block == NULL) | |
1686 | within_current_scope = 1; | |
1687 | else | |
1688 | { | |
b5db5dfc UW |
1689 | struct frame_info *fi = get_current_frame (); |
1690 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1691 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1692 | ||
c9cf6e20 MG |
1693 | /* If we're at a point where the stack has been destroyed |
1694 | (e.g. in a function epilogue), unwinding may not work | |
1695 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1696 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1697 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1698 | return; |
66076460 DJ |
1699 | |
1700 | /* Save the current frame's ID so we can restore it after | |
1701 | evaluating the watchpoint expression on its own frame. */ | |
1702 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1703 | took a frame parameter, so that we didn't have to change the | |
1704 | selected frame. */ | |
1705 | frame_saved = 1; | |
1706 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1707 | ||
a5606eee VP |
1708 | fi = frame_find_by_id (b->watchpoint_frame); |
1709 | within_current_scope = (fi != NULL); | |
1710 | if (within_current_scope) | |
1711 | select_frame (fi); | |
1712 | } | |
1713 | ||
b5db5dfc UW |
1714 | /* We don't free locations. They are stored in the bp_location array |
1715 | and update_global_location_list will eventually delete them and | |
1716 | remove breakpoints if needed. */ | |
c1fc2657 | 1717 | b->loc = NULL; |
b5db5dfc | 1718 | |
a5606eee VP |
1719 | if (within_current_scope && reparse) |
1720 | { | |
bbc13ae3 | 1721 | const char *s; |
d63d0675 | 1722 | |
4d01a485 | 1723 | b->exp.reset (); |
d63d0675 | 1724 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1725 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1726 | /* If the meaning of expression itself changed, the old value is |
1727 | no longer relevant. We don't want to report a watchpoint hit | |
1728 | to the user when the old value and the new value may actually | |
1729 | be completely different objects. */ | |
fa4727a6 | 1730 | b->val = NULL; |
4c1d86d9 | 1731 | b->val_valid = false; |
60e1c644 PA |
1732 | |
1733 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1734 | expression is stored in the breakpoint object, not in the | |
1735 | locations (re)created below. */ | |
c1fc2657 | 1736 | if (b->cond_string != NULL) |
60e1c644 | 1737 | { |
4d01a485 | 1738 | b->cond_exp.reset (); |
60e1c644 | 1739 | |
c1fc2657 | 1740 | s = b->cond_string; |
1bb9788d | 1741 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1742 | } |
a5606eee | 1743 | } |
a5606eee VP |
1744 | |
1745 | /* If we failed to parse the expression, for example because | |
1746 | it refers to a global variable in a not-yet-loaded shared library, | |
1747 | don't try to insert watchpoint. We don't automatically delete | |
1748 | such watchpoint, though, since failure to parse expression | |
1749 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1750 | if (!target_has_execution) |
2d134ed3 PA |
1751 | { |
1752 | /* Without execution, memory can't change. No use to try and | |
1753 | set watchpoint locations. The watchpoint will be reset when | |
1754 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1755 | if (!can_use_hw_watchpoints) |
1756 | { | |
c1fc2657 SM |
1757 | if (b->ops->works_in_software_mode (b)) |
1758 | b->type = bp_watchpoint; | |
e8369a73 | 1759 | else |
638aa5a1 AB |
1760 | error (_("Can't set read/access watchpoint when " |
1761 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1762 | } |
2d134ed3 PA |
1763 | } |
1764 | else if (within_current_scope && b->exp) | |
a5606eee | 1765 | { |
0cf6dd15 | 1766 | int pc = 0; |
a6535de1 | 1767 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 1768 | struct value *v, *result; |
2d134ed3 | 1769 | struct program_space *frame_pspace; |
a5606eee | 1770 | |
4d01a485 | 1771 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1772 | |
a5606eee VP |
1773 | /* Avoid setting b->val if it's already set. The meaning of |
1774 | b->val is 'the last value' user saw, and we should update | |
1775 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1776 | happens, the code that reports it updates b->val directly. |
1777 | We don't keep track of the memory value for masked | |
1778 | watchpoints. */ | |
c1fc2657 | 1779 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1780 | { |
bb9d5f81 | 1781 | if (b->val_bitsize != 0) |
850645cf TT |
1782 | v = extract_bitfield_from_watchpoint_value (b, v); |
1783 | b->val = release_value (v); | |
4c1d86d9 | 1784 | b->val_valid = true; |
fa4727a6 | 1785 | } |
a5606eee | 1786 | |
2d134ed3 PA |
1787 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1788 | ||
a5606eee | 1789 | /* Look at each value on the value chain. */ |
a6535de1 TT |
1790 | gdb_assert (!val_chain.empty ()); |
1791 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 1792 | { |
a6535de1 TT |
1793 | v = iter.get (); |
1794 | ||
a5606eee VP |
1795 | /* If it's a memory location, and GDB actually needed |
1796 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1797 | must watch it. If the first value returned is |
1798 | still lazy, that means an error occurred reading it; | |
1799 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1800 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 1801 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
1802 | { |
1803 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1804 | |
a5606eee VP |
1805 | /* We only watch structs and arrays if user asked |
1806 | for it explicitly, never if they just happen to | |
1807 | appear in the middle of some value chain. */ | |
fa4727a6 | 1808 | if (v == result |
a5606eee VP |
1809 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1810 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1811 | { | |
1812 | CORE_ADDR addr; | |
f486487f | 1813 | enum target_hw_bp_type type; |
a5606eee | 1814 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1815 | int bitpos = 0, bitsize = 0; |
1816 | ||
1817 | if (value_bitsize (v) != 0) | |
1818 | { | |
1819 | /* Extract the bit parameters out from the bitfield | |
1820 | sub-expression. */ | |
1821 | bitpos = value_bitpos (v); | |
1822 | bitsize = value_bitsize (v); | |
1823 | } | |
1824 | else if (v == result && b->val_bitsize != 0) | |
1825 | { | |
1826 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1827 | lvalue whose bit parameters are saved in the fields | |
1828 | VAL_BITPOS and VAL_BITSIZE. */ | |
1829 | bitpos = b->val_bitpos; | |
1830 | bitsize = b->val_bitsize; | |
1831 | } | |
a5606eee | 1832 | |
42ae5230 | 1833 | addr = value_address (v); |
bb9d5f81 PP |
1834 | if (bitsize != 0) |
1835 | { | |
1836 | /* Skip the bytes that don't contain the bitfield. */ | |
1837 | addr += bitpos / 8; | |
1838 | } | |
1839 | ||
a5606eee | 1840 | type = hw_write; |
c1fc2657 | 1841 | if (b->type == bp_read_watchpoint) |
a5606eee | 1842 | type = hw_read; |
c1fc2657 | 1843 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1844 | type = hw_access; |
3a5c3e22 | 1845 | |
c1fc2657 SM |
1846 | loc = allocate_bp_location (b); |
1847 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1848 | ; |
1849 | *tmp = loc; | |
a6d9a66e | 1850 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1851 | |
1852 | loc->pspace = frame_pspace; | |
f17d9474 | 1853 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
1854 | |
1855 | if (bitsize != 0) | |
1856 | { | |
1857 | /* Just cover the bytes that make up the bitfield. */ | |
1858 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1859 | } | |
1860 | else | |
1861 | loc->length = TYPE_LENGTH (value_type (v)); | |
1862 | ||
a5606eee VP |
1863 | loc->watchpoint_type = type; |
1864 | } | |
1865 | } | |
9fa40276 TJB |
1866 | } |
1867 | ||
1868 | /* Change the type of breakpoint between hardware assisted or | |
1869 | an ordinary watchpoint depending on the hardware support | |
1870 | and free hardware slots. REPARSE is set when the inferior | |
1871 | is started. */ | |
a9634178 | 1872 | if (reparse) |
9fa40276 | 1873 | { |
e09342b5 | 1874 | int reg_cnt; |
9fa40276 TJB |
1875 | enum bp_loc_type loc_type; |
1876 | struct bp_location *bl; | |
a5606eee | 1877 | |
a9634178 | 1878 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1879 | |
1880 | if (reg_cnt) | |
9fa40276 TJB |
1881 | { |
1882 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1883 | enum bptype type; |
9fa40276 | 1884 | |
a9634178 TJB |
1885 | /* Use an exact watchpoint when there's only one memory region to be |
1886 | watched, and only one debug register is needed to watch it. */ | |
1887 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1888 | ||
9fa40276 | 1889 | /* We need to determine how many resources are already |
e09342b5 TJB |
1890 | used for all other hardware watchpoints plus this one |
1891 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1892 | this watchpoint in as well. */ |
1893 | ||
1894 | /* If this is a software watchpoint, we try to turn it | |
1895 | to a hardware one -- count resources as if B was of | |
1896 | hardware watchpoint type. */ | |
c1fc2657 | 1897 | type = b->type; |
a1398e0c PA |
1898 | if (type == bp_watchpoint) |
1899 | type = bp_hardware_watchpoint; | |
1900 | ||
1901 | /* This watchpoint may or may not have been placed on | |
1902 | the list yet at this point (it won't be in the list | |
1903 | if we're trying to create it for the first time, | |
1904 | through watch_command), so always account for it | |
1905 | manually. */ | |
1906 | ||
1907 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 1908 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
1909 | |
1910 | /* Add in the resources needed for B. */ | |
c1fc2657 | 1911 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
1912 | |
1913 | target_resources_ok | |
1914 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 1915 | if (target_resources_ok <= 0) |
a9634178 | 1916 | { |
c1fc2657 | 1917 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
1918 | |
1919 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1920 | error (_("Target does not support this type of " |
1921 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1922 | else if (target_resources_ok < 0 && !sw_mode) |
1923 | error (_("There are not enough available hardware " | |
1924 | "resources for this watchpoint.")); | |
a1398e0c PA |
1925 | |
1926 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 1927 | b->type = bp_watchpoint; |
a1398e0c PA |
1928 | } |
1929 | else | |
1930 | { | |
1931 | /* If this was a software watchpoint, we've just | |
1932 | found we have enough resources to turn it to a | |
1933 | hardware watchpoint. Otherwise, this is a | |
1934 | nop. */ | |
c1fc2657 | 1935 | b->type = type; |
a9634178 | 1936 | } |
9fa40276 | 1937 | } |
c1fc2657 | 1938 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
1939 | { |
1940 | if (!can_use_hw_watchpoints) | |
1941 | error (_("Can't set read/access watchpoint when " | |
1942 | "hardware watchpoints are disabled.")); | |
1943 | else | |
1944 | error (_("Expression cannot be implemented with " | |
1945 | "read/access watchpoint.")); | |
1946 | } | |
9fa40276 | 1947 | else |
c1fc2657 | 1948 | b->type = bp_watchpoint; |
9fa40276 | 1949 | |
c1fc2657 | 1950 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 1951 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 1952 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
1953 | bl->loc_type = loc_type; |
1954 | } | |
1955 | ||
c7437ca6 PA |
1956 | /* If a software watchpoint is not watching any memory, then the |
1957 | above left it without any location set up. But, | |
1958 | bpstat_stop_status requires a location to be able to report | |
1959 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
1960 | if (b->type == bp_watchpoint && b->loc == NULL) |
1961 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
1962 | } |
1963 | else if (!within_current_scope) | |
7270d8f2 | 1964 | { |
ac74f770 MS |
1965 | printf_filtered (_("\ |
1966 | Watchpoint %d deleted because the program has left the block\n\ | |
1967 | in which its expression is valid.\n"), | |
c1fc2657 | 1968 | b->number); |
d0fb5eae | 1969 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1970 | } |
a5606eee VP |
1971 | |
1972 | /* Restore the selected frame. */ | |
66076460 DJ |
1973 | if (frame_saved) |
1974 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1975 | } |
1976 | ||
a5606eee | 1977 | |
74960c60 | 1978 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
1979 | inserted in the inferior. We don't differentiate the type of BL's owner |
1980 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
1981 | breakpoint_ops is not defined, because in insert_bp_location, | |
1982 | tracepoint's insert_location will not be called. */ | |
74960c60 | 1983 | static int |
35df4500 | 1984 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1985 | { |
35df4500 | 1986 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1987 | return 0; |
1988 | ||
35df4500 | 1989 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1990 | return 0; |
1991 | ||
35df4500 | 1992 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1993 | return 0; |
1994 | ||
f8eba3c6 TT |
1995 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
1996 | return 0; | |
1997 | ||
56710373 PA |
1998 | /* This is set for example, when we're attached to the parent of a |
1999 | vfork, and have detached from the child. The child is running | |
2000 | free, and we expect it to do an exec or exit, at which point the | |
2001 | OS makes the parent schedulable again (and the target reports | |
2002 | that the vfork is done). Until the child is done with the shared | |
2003 | memory region, do not insert breakpoints in the parent, otherwise | |
2004 | the child could still trip on the parent's breakpoints. Since | |
2005 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2006 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2007 | return 0; |
2008 | ||
31e77af2 | 2009 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2010 | location, except if the breakpoint is a single-step breakpoint, |
2011 | and the breakpoint's thread is the thread which is stepping past | |
2012 | a breakpoint. */ | |
31e77af2 PA |
2013 | if ((bl->loc_type == bp_loc_software_breakpoint |
2014 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2015 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2016 | bl->address) |
2017 | /* The single-step breakpoint may be inserted at the location | |
2018 | we're trying to step if the instruction branches to itself. | |
2019 | However, the instruction won't be executed at all and it may | |
2020 | break the semantics of the instruction, for example, the | |
2021 | instruction is a conditional branch or updates some flags. | |
2022 | We can't fix it unless GDB is able to emulate the instruction | |
2023 | or switch to displaced stepping. */ | |
2024 | && !(bl->owner->type == bp_single_step | |
2025 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2026 | { |
2027 | if (debug_infrun) | |
2028 | { | |
2029 | fprintf_unfiltered (gdb_stdlog, | |
2030 | "infrun: skipping breakpoint: " | |
2031 | "stepping past insn at: %s\n", | |
2032 | paddress (bl->gdbarch, bl->address)); | |
2033 | } | |
2034 | return 0; | |
2035 | } | |
31e77af2 | 2036 | |
963f9c80 PA |
2037 | /* Don't insert watchpoints if we're trying to step past the |
2038 | instruction that triggered one. */ | |
2039 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2040 | && stepping_past_nonsteppable_watchpoint ()) | |
2041 | { | |
2042 | if (debug_infrun) | |
2043 | { | |
2044 | fprintf_unfiltered (gdb_stdlog, | |
2045 | "infrun: stepping past non-steppable watchpoint. " | |
2046 | "skipping watchpoint at %s:%d\n", | |
2047 | paddress (bl->gdbarch, bl->address), | |
2048 | bl->length); | |
2049 | } | |
2050 | return 0; | |
2051 | } | |
2052 | ||
74960c60 VP |
2053 | return 1; |
2054 | } | |
2055 | ||
934709f0 PW |
2056 | /* Same as should_be_inserted but does the check assuming |
2057 | that the location is not duplicated. */ | |
2058 | ||
2059 | static int | |
2060 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2061 | { | |
2062 | int result; | |
2063 | const int save_duplicate = bl->duplicate; | |
2064 | ||
2065 | bl->duplicate = 0; | |
2066 | result = should_be_inserted (bl); | |
2067 | bl->duplicate = save_duplicate; | |
2068 | return result; | |
2069 | } | |
2070 | ||
b775012e LM |
2071 | /* Parses a conditional described by an expression COND into an |
2072 | agent expression bytecode suitable for evaluation | |
2073 | by the bytecode interpreter. Return NULL if there was | |
2074 | any error during parsing. */ | |
2075 | ||
833177a4 | 2076 | static agent_expr_up |
b775012e LM |
2077 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2078 | { | |
833177a4 | 2079 | if (cond == NULL) |
b775012e LM |
2080 | return NULL; |
2081 | ||
833177a4 PA |
2082 | agent_expr_up aexpr; |
2083 | ||
b775012e LM |
2084 | /* We don't want to stop processing, so catch any errors |
2085 | that may show up. */ | |
a70b8144 | 2086 | try |
b775012e | 2087 | { |
036e657b | 2088 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2089 | } |
2090 | ||
230d2906 | 2091 | catch (const gdb_exception_error &ex) |
b775012e LM |
2092 | { |
2093 | /* If we got here, it means the condition could not be parsed to a valid | |
2094 | bytecode expression and thus can't be evaluated on the target's side. | |
2095 | It's no use iterating through the conditions. */ | |
b775012e LM |
2096 | } |
2097 | ||
2098 | /* We have a valid agent expression. */ | |
2099 | return aexpr; | |
2100 | } | |
2101 | ||
2102 | /* Based on location BL, create a list of breakpoint conditions to be | |
2103 | passed on to the target. If we have duplicated locations with different | |
2104 | conditions, we will add such conditions to the list. The idea is that the | |
2105 | target will evaluate the list of conditions and will only notify GDB when | |
2106 | one of them is true. */ | |
2107 | ||
2108 | static void | |
2109 | build_target_condition_list (struct bp_location *bl) | |
2110 | { | |
2111 | struct bp_location **locp = NULL, **loc2p; | |
2112 | int null_condition_or_parse_error = 0; | |
2113 | int modified = bl->needs_update; | |
2114 | struct bp_location *loc; | |
2115 | ||
8b4f3082 | 2116 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2117 | bl->target_info.conditions.clear (); |
8b4f3082 | 2118 | |
b775012e LM |
2119 | /* This is only meaningful if the target is |
2120 | evaluating conditions and if the user has | |
2121 | opted for condition evaluation on the target's | |
2122 | side. */ | |
2123 | if (gdb_evaluates_breakpoint_condition_p () | |
2124 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2125 | return; | |
2126 | ||
2127 | /* Do a first pass to check for locations with no assigned | |
2128 | conditions or conditions that fail to parse to a valid agent expression | |
2129 | bytecode. If any of these happen, then it's no use to send conditions | |
2130 | to the target since this location will always trigger and generate a | |
2131 | response back to GDB. */ | |
2132 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2133 | { | |
2134 | loc = (*loc2p); | |
2135 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2136 | { | |
2137 | if (modified) | |
2138 | { | |
b775012e LM |
2139 | /* Re-parse the conditions since something changed. In that |
2140 | case we already freed the condition bytecodes (see | |
2141 | force_breakpoint_reinsertion). We just | |
2142 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2143 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2144 | loc->cond.get ()); | |
b775012e LM |
2145 | } |
2146 | ||
2147 | /* If we have a NULL bytecode expression, it means something | |
2148 | went wrong or we have a null condition expression. */ | |
2149 | if (!loc->cond_bytecode) | |
2150 | { | |
2151 | null_condition_or_parse_error = 1; | |
2152 | break; | |
2153 | } | |
2154 | } | |
2155 | } | |
2156 | ||
2157 | /* If any of these happened, it means we will have to evaluate the conditions | |
2158 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2159 | for all the other duplicate locations, thus we free all of them here. | |
2160 | ||
2161 | This is so we have a finer control over which locations' conditions are | |
2162 | being evaluated by GDB or the remote stub. */ | |
2163 | if (null_condition_or_parse_error) | |
2164 | { | |
2165 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2166 | { | |
2167 | loc = (*loc2p); | |
2168 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2169 | { | |
2170 | /* Only go as far as the first NULL bytecode is | |
2171 | located. */ | |
2172 | if (!loc->cond_bytecode) | |
2173 | return; | |
2174 | ||
833177a4 | 2175 | loc->cond_bytecode.reset (); |
b775012e LM |
2176 | } |
2177 | } | |
2178 | } | |
2179 | ||
2180 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2181 | for this location's address. */ | |
2182 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2183 | { | |
2184 | loc = (*loc2p); | |
2185 | if (loc->cond | |
2186 | && is_breakpoint (loc->owner) | |
2187 | && loc->pspace->num == bl->pspace->num | |
2188 | && loc->owner->enable_state == bp_enabled | |
2189 | && loc->enabled) | |
3cde5c42 PA |
2190 | { |
2191 | /* Add the condition to the vector. This will be used later | |
2192 | to send the conditions to the target. */ | |
2193 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2194 | } | |
b775012e LM |
2195 | } |
2196 | ||
2197 | return; | |
2198 | } | |
2199 | ||
d3ce09f5 SS |
2200 | /* Parses a command described by string CMD into an agent expression |
2201 | bytecode suitable for evaluation by the bytecode interpreter. | |
2202 | Return NULL if there was any error during parsing. */ | |
2203 | ||
833177a4 | 2204 | static agent_expr_up |
d3ce09f5 SS |
2205 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2206 | { | |
bbc13ae3 KS |
2207 | const char *cmdrest; |
2208 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2209 | struct gdbarch *gdbarch = get_current_arch (); |
2210 | ||
833177a4 | 2211 | if (cmd == NULL) |
d3ce09f5 SS |
2212 | return NULL; |
2213 | ||
2214 | cmdrest = cmd; | |
2215 | ||
2216 | if (*cmdrest == ',') | |
2217 | ++cmdrest; | |
f1735a53 | 2218 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2219 | |
2220 | if (*cmdrest++ != '"') | |
2221 | error (_("No format string following the location")); | |
2222 | ||
2223 | format_start = cmdrest; | |
2224 | ||
8e481c3b | 2225 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2226 | |
2227 | format_end = cmdrest; | |
2228 | ||
2229 | if (*cmdrest++ != '"') | |
2230 | error (_("Bad format string, non-terminated '\"'.")); | |
2231 | ||
f1735a53 | 2232 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2233 | |
2234 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2235 | error (_("Invalid argument syntax")); | |
2236 | ||
2237 | if (*cmdrest == ',') | |
2238 | cmdrest++; | |
f1735a53 | 2239 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2240 | |
2241 | /* For each argument, make an expression. */ | |
2242 | ||
8e481c3b | 2243 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2244 | while (*cmdrest != '\0') |
2245 | { | |
bbc13ae3 | 2246 | const char *cmd1; |
d3ce09f5 SS |
2247 | |
2248 | cmd1 = cmdrest; | |
4d01a485 | 2249 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2250 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2251 | cmdrest = cmd1; |
2252 | if (*cmdrest == ',') | |
2253 | ++cmdrest; | |
2254 | } | |
2255 | ||
833177a4 PA |
2256 | agent_expr_up aexpr; |
2257 | ||
d3ce09f5 SS |
2258 | /* We don't want to stop processing, so catch any errors |
2259 | that may show up. */ | |
a70b8144 | 2260 | try |
d3ce09f5 | 2261 | { |
036e657b JB |
2262 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2263 | format_start, format_end - format_start, | |
8e481c3b | 2264 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2265 | } |
230d2906 | 2266 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2267 | { |
2268 | /* If we got here, it means the command could not be parsed to a valid | |
2269 | bytecode expression and thus can't be evaluated on the target's side. | |
2270 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2271 | } |
492d29ea | 2272 | |
d3ce09f5 SS |
2273 | /* We have a valid agent expression, return it. */ |
2274 | return aexpr; | |
2275 | } | |
2276 | ||
2277 | /* Based on location BL, create a list of breakpoint commands to be | |
2278 | passed on to the target. If we have duplicated locations with | |
2279 | different commands, we will add any such to the list. */ | |
2280 | ||
2281 | static void | |
2282 | build_target_command_list (struct bp_location *bl) | |
2283 | { | |
2284 | struct bp_location **locp = NULL, **loc2p; | |
2285 | int null_command_or_parse_error = 0; | |
2286 | int modified = bl->needs_update; | |
2287 | struct bp_location *loc; | |
2288 | ||
3cde5c42 PA |
2289 | /* Clear commands left over from a previous insert. */ |
2290 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2291 | |
41fac0cf | 2292 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2293 | return; |
2294 | ||
41fac0cf PA |
2295 | /* For now, limit to agent-style dprintf breakpoints. */ |
2296 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2297 | return; |
2298 | ||
41fac0cf PA |
2299 | /* For now, if we have any duplicate location that isn't a dprintf, |
2300 | don't install the target-side commands, as that would make the | |
2301 | breakpoint not be reported to the core, and we'd lose | |
2302 | control. */ | |
2303 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2304 | { | |
2305 | loc = (*loc2p); | |
2306 | if (is_breakpoint (loc->owner) | |
2307 | && loc->pspace->num == bl->pspace->num | |
2308 | && loc->owner->type != bp_dprintf) | |
2309 | return; | |
2310 | } | |
2311 | ||
d3ce09f5 SS |
2312 | /* Do a first pass to check for locations with no assigned |
2313 | conditions or conditions that fail to parse to a valid agent expression | |
2314 | bytecode. If any of these happen, then it's no use to send conditions | |
2315 | to the target since this location will always trigger and generate a | |
2316 | response back to GDB. */ | |
2317 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2318 | { | |
2319 | loc = (*loc2p); | |
2320 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2321 | { | |
2322 | if (modified) | |
2323 | { | |
d3ce09f5 SS |
2324 | /* Re-parse the commands since something changed. In that |
2325 | case we already freed the command bytecodes (see | |
2326 | force_breakpoint_reinsertion). We just | |
2327 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2328 | loc->cmd_bytecode |
2329 | = parse_cmd_to_aexpr (bl->address, | |
2330 | loc->owner->extra_string); | |
d3ce09f5 SS |
2331 | } |
2332 | ||
2333 | /* If we have a NULL bytecode expression, it means something | |
2334 | went wrong or we have a null command expression. */ | |
2335 | if (!loc->cmd_bytecode) | |
2336 | { | |
2337 | null_command_or_parse_error = 1; | |
2338 | break; | |
2339 | } | |
2340 | } | |
2341 | } | |
2342 | ||
2343 | /* If anything failed, then we're not doing target-side commands, | |
2344 | and so clean up. */ | |
2345 | if (null_command_or_parse_error) | |
2346 | { | |
2347 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2348 | { | |
2349 | loc = (*loc2p); | |
2350 | if (is_breakpoint (loc->owner) | |
2351 | && loc->pspace->num == bl->pspace->num) | |
2352 | { | |
2353 | /* Only go as far as the first NULL bytecode is | |
2354 | located. */ | |
40fb6c5e | 2355 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2356 | return; |
2357 | ||
833177a4 | 2358 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2359 | } |
2360 | } | |
2361 | } | |
2362 | ||
2363 | /* No NULL commands or failed bytecode generation. Build a command list | |
2364 | for this location's address. */ | |
2365 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2366 | { | |
2367 | loc = (*loc2p); | |
2368 | if (loc->owner->extra_string | |
2369 | && is_breakpoint (loc->owner) | |
2370 | && loc->pspace->num == bl->pspace->num | |
2371 | && loc->owner->enable_state == bp_enabled | |
2372 | && loc->enabled) | |
3cde5c42 PA |
2373 | { |
2374 | /* Add the command to the vector. This will be used later | |
2375 | to send the commands to the target. */ | |
2376 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2377 | } | |
d3ce09f5 SS |
2378 | } |
2379 | ||
2380 | bl->target_info.persist = 0; | |
2381 | /* Maybe flag this location as persistent. */ | |
2382 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2383 | bl->target_info.persist = 1; | |
2384 | } | |
2385 | ||
833b7ab5 YQ |
2386 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2387 | of breakpoint according to ADDR except single-step breakpoint. | |
2388 | Get the kind of single-step breakpoint according to the current | |
2389 | registers state. */ | |
cd6c3b4f YQ |
2390 | |
2391 | static int | |
2392 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2393 | { | |
833b7ab5 YQ |
2394 | if (bl->owner->type == bp_single_step) |
2395 | { | |
2396 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2397 | struct regcache *regcache; | |
2398 | ||
00431a78 | 2399 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2400 | |
2401 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2402 | regcache, addr); | |
2403 | } | |
2404 | else | |
2405 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2406 | } |
2407 | ||
35df4500 TJB |
2408 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2409 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2410 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2411 | Returns 0 for success, 1 if the bp_location type is not supported or |
2412 | -1 for failure. | |
879bfdc2 | 2413 | |
4a64f543 MS |
2414 | NOTE drow/2003-09-09: This routine could be broken down to an |
2415 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2416 | static int |
35df4500 | 2417 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2418 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2419 | int *disabled_breaks, |
dd61ec5c MW |
2420 | int *hw_breakpoint_error, |
2421 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2422 | { |
cc06b668 | 2423 | gdb_exception bp_excpt; |
879bfdc2 | 2424 | |
b775012e | 2425 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2426 | return 0; |
2427 | ||
35c63cd8 JB |
2428 | /* Note we don't initialize bl->target_info, as that wipes out |
2429 | the breakpoint location's shadow_contents if the breakpoint | |
2430 | is still inserted at that location. This in turn breaks | |
2431 | target_read_memory which depends on these buffers when | |
2432 | a memory read is requested at the breakpoint location: | |
2433 | Once the target_info has been wiped, we fail to see that | |
2434 | we have a breakpoint inserted at that address and thus | |
2435 | read the breakpoint instead of returning the data saved in | |
2436 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2437 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2438 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2439 | bl->target_info.length = bl->length; |
8181d85f | 2440 | |
b775012e LM |
2441 | /* When working with target-side conditions, we must pass all the conditions |
2442 | for the same breakpoint address down to the target since GDB will not | |
2443 | insert those locations. With a list of breakpoint conditions, the target | |
2444 | can decide when to stop and notify GDB. */ | |
2445 | ||
2446 | if (is_breakpoint (bl->owner)) | |
2447 | { | |
2448 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2449 | build_target_command_list (bl); |
2450 | /* Reset the modification marker. */ | |
b775012e LM |
2451 | bl->needs_update = 0; |
2452 | } | |
2453 | ||
35df4500 TJB |
2454 | if (bl->loc_type == bp_loc_software_breakpoint |
2455 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2456 | { |
35df4500 | 2457 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2458 | { |
2459 | /* If the explicitly specified breakpoint type | |
2460 | is not hardware breakpoint, check the memory map to see | |
2461 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2462 | |
765dc015 VP |
2463 | Two important cases are: |
2464 | - location type is not hardware breakpoint, memory | |
2465 | is readonly. We change the type of the location to | |
2466 | hardware breakpoint. | |
4a64f543 MS |
2467 | - location type is hardware breakpoint, memory is |
2468 | read-write. This means we've previously made the | |
2469 | location hardware one, but then the memory map changed, | |
2470 | so we undo. | |
765dc015 | 2471 | |
4a64f543 MS |
2472 | When breakpoints are removed, remove_breakpoints will use |
2473 | location types we've just set here, the only possible | |
2474 | problem is that memory map has changed during running | |
2475 | program, but it's not going to work anyway with current | |
2476 | gdb. */ | |
765dc015 | 2477 | struct mem_region *mr |
0d5ed153 | 2478 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2479 | |
2480 | if (mr) | |
2481 | { | |
2482 | if (automatic_hardware_breakpoints) | |
2483 | { | |
765dc015 VP |
2484 | enum bp_loc_type new_type; |
2485 | ||
2486 | if (mr->attrib.mode != MEM_RW) | |
2487 | new_type = bp_loc_hardware_breakpoint; | |
2488 | else | |
2489 | new_type = bp_loc_software_breakpoint; | |
2490 | ||
35df4500 | 2491 | if (new_type != bl->loc_type) |
765dc015 VP |
2492 | { |
2493 | static int said = 0; | |
cc59ec59 | 2494 | |
35df4500 | 2495 | bl->loc_type = new_type; |
765dc015 VP |
2496 | if (!said) |
2497 | { | |
3e43a32a MS |
2498 | fprintf_filtered (gdb_stdout, |
2499 | _("Note: automatically using " | |
2500 | "hardware breakpoints for " | |
2501 | "read-only addresses.\n")); | |
765dc015 VP |
2502 | said = 1; |
2503 | } | |
2504 | } | |
2505 | } | |
35df4500 | 2506 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2507 | && mr->attrib.mode != MEM_RW) |
2508 | { | |
2509 | fprintf_unfiltered (tmp_error_stream, | |
2510 | _("Cannot insert breakpoint %d.\n" | |
2511 | "Cannot set software breakpoint " | |
2512 | "at read-only address %s\n"), | |
2513 | bl->owner->number, | |
2514 | paddress (bl->gdbarch, bl->address)); | |
2515 | return 1; | |
2516 | } | |
765dc015 VP |
2517 | } |
2518 | } | |
2519 | ||
879bfdc2 DJ |
2520 | /* First check to see if we have to handle an overlay. */ |
2521 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2522 | || bl->section == NULL |
2523 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2524 | { |
2525 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2526 | try |
dd61ec5c | 2527 | { |
0000e5cc PA |
2528 | int val; |
2529 | ||
dd61ec5c | 2530 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2531 | if (val) |
688fca4f | 2532 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2533 | } |
94aeb44b | 2534 | catch (gdb_exception &e) |
dd61ec5c | 2535 | { |
94aeb44b | 2536 | bp_excpt = std::move (e); |
dd61ec5c | 2537 | } |
879bfdc2 DJ |
2538 | } |
2539 | else | |
2540 | { | |
4a64f543 | 2541 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2542 | Shall we set a breakpoint at the LMA? */ |
2543 | if (!overlay_events_enabled) | |
2544 | { | |
2545 | /* Yes -- overlay event support is not active, | |
2546 | so we must try to set a breakpoint at the LMA. | |
2547 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2548 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2549 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2550 | bl->owner->number); |
879bfdc2 DJ |
2551 | else |
2552 | { | |
35df4500 TJB |
2553 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2554 | bl->section); | |
879bfdc2 | 2555 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2556 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2557 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2558 | |
2559 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2560 | try |
0000e5cc PA |
2561 | { |
2562 | int val; | |
2563 | ||
579c6ad9 | 2564 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2565 | = breakpoint_kind (bl, &addr); |
2566 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2567 | val = target_insert_breakpoint (bl->gdbarch, |
2568 | &bl->overlay_target_info); | |
2569 | if (val) | |
688fca4f PA |
2570 | bp_excpt |
2571 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2572 | } |
94aeb44b | 2573 | catch (gdb_exception &e) |
0000e5cc | 2574 | { |
94aeb44b | 2575 | bp_excpt = std::move (e); |
0000e5cc PA |
2576 | } |
2577 | ||
688fca4f | 2578 | if (bp_excpt.reason != 0) |
99361f52 | 2579 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2580 | "Overlay breakpoint %d " |
2581 | "failed: in ROM?\n", | |
35df4500 | 2582 | bl->owner->number); |
879bfdc2 DJ |
2583 | } |
2584 | } | |
2585 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2586 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2587 | { |
2588 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2589 | try |
dd61ec5c | 2590 | { |
0000e5cc PA |
2591 | int val; |
2592 | ||
dd61ec5c | 2593 | val = bl->owner->ops->insert_location (bl); |
0000e5cc | 2594 | if (val) |
688fca4f | 2595 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2596 | } |
94aeb44b | 2597 | catch (gdb_exception &e) |
dd61ec5c | 2598 | { |
94aeb44b | 2599 | bp_excpt = std::move (e); |
dd61ec5c | 2600 | } |
879bfdc2 DJ |
2601 | } |
2602 | else | |
2603 | { | |
2604 | /* No. This breakpoint will not be inserted. | |
2605 | No error, but do not mark the bp as 'inserted'. */ | |
2606 | return 0; | |
2607 | } | |
2608 | } | |
2609 | ||
688fca4f | 2610 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2611 | { |
2612 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2613 | |
2614 | /* In some cases, we might not be able to insert a | |
2615 | breakpoint in a shared library that has already been | |
2616 | removed, but we have not yet processed the shlib unload | |
2617 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2618 | breakpoint insertion themselves can't tell why the |
2619 | breakpoint insertion failed (e.g., the remote target | |
2620 | doesn't define error codes), so we must treat generic | |
2621 | errors as memory errors. */ | |
688fca4f PA |
2622 | if (bp_excpt.reason == RETURN_ERROR |
2623 | && (bp_excpt.error == GENERIC_ERROR | |
2624 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2625 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2626 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2627 | || shared_objfile_contains_address_p (bl->pspace, |
2628 | bl->address))) | |
879bfdc2 | 2629 | { |
4a64f543 | 2630 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2631 | bl->shlib_disabled = 1; |
76727919 | 2632 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2633 | if (!*disabled_breaks) |
2634 | { | |
2635 | fprintf_unfiltered (tmp_error_stream, | |
2636 | "Cannot insert breakpoint %d.\n", | |
2637 | bl->owner->number); | |
2638 | fprintf_unfiltered (tmp_error_stream, | |
2639 | "Temporarily disabling shared " | |
2640 | "library breakpoints:\n"); | |
2641 | } | |
2642 | *disabled_breaks = 1; | |
879bfdc2 | 2643 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2644 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2645 | return 0; |
879bfdc2 DJ |
2646 | } |
2647 | else | |
879bfdc2 | 2648 | { |
35df4500 | 2649 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2650 | { |
0000e5cc | 2651 | *hw_breakpoint_error = 1; |
688fca4f | 2652 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
dd61ec5c MW |
2653 | fprintf_unfiltered (tmp_error_stream, |
2654 | "Cannot insert hardware breakpoint %d%s", | |
688fca4f PA |
2655 | bl->owner->number, |
2656 | bp_excpt.message ? ":" : ".\n"); | |
2657 | if (bp_excpt.message != NULL) | |
2658 | fprintf_unfiltered (tmp_error_stream, "%s.\n", | |
3d6e9d23 | 2659 | bp_excpt.what ()); |
879bfdc2 DJ |
2660 | } |
2661 | else | |
2662 | { | |
688fca4f | 2663 | if (bp_excpt.message == NULL) |
0000e5cc | 2664 | { |
1ccbe998 | 2665 | std::string message |
0000e5cc PA |
2666 | = memory_error_message (TARGET_XFER_E_IO, |
2667 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2668 | |
2669 | fprintf_unfiltered (tmp_error_stream, | |
2670 | "Cannot insert breakpoint %d.\n" | |
2671 | "%s\n", | |
1ccbe998 | 2672 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2673 | } |
2674 | else | |
2675 | { | |
2676 | fprintf_unfiltered (tmp_error_stream, | |
2677 | "Cannot insert breakpoint %d: %s\n", | |
2678 | bl->owner->number, | |
3d6e9d23 | 2679 | bp_excpt.what ()); |
0000e5cc | 2680 | } |
879bfdc2 | 2681 | } |
0000e5cc | 2682 | return 1; |
879bfdc2 DJ |
2683 | |
2684 | } | |
2685 | } | |
2686 | else | |
35df4500 | 2687 | bl->inserted = 1; |
879bfdc2 | 2688 | |
0000e5cc | 2689 | return 0; |
879bfdc2 DJ |
2690 | } |
2691 | ||
35df4500 | 2692 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2693 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2694 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2695 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2696 | { |
0000e5cc PA |
2697 | int val; |
2698 | ||
77b06cd7 TJB |
2699 | gdb_assert (bl->owner->ops != NULL |
2700 | && bl->owner->ops->insert_location != NULL); | |
2701 | ||
2702 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2703 | |
2704 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2705 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2706 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2707 | { |
2708 | struct bp_location *loc, **loc_temp; | |
2709 | ||
2710 | /* But don't try to insert it, if there's already another | |
2711 | hw_access location that would be considered a duplicate | |
2712 | of this one. */ | |
2713 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2714 | if (loc != bl |
85d721b8 | 2715 | && loc->watchpoint_type == hw_access |
35df4500 | 2716 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2717 | { |
35df4500 TJB |
2718 | bl->duplicate = 1; |
2719 | bl->inserted = 1; | |
2720 | bl->target_info = loc->target_info; | |
2721 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2722 | val = 0; |
2723 | break; | |
2724 | } | |
2725 | ||
2726 | if (val == 1) | |
2727 | { | |
77b06cd7 TJB |
2728 | bl->watchpoint_type = hw_access; |
2729 | val = bl->owner->ops->insert_location (bl); | |
2730 | ||
2731 | if (val) | |
2732 | /* Back to the original value. */ | |
2733 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2734 | } |
2735 | } | |
2736 | ||
35df4500 | 2737 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2738 | } |
2739 | ||
35df4500 | 2740 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2741 | { |
0000e5cc PA |
2742 | int val; |
2743 | ||
77b06cd7 TJB |
2744 | gdb_assert (bl->owner->ops != NULL |
2745 | && bl->owner->ops->insert_location != NULL); | |
2746 | ||
2747 | val = bl->owner->ops->insert_location (bl); | |
2748 | if (val) | |
2749 | { | |
2750 | bl->owner->enable_state = bp_disabled; | |
2751 | ||
2752 | if (val == 1) | |
2753 | warning (_("\ | |
2754 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2755 | of catchpoint."), bl->owner->number); | |
2756 | else | |
2757 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2758 | } | |
2759 | ||
2760 | bl->inserted = (val == 0); | |
1640b821 DJ |
2761 | |
2762 | /* We've already printed an error message if there was a problem | |
2763 | inserting this catchpoint, and we've disabled the catchpoint, | |
2764 | so just return success. */ | |
2765 | return 0; | |
879bfdc2 DJ |
2766 | } |
2767 | ||
2768 | return 0; | |
2769 | } | |
2770 | ||
6c95b8df PA |
2771 | /* This function is called when program space PSPACE is about to be |
2772 | deleted. It takes care of updating breakpoints to not reference | |
2773 | PSPACE anymore. */ | |
2774 | ||
2775 | void | |
2776 | breakpoint_program_space_exit (struct program_space *pspace) | |
2777 | { | |
2778 | struct breakpoint *b, *b_temp; | |
876fa593 | 2779 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2780 | |
2781 | /* Remove any breakpoint that was set through this program space. */ | |
2782 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2783 | { | |
2784 | if (b->pspace == pspace) | |
2785 | delete_breakpoint (b); | |
2786 | } | |
2787 | ||
2788 | /* Breakpoints set through other program spaces could have locations | |
2789 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2790 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2791 | { |
2792 | struct bp_location *tmp; | |
2793 | ||
2794 | if (loc->pspace == pspace) | |
2795 | { | |
2bdf28a0 | 2796 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2797 | if (loc->owner->loc == loc) |
2798 | loc->owner->loc = loc->next; | |
2799 | else | |
2800 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2801 | if (tmp->next == loc) | |
2802 | { | |
2803 | tmp->next = loc->next; | |
2804 | break; | |
2805 | } | |
2806 | } | |
2807 | } | |
2808 | ||
2809 | /* Now update the global location list to permanently delete the | |
2810 | removed locations above. */ | |
44702360 | 2811 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2812 | } |
2813 | ||
74960c60 VP |
2814 | /* Make sure all breakpoints are inserted in inferior. |
2815 | Throws exception on any error. | |
2816 | A breakpoint that is already inserted won't be inserted | |
2817 | again, so calling this function twice is safe. */ | |
2818 | void | |
2819 | insert_breakpoints (void) | |
2820 | { | |
2821 | struct breakpoint *bpt; | |
2822 | ||
2823 | ALL_BREAKPOINTS (bpt) | |
2824 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2825 | { |
2826 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2827 | ||
2828 | update_watchpoint (w, 0 /* don't reparse. */); | |
2829 | } | |
74960c60 | 2830 | |
04086b45 PA |
2831 | /* Updating watchpoints creates new locations, so update the global |
2832 | location list. Explicitly tell ugll to insert locations and | |
2833 | ignore breakpoints_always_inserted_mode. */ | |
2834 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2835 | } |
2836 | ||
20388dd6 YQ |
2837 | /* Invoke CALLBACK for each of bp_location. */ |
2838 | ||
2839 | void | |
2840 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2841 | { | |
2842 | struct bp_location *loc, **loc_tmp; | |
2843 | ||
2844 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2845 | { | |
2846 | callback (loc, NULL); | |
2847 | } | |
2848 | } | |
2849 | ||
b775012e LM |
2850 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2851 | target. It is the case with deleting and disabling of breakpoints when using | |
2852 | always-inserted mode. */ | |
2853 | ||
2854 | static void | |
2855 | update_inserted_breakpoint_locations (void) | |
2856 | { | |
2857 | struct bp_location *bl, **blp_tmp; | |
2858 | int error_flag = 0; | |
2859 | int val = 0; | |
2860 | int disabled_breaks = 0; | |
2861 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2862 | int hw_bp_details_reported = 0; |
b775012e | 2863 | |
d7e74731 | 2864 | string_file tmp_error_stream; |
b775012e LM |
2865 | |
2866 | /* Explicitly mark the warning -- this will only be printed if | |
2867 | there was an error. */ | |
d7e74731 | 2868 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2869 | |
5ed8105e | 2870 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2871 | |
2872 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2873 | { | |
2874 | /* We only want to update software breakpoints and hardware | |
2875 | breakpoints. */ | |
2876 | if (!is_breakpoint (bl->owner)) | |
2877 | continue; | |
2878 | ||
2879 | /* We only want to update locations that are already inserted | |
2880 | and need updating. This is to avoid unwanted insertion during | |
2881 | deletion of breakpoints. */ | |
4daf1902 | 2882 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
2883 | continue; |
2884 | ||
2885 | switch_to_program_space_and_thread (bl->pspace); | |
2886 | ||
2887 | /* For targets that support global breakpoints, there's no need | |
2888 | to select an inferior to insert breakpoint to. In fact, even | |
2889 | if we aren't attached to any process yet, we should still | |
2890 | insert breakpoints. */ | |
f5656ead | 2891 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
5b6d1e4f | 2892 | && (inferior_ptid == null_ptid || !target_has_execution)) |
b775012e LM |
2893 | continue; |
2894 | ||
d7e74731 | 2895 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2896 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
2897 | if (val) |
2898 | error_flag = val; | |
2899 | } | |
2900 | ||
2901 | if (error_flag) | |
2902 | { | |
223ffa71 | 2903 | target_terminal::ours_for_output (); |
b775012e LM |
2904 | error_stream (tmp_error_stream); |
2905 | } | |
b775012e LM |
2906 | } |
2907 | ||
c30eee59 | 2908 | /* Used when starting or continuing the program. */ |
c906108c | 2909 | |
74960c60 VP |
2910 | static void |
2911 | insert_breakpoint_locations (void) | |
c906108c | 2912 | { |
a5606eee | 2913 | struct breakpoint *bpt; |
35df4500 | 2914 | struct bp_location *bl, **blp_tmp; |
eacd795a | 2915 | int error_flag = 0; |
c906108c | 2916 | int val = 0; |
3fbb6ffa | 2917 | int disabled_breaks = 0; |
81d0cc19 | 2918 | int hw_breakpoint_error = 0; |
dd61ec5c | 2919 | int hw_bp_error_explained_already = 0; |
c906108c | 2920 | |
d7e74731 PA |
2921 | string_file tmp_error_stream; |
2922 | ||
81d0cc19 GS |
2923 | /* Explicitly mark the warning -- this will only be printed if |
2924 | there was an error. */ | |
d7e74731 | 2925 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 2926 | |
5ed8105e | 2927 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 2928 | |
35df4500 | 2929 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2930 | { |
b775012e | 2931 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2932 | continue; |
2933 | ||
4a64f543 MS |
2934 | /* There is no point inserting thread-specific breakpoints if |
2935 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2936 | has BL->OWNER always non-NULL. */ | |
35df4500 | 2937 | if (bl->owner->thread != -1 |
5d5658a1 | 2938 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
2939 | continue; |
2940 | ||
35df4500 | 2941 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2942 | |
2943 | /* For targets that support global breakpoints, there's no need | |
2944 | to select an inferior to insert breakpoint to. In fact, even | |
2945 | if we aren't attached to any process yet, we should still | |
2946 | insert breakpoints. */ | |
f5656ead | 2947 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
5b6d1e4f | 2948 | && (inferior_ptid == null_ptid || !target_has_execution)) |
6c95b8df PA |
2949 | continue; |
2950 | ||
d7e74731 | 2951 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 2952 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 2953 | if (val) |
eacd795a | 2954 | error_flag = val; |
879bfdc2 | 2955 | } |
c906108c | 2956 | |
4a64f543 MS |
2957 | /* If we failed to insert all locations of a watchpoint, remove |
2958 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2959 | ALL_BREAKPOINTS (bpt) |
2960 | { | |
2961 | int some_failed = 0; | |
2962 | struct bp_location *loc; | |
2963 | ||
2964 | if (!is_hardware_watchpoint (bpt)) | |
2965 | continue; | |
2966 | ||
d6b74ac4 | 2967 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2968 | continue; |
74960c60 VP |
2969 | |
2970 | if (bpt->disposition == disp_del_at_next_stop) | |
2971 | continue; | |
a5606eee VP |
2972 | |
2973 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2974 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2975 | { |
2976 | some_failed = 1; | |
2977 | break; | |
2978 | } | |
2979 | if (some_failed) | |
2980 | { | |
2981 | for (loc = bpt->loc; loc; loc = loc->next) | |
2982 | if (loc->inserted) | |
834c0d03 | 2983 | remove_breakpoint (loc); |
a5606eee VP |
2984 | |
2985 | hw_breakpoint_error = 1; | |
d7e74731 PA |
2986 | tmp_error_stream.printf ("Could not insert " |
2987 | "hardware watchpoint %d.\n", | |
2988 | bpt->number); | |
eacd795a | 2989 | error_flag = -1; |
a5606eee VP |
2990 | } |
2991 | } | |
2992 | ||
eacd795a | 2993 | if (error_flag) |
81d0cc19 GS |
2994 | { |
2995 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2996 | message about possibly exhausted resources. */ | |
dd61ec5c | 2997 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 2998 | { |
d7e74731 | 2999 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3000 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3001 | } |
223ffa71 | 3002 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3003 | error_stream (tmp_error_stream); |
3004 | } | |
c906108c SS |
3005 | } |
3006 | ||
c30eee59 TJB |
3007 | /* Used when the program stops. |
3008 | Returns zero if successful, or non-zero if there was a problem | |
3009 | removing a breakpoint location. */ | |
3010 | ||
c906108c | 3011 | int |
fba45db2 | 3012 | remove_breakpoints (void) |
c906108c | 3013 | { |
35df4500 | 3014 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3015 | int val = 0; |
c906108c | 3016 | |
35df4500 | 3017 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3018 | { |
1e4d1764 | 3019 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3020 | val |= remove_breakpoint (bl); |
c5aa993b | 3021 | } |
3a1bae8e | 3022 | return val; |
c906108c SS |
3023 | } |
3024 | ||
49fa26b0 PA |
3025 | /* When a thread exits, remove breakpoints that are related to |
3026 | that thread. */ | |
3027 | ||
3028 | static void | |
3029 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3030 | { | |
3031 | struct breakpoint *b, *b_tmp; | |
3032 | ||
3033 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3034 | { | |
5d5658a1 | 3035 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3036 | { |
3037 | b->disposition = disp_del_at_next_stop; | |
3038 | ||
3039 | printf_filtered (_("\ | |
43792cf0 PA |
3040 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3041 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3042 | |
3043 | /* Hide it from the user. */ | |
3044 | b->number = 0; | |
3045 | } | |
3046 | } | |
3047 | } | |
3048 | ||
f3869b1a | 3049 | /* See breakpoint.h. */ |
6c95b8df | 3050 | |
f3869b1a | 3051 | void |
00431a78 | 3052 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3053 | { |
35df4500 | 3054 | struct bp_location *bl, **blp_tmp; |
6c95b8df | 3055 | int val; |
6c95b8df | 3056 | |
35df4500 | 3057 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3058 | { |
35df4500 | 3059 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3060 | continue; |
3061 | ||
fc126975 | 3062 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3063 | { |
834c0d03 | 3064 | val = remove_breakpoint (bl); |
6c95b8df | 3065 | if (val != 0) |
f3869b1a | 3066 | return; |
6c95b8df PA |
3067 | } |
3068 | } | |
6c95b8df PA |
3069 | } |
3070 | ||
e58b0e63 PA |
3071 | static int internal_breakpoint_number = -1; |
3072 | ||
84f4c1fe PM |
3073 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3074 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3075 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3076 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3077 | breakpoint_count and that value incremented. Internal breakpoints |
3078 | do not set the internal var bpnum. */ | |
3079 | static void | |
3080 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3081 | { | |
3082 | if (internal) | |
3083 | b->number = internal_breakpoint_number--; | |
3084 | else | |
3085 | { | |
3086 | set_breakpoint_count (breakpoint_count + 1); | |
3087 | b->number = breakpoint_count; | |
3088 | } | |
3089 | } | |
3090 | ||
e62c965a | 3091 | static struct breakpoint * |
a6d9a66e | 3092 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3093 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3094 | const struct breakpoint_ops *ops) |
e62c965a | 3095 | { |
51abb421 | 3096 | symtab_and_line sal; |
e62c965a PP |
3097 | sal.pc = address; |
3098 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3099 | sal.pspace = current_program_space; |
e62c965a | 3100 | |
51abb421 | 3101 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3102 | b->number = internal_breakpoint_number--; |
3103 | b->disposition = disp_donttouch; | |
3104 | ||
3105 | return b; | |
3106 | } | |
3107 | ||
17450429 PP |
3108 | static const char *const longjmp_names[] = |
3109 | { | |
3110 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3111 | }; | |
3112 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3113 | ||
3114 | /* Per-objfile data private to breakpoint.c. */ | |
3115 | struct breakpoint_objfile_data | |
3116 | { | |
3117 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
43dce439 | 3118 | struct bound_minimal_symbol overlay_msym {}; |
17450429 PP |
3119 | |
3120 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
43dce439 | 3121 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
17450429 | 3122 | |
28106bc2 | 3123 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3124 | int longjmp_searched = 0; |
28106bc2 | 3125 | |
45461e0d SM |
3126 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3127 | references. */ | |
3128 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3129 | |
17450429 | 3130 | /* Minimal symbol for "std::terminate()" (if any). */ |
43dce439 | 3131 | struct bound_minimal_symbol terminate_msym {}; |
17450429 PP |
3132 | |
3133 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
43dce439 | 3134 | struct bound_minimal_symbol exception_msym {}; |
28106bc2 SDJ |
3135 | |
3136 | /* True if we have looked for exception probes. */ | |
43dce439 | 3137 | int exception_searched = 0; |
28106bc2 | 3138 | |
45461e0d SM |
3139 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3140 | references. */ | |
3141 | std::vector<probe *> exception_probes; | |
17450429 PP |
3142 | }; |
3143 | ||
51d3063a TT |
3144 | static const struct objfile_key<breakpoint_objfile_data> |
3145 | breakpoint_objfile_key; | |
17450429 PP |
3146 | |
3147 | /* Minimal symbol not found sentinel. */ | |
3148 | static struct minimal_symbol msym_not_found; | |
3149 | ||
3150 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3151 | ||
3152 | static int | |
3153 | msym_not_found_p (const struct minimal_symbol *msym) | |
3154 | { | |
3155 | return msym == &msym_not_found; | |
3156 | } | |
3157 | ||
3158 | /* Return per-objfile data needed by breakpoint.c. | |
3159 | Allocate the data if necessary. */ | |
3160 | ||
3161 | static struct breakpoint_objfile_data * | |
3162 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3163 | { | |
3164 | struct breakpoint_objfile_data *bp_objfile_data; | |
3165 | ||
51d3063a | 3166 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3167 | if (bp_objfile_data == NULL) |
51d3063a | 3168 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3169 | return bp_objfile_data; |
3170 | } | |
3171 | ||
e62c965a | 3172 | static void |
af02033e | 3173 | create_overlay_event_breakpoint (void) |
e62c965a | 3174 | { |
af02033e | 3175 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3176 | |
2030c079 | 3177 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3178 | { |
3179 | struct breakpoint *b; | |
17450429 PP |
3180 | struct breakpoint_objfile_data *bp_objfile_data; |
3181 | CORE_ADDR addr; | |
67994074 | 3182 | struct explicit_location explicit_loc; |
69de3c6a | 3183 | |
17450429 PP |
3184 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3185 | ||
3b7344d5 | 3186 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3187 | continue; |
3188 | ||
3b7344d5 | 3189 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3190 | { |
3b7344d5 | 3191 | struct bound_minimal_symbol m; |
17450429 PP |
3192 | |
3193 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3194 | if (m.minsym == NULL) |
17450429 PP |
3195 | { |
3196 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3197 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3198 | continue; |
3199 | } | |
3200 | bp_objfile_data->overlay_msym = m; | |
3201 | } | |
e62c965a | 3202 | |
77e371c0 | 3203 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3204 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3205 | bp_overlay_event, |
3206 | &internal_breakpoint_ops); | |
67994074 KS |
3207 | initialize_explicit_location (&explicit_loc); |
3208 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3209 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3210 | |
69de3c6a PP |
3211 | if (overlay_debugging == ovly_auto) |
3212 | { | |
3213 | b->enable_state = bp_enabled; | |
3214 | overlay_events_enabled = 1; | |
3215 | } | |
3216 | else | |
3217 | { | |
3218 | b->enable_state = bp_disabled; | |
3219 | overlay_events_enabled = 0; | |
3220 | } | |
e62c965a | 3221 | } |
e62c965a PP |
3222 | } |
3223 | ||
0fd8e87f | 3224 | static void |
af02033e | 3225 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3226 | { |
6c95b8df | 3227 | struct program_space *pspace; |
6c95b8df | 3228 | |
5ed8105e | 3229 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3230 | |
6c95b8df | 3231 | ALL_PSPACES (pspace) |
af02033e | 3232 | { |
af02033e PP |
3233 | set_current_program_space (pspace); |
3234 | ||
2030c079 | 3235 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
3236 | { |
3237 | int i; | |
3238 | struct gdbarch *gdbarch; | |
3239 | struct breakpoint_objfile_data *bp_objfile_data; | |
0fd8e87f | 3240 | |
aed57c53 | 3241 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3242 | |
aed57c53 | 3243 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3244 | |
aed57c53 TT |
3245 | if (!bp_objfile_data->longjmp_searched) |
3246 | { | |
3247 | std::vector<probe *> ret | |
3248 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
25f9533e | 3249 | |
aed57c53 TT |
3250 | if (!ret.empty ()) |
3251 | { | |
3252 | /* We are only interested in checking one element. */ | |
3253 | probe *p = ret[0]; | |
3254 | ||
3255 | if (!p->can_evaluate_arguments ()) | |
3256 | { | |
3257 | /* We cannot use the probe interface here, because it does | |
3258 | not know how to evaluate arguments. */ | |
3259 | ret.clear (); | |
3260 | } | |
3261 | } | |
3262 | bp_objfile_data->longjmp_probes = ret; | |
3263 | bp_objfile_data->longjmp_searched = 1; | |
3264 | } | |
25f9533e | 3265 | |
aed57c53 TT |
3266 | if (!bp_objfile_data->longjmp_probes.empty ()) |
3267 | { | |
3268 | for (probe *p : bp_objfile_data->longjmp_probes) | |
3269 | { | |
3270 | struct breakpoint *b; | |
3271 | ||
3272 | b = create_internal_breakpoint (gdbarch, | |
3273 | p->get_relocated_address (objfile), | |
3274 | bp_longjmp_master, | |
3275 | &internal_breakpoint_ops); | |
3276 | b->location = new_probe_location ("-probe-stap libc:longjmp"); | |
3277 | b->enable_state = bp_disabled; | |
3278 | } | |
28106bc2 | 3279 | |
aed57c53 TT |
3280 | continue; |
3281 | } | |
28106bc2 | 3282 | |
aed57c53 | 3283 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
28106bc2 | 3284 | continue; |
28106bc2 | 3285 | |
aed57c53 TT |
3286 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
3287 | { | |
3288 | struct breakpoint *b; | |
3289 | const char *func_name; | |
3290 | CORE_ADDR addr; | |
3291 | struct explicit_location explicit_loc; | |
0fd8e87f | 3292 | |
aed57c53 TT |
3293 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
3294 | continue; | |
17450429 | 3295 | |
aed57c53 TT |
3296 | func_name = longjmp_names[i]; |
3297 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3298 | { | |
3299 | struct bound_minimal_symbol m; | |
3300 | ||
3301 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3302 | if (m.minsym == NULL) | |
3303 | { | |
3304 | /* Prevent future lookups in this objfile. */ | |
3305 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
3306 | continue; | |
3307 | } | |
3308 | bp_objfile_data->longjmp_msym[i] = m; | |
3309 | } | |
17450429 | 3310 | |
aed57c53 TT |
3311 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
3312 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, | |
3313 | &internal_breakpoint_ops); | |
3314 | initialize_explicit_location (&explicit_loc); | |
3315 | explicit_loc.function_name = ASTRDUP (func_name); | |
3316 | b->location = new_explicit_location (&explicit_loc); | |
3317 | b->enable_state = bp_disabled; | |
3318 | } | |
3319 | } | |
af02033e | 3320 | } |
0fd8e87f UW |
3321 | } |
3322 | ||
af02033e | 3323 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3324 | static void |
af02033e | 3325 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3326 | { |
3327 | struct program_space *pspace; | |
af02033e | 3328 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3329 | |
5ed8105e | 3330 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3331 | |
3332 | ALL_PSPACES (pspace) | |
17450429 | 3333 | { |
17450429 PP |
3334 | CORE_ADDR addr; |
3335 | ||
3336 | set_current_program_space (pspace); | |
3337 | ||
2030c079 | 3338 | for (objfile *objfile : current_program_space->objfiles ()) |
aed57c53 TT |
3339 | { |
3340 | struct breakpoint *b; | |
3341 | struct breakpoint_objfile_data *bp_objfile_data; | |
3342 | struct explicit_location explicit_loc; | |
aa7d318d | 3343 | |
aed57c53 | 3344 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3345 | |
aed57c53 TT |
3346 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3347 | continue; | |
17450429 | 3348 | |
aed57c53 TT |
3349 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3350 | { | |
3351 | struct bound_minimal_symbol m; | |
17450429 | 3352 | |
aed57c53 TT |
3353 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
3354 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text | |
3355 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
3356 | { | |
3357 | /* Prevent future lookups in this objfile. */ | |
3358 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3359 | continue; | |
3360 | } | |
3361 | bp_objfile_data->terminate_msym = m; | |
3362 | } | |
aa7d318d | 3363 | |
aed57c53 TT |
3364 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
3365 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
3366 | bp_std_terminate_master, | |
3367 | &internal_breakpoint_ops); | |
3368 | initialize_explicit_location (&explicit_loc); | |
3369 | explicit_loc.function_name = ASTRDUP (func_name); | |
3370 | b->location = new_explicit_location (&explicit_loc); | |
3371 | b->enable_state = bp_disabled; | |
3372 | } | |
17450429 | 3373 | } |
aa7d318d TT |
3374 | } |
3375 | ||
186c406b TT |
3376 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3377 | ||
70221824 | 3378 | static void |
186c406b TT |
3379 | create_exception_master_breakpoint (void) |
3380 | { | |
17450429 | 3381 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b | 3382 | |
2030c079 | 3383 | for (objfile *objfile : current_program_space->objfiles ()) |
186c406b | 3384 | { |
17450429 PP |
3385 | struct breakpoint *b; |
3386 | struct gdbarch *gdbarch; | |
3387 | struct breakpoint_objfile_data *bp_objfile_data; | |
3388 | CORE_ADDR addr; | |
67994074 | 3389 | struct explicit_location explicit_loc; |
17450429 PP |
3390 | |
3391 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3392 | ||
28106bc2 SDJ |
3393 | /* We prefer the SystemTap probe point if it exists. */ |
3394 | if (!bp_objfile_data->exception_searched) | |
3395 | { | |
45461e0d SM |
3396 | std::vector<probe *> ret |
3397 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
25f9533e | 3398 | |
45461e0d | 3399 | if (!ret.empty ()) |
25f9533e SDJ |
3400 | { |
3401 | /* We are only interested in checking one element. */ | |
45461e0d | 3402 | probe *p = ret[0]; |
25f9533e | 3403 | |
935676c9 | 3404 | if (!p->can_evaluate_arguments ()) |
25f9533e SDJ |
3405 | { |
3406 | /* We cannot use the probe interface here, because it does | |
3407 | not know how to evaluate arguments. */ | |
45461e0d | 3408 | ret.clear (); |
25f9533e SDJ |
3409 | } |
3410 | } | |
3411 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3412 | bp_objfile_data->exception_searched = 1; |
3413 | } | |
3414 | ||
45461e0d | 3415 | if (!bp_objfile_data->exception_probes.empty ()) |
28106bc2 | 3416 | { |
b926417a | 3417 | gdbarch = get_objfile_arch (objfile); |
45461e0d SM |
3418 | |
3419 | for (probe *p : bp_objfile_data->exception_probes) | |
28106bc2 | 3420 | { |
729662a5 | 3421 | b = create_internal_breakpoint (gdbarch, |
935676c9 | 3422 | p->get_relocated_address (objfile), |
28106bc2 SDJ |
3423 | bp_exception_master, |
3424 | &internal_breakpoint_ops); | |
d28cd78a | 3425 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3426 | b->enable_state = bp_disabled; |
3427 | } | |
3428 | ||
3429 | continue; | |
3430 | } | |
3431 | ||
3432 | /* Otherwise, try the hook function. */ | |
3433 | ||
3b7344d5 | 3434 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3435 | continue; |
3436 | ||
3437 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3438 | |
3b7344d5 | 3439 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3440 | { |
3b7344d5 | 3441 | struct bound_minimal_symbol debug_hook; |
186c406b | 3442 | |
17450429 | 3443 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3444 | if (debug_hook.minsym == NULL) |
17450429 | 3445 | { |
3b7344d5 | 3446 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3447 | continue; |
3448 | } | |
3449 | ||
3450 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3451 | } |
17450429 | 3452 | |
77e371c0 | 3453 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
8b88a78e PA |
3454 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3455 | current_top_target ()); | |
06edf0c0 PA |
3456 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3457 | &internal_breakpoint_ops); | |
67994074 KS |
3458 | initialize_explicit_location (&explicit_loc); |
3459 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3460 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3461 | b->enable_state = bp_disabled; |
186c406b | 3462 | } |
186c406b TT |
3463 | } |
3464 | ||
9ef9e6a6 KS |
3465 | /* Does B have a location spec? */ |
3466 | ||
3467 | static int | |
3468 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3469 | { | |
d28cd78a | 3470 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3471 | } |
3472 | ||
c906108c | 3473 | void |
fba45db2 | 3474 | update_breakpoints_after_exec (void) |
c906108c | 3475 | { |
35df4500 | 3476 | struct breakpoint *b, *b_tmp; |
876fa593 | 3477 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3478 | |
25b22b0a PA |
3479 | /* We're about to delete breakpoints from GDB's lists. If the |
3480 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3481 | writing the breakpoints' "shadow contents" back into memory. The | |
3482 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3483 | do that. Instead, the target is responsible from marking | |
3484 | breakpoints out as soon as it detects an exec. We don't do that | |
3485 | here instead, because there may be other attempts to delete | |
3486 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3487 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3488 | if (bploc->pspace == current_program_space) |
3489 | gdb_assert (!bploc->inserted); | |
c906108c | 3490 | |
35df4500 | 3491 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3492 | { |
6c95b8df PA |
3493 | if (b->pspace != current_program_space) |
3494 | continue; | |
3495 | ||
4a64f543 | 3496 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3497 | if (b->type == bp_shlib_event) |
3498 | { | |
3499 | delete_breakpoint (b); | |
3500 | continue; | |
3501 | } | |
c906108c | 3502 | |
4a64f543 | 3503 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3504 | if (b->type == bp_jit_event) |
3505 | { | |
3506 | delete_breakpoint (b); | |
3507 | continue; | |
3508 | } | |
3509 | ||
1900040c | 3510 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3511 | as must overlay event and longjmp master breakpoints. */ |
3512 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3513 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3514 | || b->type == bp_exception_master) | |
c4093a6a JM |
3515 | { |
3516 | delete_breakpoint (b); | |
3517 | continue; | |
3518 | } | |
3519 | ||
4a64f543 | 3520 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3521 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3522 | { |
3523 | delete_breakpoint (b); | |
3524 | continue; | |
3525 | } | |
3526 | ||
7c16b83e PA |
3527 | /* Just like single-step breakpoints. */ |
3528 | if (b->type == bp_single_step) | |
3529 | { | |
3530 | delete_breakpoint (b); | |
3531 | continue; | |
3532 | } | |
3533 | ||
611c83ae PA |
3534 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3535 | after an exec. */ | |
186c406b | 3536 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3537 | || b->type == bp_longjmp_call_dummy |
186c406b | 3538 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3539 | { |
3540 | delete_breakpoint (b); | |
3541 | continue; | |
3542 | } | |
3543 | ||
ce78b96d JB |
3544 | if (b->type == bp_catchpoint) |
3545 | { | |
3546 | /* For now, none of the bp_catchpoint breakpoints need to | |
3547 | do anything at this point. In the future, if some of | |
3548 | the catchpoints need to something, we will need to add | |
3549 | a new method, and call this method from here. */ | |
3550 | continue; | |
3551 | } | |
3552 | ||
c5aa993b JM |
3553 | /* bp_finish is a special case. The only way we ought to be able |
3554 | to see one of these when an exec() has happened, is if the user | |
3555 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3556 | carries them to the call-site of the current callee, by setting | |
3557 | a temporary bp there and resuming. But in this case, the finish | |
3558 | will carry them entirely through the vfork & exec. | |
3559 | ||
3560 | We don't want to allow a bp_finish to remain inserted now. But | |
3561 | we can't safely delete it, 'cause finish_command has a handle to | |
3562 | the bp on a bpstat, and will later want to delete it. There's a | |
3563 | chance (and I've seen it happen) that if we delete the bp_finish | |
3564 | here, that its storage will get reused by the time finish_command | |
3565 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3566 | We really must allow finish_command to delete a bp_finish. | |
3567 | ||
e5dd4106 | 3568 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3569 | it's safe to delete something others may have handles to?" |
3570 | problem, what we'll do here is just uninsert the bp_finish, and | |
3571 | let finish_command delete it. | |
3572 | ||
3573 | (We know the bp_finish is "doomed" in the sense that it's | |
3574 | momentary, and will be deleted as soon as finish_command sees | |
3575 | the inferior stopped. So it doesn't matter that the bp's | |
3576 | address is probably bogus in the new a.out, unlike e.g., the | |
3577 | solib breakpoints.) */ | |
c5aa993b | 3578 | |
c5aa993b JM |
3579 | if (b->type == bp_finish) |
3580 | { | |
3581 | continue; | |
3582 | } | |
3583 | ||
3584 | /* Without a symbolic address, we have little hope of the | |
3585 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3586 | a.out. */ |
9ef9e6a6 | 3587 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3588 | { |
3589 | delete_breakpoint (b); | |
3590 | continue; | |
3591 | } | |
c5aa993b | 3592 | } |
c906108c SS |
3593 | } |
3594 | ||
3595 | int | |
d80ee84f | 3596 | detach_breakpoints (ptid_t ptid) |
c906108c | 3597 | { |
35df4500 | 3598 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3599 | int val = 0; |
2989a365 | 3600 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3601 | struct inferior *inf = current_inferior (); |
c5aa993b | 3602 | |
e99b03dc | 3603 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3604 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3605 | |
6c95b8df | 3606 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3607 | inferior_ptid = ptid; |
35df4500 | 3608 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3609 | { |
35df4500 | 3610 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3611 | continue; |
3612 | ||
bd9673a4 PW |
3613 | /* This function must physically remove breakpoints locations |
3614 | from the specified ptid, without modifying the breakpoint | |
3615 | package's state. Locations of type bp_loc_other are only | |
3616 | maintained at GDB side. So, there is no need to remove | |
3617 | these bp_loc_other locations. Moreover, removing these | |
3618 | would modify the breakpoint package's state. */ | |
3619 | if (bl->loc_type == bp_loc_other) | |
3620 | continue; | |
3621 | ||
35df4500 | 3622 | if (bl->inserted) |
b2b6a7da | 3623 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3624 | } |
d03285ec | 3625 | |
3a1bae8e | 3626 | return val; |
c906108c SS |
3627 | } |
3628 | ||
35df4500 | 3629 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3630 | Note that this is used to detach breakpoints from a child fork. |
3631 | When we get here, the child isn't in the inferior list, and neither | |
3632 | do we have objects to represent its address space --- we should | |
35df4500 | 3633 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3634 | |
c906108c | 3635 | static int |
b2b6a7da | 3636 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3637 | { |
3638 | int val; | |
c5aa993b | 3639 | |
35df4500 TJB |
3640 | /* BL is never in moribund_locations by our callers. */ |
3641 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3642 | |
74960c60 VP |
3643 | /* The type of none suggests that owner is actually deleted. |
3644 | This should not ever happen. */ | |
35df4500 | 3645 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3646 | |
35df4500 TJB |
3647 | if (bl->loc_type == bp_loc_software_breakpoint |
3648 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3649 | { |
c02f5703 MS |
3650 | /* "Normal" instruction breakpoint: either the standard |
3651 | trap-instruction bp (bp_breakpoint), or a | |
3652 | bp_hardware_breakpoint. */ | |
3653 | ||
3654 | /* First check to see if we have to handle an overlay. */ | |
3655 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3656 | || bl->section == NULL |
3657 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3658 | { |
3659 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3660 | |
3661 | /* If we're trying to uninsert a memory breakpoint that we | |
3662 | know is set in a dynamic object that is marked | |
3663 | shlib_disabled, then either the dynamic object was | |
3664 | removed with "remove-symbol-file" or with | |
3665 | "nosharedlibrary". In the former case, we don't know | |
3666 | whether another dynamic object might have loaded over the | |
3667 | breakpoint's address -- the user might well let us know | |
3668 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3669 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3670 | list of dynamically loaded objects). If we have the |
3671 | breakpoint's shadow memory, that is, this is a software | |
3672 | breakpoint managed by GDB, check whether the breakpoint | |
3673 | is still inserted in memory, to avoid overwriting wrong | |
3674 | code with stale saved shadow contents. Note that HW | |
3675 | breakpoints don't have shadow memory, as they're | |
3676 | implemented using a mechanism that is not dependent on | |
3677 | being able to modify the target's memory, and as such | |
3678 | they should always be removed. */ | |
3679 | if (bl->shlib_disabled | |
3680 | && bl->target_info.shadow_len != 0 | |
3681 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3682 | val = 0; | |
3683 | else | |
73971819 | 3684 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3685 | } |
c906108c SS |
3686 | else |
3687 | { | |
4a64f543 | 3688 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3689 | Did we set a breakpoint at the LMA? */ |
3690 | if (!overlay_events_enabled) | |
3691 | { | |
3692 | /* Yes -- overlay event support is not active, so we | |
3693 | should have set a breakpoint at the LMA. Remove it. | |
3694 | */ | |
c02f5703 MS |
3695 | /* Ignore any failures: if the LMA is in ROM, we will |
3696 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3697 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3698 | target_remove_hw_breakpoint (bl->gdbarch, | |
3699 | &bl->overlay_target_info); | |
c02f5703 | 3700 | else |
35df4500 | 3701 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3702 | &bl->overlay_target_info, |
3703 | reason); | |
c02f5703 MS |
3704 | } |
3705 | /* Did we set a breakpoint at the VMA? | |
3706 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3707 | if (bl->inserted) |
c906108c | 3708 | { |
c02f5703 MS |
3709 | /* Yes -- remove it. Previously we did not bother to |
3710 | remove the breakpoint if the section had been | |
3711 | unmapped, but let's not rely on that being safe. We | |
3712 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3713 | |
3714 | /* However, we should remove *software* breakpoints only | |
3715 | if the section is still mapped, or else we overwrite | |
3716 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3717 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3718 | || section_is_mapped (bl->section)) | |
73971819 | 3719 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3720 | else |
3721 | val = 0; | |
c906108c | 3722 | } |
c02f5703 MS |
3723 | else |
3724 | { | |
3725 | /* No -- not inserted, so no need to remove. No error. */ | |
3726 | val = 0; | |
3727 | } | |
c906108c | 3728 | } |
879d1e6b | 3729 | |
08351840 PA |
3730 | /* In some cases, we might not be able to remove a breakpoint in |
3731 | a shared library that has already been removed, but we have | |
3732 | not yet processed the shlib unload event. Similarly for an | |
3733 | unloaded add-symbol-file object - the user might not yet have | |
3734 | had the chance to remove-symbol-file it. shlib_disabled will | |
3735 | be set if the library/object has already been removed, but | |
3736 | the breakpoint hasn't been uninserted yet, e.g., after | |
3737 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3738 | always-inserted mode. */ | |
076855f9 | 3739 | if (val |
08351840 PA |
3740 | && (bl->loc_type == bp_loc_software_breakpoint |
3741 | && (bl->shlib_disabled | |
3742 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3743 | || shared_objfile_contains_address_p (bl->pspace, |
3744 | bl->address)))) | |
879d1e6b UW |
3745 | val = 0; |
3746 | ||
c906108c SS |
3747 | if (val) |
3748 | return val; | |
b2b6a7da | 3749 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3750 | } |
35df4500 | 3751 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3752 | { |
77b06cd7 TJB |
3753 | gdb_assert (bl->owner->ops != NULL |
3754 | && bl->owner->ops->remove_location != NULL); | |
3755 | ||
b2b6a7da | 3756 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3757 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3758 | |
c906108c | 3759 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3760 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3761 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3762 | bl->owner->number); |
c906108c | 3763 | } |
35df4500 TJB |
3764 | else if (bl->owner->type == bp_catchpoint |
3765 | && breakpoint_enabled (bl->owner) | |
3766 | && !bl->duplicate) | |
ce78b96d | 3767 | { |
77b06cd7 TJB |
3768 | gdb_assert (bl->owner->ops != NULL |
3769 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3770 | |
73971819 | 3771 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3772 | if (val) |
3773 | return val; | |
77b06cd7 | 3774 | |
b2b6a7da | 3775 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3776 | } |
c906108c SS |
3777 | |
3778 | return 0; | |
3779 | } | |
3780 | ||
6c95b8df | 3781 | static int |
834c0d03 | 3782 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3783 | { |
35df4500 TJB |
3784 | /* BL is never in moribund_locations by our callers. */ |
3785 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3786 | |
6c95b8df PA |
3787 | /* The type of none suggests that owner is actually deleted. |
3788 | This should not ever happen. */ | |
35df4500 | 3789 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3790 | |
5ed8105e | 3791 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3792 | |
35df4500 | 3793 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3794 | |
5ed8105e | 3795 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3796 | } |
3797 | ||
c906108c SS |
3798 | /* Clear the "inserted" flag in all breakpoints. */ |
3799 | ||
25b22b0a | 3800 | void |
fba45db2 | 3801 | mark_breakpoints_out (void) |
c906108c | 3802 | { |
35df4500 | 3803 | struct bp_location *bl, **blp_tmp; |
c906108c | 3804 | |
35df4500 | 3805 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3806 | if (bl->pspace == current_program_space) |
35df4500 | 3807 | bl->inserted = 0; |
c906108c SS |
3808 | } |
3809 | ||
53a5351d JM |
3810 | /* Clear the "inserted" flag in all breakpoints and delete any |
3811 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3812 | |
3813 | Plus other such housekeeping that has to be done for breakpoints | |
3814 | between runs. | |
3815 | ||
53a5351d JM |
3816 | Note: this function gets called at the end of a run (by |
3817 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 3818 | init_wait_for_inferior). */ |
c906108c SS |
3819 | |
3820 | ||
3821 | ||
3822 | void | |
fba45db2 | 3823 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 3824 | { |
35df4500 | 3825 | struct breakpoint *b, *b_tmp; |
6c95b8df | 3826 | struct program_space *pspace = current_program_space; |
c906108c | 3827 | |
50c71eaf PA |
3828 | /* If breakpoint locations are shared across processes, then there's |
3829 | nothing to do. */ | |
f5656ead | 3830 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
3831 | return; |
3832 | ||
1a853c52 | 3833 | mark_breakpoints_out (); |
075f6582 | 3834 | |
35df4500 | 3835 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3836 | { |
6c95b8df PA |
3837 | if (b->loc && b->loc->pspace != pspace) |
3838 | continue; | |
3839 | ||
c5aa993b JM |
3840 | switch (b->type) |
3841 | { | |
3842 | case bp_call_dummy: | |
e2e4d78b | 3843 | case bp_longjmp_call_dummy: |
c906108c | 3844 | |
c5aa993b | 3845 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
3846 | cause problems when the inferior is rerun, so we better get |
3847 | rid of it. */ | |
3848 | ||
3849 | case bp_watchpoint_scope: | |
3850 | ||
3851 | /* Also get rid of scope breakpoints. */ | |
3852 | ||
3853 | case bp_shlib_event: | |
3854 | ||
3855 | /* Also remove solib event breakpoints. Their addresses may | |
3856 | have changed since the last time we ran the program. | |
3857 | Actually we may now be debugging against different target; | |
3858 | and so the solib backend that installed this breakpoint may | |
3859 | not be used in by the target. E.g., | |
3860 | ||
3861 | (gdb) file prog-linux | |
3862 | (gdb) run # native linux target | |
3863 | ... | |
3864 | (gdb) kill | |
3865 | (gdb) file prog-win.exe | |
3866 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
3867 | */ | |
c906108c | 3868 | |
f59f708a PA |
3869 | case bp_step_resume: |
3870 | ||
3871 | /* Also remove step-resume breakpoints. */ | |
3872 | ||
7c16b83e PA |
3873 | case bp_single_step: |
3874 | ||
3875 | /* Also remove single-step breakpoints. */ | |
3876 | ||
c5aa993b JM |
3877 | delete_breakpoint (b); |
3878 | break; | |
c906108c | 3879 | |
c5aa993b JM |
3880 | case bp_watchpoint: |
3881 | case bp_hardware_watchpoint: | |
3882 | case bp_read_watchpoint: | |
3883 | case bp_access_watchpoint: | |
3a5c3e22 PA |
3884 | { |
3885 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 3886 | |
3a5c3e22 PA |
3887 | /* Likewise for watchpoints on local expressions. */ |
3888 | if (w->exp_valid_block != NULL) | |
3889 | delete_breakpoint (b); | |
63000888 | 3890 | else |
3a5c3e22 | 3891 | { |
63000888 PA |
3892 | /* Get rid of existing locations, which are no longer |
3893 | valid. New ones will be created in | |
3894 | update_watchpoint, when the inferior is restarted. | |
3895 | The next update_global_location_list call will | |
3896 | garbage collect them. */ | |
3897 | b->loc = NULL; | |
3898 | ||
3899 | if (context == inf_starting) | |
3900 | { | |
3901 | /* Reset val field to force reread of starting value in | |
3902 | insert_breakpoints. */ | |
850645cf | 3903 | w->val.reset (nullptr); |
4c1d86d9 | 3904 | w->val_valid = false; |
63000888 PA |
3905 | } |
3906 | } | |
3a5c3e22 | 3907 | } |
c5aa993b JM |
3908 | break; |
3909 | default: | |
c5aa993b JM |
3910 | break; |
3911 | } | |
3912 | } | |
1c5cfe86 PA |
3913 | |
3914 | /* Get rid of the moribund locations. */ | |
1123588c | 3915 | for (bp_location *bl : moribund_locations) |
35df4500 | 3916 | decref_bp_location (&bl); |
1123588c | 3917 | moribund_locations.clear (); |
c906108c SS |
3918 | } |
3919 | ||
6c95b8df PA |
3920 | /* These functions concern about actual breakpoints inserted in the |
3921 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
3922 | we need to hop over the bkpt --- so we check for address space | |
3923 | match, not program space. */ | |
3924 | ||
c2c6d25f JM |
3925 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
3926 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
3927 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
3928 | permanent breakpoint. | |
3929 | - When continuing from a location with an ordinary breakpoint, we | |
3930 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 3931 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
3932 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
3933 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 3934 | |
c2c6d25f | 3935 | enum breakpoint_here |
accd0bcd | 3936 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 3937 | { |
35df4500 | 3938 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 3939 | int any_breakpoint_here = 0; |
c906108c | 3940 | |
35df4500 | 3941 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 3942 | { |
35df4500 TJB |
3943 | if (bl->loc_type != bp_loc_software_breakpoint |
3944 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3945 | continue; |
3946 | ||
f1310107 | 3947 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 3948 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 3949 | || bl->permanent) |
f1310107 | 3950 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
3951 | { |
3952 | if (overlay_debugging | |
35df4500 TJB |
3953 | && section_is_overlay (bl->section) |
3954 | && !section_is_mapped (bl->section)) | |
075f6582 | 3955 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 3956 | else if (bl->permanent) |
075f6582 DJ |
3957 | return permanent_breakpoint_here; |
3958 | else | |
3959 | any_breakpoint_here = 1; | |
3960 | } | |
3961 | } | |
c906108c | 3962 | |
f486487f | 3963 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
3964 | } |
3965 | ||
d35ae833 PA |
3966 | /* See breakpoint.h. */ |
3967 | ||
3968 | int | |
accd0bcd | 3969 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
3970 | CORE_ADDR addr, ULONGEST len) |
3971 | { | |
3972 | struct bp_location *bl, **blp_tmp; | |
3973 | ||
3974 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3975 | { | |
3976 | if (bl->loc_type != bp_loc_software_breakpoint | |
3977 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
3978 | continue; | |
3979 | ||
3980 | if ((breakpoint_enabled (bl->owner) | |
3981 | || bl->permanent) | |
3982 | && breakpoint_location_address_range_overlap (bl, aspace, | |
3983 | addr, len)) | |
3984 | { | |
3985 | if (overlay_debugging | |
3986 | && section_is_overlay (bl->section) | |
3987 | && !section_is_mapped (bl->section)) | |
3988 | { | |
3989 | /* Unmapped overlay -- can't be a match. */ | |
3990 | continue; | |
3991 | } | |
3992 | ||
3993 | return 1; | |
3994 | } | |
3995 | } | |
3996 | ||
3997 | return 0; | |
3998 | } | |
3999 | ||
1c5cfe86 PA |
4000 | /* Return true if there's a moribund breakpoint at PC. */ |
4001 | ||
4002 | int | |
accd0bcd | 4003 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 4004 | { |
1123588c | 4005 | for (bp_location *loc : moribund_locations) |
f1310107 | 4006 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4007 | return 1; |
4008 | ||
4009 | return 0; | |
4010 | } | |
c2c6d25f | 4011 | |
f7ce857f PA |
4012 | /* Returns non-zero iff BL is inserted at PC, in address space |
4013 | ASPACE. */ | |
4014 | ||
4015 | static int | |
4016 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4017 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4018 | { |
4019 | if (bl->inserted | |
4020 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4021 | aspace, pc)) | |
4022 | { | |
4023 | if (overlay_debugging | |
4024 | && section_is_overlay (bl->section) | |
4025 | && !section_is_mapped (bl->section)) | |
4026 | return 0; /* unmapped overlay -- can't be a match */ | |
4027 | else | |
4028 | return 1; | |
4029 | } | |
4030 | return 0; | |
4031 | } | |
4032 | ||
a1fd2fa5 | 4033 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4034 | |
4035 | int | |
accd0bcd | 4036 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4037 | { |
f7ce857f | 4038 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4039 | |
f7ce857f | 4040 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4041 | { |
f7ce857f PA |
4042 | struct bp_location *bl = *blp; |
4043 | ||
35df4500 TJB |
4044 | if (bl->loc_type != bp_loc_software_breakpoint |
4045 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4046 | continue; |
4047 | ||
f7ce857f PA |
4048 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4049 | return 1; | |
c5aa993b | 4050 | } |
c36b740a VP |
4051 | return 0; |
4052 | } | |
4053 | ||
a1fd2fa5 PA |
4054 | /* This function returns non-zero iff there is a software breakpoint |
4055 | inserted at PC. */ | |
c36b740a VP |
4056 | |
4057 | int | |
accd0bcd | 4058 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4059 | CORE_ADDR pc) |
4fa8626c | 4060 | { |
f7ce857f | 4061 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4062 | |
f7ce857f | 4063 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4064 | { |
f7ce857f PA |
4065 | struct bp_location *bl = *blp; |
4066 | ||
35df4500 | 4067 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4068 | continue; |
4069 | ||
f7ce857f PA |
4070 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4071 | return 1; | |
4fa8626c DJ |
4072 | } |
4073 | ||
4074 | return 0; | |
9c02b525 PA |
4075 | } |
4076 | ||
4077 | /* See breakpoint.h. */ | |
4078 | ||
4079 | int | |
accd0bcd | 4080 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4081 | CORE_ADDR pc) |
4082 | { | |
4083 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4084 | |
4085 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4086 | { | |
4087 | struct bp_location *bl = *blp; | |
4088 | ||
4089 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4090 | continue; | |
4091 | ||
4092 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4093 | return 1; | |
4094 | } | |
4095 | ||
4096 | return 0; | |
4fa8626c DJ |
4097 | } |
4098 | ||
9093389c | 4099 | int |
accd0bcd | 4100 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4101 | CORE_ADDR addr, ULONGEST len) |
4102 | { | |
4103 | struct breakpoint *bpt; | |
4104 | ||
4105 | ALL_BREAKPOINTS (bpt) | |
4106 | { | |
4107 | struct bp_location *loc; | |
4108 | ||
4109 | if (bpt->type != bp_hardware_watchpoint | |
4110 | && bpt->type != bp_access_watchpoint) | |
4111 | continue; | |
4112 | ||
4113 | if (!breakpoint_enabled (bpt)) | |
4114 | continue; | |
4115 | ||
4116 | for (loc = bpt->loc; loc; loc = loc->next) | |
4117 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4118 | { | |
4119 | CORE_ADDR l, h; | |
4120 | ||
4121 | /* Check for intersection. */ | |
768adc05 PA |
4122 | l = std::max<CORE_ADDR> (loc->address, addr); |
4123 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4124 | if (l < h) |
4125 | return 1; | |
4126 | } | |
4127 | } | |
4128 | return 0; | |
4129 | } | |
c5aa993b | 4130 | |
f2478a7e | 4131 | /* See breakpoint.h. */ |
c906108c | 4132 | |
f2478a7e SM |
4133 | bool |
4134 | is_catchpoint (struct breakpoint *b) | |
c906108c | 4135 | { |
f2478a7e | 4136 | return (b->type == bp_catchpoint); |
c906108c SS |
4137 | } |
4138 | ||
f431efe5 PA |
4139 | /* Frees any storage that is part of a bpstat. Does not walk the |
4140 | 'next' chain. */ | |
4141 | ||
04afa70c | 4142 | bpstats::~bpstats () |
198757a8 | 4143 | { |
04afa70c TT |
4144 | if (bp_location_at != NULL) |
4145 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4146 | } |
4147 | ||
c906108c SS |
4148 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4149 | Also free any storage that is part of a bpstat. */ | |
4150 | ||
4151 | void | |
fba45db2 | 4152 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4153 | { |
4154 | bpstat p; | |
4155 | bpstat q; | |
4156 | ||
4157 | if (bsp == 0) | |
4158 | return; | |
4159 | p = *bsp; | |
4160 | while (p != NULL) | |
4161 | { | |
4162 | q = p->next; | |
04afa70c | 4163 | delete p; |
c906108c SS |
4164 | p = q; |
4165 | } | |
4166 | *bsp = NULL; | |
4167 | } | |
4168 | ||
04afa70c TT |
4169 | bpstats::bpstats (const bpstats &other) |
4170 | : next (NULL), | |
4171 | bp_location_at (other.bp_location_at), | |
4172 | breakpoint_at (other.breakpoint_at), | |
4173 | commands (other.commands), | |
04afa70c TT |
4174 | print (other.print), |
4175 | stop (other.stop), | |
4176 | print_it (other.print_it) | |
4177 | { | |
850645cf TT |
4178 | if (other.old_val != NULL) |
4179 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c | 4180 | incref_bp_location (bp_location_at); |
04afa70c TT |
4181 | } |
4182 | ||
c906108c SS |
4183 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4184 | is part of the bpstat is copied as well. */ | |
4185 | ||
4186 | bpstat | |
fba45db2 | 4187 | bpstat_copy (bpstat bs) |
c906108c SS |
4188 | { |
4189 | bpstat p = NULL; | |
4190 | bpstat tmp; | |
4191 | bpstat retval = NULL; | |
4192 | ||
4193 | if (bs == NULL) | |
4194 | return bs; | |
4195 | ||
4196 | for (; bs != NULL; bs = bs->next) | |
4197 | { | |
04afa70c | 4198 | tmp = new bpstats (*bs); |
31cc81e9 | 4199 | |
c906108c SS |
4200 | if (p == NULL) |
4201 | /* This is the first thing in the chain. */ | |
4202 | retval = tmp; | |
4203 | else | |
4204 | p->next = tmp; | |
4205 | p = tmp; | |
4206 | } | |
4207 | p->next = NULL; | |
4208 | return retval; | |
4209 | } | |
4210 | ||
4a64f543 | 4211 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4212 | |
4213 | bpstat | |
fba45db2 | 4214 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4215 | { |
c5aa993b JM |
4216 | if (bsp == NULL) |
4217 | return NULL; | |
c906108c | 4218 | |
c5aa993b JM |
4219 | for (; bsp != NULL; bsp = bsp->next) |
4220 | { | |
f431efe5 | 4221 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4222 | return bsp; |
4223 | } | |
c906108c SS |
4224 | return NULL; |
4225 | } | |
4226 | ||
ab04a2af TT |
4227 | /* See breakpoint.h. */ |
4228 | ||
4c462cb0 | 4229 | bool |
427cd150 | 4230 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4231 | { |
ab04a2af TT |
4232 | for (; bsp != NULL; bsp = bsp->next) |
4233 | { | |
427cd150 TT |
4234 | if (bsp->breakpoint_at == NULL) |
4235 | { | |
4236 | /* A moribund location can never explain a signal other than | |
4237 | GDB_SIGNAL_TRAP. */ | |
4238 | if (sig == GDB_SIGNAL_TRAP) | |
4c462cb0 | 4239 | return true; |
427cd150 TT |
4240 | } |
4241 | else | |
47591c29 PA |
4242 | { |
4243 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4244 | sig)) | |
4c462cb0 | 4245 | return true; |
47591c29 | 4246 | } |
ab04a2af TT |
4247 | } |
4248 | ||
4c462cb0 | 4249 | return false; |
ab04a2af TT |
4250 | } |
4251 | ||
4a64f543 MS |
4252 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4253 | stopped at. *BSP upon return is a bpstat which points to the | |
4254 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4255 | good for anything but further calls to bpstat_num). | |
4256 | ||
8671a17b PA |
4257 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4258 | Return -1 if stopped at a breakpoint that has been deleted since | |
4259 | we set it. | |
4260 | Return 1 otherwise. */ | |
c906108c SS |
4261 | |
4262 | int | |
8671a17b | 4263 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4264 | { |
4265 | struct breakpoint *b; | |
4266 | ||
4267 | if ((*bsp) == NULL) | |
4268 | return 0; /* No more breakpoint values */ | |
8671a17b | 4269 | |
4a64f543 MS |
4270 | /* We assume we'll never have several bpstats that correspond to a |
4271 | single breakpoint -- otherwise, this function might return the | |
4272 | same number more than once and this will look ugly. */ | |
f431efe5 | 4273 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4274 | *bsp = (*bsp)->next; |
4275 | if (b == NULL) | |
4276 | return -1; /* breakpoint that's been deleted since */ | |
4277 | ||
4278 | *num = b->number; /* We have its number */ | |
4279 | return 1; | |
c906108c SS |
4280 | } |
4281 | ||
e93ca019 | 4282 | /* See breakpoint.h. */ |
c906108c SS |
4283 | |
4284 | void | |
e93ca019 | 4285 | bpstat_clear_actions (void) |
c906108c | 4286 | { |
e93ca019 JK |
4287 | bpstat bs; |
4288 | ||
00431a78 | 4289 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4290 | return; |
4291 | ||
00431a78 | 4292 | thread_info *tp = inferior_thread (); |
e93ca019 | 4293 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4294 | { |
d1b0a7bf | 4295 | bs->commands = NULL; |
850645cf | 4296 | bs->old_val.reset (nullptr); |
c906108c SS |
4297 | } |
4298 | } | |
4299 | ||
f3b1572e PA |
4300 | /* Called when a command is about to proceed the inferior. */ |
4301 | ||
4302 | static void | |
4303 | breakpoint_about_to_proceed (void) | |
4304 | { | |
d7e15655 | 4305 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4306 | { |
4307 | struct thread_info *tp = inferior_thread (); | |
4308 | ||
4309 | /* Allow inferior function calls in breakpoint commands to not | |
4310 | interrupt the command list. When the call finishes | |
4311 | successfully, the inferior will be standing at the same | |
4312 | breakpoint as if nothing happened. */ | |
16c381f0 | 4313 | if (tp->control.in_infcall) |
f3b1572e PA |
4314 | return; |
4315 | } | |
4316 | ||
4317 | breakpoint_proceeded = 1; | |
4318 | } | |
4319 | ||
abf85f46 JK |
4320 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4321 | or its equivalent. */ | |
4322 | ||
4323 | static int | |
4324 | command_line_is_silent (struct command_line *cmd) | |
4325 | { | |
4f45d445 | 4326 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4327 | } |
4328 | ||
4a64f543 MS |
4329 | /* Execute all the commands associated with all the breakpoints at |
4330 | this location. Any of these commands could cause the process to | |
4331 | proceed beyond this point, etc. We look out for such changes by | |
4332 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4333 | |
347bddb7 PA |
4334 | Returns true if a breakpoint command resumed the inferior. In that |
4335 | case, it is the caller's responsibility to recall it again with the | |
4336 | bpstat of the current thread. */ | |
4337 | ||
4338 | static int | |
4339 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4340 | { |
4341 | bpstat bs; | |
347bddb7 | 4342 | int again = 0; |
c906108c SS |
4343 | |
4344 | /* Avoid endless recursion if a `source' command is contained | |
4345 | in bs->commands. */ | |
4346 | if (executing_breakpoint_commands) | |
347bddb7 | 4347 | return 0; |
c906108c | 4348 | |
81b1e71c TT |
4349 | scoped_restore save_executing |
4350 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4351 | |
1ac32117 | 4352 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4353 | |
4a64f543 | 4354 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4355 | bs = *bsp; |
4356 | ||
4357 | breakpoint_proceeded = 0; | |
4358 | for (; bs != NULL; bs = bs->next) | |
4359 | { | |
d1b0a7bf | 4360 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4361 | |
4362 | /* Take ownership of the BSP's command tree, if it has one. | |
4363 | ||
4364 | The command tree could legitimately contain commands like | |
4365 | 'step' and 'next', which call clear_proceed_status, which | |
4366 | frees stop_bpstat's command tree. To make sure this doesn't | |
4367 | free the tree we're executing out from under us, we need to | |
4368 | take ownership of the tree ourselves. Since a given bpstat's | |
4369 | commands are only executed once, we don't need to copy it; we | |
4370 | can clear the pointer in the bpstat, and make sure we free | |
4371 | the tree when we're done. */ | |
d1b0a7bf | 4372 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4373 | bs->commands = NULL; |
d1b0a7bf TT |
4374 | if (ccmd != NULL) |
4375 | cmd = ccmd.get (); | |
abf85f46 JK |
4376 | if (command_line_is_silent (cmd)) |
4377 | { | |
4378 | /* The action has been already done by bpstat_stop_status. */ | |
4379 | cmd = cmd->next; | |
4380 | } | |
6c50ab1c | 4381 | |
c906108c SS |
4382 | while (cmd != NULL) |
4383 | { | |
4384 | execute_control_command (cmd); | |
4385 | ||
4386 | if (breakpoint_proceeded) | |
4387 | break; | |
4388 | else | |
4389 | cmd = cmd->next; | |
4390 | } | |
6c50ab1c | 4391 | |
c906108c | 4392 | if (breakpoint_proceeded) |
32c1e744 | 4393 | { |
cb814510 | 4394 | if (current_ui->async) |
347bddb7 PA |
4395 | /* If we are in async mode, then the target might be still |
4396 | running, not stopped at any breakpoint, so nothing for | |
4397 | us to do here -- just return to the event loop. */ | |
4398 | ; | |
32c1e744 VP |
4399 | else |
4400 | /* In sync mode, when execute_control_command returns | |
4401 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4402 | Breakpoint commands for that stop were not run, since |
4403 | execute_command does not run breakpoint commands -- | |
4404 | only command_line_handler does, but that one is not | |
4405 | involved in execution of breakpoint commands. So, we | |
4406 | can now execute breakpoint commands. It should be | |
4407 | noted that making execute_command do bpstat actions is | |
4408 | not an option -- in this case we'll have recursive | |
4409 | invocation of bpstat for each breakpoint with a | |
4410 | command, and can easily blow up GDB stack. Instead, we | |
4411 | return true, which will trigger the caller to recall us | |
4412 | with the new stop_bpstat. */ | |
4413 | again = 1; | |
4414 | break; | |
32c1e744 | 4415 | } |
c906108c | 4416 | } |
347bddb7 PA |
4417 | return again; |
4418 | } | |
4419 | ||
00431a78 PA |
4420 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4421 | one, is alive and has execution. Return NULL otherwise. */ | |
4422 | ||
4423 | static thread_info * | |
4424 | get_bpstat_thread () | |
4425 | { | |
4426 | if (inferior_ptid == null_ptid || !target_has_execution) | |
4427 | return NULL; | |
4428 | ||
4429 | thread_info *tp = inferior_thread (); | |
4430 | if (tp->state == THREAD_EXITED || tp->executing) | |
4431 | return NULL; | |
4432 | return tp; | |
4433 | } | |
4434 | ||
347bddb7 PA |
4435 | void |
4436 | bpstat_do_actions (void) | |
4437 | { | |
694c6bf5 | 4438 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4439 | thread_info *tp; |
353d1d73 | 4440 | |
347bddb7 | 4441 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4442 | while ((tp = get_bpstat_thread ()) != NULL) |
4443 | { | |
4444 | /* Since in sync mode, bpstat_do_actions may resume the | |
4445 | inferior, and only return when it is stopped at the next | |
4446 | breakpoint, we keep doing breakpoint actions until it returns | |
4447 | false to indicate the inferior was not resumed. */ | |
4448 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4449 | break; | |
4450 | } | |
353d1d73 | 4451 | |
694c6bf5 | 4452 | cleanup_if_error.release (); |
c906108c SS |
4453 | } |
4454 | ||
fa4727a6 DJ |
4455 | /* Print out the (old or new) value associated with a watchpoint. */ |
4456 | ||
4457 | static void | |
4458 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4459 | { | |
4460 | if (val == NULL) | |
7f6aba03 | 4461 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
fa4727a6 | 4462 | else |
79a45b7d TT |
4463 | { |
4464 | struct value_print_options opts; | |
4465 | get_user_print_options (&opts); | |
4466 | value_print (val, stream, &opts); | |
4467 | } | |
fa4727a6 DJ |
4468 | } |
4469 | ||
f303dbd6 PA |
4470 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4471 | debugging multiple threads. */ | |
4472 | ||
4473 | void | |
4474 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4475 | { | |
112e8700 | 4476 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4477 | return; |
4478 | ||
112e8700 | 4479 | uiout->text ("\n"); |
f303dbd6 PA |
4480 | |
4481 | if (show_thread_that_caused_stop ()) | |
4482 | { | |
4483 | const char *name; | |
4484 | struct thread_info *thr = inferior_thread (); | |
4485 | ||
112e8700 | 4486 | uiout->text ("Thread "); |
33eca680 | 4487 | uiout->field_string ("thread-id", print_thread_id (thr)); |
f303dbd6 PA |
4488 | |
4489 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4490 | if (name != NULL) | |
4491 | { | |
112e8700 | 4492 | uiout->text (" \""); |
33eca680 | 4493 | uiout->field_string ("name", name); |
112e8700 | 4494 | uiout->text ("\""); |
f303dbd6 PA |
4495 | } |
4496 | ||
112e8700 | 4497 | uiout->text (" hit "); |
f303dbd6 PA |
4498 | } |
4499 | } | |
4500 | ||
e514a9d6 | 4501 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4502 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4503 | 'print_it' in the bpstat structure. Under some circumstances we |
4504 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4505 | normal_stop(). */ |
e514a9d6 JM |
4506 | |
4507 | static enum print_stop_action | |
4508 | print_bp_stop_message (bpstat bs) | |
4509 | { | |
4510 | switch (bs->print_it) | |
4511 | { | |
4512 | case print_it_noop: | |
4a64f543 | 4513 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4514 | return PRINT_UNKNOWN; |
4515 | break; | |
4516 | ||
4517 | case print_it_done: | |
4518 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4519 | relevant messages. */ |
e514a9d6 JM |
4520 | return PRINT_SRC_AND_LOC; |
4521 | break; | |
4522 | ||
4523 | case print_it_normal: | |
4f8d1dc6 | 4524 | { |
f431efe5 PA |
4525 | struct breakpoint *b = bs->breakpoint_at; |
4526 | ||
1a6a67de TJB |
4527 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4528 | which has since been deleted. */ | |
4529 | if (b == NULL) | |
4530 | return PRINT_UNKNOWN; | |
4531 | ||
348d480f PA |
4532 | /* Normal case. Call the breakpoint's print_it method. */ |
4533 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4534 | } |
348d480f | 4535 | break; |
3086aeae | 4536 | |
e514a9d6 | 4537 | default: |
8e65ff28 | 4538 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4539 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4540 | break; |
c906108c | 4541 | } |
c906108c SS |
4542 | } |
4543 | ||
edcc5120 TT |
4544 | /* A helper function that prints a shared library stopped event. */ |
4545 | ||
4546 | static void | |
4547 | print_solib_event (int is_catchpoint) | |
4548 | { | |
6fb16ce6 | 4549 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4550 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4551 | |
4552 | if (!is_catchpoint) | |
4553 | { | |
4554 | if (any_added || any_deleted) | |
112e8700 | 4555 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4556 | else |
112e8700 SM |
4557 | current_uiout->text (_("Stopped due to shared library event (no " |
4558 | "libraries added or removed)\n")); | |
edcc5120 TT |
4559 | } |
4560 | ||
112e8700 SM |
4561 | if (current_uiout->is_mi_like_p ()) |
4562 | current_uiout->field_string ("reason", | |
4563 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4564 | |
4565 | if (any_deleted) | |
4566 | { | |
112e8700 | 4567 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4568 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4569 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4570 | { |
6fb16ce6 SM |
4571 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4572 | ||
edcc5120 | 4573 | if (ix > 0) |
112e8700 SM |
4574 | current_uiout->text (" "); |
4575 | current_uiout->field_string ("library", name); | |
4576 | current_uiout->text ("\n"); | |
edcc5120 | 4577 | } |
edcc5120 TT |
4578 | } |
4579 | ||
4580 | if (any_added) | |
4581 | { | |
112e8700 | 4582 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4583 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4584 | bool first = true; |
52941706 | 4585 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4586 | { |
bcb430e4 | 4587 | if (!first) |
112e8700 | 4588 | current_uiout->text (" "); |
bcb430e4 | 4589 | first = false; |
112e8700 SM |
4590 | current_uiout->field_string ("library", iter->so_name); |
4591 | current_uiout->text ("\n"); | |
edcc5120 | 4592 | } |
edcc5120 TT |
4593 | } |
4594 | } | |
4595 | ||
e514a9d6 JM |
4596 | /* Print a message indicating what happened. This is called from |
4597 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4598 | list - a list of the eventpoints that caused this stop. KIND is |
4599 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4600 | routine calls the generic print routine for printing a message |
4601 | about reasons for stopping. This will print (for example) the | |
4602 | "Breakpoint n," part of the output. The return value of this | |
4603 | routine is one of: | |
c906108c | 4604 | |
4a64f543 | 4605 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4606 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4607 | code to print the location. An example is |
c5aa993b JM |
4608 | "Breakpoint 1, " which should be followed by |
4609 | the location. | |
917317f4 | 4610 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4611 | to also print the location part of the message. |
4612 | An example is the catch/throw messages, which | |
4a64f543 | 4613 | don't require a location appended to the end. |
917317f4 | 4614 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4615 | further info to be printed. */ |
c906108c | 4616 | |
917317f4 | 4617 | enum print_stop_action |
36dfb11c | 4618 | bpstat_print (bpstat bs, int kind) |
c906108c | 4619 | { |
f486487f | 4620 | enum print_stop_action val; |
c5aa993b | 4621 | |
c906108c | 4622 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4623 | (Currently all watchpoints go on the bpstat whether hit or not. |
4624 | That probably could (should) be changed, provided care is taken | |
c906108c | 4625 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4626 | for (; bs; bs = bs->next) |
4627 | { | |
4628 | val = print_bp_stop_message (bs); | |
4629 | if (val == PRINT_SRC_ONLY | |
4630 | || val == PRINT_SRC_AND_LOC | |
4631 | || val == PRINT_NOTHING) | |
4632 | return val; | |
4633 | } | |
c906108c | 4634 | |
36dfb11c TT |
4635 | /* If we had hit a shared library event breakpoint, |
4636 | print_bp_stop_message would print out this message. If we hit an | |
4637 | OS-level shared library event, do the same thing. */ | |
4638 | if (kind == TARGET_WAITKIND_LOADED) | |
4639 | { | |
edcc5120 | 4640 | print_solib_event (0); |
36dfb11c TT |
4641 | return PRINT_NOTHING; |
4642 | } | |
4643 | ||
e514a9d6 | 4644 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4645 | with and nothing was printed. */ |
917317f4 | 4646 | return PRINT_UNKNOWN; |
c906108c SS |
4647 | } |
4648 | ||
bf469271 | 4649 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4650 | |
bf469271 PA |
4651 | static bool |
4652 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4653 | { |
278cd55f | 4654 | struct value *mark = value_mark (); |
bf469271 | 4655 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4656 | |
c906108c | 4657 | value_free_to_mark (mark); |
bf469271 | 4658 | return res; |
c906108c SS |
4659 | } |
4660 | ||
5760d0ab | 4661 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4662 | |
04afa70c TT |
4663 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4664 | : next (NULL), | |
4665 | bp_location_at (bl), | |
4666 | breakpoint_at (bl->owner), | |
4667 | commands (NULL), | |
04afa70c TT |
4668 | print (0), |
4669 | stop (0), | |
4670 | print_it (print_it_normal) | |
c906108c | 4671 | { |
f431efe5 | 4672 | incref_bp_location (bl); |
04afa70c TT |
4673 | **bs_link_pointer = this; |
4674 | *bs_link_pointer = &next; | |
4675 | } | |
4676 | ||
4677 | bpstats::bpstats () | |
4678 | : next (NULL), | |
4679 | bp_location_at (NULL), | |
4680 | breakpoint_at (NULL), | |
4681 | commands (NULL), | |
04afa70c TT |
4682 | print (0), |
4683 | stop (0), | |
4684 | print_it (print_it_normal) | |
4685 | { | |
c906108c SS |
4686 | } |
4687 | \f | |
d983da9c DJ |
4688 | /* The target has stopped with waitstatus WS. Check if any hardware |
4689 | watchpoints have triggered, according to the target. */ | |
4690 | ||
4691 | int | |
4692 | watchpoints_triggered (struct target_waitstatus *ws) | |
4693 | { | |
57810aa7 | 4694 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4695 | CORE_ADDR addr; |
4696 | struct breakpoint *b; | |
4697 | ||
4698 | if (!stopped_by_watchpoint) | |
4699 | { | |
4700 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4701 | as not triggered. */ | |
4702 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4703 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4704 | { |
4705 | struct watchpoint *w = (struct watchpoint *) b; | |
4706 | ||
4707 | w->watchpoint_triggered = watch_triggered_no; | |
4708 | } | |
d983da9c DJ |
4709 | |
4710 | return 0; | |
4711 | } | |
4712 | ||
8b88a78e | 4713 | if (!target_stopped_data_address (current_top_target (), &addr)) |
d983da9c DJ |
4714 | { |
4715 | /* We were stopped by a watchpoint, but we don't know where. | |
4716 | Mark all watchpoints as unknown. */ | |
4717 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4718 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4719 | { |
4720 | struct watchpoint *w = (struct watchpoint *) b; | |
4721 | ||
4722 | w->watchpoint_triggered = watch_triggered_unknown; | |
4723 | } | |
d983da9c | 4724 | |
3c4797ba | 4725 | return 1; |
d983da9c DJ |
4726 | } |
4727 | ||
4728 | /* The target could report the data address. Mark watchpoints | |
4729 | affected by this data address as triggered, and all others as not | |
4730 | triggered. */ | |
4731 | ||
4732 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4733 | if (is_hardware_watchpoint (b)) |
d983da9c | 4734 | { |
3a5c3e22 | 4735 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4736 | struct bp_location *loc; |
d983da9c | 4737 | |
3a5c3e22 | 4738 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4739 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4740 | { |
3a5c3e22 | 4741 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4742 | { |
3a5c3e22 PA |
4743 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4744 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4745 | |
4746 | if (newaddr == start) | |
4747 | { | |
3a5c3e22 | 4748 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4749 | break; |
4750 | } | |
4751 | } | |
4752 | /* Exact match not required. Within range is sufficient. */ | |
8b88a78e | 4753 | else if (target_watchpoint_addr_within_range (current_top_target (), |
9c06b0b4 TJB |
4754 | addr, loc->address, |
4755 | loc->length)) | |
4756 | { | |
3a5c3e22 | 4757 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4758 | break; |
4759 | } | |
4760 | } | |
d983da9c DJ |
4761 | } |
4762 | ||
4763 | return 1; | |
4764 | } | |
4765 | ||
bf469271 PA |
4766 | /* Possible return values for watchpoint_check. */ |
4767 | enum wp_check_result | |
4768 | { | |
4769 | /* The watchpoint has been deleted. */ | |
4770 | WP_DELETED = 1, | |
4771 | ||
4772 | /* The value has changed. */ | |
4773 | WP_VALUE_CHANGED = 2, | |
4774 | ||
4775 | /* The value has not changed. */ | |
4776 | WP_VALUE_NOT_CHANGED = 3, | |
4777 | ||
4778 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4779 | WP_IGNORE = 4, | |
4780 | }; | |
c906108c SS |
4781 | |
4782 | #define BP_TEMPFLAG 1 | |
4783 | #define BP_HARDWAREFLAG 2 | |
4784 | ||
4a64f543 | 4785 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4786 | changed. */ |
553e4c11 | 4787 | |
bf469271 PA |
4788 | static wp_check_result |
4789 | watchpoint_check (bpstat bs) | |
c906108c | 4790 | { |
3a5c3e22 | 4791 | struct watchpoint *b; |
c906108c SS |
4792 | struct frame_info *fr; |
4793 | int within_current_scope; | |
4794 | ||
f431efe5 | 4795 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4796 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4797 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4798 | |
f6bc2008 PA |
4799 | /* If this is a local watchpoint, we only want to check if the |
4800 | watchpoint frame is in scope if the current thread is the thread | |
4801 | that was used to create the watchpoint. */ | |
4802 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4803 | return WP_IGNORE; |
f6bc2008 | 4804 | |
c906108c SS |
4805 | if (b->exp_valid_block == NULL) |
4806 | within_current_scope = 1; | |
4807 | else | |
4808 | { | |
edb3359d DJ |
4809 | struct frame_info *frame = get_current_frame (); |
4810 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4811 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4812 | ||
c9cf6e20 | 4813 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4814 | still in the function but the stack frame has already been |
4815 | invalidated. Since we can't rely on the values of local | |
4816 | variables after the stack has been destroyed, we are treating | |
4817 | the watchpoint in that state as `not changed' without further | |
4818 | checking. Don't mark watchpoints as changed if the current | |
4819 | frame is in an epilogue - even if they are in some other | |
4820 | frame, our view of the stack is likely to be wrong and | |
4821 | frame_find_by_id could error out. */ | |
c9cf6e20 | 4822 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 4823 | return WP_IGNORE; |
a0f49112 | 4824 | |
101dcfbe | 4825 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 4826 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
4827 | |
4828 | /* If we've gotten confused in the unwinder, we might have | |
4829 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
4830 | if (within_current_scope) |
4831 | { | |
4832 | struct symbol *function; | |
4833 | ||
4834 | function = get_frame_function (fr); | |
4835 | if (function == NULL | |
4836 | || !contained_in (b->exp_valid_block, | |
4837 | SYMBOL_BLOCK_VALUE (function))) | |
4838 | within_current_scope = 0; | |
4839 | } | |
69fbadd5 | 4840 | |
edb3359d | 4841 | if (within_current_scope) |
c906108c SS |
4842 | /* If we end up stopping, the current frame will get selected |
4843 | in normal_stop. So this call to select_frame won't affect | |
4844 | the user. */ | |
0f7d239c | 4845 | select_frame (fr); |
c906108c | 4846 | } |
c5aa993b | 4847 | |
c906108c SS |
4848 | if (within_current_scope) |
4849 | { | |
4a64f543 MS |
4850 | /* We use value_{,free_to_}mark because it could be a *long* |
4851 | time before we return to the command level and call | |
4852 | free_all_values. We can't call free_all_values because we | |
4853 | might be in the middle of evaluating a function call. */ | |
c906108c | 4854 | |
0cf6dd15 | 4855 | int pc = 0; |
9c06b0b4 | 4856 | struct value *mark; |
fa4727a6 DJ |
4857 | struct value *new_val; |
4858 | ||
c1fc2657 | 4859 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
4860 | /* Since we don't know the exact trigger address (from |
4861 | stopped_data_address), just tell the user we've triggered | |
4862 | a mask watchpoint. */ | |
4863 | return WP_VALUE_CHANGED; | |
4864 | ||
4865 | mark = value_mark (); | |
4d01a485 | 4866 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 4867 | |
bb9d5f81 PP |
4868 | if (b->val_bitsize != 0) |
4869 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
4870 | ||
4a64f543 MS |
4871 | /* We use value_equal_contents instead of value_equal because |
4872 | the latter coerces an array to a pointer, thus comparing just | |
4873 | the address of the array instead of its contents. This is | |
4874 | not what we want. */ | |
fa4727a6 | 4875 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
4876 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
4877 | new_val))) | |
c906108c | 4878 | { |
c906108c | 4879 | bs->old_val = b->val; |
850645cf | 4880 | b->val = release_value (new_val); |
4c1d86d9 | 4881 | b->val_valid = true; |
850645cf TT |
4882 | if (new_val != NULL) |
4883 | value_free_to_mark (mark); | |
c906108c SS |
4884 | return WP_VALUE_CHANGED; |
4885 | } | |
4886 | else | |
4887 | { | |
60e1c644 | 4888 | /* Nothing changed. */ |
c906108c | 4889 | value_free_to_mark (mark); |
c906108c SS |
4890 | return WP_VALUE_NOT_CHANGED; |
4891 | } | |
4892 | } | |
4893 | else | |
4894 | { | |
4895 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
4896 | if we temporarily ignored the watchpoint, then when |
4897 | we reenter the block in which it is valid it contains | |
4898 | garbage (in the case of a function, it may have two | |
4899 | garbage values, one before and one after the prologue). | |
4900 | So we can't even detect the first assignment to it and | |
4901 | watch after that (since the garbage may or may not equal | |
4902 | the first value assigned). */ | |
348d480f PA |
4903 | /* We print all the stop information in |
4904 | breakpoint_ops->print_it, but in this case, by the time we | |
4905 | call breakpoint_ops->print_it this bp will be deleted | |
4906 | already. So we have no choice but print the information | |
4907 | here. */ | |
468afe6c | 4908 | |
0e454242 | 4909 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
4910 | { |
4911 | struct ui_out *uiout = current_uiout; | |
4912 | ||
112e8700 SM |
4913 | if (uiout->is_mi_like_p ()) |
4914 | uiout->field_string | |
4915 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
6a831f06 PA |
4916 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
4917 | "left the block in\n" | |
4918 | "which its expression is valid.\n", | |
4919 | signed_field ("wpnum", b->number)); | |
468afe6c | 4920 | } |
4ce44c66 | 4921 | |
cdac0397 | 4922 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 4923 | b->commands = NULL; |
d0fb5eae | 4924 | watchpoint_del_at_next_stop (b); |
c906108c SS |
4925 | |
4926 | return WP_DELETED; | |
4927 | } | |
4928 | } | |
4929 | ||
18a18393 | 4930 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
4931 | breakpoint location BL. This function does not check if we should |
4932 | stop, only if BL explains the stop. */ | |
4933 | ||
18a18393 | 4934 | static int |
6c95b8df | 4935 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 4936 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 4937 | const struct target_waitstatus *ws) |
18a18393 VP |
4938 | { |
4939 | struct breakpoint *b = bl->owner; | |
4940 | ||
348d480f | 4941 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
4942 | gdb_assert (b != NULL); |
4943 | ||
bd522513 | 4944 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
4945 | } |
4946 | ||
3a5c3e22 PA |
4947 | /* Determine if the watched values have actually changed, and we |
4948 | should stop. If not, set BS->stop to 0. */ | |
4949 | ||
18a18393 VP |
4950 | static void |
4951 | bpstat_check_watchpoint (bpstat bs) | |
4952 | { | |
2bdf28a0 | 4953 | const struct bp_location *bl; |
3a5c3e22 | 4954 | struct watchpoint *b; |
2bdf28a0 JK |
4955 | |
4956 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4957 | bl = bs->bp_location_at; |
2bdf28a0 | 4958 | gdb_assert (bl != NULL); |
3a5c3e22 | 4959 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 4960 | gdb_assert (b != NULL); |
18a18393 | 4961 | |
18a18393 | 4962 | { |
18a18393 VP |
4963 | int must_check_value = 0; |
4964 | ||
c1fc2657 | 4965 | if (b->type == bp_watchpoint) |
18a18393 VP |
4966 | /* For a software watchpoint, we must always check the |
4967 | watched value. */ | |
4968 | must_check_value = 1; | |
4969 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
4970 | /* We have a hardware watchpoint (read, write, or access) | |
4971 | and the target earlier reported an address watched by | |
4972 | this watchpoint. */ | |
4973 | must_check_value = 1; | |
4974 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 4975 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
4976 | /* We were stopped by a hardware watchpoint, but the target could |
4977 | not report the data address. We must check the watchpoint's | |
4978 | value. Access and read watchpoints are out of luck; without | |
4979 | a data address, we can't figure it out. */ | |
4980 | must_check_value = 1; | |
3a5c3e22 | 4981 | |
18a18393 VP |
4982 | if (must_check_value) |
4983 | { | |
bf469271 PA |
4984 | wp_check_result e; |
4985 | ||
a70b8144 | 4986 | try |
bf469271 PA |
4987 | { |
4988 | e = watchpoint_check (bs); | |
4989 | } | |
230d2906 | 4990 | catch (const gdb_exception &ex) |
bf469271 PA |
4991 | { |
4992 | exception_fprintf (gdb_stderr, ex, | |
4993 | "Error evaluating expression " | |
4994 | "for watchpoint %d\n", | |
4995 | b->number); | |
4996 | ||
4997 | SWITCH_THRU_ALL_UIS () | |
4998 | { | |
4999 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
5000 | b->number); | |
5001 | } | |
5002 | watchpoint_del_at_next_stop (b); | |
5003 | e = WP_DELETED; | |
5004 | } | |
bf469271 | 5005 | |
18a18393 VP |
5006 | switch (e) |
5007 | { | |
5008 | case WP_DELETED: | |
5009 | /* We've already printed what needs to be printed. */ | |
5010 | bs->print_it = print_it_done; | |
5011 | /* Stop. */ | |
5012 | break; | |
60e1c644 PA |
5013 | case WP_IGNORE: |
5014 | bs->print_it = print_it_noop; | |
5015 | bs->stop = 0; | |
5016 | break; | |
18a18393 | 5017 | case WP_VALUE_CHANGED: |
c1fc2657 | 5018 | if (b->type == bp_read_watchpoint) |
18a18393 | 5019 | { |
85d721b8 PA |
5020 | /* There are two cases to consider here: |
5021 | ||
4a64f543 | 5022 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5023 | In that case, trust the target, and always report |
5024 | the watchpoint hit to the user. Even though | |
5025 | reads don't cause value changes, the value may | |
5026 | have changed since the last time it was read, and | |
5027 | since we're not trapping writes, we will not see | |
5028 | those, and as such we should ignore our notion of | |
5029 | old value. | |
5030 | ||
4a64f543 | 5031 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5032 | reads and writes. There are two ways this may |
5033 | happen: | |
5034 | ||
4a64f543 | 5035 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5036 | reads only, but can break on accesses (reads or |
5037 | writes), such as e.g., x86. We detect this case | |
5038 | at the time we try to insert read watchpoints. | |
5039 | ||
4a64f543 | 5040 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5041 | watchpoints, but, the user set an access or write |
5042 | watchpoint watching the same memory as this read | |
5043 | watchpoint. | |
5044 | ||
5045 | If we're watching memory writes as well as reads, | |
5046 | ignore watchpoint hits when we find that the | |
5047 | value hasn't changed, as reads don't cause | |
5048 | changes. This still gives false positives when | |
5049 | the program writes the same value to memory as | |
5050 | what there was already in memory (we will confuse | |
5051 | it for a read), but it's much better than | |
5052 | nothing. */ | |
5053 | ||
5054 | int other_write_watchpoint = 0; | |
5055 | ||
5056 | if (bl->watchpoint_type == hw_read) | |
5057 | { | |
5058 | struct breakpoint *other_b; | |
5059 | ||
5060 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5061 | if (other_b->type == bp_hardware_watchpoint |
5062 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5063 | { |
3a5c3e22 PA |
5064 | struct watchpoint *other_w = |
5065 | (struct watchpoint *) other_b; | |
5066 | ||
5067 | if (other_w->watchpoint_triggered | |
5068 | == watch_triggered_yes) | |
5069 | { | |
5070 | other_write_watchpoint = 1; | |
5071 | break; | |
5072 | } | |
85d721b8 PA |
5073 | } |
5074 | } | |
5075 | ||
5076 | if (other_write_watchpoint | |
5077 | || bl->watchpoint_type == hw_access) | |
5078 | { | |
5079 | /* We're watching the same memory for writes, | |
5080 | and the value changed since the last time we | |
5081 | updated it, so this trap must be for a write. | |
5082 | Ignore it. */ | |
5083 | bs->print_it = print_it_noop; | |
5084 | bs->stop = 0; | |
5085 | } | |
18a18393 VP |
5086 | } |
5087 | break; | |
5088 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5089 | if (b->type == bp_hardware_watchpoint |
5090 | || b->type == bp_watchpoint) | |
18a18393 VP |
5091 | { |
5092 | /* Don't stop: write watchpoints shouldn't fire if | |
5093 | the value hasn't changed. */ | |
5094 | bs->print_it = print_it_noop; | |
5095 | bs->stop = 0; | |
5096 | } | |
5097 | /* Stop. */ | |
5098 | break; | |
5099 | default: | |
5100 | /* Can't happen. */ | |
18a18393 VP |
5101 | break; |
5102 | } | |
5103 | } | |
5104 | else /* must_check_value == 0 */ | |
5105 | { | |
5106 | /* This is a case where some watchpoint(s) triggered, but | |
5107 | not at the address of this watchpoint, or else no | |
5108 | watchpoint triggered after all. So don't print | |
5109 | anything for this watchpoint. */ | |
5110 | bs->print_it = print_it_noop; | |
5111 | bs->stop = 0; | |
5112 | } | |
5113 | } | |
5114 | } | |
5115 | ||
7d4df6a4 DE |
5116 | /* For breakpoints that are currently marked as telling gdb to stop, |
5117 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5118 | of breakpoint referred to by BS. If we should not stop for this |
5119 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5120 | |
18a18393 | 5121 | static void |
00431a78 | 5122 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
18a18393 | 5123 | { |
2bdf28a0 JK |
5124 | const struct bp_location *bl; |
5125 | struct breakpoint *b; | |
bf469271 PA |
5126 | /* Assume stop. */ |
5127 | bool condition_result = true; | |
7d4df6a4 DE |
5128 | struct expression *cond; |
5129 | ||
5130 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5131 | |
5132 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5133 | bl = bs->bp_location_at; |
2bdf28a0 | 5134 | gdb_assert (bl != NULL); |
f431efe5 | 5135 | b = bs->breakpoint_at; |
2bdf28a0 | 5136 | gdb_assert (b != NULL); |
18a18393 | 5137 | |
b775012e LM |
5138 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5139 | need to do so again since GDB does not know if we stopped due to a | |
5140 | breakpoint or a single step breakpoint. */ | |
5141 | ||
18a18393 | 5142 | if (frame_id_p (b->frame_id) |
edb3359d | 5143 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5144 | { |
7d4df6a4 DE |
5145 | bs->stop = 0; |
5146 | return; | |
5147 | } | |
60e1c644 | 5148 | |
12ab52e9 PA |
5149 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5150 | evaluating the condition if this isn't the specified | |
5151 | thread/task. */ | |
00431a78 PA |
5152 | if ((b->thread != -1 && b->thread != thread->global_num) |
5153 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5154 | { |
5155 | bs->stop = 0; | |
5156 | return; | |
5157 | } | |
5158 | ||
6dddc817 DE |
5159 | /* Evaluate extension language breakpoints that have a "stop" method |
5160 | implemented. */ | |
5161 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5162 | |
7d4df6a4 DE |
5163 | if (is_watchpoint (b)) |
5164 | { | |
5165 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5166 | |
4d01a485 | 5167 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5168 | } |
5169 | else | |
4d01a485 | 5170 | cond = bl->cond.get (); |
60e1c644 | 5171 | |
7d4df6a4 DE |
5172 | if (cond && b->disposition != disp_del_at_next_stop) |
5173 | { | |
5174 | int within_current_scope = 1; | |
5175 | struct watchpoint * w; | |
60e1c644 | 5176 | |
7d4df6a4 DE |
5177 | /* We use value_mark and value_free_to_mark because it could |
5178 | be a long time before we return to the command level and | |
5179 | call free_all_values. We can't call free_all_values | |
5180 | because we might be in the middle of evaluating a | |
5181 | function call. */ | |
5182 | struct value *mark = value_mark (); | |
5183 | ||
5184 | if (is_watchpoint (b)) | |
5185 | w = (struct watchpoint *) b; | |
5186 | else | |
5187 | w = NULL; | |
5188 | ||
5189 | /* Need to select the frame, with all that implies so that | |
5190 | the conditions will have the right context. Because we | |
5191 | use the frame, we will not see an inlined function's | |
5192 | variables when we arrive at a breakpoint at the start | |
5193 | of the inlined function; the current frame will be the | |
5194 | call site. */ | |
5195 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5196 | select_frame (get_current_frame ()); | |
5197 | else | |
18a18393 | 5198 | { |
7d4df6a4 DE |
5199 | struct frame_info *frame; |
5200 | ||
5201 | /* For local watchpoint expressions, which particular | |
5202 | instance of a local is being watched matters, so we | |
5203 | keep track of the frame to evaluate the expression | |
5204 | in. To evaluate the condition however, it doesn't | |
5205 | really matter which instantiation of the function | |
5206 | where the condition makes sense triggers the | |
5207 | watchpoint. This allows an expression like "watch | |
5208 | global if q > 10" set in `func', catch writes to | |
5209 | global on all threads that call `func', or catch | |
5210 | writes on all recursive calls of `func' by a single | |
5211 | thread. We simply always evaluate the condition in | |
5212 | the innermost frame that's executing where it makes | |
5213 | sense to evaluate the condition. It seems | |
5214 | intuitive. */ | |
5215 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5216 | if (frame != NULL) | |
5217 | select_frame (frame); | |
5218 | else | |
5219 | within_current_scope = 0; | |
18a18393 | 5220 | } |
7d4df6a4 | 5221 | if (within_current_scope) |
bf469271 | 5222 | { |
a70b8144 | 5223 | try |
bf469271 PA |
5224 | { |
5225 | condition_result = breakpoint_cond_eval (cond); | |
5226 | } | |
230d2906 | 5227 | catch (const gdb_exception &ex) |
bf469271 PA |
5228 | { |
5229 | exception_fprintf (gdb_stderr, ex, | |
5230 | "Error in testing breakpoint condition:\n"); | |
5231 | } | |
bf469271 | 5232 | } |
7d4df6a4 | 5233 | else |
18a18393 | 5234 | { |
7d4df6a4 DE |
5235 | warning (_("Watchpoint condition cannot be tested " |
5236 | "in the current scope")); | |
5237 | /* If we failed to set the right context for this | |
5238 | watchpoint, unconditionally report it. */ | |
18a18393 | 5239 | } |
7d4df6a4 DE |
5240 | /* FIXME-someday, should give breakpoint #. */ |
5241 | value_free_to_mark (mark); | |
18a18393 | 5242 | } |
7d4df6a4 | 5243 | |
bf469271 | 5244 | if (cond && !condition_result) |
7d4df6a4 DE |
5245 | { |
5246 | bs->stop = 0; | |
5247 | } | |
7d4df6a4 DE |
5248 | else if (b->ignore_count > 0) |
5249 | { | |
5250 | b->ignore_count--; | |
5251 | bs->stop = 0; | |
5252 | /* Increase the hit count even though we don't stop. */ | |
5253 | ++(b->hit_count); | |
76727919 | 5254 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5255 | } |
18a18393 VP |
5256 | } |
5257 | ||
1cf4d951 PA |
5258 | /* Returns true if we need to track moribund locations of LOC's type |
5259 | on the current target. */ | |
5260 | ||
5261 | static int | |
5262 | need_moribund_for_location_type (struct bp_location *loc) | |
5263 | { | |
5264 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5265 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5266 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5267 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5268 | } | |
5269 | ||
ddfe970e | 5270 | /* See breakpoint.h. */ |
c906108c SS |
5271 | |
5272 | bpstat | |
ddfe970e | 5273 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 5274 | const struct target_waitstatus *ws) |
c906108c | 5275 | { |
ddfe970e | 5276 | struct breakpoint *b; |
5760d0ab | 5277 | bpstat bs_head = NULL, *bs_link = &bs_head; |
c5aa993b | 5278 | |
429374b8 JK |
5279 | ALL_BREAKPOINTS (b) |
5280 | { | |
1a853c52 | 5281 | if (!breakpoint_enabled (b)) |
429374b8 | 5282 | continue; |
a5606eee | 5283 | |
ddfe970e | 5284 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
429374b8 | 5285 | { |
4a64f543 MS |
5286 | /* For hardware watchpoints, we look only at the first |
5287 | location. The watchpoint_check function will work on the | |
5288 | entire expression, not the individual locations. For | |
5289 | read watchpoints, the watchpoints_triggered function has | |
5290 | checked all locations already. */ | |
429374b8 JK |
5291 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5292 | break; | |
18a18393 | 5293 | |
f6592439 | 5294 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5295 | continue; |
c5aa993b | 5296 | |
09ac7c10 | 5297 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5298 | continue; |
c5aa993b | 5299 | |
4a64f543 MS |
5300 | /* Come here if it's a watchpoint, or if the break address |
5301 | matches. */ | |
c5aa993b | 5302 | |
ddfe970e KS |
5303 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
5304 | explain stop. */ | |
c5aa993b | 5305 | |
f431efe5 PA |
5306 | /* Assume we stop. Should we find a watchpoint that is not |
5307 | actually triggered, or if the condition of the breakpoint | |
5308 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5309 | bs->stop = 1; |
5310 | bs->print = 1; | |
d983da9c | 5311 | |
f431efe5 PA |
5312 | /* If this is a scope breakpoint, mark the associated |
5313 | watchpoint as triggered so that we will handle the | |
5314 | out-of-scope event. We'll get to the watchpoint next | |
5315 | iteration. */ | |
d0fb5eae | 5316 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5317 | { |
5318 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5319 | ||
5320 | w->watchpoint_triggered = watch_triggered_yes; | |
5321 | } | |
f431efe5 PA |
5322 | } |
5323 | } | |
5324 | ||
7c16b83e | 5325 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5326 | if (!target_supports_stopped_by_sw_breakpoint () |
5327 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5328 | { |
1123588c | 5329 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5330 | { |
1cf4d951 PA |
5331 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5332 | && need_moribund_for_location_type (loc)) | |
5333 | { | |
ddfe970e | 5334 | bpstat bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5335 | /* For hits of moribund locations, we should just proceed. */ |
5336 | bs->stop = 0; | |
5337 | bs->print = 0; | |
5338 | bs->print_it = print_it_noop; | |
5339 | } | |
f431efe5 PA |
5340 | } |
5341 | } | |
5342 | ||
ddfe970e KS |
5343 | return bs_head; |
5344 | } | |
5345 | ||
5346 | /* See breakpoint.h. */ | |
5347 | ||
5348 | bpstat | |
5349 | bpstat_stop_status (const address_space *aspace, | |
00431a78 | 5350 | CORE_ADDR bp_addr, thread_info *thread, |
ddfe970e KS |
5351 | const struct target_waitstatus *ws, |
5352 | bpstat stop_chain) | |
5353 | { | |
5354 | struct breakpoint *b = NULL; | |
5355 | /* First item of allocated bpstat's. */ | |
5356 | bpstat bs_head = stop_chain; | |
5357 | bpstat bs; | |
5358 | int need_remove_insert; | |
5359 | int removed_any; | |
5360 | ||
5361 | /* First, build the bpstat chain with locations that explain a | |
5362 | target stop, while being careful to not set the target running, | |
5363 | as that may invalidate locations (in particular watchpoint | |
5364 | locations are recreated). Resuming will happen here with | |
5365 | breakpoint conditions or watchpoint expressions that include | |
5366 | inferior function calls. */ | |
5367 | if (bs_head == NULL) | |
5368 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5369 | ||
edcc5120 TT |
5370 | /* A bit of special processing for shlib breakpoints. We need to |
5371 | process solib loading here, so that the lists of loaded and | |
5372 | unloaded libraries are correct before we handle "catch load" and | |
5373 | "catch unload". */ | |
5374 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5375 | { | |
5d268276 | 5376 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5377 | { |
5378 | handle_solib_event (); | |
5379 | break; | |
5380 | } | |
5381 | } | |
5382 | ||
f431efe5 PA |
5383 | /* Now go through the locations that caused the target to stop, and |
5384 | check whether we're interested in reporting this stop to higher | |
5385 | layers, or whether we should resume the target transparently. */ | |
5386 | ||
5387 | removed_any = 0; | |
5388 | ||
5760d0ab | 5389 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5390 | { |
5391 | if (!bs->stop) | |
5392 | continue; | |
5393 | ||
f431efe5 | 5394 | b = bs->breakpoint_at; |
348d480f PA |
5395 | b->ops->check_status (bs); |
5396 | if (bs->stop) | |
28010a5d | 5397 | { |
00431a78 | 5398 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5399 | |
429374b8 JK |
5400 | if (bs->stop) |
5401 | { | |
5402 | ++(b->hit_count); | |
76727919 | 5403 | gdb::observers::breakpoint_modified.notify (b); |
c906108c | 5404 | |
4a64f543 | 5405 | /* We will stop here. */ |
429374b8 JK |
5406 | if (b->disposition == disp_disable) |
5407 | { | |
816338b5 | 5408 | --(b->enable_count); |
1a853c52 | 5409 | if (b->enable_count <= 0) |
429374b8 | 5410 | b->enable_state = bp_disabled; |
f431efe5 | 5411 | removed_any = 1; |
429374b8 JK |
5412 | } |
5413 | if (b->silent) | |
5414 | bs->print = 0; | |
5415 | bs->commands = b->commands; | |
abf85f46 | 5416 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5417 | ? bs->commands.get () : NULL)) |
abf85f46 | 5418 | bs->print = 0; |
9d6e6e84 HZ |
5419 | |
5420 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5421 | } |
5422 | ||
348d480f | 5423 | } |
a9b3a50f PA |
5424 | |
5425 | /* Print nothing for this entry if we don't stop or don't | |
5426 | print. */ | |
5427 | if (!bs->stop || !bs->print) | |
5428 | bs->print_it = print_it_noop; | |
429374b8 | 5429 | } |
876fa593 | 5430 | |
d983da9c DJ |
5431 | /* If we aren't stopping, the value of some hardware watchpoint may |
5432 | not have changed, but the intermediate memory locations we are | |
5433 | watching may have. Don't bother if we're stopping; this will get | |
5434 | done later. */ | |
d832cb68 | 5435 | need_remove_insert = 0; |
5760d0ab JK |
5436 | if (! bpstat_causes_stop (bs_head)) |
5437 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5438 | if (!bs->stop |
f431efe5 PA |
5439 | && bs->breakpoint_at |
5440 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5441 | { |
3a5c3e22 PA |
5442 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5443 | ||
5444 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5445 | need_remove_insert = 1; |
d983da9c DJ |
5446 | } |
5447 | ||
d832cb68 | 5448 | if (need_remove_insert) |
44702360 | 5449 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5450 | else if (removed_any) |
44702360 | 5451 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5452 | |
5760d0ab | 5453 | return bs_head; |
c906108c | 5454 | } |
628fe4e4 JK |
5455 | |
5456 | static void | |
5457 | handle_jit_event (void) | |
5458 | { | |
5459 | struct frame_info *frame; | |
5460 | struct gdbarch *gdbarch; | |
5461 | ||
243a9253 PA |
5462 | if (debug_infrun) |
5463 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5464 | ||
628fe4e4 JK |
5465 | /* Switch terminal for any messages produced by |
5466 | breakpoint_re_set. */ | |
223ffa71 | 5467 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5468 | |
5469 | frame = get_current_frame (); | |
5470 | gdbarch = get_frame_arch (frame); | |
5471 | ||
5472 | jit_event_handler (gdbarch); | |
5473 | ||
223ffa71 | 5474 | target_terminal::inferior (); |
628fe4e4 JK |
5475 | } |
5476 | ||
5477 | /* Prepare WHAT final decision for infrun. */ | |
5478 | ||
5479 | /* Decide what infrun needs to do with this bpstat. */ | |
5480 | ||
c906108c | 5481 | struct bpstat_what |
0e30163f | 5482 | bpstat_what (bpstat bs_head) |
c906108c | 5483 | { |
c906108c | 5484 | struct bpstat_what retval; |
0e30163f | 5485 | bpstat bs; |
c906108c | 5486 | |
628fe4e4 | 5487 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5488 | retval.call_dummy = STOP_NONE; |
e2d0f980 | 5489 | retval.is_longjmp = false; |
628fe4e4 | 5490 | |
0e30163f | 5491 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5492 | { |
628fe4e4 JK |
5493 | /* Extract this BS's action. After processing each BS, we check |
5494 | if its action overrides all we've seem so far. */ | |
5495 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5496 | enum bptype bptype; | |
5497 | ||
c906108c | 5498 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5499 | { |
5500 | /* I suspect this can happen if it was a momentary | |
5501 | breakpoint which has since been deleted. */ | |
5502 | bptype = bp_none; | |
5503 | } | |
20874c92 | 5504 | else |
f431efe5 | 5505 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5506 | |
5507 | switch (bptype) | |
c906108c SS |
5508 | { |
5509 | case bp_none: | |
628fe4e4 | 5510 | break; |
c906108c SS |
5511 | case bp_breakpoint: |
5512 | case bp_hardware_breakpoint: | |
7c16b83e | 5513 | case bp_single_step: |
c906108c SS |
5514 | case bp_until: |
5515 | case bp_finish: | |
a9b3a50f | 5516 | case bp_shlib_event: |
c906108c SS |
5517 | if (bs->stop) |
5518 | { | |
5519 | if (bs->print) | |
628fe4e4 | 5520 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5521 | else |
628fe4e4 | 5522 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5523 | } |
5524 | else | |
628fe4e4 | 5525 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5526 | break; |
5527 | case bp_watchpoint: | |
5528 | case bp_hardware_watchpoint: | |
5529 | case bp_read_watchpoint: | |
5530 | case bp_access_watchpoint: | |
5531 | if (bs->stop) | |
5532 | { | |
5533 | if (bs->print) | |
628fe4e4 | 5534 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5535 | else |
628fe4e4 | 5536 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5537 | } |
5538 | else | |
628fe4e4 JK |
5539 | { |
5540 | /* There was a watchpoint, but we're not stopping. | |
5541 | This requires no further action. */ | |
5542 | } | |
c906108c SS |
5543 | break; |
5544 | case bp_longjmp: | |
e2e4d78b | 5545 | case bp_longjmp_call_dummy: |
186c406b | 5546 | case bp_exception: |
0a39bb32 PA |
5547 | if (bs->stop) |
5548 | { | |
5549 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5550 | retval.is_longjmp = bptype != bp_exception; | |
5551 | } | |
5552 | else | |
5553 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5554 | break; |
5555 | case bp_longjmp_resume: | |
186c406b | 5556 | case bp_exception_resume: |
0a39bb32 PA |
5557 | if (bs->stop) |
5558 | { | |
5559 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5560 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5561 | } | |
5562 | else | |
5563 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5564 | break; |
5565 | case bp_step_resume: | |
5566 | if (bs->stop) | |
628fe4e4 JK |
5567 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5568 | else | |
c906108c | 5569 | { |
628fe4e4 JK |
5570 | /* It is for the wrong frame. */ |
5571 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5572 | } |
c906108c | 5573 | break; |
2c03e5be PA |
5574 | case bp_hp_step_resume: |
5575 | if (bs->stop) | |
5576 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5577 | else | |
5578 | { | |
5579 | /* It is for the wrong frame. */ | |
5580 | this_action = BPSTAT_WHAT_SINGLE; | |
5581 | } | |
5582 | break; | |
c906108c | 5583 | case bp_watchpoint_scope: |
c4093a6a | 5584 | case bp_thread_event: |
1900040c | 5585 | case bp_overlay_event: |
0fd8e87f | 5586 | case bp_longjmp_master: |
aa7d318d | 5587 | case bp_std_terminate_master: |
186c406b | 5588 | case bp_exception_master: |
628fe4e4 | 5589 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5590 | break; |
ce78b96d | 5591 | case bp_catchpoint: |
c5aa993b JM |
5592 | if (bs->stop) |
5593 | { | |
5594 | if (bs->print) | |
628fe4e4 | 5595 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5596 | else |
628fe4e4 | 5597 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5598 | } |
5599 | else | |
628fe4e4 | 5600 | { |
cb1e4e32 PA |
5601 | /* Some catchpoints are implemented with breakpoints. |
5602 | For those, we need to step over the breakpoint. */ | |
5603 | if (bs->bp_location_at->loc_type != bp_loc_other) | |
5604 | this_action = BPSTAT_WHAT_SINGLE; | |
628fe4e4 JK |
5605 | } |
5606 | break; | |
628fe4e4 | 5607 | case bp_jit_event: |
628fe4e4 | 5608 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5609 | break; |
c906108c | 5610 | case bp_call_dummy: |
53a5351d JM |
5611 | /* Make sure the action is stop (silent or noisy), |
5612 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5613 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5614 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5615 | break; |
5616 | case bp_std_terminate: | |
5617 | /* Make sure the action is stop (silent or noisy), | |
5618 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5619 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5620 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5621 | break; |
1042e4c0 | 5622 | case bp_tracepoint: |
7a697b8d | 5623 | case bp_fast_tracepoint: |
0fb4aa4b | 5624 | case bp_static_tracepoint: |
1042e4c0 SS |
5625 | /* Tracepoint hits should not be reported back to GDB, and |
5626 | if one got through somehow, it should have been filtered | |
5627 | out already. */ | |
5628 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5629 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5630 | break; |
5631 | case bp_gnu_ifunc_resolver: | |
5632 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5633 | this_action = BPSTAT_WHAT_SINGLE; | |
5634 | break; | |
5635 | case bp_gnu_ifunc_resolver_return: | |
5636 | /* The breakpoint will be removed, execution will restart from the | |
5637 | PC of the former breakpoint. */ | |
5638 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5639 | break; | |
e7e0cddf SS |
5640 | |
5641 | case bp_dprintf: | |
a11cfd87 HZ |
5642 | if (bs->stop) |
5643 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5644 | else | |
5645 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5646 | break; |
5647 | ||
628fe4e4 JK |
5648 | default: |
5649 | internal_error (__FILE__, __LINE__, | |
5650 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5651 | } |
628fe4e4 | 5652 | |
325fac50 | 5653 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5654 | } |
628fe4e4 | 5655 | |
243a9253 PA |
5656 | return retval; |
5657 | } | |
628fe4e4 | 5658 | |
243a9253 PA |
5659 | void |
5660 | bpstat_run_callbacks (bpstat bs_head) | |
5661 | { | |
5662 | bpstat bs; | |
628fe4e4 | 5663 | |
0e30163f JK |
5664 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5665 | { | |
5666 | struct breakpoint *b = bs->breakpoint_at; | |
5667 | ||
5668 | if (b == NULL) | |
5669 | continue; | |
5670 | switch (b->type) | |
5671 | { | |
243a9253 PA |
5672 | case bp_jit_event: |
5673 | handle_jit_event (); | |
5674 | break; | |
0e30163f JK |
5675 | case bp_gnu_ifunc_resolver: |
5676 | gnu_ifunc_resolver_stop (b); | |
5677 | break; | |
5678 | case bp_gnu_ifunc_resolver_return: | |
5679 | gnu_ifunc_resolver_return_stop (b); | |
5680 | break; | |
5681 | } | |
5682 | } | |
c906108c SS |
5683 | } |
5684 | ||
4c462cb0 | 5685 | /* See breakpoint.h. */ |
c906108c | 5686 | |
4c462cb0 SM |
5687 | bool |
5688 | bpstat_should_step () | |
c906108c SS |
5689 | { |
5690 | struct breakpoint *b; | |
cc59ec59 | 5691 | |
c906108c | 5692 | ALL_BREAKPOINTS (b) |
717a8278 | 5693 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
4c462cb0 SM |
5694 | return true; |
5695 | return false; | |
c906108c SS |
5696 | } |
5697 | ||
4c462cb0 SM |
5698 | /* See breakpoint.h. */ |
5699 | ||
5700 | bool | |
67822962 PA |
5701 | bpstat_causes_stop (bpstat bs) |
5702 | { | |
5703 | for (; bs != NULL; bs = bs->next) | |
5704 | if (bs->stop) | |
4c462cb0 | 5705 | return true; |
67822962 | 5706 | |
4c462cb0 | 5707 | return false; |
67822962 PA |
5708 | } |
5709 | ||
c906108c | 5710 | \f |
c5aa993b | 5711 | |
170b53b2 UW |
5712 | /* Compute a string of spaces suitable to indent the next line |
5713 | so it starts at the position corresponding to the table column | |
5714 | named COL_NAME in the currently active table of UIOUT. */ | |
5715 | ||
5716 | static char * | |
5717 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5718 | { | |
5719 | static char wrap_indent[80]; | |
5720 | int i, total_width, width, align; | |
c5209615 | 5721 | const char *text; |
170b53b2 UW |
5722 | |
5723 | total_width = 0; | |
112e8700 | 5724 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5725 | { |
5726 | if (strcmp (text, col_name) == 0) | |
5727 | { | |
5728 | gdb_assert (total_width < sizeof wrap_indent); | |
5729 | memset (wrap_indent, ' ', total_width); | |
5730 | wrap_indent[total_width] = 0; | |
5731 | ||
5732 | return wrap_indent; | |
5733 | } | |
5734 | ||
5735 | total_width += width + 1; | |
5736 | } | |
5737 | ||
5738 | return NULL; | |
5739 | } | |
5740 | ||
b775012e LM |
5741 | /* Determine if the locations of this breakpoint will have their conditions |
5742 | evaluated by the target, host or a mix of both. Returns the following: | |
5743 | ||
5744 | "host": Host evals condition. | |
5745 | "host or target": Host or Target evals condition. | |
5746 | "target": Target evals condition. | |
5747 | */ | |
5748 | ||
5749 | static const char * | |
5750 | bp_condition_evaluator (struct breakpoint *b) | |
5751 | { | |
5752 | struct bp_location *bl; | |
5753 | char host_evals = 0; | |
5754 | char target_evals = 0; | |
5755 | ||
5756 | if (!b) | |
5757 | return NULL; | |
5758 | ||
5759 | if (!is_breakpoint (b)) | |
5760 | return NULL; | |
5761 | ||
5762 | if (gdb_evaluates_breakpoint_condition_p () | |
5763 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5764 | return condition_evaluation_host; | |
5765 | ||
5766 | for (bl = b->loc; bl; bl = bl->next) | |
5767 | { | |
5768 | if (bl->cond_bytecode) | |
5769 | target_evals++; | |
5770 | else | |
5771 | host_evals++; | |
5772 | } | |
5773 | ||
5774 | if (host_evals && target_evals) | |
5775 | return condition_evaluation_both; | |
5776 | else if (target_evals) | |
5777 | return condition_evaluation_target; | |
5778 | else | |
5779 | return condition_evaluation_host; | |
5780 | } | |
5781 | ||
5782 | /* Determine the breakpoint location's condition evaluator. This is | |
5783 | similar to bp_condition_evaluator, but for locations. */ | |
5784 | ||
5785 | static const char * | |
5786 | bp_location_condition_evaluator (struct bp_location *bl) | |
5787 | { | |
5788 | if (bl && !is_breakpoint (bl->owner)) | |
5789 | return NULL; | |
5790 | ||
5791 | if (gdb_evaluates_breakpoint_condition_p () | |
5792 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5793 | return condition_evaluation_host; | |
5794 | ||
5795 | if (bl && bl->cond_bytecode) | |
5796 | return condition_evaluation_target; | |
5797 | else | |
5798 | return condition_evaluation_host; | |
5799 | } | |
5800 | ||
859825b8 JK |
5801 | /* Print the LOC location out of the list of B->LOC locations. */ |
5802 | ||
170b53b2 UW |
5803 | static void |
5804 | print_breakpoint_location (struct breakpoint *b, | |
5805 | struct bp_location *loc) | |
0d381245 | 5806 | { |
79a45e25 | 5807 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5808 | |
5809 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5810 | |
859825b8 JK |
5811 | if (loc != NULL && loc->shlib_disabled) |
5812 | loc = NULL; | |
5813 | ||
6c95b8df PA |
5814 | if (loc != NULL) |
5815 | set_current_program_space (loc->pspace); | |
5816 | ||
56435ebe | 5817 | if (b->display_canonical) |
d28cd78a | 5818 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 5819 | else if (loc && loc->symtab) |
0d381245 | 5820 | { |
4a27f119 KS |
5821 | const struct symbol *sym = loc->symbol; |
5822 | ||
0d381245 VP |
5823 | if (sym) |
5824 | { | |
112e8700 | 5825 | uiout->text ("in "); |
987012b8 | 5826 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 5827 | function_name_style.style ()); |
112e8700 SM |
5828 | uiout->text (" "); |
5829 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
5830 | uiout->text ("at "); | |
0d381245 | 5831 | } |
112e8700 | 5832 | uiout->field_string ("file", |
cbe56571 | 5833 | symtab_to_filename_for_display (loc->symtab), |
e43b10e1 | 5834 | file_name_style.style ()); |
112e8700 | 5835 | uiout->text (":"); |
05cba821 | 5836 | |
112e8700 SM |
5837 | if (uiout->is_mi_like_p ()) |
5838 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 5839 | |
381befee | 5840 | uiout->field_signed ("line", loc->line_number); |
0d381245 | 5841 | } |
859825b8 | 5842 | else if (loc) |
0d381245 | 5843 | { |
d7e74731 | 5844 | string_file stb; |
170b53b2 | 5845 | |
d7e74731 | 5846 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 5847 | demangle, ""); |
112e8700 | 5848 | uiout->field_stream ("at", stb); |
0d381245 | 5849 | } |
859825b8 | 5850 | else |
f00aae0f | 5851 | { |
d28cd78a TT |
5852 | uiout->field_string ("pending", |
5853 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
5854 | /* If extra_string is available, it could be holding a condition |
5855 | or dprintf arguments. In either case, make sure it is printed, | |
5856 | too, but only for non-MI streams. */ | |
112e8700 | 5857 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
5858 | { |
5859 | if (b->type == bp_dprintf) | |
112e8700 | 5860 | uiout->text (","); |
f00aae0f | 5861 | else |
112e8700 SM |
5862 | uiout->text (" "); |
5863 | uiout->text (b->extra_string); | |
f00aae0f KS |
5864 | } |
5865 | } | |
6c95b8df | 5866 | |
b775012e LM |
5867 | if (loc && is_breakpoint (b) |
5868 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
5869 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
5870 | { | |
112e8700 SM |
5871 | uiout->text (" ("); |
5872 | uiout->field_string ("evaluated-by", | |
b775012e | 5873 | bp_location_condition_evaluator (loc)); |
112e8700 | 5874 | uiout->text (")"); |
b775012e | 5875 | } |
0d381245 VP |
5876 | } |
5877 | ||
269b11a2 PA |
5878 | static const char * |
5879 | bptype_string (enum bptype type) | |
c906108c | 5880 | { |
c4093a6a JM |
5881 | struct ep_type_description |
5882 | { | |
5883 | enum bptype type; | |
a121b7c1 | 5884 | const char *description; |
c4093a6a JM |
5885 | }; |
5886 | static struct ep_type_description bptypes[] = | |
c906108c | 5887 | { |
c5aa993b JM |
5888 | {bp_none, "?deleted?"}, |
5889 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 5890 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 5891 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
5892 | {bp_until, "until"}, |
5893 | {bp_finish, "finish"}, | |
5894 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 5895 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
5896 | {bp_read_watchpoint, "read watchpoint"}, |
5897 | {bp_access_watchpoint, "acc watchpoint"}, | |
5898 | {bp_longjmp, "longjmp"}, | |
5899 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 5900 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
5901 | {bp_exception, "exception"}, |
5902 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 5903 | {bp_step_resume, "step resume"}, |
2c03e5be | 5904 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
5905 | {bp_watchpoint_scope, "watchpoint scope"}, |
5906 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 5907 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 5908 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 5909 | {bp_thread_event, "thread events"}, |
1900040c | 5910 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 5911 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 5912 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 5913 | {bp_exception_master, "exception master"}, |
ce78b96d | 5914 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 5915 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 5916 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 5917 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 5918 | {bp_dprintf, "dprintf"}, |
4efc6507 | 5919 | {bp_jit_event, "jit events"}, |
0e30163f JK |
5920 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
5921 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 5922 | }; |
269b11a2 PA |
5923 | |
5924 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
5925 | || ((int) type != bptypes[(int) type].type)) | |
5926 | internal_error (__FILE__, __LINE__, | |
5927 | _("bptypes table does not describe type #%d."), | |
5928 | (int) type); | |
5929 | ||
5930 | return bptypes[(int) type].description; | |
5931 | } | |
5932 | ||
998580f1 MK |
5933 | /* For MI, output a field named 'thread-groups' with a list as the value. |
5934 | For CLI, prefix the list with the string 'inf'. */ | |
5935 | ||
5936 | static void | |
5937 | output_thread_groups (struct ui_out *uiout, | |
5938 | const char *field_name, | |
5c632425 | 5939 | const std::vector<int> &inf_nums, |
998580f1 MK |
5940 | int mi_only) |
5941 | { | |
112e8700 | 5942 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
5943 | |
5944 | /* For backward compatibility, don't display inferiors in CLI unless | |
5945 | there are several. Always display them for MI. */ | |
5946 | if (!is_mi && mi_only) | |
5947 | return; | |
5948 | ||
10f489e5 | 5949 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 5950 | |
5c632425 | 5951 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
5952 | { |
5953 | if (is_mi) | |
5954 | { | |
5955 | char mi_group[10]; | |
5956 | ||
5c632425 | 5957 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 5958 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
5959 | } |
5960 | else | |
5961 | { | |
5962 | if (i == 0) | |
112e8700 | 5963 | uiout->text (" inf "); |
998580f1 | 5964 | else |
112e8700 | 5965 | uiout->text (", "); |
998580f1 | 5966 | |
5c632425 | 5967 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
5968 | } |
5969 | } | |
998580f1 MK |
5970 | } |
5971 | ||
a38118e5 PA |
5972 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
5973 | instead of going via breakpoint_ops::print_one. This makes "maint | |
5974 | info breakpoints" show the software breakpoint locations of | |
5975 | catchpoints, which are considered internal implementation | |
5976 | detail. */ | |
269b11a2 PA |
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, | |
a38118e5 | 5983 | int allflag, bool raw_loc) |
269b11a2 PA |
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 |
381befee | 6012 | uiout->field_signed ("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 */ |
a38118e5 | 6036 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
b58a68fe | 6037 | b->ops->print_one (b, last_loc); |
3086aeae | 6038 | else |
a38118e5 PA |
6039 | { |
6040 | if (is_watchpoint (b)) | |
3a5c3e22 PA |
6041 | { |
6042 | struct watchpoint *w = (struct watchpoint *) b; | |
6043 | ||
6044 | /* Field 4, the address, is omitted (which makes the columns | |
6045 | not line up too nicely with the headers, but the effect | |
6046 | is relatively readable). */ | |
6047 | if (opts.addressprint) | |
112e8700 | 6048 | uiout->field_skip ("addr"); |
3a5c3e22 | 6049 | annotate_field (5); |
112e8700 | 6050 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6051 | } |
f06f1252 TT |
6052 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
6053 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6054 | { |
6055 | if (opts.addressprint) | |
6056 | { | |
6057 | annotate_field (4); | |
6058 | if (header_of_multiple) | |
7f6aba03 TT |
6059 | uiout->field_string ("addr", "<MULTIPLE>", |
6060 | metadata_style.style ()); | |
a38118e5 | 6061 | else if (b->loc == NULL || loc->shlib_disabled) |
7f6aba03 TT |
6062 | uiout->field_string ("addr", "<PENDING>", |
6063 | metadata_style.style ()); | |
a38118e5 PA |
6064 | else |
6065 | uiout->field_core_addr ("addr", | |
6066 | loc->gdbarch, loc->address); | |
6067 | } | |
6068 | annotate_field (5); | |
6069 | if (!header_of_multiple) | |
6070 | print_breakpoint_location (b, loc); | |
6071 | if (b->loc) | |
6072 | *last_loc = b->loc; | |
6073 | } | |
6074 | } | |
6c95b8df | 6075 | |
998580f1 | 6076 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6077 | { |
5c632425 | 6078 | std::vector<int> inf_nums; |
998580f1 | 6079 | int mi_only = 1; |
6c95b8df | 6080 | |
08036331 | 6081 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6082 | { |
6083 | if (inf->pspace == loc->pspace) | |
5c632425 | 6084 | inf_nums.push_back (inf->num); |
6c95b8df | 6085 | } |
998580f1 MK |
6086 | |
6087 | /* For backward compatibility, don't display inferiors in CLI unless | |
6088 | there are several. Always display for MI. */ | |
6089 | if (allflag | |
6090 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6091 | && (number_of_program_spaces () > 1 | |
6092 | || number_of_inferiors () > 1) | |
6093 | /* LOC is for existing B, it cannot be in | |
6094 | moribund_locations and thus having NULL OWNER. */ | |
6095 | && loc->owner->type != bp_catchpoint)) | |
6096 | mi_only = 0; | |
5c632425 | 6097 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6098 | } |
6099 | ||
4a306c9a | 6100 | if (!part_of_multiple) |
c4093a6a | 6101 | { |
4a306c9a JB |
6102 | if (b->thread != -1) |
6103 | { | |
6104 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6105 | "stop only in" line a little further down. */ |
112e8700 | 6106 | uiout->text (" thread "); |
381befee | 6107 | uiout->field_signed ("thread", b->thread); |
4a306c9a JB |
6108 | } |
6109 | else if (b->task != 0) | |
6110 | { | |
112e8700 | 6111 | uiout->text (" task "); |
381befee | 6112 | uiout->field_signed ("task", b->task); |
4a306c9a | 6113 | } |
c4093a6a | 6114 | } |
f1310107 | 6115 | |
112e8700 | 6116 | uiout->text ("\n"); |
f1310107 | 6117 | |
348d480f | 6118 | if (!part_of_multiple) |
f1310107 TJB |
6119 | b->ops->print_one_detail (b, uiout); |
6120 | ||
0d381245 | 6121 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6122 | { |
6123 | annotate_field (6); | |
112e8700 | 6124 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6125 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6126 | the frame ID. */ |
112e8700 | 6127 | uiout->field_core_addr ("frame", |
5af949e3 | 6128 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6129 | uiout->text ("\n"); |
c4093a6a JM |
6130 | } |
6131 | ||
28010a5d | 6132 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6133 | { |
6134 | annotate_field (7); | |
d77f58be | 6135 | if (is_tracepoint (b)) |
112e8700 | 6136 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6137 | else |
112e8700 SM |
6138 | uiout->text ("\tstop only if "); |
6139 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6140 | |
6141 | /* Print whether the target is doing the breakpoint's condition | |
6142 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6143 | if (is_breakpoint (b) | |
6144 | && breakpoint_condition_evaluation_mode () | |
6145 | == condition_evaluation_target) | |
6146 | { | |
6a831f06 PA |
6147 | uiout->message (" (%pF evals)", |
6148 | string_field ("evaluated-by", | |
6149 | bp_condition_evaluator (b))); | |
b775012e | 6150 | } |
112e8700 | 6151 | uiout->text ("\n"); |
0101ce28 JJ |
6152 | } |
6153 | ||
0d381245 | 6154 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6155 | { |
4a64f543 | 6156 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6157 | uiout->text ("\tstop only in thread "); |
6158 | if (uiout->is_mi_like_p ()) | |
381befee | 6159 | uiout->field_signed ("thread", b->thread); |
5d5658a1 PA |
6160 | else |
6161 | { | |
6162 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6163 | ||
112e8700 | 6164 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6165 | } |
112e8700 | 6166 | uiout->text ("\n"); |
c4093a6a JM |
6167 | } |
6168 | ||
556ec64d YQ |
6169 | if (!part_of_multiple) |
6170 | { | |
6171 | if (b->hit_count) | |
31f56a27 YQ |
6172 | { |
6173 | /* FIXME should make an annotation for this. */ | |
6174 | if (is_catchpoint (b)) | |
112e8700 | 6175 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6176 | else if (is_tracepoint (b)) |
112e8700 | 6177 | uiout->text ("\ttracepoint"); |
31f56a27 | 6178 | else |
112e8700 SM |
6179 | uiout->text ("\tbreakpoint"); |
6180 | uiout->text (" already hit "); | |
381befee | 6181 | uiout->field_signed ("times", b->hit_count); |
31f56a27 | 6182 | if (b->hit_count == 1) |
112e8700 | 6183 | uiout->text (" time\n"); |
31f56a27 | 6184 | else |
112e8700 | 6185 | uiout->text (" times\n"); |
31f56a27 | 6186 | } |
556ec64d YQ |
6187 | else |
6188 | { | |
31f56a27 | 6189 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 | 6190 | if (uiout->is_mi_like_p ()) |
381befee | 6191 | uiout->field_signed ("times", b->hit_count); |
556ec64d YQ |
6192 | } |
6193 | } | |
8b93c638 | 6194 | |
0d381245 | 6195 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6196 | { |
6197 | annotate_field (8); | |
6a831f06 PA |
6198 | uiout->message ("\tignore next %pF hits\n", |
6199 | signed_field ("ignore", b->ignore_count)); | |
c4093a6a | 6200 | } |
059fb39f | 6201 | |
816338b5 SS |
6202 | /* Note that an enable count of 1 corresponds to "enable once" |
6203 | behavior, which is reported by the combination of enablement and | |
6204 | disposition, so we don't need to mention it here. */ | |
6205 | if (!part_of_multiple && b->enable_count > 1) | |
6206 | { | |
6207 | annotate_field (8); | |
112e8700 | 6208 | uiout->text ("\tdisable after "); |
816338b5 SS |
6209 | /* Tweak the wording to clarify that ignore and enable counts |
6210 | are distinct, and have additive effect. */ | |
6211 | if (b->ignore_count) | |
112e8700 | 6212 | uiout->text ("additional "); |
816338b5 | 6213 | else |
112e8700 | 6214 | uiout->text ("next "); |
381befee | 6215 | uiout->field_signed ("enable", b->enable_count); |
112e8700 | 6216 | uiout->text (" hits\n"); |
816338b5 SS |
6217 | } |
6218 | ||
f196051f SS |
6219 | if (!part_of_multiple && is_tracepoint (b)) |
6220 | { | |
6221 | struct tracepoint *tp = (struct tracepoint *) b; | |
6222 | ||
6223 | if (tp->traceframe_usage) | |
6224 | { | |
112e8700 | 6225 | uiout->text ("\ttrace buffer usage "); |
381befee | 6226 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
112e8700 | 6227 | uiout->text (" bytes\n"); |
f196051f SS |
6228 | } |
6229 | } | |
d3ce09f5 | 6230 | |
d1b0a7bf | 6231 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6232 | if (!part_of_multiple && l) |
c4093a6a JM |
6233 | { |
6234 | annotate_field (9); | |
2e783024 | 6235 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6236 | print_command_lines (uiout, l, 4); |
c4093a6a | 6237 | } |
d24317b4 | 6238 | |
d9b3f62e | 6239 | if (is_tracepoint (b)) |
1042e4c0 | 6240 | { |
d9b3f62e PA |
6241 | struct tracepoint *t = (struct tracepoint *) b; |
6242 | ||
6243 | if (!part_of_multiple && t->pass_count) | |
6244 | { | |
6245 | annotate_field (10); | |
112e8700 | 6246 | uiout->text ("\tpass count "); |
381befee | 6247 | uiout->field_signed ("pass", t->pass_count); |
112e8700 | 6248 | uiout->text (" \n"); |
d9b3f62e | 6249 | } |
f2a8bc8a YQ |
6250 | |
6251 | /* Don't display it when tracepoint or tracepoint location is | |
6252 | pending. */ | |
6253 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6254 | { | |
6255 | annotate_field (11); | |
6256 | ||
112e8700 SM |
6257 | if (uiout->is_mi_like_p ()) |
6258 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6259 | loc->inserted ? "y" : "n"); |
6260 | else | |
6261 | { | |
6262 | if (loc->inserted) | |
112e8700 | 6263 | uiout->text ("\t"); |
f2a8bc8a | 6264 | else |
112e8700 SM |
6265 | uiout->text ("\tnot "); |
6266 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6267 | } |
6268 | } | |
1042e4c0 SS |
6269 | } |
6270 | ||
112e8700 | 6271 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6272 | { |
3a5c3e22 PA |
6273 | if (is_watchpoint (b)) |
6274 | { | |
6275 | struct watchpoint *w = (struct watchpoint *) b; | |
6276 | ||
112e8700 | 6277 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6278 | } |
f00aae0f | 6279 | else if (b->location != NULL |
d28cd78a | 6280 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6281 | uiout->field_string ("original-location", |
d28cd78a | 6282 | event_location_to_string (b->location.get ())); |
d24317b4 | 6283 | } |
c4093a6a | 6284 | } |
c5aa993b | 6285 | |
13674803 SM |
6286 | /* See breakpoint.h. */ |
6287 | ||
6288 | bool fix_multi_location_breakpoint_output_globally = false; | |
6289 | ||
0d381245 VP |
6290 | static void |
6291 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6292 | struct bp_location **last_loc, |
6c95b8df | 6293 | int allflag) |
0d381245 | 6294 | { |
79a45e25 | 6295 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6296 | bool use_fixed_output |
6297 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6298 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6299 | |
b4be1b06 | 6300 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
a38118e5 | 6301 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
8d3788bd | 6302 | |
b4be1b06 SM |
6303 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6304 | are outside. */ | |
6305 | if (!use_fixed_output) | |
6306 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6307 | |
6308 | /* If this breakpoint has custom print function, | |
6309 | it's already printed. Otherwise, print individual | |
6310 | locations, if any. */ | |
a38118e5 PA |
6311 | if (b->ops == NULL |
6312 | || b->ops->print_one == NULL | |
6313 | || allflag) | |
0d381245 | 6314 | { |
4a64f543 MS |
6315 | /* If breakpoint has a single location that is disabled, we |
6316 | print it as if it had several locations, since otherwise it's | |
6317 | hard to represent "breakpoint enabled, location disabled" | |
6318 | situation. | |
6319 | ||
6320 | Note that while hardware watchpoints have several locations | |
a38118e5 PA |
6321 | internally, that's not a property exposed to users. |
6322 | ||
6323 | Likewise, while catchpoints may be implemented with | |
6324 | breakpoints (e.g., catch throw), that's not a property | |
6325 | exposed to users. We do however display the internal | |
6326 | breakpoint locations with "maint info breakpoints". */ | |
6327 | if (!is_hardware_watchpoint (b) | |
f06f1252 TT |
6328 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
6329 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6330 | && (allflag |
6331 | || (b->loc && (b->loc->next || !b->loc->enabled)))) | |
0d381245 | 6332 | { |
b4be1b06 SM |
6333 | gdb::optional<ui_out_emit_list> locations_list; |
6334 | ||
6335 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6336 | MI record. For later versions, place breakpoint locations in a | |
6337 | list. */ | |
6338 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6339 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6340 | |
b4be1b06 SM |
6341 | int n = 1; |
6342 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) | |
8d3788bd | 6343 | { |
b4be1b06 | 6344 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
a38118e5 PA |
6345 | print_one_breakpoint_location (b, loc, n, last_loc, |
6346 | allflag, allflag); | |
8d3788bd | 6347 | } |
0d381245 VP |
6348 | } |
6349 | } | |
6350 | } | |
6351 | ||
a6d9a66e UW |
6352 | static int |
6353 | breakpoint_address_bits (struct breakpoint *b) | |
6354 | { | |
6355 | int print_address_bits = 0; | |
6356 | struct bp_location *loc; | |
6357 | ||
c6d81124 PA |
6358 | /* Software watchpoints that aren't watching memory don't have an |
6359 | address to print. */ | |
6360 | if (is_no_memory_software_watchpoint (b)) | |
6361 | return 0; | |
6362 | ||
a6d9a66e UW |
6363 | for (loc = b->loc; loc; loc = loc->next) |
6364 | { | |
c7437ca6 PA |
6365 | int addr_bit; |
6366 | ||
c7437ca6 | 6367 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6368 | if (addr_bit > print_address_bits) |
6369 | print_address_bits = addr_bit; | |
6370 | } | |
6371 | ||
6372 | return print_address_bits; | |
6373 | } | |
0d381245 | 6374 | |
65630365 | 6375 | /* See breakpoint.h. */ |
c5aa993b | 6376 | |
65630365 PA |
6377 | void |
6378 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6379 | { |
a6d9a66e | 6380 | struct bp_location *dummy_loc = NULL; |
65630365 | 6381 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6382 | } |
c5aa993b | 6383 | |
09d682a4 TT |
6384 | /* Return true if this breakpoint was set by the user, false if it is |
6385 | internal or momentary. */ | |
6386 | ||
6387 | int | |
6388 | user_breakpoint_p (struct breakpoint *b) | |
6389 | { | |
46c6471b | 6390 | return b->number > 0; |
09d682a4 TT |
6391 | } |
6392 | ||
93daf339 TT |
6393 | /* See breakpoint.h. */ |
6394 | ||
6395 | int | |
6396 | pending_breakpoint_p (struct breakpoint *b) | |
6397 | { | |
6398 | return b->loc == NULL; | |
6399 | } | |
6400 | ||
5c458ae8 SM |
6401 | /* Print information on breakpoints (including watchpoints and tracepoints). |
6402 | ||
6403 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as | |
6404 | understood by number_or_range_parser. Only breakpoints included in this | |
6405 | list are then printed. | |
6406 | ||
6407 | If SHOW_INTERNAL is true, print internal breakpoints. | |
6408 | ||
6409 | If FILTER is non-NULL, call it on each breakpoint and only include the | |
6410 | ones for which it returns true. | |
6411 | ||
6412 | Return the total number of breakpoints listed. */ | |
c906108c | 6413 | |
d77f58be | 6414 | static int |
5c458ae8 | 6415 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
f2478a7e | 6416 | bool (*filter) (const struct breakpoint *)) |
c4093a6a | 6417 | { |
52f0bd74 | 6418 | struct breakpoint *b; |
a6d9a66e | 6419 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6420 | int nr_printable_breakpoints; |
79a45b7d | 6421 | struct value_print_options opts; |
a6d9a66e | 6422 | int print_address_bits = 0; |
269b11a2 | 6423 | int print_type_col_width = 14; |
79a45e25 | 6424 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6425 | |
79a45b7d TT |
6426 | get_user_print_options (&opts); |
6427 | ||
4a64f543 MS |
6428 | /* Compute the number of rows in the table, as well as the size |
6429 | required for address fields. */ | |
7f3b0473 AC |
6430 | nr_printable_breakpoints = 0; |
6431 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6432 | { |
6433 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6434 | if (filter && !filter (b)) | |
6435 | continue; | |
6436 | ||
5c458ae8 | 6437 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
e5a67952 | 6438 | accept. Skip the others. */ |
5c458ae8 | 6439 | if (bp_num_list != NULL && *bp_num_list != '\0') |
e5a67952 | 6440 | { |
5c458ae8 | 6441 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
e5a67952 | 6442 | continue; |
5c458ae8 | 6443 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
e5a67952 MS |
6444 | continue; |
6445 | } | |
269b11a2 | 6446 | |
5c458ae8 | 6447 | if (show_internal || user_breakpoint_p (b)) |
e5a67952 MS |
6448 | { |
6449 | int addr_bit, type_len; | |
a6d9a66e | 6450 | |
e5a67952 MS |
6451 | addr_bit = breakpoint_address_bits (b); |
6452 | if (addr_bit > print_address_bits) | |
6453 | print_address_bits = addr_bit; | |
269b11a2 | 6454 | |
e5a67952 MS |
6455 | type_len = strlen (bptype_string (b->type)); |
6456 | if (type_len > print_type_col_width) | |
6457 | print_type_col_width = type_len; | |
6458 | ||
6459 | nr_printable_breakpoints++; | |
6460 | } | |
6461 | } | |
7f3b0473 | 6462 | |
4a2b031d TT |
6463 | { |
6464 | ui_out_emit_table table_emitter (uiout, | |
6465 | opts.addressprint ? 6 : 5, | |
6466 | nr_printable_breakpoints, | |
6467 | "BreakpointTable"); | |
6468 | ||
6469 | if (nr_printable_breakpoints > 0) | |
6470 | annotate_breakpoints_headers (); | |
6471 | if (nr_printable_breakpoints > 0) | |
6472 | annotate_field (0); | |
6473 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6474 | if (nr_printable_breakpoints > 0) | |
6475 | annotate_field (1); | |
6476 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6477 | if (nr_printable_breakpoints > 0) | |
6478 | annotate_field (2); | |
6479 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6480 | if (nr_printable_breakpoints > 0) | |
6481 | annotate_field (3); | |
6482 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6483 | if (opts.addressprint) | |
6484 | { | |
6485 | if (nr_printable_breakpoints > 0) | |
6486 | annotate_field (4); | |
6487 | if (print_address_bits <= 32) | |
6488 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6489 | else | |
6490 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6491 | } | |
6492 | if (nr_printable_breakpoints > 0) | |
6493 | annotate_field (5); | |
6494 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6495 | uiout->table_body (); | |
6496 | if (nr_printable_breakpoints > 0) | |
6497 | annotate_breakpoints_table (); | |
6498 | ||
6499 | ALL_BREAKPOINTS (b) | |
6500 | { | |
6501 | QUIT; | |
6502 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6503 | if (filter && !filter (b)) | |
6504 | continue; | |
e5a67952 | 6505 | |
5c458ae8 | 6506 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
4a2b031d | 6507 | accept. Skip the others. */ |
e5a67952 | 6508 | |
5c458ae8 | 6509 | if (bp_num_list != NULL && *bp_num_list != '\0') |
4a2b031d | 6510 | { |
5c458ae8 | 6511 | if (show_internal) /* maintenance info breakpoint */ |
4a2b031d | 6512 | { |
5c458ae8 | 6513 | if (parse_and_eval_long (bp_num_list) != b->number) |
4a2b031d TT |
6514 | continue; |
6515 | } | |
6516 | else /* all others */ | |
6517 | { | |
5c458ae8 | 6518 | if (!number_is_in_list (bp_num_list, b->number)) |
4a2b031d TT |
6519 | continue; |
6520 | } | |
6521 | } | |
6522 | /* We only print out user settable breakpoints unless the | |
5c458ae8 SM |
6523 | show_internal is set. */ |
6524 | if (show_internal || user_breakpoint_p (b)) | |
6525 | print_one_breakpoint (b, &last_loc, show_internal); | |
4a2b031d TT |
6526 | } |
6527 | } | |
698384cd | 6528 | |
7f3b0473 | 6529 | if (nr_printable_breakpoints == 0) |
c906108c | 6530 | { |
4a64f543 MS |
6531 | /* If there's a filter, let the caller decide how to report |
6532 | empty list. */ | |
d77f58be SS |
6533 | if (!filter) |
6534 | { | |
5c458ae8 | 6535 | if (bp_num_list == NULL || *bp_num_list == '\0') |
112e8700 | 6536 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6537 | else |
112e8700 | 6538 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
5c458ae8 | 6539 | bp_num_list); |
d77f58be | 6540 | } |
c906108c SS |
6541 | } |
6542 | else | |
c4093a6a | 6543 | { |
a6d9a66e UW |
6544 | if (last_loc && !server_command) |
6545 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6546 | } |
c906108c | 6547 | |
4a64f543 | 6548 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6549 | there have been breakpoints? */ |
c906108c | 6550 | annotate_breakpoints_table_end (); |
d77f58be SS |
6551 | |
6552 | return nr_printable_breakpoints; | |
c906108c SS |
6553 | } |
6554 | ||
ad443146 SS |
6555 | /* Display the value of default-collect in a way that is generally |
6556 | compatible with the breakpoint list. */ | |
6557 | ||
6558 | static void | |
6559 | default_collect_info (void) | |
6560 | { | |
79a45e25 PA |
6561 | struct ui_out *uiout = current_uiout; |
6562 | ||
ad443146 SS |
6563 | /* If it has no value (which is frequently the case), say nothing; a |
6564 | message like "No default-collect." gets in user's face when it's | |
6565 | not wanted. */ | |
6566 | if (!*default_collect) | |
6567 | return; | |
6568 | ||
6569 | /* The following phrase lines up nicely with per-tracepoint collect | |
6570 | actions. */ | |
112e8700 SM |
6571 | uiout->text ("default collect "); |
6572 | uiout->field_string ("default-collect", default_collect); | |
6573 | uiout->text (" \n"); | |
ad443146 SS |
6574 | } |
6575 | ||
c906108c | 6576 | static void |
0b39b52e | 6577 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6578 | { |
5c458ae8 | 6579 | breakpoint_1 (args, false, NULL); |
ad443146 SS |
6580 | |
6581 | default_collect_info (); | |
d77f58be SS |
6582 | } |
6583 | ||
6584 | static void | |
1d12d88f | 6585 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6586 | { |
5c458ae8 | 6587 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
79a45e25 | 6588 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6589 | |
6590 | if (num_printed == 0) | |
6591 | { | |
e5a67952 | 6592 | if (args == NULL || *args == '\0') |
112e8700 | 6593 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6594 | else |
112e8700 | 6595 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6596 | } |
c906108c SS |
6597 | } |
6598 | ||
7a292a7a | 6599 | static void |
4495129a | 6600 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6601 | { |
5c458ae8 | 6602 | breakpoint_1 (args, true, NULL); |
ad443146 SS |
6603 | |
6604 | default_collect_info (); | |
c906108c SS |
6605 | } |
6606 | ||
0d381245 | 6607 | static int |
714835d5 | 6608 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6609 | struct program_space *pspace, |
714835d5 | 6610 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6611 | { |
6612 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6613 | |
0d381245 VP |
6614 | for (; bl; bl = bl->next) |
6615 | { | |
6c95b8df PA |
6616 | if (bl->pspace == pspace |
6617 | && bl->address == pc | |
0d381245 VP |
6618 | && (!overlay_debugging || bl->section == section)) |
6619 | return 1; | |
6620 | } | |
6621 | return 0; | |
6622 | } | |
6623 | ||
672f9b60 | 6624 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6625 | concerns with logical breakpoints, so we match program spaces, not |
6626 | address spaces. */ | |
c906108c SS |
6627 | |
6628 | static void | |
6c95b8df PA |
6629 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6630 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6631 | struct obj_section *section, int thread) |
c906108c | 6632 | { |
52f0bd74 AC |
6633 | int others = 0; |
6634 | struct breakpoint *b; | |
c906108c SS |
6635 | |
6636 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6637 | others += (user_breakpoint_p (b) |
6638 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6639 | if (others > 0) |
6640 | { | |
a3f17187 AC |
6641 | if (others == 1) |
6642 | printf_filtered (_("Note: breakpoint ")); | |
6643 | else /* if (others == ???) */ | |
6644 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6645 | ALL_BREAKPOINTS (b) |
672f9b60 | 6646 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6647 | { |
6648 | others--; | |
6649 | printf_filtered ("%d", b->number); | |
6650 | if (b->thread == -1 && thread != -1) | |
6651 | printf_filtered (" (all threads)"); | |
6652 | else if (b->thread != -1) | |
6653 | printf_filtered (" (thread %d)", b->thread); | |
6654 | printf_filtered ("%s%s ", | |
059fb39f | 6655 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6656 | || b->enable_state == bp_call_disabled) |
0d381245 | 6657 | ? " (disabled)" |
0d381245 VP |
6658 | : ""), |
6659 | (others > 1) ? "," | |
6660 | : ((others == 1) ? " and" : "")); | |
6661 | } | |
6a831f06 PA |
6662 | current_uiout->message (_("also set at pc %ps.\n"), |
6663 | styled_string (address_style.style (), | |
6664 | paddress (gdbarch, pc))); | |
c906108c SS |
6665 | } |
6666 | } | |
6667 | \f | |
c906108c | 6668 | |
cb1e4e32 PA |
6669 | /* Return true iff it is meaningful to use the address member of LOC. |
6670 | For some breakpoint types, the locations' address members are | |
6671 | irrelevant and it makes no sense to attempt to compare them to | |
6672 | other addresses (or use them for any other purpose either). | |
2d134ed3 | 6673 | |
cb1e4e32 PA |
6674 | More specifically, software watchpoints and catchpoints that are |
6675 | not backed by breakpoints always have a zero valued location | |
6676 | address and we don't want to mark breakpoints of any of these types | |
6677 | to be a duplicate of an actual breakpoint location at address | |
6678 | zero. */ | |
e4f237da | 6679 | |
cb1e4e32 PA |
6680 | static bool |
6681 | bl_address_is_meaningful (bp_location *loc) | |
e4f237da | 6682 | { |
cb1e4e32 | 6683 | return loc->loc_type != bp_loc_other; |
2d134ed3 PA |
6684 | } |
6685 | ||
6686 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6687 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6688 | ||
6689 | static int | |
4a64f543 MS |
6690 | watchpoint_locations_match (struct bp_location *loc1, |
6691 | struct bp_location *loc2) | |
2d134ed3 | 6692 | { |
3a5c3e22 PA |
6693 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6694 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6695 | ||
6696 | /* Both of them must exist. */ | |
6697 | gdb_assert (w1 != NULL); | |
6698 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6699 | |
4a64f543 MS |
6700 | /* If the target can evaluate the condition expression in hardware, |
6701 | then we we need to insert both watchpoints even if they are at | |
6702 | the same place. Otherwise the watchpoint will only trigger when | |
6703 | the condition of whichever watchpoint was inserted evaluates to | |
6704 | true, not giving a chance for GDB to check the condition of the | |
6705 | other watchpoint. */ | |
3a5c3e22 | 6706 | if ((w1->cond_exp |
4a64f543 MS |
6707 | && target_can_accel_watchpoint_condition (loc1->address, |
6708 | loc1->length, | |
0cf6dd15 | 6709 | loc1->watchpoint_type, |
4d01a485 | 6710 | w1->cond_exp.get ())) |
3a5c3e22 | 6711 | || (w2->cond_exp |
4a64f543 MS |
6712 | && target_can_accel_watchpoint_condition (loc2->address, |
6713 | loc2->length, | |
0cf6dd15 | 6714 | loc2->watchpoint_type, |
4d01a485 | 6715 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6716 | return 0; |
6717 | ||
85d721b8 PA |
6718 | /* Note that this checks the owner's type, not the location's. In |
6719 | case the target does not support read watchpoints, but does | |
6720 | support access watchpoints, we'll have bp_read_watchpoint | |
6721 | watchpoints with hw_access locations. Those should be considered | |
6722 | duplicates of hw_read locations. The hw_read locations will | |
6723 | become hw_access locations later. */ | |
2d134ed3 PA |
6724 | return (loc1->owner->type == loc2->owner->type |
6725 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6726 | && loc1->address == loc2->address | |
6727 | && loc1->length == loc2->length); | |
e4f237da KB |
6728 | } |
6729 | ||
31e77af2 | 6730 | /* See breakpoint.h. */ |
6c95b8df | 6731 | |
31e77af2 | 6732 | int |
accd0bcd YQ |
6733 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6734 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6735 | { |
f5656ead | 6736 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6737 | || aspace1 == aspace2) |
6738 | && addr1 == addr2); | |
6739 | } | |
6740 | ||
f1310107 TJB |
6741 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6742 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6743 | matches ASPACE2. On targets that have global breakpoints, the address | |
6744 | space doesn't really matter. */ | |
6745 | ||
6746 | static int | |
accd0bcd YQ |
6747 | breakpoint_address_match_range (const address_space *aspace1, |
6748 | CORE_ADDR addr1, | |
6749 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6750 | CORE_ADDR addr2) |
6751 | { | |
f5656ead | 6752 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6753 | || aspace1 == aspace2) |
6754 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6755 | } | |
6756 | ||
6757 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6758 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6759 | matches the breakpoint's address space. On targets that have global | |
6760 | breakpoints, the address space doesn't really matter. */ | |
6761 | ||
6762 | static int | |
6763 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6764 | const address_space *aspace, |
f1310107 TJB |
6765 | CORE_ADDR addr) |
6766 | { | |
6767 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6768 | aspace, addr) | |
6769 | || (bl->length | |
6770 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6771 | bl->address, bl->length, | |
6772 | aspace, addr))); | |
6773 | } | |
6774 | ||
d35ae833 PA |
6775 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6776 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6777 | match happens only if ASPACE matches the breakpoint's address | |
6778 | space. On targets that have global breakpoints, the address space | |
6779 | doesn't really matter. */ | |
6780 | ||
6781 | static int | |
6782 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6783 | const address_space *aspace, |
d35ae833 PA |
6784 | CORE_ADDR addr, int len) |
6785 | { | |
6786 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6787 | || bl->pspace->aspace == aspace) | |
6788 | { | |
6789 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6790 | ||
6791 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
6792 | return 1; | |
6793 | } | |
6794 | return 0; | |
6795 | } | |
6796 | ||
1e4d1764 YQ |
6797 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
6798 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
6799 | true, otherwise returns false. */ | |
6800 | ||
6801 | static int | |
6802 | tracepoint_locations_match (struct bp_location *loc1, | |
6803 | struct bp_location *loc2) | |
6804 | { | |
6805 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
6806 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
6807 | locations at the same address of different tracepoints are regarded as | |
6808 | different locations. */ | |
6809 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
6810 | else | |
6811 | return 0; | |
6812 | } | |
6813 | ||
2d134ed3 | 6814 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
cb1e4e32 PA |
6815 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
6816 | the same location. */ | |
2d134ed3 PA |
6817 | |
6818 | static int | |
4a64f543 MS |
6819 | breakpoint_locations_match (struct bp_location *loc1, |
6820 | struct bp_location *loc2) | |
2d134ed3 | 6821 | { |
2bdf28a0 JK |
6822 | int hw_point1, hw_point2; |
6823 | ||
6824 | /* Both of them must not be in moribund_locations. */ | |
6825 | gdb_assert (loc1->owner != NULL); | |
6826 | gdb_assert (loc2->owner != NULL); | |
6827 | ||
6828 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
6829 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
6830 | |
6831 | if (hw_point1 != hw_point2) | |
6832 | return 0; | |
6833 | else if (hw_point1) | |
6834 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
6835 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
6836 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 6837 | else |
f1310107 TJB |
6838 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
6839 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
6840 | loc2->pspace->aspace, loc2->address) | |
6841 | && loc1->length == loc2->length); | |
2d134ed3 PA |
6842 | } |
6843 | ||
76897487 KB |
6844 | static void |
6845 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
6846 | int bnum, int have_bnum) | |
6847 | { | |
f63fbe86 MS |
6848 | /* The longest string possibly returned by hex_string_custom |
6849 | is 50 chars. These must be at least that big for safety. */ | |
6850 | char astr1[64]; | |
6851 | char astr2[64]; | |
76897487 | 6852 | |
bb599908 PH |
6853 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
6854 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 6855 | if (have_bnum) |
8a3fe4f8 | 6856 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
6857 | bnum, astr1, astr2); |
6858 | else | |
8a3fe4f8 | 6859 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
6860 | } |
6861 | ||
4a64f543 MS |
6862 | /* Adjust a breakpoint's address to account for architectural |
6863 | constraints on breakpoint placement. Return the adjusted address. | |
6864 | Note: Very few targets require this kind of adjustment. For most | |
6865 | targets, this function is simply the identity function. */ | |
76897487 KB |
6866 | |
6867 | static CORE_ADDR | |
a6d9a66e UW |
6868 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
6869 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 6870 | { |
a0de8c21 YQ |
6871 | if (bptype == bp_watchpoint |
6872 | || bptype == bp_hardware_watchpoint | |
6873 | || bptype == bp_read_watchpoint | |
6874 | || bptype == bp_access_watchpoint | |
6875 | || bptype == bp_catchpoint) | |
88f7da05 KB |
6876 | { |
6877 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
6878 | have their addresses modified. */ | |
6879 | return bpaddr; | |
6880 | } | |
7c16b83e PA |
6881 | else if (bptype == bp_single_step) |
6882 | { | |
6883 | /* Single-step breakpoints should not have their addresses | |
6884 | modified. If there's any architectural constrain that | |
6885 | applies to this address, then it should have already been | |
6886 | taken into account when the breakpoint was created in the | |
6887 | first place. If we didn't do this, stepping through e.g., | |
6888 | Thumb-2 IT blocks would break. */ | |
6889 | return bpaddr; | |
6890 | } | |
76897487 KB |
6891 | else |
6892 | { | |
a0de8c21 YQ |
6893 | CORE_ADDR adjusted_bpaddr = bpaddr; |
6894 | ||
6895 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
6896 | { | |
6897 | /* Some targets have architectural constraints on the placement | |
6898 | of breakpoint instructions. Obtain the adjusted address. */ | |
6899 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
6900 | } | |
76897487 | 6901 | |
a0de8c21 | 6902 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
6903 | |
6904 | /* An adjusted breakpoint address can significantly alter | |
6905 | a user's expectations. Print a warning if an adjustment | |
6906 | is required. */ | |
6907 | if (adjusted_bpaddr != bpaddr) | |
6908 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
6909 | ||
6910 | return adjusted_bpaddr; | |
6911 | } | |
6912 | } | |
6913 | ||
cb1e4e32 PA |
6914 | static bp_loc_type |
6915 | bp_location_from_bp_type (bptype type) | |
7cc221ef | 6916 | { |
cb1e4e32 | 6917 | switch (type) |
e049a4b5 DJ |
6918 | { |
6919 | case bp_breakpoint: | |
7c16b83e | 6920 | case bp_single_step: |
e049a4b5 DJ |
6921 | case bp_until: |
6922 | case bp_finish: | |
6923 | case bp_longjmp: | |
6924 | case bp_longjmp_resume: | |
e2e4d78b | 6925 | case bp_longjmp_call_dummy: |
186c406b TT |
6926 | case bp_exception: |
6927 | case bp_exception_resume: | |
e049a4b5 | 6928 | case bp_step_resume: |
2c03e5be | 6929 | case bp_hp_step_resume: |
e049a4b5 DJ |
6930 | case bp_watchpoint_scope: |
6931 | case bp_call_dummy: | |
aa7d318d | 6932 | case bp_std_terminate: |
e049a4b5 DJ |
6933 | case bp_shlib_event: |
6934 | case bp_thread_event: | |
6935 | case bp_overlay_event: | |
4efc6507 | 6936 | case bp_jit_event: |
0fd8e87f | 6937 | case bp_longjmp_master: |
aa7d318d | 6938 | case bp_std_terminate_master: |
186c406b | 6939 | case bp_exception_master: |
0e30163f JK |
6940 | case bp_gnu_ifunc_resolver: |
6941 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 6942 | case bp_dprintf: |
cb1e4e32 | 6943 | return bp_loc_software_breakpoint; |
e049a4b5 | 6944 | case bp_hardware_breakpoint: |
cb1e4e32 | 6945 | return bp_loc_hardware_breakpoint; |
e049a4b5 DJ |
6946 | case bp_hardware_watchpoint: |
6947 | case bp_read_watchpoint: | |
6948 | case bp_access_watchpoint: | |
cb1e4e32 | 6949 | return bp_loc_hardware_watchpoint; |
e049a4b5 | 6950 | case bp_watchpoint: |
ce78b96d | 6951 | case bp_catchpoint: |
15c3d785 PA |
6952 | case bp_tracepoint: |
6953 | case bp_fast_tracepoint: | |
0fb4aa4b | 6954 | case bp_static_tracepoint: |
cb1e4e32 | 6955 | return bp_loc_other; |
e049a4b5 | 6956 | default: |
e2e0b3e5 | 6957 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 | 6958 | } |
cb1e4e32 PA |
6959 | } |
6960 | ||
6961 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) | |
6962 | { | |
6963 | this->owner = owner; | |
6964 | this->cond_bytecode = NULL; | |
6965 | this->shlib_disabled = 0; | |
6966 | this->enabled = 1; | |
6967 | ||
6968 | this->loc_type = type; | |
e049a4b5 | 6969 | |
cb1e4e32 PA |
6970 | if (this->loc_type == bp_loc_software_breakpoint |
6971 | || this->loc_type == bp_loc_hardware_breakpoint) | |
6972 | mark_breakpoint_location_modified (this); | |
6973 | ||
6974 | this->refc = 1; | |
6975 | } | |
6976 | ||
6977 | bp_location::bp_location (breakpoint *owner) | |
6978 | : bp_location::bp_location (owner, | |
6979 | bp_location_from_bp_type (owner->type)) | |
6980 | { | |
28010a5d PA |
6981 | } |
6982 | ||
6983 | /* Allocate a struct bp_location. */ | |
6984 | ||
6985 | static struct bp_location * | |
6986 | allocate_bp_location (struct breakpoint *bpt) | |
6987 | { | |
348d480f PA |
6988 | return bpt->ops->allocate_location (bpt); |
6989 | } | |
7cc221ef | 6990 | |
f431efe5 PA |
6991 | static void |
6992 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 6993 | { |
4d01a485 | 6994 | delete loc; |
fe3f5fa8 VP |
6995 | } |
6996 | ||
f431efe5 PA |
6997 | /* Increment reference count. */ |
6998 | ||
6999 | static void | |
7000 | incref_bp_location (struct bp_location *bl) | |
7001 | { | |
7002 | ++bl->refc; | |
7003 | } | |
7004 | ||
7005 | /* Decrement reference count. If the reference count reaches 0, | |
7006 | destroy the bp_location. Sets *BLP to NULL. */ | |
7007 | ||
7008 | static void | |
7009 | decref_bp_location (struct bp_location **blp) | |
7010 | { | |
0807b50c PA |
7011 | gdb_assert ((*blp)->refc > 0); |
7012 | ||
f431efe5 PA |
7013 | if (--(*blp)->refc == 0) |
7014 | free_bp_location (*blp); | |
7015 | *blp = NULL; | |
7016 | } | |
7017 | ||
346774a9 | 7018 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7019 | |
b270e6f9 TT |
7020 | static breakpoint * |
7021 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7022 | { |
346774a9 | 7023 | struct breakpoint *b1; |
b270e6f9 | 7024 | struct breakpoint *result = b.get (); |
c906108c | 7025 | |
346774a9 PA |
7026 | /* Add this breakpoint to the end of the chain so that a list of |
7027 | breakpoints will come out in order of increasing numbers. */ | |
7028 | ||
7029 | b1 = breakpoint_chain; | |
7030 | if (b1 == 0) | |
b270e6f9 | 7031 | breakpoint_chain = b.release (); |
346774a9 PA |
7032 | else |
7033 | { | |
7034 | while (b1->next) | |
7035 | b1 = b1->next; | |
b270e6f9 | 7036 | b1->next = b.release (); |
346774a9 | 7037 | } |
b270e6f9 TT |
7038 | |
7039 | return result; | |
346774a9 PA |
7040 | } |
7041 | ||
7042 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7043 | ||
7044 | static void | |
7045 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7046 | struct gdbarch *gdbarch, | |
28010a5d | 7047 | enum bptype bptype, |
c0a91b2b | 7048 | const struct breakpoint_ops *ops) |
346774a9 | 7049 | { |
348d480f PA |
7050 | gdb_assert (ops != NULL); |
7051 | ||
28010a5d | 7052 | b->ops = ops; |
4d28f7a8 | 7053 | b->type = bptype; |
a6d9a66e | 7054 | b->gdbarch = gdbarch; |
c906108c SS |
7055 | b->language = current_language->la_language; |
7056 | b->input_radix = input_radix; | |
d0fb5eae | 7057 | b->related_breakpoint = b; |
346774a9 PA |
7058 | } |
7059 | ||
7060 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7061 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7062 | |
7063 | static struct breakpoint * | |
7064 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7065 | enum bptype bptype, |
c0a91b2b | 7066 | const struct breakpoint_ops *ops) |
346774a9 | 7067 | { |
3b0871f4 | 7068 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7069 | |
3b0871f4 | 7070 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7071 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7072 | } |
7073 | ||
0ba852ab | 7074 | /* Initialize loc->function_name. */ |
0e30163f | 7075 | |
0d381245 | 7076 | static void |
0ba852ab | 7077 | set_breakpoint_location_function (struct bp_location *loc) |
0d381245 | 7078 | { |
2bdf28a0 JK |
7079 | gdb_assert (loc->owner != NULL); |
7080 | ||
0d381245 | 7081 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7082 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7083 | || is_tracepoint (loc->owner)) |
0d381245 | 7084 | { |
2c02bd72 | 7085 | const char *function_name; |
0e30163f | 7086 | |
3467ec66 | 7087 | if (loc->msymbol != NULL |
f50776aa | 7088 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
0ba852ab | 7089 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
0e30163f JK |
7090 | { |
7091 | struct breakpoint *b = loc->owner; | |
7092 | ||
c9d95fa3 | 7093 | function_name = loc->msymbol->linkage_name (); |
3467ec66 PA |
7094 | |
7095 | if (b->type == bp_breakpoint && b->loc == loc | |
7096 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7097 | { |
7098 | /* Create only the whole new breakpoint of this type but do not | |
7099 | mess more complicated breakpoints with multiple locations. */ | |
7100 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7101 | /* Remember the resolver's address for use by the return |
7102 | breakpoint. */ | |
3467ec66 | 7103 | loc->related_address = loc->address; |
0e30163f JK |
7104 | } |
7105 | } | |
3467ec66 PA |
7106 | else |
7107 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7108 | |
2c02bd72 DE |
7109 | if (function_name) |
7110 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7111 | } |
7112 | } | |
7113 | ||
a6d9a66e | 7114 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7115 | struct gdbarch * |
a6d9a66e UW |
7116 | get_sal_arch (struct symtab_and_line sal) |
7117 | { | |
7118 | if (sal.section) | |
7119 | return get_objfile_arch (sal.section->objfile); | |
7120 | if (sal.symtab) | |
eb822aa6 | 7121 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7122 | |
7123 | return NULL; | |
7124 | } | |
7125 | ||
346774a9 PA |
7126 | /* Low level routine for partially initializing a breakpoint of type |
7127 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7128 | file name, and line number are provided by SAL. |
0d381245 VP |
7129 | |
7130 | It is expected that the caller will complete the initialization of | |
7131 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7132 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7133 | |
346774a9 PA |
7134 | static void |
7135 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7136 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7137 | const struct breakpoint_ops *ops) |
0d381245 | 7138 | { |
28010a5d | 7139 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7140 | |
3742cc8b | 7141 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7142 | |
6c95b8df PA |
7143 | if (bptype != bp_catchpoint) |
7144 | gdb_assert (sal.pspace != NULL); | |
7145 | ||
f8eba3c6 TT |
7146 | /* Store the program space that was used to set the breakpoint, |
7147 | except for ordinary breakpoints, which are independent of the | |
7148 | program space. */ | |
7149 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7150 | b->pspace = sal.pspace; | |
346774a9 | 7151 | } |
c906108c | 7152 | |
346774a9 PA |
7153 | /* set_raw_breakpoint is a low level routine for allocating and |
7154 | partially initializing a breakpoint of type BPTYPE. The newly | |
7155 | created breakpoint's address, section, source file name, and line | |
7156 | number are provided by SAL. The newly created and partially | |
7157 | initialized breakpoint is added to the breakpoint chain and | |
7158 | is also returned as the value of this function. | |
7159 | ||
7160 | It is expected that the caller will complete the initialization of | |
7161 | the newly created breakpoint struct as well as output any status | |
7162 | information regarding the creation of a new breakpoint. In | |
7163 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7164 | number! Care should be taken to not allow an error to occur | |
7165 | prior to completing the initialization of the breakpoint. If this | |
7166 | should happen, a bogus breakpoint will be left on the chain. */ | |
7167 | ||
7168 | struct breakpoint * | |
7169 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7170 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7171 | const struct breakpoint_ops *ops) |
346774a9 | 7172 | { |
3b0871f4 | 7173 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7174 | |
3b0871f4 | 7175 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7176 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7177 | } |
7178 | ||
53a5351d | 7179 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7180 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7181 | initiated the operation. */ | |
c906108c SS |
7182 | |
7183 | void | |
186c406b | 7184 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7185 | { |
35df4500 | 7186 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7187 | int thread = tp->global_num; |
0fd8e87f UW |
7188 | |
7189 | /* To avoid having to rescan all objfile symbols at every step, | |
7190 | we maintain a list of continually-inserted but always disabled | |
7191 | longjmp "master" breakpoints. Here, we simply create momentary | |
7192 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7193 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7194 | if (b->pspace == current_program_space |
186c406b TT |
7195 | && (b->type == bp_longjmp_master |
7196 | || b->type == bp_exception_master)) | |
0fd8e87f | 7197 | { |
06edf0c0 PA |
7198 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7199 | struct breakpoint *clone; | |
cc59ec59 | 7200 | |
e2e4d78b JK |
7201 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7202 | after their removal. */ | |
06edf0c0 | 7203 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7204 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7205 | clone->thread = thread; |
7206 | } | |
186c406b TT |
7207 | |
7208 | tp->initiating_frame = frame; | |
c906108c SS |
7209 | } |
7210 | ||
611c83ae | 7211 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7212 | void |
611c83ae | 7213 | delete_longjmp_breakpoint (int thread) |
c906108c | 7214 | { |
35df4500 | 7215 | struct breakpoint *b, *b_tmp; |
c906108c | 7216 | |
35df4500 | 7217 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7218 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7219 | { |
7220 | if (b->thread == thread) | |
7221 | delete_breakpoint (b); | |
7222 | } | |
c906108c SS |
7223 | } |
7224 | ||
f59f708a PA |
7225 | void |
7226 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7227 | { | |
7228 | struct breakpoint *b, *b_tmp; | |
7229 | ||
7230 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7231 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7232 | { | |
7233 | if (b->thread == thread) | |
7234 | b->disposition = disp_del_at_next_stop; | |
7235 | } | |
7236 | } | |
7237 | ||
e2e4d78b JK |
7238 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7239 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7240 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7241 | breakpoints. */ | |
7242 | ||
7243 | struct breakpoint * | |
7244 | set_longjmp_breakpoint_for_call_dummy (void) | |
7245 | { | |
7246 | struct breakpoint *b, *retval = NULL; | |
7247 | ||
7248 | ALL_BREAKPOINTS (b) | |
7249 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7250 | { | |
7251 | struct breakpoint *new_b; | |
7252 | ||
7253 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7254 | &momentary_breakpoint_ops, |
7255 | 1); | |
00431a78 | 7256 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7257 | |
7258 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7259 | ||
7260 | gdb_assert (new_b->related_breakpoint == new_b); | |
7261 | if (retval == NULL) | |
7262 | retval = new_b; | |
7263 | new_b->related_breakpoint = retval; | |
7264 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7265 | retval = retval->related_breakpoint; | |
7266 | retval->related_breakpoint = new_b; | |
7267 | } | |
7268 | ||
7269 | return retval; | |
7270 | } | |
7271 | ||
7272 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7273 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7274 | stack. |
7275 | ||
7276 | You should call this function only at places where it is safe to currently | |
7277 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7278 | frames. */ | |
7279 | ||
7280 | void | |
b67a2c6f | 7281 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7282 | { |
7283 | struct breakpoint *b, *b_tmp; | |
7284 | ||
7285 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7286 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7287 | { |
7288 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7289 | ||
7290 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7291 | dummy_b = dummy_b->related_breakpoint; | |
7292 | if (dummy_b->type != bp_call_dummy | |
7293 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7294 | continue; | |
7295 | ||
00431a78 | 7296 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7297 | |
7298 | while (b->related_breakpoint != b) | |
7299 | { | |
7300 | if (b_tmp == b->related_breakpoint) | |
7301 | b_tmp = b->related_breakpoint->next; | |
7302 | delete_breakpoint (b->related_breakpoint); | |
7303 | } | |
7304 | delete_breakpoint (b); | |
7305 | } | |
7306 | } | |
7307 | ||
1900040c MS |
7308 | void |
7309 | enable_overlay_breakpoints (void) | |
7310 | { | |
52f0bd74 | 7311 | struct breakpoint *b; |
1900040c MS |
7312 | |
7313 | ALL_BREAKPOINTS (b) | |
7314 | if (b->type == bp_overlay_event) | |
7315 | { | |
7316 | b->enable_state = bp_enabled; | |
44702360 | 7317 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7318 | overlay_events_enabled = 1; |
1900040c MS |
7319 | } |
7320 | } | |
7321 | ||
7322 | void | |
7323 | disable_overlay_breakpoints (void) | |
7324 | { | |
52f0bd74 | 7325 | struct breakpoint *b; |
1900040c MS |
7326 | |
7327 | ALL_BREAKPOINTS (b) | |
7328 | if (b->type == bp_overlay_event) | |
7329 | { | |
7330 | b->enable_state = bp_disabled; | |
44702360 | 7331 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7332 | overlay_events_enabled = 0; |
1900040c MS |
7333 | } |
7334 | } | |
7335 | ||
aa7d318d TT |
7336 | /* Set an active std::terminate breakpoint for each std::terminate |
7337 | master breakpoint. */ | |
7338 | void | |
7339 | set_std_terminate_breakpoint (void) | |
7340 | { | |
35df4500 | 7341 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7342 | |
35df4500 | 7343 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7344 | if (b->pspace == current_program_space |
7345 | && b->type == bp_std_terminate_master) | |
7346 | { | |
06edf0c0 | 7347 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7348 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7349 | } |
7350 | } | |
7351 | ||
7352 | /* Delete all the std::terminate breakpoints. */ | |
7353 | void | |
7354 | delete_std_terminate_breakpoint (void) | |
7355 | { | |
35df4500 | 7356 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7357 | |
35df4500 | 7358 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7359 | if (b->type == bp_std_terminate) |
7360 | delete_breakpoint (b); | |
7361 | } | |
7362 | ||
c4093a6a | 7363 | struct breakpoint * |
a6d9a66e | 7364 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7365 | { |
7366 | struct breakpoint *b; | |
c4093a6a | 7367 | |
06edf0c0 PA |
7368 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7369 | &internal_breakpoint_ops); | |
7370 | ||
b5de0fa7 | 7371 | b->enable_state = bp_enabled; |
f00aae0f | 7372 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7373 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7374 | |
44702360 | 7375 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7376 | |
c4093a6a JM |
7377 | return b; |
7378 | } | |
7379 | ||
0101ce28 JJ |
7380 | struct lang_and_radix |
7381 | { | |
7382 | enum language lang; | |
7383 | int radix; | |
7384 | }; | |
7385 | ||
4efc6507 DE |
7386 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7387 | ||
7388 | struct breakpoint * | |
7389 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7390 | { | |
2a7f3dff PA |
7391 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7392 | &internal_breakpoint_ops); | |
4efc6507 | 7393 | } |
0101ce28 | 7394 | |
03673fc7 PP |
7395 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7396 | ||
7397 | void | |
7398 | remove_jit_event_breakpoints (void) | |
7399 | { | |
7400 | struct breakpoint *b, *b_tmp; | |
7401 | ||
7402 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7403 | if (b->type == bp_jit_event | |
7404 | && b->loc->pspace == current_program_space) | |
7405 | delete_breakpoint (b); | |
7406 | } | |
7407 | ||
cae688ec JJ |
7408 | void |
7409 | remove_solib_event_breakpoints (void) | |
7410 | { | |
35df4500 | 7411 | struct breakpoint *b, *b_tmp; |
cae688ec | 7412 | |
35df4500 | 7413 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7414 | if (b->type == bp_shlib_event |
7415 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7416 | delete_breakpoint (b); |
7417 | } | |
7418 | ||
f37f681c PA |
7419 | /* See breakpoint.h. */ |
7420 | ||
7421 | void | |
7422 | remove_solib_event_breakpoints_at_next_stop (void) | |
7423 | { | |
7424 | struct breakpoint *b, *b_tmp; | |
7425 | ||
7426 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7427 | if (b->type == bp_shlib_event | |
7428 | && b->loc->pspace == current_program_space) | |
7429 | b->disposition = disp_del_at_next_stop; | |
7430 | } | |
7431 | ||
04086b45 PA |
7432 | /* Helper for create_solib_event_breakpoint / |
7433 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7434 | INSERT_MODE to pass through to update_global_location_list. */ | |
7435 | ||
7436 | static struct breakpoint * | |
7437 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7438 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7439 | { |
7440 | struct breakpoint *b; | |
7441 | ||
06edf0c0 PA |
7442 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7443 | &internal_breakpoint_ops); | |
04086b45 | 7444 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7445 | return b; |
7446 | } | |
7447 | ||
04086b45 PA |
7448 | struct breakpoint * |
7449 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7450 | { | |
7451 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7452 | } | |
7453 | ||
f37f681c PA |
7454 | /* See breakpoint.h. */ |
7455 | ||
7456 | struct breakpoint * | |
7457 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7458 | { | |
7459 | struct breakpoint *b; | |
7460 | ||
04086b45 PA |
7461 | /* Explicitly tell update_global_location_list to insert |
7462 | locations. */ | |
7463 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7464 | if (!b->loc->inserted) |
7465 | { | |
7466 | delete_breakpoint (b); | |
7467 | return NULL; | |
7468 | } | |
7469 | return b; | |
7470 | } | |
7471 | ||
cae688ec JJ |
7472 | /* Disable any breakpoints that are on code in shared libraries. Only |
7473 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7474 | ||
7475 | void | |
cb851954 | 7476 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7477 | { |
876fa593 | 7478 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7479 | |
876fa593 | 7480 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7481 | { |
2bdf28a0 | 7482 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7483 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7484 | |
4a64f543 MS |
7485 | /* We apply the check to all breakpoints, including disabled for |
7486 | those with loc->duplicate set. This is so that when breakpoint | |
7487 | becomes enabled, or the duplicate is removed, gdb will try to | |
7488 | insert all breakpoints. If we don't set shlib_disabled here, | |
7489 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7490 | if (((b->type == bp_breakpoint) |
508ccb1f | 7491 | || (b->type == bp_jit_event) |
1042e4c0 | 7492 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7493 | || (is_tracepoint (b))) |
6c95b8df | 7494 | && loc->pspace == current_program_space |
0d381245 | 7495 | && !loc->shlib_disabled |
6c95b8df | 7496 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7497 | ) |
0d381245 VP |
7498 | { |
7499 | loc->shlib_disabled = 1; | |
7500 | } | |
cae688ec JJ |
7501 | } |
7502 | } | |
7503 | ||
63644780 NB |
7504 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7505 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7506 | disabled ones can just stay disabled. */ | |
84acb35a | 7507 | |
75149521 | 7508 | static void |
84acb35a JJ |
7509 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7510 | { | |
876fa593 | 7511 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7512 | int disabled_shlib_breaks = 0; |
7513 | ||
876fa593 | 7514 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7515 | { |
2bdf28a0 | 7516 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7517 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7518 | |
1e4d1764 | 7519 | if (solib->pspace == loc->pspace |
e2dd7057 | 7520 | && !loc->shlib_disabled |
1e4d1764 YQ |
7521 | && (((b->type == bp_breakpoint |
7522 | || b->type == bp_jit_event | |
7523 | || b->type == bp_hardware_breakpoint) | |
7524 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7525 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7526 | || is_tracepoint (b)) | |
e2dd7057 | 7527 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7528 | { |
e2dd7057 PP |
7529 | loc->shlib_disabled = 1; |
7530 | /* At this point, we cannot rely on remove_breakpoint | |
7531 | succeeding so we must mark the breakpoint as not inserted | |
7532 | to prevent future errors occurring in remove_breakpoints. */ | |
7533 | loc->inserted = 0; | |
8d3788bd VP |
7534 | |
7535 | /* This may cause duplicate notifications for the same breakpoint. */ | |
76727919 | 7536 | gdb::observers::breakpoint_modified.notify (b); |
8d3788bd | 7537 | |
e2dd7057 PP |
7538 | if (!disabled_shlib_breaks) |
7539 | { | |
223ffa71 | 7540 | target_terminal::ours_for_output (); |
3e43a32a MS |
7541 | warning (_("Temporarily disabling breakpoints " |
7542 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7543 | solib->so_name); |
84acb35a | 7544 | } |
e2dd7057 | 7545 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7546 | } |
7547 | } | |
84acb35a JJ |
7548 | } |
7549 | ||
63644780 NB |
7550 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7551 | notification of free_objfile. Only apply to enabled breakpoints, | |
7552 | disabled ones can just stay disabled. */ | |
7553 | ||
7554 | static void | |
7555 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7556 | { | |
7557 | struct breakpoint *b; | |
7558 | ||
7559 | if (objfile == NULL) | |
7560 | return; | |
7561 | ||
d03de421 PA |
7562 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7563 | managed by the user with add-symbol-file/remove-symbol-file. | |
7564 | Similarly to how breakpoints in shared libraries are handled in | |
7565 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7566 | shlib_disabled so they end up uninserted on the next global |
7567 | location list update. Shared libraries not loaded by the user | |
7568 | aren't handled here -- they're already handled in | |
7569 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7570 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7571 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7572 | main objfile). */ | |
7573 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7574 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7575 | return; |
7576 | ||
7577 | ALL_BREAKPOINTS (b) | |
7578 | { | |
7579 | struct bp_location *loc; | |
7580 | int bp_modified = 0; | |
7581 | ||
7582 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7583 | continue; | |
7584 | ||
7585 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7586 | { | |
7587 | CORE_ADDR loc_addr = loc->address; | |
7588 | ||
7589 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7590 | && loc->loc_type != bp_loc_software_breakpoint) | |
7591 | continue; | |
7592 | ||
7593 | if (loc->shlib_disabled != 0) | |
7594 | continue; | |
7595 | ||
7596 | if (objfile->pspace != loc->pspace) | |
7597 | continue; | |
7598 | ||
7599 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7600 | && loc->loc_type != bp_loc_software_breakpoint) | |
7601 | continue; | |
7602 | ||
7603 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7604 | { | |
7605 | loc->shlib_disabled = 1; | |
08351840 PA |
7606 | /* At this point, we don't know whether the object was |
7607 | unmapped from the inferior or not, so leave the | |
7608 | inserted flag alone. We'll handle failure to | |
7609 | uninsert quietly, in case the object was indeed | |
7610 | unmapped. */ | |
63644780 NB |
7611 | |
7612 | mark_breakpoint_location_modified (loc); | |
7613 | ||
7614 | bp_modified = 1; | |
7615 | } | |
7616 | } | |
7617 | ||
7618 | if (bp_modified) | |
76727919 | 7619 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7620 | } |
7621 | } | |
7622 | ||
ce78b96d JB |
7623 | /* FORK & VFORK catchpoints. */ |
7624 | ||
e29a4733 | 7625 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7626 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7627 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7628 | |
c1fc2657 | 7629 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7630 | { |
e29a4733 PA |
7631 | /* Process id of a child process whose forking triggered this |
7632 | catchpoint. This field is only valid immediately after this | |
7633 | catchpoint has triggered. */ | |
7634 | ptid_t forked_inferior_pid; | |
7635 | }; | |
7636 | ||
4a64f543 MS |
7637 | /* Implement the "insert" breakpoint_ops method for fork |
7638 | catchpoints. */ | |
ce78b96d | 7639 | |
77b06cd7 TJB |
7640 | static int |
7641 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7642 | { |
e99b03dc | 7643 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7644 | } |
7645 | ||
4a64f543 MS |
7646 | /* Implement the "remove" breakpoint_ops method for fork |
7647 | catchpoints. */ | |
ce78b96d JB |
7648 | |
7649 | static int | |
73971819 | 7650 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7651 | { |
e99b03dc | 7652 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7653 | } |
7654 | ||
7655 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7656 | catchpoints. */ | |
7657 | ||
7658 | static int | |
f1310107 | 7659 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
bd522513 | 7660 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7661 | const struct target_waitstatus *ws) |
ce78b96d | 7662 | { |
e29a4733 PA |
7663 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7664 | ||
f90263c1 TT |
7665 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7666 | return 0; | |
7667 | ||
7668 | c->forked_inferior_pid = ws->value.related_pid; | |
7669 | return 1; | |
ce78b96d JB |
7670 | } |
7671 | ||
4a64f543 MS |
7672 | /* Implement the "print_it" breakpoint_ops method for fork |
7673 | catchpoints. */ | |
ce78b96d JB |
7674 | |
7675 | static enum print_stop_action | |
348d480f | 7676 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7677 | { |
36dfb11c | 7678 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7679 | struct breakpoint *b = bs->breakpoint_at; |
7680 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7681 | |
ce78b96d | 7682 | annotate_catchpoint (b->number); |
f303dbd6 | 7683 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7684 | if (b->disposition == disp_del) |
112e8700 | 7685 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7686 | else |
112e8700 SM |
7687 | uiout->text ("Catchpoint "); |
7688 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7689 | { |
112e8700 SM |
7690 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7691 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7692 | } |
381befee | 7693 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7694 | uiout->text (" (forked process "); |
381befee | 7695 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7696 | uiout->text ("), "); |
ce78b96d JB |
7697 | return PRINT_SRC_AND_LOC; |
7698 | } | |
7699 | ||
4a64f543 MS |
7700 | /* Implement the "print_one" breakpoint_ops method for fork |
7701 | catchpoints. */ | |
ce78b96d JB |
7702 | |
7703 | static void | |
a6d9a66e | 7704 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7705 | { |
e29a4733 | 7706 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7707 | struct value_print_options opts; |
79a45e25 | 7708 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7709 | |
7710 | get_user_print_options (&opts); | |
7711 | ||
4a64f543 MS |
7712 | /* Field 4, the address, is omitted (which makes the columns not |
7713 | line up too nicely with the headers, but the effect is relatively | |
7714 | readable). */ | |
79a45b7d | 7715 | if (opts.addressprint) |
112e8700 | 7716 | uiout->field_skip ("addr"); |
ce78b96d | 7717 | annotate_field (5); |
112e8700 | 7718 | uiout->text ("fork"); |
d7e15655 | 7719 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7720 | { |
112e8700 | 7721 | uiout->text (", process "); |
381befee | 7722 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7723 | uiout->spaces (1); |
ce78b96d | 7724 | } |
8ac3646f | 7725 | |
112e8700 SM |
7726 | if (uiout->is_mi_like_p ()) |
7727 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
7728 | } |
7729 | ||
7730 | /* Implement the "print_mention" breakpoint_ops method for fork | |
7731 | catchpoints. */ | |
7732 | ||
7733 | static void | |
7734 | print_mention_catch_fork (struct breakpoint *b) | |
7735 | { | |
7736 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
7737 | } | |
7738 | ||
6149aea9 PA |
7739 | /* Implement the "print_recreate" breakpoint_ops method for fork |
7740 | catchpoints. */ | |
7741 | ||
7742 | static void | |
7743 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
7744 | { | |
7745 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 7746 | print_recreate_thread (b, fp); |
6149aea9 PA |
7747 | } |
7748 | ||
ce78b96d JB |
7749 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
7750 | ||
2060206e | 7751 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 7752 | |
4a64f543 MS |
7753 | /* Implement the "insert" breakpoint_ops method for vfork |
7754 | catchpoints. */ | |
ce78b96d | 7755 | |
77b06cd7 TJB |
7756 | static int |
7757 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 7758 | { |
e99b03dc | 7759 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7760 | } |
7761 | ||
4a64f543 MS |
7762 | /* Implement the "remove" breakpoint_ops method for vfork |
7763 | catchpoints. */ | |
ce78b96d JB |
7764 | |
7765 | static int | |
73971819 | 7766 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7767 | { |
e99b03dc | 7768 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
ce78b96d JB |
7769 | } |
7770 | ||
7771 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
7772 | catchpoints. */ | |
7773 | ||
7774 | static int | |
f1310107 | 7775 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
bd522513 | 7776 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 7777 | const struct target_waitstatus *ws) |
ce78b96d | 7778 | { |
e29a4733 PA |
7779 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7780 | ||
f90263c1 TT |
7781 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
7782 | return 0; | |
7783 | ||
7784 | c->forked_inferior_pid = ws->value.related_pid; | |
7785 | return 1; | |
ce78b96d JB |
7786 | } |
7787 | ||
4a64f543 MS |
7788 | /* Implement the "print_it" breakpoint_ops method for vfork |
7789 | catchpoints. */ | |
ce78b96d JB |
7790 | |
7791 | static enum print_stop_action | |
348d480f | 7792 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 7793 | { |
36dfb11c | 7794 | struct ui_out *uiout = current_uiout; |
348d480f | 7795 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
7796 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
7797 | ||
ce78b96d | 7798 | annotate_catchpoint (b->number); |
f303dbd6 | 7799 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7800 | if (b->disposition == disp_del) |
112e8700 | 7801 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7802 | else |
112e8700 SM |
7803 | uiout->text ("Catchpoint "); |
7804 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7805 | { |
112e8700 SM |
7806 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
7807 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7808 | } |
381befee | 7809 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 7810 | uiout->text (" (vforked process "); |
381befee | 7811 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
112e8700 | 7812 | uiout->text ("), "); |
ce78b96d JB |
7813 | return PRINT_SRC_AND_LOC; |
7814 | } | |
7815 | ||
4a64f543 MS |
7816 | /* Implement the "print_one" breakpoint_ops method for vfork |
7817 | catchpoints. */ | |
ce78b96d JB |
7818 | |
7819 | static void | |
a6d9a66e | 7820 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7821 | { |
e29a4733 | 7822 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7823 | struct value_print_options opts; |
79a45e25 | 7824 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7825 | |
7826 | get_user_print_options (&opts); | |
4a64f543 MS |
7827 | /* Field 4, the address, is omitted (which makes the columns not |
7828 | line up too nicely with the headers, but the effect is relatively | |
7829 | readable). */ | |
79a45b7d | 7830 | if (opts.addressprint) |
112e8700 | 7831 | uiout->field_skip ("addr"); |
ce78b96d | 7832 | annotate_field (5); |
112e8700 | 7833 | uiout->text ("vfork"); |
d7e15655 | 7834 | if (c->forked_inferior_pid != null_ptid) |
ce78b96d | 7835 | { |
112e8700 | 7836 | uiout->text (", process "); |
381befee | 7837 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
112e8700 | 7838 | uiout->spaces (1); |
ce78b96d | 7839 | } |
8ac3646f | 7840 | |
112e8700 SM |
7841 | if (uiout->is_mi_like_p ()) |
7842 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
7843 | } |
7844 | ||
7845 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
7846 | catchpoints. */ | |
7847 | ||
7848 | static void | |
7849 | print_mention_catch_vfork (struct breakpoint *b) | |
7850 | { | |
7851 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
7852 | } | |
7853 | ||
6149aea9 PA |
7854 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
7855 | catchpoints. */ | |
7856 | ||
7857 | static void | |
7858 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
7859 | { | |
7860 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 7861 | print_recreate_thread (b, fp); |
6149aea9 PA |
7862 | } |
7863 | ||
ce78b96d JB |
7864 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
7865 | ||
2060206e | 7866 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 7867 | |
edcc5120 | 7868 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 7869 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
7870 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
7871 | ||
c1fc2657 | 7872 | struct solib_catchpoint : public breakpoint |
edcc5120 | 7873 | { |
c1fc2657 | 7874 | ~solib_catchpoint () override; |
edcc5120 TT |
7875 | |
7876 | /* True for "catch load", false for "catch unload". */ | |
7877 | unsigned char is_load; | |
7878 | ||
7879 | /* Regular expression to match, if any. COMPILED is only valid when | |
7880 | REGEX is non-NULL. */ | |
7881 | char *regex; | |
2d7cc5c7 | 7882 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
7883 | }; |
7884 | ||
c1fc2657 | 7885 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 7886 | { |
c1fc2657 | 7887 | xfree (this->regex); |
edcc5120 TT |
7888 | } |
7889 | ||
7890 | static int | |
7891 | insert_catch_solib (struct bp_location *ignore) | |
7892 | { | |
7893 | return 0; | |
7894 | } | |
7895 | ||
7896 | static int | |
73971819 | 7897 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
7898 | { |
7899 | return 0; | |
7900 | } | |
7901 | ||
7902 | static int | |
7903 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
bd522513 | 7904 | const address_space *aspace, |
edcc5120 TT |
7905 | CORE_ADDR bp_addr, |
7906 | const struct target_waitstatus *ws) | |
7907 | { | |
7908 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
7909 | struct breakpoint *other; | |
7910 | ||
7911 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
7912 | return 1; | |
7913 | ||
7914 | ALL_BREAKPOINTS (other) | |
7915 | { | |
7916 | struct bp_location *other_bl; | |
7917 | ||
7918 | if (other == bl->owner) | |
7919 | continue; | |
7920 | ||
7921 | if (other->type != bp_shlib_event) | |
7922 | continue; | |
7923 | ||
c1fc2657 | 7924 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
7925 | continue; |
7926 | ||
7927 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
7928 | { | |
7929 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
7930 | return 1; | |
7931 | } | |
7932 | } | |
7933 | ||
7934 | return 0; | |
7935 | } | |
7936 | ||
7937 | static void | |
7938 | check_status_catch_solib (struct bpstats *bs) | |
7939 | { | |
7940 | struct solib_catchpoint *self | |
7941 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
edcc5120 TT |
7942 | |
7943 | if (self->is_load) | |
7944 | { | |
52941706 | 7945 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 TT |
7946 | { |
7947 | if (!self->regex | |
2d7cc5c7 | 7948 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
7949 | return; |
7950 | } | |
7951 | } | |
7952 | else | |
7953 | { | |
6fb16ce6 | 7954 | for (const std::string &iter : current_program_space->deleted_solibs) |
edcc5120 TT |
7955 | { |
7956 | if (!self->regex | |
6fb16ce6 | 7957 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
edcc5120 TT |
7958 | return; |
7959 | } | |
7960 | } | |
7961 | ||
7962 | bs->stop = 0; | |
7963 | bs->print_it = print_it_noop; | |
7964 | } | |
7965 | ||
7966 | static enum print_stop_action | |
7967 | print_it_catch_solib (bpstat bs) | |
7968 | { | |
7969 | struct breakpoint *b = bs->breakpoint_at; | |
7970 | struct ui_out *uiout = current_uiout; | |
7971 | ||
7972 | annotate_catchpoint (b->number); | |
f303dbd6 | 7973 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 7974 | if (b->disposition == disp_del) |
112e8700 | 7975 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 7976 | else |
112e8700 | 7977 | uiout->text ("Catchpoint "); |
381befee | 7978 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
7979 | uiout->text ("\n"); |
7980 | if (uiout->is_mi_like_p ()) | |
7981 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
7982 | print_solib_event (1); |
7983 | return PRINT_SRC_AND_LOC; | |
7984 | } | |
7985 | ||
7986 | static void | |
7987 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
7988 | { | |
7989 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
7990 | struct value_print_options opts; | |
7991 | struct ui_out *uiout = current_uiout; | |
edcc5120 TT |
7992 | |
7993 | get_user_print_options (&opts); | |
7994 | /* Field 4, the address, is omitted (which makes the columns not | |
7995 | line up too nicely with the headers, but the effect is relatively | |
7996 | readable). */ | |
7997 | if (opts.addressprint) | |
7998 | { | |
7999 | annotate_field (4); | |
112e8700 | 8000 | uiout->field_skip ("addr"); |
edcc5120 TT |
8001 | } |
8002 | ||
528e1572 | 8003 | std::string msg; |
edcc5120 TT |
8004 | annotate_field (5); |
8005 | if (self->is_load) | |
8006 | { | |
8007 | if (self->regex) | |
528e1572 | 8008 | msg = string_printf (_("load of library matching %s"), self->regex); |
edcc5120 | 8009 | else |
528e1572 | 8010 | msg = _("load of library"); |
edcc5120 TT |
8011 | } |
8012 | else | |
8013 | { | |
8014 | if (self->regex) | |
528e1572 | 8015 | msg = string_printf (_("unload of library matching %s"), self->regex); |
edcc5120 | 8016 | else |
528e1572 | 8017 | msg = _("unload of library"); |
edcc5120 | 8018 | } |
112e8700 | 8019 | uiout->field_string ("what", msg); |
8ac3646f | 8020 | |
112e8700 SM |
8021 | if (uiout->is_mi_like_p ()) |
8022 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8023 | } |
8024 | ||
8025 | static void | |
8026 | print_mention_catch_solib (struct breakpoint *b) | |
8027 | { | |
8028 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8029 | ||
8030 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8031 | self->is_load ? "load" : "unload"); | |
8032 | } | |
8033 | ||
8034 | static void | |
8035 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8036 | { | |
8037 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8038 | ||
8039 | fprintf_unfiltered (fp, "%s %s", | |
8040 | b->disposition == disp_del ? "tcatch" : "catch", | |
8041 | self->is_load ? "load" : "unload"); | |
8042 | if (self->regex) | |
8043 | fprintf_unfiltered (fp, " %s", self->regex); | |
8044 | fprintf_unfiltered (fp, "\n"); | |
8045 | } | |
8046 | ||
8047 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8048 | ||
91985142 MG |
8049 | /* Shared helper function (MI and CLI) for creating and installing |
8050 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8051 | the events to be caught are load events, otherwise they are | |
8052 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8053 | temporary one. If ENABLED is non-zero the catchpoint is | |
8054 | created in an enabled state. */ | |
edcc5120 | 8055 | |
91985142 | 8056 | void |
a121b7c1 | 8057 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8058 | { |
edcc5120 | 8059 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8060 | |
edcc5120 TT |
8061 | if (!arg) |
8062 | arg = ""; | |
f1735a53 | 8063 | arg = skip_spaces (arg); |
edcc5120 | 8064 | |
36bd8eaa | 8065 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8066 | |
8067 | if (*arg != '\0') | |
8068 | { | |
2d7cc5c7 PA |
8069 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8070 | _("Invalid regexp"))); | |
edcc5120 TT |
8071 | c->regex = xstrdup (arg); |
8072 | } | |
8073 | ||
8074 | c->is_load = is_load; | |
36bd8eaa | 8075 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8076 | &catch_solib_breakpoint_ops); |
8077 | ||
c1fc2657 | 8078 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8079 | |
b270e6f9 | 8080 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8081 | } |
8082 | ||
91985142 MG |
8083 | /* A helper function that does all the work for "catch load" and |
8084 | "catch unload". */ | |
8085 | ||
8086 | static void | |
eb4c3f4a | 8087 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
91985142 MG |
8088 | struct cmd_list_element *command) |
8089 | { | |
8090 | int tempflag; | |
8091 | const int enabled = 1; | |
8092 | ||
8093 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8094 | ||
8095 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8096 | } | |
8097 | ||
edcc5120 | 8098 | static void |
eb4c3f4a | 8099 | catch_load_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8100 | struct cmd_list_element *command) |
8101 | { | |
8102 | catch_load_or_unload (arg, from_tty, 1, command); | |
8103 | } | |
8104 | ||
8105 | static void | |
eb4c3f4a | 8106 | catch_unload_command_1 (const char *arg, int from_tty, |
edcc5120 TT |
8107 | struct cmd_list_element *command) |
8108 | { | |
8109 | catch_load_or_unload (arg, from_tty, 0, command); | |
8110 | } | |
8111 | ||
346774a9 PA |
8112 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8113 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8114 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8115 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8116 | |
ab04a2af | 8117 | void |
346774a9 PA |
8118 | init_catchpoint (struct breakpoint *b, |
8119 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8120 | const char *cond_string, |
c0a91b2b | 8121 | const struct breakpoint_ops *ops) |
c906108c | 8122 | { |
51abb421 | 8123 | symtab_and_line sal; |
6c95b8df | 8124 | sal.pspace = current_program_space; |
c5aa993b | 8125 | |
28010a5d | 8126 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8127 | |
1b36a34b | 8128 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8129 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8130 | } |
8131 | ||
28010a5d | 8132 | void |
b270e6f9 | 8133 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8134 | { |
b270e6f9 | 8135 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8136 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8137 | if (is_tracepoint (b)) |
8138 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8139 | if (!internal) |
8140 | mention (b); | |
76727919 | 8141 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
8142 | |
8143 | if (update_gll) | |
44702360 | 8144 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8145 | } |
8146 | ||
9b70b993 | 8147 | static void |
a6d9a66e | 8148 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8149 | int tempflag, const char *cond_string, |
c0a91b2b | 8150 | const struct breakpoint_ops *ops) |
c906108c | 8151 | { |
b270e6f9 | 8152 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8153 | |
b270e6f9 | 8154 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8155 | |
8156 | c->forked_inferior_pid = null_ptid; | |
8157 | ||
b270e6f9 | 8158 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8159 | } |
8160 | ||
fe798b75 JB |
8161 | /* Exec catchpoints. */ |
8162 | ||
b4d90040 | 8163 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8164 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8165 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8166 | ||
c1fc2657 | 8167 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8168 | { |
c1fc2657 | 8169 | ~exec_catchpoint () override; |
b4d90040 PA |
8170 | |
8171 | /* Filename of a program whose exec triggered this catchpoint. | |
8172 | This field is only valid immediately after this catchpoint has | |
8173 | triggered. */ | |
8174 | char *exec_pathname; | |
8175 | }; | |
8176 | ||
c1fc2657 | 8177 | /* Exec catchpoint destructor. */ |
b4d90040 | 8178 | |
c1fc2657 | 8179 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8180 | { |
c1fc2657 | 8181 | xfree (this->exec_pathname); |
b4d90040 PA |
8182 | } |
8183 | ||
77b06cd7 TJB |
8184 | static int |
8185 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8186 | { |
e99b03dc | 8187 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8188 | } |
c906108c | 8189 | |
fe798b75 | 8190 | static int |
73971819 | 8191 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8192 | { |
e99b03dc | 8193 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
fe798b75 | 8194 | } |
c906108c | 8195 | |
fe798b75 | 8196 | static int |
f1310107 | 8197 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
bd522513 | 8198 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 8199 | const struct target_waitstatus *ws) |
fe798b75 | 8200 | { |
b4d90040 PA |
8201 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8202 | ||
f90263c1 TT |
8203 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8204 | return 0; | |
8205 | ||
8206 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8207 | return 1; | |
fe798b75 | 8208 | } |
c906108c | 8209 | |
fe798b75 | 8210 | static enum print_stop_action |
348d480f | 8211 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8212 | { |
36dfb11c | 8213 | struct ui_out *uiout = current_uiout; |
348d480f | 8214 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8215 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8216 | ||
fe798b75 | 8217 | annotate_catchpoint (b->number); |
f303dbd6 | 8218 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8219 | if (b->disposition == disp_del) |
112e8700 | 8220 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8221 | else |
112e8700 SM |
8222 | uiout->text ("Catchpoint "); |
8223 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8224 | { |
112e8700 SM |
8225 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8226 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8227 | } |
381befee | 8228 | uiout->field_signed ("bkptno", b->number); |
112e8700 SM |
8229 | uiout->text (" (exec'd "); |
8230 | uiout->field_string ("new-exec", c->exec_pathname); | |
8231 | uiout->text ("), "); | |
36dfb11c | 8232 | |
fe798b75 | 8233 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8234 | } |
8235 | ||
fe798b75 | 8236 | static void |
a6d9a66e | 8237 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8238 | { |
b4d90040 | 8239 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8240 | struct value_print_options opts; |
79a45e25 | 8241 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8242 | |
8243 | get_user_print_options (&opts); | |
8244 | ||
8245 | /* Field 4, the address, is omitted (which makes the columns | |
8246 | not line up too nicely with the headers, but the effect | |
8247 | is relatively readable). */ | |
8248 | if (opts.addressprint) | |
112e8700 | 8249 | uiout->field_skip ("addr"); |
fe798b75 | 8250 | annotate_field (5); |
112e8700 | 8251 | uiout->text ("exec"); |
b4d90040 | 8252 | if (c->exec_pathname != NULL) |
fe798b75 | 8253 | { |
112e8700 SM |
8254 | uiout->text (", program \""); |
8255 | uiout->field_string ("what", c->exec_pathname); | |
8256 | uiout->text ("\" "); | |
fe798b75 | 8257 | } |
8ac3646f | 8258 | |
112e8700 SM |
8259 | if (uiout->is_mi_like_p ()) |
8260 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8261 | } |
8262 | ||
8263 | static void | |
8264 | print_mention_catch_exec (struct breakpoint *b) | |
8265 | { | |
8266 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8267 | } | |
8268 | ||
6149aea9 PA |
8269 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8270 | catchpoints. */ | |
8271 | ||
8272 | static void | |
8273 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8274 | { | |
8275 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8276 | print_recreate_thread (b, fp); |
6149aea9 PA |
8277 | } |
8278 | ||
2060206e | 8279 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8280 | |
c906108c | 8281 | static int |
fba45db2 | 8282 | hw_breakpoint_used_count (void) |
c906108c | 8283 | { |
c906108c | 8284 | int i = 0; |
f1310107 TJB |
8285 | struct breakpoint *b; |
8286 | struct bp_location *bl; | |
c906108c SS |
8287 | |
8288 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8289 | { |
d6b74ac4 | 8290 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8291 | for (bl = b->loc; bl; bl = bl->next) |
8292 | { | |
8293 | /* Special types of hardware breakpoints may use more than | |
8294 | one register. */ | |
348d480f | 8295 | i += b->ops->resources_needed (bl); |
f1310107 | 8296 | } |
c5aa993b | 8297 | } |
c906108c SS |
8298 | |
8299 | return i; | |
8300 | } | |
8301 | ||
a1398e0c PA |
8302 | /* Returns the resources B would use if it were a hardware |
8303 | watchpoint. */ | |
8304 | ||
c906108c | 8305 | static int |
a1398e0c | 8306 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8307 | { |
c906108c | 8308 | int i = 0; |
e09342b5 | 8309 | struct bp_location *bl; |
c906108c | 8310 | |
a1398e0c PA |
8311 | if (!breakpoint_enabled (b)) |
8312 | return 0; | |
8313 | ||
8314 | for (bl = b->loc; bl; bl = bl->next) | |
8315 | { | |
8316 | /* Special types of hardware watchpoints may use more than | |
8317 | one register. */ | |
8318 | i += b->ops->resources_needed (bl); | |
8319 | } | |
8320 | ||
8321 | return i; | |
8322 | } | |
8323 | ||
8324 | /* Returns the sum the used resources of all hardware watchpoints of | |
8325 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8326 | the sum of the used resources of all hardware watchpoints of other | |
8327 | types _not_ TYPE. */ | |
8328 | ||
8329 | static int | |
8330 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8331 | enum bptype type, int *other_type_used) | |
8332 | { | |
8333 | int i = 0; | |
8334 | struct breakpoint *b; | |
8335 | ||
c906108c SS |
8336 | *other_type_used = 0; |
8337 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8338 | { |
a1398e0c PA |
8339 | if (b == except) |
8340 | continue; | |
e09342b5 TJB |
8341 | if (!breakpoint_enabled (b)) |
8342 | continue; | |
8343 | ||
a1398e0c PA |
8344 | if (b->type == type) |
8345 | i += hw_watchpoint_use_count (b); | |
8346 | else if (is_hardware_watchpoint (b)) | |
8347 | *other_type_used = 1; | |
e09342b5 TJB |
8348 | } |
8349 | ||
c906108c SS |
8350 | return i; |
8351 | } | |
8352 | ||
c906108c | 8353 | void |
fba45db2 | 8354 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8355 | { |
c5aa993b | 8356 | struct breakpoint *b; |
c906108c SS |
8357 | |
8358 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8359 | { |
cc60f2e3 | 8360 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8361 | { |
b5de0fa7 | 8362 | b->enable_state = bp_call_disabled; |
44702360 | 8363 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8364 | } |
8365 | } | |
c906108c SS |
8366 | } |
8367 | ||
8368 | void | |
fba45db2 | 8369 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8370 | { |
c5aa993b | 8371 | struct breakpoint *b; |
c906108c SS |
8372 | |
8373 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8374 | { |
cc60f2e3 | 8375 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8376 | { |
b5de0fa7 | 8377 | b->enable_state = bp_enabled; |
44702360 | 8378 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8379 | } |
8380 | } | |
c906108c SS |
8381 | } |
8382 | ||
8bea4e01 UW |
8383 | void |
8384 | disable_breakpoints_before_startup (void) | |
8385 | { | |
6c95b8df | 8386 | current_program_space->executing_startup = 1; |
44702360 | 8387 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8388 | } |
8389 | ||
8390 | void | |
8391 | enable_breakpoints_after_startup (void) | |
8392 | { | |
6c95b8df | 8393 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8394 | breakpoint_re_set (); |
8bea4e01 UW |
8395 | } |
8396 | ||
7c16b83e PA |
8397 | /* Create a new single-step breakpoint for thread THREAD, with no |
8398 | locations. */ | |
c906108c | 8399 | |
7c16b83e PA |
8400 | static struct breakpoint * |
8401 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8402 | { | |
b270e6f9 | 8403 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8404 | |
b270e6f9 | 8405 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8406 | &momentary_breakpoint_ops); |
8407 | ||
8408 | b->disposition = disp_donttouch; | |
8409 | b->frame_id = null_frame_id; | |
8410 | ||
8411 | b->thread = thread; | |
8412 | gdb_assert (b->thread != 0); | |
8413 | ||
b270e6f9 | 8414 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8415 | } |
8416 | ||
8417 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8418 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8419 | frame. */ | |
c906108c | 8420 | |
454dafbd | 8421 | breakpoint_up |
a6d9a66e UW |
8422 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8423 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8424 | { |
52f0bd74 | 8425 | struct breakpoint *b; |
edb3359d | 8426 | |
193facb3 JK |
8427 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8428 | tail-called one. */ | |
8429 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8430 | |
06edf0c0 | 8431 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8432 | b->enable_state = bp_enabled; |
8433 | b->disposition = disp_donttouch; | |
818dd999 | 8434 | b->frame_id = frame_id; |
c906108c | 8435 | |
00431a78 | 8436 | b->thread = inferior_thread ()->global_num; |
c906108c | 8437 | |
44702360 | 8438 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8439 | |
454dafbd | 8440 | return breakpoint_up (b); |
c906108c | 8441 | } |
611c83ae | 8442 | |
06edf0c0 | 8443 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8444 | The new breakpoint will have type TYPE, use OPS as its |
8445 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8446 | |
06edf0c0 PA |
8447 | static struct breakpoint * |
8448 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8449 | enum bptype type, | |
a1aa2221 LM |
8450 | const struct breakpoint_ops *ops, |
8451 | int loc_enabled) | |
e58b0e63 PA |
8452 | { |
8453 | struct breakpoint *copy; | |
8454 | ||
06edf0c0 | 8455 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8456 | copy->loc = allocate_bp_location (copy); |
0ba852ab | 8457 | set_breakpoint_location_function (copy->loc); |
e58b0e63 | 8458 | |
a6d9a66e | 8459 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8460 | copy->loc->requested_address = orig->loc->requested_address; |
8461 | copy->loc->address = orig->loc->address; | |
8462 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8463 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8464 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8465 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8466 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8467 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8468 | copy->frame_id = orig->frame_id; |
8469 | copy->thread = orig->thread; | |
6c95b8df | 8470 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8471 | |
8472 | copy->enable_state = bp_enabled; | |
8473 | copy->disposition = disp_donttouch; | |
8474 | copy->number = internal_breakpoint_number--; | |
8475 | ||
44702360 | 8476 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8477 | return copy; |
8478 | } | |
8479 | ||
06edf0c0 PA |
8480 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8481 | ORIG is NULL. */ | |
8482 | ||
8483 | struct breakpoint * | |
8484 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8485 | { | |
8486 | /* If there's nothing to clone, then return nothing. */ | |
8487 | if (orig == NULL) | |
8488 | return NULL; | |
8489 | ||
a1aa2221 | 8490 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8491 | } |
8492 | ||
454dafbd | 8493 | breakpoint_up |
a6d9a66e UW |
8494 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8495 | enum bptype type) | |
611c83ae PA |
8496 | { |
8497 | struct symtab_and_line sal; | |
8498 | ||
8499 | sal = find_pc_line (pc, 0); | |
8500 | sal.pc = pc; | |
8501 | sal.section = find_pc_overlay (pc); | |
8502 | sal.explicit_pc = 1; | |
8503 | ||
a6d9a66e | 8504 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8505 | } |
c906108c | 8506 | \f |
c5aa993b | 8507 | |
c906108c SS |
8508 | /* Tell the user we have just set a breakpoint B. */ |
8509 | ||
8510 | static void | |
fba45db2 | 8511 | mention (struct breakpoint *b) |
c906108c | 8512 | { |
348d480f | 8513 | b->ops->print_mention (b); |
2d33446d | 8514 | current_uiout->text ("\n"); |
c906108c | 8515 | } |
c906108c | 8516 | \f |
c5aa993b | 8517 | |
5133a315 | 8518 | static bool bp_loc_is_permanent (struct bp_location *loc); |
1a853c52 | 8519 | |
0d381245 | 8520 | static struct bp_location * |
39d61571 | 8521 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8522 | const struct symtab_and_line *sal) |
8523 | { | |
8524 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8525 | CORE_ADDR adjusted_address; |
8526 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8527 | ||
8528 | if (loc_gdbarch == NULL) | |
8529 | loc_gdbarch = b->gdbarch; | |
8530 | ||
8531 | /* Adjust the breakpoint's address prior to allocating a location. | |
8532 | Once we call allocate_bp_location(), that mostly uninitialized | |
8533 | location will be placed on the location chain. Adjustment of the | |
8534 | breakpoint may cause target_read_memory() to be called and we do | |
8535 | not want its scan of the location chain to find a breakpoint and | |
8536 | location that's only been partially initialized. */ | |
8537 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8538 | sal->pc, b->type); | |
0d381245 | 8539 | |
d30113d4 | 8540 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8541 | loc = allocate_bp_location (b); |
d30113d4 JK |
8542 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8543 | tmp = &((*tmp)->next)) | |
0d381245 | 8544 | ; |
d30113d4 | 8545 | loc->next = *tmp; |
0d381245 | 8546 | *tmp = loc; |
3742cc8b | 8547 | |
0d381245 | 8548 | loc->requested_address = sal->pc; |
3742cc8b | 8549 | loc->address = adjusted_address; |
6c95b8df | 8550 | loc->pspace = sal->pspace; |
935676c9 | 8551 | loc->probe.prob = sal->prob; |
729662a5 | 8552 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8553 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8554 | loc->section = sal->section; |
3742cc8b | 8555 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8556 | loc->line_number = sal->line; |
2f202fde | 8557 | loc->symtab = sal->symtab; |
4a27f119 | 8558 | loc->symbol = sal->symbol; |
3467ec66 PA |
8559 | loc->msymbol = sal->msymbol; |
8560 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8561 | |
0ba852ab | 8562 | set_breakpoint_location_function (loc); |
1a853c52 | 8563 | |
6ae88661 LM |
8564 | /* While by definition, permanent breakpoints are already present in the |
8565 | code, we don't mark the location as inserted. Normally one would expect | |
8566 | that GDB could rely on that breakpoint instruction to stop the program, | |
8567 | thus removing the need to insert its own breakpoint, except that executing | |
8568 | the breakpoint instruction can kill the target instead of reporting a | |
8569 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8570 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8571 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8572 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8573 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8574 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8575 | it manually increments the PC, thus avoiding executing the breakpoint | |
8576 | instruction.) */ | |
1a853c52 | 8577 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8578 | loc->permanent = 1; |
1a853c52 | 8579 | |
0d381245 VP |
8580 | return loc; |
8581 | } | |
514f746b AR |
8582 | \f |
8583 | ||
5133a315 LM |
8584 | /* Return true if LOC is pointing to a permanent breakpoint, |
8585 | return false otherwise. */ | |
1cf4d951 | 8586 | |
5133a315 | 8587 | static bool |
1cf4d951 PA |
8588 | bp_loc_is_permanent (struct bp_location *loc) |
8589 | { | |
514f746b AR |
8590 | gdb_assert (loc != NULL); |
8591 | ||
cb1e4e32 PA |
8592 | /* If we have a non-breakpoint-backed catchpoint or a software |
8593 | watchpoint, just return 0. We should not attempt to read from | |
8594 | the addresses the locations of these breakpoint types point to. | |
5133a315 | 8595 | gdbarch_program_breakpoint_here_p, below, will attempt to read |
244558af | 8596 | memory. */ |
cb1e4e32 | 8597 | if (!bl_address_is_meaningful (loc)) |
5133a315 | 8598 | return false; |
244558af | 8599 | |
5ed8105e | 8600 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8601 | switch_to_program_space_and_thread (loc->pspace); |
5133a315 | 8602 | return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8603 | } |
8604 | ||
e7e0cddf SS |
8605 | /* Build a command list for the dprintf corresponding to the current |
8606 | settings of the dprintf style options. */ | |
8607 | ||
8608 | static void | |
8609 | update_dprintf_command_list (struct breakpoint *b) | |
8610 | { | |
8611 | char *dprintf_args = b->extra_string; | |
8612 | char *printf_line = NULL; | |
8613 | ||
8614 | if (!dprintf_args) | |
8615 | return; | |
8616 | ||
8617 | dprintf_args = skip_spaces (dprintf_args); | |
8618 | ||
8619 | /* Allow a comma, as it may have terminated a location, but don't | |
8620 | insist on it. */ | |
8621 | if (*dprintf_args == ',') | |
8622 | ++dprintf_args; | |
8623 | dprintf_args = skip_spaces (dprintf_args); | |
8624 | ||
8625 | if (*dprintf_args != '"') | |
8626 | error (_("Bad format string, missing '\"'.")); | |
8627 | ||
d3ce09f5 | 8628 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8629 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8630 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8631 | { |
8632 | if (!dprintf_function) | |
8633 | error (_("No function supplied for dprintf call")); | |
8634 | ||
8635 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8636 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8637 | dprintf_function, | |
8638 | dprintf_channel, | |
8639 | dprintf_args); | |
8640 | else | |
8641 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8642 | dprintf_function, | |
8643 | dprintf_args); | |
8644 | } | |
d3ce09f5 SS |
8645 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8646 | { | |
8647 | if (target_can_run_breakpoint_commands ()) | |
8648 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8649 | else | |
8650 | { | |
8651 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8652 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8653 | } | |
8654 | } | |
e7e0cddf SS |
8655 | else |
8656 | internal_error (__FILE__, __LINE__, | |
8657 | _("Invalid dprintf style.")); | |
8658 | ||
f28045c2 | 8659 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8660 | |
12973681 TT |
8661 | /* Manufacture a printf sequence. */ |
8662 | struct command_line *printf_cmd_line | |
8663 | = new struct command_line (simple_control, printf_line); | |
8664 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, | |
8665 | command_lines_deleter ())); | |
e7e0cddf SS |
8666 | } |
8667 | ||
8668 | /* Update all dprintf commands, making their command lists reflect | |
8669 | current style settings. */ | |
8670 | ||
8671 | static void | |
eb4c3f4a | 8672 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8673 | struct cmd_list_element *c) |
8674 | { | |
8675 | struct breakpoint *b; | |
8676 | ||
8677 | ALL_BREAKPOINTS (b) | |
8678 | { | |
8679 | if (b->type == bp_dprintf) | |
8680 | update_dprintf_command_list (b); | |
8681 | } | |
8682 | } | |
c3f6f71d | 8683 | |
f00aae0f KS |
8684 | /* Create a breakpoint with SAL as location. Use LOCATION |
8685 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8686 | as condition expression. If LOCATION is NULL then create an |
8687 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8688 | |
8689 | static void | |
d9b3f62e | 8690 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8691 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8692 | event_location_up &&location, |
e1e01040 PA |
8693 | gdb::unique_xmalloc_ptr<char> filter, |
8694 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8695 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8696 | enum bptype type, enum bpdisp disposition, |
8697 | int thread, int task, int ignore_count, | |
c0a91b2b | 8698 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8699 | int enabled, int internal, unsigned flags, |
8700 | int display_canonical) | |
018d34a4 | 8701 | { |
0d381245 | 8702 | int i; |
018d34a4 VP |
8703 | |
8704 | if (type == bp_hardware_breakpoint) | |
8705 | { | |
fbbd034e AS |
8706 | int target_resources_ok; |
8707 | ||
8708 | i = hw_breakpoint_used_count (); | |
8709 | target_resources_ok = | |
8710 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8711 | i + 1, 0); |
8712 | if (target_resources_ok == 0) | |
8713 | error (_("No hardware breakpoint support in the target.")); | |
8714 | else if (target_resources_ok < 0) | |
8715 | error (_("Hardware breakpoints used exceeds limit.")); | |
8716 | } | |
8717 | ||
6c5b2ebe | 8718 | gdb_assert (!sals.empty ()); |
6c95b8df | 8719 | |
6c5b2ebe | 8720 | for (const auto &sal : sals) |
0d381245 | 8721 | { |
0d381245 VP |
8722 | struct bp_location *loc; |
8723 | ||
8724 | if (from_tty) | |
5af949e3 UW |
8725 | { |
8726 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8727 | if (!loc_gdbarch) | |
8728 | loc_gdbarch = gdbarch; | |
8729 | ||
8730 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8731 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8732 | } |
0d381245 | 8733 | |
6c5b2ebe | 8734 | if (&sal == &sals[0]) |
0d381245 | 8735 | { |
d9b3f62e | 8736 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8737 | b->thread = thread; |
4a306c9a | 8738 | b->task = task; |
855a6e68 | 8739 | |
e1e01040 PA |
8740 | b->cond_string = cond_string.release (); |
8741 | b->extra_string = extra_string.release (); | |
0d381245 | 8742 | b->ignore_count = ignore_count; |
41447f92 | 8743 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8744 | b->disposition = disposition; |
6c95b8df | 8745 | |
44f238bb PA |
8746 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8747 | b->loc->inserted = 1; | |
8748 | ||
0fb4aa4b PA |
8749 | if (type == bp_static_tracepoint) |
8750 | { | |
d9b3f62e | 8751 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8752 | struct static_tracepoint_marker marker; |
8753 | ||
983af33b | 8754 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8755 | { |
8756 | /* We already know the marker exists, otherwise, we | |
8757 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8758 | const char *p |
8759 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8760 | const char *endp; |
0fb4aa4b | 8761 | |
f1735a53 | 8762 | p = skip_spaces (p); |
0fb4aa4b | 8763 | |
f1735a53 | 8764 | endp = skip_to_space (p); |
0fb4aa4b | 8765 | |
5d9310c4 | 8766 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8767 | |
3e43a32a MS |
8768 | printf_filtered (_("Probed static tracepoint " |
8769 | "marker \"%s\"\n"), | |
5d9310c4 | 8770 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8771 | } |
8772 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8773 | { | |
5d9310c4 | 8774 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8775 | |
3e43a32a MS |
8776 | printf_filtered (_("Probed static tracepoint " |
8777 | "marker \"%s\"\n"), | |
5d9310c4 | 8778 | t->static_trace_marker_id.c_str ()); |
0fb4aa4b PA |
8779 | } |
8780 | else | |
3e43a32a MS |
8781 | warning (_("Couldn't determine the static " |
8782 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8783 | } |
8784 | ||
0d381245 VP |
8785 | loc = b->loc; |
8786 | } | |
8787 | else | |
018d34a4 | 8788 | { |
39d61571 | 8789 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8790 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8791 | loc->inserted = 1; | |
0d381245 VP |
8792 | } |
8793 | ||
8794 | if (b->cond_string) | |
8795 | { | |
bbc13ae3 KS |
8796 | const char *arg = b->cond_string; |
8797 | ||
1bb9788d TT |
8798 | loc->cond = parse_exp_1 (&arg, loc->address, |
8799 | block_for_pc (loc->address), 0); | |
0d381245 | 8800 | if (*arg) |
588ae58c | 8801 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 8802 | } |
e7e0cddf SS |
8803 | |
8804 | /* Dynamic printf requires and uses additional arguments on the | |
8805 | command line, otherwise it's an error. */ | |
8806 | if (type == bp_dprintf) | |
8807 | { | |
8808 | if (b->extra_string) | |
8809 | update_dprintf_command_list (b); | |
8810 | else | |
8811 | error (_("Format string required")); | |
8812 | } | |
8813 | else if (b->extra_string) | |
588ae58c | 8814 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 8815 | } |
018d34a4 | 8816 | |
56435ebe | 8817 | b->display_canonical = display_canonical; |
f00aae0f | 8818 | if (location != NULL) |
d28cd78a | 8819 | b->location = std::move (location); |
018d34a4 | 8820 | else |
d28cd78a | 8821 | b->location = new_address_location (b->loc->address, NULL, 0); |
c0e8dcd8 | 8822 | b->filter = std::move (filter); |
d9b3f62e | 8823 | } |
018d34a4 | 8824 | |
d9b3f62e PA |
8825 | static void |
8826 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 8827 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8828 | event_location_up &&location, |
e1e01040 PA |
8829 | gdb::unique_xmalloc_ptr<char> filter, |
8830 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8831 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8832 | enum bptype type, enum bpdisp disposition, |
8833 | int thread, int task, int ignore_count, | |
c0a91b2b | 8834 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8835 | int enabled, int internal, unsigned flags, |
8836 | int display_canonical) | |
d9b3f62e | 8837 | { |
a5e364af | 8838 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 8839 | |
a5e364af | 8840 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 8841 | sals, std::move (location), |
e1e01040 PA |
8842 | std::move (filter), |
8843 | std::move (cond_string), | |
8844 | std::move (extra_string), | |
d9b3f62e PA |
8845 | type, disposition, |
8846 | thread, task, ignore_count, | |
8847 | ops, from_tty, | |
44f238bb PA |
8848 | enabled, internal, flags, |
8849 | display_canonical); | |
d9b3f62e | 8850 | |
b270e6f9 | 8851 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
8852 | } |
8853 | ||
8854 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8855 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8856 | value. COND_STRING, if not NULL, specified the condition to be | |
8857 | used for all breakpoints. Essentially the only case where | |
8858 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8859 | function. In that case, it's still not possible to specify | |
8860 | separate conditions for different overloaded functions, so | |
8861 | we take just a single condition string. | |
8862 | ||
c3f6f71d | 8863 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8864 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8865 | array contents). If the function fails (error() is called), the |
8866 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8867 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8868 | |
8869 | static void | |
8cdf0e15 | 8870 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8871 | struct linespec_result *canonical, |
e1e01040 PA |
8872 | gdb::unique_xmalloc_ptr<char> cond_string, |
8873 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
8874 | enum bptype type, enum bpdisp disposition, |
8875 | int thread, int task, int ignore_count, | |
c0a91b2b | 8876 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8877 | int enabled, int internal, unsigned flags) |
c906108c | 8878 | { |
f8eba3c6 | 8879 | if (canonical->pre_expanded) |
6c5b2ebe | 8880 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 8881 | |
6c5b2ebe | 8882 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 8883 | { |
f00aae0f | 8884 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 8885 | 'break', without arguments. */ |
ffc2605c | 8886 | event_location_up location |
f00aae0f | 8887 | = (canonical->location != NULL |
8e9e35b1 | 8888 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 8889 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 8890 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 8891 | |
6c5b2ebe | 8892 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 8893 | std::move (location), |
e1e01040 PA |
8894 | std::move (filter_string), |
8895 | std::move (cond_string), | |
8896 | std::move (extra_string), | |
e7e0cddf | 8897 | type, disposition, |
84f4c1fe | 8898 | thread, task, ignore_count, ops, |
44f238bb | 8899 | from_tty, enabled, internal, flags, |
56435ebe | 8900 | canonical->special_display); |
c3f6f71d | 8901 | } |
c3f6f71d | 8902 | } |
c906108c | 8903 | |
f00aae0f | 8904 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 8905 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
8906 | addresses found. LOCATION points to the end of the SAL (for |
8907 | linespec locations). | |
9998af43 TJB |
8908 | |
8909 | The array and the line spec strings are allocated on the heap, it is | |
8910 | the caller's responsibility to free them. */ | |
c906108c | 8911 | |
b9362cc7 | 8912 | static void |
f00aae0f | 8913 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 8914 | struct linespec_result *canonical) |
c3f6f71d | 8915 | { |
f00aae0f KS |
8916 | struct symtab_and_line cursal; |
8917 | ||
8918 | if (event_location_type (location) == LINESPEC_LOCATION) | |
8919 | { | |
a20714ff | 8920 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 8921 | |
a20714ff | 8922 | if (spec == NULL) |
f00aae0f KS |
8923 | { |
8924 | /* The last displayed codepoint, if it's valid, is our default | |
8925 | breakpoint address. */ | |
8926 | if (last_displayed_sal_is_valid ()) | |
8927 | { | |
f00aae0f KS |
8928 | /* Set sal's pspace, pc, symtab, and line to the values |
8929 | corresponding to the last call to print_frame_info. | |
8930 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
8931 | as the breakpoint line number is inappropriate otherwise. | |
8932 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
8933 | symtab_and_line sal = get_last_displayed_sal (); |
8934 | CORE_ADDR pc = sal.pc; | |
8935 | ||
f00aae0f KS |
8936 | sal = find_pc_line (pc, 0); |
8937 | ||
8938 | /* "break" without arguments is equivalent to "break *PC" | |
8939 | where PC is the last displayed codepoint's address. So | |
8940 | make sure to set sal.explicit_pc to prevent GDB from | |
8941 | trying to expand the list of sals to include all other | |
8942 | instances with the same symtab and line. */ | |
8943 | sal.pc = pc; | |
8944 | sal.explicit_pc = 1; | |
8945 | ||
6c5b2ebe PA |
8946 | struct linespec_sals lsal; |
8947 | lsal.sals = {sal}; | |
f00aae0f KS |
8948 | lsal.canonical = NULL; |
8949 | ||
6c5b2ebe | 8950 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
8951 | return; |
8952 | } | |
8953 | else | |
8954 | error (_("No default breakpoint address now.")); | |
c906108c | 8955 | } |
c906108c | 8956 | } |
f00aae0f KS |
8957 | |
8958 | /* Force almost all breakpoints to be in terms of the | |
8959 | current_source_symtab (which is decode_line_1's default). | |
8960 | This should produce the results we want almost all of the | |
8961 | time while leaving default_breakpoint_* alone. | |
8962 | ||
8963 | ObjC: However, don't match an Objective-C method name which | |
8964 | may have a '+' or '-' succeeded by a '['. */ | |
8965 | cursal = get_current_source_symtab_and_line (); | |
8966 | if (last_displayed_sal_is_valid ()) | |
c906108c | 8967 | { |
a20714ff | 8968 | const char *spec = NULL; |
cc80f267 | 8969 | |
f00aae0f | 8970 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 8971 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 8972 | |
f00aae0f | 8973 | if (!cursal.symtab |
a20714ff PA |
8974 | || (spec != NULL |
8975 | && strchr ("+-", spec[0]) != NULL | |
8976 | && spec[1] != '[')) | |
f00aae0f | 8977 | { |
c2f4122d | 8978 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
8979 | get_last_displayed_symtab (), |
8980 | get_last_displayed_line (), | |
8981 | canonical, NULL, NULL); | |
8982 | return; | |
8983 | } | |
c906108c | 8984 | } |
f00aae0f | 8985 | |
c2f4122d | 8986 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 8987 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 8988 | } |
c906108c | 8989 | |
c906108c | 8990 | |
c3f6f71d | 8991 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 8992 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 8993 | |
b9362cc7 | 8994 | static void |
6c5b2ebe | 8995 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 8996 | { |
6c5b2ebe PA |
8997 | for (auto &sal : sals) |
8998 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
8999 | } |
9000 | ||
7a697b8d SS |
9001 | /* Fast tracepoints may have restrictions on valid locations. For |
9002 | instance, a fast tracepoint using a jump instead of a trap will | |
9003 | likely have to overwrite more bytes than a trap would, and so can | |
9004 | only be placed where the instruction is longer than the jump, or a | |
9005 | multi-instruction sequence does not have a jump into the middle of | |
9006 | it, etc. */ | |
9007 | ||
9008 | static void | |
9009 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9010 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9011 | { |
6c5b2ebe | 9012 | for (const auto &sal : sals) |
7a697b8d | 9013 | { |
f8eba3c6 TT |
9014 | struct gdbarch *sarch; |
9015 | ||
6c5b2ebe | 9016 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9017 | /* We fall back to GDBARCH if there is no architecture |
9018 | associated with SAL. */ | |
9019 | if (sarch == NULL) | |
9020 | sarch = gdbarch; | |
281d762b TT |
9021 | std::string msg; |
9022 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 9023 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 9024 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
9025 | } |
9026 | } | |
9027 | ||
018d34a4 VP |
9028 | /* Given TOK, a string specification of condition and thread, as |
9029 | accepted by the 'break' command, extract the condition | |
9030 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9031 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9032 | If no condition is found, *COND_STRING is set to NULL. |
9033 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9034 | |
9035 | static void | |
bbc13ae3 | 9036 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9037 | char **cond_string, int *thread, int *task, |
9038 | char **rest) | |
018d34a4 VP |
9039 | { |
9040 | *cond_string = NULL; | |
9041 | *thread = -1; | |
ed1d1739 KS |
9042 | *task = 0; |
9043 | *rest = NULL; | |
9044 | ||
018d34a4 VP |
9045 | while (tok && *tok) |
9046 | { | |
bbc13ae3 | 9047 | const char *end_tok; |
018d34a4 | 9048 | int toklen; |
bbc13ae3 KS |
9049 | const char *cond_start = NULL; |
9050 | const char *cond_end = NULL; | |
cc59ec59 | 9051 | |
f1735a53 | 9052 | tok = skip_spaces (tok); |
e7e0cddf SS |
9053 | |
9054 | if ((*tok == '"' || *tok == ',') && rest) | |
9055 | { | |
9056 | *rest = savestring (tok, strlen (tok)); | |
9057 | return; | |
9058 | } | |
9059 | ||
f1735a53 | 9060 | end_tok = skip_to_space (tok); |
d634f2de | 9061 | |
018d34a4 | 9062 | toklen = end_tok - tok; |
d634f2de | 9063 | |
018d34a4 VP |
9064 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9065 | { | |
9066 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9067 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9068 | cond_end = tok; |
d634f2de | 9069 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9070 | } |
9071 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9072 | { | |
5d5658a1 PA |
9073 | const char *tmptok; |
9074 | struct thread_info *thr; | |
d634f2de | 9075 | |
018d34a4 | 9076 | tok = end_tok + 1; |
5d5658a1 | 9077 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9078 | if (tok == tmptok) |
9079 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9080 | *thread = thr->global_num; |
bbc13ae3 | 9081 | tok = tmptok; |
018d34a4 | 9082 | } |
4a306c9a JB |
9083 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9084 | { | |
9085 | char *tmptok; | |
9086 | ||
9087 | tok = end_tok + 1; | |
bbc13ae3 | 9088 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9089 | if (tok == tmptok) |
9090 | error (_("Junk after task keyword.")); | |
9091 | if (!valid_task_id (*task)) | |
b6199126 | 9092 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9093 | tok = tmptok; |
4a306c9a | 9094 | } |
e7e0cddf SS |
9095 | else if (rest) |
9096 | { | |
9097 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9098 | return; |
e7e0cddf | 9099 | } |
018d34a4 VP |
9100 | else |
9101 | error (_("Junk at end of arguments.")); | |
9102 | } | |
9103 | } | |
9104 | ||
0fb4aa4b PA |
9105 | /* Decode a static tracepoint marker spec. */ |
9106 | ||
6c5b2ebe | 9107 | static std::vector<symtab_and_line> |
f00aae0f | 9108 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 9109 | { |
f00aae0f KS |
9110 | const char *p = &(*arg_p)[3]; |
9111 | const char *endp; | |
0fb4aa4b | 9112 | |
f1735a53 | 9113 | p = skip_spaces (p); |
0fb4aa4b | 9114 | |
f1735a53 | 9115 | endp = skip_to_space (p); |
0fb4aa4b | 9116 | |
81b1e71c | 9117 | std::string marker_str (p, endp - p); |
0fb4aa4b | 9118 | |
5d9310c4 SM |
9119 | std::vector<static_tracepoint_marker> markers |
9120 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
9121 | if (markers.empty ()) | |
81b1e71c TT |
9122 | error (_("No known static tracepoint marker named %s"), |
9123 | marker_str.c_str ()); | |
0fb4aa4b | 9124 | |
6c5b2ebe | 9125 | std::vector<symtab_and_line> sals; |
5d9310c4 | 9126 | sals.reserve (markers.size ()); |
0fb4aa4b | 9127 | |
5d9310c4 | 9128 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 9129 | { |
5d9310c4 SM |
9130 | symtab_and_line sal = find_pc_line (marker.address, 0); |
9131 | sal.pc = marker.address; | |
6c5b2ebe | 9132 | sals.push_back (sal); |
5d9310c4 | 9133 | } |
0fb4aa4b | 9134 | |
0fb4aa4b PA |
9135 | *arg_p = endp; |
9136 | return sals; | |
9137 | } | |
9138 | ||
bac7c5cf GB |
9139 | /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and |
9140 | according to IS_TRACEPOINT. */ | |
9141 | ||
9142 | static const struct breakpoint_ops * | |
9143 | breakpoint_ops_for_event_location_type (enum event_location_type location_type, | |
9144 | bool is_tracepoint) | |
9145 | { | |
9146 | if (is_tracepoint) | |
9147 | { | |
9148 | if (location_type == PROBE_LOCATION) | |
9149 | return &tracepoint_probe_breakpoint_ops; | |
9150 | else | |
9151 | return &tracepoint_breakpoint_ops; | |
9152 | } | |
9153 | else | |
9154 | { | |
9155 | if (location_type == PROBE_LOCATION) | |
9156 | return &bkpt_probe_breakpoint_ops; | |
9157 | else | |
9158 | return &bkpt_breakpoint_ops; | |
9159 | } | |
9160 | } | |
9161 | ||
9162 | /* See breakpoint.h. */ | |
9163 | ||
9164 | const struct breakpoint_ops * | |
9165 | breakpoint_ops_for_event_location (const struct event_location *location, | |
9166 | bool is_tracepoint) | |
9167 | { | |
9168 | if (location != nullptr) | |
9169 | return breakpoint_ops_for_event_location_type | |
9170 | (event_location_type (location), is_tracepoint); | |
9171 | return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; | |
9172 | } | |
9173 | ||
f00aae0f | 9174 | /* See breakpoint.h. */ |
0101ce28 | 9175 | |
8cdf0e15 VP |
9176 | int |
9177 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9178 | const struct event_location *location, |
9179 | const char *cond_string, | |
9180 | int thread, const char *extra_string, | |
f00aae0f | 9181 | int parse_extra, |
0fb4aa4b | 9182 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9183 | int ignore_count, |
9184 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9185 | const struct breakpoint_ops *ops, |
44f238bb PA |
9186 | int from_tty, int enabled, int internal, |
9187 | unsigned flags) | |
c3f6f71d | 9188 | { |
7efd8fc2 | 9189 | struct linespec_result canonical; |
0101ce28 | 9190 | int pending = 0; |
4a306c9a | 9191 | int task = 0; |
86b17b60 | 9192 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9193 | |
348d480f PA |
9194 | gdb_assert (ops != NULL); |
9195 | ||
f00aae0f KS |
9196 | /* If extra_string isn't useful, set it to NULL. */ |
9197 | if (extra_string != NULL && *extra_string == '\0') | |
9198 | extra_string = NULL; | |
9199 | ||
a70b8144 | 9200 | try |
b78a6381 | 9201 | { |
f00aae0f | 9202 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9203 | } |
230d2906 | 9204 | catch (const gdb_exception_error &e) |
0101ce28 | 9205 | { |
492d29ea PA |
9206 | /* If caller is interested in rc value from parse, set |
9207 | value. */ | |
9208 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9209 | { |
05ff989b AC |
9210 | /* If pending breakpoint support is turned off, throw |
9211 | error. */ | |
fa8d40ab JJ |
9212 | |
9213 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 9214 | throw; |
723a2275 VP |
9215 | |
9216 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9217 | |
05ff989b AC |
9218 | /* If pending breakpoint support is auto query and the user |
9219 | selects no, then simply return the error code. */ | |
059fb39f | 9220 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9221 | && !nquery (_("Make %s pending on future shared library load? "), |
9222 | bptype_string (type_wanted))) | |
fd9b8c24 | 9223 | return 0; |
fa8d40ab | 9224 | |
05ff989b AC |
9225 | /* At this point, either the user was queried about setting |
9226 | a pending breakpoint and selected yes, or pending | |
9227 | breakpoint behavior is on and thus a pending breakpoint | |
9228 | is defaulted on behalf of the user. */ | |
f00aae0f | 9229 | pending = 1; |
0101ce28 | 9230 | } |
492d29ea | 9231 | else |
eedc3f4f | 9232 | throw; |
0101ce28 | 9233 | } |
492d29ea | 9234 | |
6c5b2ebe | 9235 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9236 | return 0; |
c3f6f71d | 9237 | |
c3f6f71d JM |
9238 | /* Resolve all line numbers to PC's and verify that the addresses |
9239 | are ok for the target. */ | |
0101ce28 | 9240 | if (!pending) |
f8eba3c6 | 9241 | { |
6c5b2ebe PA |
9242 | for (auto &lsal : canonical.lsals) |
9243 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9244 | } |
c3f6f71d | 9245 | |
7a697b8d | 9246 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9247 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9248 | { |
6c5b2ebe PA |
9249 | for (const auto &lsal : canonical.lsals) |
9250 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9251 | } |
7a697b8d | 9252 | |
c3f6f71d JM |
9253 | /* Verify that condition can be parsed, before setting any |
9254 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9255 | breakpoint. */ |
0101ce28 | 9256 | if (!pending) |
c3f6f71d | 9257 | { |
e1e01040 PA |
9258 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9259 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9260 | ||
f00aae0f | 9261 | if (parse_extra) |
72b2ff0e | 9262 | { |
0878d0fa | 9263 | char *rest; |
e1e01040 | 9264 | char *cond; |
52d361e1 | 9265 | |
6c5b2ebe | 9266 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9267 | |
0878d0fa YQ |
9268 | /* Here we only parse 'arg' to separate condition |
9269 | from thread number, so parsing in context of first | |
9270 | sal is OK. When setting the breakpoint we'll | |
9271 | re-parse it in context of each sal. */ | |
9272 | ||
6c5b2ebe | 9273 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9274 | &cond, &thread, &task, &rest); |
9275 | cond_string_copy.reset (cond); | |
9276 | extra_string_copy.reset (rest); | |
72b2ff0e | 9277 | } |
2f069f6f | 9278 | else |
72b2ff0e | 9279 | { |
f00aae0f KS |
9280 | if (type_wanted != bp_dprintf |
9281 | && extra_string != NULL && *extra_string != '\0') | |
9282 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9283 | |
9284 | /* Create a private copy of condition string. */ | |
9285 | if (cond_string) | |
e1e01040 | 9286 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9287 | /* Create a private copy of any extra string. */ |
9288 | if (extra_string) | |
e1e01040 | 9289 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9290 | } |
0fb4aa4b | 9291 | |
52d361e1 | 9292 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9293 | std::move (cond_string_copy), |
9294 | std::move (extra_string_copy), | |
9295 | type_wanted, | |
d9b3f62e PA |
9296 | tempflag ? disp_del : disp_donttouch, |
9297 | thread, task, ignore_count, ops, | |
44f238bb | 9298 | from_tty, enabled, internal, flags); |
c906108c | 9299 | } |
0101ce28 JJ |
9300 | else |
9301 | { | |
a5e364af | 9302 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9303 | |
a5e364af | 9304 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9305 | b->location = copy_event_location (location); |
bfccc43c | 9306 | |
f00aae0f KS |
9307 | if (parse_extra) |
9308 | b->cond_string = NULL; | |
e12c7713 MK |
9309 | else |
9310 | { | |
9311 | /* Create a private copy of condition string. */ | |
e1e01040 | 9312 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9313 | b->thread = thread; |
e12c7713 | 9314 | } |
f00aae0f KS |
9315 | |
9316 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9317 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9318 | b->ignore_count = ignore_count; |
0101ce28 | 9319 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9320 | b->condition_not_parsed = 1; |
41447f92 | 9321 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9322 | if ((type_wanted != bp_breakpoint |
9323 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9324 | b->pspace = current_program_space; |
8bea4e01 | 9325 | |
b270e6f9 | 9326 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9327 | } |
9328 | ||
6c5b2ebe | 9329 | if (canonical.lsals.size () > 1) |
95a42b64 | 9330 | { |
3e43a32a MS |
9331 | warning (_("Multiple breakpoints were set.\nUse the " |
9332 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9333 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9334 | } |
9335 | ||
44702360 | 9336 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9337 | |
9338 | return 1; | |
c3f6f71d | 9339 | } |
c906108c | 9340 | |
348d480f | 9341 | /* Set a breakpoint. |
72b2ff0e VP |
9342 | ARG is a string describing breakpoint address, |
9343 | condition, and thread. | |
9344 | FLAG specifies if a breakpoint is hardware on, | |
9345 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9346 | and BP_TEMPFLAG. */ | |
348d480f | 9347 | |
98deb0da | 9348 | static void |
f2fc3015 | 9349 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9350 | { |
72b2ff0e | 9351 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9352 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9353 | ? bp_hardware_breakpoint | |
9354 | : bp_breakpoint); | |
f00aae0f | 9355 | |
ffc2605c | 9356 | event_location_up location = string_to_event_location (&arg, current_language); |
bac7c5cf GB |
9357 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
9358 | (location.get (), false /* is_tracepoint */); | |
c3f6f71d | 9359 | |
8cdf0e15 | 9360 | create_breakpoint (get_current_arch (), |
ffc2605c | 9361 | location.get (), |
f00aae0f | 9362 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9363 | tempflag, type_wanted, |
8cdf0e15 VP |
9364 | 0 /* Ignore count */, |
9365 | pending_break_support, | |
55aa24fb | 9366 | ops, |
8cdf0e15 | 9367 | from_tty, |
84f4c1fe | 9368 | 1 /* enabled */, |
44f238bb PA |
9369 | 0 /* internal */, |
9370 | 0); | |
c906108c SS |
9371 | } |
9372 | ||
c906108c SS |
9373 | /* Helper function for break_command_1 and disassemble_command. */ |
9374 | ||
9375 | void | |
fba45db2 | 9376 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9377 | { |
9378 | CORE_ADDR pc; | |
9379 | ||
9380 | if (sal->pc == 0 && sal->symtab != NULL) | |
9381 | { | |
9382 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9383 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9384 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9385 | sal->pc = pc; |
6a048695 | 9386 | |
4a64f543 MS |
9387 | /* If this SAL corresponds to a breakpoint inserted using a line |
9388 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9389 | if (sal->explicit_line) |
059acae7 | 9390 | skip_prologue_sal (sal); |
c906108c SS |
9391 | } |
9392 | ||
9393 | if (sal->section == 0 && sal->symtab != NULL) | |
9394 | { | |
346d1dfe | 9395 | const struct blockvector *bv; |
3977b71f | 9396 | const struct block *b; |
c5aa993b | 9397 | struct symbol *sym; |
c906108c | 9398 | |
43f3e411 DE |
9399 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9400 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9401 | if (bv != NULL) |
9402 | { | |
7f0df278 | 9403 | sym = block_linkage_function (b); |
c906108c SS |
9404 | if (sym != NULL) |
9405 | { | |
eb822aa6 DE |
9406 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9407 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9408 | sym); | |
c906108c SS |
9409 | } |
9410 | else | |
9411 | { | |
4a64f543 MS |
9412 | /* It really is worthwhile to have the section, so we'll |
9413 | just have to look harder. This case can be executed | |
9414 | if we have line numbers but no functions (as can | |
9415 | happen in assembly source). */ | |
c906108c | 9416 | |
5ed8105e | 9417 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9418 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9419 | |
5ed8105e | 9420 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9421 | if (msym.minsym) |
efd66ac6 | 9422 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9423 | } |
9424 | } | |
9425 | } | |
9426 | } | |
9427 | ||
9428 | void | |
0b39b52e | 9429 | break_command (const char *arg, int from_tty) |
c906108c | 9430 | { |
db107f19 | 9431 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9432 | } |
9433 | ||
c906108c | 9434 | void |
0b39b52e | 9435 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9436 | { |
db107f19 | 9437 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9438 | } |
9439 | ||
c906108c | 9440 | static void |
0b39b52e | 9441 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9442 | { |
db107f19 | 9443 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9444 | } |
9445 | ||
9446 | static void | |
0b39b52e | 9447 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9448 | { |
db107f19 | 9449 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9450 | } |
9451 | ||
9452 | static void | |
ee7ddd71 | 9453 | stop_command (const char *arg, int from_tty) |
c906108c | 9454 | { |
a3f17187 | 9455 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9456 | Usage: stop in <function | address>\n\ |
a3f17187 | 9457 | stop at <line>\n")); |
c906108c SS |
9458 | } |
9459 | ||
9460 | static void | |
4495129a | 9461 | stopin_command (const char *arg, int from_tty) |
c906108c SS |
9462 | { |
9463 | int badInput = 0; | |
9464 | ||
cafb3438 | 9465 | if (arg == NULL) |
c906108c SS |
9466 | badInput = 1; |
9467 | else if (*arg != '*') | |
9468 | { | |
4495129a | 9469 | const char *argptr = arg; |
c906108c SS |
9470 | int hasColon = 0; |
9471 | ||
4a64f543 | 9472 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9473 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9474 | function/method name. */ |
c906108c | 9475 | while (*argptr && !hasColon) |
c5aa993b JM |
9476 | { |
9477 | hasColon = (*argptr == ':'); | |
9478 | argptr++; | |
9479 | } | |
c906108c SS |
9480 | |
9481 | if (hasColon) | |
c5aa993b | 9482 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9483 | else |
c5aa993b | 9484 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9485 | } |
9486 | ||
9487 | if (badInput) | |
a3f17187 | 9488 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9489 | else |
db107f19 | 9490 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9491 | } |
9492 | ||
9493 | static void | |
4495129a | 9494 | stopat_command (const char *arg, int from_tty) |
c906108c SS |
9495 | { |
9496 | int badInput = 0; | |
9497 | ||
cafb3438 | 9498 | if (arg == NULL || *arg == '*') /* no line number */ |
c906108c SS |
9499 | badInput = 1; |
9500 | else | |
9501 | { | |
4495129a | 9502 | const char *argptr = arg; |
c906108c SS |
9503 | int hasColon = 0; |
9504 | ||
4a64f543 MS |
9505 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9506 | it is probably a line number. */ | |
c906108c | 9507 | while (*argptr && !hasColon) |
c5aa993b JM |
9508 | { |
9509 | hasColon = (*argptr == ':'); | |
9510 | argptr++; | |
9511 | } | |
c906108c SS |
9512 | |
9513 | if (hasColon) | |
c5aa993b | 9514 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9515 | else |
c5aa993b | 9516 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9517 | } |
9518 | ||
9519 | if (badInput) | |
65e65158 | 9520 | printf_filtered (_("Usage: stop at LINE\n")); |
c906108c | 9521 | else |
db107f19 | 9522 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9523 | } |
9524 | ||
e7e0cddf SS |
9525 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9526 | with a prewired command list consisting of a single output command, | |
9527 | built from extra arguments supplied on the dprintf command | |
9528 | line. */ | |
9529 | ||
da821c7b | 9530 | static void |
0b39b52e | 9531 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9532 | { |
ffc2605c | 9533 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9534 | |
9535 | /* If non-NULL, ARG should have been advanced past the location; | |
9536 | the next character must be ','. */ | |
9537 | if (arg != NULL) | |
9538 | { | |
9539 | if (arg[0] != ',' || arg[1] == '\0') | |
9540 | error (_("Format string required")); | |
9541 | else | |
9542 | { | |
9543 | /* Skip the comma. */ | |
9544 | ++arg; | |
9545 | } | |
9546 | } | |
9547 | ||
e7e0cddf | 9548 | create_breakpoint (get_current_arch (), |
ffc2605c | 9549 | location.get (), |
f00aae0f | 9550 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9551 | 0, bp_dprintf, |
9552 | 0 /* Ignore count */, | |
9553 | pending_break_support, | |
9554 | &dprintf_breakpoint_ops, | |
9555 | from_tty, | |
9556 | 1 /* enabled */, | |
9557 | 0 /* internal */, | |
9558 | 0); | |
9559 | } | |
9560 | ||
d3ce09f5 | 9561 | static void |
0b39b52e | 9562 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9563 | { |
9564 | error (_("May only run agent-printf on the target")); | |
9565 | } | |
9566 | ||
f1310107 TJB |
9567 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9568 | ranged breakpoints. */ | |
9569 | ||
9570 | static int | |
9571 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
bd522513 | 9572 | const address_space *aspace, |
09ac7c10 TT |
9573 | CORE_ADDR bp_addr, |
9574 | const struct target_waitstatus *ws) | |
f1310107 | 9575 | { |
09ac7c10 | 9576 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9577 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9578 | return 0; |
9579 | ||
f1310107 TJB |
9580 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9581 | bl->length, aspace, bp_addr); | |
9582 | } | |
9583 | ||
9584 | /* Implement the "resources_needed" breakpoint_ops method for | |
9585 | ranged breakpoints. */ | |
9586 | ||
9587 | static int | |
9588 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9589 | { | |
9590 | return target_ranged_break_num_registers (); | |
9591 | } | |
9592 | ||
9593 | /* Implement the "print_it" breakpoint_ops method for | |
9594 | ranged breakpoints. */ | |
9595 | ||
9596 | static enum print_stop_action | |
348d480f | 9597 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9598 | { |
348d480f | 9599 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9600 | struct bp_location *bl = b->loc; |
79a45e25 | 9601 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9602 | |
9603 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9604 | ||
9605 | /* Ranged breakpoints have only one location. */ | |
9606 | gdb_assert (bl && bl->next == NULL); | |
9607 | ||
9608 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9609 | |
9610 | maybe_print_thread_hit_breakpoint (uiout); | |
9611 | ||
f1310107 | 9612 | if (b->disposition == disp_del) |
112e8700 | 9613 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9614 | else |
112e8700 SM |
9615 | uiout->text ("Ranged breakpoint "); |
9616 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9617 | { |
112e8700 | 9618 | uiout->field_string ("reason", |
f1310107 | 9619 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9620 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9621 | } |
381befee | 9622 | uiout->field_signed ("bkptno", b->number); |
112e8700 | 9623 | uiout->text (", "); |
f1310107 TJB |
9624 | |
9625 | return PRINT_SRC_AND_LOC; | |
9626 | } | |
9627 | ||
9628 | /* Implement the "print_one" breakpoint_ops method for | |
9629 | ranged breakpoints. */ | |
9630 | ||
9631 | static void | |
9632 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9633 | struct bp_location **last_loc) | |
9634 | { | |
9635 | struct bp_location *bl = b->loc; | |
9636 | struct value_print_options opts; | |
79a45e25 | 9637 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9638 | |
9639 | /* Ranged breakpoints have only one location. */ | |
9640 | gdb_assert (bl && bl->next == NULL); | |
9641 | ||
9642 | get_user_print_options (&opts); | |
9643 | ||
9644 | if (opts.addressprint) | |
9645 | /* We don't print the address range here, it will be printed later | |
9646 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9647 | uiout->field_skip ("addr"); |
f1310107 TJB |
9648 | annotate_field (5); |
9649 | print_breakpoint_location (b, bl); | |
9650 | *last_loc = bl; | |
9651 | } | |
9652 | ||
9653 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9654 | ranged breakpoints. */ | |
9655 | ||
9656 | static void | |
9657 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9658 | struct ui_out *uiout) | |
9659 | { | |
9660 | CORE_ADDR address_start, address_end; | |
9661 | struct bp_location *bl = b->loc; | |
d7e74731 | 9662 | string_file stb; |
f1310107 TJB |
9663 | |
9664 | gdb_assert (bl); | |
9665 | ||
9666 | address_start = bl->address; | |
9667 | address_end = address_start + bl->length - 1; | |
9668 | ||
112e8700 | 9669 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9670 | stb.printf ("[%s, %s]", |
9671 | print_core_address (bl->gdbarch, address_start), | |
9672 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9673 | uiout->field_stream ("addr", stb); |
9674 | uiout->text ("\n"); | |
f1310107 TJB |
9675 | } |
9676 | ||
9677 | /* Implement the "print_mention" breakpoint_ops method for | |
9678 | ranged breakpoints. */ | |
9679 | ||
9680 | static void | |
9681 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
9682 | { | |
9683 | struct bp_location *bl = b->loc; | |
79a45e25 | 9684 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9685 | |
9686 | gdb_assert (bl); | |
9687 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9688 | ||
2d33446d TT |
9689 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
9690 | b->number, paddress (bl->gdbarch, bl->address), | |
9691 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
f1310107 TJB |
9692 | } |
9693 | ||
9694 | /* Implement the "print_recreate" breakpoint_ops method for | |
9695 | ranged breakpoints. */ | |
9696 | ||
9697 | static void | |
9698 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
9699 | { | |
f00aae0f | 9700 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
9701 | event_location_to_string (b->location.get ()), |
9702 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 9703 | print_recreate_thread (b, fp); |
f1310107 TJB |
9704 | } |
9705 | ||
9706 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
9707 | ||
2060206e | 9708 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
9709 | |
9710 | /* Find the address where the end of the breakpoint range should be | |
9711 | placed, given the SAL of the end of the range. This is so that if | |
9712 | the user provides a line number, the end of the range is set to the | |
9713 | last instruction of the given line. */ | |
9714 | ||
9715 | static CORE_ADDR | |
9716 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9717 | { | |
9718 | CORE_ADDR end; | |
9719 | ||
9720 | /* If the user provided a PC value, use it. Otherwise, | |
9721 | find the address of the end of the given location. */ | |
9722 | if (sal.explicit_pc) | |
9723 | end = sal.pc; | |
9724 | else | |
9725 | { | |
9726 | int ret; | |
9727 | CORE_ADDR start; | |
9728 | ||
9729 | ret = find_line_pc_range (sal, &start, &end); | |
9730 | if (!ret) | |
9731 | error (_("Could not find location of the end of the range.")); | |
9732 | ||
9733 | /* find_line_pc_range returns the start of the next line. */ | |
9734 | end--; | |
9735 | } | |
9736 | ||
9737 | return end; | |
9738 | } | |
9739 | ||
9740 | /* Implement the "break-range" CLI command. */ | |
9741 | ||
9742 | static void | |
0b39b52e | 9743 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9744 | { |
f2fc3015 | 9745 | const char *arg_start; |
f1310107 TJB |
9746 | struct linespec_result canonical_start, canonical_end; |
9747 | int bp_count, can_use_bp, length; | |
9748 | CORE_ADDR end; | |
9749 | struct breakpoint *b; | |
f1310107 TJB |
9750 | |
9751 | /* We don't support software ranged breakpoints. */ | |
9752 | if (target_ranged_break_num_registers () < 0) | |
9753 | error (_("This target does not support hardware ranged breakpoints.")); | |
9754 | ||
9755 | bp_count = hw_breakpoint_used_count (); | |
9756 | bp_count += target_ranged_break_num_registers (); | |
9757 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9758 | bp_count, 0); | |
9759 | if (can_use_bp < 0) | |
9760 | error (_("Hardware breakpoints used exceeds limit.")); | |
9761 | ||
f8eba3c6 | 9762 | arg = skip_spaces (arg); |
f1310107 TJB |
9763 | if (arg == NULL || arg[0] == '\0') |
9764 | error(_("No address range specified.")); | |
9765 | ||
f8eba3c6 | 9766 | arg_start = arg; |
ffc2605c TT |
9767 | event_location_up start_location = string_to_event_location (&arg, |
9768 | current_language); | |
9769 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
9770 | |
9771 | if (arg[0] != ',') | |
9772 | error (_("Too few arguments.")); | |
6c5b2ebe | 9773 | else if (canonical_start.lsals.empty ()) |
f1310107 | 9774 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 9775 | |
6c5b2ebe | 9776 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 9777 | |
6c5b2ebe PA |
9778 | if (canonical_start.lsals.size () > 1 |
9779 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
9780 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9781 | ||
6c5b2ebe | 9782 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 9783 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
9784 | |
9785 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9786 | arg = skip_spaces (arg); |
f1310107 TJB |
9787 | |
9788 | /* Parse the end location. */ | |
9789 | ||
f1310107 TJB |
9790 | arg_start = arg; |
9791 | ||
f8eba3c6 | 9792 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9793 | parse_breakpoint_sals because we need to specify the start location's |
9794 | symtab and line as the default symtab and line for the end of the | |
9795 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9796 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
9797 | event_location_up end_location = string_to_event_location (&arg, |
9798 | current_language); | |
9799 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
9800 | sal_start.symtab, sal_start.line, |
9801 | &canonical_end, NULL, NULL); | |
9802 | ||
6c5b2ebe | 9803 | if (canonical_end.lsals.empty ()) |
f1310107 | 9804 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 9805 | |
6c5b2ebe PA |
9806 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
9807 | if (canonical_end.lsals.size () > 1 | |
9808 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
9809 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9810 | ||
6c5b2ebe | 9811 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
9812 | |
9813 | end = find_breakpoint_range_end (sal_end); | |
9814 | if (sal_start.pc > end) | |
177b42fe | 9815 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9816 | |
9817 | length = end - sal_start.pc + 1; | |
9818 | if (length < 0) | |
9819 | /* Length overflowed. */ | |
9820 | error (_("Address range too large.")); | |
9821 | else if (length == 1) | |
9822 | { | |
9823 | /* This range is simple enough to be handled by | |
9824 | the `hbreak' command. */ | |
81b1e71c | 9825 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
9826 | |
9827 | return; | |
9828 | } | |
9829 | ||
9830 | /* Now set up the breakpoint. */ | |
9831 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 9832 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
9833 | set_breakpoint_count (breakpoint_count + 1); |
9834 | b->number = breakpoint_count; | |
9835 | b->disposition = disp_donttouch; | |
d28cd78a TT |
9836 | b->location = std::move (start_location); |
9837 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
9838 | b->loc->length = length; |
9839 | ||
f1310107 | 9840 | mention (b); |
76727919 | 9841 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 9842 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
9843 | } |
9844 | ||
4a64f543 MS |
9845 | /* Return non-zero if EXP is verified as constant. Returned zero |
9846 | means EXP is variable. Also the constant detection may fail for | |
9847 | some constant expressions and in such case still falsely return | |
9848 | zero. */ | |
2e6e3d9c | 9849 | |
65d79d4b SDJ |
9850 | static int |
9851 | watchpoint_exp_is_const (const struct expression *exp) | |
9852 | { | |
9853 | int i = exp->nelts; | |
9854 | ||
9855 | while (i > 0) | |
9856 | { | |
9857 | int oplenp, argsp; | |
9858 | ||
9859 | /* We are only interested in the descriptor of each element. */ | |
9860 | operator_length (exp, i, &oplenp, &argsp); | |
9861 | i -= oplenp; | |
9862 | ||
9863 | switch (exp->elts[i].opcode) | |
9864 | { | |
9865 | case BINOP_ADD: | |
9866 | case BINOP_SUB: | |
9867 | case BINOP_MUL: | |
9868 | case BINOP_DIV: | |
9869 | case BINOP_REM: | |
9870 | case BINOP_MOD: | |
9871 | case BINOP_LSH: | |
9872 | case BINOP_RSH: | |
9873 | case BINOP_LOGICAL_AND: | |
9874 | case BINOP_LOGICAL_OR: | |
9875 | case BINOP_BITWISE_AND: | |
9876 | case BINOP_BITWISE_IOR: | |
9877 | case BINOP_BITWISE_XOR: | |
9878 | case BINOP_EQUAL: | |
9879 | case BINOP_NOTEQUAL: | |
9880 | case BINOP_LESS: | |
9881 | case BINOP_GTR: | |
9882 | case BINOP_LEQ: | |
9883 | case BINOP_GEQ: | |
9884 | case BINOP_REPEAT: | |
9885 | case BINOP_COMMA: | |
9886 | case BINOP_EXP: | |
9887 | case BINOP_MIN: | |
9888 | case BINOP_MAX: | |
9889 | case BINOP_INTDIV: | |
9890 | case BINOP_CONCAT: | |
65d79d4b SDJ |
9891 | case TERNOP_COND: |
9892 | case TERNOP_SLICE: | |
65d79d4b SDJ |
9893 | |
9894 | case OP_LONG: | |
edd079d9 | 9895 | case OP_FLOAT: |
65d79d4b SDJ |
9896 | case OP_LAST: |
9897 | case OP_COMPLEX: | |
9898 | case OP_STRING: | |
65d79d4b SDJ |
9899 | case OP_ARRAY: |
9900 | case OP_TYPE: | |
608b4967 TT |
9901 | case OP_TYPEOF: |
9902 | case OP_DECLTYPE: | |
6e72ca20 | 9903 | case OP_TYPEID: |
65d79d4b SDJ |
9904 | case OP_NAME: |
9905 | case OP_OBJC_NSSTRING: | |
9906 | ||
9907 | case UNOP_NEG: | |
9908 | case UNOP_LOGICAL_NOT: | |
9909 | case UNOP_COMPLEMENT: | |
9910 | case UNOP_ADDR: | |
9911 | case UNOP_HIGH: | |
aeaa2474 | 9912 | case UNOP_CAST: |
9eaf6705 TT |
9913 | |
9914 | case UNOP_CAST_TYPE: | |
9915 | case UNOP_REINTERPRET_CAST: | |
9916 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
9917 | /* Unary, binary and ternary operators: We have to check |
9918 | their operands. If they are constant, then so is the | |
9919 | result of that operation. For instance, if A and B are | |
9920 | determined to be constants, then so is "A + B". | |
9921 | ||
9922 | UNOP_IND is one exception to the rule above, because the | |
9923 | value of *ADDR is not necessarily a constant, even when | |
9924 | ADDR is. */ | |
65d79d4b SDJ |
9925 | break; |
9926 | ||
9927 | case OP_VAR_VALUE: | |
9928 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 9929 | |
65d79d4b | 9930 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
9931 | possible that a buggy compiler could mark a variable as |
9932 | constant even when it is not, and TYPE_CONST would return | |
9933 | true in this case, while SYMBOL_CLASS wouldn't. | |
9934 | ||
9935 | We also have to check for function symbols because they | |
9936 | are always constant. */ | |
65d79d4b SDJ |
9937 | { |
9938 | struct symbol *s = exp->elts[i + 2].symbol; | |
9939 | ||
9940 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
9941 | && SYMBOL_CLASS (s) != LOC_CONST | |
9942 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
9943 | return 0; | |
9944 | break; | |
9945 | } | |
9946 | ||
9947 | /* The default action is to return 0 because we are using | |
9948 | the optimistic approach here: If we don't know something, | |
9949 | then it is not a constant. */ | |
9950 | default: | |
9951 | return 0; | |
9952 | } | |
9953 | } | |
9954 | ||
9955 | return 1; | |
9956 | } | |
9957 | ||
c1fc2657 | 9958 | /* Watchpoint destructor. */ |
3a5c3e22 | 9959 | |
c1fc2657 | 9960 | watchpoint::~watchpoint () |
3a5c3e22 | 9961 | { |
c1fc2657 SM |
9962 | xfree (this->exp_string); |
9963 | xfree (this->exp_string_reparse); | |
3a5c3e22 PA |
9964 | } |
9965 | ||
348d480f PA |
9966 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
9967 | ||
9968 | static void | |
9969 | re_set_watchpoint (struct breakpoint *b) | |
9970 | { | |
3a5c3e22 PA |
9971 | struct watchpoint *w = (struct watchpoint *) b; |
9972 | ||
348d480f PA |
9973 | /* Watchpoint can be either on expression using entirely global |
9974 | variables, or it can be on local variables. | |
9975 | ||
9976 | Watchpoints of the first kind are never auto-deleted, and even | |
9977 | persist across program restarts. Since they can use variables | |
9978 | from shared libraries, we need to reparse expression as libraries | |
9979 | are loaded and unloaded. | |
9980 | ||
9981 | Watchpoints on local variables can also change meaning as result | |
9982 | of solib event. For example, if a watchpoint uses both a local | |
9983 | and a global variables in expression, it's a local watchpoint, | |
9984 | but unloading of a shared library will make the expression | |
9985 | invalid. This is not a very common use case, but we still | |
9986 | re-evaluate expression, to avoid surprises to the user. | |
9987 | ||
9988 | Note that for local watchpoints, we re-evaluate it only if | |
9989 | watchpoints frame id is still valid. If it's not, it means the | |
9990 | watchpoint is out of scope and will be deleted soon. In fact, | |
9991 | I'm not sure we'll ever be called in this case. | |
9992 | ||
9993 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 9994 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 9995 | |
3a5c3e22 PA |
9996 | Don't do anything about disabled watchpoints, since they will be |
9997 | reevaluated again when enabled. */ | |
9998 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
9999 | } |
10000 | ||
77b06cd7 TJB |
10001 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10002 | ||
10003 | static int | |
10004 | insert_watchpoint (struct bp_location *bl) | |
10005 | { | |
3a5c3e22 PA |
10006 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10007 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10008 | |
10009 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10010 | w->cond_exp.get ()); |
77b06cd7 TJB |
10011 | } |
10012 | ||
10013 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10014 | ||
10015 | static int | |
73971819 | 10016 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10017 | { |
3a5c3e22 PA |
10018 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10019 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10020 | |
10021 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10022 | w->cond_exp.get ()); |
e09342b5 TJB |
10023 | } |
10024 | ||
e09342b5 | 10025 | static int |
348d480f | 10026 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
bd522513 | 10027 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 10028 | const struct target_waitstatus *ws) |
e09342b5 | 10029 | { |
348d480f | 10030 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10031 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10032 | |
348d480f PA |
10033 | /* Continuable hardware watchpoints are treated as non-existent if the |
10034 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10035 | some data address). Otherwise gdb won't stop on a break instruction | |
10036 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10037 | been defined. Also skip watchpoints which we know did not trigger | |
10038 | (did not match the data address). */ | |
10039 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10040 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10041 | return 0; |
9c06b0b4 | 10042 | |
348d480f | 10043 | return 1; |
9c06b0b4 TJB |
10044 | } |
10045 | ||
348d480f PA |
10046 | static void |
10047 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10048 | { |
348d480f | 10049 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10050 | |
348d480f | 10051 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10052 | } |
10053 | ||
10054 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10055 | hardware watchpoints. */ |
9c06b0b4 TJB |
10056 | |
10057 | static int | |
348d480f | 10058 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10059 | { |
3a5c3e22 PA |
10060 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10061 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10062 | |
10063 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10064 | } |
10065 | ||
10066 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10067 | hardware watchpoints. */ |
9c06b0b4 TJB |
10068 | |
10069 | static int | |
348d480f | 10070 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10071 | { |
efa80663 PA |
10072 | /* Read and access watchpoints only work with hardware support. */ |
10073 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10074 | } |
10075 | ||
9c06b0b4 | 10076 | static enum print_stop_action |
348d480f | 10077 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10078 | { |
348d480f | 10079 | struct breakpoint *b; |
348d480f | 10080 | enum print_stop_action result; |
3a5c3e22 | 10081 | struct watchpoint *w; |
79a45e25 | 10082 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10083 | |
10084 | gdb_assert (bs->bp_location_at != NULL); | |
10085 | ||
348d480f | 10086 | b = bs->breakpoint_at; |
3a5c3e22 | 10087 | w = (struct watchpoint *) b; |
348d480f | 10088 | |
f303dbd6 PA |
10089 | annotate_watchpoint (b->number); |
10090 | maybe_print_thread_hit_breakpoint (uiout); | |
10091 | ||
d7e74731 PA |
10092 | string_file stb; |
10093 | ||
76f9c9cf | 10094 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10095 | switch (b->type) |
10096 | { | |
348d480f | 10097 | case bp_watchpoint: |
9c06b0b4 | 10098 | case bp_hardware_watchpoint: |
112e8700 SM |
10099 | if (uiout->is_mi_like_p ()) |
10100 | uiout->field_string | |
10101 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10102 | mention (b); |
76f9c9cf | 10103 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10104 | uiout->text ("\nOld value = "); |
850645cf | 10105 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10106 | uiout->field_stream ("old", stb); |
10107 | uiout->text ("\nNew value = "); | |
850645cf | 10108 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10109 | uiout->field_stream ("new", stb); |
10110 | uiout->text ("\n"); | |
348d480f PA |
10111 | /* More than one watchpoint may have been triggered. */ |
10112 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10113 | break; |
10114 | ||
10115 | case bp_read_watchpoint: | |
112e8700 SM |
10116 | if (uiout->is_mi_like_p ()) |
10117 | uiout->field_string | |
10118 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10119 | mention (b); |
76f9c9cf | 10120 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10121 | uiout->text ("\nValue = "); |
850645cf | 10122 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10123 | uiout->field_stream ("value", stb); |
10124 | uiout->text ("\n"); | |
348d480f | 10125 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10126 | break; |
10127 | ||
10128 | case bp_access_watchpoint: | |
348d480f PA |
10129 | if (bs->old_val != NULL) |
10130 | { | |
112e8700 SM |
10131 | if (uiout->is_mi_like_p ()) |
10132 | uiout->field_string | |
10133 | ("reason", | |
348d480f PA |
10134 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10135 | mention (b); | |
76f9c9cf | 10136 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10137 | uiout->text ("\nOld value = "); |
850645cf | 10138 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
10139 | uiout->field_stream ("old", stb); |
10140 | uiout->text ("\nNew value = "); | |
348d480f PA |
10141 | } |
10142 | else | |
10143 | { | |
10144 | mention (b); | |
112e8700 SM |
10145 | if (uiout->is_mi_like_p ()) |
10146 | uiout->field_string | |
10147 | ("reason", | |
348d480f | 10148 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10149 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10150 | uiout->text ("\nValue = "); |
348d480f | 10151 | } |
850645cf | 10152 | watchpoint_value_print (w->val.get (), &stb); |
112e8700 SM |
10153 | uiout->field_stream ("new", stb); |
10154 | uiout->text ("\n"); | |
348d480f | 10155 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10156 | break; |
10157 | default: | |
348d480f | 10158 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10159 | } |
10160 | ||
348d480f PA |
10161 | return result; |
10162 | } | |
10163 | ||
10164 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10165 | watchpoints. */ | |
10166 | ||
10167 | static void | |
10168 | print_mention_watchpoint (struct breakpoint *b) | |
10169 | { | |
3a5c3e22 | 10170 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10171 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10172 | const char *tuple_name; |
348d480f PA |
10173 | |
10174 | switch (b->type) | |
10175 | { | |
10176 | case bp_watchpoint: | |
112e8700 | 10177 | uiout->text ("Watchpoint "); |
46b9c129 | 10178 | tuple_name = "wpt"; |
348d480f PA |
10179 | break; |
10180 | case bp_hardware_watchpoint: | |
112e8700 | 10181 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10182 | tuple_name = "wpt"; |
348d480f PA |
10183 | break; |
10184 | case bp_read_watchpoint: | |
112e8700 | 10185 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10186 | tuple_name = "hw-rwpt"; |
348d480f PA |
10187 | break; |
10188 | case bp_access_watchpoint: | |
112e8700 | 10189 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10190 | tuple_name = "hw-awpt"; |
348d480f PA |
10191 | break; |
10192 | default: | |
10193 | internal_error (__FILE__, __LINE__, | |
10194 | _("Invalid hardware watchpoint type.")); | |
10195 | } | |
10196 | ||
46b9c129 | 10197 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10198 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10199 | uiout->text (": "); |
10200 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10201 | } |
10202 | ||
10203 | /* Implement the "print_recreate" breakpoint_ops method for | |
10204 | watchpoints. */ | |
10205 | ||
10206 | static void | |
10207 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10208 | { | |
3a5c3e22 PA |
10209 | struct watchpoint *w = (struct watchpoint *) b; |
10210 | ||
348d480f PA |
10211 | switch (b->type) |
10212 | { | |
10213 | case bp_watchpoint: | |
10214 | case bp_hardware_watchpoint: | |
10215 | fprintf_unfiltered (fp, "watch"); | |
10216 | break; | |
10217 | case bp_read_watchpoint: | |
10218 | fprintf_unfiltered (fp, "rwatch"); | |
10219 | break; | |
10220 | case bp_access_watchpoint: | |
10221 | fprintf_unfiltered (fp, "awatch"); | |
10222 | break; | |
10223 | default: | |
10224 | internal_error (__FILE__, __LINE__, | |
10225 | _("Invalid watchpoint type.")); | |
10226 | } | |
10227 | ||
3a5c3e22 | 10228 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10229 | print_recreate_thread (b, fp); |
348d480f PA |
10230 | } |
10231 | ||
427cd150 TT |
10232 | /* Implement the "explains_signal" breakpoint_ops method for |
10233 | watchpoints. */ | |
10234 | ||
47591c29 | 10235 | static int |
427cd150 TT |
10236 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10237 | { | |
10238 | /* A software watchpoint cannot cause a signal other than | |
10239 | GDB_SIGNAL_TRAP. */ | |
10240 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10241 | return 0; |
427cd150 | 10242 | |
47591c29 | 10243 | return 1; |
427cd150 TT |
10244 | } |
10245 | ||
348d480f PA |
10246 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10247 | ||
2060206e | 10248 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10249 | |
10250 | /* Implement the "insert" breakpoint_ops method for | |
10251 | masked hardware watchpoints. */ | |
10252 | ||
10253 | static int | |
10254 | insert_masked_watchpoint (struct bp_location *bl) | |
10255 | { | |
3a5c3e22 PA |
10256 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10257 | ||
10258 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10259 | bl->watchpoint_type); |
10260 | } | |
10261 | ||
10262 | /* Implement the "remove" breakpoint_ops method for | |
10263 | masked hardware watchpoints. */ | |
10264 | ||
10265 | static int | |
73971819 | 10266 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10267 | { |
3a5c3e22 PA |
10268 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10269 | ||
10270 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10271 | bl->watchpoint_type); |
10272 | } | |
10273 | ||
10274 | /* Implement the "resources_needed" breakpoint_ops method for | |
10275 | masked hardware watchpoints. */ | |
10276 | ||
10277 | static int | |
10278 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10279 | { | |
3a5c3e22 PA |
10280 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10281 | ||
10282 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10283 | } |
10284 | ||
10285 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10286 | masked hardware watchpoints. */ | |
10287 | ||
10288 | static int | |
10289 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10290 | { | |
10291 | return 0; | |
10292 | } | |
10293 | ||
10294 | /* Implement the "print_it" breakpoint_ops method for | |
10295 | masked hardware watchpoints. */ | |
10296 | ||
10297 | static enum print_stop_action | |
10298 | print_it_masked_watchpoint (bpstat bs) | |
10299 | { | |
10300 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10301 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10302 | |
10303 | /* Masked watchpoints have only one location. */ | |
10304 | gdb_assert (b->loc && b->loc->next == NULL); | |
10305 | ||
f303dbd6 PA |
10306 | annotate_watchpoint (b->number); |
10307 | maybe_print_thread_hit_breakpoint (uiout); | |
10308 | ||
348d480f PA |
10309 | switch (b->type) |
10310 | { | |
10311 | case bp_hardware_watchpoint: | |
112e8700 SM |
10312 | if (uiout->is_mi_like_p ()) |
10313 | uiout->field_string | |
10314 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10315 | break; |
10316 | ||
10317 | case bp_read_watchpoint: | |
112e8700 SM |
10318 | if (uiout->is_mi_like_p ()) |
10319 | uiout->field_string | |
10320 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10321 | break; |
10322 | ||
10323 | case bp_access_watchpoint: | |
112e8700 SM |
10324 | if (uiout->is_mi_like_p ()) |
10325 | uiout->field_string | |
10326 | ("reason", | |
348d480f PA |
10327 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10328 | break; | |
10329 | default: | |
10330 | internal_error (__FILE__, __LINE__, | |
10331 | _("Invalid hardware watchpoint type.")); | |
10332 | } | |
10333 | ||
10334 | mention (b); | |
112e8700 | 10335 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10336 | Check the underlying instruction at PC for the memory\n\ |
10337 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10338 | uiout->text ("\n"); |
9c06b0b4 TJB |
10339 | |
10340 | /* More than one watchpoint may have been triggered. */ | |
10341 | return PRINT_UNKNOWN; | |
10342 | } | |
10343 | ||
10344 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10345 | masked hardware watchpoints. */ | |
10346 | ||
10347 | static void | |
10348 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10349 | struct ui_out *uiout) | |
10350 | { | |
3a5c3e22 PA |
10351 | struct watchpoint *w = (struct watchpoint *) b; |
10352 | ||
9c06b0b4 TJB |
10353 | /* Masked watchpoints have only one location. */ |
10354 | gdb_assert (b->loc && b->loc->next == NULL); | |
10355 | ||
112e8700 SM |
10356 | uiout->text ("\tmask "); |
10357 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10358 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10359 | } |
10360 | ||
10361 | /* Implement the "print_mention" breakpoint_ops method for | |
10362 | masked hardware watchpoints. */ | |
10363 | ||
10364 | static void | |
10365 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10366 | { | |
3a5c3e22 | 10367 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10368 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10369 | const char *tuple_name; |
9c06b0b4 TJB |
10370 | |
10371 | switch (b->type) | |
10372 | { | |
10373 | case bp_hardware_watchpoint: | |
112e8700 | 10374 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10375 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10376 | break; |
10377 | case bp_read_watchpoint: | |
112e8700 | 10378 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10379 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10380 | break; |
10381 | case bp_access_watchpoint: | |
112e8700 | 10382 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10383 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10384 | break; |
10385 | default: | |
10386 | internal_error (__FILE__, __LINE__, | |
10387 | _("Invalid hardware watchpoint type.")); | |
10388 | } | |
10389 | ||
46b9c129 | 10390 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
381befee | 10391 | uiout->field_signed ("number", b->number); |
112e8700 SM |
10392 | uiout->text (": "); |
10393 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10394 | } |
10395 | ||
10396 | /* Implement the "print_recreate" breakpoint_ops method for | |
10397 | masked hardware watchpoints. */ | |
10398 | ||
10399 | static void | |
10400 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10401 | { | |
3a5c3e22 | 10402 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10403 | char tmp[40]; |
10404 | ||
10405 | switch (b->type) | |
10406 | { | |
10407 | case bp_hardware_watchpoint: | |
10408 | fprintf_unfiltered (fp, "watch"); | |
10409 | break; | |
10410 | case bp_read_watchpoint: | |
10411 | fprintf_unfiltered (fp, "rwatch"); | |
10412 | break; | |
10413 | case bp_access_watchpoint: | |
10414 | fprintf_unfiltered (fp, "awatch"); | |
10415 | break; | |
10416 | default: | |
10417 | internal_error (__FILE__, __LINE__, | |
10418 | _("Invalid hardware watchpoint type.")); | |
10419 | } | |
10420 | ||
3a5c3e22 PA |
10421 | sprintf_vma (tmp, w->hw_wp_mask); |
10422 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10423 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10424 | } |
10425 | ||
10426 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10427 | ||
2060206e | 10428 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10429 | |
10430 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10431 | ||
f2478a7e | 10432 | static bool |
9c06b0b4 TJB |
10433 | is_masked_watchpoint (const struct breakpoint *b) |
10434 | { | |
10435 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10436 | } | |
10437 | ||
53a5351d JM |
10438 | /* accessflag: hw_write: watch write, |
10439 | hw_read: watch read, | |
10440 | hw_access: watch access (read or write) */ | |
c906108c | 10441 | static void |
bbc13ae3 | 10442 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10443 | int just_location, int internal) |
c906108c | 10444 | { |
c1fc2657 | 10445 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10446 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 10447 | struct value *result; |
bb9d5f81 | 10448 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10449 | const char *exp_start = NULL; |
10450 | const char *exp_end = NULL; | |
10451 | const char *tok, *end_tok; | |
9c06b0b4 | 10452 | int toklen = -1; |
bbc13ae3 KS |
10453 | const char *cond_start = NULL; |
10454 | const char *cond_end = NULL; | |
c906108c | 10455 | enum bptype bp_type; |
37e4754d | 10456 | int thread = -1; |
0cf6dd15 | 10457 | int pc = 0; |
9c06b0b4 TJB |
10458 | /* Flag to indicate whether we are going to use masks for |
10459 | the hardware watchpoint. */ | |
10460 | int use_mask = 0; | |
10461 | CORE_ADDR mask = 0; | |
c906108c | 10462 | |
37e4754d LM |
10463 | /* Make sure that we actually have parameters to parse. */ |
10464 | if (arg != NULL && arg[0] != '\0') | |
10465 | { | |
bbc13ae3 KS |
10466 | const char *value_start; |
10467 | ||
10468 | exp_end = arg + strlen (arg); | |
37e4754d | 10469 | |
9c06b0b4 TJB |
10470 | /* Look for "parameter value" pairs at the end |
10471 | of the arguments string. */ | |
bbc13ae3 | 10472 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10473 | { |
10474 | /* Skip whitespace at the end of the argument list. */ | |
10475 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10476 | tok--; | |
10477 | ||
10478 | /* Find the beginning of the last token. | |
10479 | This is the value of the parameter. */ | |
10480 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10481 | tok--; | |
10482 | value_start = tok + 1; | |
10483 | ||
10484 | /* Skip whitespace. */ | |
10485 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10486 | tok--; | |
10487 | ||
10488 | end_tok = tok; | |
10489 | ||
10490 | /* Find the beginning of the second to last token. | |
10491 | This is the parameter itself. */ | |
10492 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10493 | tok--; | |
10494 | tok++; | |
10495 | toklen = end_tok - tok + 1; | |
10496 | ||
61012eef | 10497 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10498 | { |
5d5658a1 | 10499 | struct thread_info *thr; |
9c06b0b4 TJB |
10500 | /* At this point we've found a "thread" token, which means |
10501 | the user is trying to set a watchpoint that triggers | |
10502 | only in a specific thread. */ | |
5d5658a1 | 10503 | const char *endp; |
37e4754d | 10504 | |
9c06b0b4 TJB |
10505 | if (thread != -1) |
10506 | error(_("You can specify only one thread.")); | |
37e4754d | 10507 | |
9c06b0b4 | 10508 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10509 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10510 | |
5d5658a1 | 10511 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10512 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10513 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10514 | |
5d5658a1 | 10515 | thread = thr->global_num; |
9c06b0b4 | 10516 | } |
61012eef | 10517 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10518 | { |
10519 | /* We've found a "mask" token, which means the user wants to | |
10520 | create a hardware watchpoint that is going to have the mask | |
10521 | facility. */ | |
10522 | struct value *mask_value, *mark; | |
37e4754d | 10523 | |
9c06b0b4 TJB |
10524 | if (use_mask) |
10525 | error(_("You can specify only one mask.")); | |
37e4754d | 10526 | |
9c06b0b4 | 10527 | use_mask = just_location = 1; |
37e4754d | 10528 | |
9c06b0b4 TJB |
10529 | mark = value_mark (); |
10530 | mask_value = parse_to_comma_and_eval (&value_start); | |
10531 | mask = value_as_address (mask_value); | |
10532 | value_free_to_mark (mark); | |
10533 | } | |
10534 | else | |
10535 | /* We didn't recognize what we found. We should stop here. */ | |
10536 | break; | |
37e4754d | 10537 | |
9c06b0b4 TJB |
10538 | /* Truncate the string and get rid of the "parameter value" pair before |
10539 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10540 | exp_end = tok; |
9c06b0b4 | 10541 | } |
37e4754d | 10542 | } |
bbc13ae3 KS |
10543 | else |
10544 | exp_end = arg; | |
37e4754d | 10545 | |
bbc13ae3 KS |
10546 | /* Parse the rest of the arguments. From here on out, everything |
10547 | is in terms of a newly allocated string instead of the original | |
10548 | ARG. */ | |
81b1e71c TT |
10549 | std::string expression (arg, exp_end - arg); |
10550 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10551 | innermost_block_tracker tracker; |
10552 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10553 | exp_end = arg; |
fa8a61dc TT |
10554 | /* Remove trailing whitespace from the expression before saving it. |
10555 | This makes the eventual display of the expression string a bit | |
10556 | prettier. */ | |
10557 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10558 | --exp_end; | |
10559 | ||
65d79d4b | 10560 | /* Checking if the expression is not constant. */ |
4d01a485 | 10561 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10562 | { |
10563 | int len; | |
10564 | ||
10565 | len = exp_end - exp_start; | |
10566 | while (len > 0 && isspace (exp_start[len - 1])) | |
10567 | len--; | |
10568 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10569 | } | |
10570 | ||
699bd4cf | 10571 | exp_valid_block = tracker.block (); |
b926417a | 10572 | struct value *mark = value_mark (); |
850645cf TT |
10573 | struct value *val_as_value = nullptr; |
10574 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, | |
10575 | just_location); | |
06a64a0b | 10576 | |
850645cf | 10577 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10578 | { |
850645cf TT |
10579 | saved_bitpos = value_bitpos (val_as_value); |
10580 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10581 | } |
10582 | ||
850645cf | 10583 | value_ref_ptr val; |
06a64a0b TT |
10584 | if (just_location) |
10585 | { | |
9c06b0b4 TJB |
10586 | int ret; |
10587 | ||
06a64a0b | 10588 | exp_valid_block = NULL; |
850645cf | 10589 | val = release_value (value_addr (result)); |
06a64a0b | 10590 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10591 | |
10592 | if (use_mask) | |
10593 | { | |
850645cf | 10594 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10595 | mask); |
10596 | if (ret == -1) | |
10597 | error (_("This target does not support masked watchpoints.")); | |
10598 | else if (ret == -2) | |
10599 | error (_("Invalid mask or memory region.")); | |
10600 | } | |
06a64a0b | 10601 | } |
850645cf TT |
10602 | else if (val_as_value != NULL) |
10603 | val = release_value (val_as_value); | |
c906108c | 10604 | |
f1735a53 TT |
10605 | tok = skip_spaces (arg); |
10606 | end_tok = skip_to_space (tok); | |
c906108c SS |
10607 | |
10608 | toklen = end_tok - tok; | |
10609 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10610 | { | |
10611 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10612 | innermost_block_tracker if_tracker; |
10613 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10614 | |
10615 | /* The watchpoint expression may not be local, but the condition | |
10616 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10617 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10618 | |
c906108c SS |
10619 | cond_end = tok; |
10620 | } | |
10621 | if (*tok) | |
8a3fe4f8 | 10622 | error (_("Junk at end of command.")); |
c906108c | 10623 | |
441d7c93 PA |
10624 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10625 | ||
10626 | /* Save this because create_internal_breakpoint below invalidates | |
10627 | 'wp_frame'. */ | |
10628 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10629 | |
10630 | /* If the expression is "local", then set up a "watchpoint scope" | |
10631 | breakpoint at the point where we've left the scope of the watchpoint | |
10632 | expression. Create the scope breakpoint before the watchpoint, so | |
10633 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10634 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10635 | { |
441d7c93 PA |
10636 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10637 | ||
10638 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10639 | { |
441d7c93 PA |
10640 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10641 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10642 | ||
edb3359d | 10643 | scope_breakpoint |
441d7c93 | 10644 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10645 | bp_watchpoint_scope, |
10646 | &momentary_breakpoint_ops); | |
d983da9c | 10647 | |
441d7c93 PA |
10648 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10649 | wp_frame = NULL; | |
10650 | ||
edb3359d | 10651 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10652 | |
edb3359d DJ |
10653 | /* Automatically delete the breakpoint when it hits. */ |
10654 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10655 | |
edb3359d | 10656 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10657 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10658 | |
edb3359d | 10659 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10660 | scope_breakpoint->loc->gdbarch = caller_arch; |
10661 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10662 | scope_breakpoint->loc->address |
a6d9a66e UW |
10663 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10664 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10665 | scope_breakpoint->type); |
10666 | } | |
d983da9c DJ |
10667 | } |
10668 | ||
e8369a73 AB |
10669 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10670 | watchpoints here even if hardware watchpoints are turned off, a call | |
10671 | to update_watchpoint later in this function will cause the type to | |
10672 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10673 | ||
10674 | if (accessflag == hw_read) | |
10675 | bp_type = bp_read_watchpoint; | |
10676 | else if (accessflag == hw_access) | |
10677 | bp_type = bp_access_watchpoint; | |
10678 | else | |
10679 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10680 | |
b270e6f9 | 10681 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 10682 | |
348d480f | 10683 | if (use_mask) |
b270e6f9 | 10684 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10685 | &masked_watchpoint_breakpoint_ops); |
348d480f | 10686 | else |
b270e6f9 | 10687 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 10688 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
10689 | w->thread = thread; |
10690 | w->disposition = disp_donttouch; | |
10691 | w->pspace = current_program_space; | |
b22e99fd | 10692 | w->exp = std::move (exp); |
3a5c3e22 PA |
10693 | w->exp_valid_block = exp_valid_block; |
10694 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10695 | if (just_location) |
10696 | { | |
850645cf TT |
10697 | struct type *t = value_type (val.get ()); |
10698 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10699 | |
43cc5389 TT |
10700 | w->exp_string_reparse |
10701 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 10702 | |
3a5c3e22 | 10703 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 10704 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
10705 | } |
10706 | else | |
3a5c3e22 | 10707 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
10708 | |
10709 | if (use_mask) | |
10710 | { | |
3a5c3e22 | 10711 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10712 | } |
10713 | else | |
10714 | { | |
3a5c3e22 | 10715 | w->val = val; |
bb9d5f81 PP |
10716 | w->val_bitpos = saved_bitpos; |
10717 | w->val_bitsize = saved_bitsize; | |
4c1d86d9 | 10718 | w->val_valid = true; |
9c06b0b4 | 10719 | } |
77b06cd7 | 10720 | |
c906108c | 10721 | if (cond_start) |
c1fc2657 | 10722 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 10723 | else |
c1fc2657 | 10724 | w->cond_string = 0; |
c5aa993b | 10725 | |
441d7c93 | 10726 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10727 | { |
441d7c93 | 10728 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10729 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10730 | } |
c906108c | 10731 | else |
f6bc2008 | 10732 | { |
3a5c3e22 PA |
10733 | w->watchpoint_frame = null_frame_id; |
10734 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10735 | } |
c906108c | 10736 | |
d983da9c | 10737 | if (scope_breakpoint != NULL) |
c906108c | 10738 | { |
d983da9c DJ |
10739 | /* The scope breakpoint is related to the watchpoint. We will |
10740 | need to act on them together. */ | |
c1fc2657 | 10741 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10742 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10743 | } |
d983da9c | 10744 | |
06a64a0b TT |
10745 | if (!just_location) |
10746 | value_free_to_mark (mark); | |
2d134ed3 | 10747 | |
b270e6f9 TT |
10748 | /* Finally update the new watchpoint. This creates the locations |
10749 | that should be inserted. */ | |
10750 | update_watchpoint (w.get (), 1); | |
a9634178 | 10751 | |
b270e6f9 | 10752 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10753 | } |
10754 | ||
e09342b5 | 10755 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10756 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10757 | |
c906108c | 10758 | static int |
a6535de1 | 10759 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
10760 | { |
10761 | int found_memory_cnt = 0; | |
10762 | ||
10763 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10764 | if (!can_use_hw_watchpoints) |
c906108c | 10765 | return 0; |
c5aa993b | 10766 | |
a6535de1 TT |
10767 | gdb_assert (!vals.empty ()); |
10768 | struct value *head = vals[0].get (); | |
10769 | ||
5c44784c JM |
10770 | /* Make sure that the value of the expression depends only upon |
10771 | memory contents, and values computed from them within GDB. If we | |
10772 | find any register references or function calls, we can't use a | |
10773 | hardware watchpoint. | |
10774 | ||
10775 | The idea here is that evaluating an expression generates a series | |
10776 | of values, one holding the value of every subexpression. (The | |
10777 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10778 | a*b+c.) GDB's values hold almost enough information to establish | |
10779 | the criteria given above --- they identify memory lvalues, | |
10780 | register lvalues, computed values, etcetera. So we can evaluate | |
10781 | the expression, and then scan the chain of values that leaves | |
10782 | behind to decide whether we can detect any possible change to the | |
10783 | expression's final value using only hardware watchpoints. | |
10784 | ||
10785 | However, I don't think that the values returned by inferior | |
10786 | function calls are special in any way. So this function may not | |
10787 | notice that an expression involving an inferior function call | |
10788 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 10789 | for (const value_ref_ptr &iter : vals) |
c906108c | 10790 | { |
a6535de1 TT |
10791 | struct value *v = iter.get (); |
10792 | ||
5c44784c | 10793 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10794 | { |
8464be76 DJ |
10795 | if (v != head && value_lazy (v)) |
10796 | /* A lazy memory lvalue in the chain is one that GDB never | |
10797 | needed to fetch; we either just used its address (e.g., | |
10798 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10799 | in `a,b'). This doesn't apply to HEAD; if that is | |
10800 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10801 | ; |
53a5351d | 10802 | else |
5c44784c JM |
10803 | { |
10804 | /* Ahh, memory we actually used! Check if we can cover | |
10805 | it with hardware watchpoints. */ | |
df407dfe | 10806 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10807 | |
10808 | /* We only watch structs and arrays if user asked for it | |
10809 | explicitly, never if they just happen to appear in a | |
10810 | middle of some value chain. */ | |
10811 | if (v == head | |
10812 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
10813 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
10814 | { | |
42ae5230 | 10815 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10816 | int len; |
10817 | int num_regs; | |
10818 | ||
a9634178 | 10819 | len = (target_exact_watchpoints |
e09342b5 TJB |
10820 | && is_scalar_type_recursive (vtype))? |
10821 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10822 | |
e09342b5 TJB |
10823 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10824 | if (!num_regs) | |
2e70b7b9 MS |
10825 | return 0; |
10826 | else | |
e09342b5 | 10827 | found_memory_cnt += num_regs; |
2e70b7b9 | 10828 | } |
5c44784c | 10829 | } |
c5aa993b | 10830 | } |
5086187c AC |
10831 | else if (VALUE_LVAL (v) != not_lval |
10832 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10833 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10834 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10835 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10836 | } |
10837 | ||
10838 | /* The expression itself looks suitable for using a hardware | |
10839 | watchpoint, but give the target machine a chance to reject it. */ | |
10840 | return found_memory_cnt; | |
10841 | } | |
10842 | ||
8b93c638 | 10843 | void |
f2fc3015 | 10844 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10845 | { |
84f4c1fe | 10846 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10847 | } |
10848 | ||
06a64a0b TT |
10849 | /* A helper function that looks for the "-location" argument and then |
10850 | calls watch_command_1. */ | |
10851 | ||
10852 | static void | |
0b39b52e | 10853 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b TT |
10854 | { |
10855 | int just_location = 0; | |
10856 | ||
10857 | if (arg | |
10858 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
10859 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
cbba3ecd | 10860 | just_location = 1; |
06a64a0b | 10861 | |
84f4c1fe | 10862 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 10863 | } |
8926118c | 10864 | |
c5aa993b | 10865 | static void |
0b39b52e | 10866 | watch_command (const char *arg, int from_tty) |
c906108c | 10867 | { |
06a64a0b | 10868 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10869 | } |
10870 | ||
8b93c638 | 10871 | void |
f2fc3015 | 10872 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10873 | { |
84f4c1fe | 10874 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10875 | } |
8926118c | 10876 | |
c5aa993b | 10877 | static void |
0b39b52e | 10878 | rwatch_command (const char *arg, int from_tty) |
c906108c | 10879 | { |
06a64a0b | 10880 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10881 | } |
10882 | ||
8b93c638 | 10883 | void |
f2fc3015 | 10884 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
8b93c638 | 10885 | { |
84f4c1fe | 10886 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10887 | } |
8926118c | 10888 | |
c5aa993b | 10889 | static void |
0b39b52e | 10890 | awatch_command (const char *arg, int from_tty) |
c906108c | 10891 | { |
06a64a0b | 10892 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10893 | } |
c906108c | 10894 | \f |
c5aa993b | 10895 | |
cfc31633 PA |
10896 | /* Data for the FSM that manages the until(location)/advance commands |
10897 | in infcmd.c. Here because it uses the mechanisms of | |
10898 | breakpoints. */ | |
c906108c | 10899 | |
46e3ed7f | 10900 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 10901 | { |
46e3ed7f | 10902 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
10903 | int thread; |
10904 | ||
10905 | /* The breakpoint set at the destination location. */ | |
46e3ed7f | 10906 | breakpoint_up location_breakpoint; |
cfc31633 PA |
10907 | |
10908 | /* Breakpoint set at the return address in the caller frame. May be | |
10909 | NULL. */ | |
46e3ed7f | 10910 | breakpoint_up caller_breakpoint; |
cfc31633 | 10911 | |
46e3ed7f TT |
10912 | until_break_fsm (struct interp *cmd_interp, int thread, |
10913 | breakpoint_up &&location_breakpoint, | |
10914 | breakpoint_up &&caller_breakpoint) | |
10915 | : thread_fsm (cmd_interp), | |
10916 | thread (thread), | |
10917 | location_breakpoint (std::move (location_breakpoint)), | |
10918 | caller_breakpoint (std::move (caller_breakpoint)) | |
10919 | { | |
10920 | } | |
cfc31633 | 10921 | |
46e3ed7f TT |
10922 | void clean_up (struct thread_info *thread) override; |
10923 | bool should_stop (struct thread_info *thread) override; | |
10924 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
10925 | }; |
10926 | ||
cfc31633 PA |
10927 | /* Implementation of the 'should_stop' FSM method for the |
10928 | until(location)/advance commands. */ | |
10929 | ||
46e3ed7f TT |
10930 | bool |
10931 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 10932 | { |
cfc31633 | 10933 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10934 | location_breakpoint.get ()) != NULL |
10935 | || (caller_breakpoint != NULL | |
cfc31633 | 10936 | && bpstat_find_breakpoint (tp->control.stop_bpstat, |
46e3ed7f TT |
10937 | caller_breakpoint.get ()) != NULL)) |
10938 | set_finished (); | |
cfc31633 | 10939 | |
46e3ed7f | 10940 | return true; |
cfc31633 PA |
10941 | } |
10942 | ||
10943 | /* Implementation of the 'clean_up' FSM method for the | |
10944 | until(location)/advance commands. */ | |
10945 | ||
46e3ed7f TT |
10946 | void |
10947 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 10948 | { |
cfc31633 | 10949 | /* Clean up our temporary breakpoints. */ |
46e3ed7f TT |
10950 | location_breakpoint.reset (); |
10951 | caller_breakpoint.reset (); | |
10952 | delete_longjmp_breakpoint (thread); | |
cfc31633 PA |
10953 | } |
10954 | ||
10955 | /* Implementation of the 'async_reply_reason' FSM method for the | |
10956 | until(location)/advance commands. */ | |
10957 | ||
46e3ed7f TT |
10958 | enum async_reply_reason |
10959 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
10960 | { |
10961 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
10962 | } |
10963 | ||
c906108c | 10964 | void |
f2fc3015 | 10965 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 10966 | { |
8556afb4 PA |
10967 | struct frame_info *frame; |
10968 | struct gdbarch *frame_gdbarch; | |
10969 | struct frame_id stack_frame_id; | |
10970 | struct frame_id caller_frame_id; | |
186c406b TT |
10971 | int thread; |
10972 | struct thread_info *tp; | |
c906108c | 10973 | |
70509625 | 10974 | clear_proceed_status (0); |
c906108c SS |
10975 | |
10976 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 10977 | this function. */ |
c5aa993b | 10978 | |
ffc2605c | 10979 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 10980 | |
6c5b2ebe PA |
10981 | std::vector<symtab_and_line> sals |
10982 | = (last_displayed_sal_is_valid () | |
10983 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
10984 | get_last_displayed_symtab (), | |
10985 | get_last_displayed_line ()) | |
10986 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 10987 | NULL, NULL, 0)); |
c5aa993b | 10988 | |
6c5b2ebe | 10989 | if (sals.size () != 1) |
8a3fe4f8 | 10990 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 10991 | |
6c5b2ebe | 10992 | symtab_and_line &sal = sals[0]; |
c5aa993b | 10993 | |
c906108c | 10994 | if (*arg) |
8a3fe4f8 | 10995 | error (_("Junk at end of arguments.")); |
c5aa993b | 10996 | |
c906108c | 10997 | resolve_sal_pc (&sal); |
c5aa993b | 10998 | |
186c406b | 10999 | tp = inferior_thread (); |
5d5658a1 | 11000 | thread = tp->global_num; |
186c406b | 11001 | |
8556afb4 PA |
11002 | /* Note linespec handling above invalidates the frame chain. |
11003 | Installing a breakpoint also invalidates the frame chain (as it | |
11004 | may need to switch threads), so do any frame handling before | |
11005 | that. */ | |
11006 | ||
11007 | frame = get_selected_frame (NULL); | |
11008 | frame_gdbarch = get_frame_arch (frame); | |
11009 | stack_frame_id = get_stack_frame_id (frame); | |
11010 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11011 | |
ae66c1fc EZ |
11012 | /* Keep within the current frame, or in frames called by the current |
11013 | one. */ | |
edb3359d | 11014 | |
454dafbd | 11015 | breakpoint_up caller_breakpoint; |
5419bdae TT |
11016 | |
11017 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
11018 | ||
883bc8d1 | 11019 | if (frame_id_p (caller_frame_id)) |
c906108c | 11020 | { |
883bc8d1 | 11021 | struct symtab_and_line sal2; |
cfc31633 | 11022 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11023 | |
11024 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11025 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11026 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11027 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11028 | sal2, | |
11029 | caller_frame_id, | |
11030 | bp_until); | |
186c406b | 11031 | |
883bc8d1 | 11032 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 11033 | lj_deleter.emplace (thread); |
c906108c | 11034 | } |
c5aa993b | 11035 | |
c70a6932 JK |
11036 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11037 | frame = NULL; | |
11038 | ||
454dafbd | 11039 | breakpoint_up location_breakpoint; |
883bc8d1 PA |
11040 | if (anywhere) |
11041 | /* If the user told us to continue until a specified location, | |
11042 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11043 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11044 | null_frame_id, bp_until); | |
883bc8d1 PA |
11045 | else |
11046 | /* Otherwise, specify the selected frame, because we want to stop | |
11047 | only at the very same frame. */ | |
cfc31633 PA |
11048 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11049 | stack_frame_id, bp_until); | |
883bc8d1 | 11050 | |
46e3ed7f TT |
11051 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
11052 | std::move (location_breakpoint), | |
11053 | std::move (caller_breakpoint)); | |
f107f563 | 11054 | |
5419bdae TT |
11055 | if (lj_deleter) |
11056 | lj_deleter->release (); | |
f107f563 | 11057 | |
cfc31633 | 11058 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11059 | } |
ae66c1fc | 11060 | |
c906108c SS |
11061 | /* This function attempts to parse an optional "if <cond>" clause |
11062 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11063 | |
c906108c SS |
11064 | Else, it returns a pointer to the condition string. (It does not |
11065 | attempt to evaluate the string against a particular block.) And, | |
11066 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11067 | if clause in the arg string. */ |
53a5351d | 11068 | |
63160a43 PA |
11069 | const char * |
11070 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11071 | { |
63160a43 | 11072 | const char *cond_string; |
c5aa993b JM |
11073 | |
11074 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11075 | return NULL; |
c5aa993b | 11076 | |
4a64f543 | 11077 | /* Skip the "if" keyword. */ |
c906108c | 11078 | (*arg) += 2; |
c5aa993b | 11079 | |
c906108c | 11080 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11081 | condition string. */ |
f1735a53 | 11082 | *arg = skip_spaces (*arg); |
c906108c | 11083 | cond_string = *arg; |
c5aa993b | 11084 | |
4a64f543 MS |
11085 | /* Assume that the condition occupies the remainder of the arg |
11086 | string. */ | |
c906108c | 11087 | (*arg) += strlen (cond_string); |
c5aa993b | 11088 | |
c906108c SS |
11089 | return cond_string; |
11090 | } | |
c5aa993b | 11091 | |
c906108c SS |
11092 | /* Commands to deal with catching events, such as signals, exceptions, |
11093 | process start/exit, etc. */ | |
c5aa993b JM |
11094 | |
11095 | typedef enum | |
11096 | { | |
44feb3ce TT |
11097 | catch_fork_temporary, catch_vfork_temporary, |
11098 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11099 | } |
11100 | catch_fork_kind; | |
11101 | ||
c906108c | 11102 | static void |
eb4c3f4a | 11103 | catch_fork_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11104 | struct cmd_list_element *command) |
c906108c | 11105 | { |
a6d9a66e | 11106 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11107 | const char *cond_string = NULL; |
44feb3ce TT |
11108 | catch_fork_kind fork_kind; |
11109 | int tempflag; | |
11110 | ||
11111 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11112 | tempflag = (fork_kind == catch_fork_temporary | |
11113 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11114 | |
44feb3ce TT |
11115 | if (!arg) |
11116 | arg = ""; | |
f1735a53 | 11117 | arg = skip_spaces (arg); |
c5aa993b | 11118 | |
c906108c | 11119 | /* The allowed syntax is: |
c5aa993b JM |
11120 | catch [v]fork |
11121 | catch [v]fork if <cond> | |
11122 | ||
4a64f543 | 11123 | First, check if there's an if clause. */ |
c906108c | 11124 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11125 | |
c906108c | 11126 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11127 | error (_("Junk at end of arguments.")); |
c5aa993b | 11128 | |
c906108c | 11129 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11130 | and enable reporting of such events. */ |
c5aa993b JM |
11131 | switch (fork_kind) |
11132 | { | |
44feb3ce TT |
11133 | case catch_fork_temporary: |
11134 | case catch_fork_permanent: | |
a6d9a66e | 11135 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11136 | &catch_fork_breakpoint_ops); |
c906108c | 11137 | break; |
44feb3ce TT |
11138 | case catch_vfork_temporary: |
11139 | case catch_vfork_permanent: | |
a6d9a66e | 11140 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11141 | &catch_vfork_breakpoint_ops); |
c906108c | 11142 | break; |
c5aa993b | 11143 | default: |
8a3fe4f8 | 11144 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11145 | break; |
c5aa993b | 11146 | } |
c906108c SS |
11147 | } |
11148 | ||
11149 | static void | |
eb4c3f4a | 11150 | catch_exec_command_1 (const char *arg, int from_tty, |
cc59ec59 | 11151 | struct cmd_list_element *command) |
c906108c | 11152 | { |
a6d9a66e | 11153 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11154 | int tempflag; |
63160a43 | 11155 | const char *cond_string = NULL; |
c906108c | 11156 | |
44feb3ce TT |
11157 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11158 | ||
11159 | if (!arg) | |
11160 | arg = ""; | |
f1735a53 | 11161 | arg = skip_spaces (arg); |
c906108c SS |
11162 | |
11163 | /* The allowed syntax is: | |
c5aa993b JM |
11164 | catch exec |
11165 | catch exec if <cond> | |
c906108c | 11166 | |
4a64f543 | 11167 | First, check if there's an if clause. */ |
c906108c SS |
11168 | cond_string = ep_parse_optional_if_clause (&arg); |
11169 | ||
11170 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11171 | error (_("Junk at end of arguments.")); |
c906108c | 11172 | |
b270e6f9 TT |
11173 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11174 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11175 | &catch_exec_breakpoint_ops); |
11176 | c->exec_pathname = NULL; | |
11177 | ||
b270e6f9 | 11178 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11179 | } |
c5aa993b | 11180 | |
9ac4176b | 11181 | void |
28010a5d PA |
11182 | init_ada_exception_breakpoint (struct breakpoint *b, |
11183 | struct gdbarch *gdbarch, | |
11184 | struct symtab_and_line sal, | |
f2fc3015 | 11185 | const char *addr_string, |
c0a91b2b | 11186 | const struct breakpoint_ops *ops, |
28010a5d | 11187 | int tempflag, |
349774ef | 11188 | int enabled, |
28010a5d | 11189 | int from_tty) |
f7f9143b | 11190 | { |
f7f9143b JB |
11191 | if (from_tty) |
11192 | { | |
5af949e3 UW |
11193 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11194 | if (!loc_gdbarch) | |
11195 | loc_gdbarch = gdbarch; | |
11196 | ||
6c95b8df PA |
11197 | describe_other_breakpoints (loc_gdbarch, |
11198 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11199 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11200 | version for exception catchpoints, because two catchpoints | |
11201 | used for different exception names will use the same address. | |
11202 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11203 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11204 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11205 | the user what type of catchpoint it is. The above is good |
11206 | enough for now, though. */ | |
11207 | } | |
11208 | ||
f06f1252 | 11209 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
f7f9143b | 11210 | |
349774ef | 11211 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11212 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11213 | b->location = string_to_event_location (&addr_string, |
11214 | language_def (language_ada)); | |
f7f9143b | 11215 | b->language = language_ada; |
f7f9143b JB |
11216 | } |
11217 | ||
c906108c | 11218 | static void |
981a3fb3 | 11219 | catch_command (const char *arg, int from_tty) |
c906108c | 11220 | { |
44feb3ce | 11221 | error (_("Catch requires an event name.")); |
c906108c SS |
11222 | } |
11223 | \f | |
11224 | ||
11225 | static void | |
981a3fb3 | 11226 | tcatch_command (const char *arg, int from_tty) |
c906108c | 11227 | { |
44feb3ce | 11228 | error (_("Catch requires an event name.")); |
c906108c SS |
11229 | } |
11230 | ||
81b1e71c | 11231 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
11232 | |
11233 | static int | |
81b1e71c | 11234 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 11235 | { |
81b1e71c TT |
11236 | uintptr_t ua = (uintptr_t) a; |
11237 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 11238 | |
81b1e71c | 11239 | if (a->number < b->number) |
8a2c437b | 11240 | return -1; |
81b1e71c | 11241 | else if (a->number > b->number) |
8a2c437b TT |
11242 | return 1; |
11243 | ||
11244 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11245 | the number 0. */ | |
11246 | if (ua < ub) | |
11247 | return -1; | |
94b0e70d | 11248 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11249 | } |
11250 | ||
80f8a6eb | 11251 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11252 | |
11253 | static void | |
0b39b52e | 11254 | clear_command (const char *arg, int from_tty) |
c906108c | 11255 | { |
81b1e71c | 11256 | struct breakpoint *b; |
c906108c | 11257 | int default_match; |
c906108c | 11258 | |
6c5b2ebe PA |
11259 | std::vector<symtab_and_line> decoded_sals; |
11260 | symtab_and_line last_sal; | |
11261 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11262 | if (arg) |
11263 | { | |
6c5b2ebe PA |
11264 | decoded_sals |
11265 | = decode_line_with_current_source (arg, | |
11266 | (DECODE_LINE_FUNFIRSTLINE | |
11267 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11268 | default_match = 0; |
6c5b2ebe | 11269 | sals = decoded_sals; |
c906108c SS |
11270 | } |
11271 | else | |
11272 | { | |
1bfeeb0f JL |
11273 | /* Set sal's line, symtab, pc, and pspace to the values |
11274 | corresponding to the last call to print_frame_info. If the | |
11275 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11276 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11277 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11278 | error (_("No source file specified.")); |
c906108c | 11279 | |
c906108c | 11280 | default_match = 1; |
6c5b2ebe | 11281 | sals = last_sal; |
c906108c SS |
11282 | } |
11283 | ||
4a64f543 MS |
11284 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11285 | seems, because all existing breakpoints typically have both | |
11286 | file/line and pc set. So, if clear is given file/line, we can | |
11287 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11288 | |
11289 | We only support clearing given the address explicitly | |
11290 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11291 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11292 | due to optimization, all in one block. |
4a64f543 MS |
11293 | |
11294 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11295 | PC corresponding to the same file:line, the breakpoint won't |
11296 | be cleared. We probably can still clear the breakpoint, but | |
11297 | since the other PC value is never presented to user, user | |
11298 | can only find it by guessing, and it does not seem important | |
11299 | to support that. */ | |
11300 | ||
4a64f543 MS |
11301 | /* For each line spec given, delete bps which correspond to it. Do |
11302 | it in two passes, solely to preserve the current behavior that | |
11303 | from_tty is forced true if we delete more than one | |
11304 | breakpoint. */ | |
c906108c | 11305 | |
81b1e71c | 11306 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 11307 | for (const auto &sal : sals) |
c906108c | 11308 | { |
05cba821 JK |
11309 | const char *sal_fullname; |
11310 | ||
c906108c | 11311 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11312 | If line given (pc == 0), clear all bpts on specified line. |
11313 | If defaulting, clear all bpts on default line | |
c906108c | 11314 | or at default pc. |
c5aa993b JM |
11315 | |
11316 | defaulting sal.pc != 0 tests to do | |
11317 | ||
11318 | 0 1 pc | |
11319 | 1 1 pc _and_ line | |
11320 | 0 0 line | |
11321 | 1 0 <can't happen> */ | |
c906108c | 11322 | |
05cba821 JK |
11323 | sal_fullname = (sal.symtab == NULL |
11324 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11325 | |
4a64f543 | 11326 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11327 | ALL_BREAKPOINTS (b) |
c5aa993b | 11328 | { |
0d381245 | 11329 | int match = 0; |
4a64f543 | 11330 | /* Are we going to delete b? */ |
cc60f2e3 | 11331 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11332 | { |
11333 | struct bp_location *loc = b->loc; | |
11334 | for (; loc; loc = loc->next) | |
11335 | { | |
f8eba3c6 TT |
11336 | /* If the user specified file:line, don't allow a PC |
11337 | match. This matches historical gdb behavior. */ | |
11338 | int pc_match = (!sal.explicit_line | |
11339 | && sal.pc | |
11340 | && (loc->pspace == sal.pspace) | |
11341 | && (loc->address == sal.pc) | |
11342 | && (!section_is_overlay (loc->section) | |
11343 | || loc->section == sal.section)); | |
4aac40c8 TT |
11344 | int line_match = 0; |
11345 | ||
11346 | if ((default_match || sal.explicit_line) | |
2f202fde | 11347 | && loc->symtab != NULL |
05cba821 | 11348 | && sal_fullname != NULL |
4aac40c8 | 11349 | && sal.pspace == loc->pspace |
05cba821 JK |
11350 | && loc->line_number == sal.line |
11351 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11352 | sal_fullname) == 0) | |
11353 | line_match = 1; | |
4aac40c8 | 11354 | |
0d381245 VP |
11355 | if (pc_match || line_match) |
11356 | { | |
11357 | match = 1; | |
11358 | break; | |
11359 | } | |
11360 | } | |
11361 | } | |
11362 | ||
11363 | if (match) | |
81b1e71c | 11364 | found.push_back (b); |
c906108c | 11365 | } |
80f8a6eb | 11366 | } |
8a2c437b | 11367 | |
80f8a6eb | 11368 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 11369 | if (found.empty ()) |
80f8a6eb MS |
11370 | { |
11371 | if (arg) | |
8a3fe4f8 | 11372 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11373 | else |
8a3fe4f8 | 11374 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11375 | } |
c906108c | 11376 | |
8a2c437b | 11377 | /* Remove duplicates from the vec. */ |
81b1e71c | 11378 | std::sort (found.begin (), found.end (), |
b926417a | 11379 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11380 | { |
b926417a | 11381 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
11382 | }); |
11383 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 11384 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 11385 | { |
b926417a | 11386 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
11387 | }), |
11388 | found.end ()); | |
8a2c437b | 11389 | |
81b1e71c | 11390 | if (found.size () > 1) |
4a64f543 | 11391 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11392 | if (from_tty) |
a3f17187 | 11393 | { |
81b1e71c | 11394 | if (found.size () == 1) |
a3f17187 AC |
11395 | printf_unfiltered (_("Deleted breakpoint ")); |
11396 | else | |
11397 | printf_unfiltered (_("Deleted breakpoints ")); | |
11398 | } | |
d6e956e5 | 11399 | |
81b1e71c | 11400 | for (breakpoint *iter : found) |
80f8a6eb | 11401 | { |
c5aa993b | 11402 | if (from_tty) |
81b1e71c TT |
11403 | printf_unfiltered ("%d ", iter->number); |
11404 | delete_breakpoint (iter); | |
c906108c | 11405 | } |
80f8a6eb MS |
11406 | if (from_tty) |
11407 | putchar_unfiltered ('\n'); | |
c906108c SS |
11408 | } |
11409 | \f | |
11410 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11411 | all breakpoints that are marked for deletion, whether hit or not. | |
11412 | This is called after any breakpoint is hit, or after errors. */ | |
11413 | ||
11414 | void | |
fba45db2 | 11415 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11416 | { |
35df4500 | 11417 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11418 | |
11419 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11420 | if (bs->breakpoint_at |
11421 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11422 | && bs->stop) |
f431efe5 | 11423 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11424 | |
35df4500 | 11425 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11426 | { |
b5de0fa7 | 11427 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11428 | delete_breakpoint (b); |
11429 | } | |
c906108c SS |
11430 | } |
11431 | ||
4a64f543 | 11432 | /* A comparison function for bp_location AP and BP being interfaced to |
39ef2f62 | 11433 | std::sort. Sort elements primarily by their ADDRESS (no matter what |
cb1e4e32 PA |
11434 | bl_address_is_meaningful says), secondarily by ordering first |
11435 | permanent elements and terciarily just ensuring the array is sorted | |
39ef2f62 | 11436 | stable way despite std::sort being an unstable algorithm. */ |
876fa593 JK |
11437 | |
11438 | static int | |
39ef2f62 | 11439 | bp_location_is_less_than (const bp_location *a, const bp_location *b) |
876fa593 | 11440 | { |
876fa593 | 11441 | if (a->address != b->address) |
39ef2f62 | 11442 | return a->address < b->address; |
876fa593 | 11443 | |
dea2aa5f LM |
11444 | /* Sort locations at the same address by their pspace number, keeping |
11445 | locations of the same inferior (in a multi-inferior environment) | |
11446 | grouped. */ | |
11447 | ||
11448 | if (a->pspace->num != b->pspace->num) | |
39ef2f62 | 11449 | return a->pspace->num < b->pspace->num; |
dea2aa5f | 11450 | |
876fa593 | 11451 | /* Sort permanent breakpoints first. */ |
1a853c52 | 11452 | if (a->permanent != b->permanent) |
39ef2f62 | 11453 | return a->permanent > b->permanent; |
876fa593 | 11454 | |
c56a97f9 JK |
11455 | /* Make the internal GDB representation stable across GDB runs |
11456 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11457 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11458 | |
11459 | if (a->owner->number != b->owner->number) | |
39ef2f62 | 11460 | return a->owner->number < b->owner->number; |
876fa593 | 11461 | |
39ef2f62 | 11462 | return a < b; |
876fa593 JK |
11463 | } |
11464 | ||
f5336ca5 PA |
11465 | /* Set bp_locations_placed_address_before_address_max and |
11466 | bp_locations_shadow_len_after_address_max according to the current | |
11467 | content of the bp_locations array. */ | |
f7545552 TT |
11468 | |
11469 | static void | |
f5336ca5 | 11470 | bp_locations_target_extensions_update (void) |
f7545552 | 11471 | { |
876fa593 JK |
11472 | struct bp_location *bl, **blp_tmp; |
11473 | ||
f5336ca5 PA |
11474 | bp_locations_placed_address_before_address_max = 0; |
11475 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11476 | |
11477 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11478 | { | |
11479 | CORE_ADDR start, end, addr; | |
11480 | ||
11481 | if (!bp_location_has_shadow (bl)) | |
11482 | continue; | |
11483 | ||
11484 | start = bl->target_info.placed_address; | |
11485 | end = start + bl->target_info.shadow_len; | |
11486 | ||
11487 | gdb_assert (bl->address >= start); | |
11488 | addr = bl->address - start; | |
f5336ca5 PA |
11489 | if (addr > bp_locations_placed_address_before_address_max) |
11490 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11491 | |
11492 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11493 | ||
11494 | gdb_assert (bl->address < end); | |
11495 | addr = end - bl->address; | |
f5336ca5 PA |
11496 | if (addr > bp_locations_shadow_len_after_address_max) |
11497 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11498 | } |
f7545552 TT |
11499 | } |
11500 | ||
1e4d1764 YQ |
11501 | /* Download tracepoint locations if they haven't been. */ |
11502 | ||
11503 | static void | |
11504 | download_tracepoint_locations (void) | |
11505 | { | |
7ed2c994 | 11506 | struct breakpoint *b; |
dd2e65cc | 11507 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11508 | |
5ed8105e | 11509 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11510 | |
7ed2c994 | 11511 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11512 | { |
7ed2c994 | 11513 | struct bp_location *bl; |
1e4d1764 | 11514 | struct tracepoint *t; |
f2a8bc8a | 11515 | int bp_location_downloaded = 0; |
1e4d1764 | 11516 | |
7ed2c994 | 11517 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11518 | ? !may_insert_fast_tracepoints |
11519 | : !may_insert_tracepoints)) | |
11520 | continue; | |
11521 | ||
dd2e65cc YQ |
11522 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11523 | { | |
11524 | if (target_can_download_tracepoint ()) | |
11525 | can_download_tracepoint = TRIBOOL_TRUE; | |
11526 | else | |
11527 | can_download_tracepoint = TRIBOOL_FALSE; | |
11528 | } | |
11529 | ||
11530 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11531 | break; | |
11532 | ||
7ed2c994 YQ |
11533 | for (bl = b->loc; bl; bl = bl->next) |
11534 | { | |
11535 | /* In tracepoint, locations are _never_ duplicated, so | |
11536 | should_be_inserted is equivalent to | |
11537 | unduplicated_should_be_inserted. */ | |
11538 | if (!should_be_inserted (bl) || bl->inserted) | |
11539 | continue; | |
1e4d1764 | 11540 | |
7ed2c994 | 11541 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11542 | |
7ed2c994 | 11543 | target_download_tracepoint (bl); |
1e4d1764 | 11544 | |
7ed2c994 | 11545 | bl->inserted = 1; |
f2a8bc8a | 11546 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11547 | } |
11548 | t = (struct tracepoint *) b; | |
11549 | t->number_on_target = b->number; | |
f2a8bc8a | 11550 | if (bp_location_downloaded) |
76727919 | 11551 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11552 | } |
1e4d1764 YQ |
11553 | } |
11554 | ||
934709f0 PW |
11555 | /* Swap the insertion/duplication state between two locations. */ |
11556 | ||
11557 | static void | |
11558 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11559 | { | |
11560 | const int left_inserted = left->inserted; | |
11561 | const int left_duplicate = left->duplicate; | |
b775012e | 11562 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11563 | const struct bp_target_info left_target_info = left->target_info; |
11564 | ||
1e4d1764 YQ |
11565 | /* Locations of tracepoints can never be duplicated. */ |
11566 | if (is_tracepoint (left->owner)) | |
11567 | gdb_assert (!left->duplicate); | |
11568 | if (is_tracepoint (right->owner)) | |
11569 | gdb_assert (!right->duplicate); | |
11570 | ||
934709f0 PW |
11571 | left->inserted = right->inserted; |
11572 | left->duplicate = right->duplicate; | |
b775012e | 11573 | left->needs_update = right->needs_update; |
934709f0 PW |
11574 | left->target_info = right->target_info; |
11575 | right->inserted = left_inserted; | |
11576 | right->duplicate = left_duplicate; | |
b775012e | 11577 | right->needs_update = left_needs_update; |
934709f0 PW |
11578 | right->target_info = left_target_info; |
11579 | } | |
11580 | ||
b775012e LM |
11581 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11582 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11583 | conditions on the target's side. Such conditions need to be updated on | |
11584 | the target. */ | |
11585 | ||
11586 | static void | |
11587 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11588 | { | |
11589 | struct bp_location **locp = NULL, **loc2p; | |
11590 | struct bp_location *loc; | |
11591 | CORE_ADDR address = 0; | |
11592 | int pspace_num; | |
11593 | ||
11594 | address = bl->address; | |
11595 | pspace_num = bl->pspace->num; | |
11596 | ||
11597 | /* This is only meaningful if the target is | |
11598 | evaluating conditions and if the user has | |
11599 | opted for condition evaluation on the target's | |
11600 | side. */ | |
11601 | if (gdb_evaluates_breakpoint_condition_p () | |
11602 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11603 | return; | |
11604 | ||
11605 | /* Flag all breakpoint locations with this address and | |
11606 | the same program space as the location | |
11607 | as "its condition has changed". We need to | |
11608 | update the conditions on the target's side. */ | |
11609 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
11610 | { | |
11611 | loc = *loc2p; | |
11612 | ||
11613 | if (!is_breakpoint (loc->owner) | |
11614 | || pspace_num != loc->pspace->num) | |
11615 | continue; | |
11616 | ||
11617 | /* Flag the location appropriately. We use a different state to | |
11618 | let everyone know that we already updated the set of locations | |
11619 | with addr bl->address and program space bl->pspace. This is so | |
11620 | we don't have to keep calling these functions just to mark locations | |
11621 | that have already been marked. */ | |
11622 | loc->condition_changed = condition_updated; | |
11623 | ||
11624 | /* Free the agent expression bytecode as well. We will compute | |
11625 | it later on. */ | |
833177a4 | 11626 | loc->cond_bytecode.reset (); |
b775012e LM |
11627 | } |
11628 | } | |
44702360 PA |
11629 | /* Called whether new breakpoints are created, or existing breakpoints |
11630 | deleted, to update the global location list and recompute which | |
11631 | locations are duplicate of which. | |
b775012e | 11632 | |
04086b45 PA |
11633 | The INSERT_MODE flag determines whether locations may not, may, or |
11634 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11635 | info. */ | |
b60e7edf | 11636 | |
0d381245 | 11637 | static void |
44702360 | 11638 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11639 | { |
74960c60 | 11640 | struct breakpoint *b; |
876fa593 | 11641 | struct bp_location **locp, *loc; |
b775012e LM |
11642 | /* Last breakpoint location address that was marked for update. */ |
11643 | CORE_ADDR last_addr = 0; | |
11644 | /* Last breakpoint location program space that was marked for update. */ | |
11645 | int last_pspace_num = -1; | |
f7545552 | 11646 | |
2d134ed3 PA |
11647 | /* Used in the duplicates detection below. When iterating over all |
11648 | bp_locations, points to the first bp_location of a given address. | |
11649 | Breakpoints and watchpoints of different types are never | |
11650 | duplicates of each other. Keep one pointer for each type of | |
11651 | breakpoint/watchpoint, so we only need to loop over all locations | |
11652 | once. */ | |
11653 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11654 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11655 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11656 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11657 | |
f5336ca5 PA |
11658 | /* Saved former bp_locations array which we compare against the newly |
11659 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
81b1e71c | 11660 | struct bp_location **old_locp; |
f5336ca5 | 11661 | unsigned old_locations_count; |
81b1e71c | 11662 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
876fa593 | 11663 | |
f5336ca5 PA |
11664 | old_locations_count = bp_locations_count; |
11665 | bp_locations = NULL; | |
11666 | bp_locations_count = 0; | |
0d381245 | 11667 | |
74960c60 | 11668 | ALL_BREAKPOINTS (b) |
876fa593 | 11669 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 11670 | bp_locations_count++; |
876fa593 | 11671 | |
f5336ca5 PA |
11672 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
11673 | locp = bp_locations; | |
876fa593 JK |
11674 | ALL_BREAKPOINTS (b) |
11675 | for (loc = b->loc; loc; loc = loc->next) | |
11676 | *locp++ = loc; | |
39ef2f62 CB |
11677 | std::sort (bp_locations, bp_locations + bp_locations_count, |
11678 | bp_location_is_less_than); | |
876fa593 | 11679 | |
f5336ca5 | 11680 | bp_locations_target_extensions_update (); |
74960c60 | 11681 | |
4a64f543 MS |
11682 | /* Identify bp_location instances that are no longer present in the |
11683 | new list, and therefore should be freed. Note that it's not | |
11684 | necessary that those locations should be removed from inferior -- | |
11685 | if there's another location at the same address (previously | |
11686 | marked as duplicate), we don't need to remove/insert the | |
11687 | location. | |
876fa593 | 11688 | |
4a64f543 MS |
11689 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11690 | and former bp_location array state respectively. */ | |
876fa593 | 11691 | |
f5336ca5 | 11692 | locp = bp_locations; |
81b1e71c TT |
11693 | for (old_locp = old_locations.get (); |
11694 | old_locp < old_locations.get () + old_locations_count; | |
876fa593 | 11695 | old_locp++) |
74960c60 | 11696 | { |
876fa593 | 11697 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 11698 | struct bp_location **loc2p; |
876fa593 | 11699 | |
e5dd4106 | 11700 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11701 | not, we have to free it. */ |
c7d46a38 | 11702 | int found_object = 0; |
20874c92 VP |
11703 | /* Tells if the location should remain inserted in the target. */ |
11704 | int keep_in_target = 0; | |
11705 | int removed = 0; | |
876fa593 | 11706 | |
4a64f543 MS |
11707 | /* Skip LOCP entries which will definitely never be needed. |
11708 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 11709 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 11710 | && (*locp)->address < old_loc->address) |
876fa593 | 11711 | locp++; |
c7d46a38 PA |
11712 | |
11713 | for (loc2p = locp; | |
f5336ca5 | 11714 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
11715 | && (*loc2p)->address == old_loc->address); |
11716 | loc2p++) | |
11717 | { | |
b775012e LM |
11718 | /* Check if this is a new/duplicated location or a duplicated |
11719 | location that had its condition modified. If so, we want to send | |
11720 | its condition to the target if evaluation of conditions is taking | |
11721 | place there. */ | |
11722 | if ((*loc2p)->condition_changed == condition_modified | |
11723 | && (last_addr != old_loc->address | |
11724 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11725 | { |
b775012e LM |
11726 | force_breakpoint_reinsertion (*loc2p); |
11727 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 11728 | } |
b775012e LM |
11729 | |
11730 | if (*loc2p == old_loc) | |
11731 | found_object = 1; | |
c7d46a38 | 11732 | } |
74960c60 | 11733 | |
b775012e LM |
11734 | /* We have already handled this address, update it so that we don't |
11735 | have to go through updates again. */ | |
11736 | last_addr = old_loc->address; | |
11737 | ||
11738 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11739 | if (!found_object) | |
11740 | force_breakpoint_reinsertion (old_loc); | |
11741 | ||
4a64f543 MS |
11742 | /* If this location is no longer present, and inserted, look if |
11743 | there's maybe a new location at the same address. If so, | |
11744 | mark that one inserted, and don't remove this one. This is | |
11745 | needed so that we don't have a time window where a breakpoint | |
11746 | at certain location is not inserted. */ | |
74960c60 | 11747 | |
876fa593 | 11748 | if (old_loc->inserted) |
0d381245 | 11749 | { |
4a64f543 MS |
11750 | /* If the location is inserted now, we might have to remove |
11751 | it. */ | |
74960c60 | 11752 | |
876fa593 | 11753 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11754 | { |
4a64f543 MS |
11755 | /* The location is still present in the location list, |
11756 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11757 | keep_in_target = 1; |
74960c60 VP |
11758 | } |
11759 | else | |
11760 | { | |
b775012e LM |
11761 | /* This location still exists, but it won't be kept in the |
11762 | target since it may have been disabled. We proceed to | |
11763 | remove its target-side condition. */ | |
11764 | ||
4a64f543 MS |
11765 | /* The location is either no longer present, or got |
11766 | disabled. See if there's another location at the | |
11767 | same address, in which case we don't need to remove | |
11768 | this one from the target. */ | |
876fa593 | 11769 | |
2bdf28a0 | 11770 | /* OLD_LOC comes from existing struct breakpoint. */ |
cb1e4e32 | 11771 | if (bl_address_is_meaningful (old_loc)) |
876fa593 | 11772 | { |
876fa593 | 11773 | for (loc2p = locp; |
f5336ca5 | 11774 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 11775 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
11776 | loc2p++) |
11777 | { | |
11778 | struct bp_location *loc2 = *loc2p; | |
11779 | ||
2d134ed3 | 11780 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11781 | { |
85d721b8 PA |
11782 | /* Read watchpoint locations are switched to |
11783 | access watchpoints, if the former are not | |
11784 | supported, but the latter are. */ | |
11785 | if (is_hardware_watchpoint (old_loc->owner)) | |
11786 | { | |
11787 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11788 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11789 | } | |
11790 | ||
934709f0 PW |
11791 | /* loc2 is a duplicated location. We need to check |
11792 | if it should be inserted in case it will be | |
11793 | unduplicated. */ | |
11794 | if (loc2 != old_loc | |
11795 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 11796 | { |
934709f0 | 11797 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11798 | keep_in_target = 1; |
11799 | break; | |
11800 | } | |
876fa593 JK |
11801 | } |
11802 | } | |
11803 | } | |
74960c60 VP |
11804 | } |
11805 | ||
20874c92 VP |
11806 | if (!keep_in_target) |
11807 | { | |
834c0d03 | 11808 | if (remove_breakpoint (old_loc)) |
20874c92 | 11809 | { |
4a64f543 MS |
11810 | /* This is just about all we can do. We could keep |
11811 | this location on the global list, and try to | |
11812 | remove it next time, but there's no particular | |
11813 | reason why we will succeed next time. | |
20874c92 | 11814 | |
4a64f543 MS |
11815 | Note that at this point, old_loc->owner is still |
11816 | valid, as delete_breakpoint frees the breakpoint | |
11817 | only after calling us. */ | |
3e43a32a MS |
11818 | printf_filtered (_("warning: Error removing " |
11819 | "breakpoint %d\n"), | |
876fa593 | 11820 | old_loc->owner->number); |
20874c92 VP |
11821 | } |
11822 | removed = 1; | |
11823 | } | |
0d381245 | 11824 | } |
74960c60 VP |
11825 | |
11826 | if (!found_object) | |
1c5cfe86 | 11827 | { |
fbea99ea | 11828 | if (removed && target_is_non_stop_p () |
1cf4d951 | 11829 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 11830 | { |
db82e815 PA |
11831 | /* This location was removed from the target. In |
11832 | non-stop mode, a race condition is possible where | |
11833 | we've removed a breakpoint, but stop events for that | |
11834 | breakpoint are already queued and will arrive later. | |
11835 | We apply an heuristic to be able to distinguish such | |
11836 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11837 | breakpoint location for a bit, and will retire it | |
11838 | after we see some number of events. The theory here | |
11839 | is that reporting of events should, "on the average", | |
11840 | be fair, so after a while we'll see events from all | |
11841 | threads that have anything of interest, and no longer | |
11842 | need to keep this breakpoint location around. We | |
11843 | don't hold locations forever so to reduce chances of | |
11844 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11845 | SIGTRAP. | |
11846 | ||
11847 | The heuristic failing can be disastrous on | |
11848 | decr_pc_after_break targets. | |
11849 | ||
11850 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11851 | if we fail to recognize a late breakpoint SIGTRAP, | |
11852 | because events_till_retirement has reached 0 too | |
11853 | soon, we'll fail to do the PC adjustment, and report | |
11854 | a random SIGTRAP to the user. When the user resumes | |
11855 | the inferior, it will most likely immediately crash | |
2dec564e | 11856 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11857 | corrupted, because of being resumed e.g., in the |
11858 | middle of a multi-byte instruction, or skipped a | |
11859 | one-byte instruction. This was actually seen happen | |
11860 | on native x86-linux, and should be less rare on | |
11861 | targets that do not support new thread events, like | |
11862 | remote, due to the heuristic depending on | |
11863 | thread_count. | |
11864 | ||
11865 | Mistaking a random SIGTRAP for a breakpoint trap | |
11866 | causes similar symptoms (PC adjustment applied when | |
11867 | it shouldn't), but then again, playing with SIGTRAPs | |
11868 | behind the debugger's back is asking for trouble. | |
11869 | ||
11870 | Since hardware watchpoint traps are always | |
11871 | distinguishable from other traps, so we don't need to | |
11872 | apply keep hardware watchpoint moribund locations | |
11873 | around. We simply always ignore hardware watchpoint | |
11874 | traps we can no longer explain. */ | |
11875 | ||
5b6d1e4f PA |
11876 | process_stratum_target *proc_target = nullptr; |
11877 | for (inferior *inf : all_inferiors ()) | |
11878 | if (inf->pspace == old_loc->pspace) | |
11879 | { | |
11880 | proc_target = inf->process_target (); | |
11881 | break; | |
11882 | } | |
11883 | if (proc_target != nullptr) | |
11884 | old_loc->events_till_retirement | |
11885 | = 3 * (thread_count (proc_target) + 1); | |
11886 | else | |
11887 | old_loc->events_till_retirement = 1; | |
876fa593 | 11888 | old_loc->owner = NULL; |
20874c92 | 11889 | |
1123588c | 11890 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
11891 | } |
11892 | else | |
f431efe5 PA |
11893 | { |
11894 | old_loc->owner = NULL; | |
11895 | decref_bp_location (&old_loc); | |
11896 | } | |
20874c92 | 11897 | } |
74960c60 | 11898 | } |
1c5cfe86 | 11899 | |
348d480f PA |
11900 | /* Rescan breakpoints at the same address and section, marking the |
11901 | first one as "first" and any others as "duplicates". This is so | |
11902 | that the bpt instruction is only inserted once. If we have a | |
11903 | permanent breakpoint at the same place as BPT, make that one the | |
11904 | official one, and the rest as duplicates. Permanent breakpoints | |
11905 | are sorted first for the same address. | |
11906 | ||
11907 | Do the same for hardware watchpoints, but also considering the | |
11908 | watchpoint's type (regular/access/read) and length. */ | |
11909 | ||
11910 | bp_loc_first = NULL; | |
11911 | wp_loc_first = NULL; | |
11912 | awp_loc_first = NULL; | |
11913 | rwp_loc_first = NULL; | |
11914 | ALL_BP_LOCATIONS (loc, locp) | |
11915 | { | |
11916 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11917 | non-NULL. */ | |
348d480f | 11918 | struct bp_location **loc_first_p; |
d3fbdd86 | 11919 | b = loc->owner; |
348d480f | 11920 | |
6f380991 | 11921 | if (!unduplicated_should_be_inserted (loc) |
cb1e4e32 | 11922 | || !bl_address_is_meaningful (loc) |
1e4d1764 YQ |
11923 | /* Don't detect duplicate for tracepoint locations because they are |
11924 | never duplicated. See the comments in field `duplicate' of | |
11925 | `struct bp_location'. */ | |
348d480f | 11926 | || is_tracepoint (b)) |
b775012e LM |
11927 | { |
11928 | /* Clear the condition modification flag. */ | |
11929 | loc->condition_changed = condition_unchanged; | |
11930 | continue; | |
11931 | } | |
348d480f | 11932 | |
348d480f PA |
11933 | if (b->type == bp_hardware_watchpoint) |
11934 | loc_first_p = &wp_loc_first; | |
11935 | else if (b->type == bp_read_watchpoint) | |
11936 | loc_first_p = &rwp_loc_first; | |
11937 | else if (b->type == bp_access_watchpoint) | |
11938 | loc_first_p = &awp_loc_first; | |
11939 | else | |
11940 | loc_first_p = &bp_loc_first; | |
11941 | ||
11942 | if (*loc_first_p == NULL | |
11943 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11944 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11945 | { | |
11946 | *loc_first_p = loc; | |
11947 | loc->duplicate = 0; | |
b775012e LM |
11948 | |
11949 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11950 | { | |
11951 | loc->needs_update = 1; | |
11952 | /* Clear the condition modification flag. */ | |
11953 | loc->condition_changed = condition_unchanged; | |
11954 | } | |
348d480f PA |
11955 | continue; |
11956 | } | |
11957 | ||
934709f0 PW |
11958 | |
11959 | /* This and the above ensure the invariant that the first location | |
11960 | is not duplicated, and is the inserted one. | |
11961 | All following are marked as duplicated, and are not inserted. */ | |
11962 | if (loc->inserted) | |
11963 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11964 | loc->duplicate = 1; |
11965 | ||
b775012e LM |
11966 | /* Clear the condition modification flag. */ |
11967 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
11968 | } |
11969 | ||
a25a5a45 | 11970 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 11971 | { |
04086b45 | 11972 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
11973 | insert_breakpoint_locations (); |
11974 | else | |
11975 | { | |
44702360 PA |
11976 | /* Even though the caller told us to not insert new |
11977 | locations, we may still need to update conditions on the | |
11978 | target's side of breakpoints that were already inserted | |
11979 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
11980 | only update conditions for locations that are marked |
11981 | "needs_update". */ | |
11982 | update_inserted_breakpoint_locations (); | |
11983 | } | |
11984 | } | |
348d480f | 11985 | |
04086b45 | 11986 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 11987 | download_tracepoint_locations (); |
348d480f PA |
11988 | } |
11989 | ||
11990 | void | |
11991 | breakpoint_retire_moribund (void) | |
11992 | { | |
1123588c TT |
11993 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
11994 | { | |
11995 | struct bp_location *loc = moribund_locations[ix]; | |
11996 | if (--(loc->events_till_retirement) == 0) | |
11997 | { | |
11998 | decref_bp_location (&loc); | |
11999 | unordered_remove (moribund_locations, ix); | |
12000 | --ix; | |
12001 | } | |
12002 | } | |
348d480f PA |
12003 | } |
12004 | ||
12005 | static void | |
44702360 | 12006 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12007 | { |
348d480f | 12008 | |
a70b8144 | 12009 | try |
492d29ea PA |
12010 | { |
12011 | update_global_location_list (insert_mode); | |
12012 | } | |
230d2906 | 12013 | catch (const gdb_exception_error &e) |
492d29ea PA |
12014 | { |
12015 | } | |
348d480f PA |
12016 | } |
12017 | ||
12018 | /* Clear BKP from a BPS. */ | |
12019 | ||
12020 | static void | |
12021 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12022 | { | |
12023 | bpstat bs; | |
12024 | ||
12025 | for (bs = bps; bs; bs = bs->next) | |
12026 | if (bs->breakpoint_at == bpt) | |
12027 | { | |
12028 | bs->breakpoint_at = NULL; | |
12029 | bs->old_val = NULL; | |
12030 | /* bs->commands will be freed later. */ | |
12031 | } | |
12032 | } | |
12033 | ||
12034 | /* Callback for iterate_over_threads. */ | |
12035 | static int | |
12036 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12037 | { | |
9a3c8263 | 12038 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12039 | |
12040 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12041 | return 0; | |
12042 | } | |
12043 | ||
12044 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12045 | callbacks. */ | |
12046 | ||
12047 | static void | |
12048 | say_where (struct breakpoint *b) | |
12049 | { | |
12050 | struct value_print_options opts; | |
12051 | ||
12052 | get_user_print_options (&opts); | |
12053 | ||
12054 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12055 | single string. */ | |
12056 | if (b->loc == NULL) | |
12057 | { | |
f00aae0f KS |
12058 | /* For pending locations, the output differs slightly based |
12059 | on b->extra_string. If this is non-NULL, it contains either | |
12060 | a condition or dprintf arguments. */ | |
12061 | if (b->extra_string == NULL) | |
12062 | { | |
12063 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12064 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12065 | } |
12066 | else if (b->type == bp_dprintf) | |
12067 | { | |
12068 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12069 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12070 | b->extra_string); |
12071 | } | |
12072 | else | |
12073 | { | |
12074 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12075 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12076 | b->extra_string); |
12077 | } | |
348d480f PA |
12078 | } |
12079 | else | |
12080 | { | |
2f202fde | 12081 | if (opts.addressprint || b->loc->symtab == NULL) |
6a831f06 PA |
12082 | printf_filtered (" at %ps", |
12083 | styled_string (address_style.style (), | |
12084 | paddress (b->loc->gdbarch, | |
12085 | b->loc->address))); | |
2f202fde | 12086 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12087 | { |
12088 | /* If there is a single location, we can print the location | |
12089 | more nicely. */ | |
12090 | if (b->loc->next == NULL) | |
0bb296cb | 12091 | { |
6a831f06 PA |
12092 | const char *filename |
12093 | = symtab_to_filename_for_display (b->loc->symtab); | |
12094 | printf_filtered (": file %ps, line %d.", | |
12095 | styled_string (file_name_style.style (), | |
12096 | filename), | |
0bb296cb TT |
12097 | b->loc->line_number); |
12098 | } | |
f8eba3c6 TT |
12099 | else |
12100 | /* This is not ideal, but each location may have a | |
12101 | different file name, and this at least reflects the | |
12102 | real situation somewhat. */ | |
f00aae0f | 12103 | printf_filtered (": %s.", |
d28cd78a | 12104 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12105 | } |
348d480f PA |
12106 | |
12107 | if (b->loc->next) | |
12108 | { | |
12109 | struct bp_location *loc = b->loc; | |
12110 | int n = 0; | |
12111 | for (; loc; loc = loc->next) | |
12112 | ++n; | |
12113 | printf_filtered (" (%d locations)", n); | |
12114 | } | |
12115 | } | |
12116 | } | |
12117 | ||
5f486660 | 12118 | bp_location::~bp_location () |
348d480f | 12119 | { |
5f486660 | 12120 | xfree (function_name); |
348d480f PA |
12121 | } |
12122 | ||
c1fc2657 | 12123 | /* Destructor for the breakpoint base class. */ |
348d480f | 12124 | |
c1fc2657 | 12125 | breakpoint::~breakpoint () |
348d480f | 12126 | { |
c1fc2657 SM |
12127 | xfree (this->cond_string); |
12128 | xfree (this->extra_string); | |
348d480f PA |
12129 | } |
12130 | ||
2060206e PA |
12131 | static struct bp_location * |
12132 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12133 | { |
5f486660 | 12134 | return new bp_location (self); |
348d480f PA |
12135 | } |
12136 | ||
2060206e PA |
12137 | static void |
12138 | base_breakpoint_re_set (struct breakpoint *b) | |
12139 | { | |
12140 | /* Nothing to re-set. */ | |
12141 | } | |
12142 | ||
12143 | #define internal_error_pure_virtual_called() \ | |
12144 | gdb_assert_not_reached ("pure virtual function called") | |
12145 | ||
12146 | static int | |
12147 | base_breakpoint_insert_location (struct bp_location *bl) | |
12148 | { | |
12149 | internal_error_pure_virtual_called (); | |
12150 | } | |
12151 | ||
12152 | static int | |
73971819 PA |
12153 | base_breakpoint_remove_location (struct bp_location *bl, |
12154 | enum remove_bp_reason reason) | |
2060206e PA |
12155 | { |
12156 | internal_error_pure_virtual_called (); | |
12157 | } | |
12158 | ||
12159 | static int | |
12160 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12161 | const address_space *aspace, |
09ac7c10 TT |
12162 | CORE_ADDR bp_addr, |
12163 | const struct target_waitstatus *ws) | |
2060206e PA |
12164 | { |
12165 | internal_error_pure_virtual_called (); | |
12166 | } | |
12167 | ||
12168 | static void | |
12169 | base_breakpoint_check_status (bpstat bs) | |
12170 | { | |
12171 | /* Always stop. */ | |
12172 | } | |
12173 | ||
12174 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12175 | errors. */ | |
12176 | ||
12177 | static int | |
12178 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12179 | { | |
12180 | internal_error_pure_virtual_called (); | |
12181 | } | |
12182 | ||
12183 | /* A "resources_needed" breakpoint_ops method that just internal | |
12184 | errors. */ | |
12185 | ||
12186 | static int | |
12187 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12188 | { | |
12189 | internal_error_pure_virtual_called (); | |
12190 | } | |
12191 | ||
12192 | static enum print_stop_action | |
12193 | base_breakpoint_print_it (bpstat bs) | |
12194 | { | |
12195 | internal_error_pure_virtual_called (); | |
12196 | } | |
12197 | ||
12198 | static void | |
12199 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12200 | struct ui_out *uiout) | |
12201 | { | |
12202 | /* nothing */ | |
12203 | } | |
12204 | ||
12205 | static void | |
12206 | base_breakpoint_print_mention (struct breakpoint *b) | |
12207 | { | |
12208 | internal_error_pure_virtual_called (); | |
12209 | } | |
12210 | ||
12211 | static void | |
12212 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12213 | { | |
12214 | internal_error_pure_virtual_called (); | |
12215 | } | |
12216 | ||
983af33b | 12217 | static void |
f00aae0f KS |
12218 | base_breakpoint_create_sals_from_location |
12219 | (const struct event_location *location, | |
12220 | struct linespec_result *canonical, | |
12221 | enum bptype type_wanted) | |
983af33b SDJ |
12222 | { |
12223 | internal_error_pure_virtual_called (); | |
12224 | } | |
12225 | ||
12226 | static void | |
12227 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12228 | struct linespec_result *c, | |
e1e01040 PA |
12229 | gdb::unique_xmalloc_ptr<char> cond_string, |
12230 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12231 | enum bptype type_wanted, |
12232 | enum bpdisp disposition, | |
12233 | int thread, | |
12234 | int task, int ignore_count, | |
12235 | const struct breakpoint_ops *o, | |
12236 | int from_tty, int enabled, | |
44f238bb | 12237 | int internal, unsigned flags) |
983af33b SDJ |
12238 | { |
12239 | internal_error_pure_virtual_called (); | |
12240 | } | |
12241 | ||
6c5b2ebe | 12242 | static std::vector<symtab_and_line> |
f00aae0f KS |
12243 | base_breakpoint_decode_location (struct breakpoint *b, |
12244 | const struct event_location *location, | |
6c5b2ebe | 12245 | struct program_space *search_pspace) |
983af33b SDJ |
12246 | { |
12247 | internal_error_pure_virtual_called (); | |
12248 | } | |
12249 | ||
ab04a2af TT |
12250 | /* The default 'explains_signal' method. */ |
12251 | ||
47591c29 | 12252 | static int |
427cd150 | 12253 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12254 | { |
47591c29 | 12255 | return 1; |
ab04a2af TT |
12256 | } |
12257 | ||
9d6e6e84 HZ |
12258 | /* The default "after_condition_true" method. */ |
12259 | ||
12260 | static void | |
12261 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12262 | { | |
12263 | /* Nothing to do. */ | |
12264 | } | |
12265 | ||
ab04a2af | 12266 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12267 | { |
2060206e PA |
12268 | base_breakpoint_allocate_location, |
12269 | base_breakpoint_re_set, | |
12270 | base_breakpoint_insert_location, | |
12271 | base_breakpoint_remove_location, | |
12272 | base_breakpoint_breakpoint_hit, | |
12273 | base_breakpoint_check_status, | |
12274 | base_breakpoint_resources_needed, | |
12275 | base_breakpoint_works_in_software_mode, | |
12276 | base_breakpoint_print_it, | |
12277 | NULL, | |
12278 | base_breakpoint_print_one_detail, | |
12279 | base_breakpoint_print_mention, | |
983af33b | 12280 | base_breakpoint_print_recreate, |
5f700d83 | 12281 | base_breakpoint_create_sals_from_location, |
983af33b | 12282 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12283 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12284 | base_breakpoint_explains_signal, |
12285 | base_breakpoint_after_condition_true, | |
2060206e PA |
12286 | }; |
12287 | ||
12288 | /* Default breakpoint_ops methods. */ | |
12289 | ||
12290 | static void | |
348d480f PA |
12291 | bkpt_re_set (struct breakpoint *b) |
12292 | { | |
06edf0c0 | 12293 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12294 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12295 | { |
f00aae0f | 12296 | /* Anything without a location can't be re-set. */ |
348d480f | 12297 | delete_breakpoint (b); |
06edf0c0 | 12298 | return; |
348d480f | 12299 | } |
06edf0c0 PA |
12300 | |
12301 | breakpoint_re_set_default (b); | |
348d480f PA |
12302 | } |
12303 | ||
2060206e | 12304 | static int |
348d480f PA |
12305 | bkpt_insert_location (struct bp_location *bl) |
12306 | { | |
cd6c3b4f YQ |
12307 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12308 | ||
579c6ad9 | 12309 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12310 | bl->target_info.placed_address = addr; |
12311 | ||
348d480f | 12312 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12313 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12314 | else |
7c16b83e | 12315 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12316 | } |
12317 | ||
2060206e | 12318 | static int |
73971819 | 12319 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12320 | { |
12321 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12322 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12323 | else | |
73971819 | 12324 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12325 | } |
12326 | ||
2060206e | 12327 | static int |
348d480f | 12328 | bkpt_breakpoint_hit (const struct bp_location *bl, |
bd522513 | 12329 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12330 | const struct target_waitstatus *ws) |
348d480f | 12331 | { |
09ac7c10 | 12332 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12333 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12334 | return 0; |
12335 | ||
348d480f PA |
12336 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12337 | aspace, bp_addr)) | |
12338 | return 0; | |
12339 | ||
12340 | if (overlay_debugging /* unmapped overlay section */ | |
12341 | && section_is_overlay (bl->section) | |
12342 | && !section_is_mapped (bl->section)) | |
12343 | return 0; | |
12344 | ||
12345 | return 1; | |
12346 | } | |
12347 | ||
cd1608cc PA |
12348 | static int |
12349 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12350 | const address_space *aspace, CORE_ADDR bp_addr, |
cd1608cc PA |
12351 | const struct target_waitstatus *ws) |
12352 | { | |
12353 | if (dprintf_style == dprintf_style_agent | |
12354 | && target_can_run_breakpoint_commands ()) | |
12355 | { | |
12356 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12357 | for this address it must be for a breakpoint that happens to | |
12358 | be set at the same address. */ | |
12359 | return 0; | |
12360 | } | |
12361 | ||
12362 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12363 | } | |
12364 | ||
2060206e | 12365 | static int |
348d480f PA |
12366 | bkpt_resources_needed (const struct bp_location *bl) |
12367 | { | |
12368 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12369 | ||
12370 | return 1; | |
12371 | } | |
12372 | ||
2060206e | 12373 | static enum print_stop_action |
348d480f PA |
12374 | bkpt_print_it (bpstat bs) |
12375 | { | |
348d480f PA |
12376 | struct breakpoint *b; |
12377 | const struct bp_location *bl; | |
001c8c33 | 12378 | int bp_temp; |
79a45e25 | 12379 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12380 | |
12381 | gdb_assert (bs->bp_location_at != NULL); | |
12382 | ||
12383 | bl = bs->bp_location_at; | |
12384 | b = bs->breakpoint_at; | |
12385 | ||
001c8c33 PA |
12386 | bp_temp = b->disposition == disp_del; |
12387 | if (bl->address != bl->requested_address) | |
12388 | breakpoint_adjustment_warning (bl->requested_address, | |
12389 | bl->address, | |
12390 | b->number, 1); | |
12391 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12392 | maybe_print_thread_hit_breakpoint (uiout); |
12393 | ||
112e8700 | 12394 | if (uiout->is_mi_like_p ()) |
348d480f | 12395 | { |
112e8700 | 12396 | uiout->field_string ("reason", |
001c8c33 | 12397 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12398 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12399 | } |
6a831f06 PA |
12400 | if (bp_temp) |
12401 | uiout->message ("Temporary breakpoint %pF, ", | |
12402 | signed_field ("bkptno", b->number)); | |
12403 | else | |
12404 | uiout->message ("Breakpoint %pF, ", | |
12405 | signed_field ("bkptno", b->number)); | |
06edf0c0 | 12406 | |
001c8c33 | 12407 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12408 | } |
12409 | ||
2060206e | 12410 | static void |
06edf0c0 PA |
12411 | bkpt_print_mention (struct breakpoint *b) |
12412 | { | |
112e8700 | 12413 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12414 | return; |
12415 | ||
12416 | switch (b->type) | |
12417 | { | |
12418 | case bp_breakpoint: | |
12419 | case bp_gnu_ifunc_resolver: | |
12420 | if (b->disposition == disp_del) | |
12421 | printf_filtered (_("Temporary breakpoint")); | |
12422 | else | |
12423 | printf_filtered (_("Breakpoint")); | |
12424 | printf_filtered (_(" %d"), b->number); | |
12425 | if (b->type == bp_gnu_ifunc_resolver) | |
12426 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12427 | break; | |
12428 | case bp_hardware_breakpoint: | |
12429 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12430 | break; | |
e7e0cddf SS |
12431 | case bp_dprintf: |
12432 | printf_filtered (_("Dprintf %d"), b->number); | |
12433 | break; | |
06edf0c0 PA |
12434 | } |
12435 | ||
12436 | say_where (b); | |
12437 | } | |
12438 | ||
2060206e | 12439 | static void |
06edf0c0 PA |
12440 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12441 | { | |
12442 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12443 | fprintf_unfiltered (fp, "tbreak"); | |
12444 | else if (tp->type == bp_breakpoint) | |
12445 | fprintf_unfiltered (fp, "break"); | |
12446 | else if (tp->type == bp_hardware_breakpoint | |
12447 | && tp->disposition == disp_del) | |
12448 | fprintf_unfiltered (fp, "thbreak"); | |
12449 | else if (tp->type == bp_hardware_breakpoint) | |
12450 | fprintf_unfiltered (fp, "hbreak"); | |
12451 | else | |
12452 | internal_error (__FILE__, __LINE__, | |
12453 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12454 | ||
f00aae0f | 12455 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12456 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12457 | |
12458 | /* Print out extra_string if this breakpoint is pending. It might | |
12459 | contain, for example, conditions that were set by the user. */ | |
12460 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12461 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12462 | ||
dd11a36c | 12463 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12464 | } |
12465 | ||
983af33b | 12466 | static void |
f00aae0f KS |
12467 | bkpt_create_sals_from_location (const struct event_location *location, |
12468 | struct linespec_result *canonical, | |
12469 | enum bptype type_wanted) | |
983af33b | 12470 | { |
f00aae0f | 12471 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12472 | } |
12473 | ||
12474 | static void | |
12475 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12476 | struct linespec_result *canonical, | |
e1e01040 PA |
12477 | gdb::unique_xmalloc_ptr<char> cond_string, |
12478 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12479 | enum bptype type_wanted, |
12480 | enum bpdisp disposition, | |
12481 | int thread, | |
12482 | int task, int ignore_count, | |
12483 | const struct breakpoint_ops *ops, | |
12484 | int from_tty, int enabled, | |
44f238bb | 12485 | int internal, unsigned flags) |
983af33b | 12486 | { |
023fa29b | 12487 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12488 | std::move (cond_string), |
12489 | std::move (extra_string), | |
e7e0cddf | 12490 | type_wanted, |
983af33b SDJ |
12491 | disposition, thread, task, |
12492 | ignore_count, ops, from_tty, | |
44f238bb | 12493 | enabled, internal, flags); |
983af33b SDJ |
12494 | } |
12495 | ||
6c5b2ebe | 12496 | static std::vector<symtab_and_line> |
f00aae0f KS |
12497 | bkpt_decode_location (struct breakpoint *b, |
12498 | const struct event_location *location, | |
6c5b2ebe | 12499 | struct program_space *search_pspace) |
983af33b | 12500 | { |
6c5b2ebe | 12501 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12502 | } |
12503 | ||
06edf0c0 PA |
12504 | /* Virtual table for internal breakpoints. */ |
12505 | ||
12506 | static void | |
12507 | internal_bkpt_re_set (struct breakpoint *b) | |
12508 | { | |
12509 | switch (b->type) | |
12510 | { | |
12511 | /* Delete overlay event and longjmp master breakpoints; they | |
12512 | will be reset later by breakpoint_re_set. */ | |
12513 | case bp_overlay_event: | |
12514 | case bp_longjmp_master: | |
12515 | case bp_std_terminate_master: | |
12516 | case bp_exception_master: | |
12517 | delete_breakpoint (b); | |
12518 | break; | |
12519 | ||
12520 | /* This breakpoint is special, it's set up when the inferior | |
12521 | starts and we really don't want to touch it. */ | |
12522 | case bp_shlib_event: | |
12523 | ||
12524 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12525 | it is set up, we do not want to touch it. */ | |
12526 | case bp_thread_event: | |
12527 | break; | |
12528 | } | |
12529 | } | |
12530 | ||
12531 | static void | |
12532 | internal_bkpt_check_status (bpstat bs) | |
12533 | { | |
a9b3a50f PA |
12534 | if (bs->breakpoint_at->type == bp_shlib_event) |
12535 | { | |
12536 | /* If requested, stop when the dynamic linker notifies GDB of | |
12537 | events. This allows the user to get control and place | |
12538 | breakpoints in initializer routines for dynamically loaded | |
12539 | objects (among other things). */ | |
12540 | bs->stop = stop_on_solib_events; | |
12541 | bs->print = stop_on_solib_events; | |
12542 | } | |
12543 | else | |
12544 | bs->stop = 0; | |
06edf0c0 PA |
12545 | } |
12546 | ||
12547 | static enum print_stop_action | |
12548 | internal_bkpt_print_it (bpstat bs) | |
12549 | { | |
06edf0c0 | 12550 | struct breakpoint *b; |
06edf0c0 | 12551 | |
06edf0c0 PA |
12552 | b = bs->breakpoint_at; |
12553 | ||
06edf0c0 PA |
12554 | switch (b->type) |
12555 | { | |
348d480f PA |
12556 | case bp_shlib_event: |
12557 | /* Did we stop because the user set the stop_on_solib_events | |
12558 | variable? (If so, we report this as a generic, "Stopped due | |
12559 | to shlib event" message.) */ | |
edcc5120 | 12560 | print_solib_event (0); |
348d480f PA |
12561 | break; |
12562 | ||
12563 | case bp_thread_event: | |
12564 | /* Not sure how we will get here. | |
12565 | GDB should not stop for these breakpoints. */ | |
12566 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12567 | break; |
12568 | ||
12569 | case bp_overlay_event: | |
12570 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12571 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12572 | break; |
12573 | ||
12574 | case bp_longjmp_master: | |
12575 | /* These should never be enabled. */ | |
12576 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12577 | break; |
12578 | ||
12579 | case bp_std_terminate_master: | |
12580 | /* These should never be enabled. */ | |
12581 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12582 | "gdb should not stop!\n")); | |
348d480f PA |
12583 | break; |
12584 | ||
12585 | case bp_exception_master: | |
12586 | /* These should never be enabled. */ | |
12587 | printf_filtered (_("Exception Master Breakpoint: " | |
12588 | "gdb should not stop!\n")); | |
06edf0c0 PA |
12589 | break; |
12590 | } | |
12591 | ||
001c8c33 | 12592 | return PRINT_NOTHING; |
06edf0c0 PA |
12593 | } |
12594 | ||
12595 | static void | |
12596 | internal_bkpt_print_mention (struct breakpoint *b) | |
12597 | { | |
12598 | /* Nothing to mention. These breakpoints are internal. */ | |
12599 | } | |
12600 | ||
06edf0c0 PA |
12601 | /* Virtual table for momentary breakpoints */ |
12602 | ||
12603 | static void | |
12604 | momentary_bkpt_re_set (struct breakpoint *b) | |
12605 | { | |
12606 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 12607 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
12608 | Otherwise these should have been blown away via the cleanup chain |
12609 | or by breakpoint_init_inferior when we rerun the executable. */ | |
12610 | } | |
12611 | ||
12612 | static void | |
12613 | momentary_bkpt_check_status (bpstat bs) | |
12614 | { | |
12615 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
12616 | } | |
12617 | ||
12618 | static enum print_stop_action | |
12619 | momentary_bkpt_print_it (bpstat bs) | |
12620 | { | |
001c8c33 | 12621 | return PRINT_UNKNOWN; |
348d480f PA |
12622 | } |
12623 | ||
06edf0c0 PA |
12624 | static void |
12625 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 12626 | { |
06edf0c0 | 12627 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
12628 | } |
12629 | ||
e2e4d78b JK |
12630 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
12631 | ||
12632 | It gets cleared already on the removal of the first one of such placed | |
12633 | breakpoints. This is OK as they get all removed altogether. */ | |
12634 | ||
c1fc2657 | 12635 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 12636 | { |
c1fc2657 | 12637 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 12638 | |
c1fc2657 | 12639 | if (tp != NULL) |
e2e4d78b | 12640 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
12641 | } |
12642 | ||
55aa24fb SDJ |
12643 | /* Specific methods for probe breakpoints. */ |
12644 | ||
12645 | static int | |
12646 | bkpt_probe_insert_location (struct bp_location *bl) | |
12647 | { | |
12648 | int v = bkpt_insert_location (bl); | |
12649 | ||
12650 | if (v == 0) | |
12651 | { | |
12652 | /* The insertion was successful, now let's set the probe's semaphore | |
12653 | if needed. */ | |
935676c9 | 12654 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb SDJ |
12655 | } |
12656 | ||
12657 | return v; | |
12658 | } | |
12659 | ||
12660 | static int | |
73971819 PA |
12661 | bkpt_probe_remove_location (struct bp_location *bl, |
12662 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
12663 | { |
12664 | /* Let's clear the semaphore before removing the location. */ | |
935676c9 | 12665 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
55aa24fb | 12666 | |
73971819 | 12667 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
12668 | } |
12669 | ||
12670 | static void | |
f00aae0f | 12671 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12672 | struct linespec_result *canonical, |
f00aae0f | 12673 | enum bptype type_wanted) |
55aa24fb SDJ |
12674 | { |
12675 | struct linespec_sals lsal; | |
12676 | ||
c2f4122d | 12677 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
12678 | lsal.canonical |
12679 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12680 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
12681 | } |
12682 | ||
6c5b2ebe | 12683 | static std::vector<symtab_and_line> |
f00aae0f KS |
12684 | bkpt_probe_decode_location (struct breakpoint *b, |
12685 | const struct event_location *location, | |
6c5b2ebe | 12686 | struct program_space *search_pspace) |
55aa24fb | 12687 | { |
6c5b2ebe PA |
12688 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
12689 | if (sals.empty ()) | |
55aa24fb | 12690 | error (_("probe not found")); |
6c5b2ebe | 12691 | return sals; |
55aa24fb SDJ |
12692 | } |
12693 | ||
348d480f | 12694 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 12695 | |
348d480f PA |
12696 | static void |
12697 | tracepoint_re_set (struct breakpoint *b) | |
12698 | { | |
12699 | breakpoint_re_set_default (b); | |
12700 | } | |
876fa593 | 12701 | |
348d480f PA |
12702 | static int |
12703 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
bd522513 | 12704 | const address_space *aspace, CORE_ADDR bp_addr, |
09ac7c10 | 12705 | const struct target_waitstatus *ws) |
348d480f PA |
12706 | { |
12707 | /* By definition, the inferior does not report stops at | |
12708 | tracepoints. */ | |
12709 | return 0; | |
74960c60 VP |
12710 | } |
12711 | ||
12712 | static void | |
348d480f PA |
12713 | tracepoint_print_one_detail (const struct breakpoint *self, |
12714 | struct ui_out *uiout) | |
74960c60 | 12715 | { |
d9b3f62e | 12716 | struct tracepoint *tp = (struct tracepoint *) self; |
5d9310c4 | 12717 | if (!tp->static_trace_marker_id.empty ()) |
348d480f PA |
12718 | { |
12719 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 12720 | |
6a831f06 PA |
12721 | uiout->message ("\tmarker id is %pF\n", |
12722 | string_field ("static-tracepoint-marker-string-id", | |
12723 | tp->static_trace_marker_id.c_str ())); | |
348d480f | 12724 | } |
0d381245 VP |
12725 | } |
12726 | ||
a474d7c2 | 12727 | static void |
348d480f | 12728 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 12729 | { |
112e8700 | 12730 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12731 | return; |
cc59ec59 | 12732 | |
348d480f PA |
12733 | switch (b->type) |
12734 | { | |
12735 | case bp_tracepoint: | |
12736 | printf_filtered (_("Tracepoint")); | |
12737 | printf_filtered (_(" %d"), b->number); | |
12738 | break; | |
12739 | case bp_fast_tracepoint: | |
12740 | printf_filtered (_("Fast tracepoint")); | |
12741 | printf_filtered (_(" %d"), b->number); | |
12742 | break; | |
12743 | case bp_static_tracepoint: | |
12744 | printf_filtered (_("Static tracepoint")); | |
12745 | printf_filtered (_(" %d"), b->number); | |
12746 | break; | |
12747 | default: | |
12748 | internal_error (__FILE__, __LINE__, | |
12749 | _("unhandled tracepoint type %d"), (int) b->type); | |
12750 | } | |
12751 | ||
12752 | say_where (b); | |
a474d7c2 PA |
12753 | } |
12754 | ||
348d480f | 12755 | static void |
d9b3f62e | 12756 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 12757 | { |
d9b3f62e PA |
12758 | struct tracepoint *tp = (struct tracepoint *) self; |
12759 | ||
12760 | if (self->type == bp_fast_tracepoint) | |
348d480f | 12761 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 12762 | else if (self->type == bp_static_tracepoint) |
348d480f | 12763 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 12764 | else if (self->type == bp_tracepoint) |
348d480f PA |
12765 | fprintf_unfiltered (fp, "trace"); |
12766 | else | |
12767 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 12768 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 12769 | |
f00aae0f | 12770 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12771 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
12772 | print_recreate_thread (self, fp); |
12773 | ||
12774 | if (tp->pass_count) | |
12775 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
12776 | } |
12777 | ||
983af33b | 12778 | static void |
f00aae0f KS |
12779 | tracepoint_create_sals_from_location (const struct event_location *location, |
12780 | struct linespec_result *canonical, | |
12781 | enum bptype type_wanted) | |
983af33b | 12782 | { |
f00aae0f | 12783 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12784 | } |
12785 | ||
12786 | static void | |
12787 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12788 | struct linespec_result *canonical, | |
e1e01040 PA |
12789 | gdb::unique_xmalloc_ptr<char> cond_string, |
12790 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12791 | enum bptype type_wanted, |
12792 | enum bpdisp disposition, | |
12793 | int thread, | |
12794 | int task, int ignore_count, | |
12795 | const struct breakpoint_ops *ops, | |
12796 | int from_tty, int enabled, | |
44f238bb | 12797 | int internal, unsigned flags) |
983af33b | 12798 | { |
023fa29b | 12799 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12800 | std::move (cond_string), |
12801 | std::move (extra_string), | |
e7e0cddf | 12802 | type_wanted, |
983af33b SDJ |
12803 | disposition, thread, task, |
12804 | ignore_count, ops, from_tty, | |
44f238bb | 12805 | enabled, internal, flags); |
983af33b SDJ |
12806 | } |
12807 | ||
6c5b2ebe | 12808 | static std::vector<symtab_and_line> |
f00aae0f KS |
12809 | tracepoint_decode_location (struct breakpoint *b, |
12810 | const struct event_location *location, | |
6c5b2ebe | 12811 | struct program_space *search_pspace) |
983af33b | 12812 | { |
6c5b2ebe | 12813 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12814 | } |
12815 | ||
2060206e | 12816 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 12817 | |
bac7c5cf | 12818 | /* Virtual table for tracepoints on static probes. */ |
55aa24fb SDJ |
12819 | |
12820 | static void | |
f00aae0f KS |
12821 | tracepoint_probe_create_sals_from_location |
12822 | (const struct event_location *location, | |
12823 | struct linespec_result *canonical, | |
12824 | enum bptype type_wanted) | |
55aa24fb SDJ |
12825 | { |
12826 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 12827 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
12828 | } |
12829 | ||
6c5b2ebe | 12830 | static std::vector<symtab_and_line> |
f00aae0f KS |
12831 | tracepoint_probe_decode_location (struct breakpoint *b, |
12832 | const struct event_location *location, | |
6c5b2ebe | 12833 | struct program_space *search_pspace) |
55aa24fb SDJ |
12834 | { |
12835 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 12836 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
12837 | } |
12838 | ||
5c2b4418 HZ |
12839 | /* Dprintf breakpoint_ops methods. */ |
12840 | ||
12841 | static void | |
12842 | dprintf_re_set (struct breakpoint *b) | |
12843 | { | |
12844 | breakpoint_re_set_default (b); | |
12845 | ||
f00aae0f KS |
12846 | /* extra_string should never be non-NULL for dprintf. */ |
12847 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
12848 | |
12849 | /* 1 - connect to target 1, that can run breakpoint commands. | |
12850 | 2 - create a dprintf, which resolves fine. | |
12851 | 3 - disconnect from target 1 | |
12852 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
12853 | ||
12854 | After steps #3/#4, you'll want the dprintf command list to | |
12855 | be updated, because target 1 and 2 may well return different | |
12856 | answers for target_can_run_breakpoint_commands(). | |
12857 | Given absence of finer grained resetting, we get to do | |
12858 | it all the time. */ | |
12859 | if (b->extra_string != NULL) | |
12860 | update_dprintf_command_list (b); | |
12861 | } | |
12862 | ||
2d9442cc HZ |
12863 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
12864 | ||
12865 | static void | |
12866 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
12867 | { | |
f00aae0f | 12868 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 12869 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
12870 | tp->extra_string); |
12871 | print_recreate_thread (tp, fp); | |
12872 | } | |
12873 | ||
9d6e6e84 HZ |
12874 | /* Implement the "after_condition_true" breakpoint_ops method for |
12875 | dprintf. | |
12876 | ||
12877 | dprintf's are implemented with regular commands in their command | |
12878 | list, but we run the commands here instead of before presenting the | |
12879 | stop to the user, as dprintf's don't actually cause a stop. This | |
12880 | also makes it so that the commands of multiple dprintfs at the same | |
12881 | address are all handled. */ | |
12882 | ||
12883 | static void | |
12884 | dprintf_after_condition_true (struct bpstats *bs) | |
12885 | { | |
04afa70c | 12886 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
12887 | struct bpstats *tmp_bs_p = &tmp_bs; |
12888 | ||
12889 | /* dprintf's never cause a stop. This wasn't set in the | |
12890 | check_status hook instead because that would make the dprintf's | |
12891 | condition not be evaluated. */ | |
12892 | bs->stop = 0; | |
12893 | ||
12894 | /* Run the command list here. Take ownership of it instead of | |
12895 | copying. We never want these commands to run later in | |
12896 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
12897 | be set at same address as this dprintf, or even if running the | |
12898 | commands here throws. */ | |
12899 | tmp_bs.commands = bs->commands; | |
12900 | bs->commands = NULL; | |
9d6e6e84 HZ |
12901 | |
12902 | bpstat_do_actions_1 (&tmp_bs_p); | |
12903 | ||
12904 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
12905 | bpstat_do_actions_1 may return early without processing the whole | |
12906 | list. */ | |
9d6e6e84 HZ |
12907 | } |
12908 | ||
983af33b SDJ |
12909 | /* The breakpoint_ops structure to be used on static tracepoints with |
12910 | markers (`-m'). */ | |
12911 | ||
12912 | static void | |
f00aae0f | 12913 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 12914 | struct linespec_result *canonical, |
f00aae0f | 12915 | enum bptype type_wanted) |
983af33b SDJ |
12916 | { |
12917 | struct linespec_sals lsal; | |
f00aae0f | 12918 | const char *arg_start, *arg; |
983af33b | 12919 | |
a20714ff | 12920 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 12921 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 12922 | |
f2fc3015 TT |
12923 | std::string str (arg_start, arg - arg_start); |
12924 | const char *ptr = str.c_str (); | |
a20714ff PA |
12925 | canonical->location |
12926 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 12927 | |
8e9e35b1 TT |
12928 | lsal.canonical |
12929 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12930 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
12931 | } |
12932 | ||
12933 | static void | |
12934 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12935 | struct linespec_result *canonical, | |
e1e01040 PA |
12936 | gdb::unique_xmalloc_ptr<char> cond_string, |
12937 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12938 | enum bptype type_wanted, |
12939 | enum bpdisp disposition, | |
12940 | int thread, | |
12941 | int task, int ignore_count, | |
12942 | const struct breakpoint_ops *ops, | |
12943 | int from_tty, int enabled, | |
44f238bb | 12944 | int internal, unsigned flags) |
983af33b | 12945 | { |
6c5b2ebe | 12946 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
12947 | |
12948 | /* If the user is creating a static tracepoint by marker id | |
12949 | (strace -m MARKER_ID), then store the sals index, so that | |
12950 | breakpoint_re_set can try to match up which of the newly | |
12951 | found markers corresponds to this one, and, don't try to | |
12952 | expand multiple locations for each sal, given than SALS | |
12953 | already should contain all sals for MARKER_ID. */ | |
12954 | ||
6c5b2ebe | 12955 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 12956 | { |
6c5b2ebe PA |
12957 | event_location_up location |
12958 | = copy_event_location (canonical->location.get ()); | |
983af33b | 12959 | |
b270e6f9 | 12960 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 12961 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 12962 | std::move (location), NULL, |
e1e01040 PA |
12963 | std::move (cond_string), |
12964 | std::move (extra_string), | |
e7e0cddf | 12965 | type_wanted, disposition, |
983af33b | 12966 | thread, task, ignore_count, ops, |
44f238bb | 12967 | from_tty, enabled, internal, flags, |
983af33b SDJ |
12968 | canonical->special_display); |
12969 | /* Given that its possible to have multiple markers with | |
12970 | the same string id, if the user is creating a static | |
12971 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
12972 | store the sals index, so that breakpoint_re_set can | |
12973 | try to match up which of the newly found markers | |
12974 | corresponds to this one */ | |
12975 | tp->static_trace_marker_id_idx = i; | |
12976 | ||
b270e6f9 | 12977 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
12978 | } |
12979 | } | |
12980 | ||
6c5b2ebe | 12981 | static std::vector<symtab_and_line> |
f00aae0f KS |
12982 | strace_marker_decode_location (struct breakpoint *b, |
12983 | const struct event_location *location, | |
6c5b2ebe | 12984 | struct program_space *search_pspace) |
983af33b SDJ |
12985 | { |
12986 | struct tracepoint *tp = (struct tracepoint *) b; | |
a20714ff | 12987 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 12988 | |
6c5b2ebe PA |
12989 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
12990 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 12991 | { |
6c5b2ebe PA |
12992 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
12993 | sals.resize (1); | |
12994 | return sals; | |
983af33b SDJ |
12995 | } |
12996 | else | |
5d9310c4 | 12997 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
983af33b SDJ |
12998 | } |
12999 | ||
13000 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13001 | ||
13002 | static int | |
13003 | strace_marker_p (struct breakpoint *b) | |
13004 | { | |
13005 | return b->ops == &strace_marker_breakpoint_ops; | |
13006 | } | |
13007 | ||
53a5351d | 13008 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13009 | structures. */ |
c906108c SS |
13010 | |
13011 | void | |
fba45db2 | 13012 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13013 | { |
52f0bd74 | 13014 | struct breakpoint *b; |
c906108c | 13015 | |
8a3fe4f8 | 13016 | gdb_assert (bpt != NULL); |
c906108c | 13017 | |
4a64f543 MS |
13018 | /* Has this bp already been deleted? This can happen because |
13019 | multiple lists can hold pointers to bp's. bpstat lists are | |
13020 | especial culprits. | |
13021 | ||
13022 | One example of this happening is a watchpoint's scope bp. When | |
13023 | the scope bp triggers, we notice that the watchpoint is out of | |
13024 | scope, and delete it. We also delete its scope bp. But the | |
13025 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13026 | That bpstat is then checked for auto-deleting bp's, which are | |
13027 | deleted. | |
13028 | ||
13029 | A real solution to this problem might involve reference counts in | |
13030 | bp's, and/or giving them pointers back to their referencing | |
13031 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13032 | storage when no more references were extent. A cheaper bandaid | |
13033 | was chosen. */ | |
c906108c SS |
13034 | if (bpt->type == bp_none) |
13035 | return; | |
13036 | ||
4a64f543 MS |
13037 | /* At least avoid this stale reference until the reference counting |
13038 | of breakpoints gets resolved. */ | |
d0fb5eae | 13039 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13040 | { |
d0fb5eae | 13041 | struct breakpoint *related; |
3a5c3e22 | 13042 | struct watchpoint *w; |
d0fb5eae JK |
13043 | |
13044 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13045 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13046 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13047 | w = (struct watchpoint *) bpt; |
13048 | else | |
13049 | w = NULL; | |
13050 | if (w != NULL) | |
13051 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13052 | |
13053 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13054 | for (related = bpt; related->related_breakpoint != bpt; | |
13055 | related = related->related_breakpoint); | |
13056 | related->related_breakpoint = bpt->related_breakpoint; | |
13057 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13058 | } |
13059 | ||
a9634178 TJB |
13060 | /* watch_command_1 creates a watchpoint but only sets its number if |
13061 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13062 | a problem in that process, we'll be asked to delete the half-created | |
13063 | watchpoint. In that case, don't announce the deletion. */ | |
13064 | if (bpt->number) | |
76727919 | 13065 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 13066 | |
c906108c SS |
13067 | if (breakpoint_chain == bpt) |
13068 | breakpoint_chain = bpt->next; | |
13069 | ||
c906108c SS |
13070 | ALL_BREAKPOINTS (b) |
13071 | if (b->next == bpt) | |
c5aa993b JM |
13072 | { |
13073 | b->next = bpt->next; | |
13074 | break; | |
13075 | } | |
c906108c | 13076 | |
f431efe5 PA |
13077 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13078 | been freed. */ | |
13079 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13080 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13081 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13082 | commands are associated with the bpstat; if we remove it here, | |
13083 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13084 | event-top.c won't do anything, and temporary breakpoints with | |
13085 | commands won't work. */ | |
13086 | ||
13087 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13088 | ||
4a64f543 MS |
13089 | /* Now that breakpoint is removed from breakpoint list, update the |
13090 | global location list. This will remove locations that used to | |
13091 | belong to this breakpoint. Do this before freeing the breakpoint | |
13092 | itself, since remove_breakpoint looks at location's owner. It | |
13093 | might be better design to have location completely | |
13094 | self-contained, but it's not the case now. */ | |
44702360 | 13095 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13096 | |
4a64f543 MS |
13097 | /* On the chance that someone will soon try again to delete this |
13098 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13099 | bpt->type = bp_none; |
4d01a485 | 13100 | delete bpt; |
c906108c SS |
13101 | } |
13102 | ||
51be5b68 PA |
13103 | /* Iterator function to call a user-provided callback function once |
13104 | for each of B and its related breakpoints. */ | |
13105 | ||
13106 | static void | |
13107 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13108 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13109 | { |
13110 | struct breakpoint *related; | |
13111 | ||
13112 | related = b; | |
13113 | do | |
13114 | { | |
13115 | struct breakpoint *next; | |
13116 | ||
13117 | /* FUNCTION may delete RELATED. */ | |
13118 | next = related->related_breakpoint; | |
13119 | ||
13120 | if (next == related) | |
13121 | { | |
13122 | /* RELATED is the last ring entry. */ | |
48649e1b | 13123 | function (related); |
51be5b68 PA |
13124 | |
13125 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13126 | B. There's nothing left to do anyway, so just break | |
13127 | out. */ | |
13128 | break; | |
13129 | } | |
13130 | else | |
48649e1b | 13131 | function (related); |
51be5b68 PA |
13132 | |
13133 | related = next; | |
13134 | } | |
13135 | while (related != b); | |
13136 | } | |
95a42b64 | 13137 | |
4495129a | 13138 | static void |
981a3fb3 | 13139 | delete_command (const char *arg, int from_tty) |
c906108c | 13140 | { |
35df4500 | 13141 | struct breakpoint *b, *b_tmp; |
c906108c | 13142 | |
ea9365bb TT |
13143 | dont_repeat (); |
13144 | ||
c906108c SS |
13145 | if (arg == 0) |
13146 | { | |
13147 | int breaks_to_delete = 0; | |
13148 | ||
46c6471b PA |
13149 | /* Delete all breakpoints if no argument. Do not delete |
13150 | internal breakpoints, these have to be deleted with an | |
13151 | explicit breakpoint number argument. */ | |
c5aa993b | 13152 | ALL_BREAKPOINTS (b) |
46c6471b | 13153 | if (user_breakpoint_p (b)) |
973d738b DJ |
13154 | { |
13155 | breaks_to_delete = 1; | |
13156 | break; | |
13157 | } | |
c906108c SS |
13158 | |
13159 | /* Ask user only if there are some breakpoints to delete. */ | |
13160 | if (!from_tty | |
e2e0b3e5 | 13161 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13162 | { |
35df4500 | 13163 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13164 | if (user_breakpoint_p (b)) |
c5aa993b | 13165 | delete_breakpoint (b); |
c906108c SS |
13166 | } |
13167 | } | |
13168 | else | |
48649e1b | 13169 | map_breakpoint_numbers |
b926417a | 13170 | (arg, [&] (breakpoint *br) |
48649e1b | 13171 | { |
b926417a | 13172 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 13173 | }); |
c906108c SS |
13174 | } |
13175 | ||
c2f4122d PA |
13176 | /* Return true if all locations of B bound to PSPACE are pending. If |
13177 | PSPACE is NULL, all locations of all program spaces are | |
13178 | considered. */ | |
13179 | ||
0d381245 | 13180 | static int |
c2f4122d | 13181 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13182 | { |
c2f4122d PA |
13183 | struct bp_location *loc; |
13184 | ||
13185 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13186 | if ((pspace == NULL | |
13187 | || loc->pspace == pspace) | |
13188 | && !loc->shlib_disabled | |
8645ff69 | 13189 | && !loc->pspace->executing_startup) |
0d381245 VP |
13190 | return 0; |
13191 | return 1; | |
fe3f5fa8 VP |
13192 | } |
13193 | ||
776592bf DE |
13194 | /* Subroutine of update_breakpoint_locations to simplify it. |
13195 | Return non-zero if multiple fns in list LOC have the same name. | |
13196 | Null names are ignored. */ | |
13197 | ||
13198 | static int | |
13199 | ambiguous_names_p (struct bp_location *loc) | |
13200 | { | |
13201 | struct bp_location *l; | |
459a2e4c TT |
13202 | htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
13203 | xcalloc, xfree); | |
776592bf DE |
13204 | |
13205 | for (l = loc; l != NULL; l = l->next) | |
13206 | { | |
13207 | const char **slot; | |
13208 | const char *name = l->function_name; | |
13209 | ||
13210 | /* Allow for some names to be NULL, ignore them. */ | |
13211 | if (name == NULL) | |
13212 | continue; | |
13213 | ||
13214 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13215 | INSERT); | |
4a64f543 MS |
13216 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13217 | returns NULL. */ | |
776592bf DE |
13218 | if (*slot != NULL) |
13219 | { | |
13220 | htab_delete (htab); | |
13221 | return 1; | |
13222 | } | |
13223 | *slot = name; | |
13224 | } | |
13225 | ||
13226 | htab_delete (htab); | |
13227 | return 0; | |
13228 | } | |
13229 | ||
0fb4aa4b PA |
13230 | /* When symbols change, it probably means the sources changed as well, |
13231 | and it might mean the static tracepoint markers are no longer at | |
13232 | the same address or line numbers they used to be at last we | |
13233 | checked. Losing your static tracepoints whenever you rebuild is | |
13234 | undesirable. This function tries to resync/rematch gdb static | |
13235 | tracepoints with the markers on the target, for static tracepoints | |
13236 | that have not been set by marker id. Static tracepoint that have | |
13237 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13238 | The heuristic is: | |
13239 | ||
13240 | 1) For a tracepoint set at a specific address, look for a marker at | |
13241 | the old PC. If one is found there, assume to be the same marker. | |
13242 | If the name / string id of the marker found is different from the | |
13243 | previous known name, assume that means the user renamed the marker | |
13244 | in the sources, and output a warning. | |
13245 | ||
13246 | 2) For a tracepoint set at a given line number, look for a marker | |
13247 | at the new address of the old line number. If one is found there, | |
13248 | assume to be the same marker. If the name / string id of the | |
13249 | marker found is different from the previous known name, assume that | |
13250 | means the user renamed the marker in the sources, and output a | |
13251 | warning. | |
13252 | ||
13253 | 3) If a marker is no longer found at the same address or line, it | |
13254 | may mean the marker no longer exists. But it may also just mean | |
13255 | the code changed a bit. Maybe the user added a few lines of code | |
13256 | that made the marker move up or down (in line number terms). Ask | |
13257 | the target for info about the marker with the string id as we knew | |
13258 | it. If found, update line number and address in the matching | |
13259 | static tracepoint. This will get confused if there's more than one | |
13260 | marker with the same ID (possible in UST, although unadvised | |
13261 | precisely because it confuses tools). */ | |
13262 | ||
13263 | static struct symtab_and_line | |
13264 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13265 | { | |
d9b3f62e | 13266 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13267 | struct static_tracepoint_marker marker; |
13268 | CORE_ADDR pc; | |
0fb4aa4b PA |
13269 | |
13270 | pc = sal.pc; | |
13271 | if (sal.line) | |
13272 | find_line_pc (sal.symtab, sal.line, &pc); | |
13273 | ||
13274 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13275 | { | |
5d9310c4 | 13276 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 13277 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
13278 | b->number, tp->static_trace_marker_id.c_str (), |
13279 | marker.str_id.c_str ()); | |
0fb4aa4b | 13280 | |
5d9310c4 | 13281 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
13282 | |
13283 | return sal; | |
13284 | } | |
13285 | ||
13286 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13287 | by string ID. */ | |
13288 | if (!sal.explicit_pc | |
13289 | && sal.line != 0 | |
13290 | && sal.symtab != NULL | |
5d9310c4 | 13291 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 13292 | { |
5d9310c4 SM |
13293 | std::vector<static_tracepoint_marker> markers |
13294 | = target_static_tracepoint_markers_by_strid | |
13295 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 13296 | |
5d9310c4 | 13297 | if (!markers.empty ()) |
0fb4aa4b | 13298 | { |
0fb4aa4b | 13299 | struct symbol *sym; |
80e1d417 | 13300 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13301 | struct ui_out *uiout = current_uiout; |
67994074 | 13302 | struct explicit_location explicit_loc; |
0fb4aa4b | 13303 | |
5d9310c4 | 13304 | tpmarker = &markers[0]; |
0fb4aa4b | 13305 | |
5d9310c4 | 13306 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
13307 | |
13308 | warning (_("marker for static tracepoint %d (%s) not " | |
13309 | "found at previous line number"), | |
5d9310c4 | 13310 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 13311 | |
51abb421 | 13312 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13313 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13314 | uiout->text ("Now in "); |
0fb4aa4b PA |
13315 | if (sym) |
13316 | { | |
987012b8 | 13317 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 13318 | function_name_style.style ()); |
112e8700 | 13319 | uiout->text (" at "); |
0fb4aa4b | 13320 | } |
112e8700 | 13321 | uiout->field_string ("file", |
cbe56571 | 13322 | symtab_to_filename_for_display (sal2.symtab), |
e43b10e1 | 13323 | file_name_style.style ()); |
112e8700 | 13324 | uiout->text (":"); |
0fb4aa4b | 13325 | |
112e8700 | 13326 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13327 | { |
0b0865da | 13328 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13329 | |
112e8700 | 13330 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13331 | } |
13332 | ||
381befee | 13333 | uiout->field_signed ("line", sal2.line); |
112e8700 | 13334 | uiout->text ("\n"); |
0fb4aa4b | 13335 | |
80e1d417 | 13336 | b->loc->line_number = sal2.line; |
2f202fde | 13337 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13338 | |
d28cd78a | 13339 | b->location.reset (NULL); |
67994074 KS |
13340 | initialize_explicit_location (&explicit_loc); |
13341 | explicit_loc.source_filename | |
00e52e53 | 13342 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13343 | explicit_loc.line_offset.offset = b->loc->line_number; |
13344 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13345 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13346 | |
13347 | /* Might be nice to check if function changed, and warn if | |
13348 | so. */ | |
0fb4aa4b PA |
13349 | } |
13350 | } | |
13351 | return sal; | |
13352 | } | |
13353 | ||
8d3788bd VP |
13354 | /* Returns 1 iff locations A and B are sufficiently same that |
13355 | we don't need to report breakpoint as changed. */ | |
13356 | ||
13357 | static int | |
13358 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13359 | { | |
13360 | while (a && b) | |
13361 | { | |
13362 | if (a->address != b->address) | |
13363 | return 0; | |
13364 | ||
13365 | if (a->shlib_disabled != b->shlib_disabled) | |
13366 | return 0; | |
13367 | ||
13368 | if (a->enabled != b->enabled) | |
13369 | return 0; | |
13370 | ||
13371 | a = a->next; | |
13372 | b = b->next; | |
13373 | } | |
13374 | ||
13375 | if ((a == NULL) != (b == NULL)) | |
13376 | return 0; | |
13377 | ||
13378 | return 1; | |
13379 | } | |
13380 | ||
c2f4122d PA |
13381 | /* Split all locations of B that are bound to PSPACE out of B's |
13382 | location list to a separate list and return that list's head. If | |
13383 | PSPACE is NULL, hoist out all locations of B. */ | |
13384 | ||
13385 | static struct bp_location * | |
13386 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13387 | { | |
13388 | struct bp_location head; | |
13389 | struct bp_location *i = b->loc; | |
13390 | struct bp_location **i_link = &b->loc; | |
13391 | struct bp_location *hoisted = &head; | |
13392 | ||
13393 | if (pspace == NULL) | |
13394 | { | |
13395 | i = b->loc; | |
13396 | b->loc = NULL; | |
13397 | return i; | |
13398 | } | |
13399 | ||
13400 | head.next = NULL; | |
13401 | ||
13402 | while (i != NULL) | |
13403 | { | |
13404 | if (i->pspace == pspace) | |
13405 | { | |
13406 | *i_link = i->next; | |
13407 | i->next = NULL; | |
13408 | hoisted->next = i; | |
13409 | hoisted = i; | |
13410 | } | |
13411 | else | |
13412 | i_link = &i->next; | |
13413 | i = *i_link; | |
13414 | } | |
13415 | ||
13416 | return head.next; | |
13417 | } | |
13418 | ||
13419 | /* Create new breakpoint locations for B (a hardware or software | |
13420 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13421 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13422 | FILTER_PSPACE. Locations of other program spaces are left | |
13423 | untouched. */ | |
f1310107 | 13424 | |
0e30163f | 13425 | void |
0d381245 | 13426 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13427 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13428 | gdb::array_view<const symtab_and_line> sals, |
13429 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 13430 | { |
c2f4122d | 13431 | struct bp_location *existing_locations; |
0d381245 | 13432 | |
6c5b2ebe | 13433 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13434 | { |
13435 | /* Ranged breakpoints have only one start location and one end | |
13436 | location. */ | |
13437 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13438 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13439 | "multiple locations found\n"), | |
13440 | b->number); | |
13441 | return; | |
13442 | } | |
f1310107 | 13443 | |
4a64f543 MS |
13444 | /* If there's no new locations, and all existing locations are |
13445 | pending, don't do anything. This optimizes the common case where | |
13446 | all locations are in the same shared library, that was unloaded. | |
13447 | We'd like to retain the location, so that when the library is | |
13448 | loaded again, we don't loose the enabled/disabled status of the | |
13449 | individual locations. */ | |
6c5b2ebe | 13450 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13451 | return; |
13452 | ||
c2f4122d | 13453 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13454 | |
6c5b2ebe | 13455 | for (const auto &sal : sals) |
fe3f5fa8 | 13456 | { |
f8eba3c6 TT |
13457 | struct bp_location *new_loc; |
13458 | ||
6c5b2ebe | 13459 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13460 | |
6c5b2ebe | 13461 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13462 | |
0d381245 VP |
13463 | /* Reparse conditions, they might contain references to the |
13464 | old symtab. */ | |
13465 | if (b->cond_string != NULL) | |
13466 | { | |
bbc13ae3 | 13467 | const char *s; |
fe3f5fa8 | 13468 | |
0d381245 | 13469 | s = b->cond_string; |
a70b8144 | 13470 | try |
0d381245 | 13471 | { |
6c5b2ebe PA |
13472 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13473 | block_for_pc (sal.pc), | |
0d381245 VP |
13474 | 0); |
13475 | } | |
230d2906 | 13476 | catch (const gdb_exception_error &e) |
0d381245 | 13477 | { |
3e43a32a MS |
13478 | warning (_("failed to reevaluate condition " |
13479 | "for breakpoint %d: %s"), | |
3d6e9d23 | 13480 | b->number, e.what ()); |
0d381245 VP |
13481 | new_loc->enabled = 0; |
13482 | } | |
13483 | } | |
fe3f5fa8 | 13484 | |
6c5b2ebe | 13485 | if (!sals_end.empty ()) |
f1310107 | 13486 | { |
6c5b2ebe | 13487 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13488 | |
6c5b2ebe | 13489 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13490 | } |
0d381245 | 13491 | } |
fe3f5fa8 | 13492 | |
4a64f543 MS |
13493 | /* If possible, carry over 'disable' status from existing |
13494 | breakpoints. */ | |
0d381245 VP |
13495 | { |
13496 | struct bp_location *e = existing_locations; | |
776592bf DE |
13497 | /* If there are multiple breakpoints with the same function name, |
13498 | e.g. for inline functions, comparing function names won't work. | |
13499 | Instead compare pc addresses; this is just a heuristic as things | |
13500 | may have moved, but in practice it gives the correct answer | |
13501 | often enough until a better solution is found. */ | |
13502 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13503 | ||
0d381245 VP |
13504 | for (; e; e = e->next) |
13505 | { | |
13506 | if (!e->enabled && e->function_name) | |
13507 | { | |
13508 | struct bp_location *l = b->loc; | |
776592bf DE |
13509 | if (have_ambiguous_names) |
13510 | { | |
13511 | for (; l; l = l->next) | |
f1310107 | 13512 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13513 | { |
13514 | l->enabled = 0; | |
13515 | break; | |
13516 | } | |
13517 | } | |
13518 | else | |
13519 | { | |
13520 | for (; l; l = l->next) | |
13521 | if (l->function_name | |
13522 | && strcmp (e->function_name, l->function_name) == 0) | |
13523 | { | |
13524 | l->enabled = 0; | |
13525 | break; | |
13526 | } | |
13527 | } | |
0d381245 VP |
13528 | } |
13529 | } | |
13530 | } | |
fe3f5fa8 | 13531 | |
8d3788bd | 13532 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 13533 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
13534 | } |
13535 | ||
f00aae0f | 13536 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13537 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13538 | ||
6c5b2ebe | 13539 | static std::vector<symtab_and_line> |
f00aae0f | 13540 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13541 | struct program_space *search_pspace, int *found) |
ef23e705 | 13542 | { |
cc06b668 | 13543 | struct gdb_exception exception; |
ef23e705 | 13544 | |
983af33b | 13545 | gdb_assert (b->ops != NULL); |
ef23e705 | 13546 | |
6c5b2ebe PA |
13547 | std::vector<symtab_and_line> sals; |
13548 | ||
a70b8144 | 13549 | try |
ef23e705 | 13550 | { |
6c5b2ebe | 13551 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13552 | } |
94aeb44b | 13553 | catch (gdb_exception_error &e) |
ef23e705 TJB |
13554 | { |
13555 | int not_found_and_ok = 0; | |
492d29ea | 13556 | |
ef23e705 TJB |
13557 | /* For pending breakpoints, it's expected that parsing will |
13558 | fail until the right shared library is loaded. User has | |
13559 | already told to create pending breakpoints and don't need | |
13560 | extra messages. If breakpoint is in bp_shlib_disabled | |
13561 | state, then user already saw the message about that | |
13562 | breakpoint being disabled, and don't want to see more | |
13563 | errors. */ | |
58438ac1 | 13564 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
13565 | && (b->condition_not_parsed |
13566 | || (b->loc != NULL | |
13567 | && search_pspace != NULL | |
13568 | && b->loc->pspace != search_pspace) | |
ef23e705 | 13569 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 13570 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
13571 | || b->enable_state == bp_disabled)) |
13572 | not_found_and_ok = 1; | |
13573 | ||
13574 | if (!not_found_and_ok) | |
13575 | { | |
13576 | /* We surely don't want to warn about the same breakpoint | |
13577 | 10 times. One solution, implemented here, is disable | |
13578 | the breakpoint on error. Another solution would be to | |
13579 | have separate 'warning emitted' flag. Since this | |
13580 | happens only when a binary has changed, I don't know | |
13581 | which approach is better. */ | |
13582 | b->enable_state = bp_disabled; | |
eedc3f4f | 13583 | throw; |
ef23e705 | 13584 | } |
94aeb44b TT |
13585 | |
13586 | exception = std::move (e); | |
ef23e705 TJB |
13587 | } |
13588 | ||
492d29ea | 13589 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 13590 | { |
6c5b2ebe PA |
13591 | for (auto &sal : sals) |
13592 | resolve_sal_pc (&sal); | |
f00aae0f | 13593 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 13594 | { |
ed1d1739 KS |
13595 | char *cond_string, *extra_string; |
13596 | int thread, task; | |
ef23e705 | 13597 | |
6c5b2ebe | 13598 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
13599 | &cond_string, &thread, &task, |
13600 | &extra_string); | |
f00aae0f | 13601 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
13602 | if (cond_string) |
13603 | b->cond_string = cond_string; | |
13604 | b->thread = thread; | |
13605 | b->task = task; | |
e7e0cddf | 13606 | if (extra_string) |
f00aae0f KS |
13607 | { |
13608 | xfree (b->extra_string); | |
13609 | b->extra_string = extra_string; | |
13610 | } | |
ef23e705 TJB |
13611 | b->condition_not_parsed = 0; |
13612 | } | |
13613 | ||
983af33b | 13614 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 13615 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 13616 | |
58438ac1 TT |
13617 | *found = 1; |
13618 | } | |
13619 | else | |
13620 | *found = 0; | |
ef23e705 TJB |
13621 | |
13622 | return sals; | |
13623 | } | |
13624 | ||
348d480f PA |
13625 | /* The default re_set method, for typical hardware or software |
13626 | breakpoints. Reevaluate the breakpoint and recreate its | |
13627 | locations. */ | |
13628 | ||
13629 | static void | |
28010a5d | 13630 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 13631 | { |
c2f4122d | 13632 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 13633 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 13634 | |
6c5b2ebe PA |
13635 | int found; |
13636 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
13637 | filter_pspace, &found); | |
ef23e705 | 13638 | if (found) |
6c5b2ebe | 13639 | expanded = std::move (sals); |
ef23e705 | 13640 | |
f00aae0f | 13641 | if (b->location_range_end != NULL) |
f1310107 | 13642 | { |
6c5b2ebe PA |
13643 | std::vector<symtab_and_line> sals_end |
13644 | = location_to_sals (b, b->location_range_end.get (), | |
13645 | filter_pspace, &found); | |
f1310107 | 13646 | if (found) |
6c5b2ebe | 13647 | expanded_end = std::move (sals_end); |
f1310107 TJB |
13648 | } |
13649 | ||
c2f4122d | 13650 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
13651 | } |
13652 | ||
983af33b SDJ |
13653 | /* Default method for creating SALs from an address string. It basically |
13654 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
13655 | ||
13656 | static void | |
f00aae0f KS |
13657 | create_sals_from_location_default (const struct event_location *location, |
13658 | struct linespec_result *canonical, | |
13659 | enum bptype type_wanted) | |
983af33b | 13660 | { |
f00aae0f | 13661 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
13662 | } |
13663 | ||
13664 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
13665 | function for the `create_breakpoints_sal' method of | |
13666 | breakpoint_ops. */ | |
13667 | ||
13668 | static void | |
13669 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
13670 | struct linespec_result *canonical, | |
e1e01040 PA |
13671 | gdb::unique_xmalloc_ptr<char> cond_string, |
13672 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13673 | enum bptype type_wanted, |
13674 | enum bpdisp disposition, | |
13675 | int thread, | |
13676 | int task, int ignore_count, | |
13677 | const struct breakpoint_ops *ops, | |
13678 | int from_tty, int enabled, | |
44f238bb | 13679 | int internal, unsigned flags) |
983af33b | 13680 | { |
e1e01040 PA |
13681 | create_breakpoints_sal (gdbarch, canonical, |
13682 | std::move (cond_string), | |
13683 | std::move (extra_string), | |
983af33b SDJ |
13684 | type_wanted, disposition, |
13685 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 13686 | enabled, internal, flags); |
983af33b SDJ |
13687 | } |
13688 | ||
13689 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 13690 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 13691 | |
6c5b2ebe | 13692 | static std::vector<symtab_and_line> |
f00aae0f KS |
13693 | decode_location_default (struct breakpoint *b, |
13694 | const struct event_location *location, | |
6c5b2ebe | 13695 | struct program_space *search_pspace) |
983af33b SDJ |
13696 | { |
13697 | struct linespec_result canonical; | |
13698 | ||
c2f4122d | 13699 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 13700 | NULL, 0, &canonical, multiple_symbols_all, |
c0e8dcd8 | 13701 | b->filter.get ()); |
983af33b SDJ |
13702 | |
13703 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 13704 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 13705 | |
6c5b2ebe | 13706 | if (!canonical.lsals.empty ()) |
983af33b | 13707 | { |
6c5b2ebe PA |
13708 | const linespec_sals &lsal = canonical.lsals[0]; |
13709 | return std::move (lsal.sals); | |
983af33b | 13710 | } |
6c5b2ebe | 13711 | return {}; |
983af33b SDJ |
13712 | } |
13713 | ||
bf469271 | 13714 | /* Reset a breakpoint. */ |
c906108c | 13715 | |
bf469271 PA |
13716 | static void |
13717 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 13718 | { |
fdf44873 TT |
13719 | input_radix = b->input_radix; |
13720 | set_language (b->language); | |
c906108c | 13721 | |
348d480f | 13722 | b->ops->re_set (b); |
c906108c SS |
13723 | } |
13724 | ||
c2f4122d PA |
13725 | /* Re-set breakpoint locations for the current program space. |
13726 | Locations bound to other program spaces are left untouched. */ | |
13727 | ||
c906108c | 13728 | void |
69de3c6a | 13729 | breakpoint_re_set (void) |
c906108c | 13730 | { |
35df4500 | 13731 | struct breakpoint *b, *b_tmp; |
2a7f3dff | 13732 | |
c5aa993b | 13733 | { |
fdf44873 TT |
13734 | scoped_restore_current_language save_language; |
13735 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 13736 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 13737 | |
8e817061 JB |
13738 | /* breakpoint_re_set_one sets the current_language to the language |
13739 | of the breakpoint it is resetting (see prepare_re_set_context) | |
13740 | before re-evaluating the breakpoint's location. This change can | |
13741 | unfortunately get undone by accident if the language_mode is set | |
13742 | to auto, and we either switch frames, or more likely in this context, | |
13743 | we select the current frame. | |
13744 | ||
13745 | We prevent this by temporarily turning the language_mode to | |
13746 | language_mode_manual. We restore it once all breakpoints | |
13747 | have been reset. */ | |
13748 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
13749 | language_mode = language_mode_manual; | |
13750 | ||
5ed8105e PA |
13751 | /* Note: we must not try to insert locations until after all |
13752 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
13753 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
13754 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 13755 | |
5ed8105e PA |
13756 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
13757 | { | |
a70b8144 | 13758 | try |
bf469271 PA |
13759 | { |
13760 | breakpoint_re_set_one (b); | |
13761 | } | |
230d2906 | 13762 | catch (const gdb_exception &ex) |
bf469271 PA |
13763 | { |
13764 | exception_fprintf (gdb_stderr, ex, | |
13765 | "Error in re-setting breakpoint %d: ", | |
13766 | b->number); | |
13767 | } | |
5ed8105e | 13768 | } |
5ed8105e PA |
13769 | |
13770 | jit_breakpoint_re_set (); | |
13771 | } | |
6c95b8df | 13772 | |
af02033e PP |
13773 | create_overlay_event_breakpoint (); |
13774 | create_longjmp_master_breakpoint (); | |
13775 | create_std_terminate_master_breakpoint (); | |
186c406b | 13776 | create_exception_master_breakpoint (); |
2a7f3dff PA |
13777 | |
13778 | /* Now we can insert. */ | |
13779 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
13780 | } |
13781 | \f | |
c906108c SS |
13782 | /* Reset the thread number of this breakpoint: |
13783 | ||
13784 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13785 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13786 | void |
fba45db2 | 13787 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13788 | { |
13789 | if (b->thread != -1) | |
13790 | { | |
00431a78 | 13791 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
13792 | |
13793 | /* We're being called after following a fork. The new fork is | |
13794 | selected as current, and unless this was a vfork will have a | |
13795 | different program space from the original thread. Reset that | |
13796 | as well. */ | |
13797 | b->loc->pspace = current_program_space; | |
c906108c SS |
13798 | } |
13799 | } | |
13800 | ||
03ac34d5 MS |
13801 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13802 | If from_tty is nonzero, it prints a message to that effect, | |
13803 | which ends with a period (no newline). */ | |
13804 | ||
c906108c | 13805 | void |
fba45db2 | 13806 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13807 | { |
52f0bd74 | 13808 | struct breakpoint *b; |
c906108c SS |
13809 | |
13810 | if (count < 0) | |
13811 | count = 0; | |
13812 | ||
13813 | ALL_BREAKPOINTS (b) | |
13814 | if (b->number == bptnum) | |
c5aa993b | 13815 | { |
d77f58be SS |
13816 | if (is_tracepoint (b)) |
13817 | { | |
13818 | if (from_tty && count != 0) | |
13819 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
13820 | bptnum); | |
13821 | return; | |
13822 | } | |
13823 | ||
c5aa993b | 13824 | b->ignore_count = count; |
221ea385 KS |
13825 | if (from_tty) |
13826 | { | |
13827 | if (count == 0) | |
3e43a32a MS |
13828 | printf_filtered (_("Will stop next time " |
13829 | "breakpoint %d is reached."), | |
221ea385 KS |
13830 | bptnum); |
13831 | else if (count == 1) | |
a3f17187 | 13832 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
13833 | bptnum); |
13834 | else | |
3e43a32a MS |
13835 | printf_filtered (_("Will ignore next %d " |
13836 | "crossings of breakpoint %d."), | |
221ea385 KS |
13837 | count, bptnum); |
13838 | } | |
76727919 | 13839 | gdb::observers::breakpoint_modified.notify (b); |
c5aa993b JM |
13840 | return; |
13841 | } | |
c906108c | 13842 | |
8a3fe4f8 | 13843 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13844 | } |
13845 | ||
c906108c SS |
13846 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13847 | ||
13848 | static void | |
0b39b52e | 13849 | ignore_command (const char *args, int from_tty) |
c906108c | 13850 | { |
0b39b52e | 13851 | const char *p = args; |
52f0bd74 | 13852 | int num; |
c906108c SS |
13853 | |
13854 | if (p == 0) | |
e2e0b3e5 | 13855 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13856 | |
c906108c | 13857 | num = get_number (&p); |
5c44784c | 13858 | if (num == 0) |
8a3fe4f8 | 13859 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13860 | if (*p == 0) |
8a3fe4f8 | 13861 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13862 | |
13863 | set_ignore_count (num, | |
13864 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13865 | from_tty); | |
221ea385 KS |
13866 | if (from_tty) |
13867 | printf_filtered ("\n"); | |
c906108c SS |
13868 | } |
13869 | \f | |
d0fe4701 XR |
13870 | |
13871 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
13872 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
13873 | |
13874 | static void | |
d0fe4701 XR |
13875 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
13876 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 13877 | { |
d0fe4701 XR |
13878 | if (bp_num_range.first == 0) |
13879 | { | |
13880 | warning (_("bad breakpoint number at or near '%d'"), | |
13881 | bp_num_range.first); | |
13882 | } | |
13883 | else | |
c906108c | 13884 | { |
d0fe4701 | 13885 | struct breakpoint *b, *tmp; |
197f0a60 | 13886 | |
d0fe4701 | 13887 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 13888 | { |
d0fe4701 XR |
13889 | bool match = false; |
13890 | ||
5c44784c | 13891 | ALL_BREAKPOINTS_SAFE (b, tmp) |
d0fe4701 | 13892 | if (b->number == i) |
5c44784c | 13893 | { |
bfd28288 | 13894 | match = true; |
48649e1b | 13895 | function (b); |
11cf8741 | 13896 | break; |
5c44784c | 13897 | } |
bfd28288 | 13898 | if (!match) |
d0fe4701 | 13899 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
c5aa993b | 13900 | } |
c906108c SS |
13901 | } |
13902 | } | |
13903 | ||
d0fe4701 XR |
13904 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
13905 | ARGS. */ | |
13906 | ||
13907 | static void | |
13908 | map_breakpoint_numbers (const char *args, | |
13909 | gdb::function_view<void (breakpoint *)> function) | |
13910 | { | |
13911 | if (args == NULL || *args == '\0') | |
13912 | error_no_arg (_("one or more breakpoint numbers")); | |
13913 | ||
13914 | number_or_range_parser parser (args); | |
13915 | ||
13916 | while (!parser.finished ()) | |
13917 | { | |
13918 | int num = parser.get_number (); | |
13919 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
13920 | } | |
13921 | } | |
13922 | ||
13923 | /* Return the breakpoint location structure corresponding to the | |
13924 | BP_NUM and LOC_NUM values. */ | |
13925 | ||
0d381245 | 13926 | static struct bp_location * |
d0fe4701 | 13927 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 13928 | { |
0d381245 | 13929 | struct breakpoint *b; |
0d381245 VP |
13930 | |
13931 | ALL_BREAKPOINTS (b) | |
13932 | if (b->number == bp_num) | |
13933 | { | |
13934 | break; | |
13935 | } | |
13936 | ||
13937 | if (!b || b->number != bp_num) | |
d0fe4701 | 13938 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 13939 | |
0d381245 | 13940 | if (loc_num == 0) |
d0fe4701 | 13941 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 13942 | |
d0fe4701 XR |
13943 | int n = 0; |
13944 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) | |
13945 | if (++n == loc_num) | |
13946 | return loc; | |
13947 | ||
13948 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
13949 | } |
13950 | ||
95e95a6d PA |
13951 | /* Modes of operation for extract_bp_num. */ |
13952 | enum class extract_bp_kind | |
13953 | { | |
13954 | /* Extracting a breakpoint number. */ | |
13955 | bp, | |
13956 | ||
13957 | /* Extracting a location number. */ | |
13958 | loc, | |
13959 | }; | |
13960 | ||
13961 | /* Extract a breakpoint or location number (as determined by KIND) | |
13962 | from the string starting at START. TRAILER is a character which | |
13963 | can be found after the number. If you don't want a trailer, use | |
13964 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
13965 | string. This always returns a positive integer. */ | |
13966 | ||
13967 | static int | |
13968 | extract_bp_num (extract_bp_kind kind, const char *start, | |
13969 | int trailer, const char **end_out = NULL) | |
13970 | { | |
13971 | const char *end = start; | |
13972 | int num = get_number_trailer (&end, trailer); | |
13973 | if (num < 0) | |
13974 | error (kind == extract_bp_kind::bp | |
13975 | ? _("Negative breakpoint number '%.*s'") | |
13976 | : _("Negative breakpoint location number '%.*s'"), | |
13977 | int (end - start), start); | |
13978 | if (num == 0) | |
13979 | error (kind == extract_bp_kind::bp | |
13980 | ? _("Bad breakpoint number '%.*s'") | |
13981 | : _("Bad breakpoint location number '%.*s'"), | |
13982 | int (end - start), start); | |
13983 | ||
13984 | if (end_out != NULL) | |
13985 | *end_out = end; | |
13986 | return num; | |
13987 | } | |
13988 | ||
13989 | /* Extract a breakpoint or location range (as determined by KIND) in | |
13990 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
13991 | representing the (inclusive) range. The returned pair's elements | |
13992 | are always positive integers. */ | |
13993 | ||
13994 | static std::pair<int, int> | |
13995 | extract_bp_or_bp_range (extract_bp_kind kind, | |
13996 | const std::string &arg, | |
13997 | std::string::size_type arg_offset) | |
13998 | { | |
13999 | std::pair<int, int> range; | |
14000 | const char *bp_loc = &arg[arg_offset]; | |
14001 | std::string::size_type dash = arg.find ('-', arg_offset); | |
14002 | if (dash != std::string::npos) | |
14003 | { | |
14004 | /* bp_loc is a range (x-z). */ | |
14005 | if (arg.length () == dash + 1) | |
14006 | error (kind == extract_bp_kind::bp | |
14007 | ? _("Bad breakpoint number at or near: '%s'") | |
14008 | : _("Bad breakpoint location number at or near: '%s'"), | |
14009 | bp_loc); | |
14010 | ||
14011 | const char *end; | |
14012 | const char *start_first = bp_loc; | |
14013 | const char *start_second = &arg[dash + 1]; | |
14014 | range.first = extract_bp_num (kind, start_first, '-'); | |
14015 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
14016 | ||
14017 | if (range.first > range.second) | |
14018 | error (kind == extract_bp_kind::bp | |
14019 | ? _("Inverted breakpoint range at '%.*s'") | |
14020 | : _("Inverted breakpoint location range at '%.*s'"), | |
14021 | int (end - start_first), start_first); | |
14022 | } | |
14023 | else | |
14024 | { | |
14025 | /* bp_loc is a single value. */ | |
14026 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
14027 | range.second = range.first; | |
14028 | } | |
14029 | return range; | |
14030 | } | |
14031 | ||
d0fe4701 XR |
14032 | /* Extract the breakpoint/location range specified by ARG. Returns |
14033 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
14034 | BP_LOC_RANGE. | |
14035 | ||
14036 | ARG may be in any of the following forms: | |
14037 | ||
14038 | x where 'x' is a breakpoint number. | |
14039 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
14040 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
14041 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
14042 | location number range. | |
14043 | */ | |
14044 | ||
cc638e86 | 14045 | static void |
d0fe4701 XR |
14046 | extract_bp_number_and_location (const std::string &arg, |
14047 | std::pair<int, int> &bp_num_range, | |
14048 | std::pair<int, int> &bp_loc_range) | |
14049 | { | |
14050 | std::string::size_type dot = arg.find ('.'); | |
14051 | ||
14052 | if (dot != std::string::npos) | |
14053 | { | |
14054 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
14055 | ||
14056 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 14057 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 14058 | |
95e95a6d PA |
14059 | bp_num_range.first |
14060 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
14061 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 14062 | |
95e95a6d PA |
14063 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
14064 | arg, dot + 1); | |
d0fe4701 XR |
14065 | } |
14066 | else | |
14067 | { | |
14068 | /* Handle x and x-y cases. */ | |
d0fe4701 | 14069 | |
95e95a6d | 14070 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
14071 | bp_loc_range.first = 0; |
14072 | bp_loc_range.second = 0; | |
14073 | } | |
d0fe4701 XR |
14074 | } |
14075 | ||
14076 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
14077 | specifies whether to enable or disable. */ | |
14078 | ||
14079 | static void | |
14080 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
14081 | { | |
14082 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
14083 | if (loc != NULL) | |
14084 | { | |
14085 | if (loc->enabled != enable) | |
14086 | { | |
14087 | loc->enabled = enable; | |
14088 | mark_breakpoint_location_modified (loc); | |
14089 | } | |
14090 | if (target_supports_enable_disable_tracepoint () | |
14091 | && current_trace_status ()->running && loc->owner | |
14092 | && is_tracepoint (loc->owner)) | |
14093 | target_disable_tracepoint (loc); | |
14094 | } | |
14095 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
14096 | |
14097 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
14098 | } |
14099 | ||
14100 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
14101 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
14102 | (inclusive) range of location numbers of that breakpoint to | |
14103 | enable/disable. ENABLE specifies whether to enable or disable the | |
14104 | location. */ | |
14105 | ||
14106 | static void | |
14107 | enable_disable_breakpoint_location_range (int bp_num, | |
14108 | std::pair<int, int> &bp_loc_range, | |
14109 | bool enable) | |
14110 | { | |
14111 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
14112 | enable_disable_bp_num_loc (bp_num, i, enable); | |
14113 | } | |
0d381245 | 14114 | |
1900040c MS |
14115 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14116 | If from_tty is nonzero, it prints a message to that effect, | |
14117 | which ends with a period (no newline). */ | |
14118 | ||
c906108c | 14119 | void |
fba45db2 | 14120 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14121 | { |
14122 | /* Never disable a watchpoint scope breakpoint; we want to | |
14123 | hit them when we leave scope so we can delete both the | |
14124 | watchpoint and its scope breakpoint at that time. */ | |
14125 | if (bpt->type == bp_watchpoint_scope) | |
14126 | return; | |
14127 | ||
b5de0fa7 | 14128 | bpt->enable_state = bp_disabled; |
c906108c | 14129 | |
b775012e LM |
14130 | /* Mark breakpoint locations modified. */ |
14131 | mark_breakpoint_modified (bpt); | |
14132 | ||
d248b706 KY |
14133 | if (target_supports_enable_disable_tracepoint () |
14134 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14135 | { | |
14136 | struct bp_location *location; | |
14137 | ||
14138 | for (location = bpt->loc; location; location = location->next) | |
14139 | target_disable_tracepoint (location); | |
14140 | } | |
14141 | ||
44702360 | 14142 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14143 | |
76727919 | 14144 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14145 | } |
14146 | ||
d0fe4701 XR |
14147 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
14148 | specified in ARGS. ARGS may be in any of the formats handled by | |
14149 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
14150 | or disable the breakpoints/locations. */ | |
14151 | ||
c906108c | 14152 | static void |
d0fe4701 | 14153 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 14154 | { |
c906108c | 14155 | if (args == 0) |
46c6471b PA |
14156 | { |
14157 | struct breakpoint *bpt; | |
14158 | ||
14159 | ALL_BREAKPOINTS (bpt) | |
14160 | if (user_breakpoint_p (bpt)) | |
d0fe4701 XR |
14161 | { |
14162 | if (enable) | |
14163 | enable_breakpoint (bpt); | |
14164 | else | |
14165 | disable_breakpoint (bpt); | |
14166 | } | |
46c6471b | 14167 | } |
9eaabc75 | 14168 | else |
0d381245 | 14169 | { |
cb791d59 | 14170 | std::string num = extract_arg (&args); |
9eaabc75 | 14171 | |
cb791d59 | 14172 | while (!num.empty ()) |
d248b706 | 14173 | { |
d0fe4701 | 14174 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 14175 | |
cc638e86 PA |
14176 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
14177 | ||
14178 | if (bp_loc_range.first == bp_loc_range.second | |
14179 | && bp_loc_range.first == 0) | |
d0fe4701 | 14180 | { |
cc638e86 PA |
14181 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
14182 | map_breakpoint_number_range (bp_num_range, | |
14183 | enable | |
14184 | ? enable_breakpoint | |
14185 | : disable_breakpoint); | |
14186 | } | |
14187 | else | |
14188 | { | |
14189 | /* Handle breakpoint ids with formats 'x.y' or | |
14190 | 'x.y-z'. */ | |
14191 | enable_disable_breakpoint_location_range | |
14192 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 14193 | } |
9eaabc75 | 14194 | num = extract_arg (&args); |
d248b706 | 14195 | } |
0d381245 | 14196 | } |
c906108c SS |
14197 | } |
14198 | ||
d0fe4701 XR |
14199 | /* The disable command disables the specified breakpoints/locations |
14200 | (or all defined breakpoints) so they're no longer effective in | |
14201 | stopping the inferior. ARGS may be in any of the forms defined in | |
14202 | extract_bp_number_and_location. */ | |
14203 | ||
14204 | static void | |
14205 | disable_command (const char *args, int from_tty) | |
14206 | { | |
14207 | enable_disable_command (args, from_tty, false); | |
14208 | } | |
14209 | ||
c906108c | 14210 | static void |
816338b5 SS |
14211 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14212 | int count) | |
c906108c | 14213 | { |
afe38095 | 14214 | int target_resources_ok; |
c906108c SS |
14215 | |
14216 | if (bpt->type == bp_hardware_breakpoint) | |
14217 | { | |
14218 | int i; | |
c5aa993b | 14219 | i = hw_breakpoint_used_count (); |
53a5351d | 14220 | target_resources_ok = |
d92524f1 | 14221 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14222 | i + 1, 0); |
c906108c | 14223 | if (target_resources_ok == 0) |
8a3fe4f8 | 14224 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14225 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14226 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14227 | } |
14228 | ||
cc60f2e3 | 14229 | if (is_watchpoint (bpt)) |
c906108c | 14230 | { |
d07205c2 | 14231 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14232 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14233 | |
a70b8144 | 14234 | try |
c906108c | 14235 | { |
3a5c3e22 PA |
14236 | struct watchpoint *w = (struct watchpoint *) bpt; |
14237 | ||
1e718ff1 TJB |
14238 | orig_enable_state = bpt->enable_state; |
14239 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14240 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14241 | } |
230d2906 | 14242 | catch (const gdb_exception &e) |
c5aa993b | 14243 | { |
1e718ff1 | 14244 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14245 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14246 | bpt->number); | |
14247 | return; | |
c5aa993b | 14248 | } |
c906108c | 14249 | } |
0101ce28 | 14250 | |
b775012e LM |
14251 | bpt->enable_state = bp_enabled; |
14252 | ||
14253 | /* Mark breakpoint locations modified. */ | |
14254 | mark_breakpoint_modified (bpt); | |
14255 | ||
d248b706 KY |
14256 | if (target_supports_enable_disable_tracepoint () |
14257 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14258 | { | |
14259 | struct bp_location *location; | |
14260 | ||
14261 | for (location = bpt->loc; location; location = location->next) | |
14262 | target_enable_tracepoint (location); | |
14263 | } | |
14264 | ||
b4c291bb | 14265 | bpt->disposition = disposition; |
816338b5 | 14266 | bpt->enable_count = count; |
44702360 | 14267 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14268 | |
76727919 | 14269 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
14270 | } |
14271 | ||
fe3f5fa8 | 14272 | |
c906108c | 14273 | void |
fba45db2 | 14274 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14275 | { |
816338b5 | 14276 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14277 | } |
14278 | ||
d0fe4701 XR |
14279 | /* The enable command enables the specified breakpoints/locations (or |
14280 | all defined breakpoints) so they once again become (or continue to | |
14281 | be) effective in stopping the inferior. ARGS may be in any of the | |
14282 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 14283 | |
c906108c | 14284 | static void |
981a3fb3 | 14285 | enable_command (const char *args, int from_tty) |
c906108c | 14286 | { |
d0fe4701 | 14287 | enable_disable_command (args, from_tty, true); |
c906108c SS |
14288 | } |
14289 | ||
c906108c | 14290 | static void |
4495129a | 14291 | enable_once_command (const char *args, int from_tty) |
c906108c | 14292 | { |
48649e1b TT |
14293 | map_breakpoint_numbers |
14294 | (args, [&] (breakpoint *b) | |
14295 | { | |
14296 | iterate_over_related_breakpoints | |
14297 | (b, [&] (breakpoint *bpt) | |
14298 | { | |
14299 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14300 | }); | |
14301 | }); | |
816338b5 SS |
14302 | } |
14303 | ||
14304 | static void | |
4495129a | 14305 | enable_count_command (const char *args, int from_tty) |
816338b5 | 14306 | { |
b9d61307 SM |
14307 | int count; |
14308 | ||
14309 | if (args == NULL) | |
14310 | error_no_arg (_("hit count")); | |
14311 | ||
14312 | count = get_number (&args); | |
816338b5 | 14313 | |
48649e1b TT |
14314 | map_breakpoint_numbers |
14315 | (args, [&] (breakpoint *b) | |
14316 | { | |
14317 | iterate_over_related_breakpoints | |
14318 | (b, [&] (breakpoint *bpt) | |
14319 | { | |
14320 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14321 | }); | |
14322 | }); | |
c906108c SS |
14323 | } |
14324 | ||
c906108c | 14325 | static void |
4495129a | 14326 | enable_delete_command (const char *args, int from_tty) |
c906108c | 14327 | { |
48649e1b TT |
14328 | map_breakpoint_numbers |
14329 | (args, [&] (breakpoint *b) | |
14330 | { | |
14331 | iterate_over_related_breakpoints | |
14332 | (b, [&] (breakpoint *bpt) | |
14333 | { | |
14334 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14335 | }); | |
14336 | }); | |
c906108c SS |
14337 | } |
14338 | \f | |
fa8d40ab | 14339 | static void |
981a3fb3 | 14340 | set_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14341 | { |
14342 | } | |
14343 | ||
14344 | static void | |
981a3fb3 | 14345 | show_breakpoint_cmd (const char *args, int from_tty) |
fa8d40ab JJ |
14346 | { |
14347 | } | |
14348 | ||
1f3b5d1b PP |
14349 | /* Invalidate last known value of any hardware watchpoint if |
14350 | the memory which that value represents has been written to by | |
14351 | GDB itself. */ | |
14352 | ||
14353 | static void | |
8de0566d YQ |
14354 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14355 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14356 | const bfd_byte *data) |
14357 | { | |
14358 | struct breakpoint *bp; | |
14359 | ||
14360 | ALL_BREAKPOINTS (bp) | |
14361 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14362 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14363 | { |
3a5c3e22 | 14364 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14365 | |
850645cf | 14366 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 PA |
14367 | { |
14368 | struct bp_location *loc; | |
14369 | ||
14370 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14371 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14372 | && loc->address + loc->length > addr | |
14373 | && addr + len > loc->address) | |
14374 | { | |
3a5c3e22 | 14375 | wp->val = NULL; |
4c1d86d9 | 14376 | wp->val_valid = false; |
3a5c3e22 PA |
14377 | } |
14378 | } | |
1f3b5d1b PP |
14379 | } |
14380 | } | |
14381 | ||
8181d85f DJ |
14382 | /* Create and insert a breakpoint for software single step. */ |
14383 | ||
14384 | void | |
6c95b8df | 14385 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 14386 | const address_space *aspace, |
4a64f543 | 14387 | CORE_ADDR next_pc) |
8181d85f | 14388 | { |
7c16b83e PA |
14389 | struct thread_info *tp = inferior_thread (); |
14390 | struct symtab_and_line sal; | |
14391 | CORE_ADDR pc = next_pc; | |
8181d85f | 14392 | |
34b7e8a6 PA |
14393 | if (tp->control.single_step_breakpoints == NULL) |
14394 | { | |
14395 | tp->control.single_step_breakpoints | |
5d5658a1 | 14396 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14397 | } |
8181d85f | 14398 | |
7c16b83e PA |
14399 | sal = find_pc_line (pc, 0); |
14400 | sal.pc = pc; | |
14401 | sal.section = find_pc_overlay (pc); | |
14402 | sal.explicit_pc = 1; | |
34b7e8a6 | 14403 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14404 | |
7c16b83e | 14405 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14406 | } |
14407 | ||
93f9a11f YQ |
14408 | /* Insert single step breakpoints according to the current state. */ |
14409 | ||
14410 | int | |
14411 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14412 | { | |
f5ea389a | 14413 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14414 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14415 | |
f5ea389a | 14416 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14417 | |
a0ff9e1a | 14418 | if (!next_pcs.empty ()) |
93f9a11f | 14419 | { |
f5ea389a | 14420 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 14421 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 14422 | |
a0ff9e1a | 14423 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14424 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14425 | ||
93f9a11f YQ |
14426 | return 1; |
14427 | } | |
14428 | else | |
14429 | return 0; | |
14430 | } | |
14431 | ||
34b7e8a6 | 14432 | /* See breakpoint.h. */ |
f02253f1 HZ |
14433 | |
14434 | int | |
7c16b83e | 14435 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 14436 | const address_space *aspace, |
7c16b83e | 14437 | CORE_ADDR pc) |
1aafd4da | 14438 | { |
7c16b83e | 14439 | struct bp_location *loc; |
1aafd4da | 14440 | |
7c16b83e PA |
14441 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14442 | if (loc->inserted | |
14443 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14444 | return 1; | |
1aafd4da | 14445 | |
7c16b83e | 14446 | return 0; |
ef370185 JB |
14447 | } |
14448 | ||
14449 | /* Check whether a software single-step breakpoint is inserted at | |
14450 | PC. */ | |
14451 | ||
14452 | int | |
accd0bcd | 14453 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
14454 | CORE_ADDR pc) |
14455 | { | |
34b7e8a6 PA |
14456 | struct breakpoint *bpt; |
14457 | ||
14458 | ALL_BREAKPOINTS (bpt) | |
14459 | { | |
14460 | if (bpt->type == bp_single_step | |
14461 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14462 | return 1; | |
14463 | } | |
14464 | return 0; | |
1aafd4da UW |
14465 | } |
14466 | ||
1042e4c0 SS |
14467 | /* Tracepoint-specific operations. */ |
14468 | ||
14469 | /* Set tracepoint count to NUM. */ | |
14470 | static void | |
14471 | set_tracepoint_count (int num) | |
14472 | { | |
14473 | tracepoint_count = num; | |
4fa62494 | 14474 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14475 | } |
14476 | ||
70221824 | 14477 | static void |
0b39b52e | 14478 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 14479 | { |
ffc2605c TT |
14480 | event_location_up location = string_to_event_location (&arg, |
14481 | current_language); | |
bac7c5cf GB |
14482 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
14483 | (location.get (), true /* is_tracepoint */); | |
55aa24fb | 14484 | |
558a9d82 | 14485 | create_breakpoint (get_current_arch (), |
ffc2605c | 14486 | location.get (), |
f00aae0f | 14487 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14488 | 0 /* tempflag */, |
14489 | bp_tracepoint /* type_wanted */, | |
14490 | 0 /* Ignore count */, | |
14491 | pending_break_support, | |
14492 | ops, | |
14493 | from_tty, | |
14494 | 1 /* enabled */, | |
14495 | 0 /* internal */, 0); | |
1042e4c0 SS |
14496 | } |
14497 | ||
70221824 | 14498 | static void |
0b39b52e | 14499 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 14500 | { |
ffc2605c TT |
14501 | event_location_up location = string_to_event_location (&arg, |
14502 | current_language); | |
558a9d82 | 14503 | create_breakpoint (get_current_arch (), |
ffc2605c | 14504 | location.get (), |
f00aae0f | 14505 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14506 | 0 /* tempflag */, |
14507 | bp_fast_tracepoint /* type_wanted */, | |
14508 | 0 /* Ignore count */, | |
14509 | pending_break_support, | |
14510 | &tracepoint_breakpoint_ops, | |
14511 | from_tty, | |
14512 | 1 /* enabled */, | |
14513 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14514 | } |
14515 | ||
14516 | /* strace command implementation. Creates a static tracepoint. */ | |
14517 | ||
70221824 | 14518 | static void |
0b39b52e | 14519 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 14520 | { |
983af33b | 14521 | struct breakpoint_ops *ops; |
ffc2605c | 14522 | event_location_up location; |
983af33b SDJ |
14523 | |
14524 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14525 | or with a normal static tracepoint. */ | |
61012eef | 14526 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14527 | { |
14528 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 14529 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
f00aae0f | 14530 | } |
983af33b | 14531 | else |
f00aae0f KS |
14532 | { |
14533 | ops = &tracepoint_breakpoint_ops; | |
14534 | location = string_to_event_location (&arg, current_language); | |
14535 | } | |
983af33b | 14536 | |
558a9d82 | 14537 | create_breakpoint (get_current_arch (), |
ffc2605c | 14538 | location.get (), |
f00aae0f | 14539 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14540 | 0 /* tempflag */, |
14541 | bp_static_tracepoint /* type_wanted */, | |
14542 | 0 /* Ignore count */, | |
14543 | pending_break_support, | |
14544 | ops, | |
14545 | from_tty, | |
14546 | 1 /* enabled */, | |
14547 | 0 /* internal */, 0); | |
7a697b8d SS |
14548 | } |
14549 | ||
409873ef SS |
14550 | /* Set up a fake reader function that gets command lines from a linked |
14551 | list that was acquired during tracepoint uploading. */ | |
14552 | ||
14553 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14554 | static int next_cmd; |
409873ef SS |
14555 | |
14556 | static char * | |
14557 | read_uploaded_action (void) | |
14558 | { | |
a18ba4e4 | 14559 | char *rslt = nullptr; |
409873ef | 14560 | |
a18ba4e4 SM |
14561 | if (next_cmd < this_utp->cmd_strings.size ()) |
14562 | { | |
67aa1f3c | 14563 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
14564 | next_cmd++; |
14565 | } | |
409873ef SS |
14566 | |
14567 | return rslt; | |
14568 | } | |
14569 | ||
00bf0b85 SS |
14570 | /* Given information about a tracepoint as recorded on a target (which |
14571 | can be either a live system or a trace file), attempt to create an | |
14572 | equivalent GDB tracepoint. This is not a reliable process, since | |
14573 | the target does not necessarily have all the information used when | |
14574 | the tracepoint was originally defined. */ | |
14575 | ||
d9b3f62e | 14576 | struct tracepoint * |
00bf0b85 | 14577 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14578 | { |
f2fc3015 TT |
14579 | const char *addr_str; |
14580 | char small_buf[100]; | |
d9b3f62e | 14581 | struct tracepoint *tp; |
fd9b8c24 | 14582 | |
409873ef | 14583 | if (utp->at_string) |
67aa1f3c | 14584 | addr_str = utp->at_string.get (); |
409873ef SS |
14585 | else |
14586 | { | |
14587 | /* In the absence of a source location, fall back to raw | |
14588 | address. Since there is no way to confirm that the address | |
14589 | means the same thing as when the trace was started, warn the | |
14590 | user. */ | |
3e43a32a MS |
14591 | warning (_("Uploaded tracepoint %d has no " |
14592 | "source location, using raw address"), | |
409873ef | 14593 | utp->number); |
8c042590 | 14594 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14595 | addr_str = small_buf; |
14596 | } | |
14597 | ||
14598 | /* There's not much we can do with a sequence of bytecodes. */ | |
14599 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14600 | warning (_("Uploaded tracepoint %d condition " |
14601 | "has no source form, ignoring it"), | |
409873ef | 14602 | utp->number); |
d5551862 | 14603 | |
ffc2605c TT |
14604 | event_location_up location = string_to_event_location (&addr_str, |
14605 | current_language); | |
8cdf0e15 | 14606 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14607 | location.get (), |
67aa1f3c | 14608 | utp->cond_string.get (), -1, addr_str, |
e7e0cddf | 14609 | 0 /* parse cond/thread */, |
8cdf0e15 | 14610 | 0 /* tempflag */, |
0fb4aa4b | 14611 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14612 | 0 /* Ignore count */, |
14613 | pending_break_support, | |
348d480f | 14614 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14615 | 0 /* from_tty */, |
84f4c1fe | 14616 | utp->enabled /* enabled */, |
44f238bb PA |
14617 | 0 /* internal */, |
14618 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14619 | return NULL; |
fd9b8c24 | 14620 | |
409873ef | 14621 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14622 | tp = get_tracepoint (tracepoint_count); |
14623 | gdb_assert (tp != NULL); | |
d5551862 | 14624 | |
00bf0b85 SS |
14625 | if (utp->pass > 0) |
14626 | { | |
8c042590 | 14627 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14628 | tp->number); |
00bf0b85 | 14629 | |
409873ef | 14630 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14631 | } |
14632 | ||
409873ef SS |
14633 | /* If we have uploaded versions of the original commands, set up a |
14634 | special-purpose "reader" function and call the usual command line | |
14635 | reader, then pass the result to the breakpoint command-setting | |
14636 | function. */ | |
a18ba4e4 | 14637 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 14638 | { |
12973681 | 14639 | counted_command_line cmd_list; |
00bf0b85 | 14640 | |
409873ef | 14641 | this_utp = utp; |
3149d8c1 | 14642 | next_cmd = 0; |
d5551862 | 14643 | |
60b3cef2 | 14644 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 14645 | |
c1fc2657 | 14646 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14647 | } |
a18ba4e4 SM |
14648 | else if (!utp->actions.empty () |
14649 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
14650 | warning (_("Uploaded tracepoint %d actions " |
14651 | "have no source form, ignoring them"), | |
409873ef | 14652 | utp->number); |
00bf0b85 | 14653 | |
f196051f | 14654 | /* Copy any status information that might be available. */ |
c1fc2657 | 14655 | tp->hit_count = utp->hit_count; |
f196051f SS |
14656 | tp->traceframe_usage = utp->traceframe_usage; |
14657 | ||
00bf0b85 | 14658 | return tp; |
d9b3f62e | 14659 | } |
00bf0b85 | 14660 | |
1042e4c0 SS |
14661 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14662 | omitted. */ | |
14663 | ||
14664 | static void | |
1d12d88f | 14665 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 14666 | { |
79a45e25 | 14667 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14668 | int num_printed; |
1042e4c0 | 14669 | |
5c458ae8 | 14670 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
d77f58be SS |
14671 | |
14672 | if (num_printed == 0) | |
1042e4c0 | 14673 | { |
e5a67952 | 14674 | if (args == NULL || *args == '\0') |
112e8700 | 14675 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14676 | else |
112e8700 | 14677 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14678 | } |
ad443146 SS |
14679 | |
14680 | default_collect_info (); | |
1042e4c0 SS |
14681 | } |
14682 | ||
4a64f543 | 14683 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14684 | Not supported by all targets. */ |
14685 | static void | |
5fed81ff | 14686 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14687 | { |
14688 | enable_command (args, from_tty); | |
14689 | } | |
14690 | ||
4a64f543 | 14691 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
14692 | Not supported by all targets. */ |
14693 | static void | |
5fed81ff | 14694 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
14695 | { |
14696 | disable_command (args, from_tty); | |
14697 | } | |
14698 | ||
4a64f543 | 14699 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 14700 | static void |
4495129a | 14701 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 14702 | { |
35df4500 | 14703 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
14704 | |
14705 | dont_repeat (); | |
14706 | ||
14707 | if (arg == 0) | |
14708 | { | |
14709 | int breaks_to_delete = 0; | |
14710 | ||
14711 | /* Delete all breakpoints if no argument. | |
14712 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
14713 | have to be deleted with an explicit breakpoint number |
14714 | argument. */ | |
1042e4c0 | 14715 | ALL_TRACEPOINTS (b) |
46c6471b | 14716 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
14717 | { |
14718 | breaks_to_delete = 1; | |
14719 | break; | |
14720 | } | |
1042e4c0 SS |
14721 | |
14722 | /* Ask user only if there are some breakpoints to delete. */ | |
14723 | if (!from_tty | |
14724 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
14725 | { | |
35df4500 | 14726 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 14727 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 14728 | delete_breakpoint (b); |
1042e4c0 SS |
14729 | } |
14730 | } | |
14731 | else | |
48649e1b | 14732 | map_breakpoint_numbers |
b926417a | 14733 | (arg, [&] (breakpoint *br) |
48649e1b | 14734 | { |
b926417a | 14735 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 14736 | }); |
1042e4c0 SS |
14737 | } |
14738 | ||
197f0a60 TT |
14739 | /* Helper function for trace_pass_command. */ |
14740 | ||
14741 | static void | |
d9b3f62e | 14742 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 14743 | { |
d9b3f62e | 14744 | tp->pass_count = count; |
76727919 | 14745 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 TT |
14746 | if (from_tty) |
14747 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 14748 | tp->number, count); |
197f0a60 TT |
14749 | } |
14750 | ||
1042e4c0 SS |
14751 | /* Set passcount for tracepoint. |
14752 | ||
14753 | First command argument is passcount, second is tracepoint number. | |
14754 | If tracepoint number omitted, apply to most recently defined. | |
14755 | Also accepts special argument "all". */ | |
14756 | ||
14757 | static void | |
0b39b52e | 14758 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 14759 | { |
d9b3f62e | 14760 | struct tracepoint *t1; |
0b39b52e | 14761 | ULONGEST count; |
1042e4c0 SS |
14762 | |
14763 | if (args == 0 || *args == 0) | |
3e43a32a MS |
14764 | error (_("passcount command requires an " |
14765 | "argument (count + optional TP num)")); | |
1042e4c0 | 14766 | |
0b39b52e | 14767 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 14768 | |
529480d0 | 14769 | args = skip_spaces (args); |
1042e4c0 SS |
14770 | if (*args && strncasecmp (args, "all", 3) == 0) |
14771 | { | |
d9b3f62e PA |
14772 | struct breakpoint *b; |
14773 | ||
1042e4c0 | 14774 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
14775 | if (*args) |
14776 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 14777 | |
d9b3f62e | 14778 | ALL_TRACEPOINTS (b) |
197f0a60 | 14779 | { |
d9b3f62e | 14780 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
14781 | trace_pass_set_count (t1, count, from_tty); |
14782 | } | |
14783 | } | |
14784 | else if (*args == '\0') | |
1042e4c0 | 14785 | { |
5fa1d40e | 14786 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 14787 | if (t1) |
197f0a60 TT |
14788 | trace_pass_set_count (t1, count, from_tty); |
14789 | } | |
14790 | else | |
14791 | { | |
bfd28288 PA |
14792 | number_or_range_parser parser (args); |
14793 | while (!parser.finished ()) | |
1042e4c0 | 14794 | { |
bfd28288 | 14795 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
14796 | if (t1) |
14797 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14798 | } |
14799 | } | |
1042e4c0 SS |
14800 | } |
14801 | ||
d9b3f62e | 14802 | struct tracepoint * |
1042e4c0 SS |
14803 | get_tracepoint (int num) |
14804 | { | |
14805 | struct breakpoint *t; | |
14806 | ||
14807 | ALL_TRACEPOINTS (t) | |
14808 | if (t->number == num) | |
d9b3f62e | 14809 | return (struct tracepoint *) t; |
1042e4c0 SS |
14810 | |
14811 | return NULL; | |
14812 | } | |
14813 | ||
d5551862 SS |
14814 | /* Find the tracepoint with the given target-side number (which may be |
14815 | different from the tracepoint number after disconnecting and | |
14816 | reconnecting). */ | |
14817 | ||
d9b3f62e | 14818 | struct tracepoint * |
d5551862 SS |
14819 | get_tracepoint_by_number_on_target (int num) |
14820 | { | |
d9b3f62e | 14821 | struct breakpoint *b; |
d5551862 | 14822 | |
d9b3f62e PA |
14823 | ALL_TRACEPOINTS (b) |
14824 | { | |
14825 | struct tracepoint *t = (struct tracepoint *) b; | |
14826 | ||
14827 | if (t->number_on_target == num) | |
14828 | return t; | |
14829 | } | |
d5551862 SS |
14830 | |
14831 | return NULL; | |
14832 | } | |
14833 | ||
1042e4c0 | 14834 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 14835 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
14836 | If the argument is missing, the most recent tracepoint |
14837 | (tracepoint_count) is returned. */ | |
14838 | ||
d9b3f62e | 14839 | struct tracepoint * |
0b39b52e | 14840 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 14841 | number_or_range_parser *parser) |
1042e4c0 | 14842 | { |
1042e4c0 SS |
14843 | struct breakpoint *t; |
14844 | int tpnum; | |
0b39b52e | 14845 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 14846 | |
bfd28288 | 14847 | if (parser != NULL) |
197f0a60 | 14848 | { |
bfd28288 PA |
14849 | gdb_assert (!parser->finished ()); |
14850 | tpnum = parser->get_number (); | |
197f0a60 TT |
14851 | } |
14852 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 14853 | tpnum = tracepoint_count; |
1042e4c0 | 14854 | else |
197f0a60 | 14855 | tpnum = get_number (arg); |
1042e4c0 SS |
14856 | |
14857 | if (tpnum <= 0) | |
14858 | { | |
14859 | if (instring && *instring) | |
14860 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
14861 | instring); | |
14862 | else | |
5fa1d40e | 14863 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
14864 | return NULL; |
14865 | } | |
14866 | ||
14867 | ALL_TRACEPOINTS (t) | |
14868 | if (t->number == tpnum) | |
14869 | { | |
d9b3f62e | 14870 | return (struct tracepoint *) t; |
1042e4c0 SS |
14871 | } |
14872 | ||
1042e4c0 SS |
14873 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
14874 | return NULL; | |
14875 | } | |
14876 | ||
d9b3f62e PA |
14877 | void |
14878 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14879 | { | |
14880 | if (b->thread != -1) | |
14881 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
14882 | ||
14883 | if (b->task != 0) | |
14884 | fprintf_unfiltered (fp, " task %d", b->task); | |
14885 | ||
14886 | fprintf_unfiltered (fp, "\n"); | |
14887 | } | |
14888 | ||
6149aea9 PA |
14889 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14890 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14891 | on each breakpoint and only include the ones for which it returns | |
f2478a7e | 14892 | true. */ |
6149aea9 | 14893 | |
1042e4c0 | 14894 | static void |
4495129a | 14895 | save_breakpoints (const char *filename, int from_tty, |
f2478a7e | 14896 | bool (*filter) (const struct breakpoint *)) |
1042e4c0 SS |
14897 | { |
14898 | struct breakpoint *tp; | |
6149aea9 | 14899 | int any = 0; |
6149aea9 | 14900 | int extra_trace_bits = 0; |
1042e4c0 | 14901 | |
6149aea9 PA |
14902 | if (filename == 0 || *filename == 0) |
14903 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14904 | |
14905 | /* See if we have anything to save. */ | |
6149aea9 | 14906 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14907 | { |
6149aea9 | 14908 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14909 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
14910 | continue; |
14911 | ||
14912 | /* If we have a filter, only save the breakpoints it accepts. */ | |
14913 | if (filter && !filter (tp)) | |
14914 | continue; | |
14915 | ||
14916 | any = 1; | |
14917 | ||
14918 | if (is_tracepoint (tp)) | |
14919 | { | |
14920 | extra_trace_bits = 1; | |
14921 | ||
14922 | /* We can stop searching. */ | |
14923 | break; | |
14924 | } | |
1042e4c0 | 14925 | } |
6149aea9 PA |
14926 | |
14927 | if (!any) | |
1042e4c0 | 14928 | { |
6149aea9 | 14929 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14930 | return; |
14931 | } | |
14932 | ||
ee0c3293 | 14933 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
14934 | |
14935 | stdio_file fp; | |
14936 | ||
ee0c3293 | 14937 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 14938 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 14939 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 14940 | |
6149aea9 | 14941 | if (extra_trace_bits) |
d7e74731 | 14942 | save_trace_state_variables (&fp); |
8bf6485c | 14943 | |
6149aea9 | 14944 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 14945 | { |
6149aea9 | 14946 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 14947 | if (!user_breakpoint_p (tp)) |
6149aea9 | 14948 | continue; |
8bf6485c | 14949 | |
6149aea9 PA |
14950 | /* If we have a filter, only save the breakpoints it accepts. */ |
14951 | if (filter && !filter (tp)) | |
14952 | continue; | |
14953 | ||
d7e74731 | 14954 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 14955 | |
6149aea9 PA |
14956 | /* Note, we can't rely on tp->number for anything, as we can't |
14957 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14958 | instead. */ | |
14959 | ||
14960 | if (tp->cond_string) | |
d7e74731 | 14961 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
14962 | |
14963 | if (tp->ignore_count) | |
d7e74731 | 14964 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 14965 | |
2d9442cc | 14966 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 14967 | { |
d7e74731 | 14968 | fp.puts (" commands\n"); |
a7bdde9e | 14969 | |
d7e74731 | 14970 | current_uiout->redirect (&fp); |
a70b8144 | 14971 | try |
1042e4c0 | 14972 | { |
d1b0a7bf | 14973 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 14974 | } |
230d2906 | 14975 | catch (const gdb_exception &ex) |
492d29ea | 14976 | { |
112e8700 | 14977 | current_uiout->redirect (NULL); |
eedc3f4f | 14978 | throw; |
492d29ea | 14979 | } |
1042e4c0 | 14980 | |
112e8700 | 14981 | current_uiout->redirect (NULL); |
d7e74731 | 14982 | fp.puts (" end\n"); |
1042e4c0 | 14983 | } |
6149aea9 PA |
14984 | |
14985 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 14986 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
14987 | |
14988 | /* If this is a multi-location breakpoint, check if the locations | |
14989 | should be individually disabled. Watchpoint locations are | |
14990 | special, and not user visible. */ | |
14991 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
14992 | { | |
14993 | struct bp_location *loc; | |
14994 | int n = 1; | |
14995 | ||
14996 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
14997 | if (!loc->enabled) | |
d7e74731 | 14998 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 14999 | } |
1042e4c0 | 15000 | } |
8bf6485c | 15001 | |
6149aea9 | 15002 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15003 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15004 | |
1042e4c0 | 15005 | if (from_tty) |
ee0c3293 | 15006 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15007 | } |
15008 | ||
15009 | /* The `save breakpoints' command. */ | |
15010 | ||
15011 | static void | |
4495129a | 15012 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
15013 | { |
15014 | save_breakpoints (args, from_tty, NULL); | |
15015 | } | |
15016 | ||
15017 | /* The `save tracepoints' command. */ | |
15018 | ||
15019 | static void | |
4495129a | 15020 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
15021 | { |
15022 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15023 | } |
15024 | ||
15025 | /* Create a vector of all tracepoints. */ | |
15026 | ||
f51e0e20 | 15027 | std::vector<breakpoint *> |
eeae04df | 15028 | all_tracepoints (void) |
1042e4c0 | 15029 | { |
f51e0e20 | 15030 | std::vector<breakpoint *> tp_vec; |
1042e4c0 SS |
15031 | struct breakpoint *tp; |
15032 | ||
15033 | ALL_TRACEPOINTS (tp) | |
15034 | { | |
f51e0e20 | 15035 | tp_vec.push_back (tp); |
1042e4c0 SS |
15036 | } |
15037 | ||
15038 | return tp_vec; | |
15039 | } | |
15040 | ||
c906108c | 15041 | \f |
629500fa KS |
15042 | /* This help string is used to consolidate all the help string for specifying |
15043 | locations used by several commands. */ | |
15044 | ||
15045 | #define LOCATION_HELP_STRING \ | |
15046 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15047 | source filename, function name, label name, and line number.\n\ | |
15048 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15049 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15050 | \"factorial.c:fact:the_top\".\n\ | |
15051 | \n\ | |
15052 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15053 | program. Example: To specify the fourth byte past the start function\n\ | |
15054 | \"main\", use \"*main + 4\".\n\ | |
15055 | \n\ | |
15056 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15057 | syntax to specify location parameters.\n\ | |
15058 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15059 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
15060 | -function fact -label the_top\".\n\ |
15061 | \n\ | |
15062 | By default, a specified function is matched against the program's\n\ | |
15063 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
15064 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
15065 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
15066 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 15067 | specified name as a complete fully-qualified name instead." |
629500fa | 15068 | |
4a64f543 MS |
15069 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15070 | commands. It is defined as a macro to prevent duplication. | |
15071 | COMMAND should be a string constant containing the name of the | |
15072 | command. */ | |
629500fa | 15073 | |
31e2b00f | 15074 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15075 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15076 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15077 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15078 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15079 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15080 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15081 | below.\n\ | |
15082 | \n\ | |
dc10affe PA |
15083 | With no LOCATION, uses current execution address of the selected\n\ |
15084 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15085 | \n\ |
15086 | THREADNUM is the number from \"info threads\".\n\ | |
15087 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15088 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15089 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15090 | conditions are different.\n\ | |
31e2b00f AS |
15091 | \n\ |
15092 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15093 | ||
44feb3ce TT |
15094 | /* List of subcommands for "catch". */ |
15095 | static struct cmd_list_element *catch_cmdlist; | |
15096 | ||
15097 | /* List of subcommands for "tcatch". */ | |
15098 | static struct cmd_list_element *tcatch_cmdlist; | |
15099 | ||
9ac4176b | 15100 | void |
a121b7c1 | 15101 | add_catch_command (const char *name, const char *docstring, |
eb4c3f4a | 15102 | cmd_const_sfunc_ftype *sfunc, |
625e8578 | 15103 | completer_ftype *completer, |
44feb3ce TT |
15104 | void *user_data_catch, |
15105 | void *user_data_tcatch) | |
15106 | { | |
15107 | struct cmd_list_element *command; | |
15108 | ||
0450cc4c | 15109 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15110 | &catch_cmdlist); |
15111 | set_cmd_sfunc (command, sfunc); | |
15112 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15113 | set_cmd_completer (command, completer); |
44feb3ce | 15114 | |
0450cc4c | 15115 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce TT |
15116 | &tcatch_cmdlist); |
15117 | set_cmd_sfunc (command, sfunc); | |
15118 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15119 | set_cmd_completer (command, completer); |
44feb3ce TT |
15120 | } |
15121 | ||
6149aea9 | 15122 | static void |
981a3fb3 | 15123 | save_command (const char *arg, int from_tty) |
6149aea9 | 15124 | { |
3e43a32a MS |
15125 | printf_unfiltered (_("\"save\" must be followed by " |
15126 | "the name of a save subcommand.\n")); | |
635c7e8a | 15127 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15128 | } |
15129 | ||
84f4c1fe | 15130 | struct breakpoint * |
95da600f | 15131 | iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback) |
84f4c1fe | 15132 | { |
35df4500 | 15133 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15134 | |
35df4500 | 15135 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe | 15136 | { |
95da600f | 15137 | if (callback (b)) |
84f4c1fe PM |
15138 | return b; |
15139 | } | |
15140 | ||
15141 | return NULL; | |
15142 | } | |
15143 | ||
0574c78f GB |
15144 | /* Zero if any of the breakpoint's locations could be a location where |
15145 | functions have been inlined, nonzero otherwise. */ | |
15146 | ||
15147 | static int | |
15148 | is_non_inline_function (struct breakpoint *b) | |
15149 | { | |
15150 | /* The shared library event breakpoint is set on the address of a | |
15151 | non-inline function. */ | |
15152 | if (b->type == bp_shlib_event) | |
15153 | return 1; | |
15154 | ||
15155 | return 0; | |
15156 | } | |
15157 | ||
15158 | /* Nonzero if the specified PC cannot be a location where functions | |
15159 | have been inlined. */ | |
15160 | ||
15161 | int | |
accd0bcd | 15162 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
09ac7c10 | 15163 | const struct target_waitstatus *ws) |
0574c78f GB |
15164 | { |
15165 | struct breakpoint *b; | |
15166 | struct bp_location *bl; | |
15167 | ||
15168 | ALL_BREAKPOINTS (b) | |
15169 | { | |
15170 | if (!is_non_inline_function (b)) | |
15171 | continue; | |
15172 | ||
15173 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15174 | { | |
15175 | if (!bl->shlib_disabled | |
09ac7c10 | 15176 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15177 | return 1; |
15178 | } | |
15179 | } | |
15180 | ||
15181 | return 0; | |
15182 | } | |
15183 | ||
2f202fde JK |
15184 | /* Remove any references to OBJFILE which is going to be freed. */ |
15185 | ||
15186 | void | |
15187 | breakpoint_free_objfile (struct objfile *objfile) | |
15188 | { | |
15189 | struct bp_location **locp, *loc; | |
15190 | ||
15191 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15192 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15193 | loc->symtab = NULL; |
15194 | } | |
15195 | ||
2060206e PA |
15196 | void |
15197 | initialize_breakpoint_ops (void) | |
15198 | { | |
15199 | static int initialized = 0; | |
15200 | ||
15201 | struct breakpoint_ops *ops; | |
15202 | ||
15203 | if (initialized) | |
15204 | return; | |
15205 | initialized = 1; | |
15206 | ||
15207 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15208 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15209 | internal and momentary breakpoints, etc.). */ | |
15210 | ops = &bkpt_base_breakpoint_ops; | |
15211 | *ops = base_breakpoint_ops; | |
15212 | ops->re_set = bkpt_re_set; | |
15213 | ops->insert_location = bkpt_insert_location; | |
15214 | ops->remove_location = bkpt_remove_location; | |
15215 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15216 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15217 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15218 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15219 | |
15220 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15221 | ops = &bkpt_breakpoint_ops; | |
15222 | *ops = bkpt_base_breakpoint_ops; | |
15223 | ops->re_set = bkpt_re_set; | |
15224 | ops->resources_needed = bkpt_resources_needed; | |
15225 | ops->print_it = bkpt_print_it; | |
15226 | ops->print_mention = bkpt_print_mention; | |
15227 | ops->print_recreate = bkpt_print_recreate; | |
15228 | ||
15229 | /* Ranged breakpoints. */ | |
15230 | ops = &ranged_breakpoint_ops; | |
15231 | *ops = bkpt_breakpoint_ops; | |
15232 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15233 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15234 | ops->print_it = print_it_ranged_breakpoint; | |
15235 | ops->print_one = print_one_ranged_breakpoint; | |
15236 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15237 | ops->print_mention = print_mention_ranged_breakpoint; | |
15238 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15239 | ||
15240 | /* Internal breakpoints. */ | |
15241 | ops = &internal_breakpoint_ops; | |
15242 | *ops = bkpt_base_breakpoint_ops; | |
15243 | ops->re_set = internal_bkpt_re_set; | |
15244 | ops->check_status = internal_bkpt_check_status; | |
15245 | ops->print_it = internal_bkpt_print_it; | |
15246 | ops->print_mention = internal_bkpt_print_mention; | |
15247 | ||
15248 | /* Momentary breakpoints. */ | |
15249 | ops = &momentary_breakpoint_ops; | |
15250 | *ops = bkpt_base_breakpoint_ops; | |
15251 | ops->re_set = momentary_bkpt_re_set; | |
15252 | ops->check_status = momentary_bkpt_check_status; | |
15253 | ops->print_it = momentary_bkpt_print_it; | |
15254 | ops->print_mention = momentary_bkpt_print_mention; | |
15255 | ||
55aa24fb SDJ |
15256 | /* Probe breakpoints. */ |
15257 | ops = &bkpt_probe_breakpoint_ops; | |
15258 | *ops = bkpt_breakpoint_ops; | |
15259 | ops->insert_location = bkpt_probe_insert_location; | |
15260 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15261 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15262 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15263 | |
2060206e PA |
15264 | /* Watchpoints. */ |
15265 | ops = &watchpoint_breakpoint_ops; | |
15266 | *ops = base_breakpoint_ops; | |
15267 | ops->re_set = re_set_watchpoint; | |
15268 | ops->insert_location = insert_watchpoint; | |
15269 | ops->remove_location = remove_watchpoint; | |
15270 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15271 | ops->check_status = check_status_watchpoint; | |
15272 | ops->resources_needed = resources_needed_watchpoint; | |
15273 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15274 | ops->print_it = print_it_watchpoint; | |
15275 | ops->print_mention = print_mention_watchpoint; | |
15276 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15277 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15278 | |
15279 | /* Masked watchpoints. */ | |
15280 | ops = &masked_watchpoint_breakpoint_ops; | |
15281 | *ops = watchpoint_breakpoint_ops; | |
15282 | ops->insert_location = insert_masked_watchpoint; | |
15283 | ops->remove_location = remove_masked_watchpoint; | |
15284 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15285 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15286 | ops->print_it = print_it_masked_watchpoint; | |
15287 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15288 | ops->print_mention = print_mention_masked_watchpoint; | |
15289 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15290 | ||
15291 | /* Tracepoints. */ | |
15292 | ops = &tracepoint_breakpoint_ops; | |
15293 | *ops = base_breakpoint_ops; | |
15294 | ops->re_set = tracepoint_re_set; | |
15295 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15296 | ops->print_one_detail = tracepoint_print_one_detail; | |
15297 | ops->print_mention = tracepoint_print_mention; | |
15298 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15299 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15300 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15301 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15302 | |
55aa24fb SDJ |
15303 | /* Probe tracepoints. */ |
15304 | ops = &tracepoint_probe_breakpoint_ops; | |
15305 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15306 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15307 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15308 | |
983af33b SDJ |
15309 | /* Static tracepoints with marker (`-m'). */ |
15310 | ops = &strace_marker_breakpoint_ops; | |
15311 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15312 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15313 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15314 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15315 | |
15316 | /* Fork catchpoints. */ | |
15317 | ops = &catch_fork_breakpoint_ops; | |
15318 | *ops = base_breakpoint_ops; | |
15319 | ops->insert_location = insert_catch_fork; | |
15320 | ops->remove_location = remove_catch_fork; | |
15321 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15322 | ops->print_it = print_it_catch_fork; | |
15323 | ops->print_one = print_one_catch_fork; | |
15324 | ops->print_mention = print_mention_catch_fork; | |
15325 | ops->print_recreate = print_recreate_catch_fork; | |
15326 | ||
15327 | /* Vfork catchpoints. */ | |
15328 | ops = &catch_vfork_breakpoint_ops; | |
15329 | *ops = base_breakpoint_ops; | |
15330 | ops->insert_location = insert_catch_vfork; | |
15331 | ops->remove_location = remove_catch_vfork; | |
15332 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15333 | ops->print_it = print_it_catch_vfork; | |
15334 | ops->print_one = print_one_catch_vfork; | |
15335 | ops->print_mention = print_mention_catch_vfork; | |
15336 | ops->print_recreate = print_recreate_catch_vfork; | |
15337 | ||
15338 | /* Exec catchpoints. */ | |
15339 | ops = &catch_exec_breakpoint_ops; | |
15340 | *ops = base_breakpoint_ops; | |
2060206e PA |
15341 | ops->insert_location = insert_catch_exec; |
15342 | ops->remove_location = remove_catch_exec; | |
15343 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15344 | ops->print_it = print_it_catch_exec; | |
15345 | ops->print_one = print_one_catch_exec; | |
15346 | ops->print_mention = print_mention_catch_exec; | |
15347 | ops->print_recreate = print_recreate_catch_exec; | |
15348 | ||
edcc5120 TT |
15349 | /* Solib-related catchpoints. */ |
15350 | ops = &catch_solib_breakpoint_ops; | |
15351 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15352 | ops->insert_location = insert_catch_solib; |
15353 | ops->remove_location = remove_catch_solib; | |
15354 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15355 | ops->check_status = check_status_catch_solib; | |
15356 | ops->print_it = print_it_catch_solib; | |
15357 | ops->print_one = print_one_catch_solib; | |
15358 | ops->print_mention = print_mention_catch_solib; | |
15359 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15360 | |
15361 | ops = &dprintf_breakpoint_ops; | |
15362 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15363 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15364 | ops->resources_needed = bkpt_resources_needed; |
15365 | ops->print_it = bkpt_print_it; | |
15366 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15367 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15368 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15369 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15370 | } |
15371 | ||
8bfd80db YQ |
15372 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15373 | ||
15374 | static struct cmd_list_element *enablebreaklist = NULL; | |
15375 | ||
8588b356 SM |
15376 | /* See breakpoint.h. */ |
15377 | ||
15378 | cmd_list_element *commands_cmd_element = nullptr; | |
15379 | ||
6c265988 | 15380 | void _initialize_breakpoint (); |
c906108c | 15381 | void |
6c265988 | 15382 | _initialize_breakpoint () |
c906108c SS |
15383 | { |
15384 | struct cmd_list_element *c; | |
15385 | ||
2060206e PA |
15386 | initialize_breakpoint_ops (); |
15387 | ||
76727919 TT |
15388 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
15389 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); | |
15390 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); | |
84acb35a | 15391 | |
c906108c SS |
15392 | breakpoint_chain = 0; |
15393 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15394 | before a breakpoint is set. */ | |
15395 | breakpoint_count = 0; | |
15396 | ||
1042e4c0 SS |
15397 | tracepoint_count = 0; |
15398 | ||
1bedd215 AC |
15399 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15400 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15401 | Usage is `ignore N COUNT'.")); | |
c906108c | 15402 | |
8588b356 SM |
15403 | commands_cmd_element = add_com ("commands", class_breakpoint, |
15404 | commands_command, _("\ | |
18da0c51 MG |
15405 | Set commands to be executed when the given breakpoints are hit.\n\ |
15406 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15407 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15408 | (e.g. `5-7').\n\ | |
c906108c SS |
15409 | With no argument, the targeted breakpoint is the last one set.\n\ |
15410 | The commands themselves follow starting on the next line.\n\ | |
15411 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15412 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15413 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15414 | |
d55637df | 15415 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15416 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15417 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15418 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15419 | set_cmd_completer (c, condition_completer); |
c906108c | 15420 | |
1bedd215 | 15421 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15422 | Set a temporary breakpoint.\n\ |
c906108c SS |
15423 | Like \"break\" except the breakpoint is only temporary,\n\ |
15424 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15425 | by using \"enable delete\" on the breakpoint number.\n\ |
15426 | \n" | |
15427 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15428 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15429 | |
1bedd215 | 15430 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15431 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15432 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15433 | some target hardware may not have this support.\n\ |
15434 | \n" | |
15435 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15436 | set_cmd_completer (c, location_completer); |
c906108c | 15437 | |
1bedd215 | 15438 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15439 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15440 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15441 | so it will be deleted when hit.\n\ |
15442 | \n" | |
15443 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15444 | set_cmd_completer (c, location_completer); |
c906108c | 15445 | |
1bedd215 | 15446 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
590042fc PW |
15447 | Enable all or some breakpoints.\n\ |
15448 | Usage: enable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15449 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15450 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15451 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15452 | With a subcommand you can enable temporarily."), |
c906108c | 15453 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15454 | |
15455 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15456 | ||
84951ab5 | 15457 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
590042fc PW |
15458 | Enable all or some breakpoints.\n\ |
15459 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15460 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15461 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 15462 | May be abbreviated to simply \"enable\"."), |
c5aa993b | 15463 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15464 | |
1a966eab | 15465 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15466 | Enable some breakpoints for one hit.\n\ |
15467 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ | |
1a966eab | 15468 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
c906108c SS |
15469 | &enablebreaklist); |
15470 | ||
1a966eab | 15471 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15472 | Enable some breakpoints and delete when hit.\n\ |
15473 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ | |
1a966eab | 15474 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15475 | &enablebreaklist); |
15476 | ||
816338b5 | 15477 | add_cmd ("count", no_class, enable_count_command, _("\ |
590042fc PW |
15478 | Enable some breakpoints for COUNT hits.\n\ |
15479 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15480 | If a breakpoint is hit while enabled in this fashion,\n\ |
15481 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15482 | &enablebreaklist); | |
15483 | ||
1a966eab | 15484 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
15485 | Enable some breakpoints and delete when hit.\n\ |
15486 | Usage: enable delete BREAKPOINTNUM...\n\ | |
1a966eab | 15487 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
15488 | &enablelist); |
15489 | ||
1a966eab | 15490 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
15491 | Enable some breakpoints for one hit.\n\ |
15492 | Usage: enable once BREAKPOINTNUM...\n\ | |
1a966eab | 15493 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
816338b5 SS |
15494 | &enablelist); |
15495 | ||
15496 | add_cmd ("count", no_class, enable_count_command, _("\ | |
590042fc PW |
15497 | Enable some breakpoints for COUNT hits.\n\ |
15498 | Usage: enable count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
15499 | If a breakpoint is hit while enabled in this fashion,\n\ |
15500 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15501 | &enablelist); |
15502 | ||
1bedd215 | 15503 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
590042fc PW |
15504 | Disable all or some breakpoints.\n\ |
15505 | Usage: disable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15506 | Arguments are breakpoint numbers with spaces in between.\n\ |
15507 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15508 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15509 | &disablelist, "disable ", 1, &cmdlist); |
15510 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15511 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15512 | |
1a966eab | 15513 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
590042fc PW |
15514 | Disable all or some breakpoints.\n\ |
15515 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15516 | Arguments are breakpoint numbers with spaces in between.\n\ |
15517 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15518 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15519 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15520 | &disablelist); |
15521 | ||
1bedd215 | 15522 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
590042fc PW |
15523 | Delete all or some breakpoints.\n\ |
15524 | Usage: delete [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15525 | Arguments are breakpoint numbers with spaces in between.\n\ |
15526 | To delete all breakpoints, give no argument.\n\ | |
15527 | \n\ | |
590042fc | 15528 | Also a prefix command for deletion of other GDB objects."), |
c906108c SS |
15529 | &deletelist, "delete ", 1, &cmdlist); |
15530 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15531 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15532 | |
1a966eab | 15533 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
590042fc PW |
15534 | Delete all or some breakpoints or auto-display expressions.\n\ |
15535 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
15536 | Arguments are breakpoint numbers with spaces in between.\n\ |
15537 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15538 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15539 | &deletelist); |
15540 | ||
1bedd215 | 15541 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15542 | Clear breakpoint at specified location.\n\ |
15543 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15544 | \n\ |
15545 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 15546 | is executing in.\n" |
89549d7f | 15547 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 15548 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15549 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15550 | |
1bedd215 | 15551 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15552 | Set breakpoint at specified location.\n" |
31e2b00f | 15553 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15554 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15555 | |
c906108c SS |
15556 | add_com_alias ("b", "break", class_run, 1); |
15557 | add_com_alias ("br", "break", class_run, 1); | |
15558 | add_com_alias ("bre", "break", class_run, 1); | |
15559 | add_com_alias ("brea", "break", class_run, 1); | |
15560 | ||
c906108c SS |
15561 | if (dbx_commands) |
15562 | { | |
1bedd215 AC |
15563 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15564 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15565 | &stoplist, "stop ", 1, &cmdlist); |
15566 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15567 | _("Break in function or address."), &stoplist); |
c5aa993b | 15568 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15569 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15570 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15571 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15572 | The \"Type\" column indicates one of:\n\ |
15573 | \tbreakpoint - normal breakpoint\n\ | |
15574 | \twatchpoint - watchpoint\n\ | |
15575 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15576 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15577 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15578 | address and file/line number respectively.\n\ |
15579 | \n\ | |
15580 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15581 | are set to the address of the last breakpoint listed unless the command\n\ |
15582 | is prefixed with \"server \".\n\n\ | |
c906108c | 15583 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15584 | breakpoint set.")); |
c906108c SS |
15585 | } |
15586 | ||
11db9430 | 15587 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15588 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15589 | The \"Type\" column indicates one of:\n\ |
15590 | \tbreakpoint - normal breakpoint\n\ | |
15591 | \twatchpoint - watchpoint\n\ | |
15592 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15593 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15594 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15595 | address and file/line number respectively.\n\ |
15596 | \n\ | |
15597 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15598 | are set to the address of the last breakpoint listed unless the command\n\ |
15599 | is prefixed with \"server \".\n\n\ | |
c906108c | 15600 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15601 | breakpoint set.")); |
c906108c | 15602 | |
6b04bdb7 MS |
15603 | add_info_alias ("b", "breakpoints", 1); |
15604 | ||
1a966eab AC |
15605 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15606 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15607 | The \"Type\" column indicates one of:\n\ |
15608 | \tbreakpoint - normal breakpoint\n\ | |
15609 | \twatchpoint - watchpoint\n\ | |
15610 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15611 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15612 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15613 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15614 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15615 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15616 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15617 | address and file/line number respectively.\n\ |
15618 | \n\ | |
15619 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15620 | are set to the address of the last breakpoint listed unless the command\n\ |
15621 | is prefixed with \"server \".\n\n\ | |
c906108c | 15622 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15623 | breakpoint set."), |
c906108c SS |
15624 | &maintenanceinfolist); |
15625 | ||
44feb3ce TT |
15626 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15627 | Set catchpoints to catch events."), | |
15628 | &catch_cmdlist, "catch ", | |
15629 | 0/*allow-unknown*/, &cmdlist); | |
15630 | ||
15631 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15632 | Set temporary catchpoints to catch events."), | |
15633 | &tcatch_cmdlist, "tcatch ", | |
15634 | 0/*allow-unknown*/, &cmdlist); | |
15635 | ||
44feb3ce TT |
15636 | add_catch_command ("fork", _("Catch calls to fork."), |
15637 | catch_fork_command_1, | |
a96d9b2e | 15638 | NULL, |
44feb3ce TT |
15639 | (void *) (uintptr_t) catch_fork_permanent, |
15640 | (void *) (uintptr_t) catch_fork_temporary); | |
15641 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15642 | catch_fork_command_1, | |
a96d9b2e | 15643 | NULL, |
44feb3ce TT |
15644 | (void *) (uintptr_t) catch_vfork_permanent, |
15645 | (void *) (uintptr_t) catch_vfork_temporary); | |
15646 | add_catch_command ("exec", _("Catch calls to exec."), | |
15647 | catch_exec_command_1, | |
a96d9b2e SDJ |
15648 | NULL, |
15649 | CATCH_PERMANENT, | |
15650 | CATCH_TEMPORARY); | |
edcc5120 TT |
15651 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15652 | Usage: catch load [REGEX]\n\ | |
15653 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15654 | catch_load_command_1, | |
15655 | NULL, | |
15656 | CATCH_PERMANENT, | |
15657 | CATCH_TEMPORARY); | |
15658 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15659 | Usage: catch unload [REGEX]\n\ | |
15660 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15661 | catch_unload_command_1, | |
15662 | NULL, | |
15663 | CATCH_PERMANENT, | |
15664 | CATCH_TEMPORARY); | |
c5aa993b | 15665 | |
1bedd215 AC |
15666 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15667 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15668 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15669 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15670 | an expression changes.\n\ |
15671 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15672 | the memory to which it refers.")); | |
65d12d83 | 15673 | set_cmd_completer (c, expression_completer); |
c906108c | 15674 | |
1bedd215 AC |
15675 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15676 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15677 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15678 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15679 | an expression is read.\n\ |
15680 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15681 | the memory to which it refers.")); | |
65d12d83 | 15682 | set_cmd_completer (c, expression_completer); |
c906108c | 15683 | |
1bedd215 AC |
15684 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15685 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15686 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15687 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15688 | an expression is either read or written.\n\ |
15689 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15690 | the memory to which it refers.")); | |
65d12d83 | 15691 | set_cmd_completer (c, expression_completer); |
c906108c | 15692 | |
11db9430 | 15693 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15694 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15695 | |
920d2a44 AC |
15696 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15697 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15698 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15699 | &can_use_hw_watchpoints, _("\ | |
15700 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15701 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15702 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15703 | such is available. (However, any hardware watchpoints that were\n\ | |
15704 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
15705 | hardware.)"), |
15706 | NULL, | |
920d2a44 | 15707 | show_can_use_hw_watchpoints, |
85c07804 | 15708 | &setlist, &showlist); |
c906108c SS |
15709 | |
15710 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 15711 | |
1042e4c0 SS |
15712 | /* Tracepoint manipulation commands. */ |
15713 | ||
15714 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 15715 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
15716 | \n" |
15717 | BREAK_ARGS_HELP ("trace") "\n\ | |
15718 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15719 | set_cmd_completer (c, location_completer); | |
15720 | ||
15721 | add_com_alias ("tp", "trace", class_alias, 0); | |
15722 | add_com_alias ("tr", "trace", class_alias, 1); | |
15723 | add_com_alias ("tra", "trace", class_alias, 1); | |
15724 | add_com_alias ("trac", "trace", class_alias, 1); | |
15725 | ||
7a697b8d | 15726 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 15727 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
15728 | \n" |
15729 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
15730 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15731 | set_cmd_completer (c, location_completer); | |
15732 | ||
0fb4aa4b | 15733 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 15734 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
15735 | \n\ |
15736 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
15737 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
15738 | or -m MARKER_ID.\n\n\ | |
15739 | If a marker id is specified, probe the marker with that name. With\n\ | |
15740 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
15741 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
15742 | This collects arbitrary user data passed in the probe point call to the\n\ | |
15743 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
15744 | by printing the $_sdata variable like any other convenience variable.\n\ | |
15745 | \n\ | |
15746 | CONDITION is a boolean expression.\n\ | |
89549d7f | 15747 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
15748 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
15749 | conditions are different.\n\ | |
0fb4aa4b PA |
15750 | \n\ |
15751 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
15752 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
15753 | set_cmd_completer (c, location_completer); | |
15754 | ||
11db9430 | 15755 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 15756 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
15757 | Convenience variable \"$tpnum\" contains the number of the\n\ |
15758 | last tracepoint set.")); | |
15759 | ||
15760 | add_info_alias ("tp", "tracepoints", 1); | |
15761 | ||
15762 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
15763 | Delete specified tracepoints.\n\ | |
15764 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15765 | No argument means delete all tracepoints."), | |
15766 | &deletelist); | |
7e20dfcd | 15767 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
15768 | |
15769 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
15770 | Disable specified tracepoints.\n\ | |
15771 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15772 | No argument means disable all tracepoints."), | |
15773 | &disablelist); | |
15774 | deprecate_cmd (c, "disable"); | |
15775 | ||
15776 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
15777 | Enable specified tracepoints.\n\ | |
15778 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
15779 | No argument means enable all tracepoints."), | |
15780 | &enablelist); | |
15781 | deprecate_cmd (c, "enable"); | |
15782 | ||
15783 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
15784 | Set the passcount for a tracepoint.\n\ | |
15785 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
15786 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
15787 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
15788 | ||
6149aea9 PA |
15789 | add_prefix_cmd ("save", class_breakpoint, save_command, |
15790 | _("Save breakpoint definitions as a script."), | |
15791 | &save_cmdlist, "save ", | |
15792 | 0/*allow-unknown*/, &cmdlist); | |
15793 | ||
15794 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
15795 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 15796 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
15797 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
15798 | session to restore them."), | |
15799 | &save_cmdlist); | |
15800 | set_cmd_completer (c, filename_completer); | |
15801 | ||
15802 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 15803 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
15804 | Use the 'source' command in another debug session to restore them."), |
15805 | &save_cmdlist); | |
1042e4c0 SS |
15806 | set_cmd_completer (c, filename_completer); |
15807 | ||
6149aea9 PA |
15808 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
15809 | deprecate_cmd (c, "save tracepoints"); | |
15810 | ||
1bedd215 | 15811 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
590042fc | 15812 | Breakpoint specific settings.\n\ |
fa8d40ab | 15813 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15814 | pending breakpoint behavior."), |
fa8d40ab JJ |
15815 | &breakpoint_set_cmdlist, "set breakpoint ", |
15816 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 15817 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
590042fc | 15818 | Breakpoint specific settings.\n\ |
fa8d40ab | 15819 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 15820 | pending breakpoint behavior."), |
fa8d40ab JJ |
15821 | &breakpoint_show_cmdlist, "show breakpoint ", |
15822 | 0/*allow-unknown*/, &showlist); | |
15823 | ||
7915a72c AC |
15824 | add_setshow_auto_boolean_cmd ("pending", no_class, |
15825 | &pending_break_support, _("\ | |
15826 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
15827 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
15828 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
15829 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
15830 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 15831 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 15832 | NULL, |
920d2a44 | 15833 | show_pending_break_support, |
6e1d7d6c AC |
15834 | &breakpoint_set_cmdlist, |
15835 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
15836 | |
15837 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
15838 | |
15839 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
15840 | &automatic_hardware_breakpoints, _("\ | |
15841 | Set automatic usage of hardware breakpoints."), _("\ | |
15842 | Show automatic usage of hardware breakpoints."), _("\ | |
15843 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
15844 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
15845 | a warning will be emitted for such breakpoints."), | |
15846 | NULL, | |
15847 | show_automatic_hardware_breakpoints, | |
15848 | &breakpoint_set_cmdlist, | |
15849 | &breakpoint_show_cmdlist); | |
74960c60 | 15850 | |
a25a5a45 PA |
15851 | add_setshow_boolean_cmd ("always-inserted", class_support, |
15852 | &always_inserted_mode, _("\ | |
74960c60 VP |
15853 | Set mode for inserting breakpoints."), _("\ |
15854 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
15855 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
15856 | they're created, kept inserted even when execution stops, and removed\n\ | |
15857 | only when the user deletes them. When this mode is off (the default),\n\ | |
15858 | breakpoints are inserted only when execution continues, and removed\n\ | |
15859 | when execution stops."), | |
72d0e2c5 YQ |
15860 | NULL, |
15861 | &show_always_inserted_mode, | |
15862 | &breakpoint_set_cmdlist, | |
15863 | &breakpoint_show_cmdlist); | |
f1310107 | 15864 | |
b775012e LM |
15865 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
15866 | condition_evaluation_enums, | |
15867 | &condition_evaluation_mode_1, _("\ | |
15868 | Set mode of breakpoint condition evaluation."), _("\ | |
15869 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 15870 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
15871 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
15872 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
15873 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
15874 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
15875 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
15876 | be set to \"gdb\""), | |
15877 | &set_condition_evaluation_mode, | |
15878 | &show_condition_evaluation_mode, | |
15879 | &breakpoint_set_cmdlist, | |
15880 | &breakpoint_show_cmdlist); | |
15881 | ||
f1310107 TJB |
15882 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
15883 | Set a breakpoint for an address range.\n\ | |
15884 | break-range START-LOCATION, END-LOCATION\n\ | |
15885 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
15886 | LINENUM, for that line in the current file,\n\ | |
15887 | FILE:LINENUM, for that line in that file,\n\ | |
15888 | +OFFSET, for that number of lines after the current line\n\ | |
15889 | or the start of the range\n\ | |
15890 | FUNCTION, for the first line in that function,\n\ | |
15891 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
15892 | *ADDRESS, for the instruction at that address.\n\ | |
15893 | \n\ | |
15894 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
15895 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
15896 | range (including START-LOCATION and END-LOCATION).")); | |
15897 | ||
e7e0cddf | 15898 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 15899 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 15900 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
15901 | location may be a linespec, explicit, or address location.\n" |
15902 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
15903 | set_cmd_completer (c, location_completer); |
15904 | ||
15905 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
15906 | dprintf_style_enums, &dprintf_style, _("\ | |
15907 | Set the style of usage for dynamic printf."), _("\ | |
15908 | Show the style of usage for dynamic printf."), _("\ | |
15909 | This setting chooses how GDB will do a dynamic printf.\n\ | |
15910 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
15911 | console, as with the \"printf\" command.\n\ | |
15912 | If the value is \"call\", the print is done by calling a function in your\n\ | |
15913 | program; by default printf(), but you can choose a different function or\n\ | |
15914 | output stream by setting dprintf-function and dprintf-channel."), | |
15915 | update_dprintf_commands, NULL, | |
15916 | &setlist, &showlist); | |
15917 | ||
15918 | dprintf_function = xstrdup ("printf"); | |
15919 | add_setshow_string_cmd ("dprintf-function", class_support, | |
15920 | &dprintf_function, _("\ | |
590042fc PW |
15921 | Set the function to use for dynamic printf."), _("\ |
15922 | Show the function to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15923 | update_dprintf_commands, NULL, |
15924 | &setlist, &showlist); | |
15925 | ||
15926 | dprintf_channel = xstrdup (""); | |
15927 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
15928 | &dprintf_channel, _("\ | |
590042fc PW |
15929 | Set the channel to use for dynamic printf."), _("\ |
15930 | Show the channel to use for dynamic printf."), NULL, | |
e7e0cddf SS |
15931 | update_dprintf_commands, NULL, |
15932 | &setlist, &showlist); | |
15933 | ||
d3ce09f5 SS |
15934 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
15935 | &disconnected_dprintf, _("\ | |
15936 | Set whether dprintf continues after GDB disconnects."), _("\ | |
15937 | Show whether dprintf continues after GDB disconnects."), _("\ | |
15938 | Use this to let dprintf commands continue to hit and produce output\n\ | |
15939 | even if GDB disconnects or detaches from the target."), | |
15940 | NULL, | |
15941 | NULL, | |
15942 | &setlist, &showlist); | |
15943 | ||
15944 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
590042fc PW |
15945 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
15946 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
15947 | This supports most C printf format specifications, like %s, %d, etc.\n\ | |
15948 | This is useful for formatted output in user-defined commands.")); | |
d3ce09f5 | 15949 | |
491144b5 | 15950 | automatic_hardware_breakpoints = true; |
f3b1572e | 15951 | |
76727919 TT |
15952 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
15953 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); | |
c906108c | 15954 | } |