]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
4a94e368 | 3 | Copyright (C) 1986-2022 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
d55e5aa6 | 21 | #include "arch-utils.h" |
4de283e4 TT |
22 | #include <ctype.h> |
23 | #include "hashtab.h" | |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
c906108c | 26 | #include "breakpoint.h" |
4de283e4 TT |
27 | #include "tracepoint.h" |
28 | #include "gdbtypes.h" | |
c906108c | 29 | #include "expression.h" |
d55e5aa6 | 30 | #include "gdbcore.h" |
4de283e4 TT |
31 | #include "gdbcmd.h" |
32 | #include "value.h" | |
33 | #include "command.h" | |
c906108c | 34 | #include "inferior.h" |
45741a9c | 35 | #include "infrun.h" |
4de283e4 TT |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
c906108c | 38 | #include "language.h" |
4de283e4 TT |
39 | #include "gdb-demangle.h" |
40 | #include "filenames.h" | |
41 | #include "annotate.h" | |
42 | #include "symfile.h" | |
d55e5aa6 | 43 | #include "objfiles.h" |
4de283e4 TT |
44 | #include "source.h" |
45 | #include "linespec.h" | |
46 | #include "completer.h" | |
47 | #include "ui-out.h" | |
48 | #include "cli/cli-script.h" | |
49 | #include "block.h" | |
50 | #include "solib.h" | |
51 | #include "solist.h" | |
d55e5aa6 | 52 | #include "observable.h" |
4de283e4 TT |
53 | #include "memattr.h" |
54 | #include "ada-lang.h" | |
55 | #include "top.h" | |
56 | #include "valprint.h" | |
57 | #include "jit.h" | |
65d79d4b | 58 | #include "parser-defs.h" |
d322d6d6 | 59 | #include "gdbsupport/gdb_regex.h" |
55aa24fb | 60 | #include "probe.h" |
4de283e4 | 61 | #include "cli/cli-utils.h" |
d55e5aa6 | 62 | #include "stack.h" |
4de283e4 TT |
63 | #include "ax-gdb.h" |
64 | #include "dummy-frame.h" | |
65 | #include "interps.h" | |
268a13a5 | 66 | #include "gdbsupport/format.h" |
cfc31633 | 67 | #include "thread-fsm.h" |
5d5658a1 | 68 | #include "tid-parse.h" |
4de283e4 | 69 | #include "cli/cli-style.h" |
0f8e2034 | 70 | #include "cli/cli-decode.h" |
d3ce09f5 | 71 | |
1042e4c0 | 72 | /* readline include files */ |
073bbbb0 | 73 | #include "readline/tilde.h" |
1042e4c0 SS |
74 | |
75 | /* readline defines this. */ | |
76 | #undef savestring | |
77 | ||
034dad6f | 78 | #include "mi/mi-common.h" |
6dddc817 | 79 | #include "extension.h" |
325fac50 | 80 | #include <algorithm> |
5ed8105e | 81 | #include "progspace-and-thread.h" |
268a13a5 TT |
82 | #include "gdbsupport/array-view.h" |
83 | #include "gdbsupport/gdb_optional.h" | |
104c1213 | 84 | |
4a64f543 | 85 | /* Prototypes for local functions. */ |
c906108c | 86 | |
896b6bda | 87 | static void map_breakpoint_numbers (const char *, |
48649e1b | 88 | gdb::function_view<void (breakpoint *)>); |
c906108c | 89 | |
348d480f PA |
90 | static void breakpoint_re_set_default (struct breakpoint *); |
91 | ||
f00aae0f | 92 | static void |
626d2320 | 93 | create_sals_from_location_default (struct event_location *location, |
f00aae0f KS |
94 | struct linespec_result *canonical, |
95 | enum bptype type_wanted); | |
983af33b SDJ |
96 | |
97 | static void create_breakpoints_sal_default (struct gdbarch *, | |
98 | struct linespec_result *, | |
e1e01040 PA |
99 | gdb::unique_xmalloc_ptr<char>, |
100 | gdb::unique_xmalloc_ptr<char>, | |
101 | enum bptype, | |
983af33b SDJ |
102 | enum bpdisp, int, int, |
103 | int, | |
104 | const struct breakpoint_ops *, | |
44f238bb | 105 | int, int, int, unsigned); |
983af33b | 106 | |
6c5b2ebe | 107 | static std::vector<symtab_and_line> decode_location_default |
626d2320 | 108 | (struct breakpoint *b, struct event_location *location, |
6c5b2ebe | 109 | struct program_space *search_pspace); |
983af33b | 110 | |
a6535de1 TT |
111 | static int can_use_hardware_watchpoint |
112 | (const std::vector<value_ref_ptr> &vals); | |
c906108c | 113 | |
a14ed312 | 114 | static void mention (struct breakpoint *); |
c906108c | 115 | |
348d480f PA |
116 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
117 | enum bptype, | |
c0a91b2b | 118 | const struct breakpoint_ops *); |
3742cc8b YQ |
119 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
120 | const struct symtab_and_line *); | |
121 | ||
4a64f543 MS |
122 | /* This function is used in gdbtk sources and thus can not be made |
123 | static. */ | |
cd0f67f3 SM |
124 | static struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
125 | struct symtab_and_line, | |
126 | enum bptype, | |
127 | const struct breakpoint_ops *); | |
c906108c | 128 | |
06edf0c0 PA |
129 | static struct breakpoint * |
130 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
131 | enum bptype type, | |
a1aa2221 LM |
132 | const struct breakpoint_ops *ops, |
133 | int loc_enabled); | |
06edf0c0 | 134 | |
76897487 KB |
135 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
136 | ||
a6d9a66e UW |
137 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
138 | CORE_ADDR bpaddr, | |
dda83cd7 | 139 | enum bptype bptype); |
76897487 | 140 | |
6c95b8df PA |
141 | static void describe_other_breakpoints (struct gdbarch *, |
142 | struct program_space *, CORE_ADDR, | |
5af949e3 | 143 | struct obj_section *, int); |
c906108c | 144 | |
85d721b8 PA |
145 | static int watchpoint_locations_match (struct bp_location *loc1, |
146 | struct bp_location *loc2); | |
147 | ||
7f32a4d5 PA |
148 | static int breakpoint_locations_match (struct bp_location *loc1, |
149 | struct bp_location *loc2, | |
150 | bool sw_hw_bps_match = false); | |
151 | ||
f1310107 | 152 | static int breakpoint_location_address_match (struct bp_location *bl, |
accd0bcd | 153 | const struct address_space *aspace, |
f1310107 TJB |
154 | CORE_ADDR addr); |
155 | ||
d35ae833 | 156 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
accd0bcd | 157 | const address_space *, |
d35ae833 PA |
158 | CORE_ADDR, int); |
159 | ||
834c0d03 | 160 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 161 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 162 | |
313f3b21 | 163 | static enum print_stop_action print_bp_stop_message (bpstat *bs); |
c906108c | 164 | |
a14ed312 | 165 | static int hw_breakpoint_used_count (void); |
c906108c | 166 | |
a1398e0c PA |
167 | static int hw_watchpoint_use_count (struct breakpoint *); |
168 | ||
169 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
170 | enum bptype type, | |
171 | int *other_type_used); | |
c906108c | 172 | |
816338b5 SS |
173 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
174 | int count); | |
c906108c | 175 | |
f431efe5 | 176 | static void decref_bp_location (struct bp_location **loc); |
fe3f5fa8 | 177 | |
39d61571 | 178 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 179 | |
5d926615 TT |
180 | static std::vector<symtab_and_line> bkpt_probe_decode_location |
181 | (struct breakpoint *b, | |
182 | struct event_location *location, | |
183 | struct program_space *search_pspace); | |
184 | ||
44702360 PA |
185 | /* update_global_location_list's modes of operation wrt to whether to |
186 | insert locations now. */ | |
187 | enum ugll_insert_mode | |
188 | { | |
189 | /* Don't insert any breakpoint locations into the inferior, only | |
190 | remove already-inserted locations that no longer should be | |
191 | inserted. Functions that delete a breakpoint or breakpoints | |
192 | should specify this mode, so that deleting a breakpoint doesn't | |
193 | have the side effect of inserting the locations of other | |
194 | breakpoints that are marked not-inserted, but should_be_inserted | |
195 | returns true on them. | |
196 | ||
197 | This behavior is useful is situations close to tear-down -- e.g., | |
198 | after an exec, while the target still has execution, but | |
199 | breakpoint shadows of the previous executable image should *NOT* | |
200 | be restored to the new image; or before detaching, where the | |
201 | target still has execution and wants to delete breakpoints from | |
202 | GDB's lists, and all breakpoints had already been removed from | |
203 | the inferior. */ | |
204 | UGLL_DONT_INSERT, | |
205 | ||
a25a5a45 PA |
206 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
207 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
208 | UGLL_MAY_INSERT, |
209 | ||
a25a5a45 PA |
210 | /* Insert locations now, irrespective of |
211 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
212 | stopped right now, and the user did "continue". We need to | |
213 | insert breakpoints _before_ resuming the target, but | |
214 | UGLL_MAY_INSERT wouldn't insert them, because | |
215 | breakpoints_should_be_inserted_now returns false at that point, | |
216 | as no thread is running yet. */ | |
04086b45 | 217 | UGLL_INSERT |
44702360 PA |
218 | }; |
219 | ||
220 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 221 | |
44702360 | 222 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 223 | |
74960c60 | 224 | static void insert_breakpoint_locations (void); |
a5606eee | 225 | |
0b39b52e | 226 | static void trace_pass_command (const char *, int); |
1042e4c0 | 227 | |
558a9d82 YQ |
228 | static void set_tracepoint_count (int num); |
229 | ||
f2478a7e | 230 | static bool is_masked_watchpoint (const struct breakpoint *b); |
9c06b0b4 | 231 | |
983af33b SDJ |
232 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
233 | otherwise. */ | |
234 | ||
235 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 236 | |
8613a476 TT |
237 | static void bkpt_probe_create_sals_from_location |
238 | (struct event_location *location, | |
239 | struct linespec_result *canonical, | |
240 | enum bptype type_wanted); | |
241 | static void tracepoint_probe_create_sals_from_location | |
242 | (struct event_location *location, | |
243 | struct linespec_result *canonical, | |
244 | enum bptype type_wanted); | |
245 | ||
a678887d | 246 | const struct breakpoint_ops base_breakpoint_ops = |
8613a476 TT |
247 | { |
248 | create_sals_from_location_default, | |
249 | create_breakpoints_sal_default, | |
250 | }; | |
251 | ||
55aa24fb | 252 | /* Breakpoints set on probes. */ |
a678887d | 253 | static const struct breakpoint_ops bkpt_probe_breakpoint_ops = |
8613a476 TT |
254 | { |
255 | bkpt_probe_create_sals_from_location, | |
256 | create_breakpoints_sal_default, | |
257 | }; | |
55aa24fb | 258 | |
bac7c5cf | 259 | /* Tracepoints set on probes. */ |
a678887d | 260 | static const struct breakpoint_ops tracepoint_probe_breakpoint_ops = |
8613a476 TT |
261 | { |
262 | tracepoint_probe_create_sals_from_location, | |
263 | create_breakpoints_sal_default, | |
264 | }; | |
bac7c5cf | 265 | |
098f1272 TT |
266 | /* The structure to be used in regular breakpoints. */ |
267 | struct ordinary_breakpoint : public base_breakpoint | |
268 | { | |
7dd8e7ae TT |
269 | int resources_needed (const struct bp_location *) override; |
270 | enum print_stop_action print_it (struct bpstat *bs) override; | |
271 | void print_mention () override; | |
272 | void print_recreate (struct ui_file *fp) override; | |
098f1272 TT |
273 | }; |
274 | ||
275 | /* Internal breakpoints. */ | |
276 | struct internal_breakpoint : public base_breakpoint | |
277 | { | |
c359fff5 TT |
278 | void re_set () override; |
279 | void check_status (struct bpstat *bs) override; | |
280 | enum print_stop_action print_it (struct bpstat *bs) override; | |
281 | void print_mention () override; | |
098f1272 TT |
282 | }; |
283 | ||
284 | /* Momentary breakpoints. */ | |
285 | struct momentary_breakpoint : public base_breakpoint | |
286 | { | |
1fd30a47 TT |
287 | void re_set () override; |
288 | void check_status (struct bpstat *bs) override; | |
289 | enum print_stop_action print_it (struct bpstat *bs) override; | |
290 | void print_mention () override; | |
098f1272 TT |
291 | }; |
292 | ||
293 | /* DPrintf breakpoints. */ | |
5ad71d67 | 294 | struct dprintf_breakpoint : public ordinary_breakpoint |
098f1272 | 295 | { |
f293a0b5 TT |
296 | void re_set () override; |
297 | int breakpoint_hit (const struct bp_location *bl, | |
298 | const address_space *aspace, | |
299 | CORE_ADDR bp_addr, | |
300 | const target_waitstatus &ws) override; | |
301 | void print_recreate (struct ui_file *fp) override; | |
302 | void after_condition_true (struct bpstat *bs) override; | |
098f1272 TT |
303 | }; |
304 | ||
ec45bb67 TT |
305 | /* Ranged breakpoints. */ |
306 | struct ranged_breakpoint : public ordinary_breakpoint | |
307 | { | |
308 | int breakpoint_hit (const struct bp_location *bl, | |
309 | const address_space *aspace, | |
310 | CORE_ADDR bp_addr, | |
311 | const target_waitstatus &ws) override; | |
312 | int resources_needed (const struct bp_location *) override; | |
313 | enum print_stop_action print_it (struct bpstat *bs) override; | |
314 | bool print_one (struct bp_location **) override; | |
315 | void print_one_detail (struct ui_out *) const override; | |
316 | void print_mention () override; | |
317 | void print_recreate (struct ui_file *fp) override; | |
318 | }; | |
319 | ||
6d7a8c56 TT |
320 | /* Static tracepoints with marker (`-m'). */ |
321 | struct static_marker_tracepoint : public tracepoint | |
322 | { | |
323 | std::vector<symtab_and_line> decode_location | |
324 | (struct event_location *location, | |
325 | struct program_space *search_pspace) override; | |
326 | }; | |
327 | ||
d3ce09f5 SS |
328 | /* The style in which to perform a dynamic printf. This is a user |
329 | option because different output options have different tradeoffs; | |
330 | if GDB does the printing, there is better error handling if there | |
331 | is a problem with any of the arguments, but using an inferior | |
332 | function lets you have special-purpose printers and sending of | |
333 | output to the same place as compiled-in print functions. */ | |
334 | ||
335 | static const char dprintf_style_gdb[] = "gdb"; | |
336 | static const char dprintf_style_call[] = "call"; | |
337 | static const char dprintf_style_agent[] = "agent"; | |
338 | static const char *const dprintf_style_enums[] = { | |
339 | dprintf_style_gdb, | |
340 | dprintf_style_call, | |
341 | dprintf_style_agent, | |
342 | NULL | |
343 | }; | |
344 | static const char *dprintf_style = dprintf_style_gdb; | |
345 | ||
346 | /* The function to use for dynamic printf if the preferred style is to | |
347 | call into the inferior. The value is simply a string that is | |
348 | copied into the command, so it can be anything that GDB can | |
349 | evaluate to a callable address, not necessarily a function name. */ | |
350 | ||
e0700ba4 | 351 | static std::string dprintf_function = "printf"; |
d3ce09f5 SS |
352 | |
353 | /* The channel to use for dynamic printf if the preferred style is to | |
354 | call into the inferior; if a nonempty string, it will be passed to | |
355 | the call as the first argument, with the format string as the | |
356 | second. As with the dprintf function, this can be anything that | |
357 | GDB knows how to evaluate, so in addition to common choices like | |
358 | "stderr", this could be an app-specific expression like | |
359 | "mystreams[curlogger]". */ | |
360 | ||
e0700ba4 | 361 | static std::string dprintf_channel; |
d3ce09f5 SS |
362 | |
363 | /* True if dprintf commands should continue to operate even if GDB | |
364 | has disconnected. */ | |
491144b5 | 365 | static bool disconnected_dprintf = true; |
d3ce09f5 | 366 | |
5cea2a26 PA |
367 | struct command_line * |
368 | breakpoint_commands (struct breakpoint *b) | |
369 | { | |
d1b0a7bf | 370 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 371 | } |
3daf8fe5 | 372 | |
f3b1572e PA |
373 | /* Flag indicating that a command has proceeded the inferior past the |
374 | current breakpoint. */ | |
375 | ||
491144b5 | 376 | static bool breakpoint_proceeded; |
f3b1572e | 377 | |
956a9fb9 | 378 | const char * |
2cec12e5 AR |
379 | bpdisp_text (enum bpdisp disp) |
380 | { | |
4a64f543 MS |
381 | /* NOTE: the following values are a part of MI protocol and |
382 | represent values of 'disp' field returned when inferior stops at | |
383 | a breakpoint. */ | |
bc043ef3 | 384 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 385 | |
2cec12e5 AR |
386 | return bpdisps[(int) disp]; |
387 | } | |
c906108c | 388 | |
4a64f543 | 389 | /* Prototypes for exported functions. */ |
c906108c | 390 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 391 | if such is available. */ |
c906108c SS |
392 | static int can_use_hw_watchpoints; |
393 | ||
920d2a44 AC |
394 | static void |
395 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
396 | struct cmd_list_element *c, | |
397 | const char *value) | |
398 | { | |
6cb06a8c TT |
399 | gdb_printf (file, |
400 | _("Debugger's willingness to use " | |
401 | "watchpoint hardware is %s.\n"), | |
402 | value); | |
920d2a44 AC |
403 | } |
404 | ||
fa8d40ab JJ |
405 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
406 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 407 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
408 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
409 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
410 | static void |
411 | show_pending_break_support (struct ui_file *file, int from_tty, | |
412 | struct cmd_list_element *c, | |
413 | const char *value) | |
414 | { | |
6cb06a8c TT |
415 | gdb_printf (file, |
416 | _("Debugger's behavior regarding " | |
417 | "pending breakpoints is %s.\n"), | |
418 | value); | |
920d2a44 | 419 | } |
fa8d40ab | 420 | |
491144b5 | 421 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 422 | set with "break" but falling in read-only memory. |
491144b5 | 423 | If false, gdb will warn about such breakpoints, but won't automatically |
765dc015 | 424 | use hardware breakpoints. */ |
491144b5 | 425 | static bool automatic_hardware_breakpoints; |
765dc015 VP |
426 | static void |
427 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
428 | struct cmd_list_element *c, | |
429 | const char *value) | |
430 | { | |
6cb06a8c TT |
431 | gdb_printf (file, |
432 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
433 | value); | |
765dc015 VP |
434 | } |
435 | ||
a25a5a45 PA |
436 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
437 | stopped, and immediately inserts any new breakpoints as soon as | |
438 | they're created. If off (default), GDB keeps breakpoints off of | |
439 | the target as long as possible. That is, it delays inserting | |
440 | breakpoints until the next resume, and removes them again when the | |
441 | target fully stops. This is a bit safer in case GDB crashes while | |
442 | processing user input. */ | |
491144b5 | 443 | static bool always_inserted_mode = false; |
72d0e2c5 | 444 | |
33e5cbd6 | 445 | static void |
74960c60 | 446 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 447 | struct cmd_list_element *c, const char *value) |
74960c60 | 448 | { |
6cb06a8c TT |
449 | gdb_printf (file, _("Always inserted breakpoint mode is %s.\n"), |
450 | value); | |
74960c60 VP |
451 | } |
452 | ||
b57bacec PA |
453 | /* See breakpoint.h. */ |
454 | ||
33e5cbd6 | 455 | int |
a25a5a45 | 456 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 457 | { |
a25a5a45 PA |
458 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
459 | { | |
460 | /* If breakpoints are global, they should be inserted even if no | |
461 | thread under gdb's control is running, or even if there are | |
462 | no threads under GDB's control yet. */ | |
463 | return 1; | |
464 | } | |
5b6d1e4f | 465 | else |
a25a5a45 | 466 | { |
a25a5a45 PA |
467 | if (always_inserted_mode) |
468 | { | |
469 | /* The user wants breakpoints inserted even if all threads | |
470 | are stopped. */ | |
471 | return 1; | |
472 | } | |
473 | ||
5b6d1e4f PA |
474 | for (inferior *inf : all_inferiors ()) |
475 | if (inf->has_execution () | |
476 | && threads_are_executing (inf->process_target ())) | |
477 | return 1; | |
372316f1 PA |
478 | |
479 | /* Don't remove breakpoints yet if, even though all threads are | |
480 | stopped, we still have events to process. */ | |
08036331 | 481 | for (thread_info *tp : all_non_exited_threads ()) |
1edb66d8 | 482 | if (tp->resumed () && tp->has_pending_waitstatus ()) |
372316f1 | 483 | return 1; |
a25a5a45 PA |
484 | } |
485 | return 0; | |
33e5cbd6 | 486 | } |
765dc015 | 487 | |
b775012e LM |
488 | static const char condition_evaluation_both[] = "host or target"; |
489 | ||
490 | /* Modes for breakpoint condition evaluation. */ | |
491 | static const char condition_evaluation_auto[] = "auto"; | |
492 | static const char condition_evaluation_host[] = "host"; | |
493 | static const char condition_evaluation_target[] = "target"; | |
494 | static const char *const condition_evaluation_enums[] = { | |
495 | condition_evaluation_auto, | |
496 | condition_evaluation_host, | |
497 | condition_evaluation_target, | |
498 | NULL | |
499 | }; | |
500 | ||
501 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
502 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
503 | ||
504 | /* Global that we use to display information to the user (gets its value from | |
505 | condition_evaluation_mode_1. */ | |
506 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
507 | ||
508 | /* Translate a condition evaluation mode MODE into either "host" | |
509 | or "target". This is used mostly to translate from "auto" to the | |
510 | real setting that is being used. It returns the translated | |
511 | evaluation mode. */ | |
512 | ||
513 | static const char * | |
514 | translate_condition_evaluation_mode (const char *mode) | |
515 | { | |
516 | if (mode == condition_evaluation_auto) | |
517 | { | |
518 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
519 | return condition_evaluation_target; | |
520 | else | |
521 | return condition_evaluation_host; | |
522 | } | |
523 | else | |
524 | return mode; | |
525 | } | |
526 | ||
527 | /* Discovers what condition_evaluation_auto translates to. */ | |
528 | ||
529 | static const char * | |
530 | breakpoint_condition_evaluation_mode (void) | |
531 | { | |
532 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
533 | } | |
534 | ||
535 | /* Return true if GDB should evaluate breakpoint conditions or false | |
536 | otherwise. */ | |
537 | ||
538 | static int | |
539 | gdb_evaluates_breakpoint_condition_p (void) | |
540 | { | |
541 | const char *mode = breakpoint_condition_evaluation_mode (); | |
542 | ||
543 | return (mode == condition_evaluation_host); | |
544 | } | |
545 | ||
c906108c SS |
546 | /* Are we executing breakpoint commands? */ |
547 | static int executing_breakpoint_commands; | |
548 | ||
c02f5703 MS |
549 | /* Are overlay event breakpoints enabled? */ |
550 | static int overlay_events_enabled; | |
551 | ||
e09342b5 | 552 | /* See description in breakpoint.h. */ |
491144b5 | 553 | bool target_exact_watchpoints = false; |
e09342b5 | 554 | |
c906108c | 555 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 556 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 557 | current breakpoint. */ |
c906108c | 558 | |
5c44784c JM |
559 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
560 | for (B = breakpoint_chain; \ | |
561 | B ? (TMP=B->next, 1): 0; \ | |
562 | B = TMP) | |
c906108c | 563 | |
7cc221ef | 564 | /* Chains of all breakpoints defined. */ |
c906108c | 565 | |
81e6b8eb | 566 | static struct breakpoint *breakpoint_chain; |
c906108c | 567 | |
240edef6 | 568 | /* See breakpoint.h. */ |
43892fdf | 569 | |
240edef6 | 570 | breakpoint_range |
43892fdf SM |
571 | all_breakpoints () |
572 | { | |
573 | return breakpoint_range (breakpoint_chain); | |
574 | } | |
575 | ||
240edef6 | 576 | /* See breakpoint.h. */ |
1428b37a | 577 | |
240edef6 | 578 | breakpoint_safe_range |
1428b37a SM |
579 | all_breakpoints_safe () |
580 | { | |
581 | return breakpoint_safe_range (all_breakpoints ()); | |
582 | } | |
583 | ||
f6d17b2b SM |
584 | /* See breakpoint.h. */ |
585 | ||
586 | tracepoint_range | |
587 | all_tracepoints () | |
588 | { | |
589 | return tracepoint_range (breakpoint_chain); | |
590 | } | |
591 | ||
39ef2f62 | 592 | /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ |
876fa593 | 593 | |
5d51cd5d | 594 | static std::vector<bp_location *> bp_locations; |
876fa593 | 595 | |
055c879f SM |
596 | /* See breakpoint.h. */ |
597 | ||
598 | const std::vector<bp_location *> & | |
48d7020b SM |
599 | all_bp_locations () |
600 | { | |
601 | return bp_locations; | |
602 | } | |
603 | ||
e0d9a270 SM |
604 | /* Range to iterate over breakpoint locations at a given address. */ |
605 | ||
606 | struct bp_locations_at_addr_range | |
607 | { | |
608 | using iterator = std::vector<bp_location *>::iterator; | |
609 | ||
610 | bp_locations_at_addr_range (CORE_ADDR addr) | |
611 | { | |
612 | struct compare | |
613 | { | |
614 | bool operator() (const bp_location *loc, CORE_ADDR addr_) const | |
615 | { return loc->address < addr_; } | |
616 | ||
617 | bool operator() (CORE_ADDR addr_, const bp_location *loc) const | |
618 | { return addr_ < loc->address; } | |
619 | }; | |
620 | ||
621 | auto it_pair = std::equal_range (bp_locations.begin (), bp_locations.end (), | |
622 | addr, compare ()); | |
623 | ||
624 | m_begin = it_pair.first; | |
625 | m_end = it_pair.second; | |
626 | } | |
627 | ||
628 | iterator begin () const | |
629 | { return m_begin; } | |
630 | ||
631 | iterator end () const | |
632 | { return m_end; } | |
633 | ||
634 | private: | |
635 | iterator m_begin; | |
636 | iterator m_end; | |
637 | }; | |
638 | ||
639 | /* Return a range to iterate over all breakpoint locations exactly at address | |
640 | ADDR. | |
641 | ||
642 | If it's needed to iterate multiple times on the same range, it's possible | |
643 | to save the range in a local variable and use it multiple times: | |
644 | ||
645 | auto range = all_bp_locations_at_addr (addr); | |
646 | ||
647 | for (bp_location *loc : range) | |
648 | // use loc | |
649 | ||
650 | for (bp_location *loc : range) | |
651 | // use loc | |
652 | ||
653 | This saves a bit of time, as it avoids re-doing the binary searches to find | |
654 | the range's boundaries. Just remember not to change the bp_locations vector | |
655 | in the mean time, as it could make the range's iterators stale. */ | |
656 | ||
657 | static bp_locations_at_addr_range | |
658 | all_bp_locations_at_addr (CORE_ADDR addr) | |
659 | { | |
660 | return bp_locations_at_addr_range (addr); | |
661 | } | |
662 | ||
4a64f543 | 663 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 664 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 665 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 666 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 667 | an address you need to read. */ |
876fa593 | 668 | |
f5336ca5 | 669 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 670 | |
4a64f543 MS |
671 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
672 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
673 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
674 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 675 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 676 | |
f5336ca5 | 677 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 678 | |
4a64f543 | 679 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
680 | from the bp_locations array, but for which a hit may still be |
681 | reported by a target. */ | |
1123588c | 682 | static std::vector<bp_location *> moribund_locations; |
20874c92 | 683 | |
c906108c SS |
684 | /* Number of last breakpoint made. */ |
685 | ||
95a42b64 TT |
686 | static int breakpoint_count; |
687 | ||
86b17b60 PA |
688 | /* The value of `breakpoint_count' before the last command that |
689 | created breakpoints. If the last (break-like) command created more | |
690 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
691 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
692 | static int prev_breakpoint_count; | |
c906108c | 693 | |
1042e4c0 SS |
694 | /* Number of last tracepoint made. */ |
695 | ||
95a42b64 | 696 | static int tracepoint_count; |
1042e4c0 | 697 | |
6149aea9 PA |
698 | static struct cmd_list_element *breakpoint_set_cmdlist; |
699 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 700 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 701 | |
468d015d JJ |
702 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
703 | static int | |
704 | breakpoint_enabled (struct breakpoint *b) | |
705 | { | |
0d381245 | 706 | return (b->enable_state == bp_enabled); |
468d015d JJ |
707 | } |
708 | ||
c906108c SS |
709 | /* Set breakpoint count to NUM. */ |
710 | ||
95a42b64 | 711 | static void |
fba45db2 | 712 | set_breakpoint_count (int num) |
c906108c | 713 | { |
86b17b60 | 714 | prev_breakpoint_count = breakpoint_count; |
c906108c | 715 | breakpoint_count = num; |
4fa62494 | 716 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
717 | } |
718 | ||
86b17b60 PA |
719 | /* Used by `start_rbreak_breakpoints' below, to record the current |
720 | breakpoint count before "rbreak" creates any breakpoint. */ | |
721 | static int rbreak_start_breakpoint_count; | |
722 | ||
95a42b64 TT |
723 | /* Called at the start an "rbreak" command to record the first |
724 | breakpoint made. */ | |
86b17b60 | 725 | |
c80049d3 | 726 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
95a42b64 | 727 | { |
86b17b60 | 728 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
729 | } |
730 | ||
731 | /* Called at the end of an "rbreak" command to record the last | |
732 | breakpoint made. */ | |
86b17b60 | 733 | |
c80049d3 | 734 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
95a42b64 | 735 | { |
86b17b60 | 736 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
737 | } |
738 | ||
4a64f543 | 739 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
740 | |
741 | void | |
fba45db2 | 742 | clear_breakpoint_hit_counts (void) |
c906108c | 743 | { |
43892fdf | 744 | for (breakpoint *b : all_breakpoints ()) |
c906108c SS |
745 | b->hit_count = 0; |
746 | } | |
747 | ||
c906108c | 748 | \f |
48cb2d85 VP |
749 | /* Return the breakpoint with the specified number, or NULL |
750 | if the number does not refer to an existing breakpoint. */ | |
751 | ||
752 | struct breakpoint * | |
753 | get_breakpoint (int num) | |
754 | { | |
43892fdf | 755 | for (breakpoint *b : all_breakpoints ()) |
48cb2d85 VP |
756 | if (b->number == num) |
757 | return b; | |
758 | ||
43892fdf | 759 | return nullptr; |
48cb2d85 | 760 | } |
5c44784c | 761 | |
c906108c | 762 | \f |
adc36818 | 763 | |
b775012e LM |
764 | /* Mark locations as "conditions have changed" in case the target supports |
765 | evaluating conditions on its side. */ | |
766 | ||
767 | static void | |
768 | mark_breakpoint_modified (struct breakpoint *b) | |
769 | { | |
b775012e LM |
770 | /* This is only meaningful if the target is |
771 | evaluating conditions and if the user has | |
772 | opted for condition evaluation on the target's | |
773 | side. */ | |
774 | if (gdb_evaluates_breakpoint_condition_p () | |
775 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
776 | return; | |
777 | ||
778 | if (!is_breakpoint (b)) | |
779 | return; | |
780 | ||
40cb8ca5 | 781 | for (bp_location *loc : b->locations ()) |
b775012e LM |
782 | loc->condition_changed = condition_modified; |
783 | } | |
784 | ||
785 | /* Mark location as "conditions have changed" in case the target supports | |
786 | evaluating conditions on its side. */ | |
787 | ||
788 | static void | |
789 | mark_breakpoint_location_modified (struct bp_location *loc) | |
790 | { | |
791 | /* This is only meaningful if the target is | |
792 | evaluating conditions and if the user has | |
793 | opted for condition evaluation on the target's | |
794 | side. */ | |
795 | if (gdb_evaluates_breakpoint_condition_p () | |
796 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
797 | ||
798 | return; | |
799 | ||
800 | if (!is_breakpoint (loc->owner)) | |
801 | return; | |
802 | ||
803 | loc->condition_changed = condition_modified; | |
804 | } | |
805 | ||
806 | /* Sets the condition-evaluation mode using the static global | |
807 | condition_evaluation_mode. */ | |
808 | ||
809 | static void | |
eb4c3f4a | 810 | set_condition_evaluation_mode (const char *args, int from_tty, |
b775012e LM |
811 | struct cmd_list_element *c) |
812 | { | |
b775012e LM |
813 | const char *old_mode, *new_mode; |
814 | ||
815 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
816 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
817 | { | |
818 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
819 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
820 | "Using host evaluation mode instead.")); | |
821 | return; | |
822 | } | |
823 | ||
824 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
825 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
826 | ||
abf1152a JK |
827 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
828 | settings was "auto". */ | |
829 | condition_evaluation_mode = condition_evaluation_mode_1; | |
830 | ||
b775012e LM |
831 | /* Only update the mode if the user picked a different one. */ |
832 | if (new_mode != old_mode) | |
833 | { | |
b775012e LM |
834 | /* If the user switched to a different evaluation mode, we |
835 | need to synch the changes with the target as follows: | |
836 | ||
837 | "host" -> "target": Send all (valid) conditions to the target. | |
838 | "target" -> "host": Remove all the conditions from the target. | |
839 | */ | |
840 | ||
b775012e LM |
841 | if (new_mode == condition_evaluation_target) |
842 | { | |
843 | /* Mark everything modified and synch conditions with the | |
844 | target. */ | |
48d7020b | 845 | for (bp_location *loc : all_bp_locations ()) |
b775012e | 846 | mark_breakpoint_location_modified (loc); |
24b21115 | 847 | } |
b775012e LM |
848 | else |
849 | { | |
850 | /* Manually mark non-duplicate locations to synch conditions | |
851 | with the target. We do this to remove all the conditions the | |
852 | target knows about. */ | |
48d7020b | 853 | for (bp_location *loc : all_bp_locations ()) |
b775012e LM |
854 | if (is_breakpoint (loc->owner) && loc->inserted) |
855 | loc->needs_update = 1; | |
856 | } | |
857 | ||
858 | /* Do the update. */ | |
44702360 | 859 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
860 | } |
861 | ||
862 | return; | |
863 | } | |
864 | ||
865 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
866 | what "auto" is translating to. */ | |
867 | ||
868 | static void | |
869 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
870 | struct cmd_list_element *c, const char *value) | |
871 | { | |
872 | if (condition_evaluation_mode == condition_evaluation_auto) | |
6cb06a8c TT |
873 | gdb_printf (file, |
874 | _("Breakpoint condition evaluation " | |
875 | "mode is %s (currently %s).\n"), | |
876 | value, | |
877 | breakpoint_condition_evaluation_mode ()); | |
b775012e | 878 | else |
6cb06a8c TT |
879 | gdb_printf (file, _("Breakpoint condition evaluation mode is %s.\n"), |
880 | value); | |
b775012e LM |
881 | } |
882 | ||
b5fa468f TBA |
883 | /* Parse COND_STRING in the context of LOC and set as the condition |
884 | expression of LOC. BP_NUM is the number of LOC's owner, LOC_NUM is | |
885 | the number of LOC within its owner. In case of parsing error, mark | |
886 | LOC as DISABLED_BY_COND. In case of success, unset DISABLED_BY_COND. */ | |
887 | ||
888 | static void | |
889 | set_breakpoint_location_condition (const char *cond_string, bp_location *loc, | |
890 | int bp_num, int loc_num) | |
891 | { | |
892 | bool has_junk = false; | |
893 | try | |
894 | { | |
895 | expression_up new_exp = parse_exp_1 (&cond_string, loc->address, | |
896 | block_for_pc (loc->address), 0); | |
897 | if (*cond_string != 0) | |
898 | has_junk = true; | |
899 | else | |
900 | { | |
901 | loc->cond = std::move (new_exp); | |
902 | if (loc->disabled_by_cond && loc->enabled) | |
6cb06a8c TT |
903 | gdb_printf (_("Breakpoint %d's condition is now valid at " |
904 | "location %d, enabling.\n"), | |
905 | bp_num, loc_num); | |
b5fa468f TBA |
906 | |
907 | loc->disabled_by_cond = false; | |
908 | } | |
909 | } | |
910 | catch (const gdb_exception_error &e) | |
911 | { | |
912 | if (loc->enabled) | |
913 | { | |
914 | /* Warn if a user-enabled location is now becoming disabled-by-cond. | |
915 | BP_NUM is 0 if the breakpoint is being defined for the first | |
916 | time using the "break ... if ..." command, and non-zero if | |
917 | already defined. */ | |
918 | if (bp_num != 0) | |
919 | warning (_("failed to validate condition at location %d.%d, " | |
920 | "disabling:\n %s"), bp_num, loc_num, e.what ()); | |
921 | else | |
922 | warning (_("failed to validate condition at location %d, " | |
923 | "disabling:\n %s"), loc_num, e.what ()); | |
924 | } | |
925 | ||
926 | loc->disabled_by_cond = true; | |
927 | } | |
928 | ||
929 | if (has_junk) | |
930 | error (_("Garbage '%s' follows condition"), cond_string); | |
931 | } | |
932 | ||
adc36818 | 933 | void |
7a26bd4d | 934 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
733d554a | 935 | int from_tty, bool force) |
adc36818 | 936 | { |
4c55e970 | 937 | if (*exp == 0) |
3a5c3e22 | 938 | { |
6f781ee3 | 939 | b->cond_string.reset (); |
3a5c3e22 | 940 | |
4c55e970 | 941 | if (is_watchpoint (b)) |
78319c15 | 942 | static_cast<watchpoint *> (b)->cond_exp.reset (); |
4c55e970 TBA |
943 | else |
944 | { | |
b5fa468f | 945 | int loc_num = 1; |
40cb8ca5 | 946 | for (bp_location *loc : b->locations ()) |
4c55e970 TBA |
947 | { |
948 | loc->cond.reset (); | |
b5fa468f | 949 | if (loc->disabled_by_cond && loc->enabled) |
6cb06a8c TT |
950 | gdb_printf (_("Breakpoint %d's condition is now valid at " |
951 | "location %d, enabling.\n"), | |
952 | b->number, loc_num); | |
b5fa468f TBA |
953 | loc->disabled_by_cond = false; |
954 | loc_num++; | |
4c55e970 TBA |
955 | |
956 | /* No need to free the condition agent expression | |
957 | bytecode (if we have one). We will handle this | |
958 | when we go through update_global_location_list. */ | |
959 | } | |
960 | } | |
1e620590 | 961 | |
adc36818 | 962 | if (from_tty) |
6cb06a8c | 963 | gdb_printf (_("Breakpoint %d now unconditional.\n"), b->number); |
adc36818 PM |
964 | } |
965 | else | |
966 | { | |
adc36818 PM |
967 | if (is_watchpoint (b)) |
968 | { | |
699bd4cf | 969 | innermost_block_tracker tracker; |
78319c15 | 970 | const char *arg = exp; |
4c55e970 | 971 | expression_up new_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
78319c15 | 972 | if (*arg != 0) |
adc36818 | 973 | error (_("Junk at end of expression")); |
78319c15 | 974 | watchpoint *w = static_cast<watchpoint *> (b); |
4c55e970 | 975 | w->cond_exp = std::move (new_exp); |
699bd4cf | 976 | w->cond_exp_valid_block = tracker.block (); |
adc36818 PM |
977 | } |
978 | else | |
979 | { | |
4c55e970 TBA |
980 | /* Parse and set condition expressions. We make two passes. |
981 | In the first, we parse the condition string to see if it | |
b5fa468f TBA |
982 | is valid in at least one location. If so, the condition |
983 | would be accepted. So we go ahead and set the locations' | |
984 | conditions. In case no valid case is found, we throw | |
4c55e970 TBA |
985 | the error and the condition string will be rejected. |
986 | This two-pass approach is taken to avoid setting the | |
987 | state of locations in case of a reject. */ | |
40cb8ca5 | 988 | for (bp_location *loc : b->locations ()) |
4c55e970 | 989 | { |
b5fa468f TBA |
990 | try |
991 | { | |
992 | const char *arg = exp; | |
993 | parse_exp_1 (&arg, loc->address, | |
994 | block_for_pc (loc->address), 0); | |
995 | if (*arg != 0) | |
996 | error (_("Junk at end of expression")); | |
997 | break; | |
998 | } | |
999 | catch (const gdb_exception_error &e) | |
1000 | { | |
1001 | /* Condition string is invalid. If this happens to | |
733d554a TBA |
1002 | be the last loc, abandon (if not forced) or continue |
1003 | (if forced). */ | |
1004 | if (loc->next == nullptr && !force) | |
b5fa468f TBA |
1005 | throw; |
1006 | } | |
4c55e970 TBA |
1007 | } |
1008 | ||
b5fa468f | 1009 | /* If we reach here, the condition is valid at some locations. */ |
dda83cd7 | 1010 | int loc_num = 1; |
40cb8ca5 SM |
1011 | for (bp_location *loc : b->locations ()) |
1012 | { | |
1013 | set_breakpoint_location_condition (exp, loc, b->number, loc_num); | |
1014 | loc_num++; | |
1015 | } | |
adc36818 | 1016 | } |
1e620590 TBA |
1017 | |
1018 | /* We know that the new condition parsed successfully. The | |
1019 | condition string of the breakpoint can be safely updated. */ | |
6f781ee3 | 1020 | b->cond_string = make_unique_xstrdup (exp); |
1e620590 | 1021 | b->condition_not_parsed = 0; |
adc36818 | 1022 | } |
b775012e LM |
1023 | mark_breakpoint_modified (b); |
1024 | ||
76727919 | 1025 | gdb::observers::breakpoint_modified.notify (b); |
adc36818 PM |
1026 | } |
1027 | ||
79aabb73 TBA |
1028 | /* See breakpoint.h. */ |
1029 | ||
1030 | void | |
1031 | set_breakpoint_condition (int bpnum, const char *exp, int from_tty, | |
1032 | bool force) | |
1033 | { | |
43892fdf | 1034 | for (breakpoint *b : all_breakpoints ()) |
79aabb73 TBA |
1035 | if (b->number == bpnum) |
1036 | { | |
1037 | /* Check if this breakpoint has a "stop" method implemented in an | |
1038 | extension language. This method and conditions entered into GDB | |
1039 | from the CLI are mutually exclusive. */ | |
1040 | const struct extension_language_defn *extlang | |
1041 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1042 | ||
1043 | if (extlang != NULL) | |
1044 | { | |
1045 | error (_("Only one stop condition allowed. There is currently" | |
1046 | " a %s stop condition defined for this breakpoint."), | |
1047 | ext_lang_capitalized_name (extlang)); | |
1048 | } | |
1049 | set_breakpoint_condition (b, exp, from_tty, force); | |
1050 | ||
1051 | if (is_breakpoint (b)) | |
1052 | update_global_location_list (UGLL_MAY_INSERT); | |
1053 | ||
1054 | return; | |
1055 | } | |
1056 | ||
1057 | error (_("No breakpoint number %d."), bpnum); | |
1058 | } | |
1059 | ||
b1d4d8d1 TBA |
1060 | /* The options for the "condition" command. */ |
1061 | ||
1062 | struct condition_command_opts | |
1063 | { | |
1064 | /* For "-force". */ | |
1065 | bool force_condition = false; | |
1066 | }; | |
1067 | ||
1068 | static const gdb::option::option_def condition_command_option_defs[] = { | |
1069 | ||
1070 | gdb::option::flag_option_def<condition_command_opts> { | |
1071 | "force", | |
1072 | [] (condition_command_opts *opts) { return &opts->force_condition; }, | |
1073 | N_("Set the condition even if it is invalid for all current locations."), | |
1074 | }, | |
1075 | ||
1076 | }; | |
1077 | ||
1078 | /* Create an option_def_group for the "condition" options, with | |
1079 | CC_OPTS as context. */ | |
1080 | ||
1081 | static inline gdb::option::option_def_group | |
1082 | make_condition_command_options_def_group (condition_command_opts *cc_opts) | |
1083 | { | |
1084 | return {{condition_command_option_defs}, cc_opts}; | |
1085 | } | |
1086 | ||
d55637df TT |
1087 | /* Completion for the "condition" command. */ |
1088 | ||
eb3ff9a5 | 1089 | static void |
6f937416 | 1090 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 1091 | completion_tracker &tracker, |
b1d4d8d1 | 1092 | const char *text, const char * /*word*/) |
d55637df | 1093 | { |
b1d4d8d1 TBA |
1094 | bool has_no_arguments = (*text == '\0'); |
1095 | condition_command_opts cc_opts; | |
1096 | const auto group = make_condition_command_options_def_group (&cc_opts); | |
1097 | if (gdb::option::complete_options | |
1098 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group)) | |
1099 | return; | |
d55637df | 1100 | |
f1735a53 | 1101 | text = skip_spaces (text); |
b1d4d8d1 | 1102 | const char *space = skip_to_space (text); |
d55637df TT |
1103 | if (*space == '\0') |
1104 | { | |
1105 | int len; | |
d55637df TT |
1106 | |
1107 | if (text[0] == '$') | |
1108 | { | |
b1d4d8d1 | 1109 | tracker.advance_custom_word_point_by (1); |
d55637df | 1110 | /* We don't support completion of history indices. */ |
eb3ff9a5 PA |
1111 | if (!isdigit (text[1])) |
1112 | complete_internalvar (tracker, &text[1]); | |
1113 | return; | |
d55637df TT |
1114 | } |
1115 | ||
b1d4d8d1 TBA |
1116 | /* Suggest the "-force" flag if no arguments are given. If |
1117 | arguments were passed, they either already include the flag, | |
1118 | or we are beyond the point of suggesting it because it's | |
1119 | positionally the first argument. */ | |
1120 | if (has_no_arguments) | |
1121 | gdb::option::complete_on_all_options (tracker, group); | |
1122 | ||
d55637df TT |
1123 | /* We're completing the breakpoint number. */ |
1124 | len = strlen (text); | |
1125 | ||
43892fdf | 1126 | for (breakpoint *b : all_breakpoints ()) |
58ce7251 SDJ |
1127 | { |
1128 | char number[50]; | |
1129 | ||
1130 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1131 | ||
1132 | if (strncmp (number, text, len) == 0) | |
b02f78f9 | 1133 | tracker.add_completion (make_unique_xstrdup (number)); |
58ce7251 | 1134 | } |
d55637df | 1135 | |
eb3ff9a5 | 1136 | return; |
d55637df TT |
1137 | } |
1138 | ||
b1d4d8d1 TBA |
1139 | /* We're completing the expression part. Skip the breakpoint num. */ |
1140 | const char *exp_start = skip_spaces (space); | |
1141 | tracker.advance_custom_word_point_by (exp_start - text); | |
1142 | text = exp_start; | |
1143 | const char *word = advance_to_expression_complete_word_point (tracker, text); | |
eb3ff9a5 | 1144 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
1145 | } |
1146 | ||
c906108c SS |
1147 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1148 | ||
1149 | static void | |
0b39b52e | 1150 | condition_command (const char *arg, int from_tty) |
c906108c | 1151 | { |
0b39b52e | 1152 | const char *p; |
52f0bd74 | 1153 | int bnum; |
c906108c SS |
1154 | |
1155 | if (arg == 0) | |
e2e0b3e5 | 1156 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1157 | |
1158 | p = arg; | |
733d554a TBA |
1159 | |
1160 | /* Check if the "-force" flag was passed. */ | |
b1d4d8d1 TBA |
1161 | condition_command_opts cc_opts; |
1162 | const auto group = make_condition_command_options_def_group (&cc_opts); | |
1163 | gdb::option::process_options | |
1164 | (&p, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group); | |
733d554a | 1165 | |
c906108c | 1166 | bnum = get_number (&p); |
5c44784c | 1167 | if (bnum == 0) |
8a3fe4f8 | 1168 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c | 1169 | |
79aabb73 | 1170 | set_breakpoint_condition (bnum, p, from_tty, cc_opts.force_condition); |
c906108c SS |
1171 | } |
1172 | ||
a7bdde9e VP |
1173 | /* Check that COMMAND do not contain commands that are suitable |
1174 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1175 | Throw if any such commands is found. */ |
1176 | ||
a7bdde9e VP |
1177 | static void |
1178 | check_no_tracepoint_commands (struct command_line *commands) | |
1179 | { | |
1180 | struct command_line *c; | |
cc59ec59 | 1181 | |
a7bdde9e VP |
1182 | for (c = commands; c; c = c->next) |
1183 | { | |
a7bdde9e | 1184 | if (c->control_type == while_stepping_control) |
3e43a32a MS |
1185 | error (_("The 'while-stepping' command can " |
1186 | "only be used for tracepoints")); | |
a7bdde9e | 1187 | |
12973681 TT |
1188 | check_no_tracepoint_commands (c->body_list_0.get ()); |
1189 | check_no_tracepoint_commands (c->body_list_1.get ()); | |
a7bdde9e VP |
1190 | |
1191 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1192 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1193 | command directly. */ |
1194 | if (strstr (c->line, "collect ") == c->line) | |
1195 | error (_("The 'collect' command can only be used for tracepoints")); | |
1196 | ||
51661e93 VP |
1197 | if (strstr (c->line, "teval ") == c->line) |
1198 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1199 | } |
1200 | } | |
1201 | ||
098f1272 | 1202 | struct longjmp_breakpoint : public momentary_breakpoint |
3b0871f4 | 1203 | { |
c1fc2657 | 1204 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1205 | }; |
1206 | ||
d77f58be SS |
1207 | /* Encapsulate tests for different types of tracepoints. */ |
1208 | ||
3b0871f4 SM |
1209 | static bool |
1210 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1211 | { |
1212 | return (type == bp_tracepoint | |
1213 | || type == bp_fast_tracepoint | |
7b572efb TT |
1214 | || type == bp_static_tracepoint |
1215 | || type == bp_static_marker_tracepoint); | |
d9b3f62e PA |
1216 | } |
1217 | ||
f2478a7e SM |
1218 | /* See breakpoint.h. */ |
1219 | ||
1220 | bool | |
d77f58be | 1221 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1222 | { |
d9b3f62e | 1223 | return is_tracepoint_type (b->type); |
a7bdde9e | 1224 | } |
d9b3f62e | 1225 | |
a5e364af SM |
1226 | /* Factory function to create an appropriate instance of breakpoint given |
1227 | TYPE. */ | |
1228 | ||
1229 | static std::unique_ptr<breakpoint> | |
1230 | new_breakpoint_from_type (bptype type) | |
1231 | { | |
1232 | breakpoint *b; | |
1233 | ||
098f1272 TT |
1234 | switch (type) |
1235 | { | |
1236 | case bp_breakpoint: | |
1237 | case bp_hardware_breakpoint: | |
1238 | b = new ordinary_breakpoint (); | |
1239 | break; | |
1240 | ||
1241 | case bp_fast_tracepoint: | |
1242 | case bp_static_tracepoint: | |
1243 | case bp_tracepoint: | |
1244 | b = new tracepoint (); | |
1245 | break; | |
1246 | ||
6d7a8c56 TT |
1247 | case bp_static_marker_tracepoint: |
1248 | b = new static_marker_tracepoint (); | |
1249 | break; | |
1250 | ||
098f1272 TT |
1251 | case bp_dprintf: |
1252 | b = new dprintf_breakpoint (); | |
1253 | break; | |
1254 | ||
1255 | case bp_overlay_event: | |
1256 | case bp_longjmp_master: | |
1257 | case bp_std_terminate_master: | |
1258 | case bp_exception_master: | |
1259 | case bp_thread_event: | |
1260 | case bp_jit_event: | |
1261 | case bp_shlib_event: | |
1262 | b = new internal_breakpoint (); | |
1263 | break; | |
1264 | ||
1265 | case bp_longjmp: | |
1266 | case bp_exception: | |
1267 | b = new longjmp_breakpoint (); | |
1268 | break; | |
1269 | ||
1270 | case bp_watchpoint_scope: | |
1271 | case bp_finish: | |
1272 | case bp_gnu_ifunc_resolver_return: | |
1273 | case bp_step_resume: | |
1274 | case bp_hp_step_resume: | |
1275 | case bp_longjmp_resume: | |
1276 | case bp_longjmp_call_dummy: | |
1277 | case bp_exception_resume: | |
1278 | case bp_call_dummy: | |
1279 | case bp_until: | |
1280 | case bp_std_terminate: | |
1281 | b = new momentary_breakpoint (); | |
1282 | break; | |
1283 | ||
1284 | default: | |
1285 | gdb_assert_not_reached ("invalid type"); | |
1286 | } | |
a5e364af SM |
1287 | |
1288 | return std::unique_ptr<breakpoint> (b); | |
1289 | } | |
1290 | ||
e5dd4106 | 1291 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1292 | breakpoint. This function will throw an exception if a problem is |
1293 | found. */ | |
48cb2d85 | 1294 | |
95a42b64 TT |
1295 | static void |
1296 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1297 | struct command_line *commands) | |
48cb2d85 | 1298 | { |
d77f58be | 1299 | if (is_tracepoint (b)) |
a7bdde9e | 1300 | { |
c9a6ce02 | 1301 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1302 | struct command_line *c; |
1303 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1304 | |
1305 | /* Reset the while-stepping step count. The previous commands | |
dda83cd7 SM |
1306 | might have included a while-stepping action, while the new |
1307 | ones might not. */ | |
c9a6ce02 PA |
1308 | t->step_count = 0; |
1309 | ||
1310 | /* We need to verify that each top-level element of commands is | |
1311 | valid for tracepoints, that there's at most one | |
1312 | while-stepping element, and that the while-stepping's body | |
1313 | has valid tracing commands excluding nested while-stepping. | |
1314 | We also need to validate the tracepoint action line in the | |
1315 | context of the tracepoint --- validate_actionline actually | |
1316 | has side effects, like setting the tracepoint's | |
1317 | while-stepping STEP_COUNT, in addition to checking if the | |
1318 | collect/teval actions parse and make sense in the | |
1319 | tracepoint's context. */ | |
a7bdde9e VP |
1320 | for (c = commands; c; c = c->next) |
1321 | { | |
a7bdde9e VP |
1322 | if (c->control_type == while_stepping_control) |
1323 | { | |
1324 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1325 | error (_("The 'while-stepping' command " |
1326 | "cannot be used for fast tracepoint")); | |
7b572efb TT |
1327 | else if (b->type == bp_static_tracepoint |
1328 | || b->type == bp_static_marker_tracepoint) | |
3e43a32a MS |
1329 | error (_("The 'while-stepping' command " |
1330 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1331 | |
1332 | if (while_stepping) | |
3e43a32a MS |
1333 | error (_("The 'while-stepping' command " |
1334 | "can be used only once")); | |
a7bdde9e VP |
1335 | else |
1336 | while_stepping = c; | |
1337 | } | |
c9a6ce02 PA |
1338 | |
1339 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1340 | } |
1341 | if (while_stepping) | |
1342 | { | |
1343 | struct command_line *c2; | |
1344 | ||
12973681 TT |
1345 | gdb_assert (while_stepping->body_list_1 == nullptr); |
1346 | c2 = while_stepping->body_list_0.get (); | |
a7bdde9e VP |
1347 | for (; c2; c2 = c2->next) |
1348 | { | |
a7bdde9e VP |
1349 | if (c2->control_type == while_stepping_control) |
1350 | error (_("The 'while-stepping' command cannot be nested")); | |
1351 | } | |
1352 | } | |
1353 | } | |
1354 | else | |
1355 | { | |
1356 | check_no_tracepoint_commands (commands); | |
1357 | } | |
95a42b64 TT |
1358 | } |
1359 | ||
0fb4aa4b PA |
1360 | /* Return a vector of all the static tracepoints set at ADDR. The |
1361 | caller is responsible for releasing the vector. */ | |
1362 | ||
f51e0e20 | 1363 | std::vector<breakpoint *> |
0fb4aa4b PA |
1364 | static_tracepoints_here (CORE_ADDR addr) |
1365 | { | |
f51e0e20 | 1366 | std::vector<breakpoint *> found; |
0fb4aa4b | 1367 | |
43892fdf | 1368 | for (breakpoint *b : all_breakpoints ()) |
7b572efb TT |
1369 | if (b->type == bp_static_tracepoint |
1370 | || b->type == bp_static_marker_tracepoint) | |
0fb4aa4b | 1371 | { |
40cb8ca5 | 1372 | for (bp_location *loc : b->locations ()) |
0fb4aa4b | 1373 | if (loc->address == addr) |
f51e0e20 | 1374 | found.push_back (b); |
0fb4aa4b PA |
1375 | } |
1376 | ||
1377 | return found; | |
1378 | } | |
1379 | ||
95a42b64 | 1380 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1381 | validate that only allowed commands are included. */ |
95a42b64 TT |
1382 | |
1383 | void | |
4a64f543 | 1384 | breakpoint_set_commands (struct breakpoint *b, |
12973681 | 1385 | counted_command_line &&commands) |
95a42b64 | 1386 | { |
93921405 | 1387 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1388 | |
d1b0a7bf | 1389 | b->commands = std::move (commands); |
76727919 | 1390 | gdb::observers::breakpoint_modified.notify (b); |
48cb2d85 VP |
1391 | } |
1392 | ||
45a43567 TT |
1393 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1394 | is not the same as the "silent" that may appear in the breakpoint's | |
1395 | commands. */ | |
1396 | ||
1397 | void | |
1398 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1399 | { | |
1400 | int old_silent = b->silent; | |
1401 | ||
1402 | b->silent = silent; | |
1403 | if (old_silent != silent) | |
76727919 | 1404 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1405 | } |
1406 | ||
1407 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1408 | breakpoint work for any thread. */ | |
1409 | ||
1410 | void | |
1411 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1412 | { | |
1413 | int old_thread = b->thread; | |
1414 | ||
1415 | b->thread = thread; | |
1416 | if (old_thread != thread) | |
76727919 | 1417 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1418 | } |
1419 | ||
1420 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1421 | breakpoint work for any task. */ | |
1422 | ||
1423 | void | |
1424 | breakpoint_set_task (struct breakpoint *b, int task) | |
1425 | { | |
1426 | int old_task = b->task; | |
1427 | ||
1428 | b->task = task; | |
1429 | if (old_task != task) | |
76727919 | 1430 | gdb::observers::breakpoint_modified.notify (b); |
45a43567 TT |
1431 | } |
1432 | ||
95a42b64 | 1433 | static void |
896b6bda | 1434 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1435 | struct command_line *control) |
95a42b64 | 1436 | { |
d1b0a7bf | 1437 | counted_command_line cmd; |
999700cd PW |
1438 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
1439 | NULL after the call to read_command_lines if the user provides an empty | |
1440 | list of command by just typing "end". */ | |
1441 | bool cmd_read = false; | |
95a42b64 | 1442 | |
896b6bda PA |
1443 | std::string new_arg; |
1444 | ||
95a42b64 TT |
1445 | if (arg == NULL || !*arg) |
1446 | { | |
da1df1db | 1447 | /* Argument not explicitly given. Synthesize it. */ |
86b17b60 | 1448 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1449 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1450 | breakpoint_count); | |
95a42b64 | 1451 | else if (breakpoint_count > 0) |
896b6bda | 1452 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b | 1453 | } |
da1df1db TBA |
1454 | else |
1455 | { | |
1456 | /* Create a copy of ARG. This is needed because the "commands" | |
1457 | command may be coming from a script. In that case, the read | |
1458 | line buffer is going to be overwritten in the lambda of | |
1459 | 'map_breakpoint_numbers' below when reading the next line | |
1460 | before we are are done parsing the breakpoint numbers. */ | |
1461 | new_arg = arg; | |
1462 | } | |
1463 | arg = new_arg.c_str (); | |
48649e1b TT |
1464 | |
1465 | map_breakpoint_numbers | |
1466 | (arg, [&] (breakpoint *b) | |
1467 | { | |
999700cd | 1468 | if (!cmd_read) |
48649e1b | 1469 | { |
999700cd | 1470 | gdb_assert (cmd == NULL); |
48649e1b | 1471 | if (control != NULL) |
12973681 | 1472 | cmd = control->body_list_0; |
48649e1b TT |
1473 | else |
1474 | { | |
81b1e71c TT |
1475 | std::string str |
1476 | = string_printf (_("Type commands for breakpoint(s) " | |
1477 | "%s, one per line."), | |
1478 | arg); | |
48649e1b | 1479 | |
60b3cef2 TT |
1480 | auto do_validate = [=] (const char *line) |
1481 | { | |
1482 | validate_actionline (line, b); | |
1483 | }; | |
1484 | gdb::function_view<void (const char *)> validator; | |
1485 | if (is_tracepoint (b)) | |
1486 | validator = do_validate; | |
1487 | ||
1488 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); | |
48649e1b | 1489 | } |
999700cd | 1490 | cmd_read = true; |
48649e1b TT |
1491 | } |
1492 | ||
1493 | /* If a breakpoint was on the list more than once, we don't need to | |
1494 | do anything. */ | |
1495 | if (b->commands != cmd) | |
1496 | { | |
d1b0a7bf | 1497 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b | 1498 | b->commands = cmd; |
76727919 | 1499 | gdb::observers::breakpoint_modified.notify (b); |
48649e1b TT |
1500 | } |
1501 | }); | |
95a42b64 TT |
1502 | } |
1503 | ||
1504 | static void | |
0b39b52e | 1505 | commands_command (const char *arg, int from_tty) |
95a42b64 TT |
1506 | { |
1507 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1508 | } |
40c03ae8 EZ |
1509 | |
1510 | /* Like commands_command, but instead of reading the commands from | |
1511 | input stream, takes them from an already parsed command structure. | |
1512 | ||
1513 | This is used by cli-script.c to DTRT with breakpoint commands | |
1514 | that are part of if and while bodies. */ | |
1515 | enum command_control_type | |
896b6bda | 1516 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1517 | { |
95a42b64 TT |
1518 | commands_command_1 (arg, 0, cmd); |
1519 | return simple_control; | |
40c03ae8 | 1520 | } |
876fa593 JK |
1521 | |
1522 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1523 | ||
1524 | static int | |
1525 | bp_location_has_shadow (struct bp_location *bl) | |
1526 | { | |
1527 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1528 | return 0; | |
1529 | if (!bl->inserted) | |
1530 | return 0; | |
1531 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1532 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1533 | return 0; |
1534 | return 1; | |
1535 | } | |
1536 | ||
9d497a19 PA |
1537 | /* Update BUF, which is LEN bytes read from the target address |
1538 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1539 | contents. | |
1540 | ||
1541 | If READBUF is not NULL, this buffer must not overlap with the of | |
1542 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1543 | failed assertion internal error will be raised. */ | |
1544 | ||
1545 | static void | |
1546 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1547 | const gdb_byte *writebuf_org, | |
1548 | ULONGEST memaddr, LONGEST len, | |
1549 | struct bp_target_info *target_info, | |
1550 | struct gdbarch *gdbarch) | |
1551 | { | |
1552 | /* Now do full processing of the found relevant range of elements. */ | |
1553 | CORE_ADDR bp_addr = 0; | |
1554 | int bp_size = 0; | |
1555 | int bptoffset = 0; | |
1556 | ||
1557 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1558 | current_program_space->aspace, 0)) | |
1559 | { | |
1560 | /* The breakpoint is inserted in a different address space. */ | |
1561 | return; | |
1562 | } | |
1563 | ||
1564 | /* Addresses and length of the part of the breakpoint that | |
1565 | we need to copy. */ | |
1566 | bp_addr = target_info->placed_address; | |
1567 | bp_size = target_info->shadow_len; | |
1568 | ||
1569 | if (bp_addr + bp_size <= memaddr) | |
1570 | { | |
1571 | /* The breakpoint is entirely before the chunk of memory we are | |
1572 | reading. */ | |
1573 | return; | |
1574 | } | |
1575 | ||
1576 | if (bp_addr >= memaddr + len) | |
1577 | { | |
1578 | /* The breakpoint is entirely after the chunk of memory we are | |
1579 | reading. */ | |
1580 | return; | |
1581 | } | |
1582 | ||
1583 | /* Offset within shadow_contents. */ | |
1584 | if (bp_addr < memaddr) | |
1585 | { | |
1586 | /* Only copy the second part of the breakpoint. */ | |
1587 | bp_size -= memaddr - bp_addr; | |
1588 | bptoffset = memaddr - bp_addr; | |
1589 | bp_addr = memaddr; | |
1590 | } | |
1591 | ||
1592 | if (bp_addr + bp_size > memaddr + len) | |
1593 | { | |
1594 | /* Only copy the first part of the breakpoint. */ | |
1595 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1596 | } | |
1597 | ||
1598 | if (readbuf != NULL) | |
1599 | { | |
1600 | /* Verify that the readbuf buffer does not overlap with the | |
1601 | shadow_contents buffer. */ | |
1602 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1603 | || readbuf >= (target_info->shadow_contents | |
1604 | + target_info->shadow_len)); | |
1605 | ||
1606 | /* Update the read buffer with this inserted breakpoint's | |
1607 | shadow. */ | |
1608 | memcpy (readbuf + bp_addr - memaddr, | |
1609 | target_info->shadow_contents + bptoffset, bp_size); | |
1610 | } | |
1611 | else | |
1612 | { | |
1613 | const unsigned char *bp; | |
0d5ed153 MR |
1614 | CORE_ADDR addr = target_info->reqstd_address; |
1615 | int placed_size; | |
9d497a19 PA |
1616 | |
1617 | /* Update the shadow with what we want to write to memory. */ | |
1618 | memcpy (target_info->shadow_contents + bptoffset, | |
1619 | writebuf_org + bp_addr - memaddr, bp_size); | |
1620 | ||
1621 | /* Determine appropriate breakpoint contents and size for this | |
1622 | address. */ | |
0d5ed153 | 1623 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1624 | |
1625 | /* Update the final write buffer with this inserted | |
1626 | breakpoint's INSN. */ | |
1627 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1628 | } | |
1629 | } | |
1630 | ||
8defab1a | 1631 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1632 | by replacing any memory breakpoints with their shadowed contents. |
1633 | ||
35c63cd8 JB |
1634 | If READBUF is not NULL, this buffer must not overlap with any of |
1635 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1636 | a failed assertion internal error will be raised. | |
1637 | ||
876fa593 | 1638 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1639 | bl->address - bp_locations_placed_address_before_address_max |
1640 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1641 | The range we were requested to resolve shadows for is: |
1642 | memaddr ... memaddr + len | |
1643 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1644 | memaddr + len <= (bl->address |
f5336ca5 | 1645 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1646 | and: |
f5336ca5 | 1647 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1648 | |
8defab1a | 1649 | void |
f0ba3972 PA |
1650 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1651 | const gdb_byte *writebuf_org, | |
1652 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1653 | { |
4a64f543 MS |
1654 | /* Left boundary, right boundary and median element of our binary |
1655 | search. */ | |
876fa593 JK |
1656 | unsigned bc_l, bc_r, bc; |
1657 | ||
4a64f543 MS |
1658 | /* Find BC_L which is a leftmost element which may affect BUF |
1659 | content. It is safe to report lower value but a failure to | |
1660 | report higher one. */ | |
876fa593 JK |
1661 | |
1662 | bc_l = 0; | |
5d51cd5d | 1663 | bc_r = bp_locations.size (); |
876fa593 JK |
1664 | while (bc_l + 1 < bc_r) |
1665 | { | |
35df4500 | 1666 | struct bp_location *bl; |
876fa593 JK |
1667 | |
1668 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1669 | bl = bp_locations[bc]; |
876fa593 | 1670 | |
4a64f543 MS |
1671 | /* Check first BL->ADDRESS will not overflow due to the added |
1672 | constant. Then advance the left boundary only if we are sure | |
1673 | the BC element can in no way affect the BUF content (MEMADDR | |
1674 | to MEMADDR + LEN range). | |
876fa593 | 1675 | |
f5336ca5 | 1676 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1677 | offset so that we cannot miss a breakpoint with its shadow |
1678 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1679 | |
f5336ca5 | 1680 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1681 | >= bl->address) |
f5336ca5 | 1682 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1683 | <= memaddr)) |
876fa593 JK |
1684 | bc_l = bc; |
1685 | else | |
1686 | bc_r = bc; | |
1687 | } | |
1688 | ||
128070bb PA |
1689 | /* Due to the binary search above, we need to make sure we pick the |
1690 | first location that's at BC_L's address. E.g., if there are | |
1691 | multiple locations at the same address, BC_L may end up pointing | |
1692 | at a duplicate location, and miss the "master"/"inserted" | |
1693 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1694 | B: | |
1695 | ||
1696 | L1@A, L2@A, L3@B, ... | |
1697 | ||
1698 | BC_L could end up pointing at location L2, while the "master" | |
1699 | location could be L1. Since the `loc->inserted' flag is only set | |
1700 | on "master" locations, we'd forget to restore the shadow of L1 | |
1701 | and L2. */ | |
1702 | while (bc_l > 0 | |
f5336ca5 | 1703 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1704 | bc_l--; |
1705 | ||
876fa593 JK |
1706 | /* Now do full processing of the found relevant range of elements. */ |
1707 | ||
5d51cd5d | 1708 | for (bc = bc_l; bc < bp_locations.size (); bc++) |
01add95b SM |
1709 | { |
1710 | struct bp_location *bl = bp_locations[bc]; | |
876fa593 | 1711 | |
01add95b SM |
1712 | /* bp_location array has BL->OWNER always non-NULL. */ |
1713 | if (bl->owner->type == bp_none) | |
1714 | warning (_("reading through apparently deleted breakpoint #%d?"), | |
1715 | bl->owner->number); | |
ffce0d52 | 1716 | |
01add95b SM |
1717 | /* Performance optimization: any further element can no longer affect BUF |
1718 | content. */ | |
876fa593 | 1719 | |
01add95b SM |
1720 | if (bl->address >= bp_locations_placed_address_before_address_max |
1721 | && (memaddr + len | |
1722 | <= (bl->address | |
1723 | - bp_locations_placed_address_before_address_max))) | |
1724 | break; | |
876fa593 | 1725 | |
01add95b SM |
1726 | if (!bp_location_has_shadow (bl)) |
1727 | continue; | |
6c95b8df | 1728 | |
01add95b SM |
1729 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1730 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1731 | } | |
c906108c | 1732 | } |
9d497a19 | 1733 | |
f2478a7e | 1734 | /* See breakpoint.h. */ |
b775012e | 1735 | |
f2478a7e | 1736 | bool |
b775012e LM |
1737 | is_breakpoint (const struct breakpoint *bpt) |
1738 | { | |
1739 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1740 | || bpt->type == bp_hardware_breakpoint |
1741 | || bpt->type == bp_dprintf); | |
b775012e LM |
1742 | } |
1743 | ||
60e1c644 PA |
1744 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1745 | ||
f2478a7e | 1746 | static bool |
d77f58be | 1747 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1748 | { |
1749 | return (bpt->type == bp_hardware_watchpoint | |
1750 | || bpt->type == bp_read_watchpoint | |
1751 | || bpt->type == bp_access_watchpoint); | |
1752 | } | |
7270d8f2 | 1753 | |
f2478a7e | 1754 | /* See breakpoint.h. */ |
60e1c644 | 1755 | |
f2478a7e | 1756 | bool |
d77f58be | 1757 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1758 | { |
1759 | return (is_hardware_watchpoint (bpt) | |
1760 | || bpt->type == bp_watchpoint); | |
1761 | } | |
1762 | ||
3a5c3e22 PA |
1763 | /* Returns true if the current thread and its running state are safe |
1764 | to evaluate or update watchpoint B. Watchpoints on local | |
1765 | expressions need to be evaluated in the context of the thread that | |
1766 | was current when the watchpoint was created, and, that thread needs | |
1767 | to be stopped to be able to select the correct frame context. | |
1768 | Watchpoints on global expressions can be evaluated on any thread, | |
1769 | and in any state. It is presently left to the target allowing | |
1770 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1771 | |
1772 | static int | |
3a5c3e22 | 1773 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1774 | { |
c1fc2657 | 1775 | return (b->pspace == current_program_space |
d7e15655 TT |
1776 | && (b->watchpoint_thread == null_ptid |
1777 | || (inferior_ptid == b->watchpoint_thread | |
611841bb | 1778 | && !inferior_thread ()->executing ()))); |
f6bc2008 PA |
1779 | } |
1780 | ||
d0fb5eae JK |
1781 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1782 | associated bp_watchpoint_scope breakpoint. */ | |
1783 | ||
1784 | static void | |
3a5c3e22 | 1785 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1786 | { |
c1fc2657 | 1787 | if (w->related_breakpoint != w) |
d0fb5eae | 1788 | { |
c1fc2657 SM |
1789 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1790 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1791 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1792 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1793 | w->related_breakpoint = w; | |
d0fb5eae | 1794 | } |
c1fc2657 | 1795 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1796 | } |
1797 | ||
bb9d5f81 PP |
1798 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1799 | watchpoint W. */ | |
1800 | ||
1801 | static struct value * | |
1802 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1803 | { | |
1804 | struct value *bit_val; | |
1805 | ||
1806 | if (val == NULL) | |
1807 | return NULL; | |
1808 | ||
1809 | bit_val = allocate_value (value_type (val)); | |
1810 | ||
1811 | unpack_value_bitfield (bit_val, | |
1812 | w->val_bitpos, | |
1813 | w->val_bitsize, | |
50888e42 | 1814 | value_contents_for_printing (val).data (), |
bb9d5f81 PP |
1815 | value_offset (val), |
1816 | val); | |
1817 | ||
1818 | return bit_val; | |
1819 | } | |
1820 | ||
c6d81124 PA |
1821 | /* Allocate a dummy location and add it to B, which must be a software |
1822 | watchpoint. This is required because even if a software watchpoint | |
1823 | is not watching any memory, bpstat_stop_status requires a location | |
1824 | to be able to report stops. */ | |
1825 | ||
1826 | static void | |
1827 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1828 | struct program_space *pspace) | |
1829 | { | |
1830 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1831 | ||
1832 | b->loc = allocate_bp_location (b); | |
1833 | b->loc->pspace = pspace; | |
1834 | b->loc->address = -1; | |
1835 | b->loc->length = -1; | |
1836 | } | |
1837 | ||
1838 | /* Returns true if B is a software watchpoint that is not watching any | |
1839 | memory (e.g., "watch $pc"). */ | |
1840 | ||
f2478a7e | 1841 | static bool |
c6d81124 PA |
1842 | is_no_memory_software_watchpoint (struct breakpoint *b) |
1843 | { | |
1844 | return (b->type == bp_watchpoint | |
1845 | && b->loc != NULL | |
1846 | && b->loc->next == NULL | |
1847 | && b->loc->address == -1 | |
1848 | && b->loc->length == -1); | |
1849 | } | |
1850 | ||
567e1b4e JB |
1851 | /* Assuming that B is a watchpoint: |
1852 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1853 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1854 | - Evaluate the condition if there is one, and store the result |
1855 | in b->loc->cond. | |
a5606eee VP |
1856 | - Update the list of values that must be watched in B->loc. |
1857 | ||
4a64f543 MS |
1858 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1859 | nothing. If this is local watchpoint that is out of scope, delete | |
1860 | it. | |
1861 | ||
1862 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1863 | removed + inserted on each stop here. Normal breakpoints must | |
1864 | never be removed because they might be missed by a running thread | |
1865 | when debugging in non-stop mode. On the other hand, hardware | |
1866 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1867 | to each LWP since they are stored in each LWP's hardware debug | |
1868 | registers. Therefore, such LWP must be stopped first in order to | |
1869 | be able to modify its hardware watchpoints. | |
1870 | ||
1871 | Hardware watchpoints must be reset exactly once after being | |
1872 | presented to the user. It cannot be done sooner, because it would | |
1873 | reset the data used to present the watchpoint hit to the user. And | |
1874 | it must not be done later because it could display the same single | |
1875 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1876 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1877 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1878 | not user-visible - its hit is suppressed if the memory content has | |
1879 | not changed. | |
1880 | ||
1881 | The following constraints influence the location where we can reset | |
1882 | hardware watchpoints: | |
1883 | ||
1884 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1885 | called several times when GDB stops. | |
1886 | ||
1887 | [linux] | |
1888 | * Multiple hardware watchpoints can be hit at the same time, | |
1889 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1890 | hit at a time as the reason for stopping, and all the other hits | |
1891 | are presented later, one after the other, each time the user | |
1892 | requests the execution to be resumed. Execution is not resumed | |
1893 | for the threads still having pending hit event stored in | |
1894 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1895 | the inferior on the first stop the thread hit event is kept being | |
1896 | reported from its cached value by linux_nat_stopped_data_address | |
1897 | until the real thread resume happens after the watchpoint gets | |
1898 | presented and thus its LWP_INFO->STATUS gets reset. | |
1899 | ||
1900 | Therefore the hardware watchpoint hit can get safely reset on the | |
1901 | watchpoint removal from inferior. */ | |
a79d3c27 | 1902 | |
b40ce68a | 1903 | static void |
3a5c3e22 | 1904 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1905 | { |
a5606eee | 1906 | int within_current_scope; |
a5606eee | 1907 | struct frame_id saved_frame_id; |
66076460 | 1908 | int frame_saved; |
a5606eee | 1909 | |
f6bc2008 PA |
1910 | /* If this is a local watchpoint, we only want to check if the |
1911 | watchpoint frame is in scope if the current thread is the thread | |
1912 | that was used to create the watchpoint. */ | |
1913 | if (!watchpoint_in_thread_scope (b)) | |
1914 | return; | |
1915 | ||
c1fc2657 | 1916 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1917 | return; |
1918 | ||
66076460 | 1919 | frame_saved = 0; |
a5606eee VP |
1920 | |
1921 | /* Determine if the watchpoint is within scope. */ | |
1922 | if (b->exp_valid_block == NULL) | |
1923 | within_current_scope = 1; | |
1924 | else | |
1925 | { | |
b5db5dfc UW |
1926 | struct frame_info *fi = get_current_frame (); |
1927 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1928 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1929 | ||
c9cf6e20 MG |
1930 | /* If we're at a point where the stack has been destroyed |
1931 | (e.g. in a function epilogue), unwinding may not work | |
1932 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1933 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1934 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1935 | return; |
66076460 DJ |
1936 | |
1937 | /* Save the current frame's ID so we can restore it after | |
dda83cd7 | 1938 | evaluating the watchpoint expression on its own frame. */ |
66076460 | 1939 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
dda83cd7 SM |
1940 | took a frame parameter, so that we didn't have to change the |
1941 | selected frame. */ | |
66076460 DJ |
1942 | frame_saved = 1; |
1943 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1944 | ||
a5606eee VP |
1945 | fi = frame_find_by_id (b->watchpoint_frame); |
1946 | within_current_scope = (fi != NULL); | |
1947 | if (within_current_scope) | |
1948 | select_frame (fi); | |
1949 | } | |
1950 | ||
b5db5dfc UW |
1951 | /* We don't free locations. They are stored in the bp_location array |
1952 | and update_global_location_list will eventually delete them and | |
1953 | remove breakpoints if needed. */ | |
c1fc2657 | 1954 | b->loc = NULL; |
b5db5dfc | 1955 | |
a5606eee VP |
1956 | if (within_current_scope && reparse) |
1957 | { | |
bbc13ae3 | 1958 | const char *s; |
d63d0675 | 1959 | |
4d01a485 | 1960 | b->exp.reset (); |
a4c50be3 TT |
1961 | s = (b->exp_string_reparse |
1962 | ? b->exp_string_reparse.get () | |
1963 | : b->exp_string.get ()); | |
1bb9788d | 1964 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1965 | /* If the meaning of expression itself changed, the old value is |
1966 | no longer relevant. We don't want to report a watchpoint hit | |
1967 | to the user when the old value and the new value may actually | |
1968 | be completely different objects. */ | |
fa4727a6 | 1969 | b->val = NULL; |
4c1d86d9 | 1970 | b->val_valid = false; |
60e1c644 PA |
1971 | |
1972 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1973 | expression is stored in the breakpoint object, not in the | |
1974 | locations (re)created below. */ | |
c1fc2657 | 1975 | if (b->cond_string != NULL) |
60e1c644 | 1976 | { |
4d01a485 | 1977 | b->cond_exp.reset (); |
60e1c644 | 1978 | |
6f781ee3 | 1979 | s = b->cond_string.get (); |
1bb9788d | 1980 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1981 | } |
a5606eee | 1982 | } |
a5606eee VP |
1983 | |
1984 | /* If we failed to parse the expression, for example because | |
1985 | it refers to a global variable in a not-yet-loaded shared library, | |
1986 | don't try to insert watchpoint. We don't automatically delete | |
1987 | such watchpoint, though, since failure to parse expression | |
1988 | is different from out-of-scope watchpoint. */ | |
55f6301a | 1989 | if (!target_has_execution ()) |
2d134ed3 PA |
1990 | { |
1991 | /* Without execution, memory can't change. No use to try and | |
1992 | set watchpoint locations. The watchpoint will be reset when | |
1993 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1994 | if (!can_use_hw_watchpoints) |
1995 | { | |
c47614fe | 1996 | if (b->works_in_software_mode ()) |
c1fc2657 | 1997 | b->type = bp_watchpoint; |
e8369a73 | 1998 | else |
638aa5a1 AB |
1999 | error (_("Can't set read/access watchpoint when " |
2000 | "hardware watchpoints are disabled.")); | |
e8369a73 | 2001 | } |
2d134ed3 PA |
2002 | } |
2003 | else if (within_current_scope && b->exp) | |
a5606eee | 2004 | { |
a6535de1 | 2005 | std::vector<value_ref_ptr> val_chain; |
8d49165d | 2006 | struct value *v, *result; |
2d134ed3 | 2007 | struct program_space *frame_pspace; |
a5606eee | 2008 | |
1eaebe02 | 2009 | fetch_subexp_value (b->exp.get (), b->exp->op.get (), &v, &result, |
413403fc | 2010 | &val_chain, false); |
a5606eee | 2011 | |
a5606eee VP |
2012 | /* Avoid setting b->val if it's already set. The meaning of |
2013 | b->val is 'the last value' user saw, and we should update | |
2014 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
2015 | happens, the code that reports it updates b->val directly. |
2016 | We don't keep track of the memory value for masked | |
2017 | watchpoints. */ | |
c1fc2657 | 2018 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 2019 | { |
bb9d5f81 | 2020 | if (b->val_bitsize != 0) |
850645cf TT |
2021 | v = extract_bitfield_from_watchpoint_value (b, v); |
2022 | b->val = release_value (v); | |
4c1d86d9 | 2023 | b->val_valid = true; |
fa4727a6 | 2024 | } |
a5606eee | 2025 | |
2d134ed3 PA |
2026 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
2027 | ||
a5606eee | 2028 | /* Look at each value on the value chain. */ |
a6535de1 TT |
2029 | gdb_assert (!val_chain.empty ()); |
2030 | for (const value_ref_ptr &iter : val_chain) | |
a5606eee | 2031 | { |
a6535de1 TT |
2032 | v = iter.get (); |
2033 | ||
a5606eee VP |
2034 | /* If it's a memory location, and GDB actually needed |
2035 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
2036 | must watch it. If the first value returned is |
2037 | still lazy, that means an error occurred reading it; | |
2038 | watch it anyway in case it becomes readable. */ | |
a5606eee | 2039 | if (VALUE_LVAL (v) == lval_memory |
a6535de1 | 2040 | && (v == val_chain[0] || ! value_lazy (v))) |
a5606eee VP |
2041 | { |
2042 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 2043 | |
a5606eee VP |
2044 | /* We only watch structs and arrays if user asked |
2045 | for it explicitly, never if they just happen to | |
2046 | appear in the middle of some value chain. */ | |
fa4727a6 | 2047 | if (v == result |
78134374 SM |
2048 | || (vtype->code () != TYPE_CODE_STRUCT |
2049 | && vtype->code () != TYPE_CODE_ARRAY)) | |
a5606eee VP |
2050 | { |
2051 | CORE_ADDR addr; | |
f486487f | 2052 | enum target_hw_bp_type type; |
a5606eee | 2053 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2054 | int bitpos = 0, bitsize = 0; |
2055 | ||
2056 | if (value_bitsize (v) != 0) | |
2057 | { | |
2058 | /* Extract the bit parameters out from the bitfield | |
2059 | sub-expression. */ | |
2060 | bitpos = value_bitpos (v); | |
2061 | bitsize = value_bitsize (v); | |
2062 | } | |
2063 | else if (v == result && b->val_bitsize != 0) | |
2064 | { | |
2065 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2066 | lvalue whose bit parameters are saved in the fields | |
2067 | VAL_BITPOS and VAL_BITSIZE. */ | |
2068 | bitpos = b->val_bitpos; | |
2069 | bitsize = b->val_bitsize; | |
2070 | } | |
a5606eee | 2071 | |
42ae5230 | 2072 | addr = value_address (v); |
bb9d5f81 PP |
2073 | if (bitsize != 0) |
2074 | { | |
2075 | /* Skip the bytes that don't contain the bitfield. */ | |
2076 | addr += bitpos / 8; | |
2077 | } | |
2078 | ||
a5606eee | 2079 | type = hw_write; |
c1fc2657 | 2080 | if (b->type == bp_read_watchpoint) |
a5606eee | 2081 | type = hw_read; |
c1fc2657 | 2082 | else if (b->type == bp_access_watchpoint) |
a5606eee | 2083 | type = hw_access; |
3a5c3e22 | 2084 | |
c1fc2657 SM |
2085 | loc = allocate_bp_location (b); |
2086 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2087 | ; |
2088 | *tmp = loc; | |
8ee511af | 2089 | loc->gdbarch = value_type (v)->arch (); |
6c95b8df PA |
2090 | |
2091 | loc->pspace = frame_pspace; | |
f17d9474 | 2092 | loc->address = address_significant (loc->gdbarch, addr); |
bb9d5f81 PP |
2093 | |
2094 | if (bitsize != 0) | |
2095 | { | |
2096 | /* Just cover the bytes that make up the bitfield. */ | |
2097 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2098 | } | |
2099 | else | |
2100 | loc->length = TYPE_LENGTH (value_type (v)); | |
2101 | ||
a5606eee VP |
2102 | loc->watchpoint_type = type; |
2103 | } | |
2104 | } | |
9fa40276 TJB |
2105 | } |
2106 | ||
2107 | /* Change the type of breakpoint between hardware assisted or | |
2108 | an ordinary watchpoint depending on the hardware support | |
2109 | and free hardware slots. REPARSE is set when the inferior | |
2110 | is started. */ | |
a9634178 | 2111 | if (reparse) |
9fa40276 | 2112 | { |
e09342b5 | 2113 | int reg_cnt; |
9fa40276 | 2114 | enum bp_loc_type loc_type; |
a5606eee | 2115 | |
a9634178 | 2116 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2117 | |
2118 | if (reg_cnt) | |
9fa40276 TJB |
2119 | { |
2120 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2121 | enum bptype type; |
9fa40276 | 2122 | |
a9634178 TJB |
2123 | /* Use an exact watchpoint when there's only one memory region to be |
2124 | watched, and only one debug register is needed to watch it. */ | |
2125 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2126 | ||
9fa40276 | 2127 | /* We need to determine how many resources are already |
e09342b5 TJB |
2128 | used for all other hardware watchpoints plus this one |
2129 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2130 | this watchpoint in as well. */ |
2131 | ||
2132 | /* If this is a software watchpoint, we try to turn it | |
2133 | to a hardware one -- count resources as if B was of | |
2134 | hardware watchpoint type. */ | |
c1fc2657 | 2135 | type = b->type; |
a1398e0c PA |
2136 | if (type == bp_watchpoint) |
2137 | type = bp_hardware_watchpoint; | |
2138 | ||
2139 | /* This watchpoint may or may not have been placed on | |
2140 | the list yet at this point (it won't be in the list | |
2141 | if we're trying to create it for the first time, | |
2142 | through watch_command), so always account for it | |
2143 | manually. */ | |
2144 | ||
2145 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 2146 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
2147 | |
2148 | /* Add in the resources needed for B. */ | |
c1fc2657 | 2149 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
2150 | |
2151 | target_resources_ok | |
2152 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2153 | if (target_resources_ok <= 0) |
a9634178 | 2154 | { |
c47614fe | 2155 | int sw_mode = b->works_in_software_mode (); |
9c06b0b4 TJB |
2156 | |
2157 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2158 | error (_("Target does not support this type of " |
2159 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2160 | else if (target_resources_ok < 0 && !sw_mode) |
2161 | error (_("There are not enough available hardware " | |
2162 | "resources for this watchpoint.")); | |
a1398e0c PA |
2163 | |
2164 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 2165 | b->type = bp_watchpoint; |
a1398e0c PA |
2166 | } |
2167 | else | |
2168 | { | |
2169 | /* If this was a software watchpoint, we've just | |
2170 | found we have enough resources to turn it to a | |
2171 | hardware watchpoint. Otherwise, this is a | |
2172 | nop. */ | |
c1fc2657 | 2173 | b->type = type; |
a9634178 | 2174 | } |
9fa40276 | 2175 | } |
c47614fe | 2176 | else if (!b->works_in_software_mode ()) |
638aa5a1 AB |
2177 | { |
2178 | if (!can_use_hw_watchpoints) | |
2179 | error (_("Can't set read/access watchpoint when " | |
2180 | "hardware watchpoints are disabled.")); | |
2181 | else | |
2182 | error (_("Expression cannot be implemented with " | |
2183 | "read/access watchpoint.")); | |
2184 | } | |
9fa40276 | 2185 | else |
c1fc2657 | 2186 | b->type = bp_watchpoint; |
9fa40276 | 2187 | |
c1fc2657 | 2188 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2189 | : bp_loc_hardware_watchpoint); |
40cb8ca5 | 2190 | for (bp_location *bl : b->locations ()) |
9fa40276 TJB |
2191 | bl->loc_type = loc_type; |
2192 | } | |
2193 | ||
c7437ca6 PA |
2194 | /* If a software watchpoint is not watching any memory, then the |
2195 | above left it without any location set up. But, | |
2196 | bpstat_stop_status requires a location to be able to report | |
2197 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2198 | if (b->type == bp_watchpoint && b->loc == NULL) |
2199 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2200 | } |
2201 | else if (!within_current_scope) | |
7270d8f2 | 2202 | { |
6cb06a8c | 2203 | gdb_printf (_("\ |
ac74f770 MS |
2204 | Watchpoint %d deleted because the program has left the block\n\ |
2205 | in which its expression is valid.\n"), | |
6cb06a8c | 2206 | b->number); |
d0fb5eae | 2207 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2208 | } |
a5606eee VP |
2209 | |
2210 | /* Restore the selected frame. */ | |
66076460 DJ |
2211 | if (frame_saved) |
2212 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2213 | } |
2214 | ||
a5606eee | 2215 | |
74960c60 | 2216 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2217 | inserted in the inferior. We don't differentiate the type of BL's owner |
2218 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2219 | breakpoint_ops is not defined, because in insert_bp_location, | |
2220 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2221 | static int |
35df4500 | 2222 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2223 | { |
35df4500 | 2224 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2225 | return 0; |
2226 | ||
35df4500 | 2227 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2228 | return 0; |
2229 | ||
b5fa468f TBA |
2230 | if (!bl->enabled || bl->disabled_by_cond |
2231 | || bl->shlib_disabled || bl->duplicate) | |
74960c60 VP |
2232 | return 0; |
2233 | ||
f8eba3c6 TT |
2234 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2235 | return 0; | |
2236 | ||
56710373 PA |
2237 | /* This is set for example, when we're attached to the parent of a |
2238 | vfork, and have detached from the child. The child is running | |
2239 | free, and we expect it to do an exec or exit, at which point the | |
2240 | OS makes the parent schedulable again (and the target reports | |
2241 | that the vfork is done). Until the child is done with the shared | |
2242 | memory region, do not insert breakpoints in the parent, otherwise | |
2243 | the child could still trip on the parent's breakpoints. Since | |
2244 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2245 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2246 | return 0; |
2247 | ||
31e77af2 | 2248 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2249 | location, except if the breakpoint is a single-step breakpoint, |
2250 | and the breakpoint's thread is the thread which is stepping past | |
2251 | a breakpoint. */ | |
31e77af2 PA |
2252 | if ((bl->loc_type == bp_loc_software_breakpoint |
2253 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2254 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2255 | bl->address) |
2256 | /* The single-step breakpoint may be inserted at the location | |
2257 | we're trying to step if the instruction branches to itself. | |
2258 | However, the instruction won't be executed at all and it may | |
2259 | break the semantics of the instruction, for example, the | |
2260 | instruction is a conditional branch or updates some flags. | |
2261 | We can't fix it unless GDB is able to emulate the instruction | |
2262 | or switch to displaced stepping. */ | |
2263 | && !(bl->owner->type == bp_single_step | |
2264 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 | 2265 | { |
1eb8556f SM |
2266 | infrun_debug_printf ("skipping breakpoint: stepping past insn at: %s", |
2267 | paddress (bl->gdbarch, bl->address)); | |
e558d7c1 PA |
2268 | return 0; |
2269 | } | |
31e77af2 | 2270 | |
963f9c80 PA |
2271 | /* Don't insert watchpoints if we're trying to step past the |
2272 | instruction that triggered one. */ | |
2273 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2274 | && stepping_past_nonsteppable_watchpoint ()) | |
2275 | { | |
1eb8556f | 2276 | infrun_debug_printf ("stepping past non-steppable watchpoint. " |
ae1f4d2d | 2277 | "skipping watchpoint at %s:%d", |
1eb8556f | 2278 | paddress (bl->gdbarch, bl->address), bl->length); |
963f9c80 PA |
2279 | return 0; |
2280 | } | |
2281 | ||
74960c60 VP |
2282 | return 1; |
2283 | } | |
2284 | ||
934709f0 PW |
2285 | /* Same as should_be_inserted but does the check assuming |
2286 | that the location is not duplicated. */ | |
2287 | ||
2288 | static int | |
2289 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2290 | { | |
2291 | int result; | |
2292 | const int save_duplicate = bl->duplicate; | |
2293 | ||
2294 | bl->duplicate = 0; | |
2295 | result = should_be_inserted (bl); | |
2296 | bl->duplicate = save_duplicate; | |
2297 | return result; | |
2298 | } | |
2299 | ||
b775012e LM |
2300 | /* Parses a conditional described by an expression COND into an |
2301 | agent expression bytecode suitable for evaluation | |
2302 | by the bytecode interpreter. Return NULL if there was | |
2303 | any error during parsing. */ | |
2304 | ||
833177a4 | 2305 | static agent_expr_up |
b775012e LM |
2306 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2307 | { | |
833177a4 | 2308 | if (cond == NULL) |
b775012e LM |
2309 | return NULL; |
2310 | ||
833177a4 PA |
2311 | agent_expr_up aexpr; |
2312 | ||
b775012e LM |
2313 | /* We don't want to stop processing, so catch any errors |
2314 | that may show up. */ | |
a70b8144 | 2315 | try |
b775012e | 2316 | { |
036e657b | 2317 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2318 | } |
2319 | ||
230d2906 | 2320 | catch (const gdb_exception_error &ex) |
b775012e LM |
2321 | { |
2322 | /* If we got here, it means the condition could not be parsed to a valid | |
2323 | bytecode expression and thus can't be evaluated on the target's side. | |
2324 | It's no use iterating through the conditions. */ | |
b775012e LM |
2325 | } |
2326 | ||
2327 | /* We have a valid agent expression. */ | |
2328 | return aexpr; | |
2329 | } | |
2330 | ||
2331 | /* Based on location BL, create a list of breakpoint conditions to be | |
2332 | passed on to the target. If we have duplicated locations with different | |
2333 | conditions, we will add such conditions to the list. The idea is that the | |
2334 | target will evaluate the list of conditions and will only notify GDB when | |
2335 | one of them is true. */ | |
2336 | ||
2337 | static void | |
2338 | build_target_condition_list (struct bp_location *bl) | |
2339 | { | |
b775012e LM |
2340 | int null_condition_or_parse_error = 0; |
2341 | int modified = bl->needs_update; | |
b775012e | 2342 | |
8b4f3082 | 2343 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2344 | bl->target_info.conditions.clear (); |
8b4f3082 | 2345 | |
b775012e LM |
2346 | /* This is only meaningful if the target is |
2347 | evaluating conditions and if the user has | |
2348 | opted for condition evaluation on the target's | |
2349 | side. */ | |
2350 | if (gdb_evaluates_breakpoint_condition_p () | |
2351 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2352 | return; | |
2353 | ||
e0d9a270 SM |
2354 | auto loc_range = all_bp_locations_at_addr (bl->address); |
2355 | ||
b775012e | 2356 | /* Do a first pass to check for locations with no assigned |
7f32a4d5 PA |
2357 | conditions or conditions that fail to parse to a valid agent |
2358 | expression bytecode. If any of these happen, then it's no use to | |
2359 | send conditions to the target since this location will always | |
2360 | trigger and generate a response back to GDB. Note we consider | |
2361 | all locations at the same address irrespective of type, i.e., | |
2362 | even if the locations aren't considered duplicates (e.g., | |
2363 | software breakpoint and hardware breakpoint at the same | |
2364 | address). */ | |
e0d9a270 | 2365 | for (bp_location *loc : loc_range) |
b775012e | 2366 | { |
b775012e LM |
2367 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
2368 | { | |
2369 | if (modified) | |
2370 | { | |
b775012e LM |
2371 | /* Re-parse the conditions since something changed. In that |
2372 | case we already freed the condition bytecodes (see | |
2373 | force_breakpoint_reinsertion). We just | |
2374 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2375 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2376 | loc->cond.get ()); | |
b775012e LM |
2377 | } |
2378 | ||
2379 | /* If we have a NULL bytecode expression, it means something | |
2380 | went wrong or we have a null condition expression. */ | |
2381 | if (!loc->cond_bytecode) | |
2382 | { | |
2383 | null_condition_or_parse_error = 1; | |
2384 | break; | |
2385 | } | |
2386 | } | |
2387 | } | |
2388 | ||
2389 | /* If any of these happened, it means we will have to evaluate the conditions | |
2390 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2391 | for all the other duplicate locations, thus we free all of them here. | |
2392 | ||
2393 | This is so we have a finer control over which locations' conditions are | |
2394 | being evaluated by GDB or the remote stub. */ | |
2395 | if (null_condition_or_parse_error) | |
2396 | { | |
e0d9a270 | 2397 | for (bp_location *loc : loc_range) |
b775012e | 2398 | { |
b775012e LM |
2399 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
2400 | { | |
2401 | /* Only go as far as the first NULL bytecode is | |
2402 | located. */ | |
2403 | if (!loc->cond_bytecode) | |
2404 | return; | |
2405 | ||
833177a4 | 2406 | loc->cond_bytecode.reset (); |
b775012e LM |
2407 | } |
2408 | } | |
2409 | } | |
2410 | ||
7f32a4d5 PA |
2411 | /* No NULL conditions or failed bytecode generation. Build a |
2412 | condition list for this location's address. If we have software | |
2413 | and hardware locations at the same address, they aren't | |
2414 | considered duplicates, but we still marge all the conditions | |
2415 | anyway, as it's simpler, and doesn't really make a practical | |
2416 | difference. */ | |
e0d9a270 SM |
2417 | for (bp_location *loc : loc_range) |
2418 | if (loc->cond | |
2419 | && is_breakpoint (loc->owner) | |
2420 | && loc->pspace->num == bl->pspace->num | |
2421 | && loc->owner->enable_state == bp_enabled | |
2422 | && loc->enabled | |
2423 | && !loc->disabled_by_cond) | |
2424 | { | |
2425 | /* Add the condition to the vector. This will be used later | |
2426 | to send the conditions to the target. */ | |
2427 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2428 | } | |
b775012e LM |
2429 | |
2430 | return; | |
2431 | } | |
2432 | ||
d3ce09f5 SS |
2433 | /* Parses a command described by string CMD into an agent expression |
2434 | bytecode suitable for evaluation by the bytecode interpreter. | |
2435 | Return NULL if there was any error during parsing. */ | |
2436 | ||
833177a4 | 2437 | static agent_expr_up |
d3ce09f5 SS |
2438 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2439 | { | |
bbc13ae3 KS |
2440 | const char *cmdrest; |
2441 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2442 | struct gdbarch *gdbarch = get_current_arch (); |
2443 | ||
833177a4 | 2444 | if (cmd == NULL) |
d3ce09f5 SS |
2445 | return NULL; |
2446 | ||
2447 | cmdrest = cmd; | |
2448 | ||
2449 | if (*cmdrest == ',') | |
2450 | ++cmdrest; | |
f1735a53 | 2451 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2452 | |
2453 | if (*cmdrest++ != '"') | |
2454 | error (_("No format string following the location")); | |
2455 | ||
2456 | format_start = cmdrest; | |
2457 | ||
8e481c3b | 2458 | format_pieces fpieces (&cmdrest); |
d3ce09f5 SS |
2459 | |
2460 | format_end = cmdrest; | |
2461 | ||
2462 | if (*cmdrest++ != '"') | |
2463 | error (_("Bad format string, non-terminated '\"'.")); | |
2464 | ||
f1735a53 | 2465 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2466 | |
2467 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2468 | error (_("Invalid argument syntax")); | |
2469 | ||
2470 | if (*cmdrest == ',') | |
2471 | cmdrest++; | |
f1735a53 | 2472 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2473 | |
2474 | /* For each argument, make an expression. */ | |
2475 | ||
8e481c3b | 2476 | std::vector<struct expression *> argvec; |
d3ce09f5 SS |
2477 | while (*cmdrest != '\0') |
2478 | { | |
bbc13ae3 | 2479 | const char *cmd1; |
d3ce09f5 SS |
2480 | |
2481 | cmd1 = cmdrest; | |
4d01a485 | 2482 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
8e481c3b | 2483 | argvec.push_back (expr.release ()); |
d3ce09f5 SS |
2484 | cmdrest = cmd1; |
2485 | if (*cmdrest == ',') | |
2486 | ++cmdrest; | |
2487 | } | |
2488 | ||
833177a4 PA |
2489 | agent_expr_up aexpr; |
2490 | ||
d3ce09f5 SS |
2491 | /* We don't want to stop processing, so catch any errors |
2492 | that may show up. */ | |
a70b8144 | 2493 | try |
d3ce09f5 | 2494 | { |
036e657b JB |
2495 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2496 | format_start, format_end - format_start, | |
8e481c3b | 2497 | argvec.size (), argvec.data ()); |
d3ce09f5 | 2498 | } |
230d2906 | 2499 | catch (const gdb_exception_error &ex) |
d3ce09f5 SS |
2500 | { |
2501 | /* If we got here, it means the command could not be parsed to a valid | |
2502 | bytecode expression and thus can't be evaluated on the target's side. | |
2503 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2504 | } |
492d29ea | 2505 | |
d3ce09f5 SS |
2506 | /* We have a valid agent expression, return it. */ |
2507 | return aexpr; | |
2508 | } | |
2509 | ||
2510 | /* Based on location BL, create a list of breakpoint commands to be | |
2511 | passed on to the target. If we have duplicated locations with | |
2512 | different commands, we will add any such to the list. */ | |
2513 | ||
2514 | static void | |
2515 | build_target_command_list (struct bp_location *bl) | |
2516 | { | |
d3ce09f5 SS |
2517 | int null_command_or_parse_error = 0; |
2518 | int modified = bl->needs_update; | |
d3ce09f5 | 2519 | |
3cde5c42 PA |
2520 | /* Clear commands left over from a previous insert. */ |
2521 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2522 | |
41fac0cf | 2523 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2524 | return; |
2525 | ||
41fac0cf PA |
2526 | /* For now, limit to agent-style dprintf breakpoints. */ |
2527 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2528 | return; |
2529 | ||
e0d9a270 SM |
2530 | auto loc_range = all_bp_locations_at_addr (bl->address); |
2531 | ||
7f32a4d5 PA |
2532 | /* For now, if we have any location at the same address that isn't a |
2533 | dprintf, don't install the target-side commands, as that would | |
2534 | make the breakpoint not be reported to the core, and we'd lose | |
41fac0cf | 2535 | control. */ |
e0d9a270 SM |
2536 | for (bp_location *loc : loc_range) |
2537 | if (is_breakpoint (loc->owner) | |
2538 | && loc->pspace->num == bl->pspace->num | |
2539 | && loc->owner->type != bp_dprintf) | |
2540 | return; | |
41fac0cf | 2541 | |
d3ce09f5 SS |
2542 | /* Do a first pass to check for locations with no assigned |
2543 | conditions or conditions that fail to parse to a valid agent expression | |
2544 | bytecode. If any of these happen, then it's no use to send conditions | |
2545 | to the target since this location will always trigger and generate a | |
2546 | response back to GDB. */ | |
e0d9a270 | 2547 | for (bp_location *loc : loc_range) |
d3ce09f5 | 2548 | { |
d3ce09f5 SS |
2549 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
2550 | { | |
2551 | if (modified) | |
2552 | { | |
d3ce09f5 SS |
2553 | /* Re-parse the commands since something changed. In that |
2554 | case we already freed the command bytecodes (see | |
2555 | force_breakpoint_reinsertion). We just | |
2556 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2557 | loc->cmd_bytecode |
2558 | = parse_cmd_to_aexpr (bl->address, | |
6f781ee3 | 2559 | loc->owner->extra_string.get ()); |
d3ce09f5 SS |
2560 | } |
2561 | ||
2562 | /* If we have a NULL bytecode expression, it means something | |
2563 | went wrong or we have a null command expression. */ | |
2564 | if (!loc->cmd_bytecode) | |
2565 | { | |
2566 | null_command_or_parse_error = 1; | |
2567 | break; | |
2568 | } | |
2569 | } | |
2570 | } | |
2571 | ||
2572 | /* If anything failed, then we're not doing target-side commands, | |
2573 | and so clean up. */ | |
2574 | if (null_command_or_parse_error) | |
2575 | { | |
e0d9a270 SM |
2576 | for (bp_location *loc : loc_range) |
2577 | if (is_breakpoint (loc->owner) | |
2578 | && loc->pspace->num == bl->pspace->num) | |
2579 | { | |
2580 | /* Only go as far as the first NULL bytecode is | |
2581 | located. */ | |
2582 | if (loc->cmd_bytecode == NULL) | |
2583 | return; | |
d3ce09f5 | 2584 | |
e0d9a270 SM |
2585 | loc->cmd_bytecode.reset (); |
2586 | } | |
d3ce09f5 SS |
2587 | } |
2588 | ||
7f32a4d5 PA |
2589 | /* No NULL commands or failed bytecode generation. Build a command |
2590 | list for all duplicate locations at this location's address. | |
2591 | Note that here we must care for whether the breakpoint location | |
2592 | types are considered duplicates, otherwise, say, if we have a | |
2593 | software and hardware location at the same address, the target | |
2594 | could end up running the commands twice. For the moment, we only | |
2595 | support targets-side commands with dprintf, but it doesn't hurt | |
2596 | to be pedantically correct in case that changes. */ | |
e0d9a270 SM |
2597 | for (bp_location *loc : loc_range) |
2598 | if (breakpoint_locations_match (bl, loc) | |
2599 | && loc->owner->extra_string | |
2600 | && is_breakpoint (loc->owner) | |
2601 | && loc->pspace->num == bl->pspace->num | |
2602 | && loc->owner->enable_state == bp_enabled | |
2603 | && loc->enabled | |
2604 | && !loc->disabled_by_cond) | |
2605 | { | |
2606 | /* Add the command to the vector. This will be used later | |
2607 | to send the commands to the target. */ | |
2608 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2609 | } | |
d3ce09f5 SS |
2610 | |
2611 | bl->target_info.persist = 0; | |
2612 | /* Maybe flag this location as persistent. */ | |
2613 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2614 | bl->target_info.persist = 1; | |
2615 | } | |
2616 | ||
833b7ab5 YQ |
2617 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2618 | of breakpoint according to ADDR except single-step breakpoint. | |
2619 | Get the kind of single-step breakpoint according to the current | |
2620 | registers state. */ | |
cd6c3b4f YQ |
2621 | |
2622 | static int | |
2623 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2624 | { | |
833b7ab5 YQ |
2625 | if (bl->owner->type == bp_single_step) |
2626 | { | |
2627 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2628 | struct regcache *regcache; | |
2629 | ||
00431a78 | 2630 | regcache = get_thread_regcache (thr); |
833b7ab5 YQ |
2631 | |
2632 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2633 | regcache, addr); | |
2634 | } | |
2635 | else | |
2636 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2637 | } |
2638 | ||
35df4500 TJB |
2639 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2640 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2641 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2642 | Returns 0 for success, 1 if the bp_location type is not supported or |
2643 | -1 for failure. | |
879bfdc2 | 2644 | |
4a64f543 MS |
2645 | NOTE drow/2003-09-09: This routine could be broken down to an |
2646 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2647 | static int |
35df4500 | 2648 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2649 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2650 | int *disabled_breaks, |
dd61ec5c MW |
2651 | int *hw_breakpoint_error, |
2652 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2653 | { |
cc06b668 | 2654 | gdb_exception bp_excpt; |
879bfdc2 | 2655 | |
b775012e | 2656 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2657 | return 0; |
2658 | ||
35c63cd8 JB |
2659 | /* Note we don't initialize bl->target_info, as that wipes out |
2660 | the breakpoint location's shadow_contents if the breakpoint | |
2661 | is still inserted at that location. This in turn breaks | |
2662 | target_read_memory which depends on these buffers when | |
2663 | a memory read is requested at the breakpoint location: | |
2664 | Once the target_info has been wiped, we fail to see that | |
2665 | we have a breakpoint inserted at that address and thus | |
2666 | read the breakpoint instead of returning the data saved in | |
2667 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2668 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2669 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2670 | bl->target_info.length = bl->length; |
8181d85f | 2671 | |
b775012e LM |
2672 | /* When working with target-side conditions, we must pass all the conditions |
2673 | for the same breakpoint address down to the target since GDB will not | |
2674 | insert those locations. With a list of breakpoint conditions, the target | |
2675 | can decide when to stop and notify GDB. */ | |
2676 | ||
2677 | if (is_breakpoint (bl->owner)) | |
2678 | { | |
2679 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2680 | build_target_command_list (bl); |
2681 | /* Reset the modification marker. */ | |
b775012e LM |
2682 | bl->needs_update = 0; |
2683 | } | |
2684 | ||
7f32a4d5 PA |
2685 | /* If "set breakpoint auto-hw" is "on" and a software breakpoint was |
2686 | set at a read-only address, then a breakpoint location will have | |
2687 | been changed to hardware breakpoint before we get here. If it is | |
2688 | "off" however, error out before actually trying to insert the | |
2689 | breakpoint, with a nicer error message. */ | |
35df4500 | 2690 | if (bl->loc_type == bp_loc_software_breakpoint |
7f32a4d5 | 2691 | && !automatic_hardware_breakpoints) |
879bfdc2 | 2692 | { |
7f32a4d5 | 2693 | mem_region *mr = lookup_mem_region (bl->address); |
cc59ec59 | 2694 | |
7f32a4d5 PA |
2695 | if (mr != nullptr && mr->attrib.mode != MEM_RW) |
2696 | { | |
6cb06a8c TT |
2697 | gdb_printf (tmp_error_stream, |
2698 | _("Cannot insert breakpoint %d.\n" | |
2699 | "Cannot set software breakpoint " | |
2700 | "at read-only address %s\n"), | |
2701 | bl->owner->number, | |
2702 | paddress (bl->gdbarch, bl->address)); | |
7f32a4d5 | 2703 | return 1; |
765dc015 | 2704 | } |
7f32a4d5 PA |
2705 | } |
2706 | ||
2707 | if (bl->loc_type == bp_loc_software_breakpoint | |
2708 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2709 | { | |
879bfdc2 DJ |
2710 | /* First check to see if we have to handle an overlay. */ |
2711 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2712 | || bl->section == NULL |
2713 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2714 | { |
2715 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2716 | try |
dd61ec5c | 2717 | { |
0000e5cc PA |
2718 | int val; |
2719 | ||
c47614fe | 2720 | val = bl->owner->insert_location (bl); |
0000e5cc | 2721 | if (val) |
688fca4f | 2722 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dd61ec5c | 2723 | } |
94aeb44b | 2724 | catch (gdb_exception &e) |
dd61ec5c | 2725 | { |
94aeb44b | 2726 | bp_excpt = std::move (e); |
dd61ec5c | 2727 | } |
879bfdc2 DJ |
2728 | } |
2729 | else | |
2730 | { | |
4a64f543 | 2731 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2732 | Shall we set a breakpoint at the LMA? */ |
2733 | if (!overlay_events_enabled) | |
2734 | { | |
2735 | /* Yes -- overlay event support is not active, | |
2736 | so we must try to set a breakpoint at the LMA. | |
2737 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2738 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2739 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2740 | bl->owner->number); |
879bfdc2 DJ |
2741 | else |
2742 | { | |
35df4500 TJB |
2743 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2744 | bl->section); | |
879bfdc2 | 2745 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2746 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2747 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2748 | |
2749 | /* No overlay handling: just set the breakpoint. */ | |
a70b8144 | 2750 | try |
0000e5cc PA |
2751 | { |
2752 | int val; | |
2753 | ||
579c6ad9 | 2754 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2755 | = breakpoint_kind (bl, &addr); |
2756 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2757 | val = target_insert_breakpoint (bl->gdbarch, |
2758 | &bl->overlay_target_info); | |
2759 | if (val) | |
688fca4f PA |
2760 | bp_excpt |
2761 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; | |
0000e5cc | 2762 | } |
94aeb44b | 2763 | catch (gdb_exception &e) |
0000e5cc | 2764 | { |
94aeb44b | 2765 | bp_excpt = std::move (e); |
0000e5cc PA |
2766 | } |
2767 | ||
688fca4f | 2768 | if (bp_excpt.reason != 0) |
6cb06a8c TT |
2769 | gdb_printf (tmp_error_stream, |
2770 | "Overlay breakpoint %d " | |
2771 | "failed: in ROM?\n", | |
2772 | bl->owner->number); | |
879bfdc2 DJ |
2773 | } |
2774 | } | |
2775 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2776 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2777 | { |
2778 | /* Yes. This overlay section is mapped into memory. */ | |
a70b8144 | 2779 | try |
dda83cd7 | 2780 | { |
0000e5cc PA |
2781 | int val; |
2782 | ||
c47614fe | 2783 | val = bl->owner->insert_location (bl); |
0000e5cc | 2784 | if (val) |
688fca4f | 2785 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
dda83cd7 | 2786 | } |
94aeb44b | 2787 | catch (gdb_exception &e) |
dda83cd7 | 2788 | { |
94aeb44b | 2789 | bp_excpt = std::move (e); |
dda83cd7 | 2790 | } |
879bfdc2 DJ |
2791 | } |
2792 | else | |
2793 | { | |
2794 | /* No. This breakpoint will not be inserted. | |
2795 | No error, but do not mark the bp as 'inserted'. */ | |
2796 | return 0; | |
2797 | } | |
2798 | } | |
2799 | ||
688fca4f | 2800 | if (bp_excpt.reason != 0) |
879bfdc2 DJ |
2801 | { |
2802 | /* Can't set the breakpoint. */ | |
0000e5cc | 2803 | |
80dc83fd AB |
2804 | /* If the target has closed then it will have deleted any |
2805 | breakpoints inserted within the target inferior, as a result | |
2806 | any further attempts to interact with the breakpoint objects | |
2807 | is not possible. Just rethrow the error. */ | |
2808 | if (bp_excpt.error == TARGET_CLOSE_ERROR) | |
2809 | throw bp_excpt; | |
2810 | gdb_assert (bl->owner != nullptr); | |
2811 | ||
0000e5cc PA |
2812 | /* In some cases, we might not be able to insert a |
2813 | breakpoint in a shared library that has already been | |
2814 | removed, but we have not yet processed the shlib unload | |
2815 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2816 | breakpoint insertion themselves can't tell why the |
2817 | breakpoint insertion failed (e.g., the remote target | |
2818 | doesn't define error codes), so we must treat generic | |
2819 | errors as memory errors. */ | |
688fca4f PA |
2820 | if (bp_excpt.reason == RETURN_ERROR |
2821 | && (bp_excpt.error == GENERIC_ERROR | |
2822 | || bp_excpt.error == MEMORY_ERROR) | |
076855f9 | 2823 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2824 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2825 | || shared_objfile_contains_address_p (bl->pspace, |
2826 | bl->address))) | |
879bfdc2 | 2827 | { |
4a64f543 | 2828 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2829 | bl->shlib_disabled = 1; |
76727919 | 2830 | gdb::observers::breakpoint_modified.notify (bl->owner); |
3fbb6ffa TJB |
2831 | if (!*disabled_breaks) |
2832 | { | |
6cb06a8c TT |
2833 | gdb_printf (tmp_error_stream, |
2834 | "Cannot insert breakpoint %d.\n", | |
2835 | bl->owner->number); | |
2836 | gdb_printf (tmp_error_stream, | |
2837 | "Temporarily disabling shared " | |
2838 | "library breakpoints:\n"); | |
3fbb6ffa TJB |
2839 | } |
2840 | *disabled_breaks = 1; | |
6cb06a8c TT |
2841 | gdb_printf (tmp_error_stream, |
2842 | "breakpoint #%d\n", bl->owner->number); | |
0000e5cc | 2843 | return 0; |
879bfdc2 DJ |
2844 | } |
2845 | else | |
879bfdc2 | 2846 | { |
35df4500 | 2847 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2848 | { |
0000e5cc | 2849 | *hw_breakpoint_error = 1; |
688fca4f | 2850 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
6cb06a8c TT |
2851 | gdb_printf (tmp_error_stream, |
2852 | "Cannot insert hardware breakpoint %d%s", | |
2853 | bl->owner->number, | |
2854 | bp_excpt.message ? ":" : ".\n"); | |
dda83cd7 | 2855 | if (bp_excpt.message != NULL) |
6cb06a8c TT |
2856 | gdb_printf (tmp_error_stream, "%s.\n", |
2857 | bp_excpt.what ()); | |
879bfdc2 DJ |
2858 | } |
2859 | else | |
2860 | { | |
688fca4f | 2861 | if (bp_excpt.message == NULL) |
0000e5cc | 2862 | { |
1ccbe998 | 2863 | std::string message |
0000e5cc PA |
2864 | = memory_error_message (TARGET_XFER_E_IO, |
2865 | bl->gdbarch, bl->address); | |
0000e5cc | 2866 | |
6cb06a8c TT |
2867 | gdb_printf (tmp_error_stream, |
2868 | "Cannot insert breakpoint %d.\n" | |
2869 | "%s\n", | |
2870 | bl->owner->number, message.c_str ()); | |
0000e5cc PA |
2871 | } |
2872 | else | |
2873 | { | |
6cb06a8c TT |
2874 | gdb_printf (tmp_error_stream, |
2875 | "Cannot insert breakpoint %d: %s\n", | |
2876 | bl->owner->number, | |
2877 | bp_excpt.what ()); | |
0000e5cc | 2878 | } |
879bfdc2 | 2879 | } |
0000e5cc | 2880 | return 1; |
879bfdc2 DJ |
2881 | |
2882 | } | |
2883 | } | |
2884 | else | |
35df4500 | 2885 | bl->inserted = 1; |
879bfdc2 | 2886 | |
0000e5cc | 2887 | return 0; |
879bfdc2 DJ |
2888 | } |
2889 | ||
35df4500 | 2890 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2891 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2892 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2893 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2894 | { |
0000e5cc PA |
2895 | int val; |
2896 | ||
c47614fe | 2897 | val = bl->owner->insert_location (bl); |
85d721b8 PA |
2898 | |
2899 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2900 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2901 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 | 2902 | { |
85d721b8 PA |
2903 | /* But don't try to insert it, if there's already another |
2904 | hw_access location that would be considered a duplicate | |
2905 | of this one. */ | |
48d7020b | 2906 | for (bp_location *loc : all_bp_locations ()) |
35df4500 | 2907 | if (loc != bl |
85d721b8 | 2908 | && loc->watchpoint_type == hw_access |
35df4500 | 2909 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2910 | { |
35df4500 TJB |
2911 | bl->duplicate = 1; |
2912 | bl->inserted = 1; | |
2913 | bl->target_info = loc->target_info; | |
2914 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2915 | val = 0; |
2916 | break; | |
2917 | } | |
2918 | ||
2919 | if (val == 1) | |
2920 | { | |
77b06cd7 | 2921 | bl->watchpoint_type = hw_access; |
c47614fe | 2922 | val = bl->owner->insert_location (bl); |
77b06cd7 TJB |
2923 | |
2924 | if (val) | |
2925 | /* Back to the original value. */ | |
2926 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2927 | } |
2928 | } | |
2929 | ||
35df4500 | 2930 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2931 | } |
2932 | ||
35df4500 | 2933 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2934 | { |
0000e5cc PA |
2935 | int val; |
2936 | ||
c47614fe | 2937 | val = bl->owner->insert_location (bl); |
77b06cd7 TJB |
2938 | if (val) |
2939 | { | |
2940 | bl->owner->enable_state = bp_disabled; | |
2941 | ||
2942 | if (val == 1) | |
2943 | warning (_("\ | |
2944 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2945 | of catchpoint."), bl->owner->number); | |
2946 | else | |
2947 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2948 | } | |
2949 | ||
2950 | bl->inserted = (val == 0); | |
1640b821 DJ |
2951 | |
2952 | /* We've already printed an error message if there was a problem | |
2953 | inserting this catchpoint, and we've disabled the catchpoint, | |
2954 | so just return success. */ | |
2955 | return 0; | |
879bfdc2 DJ |
2956 | } |
2957 | ||
2958 | return 0; | |
2959 | } | |
2960 | ||
6c95b8df PA |
2961 | /* This function is called when program space PSPACE is about to be |
2962 | deleted. It takes care of updating breakpoints to not reference | |
2963 | PSPACE anymore. */ | |
2964 | ||
2965 | void | |
2966 | breakpoint_program_space_exit (struct program_space *pspace) | |
2967 | { | |
6c95b8df | 2968 | /* Remove any breakpoint that was set through this program space. */ |
1428b37a SM |
2969 | for (breakpoint *b : all_breakpoints_safe ()) |
2970 | if (b->pspace == pspace) | |
2971 | delete_breakpoint (b); | |
6c95b8df PA |
2972 | |
2973 | /* Breakpoints set through other program spaces could have locations | |
2974 | bound to PSPACE as well. Remove those. */ | |
48d7020b | 2975 | for (bp_location *loc : all_bp_locations ()) |
6c95b8df PA |
2976 | { |
2977 | struct bp_location *tmp; | |
2978 | ||
2979 | if (loc->pspace == pspace) | |
2980 | { | |
2bdf28a0 | 2981 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2982 | if (loc->owner->loc == loc) |
2983 | loc->owner->loc = loc->next; | |
2984 | else | |
2985 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2986 | if (tmp->next == loc) | |
2987 | { | |
2988 | tmp->next = loc->next; | |
2989 | break; | |
2990 | } | |
2991 | } | |
2992 | } | |
2993 | ||
2994 | /* Now update the global location list to permanently delete the | |
2995 | removed locations above. */ | |
44702360 | 2996 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2997 | } |
2998 | ||
74960c60 VP |
2999 | /* Make sure all breakpoints are inserted in inferior. |
3000 | Throws exception on any error. | |
3001 | A breakpoint that is already inserted won't be inserted | |
3002 | again, so calling this function twice is safe. */ | |
3003 | void | |
3004 | insert_breakpoints (void) | |
3005 | { | |
43892fdf | 3006 | for (breakpoint *bpt : all_breakpoints ()) |
74960c60 | 3007 | if (is_hardware_watchpoint (bpt)) |
3a5c3e22 PA |
3008 | { |
3009 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3010 | ||
3011 | update_watchpoint (w, 0 /* don't reparse. */); | |
3012 | } | |
74960c60 | 3013 | |
04086b45 PA |
3014 | /* Updating watchpoints creates new locations, so update the global |
3015 | location list. Explicitly tell ugll to insert locations and | |
7f32a4d5 PA |
3016 | ignore breakpoints_always_inserted_mode. Also, |
3017 | update_global_location_list tries to "upgrade" software | |
3018 | breakpoints to hardware breakpoints to handle "set breakpoint | |
3019 | auto-hw", so we need to call it even if we don't have new | |
3020 | locations. */ | |
04086b45 | 3021 | update_global_location_list (UGLL_INSERT); |
74960c60 VP |
3022 | } |
3023 | ||
b775012e LM |
3024 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3025 | target. It is the case with deleting and disabling of breakpoints when using | |
3026 | always-inserted mode. */ | |
3027 | ||
3028 | static void | |
3029 | update_inserted_breakpoint_locations (void) | |
3030 | { | |
b775012e LM |
3031 | int error_flag = 0; |
3032 | int val = 0; | |
3033 | int disabled_breaks = 0; | |
3034 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3035 | int hw_bp_details_reported = 0; |
b775012e | 3036 | |
d7e74731 | 3037 | string_file tmp_error_stream; |
b775012e LM |
3038 | |
3039 | /* Explicitly mark the warning -- this will only be printed if | |
3040 | there was an error. */ | |
d7e74731 | 3041 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 3042 | |
5ed8105e | 3043 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e | 3044 | |
48d7020b | 3045 | for (bp_location *bl : all_bp_locations ()) |
b775012e LM |
3046 | { |
3047 | /* We only want to update software breakpoints and hardware | |
3048 | breakpoints. */ | |
3049 | if (!is_breakpoint (bl->owner)) | |
3050 | continue; | |
3051 | ||
3052 | /* We only want to update locations that are already inserted | |
3053 | and need updating. This is to avoid unwanted insertion during | |
3054 | deletion of breakpoints. */ | |
4daf1902 | 3055 | if (!bl->inserted || !bl->needs_update) |
b775012e LM |
3056 | continue; |
3057 | ||
3058 | switch_to_program_space_and_thread (bl->pspace); | |
3059 | ||
3060 | /* For targets that support global breakpoints, there's no need | |
3061 | to select an inferior to insert breakpoint to. In fact, even | |
3062 | if we aren't attached to any process yet, we should still | |
3063 | insert breakpoints. */ | |
f5656ead | 3064 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
55f6301a | 3065 | && (inferior_ptid == null_ptid || !target_has_execution ())) |
b775012e LM |
3066 | continue; |
3067 | ||
d7e74731 | 3068 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3069 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3070 | if (val) |
3071 | error_flag = val; | |
3072 | } | |
3073 | ||
3074 | if (error_flag) | |
3075 | { | |
223ffa71 | 3076 | target_terminal::ours_for_output (); |
b775012e LM |
3077 | error_stream (tmp_error_stream); |
3078 | } | |
b775012e LM |
3079 | } |
3080 | ||
c30eee59 | 3081 | /* Used when starting or continuing the program. */ |
c906108c | 3082 | |
74960c60 VP |
3083 | static void |
3084 | insert_breakpoint_locations (void) | |
c906108c | 3085 | { |
eacd795a | 3086 | int error_flag = 0; |
c906108c | 3087 | int val = 0; |
3fbb6ffa | 3088 | int disabled_breaks = 0; |
81d0cc19 | 3089 | int hw_breakpoint_error = 0; |
dd61ec5c | 3090 | int hw_bp_error_explained_already = 0; |
c906108c | 3091 | |
d7e74731 PA |
3092 | string_file tmp_error_stream; |
3093 | ||
81d0cc19 GS |
3094 | /* Explicitly mark the warning -- this will only be printed if |
3095 | there was an error. */ | |
d7e74731 | 3096 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3097 | |
5ed8105e | 3098 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3099 | |
48d7020b | 3100 | for (bp_location *bl : all_bp_locations ()) |
879bfdc2 | 3101 | { |
b775012e | 3102 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3103 | continue; |
3104 | ||
4a64f543 MS |
3105 | /* There is no point inserting thread-specific breakpoints if |
3106 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3107 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3108 | if (bl->owner->thread != -1 |
5d5658a1 | 3109 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3110 | continue; |
3111 | ||
35df4500 | 3112 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3113 | |
3114 | /* For targets that support global breakpoints, there's no need | |
3115 | to select an inferior to insert breakpoint to. In fact, even | |
3116 | if we aren't attached to any process yet, we should still | |
3117 | insert breakpoints. */ | |
f5656ead | 3118 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
55f6301a | 3119 | && (inferior_ptid == null_ptid || !target_has_execution ())) |
6c95b8df PA |
3120 | continue; |
3121 | ||
d7e74731 | 3122 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3123 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3124 | if (val) |
eacd795a | 3125 | error_flag = val; |
879bfdc2 | 3126 | } |
c906108c | 3127 | |
4a64f543 MS |
3128 | /* If we failed to insert all locations of a watchpoint, remove |
3129 | them, as half-inserted watchpoint is of limited use. */ | |
43892fdf | 3130 | for (breakpoint *bpt : all_breakpoints ()) |
a5606eee VP |
3131 | { |
3132 | int some_failed = 0; | |
a5606eee VP |
3133 | |
3134 | if (!is_hardware_watchpoint (bpt)) | |
3135 | continue; | |
3136 | ||
d6b74ac4 | 3137 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3138 | continue; |
74960c60 VP |
3139 | |
3140 | if (bpt->disposition == disp_del_at_next_stop) | |
3141 | continue; | |
a5606eee | 3142 | |
40cb8ca5 | 3143 | for (bp_location *loc : bpt->locations ()) |
56710373 | 3144 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3145 | { |
3146 | some_failed = 1; | |
3147 | break; | |
3148 | } | |
40cb8ca5 | 3149 | |
a5606eee VP |
3150 | if (some_failed) |
3151 | { | |
40cb8ca5 | 3152 | for (bp_location *loc : bpt->locations ()) |
a5606eee | 3153 | if (loc->inserted) |
834c0d03 | 3154 | remove_breakpoint (loc); |
a5606eee VP |
3155 | |
3156 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3157 | tmp_error_stream.printf ("Could not insert " |
3158 | "hardware watchpoint %d.\n", | |
3159 | bpt->number); | |
eacd795a | 3160 | error_flag = -1; |
a5606eee VP |
3161 | } |
3162 | } | |
3163 | ||
eacd795a | 3164 | if (error_flag) |
81d0cc19 GS |
3165 | { |
3166 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
dda83cd7 | 3167 | message about possibly exhausted resources. */ |
dd61ec5c | 3168 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3169 | { |
d7e74731 | 3170 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3171 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3172 | } |
223ffa71 | 3173 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3174 | error_stream (tmp_error_stream); |
3175 | } | |
c906108c SS |
3176 | } |
3177 | ||
c30eee59 TJB |
3178 | /* Used when the program stops. |
3179 | Returns zero if successful, or non-zero if there was a problem | |
3180 | removing a breakpoint location. */ | |
3181 | ||
c906108c | 3182 | int |
fba45db2 | 3183 | remove_breakpoints (void) |
c906108c | 3184 | { |
3a1bae8e | 3185 | int val = 0; |
c906108c | 3186 | |
48d7020b | 3187 | for (bp_location *bl : all_bp_locations ()) |
1e4d1764 | 3188 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3189 | val |= remove_breakpoint (bl); |
01add95b | 3190 | |
3a1bae8e | 3191 | return val; |
c906108c SS |
3192 | } |
3193 | ||
49fa26b0 PA |
3194 | /* When a thread exits, remove breakpoints that are related to |
3195 | that thread. */ | |
3196 | ||
3197 | static void | |
3198 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3199 | { | |
1428b37a | 3200 | for (breakpoint *b : all_breakpoints_safe ()) |
49fa26b0 | 3201 | { |
5d5658a1 | 3202 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3203 | { |
3204 | b->disposition = disp_del_at_next_stop; | |
3205 | ||
6cb06a8c | 3206 | gdb_printf (_("\ |
43792cf0 | 3207 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
6cb06a8c | 3208 | b->number, print_thread_id (tp)); |
49fa26b0 PA |
3209 | |
3210 | /* Hide it from the user. */ | |
3211 | b->number = 0; | |
3212 | } | |
3213 | } | |
3214 | } | |
3215 | ||
f3869b1a | 3216 | /* See breakpoint.h. */ |
6c95b8df | 3217 | |
f3869b1a | 3218 | void |
00431a78 | 3219 | remove_breakpoints_inf (inferior *inf) |
6c95b8df | 3220 | { |
6c95b8df | 3221 | int val; |
6c95b8df | 3222 | |
48d7020b | 3223 | for (bp_location *bl : all_bp_locations ()) |
01add95b SM |
3224 | { |
3225 | if (bl->pspace != inf->pspace) | |
3226 | continue; | |
6c95b8df | 3227 | |
01add95b SM |
3228 | if (bl->inserted && !bl->target_info.persist) |
3229 | { | |
3230 | val = remove_breakpoint (bl); | |
3231 | if (val != 0) | |
3232 | return; | |
3233 | } | |
3234 | } | |
6c95b8df PA |
3235 | } |
3236 | ||
e58b0e63 PA |
3237 | static int internal_breakpoint_number = -1; |
3238 | ||
84f4c1fe PM |
3239 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3240 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3241 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3242 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3243 | breakpoint_count and that value incremented. Internal breakpoints |
3244 | do not set the internal var bpnum. */ | |
3245 | static void | |
3246 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3247 | { | |
3248 | if (internal) | |
3249 | b->number = internal_breakpoint_number--; | |
3250 | else | |
3251 | { | |
3252 | set_breakpoint_count (breakpoint_count + 1); | |
3253 | b->number = breakpoint_count; | |
3254 | } | |
3255 | } | |
3256 | ||
e62c965a | 3257 | static struct breakpoint * |
a6d9a66e | 3258 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3259 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3260 | const struct breakpoint_ops *ops) |
e62c965a | 3261 | { |
51abb421 | 3262 | symtab_and_line sal; |
e62c965a PP |
3263 | sal.pc = address; |
3264 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3265 | sal.pspace = current_program_space; |
e62c965a | 3266 | |
51abb421 | 3267 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3268 | b->number = internal_breakpoint_number--; |
3269 | b->disposition = disp_donttouch; | |
3270 | ||
3271 | return b; | |
3272 | } | |
3273 | ||
17450429 PP |
3274 | static const char *const longjmp_names[] = |
3275 | { | |
3276 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3277 | }; | |
3278 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3279 | ||
3280 | /* Per-objfile data private to breakpoint.c. */ | |
3281 | struct breakpoint_objfile_data | |
3282 | { | |
3283 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
f6b3ad54 | 3284 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3285 | |
3286 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
f6b3ad54 | 3287 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3288 | |
28106bc2 | 3289 | /* True if we have looked for longjmp probes. */ |
43dce439 | 3290 | int longjmp_searched = 0; |
28106bc2 | 3291 | |
45461e0d SM |
3292 | /* SystemTap probe points for longjmp (if any). These are non-owning |
3293 | references. */ | |
3294 | std::vector<probe *> longjmp_probes; | |
28106bc2 | 3295 | |
17450429 | 3296 | /* Minimal symbol for "std::terminate()" (if any). */ |
f6b3ad54 | 3297 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3298 | |
3299 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
f6b3ad54 | 3300 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3301 | |
3302 | /* True if we have looked for exception probes. */ | |
43dce439 | 3303 | int exception_searched = 0; |
28106bc2 | 3304 | |
45461e0d SM |
3305 | /* SystemTap probe points for unwinding (if any). These are non-owning |
3306 | references. */ | |
3307 | std::vector<probe *> exception_probes; | |
17450429 PP |
3308 | }; |
3309 | ||
51d3063a TT |
3310 | static const struct objfile_key<breakpoint_objfile_data> |
3311 | breakpoint_objfile_key; | |
17450429 PP |
3312 | |
3313 | /* Minimal symbol not found sentinel. */ | |
3314 | static struct minimal_symbol msym_not_found; | |
3315 | ||
3316 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3317 | ||
3318 | static int | |
3319 | msym_not_found_p (const struct minimal_symbol *msym) | |
3320 | { | |
3321 | return msym == &msym_not_found; | |
3322 | } | |
3323 | ||
3324 | /* Return per-objfile data needed by breakpoint.c. | |
3325 | Allocate the data if necessary. */ | |
3326 | ||
3327 | static struct breakpoint_objfile_data * | |
3328 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3329 | { | |
3330 | struct breakpoint_objfile_data *bp_objfile_data; | |
3331 | ||
51d3063a | 3332 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
17450429 | 3333 | if (bp_objfile_data == NULL) |
51d3063a | 3334 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
17450429 PP |
3335 | return bp_objfile_data; |
3336 | } | |
3337 | ||
e62c965a | 3338 | static void |
af02033e | 3339 | create_overlay_event_breakpoint (void) |
e62c965a | 3340 | { |
af02033e | 3341 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3342 | |
2030c079 | 3343 | for (objfile *objfile : current_program_space->objfiles ()) |
69de3c6a PP |
3344 | { |
3345 | struct breakpoint *b; | |
17450429 PP |
3346 | struct breakpoint_objfile_data *bp_objfile_data; |
3347 | CORE_ADDR addr; | |
67994074 | 3348 | struct explicit_location explicit_loc; |
69de3c6a | 3349 | |
17450429 PP |
3350 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3351 | ||
3b7344d5 | 3352 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3353 | continue; |
3354 | ||
3b7344d5 | 3355 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3356 | { |
3b7344d5 | 3357 | struct bound_minimal_symbol m; |
17450429 PP |
3358 | |
3359 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3360 | if (m.minsym == NULL) |
17450429 PP |
3361 | { |
3362 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3363 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3364 | continue; |
3365 | } | |
3366 | bp_objfile_data->overlay_msym = m; | |
3367 | } | |
e62c965a | 3368 | |
4aeddc50 | 3369 | addr = bp_objfile_data->overlay_msym.value_address (); |
08feed99 | 3370 | b = create_internal_breakpoint (objfile->arch (), addr, |
dda83cd7 | 3371 | bp_overlay_event, |
a0cd5f08 | 3372 | &base_breakpoint_ops); |
67994074 KS |
3373 | initialize_explicit_location (&explicit_loc); |
3374 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3375 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3376 | |
69de3c6a | 3377 | if (overlay_debugging == ovly_auto) |
dda83cd7 SM |
3378 | { |
3379 | b->enable_state = bp_enabled; | |
3380 | overlay_events_enabled = 1; | |
3381 | } | |
69de3c6a PP |
3382 | else |
3383 | { | |
dda83cd7 SM |
3384 | b->enable_state = bp_disabled; |
3385 | overlay_events_enabled = 0; | |
69de3c6a | 3386 | } |
e62c965a | 3387 | } |
e62c965a PP |
3388 | } |
3389 | ||
2a7f6487 TV |
3390 | /* Install a master longjmp breakpoint for OBJFILE using a probe. Return |
3391 | true if a breakpoint was installed. */ | |
3392 | ||
3393 | static bool | |
3394 | create_longjmp_master_breakpoint_probe (objfile *objfile) | |
0fd8e87f | 3395 | { |
2a7f6487 TV |
3396 | struct gdbarch *gdbarch = objfile->arch (); |
3397 | struct breakpoint_objfile_data *bp_objfile_data | |
3398 | = get_breakpoint_objfile_data (objfile); | |
0fd8e87f | 3399 | |
2a7f6487 | 3400 | if (!bp_objfile_data->longjmp_searched) |
94c93c35 | 3401 | { |
2a7f6487 TV |
3402 | std::vector<probe *> ret |
3403 | = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
af02033e | 3404 | |
2a7f6487 | 3405 | if (!ret.empty ()) |
94c93c35 | 3406 | { |
2a7f6487 TV |
3407 | /* We are only interested in checking one element. */ |
3408 | probe *p = ret[0]; | |
0fd8e87f | 3409 | |
2a7f6487 TV |
3410 | if (!p->can_evaluate_arguments ()) |
3411 | { | |
3412 | /* We cannot use the probe interface here, | |
3413 | because it does not know how to evaluate | |
3414 | arguments. */ | |
3415 | ret.clear (); | |
3416 | } | |
3417 | } | |
3418 | bp_objfile_data->longjmp_probes = ret; | |
3419 | bp_objfile_data->longjmp_searched = 1; | |
3420 | } | |
0fd8e87f | 3421 | |
2a7f6487 TV |
3422 | if (bp_objfile_data->longjmp_probes.empty ()) |
3423 | return false; | |
17450429 | 3424 | |
2a7f6487 TV |
3425 | for (probe *p : bp_objfile_data->longjmp_probes) |
3426 | { | |
3427 | struct breakpoint *b; | |
25f9533e | 3428 | |
2a7f6487 TV |
3429 | b = create_internal_breakpoint (gdbarch, |
3430 | p->get_relocated_address (objfile), | |
3431 | bp_longjmp_master, | |
a0cd5f08 | 3432 | &base_breakpoint_ops); |
2a7f6487 TV |
3433 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
3434 | b->enable_state = bp_disabled; | |
3435 | } | |
aed57c53 | 3436 | |
2a7f6487 TV |
3437 | return true; |
3438 | } | |
25f9533e | 3439 | |
2a7f6487 TV |
3440 | /* Install master longjmp breakpoints for OBJFILE using longjmp_names. |
3441 | Return true if at least one breakpoint was installed. */ | |
3442 | ||
3443 | static bool | |
3444 | create_longjmp_master_breakpoint_names (objfile *objfile) | |
3445 | { | |
3446 | struct gdbarch *gdbarch = objfile->arch (); | |
3447 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
3448 | return false; | |
3449 | ||
3450 | struct breakpoint_objfile_data *bp_objfile_data | |
3451 | = get_breakpoint_objfile_data (objfile); | |
3452 | unsigned int installed_bp = 0; | |
3453 | ||
3454 | for (int i = 0; i < NUM_LONGJMP_NAMES; i++) | |
3455 | { | |
3456 | struct breakpoint *b; | |
3457 | const char *func_name; | |
3458 | CORE_ADDR addr; | |
3459 | struct explicit_location explicit_loc; | |
3460 | ||
3461 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) | |
3462 | continue; | |
28106bc2 | 3463 | |
2a7f6487 TV |
3464 | func_name = longjmp_names[i]; |
3465 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) | |
3466 | { | |
3467 | struct bound_minimal_symbol m; | |
3468 | ||
3469 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3470 | if (m.minsym == NULL) | |
3471 | { | |
3472 | /* Prevent future lookups in this objfile. */ | |
3473 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; | |
94c93c35 TT |
3474 | continue; |
3475 | } | |
2a7f6487 TV |
3476 | bp_objfile_data->longjmp_msym[i] = m; |
3477 | } | |
28106bc2 | 3478 | |
4aeddc50 | 3479 | addr = bp_objfile_data->longjmp_msym[i].value_address (); |
2a7f6487 | 3480 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
a0cd5f08 | 3481 | &base_breakpoint_ops); |
2a7f6487 TV |
3482 | initialize_explicit_location (&explicit_loc); |
3483 | explicit_loc.function_name = ASTRDUP (func_name); | |
3484 | b->location = new_explicit_location (&explicit_loc); | |
3485 | b->enable_state = bp_disabled; | |
3486 | installed_bp++; | |
3487 | } | |
28106bc2 | 3488 | |
2a7f6487 TV |
3489 | return installed_bp > 0; |
3490 | } | |
0fd8e87f | 3491 | |
2a7f6487 | 3492 | /* Create a master longjmp breakpoint. */ |
17450429 | 3493 | |
2a7f6487 TV |
3494 | static void |
3495 | create_longjmp_master_breakpoint (void) | |
3496 | { | |
3497 | scoped_restore_current_program_space restore_pspace; | |
aed57c53 | 3498 | |
2a7f6487 TV |
3499 | for (struct program_space *pspace : program_spaces) |
3500 | { | |
3501 | set_current_program_space (pspace); | |
17450429 | 3502 | |
2a7f6487 TV |
3503 | for (objfile *obj : current_program_space->objfiles ()) |
3504 | { | |
3505 | /* Skip separate debug object, it's handled in the loop below. */ | |
3506 | if (obj->separate_debug_objfile_backlink != nullptr) | |
3507 | continue; | |
3508 | ||
3509 | /* Try a probe kind breakpoint on main objfile. */ | |
3510 | if (create_longjmp_master_breakpoint_probe (obj)) | |
3511 | continue; | |
3512 | ||
3513 | /* Try longjmp_names kind breakpoints on main and separate_debug | |
3514 | objfiles. */ | |
3515 | for (objfile *debug_objfile : obj->separate_debug_objfiles ()) | |
3516 | if (create_longjmp_master_breakpoint_names (debug_objfile)) | |
3517 | break; | |
94c93c35 TT |
3518 | } |
3519 | } | |
0fd8e87f UW |
3520 | } |
3521 | ||
af02033e | 3522 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3523 | static void |
af02033e | 3524 | create_std_terminate_master_breakpoint (void) |
aa7d318d | 3525 | { |
af02033e | 3526 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3527 | |
5ed8105e | 3528 | scoped_restore_current_program_space restore_pspace; |
aa7d318d | 3529 | |
94c93c35 TT |
3530 | for (struct program_space *pspace : program_spaces) |
3531 | { | |
3532 | CORE_ADDR addr; | |
17450429 | 3533 | |
94c93c35 | 3534 | set_current_program_space (pspace); |
17450429 | 3535 | |
94c93c35 TT |
3536 | for (objfile *objfile : current_program_space->objfiles ()) |
3537 | { | |
3538 | struct breakpoint *b; | |
3539 | struct breakpoint_objfile_data *bp_objfile_data; | |
3540 | struct explicit_location explicit_loc; | |
aa7d318d | 3541 | |
94c93c35 | 3542 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3543 | |
94c93c35 TT |
3544 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
3545 | continue; | |
17450429 | 3546 | |
94c93c35 TT |
3547 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
3548 | { | |
3549 | struct bound_minimal_symbol m; | |
17450429 | 3550 | |
94c93c35 | 3551 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
60f62e2b SM |
3552 | if (m.minsym == NULL || (m.minsym->type () != mst_text |
3553 | && m.minsym->type () != mst_file_text)) | |
94c93c35 TT |
3554 | { |
3555 | /* Prevent future lookups in this objfile. */ | |
3556 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; | |
3557 | continue; | |
3558 | } | |
3559 | bp_objfile_data->terminate_msym = m; | |
3560 | } | |
aa7d318d | 3561 | |
4aeddc50 | 3562 | addr = bp_objfile_data->terminate_msym.value_address (); |
94c93c35 TT |
3563 | b = create_internal_breakpoint (objfile->arch (), addr, |
3564 | bp_std_terminate_master, | |
a0cd5f08 | 3565 | &base_breakpoint_ops); |
94c93c35 TT |
3566 | initialize_explicit_location (&explicit_loc); |
3567 | explicit_loc.function_name = ASTRDUP (func_name); | |
3568 | b->location = new_explicit_location (&explicit_loc); | |
3569 | b->enable_state = bp_disabled; | |
3570 | } | |
3571 | } | |
aa7d318d TT |
3572 | } |
3573 | ||
1940319c TV |
3574 | /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using a |
3575 | probe. Return true if a breakpoint was installed. */ | |
186c406b | 3576 | |
1940319c TV |
3577 | static bool |
3578 | create_exception_master_breakpoint_probe (objfile *objfile) | |
186c406b | 3579 | { |
1940319c TV |
3580 | struct breakpoint *b; |
3581 | struct gdbarch *gdbarch; | |
3582 | struct breakpoint_objfile_data *bp_objfile_data; | |
186c406b | 3583 | |
1940319c | 3584 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
17450429 | 3585 | |
1940319c TV |
3586 | /* We prefer the SystemTap probe point if it exists. */ |
3587 | if (!bp_objfile_data->exception_searched) | |
3588 | { | |
3589 | std::vector<probe *> ret | |
3590 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
17450429 | 3591 | |
1940319c | 3592 | if (!ret.empty ()) |
28106bc2 | 3593 | { |
1940319c TV |
3594 | /* We are only interested in checking one element. */ |
3595 | probe *p = ret[0]; | |
25f9533e | 3596 | |
1940319c | 3597 | if (!p->can_evaluate_arguments ()) |
25f9533e | 3598 | { |
1940319c TV |
3599 | /* We cannot use the probe interface here, because it does |
3600 | not know how to evaluate arguments. */ | |
3601 | ret.clear (); | |
25f9533e | 3602 | } |
28106bc2 | 3603 | } |
1940319c TV |
3604 | bp_objfile_data->exception_probes = ret; |
3605 | bp_objfile_data->exception_searched = 1; | |
3606 | } | |
28106bc2 | 3607 | |
1940319c TV |
3608 | if (bp_objfile_data->exception_probes.empty ()) |
3609 | return false; | |
45461e0d | 3610 | |
1940319c | 3611 | gdbarch = objfile->arch (); |
28106bc2 | 3612 | |
1940319c TV |
3613 | for (probe *p : bp_objfile_data->exception_probes) |
3614 | { | |
3615 | b = create_internal_breakpoint (gdbarch, | |
3616 | p->get_relocated_address (objfile), | |
3617 | bp_exception_master, | |
a0cd5f08 | 3618 | &base_breakpoint_ops); |
1940319c TV |
3619 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
3620 | b->enable_state = bp_disabled; | |
3621 | } | |
28106bc2 | 3622 | |
1940319c TV |
3623 | return true; |
3624 | } | |
28106bc2 | 3625 | |
1940319c TV |
3626 | /* Install a master breakpoint on the unwinder's debug hook for OBJFILE using |
3627 | _Unwind_DebugHook. Return true if a breakpoint was installed. */ | |
17450429 | 3628 | |
1940319c TV |
3629 | static bool |
3630 | create_exception_master_breakpoint_hook (objfile *objfile) | |
3631 | { | |
3632 | const char *const func_name = "_Unwind_DebugHook"; | |
3633 | struct breakpoint *b; | |
3634 | struct gdbarch *gdbarch; | |
3635 | struct breakpoint_objfile_data *bp_objfile_data; | |
3636 | CORE_ADDR addr; | |
3637 | struct explicit_location explicit_loc; | |
186c406b | 3638 | |
1940319c | 3639 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
186c406b | 3640 | |
1940319c TV |
3641 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
3642 | return false; | |
17450429 | 3643 | |
1940319c TV |
3644 | gdbarch = objfile->arch (); |
3645 | ||
3646 | if (bp_objfile_data->exception_msym.minsym == NULL) | |
3647 | { | |
3648 | struct bound_minimal_symbol debug_hook; | |
3649 | ||
3650 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); | |
3651 | if (debug_hook.minsym == NULL) | |
3652 | { | |
3653 | bp_objfile_data->exception_msym.minsym = &msym_not_found; | |
3654 | return false; | |
186c406b | 3655 | } |
17450429 | 3656 | |
1940319c TV |
3657 | bp_objfile_data->exception_msym = debug_hook; |
3658 | } | |
3659 | ||
4aeddc50 | 3660 | addr = bp_objfile_data->exception_msym.value_address (); |
328d42d8 SM |
3661 | addr = gdbarch_convert_from_func_ptr_addr |
3662 | (gdbarch, addr, current_inferior ()->top_target ()); | |
1940319c | 3663 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
a0cd5f08 | 3664 | &base_breakpoint_ops); |
1940319c TV |
3665 | initialize_explicit_location (&explicit_loc); |
3666 | explicit_loc.function_name = ASTRDUP (func_name); | |
3667 | b->location = new_explicit_location (&explicit_loc); | |
3668 | b->enable_state = bp_disabled; | |
3669 | ||
3670 | return true; | |
3671 | } | |
3672 | ||
3673 | /* Install a master breakpoint on the unwinder's debug hook. */ | |
3674 | ||
3675 | static void | |
3676 | create_exception_master_breakpoint (void) | |
3677 | { | |
3678 | for (objfile *obj : current_program_space->objfiles ()) | |
3679 | { | |
3680 | /* Skip separate debug object. */ | |
3681 | if (obj->separate_debug_objfile_backlink) | |
3682 | continue; | |
3683 | ||
3684 | /* Try a probe kind breakpoint. */ | |
3685 | if (create_exception_master_breakpoint_probe (obj)) | |
3686 | continue; | |
3687 | ||
7c6944ab TV |
3688 | /* Iterate over main and separate debug objects and try an |
3689 | _Unwind_DebugHook kind breakpoint. */ | |
3690 | for (objfile *debug_objfile : obj->separate_debug_objfiles ()) | |
3691 | if (create_exception_master_breakpoint_hook (debug_objfile)) | |
1940319c | 3692 | break; |
186c406b | 3693 | } |
186c406b TT |
3694 | } |
3695 | ||
9ef9e6a6 KS |
3696 | /* Does B have a location spec? */ |
3697 | ||
3698 | static int | |
3699 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3700 | { | |
d28cd78a | 3701 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3702 | } |
3703 | ||
c906108c | 3704 | void |
fba45db2 | 3705 | update_breakpoints_after_exec (void) |
c906108c | 3706 | { |
25b22b0a PA |
3707 | /* We're about to delete breakpoints from GDB's lists. If the |
3708 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3709 | writing the breakpoints' "shadow contents" back into memory. The | |
3710 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3711 | do that. Instead, the target is responsible from marking | |
3712 | breakpoints out as soon as it detects an exec. We don't do that | |
3713 | here instead, because there may be other attempts to delete | |
3714 | breakpoints after detecting an exec and before reaching here. */ | |
48d7020b | 3715 | for (bp_location *bploc : all_bp_locations ()) |
6c95b8df PA |
3716 | if (bploc->pspace == current_program_space) |
3717 | gdb_assert (!bploc->inserted); | |
c906108c | 3718 | |
1428b37a | 3719 | for (breakpoint *b : all_breakpoints_safe ()) |
01add95b SM |
3720 | { |
3721 | if (b->pspace != current_program_space) | |
c5aa993b | 3722 | continue; |
c906108c | 3723 | |
01add95b SM |
3724 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
3725 | if (b->type == bp_shlib_event) | |
3726 | { | |
3727 | delete_breakpoint (b); | |
3728 | continue; | |
3729 | } | |
4efc6507 | 3730 | |
01add95b SM |
3731 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
3732 | if (b->type == bp_jit_event) | |
3733 | { | |
3734 | delete_breakpoint (b); | |
3735 | continue; | |
3736 | } | |
c4093a6a | 3737 | |
01add95b SM |
3738 | /* Thread event breakpoints must be set anew after an exec(), |
3739 | as must overlay event and longjmp master breakpoints. */ | |
3740 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
3741 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master | |
3742 | || b->type == bp_exception_master) | |
3743 | { | |
3744 | delete_breakpoint (b); | |
3745 | continue; | |
3746 | } | |
c5aa993b | 3747 | |
01add95b SM |
3748 | /* Step-resume breakpoints are meaningless after an exec(). */ |
3749 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) | |
3750 | { | |
3751 | delete_breakpoint (b); | |
3752 | continue; | |
3753 | } | |
7c16b83e | 3754 | |
01add95b SM |
3755 | /* Just like single-step breakpoints. */ |
3756 | if (b->type == bp_single_step) | |
3757 | { | |
3758 | delete_breakpoint (b); | |
3759 | continue; | |
3760 | } | |
611c83ae | 3761 | |
01add95b SM |
3762 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3763 | after an exec. */ | |
3764 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume | |
3765 | || b->type == bp_longjmp_call_dummy | |
3766 | || b->type == bp_exception || b->type == bp_exception_resume) | |
3767 | { | |
3768 | delete_breakpoint (b); | |
3769 | continue; | |
3770 | } | |
ce78b96d | 3771 | |
01add95b SM |
3772 | if (b->type == bp_catchpoint) |
3773 | { | |
3774 | /* For now, none of the bp_catchpoint breakpoints need to | |
3775 | do anything at this point. In the future, if some of | |
3776 | the catchpoints need to something, we will need to add | |
3777 | a new method, and call this method from here. */ | |
3778 | continue; | |
3779 | } | |
c5aa993b | 3780 | |
01add95b SM |
3781 | /* bp_finish is a special case. The only way we ought to be able |
3782 | to see one of these when an exec() has happened, is if the user | |
3783 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3784 | carries them to the call-site of the current callee, by setting | |
3785 | a temporary bp there and resuming. But in this case, the finish | |
3786 | will carry them entirely through the vfork & exec. | |
3787 | ||
3788 | We don't want to allow a bp_finish to remain inserted now. But | |
3789 | we can't safely delete it, 'cause finish_command has a handle to | |
3790 | the bp on a bpstat, and will later want to delete it. There's a | |
3791 | chance (and I've seen it happen) that if we delete the bp_finish | |
3792 | here, that its storage will get reused by the time finish_command | |
3793 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3794 | We really must allow finish_command to delete a bp_finish. | |
3795 | ||
3796 | In the absence of a general solution for the "how do we know | |
3797 | it's safe to delete something others may have handles to?" | |
3798 | problem, what we'll do here is just uninsert the bp_finish, and | |
3799 | let finish_command delete it. | |
3800 | ||
3801 | (We know the bp_finish is "doomed" in the sense that it's | |
3802 | momentary, and will be deleted as soon as finish_command sees | |
3803 | the inferior stopped. So it doesn't matter that the bp's | |
3804 | address is probably bogus in the new a.out, unlike e.g., the | |
3805 | solib breakpoints.) */ | |
3806 | ||
3807 | if (b->type == bp_finish) | |
3808 | { | |
3809 | continue; | |
3810 | } | |
3811 | ||
3812 | /* Without a symbolic address, we have little hope of the | |
3813 | pre-exec() address meaning the same thing in the post-exec() | |
3814 | a.out. */ | |
3815 | if (breakpoint_event_location_empty_p (b)) | |
3816 | { | |
3817 | delete_breakpoint (b); | |
3818 | continue; | |
3819 | } | |
3820 | } | |
c906108c SS |
3821 | } |
3822 | ||
3823 | int | |
d80ee84f | 3824 | detach_breakpoints (ptid_t ptid) |
c906108c | 3825 | { |
3a1bae8e | 3826 | int val = 0; |
2989a365 | 3827 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3828 | struct inferior *inf = current_inferior (); |
c5aa993b | 3829 | |
e99b03dc | 3830 | if (ptid.pid () == inferior_ptid.pid ()) |
8a3fe4f8 | 3831 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3832 | |
6c95b8df | 3833 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3834 | inferior_ptid = ptid; |
48d7020b | 3835 | for (bp_location *bl : all_bp_locations ()) |
01add95b SM |
3836 | { |
3837 | if (bl->pspace != inf->pspace) | |
3838 | continue; | |
3839 | ||
3840 | /* This function must physically remove breakpoints locations | |
3841 | from the specified ptid, without modifying the breakpoint | |
3842 | package's state. Locations of type bp_loc_other are only | |
3843 | maintained at GDB side. So, there is no need to remove | |
3844 | these bp_loc_other locations. Moreover, removing these | |
3845 | would modify the breakpoint package's state. */ | |
3846 | if (bl->loc_type == bp_loc_other) | |
3847 | continue; | |
3848 | ||
3849 | if (bl->inserted) | |
3850 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); | |
3851 | } | |
d03285ec | 3852 | |
3a1bae8e | 3853 | return val; |
c906108c SS |
3854 | } |
3855 | ||
35df4500 | 3856 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3857 | Note that this is used to detach breakpoints from a child fork. |
3858 | When we get here, the child isn't in the inferior list, and neither | |
3859 | do we have objects to represent its address space --- we should | |
35df4500 | 3860 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3861 | |
c906108c | 3862 | static int |
b2b6a7da | 3863 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3864 | { |
3865 | int val; | |
c5aa993b | 3866 | |
35df4500 TJB |
3867 | /* BL is never in moribund_locations by our callers. */ |
3868 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3869 | |
74960c60 VP |
3870 | /* The type of none suggests that owner is actually deleted. |
3871 | This should not ever happen. */ | |
35df4500 | 3872 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3873 | |
35df4500 TJB |
3874 | if (bl->loc_type == bp_loc_software_breakpoint |
3875 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3876 | { |
c02f5703 MS |
3877 | /* "Normal" instruction breakpoint: either the standard |
3878 | trap-instruction bp (bp_breakpoint), or a | |
3879 | bp_hardware_breakpoint. */ | |
3880 | ||
3881 | /* First check to see if we have to handle an overlay. */ | |
3882 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3883 | || bl->section == NULL |
3884 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3885 | { |
3886 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3887 | |
3888 | /* If we're trying to uninsert a memory breakpoint that we | |
3889 | know is set in a dynamic object that is marked | |
3890 | shlib_disabled, then either the dynamic object was | |
3891 | removed with "remove-symbol-file" or with | |
3892 | "nosharedlibrary". In the former case, we don't know | |
3893 | whether another dynamic object might have loaded over the | |
3894 | breakpoint's address -- the user might well let us know | |
3895 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3896 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3897 | list of dynamically loaded objects). If we have the |
3898 | breakpoint's shadow memory, that is, this is a software | |
3899 | breakpoint managed by GDB, check whether the breakpoint | |
3900 | is still inserted in memory, to avoid overwriting wrong | |
3901 | code with stale saved shadow contents. Note that HW | |
3902 | breakpoints don't have shadow memory, as they're | |
3903 | implemented using a mechanism that is not dependent on | |
3904 | being able to modify the target's memory, and as such | |
3905 | they should always be removed. */ | |
3906 | if (bl->shlib_disabled | |
3907 | && bl->target_info.shadow_len != 0 | |
3908 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3909 | val = 0; | |
3910 | else | |
c47614fe | 3911 | val = bl->owner->remove_location (bl, reason); |
c02f5703 | 3912 | } |
c906108c SS |
3913 | else |
3914 | { | |
4a64f543 | 3915 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3916 | Did we set a breakpoint at the LMA? */ |
3917 | if (!overlay_events_enabled) | |
3918 | { | |
3919 | /* Yes -- overlay event support is not active, so we | |
3920 | should have set a breakpoint at the LMA. Remove it. | |
3921 | */ | |
c02f5703 MS |
3922 | /* Ignore any failures: if the LMA is in ROM, we will |
3923 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3924 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3925 | target_remove_hw_breakpoint (bl->gdbarch, | |
3926 | &bl->overlay_target_info); | |
c02f5703 | 3927 | else |
35df4500 | 3928 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3929 | &bl->overlay_target_info, |
3930 | reason); | |
c02f5703 MS |
3931 | } |
3932 | /* Did we set a breakpoint at the VMA? | |
3933 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3934 | if (bl->inserted) |
c906108c | 3935 | { |
c02f5703 MS |
3936 | /* Yes -- remove it. Previously we did not bother to |
3937 | remove the breakpoint if the section had been | |
3938 | unmapped, but let's not rely on that being safe. We | |
3939 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3940 | |
3941 | /* However, we should remove *software* breakpoints only | |
3942 | if the section is still mapped, or else we overwrite | |
3943 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3944 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3945 | || section_is_mapped (bl->section)) | |
c47614fe | 3946 | val = bl->owner->remove_location (bl, reason); |
aa67235e UW |
3947 | else |
3948 | val = 0; | |
c906108c | 3949 | } |
c02f5703 MS |
3950 | else |
3951 | { | |
3952 | /* No -- not inserted, so no need to remove. No error. */ | |
3953 | val = 0; | |
3954 | } | |
c906108c | 3955 | } |
879d1e6b | 3956 | |
08351840 PA |
3957 | /* In some cases, we might not be able to remove a breakpoint in |
3958 | a shared library that has already been removed, but we have | |
3959 | not yet processed the shlib unload event. Similarly for an | |
3960 | unloaded add-symbol-file object - the user might not yet have | |
3961 | had the chance to remove-symbol-file it. shlib_disabled will | |
3962 | be set if the library/object has already been removed, but | |
3963 | the breakpoint hasn't been uninserted yet, e.g., after | |
3964 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3965 | always-inserted mode. */ | |
076855f9 | 3966 | if (val |
08351840 PA |
3967 | && (bl->loc_type == bp_loc_software_breakpoint |
3968 | && (bl->shlib_disabled | |
3969 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3970 | || shared_objfile_contains_address_p (bl->pspace, |
3971 | bl->address)))) | |
879d1e6b UW |
3972 | val = 0; |
3973 | ||
c906108c SS |
3974 | if (val) |
3975 | return val; | |
b2b6a7da | 3976 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3977 | } |
35df4500 | 3978 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3979 | { |
b2b6a7da | 3980 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c47614fe | 3981 | bl->owner->remove_location (bl, reason); |
2e70b7b9 | 3982 | |
c906108c | 3983 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3984 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3985 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3986 | bl->owner->number); |
c906108c | 3987 | } |
35df4500 | 3988 | else if (bl->owner->type == bp_catchpoint |
dda83cd7 SM |
3989 | && breakpoint_enabled (bl->owner) |
3990 | && !bl->duplicate) | |
ce78b96d | 3991 | { |
c47614fe | 3992 | val = bl->owner->remove_location (bl, reason); |
ce78b96d JB |
3993 | if (val) |
3994 | return val; | |
77b06cd7 | 3995 | |
b2b6a7da | 3996 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3997 | } |
c906108c SS |
3998 | |
3999 | return 0; | |
4000 | } | |
4001 | ||
6c95b8df | 4002 | static int |
834c0d03 | 4003 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 4004 | { |
35df4500 TJB |
4005 | /* BL is never in moribund_locations by our callers. */ |
4006 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4007 | |
6c95b8df PA |
4008 | /* The type of none suggests that owner is actually deleted. |
4009 | This should not ever happen. */ | |
35df4500 | 4010 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 4011 | |
5ed8105e | 4012 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 4013 | |
35df4500 | 4014 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4015 | |
5ed8105e | 4016 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4017 | } |
4018 | ||
c906108c SS |
4019 | /* Clear the "inserted" flag in all breakpoints. */ |
4020 | ||
25b22b0a | 4021 | void |
fba45db2 | 4022 | mark_breakpoints_out (void) |
c906108c | 4023 | { |
48d7020b | 4024 | for (bp_location *bl : all_bp_locations ()) |
66c4b3e8 | 4025 | if (bl->pspace == current_program_space) |
35df4500 | 4026 | bl->inserted = 0; |
c906108c SS |
4027 | } |
4028 | ||
53a5351d JM |
4029 | /* Clear the "inserted" flag in all breakpoints and delete any |
4030 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4031 | |
4032 | Plus other such housekeeping that has to be done for breakpoints | |
4033 | between runs. | |
4034 | ||
53a5351d JM |
4035 | Note: this function gets called at the end of a run (by |
4036 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4037 | init_wait_for_inferior). */ |
c906108c SS |
4038 | |
4039 | ||
4040 | ||
4041 | void | |
fba45db2 | 4042 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4043 | { |
6c95b8df | 4044 | struct program_space *pspace = current_program_space; |
c906108c | 4045 | |
50c71eaf PA |
4046 | /* If breakpoint locations are shared across processes, then there's |
4047 | nothing to do. */ | |
f5656ead | 4048 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4049 | return; |
4050 | ||
1a853c52 | 4051 | mark_breakpoints_out (); |
075f6582 | 4052 | |
1428b37a | 4053 | for (breakpoint *b : all_breakpoints_safe ()) |
01add95b SM |
4054 | { |
4055 | if (b->loc && b->loc->pspace != pspace) | |
4056 | continue; | |
6c95b8df | 4057 | |
01add95b SM |
4058 | switch (b->type) |
4059 | { | |
4060 | case bp_call_dummy: | |
4061 | case bp_longjmp_call_dummy: | |
c906108c | 4062 | |
01add95b SM |
4063 | /* If the call dummy breakpoint is at the entry point it will |
4064 | cause problems when the inferior is rerun, so we better get | |
4065 | rid of it. */ | |
ab92d69b | 4066 | |
01add95b | 4067 | case bp_watchpoint_scope: |
ab92d69b | 4068 | |
01add95b | 4069 | /* Also get rid of scope breakpoints. */ |
ab92d69b | 4070 | |
01add95b | 4071 | case bp_shlib_event: |
ab92d69b | 4072 | |
01add95b SM |
4073 | /* Also remove solib event breakpoints. Their addresses may |
4074 | have changed since the last time we ran the program. | |
4075 | Actually we may now be debugging against different target; | |
4076 | and so the solib backend that installed this breakpoint may | |
4077 | not be used in by the target. E.g., | |
ab92d69b | 4078 | |
01add95b SM |
4079 | (gdb) file prog-linux |
4080 | (gdb) run # native linux target | |
4081 | ... | |
4082 | (gdb) kill | |
4083 | (gdb) file prog-win.exe | |
4084 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4085 | */ | |
c906108c | 4086 | |
01add95b | 4087 | case bp_step_resume: |
f59f708a | 4088 | |
01add95b | 4089 | /* Also remove step-resume breakpoints. */ |
f59f708a | 4090 | |
01add95b | 4091 | case bp_single_step: |
7c16b83e | 4092 | |
01add95b | 4093 | /* Also remove single-step breakpoints. */ |
7c16b83e | 4094 | |
01add95b SM |
4095 | delete_breakpoint (b); |
4096 | break; | |
c906108c | 4097 | |
01add95b SM |
4098 | case bp_watchpoint: |
4099 | case bp_hardware_watchpoint: | |
4100 | case bp_read_watchpoint: | |
4101 | case bp_access_watchpoint: | |
4102 | { | |
4103 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4104 | |
01add95b SM |
4105 | /* Likewise for watchpoints on local expressions. */ |
4106 | if (w->exp_valid_block != NULL) | |
4107 | delete_breakpoint (b); | |
4108 | else | |
4109 | { | |
4110 | /* Get rid of existing locations, which are no longer | |
4111 | valid. New ones will be created in | |
4112 | update_watchpoint, when the inferior is restarted. | |
4113 | The next update_global_location_list call will | |
4114 | garbage collect them. */ | |
4115 | b->loc = NULL; | |
4116 | ||
4117 | if (context == inf_starting) | |
4118 | { | |
4119 | /* Reset val field to force reread of starting value in | |
4120 | insert_breakpoints. */ | |
4121 | w->val.reset (nullptr); | |
4122 | w->val_valid = false; | |
4123 | } | |
4124 | } | |
4125 | } | |
4126 | break; | |
4127 | default: | |
4128 | break; | |
3a5c3e22 | 4129 | } |
01add95b | 4130 | } |
1c5cfe86 PA |
4131 | |
4132 | /* Get rid of the moribund locations. */ | |
1123588c | 4133 | for (bp_location *bl : moribund_locations) |
35df4500 | 4134 | decref_bp_location (&bl); |
1123588c | 4135 | moribund_locations.clear (); |
c906108c SS |
4136 | } |
4137 | ||
6c95b8df PA |
4138 | /* These functions concern about actual breakpoints inserted in the |
4139 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4140 | we need to hop over the bkpt --- so we check for address space | |
4141 | match, not program space. */ | |
4142 | ||
c2c6d25f JM |
4143 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4144 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4145 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4146 | permanent breakpoint. | |
4147 | - When continuing from a location with an ordinary breakpoint, we | |
4148 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4149 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4150 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4151 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4152 | |
c2c6d25f | 4153 | enum breakpoint_here |
accd0bcd | 4154 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4155 | { |
c2c6d25f | 4156 | int any_breakpoint_here = 0; |
c906108c | 4157 | |
48d7020b | 4158 | for (bp_location *bl : all_bp_locations ()) |
075f6582 | 4159 | { |
35df4500 TJB |
4160 | if (bl->loc_type != bp_loc_software_breakpoint |
4161 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4162 | continue; |
4163 | ||
f1310107 | 4164 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4165 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4166 | || bl->permanent) |
f1310107 | 4167 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4168 | { |
4169 | if (overlay_debugging | |
35df4500 TJB |
4170 | && section_is_overlay (bl->section) |
4171 | && !section_is_mapped (bl->section)) | |
075f6582 | 4172 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4173 | else if (bl->permanent) |
075f6582 DJ |
4174 | return permanent_breakpoint_here; |
4175 | else | |
4176 | any_breakpoint_here = 1; | |
4177 | } | |
4178 | } | |
c906108c | 4179 | |
f486487f | 4180 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4181 | } |
4182 | ||
d35ae833 PA |
4183 | /* See breakpoint.h. */ |
4184 | ||
4185 | int | |
accd0bcd | 4186 | breakpoint_in_range_p (const address_space *aspace, |
d35ae833 PA |
4187 | CORE_ADDR addr, ULONGEST len) |
4188 | { | |
48d7020b | 4189 | for (bp_location *bl : all_bp_locations ()) |
d35ae833 PA |
4190 | { |
4191 | if (bl->loc_type != bp_loc_software_breakpoint | |
4192 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4193 | continue; | |
4194 | ||
4195 | if ((breakpoint_enabled (bl->owner) | |
4196 | || bl->permanent) | |
4197 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4198 | addr, len)) | |
4199 | { | |
4200 | if (overlay_debugging | |
4201 | && section_is_overlay (bl->section) | |
4202 | && !section_is_mapped (bl->section)) | |
4203 | { | |
4204 | /* Unmapped overlay -- can't be a match. */ | |
4205 | continue; | |
4206 | } | |
4207 | ||
4208 | return 1; | |
4209 | } | |
4210 | } | |
4211 | ||
4212 | return 0; | |
4213 | } | |
4214 | ||
1c5cfe86 PA |
4215 | /* Return true if there's a moribund breakpoint at PC. */ |
4216 | ||
4217 | int | |
accd0bcd | 4218 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
1c5cfe86 | 4219 | { |
1123588c | 4220 | for (bp_location *loc : moribund_locations) |
f1310107 | 4221 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4222 | return 1; |
4223 | ||
4224 | return 0; | |
4225 | } | |
c2c6d25f | 4226 | |
f7ce857f PA |
4227 | /* Returns non-zero iff BL is inserted at PC, in address space |
4228 | ASPACE. */ | |
4229 | ||
4230 | static int | |
4231 | bp_location_inserted_here_p (struct bp_location *bl, | |
accd0bcd | 4232 | const address_space *aspace, CORE_ADDR pc) |
f7ce857f PA |
4233 | { |
4234 | if (bl->inserted | |
4235 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4236 | aspace, pc)) | |
4237 | { | |
4238 | if (overlay_debugging | |
4239 | && section_is_overlay (bl->section) | |
4240 | && !section_is_mapped (bl->section)) | |
4241 | return 0; /* unmapped overlay -- can't be a match */ | |
4242 | else | |
4243 | return 1; | |
4244 | } | |
4245 | return 0; | |
4246 | } | |
4247 | ||
a1fd2fa5 | 4248 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4249 | |
4250 | int | |
accd0bcd | 4251 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
c906108c | 4252 | { |
e0d9a270 | 4253 | for (bp_location *bl : all_bp_locations_at_addr (pc)) |
c5aa993b | 4254 | { |
35df4500 TJB |
4255 | if (bl->loc_type != bp_loc_software_breakpoint |
4256 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4257 | continue; |
4258 | ||
f7ce857f PA |
4259 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4260 | return 1; | |
c5aa993b | 4261 | } |
c36b740a VP |
4262 | return 0; |
4263 | } | |
4264 | ||
a1fd2fa5 PA |
4265 | /* This function returns non-zero iff there is a software breakpoint |
4266 | inserted at PC. */ | |
c36b740a VP |
4267 | |
4268 | int | |
accd0bcd | 4269 | software_breakpoint_inserted_here_p (const address_space *aspace, |
a1fd2fa5 | 4270 | CORE_ADDR pc) |
4fa8626c | 4271 | { |
e0d9a270 | 4272 | for (bp_location *bl : all_bp_locations_at_addr (pc)) |
4fa8626c | 4273 | { |
35df4500 | 4274 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4275 | continue; |
4276 | ||
f7ce857f PA |
4277 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4278 | return 1; | |
4fa8626c DJ |
4279 | } |
4280 | ||
4281 | return 0; | |
9c02b525 PA |
4282 | } |
4283 | ||
4284 | /* See breakpoint.h. */ | |
4285 | ||
4286 | int | |
accd0bcd | 4287 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
9c02b525 PA |
4288 | CORE_ADDR pc) |
4289 | { | |
e0d9a270 | 4290 | for (bp_location *bl : all_bp_locations_at_addr (pc)) |
9c02b525 | 4291 | { |
9c02b525 PA |
4292 | if (bl->loc_type != bp_loc_hardware_breakpoint) |
4293 | continue; | |
4294 | ||
4295 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4296 | return 1; | |
4297 | } | |
4298 | ||
4299 | return 0; | |
4fa8626c DJ |
4300 | } |
4301 | ||
9093389c | 4302 | int |
accd0bcd | 4303 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
9093389c PA |
4304 | CORE_ADDR addr, ULONGEST len) |
4305 | { | |
43892fdf | 4306 | for (breakpoint *bpt : all_breakpoints ()) |
9093389c | 4307 | { |
9093389c PA |
4308 | if (bpt->type != bp_hardware_watchpoint |
4309 | && bpt->type != bp_access_watchpoint) | |
4310 | continue; | |
4311 | ||
4312 | if (!breakpoint_enabled (bpt)) | |
4313 | continue; | |
4314 | ||
40cb8ca5 | 4315 | for (bp_location *loc : bpt->locations ()) |
9093389c PA |
4316 | if (loc->pspace->aspace == aspace && loc->inserted) |
4317 | { | |
4318 | CORE_ADDR l, h; | |
4319 | ||
4320 | /* Check for intersection. */ | |
768adc05 PA |
4321 | l = std::max<CORE_ADDR> (loc->address, addr); |
4322 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4323 | if (l < h) |
4324 | return 1; | |
4325 | } | |
4326 | } | |
4327 | return 0; | |
4328 | } | |
c5aa993b | 4329 | |
f2478a7e | 4330 | /* See breakpoint.h. */ |
c906108c | 4331 | |
f2478a7e SM |
4332 | bool |
4333 | is_catchpoint (struct breakpoint *b) | |
c906108c | 4334 | { |
f2478a7e | 4335 | return (b->type == bp_catchpoint); |
c906108c SS |
4336 | } |
4337 | ||
c906108c SS |
4338 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4339 | Also free any storage that is part of a bpstat. */ | |
4340 | ||
4341 | void | |
313f3b21 | 4342 | bpstat_clear (bpstat **bsp) |
c906108c | 4343 | { |
313f3b21 SM |
4344 | bpstat *p; |
4345 | bpstat *q; | |
c906108c SS |
4346 | |
4347 | if (bsp == 0) | |
4348 | return; | |
4349 | p = *bsp; | |
4350 | while (p != NULL) | |
4351 | { | |
4352 | q = p->next; | |
04afa70c | 4353 | delete p; |
c906108c SS |
4354 | p = q; |
4355 | } | |
4356 | *bsp = NULL; | |
4357 | } | |
4358 | ||
313f3b21 | 4359 | bpstat::bpstat (const bpstat &other) |
04afa70c TT |
4360 | : next (NULL), |
4361 | bp_location_at (other.bp_location_at), | |
4362 | breakpoint_at (other.breakpoint_at), | |
4363 | commands (other.commands), | |
04afa70c TT |
4364 | print (other.print), |
4365 | stop (other.stop), | |
4366 | print_it (other.print_it) | |
4367 | { | |
850645cf TT |
4368 | if (other.old_val != NULL) |
4369 | old_val = release_value (value_copy (other.old_val.get ())); | |
04afa70c TT |
4370 | } |
4371 | ||
c906108c SS |
4372 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4373 | is part of the bpstat is copied as well. */ | |
4374 | ||
313f3b21 SM |
4375 | bpstat * |
4376 | bpstat_copy (bpstat *bs) | |
c906108c | 4377 | { |
313f3b21 SM |
4378 | bpstat *p = nullptr; |
4379 | bpstat *tmp; | |
4380 | bpstat *retval = nullptr; | |
c906108c SS |
4381 | |
4382 | if (bs == NULL) | |
4383 | return bs; | |
4384 | ||
4385 | for (; bs != NULL; bs = bs->next) | |
4386 | { | |
313f3b21 | 4387 | tmp = new bpstat (*bs); |
31cc81e9 | 4388 | |
c906108c SS |
4389 | if (p == NULL) |
4390 | /* This is the first thing in the chain. */ | |
4391 | retval = tmp; | |
4392 | else | |
4393 | p->next = tmp; | |
4394 | p = tmp; | |
4395 | } | |
4396 | p->next = NULL; | |
4397 | return retval; | |
4398 | } | |
4399 | ||
4a64f543 | 4400 | /* Find the bpstat associated with this breakpoint. */ |
c906108c | 4401 | |
313f3b21 SM |
4402 | bpstat * |
4403 | bpstat_find_breakpoint (bpstat *bsp, struct breakpoint *breakpoint) | |
c906108c | 4404 | { |
c5aa993b JM |
4405 | if (bsp == NULL) |
4406 | return NULL; | |
c906108c | 4407 | |
c5aa993b JM |
4408 | for (; bsp != NULL; bsp = bsp->next) |
4409 | { | |
f431efe5 | 4410 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4411 | return bsp; |
4412 | } | |
c906108c SS |
4413 | return NULL; |
4414 | } | |
4415 | ||
ab04a2af TT |
4416 | /* See breakpoint.h. */ |
4417 | ||
4c462cb0 | 4418 | bool |
313f3b21 | 4419 | bpstat_explains_signal (bpstat *bsp, enum gdb_signal sig) |
ab04a2af | 4420 | { |
ab04a2af TT |
4421 | for (; bsp != NULL; bsp = bsp->next) |
4422 | { | |
427cd150 TT |
4423 | if (bsp->breakpoint_at == NULL) |
4424 | { | |
4425 | /* A moribund location can never explain a signal other than | |
4426 | GDB_SIGNAL_TRAP. */ | |
4427 | if (sig == GDB_SIGNAL_TRAP) | |
4c462cb0 | 4428 | return true; |
427cd150 TT |
4429 | } |
4430 | else | |
47591c29 | 4431 | { |
c47614fe | 4432 | if (bsp->breakpoint_at->explains_signal (sig)) |
4c462cb0 | 4433 | return true; |
47591c29 | 4434 | } |
ab04a2af TT |
4435 | } |
4436 | ||
4c462cb0 | 4437 | return false; |
ab04a2af TT |
4438 | } |
4439 | ||
4a64f543 MS |
4440 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4441 | stopped at. *BSP upon return is a bpstat which points to the | |
4442 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4443 | good for anything but further calls to bpstat_num). | |
4444 | ||
8671a17b PA |
4445 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4446 | Return -1 if stopped at a breakpoint that has been deleted since | |
4447 | we set it. | |
4448 | Return 1 otherwise. */ | |
c906108c SS |
4449 | |
4450 | int | |
313f3b21 | 4451 | bpstat_num (bpstat **bsp, int *num) |
c906108c SS |
4452 | { |
4453 | struct breakpoint *b; | |
4454 | ||
4455 | if ((*bsp) == NULL) | |
4456 | return 0; /* No more breakpoint values */ | |
8671a17b | 4457 | |
4a64f543 MS |
4458 | /* We assume we'll never have several bpstats that correspond to a |
4459 | single breakpoint -- otherwise, this function might return the | |
4460 | same number more than once and this will look ugly. */ | |
f431efe5 | 4461 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4462 | *bsp = (*bsp)->next; |
4463 | if (b == NULL) | |
4464 | return -1; /* breakpoint that's been deleted since */ | |
4465 | ||
4466 | *num = b->number; /* We have its number */ | |
4467 | return 1; | |
c906108c SS |
4468 | } |
4469 | ||
e93ca019 | 4470 | /* See breakpoint.h. */ |
c906108c SS |
4471 | |
4472 | void | |
e93ca019 | 4473 | bpstat_clear_actions (void) |
c906108c | 4474 | { |
313f3b21 | 4475 | bpstat *bs; |
e93ca019 | 4476 | |
00431a78 | 4477 | if (inferior_ptid == null_ptid) |
e93ca019 JK |
4478 | return; |
4479 | ||
00431a78 | 4480 | thread_info *tp = inferior_thread (); |
e93ca019 | 4481 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
c906108c | 4482 | { |
d1b0a7bf | 4483 | bs->commands = NULL; |
850645cf | 4484 | bs->old_val.reset (nullptr); |
c906108c SS |
4485 | } |
4486 | } | |
4487 | ||
f3b1572e PA |
4488 | /* Called when a command is about to proceed the inferior. */ |
4489 | ||
4490 | static void | |
4491 | breakpoint_about_to_proceed (void) | |
4492 | { | |
d7e15655 | 4493 | if (inferior_ptid != null_ptid) |
f3b1572e PA |
4494 | { |
4495 | struct thread_info *tp = inferior_thread (); | |
4496 | ||
4497 | /* Allow inferior function calls in breakpoint commands to not | |
4498 | interrupt the command list. When the call finishes | |
4499 | successfully, the inferior will be standing at the same | |
4500 | breakpoint as if nothing happened. */ | |
16c381f0 | 4501 | if (tp->control.in_infcall) |
f3b1572e PA |
4502 | return; |
4503 | } | |
4504 | ||
4505 | breakpoint_proceeded = 1; | |
4506 | } | |
4507 | ||
abf85f46 JK |
4508 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4509 | or its equivalent. */ | |
4510 | ||
4511 | static int | |
4512 | command_line_is_silent (struct command_line *cmd) | |
4513 | { | |
4f45d445 | 4514 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4515 | } |
4516 | ||
4a64f543 MS |
4517 | /* Execute all the commands associated with all the breakpoints at |
4518 | this location. Any of these commands could cause the process to | |
4519 | proceed beyond this point, etc. We look out for such changes by | |
4520 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4521 | |
347bddb7 PA |
4522 | Returns true if a breakpoint command resumed the inferior. In that |
4523 | case, it is the caller's responsibility to recall it again with the | |
4524 | bpstat of the current thread. */ | |
4525 | ||
4526 | static int | |
313f3b21 | 4527 | bpstat_do_actions_1 (bpstat **bsp) |
c906108c | 4528 | { |
313f3b21 | 4529 | bpstat *bs; |
347bddb7 | 4530 | int again = 0; |
c906108c SS |
4531 | |
4532 | /* Avoid endless recursion if a `source' command is contained | |
4533 | in bs->commands. */ | |
4534 | if (executing_breakpoint_commands) | |
347bddb7 | 4535 | return 0; |
c906108c | 4536 | |
81b1e71c TT |
4537 | scoped_restore save_executing |
4538 | = make_scoped_restore (&executing_breakpoint_commands, 1); | |
c906108c | 4539 | |
1ac32117 | 4540 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4541 | |
4a64f543 | 4542 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4543 | bs = *bsp; |
4544 | ||
4545 | breakpoint_proceeded = 0; | |
4546 | for (; bs != NULL; bs = bs->next) | |
4547 | { | |
d1b0a7bf | 4548 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4549 | |
4550 | /* Take ownership of the BSP's command tree, if it has one. | |
4551 | ||
dda83cd7 SM |
4552 | The command tree could legitimately contain commands like |
4553 | 'step' and 'next', which call clear_proceed_status, which | |
4554 | frees stop_bpstat's command tree. To make sure this doesn't | |
4555 | free the tree we're executing out from under us, we need to | |
4556 | take ownership of the tree ourselves. Since a given bpstat's | |
4557 | commands are only executed once, we don't need to copy it; we | |
4558 | can clear the pointer in the bpstat, and make sure we free | |
4559 | the tree when we're done. */ | |
d1b0a7bf | 4560 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4561 | bs->commands = NULL; |
d1b0a7bf TT |
4562 | if (ccmd != NULL) |
4563 | cmd = ccmd.get (); | |
abf85f46 JK |
4564 | if (command_line_is_silent (cmd)) |
4565 | { | |
4566 | /* The action has been already done by bpstat_stop_status. */ | |
4567 | cmd = cmd->next; | |
4568 | } | |
6c50ab1c | 4569 | |
c906108c SS |
4570 | while (cmd != NULL) |
4571 | { | |
4572 | execute_control_command (cmd); | |
4573 | ||
4574 | if (breakpoint_proceeded) | |
4575 | break; | |
4576 | else | |
4577 | cmd = cmd->next; | |
4578 | } | |
6c50ab1c | 4579 | |
c906108c | 4580 | if (breakpoint_proceeded) |
32c1e744 | 4581 | { |
cb814510 | 4582 | if (current_ui->async) |
347bddb7 PA |
4583 | /* If we are in async mode, then the target might be still |
4584 | running, not stopped at any breakpoint, so nothing for | |
4585 | us to do here -- just return to the event loop. */ | |
4586 | ; | |
32c1e744 VP |
4587 | else |
4588 | /* In sync mode, when execute_control_command returns | |
4589 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4590 | Breakpoint commands for that stop were not run, since |
4591 | execute_command does not run breakpoint commands -- | |
4592 | only command_line_handler does, but that one is not | |
4593 | involved in execution of breakpoint commands. So, we | |
4594 | can now execute breakpoint commands. It should be | |
4595 | noted that making execute_command do bpstat actions is | |
4596 | not an option -- in this case we'll have recursive | |
4597 | invocation of bpstat for each breakpoint with a | |
4598 | command, and can easily blow up GDB stack. Instead, we | |
4599 | return true, which will trigger the caller to recall us | |
4600 | with the new stop_bpstat. */ | |
4601 | again = 1; | |
4602 | break; | |
32c1e744 | 4603 | } |
c906108c | 4604 | } |
347bddb7 PA |
4605 | return again; |
4606 | } | |
4607 | ||
00431a78 PA |
4608 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
4609 | one, is alive and has execution. Return NULL otherwise. */ | |
4610 | ||
4611 | static thread_info * | |
4612 | get_bpstat_thread () | |
4613 | { | |
55f6301a | 4614 | if (inferior_ptid == null_ptid || !target_has_execution ()) |
00431a78 PA |
4615 | return NULL; |
4616 | ||
4617 | thread_info *tp = inferior_thread (); | |
611841bb | 4618 | if (tp->state == THREAD_EXITED || tp->executing ()) |
00431a78 PA |
4619 | return NULL; |
4620 | return tp; | |
4621 | } | |
4622 | ||
347bddb7 PA |
4623 | void |
4624 | bpstat_do_actions (void) | |
4625 | { | |
694c6bf5 | 4626 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
00431a78 | 4627 | thread_info *tp; |
353d1d73 | 4628 | |
347bddb7 | 4629 | /* Do any commands attached to breakpoint we are stopped at. */ |
00431a78 PA |
4630 | while ((tp = get_bpstat_thread ()) != NULL) |
4631 | { | |
4632 | /* Since in sync mode, bpstat_do_actions may resume the | |
4633 | inferior, and only return when it is stopped at the next | |
4634 | breakpoint, we keep doing breakpoint actions until it returns | |
4635 | false to indicate the inferior was not resumed. */ | |
4636 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) | |
4637 | break; | |
4638 | } | |
353d1d73 | 4639 | |
694c6bf5 | 4640 | cleanup_if_error.release (); |
c906108c SS |
4641 | } |
4642 | ||
fa4727a6 DJ |
4643 | /* Print out the (old or new) value associated with a watchpoint. */ |
4644 | ||
4645 | static void | |
4646 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4647 | { | |
4648 | if (val == NULL) | |
7f6aba03 | 4649 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
fa4727a6 | 4650 | else |
79a45b7d TT |
4651 | { |
4652 | struct value_print_options opts; | |
4653 | get_user_print_options (&opts); | |
4654 | value_print (val, stream, &opts); | |
4655 | } | |
fa4727a6 DJ |
4656 | } |
4657 | ||
f303dbd6 PA |
4658 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4659 | debugging multiple threads. */ | |
4660 | ||
4661 | void | |
4662 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4663 | { | |
112e8700 | 4664 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4665 | return; |
4666 | ||
112e8700 | 4667 | uiout->text ("\n"); |
f303dbd6 PA |
4668 | |
4669 | if (show_thread_that_caused_stop ()) | |
4670 | { | |
f303dbd6 PA |
4671 | struct thread_info *thr = inferior_thread (); |
4672 | ||
112e8700 | 4673 | uiout->text ("Thread "); |
33eca680 | 4674 | uiout->field_string ("thread-id", print_thread_id (thr)); |
f303dbd6 | 4675 | |
25558938 | 4676 | const char *name = thread_name (thr); |
f303dbd6 PA |
4677 | if (name != NULL) |
4678 | { | |
112e8700 | 4679 | uiout->text (" \""); |
33eca680 | 4680 | uiout->field_string ("name", name); |
112e8700 | 4681 | uiout->text ("\""); |
f303dbd6 PA |
4682 | } |
4683 | ||
112e8700 | 4684 | uiout->text (" hit "); |
f303dbd6 PA |
4685 | } |
4686 | } | |
4687 | ||
e514a9d6 | 4688 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4689 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4690 | 'print_it' in the bpstat structure. Under some circumstances we |
4691 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4692 | normal_stop(). */ |
e514a9d6 JM |
4693 | |
4694 | static enum print_stop_action | |
313f3b21 | 4695 | print_bp_stop_message (bpstat *bs) |
e514a9d6 JM |
4696 | { |
4697 | switch (bs->print_it) | |
4698 | { | |
4699 | case print_it_noop: | |
4a64f543 | 4700 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4701 | return PRINT_UNKNOWN; |
4702 | break; | |
4703 | ||
4704 | case print_it_done: | |
4705 | /* We still want to print the frame, but we already printed the | |
dda83cd7 | 4706 | relevant messages. */ |
e514a9d6 JM |
4707 | return PRINT_SRC_AND_LOC; |
4708 | break; | |
4709 | ||
4710 | case print_it_normal: | |
4f8d1dc6 | 4711 | { |
f431efe5 PA |
4712 | struct breakpoint *b = bs->breakpoint_at; |
4713 | ||
1a6a67de TJB |
4714 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4715 | which has since been deleted. */ | |
4716 | if (b == NULL) | |
4717 | return PRINT_UNKNOWN; | |
4718 | ||
348d480f | 4719 | /* Normal case. Call the breakpoint's print_it method. */ |
c47614fe | 4720 | return b->print_it (bs); |
4f8d1dc6 | 4721 | } |
348d480f | 4722 | break; |
3086aeae | 4723 | |
e514a9d6 | 4724 | default: |
8e65ff28 | 4725 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4726 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4727 | break; |
c906108c | 4728 | } |
c906108c SS |
4729 | } |
4730 | ||
2f9ee862 | 4731 | /* See breakpoint.h. */ |
edcc5120 | 4732 | |
2f9ee862 | 4733 | void |
4e9e993a | 4734 | print_solib_event (bool is_catchpoint) |
edcc5120 | 4735 | { |
6fb16ce6 | 4736 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
bcb430e4 | 4737 | bool any_added = !current_program_space->added_solibs.empty (); |
edcc5120 TT |
4738 | |
4739 | if (!is_catchpoint) | |
4740 | { | |
4741 | if (any_added || any_deleted) | |
112e8700 | 4742 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4743 | else |
112e8700 SM |
4744 | current_uiout->text (_("Stopped due to shared library event (no " |
4745 | "libraries added or removed)\n")); | |
edcc5120 TT |
4746 | } |
4747 | ||
112e8700 SM |
4748 | if (current_uiout->is_mi_like_p ()) |
4749 | current_uiout->field_string ("reason", | |
4750 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4751 | |
4752 | if (any_deleted) | |
4753 | { | |
112e8700 | 4754 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4755 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
6fb16ce6 | 4756 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
edcc5120 | 4757 | { |
6fb16ce6 SM |
4758 | const std::string &name = current_program_space->deleted_solibs[ix]; |
4759 | ||
edcc5120 | 4760 | if (ix > 0) |
112e8700 SM |
4761 | current_uiout->text (" "); |
4762 | current_uiout->field_string ("library", name); | |
4763 | current_uiout->text ("\n"); | |
edcc5120 | 4764 | } |
edcc5120 TT |
4765 | } |
4766 | ||
4767 | if (any_added) | |
4768 | { | |
112e8700 | 4769 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4770 | ui_out_emit_list list_emitter (current_uiout, "added"); |
bcb430e4 | 4771 | bool first = true; |
52941706 | 4772 | for (so_list *iter : current_program_space->added_solibs) |
edcc5120 | 4773 | { |
bcb430e4 | 4774 | if (!first) |
112e8700 | 4775 | current_uiout->text (" "); |
bcb430e4 | 4776 | first = false; |
112e8700 SM |
4777 | current_uiout->field_string ("library", iter->so_name); |
4778 | current_uiout->text ("\n"); | |
edcc5120 | 4779 | } |
edcc5120 TT |
4780 | } |
4781 | } | |
4782 | ||
e514a9d6 JM |
4783 | /* Print a message indicating what happened. This is called from |
4784 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4785 | list - a list of the eventpoints that caused this stop. KIND is |
4786 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4787 | routine calls the generic print routine for printing a message |
4788 | about reasons for stopping. This will print (for example) the | |
4789 | "Breakpoint n," part of the output. The return value of this | |
4790 | routine is one of: | |
c906108c | 4791 | |
4a64f543 | 4792 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4793 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4794 | code to print the location. An example is |
c5aa993b JM |
4795 | "Breakpoint 1, " which should be followed by |
4796 | the location. | |
917317f4 | 4797 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4798 | to also print the location part of the message. |
4799 | An example is the catch/throw messages, which | |
4a64f543 | 4800 | don't require a location appended to the end. |
917317f4 | 4801 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4802 | further info to be printed. */ |
c906108c | 4803 | |
917317f4 | 4804 | enum print_stop_action |
313f3b21 | 4805 | bpstat_print (bpstat *bs, int kind) |
c906108c | 4806 | { |
f486487f | 4807 | enum print_stop_action val; |
c5aa993b | 4808 | |
c906108c | 4809 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4810 | (Currently all watchpoints go on the bpstat whether hit or not. |
4811 | That probably could (should) be changed, provided care is taken | |
c906108c | 4812 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4813 | for (; bs; bs = bs->next) |
4814 | { | |
4815 | val = print_bp_stop_message (bs); | |
4816 | if (val == PRINT_SRC_ONLY | |
4817 | || val == PRINT_SRC_AND_LOC | |
4818 | || val == PRINT_NOTHING) | |
4819 | return val; | |
4820 | } | |
c906108c | 4821 | |
36dfb11c TT |
4822 | /* If we had hit a shared library event breakpoint, |
4823 | print_bp_stop_message would print out this message. If we hit an | |
4824 | OS-level shared library event, do the same thing. */ | |
4825 | if (kind == TARGET_WAITKIND_LOADED) | |
4826 | { | |
4e9e993a | 4827 | print_solib_event (false); |
36dfb11c TT |
4828 | return PRINT_NOTHING; |
4829 | } | |
4830 | ||
e514a9d6 | 4831 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4832 | with and nothing was printed. */ |
917317f4 | 4833 | return PRINT_UNKNOWN; |
c906108c SS |
4834 | } |
4835 | ||
bf469271 | 4836 | /* Evaluate the boolean expression EXP and return the result. */ |
c906108c | 4837 | |
bf469271 PA |
4838 | static bool |
4839 | breakpoint_cond_eval (expression *exp) | |
c906108c | 4840 | { |
278cd55f | 4841 | struct value *mark = value_mark (); |
bf469271 | 4842 | bool res = value_true (evaluate_expression (exp)); |
cc59ec59 | 4843 | |
c906108c | 4844 | value_free_to_mark (mark); |
bf469271 | 4845 | return res; |
c906108c SS |
4846 | } |
4847 | ||
5760d0ab | 4848 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4849 | |
313f3b21 | 4850 | bpstat::bpstat (struct bp_location *bl, bpstat ***bs_link_pointer) |
04afa70c | 4851 | : next (NULL), |
b6433ede | 4852 | bp_location_at (bp_location_ref_ptr::new_reference (bl)), |
04afa70c TT |
4853 | breakpoint_at (bl->owner), |
4854 | commands (NULL), | |
04afa70c TT |
4855 | print (0), |
4856 | stop (0), | |
4857 | print_it (print_it_normal) | |
c906108c | 4858 | { |
04afa70c TT |
4859 | **bs_link_pointer = this; |
4860 | *bs_link_pointer = &next; | |
4861 | } | |
4862 | ||
313f3b21 | 4863 | bpstat::bpstat () |
04afa70c | 4864 | : next (NULL), |
04afa70c TT |
4865 | breakpoint_at (NULL), |
4866 | commands (NULL), | |
04afa70c TT |
4867 | print (0), |
4868 | stop (0), | |
4869 | print_it (print_it_normal) | |
4870 | { | |
c906108c SS |
4871 | } |
4872 | \f | |
d983da9c DJ |
4873 | /* The target has stopped with waitstatus WS. Check if any hardware |
4874 | watchpoints have triggered, according to the target. */ | |
4875 | ||
4876 | int | |
c272a98c | 4877 | watchpoints_triggered (const target_waitstatus &ws) |
d983da9c | 4878 | { |
57810aa7 | 4879 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c | 4880 | CORE_ADDR addr; |
d983da9c DJ |
4881 | |
4882 | if (!stopped_by_watchpoint) | |
4883 | { | |
4884 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4885 | as not triggered. */ | |
43892fdf | 4886 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 4887 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4888 | { |
4889 | struct watchpoint *w = (struct watchpoint *) b; | |
4890 | ||
4891 | w->watchpoint_triggered = watch_triggered_no; | |
4892 | } | |
d983da9c DJ |
4893 | |
4894 | return 0; | |
4895 | } | |
4896 | ||
328d42d8 | 4897 | if (!target_stopped_data_address (current_inferior ()->top_target (), &addr)) |
d983da9c DJ |
4898 | { |
4899 | /* We were stopped by a watchpoint, but we don't know where. | |
4900 | Mark all watchpoints as unknown. */ | |
43892fdf | 4901 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 4902 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4903 | { |
4904 | struct watchpoint *w = (struct watchpoint *) b; | |
4905 | ||
4906 | w->watchpoint_triggered = watch_triggered_unknown; | |
4907 | } | |
d983da9c | 4908 | |
3c4797ba | 4909 | return 1; |
d983da9c DJ |
4910 | } |
4911 | ||
4912 | /* The target could report the data address. Mark watchpoints | |
4913 | affected by this data address as triggered, and all others as not | |
4914 | triggered. */ | |
4915 | ||
43892fdf | 4916 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 4917 | if (is_hardware_watchpoint (b)) |
d983da9c | 4918 | { |
3a5c3e22 | 4919 | struct watchpoint *w = (struct watchpoint *) b; |
d983da9c | 4920 | |
3a5c3e22 | 4921 | w->watchpoint_triggered = watch_triggered_no; |
40cb8ca5 | 4922 | for (bp_location *loc : b->locations ()) |
9c06b0b4 | 4923 | { |
3a5c3e22 | 4924 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4925 | { |
3a5c3e22 PA |
4926 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4927 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4928 | |
4929 | if (newaddr == start) | |
4930 | { | |
3a5c3e22 | 4931 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4932 | break; |
4933 | } | |
4934 | } | |
4935 | /* Exact match not required. Within range is sufficient. */ | |
328d42d8 SM |
4936 | else if (target_watchpoint_addr_within_range |
4937 | (current_inferior ()->top_target (), addr, loc->address, | |
4938 | loc->length)) | |
9c06b0b4 | 4939 | { |
3a5c3e22 | 4940 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4941 | break; |
4942 | } | |
4943 | } | |
d983da9c DJ |
4944 | } |
4945 | ||
4946 | return 1; | |
4947 | } | |
4948 | ||
bf469271 PA |
4949 | /* Possible return values for watchpoint_check. */ |
4950 | enum wp_check_result | |
4951 | { | |
4952 | /* The watchpoint has been deleted. */ | |
4953 | WP_DELETED = 1, | |
4954 | ||
4955 | /* The value has changed. */ | |
4956 | WP_VALUE_CHANGED = 2, | |
4957 | ||
4958 | /* The value has not changed. */ | |
4959 | WP_VALUE_NOT_CHANGED = 3, | |
4960 | ||
4961 | /* Ignore this watchpoint, no matter if the value changed or not. */ | |
4962 | WP_IGNORE = 4, | |
4963 | }; | |
c906108c SS |
4964 | |
4965 | #define BP_TEMPFLAG 1 | |
4966 | #define BP_HARDWAREFLAG 2 | |
4967 | ||
4a64f543 | 4968 | /* Evaluate watchpoint condition expression and check if its value |
bf469271 | 4969 | changed. */ |
553e4c11 | 4970 | |
bf469271 | 4971 | static wp_check_result |
313f3b21 | 4972 | watchpoint_check (bpstat *bs) |
c906108c | 4973 | { |
3a5c3e22 | 4974 | struct watchpoint *b; |
c906108c SS |
4975 | struct frame_info *fr; |
4976 | int within_current_scope; | |
4977 | ||
f431efe5 | 4978 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 4979 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 4980 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 4981 | |
f6bc2008 PA |
4982 | /* If this is a local watchpoint, we only want to check if the |
4983 | watchpoint frame is in scope if the current thread is the thread | |
4984 | that was used to create the watchpoint. */ | |
4985 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 4986 | return WP_IGNORE; |
f6bc2008 | 4987 | |
c906108c SS |
4988 | if (b->exp_valid_block == NULL) |
4989 | within_current_scope = 1; | |
4990 | else | |
4991 | { | |
edb3359d DJ |
4992 | struct frame_info *frame = get_current_frame (); |
4993 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
4994 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
4995 | ||
c9cf6e20 | 4996 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
4997 | still in the function but the stack frame has already been |
4998 | invalidated. Since we can't rely on the values of local | |
4999 | variables after the stack has been destroyed, we are treating | |
5000 | the watchpoint in that state as `not changed' without further | |
5001 | checking. Don't mark watchpoints as changed if the current | |
5002 | frame is in an epilogue - even if they are in some other | |
5003 | frame, our view of the stack is likely to be wrong and | |
5004 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5005 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5006 | return WP_IGNORE; |
a0f49112 | 5007 | |
101dcfbe | 5008 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5009 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5010 | |
5011 | /* If we've gotten confused in the unwinder, we might have | |
5012 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5013 | if (within_current_scope) |
5014 | { | |
5015 | struct symbol *function; | |
5016 | ||
5017 | function = get_frame_function (fr); | |
5018 | if (function == NULL | |
4aeddc50 | 5019 | || !contained_in (b->exp_valid_block, function->value_block ())) |
edb3359d DJ |
5020 | within_current_scope = 0; |
5021 | } | |
69fbadd5 | 5022 | |
edb3359d | 5023 | if (within_current_scope) |
c906108c SS |
5024 | /* If we end up stopping, the current frame will get selected |
5025 | in normal_stop. So this call to select_frame won't affect | |
5026 | the user. */ | |
0f7d239c | 5027 | select_frame (fr); |
c906108c | 5028 | } |
c5aa993b | 5029 | |
c906108c SS |
5030 | if (within_current_scope) |
5031 | { | |
4a64f543 | 5032 | /* We use value_{,free_to_}mark because it could be a *long* |
dda83cd7 SM |
5033 | time before we return to the command level and call |
5034 | free_all_values. We can't call free_all_values because we | |
5035 | might be in the middle of evaluating a function call. */ | |
c906108c | 5036 | |
9c06b0b4 | 5037 | struct value *mark; |
fa4727a6 DJ |
5038 | struct value *new_val; |
5039 | ||
c1fc2657 | 5040 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
5041 | /* Since we don't know the exact trigger address (from |
5042 | stopped_data_address), just tell the user we've triggered | |
5043 | a mask watchpoint. */ | |
5044 | return WP_VALUE_CHANGED; | |
5045 | ||
5046 | mark = value_mark (); | |
1eaebe02 | 5047 | fetch_subexp_value (b->exp.get (), b->exp->op.get (), &new_val, |
413403fc | 5048 | NULL, NULL, false); |
218d2fc6 | 5049 | |
bb9d5f81 PP |
5050 | if (b->val_bitsize != 0) |
5051 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5052 | ||
4a64f543 MS |
5053 | /* We use value_equal_contents instead of value_equal because |
5054 | the latter coerces an array to a pointer, thus comparing just | |
5055 | the address of the array instead of its contents. This is | |
5056 | not what we want. */ | |
fa4727a6 | 5057 | if ((b->val != NULL) != (new_val != NULL) |
850645cf TT |
5058 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
5059 | new_val))) | |
c906108c | 5060 | { |
c906108c | 5061 | bs->old_val = b->val; |
850645cf | 5062 | b->val = release_value (new_val); |
4c1d86d9 | 5063 | b->val_valid = true; |
850645cf TT |
5064 | if (new_val != NULL) |
5065 | value_free_to_mark (mark); | |
c906108c SS |
5066 | return WP_VALUE_CHANGED; |
5067 | } | |
5068 | else | |
5069 | { | |
60e1c644 | 5070 | /* Nothing changed. */ |
c906108c | 5071 | value_free_to_mark (mark); |
c906108c SS |
5072 | return WP_VALUE_NOT_CHANGED; |
5073 | } | |
5074 | } | |
5075 | else | |
5076 | { | |
5077 | /* This seems like the only logical thing to do because | |
dda83cd7 SM |
5078 | if we temporarily ignored the watchpoint, then when |
5079 | we reenter the block in which it is valid it contains | |
5080 | garbage (in the case of a function, it may have two | |
5081 | garbage values, one before and one after the prologue). | |
5082 | So we can't even detect the first assignment to it and | |
5083 | watch after that (since the garbage may or may not equal | |
5084 | the first value assigned). */ | |
348d480f | 5085 | /* We print all the stop information in |
c47614fe TT |
5086 | breakpointprint_it, but in this case, by the time we |
5087 | call breakpoint->print_it this bp will be deleted | |
348d480f PA |
5088 | already. So we have no choice but print the information |
5089 | here. */ | |
468afe6c | 5090 | |
0e454242 | 5091 | SWITCH_THRU_ALL_UIS () |
dda83cd7 | 5092 | { |
468afe6c PA |
5093 | struct ui_out *uiout = current_uiout; |
5094 | ||
112e8700 SM |
5095 | if (uiout->is_mi_like_p ()) |
5096 | uiout->field_string | |
5097 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
6a831f06 PA |
5098 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
5099 | "left the block in\n" | |
5100 | "which its expression is valid.\n", | |
5101 | signed_field ("wpnum", b->number)); | |
468afe6c | 5102 | } |
4ce44c66 | 5103 | |
cdac0397 | 5104 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 5105 | b->commands = NULL; |
d0fb5eae | 5106 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5107 | |
5108 | return WP_DELETED; | |
5109 | } | |
5110 | } | |
5111 | ||
18a18393 | 5112 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5113 | breakpoint location BL. This function does not check if we should |
5114 | stop, only if BL explains the stop. */ | |
5115 | ||
18a18393 | 5116 | static int |
6c95b8df | 5117 | bpstat_check_location (const struct bp_location *bl, |
accd0bcd | 5118 | const address_space *aspace, CORE_ADDR bp_addr, |
c272a98c | 5119 | const target_waitstatus &ws) |
18a18393 VP |
5120 | { |
5121 | struct breakpoint *b = bl->owner; | |
5122 | ||
348d480f | 5123 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5124 | gdb_assert (b != NULL); |
5125 | ||
c47614fe | 5126 | return b->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5127 | } |
5128 | ||
3a5c3e22 PA |
5129 | /* Determine if the watched values have actually changed, and we |
5130 | should stop. If not, set BS->stop to 0. */ | |
5131 | ||
18a18393 | 5132 | static void |
313f3b21 | 5133 | bpstat_check_watchpoint (bpstat *bs) |
18a18393 | 5134 | { |
2bdf28a0 | 5135 | const struct bp_location *bl; |
3a5c3e22 | 5136 | struct watchpoint *b; |
2bdf28a0 JK |
5137 | |
5138 | /* BS is built for existing struct breakpoint. */ | |
b6433ede | 5139 | bl = bs->bp_location_at.get (); |
2bdf28a0 | 5140 | gdb_assert (bl != NULL); |
3a5c3e22 | 5141 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5142 | gdb_assert (b != NULL); |
18a18393 | 5143 | |
18a18393 | 5144 | { |
18a18393 VP |
5145 | int must_check_value = 0; |
5146 | ||
c1fc2657 | 5147 | if (b->type == bp_watchpoint) |
18a18393 VP |
5148 | /* For a software watchpoint, we must always check the |
5149 | watched value. */ | |
5150 | must_check_value = 1; | |
5151 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5152 | /* We have a hardware watchpoint (read, write, or access) | |
5153 | and the target earlier reported an address watched by | |
5154 | this watchpoint. */ | |
5155 | must_check_value = 1; | |
5156 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5157 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5158 | /* We were stopped by a hardware watchpoint, but the target could |
5159 | not report the data address. We must check the watchpoint's | |
5160 | value. Access and read watchpoints are out of luck; without | |
5161 | a data address, we can't figure it out. */ | |
5162 | must_check_value = 1; | |
3a5c3e22 | 5163 | |
18a18393 VP |
5164 | if (must_check_value) |
5165 | { | |
bf469271 PA |
5166 | wp_check_result e; |
5167 | ||
a70b8144 | 5168 | try |
bf469271 PA |
5169 | { |
5170 | e = watchpoint_check (bs); | |
5171 | } | |
230d2906 | 5172 | catch (const gdb_exception &ex) |
bf469271 PA |
5173 | { |
5174 | exception_fprintf (gdb_stderr, ex, | |
5175 | "Error evaluating expression " | |
5176 | "for watchpoint %d\n", | |
5177 | b->number); | |
5178 | ||
5179 | SWITCH_THRU_ALL_UIS () | |
5180 | { | |
6cb06a8c TT |
5181 | gdb_printf (_("Watchpoint %d deleted.\n"), |
5182 | b->number); | |
bf469271 PA |
5183 | } |
5184 | watchpoint_del_at_next_stop (b); | |
5185 | e = WP_DELETED; | |
5186 | } | |
bf469271 | 5187 | |
18a18393 VP |
5188 | switch (e) |
5189 | { | |
5190 | case WP_DELETED: | |
5191 | /* We've already printed what needs to be printed. */ | |
5192 | bs->print_it = print_it_done; | |
5193 | /* Stop. */ | |
5194 | break; | |
60e1c644 PA |
5195 | case WP_IGNORE: |
5196 | bs->print_it = print_it_noop; | |
5197 | bs->stop = 0; | |
5198 | break; | |
18a18393 | 5199 | case WP_VALUE_CHANGED: |
c1fc2657 | 5200 | if (b->type == bp_read_watchpoint) |
18a18393 | 5201 | { |
85d721b8 PA |
5202 | /* There are two cases to consider here: |
5203 | ||
4a64f543 | 5204 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5205 | In that case, trust the target, and always report |
5206 | the watchpoint hit to the user. Even though | |
5207 | reads don't cause value changes, the value may | |
5208 | have changed since the last time it was read, and | |
5209 | since we're not trapping writes, we will not see | |
5210 | those, and as such we should ignore our notion of | |
5211 | old value. | |
5212 | ||
4a64f543 | 5213 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5214 | reads and writes. There are two ways this may |
5215 | happen: | |
5216 | ||
4a64f543 | 5217 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5218 | reads only, but can break on accesses (reads or |
5219 | writes), such as e.g., x86. We detect this case | |
5220 | at the time we try to insert read watchpoints. | |
5221 | ||
4a64f543 | 5222 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5223 | watchpoints, but, the user set an access or write |
5224 | watchpoint watching the same memory as this read | |
5225 | watchpoint. | |
5226 | ||
5227 | If we're watching memory writes as well as reads, | |
5228 | ignore watchpoint hits when we find that the | |
5229 | value hasn't changed, as reads don't cause | |
5230 | changes. This still gives false positives when | |
5231 | the program writes the same value to memory as | |
5232 | what there was already in memory (we will confuse | |
5233 | it for a read), but it's much better than | |
5234 | nothing. */ | |
5235 | ||
5236 | int other_write_watchpoint = 0; | |
5237 | ||
5238 | if (bl->watchpoint_type == hw_read) | |
5239 | { | |
43892fdf | 5240 | for (breakpoint *other_b : all_breakpoints ()) |
3a5c3e22 PA |
5241 | if (other_b->type == bp_hardware_watchpoint |
5242 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5243 | { |
3a5c3e22 PA |
5244 | struct watchpoint *other_w = |
5245 | (struct watchpoint *) other_b; | |
5246 | ||
5247 | if (other_w->watchpoint_triggered | |
5248 | == watch_triggered_yes) | |
5249 | { | |
5250 | other_write_watchpoint = 1; | |
5251 | break; | |
5252 | } | |
85d721b8 PA |
5253 | } |
5254 | } | |
5255 | ||
5256 | if (other_write_watchpoint | |
5257 | || bl->watchpoint_type == hw_access) | |
5258 | { | |
5259 | /* We're watching the same memory for writes, | |
5260 | and the value changed since the last time we | |
5261 | updated it, so this trap must be for a write. | |
5262 | Ignore it. */ | |
5263 | bs->print_it = print_it_noop; | |
5264 | bs->stop = 0; | |
5265 | } | |
18a18393 VP |
5266 | } |
5267 | break; | |
5268 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5269 | if (b->type == bp_hardware_watchpoint |
5270 | || b->type == bp_watchpoint) | |
18a18393 VP |
5271 | { |
5272 | /* Don't stop: write watchpoints shouldn't fire if | |
5273 | the value hasn't changed. */ | |
5274 | bs->print_it = print_it_noop; | |
5275 | bs->stop = 0; | |
5276 | } | |
5277 | /* Stop. */ | |
5278 | break; | |
5279 | default: | |
5280 | /* Can't happen. */ | |
18a18393 VP |
5281 | break; |
5282 | } | |
5283 | } | |
5284 | else /* must_check_value == 0 */ | |
5285 | { | |
5286 | /* This is a case where some watchpoint(s) triggered, but | |
5287 | not at the address of this watchpoint, or else no | |
5288 | watchpoint triggered after all. So don't print | |
5289 | anything for this watchpoint. */ | |
5290 | bs->print_it = print_it_noop; | |
5291 | bs->stop = 0; | |
5292 | } | |
5293 | } | |
5294 | } | |
5295 | ||
7d4df6a4 DE |
5296 | /* For breakpoints that are currently marked as telling gdb to stop, |
5297 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5298 | of breakpoint referred to by BS. If we should not stop for this |
5299 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5300 | |
18a18393 | 5301 | static void |
313f3b21 | 5302 | bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread) |
18a18393 | 5303 | { |
2bdf28a0 JK |
5304 | const struct bp_location *bl; |
5305 | struct breakpoint *b; | |
bf469271 PA |
5306 | /* Assume stop. */ |
5307 | bool condition_result = true; | |
7d4df6a4 DE |
5308 | struct expression *cond; |
5309 | ||
5310 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5311 | |
5312 | /* BS is built for existing struct breakpoint. */ | |
b6433ede | 5313 | bl = bs->bp_location_at.get (); |
2bdf28a0 | 5314 | gdb_assert (bl != NULL); |
f431efe5 | 5315 | b = bs->breakpoint_at; |
2bdf28a0 | 5316 | gdb_assert (b != NULL); |
18a18393 | 5317 | |
b775012e LM |
5318 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5319 | need to do so again since GDB does not know if we stopped due to a | |
5320 | breakpoint or a single step breakpoint. */ | |
5321 | ||
18a18393 | 5322 | if (frame_id_p (b->frame_id) |
edb3359d | 5323 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5324 | { |
7d4df6a4 DE |
5325 | bs->stop = 0; |
5326 | return; | |
5327 | } | |
60e1c644 | 5328 | |
12ab52e9 PA |
5329 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5330 | evaluating the condition if this isn't the specified | |
5331 | thread/task. */ | |
00431a78 PA |
5332 | if ((b->thread != -1 && b->thread != thread->global_num) |
5333 | || (b->task != 0 && b->task != ada_get_task_number (thread))) | |
6c1b0f7b DE |
5334 | { |
5335 | bs->stop = 0; | |
5336 | return; | |
5337 | } | |
5338 | ||
6dddc817 DE |
5339 | /* Evaluate extension language breakpoints that have a "stop" method |
5340 | implemented. */ | |
5341 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5342 | |
7d4df6a4 DE |
5343 | if (is_watchpoint (b)) |
5344 | { | |
5345 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5346 | |
4d01a485 | 5347 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5348 | } |
5349 | else | |
4d01a485 | 5350 | cond = bl->cond.get (); |
60e1c644 | 5351 | |
7d4df6a4 DE |
5352 | if (cond && b->disposition != disp_del_at_next_stop) |
5353 | { | |
5354 | int within_current_scope = 1; | |
5355 | struct watchpoint * w; | |
60e1c644 | 5356 | |
7d4df6a4 DE |
5357 | /* We use value_mark and value_free_to_mark because it could |
5358 | be a long time before we return to the command level and | |
5359 | call free_all_values. We can't call free_all_values | |
5360 | because we might be in the middle of evaluating a | |
5361 | function call. */ | |
5362 | struct value *mark = value_mark (); | |
5363 | ||
5364 | if (is_watchpoint (b)) | |
5365 | w = (struct watchpoint *) b; | |
5366 | else | |
5367 | w = NULL; | |
5368 | ||
5369 | /* Need to select the frame, with all that implies so that | |
5370 | the conditions will have the right context. Because we | |
5371 | use the frame, we will not see an inlined function's | |
5372 | variables when we arrive at a breakpoint at the start | |
5373 | of the inlined function; the current frame will be the | |
5374 | call site. */ | |
5375 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5376 | select_frame (get_current_frame ()); | |
5377 | else | |
18a18393 | 5378 | { |
7d4df6a4 DE |
5379 | struct frame_info *frame; |
5380 | ||
5381 | /* For local watchpoint expressions, which particular | |
5382 | instance of a local is being watched matters, so we | |
5383 | keep track of the frame to evaluate the expression | |
5384 | in. To evaluate the condition however, it doesn't | |
5385 | really matter which instantiation of the function | |
5386 | where the condition makes sense triggers the | |
5387 | watchpoint. This allows an expression like "watch | |
5388 | global if q > 10" set in `func', catch writes to | |
5389 | global on all threads that call `func', or catch | |
5390 | writes on all recursive calls of `func' by a single | |
5391 | thread. We simply always evaluate the condition in | |
5392 | the innermost frame that's executing where it makes | |
5393 | sense to evaluate the condition. It seems | |
5394 | intuitive. */ | |
5395 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5396 | if (frame != NULL) | |
5397 | select_frame (frame); | |
5398 | else | |
5399 | within_current_scope = 0; | |
18a18393 | 5400 | } |
7d4df6a4 | 5401 | if (within_current_scope) |
bf469271 | 5402 | { |
a70b8144 | 5403 | try |
bf469271 PA |
5404 | { |
5405 | condition_result = breakpoint_cond_eval (cond); | |
5406 | } | |
230d2906 | 5407 | catch (const gdb_exception &ex) |
bf469271 PA |
5408 | { |
5409 | exception_fprintf (gdb_stderr, ex, | |
5410 | "Error in testing breakpoint condition:\n"); | |
5411 | } | |
bf469271 | 5412 | } |
7d4df6a4 | 5413 | else |
18a18393 | 5414 | { |
7d4df6a4 DE |
5415 | warning (_("Watchpoint condition cannot be tested " |
5416 | "in the current scope")); | |
5417 | /* If we failed to set the right context for this | |
5418 | watchpoint, unconditionally report it. */ | |
18a18393 | 5419 | } |
7d4df6a4 DE |
5420 | /* FIXME-someday, should give breakpoint #. */ |
5421 | value_free_to_mark (mark); | |
18a18393 | 5422 | } |
7d4df6a4 | 5423 | |
bf469271 | 5424 | if (cond && !condition_result) |
7d4df6a4 DE |
5425 | { |
5426 | bs->stop = 0; | |
5427 | } | |
7d4df6a4 DE |
5428 | else if (b->ignore_count > 0) |
5429 | { | |
5430 | b->ignore_count--; | |
5431 | bs->stop = 0; | |
5432 | /* Increase the hit count even though we don't stop. */ | |
5433 | ++(b->hit_count); | |
76727919 | 5434 | gdb::observers::breakpoint_modified.notify (b); |
7d4df6a4 | 5435 | } |
18a18393 VP |
5436 | } |
5437 | ||
1cf4d951 PA |
5438 | /* Returns true if we need to track moribund locations of LOC's type |
5439 | on the current target. */ | |
5440 | ||
5441 | static int | |
5442 | need_moribund_for_location_type (struct bp_location *loc) | |
5443 | { | |
5444 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5445 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5446 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5447 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5448 | } | |
5449 | ||
ddfe970e | 5450 | /* See breakpoint.h. */ |
c906108c | 5451 | |
313f3b21 | 5452 | bpstat * |
ddfe970e | 5453 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
c272a98c | 5454 | const target_waitstatus &ws) |
c906108c | 5455 | { |
313f3b21 | 5456 | bpstat *bs_head = nullptr, **bs_link = &bs_head; |
c5aa993b | 5457 | |
43892fdf | 5458 | for (breakpoint *b : all_breakpoints ()) |
429374b8 | 5459 | { |
1a853c52 | 5460 | if (!breakpoint_enabled (b)) |
429374b8 | 5461 | continue; |
a5606eee | 5462 | |
40cb8ca5 | 5463 | for (bp_location *bl : b->locations ()) |
429374b8 | 5464 | { |
4a64f543 MS |
5465 | /* For hardware watchpoints, we look only at the first |
5466 | location. The watchpoint_check function will work on the | |
5467 | entire expression, not the individual locations. For | |
5468 | read watchpoints, the watchpoints_triggered function has | |
5469 | checked all locations already. */ | |
429374b8 JK |
5470 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5471 | break; | |
18a18393 | 5472 | |
b5fa468f | 5473 | if (!bl->enabled || bl->disabled_by_cond || bl->shlib_disabled) |
429374b8 | 5474 | continue; |
c5aa993b | 5475 | |
09ac7c10 | 5476 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5477 | continue; |
c5aa993b | 5478 | |
4a64f543 MS |
5479 | /* Come here if it's a watchpoint, or if the break address |
5480 | matches. */ | |
c5aa993b | 5481 | |
313f3b21 | 5482 | bpstat *bs = new bpstat (bl, &bs_link); /* Alloc a bpstat to |
ddfe970e | 5483 | explain stop. */ |
c5aa993b | 5484 | |
f431efe5 PA |
5485 | /* Assume we stop. Should we find a watchpoint that is not |
5486 | actually triggered, or if the condition of the breakpoint | |
5487 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5488 | bs->stop = 1; |
5489 | bs->print = 1; | |
d983da9c | 5490 | |
f431efe5 PA |
5491 | /* If this is a scope breakpoint, mark the associated |
5492 | watchpoint as triggered so that we will handle the | |
5493 | out-of-scope event. We'll get to the watchpoint next | |
5494 | iteration. */ | |
d0fb5eae | 5495 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5496 | { |
5497 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5498 | ||
5499 | w->watchpoint_triggered = watch_triggered_yes; | |
5500 | } | |
f431efe5 PA |
5501 | } |
5502 | } | |
5503 | ||
7c16b83e | 5504 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5505 | if (!target_supports_stopped_by_sw_breakpoint () |
5506 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5507 | { |
1123588c | 5508 | for (bp_location *loc : moribund_locations) |
f431efe5 | 5509 | { |
1cf4d951 PA |
5510 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5511 | && need_moribund_for_location_type (loc)) | |
5512 | { | |
313f3b21 | 5513 | bpstat *bs = new bpstat (loc, &bs_link); |
1cf4d951 PA |
5514 | /* For hits of moribund locations, we should just proceed. */ |
5515 | bs->stop = 0; | |
5516 | bs->print = 0; | |
5517 | bs->print_it = print_it_noop; | |
5518 | } | |
f431efe5 PA |
5519 | } |
5520 | } | |
5521 | ||
ddfe970e KS |
5522 | return bs_head; |
5523 | } | |
5524 | ||
5525 | /* See breakpoint.h. */ | |
5526 | ||
313f3b21 | 5527 | bpstat * |
ddfe970e | 5528 | bpstat_stop_status (const address_space *aspace, |
00431a78 | 5529 | CORE_ADDR bp_addr, thread_info *thread, |
c272a98c | 5530 | const target_waitstatus &ws, |
313f3b21 | 5531 | bpstat *stop_chain) |
ddfe970e KS |
5532 | { |
5533 | struct breakpoint *b = NULL; | |
5534 | /* First item of allocated bpstat's. */ | |
313f3b21 SM |
5535 | bpstat *bs_head = stop_chain; |
5536 | bpstat *bs; | |
ddfe970e KS |
5537 | int need_remove_insert; |
5538 | int removed_any; | |
5539 | ||
5540 | /* First, build the bpstat chain with locations that explain a | |
5541 | target stop, while being careful to not set the target running, | |
5542 | as that may invalidate locations (in particular watchpoint | |
5543 | locations are recreated). Resuming will happen here with | |
5544 | breakpoint conditions or watchpoint expressions that include | |
5545 | inferior function calls. */ | |
5546 | if (bs_head == NULL) | |
5547 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); | |
5548 | ||
edcc5120 TT |
5549 | /* A bit of special processing for shlib breakpoints. We need to |
5550 | process solib loading here, so that the lists of loaded and | |
5551 | unloaded libraries are correct before we handle "catch load" and | |
5552 | "catch unload". */ | |
5553 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5554 | { | |
5d268276 | 5555 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5556 | { |
5557 | handle_solib_event (); | |
5558 | break; | |
5559 | } | |
5560 | } | |
5561 | ||
f431efe5 PA |
5562 | /* Now go through the locations that caused the target to stop, and |
5563 | check whether we're interested in reporting this stop to higher | |
5564 | layers, or whether we should resume the target transparently. */ | |
5565 | ||
5566 | removed_any = 0; | |
5567 | ||
5760d0ab | 5568 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5569 | { |
5570 | if (!bs->stop) | |
5571 | continue; | |
5572 | ||
f431efe5 | 5573 | b = bs->breakpoint_at; |
c47614fe | 5574 | b->check_status (bs); |
348d480f | 5575 | if (bs->stop) |
28010a5d | 5576 | { |
00431a78 | 5577 | bpstat_check_breakpoint_conditions (bs, thread); |
f431efe5 | 5578 | |
429374b8 JK |
5579 | if (bs->stop) |
5580 | { | |
5581 | ++(b->hit_count); | |
c906108c | 5582 | |
4a64f543 | 5583 | /* We will stop here. */ |
429374b8 JK |
5584 | if (b->disposition == disp_disable) |
5585 | { | |
816338b5 | 5586 | --(b->enable_count); |
1a853c52 | 5587 | if (b->enable_count <= 0) |
429374b8 | 5588 | b->enable_state = bp_disabled; |
f431efe5 | 5589 | removed_any = 1; |
429374b8 | 5590 | } |
bd7ccaa9 | 5591 | gdb::observers::breakpoint_modified.notify (b); |
429374b8 JK |
5592 | if (b->silent) |
5593 | bs->print = 0; | |
5594 | bs->commands = b->commands; | |
abf85f46 | 5595 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5596 | ? bs->commands.get () : NULL)) |
abf85f46 | 5597 | bs->print = 0; |
9d6e6e84 | 5598 | |
c47614fe | 5599 | b->after_condition_true (bs); |
429374b8 JK |
5600 | } |
5601 | ||
348d480f | 5602 | } |
a9b3a50f PA |
5603 | |
5604 | /* Print nothing for this entry if we don't stop or don't | |
5605 | print. */ | |
5606 | if (!bs->stop || !bs->print) | |
5607 | bs->print_it = print_it_noop; | |
429374b8 | 5608 | } |
876fa593 | 5609 | |
d983da9c DJ |
5610 | /* If we aren't stopping, the value of some hardware watchpoint may |
5611 | not have changed, but the intermediate memory locations we are | |
5612 | watching may have. Don't bother if we're stopping; this will get | |
5613 | done later. */ | |
d832cb68 | 5614 | need_remove_insert = 0; |
5760d0ab JK |
5615 | if (! bpstat_causes_stop (bs_head)) |
5616 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5617 | if (!bs->stop |
f431efe5 PA |
5618 | && bs->breakpoint_at |
5619 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5620 | { |
3a5c3e22 PA |
5621 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5622 | ||
5623 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5624 | need_remove_insert = 1; |
d983da9c DJ |
5625 | } |
5626 | ||
d832cb68 | 5627 | if (need_remove_insert) |
44702360 | 5628 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5629 | else if (removed_any) |
44702360 | 5630 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5631 | |
5760d0ab | 5632 | return bs_head; |
c906108c | 5633 | } |
628fe4e4 | 5634 | |
d37e0847 PA |
5635 | /* See breakpoint.h. */ |
5636 | ||
5637 | bpstat * | |
5638 | bpstat_stop_status_nowatch (const address_space *aspace, CORE_ADDR bp_addr, | |
5639 | thread_info *thread, const target_waitstatus &ws) | |
5640 | { | |
5641 | gdb_assert (!target_stopped_by_watchpoint ()); | |
5642 | ||
5643 | /* Clear all watchpoints' 'watchpoint_triggered' value from a | |
5644 | previous stop to avoid confusing bpstat_stop_status. */ | |
5645 | watchpoints_triggered (ws); | |
5646 | ||
5647 | return bpstat_stop_status (aspace, bp_addr, thread, ws); | |
5648 | } | |
5649 | ||
628fe4e4 | 5650 | static void |
61c26be8 | 5651 | handle_jit_event (CORE_ADDR address) |
628fe4e4 | 5652 | { |
628fe4e4 JK |
5653 | struct gdbarch *gdbarch; |
5654 | ||
1eb8556f | 5655 | infrun_debug_printf ("handling bp_jit_event"); |
243a9253 | 5656 | |
628fe4e4 JK |
5657 | /* Switch terminal for any messages produced by |
5658 | breakpoint_re_set. */ | |
223ffa71 | 5659 | target_terminal::ours_for_output (); |
628fe4e4 | 5660 | |
61c26be8 MS |
5661 | gdbarch = get_frame_arch (get_current_frame ()); |
5662 | /* This event is caused by a breakpoint set in `jit_breakpoint_re_set`, | |
5663 | thus it is expected that its objectfile can be found through | |
5664 | minimal symbol lookup. If it doesn't work (and assert fails), it | |
5665 | most likely means that `jit_breakpoint_re_set` was changes and this | |
5666 | function needs to be updated too. */ | |
5667 | bound_minimal_symbol jit_bp_sym = lookup_minimal_symbol_by_pc (address); | |
5668 | gdb_assert (jit_bp_sym.objfile != nullptr); | |
5669 | jit_event_handler (gdbarch, jit_bp_sym.objfile); | |
628fe4e4 | 5670 | |
223ffa71 | 5671 | target_terminal::inferior (); |
628fe4e4 JK |
5672 | } |
5673 | ||
5674 | /* Prepare WHAT final decision for infrun. */ | |
5675 | ||
5676 | /* Decide what infrun needs to do with this bpstat. */ | |
5677 | ||
c906108c | 5678 | struct bpstat_what |
313f3b21 | 5679 | bpstat_what (bpstat *bs_head) |
c906108c | 5680 | { |
c906108c | 5681 | struct bpstat_what retval; |
313f3b21 | 5682 | bpstat *bs; |
c906108c | 5683 | |
628fe4e4 | 5684 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5685 | retval.call_dummy = STOP_NONE; |
e2d0f980 | 5686 | retval.is_longjmp = false; |
628fe4e4 | 5687 | |
0e30163f | 5688 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5689 | { |
628fe4e4 JK |
5690 | /* Extract this BS's action. After processing each BS, we check |
5691 | if its action overrides all we've seem so far. */ | |
5692 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5693 | enum bptype bptype; | |
5694 | ||
c906108c | 5695 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5696 | { |
5697 | /* I suspect this can happen if it was a momentary | |
5698 | breakpoint which has since been deleted. */ | |
5699 | bptype = bp_none; | |
5700 | } | |
20874c92 | 5701 | else |
f431efe5 | 5702 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5703 | |
5704 | switch (bptype) | |
c906108c SS |
5705 | { |
5706 | case bp_none: | |
628fe4e4 | 5707 | break; |
c906108c SS |
5708 | case bp_breakpoint: |
5709 | case bp_hardware_breakpoint: | |
7c16b83e | 5710 | case bp_single_step: |
c906108c SS |
5711 | case bp_until: |
5712 | case bp_finish: | |
a9b3a50f | 5713 | case bp_shlib_event: |
c906108c SS |
5714 | if (bs->stop) |
5715 | { | |
5716 | if (bs->print) | |
628fe4e4 | 5717 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5718 | else |
628fe4e4 | 5719 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5720 | } |
5721 | else | |
628fe4e4 | 5722 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5723 | break; |
5724 | case bp_watchpoint: | |
5725 | case bp_hardware_watchpoint: | |
5726 | case bp_read_watchpoint: | |
5727 | case bp_access_watchpoint: | |
5728 | if (bs->stop) | |
5729 | { | |
5730 | if (bs->print) | |
628fe4e4 | 5731 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5732 | else |
628fe4e4 | 5733 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5734 | } |
5735 | else | |
628fe4e4 JK |
5736 | { |
5737 | /* There was a watchpoint, but we're not stopping. | |
5738 | This requires no further action. */ | |
5739 | } | |
c906108c SS |
5740 | break; |
5741 | case bp_longjmp: | |
e2e4d78b | 5742 | case bp_longjmp_call_dummy: |
186c406b | 5743 | case bp_exception: |
0a39bb32 PA |
5744 | if (bs->stop) |
5745 | { | |
5746 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5747 | retval.is_longjmp = bptype != bp_exception; | |
5748 | } | |
5749 | else | |
5750 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5751 | break; |
5752 | case bp_longjmp_resume: | |
186c406b | 5753 | case bp_exception_resume: |
0a39bb32 PA |
5754 | if (bs->stop) |
5755 | { | |
5756 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5757 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5758 | } | |
5759 | else | |
5760 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5761 | break; |
5762 | case bp_step_resume: | |
5763 | if (bs->stop) | |
628fe4e4 JK |
5764 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5765 | else | |
c906108c | 5766 | { |
628fe4e4 JK |
5767 | /* It is for the wrong frame. */ |
5768 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5769 | } |
c906108c | 5770 | break; |
2c03e5be PA |
5771 | case bp_hp_step_resume: |
5772 | if (bs->stop) | |
5773 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5774 | else | |
5775 | { | |
5776 | /* It is for the wrong frame. */ | |
5777 | this_action = BPSTAT_WHAT_SINGLE; | |
5778 | } | |
5779 | break; | |
c906108c | 5780 | case bp_watchpoint_scope: |
c4093a6a | 5781 | case bp_thread_event: |
1900040c | 5782 | case bp_overlay_event: |
0fd8e87f | 5783 | case bp_longjmp_master: |
aa7d318d | 5784 | case bp_std_terminate_master: |
186c406b | 5785 | case bp_exception_master: |
628fe4e4 | 5786 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5787 | break; |
ce78b96d | 5788 | case bp_catchpoint: |
c5aa993b JM |
5789 | if (bs->stop) |
5790 | { | |
5791 | if (bs->print) | |
628fe4e4 | 5792 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5793 | else |
628fe4e4 | 5794 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5795 | } |
5796 | else | |
628fe4e4 | 5797 | { |
cb1e4e32 PA |
5798 | /* Some catchpoints are implemented with breakpoints. |
5799 | For those, we need to step over the breakpoint. */ | |
5800 | if (bs->bp_location_at->loc_type != bp_loc_other) | |
5801 | this_action = BPSTAT_WHAT_SINGLE; | |
628fe4e4 JK |
5802 | } |
5803 | break; | |
628fe4e4 | 5804 | case bp_jit_event: |
628fe4e4 | 5805 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5806 | break; |
c906108c | 5807 | case bp_call_dummy: |
53a5351d JM |
5808 | /* Make sure the action is stop (silent or noisy), |
5809 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5810 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5811 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5812 | break; |
5813 | case bp_std_terminate: | |
5814 | /* Make sure the action is stop (silent or noisy), | |
5815 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5816 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5817 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5818 | break; |
1042e4c0 | 5819 | case bp_tracepoint: |
7a697b8d | 5820 | case bp_fast_tracepoint: |
0fb4aa4b | 5821 | case bp_static_tracepoint: |
7b572efb | 5822 | case bp_static_marker_tracepoint: |
1042e4c0 SS |
5823 | /* Tracepoint hits should not be reported back to GDB, and |
5824 | if one got through somehow, it should have been filtered | |
5825 | out already. */ | |
5826 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5827 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5828 | break; |
5829 | case bp_gnu_ifunc_resolver: | |
5830 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5831 | this_action = BPSTAT_WHAT_SINGLE; | |
5832 | break; | |
5833 | case bp_gnu_ifunc_resolver_return: | |
5834 | /* The breakpoint will be removed, execution will restart from the | |
5835 | PC of the former breakpoint. */ | |
5836 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5837 | break; | |
e7e0cddf SS |
5838 | |
5839 | case bp_dprintf: | |
a11cfd87 HZ |
5840 | if (bs->stop) |
5841 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5842 | else | |
5843 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5844 | break; |
5845 | ||
628fe4e4 JK |
5846 | default: |
5847 | internal_error (__FILE__, __LINE__, | |
5848 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5849 | } |
628fe4e4 | 5850 | |
325fac50 | 5851 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5852 | } |
628fe4e4 | 5853 | |
243a9253 PA |
5854 | return retval; |
5855 | } | |
628fe4e4 | 5856 | |
243a9253 | 5857 | void |
313f3b21 | 5858 | bpstat_run_callbacks (bpstat *bs_head) |
243a9253 | 5859 | { |
313f3b21 | 5860 | bpstat *bs; |
628fe4e4 | 5861 | |
0e30163f JK |
5862 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5863 | { | |
5864 | struct breakpoint *b = bs->breakpoint_at; | |
5865 | ||
5866 | if (b == NULL) | |
5867 | continue; | |
5868 | switch (b->type) | |
5869 | { | |
243a9253 | 5870 | case bp_jit_event: |
61c26be8 | 5871 | handle_jit_event (bs->bp_location_at->address); |
243a9253 | 5872 | break; |
0e30163f JK |
5873 | case bp_gnu_ifunc_resolver: |
5874 | gnu_ifunc_resolver_stop (b); | |
5875 | break; | |
5876 | case bp_gnu_ifunc_resolver_return: | |
5877 | gnu_ifunc_resolver_return_stop (b); | |
5878 | break; | |
5879 | } | |
5880 | } | |
c906108c SS |
5881 | } |
5882 | ||
4c462cb0 | 5883 | /* See breakpoint.h. */ |
c906108c | 5884 | |
4c462cb0 SM |
5885 | bool |
5886 | bpstat_should_step () | |
c906108c | 5887 | { |
43892fdf | 5888 | for (breakpoint *b : all_breakpoints ()) |
717a8278 | 5889 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
4c462cb0 | 5890 | return true; |
43892fdf | 5891 | |
4c462cb0 | 5892 | return false; |
c906108c SS |
5893 | } |
5894 | ||
4c462cb0 SM |
5895 | /* See breakpoint.h. */ |
5896 | ||
5897 | bool | |
313f3b21 | 5898 | bpstat_causes_stop (bpstat *bs) |
67822962 PA |
5899 | { |
5900 | for (; bs != NULL; bs = bs->next) | |
5901 | if (bs->stop) | |
4c462cb0 | 5902 | return true; |
67822962 | 5903 | |
4c462cb0 | 5904 | return false; |
67822962 PA |
5905 | } |
5906 | ||
c906108c | 5907 | \f |
c5aa993b | 5908 | |
6c92c339 | 5909 | /* Compute a number of spaces suitable to indent the next line |
170b53b2 UW |
5910 | so it starts at the position corresponding to the table column |
5911 | named COL_NAME in the currently active table of UIOUT. */ | |
5912 | ||
6c92c339 | 5913 | static int |
170b53b2 UW |
5914 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) |
5915 | { | |
170b53b2 | 5916 | int i, total_width, width, align; |
c5209615 | 5917 | const char *text; |
170b53b2 UW |
5918 | |
5919 | total_width = 0; | |
112e8700 | 5920 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5921 | { |
5922 | if (strcmp (text, col_name) == 0) | |
6c92c339 | 5923 | return total_width; |
170b53b2 UW |
5924 | |
5925 | total_width += width + 1; | |
5926 | } | |
5927 | ||
6c92c339 | 5928 | return 0; |
170b53b2 UW |
5929 | } |
5930 | ||
b775012e LM |
5931 | /* Determine if the locations of this breakpoint will have their conditions |
5932 | evaluated by the target, host or a mix of both. Returns the following: | |
5933 | ||
5934 | "host": Host evals condition. | |
5935 | "host or target": Host or Target evals condition. | |
5936 | "target": Target evals condition. | |
5937 | */ | |
5938 | ||
5939 | static const char * | |
5940 | bp_condition_evaluator (struct breakpoint *b) | |
5941 | { | |
b775012e LM |
5942 | char host_evals = 0; |
5943 | char target_evals = 0; | |
5944 | ||
5945 | if (!b) | |
5946 | return NULL; | |
5947 | ||
5948 | if (!is_breakpoint (b)) | |
5949 | return NULL; | |
5950 | ||
5951 | if (gdb_evaluates_breakpoint_condition_p () | |
5952 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5953 | return condition_evaluation_host; | |
5954 | ||
40cb8ca5 | 5955 | for (bp_location *bl : b->locations ()) |
b775012e LM |
5956 | { |
5957 | if (bl->cond_bytecode) | |
5958 | target_evals++; | |
5959 | else | |
5960 | host_evals++; | |
5961 | } | |
5962 | ||
5963 | if (host_evals && target_evals) | |
5964 | return condition_evaluation_both; | |
5965 | else if (target_evals) | |
5966 | return condition_evaluation_target; | |
5967 | else | |
5968 | return condition_evaluation_host; | |
5969 | } | |
5970 | ||
5971 | /* Determine the breakpoint location's condition evaluator. This is | |
5972 | similar to bp_condition_evaluator, but for locations. */ | |
5973 | ||
5974 | static const char * | |
5975 | bp_location_condition_evaluator (struct bp_location *bl) | |
5976 | { | |
5977 | if (bl && !is_breakpoint (bl->owner)) | |
5978 | return NULL; | |
5979 | ||
5980 | if (gdb_evaluates_breakpoint_condition_p () | |
5981 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5982 | return condition_evaluation_host; | |
5983 | ||
5984 | if (bl && bl->cond_bytecode) | |
5985 | return condition_evaluation_target; | |
5986 | else | |
5987 | return condition_evaluation_host; | |
5988 | } | |
5989 | ||
859825b8 JK |
5990 | /* Print the LOC location out of the list of B->LOC locations. */ |
5991 | ||
170b53b2 UW |
5992 | static void |
5993 | print_breakpoint_location (struct breakpoint *b, | |
5994 | struct bp_location *loc) | |
0d381245 | 5995 | { |
79a45e25 | 5996 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
5997 | |
5998 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 5999 | |
859825b8 JK |
6000 | if (loc != NULL && loc->shlib_disabled) |
6001 | loc = NULL; | |
6002 | ||
6c95b8df PA |
6003 | if (loc != NULL) |
6004 | set_current_program_space (loc->pspace); | |
6005 | ||
56435ebe | 6006 | if (b->display_canonical) |
d28cd78a | 6007 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 6008 | else if (loc && loc->symtab) |
0d381245 | 6009 | { |
4a27f119 KS |
6010 | const struct symbol *sym = loc->symbol; |
6011 | ||
0d381245 VP |
6012 | if (sym) |
6013 | { | |
112e8700 | 6014 | uiout->text ("in "); |
987012b8 | 6015 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 6016 | function_name_style.style ()); |
112e8700 SM |
6017 | uiout->text (" "); |
6018 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
6019 | uiout->text ("at "); | |
0d381245 | 6020 | } |
112e8700 | 6021 | uiout->field_string ("file", |
cbe56571 | 6022 | symtab_to_filename_for_display (loc->symtab), |
e43b10e1 | 6023 | file_name_style.style ()); |
112e8700 | 6024 | uiout->text (":"); |
05cba821 | 6025 | |
112e8700 SM |
6026 | if (uiout->is_mi_like_p ()) |
6027 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6028 | |
381befee | 6029 | uiout->field_signed ("line", loc->line_number); |
0d381245 | 6030 | } |
859825b8 | 6031 | else if (loc) |
0d381245 | 6032 | { |
d7e74731 | 6033 | string_file stb; |
170b53b2 | 6034 | |
d7e74731 | 6035 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6036 | demangle, ""); |
112e8700 | 6037 | uiout->field_stream ("at", stb); |
0d381245 | 6038 | } |
859825b8 | 6039 | else |
f00aae0f | 6040 | { |
d28cd78a TT |
6041 | uiout->field_string ("pending", |
6042 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
6043 | /* If extra_string is available, it could be holding a condition |
6044 | or dprintf arguments. In either case, make sure it is printed, | |
6045 | too, but only for non-MI streams. */ | |
112e8700 | 6046 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6047 | { |
6048 | if (b->type == bp_dprintf) | |
112e8700 | 6049 | uiout->text (","); |
f00aae0f | 6050 | else |
112e8700 | 6051 | uiout->text (" "); |
6f781ee3 | 6052 | uiout->text (b->extra_string.get ()); |
f00aae0f KS |
6053 | } |
6054 | } | |
6c95b8df | 6055 | |
b775012e LM |
6056 | if (loc && is_breakpoint (b) |
6057 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6058 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6059 | { | |
112e8700 SM |
6060 | uiout->text (" ("); |
6061 | uiout->field_string ("evaluated-by", | |
b775012e | 6062 | bp_location_condition_evaluator (loc)); |
112e8700 | 6063 | uiout->text (")"); |
b775012e | 6064 | } |
0d381245 VP |
6065 | } |
6066 | ||
269b11a2 PA |
6067 | static const char * |
6068 | bptype_string (enum bptype type) | |
c906108c | 6069 | { |
c4093a6a JM |
6070 | struct ep_type_description |
6071 | { | |
6072 | enum bptype type; | |
a121b7c1 | 6073 | const char *description; |
c4093a6a JM |
6074 | }; |
6075 | static struct ep_type_description bptypes[] = | |
c906108c | 6076 | { |
c5aa993b JM |
6077 | {bp_none, "?deleted?"}, |
6078 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6079 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6080 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6081 | {bp_until, "until"}, |
6082 | {bp_finish, "finish"}, | |
6083 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6084 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6085 | {bp_read_watchpoint, "read watchpoint"}, |
6086 | {bp_access_watchpoint, "acc watchpoint"}, | |
6087 | {bp_longjmp, "longjmp"}, | |
6088 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6089 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6090 | {bp_exception, "exception"}, |
6091 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6092 | {bp_step_resume, "step resume"}, |
2c03e5be | 6093 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6094 | {bp_watchpoint_scope, "watchpoint scope"}, |
6095 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6096 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6097 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6098 | {bp_thread_event, "thread events"}, |
1900040c | 6099 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6100 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6101 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6102 | {bp_exception_master, "exception master"}, |
ce78b96d | 6103 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6104 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6105 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6106 | {bp_static_tracepoint, "static tracepoint"}, |
7b572efb | 6107 | {bp_static_marker_tracepoint, "static marker tracepoint"}, |
e7e0cddf | 6108 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6109 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6110 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6111 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6112 | }; |
269b11a2 PA |
6113 | |
6114 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6115 | || ((int) type != bptypes[(int) type].type)) | |
6116 | internal_error (__FILE__, __LINE__, | |
6117 | _("bptypes table does not describe type #%d."), | |
6118 | (int) type); | |
6119 | ||
6120 | return bptypes[(int) type].description; | |
6121 | } | |
6122 | ||
998580f1 MK |
6123 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6124 | For CLI, prefix the list with the string 'inf'. */ | |
6125 | ||
6126 | static void | |
6127 | output_thread_groups (struct ui_out *uiout, | |
6128 | const char *field_name, | |
5c632425 | 6129 | const std::vector<int> &inf_nums, |
998580f1 MK |
6130 | int mi_only) |
6131 | { | |
112e8700 | 6132 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6133 | |
6134 | /* For backward compatibility, don't display inferiors in CLI unless | |
6135 | there are several. Always display them for MI. */ | |
6136 | if (!is_mi && mi_only) | |
6137 | return; | |
6138 | ||
10f489e5 | 6139 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6140 | |
5c632425 | 6141 | for (size_t i = 0; i < inf_nums.size (); i++) |
998580f1 MK |
6142 | { |
6143 | if (is_mi) | |
6144 | { | |
6145 | char mi_group[10]; | |
6146 | ||
5c632425 | 6147 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
112e8700 | 6148 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6149 | } |
6150 | else | |
6151 | { | |
6152 | if (i == 0) | |
112e8700 | 6153 | uiout->text (" inf "); |
998580f1 | 6154 | else |
112e8700 | 6155 | uiout->text (", "); |
998580f1 | 6156 | |
5c632425 | 6157 | uiout->text (plongest (inf_nums[i])); |
998580f1 MK |
6158 | } |
6159 | } | |
998580f1 MK |
6160 | } |
6161 | ||
a38118e5 PA |
6162 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
6163 | instead of going via breakpoint_ops::print_one. This makes "maint | |
6164 | info breakpoints" show the software breakpoint locations of | |
6165 | catchpoints, which are considered internal implementation | |
c01e038b TT |
6166 | detail. Returns true if RAW_LOC is false and if the breakpoint's |
6167 | print_one method did something; false otherwise. */ | |
269b11a2 | 6168 | |
c01e038b | 6169 | static bool |
269b11a2 PA |
6170 | print_one_breakpoint_location (struct breakpoint *b, |
6171 | struct bp_location *loc, | |
6172 | int loc_number, | |
6173 | struct bp_location **last_loc, | |
a38118e5 | 6174 | int allflag, bool raw_loc) |
269b11a2 PA |
6175 | { |
6176 | struct command_line *l; | |
c2c6d25f | 6177 | static char bpenables[] = "nynny"; |
c906108c | 6178 | |
79a45e25 | 6179 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6180 | int header_of_multiple = 0; |
6181 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6182 | struct value_print_options opts; |
6183 | ||
6184 | get_user_print_options (&opts); | |
0d381245 VP |
6185 | |
6186 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6187 | /* See comment in print_one_breakpoint concerning treatment of |
6188 | breakpoints with single disabled location. */ | |
0d381245 VP |
6189 | if (loc == NULL |
6190 | && (b->loc != NULL | |
b5fa468f TBA |
6191 | && (b->loc->next != NULL |
6192 | || !b->loc->enabled || b->loc->disabled_by_cond))) | |
0d381245 VP |
6193 | header_of_multiple = 1; |
6194 | if (loc == NULL) | |
6195 | loc = b->loc; | |
6196 | ||
c4093a6a JM |
6197 | annotate_record (); |
6198 | ||
6199 | /* 1 */ | |
6200 | annotate_field (0); | |
0d381245 | 6201 | if (part_of_multiple) |
528e1572 | 6202 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
0d381245 | 6203 | else |
381befee | 6204 | uiout->field_signed ("number", b->number); |
c4093a6a JM |
6205 | |
6206 | /* 2 */ | |
6207 | annotate_field (1); | |
0d381245 | 6208 | if (part_of_multiple) |
112e8700 | 6209 | uiout->field_skip ("type"); |
269b11a2 | 6210 | else |
112e8700 | 6211 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6212 | |
6213 | /* 3 */ | |
6214 | annotate_field (2); | |
0d381245 | 6215 | if (part_of_multiple) |
112e8700 | 6216 | uiout->field_skip ("disp"); |
0d381245 | 6217 | else |
112e8700 | 6218 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6219 | |
c4093a6a JM |
6220 | /* 4 */ |
6221 | annotate_field (3); | |
85c88e2a TBA |
6222 | /* For locations that are disabled because of an invalid condition, |
6223 | display "N*" on CLI, where "*" refers to a footnote below the | |
6224 | table. For MI, simply display a "N" without a footnote. */ | |
6225 | const char *N = (uiout->is_mi_like_p ()) ? "N" : "N*"; | |
0d381245 | 6226 | if (part_of_multiple) |
85c88e2a | 6227 | uiout->field_string ("enabled", (loc->disabled_by_cond ? N |
b5fa468f | 6228 | : (loc->enabled ? "y" : "n"))); |
0d381245 | 6229 | else |
112e8700 | 6230 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
0d381245 | 6231 | |
c4093a6a | 6232 | /* 5 and 6 */ |
c01e038b | 6233 | bool result = false; |
c47614fe | 6234 | if (!raw_loc && b->print_one (last_loc)) |
c01e038b | 6235 | result = true; |
3086aeae | 6236 | else |
a38118e5 PA |
6237 | { |
6238 | if (is_watchpoint (b)) | |
3a5c3e22 PA |
6239 | { |
6240 | struct watchpoint *w = (struct watchpoint *) b; | |
6241 | ||
6242 | /* Field 4, the address, is omitted (which makes the columns | |
6243 | not line up too nicely with the headers, but the effect | |
6244 | is relatively readable). */ | |
6245 | if (opts.addressprint) | |
112e8700 | 6246 | uiout->field_skip ("addr"); |
3a5c3e22 | 6247 | annotate_field (5); |
a4c50be3 | 6248 | uiout->field_string ("what", w->exp_string.get ()); |
3a5c3e22 | 6249 | } |
f06f1252 TT |
6250 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
6251 | || is_ada_exception_catchpoint (b)) | |
a38118e5 PA |
6252 | { |
6253 | if (opts.addressprint) | |
6254 | { | |
6255 | annotate_field (4); | |
6256 | if (header_of_multiple) | |
7f6aba03 TT |
6257 | uiout->field_string ("addr", "<MULTIPLE>", |
6258 | metadata_style.style ()); | |
a38118e5 | 6259 | else if (b->loc == NULL || loc->shlib_disabled) |
7f6aba03 TT |
6260 | uiout->field_string ("addr", "<PENDING>", |
6261 | metadata_style.style ()); | |
a38118e5 PA |
6262 | else |
6263 | uiout->field_core_addr ("addr", | |
6264 | loc->gdbarch, loc->address); | |
6265 | } | |
6266 | annotate_field (5); | |
6267 | if (!header_of_multiple) | |
6268 | print_breakpoint_location (b, loc); | |
6269 | if (b->loc) | |
6270 | *last_loc = b->loc; | |
6271 | } | |
6272 | } | |
6c95b8df | 6273 | |
998580f1 | 6274 | if (loc != NULL && !header_of_multiple) |
6c95b8df | 6275 | { |
5c632425 | 6276 | std::vector<int> inf_nums; |
998580f1 | 6277 | int mi_only = 1; |
6c95b8df | 6278 | |
08036331 | 6279 | for (inferior *inf : all_inferiors ()) |
6c95b8df PA |
6280 | { |
6281 | if (inf->pspace == loc->pspace) | |
5c632425 | 6282 | inf_nums.push_back (inf->num); |
6c95b8df | 6283 | } |
998580f1 | 6284 | |
dda83cd7 | 6285 | /* For backward compatibility, don't display inferiors in CLI unless |
998580f1 MK |
6286 | there are several. Always display for MI. */ |
6287 | if (allflag | |
6288 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
94c93c35 | 6289 | && (program_spaces.size () > 1 |
998580f1 MK |
6290 | || number_of_inferiors () > 1) |
6291 | /* LOC is for existing B, it cannot be in | |
6292 | moribund_locations and thus having NULL OWNER. */ | |
6293 | && loc->owner->type != bp_catchpoint)) | |
6294 | mi_only = 0; | |
5c632425 | 6295 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
6c95b8df PA |
6296 | } |
6297 | ||
4a306c9a | 6298 | if (!part_of_multiple) |
c4093a6a | 6299 | { |
4a306c9a JB |
6300 | if (b->thread != -1) |
6301 | { | |
6302 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6303 | "stop only in" line a little further down. */ |
112e8700 | 6304 | uiout->text (" thread "); |
381befee | 6305 | uiout->field_signed ("thread", b->thread); |
4a306c9a JB |
6306 | } |
6307 | else if (b->task != 0) | |
6308 | { | |
112e8700 | 6309 | uiout->text (" task "); |
381befee | 6310 | uiout->field_signed ("task", b->task); |
4a306c9a | 6311 | } |
c4093a6a | 6312 | } |
f1310107 | 6313 | |
112e8700 | 6314 | uiout->text ("\n"); |
f1310107 | 6315 | |
348d480f | 6316 | if (!part_of_multiple) |
c47614fe | 6317 | b->print_one_detail (uiout); |
f1310107 | 6318 | |
0d381245 | 6319 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6320 | { |
6321 | annotate_field (6); | |
112e8700 | 6322 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6323 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
dda83cd7 | 6324 | the frame ID. */ |
112e8700 | 6325 | uiout->field_core_addr ("frame", |
5af949e3 | 6326 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6327 | uiout->text ("\n"); |
c4093a6a JM |
6328 | } |
6329 | ||
28010a5d | 6330 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6331 | { |
6332 | annotate_field (7); | |
d77f58be | 6333 | if (is_tracepoint (b)) |
112e8700 | 6334 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6335 | else |
112e8700 | 6336 | uiout->text ("\tstop only if "); |
6f781ee3 | 6337 | uiout->field_string ("cond", b->cond_string.get ()); |
b775012e LM |
6338 | |
6339 | /* Print whether the target is doing the breakpoint's condition | |
6340 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6341 | if (is_breakpoint (b) | |
6342 | && breakpoint_condition_evaluation_mode () | |
6343 | == condition_evaluation_target) | |
6344 | { | |
6a831f06 PA |
6345 | uiout->message (" (%pF evals)", |
6346 | string_field ("evaluated-by", | |
6347 | bp_condition_evaluator (b))); | |
b775012e | 6348 | } |
112e8700 | 6349 | uiout->text ("\n"); |
0101ce28 JJ |
6350 | } |
6351 | ||
0d381245 | 6352 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6353 | { |
4a64f543 | 6354 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6355 | uiout->text ("\tstop only in thread "); |
6356 | if (uiout->is_mi_like_p ()) | |
381befee | 6357 | uiout->field_signed ("thread", b->thread); |
5d5658a1 PA |
6358 | else |
6359 | { | |
6360 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6361 | ||
112e8700 | 6362 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6363 | } |
112e8700 | 6364 | uiout->text ("\n"); |
c4093a6a JM |
6365 | } |
6366 | ||
556ec64d YQ |
6367 | if (!part_of_multiple) |
6368 | { | |
6369 | if (b->hit_count) | |
31f56a27 YQ |
6370 | { |
6371 | /* FIXME should make an annotation for this. */ | |
6372 | if (is_catchpoint (b)) | |
112e8700 | 6373 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6374 | else if (is_tracepoint (b)) |
112e8700 | 6375 | uiout->text ("\ttracepoint"); |
31f56a27 | 6376 | else |
112e8700 SM |
6377 | uiout->text ("\tbreakpoint"); |
6378 | uiout->text (" already hit "); | |
381befee | 6379 | uiout->field_signed ("times", b->hit_count); |
31f56a27 | 6380 | if (b->hit_count == 1) |
112e8700 | 6381 | uiout->text (" time\n"); |
31f56a27 | 6382 | else |
112e8700 | 6383 | uiout->text (" times\n"); |
31f56a27 | 6384 | } |
556ec64d YQ |
6385 | else |
6386 | { | |
31f56a27 | 6387 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 | 6388 | if (uiout->is_mi_like_p ()) |
381befee | 6389 | uiout->field_signed ("times", b->hit_count); |
556ec64d YQ |
6390 | } |
6391 | } | |
8b93c638 | 6392 | |
0d381245 | 6393 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6394 | { |
6395 | annotate_field (8); | |
6a831f06 PA |
6396 | uiout->message ("\tignore next %pF hits\n", |
6397 | signed_field ("ignore", b->ignore_count)); | |
c4093a6a | 6398 | } |
059fb39f | 6399 | |
816338b5 SS |
6400 | /* Note that an enable count of 1 corresponds to "enable once" |
6401 | behavior, which is reported by the combination of enablement and | |
6402 | disposition, so we don't need to mention it here. */ | |
6403 | if (!part_of_multiple && b->enable_count > 1) | |
6404 | { | |
6405 | annotate_field (8); | |
112e8700 | 6406 | uiout->text ("\tdisable after "); |
816338b5 SS |
6407 | /* Tweak the wording to clarify that ignore and enable counts |
6408 | are distinct, and have additive effect. */ | |
6409 | if (b->ignore_count) | |
112e8700 | 6410 | uiout->text ("additional "); |
816338b5 | 6411 | else |
112e8700 | 6412 | uiout->text ("next "); |
381befee | 6413 | uiout->field_signed ("enable", b->enable_count); |
112e8700 | 6414 | uiout->text (" hits\n"); |
816338b5 SS |
6415 | } |
6416 | ||
f196051f SS |
6417 | if (!part_of_multiple && is_tracepoint (b)) |
6418 | { | |
6419 | struct tracepoint *tp = (struct tracepoint *) b; | |
6420 | ||
6421 | if (tp->traceframe_usage) | |
6422 | { | |
112e8700 | 6423 | uiout->text ("\ttrace buffer usage "); |
381befee | 6424 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
112e8700 | 6425 | uiout->text (" bytes\n"); |
f196051f SS |
6426 | } |
6427 | } | |
d3ce09f5 | 6428 | |
d1b0a7bf | 6429 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6430 | if (!part_of_multiple && l) |
c4093a6a JM |
6431 | { |
6432 | annotate_field (9); | |
2e783024 | 6433 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6434 | print_command_lines (uiout, l, 4); |
c4093a6a | 6435 | } |
d24317b4 | 6436 | |
d9b3f62e | 6437 | if (is_tracepoint (b)) |
1042e4c0 | 6438 | { |
d9b3f62e PA |
6439 | struct tracepoint *t = (struct tracepoint *) b; |
6440 | ||
6441 | if (!part_of_multiple && t->pass_count) | |
6442 | { | |
6443 | annotate_field (10); | |
112e8700 | 6444 | uiout->text ("\tpass count "); |
381befee | 6445 | uiout->field_signed ("pass", t->pass_count); |
112e8700 | 6446 | uiout->text (" \n"); |
d9b3f62e | 6447 | } |
f2a8bc8a YQ |
6448 | |
6449 | /* Don't display it when tracepoint or tracepoint location is | |
6450 | pending. */ | |
6451 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6452 | { | |
6453 | annotate_field (11); | |
6454 | ||
112e8700 SM |
6455 | if (uiout->is_mi_like_p ()) |
6456 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6457 | loc->inserted ? "y" : "n"); |
6458 | else | |
6459 | { | |
6460 | if (loc->inserted) | |
112e8700 | 6461 | uiout->text ("\t"); |
f2a8bc8a | 6462 | else |
112e8700 SM |
6463 | uiout->text ("\tnot "); |
6464 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6465 | } |
6466 | } | |
1042e4c0 SS |
6467 | } |
6468 | ||
112e8700 | 6469 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6470 | { |
3a5c3e22 PA |
6471 | if (is_watchpoint (b)) |
6472 | { | |
6473 | struct watchpoint *w = (struct watchpoint *) b; | |
6474 | ||
a4c50be3 | 6475 | uiout->field_string ("original-location", w->exp_string.get ()); |
3a5c3e22 | 6476 | } |
f00aae0f | 6477 | else if (b->location != NULL |
d28cd78a | 6478 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6479 | uiout->field_string ("original-location", |
d28cd78a | 6480 | event_location_to_string (b->location.get ())); |
d24317b4 | 6481 | } |
c01e038b TT |
6482 | |
6483 | return result; | |
c4093a6a | 6484 | } |
c5aa993b | 6485 | |
13674803 SM |
6486 | /* See breakpoint.h. */ |
6487 | ||
6488 | bool fix_multi_location_breakpoint_output_globally = false; | |
6489 | ||
0d381245 VP |
6490 | static void |
6491 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6492 | struct bp_location **last_loc, |
6c95b8df | 6493 | int allflag) |
0d381245 | 6494 | { |
79a45e25 | 6495 | struct ui_out *uiout = current_uiout; |
13674803 SM |
6496 | bool use_fixed_output |
6497 | = (uiout->test_flags (fix_multi_location_breakpoint_output) | |
6498 | || fix_multi_location_breakpoint_output_globally); | |
8d3788bd | 6499 | |
b4be1b06 | 6500 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
c01e038b TT |
6501 | bool printed = print_one_breakpoint_location (b, NULL, 0, last_loc, |
6502 | allflag, false); | |
8d3788bd | 6503 | |
b4be1b06 SM |
6504 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
6505 | are outside. */ | |
6506 | if (!use_fixed_output) | |
6507 | bkpt_tuple_emitter.reset (); | |
0d381245 VP |
6508 | |
6509 | /* If this breakpoint has custom print function, | |
6510 | it's already printed. Otherwise, print individual | |
6511 | locations, if any. */ | |
c01e038b | 6512 | if (!printed || allflag) |
0d381245 | 6513 | { |
4a64f543 MS |
6514 | /* If breakpoint has a single location that is disabled, we |
6515 | print it as if it had several locations, since otherwise it's | |
6516 | hard to represent "breakpoint enabled, location disabled" | |
6517 | situation. | |
6518 | ||
6519 | Note that while hardware watchpoints have several locations | |
a38118e5 PA |
6520 | internally, that's not a property exposed to users. |
6521 | ||
6522 | Likewise, while catchpoints may be implemented with | |
6523 | breakpoints (e.g., catch throw), that's not a property | |
6524 | exposed to users. We do however display the internal | |
6525 | breakpoint locations with "maint info breakpoints". */ | |
6526 | if (!is_hardware_watchpoint (b) | |
f06f1252 TT |
6527 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
6528 | || is_ada_exception_catchpoint (b)) | |
a38118e5 | 6529 | && (allflag |
b5fa468f TBA |
6530 | || (b->loc && (b->loc->next |
6531 | || !b->loc->enabled | |
6532 | || b->loc->disabled_by_cond)))) | |
0d381245 | 6533 | { |
b4be1b06 SM |
6534 | gdb::optional<ui_out_emit_list> locations_list; |
6535 | ||
6536 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid | |
6537 | MI record. For later versions, place breakpoint locations in a | |
6538 | list. */ | |
6539 | if (uiout->is_mi_like_p () && use_fixed_output) | |
6540 | locations_list.emplace (uiout, "locations"); | |
8d3788bd | 6541 | |
b4be1b06 | 6542 | int n = 1; |
40cb8ca5 | 6543 | for (bp_location *loc : b->locations ()) |
8d3788bd | 6544 | { |
b4be1b06 | 6545 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
a38118e5 PA |
6546 | print_one_breakpoint_location (b, loc, n, last_loc, |
6547 | allflag, allflag); | |
40cb8ca5 | 6548 | n++; |
8d3788bd | 6549 | } |
0d381245 VP |
6550 | } |
6551 | } | |
6552 | } | |
6553 | ||
a6d9a66e UW |
6554 | static int |
6555 | breakpoint_address_bits (struct breakpoint *b) | |
6556 | { | |
6557 | int print_address_bits = 0; | |
a6d9a66e | 6558 | |
c6d81124 PA |
6559 | /* Software watchpoints that aren't watching memory don't have an |
6560 | address to print. */ | |
6561 | if (is_no_memory_software_watchpoint (b)) | |
6562 | return 0; | |
6563 | ||
40cb8ca5 | 6564 | for (bp_location *loc : b->locations ()) |
a6d9a66e | 6565 | { |
c7437ca6 PA |
6566 | int addr_bit; |
6567 | ||
c7437ca6 | 6568 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6569 | if (addr_bit > print_address_bits) |
6570 | print_address_bits = addr_bit; | |
6571 | } | |
6572 | ||
6573 | return print_address_bits; | |
6574 | } | |
0d381245 | 6575 | |
65630365 | 6576 | /* See breakpoint.h. */ |
c5aa993b | 6577 | |
65630365 PA |
6578 | void |
6579 | print_breakpoint (breakpoint *b) | |
c4093a6a | 6580 | { |
a6d9a66e | 6581 | struct bp_location *dummy_loc = NULL; |
65630365 | 6582 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6583 | } |
c5aa993b | 6584 | |
09d682a4 TT |
6585 | /* Return true if this breakpoint was set by the user, false if it is |
6586 | internal or momentary. */ | |
6587 | ||
6588 | int | |
6589 | user_breakpoint_p (struct breakpoint *b) | |
6590 | { | |
46c6471b | 6591 | return b->number > 0; |
09d682a4 TT |
6592 | } |
6593 | ||
93daf339 TT |
6594 | /* See breakpoint.h. */ |
6595 | ||
6596 | int | |
6597 | pending_breakpoint_p (struct breakpoint *b) | |
6598 | { | |
6599 | return b->loc == NULL; | |
6600 | } | |
6601 | ||
5c458ae8 SM |
6602 | /* Print information on breakpoints (including watchpoints and tracepoints). |
6603 | ||
6604 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as | |
6605 | understood by number_or_range_parser. Only breakpoints included in this | |
6606 | list are then printed. | |
6607 | ||
6608 | If SHOW_INTERNAL is true, print internal breakpoints. | |
6609 | ||
6610 | If FILTER is non-NULL, call it on each breakpoint and only include the | |
6611 | ones for which it returns true. | |
6612 | ||
6613 | Return the total number of breakpoints listed. */ | |
c906108c | 6614 | |
d77f58be | 6615 | static int |
5c458ae8 | 6616 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
f2478a7e | 6617 | bool (*filter) (const struct breakpoint *)) |
c4093a6a | 6618 | { |
a6d9a66e | 6619 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6620 | int nr_printable_breakpoints; |
79a45b7d | 6621 | struct value_print_options opts; |
a6d9a66e | 6622 | int print_address_bits = 0; |
269b11a2 | 6623 | int print_type_col_width = 14; |
79a45e25 | 6624 | struct ui_out *uiout = current_uiout; |
b5fa468f | 6625 | bool has_disabled_by_cond_location = false; |
269b11a2 | 6626 | |
79a45b7d TT |
6627 | get_user_print_options (&opts); |
6628 | ||
4a64f543 MS |
6629 | /* Compute the number of rows in the table, as well as the size |
6630 | required for address fields. */ | |
7f3b0473 | 6631 | nr_printable_breakpoints = 0; |
43892fdf | 6632 | for (breakpoint *b : all_breakpoints ()) |
e5a67952 MS |
6633 | { |
6634 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6635 | if (filter && !filter (b)) | |
6636 | continue; | |
6637 | ||
5c458ae8 | 6638 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
e5a67952 | 6639 | accept. Skip the others. */ |
5c458ae8 | 6640 | if (bp_num_list != NULL && *bp_num_list != '\0') |
e5a67952 | 6641 | { |
5c458ae8 | 6642 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
e5a67952 | 6643 | continue; |
5c458ae8 | 6644 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
e5a67952 MS |
6645 | continue; |
6646 | } | |
269b11a2 | 6647 | |
5c458ae8 | 6648 | if (show_internal || user_breakpoint_p (b)) |
e5a67952 MS |
6649 | { |
6650 | int addr_bit, type_len; | |
a6d9a66e | 6651 | |
e5a67952 MS |
6652 | addr_bit = breakpoint_address_bits (b); |
6653 | if (addr_bit > print_address_bits) | |
6654 | print_address_bits = addr_bit; | |
269b11a2 | 6655 | |
e5a67952 MS |
6656 | type_len = strlen (bptype_string (b->type)); |
6657 | if (type_len > print_type_col_width) | |
6658 | print_type_col_width = type_len; | |
6659 | ||
6660 | nr_printable_breakpoints++; | |
6661 | } | |
6662 | } | |
7f3b0473 | 6663 | |
4a2b031d TT |
6664 | { |
6665 | ui_out_emit_table table_emitter (uiout, | |
6666 | opts.addressprint ? 6 : 5, | |
6667 | nr_printable_breakpoints, | |
6668 | "BreakpointTable"); | |
6669 | ||
6670 | if (nr_printable_breakpoints > 0) | |
6671 | annotate_breakpoints_headers (); | |
6672 | if (nr_printable_breakpoints > 0) | |
6673 | annotate_field (0); | |
6674 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6675 | if (nr_printable_breakpoints > 0) | |
6676 | annotate_field (1); | |
6677 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6678 | if (nr_printable_breakpoints > 0) | |
6679 | annotate_field (2); | |
6680 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6681 | if (nr_printable_breakpoints > 0) | |
6682 | annotate_field (3); | |
6683 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6684 | if (opts.addressprint) | |
6685 | { | |
6686 | if (nr_printable_breakpoints > 0) | |
6687 | annotate_field (4); | |
6688 | if (print_address_bits <= 32) | |
6689 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6690 | else | |
6691 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6692 | } | |
6693 | if (nr_printable_breakpoints > 0) | |
6694 | annotate_field (5); | |
6695 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6696 | uiout->table_body (); | |
6697 | if (nr_printable_breakpoints > 0) | |
6698 | annotate_breakpoints_table (); | |
6699 | ||
43892fdf | 6700 | for (breakpoint *b : all_breakpoints ()) |
4a2b031d TT |
6701 | { |
6702 | QUIT; | |
6703 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6704 | if (filter && !filter (b)) | |
6705 | continue; | |
e5a67952 | 6706 | |
5c458ae8 | 6707 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
4a2b031d | 6708 | accept. Skip the others. */ |
e5a67952 | 6709 | |
5c458ae8 | 6710 | if (bp_num_list != NULL && *bp_num_list != '\0') |
4a2b031d | 6711 | { |
5c458ae8 | 6712 | if (show_internal) /* maintenance info breakpoint */ |
4a2b031d | 6713 | { |
5c458ae8 | 6714 | if (parse_and_eval_long (bp_num_list) != b->number) |
4a2b031d TT |
6715 | continue; |
6716 | } | |
6717 | else /* all others */ | |
6718 | { | |
5c458ae8 | 6719 | if (!number_is_in_list (bp_num_list, b->number)) |
4a2b031d TT |
6720 | continue; |
6721 | } | |
6722 | } | |
6723 | /* We only print out user settable breakpoints unless the | |
5c458ae8 SM |
6724 | show_internal is set. */ |
6725 | if (show_internal || user_breakpoint_p (b)) | |
b5fa468f TBA |
6726 | { |
6727 | print_one_breakpoint (b, &last_loc, show_internal); | |
40cb8ca5 | 6728 | for (bp_location *loc : b->locations ()) |
b5fa468f TBA |
6729 | if (loc->disabled_by_cond) |
6730 | has_disabled_by_cond_location = true; | |
6731 | } | |
4a2b031d TT |
6732 | } |
6733 | } | |
698384cd | 6734 | |
7f3b0473 | 6735 | if (nr_printable_breakpoints == 0) |
c906108c | 6736 | { |
4a64f543 MS |
6737 | /* If there's a filter, let the caller decide how to report |
6738 | empty list. */ | |
d77f58be SS |
6739 | if (!filter) |
6740 | { | |
5c458ae8 | 6741 | if (bp_num_list == NULL || *bp_num_list == '\0') |
112e8700 | 6742 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6743 | else |
112e8700 | 6744 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
5c458ae8 | 6745 | bp_num_list); |
d77f58be | 6746 | } |
c906108c SS |
6747 | } |
6748 | else | |
c4093a6a | 6749 | { |
a6d9a66e UW |
6750 | if (last_loc && !server_command) |
6751 | set_next_address (last_loc->gdbarch, last_loc->address); | |
b5fa468f | 6752 | |
85c88e2a | 6753 | if (has_disabled_by_cond_location && !uiout->is_mi_like_p ()) |
b5fa468f TBA |
6754 | uiout->message (_("(*): Breakpoint condition is invalid at this " |
6755 | "location.\n")); | |
c4093a6a | 6756 | } |
c906108c | 6757 | |
4a64f543 | 6758 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6759 | there have been breakpoints? */ |
c906108c | 6760 | annotate_breakpoints_table_end (); |
d77f58be SS |
6761 | |
6762 | return nr_printable_breakpoints; | |
c906108c SS |
6763 | } |
6764 | ||
ad443146 SS |
6765 | /* Display the value of default-collect in a way that is generally |
6766 | compatible with the breakpoint list. */ | |
6767 | ||
6768 | static void | |
6769 | default_collect_info (void) | |
6770 | { | |
79a45e25 PA |
6771 | struct ui_out *uiout = current_uiout; |
6772 | ||
ad443146 SS |
6773 | /* If it has no value (which is frequently the case), say nothing; a |
6774 | message like "No default-collect." gets in user's face when it's | |
6775 | not wanted. */ | |
e0700ba4 | 6776 | if (default_collect.empty ()) |
ad443146 SS |
6777 | return; |
6778 | ||
6779 | /* The following phrase lines up nicely with per-tracepoint collect | |
6780 | actions. */ | |
112e8700 SM |
6781 | uiout->text ("default collect "); |
6782 | uiout->field_string ("default-collect", default_collect); | |
6783 | uiout->text (" \n"); | |
ad443146 SS |
6784 | } |
6785 | ||
c906108c | 6786 | static void |
0b39b52e | 6787 | info_breakpoints_command (const char *args, int from_tty) |
c906108c | 6788 | { |
5c458ae8 | 6789 | breakpoint_1 (args, false, NULL); |
ad443146 SS |
6790 | |
6791 | default_collect_info (); | |
d77f58be SS |
6792 | } |
6793 | ||
6794 | static void | |
1d12d88f | 6795 | info_watchpoints_command (const char *args, int from_tty) |
d77f58be | 6796 | { |
5c458ae8 | 6797 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
79a45e25 | 6798 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6799 | |
6800 | if (num_printed == 0) | |
6801 | { | |
e5a67952 | 6802 | if (args == NULL || *args == '\0') |
112e8700 | 6803 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6804 | else |
112e8700 | 6805 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6806 | } |
c906108c SS |
6807 | } |
6808 | ||
7a292a7a | 6809 | static void |
4495129a | 6810 | maintenance_info_breakpoints (const char *args, int from_tty) |
c906108c | 6811 | { |
5c458ae8 | 6812 | breakpoint_1 (args, true, NULL); |
ad443146 SS |
6813 | |
6814 | default_collect_info (); | |
c906108c SS |
6815 | } |
6816 | ||
0d381245 | 6817 | static int |
714835d5 | 6818 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6819 | struct program_space *pspace, |
714835d5 | 6820 | CORE_ADDR pc, struct obj_section *section) |
0d381245 | 6821 | { |
40cb8ca5 | 6822 | for (bp_location *bl : b->locations ()) |
0d381245 | 6823 | { |
6c95b8df PA |
6824 | if (bl->pspace == pspace |
6825 | && bl->address == pc | |
0d381245 VP |
6826 | && (!overlay_debugging || bl->section == section)) |
6827 | return 1; | |
6828 | } | |
6829 | return 0; | |
6830 | } | |
6831 | ||
672f9b60 | 6832 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6833 | concerns with logical breakpoints, so we match program spaces, not |
6834 | address spaces. */ | |
c906108c SS |
6835 | |
6836 | static void | |
6c95b8df PA |
6837 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6838 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6839 | struct obj_section *section, int thread) |
c906108c | 6840 | { |
52f0bd74 | 6841 | int others = 0; |
c906108c | 6842 | |
43892fdf | 6843 | for (breakpoint *b : all_breakpoints ()) |
672f9b60 | 6844 | others += (user_breakpoint_p (b) |
dda83cd7 | 6845 | && breakpoint_has_pc (b, pspace, pc, section)); |
43892fdf | 6846 | |
c906108c SS |
6847 | if (others > 0) |
6848 | { | |
a3f17187 | 6849 | if (others == 1) |
6cb06a8c | 6850 | gdb_printf (_("Note: breakpoint ")); |
a3f17187 | 6851 | else /* if (others == ???) */ |
6cb06a8c | 6852 | gdb_printf (_("Note: breakpoints ")); |
43892fdf | 6853 | for (breakpoint *b : all_breakpoints ()) |
672f9b60 | 6854 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6855 | { |
6856 | others--; | |
6cb06a8c | 6857 | gdb_printf ("%d", b->number); |
0d381245 | 6858 | if (b->thread == -1 && thread != -1) |
6cb06a8c | 6859 | gdb_printf (" (all threads)"); |
0d381245 | 6860 | else if (b->thread != -1) |
6cb06a8c TT |
6861 | gdb_printf (" (thread %d)", b->thread); |
6862 | gdb_printf ("%s%s ", | |
6863 | ((b->enable_state == bp_disabled | |
6864 | || b->enable_state == bp_call_disabled) | |
6865 | ? " (disabled)" | |
6866 | : ""), | |
6867 | (others > 1) ? "," | |
6868 | : ((others == 1) ? " and" : "")); | |
0d381245 | 6869 | } |
6a831f06 PA |
6870 | current_uiout->message (_("also set at pc %ps.\n"), |
6871 | styled_string (address_style.style (), | |
6872 | paddress (gdbarch, pc))); | |
c906108c SS |
6873 | } |
6874 | } | |
6875 | \f | |
c906108c | 6876 | |
cb1e4e32 PA |
6877 | /* Return true iff it is meaningful to use the address member of LOC. |
6878 | For some breakpoint types, the locations' address members are | |
6879 | irrelevant and it makes no sense to attempt to compare them to | |
6880 | other addresses (or use them for any other purpose either). | |
2d134ed3 | 6881 | |
cb1e4e32 PA |
6882 | More specifically, software watchpoints and catchpoints that are |
6883 | not backed by breakpoints always have a zero valued location | |
6884 | address and we don't want to mark breakpoints of any of these types | |
6885 | to be a duplicate of an actual breakpoint location at address | |
6886 | zero. */ | |
e4f237da | 6887 | |
cb1e4e32 PA |
6888 | static bool |
6889 | bl_address_is_meaningful (bp_location *loc) | |
e4f237da | 6890 | { |
cb1e4e32 | 6891 | return loc->loc_type != bp_loc_other; |
2d134ed3 PA |
6892 | } |
6893 | ||
6894 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6895 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6896 | ||
6897 | static int | |
4a64f543 MS |
6898 | watchpoint_locations_match (struct bp_location *loc1, |
6899 | struct bp_location *loc2) | |
2d134ed3 | 6900 | { |
3a5c3e22 PA |
6901 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6902 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6903 | ||
6904 | /* Both of them must exist. */ | |
6905 | gdb_assert (w1 != NULL); | |
6906 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6907 | |
4a64f543 MS |
6908 | /* If the target can evaluate the condition expression in hardware, |
6909 | then we we need to insert both watchpoints even if they are at | |
6910 | the same place. Otherwise the watchpoint will only trigger when | |
6911 | the condition of whichever watchpoint was inserted evaluates to | |
6912 | true, not giving a chance for GDB to check the condition of the | |
6913 | other watchpoint. */ | |
3a5c3e22 | 6914 | if ((w1->cond_exp |
4a64f543 MS |
6915 | && target_can_accel_watchpoint_condition (loc1->address, |
6916 | loc1->length, | |
0cf6dd15 | 6917 | loc1->watchpoint_type, |
4d01a485 | 6918 | w1->cond_exp.get ())) |
3a5c3e22 | 6919 | || (w2->cond_exp |
4a64f543 MS |
6920 | && target_can_accel_watchpoint_condition (loc2->address, |
6921 | loc2->length, | |
0cf6dd15 | 6922 | loc2->watchpoint_type, |
4d01a485 | 6923 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6924 | return 0; |
6925 | ||
85d721b8 PA |
6926 | /* Note that this checks the owner's type, not the location's. In |
6927 | case the target does not support read watchpoints, but does | |
6928 | support access watchpoints, we'll have bp_read_watchpoint | |
6929 | watchpoints with hw_access locations. Those should be considered | |
6930 | duplicates of hw_read locations. The hw_read locations will | |
6931 | become hw_access locations later. */ | |
2d134ed3 PA |
6932 | return (loc1->owner->type == loc2->owner->type |
6933 | && loc1->pspace->aspace == loc2->pspace->aspace | |
6934 | && loc1->address == loc2->address | |
6935 | && loc1->length == loc2->length); | |
e4f237da KB |
6936 | } |
6937 | ||
31e77af2 | 6938 | /* See breakpoint.h. */ |
6c95b8df | 6939 | |
31e77af2 | 6940 | int |
accd0bcd YQ |
6941 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
6942 | const address_space *aspace2, CORE_ADDR addr2) | |
6c95b8df | 6943 | { |
f5656ead | 6944 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
6945 | || aspace1 == aspace2) |
6946 | && addr1 == addr2); | |
6947 | } | |
6948 | ||
f1310107 TJB |
6949 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
6950 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
6951 | matches ASPACE2. On targets that have global breakpoints, the address | |
6952 | space doesn't really matter. */ | |
6953 | ||
6954 | static int | |
accd0bcd YQ |
6955 | breakpoint_address_match_range (const address_space *aspace1, |
6956 | CORE_ADDR addr1, | |
6957 | int len1, const address_space *aspace2, | |
f1310107 TJB |
6958 | CORE_ADDR addr2) |
6959 | { | |
f5656ead | 6960 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
6961 | || aspace1 == aspace2) |
6962 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
6963 | } | |
6964 | ||
6965 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
6966 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
6967 | matches the breakpoint's address space. On targets that have global | |
6968 | breakpoints, the address space doesn't really matter. */ | |
6969 | ||
6970 | static int | |
6971 | breakpoint_location_address_match (struct bp_location *bl, | |
accd0bcd | 6972 | const address_space *aspace, |
f1310107 TJB |
6973 | CORE_ADDR addr) |
6974 | { | |
6975 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6976 | aspace, addr) | |
6977 | || (bl->length | |
6978 | && breakpoint_address_match_range (bl->pspace->aspace, | |
6979 | bl->address, bl->length, | |
6980 | aspace, addr))); | |
6981 | } | |
6982 | ||
d35ae833 PA |
6983 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
6984 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
6985 | match happens only if ASPACE matches the breakpoint's address | |
6986 | space. On targets that have global breakpoints, the address space | |
6987 | doesn't really matter. */ | |
6988 | ||
6989 | static int | |
6990 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
accd0bcd | 6991 | const address_space *aspace, |
d35ae833 PA |
6992 | CORE_ADDR addr, int len) |
6993 | { | |
6994 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6995 | || bl->pspace->aspace == aspace) | |
6996 | { | |
6997 | int bl_len = bl->length != 0 ? bl->length : 1; | |
6998 | ||
6999 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7000 | return 1; | |
7001 | } | |
7002 | return 0; | |
7003 | } | |
7004 | ||
1e4d1764 YQ |
7005 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7006 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7007 | true, otherwise returns false. */ | |
7008 | ||
7009 | static int | |
7010 | tracepoint_locations_match (struct bp_location *loc1, | |
7011 | struct bp_location *loc2) | |
7012 | { | |
7013 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7014 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7015 | locations at the same address of different tracepoints are regarded as | |
7016 | different locations. */ | |
7017 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7018 | else | |
7019 | return 0; | |
7020 | } | |
7021 | ||
2d134ed3 | 7022 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
cb1e4e32 | 7023 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
7f32a4d5 PA |
7024 | the same location. If SW_HW_BPS_MATCH is true, then software |
7025 | breakpoint locations and hardware breakpoint locations match, | |
7026 | otherwise they don't. */ | |
2d134ed3 PA |
7027 | |
7028 | static int | |
7f32a4d5 PA |
7029 | breakpoint_locations_match (struct bp_location *loc1, |
7030 | struct bp_location *loc2, | |
7031 | bool sw_hw_bps_match) | |
2d134ed3 | 7032 | { |
2bdf28a0 JK |
7033 | int hw_point1, hw_point2; |
7034 | ||
7035 | /* Both of them must not be in moribund_locations. */ | |
7036 | gdb_assert (loc1->owner != NULL); | |
7037 | gdb_assert (loc2->owner != NULL); | |
7038 | ||
7039 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7040 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7041 | |
7042 | if (hw_point1 != hw_point2) | |
7043 | return 0; | |
7044 | else if (hw_point1) | |
7045 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7046 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7047 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7048 | else |
7f32a4d5 PA |
7049 | /* We compare bp_location.length in order to cover ranged |
7050 | breakpoints. Keep this in sync with | |
7051 | bp_location_is_less_than. */ | |
f1310107 TJB |
7052 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
7053 | loc2->pspace->aspace, loc2->address) | |
7f32a4d5 | 7054 | && (loc1->loc_type == loc2->loc_type || sw_hw_bps_match) |
f1310107 | 7055 | && loc1->length == loc2->length); |
2d134ed3 PA |
7056 | } |
7057 | ||
76897487 KB |
7058 | static void |
7059 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
dda83cd7 | 7060 | int bnum, int have_bnum) |
76897487 | 7061 | { |
f63fbe86 MS |
7062 | /* The longest string possibly returned by hex_string_custom |
7063 | is 50 chars. These must be at least that big for safety. */ | |
7064 | char astr1[64]; | |
7065 | char astr2[64]; | |
76897487 | 7066 | |
bb599908 PH |
7067 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7068 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7069 | if (have_bnum) |
8a3fe4f8 | 7070 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
dda83cd7 | 7071 | bnum, astr1, astr2); |
76897487 | 7072 | else |
8a3fe4f8 | 7073 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7074 | } |
7075 | ||
4a64f543 MS |
7076 | /* Adjust a breakpoint's address to account for architectural |
7077 | constraints on breakpoint placement. Return the adjusted address. | |
7078 | Note: Very few targets require this kind of adjustment. For most | |
7079 | targets, this function is simply the identity function. */ | |
76897487 KB |
7080 | |
7081 | static CORE_ADDR | |
a6d9a66e UW |
7082 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7083 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7084 | { |
a0de8c21 YQ |
7085 | if (bptype == bp_watchpoint |
7086 | || bptype == bp_hardware_watchpoint | |
7087 | || bptype == bp_read_watchpoint | |
7088 | || bptype == bp_access_watchpoint | |
7089 | || bptype == bp_catchpoint) | |
88f7da05 KB |
7090 | { |
7091 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
dda83cd7 | 7092 | have their addresses modified. */ |
88f7da05 KB |
7093 | return bpaddr; |
7094 | } | |
7c16b83e PA |
7095 | else if (bptype == bp_single_step) |
7096 | { | |
7097 | /* Single-step breakpoints should not have their addresses | |
7098 | modified. If there's any architectural constrain that | |
7099 | applies to this address, then it should have already been | |
7100 | taken into account when the breakpoint was created in the | |
7101 | first place. If we didn't do this, stepping through e.g., | |
7102 | Thumb-2 IT blocks would break. */ | |
7103 | return bpaddr; | |
7104 | } | |
76897487 KB |
7105 | else |
7106 | { | |
a0de8c21 YQ |
7107 | CORE_ADDR adjusted_bpaddr = bpaddr; |
7108 | ||
7109 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) | |
7110 | { | |
7111 | /* Some targets have architectural constraints on the placement | |
7112 | of breakpoint instructions. Obtain the adjusted address. */ | |
7113 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); | |
7114 | } | |
76897487 | 7115 | |
a0de8c21 | 7116 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
76897487 KB |
7117 | |
7118 | /* An adjusted breakpoint address can significantly alter | |
dda83cd7 | 7119 | a user's expectations. Print a warning if an adjustment |
76897487 KB |
7120 | is required. */ |
7121 | if (adjusted_bpaddr != bpaddr) | |
7122 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7123 | ||
7124 | return adjusted_bpaddr; | |
7125 | } | |
7126 | } | |
7127 | ||
cb1e4e32 PA |
7128 | static bp_loc_type |
7129 | bp_location_from_bp_type (bptype type) | |
7cc221ef | 7130 | { |
cb1e4e32 | 7131 | switch (type) |
e049a4b5 DJ |
7132 | { |
7133 | case bp_breakpoint: | |
7c16b83e | 7134 | case bp_single_step: |
e049a4b5 DJ |
7135 | case bp_until: |
7136 | case bp_finish: | |
7137 | case bp_longjmp: | |
7138 | case bp_longjmp_resume: | |
e2e4d78b | 7139 | case bp_longjmp_call_dummy: |
186c406b TT |
7140 | case bp_exception: |
7141 | case bp_exception_resume: | |
e049a4b5 | 7142 | case bp_step_resume: |
2c03e5be | 7143 | case bp_hp_step_resume: |
e049a4b5 DJ |
7144 | case bp_watchpoint_scope: |
7145 | case bp_call_dummy: | |
aa7d318d | 7146 | case bp_std_terminate: |
e049a4b5 DJ |
7147 | case bp_shlib_event: |
7148 | case bp_thread_event: | |
7149 | case bp_overlay_event: | |
4efc6507 | 7150 | case bp_jit_event: |
0fd8e87f | 7151 | case bp_longjmp_master: |
aa7d318d | 7152 | case bp_std_terminate_master: |
186c406b | 7153 | case bp_exception_master: |
0e30163f JK |
7154 | case bp_gnu_ifunc_resolver: |
7155 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7156 | case bp_dprintf: |
cb1e4e32 | 7157 | return bp_loc_software_breakpoint; |
e049a4b5 | 7158 | case bp_hardware_breakpoint: |
cb1e4e32 | 7159 | return bp_loc_hardware_breakpoint; |
e049a4b5 DJ |
7160 | case bp_hardware_watchpoint: |
7161 | case bp_read_watchpoint: | |
7162 | case bp_access_watchpoint: | |
cb1e4e32 | 7163 | return bp_loc_hardware_watchpoint; |
e049a4b5 | 7164 | case bp_watchpoint: |
ce78b96d | 7165 | case bp_catchpoint: |
15c3d785 PA |
7166 | case bp_tracepoint: |
7167 | case bp_fast_tracepoint: | |
0fb4aa4b | 7168 | case bp_static_tracepoint: |
7b572efb | 7169 | case bp_static_marker_tracepoint: |
cb1e4e32 | 7170 | return bp_loc_other; |
e049a4b5 | 7171 | default: |
e2e0b3e5 | 7172 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 | 7173 | } |
cb1e4e32 PA |
7174 | } |
7175 | ||
7176 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) | |
7177 | { | |
7178 | this->owner = owner; | |
7179 | this->cond_bytecode = NULL; | |
7180 | this->shlib_disabled = 0; | |
7181 | this->enabled = 1; | |
b5fa468f | 7182 | this->disabled_by_cond = false; |
cb1e4e32 PA |
7183 | |
7184 | this->loc_type = type; | |
e049a4b5 | 7185 | |
cb1e4e32 PA |
7186 | if (this->loc_type == bp_loc_software_breakpoint |
7187 | || this->loc_type == bp_loc_hardware_breakpoint) | |
7188 | mark_breakpoint_location_modified (this); | |
7189 | ||
b6433ede | 7190 | incref (); |
cb1e4e32 PA |
7191 | } |
7192 | ||
7193 | bp_location::bp_location (breakpoint *owner) | |
7194 | : bp_location::bp_location (owner, | |
7195 | bp_location_from_bp_type (owner->type)) | |
7196 | { | |
28010a5d PA |
7197 | } |
7198 | ||
7199 | /* Allocate a struct bp_location. */ | |
7200 | ||
7201 | static struct bp_location * | |
7202 | allocate_bp_location (struct breakpoint *bpt) | |
7203 | { | |
c47614fe | 7204 | return bpt->allocate_location (); |
348d480f | 7205 | } |
7cc221ef | 7206 | |
f431efe5 PA |
7207 | /* Decrement reference count. If the reference count reaches 0, |
7208 | destroy the bp_location. Sets *BLP to NULL. */ | |
7209 | ||
7210 | static void | |
7211 | decref_bp_location (struct bp_location **blp) | |
7212 | { | |
b6433ede | 7213 | bp_location_ref_policy::decref (*blp); |
f431efe5 PA |
7214 | *blp = NULL; |
7215 | } | |
7216 | ||
346774a9 | 7217 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7218 | |
b270e6f9 TT |
7219 | static breakpoint * |
7220 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7221 | { |
346774a9 | 7222 | struct breakpoint *b1; |
b270e6f9 | 7223 | struct breakpoint *result = b.get (); |
c906108c | 7224 | |
346774a9 PA |
7225 | /* Add this breakpoint to the end of the chain so that a list of |
7226 | breakpoints will come out in order of increasing numbers. */ | |
7227 | ||
7228 | b1 = breakpoint_chain; | |
7229 | if (b1 == 0) | |
b270e6f9 | 7230 | breakpoint_chain = b.release (); |
346774a9 PA |
7231 | else |
7232 | { | |
7233 | while (b1->next) | |
7234 | b1 = b1->next; | |
b270e6f9 | 7235 | b1->next = b.release (); |
346774a9 | 7236 | } |
b270e6f9 TT |
7237 | |
7238 | return result; | |
346774a9 PA |
7239 | } |
7240 | ||
7241 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7242 | ||
7243 | static void | |
7244 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7245 | struct gdbarch *gdbarch, | |
28010a5d | 7246 | enum bptype bptype, |
c0a91b2b | 7247 | const struct breakpoint_ops *ops) |
346774a9 | 7248 | { |
348d480f PA |
7249 | gdb_assert (ops != NULL); |
7250 | ||
28010a5d | 7251 | b->ops = ops; |
4d28f7a8 | 7252 | b->type = bptype; |
a6d9a66e | 7253 | b->gdbarch = gdbarch; |
c906108c SS |
7254 | b->language = current_language->la_language; |
7255 | b->input_radix = input_radix; | |
d0fb5eae | 7256 | b->related_breakpoint = b; |
346774a9 PA |
7257 | } |
7258 | ||
7259 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7260 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7261 | |
7262 | static struct breakpoint * | |
7263 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7264 | enum bptype bptype, |
c0a91b2b | 7265 | const struct breakpoint_ops *ops) |
346774a9 | 7266 | { |
3b0871f4 | 7267 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7268 | |
3b0871f4 | 7269 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7270 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7271 | } |
7272 | ||
0ba852ab | 7273 | /* Initialize loc->function_name. */ |
0e30163f | 7274 | |
0d381245 | 7275 | static void |
0ba852ab | 7276 | set_breakpoint_location_function (struct bp_location *loc) |
0d381245 | 7277 | { |
2bdf28a0 JK |
7278 | gdb_assert (loc->owner != NULL); |
7279 | ||
0d381245 | 7280 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7281 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7282 | || is_tracepoint (loc->owner)) |
0d381245 | 7283 | { |
2c02bd72 | 7284 | const char *function_name; |
0e30163f | 7285 | |
3467ec66 | 7286 | if (loc->msymbol != NULL |
60f62e2b SM |
7287 | && (loc->msymbol->type () == mst_text_gnu_ifunc |
7288 | || loc->msymbol->type () == mst_data_gnu_ifunc)) | |
0e30163f JK |
7289 | { |
7290 | struct breakpoint *b = loc->owner; | |
7291 | ||
c9d95fa3 | 7292 | function_name = loc->msymbol->linkage_name (); |
3467ec66 PA |
7293 | |
7294 | if (b->type == bp_breakpoint && b->loc == loc | |
7295 | && loc->next == NULL && b->related_breakpoint == b) | |
0e30163f JK |
7296 | { |
7297 | /* Create only the whole new breakpoint of this type but do not | |
7298 | mess more complicated breakpoints with multiple locations. */ | |
7299 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b | 7300 | /* Remember the resolver's address for use by the return |
dda83cd7 | 7301 | breakpoint. */ |
3467ec66 | 7302 | loc->related_address = loc->address; |
0e30163f JK |
7303 | } |
7304 | } | |
3467ec66 PA |
7305 | else |
7306 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); | |
0e30163f | 7307 | |
2c02bd72 | 7308 | if (function_name) |
23d6ee64 | 7309 | loc->function_name = make_unique_xstrdup (function_name); |
0d381245 VP |
7310 | } |
7311 | } | |
7312 | ||
a6d9a66e | 7313 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7314 | struct gdbarch * |
a6d9a66e UW |
7315 | get_sal_arch (struct symtab_and_line sal) |
7316 | { | |
7317 | if (sal.section) | |
08feed99 | 7318 | return sal.section->objfile->arch (); |
a6d9a66e | 7319 | if (sal.symtab) |
3c86fae3 | 7320 | return sal.symtab->compunit ()->objfile ()->arch (); |
a6d9a66e UW |
7321 | |
7322 | return NULL; | |
7323 | } | |
7324 | ||
346774a9 PA |
7325 | /* Low level routine for partially initializing a breakpoint of type |
7326 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7327 | file name, and line number are provided by SAL. |
0d381245 VP |
7328 | |
7329 | It is expected that the caller will complete the initialization of | |
7330 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7331 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7332 | |
346774a9 PA |
7333 | static void |
7334 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7335 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7336 | const struct breakpoint_ops *ops) |
0d381245 | 7337 | { |
28010a5d | 7338 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7339 | |
3742cc8b | 7340 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7341 | |
6c95b8df PA |
7342 | if (bptype != bp_catchpoint) |
7343 | gdb_assert (sal.pspace != NULL); | |
7344 | ||
f8eba3c6 TT |
7345 | /* Store the program space that was used to set the breakpoint, |
7346 | except for ordinary breakpoints, which are independent of the | |
7347 | program space. */ | |
7348 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7349 | b->pspace = sal.pspace; | |
346774a9 | 7350 | } |
c906108c | 7351 | |
346774a9 PA |
7352 | /* set_raw_breakpoint is a low level routine for allocating and |
7353 | partially initializing a breakpoint of type BPTYPE. The newly | |
7354 | created breakpoint's address, section, source file name, and line | |
7355 | number are provided by SAL. The newly created and partially | |
7356 | initialized breakpoint is added to the breakpoint chain and | |
7357 | is also returned as the value of this function. | |
7358 | ||
7359 | It is expected that the caller will complete the initialization of | |
7360 | the newly created breakpoint struct as well as output any status | |
7361 | information regarding the creation of a new breakpoint. In | |
7362 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7363 | number! Care should be taken to not allow an error to occur | |
7364 | prior to completing the initialization of the breakpoint. If this | |
7365 | should happen, a bogus breakpoint will be left on the chain. */ | |
7366 | ||
cd0f67f3 | 7367 | static struct breakpoint * |
346774a9 | 7368 | set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 7369 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7370 | const struct breakpoint_ops *ops) |
346774a9 | 7371 | { |
3b0871f4 | 7372 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7373 | |
3b0871f4 | 7374 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7375 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7376 | } |
7377 | ||
53a5351d | 7378 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7379 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7380 | initiated the operation. */ | |
c906108c SS |
7381 | |
7382 | void | |
186c406b | 7383 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7384 | { |
5d5658a1 | 7385 | int thread = tp->global_num; |
0fd8e87f UW |
7386 | |
7387 | /* To avoid having to rescan all objfile symbols at every step, | |
7388 | we maintain a list of continually-inserted but always disabled | |
7389 | longjmp "master" breakpoints. Here, we simply create momentary | |
7390 | clones of those and enable them for the requested thread. */ | |
1428b37a | 7391 | for (breakpoint *b : all_breakpoints_safe ()) |
6c95b8df | 7392 | if (b->pspace == current_program_space |
186c406b TT |
7393 | && (b->type == bp_longjmp_master |
7394 | || b->type == bp_exception_master)) | |
0fd8e87f | 7395 | { |
06edf0c0 PA |
7396 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7397 | struct breakpoint *clone; | |
cc59ec59 | 7398 | |
e2e4d78b JK |
7399 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7400 | after their removal. */ | |
06edf0c0 | 7401 | clone = momentary_breakpoint_from_master (b, type, |
a0cd5f08 | 7402 | &base_breakpoint_ops, 1); |
0fd8e87f UW |
7403 | clone->thread = thread; |
7404 | } | |
186c406b TT |
7405 | |
7406 | tp->initiating_frame = frame; | |
c906108c SS |
7407 | } |
7408 | ||
611c83ae | 7409 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7410 | void |
611c83ae | 7411 | delete_longjmp_breakpoint (int thread) |
c906108c | 7412 | { |
1428b37a | 7413 | for (breakpoint *b : all_breakpoints_safe ()) |
186c406b | 7414 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7415 | { |
7416 | if (b->thread == thread) | |
7417 | delete_breakpoint (b); | |
7418 | } | |
c906108c SS |
7419 | } |
7420 | ||
f59f708a PA |
7421 | void |
7422 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7423 | { | |
1428b37a | 7424 | for (breakpoint *b : all_breakpoints_safe ()) |
f59f708a PA |
7425 | if (b->type == bp_longjmp || b->type == bp_exception) |
7426 | { | |
7427 | if (b->thread == thread) | |
7428 | b->disposition = disp_del_at_next_stop; | |
7429 | } | |
7430 | } | |
7431 | ||
e2e4d78b JK |
7432 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7433 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7434 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7435 | breakpoints. */ | |
7436 | ||
7437 | struct breakpoint * | |
7438 | set_longjmp_breakpoint_for_call_dummy (void) | |
7439 | { | |
43892fdf | 7440 | breakpoint *retval = nullptr; |
e2e4d78b | 7441 | |
43892fdf | 7442 | for (breakpoint *b : all_breakpoints ()) |
e2e4d78b JK |
7443 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) |
7444 | { | |
7445 | struct breakpoint *new_b; | |
7446 | ||
7447 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a0cd5f08 | 7448 | &base_breakpoint_ops, |
a1aa2221 | 7449 | 1); |
00431a78 | 7450 | new_b->thread = inferior_thread ()->global_num; |
e2e4d78b JK |
7451 | |
7452 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7453 | ||
7454 | gdb_assert (new_b->related_breakpoint == new_b); | |
7455 | if (retval == NULL) | |
7456 | retval = new_b; | |
7457 | new_b->related_breakpoint = retval; | |
7458 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7459 | retval = retval->related_breakpoint; | |
7460 | retval->related_breakpoint = new_b; | |
7461 | } | |
7462 | ||
7463 | return retval; | |
7464 | } | |
7465 | ||
7466 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7467 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7468 | stack. |
7469 | ||
b4b3e2de AB |
7470 | If the unwind fails then there is not sufficient information to discard |
7471 | dummy frames. In this case, elide the clean up and the dummy frames will | |
7472 | be cleaned up next time this function is called from a location where | |
7473 | unwinding is possible. */ | |
e2e4d78b JK |
7474 | |
7475 | void | |
b67a2c6f | 7476 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7477 | { |
7478 | struct breakpoint *b, *b_tmp; | |
7479 | ||
7480 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7481 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7482 | { |
7483 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7484 | ||
b4b3e2de AB |
7485 | /* Find the bp_call_dummy breakpoint in the list of breakpoints |
7486 | chained off b->related_breakpoint. */ | |
e2e4d78b JK |
7487 | while (dummy_b != b && dummy_b->type != bp_call_dummy) |
7488 | dummy_b = dummy_b->related_breakpoint; | |
b4b3e2de AB |
7489 | |
7490 | /* If there was no bp_call_dummy breakpoint then there's nothing | |
7491 | more to do. Or, if the dummy frame associated with the | |
7492 | bp_call_dummy is still on the stack then we need to leave this | |
7493 | bp_call_dummy in place. */ | |
e2e4d78b JK |
7494 | if (dummy_b->type != bp_call_dummy |
7495 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7496 | continue; | |
b4b3e2de AB |
7497 | |
7498 | /* We didn't find the dummy frame on the stack, this could be | |
7499 | because we have longjmp'd to a stack frame that is previous to | |
7500 | the dummy frame, or it could be because the stack unwind is | |
7501 | broken at some point between the longjmp frame and the dummy | |
7502 | frame. | |
7503 | ||
7504 | Next we figure out why the stack unwind stopped. If it looks | |
7505 | like the unwind is complete then we assume the dummy frame has | |
7506 | been jumped over, however, if the unwind stopped for an | |
7507 | unexpected reason then we assume the stack unwind is currently | |
7508 | broken, and that we will (eventually) return to the dummy | |
7509 | frame. | |
7510 | ||
7511 | It might be tempting to consider using frame_id_inner here, but | |
7512 | that is not safe. There is no guarantee that the stack frames | |
7513 | we are looking at here are even on the same stack as the | |
7514 | original dummy frame, hence frame_id_inner can't be used. See | |
7515 | the comments on frame_id_inner for more details. */ | |
7516 | bool unwind_finished_unexpectedly = false; | |
7517 | for (struct frame_info *fi = get_current_frame (); fi != nullptr; ) | |
7518 | { | |
7519 | struct frame_info *prev = get_prev_frame (fi); | |
7520 | if (prev == nullptr) | |
7521 | { | |
7522 | /* FI is the last stack frame. Why did this frame not | |
7523 | unwind further? */ | |
7524 | auto stop_reason = get_frame_unwind_stop_reason (fi); | |
7525 | if (stop_reason != UNWIND_NO_REASON | |
7526 | && stop_reason != UNWIND_OUTERMOST) | |
7527 | unwind_finished_unexpectedly = true; | |
7528 | } | |
7529 | fi = prev; | |
7530 | } | |
7531 | if (unwind_finished_unexpectedly) | |
7532 | continue; | |
7533 | ||
00431a78 | 7534 | dummy_frame_discard (dummy_b->frame_id, tp); |
e2e4d78b JK |
7535 | |
7536 | while (b->related_breakpoint != b) | |
7537 | { | |
7538 | if (b_tmp == b->related_breakpoint) | |
7539 | b_tmp = b->related_breakpoint->next; | |
7540 | delete_breakpoint (b->related_breakpoint); | |
7541 | } | |
7542 | delete_breakpoint (b); | |
7543 | } | |
7544 | } | |
7545 | ||
1900040c MS |
7546 | void |
7547 | enable_overlay_breakpoints (void) | |
7548 | { | |
43892fdf | 7549 | for (breakpoint *b : all_breakpoints ()) |
1900040c | 7550 | if (b->type == bp_overlay_event) |
01add95b SM |
7551 | { |
7552 | b->enable_state = bp_enabled; | |
7553 | update_global_location_list (UGLL_MAY_INSERT); | |
7554 | overlay_events_enabled = 1; | |
7555 | } | |
1900040c MS |
7556 | } |
7557 | ||
7558 | void | |
7559 | disable_overlay_breakpoints (void) | |
7560 | { | |
43892fdf | 7561 | for (breakpoint *b : all_breakpoints ()) |
1900040c | 7562 | if (b->type == bp_overlay_event) |
01add95b SM |
7563 | { |
7564 | b->enable_state = bp_disabled; | |
7565 | update_global_location_list (UGLL_DONT_INSERT); | |
7566 | overlay_events_enabled = 0; | |
7567 | } | |
1900040c MS |
7568 | } |
7569 | ||
aa7d318d TT |
7570 | /* Set an active std::terminate breakpoint for each std::terminate |
7571 | master breakpoint. */ | |
7572 | void | |
7573 | set_std_terminate_breakpoint (void) | |
7574 | { | |
1428b37a | 7575 | for (breakpoint *b : all_breakpoints_safe ()) |
aa7d318d TT |
7576 | if (b->pspace == current_program_space |
7577 | && b->type == bp_std_terminate_master) | |
7578 | { | |
06edf0c0 | 7579 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a0cd5f08 | 7580 | &base_breakpoint_ops, 1); |
aa7d318d TT |
7581 | } |
7582 | } | |
7583 | ||
7584 | /* Delete all the std::terminate breakpoints. */ | |
7585 | void | |
7586 | delete_std_terminate_breakpoint (void) | |
7587 | { | |
1428b37a | 7588 | for (breakpoint *b : all_breakpoints_safe ()) |
aa7d318d TT |
7589 | if (b->type == bp_std_terminate) |
7590 | delete_breakpoint (b); | |
7591 | } | |
7592 | ||
c4093a6a | 7593 | struct breakpoint * |
a6d9a66e | 7594 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7595 | { |
7596 | struct breakpoint *b; | |
c4093a6a | 7597 | |
06edf0c0 | 7598 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
a0cd5f08 | 7599 | &base_breakpoint_ops); |
06edf0c0 | 7600 | |
b5de0fa7 | 7601 | b->enable_state = bp_enabled; |
f00aae0f | 7602 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7603 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7604 | |
44702360 | 7605 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7606 | |
c4093a6a JM |
7607 | return b; |
7608 | } | |
7609 | ||
0101ce28 JJ |
7610 | struct lang_and_radix |
7611 | { | |
7612 | enum language lang; | |
7613 | int radix; | |
7614 | }; | |
7615 | ||
4efc6507 DE |
7616 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7617 | ||
7618 | struct breakpoint * | |
7619 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7620 | { | |
2a7f3dff | 7621 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
a0cd5f08 | 7622 | &base_breakpoint_ops); |
4efc6507 | 7623 | } |
0101ce28 | 7624 | |
03673fc7 PP |
7625 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7626 | ||
7627 | void | |
7628 | remove_jit_event_breakpoints (void) | |
7629 | { | |
1428b37a | 7630 | for (breakpoint *b : all_breakpoints_safe ()) |
03673fc7 PP |
7631 | if (b->type == bp_jit_event |
7632 | && b->loc->pspace == current_program_space) | |
7633 | delete_breakpoint (b); | |
7634 | } | |
7635 | ||
cae688ec JJ |
7636 | void |
7637 | remove_solib_event_breakpoints (void) | |
7638 | { | |
1428b37a | 7639 | for (breakpoint *b : all_breakpoints_safe ()) |
6c95b8df PA |
7640 | if (b->type == bp_shlib_event |
7641 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7642 | delete_breakpoint (b); |
7643 | } | |
7644 | ||
f37f681c PA |
7645 | /* See breakpoint.h. */ |
7646 | ||
7647 | void | |
7648 | remove_solib_event_breakpoints_at_next_stop (void) | |
7649 | { | |
1428b37a | 7650 | for (breakpoint *b : all_breakpoints_safe ()) |
f37f681c PA |
7651 | if (b->type == bp_shlib_event |
7652 | && b->loc->pspace == current_program_space) | |
7653 | b->disposition = disp_del_at_next_stop; | |
7654 | } | |
7655 | ||
04086b45 PA |
7656 | /* Helper for create_solib_event_breakpoint / |
7657 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7658 | INSERT_MODE to pass through to update_global_location_list. */ | |
7659 | ||
7660 | static struct breakpoint * | |
7661 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7662 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7663 | { |
7664 | struct breakpoint *b; | |
7665 | ||
06edf0c0 | 7666 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
a0cd5f08 | 7667 | &base_breakpoint_ops); |
04086b45 | 7668 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7669 | return b; |
7670 | } | |
7671 | ||
04086b45 PA |
7672 | struct breakpoint * |
7673 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7674 | { | |
7675 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7676 | } | |
7677 | ||
f37f681c PA |
7678 | /* See breakpoint.h. */ |
7679 | ||
7680 | struct breakpoint * | |
7681 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7682 | { | |
7683 | struct breakpoint *b; | |
7684 | ||
04086b45 PA |
7685 | /* Explicitly tell update_global_location_list to insert |
7686 | locations. */ | |
7687 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7688 | if (!b->loc->inserted) |
7689 | { | |
7690 | delete_breakpoint (b); | |
7691 | return NULL; | |
7692 | } | |
7693 | return b; | |
7694 | } | |
7695 | ||
cae688ec JJ |
7696 | /* Disable any breakpoints that are on code in shared libraries. Only |
7697 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7698 | ||
7699 | void | |
cb851954 | 7700 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7701 | { |
48d7020b | 7702 | for (bp_location *loc : all_bp_locations ()) |
01add95b SM |
7703 | { |
7704 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ | |
7705 | struct breakpoint *b = loc->owner; | |
7706 | ||
7707 | /* We apply the check to all breakpoints, including disabled for | |
7708 | those with loc->duplicate set. This is so that when breakpoint | |
7709 | becomes enabled, or the duplicate is removed, gdb will try to | |
7710 | insert all breakpoints. If we don't set shlib_disabled here, | |
7711 | we'll try to insert those breakpoints and fail. */ | |
7712 | if (((b->type == bp_breakpoint) | |
7713 | || (b->type == bp_jit_event) | |
7714 | || (b->type == bp_hardware_breakpoint) | |
7715 | || (is_tracepoint (b))) | |
7716 | && loc->pspace == current_program_space | |
7717 | && !loc->shlib_disabled | |
7718 | && solib_name_from_address (loc->pspace, loc->address) | |
7719 | ) | |
7720 | { | |
7721 | loc->shlib_disabled = 1; | |
7722 | } | |
7723 | } | |
cae688ec JJ |
7724 | } |
7725 | ||
63644780 NB |
7726 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7727 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7728 | disabled ones can just stay disabled. */ | |
84acb35a | 7729 | |
75149521 | 7730 | static void |
84acb35a JJ |
7731 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7732 | { | |
84acb35a JJ |
7733 | int disabled_shlib_breaks = 0; |
7734 | ||
48d7020b | 7735 | for (bp_location *loc : all_bp_locations ()) |
01add95b SM |
7736 | { |
7737 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ | |
7738 | struct breakpoint *b = loc->owner; | |
7739 | ||
7740 | if (solib->pspace == loc->pspace | |
7741 | && !loc->shlib_disabled | |
7742 | && (((b->type == bp_breakpoint | |
7743 | || b->type == bp_jit_event | |
7744 | || b->type == bp_hardware_breakpoint) | |
7745 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7746 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7747 | || is_tracepoint (b)) | |
7748 | && solib_contains_address_p (solib, loc->address)) | |
7749 | { | |
7750 | loc->shlib_disabled = 1; | |
7751 | /* At this point, we cannot rely on remove_breakpoint | |
7752 | succeeding so we must mark the breakpoint as not inserted | |
7753 | to prevent future errors occurring in remove_breakpoints. */ | |
7754 | loc->inserted = 0; | |
7755 | ||
7756 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7757 | gdb::observers::breakpoint_modified.notify (b); | |
7758 | ||
7759 | if (!disabled_shlib_breaks) | |
7760 | { | |
7761 | target_terminal::ours_for_output (); | |
7762 | warning (_("Temporarily disabling breakpoints " | |
7763 | "for unloaded shared library \"%s\""), | |
7764 | solib->so_name); | |
7765 | } | |
7766 | disabled_shlib_breaks = 1; | |
7767 | } | |
7768 | } | |
84acb35a JJ |
7769 | } |
7770 | ||
63644780 NB |
7771 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7772 | notification of free_objfile. Only apply to enabled breakpoints, | |
7773 | disabled ones can just stay disabled. */ | |
7774 | ||
7775 | static void | |
7776 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7777 | { | |
63644780 NB |
7778 | if (objfile == NULL) |
7779 | return; | |
7780 | ||
d03de421 PA |
7781 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7782 | managed by the user with add-symbol-file/remove-symbol-file. | |
7783 | Similarly to how breakpoints in shared libraries are handled in | |
7784 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7785 | shlib_disabled so they end up uninserted on the next global |
7786 | location list update. Shared libraries not loaded by the user | |
7787 | aren't handled here -- they're already handled in | |
7788 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7789 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7790 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7791 | main objfile). */ | |
7792 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7793 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7794 | return; |
7795 | ||
43892fdf | 7796 | for (breakpoint *b : all_breakpoints ()) |
63644780 | 7797 | { |
63644780 NB |
7798 | int bp_modified = 0; |
7799 | ||
7800 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7801 | continue; | |
7802 | ||
40cb8ca5 | 7803 | for (bp_location *loc : b->locations ()) |
63644780 NB |
7804 | { |
7805 | CORE_ADDR loc_addr = loc->address; | |
7806 | ||
7807 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7808 | && loc->loc_type != bp_loc_software_breakpoint) | |
7809 | continue; | |
7810 | ||
7811 | if (loc->shlib_disabled != 0) | |
7812 | continue; | |
7813 | ||
7814 | if (objfile->pspace != loc->pspace) | |
7815 | continue; | |
7816 | ||
7817 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7818 | && loc->loc_type != bp_loc_software_breakpoint) | |
7819 | continue; | |
7820 | ||
7821 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7822 | { | |
7823 | loc->shlib_disabled = 1; | |
08351840 PA |
7824 | /* At this point, we don't know whether the object was |
7825 | unmapped from the inferior or not, so leave the | |
7826 | inserted flag alone. We'll handle failure to | |
7827 | uninsert quietly, in case the object was indeed | |
7828 | unmapped. */ | |
63644780 NB |
7829 | |
7830 | mark_breakpoint_location_modified (loc); | |
7831 | ||
7832 | bp_modified = 1; | |
7833 | } | |
7834 | } | |
7835 | ||
7836 | if (bp_modified) | |
76727919 | 7837 | gdb::observers::breakpoint_modified.notify (b); |
63644780 NB |
7838 | } |
7839 | } | |
7840 | ||
b650a282 | 7841 | /* See breakpoint.h. */ |
ce78b96d | 7842 | |
ab04a2af | 7843 | void |
346774a9 | 7844 | init_catchpoint (struct breakpoint *b, |
b650a282 | 7845 | struct gdbarch *gdbarch, bool temp, |
b3316ff1 | 7846 | const char *cond_string) |
c906108c | 7847 | { |
51abb421 | 7848 | symtab_and_line sal; |
6c95b8df | 7849 | sal.pspace = current_program_space; |
c5aa993b | 7850 | |
b3316ff1 | 7851 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, |
a0cd5f08 | 7852 | &base_breakpoint_ops); |
ce78b96d | 7853 | |
6f781ee3 TT |
7854 | if (cond_string == nullptr) |
7855 | b->cond_string.reset (); | |
7856 | else | |
7857 | b->cond_string = make_unique_xstrdup (cond_string); | |
b650a282 | 7858 | b->disposition = temp ? disp_del : disp_donttouch; |
346774a9 PA |
7859 | } |
7860 | ||
28010a5d | 7861 | void |
b270e6f9 | 7862 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 7863 | { |
b270e6f9 | 7864 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 7865 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
7866 | if (is_tracepoint (b)) |
7867 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
7868 | if (!internal) |
7869 | mention (b); | |
76727919 | 7870 | gdb::observers::breakpoint_created.notify (b); |
3ea46bff YQ |
7871 | |
7872 | if (update_gll) | |
44702360 | 7873 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
7874 | } |
7875 | ||
c906108c | 7876 | static int |
fba45db2 | 7877 | hw_breakpoint_used_count (void) |
c906108c | 7878 | { |
c906108c SS |
7879 | int i = 0; |
7880 | ||
43892fdf | 7881 | for (breakpoint *b : all_breakpoints ()) |
d6b74ac4 | 7882 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
40cb8ca5 | 7883 | for (bp_location *bl : b->locations ()) |
f1310107 TJB |
7884 | { |
7885 | /* Special types of hardware breakpoints may use more than | |
7886 | one register. */ | |
c47614fe | 7887 | i += b->resources_needed (bl); |
f1310107 | 7888 | } |
c906108c SS |
7889 | |
7890 | return i; | |
7891 | } | |
7892 | ||
a1398e0c PA |
7893 | /* Returns the resources B would use if it were a hardware |
7894 | watchpoint. */ | |
7895 | ||
c906108c | 7896 | static int |
a1398e0c | 7897 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 7898 | { |
c906108c SS |
7899 | int i = 0; |
7900 | ||
a1398e0c PA |
7901 | if (!breakpoint_enabled (b)) |
7902 | return 0; | |
7903 | ||
40cb8ca5 | 7904 | for (bp_location *bl : b->locations ()) |
a1398e0c PA |
7905 | { |
7906 | /* Special types of hardware watchpoints may use more than | |
7907 | one register. */ | |
c47614fe | 7908 | i += b->resources_needed (bl); |
a1398e0c PA |
7909 | } |
7910 | ||
7911 | return i; | |
7912 | } | |
7913 | ||
7914 | /* Returns the sum the used resources of all hardware watchpoints of | |
7915 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
7916 | the sum of the used resources of all hardware watchpoints of other | |
7917 | types _not_ TYPE. */ | |
7918 | ||
7919 | static int | |
7920 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
7921 | enum bptype type, int *other_type_used) | |
7922 | { | |
7923 | int i = 0; | |
a1398e0c | 7924 | |
c906108c | 7925 | *other_type_used = 0; |
43892fdf | 7926 | for (breakpoint *b : all_breakpoints ()) |
e09342b5 | 7927 | { |
a1398e0c PA |
7928 | if (b == except) |
7929 | continue; | |
e09342b5 TJB |
7930 | if (!breakpoint_enabled (b)) |
7931 | continue; | |
7932 | ||
a1398e0c PA |
7933 | if (b->type == type) |
7934 | i += hw_watchpoint_use_count (b); | |
7935 | else if (is_hardware_watchpoint (b)) | |
7936 | *other_type_used = 1; | |
e09342b5 TJB |
7937 | } |
7938 | ||
c906108c SS |
7939 | return i; |
7940 | } | |
7941 | ||
c906108c | 7942 | void |
fba45db2 | 7943 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 7944 | { |
43892fdf | 7945 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 7946 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 7947 | { |
b5de0fa7 | 7948 | b->enable_state = bp_call_disabled; |
44702360 | 7949 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b | 7950 | } |
c906108c SS |
7951 | } |
7952 | ||
7953 | void | |
fba45db2 | 7954 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 7955 | { |
43892fdf | 7956 | for (breakpoint *b : all_breakpoints ()) |
cc60f2e3 | 7957 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 7958 | { |
b5de0fa7 | 7959 | b->enable_state = bp_enabled; |
44702360 | 7960 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b | 7961 | } |
c906108c SS |
7962 | } |
7963 | ||
8bea4e01 UW |
7964 | void |
7965 | disable_breakpoints_before_startup (void) | |
7966 | { | |
6c95b8df | 7967 | current_program_space->executing_startup = 1; |
44702360 | 7968 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
7969 | } |
7970 | ||
7971 | void | |
7972 | enable_breakpoints_after_startup (void) | |
7973 | { | |
6c95b8df | 7974 | current_program_space->executing_startup = 0; |
f8eba3c6 | 7975 | breakpoint_re_set (); |
8bea4e01 UW |
7976 | } |
7977 | ||
7c16b83e PA |
7978 | /* Create a new single-step breakpoint for thread THREAD, with no |
7979 | locations. */ | |
c906108c | 7980 | |
7c16b83e PA |
7981 | static struct breakpoint * |
7982 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
7983 | { | |
2b5ab5b8 | 7984 | std::unique_ptr<breakpoint> b (new momentary_breakpoint ()); |
7c16b83e | 7985 | |
b270e6f9 | 7986 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
a0cd5f08 | 7987 | &base_breakpoint_ops); |
7c16b83e PA |
7988 | |
7989 | b->disposition = disp_donttouch; | |
7990 | b->frame_id = null_frame_id; | |
7991 | ||
7992 | b->thread = thread; | |
7993 | gdb_assert (b->thread != 0); | |
7994 | ||
b270e6f9 | 7995 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
7996 | } |
7997 | ||
7998 | /* Set a momentary breakpoint of type TYPE at address specified by | |
7999 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8000 | frame. */ | |
c906108c | 8001 | |
454dafbd | 8002 | breakpoint_up |
a6d9a66e UW |
8003 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8004 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8005 | { |
52f0bd74 | 8006 | struct breakpoint *b; |
edb3359d | 8007 | |
193facb3 JK |
8008 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8009 | tail-called one. */ | |
8010 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8011 | |
a0cd5f08 | 8012 | b = set_raw_breakpoint (gdbarch, sal, type, &base_breakpoint_ops); |
b5de0fa7 EZ |
8013 | b->enable_state = bp_enabled; |
8014 | b->disposition = disp_donttouch; | |
818dd999 | 8015 | b->frame_id = frame_id; |
c906108c | 8016 | |
00431a78 | 8017 | b->thread = inferior_thread ()->global_num; |
c906108c | 8018 | |
44702360 | 8019 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8020 | |
454dafbd | 8021 | return breakpoint_up (b); |
c906108c | 8022 | } |
611c83ae | 8023 | |
06edf0c0 | 8024 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8025 | The new breakpoint will have type TYPE, use OPS as its |
8026 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8027 | |
06edf0c0 PA |
8028 | static struct breakpoint * |
8029 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8030 | enum bptype type, | |
a1aa2221 LM |
8031 | const struct breakpoint_ops *ops, |
8032 | int loc_enabled) | |
e58b0e63 PA |
8033 | { |
8034 | struct breakpoint *copy; | |
8035 | ||
06edf0c0 | 8036 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8037 | copy->loc = allocate_bp_location (copy); |
0ba852ab | 8038 | set_breakpoint_location_function (copy->loc); |
e58b0e63 | 8039 | |
a6d9a66e | 8040 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8041 | copy->loc->requested_address = orig->loc->requested_address; |
8042 | copy->loc->address = orig->loc->address; | |
8043 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8044 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8045 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8046 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8047 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8048 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8049 | copy->frame_id = orig->frame_id; |
8050 | copy->thread = orig->thread; | |
6c95b8df | 8051 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8052 | |
8053 | copy->enable_state = bp_enabled; | |
8054 | copy->disposition = disp_donttouch; | |
8055 | copy->number = internal_breakpoint_number--; | |
8056 | ||
44702360 | 8057 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8058 | return copy; |
8059 | } | |
8060 | ||
06edf0c0 PA |
8061 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8062 | ORIG is NULL. */ | |
8063 | ||
8064 | struct breakpoint * | |
8065 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8066 | { | |
8067 | /* If there's nothing to clone, then return nothing. */ | |
8068 | if (orig == NULL) | |
8069 | return NULL; | |
8070 | ||
a0cd5f08 | 8071 | gdb_assert (orig->ops == &base_breakpoint_ops); |
a1aa2221 | 8072 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8073 | } |
8074 | ||
454dafbd | 8075 | breakpoint_up |
a6d9a66e UW |
8076 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8077 | enum bptype type) | |
611c83ae PA |
8078 | { |
8079 | struct symtab_and_line sal; | |
8080 | ||
8081 | sal = find_pc_line (pc, 0); | |
8082 | sal.pc = pc; | |
8083 | sal.section = find_pc_overlay (pc); | |
8084 | sal.explicit_pc = 1; | |
8085 | ||
a6d9a66e | 8086 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8087 | } |
c906108c | 8088 | \f |
c5aa993b | 8089 | |
c906108c SS |
8090 | /* Tell the user we have just set a breakpoint B. */ |
8091 | ||
8092 | static void | |
fba45db2 | 8093 | mention (struct breakpoint *b) |
c906108c | 8094 | { |
c47614fe | 8095 | b->print_mention (); |
2d33446d | 8096 | current_uiout->text ("\n"); |
c906108c | 8097 | } |
c906108c | 8098 | \f |
c5aa993b | 8099 | |
5133a315 | 8100 | static bool bp_loc_is_permanent (struct bp_location *loc); |
1a853c52 | 8101 | |
7f32a4d5 PA |
8102 | /* Handle "set breakpoint auto-hw on". |
8103 | ||
8104 | If the explicitly specified breakpoint type is not hardware | |
8105 | breakpoint, check the memory map to see whether the breakpoint | |
8106 | address is in read-only memory. | |
8107 | ||
8108 | - location type is not hardware breakpoint, memory is read-only. | |
8109 | We change the type of the location to hardware breakpoint. | |
8110 | ||
8111 | - location type is hardware breakpoint, memory is read-write. This | |
8112 | means we've previously made the location hardware one, but then the | |
8113 | memory map changed, so we undo. | |
8114 | */ | |
8115 | ||
8116 | static void | |
8117 | handle_automatic_hardware_breakpoints (bp_location *bl) | |
8118 | { | |
8119 | if (automatic_hardware_breakpoints | |
8120 | && bl->owner->type != bp_hardware_breakpoint | |
8121 | && (bl->loc_type == bp_loc_software_breakpoint | |
8122 | || bl->loc_type == bp_loc_hardware_breakpoint)) | |
8123 | { | |
8124 | /* When breakpoints are removed, remove_breakpoints will use | |
8125 | location types we've just set here, the only possible problem | |
8126 | is that memory map has changed during running program, but | |
8127 | it's not going to work anyway with current gdb. */ | |
8128 | mem_region *mr = lookup_mem_region (bl->address); | |
8129 | ||
8130 | if (mr != nullptr) | |
8131 | { | |
8132 | enum bp_loc_type new_type; | |
8133 | ||
8134 | if (mr->attrib.mode != MEM_RW) | |
8135 | new_type = bp_loc_hardware_breakpoint; | |
8136 | else | |
8137 | new_type = bp_loc_software_breakpoint; | |
8138 | ||
8139 | if (new_type != bl->loc_type) | |
8140 | { | |
8141 | static bool said = false; | |
8142 | ||
8143 | bl->loc_type = new_type; | |
8144 | if (!said) | |
8145 | { | |
6cb06a8c TT |
8146 | gdb_printf (_("Note: automatically using " |
8147 | "hardware breakpoints for " | |
8148 | "read-only addresses.\n")); | |
7f32a4d5 PA |
8149 | said = true; |
8150 | } | |
8151 | } | |
8152 | } | |
8153 | } | |
8154 | } | |
8155 | ||
0d381245 | 8156 | static struct bp_location * |
39d61571 | 8157 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8158 | const struct symtab_and_line *sal) |
8159 | { | |
8160 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8161 | CORE_ADDR adjusted_address; |
8162 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8163 | ||
8164 | if (loc_gdbarch == NULL) | |
8165 | loc_gdbarch = b->gdbarch; | |
8166 | ||
8167 | /* Adjust the breakpoint's address prior to allocating a location. | |
8168 | Once we call allocate_bp_location(), that mostly uninitialized | |
8169 | location will be placed on the location chain. Adjustment of the | |
8170 | breakpoint may cause target_read_memory() to be called and we do | |
8171 | not want its scan of the location chain to find a breakpoint and | |
8172 | location that's only been partially initialized. */ | |
8173 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8174 | sal->pc, b->type); | |
0d381245 | 8175 | |
d30113d4 | 8176 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8177 | loc = allocate_bp_location (b); |
d30113d4 JK |
8178 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8179 | tmp = &((*tmp)->next)) | |
0d381245 | 8180 | ; |
d30113d4 | 8181 | loc->next = *tmp; |
0d381245 | 8182 | *tmp = loc; |
3742cc8b | 8183 | |
0d381245 | 8184 | loc->requested_address = sal->pc; |
3742cc8b | 8185 | loc->address = adjusted_address; |
6c95b8df | 8186 | loc->pspace = sal->pspace; |
935676c9 | 8187 | loc->probe.prob = sal->prob; |
729662a5 | 8188 | loc->probe.objfile = sal->objfile; |
6c95b8df | 8189 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8190 | loc->section = sal->section; |
3742cc8b | 8191 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8192 | loc->line_number = sal->line; |
2f202fde | 8193 | loc->symtab = sal->symtab; |
4a27f119 | 8194 | loc->symbol = sal->symbol; |
3467ec66 PA |
8195 | loc->msymbol = sal->msymbol; |
8196 | loc->objfile = sal->objfile; | |
f8eba3c6 | 8197 | |
0ba852ab | 8198 | set_breakpoint_location_function (loc); |
1a853c52 | 8199 | |
6ae88661 LM |
8200 | /* While by definition, permanent breakpoints are already present in the |
8201 | code, we don't mark the location as inserted. Normally one would expect | |
8202 | that GDB could rely on that breakpoint instruction to stop the program, | |
8203 | thus removing the need to insert its own breakpoint, except that executing | |
8204 | the breakpoint instruction can kill the target instead of reporting a | |
8205 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8206 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8207 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8208 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8209 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8210 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8211 | it manually increments the PC, thus avoiding executing the breakpoint | |
8212 | instruction.) */ | |
1a853c52 | 8213 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8214 | loc->permanent = 1; |
1a853c52 | 8215 | |
0d381245 VP |
8216 | return loc; |
8217 | } | |
514f746b AR |
8218 | \f |
8219 | ||
5133a315 LM |
8220 | /* Return true if LOC is pointing to a permanent breakpoint, |
8221 | return false otherwise. */ | |
1cf4d951 | 8222 | |
5133a315 | 8223 | static bool |
1cf4d951 PA |
8224 | bp_loc_is_permanent (struct bp_location *loc) |
8225 | { | |
514f746b AR |
8226 | gdb_assert (loc != NULL); |
8227 | ||
cb1e4e32 PA |
8228 | /* If we have a non-breakpoint-backed catchpoint or a software |
8229 | watchpoint, just return 0. We should not attempt to read from | |
8230 | the addresses the locations of these breakpoint types point to. | |
5133a315 | 8231 | gdbarch_program_breakpoint_here_p, below, will attempt to read |
244558af | 8232 | memory. */ |
cb1e4e32 | 8233 | if (!bl_address_is_meaningful (loc)) |
5133a315 | 8234 | return false; |
244558af | 8235 | |
5ed8105e | 8236 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8237 | switch_to_program_space_and_thread (loc->pspace); |
5133a315 | 8238 | return gdbarch_program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8239 | } |
8240 | ||
e7e0cddf SS |
8241 | /* Build a command list for the dprintf corresponding to the current |
8242 | settings of the dprintf style options. */ | |
8243 | ||
8244 | static void | |
8245 | update_dprintf_command_list (struct breakpoint *b) | |
8246 | { | |
6f781ee3 | 8247 | const char *dprintf_args = b->extra_string.get (); |
8579fd13 | 8248 | gdb::unique_xmalloc_ptr<char> printf_line = nullptr; |
e7e0cddf SS |
8249 | |
8250 | if (!dprintf_args) | |
8251 | return; | |
8252 | ||
8253 | dprintf_args = skip_spaces (dprintf_args); | |
8254 | ||
8255 | /* Allow a comma, as it may have terminated a location, but don't | |
8256 | insist on it. */ | |
8257 | if (*dprintf_args == ',') | |
8258 | ++dprintf_args; | |
8259 | dprintf_args = skip_spaces (dprintf_args); | |
8260 | ||
8261 | if (*dprintf_args != '"') | |
8262 | error (_("Bad format string, missing '\"'.")); | |
8263 | ||
d3ce09f5 | 8264 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8265 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8266 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf | 8267 | { |
e0700ba4 | 8268 | if (dprintf_function.empty ()) |
e7e0cddf SS |
8269 | error (_("No function supplied for dprintf call")); |
8270 | ||
e0700ba4 | 8271 | if (!dprintf_channel.empty ()) |
e7e0cddf | 8272 | printf_line = xstrprintf ("call (void) %s (%s,%s)", |
e0700ba4 SM |
8273 | dprintf_function.c_str (), |
8274 | dprintf_channel.c_str (), | |
e7e0cddf SS |
8275 | dprintf_args); |
8276 | else | |
8277 | printf_line = xstrprintf ("call (void) %s (%s)", | |
e0700ba4 | 8278 | dprintf_function.c_str (), |
e7e0cddf SS |
8279 | dprintf_args); |
8280 | } | |
d3ce09f5 SS |
8281 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8282 | { | |
8283 | if (target_can_run_breakpoint_commands ()) | |
8284 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8285 | else | |
8286 | { | |
8287 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8288 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8289 | } | |
8290 | } | |
e7e0cddf SS |
8291 | else |
8292 | internal_error (__FILE__, __LINE__, | |
8293 | _("Invalid dprintf style.")); | |
8294 | ||
f28045c2 | 8295 | gdb_assert (printf_line != NULL); |
e7e0cddf | 8296 | |
12973681 TT |
8297 | /* Manufacture a printf sequence. */ |
8298 | struct command_line *printf_cmd_line | |
8579fd13 | 8299 | = new struct command_line (simple_control, printf_line.release ()); |
12973681 TT |
8300 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, |
8301 | command_lines_deleter ())); | |
e7e0cddf SS |
8302 | } |
8303 | ||
8304 | /* Update all dprintf commands, making their command lists reflect | |
8305 | current style settings. */ | |
8306 | ||
8307 | static void | |
eb4c3f4a | 8308 | update_dprintf_commands (const char *args, int from_tty, |
e7e0cddf SS |
8309 | struct cmd_list_element *c) |
8310 | { | |
43892fdf SM |
8311 | for (breakpoint *b : all_breakpoints ()) |
8312 | if (b->type == bp_dprintf) | |
e7e0cddf | 8313 | update_dprintf_command_list (b); |
e7e0cddf | 8314 | } |
c3f6f71d | 8315 | |
f00aae0f KS |
8316 | /* Create a breakpoint with SAL as location. Use LOCATION |
8317 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
8318 | as condition expression. If LOCATION is NULL then create an |
8319 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
8320 | |
8321 | static void | |
d9b3f62e | 8322 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 8323 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8324 | event_location_up &&location, |
e1e01040 PA |
8325 | gdb::unique_xmalloc_ptr<char> filter, |
8326 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8327 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8328 | enum bptype type, enum bpdisp disposition, |
8329 | int thread, int task, int ignore_count, | |
c0a91b2b | 8330 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8331 | int enabled, int internal, unsigned flags, |
8332 | int display_canonical) | |
018d34a4 | 8333 | { |
0d381245 | 8334 | int i; |
018d34a4 VP |
8335 | |
8336 | if (type == bp_hardware_breakpoint) | |
8337 | { | |
fbbd034e AS |
8338 | int target_resources_ok; |
8339 | ||
8340 | i = hw_breakpoint_used_count (); | |
8341 | target_resources_ok = | |
8342 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
8343 | i + 1, 0); |
8344 | if (target_resources_ok == 0) | |
8345 | error (_("No hardware breakpoint support in the target.")); | |
8346 | else if (target_resources_ok < 0) | |
8347 | error (_("Hardware breakpoints used exceeds limit.")); | |
8348 | } | |
8349 | ||
6c5b2ebe | 8350 | gdb_assert (!sals.empty ()); |
6c95b8df | 8351 | |
6c5b2ebe | 8352 | for (const auto &sal : sals) |
0d381245 | 8353 | { |
0d381245 VP |
8354 | struct bp_location *loc; |
8355 | ||
8356 | if (from_tty) | |
5af949e3 UW |
8357 | { |
8358 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
8359 | if (!loc_gdbarch) | |
8360 | loc_gdbarch = gdbarch; | |
8361 | ||
8362 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 8363 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 8364 | } |
0d381245 | 8365 | |
6c5b2ebe | 8366 | if (&sal == &sals[0]) |
0d381245 | 8367 | { |
d9b3f62e | 8368 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 8369 | b->thread = thread; |
4a306c9a | 8370 | b->task = task; |
855a6e68 | 8371 | |
6f781ee3 TT |
8372 | b->cond_string = std::move (cond_string); |
8373 | b->extra_string = std::move (extra_string); | |
0d381245 | 8374 | b->ignore_count = ignore_count; |
41447f92 | 8375 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 8376 | b->disposition = disposition; |
6c95b8df | 8377 | |
44f238bb PA |
8378 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8379 | b->loc->inserted = 1; | |
8380 | ||
7b572efb TT |
8381 | if (type == bp_static_tracepoint |
8382 | || type == bp_static_marker_tracepoint) | |
0fb4aa4b | 8383 | { |
d9b3f62e | 8384 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
8385 | struct static_tracepoint_marker marker; |
8386 | ||
983af33b | 8387 | if (strace_marker_p (b)) |
0fb4aa4b PA |
8388 | { |
8389 | /* We already know the marker exists, otherwise, we | |
8390 | wouldn't see a sal for it. */ | |
d28cd78a TT |
8391 | const char *p |
8392 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 8393 | const char *endp; |
0fb4aa4b | 8394 | |
f1735a53 | 8395 | p = skip_spaces (p); |
0fb4aa4b | 8396 | |
f1735a53 | 8397 | endp = skip_to_space (p); |
0fb4aa4b | 8398 | |
5d9310c4 | 8399 | t->static_trace_marker_id.assign (p, endp - p); |
0fb4aa4b | 8400 | |
6cb06a8c TT |
8401 | gdb_printf (_("Probed static tracepoint " |
8402 | "marker \"%s\"\n"), | |
8403 | t->static_trace_marker_id.c_str ()); | |
0fb4aa4b PA |
8404 | } |
8405 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
8406 | { | |
5d9310c4 | 8407 | t->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b | 8408 | |
6cb06a8c TT |
8409 | gdb_printf (_("Probed static tracepoint " |
8410 | "marker \"%s\"\n"), | |
8411 | t->static_trace_marker_id.c_str ()); | |
0fb4aa4b PA |
8412 | } |
8413 | else | |
3e43a32a MS |
8414 | warning (_("Couldn't determine the static " |
8415 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
8416 | } |
8417 | ||
0d381245 VP |
8418 | loc = b->loc; |
8419 | } | |
8420 | else | |
018d34a4 | 8421 | { |
39d61571 | 8422 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
8423 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
8424 | loc->inserted = 1; | |
0d381245 VP |
8425 | } |
8426 | ||
b5fa468f TBA |
8427 | /* Do not set breakpoint locations conditions yet. As locations |
8428 | are inserted, they get sorted based on their addresses. Let | |
8429 | the list stabilize to have reliable location numbers. */ | |
e7e0cddf SS |
8430 | |
8431 | /* Dynamic printf requires and uses additional arguments on the | |
8432 | command line, otherwise it's an error. */ | |
8433 | if (type == bp_dprintf) | |
8434 | { | |
8435 | if (b->extra_string) | |
8436 | update_dprintf_command_list (b); | |
8437 | else | |
8438 | error (_("Format string required")); | |
8439 | } | |
8440 | else if (b->extra_string) | |
6f781ee3 | 8441 | error (_("Garbage '%s' at end of command"), b->extra_string.get ()); |
855a6e68 | 8442 | } |
018d34a4 | 8443 | |
b5fa468f TBA |
8444 | |
8445 | /* The order of the locations is now stable. Set the location | |
8446 | condition using the location's number. */ | |
8447 | int loc_num = 1; | |
40cb8ca5 | 8448 | for (bp_location *loc : b->locations ()) |
b5fa468f TBA |
8449 | { |
8450 | if (b->cond_string != nullptr) | |
6f781ee3 TT |
8451 | set_breakpoint_location_condition (b->cond_string.get (), loc, |
8452 | b->number, loc_num); | |
b5fa468f TBA |
8453 | |
8454 | ++loc_num; | |
8455 | } | |
8456 | ||
56435ebe | 8457 | b->display_canonical = display_canonical; |
f00aae0f | 8458 | if (location != NULL) |
d28cd78a | 8459 | b->location = std::move (location); |
018d34a4 | 8460 | else |
d28cd78a | 8461 | b->location = new_address_location (b->loc->address, NULL, 0); |
c0e8dcd8 | 8462 | b->filter = std::move (filter); |
d9b3f62e | 8463 | } |
018d34a4 | 8464 | |
d9b3f62e PA |
8465 | static void |
8466 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 8467 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 8468 | event_location_up &&location, |
e1e01040 PA |
8469 | gdb::unique_xmalloc_ptr<char> filter, |
8470 | gdb::unique_xmalloc_ptr<char> cond_string, | |
8471 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
8472 | enum bptype type, enum bpdisp disposition, |
8473 | int thread, int task, int ignore_count, | |
c0a91b2b | 8474 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
8475 | int enabled, int internal, unsigned flags, |
8476 | int display_canonical) | |
d9b3f62e | 8477 | { |
a5e364af | 8478 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 8479 | |
a5e364af | 8480 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 8481 | sals, std::move (location), |
e1e01040 PA |
8482 | std::move (filter), |
8483 | std::move (cond_string), | |
8484 | std::move (extra_string), | |
d9b3f62e PA |
8485 | type, disposition, |
8486 | thread, task, ignore_count, | |
8487 | ops, from_tty, | |
44f238bb PA |
8488 | enabled, internal, flags, |
8489 | display_canonical); | |
d9b3f62e | 8490 | |
b270e6f9 | 8491 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
8492 | } |
8493 | ||
8494 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
8495 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
8496 | value. COND_STRING, if not NULL, specified the condition to be | |
8497 | used for all breakpoints. Essentially the only case where | |
8498 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
8499 | function. In that case, it's still not possible to specify | |
8500 | separate conditions for different overloaded functions, so | |
8501 | we take just a single condition string. | |
8502 | ||
c3f6f71d | 8503 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 8504 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
8505 | array contents). If the function fails (error() is called), the |
8506 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 8507 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
8508 | |
8509 | static void | |
8cdf0e15 | 8510 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 8511 | struct linespec_result *canonical, |
e1e01040 PA |
8512 | gdb::unique_xmalloc_ptr<char> cond_string, |
8513 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
8514 | enum bptype type, enum bpdisp disposition, |
8515 | int thread, int task, int ignore_count, | |
c0a91b2b | 8516 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 8517 | int enabled, int internal, unsigned flags) |
c906108c | 8518 | { |
f8eba3c6 | 8519 | if (canonical->pre_expanded) |
6c5b2ebe | 8520 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 8521 | |
6c5b2ebe | 8522 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 8523 | { |
f00aae0f | 8524 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 8525 | 'break', without arguments. */ |
ffc2605c | 8526 | event_location_up location |
f00aae0f | 8527 | = (canonical->location != NULL |
8e9e35b1 | 8528 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 8529 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 8530 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 8531 | |
6c5b2ebe | 8532 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 8533 | std::move (location), |
e1e01040 PA |
8534 | std::move (filter_string), |
8535 | std::move (cond_string), | |
8536 | std::move (extra_string), | |
e7e0cddf | 8537 | type, disposition, |
84f4c1fe | 8538 | thread, task, ignore_count, ops, |
44f238bb | 8539 | from_tty, enabled, internal, flags, |
56435ebe | 8540 | canonical->special_display); |
c3f6f71d | 8541 | } |
c3f6f71d | 8542 | } |
c906108c | 8543 | |
f00aae0f | 8544 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 8545 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
8546 | addresses found. LOCATION points to the end of the SAL (for |
8547 | linespec locations). | |
9998af43 TJB |
8548 | |
8549 | The array and the line spec strings are allocated on the heap, it is | |
8550 | the caller's responsibility to free them. */ | |
c906108c | 8551 | |
b9362cc7 | 8552 | static void |
626d2320 | 8553 | parse_breakpoint_sals (struct event_location *location, |
58438ac1 | 8554 | struct linespec_result *canonical) |
c3f6f71d | 8555 | { |
f00aae0f KS |
8556 | struct symtab_and_line cursal; |
8557 | ||
8558 | if (event_location_type (location) == LINESPEC_LOCATION) | |
8559 | { | |
a20714ff | 8560 | const char *spec = get_linespec_location (location)->spec_string; |
f00aae0f | 8561 | |
a20714ff | 8562 | if (spec == NULL) |
f00aae0f KS |
8563 | { |
8564 | /* The last displayed codepoint, if it's valid, is our default | |
8565 | breakpoint address. */ | |
8566 | if (last_displayed_sal_is_valid ()) | |
8567 | { | |
f00aae0f KS |
8568 | /* Set sal's pspace, pc, symtab, and line to the values |
8569 | corresponding to the last call to print_frame_info. | |
8570 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
8571 | as the breakpoint line number is inappropriate otherwise. | |
8572 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
8573 | symtab_and_line sal = get_last_displayed_sal (); |
8574 | CORE_ADDR pc = sal.pc; | |
8575 | ||
f00aae0f KS |
8576 | sal = find_pc_line (pc, 0); |
8577 | ||
8578 | /* "break" without arguments is equivalent to "break *PC" | |
8579 | where PC is the last displayed codepoint's address. So | |
8580 | make sure to set sal.explicit_pc to prevent GDB from | |
8581 | trying to expand the list of sals to include all other | |
8582 | instances with the same symtab and line. */ | |
8583 | sal.pc = pc; | |
8584 | sal.explicit_pc = 1; | |
8585 | ||
6c5b2ebe PA |
8586 | struct linespec_sals lsal; |
8587 | lsal.sals = {sal}; | |
f00aae0f KS |
8588 | lsal.canonical = NULL; |
8589 | ||
6c5b2ebe | 8590 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
8591 | return; |
8592 | } | |
8593 | else | |
8594 | error (_("No default breakpoint address now.")); | |
c906108c | 8595 | } |
c906108c | 8596 | } |
f00aae0f KS |
8597 | |
8598 | /* Force almost all breakpoints to be in terms of the | |
8599 | current_source_symtab (which is decode_line_1's default). | |
8600 | This should produce the results we want almost all of the | |
8601 | time while leaving default_breakpoint_* alone. | |
8602 | ||
8603 | ObjC: However, don't match an Objective-C method name which | |
8604 | may have a '+' or '-' succeeded by a '['. */ | |
8605 | cursal = get_current_source_symtab_and_line (); | |
8606 | if (last_displayed_sal_is_valid ()) | |
c906108c | 8607 | { |
a20714ff | 8608 | const char *spec = NULL; |
cc80f267 | 8609 | |
f00aae0f | 8610 | if (event_location_type (location) == LINESPEC_LOCATION) |
a20714ff | 8611 | spec = get_linespec_location (location)->spec_string; |
cc80f267 | 8612 | |
f00aae0f | 8613 | if (!cursal.symtab |
a20714ff PA |
8614 | || (spec != NULL |
8615 | && strchr ("+-", spec[0]) != NULL | |
8616 | && spec[1] != '[')) | |
f00aae0f | 8617 | { |
c2f4122d | 8618 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
8619 | get_last_displayed_symtab (), |
8620 | get_last_displayed_line (), | |
8621 | canonical, NULL, NULL); | |
8622 | return; | |
8623 | } | |
c906108c | 8624 | } |
f00aae0f | 8625 | |
c2f4122d | 8626 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 8627 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 8628 | } |
c906108c | 8629 | |
c906108c | 8630 | |
c3f6f71d | 8631 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 8632 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 8633 | |
b9362cc7 | 8634 | static void |
6c5b2ebe | 8635 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 8636 | { |
6c5b2ebe PA |
8637 | for (auto &sal : sals) |
8638 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
8639 | } |
8640 | ||
7a697b8d SS |
8641 | /* Fast tracepoints may have restrictions on valid locations. For |
8642 | instance, a fast tracepoint using a jump instead of a trap will | |
8643 | likely have to overwrite more bytes than a trap would, and so can | |
8644 | only be placed where the instruction is longer than the jump, or a | |
8645 | multi-instruction sequence does not have a jump into the middle of | |
8646 | it, etc. */ | |
8647 | ||
8648 | static void | |
8649 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 8650 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 8651 | { |
6c5b2ebe | 8652 | for (const auto &sal : sals) |
7a697b8d | 8653 | { |
f8eba3c6 TT |
8654 | struct gdbarch *sarch; |
8655 | ||
6c5b2ebe | 8656 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
8657 | /* We fall back to GDBARCH if there is no architecture |
8658 | associated with SAL. */ | |
8659 | if (sarch == NULL) | |
8660 | sarch = gdbarch; | |
281d762b TT |
8661 | std::string msg; |
8662 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) | |
53c3572a | 8663 | error (_("May not have a fast tracepoint at %s%s"), |
281d762b | 8664 | paddress (sarch, sal.pc), msg.c_str ()); |
7a697b8d SS |
8665 | } |
8666 | } | |
8667 | ||
018d34a4 VP |
8668 | /* Given TOK, a string specification of condition and thread, as |
8669 | accepted by the 'break' command, extract the condition | |
8670 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 8671 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
8672 | If no condition is found, *COND_STRING is set to NULL. |
8673 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
8674 | |
8675 | static void | |
bbc13ae3 | 8676 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
6f781ee3 TT |
8677 | gdb::unique_xmalloc_ptr<char> *cond_string, |
8678 | int *thread, int *task, | |
8679 | gdb::unique_xmalloc_ptr<char> *rest) | |
018d34a4 | 8680 | { |
6f781ee3 | 8681 | cond_string->reset (); |
018d34a4 | 8682 | *thread = -1; |
ed1d1739 | 8683 | *task = 0; |
6f781ee3 | 8684 | rest->reset (); |
733d554a | 8685 | bool force = false; |
ed1d1739 | 8686 | |
018d34a4 VP |
8687 | while (tok && *tok) |
8688 | { | |
bbc13ae3 | 8689 | const char *end_tok; |
018d34a4 | 8690 | int toklen; |
bbc13ae3 KS |
8691 | const char *cond_start = NULL; |
8692 | const char *cond_end = NULL; | |
cc59ec59 | 8693 | |
f1735a53 | 8694 | tok = skip_spaces (tok); |
e7e0cddf SS |
8695 | |
8696 | if ((*tok == '"' || *tok == ',') && rest) | |
8697 | { | |
6f781ee3 | 8698 | rest->reset (savestring (tok, strlen (tok))); |
e7e0cddf SS |
8699 | return; |
8700 | } | |
8701 | ||
f1735a53 | 8702 | end_tok = skip_to_space (tok); |
d634f2de | 8703 | |
018d34a4 | 8704 | toklen = end_tok - tok; |
d634f2de | 8705 | |
018d34a4 VP |
8706 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
8707 | { | |
8708 | tok = cond_start = end_tok + 1; | |
733d554a TBA |
8709 | try |
8710 | { | |
8711 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); | |
8712 | } | |
8713 | catch (const gdb_exception_error &) | |
8714 | { | |
8715 | if (!force) | |
8716 | throw; | |
8717 | else | |
8718 | tok = tok + strlen (tok); | |
8719 | } | |
018d34a4 | 8720 | cond_end = tok; |
6f781ee3 | 8721 | cond_string->reset (savestring (cond_start, cond_end - cond_start)); |
018d34a4 | 8722 | } |
733d554a TBA |
8723 | else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0) |
8724 | { | |
5759831a | 8725 | tok = tok + toklen; |
733d554a TBA |
8726 | force = true; |
8727 | } | |
018d34a4 VP |
8728 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
8729 | { | |
5d5658a1 PA |
8730 | const char *tmptok; |
8731 | struct thread_info *thr; | |
d634f2de | 8732 | |
018d34a4 | 8733 | tok = end_tok + 1; |
5d5658a1 | 8734 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
8735 | if (tok == tmptok) |
8736 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 8737 | *thread = thr->global_num; |
bbc13ae3 | 8738 | tok = tmptok; |
018d34a4 | 8739 | } |
4a306c9a JB |
8740 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
8741 | { | |
8742 | char *tmptok; | |
8743 | ||
8744 | tok = end_tok + 1; | |
bbc13ae3 | 8745 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
8746 | if (tok == tmptok) |
8747 | error (_("Junk after task keyword.")); | |
8748 | if (!valid_task_id (*task)) | |
b6199126 | 8749 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 8750 | tok = tmptok; |
4a306c9a | 8751 | } |
e7e0cddf SS |
8752 | else if (rest) |
8753 | { | |
6f781ee3 | 8754 | rest->reset (savestring (tok, strlen (tok))); |
ccab2054 | 8755 | return; |
e7e0cddf | 8756 | } |
018d34a4 VP |
8757 | else |
8758 | error (_("Junk at end of arguments.")); | |
8759 | } | |
8760 | } | |
8761 | ||
b5fa468f TBA |
8762 | /* Call 'find_condition_and_thread' for each sal in SALS until a parse |
8763 | succeeds. The parsed values are written to COND_STRING, THREAD, | |
8764 | TASK, and REST. See the comment of 'find_condition_and_thread' | |
8765 | for the description of these parameters and INPUT. */ | |
8766 | ||
8767 | static void | |
8768 | find_condition_and_thread_for_sals (const std::vector<symtab_and_line> &sals, | |
6f781ee3 TT |
8769 | const char *input, |
8770 | gdb::unique_xmalloc_ptr<char> *cond_string, | |
8771 | int *thread, int *task, | |
8772 | gdb::unique_xmalloc_ptr<char> *rest) | |
b5fa468f TBA |
8773 | { |
8774 | int num_failures = 0; | |
8775 | for (auto &sal : sals) | |
8776 | { | |
6f781ee3 | 8777 | gdb::unique_xmalloc_ptr<char> cond; |
b5fa468f TBA |
8778 | int thread_id = 0; |
8779 | int task_id = 0; | |
6f781ee3 | 8780 | gdb::unique_xmalloc_ptr<char> remaining; |
b5fa468f TBA |
8781 | |
8782 | /* Here we want to parse 'arg' to separate condition from thread | |
8783 | number. But because parsing happens in a context and the | |
8784 | contexts of sals might be different, try each until there is | |
8785 | success. Finding one successful parse is sufficient for our | |
8786 | goal. When setting the breakpoint we'll re-parse the | |
8787 | condition in the context of each sal. */ | |
8788 | try | |
8789 | { | |
8790 | find_condition_and_thread (input, sal.pc, &cond, &thread_id, | |
8791 | &task_id, &remaining); | |
6f781ee3 | 8792 | *cond_string = std::move (cond); |
b5fa468f TBA |
8793 | *thread = thread_id; |
8794 | *task = task_id; | |
6f781ee3 | 8795 | *rest = std::move (remaining); |
b5fa468f TBA |
8796 | break; |
8797 | } | |
8798 | catch (const gdb_exception_error &e) | |
8799 | { | |
8800 | num_failures++; | |
8801 | /* If no sal remains, do not continue. */ | |
8802 | if (num_failures == sals.size ()) | |
8803 | throw; | |
8804 | } | |
8805 | } | |
8806 | } | |
8807 | ||
0fb4aa4b PA |
8808 | /* Decode a static tracepoint marker spec. */ |
8809 | ||
6c5b2ebe | 8810 | static std::vector<symtab_and_line> |
f00aae0f | 8811 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b | 8812 | { |
f00aae0f KS |
8813 | const char *p = &(*arg_p)[3]; |
8814 | const char *endp; | |
0fb4aa4b | 8815 | |
f1735a53 | 8816 | p = skip_spaces (p); |
0fb4aa4b | 8817 | |
f1735a53 | 8818 | endp = skip_to_space (p); |
0fb4aa4b | 8819 | |
81b1e71c | 8820 | std::string marker_str (p, endp - p); |
0fb4aa4b | 8821 | |
5d9310c4 SM |
8822 | std::vector<static_tracepoint_marker> markers |
8823 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); | |
8824 | if (markers.empty ()) | |
81b1e71c TT |
8825 | error (_("No known static tracepoint marker named %s"), |
8826 | marker_str.c_str ()); | |
0fb4aa4b | 8827 | |
6c5b2ebe | 8828 | std::vector<symtab_and_line> sals; |
5d9310c4 | 8829 | sals.reserve (markers.size ()); |
0fb4aa4b | 8830 | |
5d9310c4 | 8831 | for (const static_tracepoint_marker &marker : markers) |
0fb4aa4b | 8832 | { |
5d9310c4 SM |
8833 | symtab_and_line sal = find_pc_line (marker.address, 0); |
8834 | sal.pc = marker.address; | |
6c5b2ebe | 8835 | sals.push_back (sal); |
5d9310c4 | 8836 | } |
0fb4aa4b | 8837 | |
0fb4aa4b PA |
8838 | *arg_p = endp; |
8839 | return sals; | |
8840 | } | |
8841 | ||
bac7c5cf GB |
8842 | /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and |
8843 | according to IS_TRACEPOINT. */ | |
8844 | ||
8845 | static const struct breakpoint_ops * | |
8846 | breakpoint_ops_for_event_location_type (enum event_location_type location_type, | |
8847 | bool is_tracepoint) | |
8848 | { | |
8849 | if (is_tracepoint) | |
8850 | { | |
8851 | if (location_type == PROBE_LOCATION) | |
8852 | return &tracepoint_probe_breakpoint_ops; | |
8853 | else | |
a0cd5f08 | 8854 | return &base_breakpoint_ops; |
bac7c5cf GB |
8855 | } |
8856 | else | |
8857 | { | |
8858 | if (location_type == PROBE_LOCATION) | |
8859 | return &bkpt_probe_breakpoint_ops; | |
8860 | else | |
a0cd5f08 | 8861 | return &base_breakpoint_ops; |
bac7c5cf GB |
8862 | } |
8863 | } | |
8864 | ||
8865 | /* See breakpoint.h. */ | |
8866 | ||
8867 | const struct breakpoint_ops * | |
8868 | breakpoint_ops_for_event_location (const struct event_location *location, | |
8869 | bool is_tracepoint) | |
8870 | { | |
8871 | if (location != nullptr) | |
8872 | return breakpoint_ops_for_event_location_type | |
8873 | (event_location_type (location), is_tracepoint); | |
a0cd5f08 | 8874 | return &base_breakpoint_ops; |
bac7c5cf GB |
8875 | } |
8876 | ||
f00aae0f | 8877 | /* See breakpoint.h. */ |
0101ce28 | 8878 | |
8cdf0e15 VP |
8879 | int |
8880 | create_breakpoint (struct gdbarch *gdbarch, | |
626d2320 | 8881 | struct event_location *location, |
e1e01040 PA |
8882 | const char *cond_string, |
8883 | int thread, const char *extra_string, | |
10a636cc | 8884 | bool force_condition, int parse_extra, |
0fb4aa4b | 8885 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
8886 | int ignore_count, |
8887 | enum auto_boolean pending_break_support, | |
c0a91b2b | 8888 | const struct breakpoint_ops *ops, |
44f238bb PA |
8889 | int from_tty, int enabled, int internal, |
8890 | unsigned flags) | |
c3f6f71d | 8891 | { |
7efd8fc2 | 8892 | struct linespec_result canonical; |
0101ce28 | 8893 | int pending = 0; |
4a306c9a | 8894 | int task = 0; |
86b17b60 | 8895 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 8896 | |
348d480f PA |
8897 | gdb_assert (ops != NULL); |
8898 | ||
f00aae0f KS |
8899 | /* If extra_string isn't useful, set it to NULL. */ |
8900 | if (extra_string != NULL && *extra_string == '\0') | |
8901 | extra_string = NULL; | |
8902 | ||
a70b8144 | 8903 | try |
b78a6381 | 8904 | { |
f00aae0f | 8905 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 8906 | } |
230d2906 | 8907 | catch (const gdb_exception_error &e) |
0101ce28 | 8908 | { |
492d29ea PA |
8909 | /* If caller is interested in rc value from parse, set |
8910 | value. */ | |
8911 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 8912 | { |
05ff989b AC |
8913 | /* If pending breakpoint support is turned off, throw |
8914 | error. */ | |
fa8d40ab JJ |
8915 | |
8916 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
eedc3f4f | 8917 | throw; |
723a2275 VP |
8918 | |
8919 | exception_print (gdb_stderr, e); | |
fa8d40ab | 8920 | |
dda83cd7 | 8921 | /* If pending breakpoint support is auto query and the user |
05ff989b | 8922 | selects no, then simply return the error code. */ |
059fb39f | 8923 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
8924 | && !nquery (_("Make %s pending on future shared library load? "), |
8925 | bptype_string (type_wanted))) | |
fd9b8c24 | 8926 | return 0; |
fa8d40ab | 8927 | |
05ff989b AC |
8928 | /* At this point, either the user was queried about setting |
8929 | a pending breakpoint and selected yes, or pending | |
8930 | breakpoint behavior is on and thus a pending breakpoint | |
8931 | is defaulted on behalf of the user. */ | |
f00aae0f | 8932 | pending = 1; |
0101ce28 | 8933 | } |
492d29ea | 8934 | else |
eedc3f4f | 8935 | throw; |
0101ce28 | 8936 | } |
492d29ea | 8937 | |
6c5b2ebe | 8938 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 8939 | return 0; |
c3f6f71d | 8940 | |
c3f6f71d JM |
8941 | /* Resolve all line numbers to PC's and verify that the addresses |
8942 | are ok for the target. */ | |
0101ce28 | 8943 | if (!pending) |
f8eba3c6 | 8944 | { |
6c5b2ebe PA |
8945 | for (auto &lsal : canonical.lsals) |
8946 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 8947 | } |
c3f6f71d | 8948 | |
7a697b8d | 8949 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 8950 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 8951 | { |
6c5b2ebe PA |
8952 | for (const auto &lsal : canonical.lsals) |
8953 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 8954 | } |
7a697b8d | 8955 | |
c3f6f71d JM |
8956 | /* Verify that condition can be parsed, before setting any |
8957 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 8958 | breakpoint. */ |
0101ce28 | 8959 | if (!pending) |
c3f6f71d | 8960 | { |
e1e01040 PA |
8961 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
8962 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
8963 | ||
f00aae0f | 8964 | if (parse_extra) |
dda83cd7 | 8965 | { |
6f781ee3 TT |
8966 | gdb::unique_xmalloc_ptr<char> rest; |
8967 | gdb::unique_xmalloc_ptr<char> cond; | |
52d361e1 | 8968 | |
6c5b2ebe | 8969 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 8970 | |
b5fa468f TBA |
8971 | find_condition_and_thread_for_sals (lsal.sals, extra_string, |
8972 | &cond, &thread, &task, &rest); | |
6f781ee3 TT |
8973 | cond_string_copy = std::move (cond); |
8974 | extra_string_copy = std::move (rest); | |
dda83cd7 | 8975 | } |
2f069f6f | 8976 | else |
dda83cd7 | 8977 | { |
f00aae0f KS |
8978 | if (type_wanted != bp_dprintf |
8979 | && extra_string != NULL && *extra_string != '\0') | |
8980 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa | 8981 | |
10a636cc TBA |
8982 | /* Check the validity of the condition. We should error out |
8983 | if the condition is invalid at all of the locations and | |
8984 | if it is not forced. In the PARSE_EXTRA case above, this | |
8985 | check is done when parsing the EXTRA_STRING. */ | |
8986 | if (cond_string != nullptr && !force_condition) | |
8987 | { | |
8988 | int num_failures = 0; | |
8989 | const linespec_sals &lsal = canonical.lsals[0]; | |
8990 | for (const auto &sal : lsal.sals) | |
8991 | { | |
8992 | const char *cond = cond_string; | |
8993 | try | |
8994 | { | |
8995 | parse_exp_1 (&cond, sal.pc, block_for_pc (sal.pc), 0); | |
8996 | /* One success is sufficient to keep going. */ | |
8997 | break; | |
8998 | } | |
8999 | catch (const gdb_exception_error &) | |
9000 | { | |
9001 | num_failures++; | |
9002 | /* If this is the last sal, error out. */ | |
9003 | if (num_failures == lsal.sals.size ()) | |
9004 | throw; | |
9005 | } | |
9006 | } | |
9007 | } | |
9008 | ||
0878d0fa YQ |
9009 | /* Create a private copy of condition string. */ |
9010 | if (cond_string) | |
e1e01040 | 9011 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9012 | /* Create a private copy of any extra string. */ |
9013 | if (extra_string) | |
e1e01040 | 9014 | extra_string_copy.reset (xstrdup (extra_string)); |
dda83cd7 | 9015 | } |
0fb4aa4b | 9016 | |
52d361e1 | 9017 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9018 | std::move (cond_string_copy), |
9019 | std::move (extra_string_copy), | |
9020 | type_wanted, | |
d9b3f62e PA |
9021 | tempflag ? disp_del : disp_donttouch, |
9022 | thread, task, ignore_count, ops, | |
44f238bb | 9023 | from_tty, enabled, internal, flags); |
c906108c | 9024 | } |
0101ce28 JJ |
9025 | else |
9026 | { | |
a5e364af | 9027 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9028 | |
a5e364af | 9029 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9030 | b->location = copy_event_location (location); |
bfccc43c | 9031 | |
f00aae0f KS |
9032 | if (parse_extra) |
9033 | b->cond_string = NULL; | |
e12c7713 MK |
9034 | else |
9035 | { | |
9036 | /* Create a private copy of condition string. */ | |
6f781ee3 TT |
9037 | b->cond_string.reset (cond_string != NULL |
9038 | ? xstrdup (cond_string) | |
9039 | : NULL); | |
15630549 | 9040 | b->thread = thread; |
e12c7713 | 9041 | } |
f00aae0f KS |
9042 | |
9043 | /* Create a private copy of any extra string. */ | |
6f781ee3 TT |
9044 | b->extra_string.reset (extra_string != NULL |
9045 | ? xstrdup (extra_string) | |
9046 | : NULL); | |
0101ce28 | 9047 | b->ignore_count = ignore_count; |
0101ce28 | 9048 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9049 | b->condition_not_parsed = 1; |
41447f92 | 9050 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 | 9051 | if ((type_wanted != bp_breakpoint |
dda83cd7 | 9052 | && type_wanted != bp_hardware_breakpoint) || thread != -1) |
f8eba3c6 | 9053 | b->pspace = current_program_space; |
8bea4e01 | 9054 | |
b270e6f9 | 9055 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9056 | } |
9057 | ||
6c5b2ebe | 9058 | if (canonical.lsals.size () > 1) |
95a42b64 | 9059 | { |
3e43a32a MS |
9060 | warning (_("Multiple breakpoints were set.\nUse the " |
9061 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9062 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9063 | } |
9064 | ||
44702360 | 9065 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9066 | |
9067 | return 1; | |
c3f6f71d | 9068 | } |
c906108c | 9069 | |
348d480f | 9070 | /* Set a breakpoint. |
72b2ff0e VP |
9071 | ARG is a string describing breakpoint address, |
9072 | condition, and thread. | |
9073 | FLAG specifies if a breakpoint is hardware on, | |
9074 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9075 | and BP_TEMPFLAG. */ | |
348d480f | 9076 | |
98deb0da | 9077 | static void |
f2fc3015 | 9078 | break_command_1 (const char *arg, int flag, int from_tty) |
c3f6f71d | 9079 | { |
72b2ff0e | 9080 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9081 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9082 | ? bp_hardware_breakpoint | |
9083 | : bp_breakpoint); | |
f00aae0f | 9084 | |
ffc2605c | 9085 | event_location_up location = string_to_event_location (&arg, current_language); |
bac7c5cf GB |
9086 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
9087 | (location.get (), false /* is_tracepoint */); | |
c3f6f71d | 9088 | |
8cdf0e15 | 9089 | create_breakpoint (get_current_arch (), |
ffc2605c | 9090 | location.get (), |
10a636cc | 9091 | NULL, 0, arg, false, 1 /* parse arg */, |
0fb4aa4b | 9092 | tempflag, type_wanted, |
8cdf0e15 VP |
9093 | 0 /* Ignore count */, |
9094 | pending_break_support, | |
55aa24fb | 9095 | ops, |
8cdf0e15 | 9096 | from_tty, |
84f4c1fe | 9097 | 1 /* enabled */, |
44f238bb PA |
9098 | 0 /* internal */, |
9099 | 0); | |
c906108c SS |
9100 | } |
9101 | ||
c906108c SS |
9102 | /* Helper function for break_command_1 and disassemble_command. */ |
9103 | ||
9104 | void | |
fba45db2 | 9105 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9106 | { |
9107 | CORE_ADDR pc; | |
9108 | ||
9109 | if (sal->pc == 0 && sal->symtab != NULL) | |
9110 | { | |
9111 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9112 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9113 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9114 | sal->pc = pc; |
6a048695 | 9115 | |
4a64f543 | 9116 | /* If this SAL corresponds to a breakpoint inserted using a line |
dda83cd7 | 9117 | number, then skip the function prologue if necessary. */ |
6a048695 | 9118 | if (sal->explicit_line) |
059acae7 | 9119 | skip_prologue_sal (sal); |
c906108c SS |
9120 | } |
9121 | ||
9122 | if (sal->section == 0 && sal->symtab != NULL) | |
9123 | { | |
346d1dfe | 9124 | const struct blockvector *bv; |
3977b71f | 9125 | const struct block *b; |
c5aa993b | 9126 | struct symbol *sym; |
c906108c | 9127 | |
43f3e411 | 9128 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
c6159652 | 9129 | sal->symtab->compunit ()); |
c906108c SS |
9130 | if (bv != NULL) |
9131 | { | |
7f0df278 | 9132 | sym = block_linkage_function (b); |
c906108c SS |
9133 | if (sym != NULL) |
9134 | { | |
3c86fae3 SM |
9135 | fixup_symbol_section (sym, sal->symtab->compunit ()->objfile ()); |
9136 | sal->section | |
9137 | = sym->obj_section (sal->symtab->compunit ()->objfile ()); | |
c906108c SS |
9138 | } |
9139 | else | |
9140 | { | |
4a64f543 | 9141 | /* It really is worthwhile to have the section, so we'll |
dda83cd7 SM |
9142 | just have to look harder. This case can be executed |
9143 | if we have line numbers but no functions (as can | |
9144 | happen in assembly source). */ | |
c906108c | 9145 | |
5ed8105e | 9146 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9147 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9148 | |
5ed8105e | 9149 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9150 | if (msym.minsym) |
1db66e34 | 9151 | sal->section = msym.obj_section (); |
c906108c SS |
9152 | } |
9153 | } | |
9154 | } | |
9155 | } | |
9156 | ||
9157 | void | |
0b39b52e | 9158 | break_command (const char *arg, int from_tty) |
c906108c | 9159 | { |
db107f19 | 9160 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9161 | } |
9162 | ||
c906108c | 9163 | void |
0b39b52e | 9164 | tbreak_command (const char *arg, int from_tty) |
c906108c | 9165 | { |
db107f19 | 9166 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9167 | } |
9168 | ||
c906108c | 9169 | static void |
0b39b52e | 9170 | hbreak_command (const char *arg, int from_tty) |
c906108c | 9171 | { |
db107f19 | 9172 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9173 | } |
9174 | ||
9175 | static void | |
0b39b52e | 9176 | thbreak_command (const char *arg, int from_tty) |
c906108c | 9177 | { |
db107f19 | 9178 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9179 | } |
9180 | ||
e7e0cddf SS |
9181 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9182 | with a prewired command list consisting of a single output command, | |
9183 | built from extra arguments supplied on the dprintf command | |
9184 | line. */ | |
9185 | ||
da821c7b | 9186 | static void |
0b39b52e | 9187 | dprintf_command (const char *arg, int from_tty) |
e7e0cddf | 9188 | { |
ffc2605c | 9189 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9190 | |
9191 | /* If non-NULL, ARG should have been advanced past the location; | |
9192 | the next character must be ','. */ | |
9193 | if (arg != NULL) | |
9194 | { | |
9195 | if (arg[0] != ',' || arg[1] == '\0') | |
9196 | error (_("Format string required")); | |
9197 | else | |
9198 | { | |
9199 | /* Skip the comma. */ | |
9200 | ++arg; | |
9201 | } | |
9202 | } | |
9203 | ||
e7e0cddf | 9204 | create_breakpoint (get_current_arch (), |
ffc2605c | 9205 | location.get (), |
10a636cc | 9206 | NULL, 0, arg, false, 1 /* parse arg */, |
e7e0cddf SS |
9207 | 0, bp_dprintf, |
9208 | 0 /* Ignore count */, | |
9209 | pending_break_support, | |
a0cd5f08 | 9210 | &base_breakpoint_ops, |
e7e0cddf SS |
9211 | from_tty, |
9212 | 1 /* enabled */, | |
9213 | 0 /* internal */, | |
9214 | 0); | |
9215 | } | |
9216 | ||
d3ce09f5 | 9217 | static void |
0b39b52e | 9218 | agent_printf_command (const char *arg, int from_tty) |
d3ce09f5 SS |
9219 | { |
9220 | error (_("May only run agent-printf on the target")); | |
9221 | } | |
9222 | ||
ec45bb67 | 9223 | /* Implement the "breakpoint_hit" method for ranged breakpoints. */ |
f1310107 | 9224 | |
ec45bb67 TT |
9225 | int |
9226 | ranged_breakpoint::breakpoint_hit (const struct bp_location *bl, | |
9227 | const address_space *aspace, | |
9228 | CORE_ADDR bp_addr, | |
9229 | const target_waitstatus &ws) | |
f1310107 | 9230 | { |
c272a98c SM |
9231 | if (ws.kind () != TARGET_WAITKIND_STOPPED |
9232 | || ws.sig () != GDB_SIGNAL_TRAP) | |
09ac7c10 TT |
9233 | return 0; |
9234 | ||
f1310107 TJB |
9235 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9236 | bl->length, aspace, bp_addr); | |
9237 | } | |
9238 | ||
ec45bb67 | 9239 | /* Implement the "resources_needed" method for ranged breakpoints. */ |
f1310107 | 9240 | |
ec45bb67 TT |
9241 | int |
9242 | ranged_breakpoint::resources_needed (const struct bp_location *bl) | |
f1310107 TJB |
9243 | { |
9244 | return target_ranged_break_num_registers (); | |
9245 | } | |
9246 | ||
ec45bb67 | 9247 | /* Implement the "print_it" method for ranged breakpoints. */ |
f1310107 | 9248 | |
ec45bb67 TT |
9249 | enum print_stop_action |
9250 | ranged_breakpoint::print_it (bpstat *bs) | |
f1310107 | 9251 | { |
ec45bb67 | 9252 | struct bp_location *bl = loc; |
79a45e25 | 9253 | struct ui_out *uiout = current_uiout; |
f1310107 | 9254 | |
ec45bb67 | 9255 | gdb_assert (type == bp_hardware_breakpoint); |
f1310107 TJB |
9256 | |
9257 | /* Ranged breakpoints have only one location. */ | |
9258 | gdb_assert (bl && bl->next == NULL); | |
9259 | ||
ec45bb67 | 9260 | annotate_breakpoint (number); |
f303dbd6 PA |
9261 | |
9262 | maybe_print_thread_hit_breakpoint (uiout); | |
9263 | ||
ec45bb67 | 9264 | if (disposition == disp_del) |
112e8700 | 9265 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9266 | else |
112e8700 SM |
9267 | uiout->text ("Ranged breakpoint "); |
9268 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9269 | { |
112e8700 | 9270 | uiout->field_string ("reason", |
f1310107 | 9271 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
ec45bb67 | 9272 | uiout->field_string ("disp", bpdisp_text (disposition)); |
f1310107 | 9273 | } |
ec45bb67 | 9274 | uiout->field_signed ("bkptno", number); |
112e8700 | 9275 | uiout->text (", "); |
f1310107 TJB |
9276 | |
9277 | return PRINT_SRC_AND_LOC; | |
9278 | } | |
9279 | ||
ec45bb67 | 9280 | /* Implement the "print_one" method for ranged breakpoints. */ |
f1310107 | 9281 | |
ec45bb67 TT |
9282 | bool |
9283 | ranged_breakpoint::print_one (struct bp_location **last_loc) | |
f1310107 | 9284 | { |
ec45bb67 | 9285 | struct bp_location *bl = loc; |
f1310107 | 9286 | struct value_print_options opts; |
79a45e25 | 9287 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9288 | |
9289 | /* Ranged breakpoints have only one location. */ | |
9290 | gdb_assert (bl && bl->next == NULL); | |
9291 | ||
9292 | get_user_print_options (&opts); | |
9293 | ||
9294 | if (opts.addressprint) | |
9295 | /* We don't print the address range here, it will be printed later | |
9296 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9297 | uiout->field_skip ("addr"); |
f1310107 | 9298 | annotate_field (5); |
ec45bb67 | 9299 | print_breakpoint_location (this, bl); |
f1310107 | 9300 | *last_loc = bl; |
c01e038b TT |
9301 | |
9302 | return true; | |
f1310107 TJB |
9303 | } |
9304 | ||
ec45bb67 | 9305 | /* Implement the "print_one_detail" method for ranged breakpoints. */ |
f1310107 | 9306 | |
ec45bb67 TT |
9307 | void |
9308 | ranged_breakpoint::print_one_detail (struct ui_out *uiout) const | |
f1310107 TJB |
9309 | { |
9310 | CORE_ADDR address_start, address_end; | |
ec45bb67 | 9311 | struct bp_location *bl = loc; |
d7e74731 | 9312 | string_file stb; |
f1310107 TJB |
9313 | |
9314 | gdb_assert (bl); | |
9315 | ||
9316 | address_start = bl->address; | |
9317 | address_end = address_start + bl->length - 1; | |
9318 | ||
112e8700 | 9319 | uiout->text ("\taddress range: "); |
d7e74731 PA |
9320 | stb.printf ("[%s, %s]", |
9321 | print_core_address (bl->gdbarch, address_start), | |
9322 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
9323 | uiout->field_stream ("addr", stb); |
9324 | uiout->text ("\n"); | |
f1310107 TJB |
9325 | } |
9326 | ||
ec45bb67 | 9327 | /* Implement the "print_mention" method for ranged breakpoints. */ |
f1310107 | 9328 | |
ec45bb67 TT |
9329 | void |
9330 | ranged_breakpoint::print_mention () | |
f1310107 | 9331 | { |
ec45bb67 | 9332 | struct bp_location *bl = loc; |
79a45e25 | 9333 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9334 | |
9335 | gdb_assert (bl); | |
ec45bb67 | 9336 | gdb_assert (type == bp_hardware_breakpoint); |
f1310107 | 9337 | |
2d33446d | 9338 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
ec45bb67 | 9339 | number, paddress (bl->gdbarch, bl->address), |
2d33446d | 9340 | paddress (bl->gdbarch, bl->address + bl->length - 1)); |
f1310107 TJB |
9341 | } |
9342 | ||
ec45bb67 | 9343 | /* Implement the "print_recreate" method for ranged breakpoints. */ |
f1310107 | 9344 | |
ec45bb67 TT |
9345 | void |
9346 | ranged_breakpoint::print_recreate (struct ui_file *fp) | |
f1310107 | 9347 | { |
6cb06a8c | 9348 | gdb_printf (fp, "break-range %s, %s", |
ec45bb67 TT |
9349 | event_location_to_string (location.get ()), |
9350 | event_location_to_string (location_range_end.get ())); | |
9351 | print_recreate_thread (this, fp); | |
f1310107 TJB |
9352 | } |
9353 | ||
f1310107 TJB |
9354 | /* Find the address where the end of the breakpoint range should be |
9355 | placed, given the SAL of the end of the range. This is so that if | |
9356 | the user provides a line number, the end of the range is set to the | |
9357 | last instruction of the given line. */ | |
9358 | ||
9359 | static CORE_ADDR | |
9360 | find_breakpoint_range_end (struct symtab_and_line sal) | |
9361 | { | |
9362 | CORE_ADDR end; | |
9363 | ||
9364 | /* If the user provided a PC value, use it. Otherwise, | |
9365 | find the address of the end of the given location. */ | |
9366 | if (sal.explicit_pc) | |
9367 | end = sal.pc; | |
9368 | else | |
9369 | { | |
9370 | int ret; | |
9371 | CORE_ADDR start; | |
9372 | ||
9373 | ret = find_line_pc_range (sal, &start, &end); | |
9374 | if (!ret) | |
9375 | error (_("Could not find location of the end of the range.")); | |
9376 | ||
9377 | /* find_line_pc_range returns the start of the next line. */ | |
9378 | end--; | |
9379 | } | |
9380 | ||
9381 | return end; | |
9382 | } | |
9383 | ||
9384 | /* Implement the "break-range" CLI command. */ | |
9385 | ||
9386 | static void | |
0b39b52e | 9387 | break_range_command (const char *arg, int from_tty) |
f1310107 | 9388 | { |
f2fc3015 | 9389 | const char *arg_start; |
f1310107 TJB |
9390 | struct linespec_result canonical_start, canonical_end; |
9391 | int bp_count, can_use_bp, length; | |
9392 | CORE_ADDR end; | |
9393 | struct breakpoint *b; | |
f1310107 TJB |
9394 | |
9395 | /* We don't support software ranged breakpoints. */ | |
9396 | if (target_ranged_break_num_registers () < 0) | |
9397 | error (_("This target does not support hardware ranged breakpoints.")); | |
9398 | ||
9399 | bp_count = hw_breakpoint_used_count (); | |
9400 | bp_count += target_ranged_break_num_registers (); | |
9401 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
9402 | bp_count, 0); | |
9403 | if (can_use_bp < 0) | |
9404 | error (_("Hardware breakpoints used exceeds limit.")); | |
9405 | ||
f8eba3c6 | 9406 | arg = skip_spaces (arg); |
f1310107 TJB |
9407 | if (arg == NULL || arg[0] == '\0') |
9408 | error(_("No address range specified.")); | |
9409 | ||
f8eba3c6 | 9410 | arg_start = arg; |
ffc2605c TT |
9411 | event_location_up start_location = string_to_event_location (&arg, |
9412 | current_language); | |
9413 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
9414 | |
9415 | if (arg[0] != ',') | |
9416 | error (_("Too few arguments.")); | |
6c5b2ebe | 9417 | else if (canonical_start.lsals.empty ()) |
f1310107 | 9418 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 9419 | |
6c5b2ebe | 9420 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 9421 | |
6c5b2ebe PA |
9422 | if (canonical_start.lsals.size () > 1 |
9423 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
9424 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9425 | ||
6c5b2ebe | 9426 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
81b1e71c | 9427 | std::string addr_string_start (arg_start, arg - arg_start); |
f1310107 TJB |
9428 | |
9429 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 9430 | arg = skip_spaces (arg); |
f1310107 TJB |
9431 | |
9432 | /* Parse the end location. */ | |
9433 | ||
f1310107 TJB |
9434 | arg_start = arg; |
9435 | ||
f8eba3c6 | 9436 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
9437 | parse_breakpoint_sals because we need to specify the start location's |
9438 | symtab and line as the default symtab and line for the end of the | |
9439 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
9440 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
9441 | event_location_up end_location = string_to_event_location (&arg, |
9442 | current_language); | |
9443 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
9444 | sal_start.symtab, sal_start.line, |
9445 | &canonical_end, NULL, NULL); | |
9446 | ||
6c5b2ebe | 9447 | if (canonical_end.lsals.empty ()) |
f1310107 | 9448 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 9449 | |
6c5b2ebe PA |
9450 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
9451 | if (canonical_end.lsals.size () > 1 | |
9452 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
9453 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
9454 | ||
6c5b2ebe | 9455 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
9456 | |
9457 | end = find_breakpoint_range_end (sal_end); | |
9458 | if (sal_start.pc > end) | |
177b42fe | 9459 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
9460 | |
9461 | length = end - sal_start.pc + 1; | |
9462 | if (length < 0) | |
9463 | /* Length overflowed. */ | |
9464 | error (_("Address range too large.")); | |
9465 | else if (length == 1) | |
9466 | { | |
9467 | /* This range is simple enough to be handled by | |
9468 | the `hbreak' command. */ | |
81b1e71c | 9469 | hbreak_command (&addr_string_start[0], 1); |
f1310107 TJB |
9470 | |
9471 | return; | |
9472 | } | |
9473 | ||
9474 | /* Now set up the breakpoint. */ | |
ec45bb67 TT |
9475 | std::unique_ptr<breakpoint> br (new ranged_breakpoint ()); |
9476 | init_raw_breakpoint (br.get (), get_current_arch (), | |
9477 | sal_start, bp_hardware_breakpoint, | |
a0cd5f08 | 9478 | &base_breakpoint_ops); |
ec45bb67 TT |
9479 | b = add_to_breakpoint_chain (std::move (br)); |
9480 | ||
f1310107 TJB |
9481 | set_breakpoint_count (breakpoint_count + 1); |
9482 | b->number = breakpoint_count; | |
9483 | b->disposition = disp_donttouch; | |
d28cd78a TT |
9484 | b->location = std::move (start_location); |
9485 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
9486 | b->loc->length = length; |
9487 | ||
f1310107 | 9488 | mention (b); |
76727919 | 9489 | gdb::observers::breakpoint_created.notify (b); |
44702360 | 9490 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
9491 | } |
9492 | ||
4a64f543 MS |
9493 | /* Return non-zero if EXP is verified as constant. Returned zero |
9494 | means EXP is variable. Also the constant detection may fail for | |
9495 | some constant expressions and in such case still falsely return | |
9496 | zero. */ | |
2e6e3d9c | 9497 | |
dab72643 | 9498 | static bool |
65d79d4b SDJ |
9499 | watchpoint_exp_is_const (const struct expression *exp) |
9500 | { | |
1eaebe02 | 9501 | return exp->op->constant_p (); |
65d79d4b SDJ |
9502 | } |
9503 | ||
3a292923 | 9504 | /* Implement the "re_set" method for watchpoints. */ |
348d480f | 9505 | |
3a292923 TT |
9506 | void |
9507 | watchpoint::re_set () | |
348d480f PA |
9508 | { |
9509 | /* Watchpoint can be either on expression using entirely global | |
9510 | variables, or it can be on local variables. | |
9511 | ||
9512 | Watchpoints of the first kind are never auto-deleted, and even | |
9513 | persist across program restarts. Since they can use variables | |
9514 | from shared libraries, we need to reparse expression as libraries | |
9515 | are loaded and unloaded. | |
9516 | ||
9517 | Watchpoints on local variables can also change meaning as result | |
9518 | of solib event. For example, if a watchpoint uses both a local | |
9519 | and a global variables in expression, it's a local watchpoint, | |
9520 | but unloading of a shared library will make the expression | |
9521 | invalid. This is not a very common use case, but we still | |
9522 | re-evaluate expression, to avoid surprises to the user. | |
9523 | ||
9524 | Note that for local watchpoints, we re-evaluate it only if | |
9525 | watchpoints frame id is still valid. If it's not, it means the | |
9526 | watchpoint is out of scope and will be deleted soon. In fact, | |
9527 | I'm not sure we'll ever be called in this case. | |
9528 | ||
9529 | If a local watchpoint's frame id is still valid, then | |
3a292923 | 9530 | exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 9531 | |
3a5c3e22 PA |
9532 | Don't do anything about disabled watchpoints, since they will be |
9533 | reevaluated again when enabled. */ | |
3a292923 | 9534 | update_watchpoint (this, 1 /* reparse */); |
348d480f PA |
9535 | } |
9536 | ||
3a292923 | 9537 | /* Implement the "insert" method for hardware watchpoints. */ |
77b06cd7 | 9538 | |
3a292923 TT |
9539 | int |
9540 | watchpoint::insert_location (struct bp_location *bl) | |
77b06cd7 | 9541 | { |
3a292923 | 9542 | int length = exact ? 1 : bl->length; |
e09342b5 TJB |
9543 | |
9544 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a292923 | 9545 | cond_exp.get ()); |
77b06cd7 TJB |
9546 | } |
9547 | ||
3a292923 | 9548 | /* Implement the "remove" method for hardware watchpoints. */ |
77b06cd7 | 9549 | |
3a292923 TT |
9550 | int |
9551 | watchpoint::remove_location (struct bp_location *bl, | |
9552 | enum remove_bp_reason reason) | |
77b06cd7 | 9553 | { |
3a292923 | 9554 | int length = exact ? 1 : bl->length; |
e09342b5 TJB |
9555 | |
9556 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a292923 | 9557 | cond_exp.get ()); |
e09342b5 TJB |
9558 | } |
9559 | ||
3a292923 TT |
9560 | int |
9561 | watchpoint::breakpoint_hit (const struct bp_location *bl, | |
9562 | const address_space *aspace, CORE_ADDR bp_addr, | |
9563 | const target_waitstatus &ws) | |
e09342b5 | 9564 | { |
348d480f | 9565 | struct breakpoint *b = bl->owner; |
77b06cd7 | 9566 | |
348d480f PA |
9567 | /* Continuable hardware watchpoints are treated as non-existent if the |
9568 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
9569 | some data address). Otherwise gdb won't stop on a break instruction | |
9570 | in the code (not from a breakpoint) when a hardware watchpoint has | |
9571 | been defined. Also skip watchpoints which we know did not trigger | |
9572 | (did not match the data address). */ | |
9573 | if (is_hardware_watchpoint (b) | |
3a292923 | 9574 | && watchpoint_triggered == watch_triggered_no) |
348d480f | 9575 | return 0; |
9c06b0b4 | 9576 | |
348d480f | 9577 | return 1; |
9c06b0b4 TJB |
9578 | } |
9579 | ||
3a292923 TT |
9580 | void |
9581 | watchpoint::check_status (bpstat *bs) | |
9c06b0b4 | 9582 | { |
348d480f | 9583 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 9584 | |
348d480f | 9585 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
9586 | } |
9587 | ||
3a292923 TT |
9588 | /* Implement the "resources_needed" method for hardware |
9589 | watchpoints. */ | |
9c06b0b4 | 9590 | |
3a292923 TT |
9591 | int |
9592 | watchpoint::resources_needed (const struct bp_location *bl) | |
9c06b0b4 | 9593 | { |
3a292923 | 9594 | int length = exact? 1 : bl->length; |
348d480f PA |
9595 | |
9596 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
9597 | } |
9598 | ||
3a292923 TT |
9599 | /* Implement the "works_in_software_mode" method for hardware |
9600 | watchpoints. */ | |
9c06b0b4 | 9601 | |
3a292923 TT |
9602 | int |
9603 | watchpoint::works_in_software_mode () const | |
9c06b0b4 | 9604 | { |
efa80663 | 9605 | /* Read and access watchpoints only work with hardware support. */ |
3a292923 | 9606 | return type == bp_watchpoint || type == bp_hardware_watchpoint; |
9c06b0b4 TJB |
9607 | } |
9608 | ||
3a292923 TT |
9609 | enum print_stop_action |
9610 | watchpoint::print_it (bpstat *bs) | |
9c06b0b4 | 9611 | { |
348d480f | 9612 | struct breakpoint *b; |
348d480f | 9613 | enum print_stop_action result; |
79a45e25 | 9614 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9615 | |
9616 | gdb_assert (bs->bp_location_at != NULL); | |
9617 | ||
348d480f PA |
9618 | b = bs->breakpoint_at; |
9619 | ||
f303dbd6 PA |
9620 | annotate_watchpoint (b->number); |
9621 | maybe_print_thread_hit_breakpoint (uiout); | |
9622 | ||
d7e74731 PA |
9623 | string_file stb; |
9624 | ||
76f9c9cf | 9625 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
9626 | switch (b->type) |
9627 | { | |
348d480f | 9628 | case bp_watchpoint: |
9c06b0b4 | 9629 | case bp_hardware_watchpoint: |
112e8700 SM |
9630 | if (uiout->is_mi_like_p ()) |
9631 | uiout->field_string | |
9632 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 9633 | mention (b); |
76f9c9cf | 9634 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 9635 | uiout->text ("\nOld value = "); |
850645cf | 9636 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
9637 | uiout->field_stream ("old", stb); |
9638 | uiout->text ("\nNew value = "); | |
3a292923 | 9639 | watchpoint_value_print (val.get (), &stb); |
112e8700 SM |
9640 | uiout->field_stream ("new", stb); |
9641 | uiout->text ("\n"); | |
348d480f PA |
9642 | /* More than one watchpoint may have been triggered. */ |
9643 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
9644 | break; |
9645 | ||
9646 | case bp_read_watchpoint: | |
112e8700 SM |
9647 | if (uiout->is_mi_like_p ()) |
9648 | uiout->field_string | |
9649 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 9650 | mention (b); |
76f9c9cf | 9651 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 9652 | uiout->text ("\nValue = "); |
3a292923 | 9653 | watchpoint_value_print (val.get (), &stb); |
112e8700 SM |
9654 | uiout->field_stream ("value", stb); |
9655 | uiout->text ("\n"); | |
348d480f | 9656 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9657 | break; |
9658 | ||
9659 | case bp_access_watchpoint: | |
348d480f PA |
9660 | if (bs->old_val != NULL) |
9661 | { | |
112e8700 SM |
9662 | if (uiout->is_mi_like_p ()) |
9663 | uiout->field_string | |
9664 | ("reason", | |
348d480f PA |
9665 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
9666 | mention (b); | |
76f9c9cf | 9667 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 9668 | uiout->text ("\nOld value = "); |
850645cf | 9669 | watchpoint_value_print (bs->old_val.get (), &stb); |
112e8700 SM |
9670 | uiout->field_stream ("old", stb); |
9671 | uiout->text ("\nNew value = "); | |
348d480f PA |
9672 | } |
9673 | else | |
9674 | { | |
9675 | mention (b); | |
112e8700 SM |
9676 | if (uiout->is_mi_like_p ()) |
9677 | uiout->field_string | |
9678 | ("reason", | |
348d480f | 9679 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 9680 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 9681 | uiout->text ("\nValue = "); |
348d480f | 9682 | } |
3a292923 | 9683 | watchpoint_value_print (val.get (), &stb); |
112e8700 SM |
9684 | uiout->field_stream ("new", stb); |
9685 | uiout->text ("\n"); | |
348d480f | 9686 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9687 | break; |
9688 | default: | |
348d480f | 9689 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
9690 | } |
9691 | ||
348d480f PA |
9692 | return result; |
9693 | } | |
9694 | ||
3a292923 | 9695 | /* Implement the "print_mention" method for hardware watchpoints. */ |
348d480f | 9696 | |
3a292923 TT |
9697 | void |
9698 | watchpoint::print_mention () | |
348d480f | 9699 | { |
79a45e25 | 9700 | struct ui_out *uiout = current_uiout; |
46b9c129 | 9701 | const char *tuple_name; |
348d480f | 9702 | |
3a292923 | 9703 | switch (type) |
348d480f PA |
9704 | { |
9705 | case bp_watchpoint: | |
112e8700 | 9706 | uiout->text ("Watchpoint "); |
46b9c129 | 9707 | tuple_name = "wpt"; |
348d480f PA |
9708 | break; |
9709 | case bp_hardware_watchpoint: | |
112e8700 | 9710 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 9711 | tuple_name = "wpt"; |
348d480f PA |
9712 | break; |
9713 | case bp_read_watchpoint: | |
112e8700 | 9714 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 9715 | tuple_name = "hw-rwpt"; |
348d480f PA |
9716 | break; |
9717 | case bp_access_watchpoint: | |
112e8700 | 9718 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 9719 | tuple_name = "hw-awpt"; |
348d480f PA |
9720 | break; |
9721 | default: | |
9722 | internal_error (__FILE__, __LINE__, | |
9723 | _("Invalid hardware watchpoint type.")); | |
9724 | } | |
9725 | ||
46b9c129 | 9726 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
3a292923 | 9727 | uiout->field_signed ("number", number); |
112e8700 | 9728 | uiout->text (": "); |
3a292923 | 9729 | uiout->field_string ("exp", exp_string.get ()); |
348d480f PA |
9730 | } |
9731 | ||
3a292923 | 9732 | /* Implement the "print_recreate" method for watchpoints. */ |
348d480f | 9733 | |
3a292923 TT |
9734 | void |
9735 | watchpoint::print_recreate (struct ui_file *fp) | |
348d480f | 9736 | { |
3a292923 | 9737 | switch (type) |
348d480f PA |
9738 | { |
9739 | case bp_watchpoint: | |
9740 | case bp_hardware_watchpoint: | |
6cb06a8c | 9741 | gdb_printf (fp, "watch"); |
348d480f PA |
9742 | break; |
9743 | case bp_read_watchpoint: | |
6cb06a8c | 9744 | gdb_printf (fp, "rwatch"); |
348d480f PA |
9745 | break; |
9746 | case bp_access_watchpoint: | |
6cb06a8c | 9747 | gdb_printf (fp, "awatch"); |
348d480f PA |
9748 | break; |
9749 | default: | |
9750 | internal_error (__FILE__, __LINE__, | |
9751 | _("Invalid watchpoint type.")); | |
9752 | } | |
9753 | ||
3a292923 TT |
9754 | gdb_printf (fp, " %s", exp_string.get ()); |
9755 | print_recreate_thread (this, fp); | |
348d480f PA |
9756 | } |
9757 | ||
3a292923 | 9758 | /* Implement the "explains_signal" method for watchpoints. */ |
427cd150 | 9759 | |
3a292923 TT |
9760 | int |
9761 | watchpoint::explains_signal (enum gdb_signal sig) | |
427cd150 TT |
9762 | { |
9763 | /* A software watchpoint cannot cause a signal other than | |
9764 | GDB_SIGNAL_TRAP. */ | |
3a292923 | 9765 | if (type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) |
47591c29 | 9766 | return 0; |
427cd150 | 9767 | |
47591c29 | 9768 | return 1; |
427cd150 TT |
9769 | } |
9770 | ||
3a292923 TT |
9771 | struct masked_watchpoint : public watchpoint |
9772 | { | |
9773 | int insert_location (struct bp_location *) override; | |
9774 | int remove_location (struct bp_location *, | |
9775 | enum remove_bp_reason reason) override; | |
9776 | int resources_needed (const struct bp_location *) override; | |
9777 | int works_in_software_mode () const override; | |
9778 | enum print_stop_action print_it (struct bpstat *bs) override; | |
9779 | void print_one_detail (struct ui_out *) const override; | |
9780 | void print_mention () override; | |
9781 | void print_recreate (struct ui_file *fp) override; | |
9782 | }; | |
348d480f | 9783 | |
3a292923 | 9784 | /* Implement the "insert" method for masked hardware watchpoints. */ |
348d480f | 9785 | |
3a292923 TT |
9786 | int |
9787 | masked_watchpoint::insert_location (struct bp_location *bl) | |
348d480f | 9788 | { |
3a292923 | 9789 | return target_insert_mask_watchpoint (bl->address, hw_wp_mask, |
348d480f PA |
9790 | bl->watchpoint_type); |
9791 | } | |
9792 | ||
3a292923 | 9793 | /* Implement the "remove" method for masked hardware watchpoints. */ |
348d480f | 9794 | |
3a292923 TT |
9795 | int |
9796 | masked_watchpoint::remove_location (struct bp_location *bl, | |
9797 | enum remove_bp_reason reason) | |
348d480f | 9798 | { |
3a292923 | 9799 | return target_remove_mask_watchpoint (bl->address, hw_wp_mask, |
dda83cd7 | 9800 | bl->watchpoint_type); |
348d480f PA |
9801 | } |
9802 | ||
3a292923 TT |
9803 | /* Implement the "resources_needed" method for masked hardware |
9804 | watchpoints. */ | |
348d480f | 9805 | |
3a292923 TT |
9806 | int |
9807 | masked_watchpoint::resources_needed (const struct bp_location *bl) | |
348d480f | 9808 | { |
3a292923 | 9809 | return target_masked_watch_num_registers (bl->address, hw_wp_mask); |
348d480f PA |
9810 | } |
9811 | ||
3a292923 TT |
9812 | /* Implement the "works_in_software_mode" method for masked hardware |
9813 | watchpoints. */ | |
348d480f | 9814 | |
3a292923 TT |
9815 | int |
9816 | masked_watchpoint::works_in_software_mode () const | |
348d480f PA |
9817 | { |
9818 | return 0; | |
9819 | } | |
9820 | ||
3a292923 TT |
9821 | /* Implement the "print_it" method for masked hardware |
9822 | watchpoints. */ | |
348d480f | 9823 | |
3a292923 TT |
9824 | enum print_stop_action |
9825 | masked_watchpoint::print_it (bpstat *bs) | |
348d480f PA |
9826 | { |
9827 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 9828 | struct ui_out *uiout = current_uiout; |
348d480f PA |
9829 | |
9830 | /* Masked watchpoints have only one location. */ | |
9831 | gdb_assert (b->loc && b->loc->next == NULL); | |
9832 | ||
f303dbd6 PA |
9833 | annotate_watchpoint (b->number); |
9834 | maybe_print_thread_hit_breakpoint (uiout); | |
9835 | ||
348d480f PA |
9836 | switch (b->type) |
9837 | { | |
9838 | case bp_hardware_watchpoint: | |
112e8700 SM |
9839 | if (uiout->is_mi_like_p ()) |
9840 | uiout->field_string | |
9841 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9842 | break; |
9843 | ||
9844 | case bp_read_watchpoint: | |
112e8700 SM |
9845 | if (uiout->is_mi_like_p ()) |
9846 | uiout->field_string | |
9847 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
9848 | break; |
9849 | ||
9850 | case bp_access_watchpoint: | |
112e8700 SM |
9851 | if (uiout->is_mi_like_p ()) |
9852 | uiout->field_string | |
9853 | ("reason", | |
348d480f PA |
9854 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
9855 | break; | |
9856 | default: | |
9857 | internal_error (__FILE__, __LINE__, | |
9858 | _("Invalid hardware watchpoint type.")); | |
9859 | } | |
9860 | ||
9861 | mention (b); | |
112e8700 | 9862 | uiout->text (_("\n\ |
9c06b0b4 TJB |
9863 | Check the underlying instruction at PC for the memory\n\ |
9864 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 9865 | uiout->text ("\n"); |
9c06b0b4 TJB |
9866 | |
9867 | /* More than one watchpoint may have been triggered. */ | |
9868 | return PRINT_UNKNOWN; | |
9869 | } | |
9870 | ||
3a292923 TT |
9871 | /* Implement the "print_one_detail" method for masked hardware |
9872 | watchpoints. */ | |
9c06b0b4 | 9873 | |
3a292923 TT |
9874 | void |
9875 | masked_watchpoint::print_one_detail (struct ui_out *uiout) const | |
9c06b0b4 TJB |
9876 | { |
9877 | /* Masked watchpoints have only one location. */ | |
3a292923 | 9878 | gdb_assert (loc && loc->next == NULL); |
9c06b0b4 | 9879 | |
112e8700 | 9880 | uiout->text ("\tmask "); |
3a292923 | 9881 | uiout->field_core_addr ("mask", loc->gdbarch, hw_wp_mask); |
112e8700 | 9882 | uiout->text ("\n"); |
9c06b0b4 TJB |
9883 | } |
9884 | ||
3a292923 TT |
9885 | /* Implement the "print_mention" method for masked hardware |
9886 | watchpoints. */ | |
9c06b0b4 | 9887 | |
3a292923 TT |
9888 | void |
9889 | masked_watchpoint::print_mention () | |
9c06b0b4 | 9890 | { |
79a45e25 | 9891 | struct ui_out *uiout = current_uiout; |
46b9c129 | 9892 | const char *tuple_name; |
9c06b0b4 | 9893 | |
3a292923 | 9894 | switch (type) |
9c06b0b4 TJB |
9895 | { |
9896 | case bp_hardware_watchpoint: | |
112e8700 | 9897 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 9898 | tuple_name = "wpt"; |
9c06b0b4 TJB |
9899 | break; |
9900 | case bp_read_watchpoint: | |
112e8700 | 9901 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 9902 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
9903 | break; |
9904 | case bp_access_watchpoint: | |
112e8700 | 9905 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 9906 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
9907 | break; |
9908 | default: | |
9909 | internal_error (__FILE__, __LINE__, | |
9910 | _("Invalid hardware watchpoint type.")); | |
9911 | } | |
9912 | ||
46b9c129 | 9913 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
3a292923 | 9914 | uiout->field_signed ("number", number); |
112e8700 | 9915 | uiout->text (": "); |
3a292923 | 9916 | uiout->field_string ("exp", exp_string.get ()); |
9c06b0b4 TJB |
9917 | } |
9918 | ||
3a292923 TT |
9919 | /* Implement the "print_recreate" method for masked hardware |
9920 | watchpoints. */ | |
9c06b0b4 | 9921 | |
3a292923 TT |
9922 | void |
9923 | masked_watchpoint::print_recreate (struct ui_file *fp) | |
9c06b0b4 | 9924 | { |
3a292923 | 9925 | switch (type) |
9c06b0b4 TJB |
9926 | { |
9927 | case bp_hardware_watchpoint: | |
6cb06a8c | 9928 | gdb_printf (fp, "watch"); |
9c06b0b4 TJB |
9929 | break; |
9930 | case bp_read_watchpoint: | |
6cb06a8c | 9931 | gdb_printf (fp, "rwatch"); |
9c06b0b4 TJB |
9932 | break; |
9933 | case bp_access_watchpoint: | |
6cb06a8c | 9934 | gdb_printf (fp, "awatch"); |
9c06b0b4 TJB |
9935 | break; |
9936 | default: | |
9937 | internal_error (__FILE__, __LINE__, | |
9938 | _("Invalid hardware watchpoint type.")); | |
9939 | } | |
9940 | ||
3a292923 TT |
9941 | gdb_printf (fp, " %s mask 0x%s", exp_string.get (), |
9942 | phex (hw_wp_mask, sizeof (CORE_ADDR))); | |
9943 | print_recreate_thread (this, fp); | |
9c06b0b4 TJB |
9944 | } |
9945 | ||
9c06b0b4 TJB |
9946 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ |
9947 | ||
f2478a7e | 9948 | static bool |
9c06b0b4 TJB |
9949 | is_masked_watchpoint (const struct breakpoint *b) |
9950 | { | |
3a292923 | 9951 | return dynamic_cast<const masked_watchpoint *> (b) != nullptr; |
9c06b0b4 TJB |
9952 | } |
9953 | ||
53a5351d | 9954 | /* accessflag: hw_write: watch write, |
dda83cd7 | 9955 | hw_read: watch read, |
53a5351d | 9956 | hw_access: watch access (read or write) */ |
c906108c | 9957 | static void |
bbc13ae3 | 9958 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
2e362716 | 9959 | bool just_location, bool internal) |
c906108c | 9960 | { |
c1fc2657 | 9961 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 9962 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
b926417a | 9963 | struct value *result; |
bb9d5f81 | 9964 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
9965 | const char *exp_start = NULL; |
9966 | const char *exp_end = NULL; | |
9967 | const char *tok, *end_tok; | |
9c06b0b4 | 9968 | int toklen = -1; |
bbc13ae3 KS |
9969 | const char *cond_start = NULL; |
9970 | const char *cond_end = NULL; | |
c906108c | 9971 | enum bptype bp_type; |
37e4754d | 9972 | int thread = -1; |
9c06b0b4 TJB |
9973 | /* Flag to indicate whether we are going to use masks for |
9974 | the hardware watchpoint. */ | |
2e362716 | 9975 | bool use_mask = false; |
9c06b0b4 | 9976 | CORE_ADDR mask = 0; |
8a18382f | 9977 | int task = 0; |
c906108c | 9978 | |
37e4754d LM |
9979 | /* Make sure that we actually have parameters to parse. */ |
9980 | if (arg != NULL && arg[0] != '\0') | |
9981 | { | |
bbc13ae3 KS |
9982 | const char *value_start; |
9983 | ||
9984 | exp_end = arg + strlen (arg); | |
37e4754d | 9985 | |
9c06b0b4 TJB |
9986 | /* Look for "parameter value" pairs at the end |
9987 | of the arguments string. */ | |
bbc13ae3 | 9988 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
9989 | { |
9990 | /* Skip whitespace at the end of the argument list. */ | |
9991 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9992 | tok--; | |
9993 | ||
9994 | /* Find the beginning of the last token. | |
9995 | This is the value of the parameter. */ | |
9996 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9997 | tok--; | |
9998 | value_start = tok + 1; | |
9999 | ||
10000 | /* Skip whitespace. */ | |
10001 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10002 | tok--; | |
10003 | ||
10004 | end_tok = tok; | |
10005 | ||
10006 | /* Find the beginning of the second to last token. | |
10007 | This is the parameter itself. */ | |
10008 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10009 | tok--; | |
10010 | tok++; | |
10011 | toklen = end_tok - tok + 1; | |
10012 | ||
61012eef | 10013 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10014 | { |
5d5658a1 | 10015 | struct thread_info *thr; |
9c06b0b4 TJB |
10016 | /* At this point we've found a "thread" token, which means |
10017 | the user is trying to set a watchpoint that triggers | |
10018 | only in a specific thread. */ | |
5d5658a1 | 10019 | const char *endp; |
37e4754d | 10020 | |
9c06b0b4 TJB |
10021 | if (thread != -1) |
10022 | error(_("You can specify only one thread.")); | |
37e4754d | 10023 | |
9c06b0b4 | 10024 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10025 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10026 | |
5d5658a1 | 10027 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10028 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10029 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10030 | |
5d5658a1 | 10031 | thread = thr->global_num; |
9c06b0b4 | 10032 | } |
8a18382f TT |
10033 | else if (toklen == 4 && startswith (tok, "task")) |
10034 | { | |
10035 | char *tmp; | |
10036 | ||
10037 | task = strtol (value_start, &tmp, 0); | |
10038 | if (tmp == value_start) | |
10039 | error (_("Junk after task keyword.")); | |
10040 | if (!valid_task_id (task)) | |
10041 | error (_("Unknown task %d."), task); | |
10042 | } | |
61012eef | 10043 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10044 | { |
10045 | /* We've found a "mask" token, which means the user wants to | |
10046 | create a hardware watchpoint that is going to have the mask | |
10047 | facility. */ | |
10048 | struct value *mask_value, *mark; | |
37e4754d | 10049 | |
9c06b0b4 TJB |
10050 | if (use_mask) |
10051 | error(_("You can specify only one mask.")); | |
37e4754d | 10052 | |
2e362716 | 10053 | use_mask = just_location = true; |
37e4754d | 10054 | |
9c06b0b4 TJB |
10055 | mark = value_mark (); |
10056 | mask_value = parse_to_comma_and_eval (&value_start); | |
10057 | mask = value_as_address (mask_value); | |
10058 | value_free_to_mark (mark); | |
10059 | } | |
10060 | else | |
10061 | /* We didn't recognize what we found. We should stop here. */ | |
10062 | break; | |
37e4754d | 10063 | |
9c06b0b4 TJB |
10064 | /* Truncate the string and get rid of the "parameter value" pair before |
10065 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10066 | exp_end = tok; |
9c06b0b4 | 10067 | } |
37e4754d | 10068 | } |
bbc13ae3 KS |
10069 | else |
10070 | exp_end = arg; | |
37e4754d | 10071 | |
bbc13ae3 KS |
10072 | /* Parse the rest of the arguments. From here on out, everything |
10073 | is in terms of a newly allocated string instead of the original | |
10074 | ARG. */ | |
81b1e71c TT |
10075 | std::string expression (arg, exp_end - arg); |
10076 | exp_start = arg = expression.c_str (); | |
699bd4cf TT |
10077 | innermost_block_tracker tracker; |
10078 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); | |
c906108c | 10079 | exp_end = arg; |
fa8a61dc TT |
10080 | /* Remove trailing whitespace from the expression before saving it. |
10081 | This makes the eventual display of the expression string a bit | |
10082 | prettier. */ | |
10083 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10084 | --exp_end; | |
10085 | ||
65d79d4b | 10086 | /* Checking if the expression is not constant. */ |
4d01a485 | 10087 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10088 | { |
10089 | int len; | |
10090 | ||
10091 | len = exp_end - exp_start; | |
10092 | while (len > 0 && isspace (exp_start[len - 1])) | |
10093 | len--; | |
10094 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10095 | } | |
10096 | ||
699bd4cf | 10097 | exp_valid_block = tracker.block (); |
b926417a | 10098 | struct value *mark = value_mark (); |
850645cf | 10099 | struct value *val_as_value = nullptr; |
1eaebe02 TT |
10100 | fetch_subexp_value (exp.get (), exp->op.get (), &val_as_value, &result, NULL, |
10101 | just_location); | |
06a64a0b | 10102 | |
850645cf | 10103 | if (val_as_value != NULL && just_location) |
bb9d5f81 | 10104 | { |
850645cf TT |
10105 | saved_bitpos = value_bitpos (val_as_value); |
10106 | saved_bitsize = value_bitsize (val_as_value); | |
bb9d5f81 PP |
10107 | } |
10108 | ||
850645cf | 10109 | value_ref_ptr val; |
06a64a0b TT |
10110 | if (just_location) |
10111 | { | |
9c06b0b4 TJB |
10112 | int ret; |
10113 | ||
06a64a0b | 10114 | exp_valid_block = NULL; |
850645cf | 10115 | val = release_value (value_addr (result)); |
06a64a0b | 10116 | value_free_to_mark (mark); |
9c06b0b4 TJB |
10117 | |
10118 | if (use_mask) | |
10119 | { | |
850645cf | 10120 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
9c06b0b4 TJB |
10121 | mask); |
10122 | if (ret == -1) | |
10123 | error (_("This target does not support masked watchpoints.")); | |
10124 | else if (ret == -2) | |
10125 | error (_("Invalid mask or memory region.")); | |
10126 | } | |
06a64a0b | 10127 | } |
850645cf TT |
10128 | else if (val_as_value != NULL) |
10129 | val = release_value (val_as_value); | |
c906108c | 10130 | |
f1735a53 TT |
10131 | tok = skip_spaces (arg); |
10132 | end_tok = skip_to_space (tok); | |
c906108c SS |
10133 | |
10134 | toklen = end_tok - tok; | |
10135 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10136 | { | |
10137 | tok = cond_start = end_tok + 1; | |
699bd4cf TT |
10138 | innermost_block_tracker if_tracker; |
10139 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); | |
60e1c644 PA |
10140 | |
10141 | /* The watchpoint expression may not be local, but the condition | |
10142 | may still be. E.g.: `watch global if local > 0'. */ | |
699bd4cf | 10143 | cond_exp_valid_block = if_tracker.block (); |
60e1c644 | 10144 | |
c906108c SS |
10145 | cond_end = tok; |
10146 | } | |
10147 | if (*tok) | |
8a3fe4f8 | 10148 | error (_("Junk at end of command.")); |
c906108c | 10149 | |
441d7c93 PA |
10150 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10151 | ||
10152 | /* Save this because create_internal_breakpoint below invalidates | |
10153 | 'wp_frame'. */ | |
10154 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10155 | |
10156 | /* If the expression is "local", then set up a "watchpoint scope" | |
10157 | breakpoint at the point where we've left the scope of the watchpoint | |
10158 | expression. Create the scope breakpoint before the watchpoint, so | |
10159 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10160 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10161 | { |
441d7c93 PA |
10162 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10163 | ||
10164 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10165 | { |
441d7c93 PA |
10166 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10167 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10168 | ||
24b21115 | 10169 | scope_breakpoint |
441d7c93 | 10170 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 | 10171 | bp_watchpoint_scope, |
a0cd5f08 | 10172 | &base_breakpoint_ops); |
d983da9c | 10173 | |
441d7c93 PA |
10174 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
10175 | wp_frame = NULL; | |
10176 | ||
edb3359d | 10177 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 10178 | |
edb3359d DJ |
10179 | /* Automatically delete the breakpoint when it hits. */ |
10180 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 10181 | |
edb3359d | 10182 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 10183 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 10184 | |
edb3359d | 10185 | /* Set the address at which we will stop. */ |
441d7c93 PA |
10186 | scope_breakpoint->loc->gdbarch = caller_arch; |
10187 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 10188 | scope_breakpoint->loc->address |
a6d9a66e UW |
10189 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
10190 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
10191 | scope_breakpoint->type); |
10192 | } | |
d983da9c DJ |
10193 | } |
10194 | ||
e8369a73 AB |
10195 | /* Now set up the breakpoint. We create all watchpoints as hardware |
10196 | watchpoints here even if hardware watchpoints are turned off, a call | |
10197 | to update_watchpoint later in this function will cause the type to | |
10198 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
10199 | ||
10200 | if (accessflag == hw_read) | |
10201 | bp_type = bp_read_watchpoint; | |
10202 | else if (accessflag == hw_access) | |
10203 | bp_type = bp_access_watchpoint; | |
10204 | else | |
10205 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 10206 | |
3a292923 | 10207 | std::unique_ptr<watchpoint> w; |
348d480f | 10208 | if (use_mask) |
3a292923 | 10209 | w.reset (new masked_watchpoint ()); |
348d480f | 10210 | else |
3a292923 TT |
10211 | w.reset (new watchpoint ()); |
10212 | init_raw_breakpoint_without_location (w.get (), nullptr, bp_type, | |
a0cd5f08 | 10213 | &base_breakpoint_ops); |
3a292923 | 10214 | |
c1fc2657 | 10215 | w->thread = thread; |
8a18382f | 10216 | w->task = task; |
c1fc2657 SM |
10217 | w->disposition = disp_donttouch; |
10218 | w->pspace = current_program_space; | |
b22e99fd | 10219 | w->exp = std::move (exp); |
3a5c3e22 PA |
10220 | w->exp_valid_block = exp_valid_block; |
10221 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
10222 | if (just_location) |
10223 | { | |
850645cf TT |
10224 | struct type *t = value_type (val.get ()); |
10225 | CORE_ADDR addr = value_as_address (val.get ()); | |
06a64a0b | 10226 | |
43cc5389 | 10227 | w->exp_string_reparse |
a4c50be3 | 10228 | = current_language->watch_location_expression (t, addr); |
06a64a0b | 10229 | |
8579fd13 AB |
10230 | w->exp_string = xstrprintf ("-location %.*s", |
10231 | (int) (exp_end - exp_start), exp_start); | |
06a64a0b TT |
10232 | } |
10233 | else | |
a4c50be3 | 10234 | w->exp_string.reset (savestring (exp_start, exp_end - exp_start)); |
9c06b0b4 TJB |
10235 | |
10236 | if (use_mask) | |
10237 | { | |
3a5c3e22 | 10238 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
10239 | } |
10240 | else | |
10241 | { | |
3a5c3e22 | 10242 | w->val = val; |
bb9d5f81 PP |
10243 | w->val_bitpos = saved_bitpos; |
10244 | w->val_bitsize = saved_bitsize; | |
4c1d86d9 | 10245 | w->val_valid = true; |
9c06b0b4 | 10246 | } |
77b06cd7 | 10247 | |
c906108c | 10248 | if (cond_start) |
6f781ee3 | 10249 | w->cond_string.reset (savestring (cond_start, cond_end - cond_start)); |
c906108c | 10250 | else |
c1fc2657 | 10251 | w->cond_string = 0; |
c5aa993b | 10252 | |
441d7c93 | 10253 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 10254 | { |
441d7c93 | 10255 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 10256 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 10257 | } |
c906108c | 10258 | else |
f6bc2008 | 10259 | { |
3a5c3e22 PA |
10260 | w->watchpoint_frame = null_frame_id; |
10261 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 10262 | } |
c906108c | 10263 | |
d983da9c | 10264 | if (scope_breakpoint != NULL) |
c906108c | 10265 | { |
d983da9c DJ |
10266 | /* The scope breakpoint is related to the watchpoint. We will |
10267 | need to act on them together. */ | |
c1fc2657 | 10268 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 10269 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 10270 | } |
d983da9c | 10271 | |
06a64a0b TT |
10272 | if (!just_location) |
10273 | value_free_to_mark (mark); | |
2d134ed3 | 10274 | |
b270e6f9 TT |
10275 | /* Finally update the new watchpoint. This creates the locations |
10276 | that should be inserted. */ | |
10277 | update_watchpoint (w.get (), 1); | |
a9634178 | 10278 | |
b270e6f9 | 10279 | install_breakpoint (internal, std::move (w), 1); |
c906108c SS |
10280 | } |
10281 | ||
e09342b5 | 10282 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 10283 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 10284 | |
c906108c | 10285 | static int |
a6535de1 | 10286 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
c906108c SS |
10287 | { |
10288 | int found_memory_cnt = 0; | |
10289 | ||
10290 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 10291 | if (!can_use_hw_watchpoints) |
c906108c | 10292 | return 0; |
c5aa993b | 10293 | |
a6535de1 TT |
10294 | gdb_assert (!vals.empty ()); |
10295 | struct value *head = vals[0].get (); | |
10296 | ||
5c44784c JM |
10297 | /* Make sure that the value of the expression depends only upon |
10298 | memory contents, and values computed from them within GDB. If we | |
10299 | find any register references or function calls, we can't use a | |
10300 | hardware watchpoint. | |
10301 | ||
10302 | The idea here is that evaluating an expression generates a series | |
10303 | of values, one holding the value of every subexpression. (The | |
10304 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
10305 | a*b+c.) GDB's values hold almost enough information to establish | |
10306 | the criteria given above --- they identify memory lvalues, | |
10307 | register lvalues, computed values, etcetera. So we can evaluate | |
10308 | the expression, and then scan the chain of values that leaves | |
10309 | behind to decide whether we can detect any possible change to the | |
10310 | expression's final value using only hardware watchpoints. | |
10311 | ||
10312 | However, I don't think that the values returned by inferior | |
10313 | function calls are special in any way. So this function may not | |
10314 | notice that an expression involving an inferior function call | |
10315 | can't be watched with hardware watchpoints. FIXME. */ | |
a6535de1 | 10316 | for (const value_ref_ptr &iter : vals) |
c906108c | 10317 | { |
a6535de1 TT |
10318 | struct value *v = iter.get (); |
10319 | ||
5c44784c | 10320 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 10321 | { |
8464be76 DJ |
10322 | if (v != head && value_lazy (v)) |
10323 | /* A lazy memory lvalue in the chain is one that GDB never | |
10324 | needed to fetch; we either just used its address (e.g., | |
10325 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
10326 | in `a,b'). This doesn't apply to HEAD; if that is | |
10327 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 10328 | ; |
53a5351d | 10329 | else |
5c44784c JM |
10330 | { |
10331 | /* Ahh, memory we actually used! Check if we can cover | |
dda83cd7 | 10332 | it with hardware watchpoints. */ |
df407dfe | 10333 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
10334 | |
10335 | /* We only watch structs and arrays if user asked for it | |
10336 | explicitly, never if they just happen to appear in a | |
10337 | middle of some value chain. */ | |
10338 | if (v == head | |
78134374 SM |
10339 | || (vtype->code () != TYPE_CODE_STRUCT |
10340 | && vtype->code () != TYPE_CODE_ARRAY)) | |
2e70b7b9 | 10341 | { |
42ae5230 | 10342 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
10343 | int len; |
10344 | int num_regs; | |
10345 | ||
a9634178 | 10346 | len = (target_exact_watchpoints |
e09342b5 TJB |
10347 | && is_scalar_type_recursive (vtype))? |
10348 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 10349 | |
e09342b5 TJB |
10350 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
10351 | if (!num_regs) | |
2e70b7b9 MS |
10352 | return 0; |
10353 | else | |
e09342b5 | 10354 | found_memory_cnt += num_regs; |
2e70b7b9 | 10355 | } |
5c44784c | 10356 | } |
c5aa993b | 10357 | } |
5086187c AC |
10358 | else if (VALUE_LVAL (v) != not_lval |
10359 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 10360 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 10361 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 10362 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
10363 | } |
10364 | ||
10365 | /* The expression itself looks suitable for using a hardware | |
10366 | watchpoint, but give the target machine a chance to reject it. */ | |
10367 | return found_memory_cnt; | |
10368 | } | |
10369 | ||
8b93c638 | 10370 | void |
2e362716 | 10371 | watch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 10372 | { |
84f4c1fe | 10373 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
10374 | } |
10375 | ||
a15a5258 AB |
10376 | /* Options for the watch, awatch, and rwatch commands. */ |
10377 | ||
10378 | struct watch_options | |
10379 | { | |
10380 | /* For -location. */ | |
10381 | bool location = false; | |
10382 | }; | |
10383 | ||
10384 | /* Definitions of options for the "watch", "awatch", and "rwatch" commands. | |
10385 | ||
10386 | Historically GDB always accepted both '-location' and '-l' flags for | |
10387 | these commands (both flags being synonyms). When converting to the | |
10388 | newer option scheme only '-location' is added here. That's fine (for | |
10389 | backward compatibility) as any non-ambiguous prefix of a flag will be | |
10390 | accepted, so '-l', '-loc', are now all accepted. | |
10391 | ||
10392 | What this means is that, if in the future, we add any new flag here | |
10393 | that starts with '-l' then this will break backward compatibility, so | |
10394 | please, don't do that! */ | |
10395 | ||
10396 | static const gdb::option::option_def watch_option_defs[] = { | |
10397 | gdb::option::flag_option_def<watch_options> { | |
10398 | "location", | |
10399 | [] (watch_options *opt) { return &opt->location; }, | |
10400 | N_("\ | |
10401 | This evaluates EXPRESSION and watches the memory to which is refers.\n\ | |
10402 | -l can be used as a short form of -location."), | |
10403 | }, | |
10404 | }; | |
10405 | ||
10406 | /* Returns the option group used by 'watch', 'awatch', and 'rwatch' | |
10407 | commands. */ | |
10408 | ||
10409 | static gdb::option::option_def_group | |
10410 | make_watch_options_def_group (watch_options *opts) | |
10411 | { | |
10412 | return {{watch_option_defs}, opts}; | |
10413 | } | |
10414 | ||
06a64a0b TT |
10415 | /* A helper function that looks for the "-location" argument and then |
10416 | calls watch_command_1. */ | |
10417 | ||
10418 | static void | |
0b39b52e | 10419 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
06a64a0b | 10420 | { |
a15a5258 AB |
10421 | watch_options opts; |
10422 | auto grp = make_watch_options_def_group (&opts); | |
10423 | gdb::option::process_options | |
10424 | (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp); | |
10425 | if (arg != nullptr && *arg == '\0') | |
10426 | arg = nullptr; | |
10427 | ||
10428 | watch_command_1 (arg, accessflag, from_tty, opts.location, false); | |
10429 | } | |
06a64a0b | 10430 | |
a15a5258 AB |
10431 | /* Command completion for 'watch', 'awatch', and 'rwatch' commands. */ |
10432 | static void | |
10433 | watch_command_completer (struct cmd_list_element *ignore, | |
10434 | completion_tracker &tracker, | |
10435 | const char *text, const char * /*word*/) | |
10436 | { | |
10437 | const auto group = make_watch_options_def_group (nullptr); | |
10438 | if (gdb::option::complete_options | |
10439 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group)) | |
10440 | return; | |
06a64a0b | 10441 | |
a15a5258 AB |
10442 | const char *word = advance_to_expression_complete_word_point (tracker, text); |
10443 | expression_completer (ignore, tracker, text, word); | |
8b93c638 | 10444 | } |
8926118c | 10445 | |
c5aa993b | 10446 | static void |
0b39b52e | 10447 | watch_command (const char *arg, int from_tty) |
c906108c | 10448 | { |
06a64a0b | 10449 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
10450 | } |
10451 | ||
8b93c638 | 10452 | void |
2e362716 | 10453 | rwatch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 10454 | { |
84f4c1fe | 10455 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 10456 | } |
8926118c | 10457 | |
c5aa993b | 10458 | static void |
0b39b52e | 10459 | rwatch_command (const char *arg, int from_tty) |
c906108c | 10460 | { |
06a64a0b | 10461 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
10462 | } |
10463 | ||
8b93c638 | 10464 | void |
2e362716 | 10465 | awatch_command_wrapper (const char *arg, int from_tty, bool internal) |
8b93c638 | 10466 | { |
84f4c1fe | 10467 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 10468 | } |
8926118c | 10469 | |
c5aa993b | 10470 | static void |
0b39b52e | 10471 | awatch_command (const char *arg, int from_tty) |
c906108c | 10472 | { |
06a64a0b | 10473 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 10474 | } |
c906108c | 10475 | \f |
c5aa993b | 10476 | |
cfc31633 PA |
10477 | /* Data for the FSM that manages the until(location)/advance commands |
10478 | in infcmd.c. Here because it uses the mechanisms of | |
10479 | breakpoints. */ | |
c906108c | 10480 | |
46e3ed7f | 10481 | struct until_break_fsm : public thread_fsm |
bfec99b2 | 10482 | { |
46e3ed7f | 10483 | /* The thread that was current when the command was executed. */ |
cfc31633 PA |
10484 | int thread; |
10485 | ||
df631783 PA |
10486 | /* The breakpoint set at the return address in the caller frame, |
10487 | plus breakpoints at all the destination locations. */ | |
10488 | std::vector<breakpoint_up> breakpoints; | |
cfc31633 | 10489 | |
46e3ed7f | 10490 | until_break_fsm (struct interp *cmd_interp, int thread, |
df631783 | 10491 | std::vector<breakpoint_up> &&breakpoints) |
46e3ed7f TT |
10492 | : thread_fsm (cmd_interp), |
10493 | thread (thread), | |
df631783 | 10494 | breakpoints (std::move (breakpoints)) |
46e3ed7f TT |
10495 | { |
10496 | } | |
cfc31633 | 10497 | |
46e3ed7f TT |
10498 | void clean_up (struct thread_info *thread) override; |
10499 | bool should_stop (struct thread_info *thread) override; | |
10500 | enum async_reply_reason do_async_reply_reason () override; | |
cfc31633 PA |
10501 | }; |
10502 | ||
cfc31633 PA |
10503 | /* Implementation of the 'should_stop' FSM method for the |
10504 | until(location)/advance commands. */ | |
10505 | ||
46e3ed7f TT |
10506 | bool |
10507 | until_break_fsm::should_stop (struct thread_info *tp) | |
cfc31633 | 10508 | { |
df631783 PA |
10509 | for (const breakpoint_up &bp : breakpoints) |
10510 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
10511 | bp.get ()) != NULL) | |
10512 | { | |
10513 | set_finished (); | |
10514 | break; | |
10515 | } | |
cfc31633 | 10516 | |
46e3ed7f | 10517 | return true; |
cfc31633 PA |
10518 | } |
10519 | ||
10520 | /* Implementation of the 'clean_up' FSM method for the | |
10521 | until(location)/advance commands. */ | |
10522 | ||
46e3ed7f TT |
10523 | void |
10524 | until_break_fsm::clean_up (struct thread_info *) | |
43ff13b4 | 10525 | { |
cfc31633 | 10526 | /* Clean up our temporary breakpoints. */ |
df631783 | 10527 | breakpoints.clear (); |
46e3ed7f | 10528 | delete_longjmp_breakpoint (thread); |
cfc31633 PA |
10529 | } |
10530 | ||
10531 | /* Implementation of the 'async_reply_reason' FSM method for the | |
10532 | until(location)/advance commands. */ | |
10533 | ||
46e3ed7f TT |
10534 | enum async_reply_reason |
10535 | until_break_fsm::do_async_reply_reason () | |
cfc31633 PA |
10536 | { |
10537 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
10538 | } |
10539 | ||
c906108c | 10540 | void |
f2fc3015 | 10541 | until_break_command (const char *arg, int from_tty, int anywhere) |
c906108c | 10542 | { |
8556afb4 PA |
10543 | struct frame_info *frame; |
10544 | struct gdbarch *frame_gdbarch; | |
10545 | struct frame_id stack_frame_id; | |
10546 | struct frame_id caller_frame_id; | |
186c406b TT |
10547 | int thread; |
10548 | struct thread_info *tp; | |
c906108c | 10549 | |
70509625 | 10550 | clear_proceed_status (0); |
c906108c SS |
10551 | |
10552 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 10553 | this function. */ |
c5aa993b | 10554 | |
ffc2605c | 10555 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 10556 | |
6c5b2ebe PA |
10557 | std::vector<symtab_and_line> sals |
10558 | = (last_displayed_sal_is_valid () | |
10559 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
10560 | get_last_displayed_symtab (), | |
10561 | get_last_displayed_line ()) | |
10562 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
cafb3438 | 10563 | NULL, NULL, 0)); |
c5aa993b | 10564 | |
df631783 | 10565 | if (sals.empty ()) |
8a3fe4f8 | 10566 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 10567 | |
c906108c | 10568 | if (*arg) |
8a3fe4f8 | 10569 | error (_("Junk at end of arguments.")); |
c5aa993b | 10570 | |
186c406b | 10571 | tp = inferior_thread (); |
5d5658a1 | 10572 | thread = tp->global_num; |
186c406b | 10573 | |
8556afb4 PA |
10574 | /* Note linespec handling above invalidates the frame chain. |
10575 | Installing a breakpoint also invalidates the frame chain (as it | |
10576 | may need to switch threads), so do any frame handling before | |
10577 | that. */ | |
10578 | ||
10579 | frame = get_selected_frame (NULL); | |
10580 | frame_gdbarch = get_frame_arch (frame); | |
10581 | stack_frame_id = get_stack_frame_id (frame); | |
10582 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 10583 | |
ae66c1fc EZ |
10584 | /* Keep within the current frame, or in frames called by the current |
10585 | one. */ | |
edb3359d | 10586 | |
df631783 | 10587 | std::vector<breakpoint_up> breakpoints; |
5419bdae TT |
10588 | |
10589 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; | |
10590 | ||
883bc8d1 | 10591 | if (frame_id_p (caller_frame_id)) |
c906108c | 10592 | { |
883bc8d1 | 10593 | struct symtab_and_line sal2; |
cfc31633 | 10594 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
10595 | |
10596 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
10597 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 | 10598 | caller_gdbarch = frame_unwind_caller_arch (frame); |
df631783 PA |
10599 | |
10600 | breakpoint_up caller_breakpoint | |
10601 | = set_momentary_breakpoint (caller_gdbarch, sal2, | |
10602 | caller_frame_id, bp_until); | |
10603 | breakpoints.emplace_back (std::move (caller_breakpoint)); | |
186c406b | 10604 | |
883bc8d1 | 10605 | set_longjmp_breakpoint (tp, caller_frame_id); |
5419bdae | 10606 | lj_deleter.emplace (thread); |
c906108c | 10607 | } |
c5aa993b | 10608 | |
c70a6932 JK |
10609 | /* set_momentary_breakpoint could invalidate FRAME. */ |
10610 | frame = NULL; | |
10611 | ||
df631783 PA |
10612 | /* If the user told us to continue until a specified location, we |
10613 | don't specify a frame at which we need to stop. Otherwise, | |
10614 | specify the selected frame, because we want to stop only at the | |
10615 | very same frame. */ | |
10616 | frame_id stop_frame_id = anywhere ? null_frame_id : stack_frame_id; | |
10617 | ||
10618 | for (symtab_and_line &sal : sals) | |
10619 | { | |
10620 | resolve_sal_pc (&sal); | |
10621 | ||
10622 | breakpoint_up location_breakpoint | |
10623 | = set_momentary_breakpoint (frame_gdbarch, sal, | |
10624 | stop_frame_id, bp_until); | |
10625 | breakpoints.emplace_back (std::move (location_breakpoint)); | |
10626 | } | |
883bc8d1 | 10627 | |
573269a8 LS |
10628 | tp->set_thread_fsm |
10629 | (std::unique_ptr<thread_fsm> | |
10630 | (new until_break_fsm (command_interp (), tp->global_num, | |
10631 | std::move (breakpoints)))); | |
f107f563 | 10632 | |
5419bdae TT |
10633 | if (lj_deleter) |
10634 | lj_deleter->release (); | |
f107f563 | 10635 | |
cfc31633 | 10636 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 10637 | } |
ae66c1fc | 10638 | |
9ac4176b | 10639 | void |
28010a5d PA |
10640 | init_ada_exception_breakpoint (struct breakpoint *b, |
10641 | struct gdbarch *gdbarch, | |
10642 | struct symtab_and_line sal, | |
f2fc3015 | 10643 | const char *addr_string, |
28010a5d | 10644 | int tempflag, |
349774ef | 10645 | int enabled, |
28010a5d | 10646 | int from_tty) |
f7f9143b | 10647 | { |
f7f9143b JB |
10648 | if (from_tty) |
10649 | { | |
5af949e3 UW |
10650 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
10651 | if (!loc_gdbarch) | |
10652 | loc_gdbarch = gdbarch; | |
10653 | ||
6c95b8df PA |
10654 | describe_other_breakpoints (loc_gdbarch, |
10655 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b | 10656 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
dda83cd7 SM |
10657 | version for exception catchpoints, because two catchpoints |
10658 | used for different exception names will use the same address. | |
10659 | In this case, a "breakpoint ... also set at..." warning is | |
10660 | unproductive. Besides, the warning phrasing is also a bit | |
10661 | inappropriate, we should use the word catchpoint, and tell | |
10662 | the user what type of catchpoint it is. The above is good | |
10663 | enough for now, though. */ | |
f7f9143b JB |
10664 | } |
10665 | ||
a48ddc0d | 10666 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, |
a0cd5f08 | 10667 | &base_breakpoint_ops); |
f7f9143b | 10668 | |
349774ef | 10669 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 10670 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
10671 | b->location = string_to_event_location (&addr_string, |
10672 | language_def (language_ada)); | |
f7f9143b | 10673 | b->language = language_ada; |
f7f9143b JB |
10674 | } |
10675 | ||
c906108c SS |
10676 | \f |
10677 | ||
81b1e71c | 10678 | /* Compare two breakpoints and return a strcmp-like result. */ |
8a2c437b TT |
10679 | |
10680 | static int | |
81b1e71c | 10681 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
8a2c437b | 10682 | { |
81b1e71c TT |
10683 | uintptr_t ua = (uintptr_t) a; |
10684 | uintptr_t ub = (uintptr_t) b; | |
8a2c437b | 10685 | |
81b1e71c | 10686 | if (a->number < b->number) |
8a2c437b | 10687 | return -1; |
81b1e71c | 10688 | else if (a->number > b->number) |
8a2c437b TT |
10689 | return 1; |
10690 | ||
10691 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
10692 | the number 0. */ | |
10693 | if (ua < ub) | |
10694 | return -1; | |
94b0e70d | 10695 | return ua > ub ? 1 : 0; |
8a2c437b TT |
10696 | } |
10697 | ||
80f8a6eb | 10698 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10699 | |
10700 | static void | |
0b39b52e | 10701 | clear_command (const char *arg, int from_tty) |
c906108c | 10702 | { |
c906108c | 10703 | int default_match; |
c906108c | 10704 | |
6c5b2ebe PA |
10705 | std::vector<symtab_and_line> decoded_sals; |
10706 | symtab_and_line last_sal; | |
10707 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
10708 | if (arg) |
10709 | { | |
6c5b2ebe PA |
10710 | decoded_sals |
10711 | = decode_line_with_current_source (arg, | |
10712 | (DECODE_LINE_FUNFIRSTLINE | |
10713 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 10714 | default_match = 0; |
6c5b2ebe | 10715 | sals = decoded_sals; |
c906108c SS |
10716 | } |
10717 | else | |
10718 | { | |
1bfeeb0f JL |
10719 | /* Set sal's line, symtab, pc, and pspace to the values |
10720 | corresponding to the last call to print_frame_info. If the | |
10721 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 10722 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 10723 | if (last_sal.symtab == 0) |
8a3fe4f8 | 10724 | error (_("No source file specified.")); |
c906108c | 10725 | |
c906108c | 10726 | default_match = 1; |
6c5b2ebe | 10727 | sals = last_sal; |
c906108c SS |
10728 | } |
10729 | ||
4a64f543 MS |
10730 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10731 | seems, because all existing breakpoints typically have both | |
10732 | file/line and pc set. So, if clear is given file/line, we can | |
10733 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10734 | |
10735 | We only support clearing given the address explicitly | |
10736 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10737 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10738 | due to optimization, all in one block. |
4a64f543 MS |
10739 | |
10740 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10741 | PC corresponding to the same file:line, the breakpoint won't |
10742 | be cleared. We probably can still clear the breakpoint, but | |
10743 | since the other PC value is never presented to user, user | |
10744 | can only find it by guessing, and it does not seem important | |
10745 | to support that. */ | |
10746 | ||
4a64f543 MS |
10747 | /* For each line spec given, delete bps which correspond to it. Do |
10748 | it in two passes, solely to preserve the current behavior that | |
10749 | from_tty is forced true if we delete more than one | |
10750 | breakpoint. */ | |
c906108c | 10751 | |
81b1e71c | 10752 | std::vector<struct breakpoint *> found; |
6c5b2ebe | 10753 | for (const auto &sal : sals) |
c906108c | 10754 | { |
05cba821 JK |
10755 | const char *sal_fullname; |
10756 | ||
c906108c | 10757 | /* If exact pc given, clear bpts at that pc. |
dda83cd7 SM |
10758 | If line given (pc == 0), clear all bpts on specified line. |
10759 | If defaulting, clear all bpts on default line | |
10760 | or at default pc. | |
c5aa993b | 10761 | |
dda83cd7 | 10762 | defaulting sal.pc != 0 tests to do |
c5aa993b | 10763 | |
dda83cd7 SM |
10764 | 0 1 pc |
10765 | 1 1 pc _and_ line | |
10766 | 0 0 line | |
10767 | 1 0 <can't happen> */ | |
c906108c | 10768 | |
05cba821 JK |
10769 | sal_fullname = (sal.symtab == NULL |
10770 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 10771 | |
4a64f543 | 10772 | /* Find all matching breakpoints and add them to 'found'. */ |
43892fdf | 10773 | for (breakpoint *b : all_breakpoints ()) |
c5aa993b | 10774 | { |
0d381245 | 10775 | int match = 0; |
4a64f543 | 10776 | /* Are we going to delete b? */ |
a5c69b1e EL |
10777 | if (b->type != bp_none && !is_watchpoint (b) |
10778 | && user_breakpoint_p (b)) | |
0d381245 | 10779 | { |
40cb8ca5 | 10780 | for (bp_location *loc : b->locations ()) |
0d381245 | 10781 | { |
f8eba3c6 TT |
10782 | /* If the user specified file:line, don't allow a PC |
10783 | match. This matches historical gdb behavior. */ | |
10784 | int pc_match = (!sal.explicit_line | |
10785 | && sal.pc | |
10786 | && (loc->pspace == sal.pspace) | |
10787 | && (loc->address == sal.pc) | |
10788 | && (!section_is_overlay (loc->section) | |
10789 | || loc->section == sal.section)); | |
4aac40c8 TT |
10790 | int line_match = 0; |
10791 | ||
10792 | if ((default_match || sal.explicit_line) | |
2f202fde | 10793 | && loc->symtab != NULL |
05cba821 | 10794 | && sal_fullname != NULL |
4aac40c8 | 10795 | && sal.pspace == loc->pspace |
05cba821 JK |
10796 | && loc->line_number == sal.line |
10797 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
10798 | sal_fullname) == 0) | |
10799 | line_match = 1; | |
4aac40c8 | 10800 | |
0d381245 VP |
10801 | if (pc_match || line_match) |
10802 | { | |
10803 | match = 1; | |
10804 | break; | |
10805 | } | |
10806 | } | |
10807 | } | |
10808 | ||
10809 | if (match) | |
81b1e71c | 10810 | found.push_back (b); |
c906108c | 10811 | } |
80f8a6eb | 10812 | } |
8a2c437b | 10813 | |
80f8a6eb | 10814 | /* Now go thru the 'found' chain and delete them. */ |
81b1e71c | 10815 | if (found.empty ()) |
80f8a6eb MS |
10816 | { |
10817 | if (arg) | |
8a3fe4f8 | 10818 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10819 | else |
8a3fe4f8 | 10820 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10821 | } |
c906108c | 10822 | |
8a2c437b | 10823 | /* Remove duplicates from the vec. */ |
81b1e71c | 10824 | std::sort (found.begin (), found.end (), |
b926417a | 10825 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 10826 | { |
b926417a | 10827 | return compare_breakpoints (bp_a, bp_b) < 0; |
81b1e71c TT |
10828 | }); |
10829 | found.erase (std::unique (found.begin (), found.end (), | |
b926417a | 10830 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
81b1e71c | 10831 | { |
b926417a | 10832 | return compare_breakpoints (bp_a, bp_b) == 0; |
81b1e71c TT |
10833 | }), |
10834 | found.end ()); | |
8a2c437b | 10835 | |
81b1e71c | 10836 | if (found.size () > 1) |
4a64f543 | 10837 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10838 | if (from_tty) |
a3f17187 | 10839 | { |
81b1e71c | 10840 | if (found.size () == 1) |
6cb06a8c | 10841 | gdb_printf (_("Deleted breakpoint ")); |
a3f17187 | 10842 | else |
6cb06a8c | 10843 | gdb_printf (_("Deleted breakpoints ")); |
a3f17187 | 10844 | } |
d6e956e5 | 10845 | |
81b1e71c | 10846 | for (breakpoint *iter : found) |
80f8a6eb | 10847 | { |
c5aa993b | 10848 | if (from_tty) |
6cb06a8c | 10849 | gdb_printf ("%d ", iter->number); |
81b1e71c | 10850 | delete_breakpoint (iter); |
c906108c | 10851 | } |
80f8a6eb | 10852 | if (from_tty) |
a11ac3b3 | 10853 | gdb_putc ('\n'); |
c906108c SS |
10854 | } |
10855 | \f | |
10856 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10857 | all breakpoints that are marked for deletion, whether hit or not. | |
10858 | This is called after any breakpoint is hit, or after errors. */ | |
10859 | ||
10860 | void | |
313f3b21 | 10861 | breakpoint_auto_delete (bpstat *bs) |
c906108c | 10862 | { |
c906108c | 10863 | for (; bs; bs = bs->next) |
f431efe5 PA |
10864 | if (bs->breakpoint_at |
10865 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10866 | && bs->stop) |
f431efe5 | 10867 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10868 | |
1428b37a | 10869 | for (breakpoint *b : all_breakpoints_safe ()) |
b5de0fa7 | 10870 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b | 10871 | delete_breakpoint (b); |
c906108c SS |
10872 | } |
10873 | ||
4a64f543 | 10874 | /* A comparison function for bp_location AP and BP being interfaced to |
39ef2f62 | 10875 | std::sort. Sort elements primarily by their ADDRESS (no matter what |
cb1e4e32 PA |
10876 | bl_address_is_meaningful says), secondarily by ordering first |
10877 | permanent elements and terciarily just ensuring the array is sorted | |
39ef2f62 | 10878 | stable way despite std::sort being an unstable algorithm. */ |
876fa593 JK |
10879 | |
10880 | static int | |
39ef2f62 | 10881 | bp_location_is_less_than (const bp_location *a, const bp_location *b) |
876fa593 | 10882 | { |
876fa593 | 10883 | if (a->address != b->address) |
39ef2f62 | 10884 | return a->address < b->address; |
876fa593 | 10885 | |
dea2aa5f LM |
10886 | /* Sort locations at the same address by their pspace number, keeping |
10887 | locations of the same inferior (in a multi-inferior environment) | |
10888 | grouped. */ | |
10889 | ||
10890 | if (a->pspace->num != b->pspace->num) | |
39ef2f62 | 10891 | return a->pspace->num < b->pspace->num; |
dea2aa5f | 10892 | |
876fa593 | 10893 | /* Sort permanent breakpoints first. */ |
1a853c52 | 10894 | if (a->permanent != b->permanent) |
39ef2f62 | 10895 | return a->permanent > b->permanent; |
876fa593 | 10896 | |
7f32a4d5 PA |
10897 | /* Sort by type in order to make duplicate determination easier. |
10898 | See update_global_location_list. This is kept in sync with | |
10899 | breakpoint_locations_match. */ | |
10900 | if (a->loc_type < b->loc_type) | |
10901 | return true; | |
10902 | ||
10903 | /* Likewise, for range-breakpoints, sort by length. */ | |
10904 | if (a->loc_type == bp_loc_hardware_breakpoint | |
10905 | && b->loc_type == bp_loc_hardware_breakpoint | |
10906 | && a->length < b->length) | |
10907 | return true; | |
10908 | ||
c56a97f9 JK |
10909 | /* Make the internal GDB representation stable across GDB runs |
10910 | where A and B memory inside GDB can differ. Breakpoint locations of | |
10911 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
10912 | |
10913 | if (a->owner->number != b->owner->number) | |
39ef2f62 | 10914 | return a->owner->number < b->owner->number; |
876fa593 | 10915 | |
39ef2f62 | 10916 | return a < b; |
876fa593 JK |
10917 | } |
10918 | ||
f5336ca5 PA |
10919 | /* Set bp_locations_placed_address_before_address_max and |
10920 | bp_locations_shadow_len_after_address_max according to the current | |
10921 | content of the bp_locations array. */ | |
f7545552 TT |
10922 | |
10923 | static void | |
f5336ca5 | 10924 | bp_locations_target_extensions_update (void) |
f7545552 | 10925 | { |
f5336ca5 PA |
10926 | bp_locations_placed_address_before_address_max = 0; |
10927 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 | 10928 | |
48d7020b | 10929 | for (bp_location *bl : all_bp_locations ()) |
876fa593 JK |
10930 | { |
10931 | CORE_ADDR start, end, addr; | |
10932 | ||
10933 | if (!bp_location_has_shadow (bl)) | |
10934 | continue; | |
10935 | ||
10936 | start = bl->target_info.placed_address; | |
10937 | end = start + bl->target_info.shadow_len; | |
10938 | ||
10939 | gdb_assert (bl->address >= start); | |
10940 | addr = bl->address - start; | |
f5336ca5 PA |
10941 | if (addr > bp_locations_placed_address_before_address_max) |
10942 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
10943 | |
10944 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10945 | ||
10946 | gdb_assert (bl->address < end); | |
10947 | addr = end - bl->address; | |
f5336ca5 PA |
10948 | if (addr > bp_locations_shadow_len_after_address_max) |
10949 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 10950 | } |
f7545552 TT |
10951 | } |
10952 | ||
1e4d1764 YQ |
10953 | /* Download tracepoint locations if they haven't been. */ |
10954 | ||
10955 | static void | |
10956 | download_tracepoint_locations (void) | |
10957 | { | |
dd2e65cc | 10958 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 10959 | |
5ed8105e | 10960 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 10961 | |
f6d17b2b | 10962 | for (breakpoint *b : all_tracepoints ()) |
1e4d1764 YQ |
10963 | { |
10964 | struct tracepoint *t; | |
f2a8bc8a | 10965 | int bp_location_downloaded = 0; |
1e4d1764 | 10966 | |
7ed2c994 | 10967 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
10968 | ? !may_insert_fast_tracepoints |
10969 | : !may_insert_tracepoints)) | |
10970 | continue; | |
10971 | ||
dd2e65cc YQ |
10972 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
10973 | { | |
10974 | if (target_can_download_tracepoint ()) | |
10975 | can_download_tracepoint = TRIBOOL_TRUE; | |
10976 | else | |
10977 | can_download_tracepoint = TRIBOOL_FALSE; | |
10978 | } | |
10979 | ||
10980 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
10981 | break; | |
10982 | ||
40cb8ca5 | 10983 | for (bp_location *bl : b->locations ()) |
7ed2c994 YQ |
10984 | { |
10985 | /* In tracepoint, locations are _never_ duplicated, so | |
10986 | should_be_inserted is equivalent to | |
10987 | unduplicated_should_be_inserted. */ | |
10988 | if (!should_be_inserted (bl) || bl->inserted) | |
10989 | continue; | |
1e4d1764 | 10990 | |
7ed2c994 | 10991 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 10992 | |
7ed2c994 | 10993 | target_download_tracepoint (bl); |
1e4d1764 | 10994 | |
7ed2c994 | 10995 | bl->inserted = 1; |
f2a8bc8a | 10996 | bp_location_downloaded = 1; |
7ed2c994 YQ |
10997 | } |
10998 | t = (struct tracepoint *) b; | |
10999 | t->number_on_target = b->number; | |
f2a8bc8a | 11000 | if (bp_location_downloaded) |
76727919 | 11001 | gdb::observers::breakpoint_modified.notify (b); |
1e4d1764 | 11002 | } |
1e4d1764 YQ |
11003 | } |
11004 | ||
934709f0 PW |
11005 | /* Swap the insertion/duplication state between two locations. */ |
11006 | ||
11007 | static void | |
11008 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11009 | { | |
11010 | const int left_inserted = left->inserted; | |
11011 | const int left_duplicate = left->duplicate; | |
b775012e | 11012 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11013 | const struct bp_target_info left_target_info = left->target_info; |
11014 | ||
1e4d1764 YQ |
11015 | /* Locations of tracepoints can never be duplicated. */ |
11016 | if (is_tracepoint (left->owner)) | |
11017 | gdb_assert (!left->duplicate); | |
11018 | if (is_tracepoint (right->owner)) | |
11019 | gdb_assert (!right->duplicate); | |
11020 | ||
934709f0 PW |
11021 | left->inserted = right->inserted; |
11022 | left->duplicate = right->duplicate; | |
b775012e | 11023 | left->needs_update = right->needs_update; |
934709f0 PW |
11024 | left->target_info = right->target_info; |
11025 | right->inserted = left_inserted; | |
11026 | right->duplicate = left_duplicate; | |
b775012e | 11027 | right->needs_update = left_needs_update; |
934709f0 PW |
11028 | right->target_info = left_target_info; |
11029 | } | |
11030 | ||
b775012e LM |
11031 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11032 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11033 | conditions on the target's side. Such conditions need to be updated on | |
11034 | the target. */ | |
11035 | ||
11036 | static void | |
11037 | force_breakpoint_reinsertion (struct bp_location *bl) | |
11038 | { | |
b775012e LM |
11039 | CORE_ADDR address = 0; |
11040 | int pspace_num; | |
11041 | ||
11042 | address = bl->address; | |
11043 | pspace_num = bl->pspace->num; | |
11044 | ||
11045 | /* This is only meaningful if the target is | |
11046 | evaluating conditions and if the user has | |
11047 | opted for condition evaluation on the target's | |
11048 | side. */ | |
11049 | if (gdb_evaluates_breakpoint_condition_p () | |
11050 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
11051 | return; | |
11052 | ||
11053 | /* Flag all breakpoint locations with this address and | |
11054 | the same program space as the location | |
11055 | as "its condition has changed". We need to | |
11056 | update the conditions on the target's side. */ | |
e0d9a270 | 11057 | for (bp_location *loc : all_bp_locations_at_addr (address)) |
b775012e | 11058 | { |
b775012e LM |
11059 | if (!is_breakpoint (loc->owner) |
11060 | || pspace_num != loc->pspace->num) | |
11061 | continue; | |
11062 | ||
11063 | /* Flag the location appropriately. We use a different state to | |
11064 | let everyone know that we already updated the set of locations | |
11065 | with addr bl->address and program space bl->pspace. This is so | |
11066 | we don't have to keep calling these functions just to mark locations | |
11067 | that have already been marked. */ | |
11068 | loc->condition_changed = condition_updated; | |
11069 | ||
11070 | /* Free the agent expression bytecode as well. We will compute | |
11071 | it later on. */ | |
833177a4 | 11072 | loc->cond_bytecode.reset (); |
b775012e LM |
11073 | } |
11074 | } | |
7f32a4d5 | 11075 | |
44702360 PA |
11076 | /* Called whether new breakpoints are created, or existing breakpoints |
11077 | deleted, to update the global location list and recompute which | |
11078 | locations are duplicate of which. | |
b775012e | 11079 | |
04086b45 PA |
11080 | The INSERT_MODE flag determines whether locations may not, may, or |
11081 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
11082 | info. */ | |
b60e7edf | 11083 | |
0d381245 | 11084 | static void |
44702360 | 11085 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 11086 | { |
b775012e LM |
11087 | /* Last breakpoint location address that was marked for update. */ |
11088 | CORE_ADDR last_addr = 0; | |
11089 | /* Last breakpoint location program space that was marked for update. */ | |
11090 | int last_pspace_num = -1; | |
f7545552 | 11091 | |
2d134ed3 PA |
11092 | /* Used in the duplicates detection below. When iterating over all |
11093 | bp_locations, points to the first bp_location of a given address. | |
11094 | Breakpoints and watchpoints of different types are never | |
11095 | duplicates of each other. Keep one pointer for each type of | |
11096 | breakpoint/watchpoint, so we only need to loop over all locations | |
11097 | once. */ | |
11098 | struct bp_location *bp_loc_first; /* breakpoint */ | |
11099 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
11100 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
11101 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 11102 | |
f5336ca5 PA |
11103 | /* Saved former bp_locations array which we compare against the newly |
11104 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
5d51cd5d SM |
11105 | std::vector<bp_location *> old_locations = std::move (bp_locations); |
11106 | bp_locations.clear (); | |
876fa593 | 11107 | |
43892fdf | 11108 | for (breakpoint *b : all_breakpoints ()) |
40cb8ca5 | 11109 | for (bp_location *loc : b->locations ()) |
5d51cd5d | 11110 | bp_locations.push_back (loc); |
7f32a4d5 PA |
11111 | |
11112 | /* See if we need to "upgrade" a software breakpoint to a hardware | |
11113 | breakpoint. Do this before deciding whether locations are | |
11114 | duplicates. Also do this before sorting because sorting order | |
11115 | depends on location type. */ | |
5d51cd5d SM |
11116 | for (bp_location *loc : bp_locations) |
11117 | if (!loc->inserted && should_be_inserted (loc)) | |
7f32a4d5 | 11118 | handle_automatic_hardware_breakpoints (loc); |
7f32a4d5 | 11119 | |
5d51cd5d | 11120 | std::sort (bp_locations.begin (), bp_locations.end (), |
39ef2f62 | 11121 | bp_location_is_less_than); |
876fa593 | 11122 | |
f5336ca5 | 11123 | bp_locations_target_extensions_update (); |
74960c60 | 11124 | |
4a64f543 MS |
11125 | /* Identify bp_location instances that are no longer present in the |
11126 | new list, and therefore should be freed. Note that it's not | |
11127 | necessary that those locations should be removed from inferior -- | |
11128 | if there's another location at the same address (previously | |
11129 | marked as duplicate), we don't need to remove/insert the | |
11130 | location. | |
876fa593 | 11131 | |
4a64f543 MS |
11132 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
11133 | and former bp_location array state respectively. */ | |
876fa593 | 11134 | |
5d51cd5d SM |
11135 | size_t loc_i = 0; |
11136 | for (bp_location *old_loc : old_locations) | |
74960c60 | 11137 | { |
e5dd4106 | 11138 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 11139 | not, we have to free it. */ |
c7d46a38 | 11140 | int found_object = 0; |
20874c92 VP |
11141 | /* Tells if the location should remain inserted in the target. */ |
11142 | int keep_in_target = 0; | |
11143 | int removed = 0; | |
876fa593 | 11144 | |
4a64f543 MS |
11145 | /* Skip LOCP entries which will definitely never be needed. |
11146 | Stop either at or being the one matching OLD_LOC. */ | |
5d51cd5d SM |
11147 | while (loc_i < bp_locations.size () |
11148 | && bp_locations[loc_i]->address < old_loc->address) | |
11149 | loc_i++; | |
c7d46a38 | 11150 | |
5d51cd5d SM |
11151 | for (size_t loc2_i = loc_i; |
11152 | (loc2_i < bp_locations.size () | |
11153 | && bp_locations[loc2_i]->address == old_loc->address); | |
11154 | loc2_i++) | |
c7d46a38 | 11155 | { |
b775012e LM |
11156 | /* Check if this is a new/duplicated location or a duplicated |
11157 | location that had its condition modified. If so, we want to send | |
11158 | its condition to the target if evaluation of conditions is taking | |
11159 | place there. */ | |
5d51cd5d | 11160 | if (bp_locations[loc2_i]->condition_changed == condition_modified |
b775012e LM |
11161 | && (last_addr != old_loc->address |
11162 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 11163 | { |
5d51cd5d | 11164 | force_breakpoint_reinsertion (bp_locations[loc2_i]); |
b775012e | 11165 | last_pspace_num = old_loc->pspace->num; |
c7d46a38 | 11166 | } |
b775012e | 11167 | |
5d51cd5d | 11168 | if (bp_locations[loc2_i] == old_loc) |
b775012e | 11169 | found_object = 1; |
c7d46a38 | 11170 | } |
74960c60 | 11171 | |
b775012e LM |
11172 | /* We have already handled this address, update it so that we don't |
11173 | have to go through updates again. */ | |
11174 | last_addr = old_loc->address; | |
11175 | ||
11176 | /* Target-side condition evaluation: Handle deleted locations. */ | |
11177 | if (!found_object) | |
11178 | force_breakpoint_reinsertion (old_loc); | |
11179 | ||
4a64f543 MS |
11180 | /* If this location is no longer present, and inserted, look if |
11181 | there's maybe a new location at the same address. If so, | |
11182 | mark that one inserted, and don't remove this one. This is | |
11183 | needed so that we don't have a time window where a breakpoint | |
11184 | at certain location is not inserted. */ | |
74960c60 | 11185 | |
876fa593 | 11186 | if (old_loc->inserted) |
0d381245 | 11187 | { |
4a64f543 MS |
11188 | /* If the location is inserted now, we might have to remove |
11189 | it. */ | |
74960c60 | 11190 | |
876fa593 | 11191 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 11192 | { |
4a64f543 MS |
11193 | /* The location is still present in the location list, |
11194 | and still should be inserted. Don't do anything. */ | |
20874c92 | 11195 | keep_in_target = 1; |
74960c60 VP |
11196 | } |
11197 | else | |
11198 | { | |
b775012e LM |
11199 | /* This location still exists, but it won't be kept in the |
11200 | target since it may have been disabled. We proceed to | |
11201 | remove its target-side condition. */ | |
11202 | ||
4a64f543 MS |
11203 | /* The location is either no longer present, or got |
11204 | disabled. See if there's another location at the | |
11205 | same address, in which case we don't need to remove | |
11206 | this one from the target. */ | |
876fa593 | 11207 | |
2bdf28a0 | 11208 | /* OLD_LOC comes from existing struct breakpoint. */ |
cb1e4e32 | 11209 | if (bl_address_is_meaningful (old_loc)) |
876fa593 | 11210 | { |
5d51cd5d SM |
11211 | for (size_t loc2_i = loc_i; |
11212 | (loc2_i < bp_locations.size () | |
11213 | && bp_locations[loc2_i]->address == old_loc->address); | |
11214 | loc2_i++) | |
876fa593 | 11215 | { |
5d51cd5d | 11216 | bp_location *loc2 = bp_locations[loc2_i]; |
876fa593 | 11217 | |
7f32a4d5 PA |
11218 | if (loc2 == old_loc) |
11219 | continue; | |
11220 | ||
2d134ed3 | 11221 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 11222 | { |
85d721b8 PA |
11223 | /* Read watchpoint locations are switched to |
11224 | access watchpoints, if the former are not | |
11225 | supported, but the latter are. */ | |
11226 | if (is_hardware_watchpoint (old_loc->owner)) | |
11227 | { | |
11228 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
11229 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
11230 | } | |
11231 | ||
934709f0 PW |
11232 | /* loc2 is a duplicated location. We need to check |
11233 | if it should be inserted in case it will be | |
11234 | unduplicated. */ | |
7f32a4d5 | 11235 | if (unduplicated_should_be_inserted (loc2)) |
c7d46a38 | 11236 | { |
934709f0 | 11237 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
11238 | keep_in_target = 1; |
11239 | break; | |
11240 | } | |
876fa593 JK |
11241 | } |
11242 | } | |
11243 | } | |
74960c60 VP |
11244 | } |
11245 | ||
20874c92 VP |
11246 | if (!keep_in_target) |
11247 | { | |
834c0d03 | 11248 | if (remove_breakpoint (old_loc)) |
20874c92 | 11249 | { |
4a64f543 MS |
11250 | /* This is just about all we can do. We could keep |
11251 | this location on the global list, and try to | |
11252 | remove it next time, but there's no particular | |
11253 | reason why we will succeed next time. | |
20874c92 | 11254 | |
4a64f543 MS |
11255 | Note that at this point, old_loc->owner is still |
11256 | valid, as delete_breakpoint frees the breakpoint | |
11257 | only after calling us. */ | |
6cb06a8c TT |
11258 | gdb_printf (_("warning: Error removing " |
11259 | "breakpoint %d\n"), | |
11260 | old_loc->owner->number); | |
20874c92 VP |
11261 | } |
11262 | removed = 1; | |
11263 | } | |
0d381245 | 11264 | } |
74960c60 VP |
11265 | |
11266 | if (!found_object) | |
1c5cfe86 | 11267 | { |
fbea99ea | 11268 | if (removed && target_is_non_stop_p () |
1cf4d951 | 11269 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 11270 | { |
db82e815 PA |
11271 | /* This location was removed from the target. In |
11272 | non-stop mode, a race condition is possible where | |
11273 | we've removed a breakpoint, but stop events for that | |
11274 | breakpoint are already queued and will arrive later. | |
11275 | We apply an heuristic to be able to distinguish such | |
11276 | SIGTRAPs from other random SIGTRAPs: we keep this | |
11277 | breakpoint location for a bit, and will retire it | |
11278 | after we see some number of events. The theory here | |
11279 | is that reporting of events should, "on the average", | |
11280 | be fair, so after a while we'll see events from all | |
11281 | threads that have anything of interest, and no longer | |
11282 | need to keep this breakpoint location around. We | |
11283 | don't hold locations forever so to reduce chances of | |
11284 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
11285 | SIGTRAP. | |
11286 | ||
11287 | The heuristic failing can be disastrous on | |
11288 | decr_pc_after_break targets. | |
11289 | ||
11290 | On decr_pc_after_break targets, like e.g., x86-linux, | |
11291 | if we fail to recognize a late breakpoint SIGTRAP, | |
11292 | because events_till_retirement has reached 0 too | |
11293 | soon, we'll fail to do the PC adjustment, and report | |
11294 | a random SIGTRAP to the user. When the user resumes | |
11295 | the inferior, it will most likely immediately crash | |
2dec564e | 11296 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
11297 | corrupted, because of being resumed e.g., in the |
11298 | middle of a multi-byte instruction, or skipped a | |
11299 | one-byte instruction. This was actually seen happen | |
11300 | on native x86-linux, and should be less rare on | |
11301 | targets that do not support new thread events, like | |
11302 | remote, due to the heuristic depending on | |
11303 | thread_count. | |
11304 | ||
11305 | Mistaking a random SIGTRAP for a breakpoint trap | |
11306 | causes similar symptoms (PC adjustment applied when | |
11307 | it shouldn't), but then again, playing with SIGTRAPs | |
11308 | behind the debugger's back is asking for trouble. | |
11309 | ||
11310 | Since hardware watchpoint traps are always | |
11311 | distinguishable from other traps, so we don't need to | |
11312 | apply keep hardware watchpoint moribund locations | |
11313 | around. We simply always ignore hardware watchpoint | |
11314 | traps we can no longer explain. */ | |
11315 | ||
5b6d1e4f PA |
11316 | process_stratum_target *proc_target = nullptr; |
11317 | for (inferior *inf : all_inferiors ()) | |
11318 | if (inf->pspace == old_loc->pspace) | |
11319 | { | |
11320 | proc_target = inf->process_target (); | |
11321 | break; | |
11322 | } | |
11323 | if (proc_target != nullptr) | |
11324 | old_loc->events_till_retirement | |
11325 | = 3 * (thread_count (proc_target) + 1); | |
11326 | else | |
11327 | old_loc->events_till_retirement = 1; | |
876fa593 | 11328 | old_loc->owner = NULL; |
20874c92 | 11329 | |
1123588c | 11330 | moribund_locations.push_back (old_loc); |
1c5cfe86 PA |
11331 | } |
11332 | else | |
f431efe5 PA |
11333 | { |
11334 | old_loc->owner = NULL; | |
11335 | decref_bp_location (&old_loc); | |
11336 | } | |
20874c92 | 11337 | } |
74960c60 | 11338 | } |
1c5cfe86 | 11339 | |
348d480f PA |
11340 | /* Rescan breakpoints at the same address and section, marking the |
11341 | first one as "first" and any others as "duplicates". This is so | |
11342 | that the bpt instruction is only inserted once. If we have a | |
11343 | permanent breakpoint at the same place as BPT, make that one the | |
11344 | official one, and the rest as duplicates. Permanent breakpoints | |
11345 | are sorted first for the same address. | |
11346 | ||
11347 | Do the same for hardware watchpoints, but also considering the | |
11348 | watchpoint's type (regular/access/read) and length. */ | |
11349 | ||
11350 | bp_loc_first = NULL; | |
11351 | wp_loc_first = NULL; | |
11352 | awp_loc_first = NULL; | |
11353 | rwp_loc_first = NULL; | |
40cb8ca5 | 11354 | |
48d7020b | 11355 | for (bp_location *loc : all_bp_locations ()) |
348d480f PA |
11356 | { |
11357 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
11358 | non-NULL. */ | |
348d480f | 11359 | struct bp_location **loc_first_p; |
43892fdf | 11360 | breakpoint *b = loc->owner; |
348d480f | 11361 | |
6f380991 | 11362 | if (!unduplicated_should_be_inserted (loc) |
cb1e4e32 | 11363 | || !bl_address_is_meaningful (loc) |
1e4d1764 YQ |
11364 | /* Don't detect duplicate for tracepoint locations because they are |
11365 | never duplicated. See the comments in field `duplicate' of | |
11366 | `struct bp_location'. */ | |
348d480f | 11367 | || is_tracepoint (b)) |
b775012e LM |
11368 | { |
11369 | /* Clear the condition modification flag. */ | |
11370 | loc->condition_changed = condition_unchanged; | |
11371 | continue; | |
11372 | } | |
348d480f | 11373 | |
348d480f PA |
11374 | if (b->type == bp_hardware_watchpoint) |
11375 | loc_first_p = &wp_loc_first; | |
11376 | else if (b->type == bp_read_watchpoint) | |
11377 | loc_first_p = &rwp_loc_first; | |
11378 | else if (b->type == bp_access_watchpoint) | |
11379 | loc_first_p = &awp_loc_first; | |
11380 | else | |
11381 | loc_first_p = &bp_loc_first; | |
11382 | ||
11383 | if (*loc_first_p == NULL | |
11384 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
11385 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
11386 | { | |
11387 | *loc_first_p = loc; | |
11388 | loc->duplicate = 0; | |
b775012e LM |
11389 | |
11390 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
11391 | { | |
11392 | loc->needs_update = 1; | |
11393 | /* Clear the condition modification flag. */ | |
11394 | loc->condition_changed = condition_unchanged; | |
11395 | } | |
348d480f PA |
11396 | continue; |
11397 | } | |
11398 | ||
934709f0 PW |
11399 | |
11400 | /* This and the above ensure the invariant that the first location | |
11401 | is not duplicated, and is the inserted one. | |
11402 | All following are marked as duplicated, and are not inserted. */ | |
11403 | if (loc->inserted) | |
11404 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
11405 | loc->duplicate = 1; |
11406 | ||
b775012e LM |
11407 | /* Clear the condition modification flag. */ |
11408 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
11409 | } |
11410 | ||
a25a5a45 | 11411 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 11412 | { |
04086b45 | 11413 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
11414 | insert_breakpoint_locations (); |
11415 | else | |
11416 | { | |
44702360 PA |
11417 | /* Even though the caller told us to not insert new |
11418 | locations, we may still need to update conditions on the | |
11419 | target's side of breakpoints that were already inserted | |
11420 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
11421 | only update conditions for locations that are marked |
11422 | "needs_update". */ | |
11423 | update_inserted_breakpoint_locations (); | |
11424 | } | |
11425 | } | |
348d480f | 11426 | |
04086b45 | 11427 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 | 11428 | download_tracepoint_locations (); |
348d480f PA |
11429 | } |
11430 | ||
11431 | void | |
11432 | breakpoint_retire_moribund (void) | |
11433 | { | |
1123588c TT |
11434 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
11435 | { | |
11436 | struct bp_location *loc = moribund_locations[ix]; | |
11437 | if (--(loc->events_till_retirement) == 0) | |
11438 | { | |
11439 | decref_bp_location (&loc); | |
11440 | unordered_remove (moribund_locations, ix); | |
11441 | --ix; | |
11442 | } | |
11443 | } | |
348d480f PA |
11444 | } |
11445 | ||
11446 | static void | |
44702360 | 11447 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 11448 | { |
348d480f | 11449 | |
a70b8144 | 11450 | try |
492d29ea PA |
11451 | { |
11452 | update_global_location_list (insert_mode); | |
11453 | } | |
230d2906 | 11454 | catch (const gdb_exception_error &e) |
492d29ea PA |
11455 | { |
11456 | } | |
348d480f PA |
11457 | } |
11458 | ||
11459 | /* Clear BKP from a BPS. */ | |
11460 | ||
11461 | static void | |
313f3b21 | 11462 | bpstat_remove_bp_location (bpstat *bps, struct breakpoint *bpt) |
348d480f | 11463 | { |
313f3b21 | 11464 | bpstat *bs; |
348d480f PA |
11465 | |
11466 | for (bs = bps; bs; bs = bs->next) | |
11467 | if (bs->breakpoint_at == bpt) | |
11468 | { | |
11469 | bs->breakpoint_at = NULL; | |
11470 | bs->old_val = NULL; | |
11471 | /* bs->commands will be freed later. */ | |
11472 | } | |
11473 | } | |
11474 | ||
11475 | /* Callback for iterate_over_threads. */ | |
11476 | static int | |
11477 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
11478 | { | |
9a3c8263 | 11479 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
11480 | |
11481 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
11482 | return 0; | |
11483 | } | |
11484 | ||
c47614fe | 11485 | /* Helper for breakpoint and tracepoint breakpoint->mention |
348d480f PA |
11486 | callbacks. */ |
11487 | ||
11488 | static void | |
11489 | say_where (struct breakpoint *b) | |
11490 | { | |
11491 | struct value_print_options opts; | |
11492 | ||
11493 | get_user_print_options (&opts); | |
11494 | ||
11495 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
11496 | single string. */ | |
11497 | if (b->loc == NULL) | |
11498 | { | |
f00aae0f KS |
11499 | /* For pending locations, the output differs slightly based |
11500 | on b->extra_string. If this is non-NULL, it contains either | |
11501 | a condition or dprintf arguments. */ | |
11502 | if (b->extra_string == NULL) | |
11503 | { | |
6cb06a8c TT |
11504 | gdb_printf (_(" (%s) pending."), |
11505 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
11506 | } |
11507 | else if (b->type == bp_dprintf) | |
11508 | { | |
6cb06a8c TT |
11509 | gdb_printf (_(" (%s,%s) pending."), |
11510 | event_location_to_string (b->location.get ()), | |
11511 | b->extra_string.get ()); | |
f00aae0f KS |
11512 | } |
11513 | else | |
11514 | { | |
6cb06a8c TT |
11515 | gdb_printf (_(" (%s %s) pending."), |
11516 | event_location_to_string (b->location.get ()), | |
11517 | b->extra_string.get ()); | |
f00aae0f | 11518 | } |
348d480f PA |
11519 | } |
11520 | else | |
11521 | { | |
2f202fde | 11522 | if (opts.addressprint || b->loc->symtab == NULL) |
6cb06a8c TT |
11523 | gdb_printf (" at %ps", |
11524 | styled_string (address_style.style (), | |
11525 | paddress (b->loc->gdbarch, | |
11526 | b->loc->address))); | |
2f202fde | 11527 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
11528 | { |
11529 | /* If there is a single location, we can print the location | |
11530 | more nicely. */ | |
11531 | if (b->loc->next == NULL) | |
0bb296cb | 11532 | { |
6a831f06 PA |
11533 | const char *filename |
11534 | = symtab_to_filename_for_display (b->loc->symtab); | |
6cb06a8c TT |
11535 | gdb_printf (": file %ps, line %d.", |
11536 | styled_string (file_name_style.style (), | |
11537 | filename), | |
11538 | b->loc->line_number); | |
0bb296cb | 11539 | } |
f8eba3c6 TT |
11540 | else |
11541 | /* This is not ideal, but each location may have a | |
11542 | different file name, and this at least reflects the | |
11543 | real situation somewhat. */ | |
6cb06a8c TT |
11544 | gdb_printf (": %s.", |
11545 | event_location_to_string (b->location.get ())); | |
f8eba3c6 | 11546 | } |
348d480f PA |
11547 | |
11548 | if (b->loc->next) | |
11549 | { | |
11550 | struct bp_location *loc = b->loc; | |
11551 | int n = 0; | |
11552 | for (; loc; loc = loc->next) | |
11553 | ++n; | |
6cb06a8c | 11554 | gdb_printf (" (%d locations)", n); |
348d480f PA |
11555 | } |
11556 | } | |
11557 | } | |
11558 | ||
40cb8ca5 SM |
11559 | /* See breakpoint.h. */ |
11560 | ||
9be25986 | 11561 | bp_location_range breakpoint::locations () |
40cb8ca5 | 11562 | { |
9be25986 | 11563 | return bp_location_range (this->loc); |
40cb8ca5 SM |
11564 | } |
11565 | ||
4c6a92b1 TT |
11566 | struct bp_location * |
11567 | breakpoint::allocate_location () | |
11568 | { | |
11569 | return new bp_location (this); | |
11570 | } | |
11571 | ||
2060206e PA |
11572 | #define internal_error_pure_virtual_called() \ |
11573 | gdb_assert_not_reached ("pure virtual function called") | |
11574 | ||
4c6a92b1 TT |
11575 | int |
11576 | breakpoint::insert_location (struct bp_location *bl) | |
11577 | { | |
11578 | internal_error_pure_virtual_called (); | |
11579 | } | |
11580 | ||
4c6a92b1 TT |
11581 | int |
11582 | breakpoint::remove_location (struct bp_location *bl, | |
11583 | enum remove_bp_reason reason) | |
11584 | { | |
11585 | internal_error_pure_virtual_called (); | |
11586 | } | |
11587 | ||
4c6a92b1 TT |
11588 | int |
11589 | breakpoint::breakpoint_hit (const struct bp_location *bl, | |
11590 | const address_space *aspace, | |
11591 | CORE_ADDR bp_addr, | |
11592 | const target_waitstatus &ws) | |
11593 | { | |
11594 | internal_error_pure_virtual_called (); | |
11595 | } | |
11596 | ||
4c6a92b1 TT |
11597 | int |
11598 | breakpoint::works_in_software_mode () const | |
11599 | { | |
11600 | internal_error_pure_virtual_called (); | |
11601 | } | |
11602 | ||
4c6a92b1 TT |
11603 | int |
11604 | breakpoint::resources_needed (const struct bp_location *bl) | |
11605 | { | |
11606 | internal_error_pure_virtual_called (); | |
11607 | } | |
11608 | ||
4c6a92b1 TT |
11609 | enum print_stop_action |
11610 | breakpoint::print_it (bpstat *bs) | |
11611 | { | |
11612 | internal_error_pure_virtual_called (); | |
11613 | } | |
11614 | ||
4c6a92b1 TT |
11615 | void |
11616 | breakpoint::print_mention () | |
11617 | { | |
11618 | internal_error_pure_virtual_called (); | |
11619 | } | |
11620 | ||
4c6a92b1 TT |
11621 | void |
11622 | breakpoint::print_recreate (struct ui_file *fp) | |
11623 | { | |
11624 | internal_error_pure_virtual_called (); | |
11625 | } | |
11626 | ||
4c6a92b1 TT |
11627 | std::vector<symtab_and_line> |
11628 | breakpoint::decode_location (struct event_location *location, | |
11629 | struct program_space *search_pspace) | |
11630 | { | |
11631 | internal_error_pure_virtual_called (); | |
11632 | } | |
11633 | ||
2060206e PA |
11634 | /* Default breakpoint_ops methods. */ |
11635 | ||
2b5ab5b8 TT |
11636 | void |
11637 | base_breakpoint::re_set () | |
348d480f | 11638 | { |
06edf0c0 | 11639 | /* FIXME: is this still reachable? */ |
2b5ab5b8 | 11640 | if (breakpoint_event_location_empty_p (this)) |
06edf0c0 | 11641 | { |
f00aae0f | 11642 | /* Anything without a location can't be re-set. */ |
2b5ab5b8 | 11643 | delete_breakpoint (this); |
06edf0c0 | 11644 | return; |
348d480f | 11645 | } |
06edf0c0 | 11646 | |
2b5ab5b8 | 11647 | breakpoint_re_set_default (this); |
348d480f PA |
11648 | } |
11649 | ||
2b5ab5b8 TT |
11650 | int |
11651 | base_breakpoint::insert_location (struct bp_location *bl) | |
348d480f | 11652 | { |
cd6c3b4f YQ |
11653 | CORE_ADDR addr = bl->target_info.reqstd_address; |
11654 | ||
579c6ad9 | 11655 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
11656 | bl->target_info.placed_address = addr; |
11657 | ||
5d926615 | 11658 | int result; |
348d480f | 11659 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
5d926615 | 11660 | result = target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 11661 | else |
5d926615 TT |
11662 | result = target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
11663 | ||
11664 | if (result == 0 && bl->probe.prob != nullptr) | |
11665 | { | |
11666 | /* The insertion was successful, now let's set the probe's semaphore | |
11667 | if needed. */ | |
11668 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); | |
11669 | } | |
11670 | ||
11671 | return result; | |
348d480f PA |
11672 | } |
11673 | ||
2b5ab5b8 TT |
11674 | int |
11675 | base_breakpoint::remove_location (struct bp_location *bl, | |
11676 | enum remove_bp_reason reason) | |
348d480f | 11677 | { |
5d926615 TT |
11678 | if (bl->probe.prob != nullptr) |
11679 | { | |
11680 | /* Let's clear the semaphore before removing the location. */ | |
11681 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); | |
11682 | } | |
11683 | ||
348d480f PA |
11684 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
11685 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
11686 | else | |
73971819 | 11687 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
11688 | } |
11689 | ||
2b5ab5b8 TT |
11690 | int |
11691 | base_breakpoint::breakpoint_hit (const struct bp_location *bl, | |
11692 | const address_space *aspace, | |
11693 | CORE_ADDR bp_addr, | |
11694 | const target_waitstatus &ws) | |
348d480f | 11695 | { |
c272a98c SM |
11696 | if (ws.kind () != TARGET_WAITKIND_STOPPED |
11697 | || ws.sig () != GDB_SIGNAL_TRAP) | |
09ac7c10 TT |
11698 | return 0; |
11699 | ||
348d480f PA |
11700 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
11701 | aspace, bp_addr)) | |
11702 | return 0; | |
11703 | ||
11704 | if (overlay_debugging /* unmapped overlay section */ | |
11705 | && section_is_overlay (bl->section) | |
11706 | && !section_is_mapped (bl->section)) | |
11707 | return 0; | |
11708 | ||
11709 | return 1; | |
11710 | } | |
11711 | ||
f293a0b5 TT |
11712 | int |
11713 | dprintf_breakpoint::breakpoint_hit (const struct bp_location *bl, | |
11714 | const address_space *aspace, | |
11715 | CORE_ADDR bp_addr, | |
11716 | const target_waitstatus &ws) | |
cd1608cc PA |
11717 | { |
11718 | if (dprintf_style == dprintf_style_agent | |
11719 | && target_can_run_breakpoint_commands ()) | |
11720 | { | |
11721 | /* An agent-style dprintf never causes a stop. If we see a trap | |
11722 | for this address it must be for a breakpoint that happens to | |
11723 | be set at the same address. */ | |
11724 | return 0; | |
11725 | } | |
11726 | ||
f293a0b5 | 11727 | return this->ordinary_breakpoint::breakpoint_hit (bl, aspace, bp_addr, ws); |
cd1608cc PA |
11728 | } |
11729 | ||
7dd8e7ae TT |
11730 | int |
11731 | ordinary_breakpoint::resources_needed (const struct bp_location *bl) | |
348d480f | 11732 | { |
7dd8e7ae | 11733 | gdb_assert (type == bp_hardware_breakpoint); |
348d480f PA |
11734 | |
11735 | return 1; | |
11736 | } | |
11737 | ||
7dd8e7ae TT |
11738 | enum print_stop_action |
11739 | ordinary_breakpoint::print_it (bpstat *bs) | |
348d480f | 11740 | { |
348d480f | 11741 | const struct bp_location *bl; |
001c8c33 | 11742 | int bp_temp; |
79a45e25 | 11743 | struct ui_out *uiout = current_uiout; |
348d480f | 11744 | |
b6433ede | 11745 | bl = bs->bp_location_at.get (); |
348d480f | 11746 | |
7dd8e7ae | 11747 | bp_temp = disposition == disp_del; |
001c8c33 PA |
11748 | if (bl->address != bl->requested_address) |
11749 | breakpoint_adjustment_warning (bl->requested_address, | |
11750 | bl->address, | |
7dd8e7ae TT |
11751 | number, 1); |
11752 | annotate_breakpoint (number); | |
f303dbd6 PA |
11753 | maybe_print_thread_hit_breakpoint (uiout); |
11754 | ||
112e8700 | 11755 | if (uiout->is_mi_like_p ()) |
348d480f | 11756 | { |
112e8700 | 11757 | uiout->field_string ("reason", |
001c8c33 | 11758 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
7dd8e7ae | 11759 | uiout->field_string ("disp", bpdisp_text (disposition)); |
06edf0c0 | 11760 | } |
6a831f06 PA |
11761 | if (bp_temp) |
11762 | uiout->message ("Temporary breakpoint %pF, ", | |
7dd8e7ae | 11763 | signed_field ("bkptno", number)); |
6a831f06 PA |
11764 | else |
11765 | uiout->message ("Breakpoint %pF, ", | |
7dd8e7ae | 11766 | signed_field ("bkptno", number)); |
06edf0c0 | 11767 | |
001c8c33 | 11768 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
11769 | } |
11770 | ||
7dd8e7ae TT |
11771 | void |
11772 | ordinary_breakpoint::print_mention () | |
06edf0c0 | 11773 | { |
112e8700 | 11774 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
11775 | return; |
11776 | ||
7dd8e7ae | 11777 | switch (type) |
06edf0c0 PA |
11778 | { |
11779 | case bp_breakpoint: | |
11780 | case bp_gnu_ifunc_resolver: | |
7dd8e7ae | 11781 | if (disposition == disp_del) |
6cb06a8c | 11782 | gdb_printf (_("Temporary breakpoint")); |
06edf0c0 | 11783 | else |
6cb06a8c | 11784 | gdb_printf (_("Breakpoint")); |
7dd8e7ae TT |
11785 | gdb_printf (_(" %d"), number); |
11786 | if (type == bp_gnu_ifunc_resolver) | |
6cb06a8c | 11787 | gdb_printf (_(" at gnu-indirect-function resolver")); |
06edf0c0 PA |
11788 | break; |
11789 | case bp_hardware_breakpoint: | |
7dd8e7ae | 11790 | gdb_printf (_("Hardware assisted breakpoint %d"), number); |
06edf0c0 | 11791 | break; |
e7e0cddf | 11792 | case bp_dprintf: |
7dd8e7ae | 11793 | gdb_printf (_("Dprintf %d"), number); |
e7e0cddf | 11794 | break; |
06edf0c0 PA |
11795 | } |
11796 | ||
7dd8e7ae | 11797 | say_where (this); |
06edf0c0 PA |
11798 | } |
11799 | ||
7dd8e7ae TT |
11800 | void |
11801 | ordinary_breakpoint::print_recreate (struct ui_file *fp) | |
06edf0c0 | 11802 | { |
7dd8e7ae | 11803 | if (type == bp_breakpoint && disposition == disp_del) |
6cb06a8c | 11804 | gdb_printf (fp, "tbreak"); |
7dd8e7ae | 11805 | else if (type == bp_breakpoint) |
6cb06a8c | 11806 | gdb_printf (fp, "break"); |
7dd8e7ae TT |
11807 | else if (type == bp_hardware_breakpoint |
11808 | && disposition == disp_del) | |
6cb06a8c | 11809 | gdb_printf (fp, "thbreak"); |
7dd8e7ae | 11810 | else if (type == bp_hardware_breakpoint) |
6cb06a8c | 11811 | gdb_printf (fp, "hbreak"); |
06edf0c0 PA |
11812 | else |
11813 | internal_error (__FILE__, __LINE__, | |
7dd8e7ae | 11814 | _("unhandled breakpoint type %d"), (int) type); |
06edf0c0 | 11815 | |
7dd8e7ae | 11816 | gdb_printf (fp, " %s", event_location_to_string (location.get ())); |
f00aae0f KS |
11817 | |
11818 | /* Print out extra_string if this breakpoint is pending. It might | |
11819 | contain, for example, conditions that were set by the user. */ | |
7dd8e7ae TT |
11820 | if (loc == NULL && extra_string != NULL) |
11821 | gdb_printf (fp, " %s", extra_string.get ()); | |
f00aae0f | 11822 | |
7dd8e7ae | 11823 | print_recreate_thread (this, fp); |
06edf0c0 PA |
11824 | } |
11825 | ||
2b5ab5b8 TT |
11826 | std::vector<symtab_and_line> |
11827 | base_breakpoint::decode_location (struct event_location *location, | |
11828 | struct program_space *search_pspace) | |
983af33b | 11829 | { |
5d926615 TT |
11830 | if (event_location_type (location) == PROBE_LOCATION) |
11831 | return bkpt_probe_decode_location (this, location, search_pspace); | |
11832 | ||
2b5ab5b8 | 11833 | return decode_location_default (this, location, search_pspace); |
983af33b SDJ |
11834 | } |
11835 | ||
06edf0c0 PA |
11836 | /* Virtual table for internal breakpoints. */ |
11837 | ||
c359fff5 TT |
11838 | void |
11839 | internal_breakpoint::re_set () | |
06edf0c0 | 11840 | { |
c359fff5 | 11841 | switch (type) |
06edf0c0 PA |
11842 | { |
11843 | /* Delete overlay event and longjmp master breakpoints; they | |
11844 | will be reset later by breakpoint_re_set. */ | |
11845 | case bp_overlay_event: | |
11846 | case bp_longjmp_master: | |
11847 | case bp_std_terminate_master: | |
11848 | case bp_exception_master: | |
c359fff5 | 11849 | delete_breakpoint (this); |
06edf0c0 PA |
11850 | break; |
11851 | ||
11852 | /* This breakpoint is special, it's set up when the inferior | |
dda83cd7 | 11853 | starts and we really don't want to touch it. */ |
06edf0c0 PA |
11854 | case bp_shlib_event: |
11855 | ||
11856 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
11857 | it is set up, we do not want to touch it. */ | |
11858 | case bp_thread_event: | |
11859 | break; | |
11860 | } | |
11861 | } | |
11862 | ||
c359fff5 TT |
11863 | void |
11864 | internal_breakpoint::check_status (bpstat *bs) | |
06edf0c0 | 11865 | { |
c359fff5 | 11866 | if (type == bp_shlib_event) |
a9b3a50f PA |
11867 | { |
11868 | /* If requested, stop when the dynamic linker notifies GDB of | |
11869 | events. This allows the user to get control and place | |
11870 | breakpoints in initializer routines for dynamically loaded | |
11871 | objects (among other things). */ | |
11872 | bs->stop = stop_on_solib_events; | |
11873 | bs->print = stop_on_solib_events; | |
11874 | } | |
11875 | else | |
11876 | bs->stop = 0; | |
06edf0c0 PA |
11877 | } |
11878 | ||
c359fff5 TT |
11879 | enum print_stop_action |
11880 | internal_breakpoint::print_it (bpstat *bs) | |
06edf0c0 | 11881 | { |
c359fff5 | 11882 | switch (type) |
06edf0c0 | 11883 | { |
348d480f PA |
11884 | case bp_shlib_event: |
11885 | /* Did we stop because the user set the stop_on_solib_events | |
11886 | variable? (If so, we report this as a generic, "Stopped due | |
11887 | to shlib event" message.) */ | |
4e9e993a | 11888 | print_solib_event (false); |
348d480f PA |
11889 | break; |
11890 | ||
11891 | case bp_thread_event: | |
11892 | /* Not sure how we will get here. | |
11893 | GDB should not stop for these breakpoints. */ | |
6cb06a8c | 11894 | gdb_printf (_("Thread Event Breakpoint: gdb should not stop!\n")); |
348d480f PA |
11895 | break; |
11896 | ||
11897 | case bp_overlay_event: | |
11898 | /* By analogy with the thread event, GDB should not stop for these. */ | |
6cb06a8c | 11899 | gdb_printf (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
348d480f PA |
11900 | break; |
11901 | ||
11902 | case bp_longjmp_master: | |
11903 | /* These should never be enabled. */ | |
6cb06a8c | 11904 | gdb_printf (_("Longjmp Master Breakpoint: gdb should not stop!\n")); |
348d480f PA |
11905 | break; |
11906 | ||
11907 | case bp_std_terminate_master: | |
11908 | /* These should never be enabled. */ | |
6cb06a8c TT |
11909 | gdb_printf (_("std::terminate Master Breakpoint: " |
11910 | "gdb should not stop!\n")); | |
348d480f PA |
11911 | break; |
11912 | ||
11913 | case bp_exception_master: | |
11914 | /* These should never be enabled. */ | |
6cb06a8c TT |
11915 | gdb_printf (_("Exception Master Breakpoint: " |
11916 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11917 | break; |
11918 | } | |
11919 | ||
001c8c33 | 11920 | return PRINT_NOTHING; |
06edf0c0 PA |
11921 | } |
11922 | ||
c359fff5 TT |
11923 | void |
11924 | internal_breakpoint::print_mention () | |
06edf0c0 PA |
11925 | { |
11926 | /* Nothing to mention. These breakpoints are internal. */ | |
11927 | } | |
11928 | ||
06edf0c0 PA |
11929 | /* Virtual table for momentary breakpoints */ |
11930 | ||
1fd30a47 TT |
11931 | void |
11932 | momentary_breakpoint::re_set () | |
06edf0c0 PA |
11933 | { |
11934 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 11935 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
11936 | Otherwise these should have been blown away via the cleanup chain |
11937 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11938 | } | |
11939 | ||
1fd30a47 TT |
11940 | void |
11941 | momentary_breakpoint::check_status (bpstat *bs) | |
06edf0c0 PA |
11942 | { |
11943 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11944 | } | |
11945 | ||
1fd30a47 TT |
11946 | enum print_stop_action |
11947 | momentary_breakpoint::print_it (bpstat *bs) | |
06edf0c0 | 11948 | { |
001c8c33 | 11949 | return PRINT_UNKNOWN; |
348d480f PA |
11950 | } |
11951 | ||
1fd30a47 TT |
11952 | void |
11953 | momentary_breakpoint::print_mention () | |
348d480f | 11954 | { |
06edf0c0 | 11955 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11956 | } |
11957 | ||
e2e4d78b JK |
11958 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
11959 | ||
11960 | It gets cleared already on the removal of the first one of such placed | |
11961 | breakpoints. This is OK as they get all removed altogether. */ | |
11962 | ||
c1fc2657 | 11963 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 11964 | { |
c1fc2657 | 11965 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 11966 | |
c1fc2657 | 11967 | if (tp != NULL) |
e2e4d78b | 11968 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
11969 | } |
11970 | ||
55aa24fb | 11971 | static void |
626d2320 | 11972 | bkpt_probe_create_sals_from_location (struct event_location *location, |
5f700d83 | 11973 | struct linespec_result *canonical, |
f00aae0f | 11974 | enum bptype type_wanted) |
55aa24fb SDJ |
11975 | { |
11976 | struct linespec_sals lsal; | |
11977 | ||
c2f4122d | 11978 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
11979 | lsal.canonical |
11980 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 11981 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
11982 | } |
11983 | ||
6c5b2ebe | 11984 | static std::vector<symtab_and_line> |
f00aae0f | 11985 | bkpt_probe_decode_location (struct breakpoint *b, |
626d2320 | 11986 | struct event_location *location, |
6c5b2ebe | 11987 | struct program_space *search_pspace) |
55aa24fb | 11988 | { |
6c5b2ebe PA |
11989 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
11990 | if (sals.empty ()) | |
55aa24fb | 11991 | error (_("probe not found")); |
6c5b2ebe | 11992 | return sals; |
55aa24fb SDJ |
11993 | } |
11994 | ||
348d480f | 11995 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11996 | |
779dcceb TT |
11997 | void |
11998 | tracepoint::re_set () | |
348d480f | 11999 | { |
779dcceb | 12000 | breakpoint_re_set_default (this); |
348d480f | 12001 | } |
876fa593 | 12002 | |
779dcceb TT |
12003 | int |
12004 | tracepoint::breakpoint_hit (const struct bp_location *bl, | |
12005 | const address_space *aspace, CORE_ADDR bp_addr, | |
12006 | const target_waitstatus &ws) | |
348d480f PA |
12007 | { |
12008 | /* By definition, the inferior does not report stops at | |
12009 | tracepoints. */ | |
12010 | return 0; | |
74960c60 VP |
12011 | } |
12012 | ||
779dcceb TT |
12013 | void |
12014 | tracepoint::print_one_detail (struct ui_out *uiout) const | |
74960c60 | 12015 | { |
779dcceb | 12016 | if (!static_trace_marker_id.empty ()) |
348d480f | 12017 | { |
7b572efb TT |
12018 | gdb_assert (type == bp_static_tracepoint |
12019 | || type == bp_static_marker_tracepoint); | |
cc59ec59 | 12020 | |
6a831f06 PA |
12021 | uiout->message ("\tmarker id is %pF\n", |
12022 | string_field ("static-tracepoint-marker-string-id", | |
779dcceb | 12023 | static_trace_marker_id.c_str ())); |
348d480f | 12024 | } |
0d381245 VP |
12025 | } |
12026 | ||
779dcceb TT |
12027 | void |
12028 | tracepoint::print_mention () | |
a474d7c2 | 12029 | { |
112e8700 | 12030 | if (current_uiout->is_mi_like_p ()) |
348d480f | 12031 | return; |
cc59ec59 | 12032 | |
779dcceb | 12033 | switch (type) |
348d480f PA |
12034 | { |
12035 | case bp_tracepoint: | |
6cb06a8c | 12036 | gdb_printf (_("Tracepoint")); |
779dcceb | 12037 | gdb_printf (_(" %d"), number); |
348d480f PA |
12038 | break; |
12039 | case bp_fast_tracepoint: | |
6cb06a8c | 12040 | gdb_printf (_("Fast tracepoint")); |
779dcceb | 12041 | gdb_printf (_(" %d"), number); |
348d480f PA |
12042 | break; |
12043 | case bp_static_tracepoint: | |
7b572efb | 12044 | case bp_static_marker_tracepoint: |
6cb06a8c | 12045 | gdb_printf (_("Static tracepoint")); |
779dcceb | 12046 | gdb_printf (_(" %d"), number); |
348d480f PA |
12047 | break; |
12048 | default: | |
12049 | internal_error (__FILE__, __LINE__, | |
779dcceb | 12050 | _("unhandled tracepoint type %d"), (int) type); |
348d480f PA |
12051 | } |
12052 | ||
779dcceb | 12053 | say_where (this); |
a474d7c2 PA |
12054 | } |
12055 | ||
779dcceb TT |
12056 | void |
12057 | tracepoint::print_recreate (struct ui_file *fp) | |
a474d7c2 | 12058 | { |
779dcceb | 12059 | if (type == bp_fast_tracepoint) |
6cb06a8c | 12060 | gdb_printf (fp, "ftrace"); |
7b572efb TT |
12061 | else if (type == bp_static_tracepoint |
12062 | || type == bp_static_marker_tracepoint) | |
6cb06a8c | 12063 | gdb_printf (fp, "strace"); |
779dcceb | 12064 | else if (type == bp_tracepoint) |
6cb06a8c | 12065 | gdb_printf (fp, "trace"); |
348d480f PA |
12066 | else |
12067 | internal_error (__FILE__, __LINE__, | |
779dcceb | 12068 | _("unhandled tracepoint type %d"), (int) type); |
cc59ec59 | 12069 | |
779dcceb TT |
12070 | gdb_printf (fp, " %s", event_location_to_string (location.get ())); |
12071 | print_recreate_thread (this, fp); | |
d9b3f62e | 12072 | |
779dcceb TT |
12073 | if (pass_count) |
12074 | gdb_printf (fp, " passcount %d\n", pass_count); | |
a474d7c2 PA |
12075 | } |
12076 | ||
779dcceb TT |
12077 | std::vector<symtab_and_line> |
12078 | tracepoint::decode_location (struct event_location *location, | |
12079 | struct program_space *search_pspace) | |
983af33b | 12080 | { |
8d89123d TT |
12081 | if (event_location_type (location) == PROBE_LOCATION) |
12082 | return bkpt_probe_decode_location (this, location, search_pspace); | |
12083 | ||
779dcceb | 12084 | return decode_location_default (this, location, search_pspace); |
983af33b SDJ |
12085 | } |
12086 | ||
bac7c5cf | 12087 | /* Virtual table for tracepoints on static probes. */ |
55aa24fb SDJ |
12088 | |
12089 | static void | |
f00aae0f | 12090 | tracepoint_probe_create_sals_from_location |
626d2320 | 12091 | (struct event_location *location, |
f00aae0f KS |
12092 | struct linespec_result *canonical, |
12093 | enum bptype type_wanted) | |
55aa24fb SDJ |
12094 | { |
12095 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 12096 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
12097 | } |
12098 | ||
f293a0b5 TT |
12099 | void |
12100 | dprintf_breakpoint::re_set () | |
5c2b4418 | 12101 | { |
f293a0b5 | 12102 | breakpoint_re_set_default (this); |
5c2b4418 | 12103 | |
f00aae0f | 12104 | /* extra_string should never be non-NULL for dprintf. */ |
f293a0b5 | 12105 | gdb_assert (extra_string != NULL); |
5c2b4418 HZ |
12106 | |
12107 | /* 1 - connect to target 1, that can run breakpoint commands. | |
12108 | 2 - create a dprintf, which resolves fine. | |
12109 | 3 - disconnect from target 1 | |
12110 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
12111 | ||
12112 | After steps #3/#4, you'll want the dprintf command list to | |
12113 | be updated, because target 1 and 2 may well return different | |
12114 | answers for target_can_run_breakpoint_commands(). | |
12115 | Given absence of finer grained resetting, we get to do | |
12116 | it all the time. */ | |
f293a0b5 TT |
12117 | if (extra_string != NULL) |
12118 | update_dprintf_command_list (this); | |
5c2b4418 HZ |
12119 | } |
12120 | ||
f293a0b5 | 12121 | /* Implement the "print_recreate" method for dprintf. */ |
2d9442cc | 12122 | |
f293a0b5 TT |
12123 | void |
12124 | dprintf_breakpoint::print_recreate (struct ui_file *fp) | |
2d9442cc | 12125 | { |
6cb06a8c | 12126 | gdb_printf (fp, "dprintf %s,%s", |
f293a0b5 TT |
12127 | event_location_to_string (location.get ()), |
12128 | extra_string.get ()); | |
12129 | print_recreate_thread (this, fp); | |
2d9442cc HZ |
12130 | } |
12131 | ||
f293a0b5 | 12132 | /* Implement the "after_condition_true" method for dprintf. |
9d6e6e84 HZ |
12133 | |
12134 | dprintf's are implemented with regular commands in their command | |
12135 | list, but we run the commands here instead of before presenting the | |
12136 | stop to the user, as dprintf's don't actually cause a stop. This | |
12137 | also makes it so that the commands of multiple dprintfs at the same | |
12138 | address are all handled. */ | |
12139 | ||
f293a0b5 TT |
12140 | void |
12141 | dprintf_breakpoint::after_condition_true (struct bpstat *bs) | |
9d6e6e84 | 12142 | { |
9d6e6e84 HZ |
12143 | /* dprintf's never cause a stop. This wasn't set in the |
12144 | check_status hook instead because that would make the dprintf's | |
12145 | condition not be evaluated. */ | |
12146 | bs->stop = 0; | |
12147 | ||
12148 | /* Run the command list here. Take ownership of it instead of | |
12149 | copying. We never want these commands to run later in | |
12150 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
12151 | be set at same address as this dprintf, or even if running the | |
12152 | commands here throws. */ | |
9c95aea1 KB |
12153 | counted_command_line cmds = std::move (bs->commands); |
12154 | gdb_assert (cmds != nullptr); | |
12155 | execute_control_commands (cmds.get (), 0); | |
9d6e6e84 HZ |
12156 | } |
12157 | ||
983af33b SDJ |
12158 | /* The breakpoint_ops structure to be used on static tracepoints with |
12159 | markers (`-m'). */ | |
12160 | ||
12161 | static void | |
626d2320 | 12162 | strace_marker_create_sals_from_location (struct event_location *location, |
5f700d83 | 12163 | struct linespec_result *canonical, |
f00aae0f | 12164 | enum bptype type_wanted) |
983af33b SDJ |
12165 | { |
12166 | struct linespec_sals lsal; | |
f00aae0f | 12167 | const char *arg_start, *arg; |
983af33b | 12168 | |
a20714ff | 12169 | arg = arg_start = get_linespec_location (location)->spec_string; |
f00aae0f | 12170 | lsal.sals = decode_static_tracepoint_spec (&arg); |
983af33b | 12171 | |
f2fc3015 TT |
12172 | std::string str (arg_start, arg - arg_start); |
12173 | const char *ptr = str.c_str (); | |
a20714ff PA |
12174 | canonical->location |
12175 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); | |
983af33b | 12176 | |
8e9e35b1 TT |
12177 | lsal.canonical |
12178 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 12179 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
12180 | } |
12181 | ||
12182 | static void | |
12183 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12184 | struct linespec_result *canonical, | |
e1e01040 PA |
12185 | gdb::unique_xmalloc_ptr<char> cond_string, |
12186 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12187 | enum bptype type_wanted, |
12188 | enum bpdisp disposition, | |
12189 | int thread, | |
12190 | int task, int ignore_count, | |
12191 | const struct breakpoint_ops *ops, | |
12192 | int from_tty, int enabled, | |
44f238bb | 12193 | int internal, unsigned flags) |
983af33b | 12194 | { |
6c5b2ebe | 12195 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
12196 | |
12197 | /* If the user is creating a static tracepoint by marker id | |
12198 | (strace -m MARKER_ID), then store the sals index, so that | |
12199 | breakpoint_re_set can try to match up which of the newly | |
12200 | found markers corresponds to this one, and, don't try to | |
12201 | expand multiple locations for each sal, given than SALS | |
12202 | already should contain all sals for MARKER_ID. */ | |
12203 | ||
6c5b2ebe | 12204 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 12205 | { |
6c5b2ebe PA |
12206 | event_location_up location |
12207 | = copy_event_location (canonical->location.get ()); | |
983af33b | 12208 | |
b270e6f9 | 12209 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 12210 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 12211 | std::move (location), NULL, |
e1e01040 PA |
12212 | std::move (cond_string), |
12213 | std::move (extra_string), | |
e7e0cddf | 12214 | type_wanted, disposition, |
983af33b | 12215 | thread, task, ignore_count, ops, |
44f238bb | 12216 | from_tty, enabled, internal, flags, |
983af33b SDJ |
12217 | canonical->special_display); |
12218 | /* Given that its possible to have multiple markers with | |
12219 | the same string id, if the user is creating a static | |
12220 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
12221 | store the sals index, so that breakpoint_re_set can | |
12222 | try to match up which of the newly found markers | |
12223 | corresponds to this one */ | |
12224 | tp->static_trace_marker_id_idx = i; | |
12225 | ||
b270e6f9 | 12226 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
12227 | } |
12228 | } | |
12229 | ||
6d7a8c56 TT |
12230 | std::vector<symtab_and_line> |
12231 | static_marker_tracepoint::decode_location (struct event_location *location, | |
12232 | struct program_space *search_pspace) | |
983af33b | 12233 | { |
a20714ff | 12234 | const char *s = get_linespec_location (location)->spec_string; |
983af33b | 12235 | |
6c5b2ebe | 12236 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
6d7a8c56 | 12237 | if (sals.size () > static_trace_marker_id_idx) |
983af33b | 12238 | { |
6d7a8c56 | 12239 | sals[0] = sals[static_trace_marker_id_idx]; |
6c5b2ebe PA |
12240 | sals.resize (1); |
12241 | return sals; | |
983af33b SDJ |
12242 | } |
12243 | else | |
6d7a8c56 | 12244 | error (_("marker %s not found"), static_trace_marker_id.c_str ()); |
983af33b SDJ |
12245 | } |
12246 | ||
8613a476 TT |
12247 | /* Static tracepoints with marker (`-m'). */ |
12248 | static struct breakpoint_ops strace_marker_breakpoint_ops = | |
12249 | { | |
12250 | strace_marker_create_sals_from_location, | |
12251 | strace_marker_create_breakpoints_sal, | |
12252 | }; | |
983af33b SDJ |
12253 | |
12254 | static int | |
12255 | strace_marker_p (struct breakpoint *b) | |
12256 | { | |
7b572efb | 12257 | return b->type == bp_static_marker_tracepoint; |
983af33b SDJ |
12258 | } |
12259 | ||
53a5351d | 12260 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 12261 | structures. */ |
c906108c SS |
12262 | |
12263 | void | |
fba45db2 | 12264 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 12265 | { |
8a3fe4f8 | 12266 | gdb_assert (bpt != NULL); |
c906108c | 12267 | |
4a64f543 MS |
12268 | /* Has this bp already been deleted? This can happen because |
12269 | multiple lists can hold pointers to bp's. bpstat lists are | |
12270 | especial culprits. | |
12271 | ||
12272 | One example of this happening is a watchpoint's scope bp. When | |
12273 | the scope bp triggers, we notice that the watchpoint is out of | |
12274 | scope, and delete it. We also delete its scope bp. But the | |
12275 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
12276 | That bpstat is then checked for auto-deleting bp's, which are | |
12277 | deleted. | |
12278 | ||
12279 | A real solution to this problem might involve reference counts in | |
12280 | bp's, and/or giving them pointers back to their referencing | |
12281 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
12282 | storage when no more references were extent. A cheaper bandaid | |
12283 | was chosen. */ | |
c906108c SS |
12284 | if (bpt->type == bp_none) |
12285 | return; | |
12286 | ||
4a64f543 MS |
12287 | /* At least avoid this stale reference until the reference counting |
12288 | of breakpoints gets resolved. */ | |
d0fb5eae | 12289 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 12290 | { |
d0fb5eae | 12291 | struct breakpoint *related; |
3a5c3e22 | 12292 | struct watchpoint *w; |
d0fb5eae JK |
12293 | |
12294 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 12295 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 12296 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
12297 | w = (struct watchpoint *) bpt; |
12298 | else | |
12299 | w = NULL; | |
12300 | if (w != NULL) | |
12301 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
12302 | |
12303 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
12304 | for (related = bpt; related->related_breakpoint != bpt; | |
12305 | related = related->related_breakpoint); | |
12306 | related->related_breakpoint = bpt->related_breakpoint; | |
12307 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
12308 | } |
12309 | ||
a9634178 TJB |
12310 | /* watch_command_1 creates a watchpoint but only sets its number if |
12311 | update_watchpoint succeeds in creating its bp_locations. If there's | |
12312 | a problem in that process, we'll be asked to delete the half-created | |
12313 | watchpoint. In that case, don't announce the deletion. */ | |
12314 | if (bpt->number) | |
76727919 | 12315 | gdb::observers::breakpoint_deleted.notify (bpt); |
c906108c | 12316 | |
c906108c SS |
12317 | if (breakpoint_chain == bpt) |
12318 | breakpoint_chain = bpt->next; | |
12319 | ||
43892fdf | 12320 | for (breakpoint *b : all_breakpoints ()) |
c906108c | 12321 | if (b->next == bpt) |
01add95b SM |
12322 | { |
12323 | b->next = bpt->next; | |
12324 | break; | |
12325 | } | |
c906108c | 12326 | |
f431efe5 PA |
12327 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
12328 | been freed. */ | |
12329 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 12330 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
12331 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
12332 | commands are associated with the bpstat; if we remove it here, | |
12333 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
12334 | event-top.c won't do anything, and temporary breakpoints with | |
12335 | commands won't work. */ | |
12336 | ||
12337 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
12338 | ||
4a64f543 MS |
12339 | /* Now that breakpoint is removed from breakpoint list, update the |
12340 | global location list. This will remove locations that used to | |
12341 | belong to this breakpoint. Do this before freeing the breakpoint | |
12342 | itself, since remove_breakpoint looks at location's owner. It | |
12343 | might be better design to have location completely | |
12344 | self-contained, but it's not the case now. */ | |
44702360 | 12345 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 12346 | |
4a64f543 MS |
12347 | /* On the chance that someone will soon try again to delete this |
12348 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 12349 | bpt->type = bp_none; |
4d01a485 | 12350 | delete bpt; |
c906108c SS |
12351 | } |
12352 | ||
51be5b68 PA |
12353 | /* Iterator function to call a user-provided callback function once |
12354 | for each of B and its related breakpoints. */ | |
12355 | ||
12356 | static void | |
12357 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 12358 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
12359 | { |
12360 | struct breakpoint *related; | |
12361 | ||
12362 | related = b; | |
12363 | do | |
12364 | { | |
12365 | struct breakpoint *next; | |
12366 | ||
12367 | /* FUNCTION may delete RELATED. */ | |
12368 | next = related->related_breakpoint; | |
12369 | ||
12370 | if (next == related) | |
12371 | { | |
12372 | /* RELATED is the last ring entry. */ | |
48649e1b | 12373 | function (related); |
51be5b68 PA |
12374 | |
12375 | /* FUNCTION may have deleted it, so we'd never reach back to | |
12376 | B. There's nothing left to do anyway, so just break | |
12377 | out. */ | |
12378 | break; | |
12379 | } | |
12380 | else | |
48649e1b | 12381 | function (related); |
51be5b68 PA |
12382 | |
12383 | related = next; | |
12384 | } | |
12385 | while (related != b); | |
12386 | } | |
95a42b64 | 12387 | |
4495129a | 12388 | static void |
981a3fb3 | 12389 | delete_command (const char *arg, int from_tty) |
c906108c | 12390 | { |
ea9365bb TT |
12391 | dont_repeat (); |
12392 | ||
c906108c SS |
12393 | if (arg == 0) |
12394 | { | |
12395 | int breaks_to_delete = 0; | |
12396 | ||
46c6471b | 12397 | /* Delete all breakpoints if no argument. Do not delete |
dda83cd7 SM |
12398 | internal breakpoints, these have to be deleted with an |
12399 | explicit breakpoint number argument. */ | |
43892fdf | 12400 | for (breakpoint *b : all_breakpoints ()) |
46c6471b | 12401 | if (user_breakpoint_p (b)) |
973d738b DJ |
12402 | { |
12403 | breaks_to_delete = 1; | |
12404 | break; | |
12405 | } | |
c906108c SS |
12406 | |
12407 | /* Ask user only if there are some breakpoints to delete. */ | |
12408 | if (!from_tty | |
e2e0b3e5 | 12409 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
1428b37a SM |
12410 | for (breakpoint *b : all_breakpoints_safe ()) |
12411 | if (user_breakpoint_p (b)) | |
12412 | delete_breakpoint (b); | |
c906108c SS |
12413 | } |
12414 | else | |
48649e1b | 12415 | map_breakpoint_numbers |
b926417a | 12416 | (arg, [&] (breakpoint *br) |
48649e1b | 12417 | { |
b926417a | 12418 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 12419 | }); |
c906108c SS |
12420 | } |
12421 | ||
c2f4122d PA |
12422 | /* Return true if all locations of B bound to PSPACE are pending. If |
12423 | PSPACE is NULL, all locations of all program spaces are | |
12424 | considered. */ | |
12425 | ||
0d381245 | 12426 | static int |
c2f4122d | 12427 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 12428 | { |
40cb8ca5 | 12429 | for (bp_location *loc : b->locations ()) |
c2f4122d PA |
12430 | if ((pspace == NULL |
12431 | || loc->pspace == pspace) | |
12432 | && !loc->shlib_disabled | |
8645ff69 | 12433 | && !loc->pspace->executing_startup) |
0d381245 VP |
12434 | return 0; |
12435 | return 1; | |
fe3f5fa8 VP |
12436 | } |
12437 | ||
776592bf DE |
12438 | /* Subroutine of update_breakpoint_locations to simplify it. |
12439 | Return non-zero if multiple fns in list LOC have the same name. | |
12440 | Null names are ignored. */ | |
12441 | ||
12442 | static int | |
12443 | ambiguous_names_p (struct bp_location *loc) | |
12444 | { | |
12445 | struct bp_location *l; | |
2698f5ea | 12446 | htab_up htab (htab_create_alloc (13, htab_hash_string, htab_eq_string, NULL, |
c1fb9836 | 12447 | xcalloc, xfree)); |
776592bf DE |
12448 | |
12449 | for (l = loc; l != NULL; l = l->next) | |
12450 | { | |
12451 | const char **slot; | |
23d6ee64 | 12452 | const char *name = l->function_name.get (); |
776592bf DE |
12453 | |
12454 | /* Allow for some names to be NULL, ignore them. */ | |
12455 | if (name == NULL) | |
12456 | continue; | |
12457 | ||
c1fb9836 | 12458 | slot = (const char **) htab_find_slot (htab.get (), (const void *) name, |
776592bf | 12459 | INSERT); |
4a64f543 MS |
12460 | /* NOTE: We can assume slot != NULL here because xcalloc never |
12461 | returns NULL. */ | |
776592bf | 12462 | if (*slot != NULL) |
c1fb9836 | 12463 | return 1; |
776592bf DE |
12464 | *slot = name; |
12465 | } | |
12466 | ||
776592bf DE |
12467 | return 0; |
12468 | } | |
12469 | ||
0fb4aa4b PA |
12470 | /* When symbols change, it probably means the sources changed as well, |
12471 | and it might mean the static tracepoint markers are no longer at | |
12472 | the same address or line numbers they used to be at last we | |
12473 | checked. Losing your static tracepoints whenever you rebuild is | |
12474 | undesirable. This function tries to resync/rematch gdb static | |
12475 | tracepoints with the markers on the target, for static tracepoints | |
12476 | that have not been set by marker id. Static tracepoint that have | |
12477 | been set by marker id are reset by marker id in breakpoint_re_set. | |
12478 | The heuristic is: | |
12479 | ||
12480 | 1) For a tracepoint set at a specific address, look for a marker at | |
12481 | the old PC. If one is found there, assume to be the same marker. | |
12482 | If the name / string id of the marker found is different from the | |
12483 | previous known name, assume that means the user renamed the marker | |
12484 | in the sources, and output a warning. | |
12485 | ||
12486 | 2) For a tracepoint set at a given line number, look for a marker | |
12487 | at the new address of the old line number. If one is found there, | |
12488 | assume to be the same marker. If the name / string id of the | |
12489 | marker found is different from the previous known name, assume that | |
12490 | means the user renamed the marker in the sources, and output a | |
12491 | warning. | |
12492 | ||
12493 | 3) If a marker is no longer found at the same address or line, it | |
12494 | may mean the marker no longer exists. But it may also just mean | |
12495 | the code changed a bit. Maybe the user added a few lines of code | |
12496 | that made the marker move up or down (in line number terms). Ask | |
12497 | the target for info about the marker with the string id as we knew | |
12498 | it. If found, update line number and address in the matching | |
12499 | static tracepoint. This will get confused if there's more than one | |
12500 | marker with the same ID (possible in UST, although unadvised | |
12501 | precisely because it confuses tools). */ | |
12502 | ||
12503 | static struct symtab_and_line | |
12504 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
12505 | { | |
d9b3f62e | 12506 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
12507 | struct static_tracepoint_marker marker; |
12508 | CORE_ADDR pc; | |
0fb4aa4b PA |
12509 | |
12510 | pc = sal.pc; | |
12511 | if (sal.line) | |
12512 | find_line_pc (sal.symtab, sal.line, &pc); | |
12513 | ||
12514 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
12515 | { | |
5d9310c4 | 12516 | if (tp->static_trace_marker_id != marker.str_id) |
0fb4aa4b | 12517 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
5d9310c4 SM |
12518 | b->number, tp->static_trace_marker_id.c_str (), |
12519 | marker.str_id.c_str ()); | |
0fb4aa4b | 12520 | |
5d9310c4 | 12521 | tp->static_trace_marker_id = std::move (marker.str_id); |
0fb4aa4b PA |
12522 | |
12523 | return sal; | |
12524 | } | |
12525 | ||
12526 | /* Old marker wasn't found on target at lineno. Try looking it up | |
12527 | by string ID. */ | |
12528 | if (!sal.explicit_pc | |
12529 | && sal.line != 0 | |
12530 | && sal.symtab != NULL | |
5d9310c4 | 12531 | && !tp->static_trace_marker_id.empty ()) |
0fb4aa4b | 12532 | { |
5d9310c4 SM |
12533 | std::vector<static_tracepoint_marker> markers |
12534 | = target_static_tracepoint_markers_by_strid | |
12535 | (tp->static_trace_marker_id.c_str ()); | |
0fb4aa4b | 12536 | |
5d9310c4 | 12537 | if (!markers.empty ()) |
0fb4aa4b | 12538 | { |
0fb4aa4b | 12539 | struct symbol *sym; |
80e1d417 | 12540 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 12541 | struct ui_out *uiout = current_uiout; |
67994074 | 12542 | struct explicit_location explicit_loc; |
0fb4aa4b | 12543 | |
5d9310c4 | 12544 | tpmarker = &markers[0]; |
0fb4aa4b | 12545 | |
5d9310c4 | 12546 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
0fb4aa4b PA |
12547 | |
12548 | warning (_("marker for static tracepoint %d (%s) not " | |
12549 | "found at previous line number"), | |
5d9310c4 | 12550 | b->number, tp->static_trace_marker_id.c_str ()); |
0fb4aa4b | 12551 | |
51abb421 | 12552 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 12553 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 12554 | uiout->text ("Now in "); |
0fb4aa4b PA |
12555 | if (sym) |
12556 | { | |
987012b8 | 12557 | uiout->field_string ("func", sym->print_name (), |
e43b10e1 | 12558 | function_name_style.style ()); |
112e8700 | 12559 | uiout->text (" at "); |
0fb4aa4b | 12560 | } |
112e8700 | 12561 | uiout->field_string ("file", |
cbe56571 | 12562 | symtab_to_filename_for_display (sal2.symtab), |
e43b10e1 | 12563 | file_name_style.style ()); |
112e8700 | 12564 | uiout->text (":"); |
0fb4aa4b | 12565 | |
112e8700 | 12566 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 12567 | { |
0b0865da | 12568 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 12569 | |
112e8700 | 12570 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
12571 | } |
12572 | ||
381befee | 12573 | uiout->field_signed ("line", sal2.line); |
112e8700 | 12574 | uiout->text ("\n"); |
0fb4aa4b | 12575 | |
80e1d417 | 12576 | b->loc->line_number = sal2.line; |
2f202fde | 12577 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 12578 | |
d28cd78a | 12579 | b->location.reset (NULL); |
67994074 KS |
12580 | initialize_explicit_location (&explicit_loc); |
12581 | explicit_loc.source_filename | |
00e52e53 | 12582 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
12583 | explicit_loc.line_offset.offset = b->loc->line_number; |
12584 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 12585 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
12586 | |
12587 | /* Might be nice to check if function changed, and warn if | |
12588 | so. */ | |
0fb4aa4b PA |
12589 | } |
12590 | } | |
12591 | return sal; | |
12592 | } | |
12593 | ||
8d3788bd VP |
12594 | /* Returns 1 iff locations A and B are sufficiently same that |
12595 | we don't need to report breakpoint as changed. */ | |
12596 | ||
12597 | static int | |
12598 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
12599 | { | |
12600 | while (a && b) | |
12601 | { | |
12602 | if (a->address != b->address) | |
12603 | return 0; | |
12604 | ||
12605 | if (a->shlib_disabled != b->shlib_disabled) | |
12606 | return 0; | |
12607 | ||
12608 | if (a->enabled != b->enabled) | |
12609 | return 0; | |
12610 | ||
b5fa468f TBA |
12611 | if (a->disabled_by_cond != b->disabled_by_cond) |
12612 | return 0; | |
12613 | ||
8d3788bd VP |
12614 | a = a->next; |
12615 | b = b->next; | |
12616 | } | |
12617 | ||
12618 | if ((a == NULL) != (b == NULL)) | |
12619 | return 0; | |
12620 | ||
12621 | return 1; | |
12622 | } | |
12623 | ||
c2f4122d PA |
12624 | /* Split all locations of B that are bound to PSPACE out of B's |
12625 | location list to a separate list and return that list's head. If | |
12626 | PSPACE is NULL, hoist out all locations of B. */ | |
12627 | ||
12628 | static struct bp_location * | |
12629 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
12630 | { | |
12631 | struct bp_location head; | |
12632 | struct bp_location *i = b->loc; | |
12633 | struct bp_location **i_link = &b->loc; | |
12634 | struct bp_location *hoisted = &head; | |
12635 | ||
12636 | if (pspace == NULL) | |
12637 | { | |
12638 | i = b->loc; | |
12639 | b->loc = NULL; | |
12640 | return i; | |
12641 | } | |
12642 | ||
12643 | head.next = NULL; | |
12644 | ||
12645 | while (i != NULL) | |
12646 | { | |
12647 | if (i->pspace == pspace) | |
12648 | { | |
12649 | *i_link = i->next; | |
12650 | i->next = NULL; | |
12651 | hoisted->next = i; | |
12652 | hoisted = i; | |
12653 | } | |
12654 | else | |
12655 | i_link = &i->next; | |
12656 | i = *i_link; | |
12657 | } | |
12658 | ||
12659 | return head.next; | |
12660 | } | |
12661 | ||
12662 | /* Create new breakpoint locations for B (a hardware or software | |
12663 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
12664 | zero, then B is a ranged breakpoint. Only recreates locations for | |
12665 | FILTER_PSPACE. Locations of other program spaces are left | |
12666 | untouched. */ | |
f1310107 | 12667 | |
0e30163f | 12668 | void |
0d381245 | 12669 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 12670 | struct program_space *filter_pspace, |
6c5b2ebe PA |
12671 | gdb::array_view<const symtab_and_line> sals, |
12672 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 | 12673 | { |
c2f4122d | 12674 | struct bp_location *existing_locations; |
0d381245 | 12675 | |
6c5b2ebe | 12676 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
12677 | { |
12678 | /* Ranged breakpoints have only one start location and one end | |
12679 | location. */ | |
12680 | b->enable_state = bp_disabled; | |
6cb06a8c TT |
12681 | gdb_printf (gdb_stderr, |
12682 | _("Could not reset ranged breakpoint %d: " | |
12683 | "multiple locations found\n"), | |
12684 | b->number); | |
f8eba3c6 TT |
12685 | return; |
12686 | } | |
f1310107 | 12687 | |
4a64f543 MS |
12688 | /* If there's no new locations, and all existing locations are |
12689 | pending, don't do anything. This optimizes the common case where | |
12690 | all locations are in the same shared library, that was unloaded. | |
12691 | We'd like to retain the location, so that when the library is | |
12692 | loaded again, we don't loose the enabled/disabled status of the | |
12693 | individual locations. */ | |
6c5b2ebe | 12694 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
12695 | return; |
12696 | ||
c2f4122d | 12697 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 12698 | |
6c5b2ebe | 12699 | for (const auto &sal : sals) |
fe3f5fa8 | 12700 | { |
f8eba3c6 TT |
12701 | struct bp_location *new_loc; |
12702 | ||
6c5b2ebe | 12703 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 12704 | |
6c5b2ebe | 12705 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 12706 | |
0d381245 VP |
12707 | /* Reparse conditions, they might contain references to the |
12708 | old symtab. */ | |
12709 | if (b->cond_string != NULL) | |
12710 | { | |
bbc13ae3 | 12711 | const char *s; |
fe3f5fa8 | 12712 | |
6f781ee3 | 12713 | s = b->cond_string.get (); |
a70b8144 | 12714 | try |
0d381245 | 12715 | { |
6c5b2ebe PA |
12716 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
12717 | block_for_pc (sal.pc), | |
0d381245 VP |
12718 | 0); |
12719 | } | |
230d2906 | 12720 | catch (const gdb_exception_error &e) |
0d381245 | 12721 | { |
b5fa468f | 12722 | new_loc->disabled_by_cond = true; |
0d381245 VP |
12723 | } |
12724 | } | |
fe3f5fa8 | 12725 | |
6c5b2ebe | 12726 | if (!sals_end.empty ()) |
f1310107 | 12727 | { |
6c5b2ebe | 12728 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 12729 | |
6c5b2ebe | 12730 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 12731 | } |
0d381245 | 12732 | } |
fe3f5fa8 | 12733 | |
4a64f543 MS |
12734 | /* If possible, carry over 'disable' status from existing |
12735 | breakpoints. */ | |
0d381245 VP |
12736 | { |
12737 | struct bp_location *e = existing_locations; | |
776592bf DE |
12738 | /* If there are multiple breakpoints with the same function name, |
12739 | e.g. for inline functions, comparing function names won't work. | |
12740 | Instead compare pc addresses; this is just a heuristic as things | |
12741 | may have moved, but in practice it gives the correct answer | |
12742 | often enough until a better solution is found. */ | |
12743 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
12744 | ||
0d381245 VP |
12745 | for (; e; e = e->next) |
12746 | { | |
b5fa468f | 12747 | if ((!e->enabled || e->disabled_by_cond) && e->function_name) |
0d381245 | 12748 | { |
776592bf DE |
12749 | if (have_ambiguous_names) |
12750 | { | |
40cb8ca5 | 12751 | for (bp_location *l : b->locations ()) |
7f32a4d5 PA |
12752 | { |
12753 | /* Ignore software vs hardware location type at | |
12754 | this point, because with "set breakpoint | |
12755 | auto-hw", after a re-set, locations that were | |
12756 | hardware can end up as software, or vice versa. | |
12757 | As mentioned above, this is an heuristic and in | |
12758 | practice should give the correct answer often | |
12759 | enough. */ | |
12760 | if (breakpoint_locations_match (e, l, true)) | |
12761 | { | |
b5fa468f TBA |
12762 | l->enabled = e->enabled; |
12763 | l->disabled_by_cond = e->disabled_by_cond; | |
7f32a4d5 PA |
12764 | break; |
12765 | } | |
12766 | } | |
776592bf DE |
12767 | } |
12768 | else | |
12769 | { | |
40cb8ca5 | 12770 | for (bp_location *l : b->locations ()) |
776592bf | 12771 | if (l->function_name |
23d6ee64 TT |
12772 | && strcmp (e->function_name.get (), |
12773 | l->function_name.get ()) == 0) | |
776592bf | 12774 | { |
b5fa468f TBA |
12775 | l->enabled = e->enabled; |
12776 | l->disabled_by_cond = e->disabled_by_cond; | |
776592bf DE |
12777 | break; |
12778 | } | |
12779 | } | |
0d381245 VP |
12780 | } |
12781 | } | |
12782 | } | |
fe3f5fa8 | 12783 | |
8d3788bd | 12784 | if (!locations_are_equal (existing_locations, b->loc)) |
76727919 | 12785 | gdb::observers::breakpoint_modified.notify (b); |
fe3f5fa8 VP |
12786 | } |
12787 | ||
f00aae0f | 12788 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
12789 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
12790 | ||
6c5b2ebe | 12791 | static std::vector<symtab_and_line> |
f00aae0f | 12792 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 12793 | struct program_space *search_pspace, int *found) |
ef23e705 | 12794 | { |
cc06b668 | 12795 | struct gdb_exception exception; |
ef23e705 | 12796 | |
983af33b | 12797 | gdb_assert (b->ops != NULL); |
ef23e705 | 12798 | |
6c5b2ebe PA |
12799 | std::vector<symtab_and_line> sals; |
12800 | ||
a70b8144 | 12801 | try |
ef23e705 | 12802 | { |
c47614fe | 12803 | sals = b->decode_location (location, search_pspace); |
ef23e705 | 12804 | } |
94aeb44b | 12805 | catch (gdb_exception_error &e) |
ef23e705 TJB |
12806 | { |
12807 | int not_found_and_ok = 0; | |
492d29ea | 12808 | |
ef23e705 TJB |
12809 | /* For pending breakpoints, it's expected that parsing will |
12810 | fail until the right shared library is loaded. User has | |
12811 | already told to create pending breakpoints and don't need | |
12812 | extra messages. If breakpoint is in bp_shlib_disabled | |
12813 | state, then user already saw the message about that | |
12814 | breakpoint being disabled, and don't want to see more | |
12815 | errors. */ | |
58438ac1 | 12816 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
12817 | && (b->condition_not_parsed |
12818 | || (b->loc != NULL | |
12819 | && search_pspace != NULL | |
12820 | && b->loc->pspace != search_pspace) | |
ef23e705 | 12821 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 12822 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
12823 | || b->enable_state == bp_disabled)) |
12824 | not_found_and_ok = 1; | |
12825 | ||
12826 | if (!not_found_and_ok) | |
12827 | { | |
12828 | /* We surely don't want to warn about the same breakpoint | |
12829 | 10 times. One solution, implemented here, is disable | |
12830 | the breakpoint on error. Another solution would be to | |
12831 | have separate 'warning emitted' flag. Since this | |
12832 | happens only when a binary has changed, I don't know | |
12833 | which approach is better. */ | |
12834 | b->enable_state = bp_disabled; | |
eedc3f4f | 12835 | throw; |
ef23e705 | 12836 | } |
94aeb44b TT |
12837 | |
12838 | exception = std::move (e); | |
ef23e705 TJB |
12839 | } |
12840 | ||
492d29ea | 12841 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 12842 | { |
6c5b2ebe PA |
12843 | for (auto &sal : sals) |
12844 | resolve_sal_pc (&sal); | |
f00aae0f | 12845 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 12846 | { |
6f781ee3 | 12847 | gdb::unique_xmalloc_ptr<char> cond_string, extra_string; |
ed1d1739 | 12848 | int thread, task; |
ef23e705 | 12849 | |
6f781ee3 | 12850 | find_condition_and_thread_for_sals (sals, b->extra_string.get (), |
b5fa468f TBA |
12851 | &cond_string, &thread, |
12852 | &task, &extra_string); | |
f00aae0f | 12853 | gdb_assert (b->cond_string == NULL); |
ef23e705 | 12854 | if (cond_string) |
6f781ee3 | 12855 | b->cond_string = std::move (cond_string); |
ef23e705 TJB |
12856 | b->thread = thread; |
12857 | b->task = task; | |
e7e0cddf | 12858 | if (extra_string) |
6f781ee3 | 12859 | b->extra_string = std::move (extra_string); |
ef23e705 TJB |
12860 | b->condition_not_parsed = 0; |
12861 | } | |
12862 | ||
7b572efb | 12863 | if (b->type == bp_static_tracepoint) |
6c5b2ebe | 12864 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 12865 | |
58438ac1 TT |
12866 | *found = 1; |
12867 | } | |
12868 | else | |
12869 | *found = 0; | |
ef23e705 TJB |
12870 | |
12871 | return sals; | |
12872 | } | |
12873 | ||
348d480f PA |
12874 | /* The default re_set method, for typical hardware or software |
12875 | breakpoints. Reevaluate the breakpoint and recreate its | |
12876 | locations. */ | |
12877 | ||
12878 | static void | |
28010a5d | 12879 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 12880 | { |
c2f4122d | 12881 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 12882 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 12883 | |
6c5b2ebe PA |
12884 | int found; |
12885 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
12886 | filter_pspace, &found); | |
ef23e705 | 12887 | if (found) |
6c5b2ebe | 12888 | expanded = std::move (sals); |
ef23e705 | 12889 | |
f00aae0f | 12890 | if (b->location_range_end != NULL) |
f1310107 | 12891 | { |
6c5b2ebe PA |
12892 | std::vector<symtab_and_line> sals_end |
12893 | = location_to_sals (b, b->location_range_end.get (), | |
12894 | filter_pspace, &found); | |
f1310107 | 12895 | if (found) |
6c5b2ebe | 12896 | expanded_end = std::move (sals_end); |
f1310107 TJB |
12897 | } |
12898 | ||
c2f4122d | 12899 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
12900 | } |
12901 | ||
983af33b SDJ |
12902 | /* Default method for creating SALs from an address string. It basically |
12903 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
12904 | ||
12905 | static void | |
626d2320 | 12906 | create_sals_from_location_default (struct event_location *location, |
f00aae0f KS |
12907 | struct linespec_result *canonical, |
12908 | enum bptype type_wanted) | |
983af33b | 12909 | { |
f00aae0f | 12910 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
12911 | } |
12912 | ||
12913 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
12914 | function for the `create_breakpoints_sal' method of | |
12915 | breakpoint_ops. */ | |
12916 | ||
12917 | static void | |
12918 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
12919 | struct linespec_result *canonical, | |
e1e01040 PA |
12920 | gdb::unique_xmalloc_ptr<char> cond_string, |
12921 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12922 | enum bptype type_wanted, |
12923 | enum bpdisp disposition, | |
12924 | int thread, | |
12925 | int task, int ignore_count, | |
12926 | const struct breakpoint_ops *ops, | |
12927 | int from_tty, int enabled, | |
44f238bb | 12928 | int internal, unsigned flags) |
983af33b | 12929 | { |
e1e01040 PA |
12930 | create_breakpoints_sal (gdbarch, canonical, |
12931 | std::move (cond_string), | |
12932 | std::move (extra_string), | |
983af33b SDJ |
12933 | type_wanted, disposition, |
12934 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 12935 | enabled, internal, flags); |
983af33b SDJ |
12936 | } |
12937 | ||
12938 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 12939 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 12940 | |
6c5b2ebe | 12941 | static std::vector<symtab_and_line> |
f00aae0f | 12942 | decode_location_default (struct breakpoint *b, |
626d2320 | 12943 | struct event_location *location, |
6c5b2ebe | 12944 | struct program_space *search_pspace) |
983af33b SDJ |
12945 | { |
12946 | struct linespec_result canonical; | |
12947 | ||
c2f4122d | 12948 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
cafb3438 | 12949 | NULL, 0, &canonical, multiple_symbols_all, |
c0e8dcd8 | 12950 | b->filter.get ()); |
983af33b SDJ |
12951 | |
12952 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 12953 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 12954 | |
6c5b2ebe | 12955 | if (!canonical.lsals.empty ()) |
983af33b | 12956 | { |
6c5b2ebe PA |
12957 | const linespec_sals &lsal = canonical.lsals[0]; |
12958 | return std::move (lsal.sals); | |
983af33b | 12959 | } |
6c5b2ebe | 12960 | return {}; |
983af33b SDJ |
12961 | } |
12962 | ||
bf469271 | 12963 | /* Reset a breakpoint. */ |
c906108c | 12964 | |
bf469271 PA |
12965 | static void |
12966 | breakpoint_re_set_one (breakpoint *b) | |
c906108c | 12967 | { |
fdf44873 TT |
12968 | input_radix = b->input_radix; |
12969 | set_language (b->language); | |
c906108c | 12970 | |
c47614fe | 12971 | b->re_set (); |
c906108c SS |
12972 | } |
12973 | ||
c2f4122d PA |
12974 | /* Re-set breakpoint locations for the current program space. |
12975 | Locations bound to other program spaces are left untouched. */ | |
12976 | ||
c906108c | 12977 | void |
69de3c6a | 12978 | breakpoint_re_set (void) |
c906108c | 12979 | { |
c5aa993b | 12980 | { |
fdf44873 TT |
12981 | scoped_restore_current_language save_language; |
12982 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); | |
5ed8105e | 12983 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 12984 | |
8e817061 JB |
12985 | /* breakpoint_re_set_one sets the current_language to the language |
12986 | of the breakpoint it is resetting (see prepare_re_set_context) | |
12987 | before re-evaluating the breakpoint's location. This change can | |
12988 | unfortunately get undone by accident if the language_mode is set | |
12989 | to auto, and we either switch frames, or more likely in this context, | |
12990 | we select the current frame. | |
12991 | ||
12992 | We prevent this by temporarily turning the language_mode to | |
12993 | language_mode_manual. We restore it once all breakpoints | |
12994 | have been reset. */ | |
12995 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); | |
12996 | language_mode = language_mode_manual; | |
12997 | ||
5ed8105e PA |
12998 | /* Note: we must not try to insert locations until after all |
12999 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
13000 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
13001 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 13002 | |
1428b37a | 13003 | for (breakpoint *b : all_breakpoints_safe ()) |
5ed8105e | 13004 | { |
a70b8144 | 13005 | try |
bf469271 PA |
13006 | { |
13007 | breakpoint_re_set_one (b); | |
13008 | } | |
230d2906 | 13009 | catch (const gdb_exception &ex) |
bf469271 PA |
13010 | { |
13011 | exception_fprintf (gdb_stderr, ex, | |
13012 | "Error in re-setting breakpoint %d: ", | |
13013 | b->number); | |
13014 | } | |
5ed8105e | 13015 | } |
5ed8105e PA |
13016 | |
13017 | jit_breakpoint_re_set (); | |
13018 | } | |
6c95b8df | 13019 | |
af02033e PP |
13020 | create_overlay_event_breakpoint (); |
13021 | create_longjmp_master_breakpoint (); | |
13022 | create_std_terminate_master_breakpoint (); | |
186c406b | 13023 | create_exception_master_breakpoint (); |
2a7f3dff PA |
13024 | |
13025 | /* Now we can insert. */ | |
13026 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
13027 | } |
13028 | \f | |
c906108c SS |
13029 | /* Reset the thread number of this breakpoint: |
13030 | ||
13031 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 13032 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 13033 | void |
fba45db2 | 13034 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
13035 | { |
13036 | if (b->thread != -1) | |
13037 | { | |
00431a78 | 13038 | b->thread = inferior_thread ()->global_num; |
6c95b8df PA |
13039 | |
13040 | /* We're being called after following a fork. The new fork is | |
13041 | selected as current, and unless this was a vfork will have a | |
13042 | different program space from the original thread. Reset that | |
13043 | as well. */ | |
13044 | b->loc->pspace = current_program_space; | |
c906108c SS |
13045 | } |
13046 | } | |
13047 | ||
03ac34d5 MS |
13048 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13049 | If from_tty is nonzero, it prints a message to that effect, | |
13050 | which ends with a period (no newline). */ | |
13051 | ||
c906108c | 13052 | void |
fba45db2 | 13053 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 13054 | { |
c906108c SS |
13055 | if (count < 0) |
13056 | count = 0; | |
13057 | ||
43892fdf | 13058 | for (breakpoint *b : all_breakpoints ()) |
c906108c | 13059 | if (b->number == bptnum) |
01add95b SM |
13060 | { |
13061 | if (is_tracepoint (b)) | |
13062 | { | |
13063 | if (from_tty && count != 0) | |
6cb06a8c TT |
13064 | gdb_printf (_("Ignore count ignored for tracepoint %d."), |
13065 | bptnum); | |
01add95b SM |
13066 | return; |
13067 | } | |
13068 | ||
13069 | b->ignore_count = count; | |
13070 | if (from_tty) | |
13071 | { | |
13072 | if (count == 0) | |
6cb06a8c TT |
13073 | gdb_printf (_("Will stop next time " |
13074 | "breakpoint %d is reached."), | |
13075 | bptnum); | |
01add95b | 13076 | else if (count == 1) |
6cb06a8c TT |
13077 | gdb_printf (_("Will ignore next crossing of breakpoint %d."), |
13078 | bptnum); | |
01add95b | 13079 | else |
6cb06a8c TT |
13080 | gdb_printf (_("Will ignore next %d " |
13081 | "crossings of breakpoint %d."), | |
13082 | count, bptnum); | |
01add95b SM |
13083 | } |
13084 | gdb::observers::breakpoint_modified.notify (b); | |
13085 | return; | |
13086 | } | |
c906108c | 13087 | |
8a3fe4f8 | 13088 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
13089 | } |
13090 | ||
c906108c SS |
13091 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
13092 | ||
13093 | static void | |
0b39b52e | 13094 | ignore_command (const char *args, int from_tty) |
c906108c | 13095 | { |
0b39b52e | 13096 | const char *p = args; |
52f0bd74 | 13097 | int num; |
c906108c SS |
13098 | |
13099 | if (p == 0) | |
e2e0b3e5 | 13100 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 13101 | |
c906108c | 13102 | num = get_number (&p); |
5c44784c | 13103 | if (num == 0) |
8a3fe4f8 | 13104 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 13105 | if (*p == 0) |
8a3fe4f8 | 13106 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
13107 | |
13108 | set_ignore_count (num, | |
13109 | longest_to_int (value_as_long (parse_and_eval (p))), | |
13110 | from_tty); | |
221ea385 | 13111 | if (from_tty) |
6cb06a8c | 13112 | gdb_printf ("\n"); |
c906108c SS |
13113 | } |
13114 | \f | |
d0fe4701 XR |
13115 | |
13116 | /* Call FUNCTION on each of the breakpoints with numbers in the range | |
13117 | defined by BP_NUM_RANGE (an inclusive range). */ | |
c906108c SS |
13118 | |
13119 | static void | |
d0fe4701 XR |
13120 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
13121 | gdb::function_view<void (breakpoint *)> function) | |
c906108c | 13122 | { |
d0fe4701 XR |
13123 | if (bp_num_range.first == 0) |
13124 | { | |
13125 | warning (_("bad breakpoint number at or near '%d'"), | |
13126 | bp_num_range.first); | |
13127 | } | |
13128 | else | |
c906108c | 13129 | { |
d0fe4701 | 13130 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
5c44784c | 13131 | { |
d0fe4701 XR |
13132 | bool match = false; |
13133 | ||
1428b37a | 13134 | for (breakpoint *b : all_breakpoints_safe ()) |
d0fe4701 | 13135 | if (b->number == i) |
5c44784c | 13136 | { |
bfd28288 | 13137 | match = true; |
48649e1b | 13138 | function (b); |
11cf8741 | 13139 | break; |
5c44784c | 13140 | } |
bfd28288 | 13141 | if (!match) |
6cb06a8c | 13142 | gdb_printf (_("No breakpoint number %d.\n"), i); |
c5aa993b | 13143 | } |
c906108c SS |
13144 | } |
13145 | } | |
13146 | ||
d0fe4701 XR |
13147 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
13148 | ARGS. */ | |
13149 | ||
13150 | static void | |
13151 | map_breakpoint_numbers (const char *args, | |
13152 | gdb::function_view<void (breakpoint *)> function) | |
13153 | { | |
13154 | if (args == NULL || *args == '\0') | |
13155 | error_no_arg (_("one or more breakpoint numbers")); | |
13156 | ||
13157 | number_or_range_parser parser (args); | |
13158 | ||
13159 | while (!parser.finished ()) | |
13160 | { | |
13161 | int num = parser.get_number (); | |
13162 | map_breakpoint_number_range (std::make_pair (num, num), function); | |
13163 | } | |
13164 | } | |
13165 | ||
13166 | /* Return the breakpoint location structure corresponding to the | |
13167 | BP_NUM and LOC_NUM values. */ | |
13168 | ||
0d381245 | 13169 | static struct bp_location * |
d0fe4701 | 13170 | find_location_by_number (int bp_num, int loc_num) |
0d381245 | 13171 | { |
43892fdf | 13172 | breakpoint *b = get_breakpoint (bp_num); |
0d381245 VP |
13173 | |
13174 | if (!b || b->number != bp_num) | |
d0fe4701 | 13175 | error (_("Bad breakpoint number '%d'"), bp_num); |
0d381245 | 13176 | |
0d381245 | 13177 | if (loc_num == 0) |
d0fe4701 | 13178 | error (_("Bad breakpoint location number '%d'"), loc_num); |
0d381245 | 13179 | |
d0fe4701 | 13180 | int n = 0; |
40cb8ca5 | 13181 | for (bp_location *loc : b->locations ()) |
d0fe4701 XR |
13182 | if (++n == loc_num) |
13183 | return loc; | |
13184 | ||
13185 | error (_("Bad breakpoint location number '%d'"), loc_num); | |
0d381245 VP |
13186 | } |
13187 | ||
95e95a6d PA |
13188 | /* Modes of operation for extract_bp_num. */ |
13189 | enum class extract_bp_kind | |
13190 | { | |
13191 | /* Extracting a breakpoint number. */ | |
13192 | bp, | |
13193 | ||
13194 | /* Extracting a location number. */ | |
13195 | loc, | |
13196 | }; | |
13197 | ||
13198 | /* Extract a breakpoint or location number (as determined by KIND) | |
13199 | from the string starting at START. TRAILER is a character which | |
13200 | can be found after the number. If you don't want a trailer, use | |
13201 | '\0'. If END_OUT is not NULL, it is set to point after the parsed | |
13202 | string. This always returns a positive integer. */ | |
13203 | ||
13204 | static int | |
13205 | extract_bp_num (extract_bp_kind kind, const char *start, | |
13206 | int trailer, const char **end_out = NULL) | |
13207 | { | |
13208 | const char *end = start; | |
13209 | int num = get_number_trailer (&end, trailer); | |
13210 | if (num < 0) | |
13211 | error (kind == extract_bp_kind::bp | |
13212 | ? _("Negative breakpoint number '%.*s'") | |
13213 | : _("Negative breakpoint location number '%.*s'"), | |
13214 | int (end - start), start); | |
13215 | if (num == 0) | |
13216 | error (kind == extract_bp_kind::bp | |
13217 | ? _("Bad breakpoint number '%.*s'") | |
13218 | : _("Bad breakpoint location number '%.*s'"), | |
13219 | int (end - start), start); | |
13220 | ||
13221 | if (end_out != NULL) | |
13222 | *end_out = end; | |
13223 | return num; | |
13224 | } | |
13225 | ||
13226 | /* Extract a breakpoint or location range (as determined by KIND) in | |
13227 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair | |
13228 | representing the (inclusive) range. The returned pair's elements | |
13229 | are always positive integers. */ | |
13230 | ||
13231 | static std::pair<int, int> | |
13232 | extract_bp_or_bp_range (extract_bp_kind kind, | |
13233 | const std::string &arg, | |
13234 | std::string::size_type arg_offset) | |
13235 | { | |
13236 | std::pair<int, int> range; | |
13237 | const char *bp_loc = &arg[arg_offset]; | |
13238 | std::string::size_type dash = arg.find ('-', arg_offset); | |
13239 | if (dash != std::string::npos) | |
13240 | { | |
13241 | /* bp_loc is a range (x-z). */ | |
13242 | if (arg.length () == dash + 1) | |
13243 | error (kind == extract_bp_kind::bp | |
13244 | ? _("Bad breakpoint number at or near: '%s'") | |
13245 | : _("Bad breakpoint location number at or near: '%s'"), | |
13246 | bp_loc); | |
13247 | ||
13248 | const char *end; | |
13249 | const char *start_first = bp_loc; | |
13250 | const char *start_second = &arg[dash + 1]; | |
13251 | range.first = extract_bp_num (kind, start_first, '-'); | |
13252 | range.second = extract_bp_num (kind, start_second, '\0', &end); | |
13253 | ||
13254 | if (range.first > range.second) | |
13255 | error (kind == extract_bp_kind::bp | |
13256 | ? _("Inverted breakpoint range at '%.*s'") | |
13257 | : _("Inverted breakpoint location range at '%.*s'"), | |
13258 | int (end - start_first), start_first); | |
13259 | } | |
13260 | else | |
13261 | { | |
13262 | /* bp_loc is a single value. */ | |
13263 | range.first = extract_bp_num (kind, bp_loc, '\0'); | |
13264 | range.second = range.first; | |
13265 | } | |
13266 | return range; | |
13267 | } | |
13268 | ||
d0fe4701 XR |
13269 | /* Extract the breakpoint/location range specified by ARG. Returns |
13270 | the breakpoint range in BP_NUM_RANGE, and the location range in | |
13271 | BP_LOC_RANGE. | |
13272 | ||
13273 | ARG may be in any of the following forms: | |
13274 | ||
13275 | x where 'x' is a breakpoint number. | |
13276 | x-y where 'x' and 'y' specify a breakpoint numbers range. | |
13277 | x.y where 'x' is a breakpoint number and 'y' a location number. | |
13278 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a | |
13279 | location number range. | |
13280 | */ | |
13281 | ||
cc638e86 | 13282 | static void |
d0fe4701 XR |
13283 | extract_bp_number_and_location (const std::string &arg, |
13284 | std::pair<int, int> &bp_num_range, | |
13285 | std::pair<int, int> &bp_loc_range) | |
13286 | { | |
13287 | std::string::size_type dot = arg.find ('.'); | |
13288 | ||
13289 | if (dot != std::string::npos) | |
13290 | { | |
13291 | /* Handle 'x.y' and 'x.y-z' cases. */ | |
13292 | ||
13293 | if (arg.length () == dot + 1 || dot == 0) | |
95e95a6d | 13294 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
d0fe4701 | 13295 | |
95e95a6d PA |
13296 | bp_num_range.first |
13297 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); | |
13298 | bp_num_range.second = bp_num_range.first; | |
d0fe4701 | 13299 | |
95e95a6d PA |
13300 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
13301 | arg, dot + 1); | |
d0fe4701 XR |
13302 | } |
13303 | else | |
13304 | { | |
13305 | /* Handle x and x-y cases. */ | |
d0fe4701 | 13306 | |
95e95a6d | 13307 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
d0fe4701 XR |
13308 | bp_loc_range.first = 0; |
13309 | bp_loc_range.second = 0; | |
13310 | } | |
d0fe4701 XR |
13311 | } |
13312 | ||
13313 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE | |
13314 | specifies whether to enable or disable. */ | |
13315 | ||
13316 | static void | |
13317 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) | |
13318 | { | |
13319 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); | |
13320 | if (loc != NULL) | |
13321 | { | |
b5fa468f TBA |
13322 | if (loc->disabled_by_cond && enable) |
13323 | error (_("Breakpoint %d's condition is invalid at location %d, " | |
13324 | "cannot enable."), bp_num, loc_num); | |
13325 | ||
d0fe4701 XR |
13326 | if (loc->enabled != enable) |
13327 | { | |
13328 | loc->enabled = enable; | |
13329 | mark_breakpoint_location_modified (loc); | |
13330 | } | |
13331 | if (target_supports_enable_disable_tracepoint () | |
13332 | && current_trace_status ()->running && loc->owner | |
13333 | && is_tracepoint (loc->owner)) | |
13334 | target_disable_tracepoint (loc); | |
13335 | } | |
13336 | update_global_location_list (UGLL_DONT_INSERT); | |
d7154a8d JV |
13337 | |
13338 | gdb::observers::breakpoint_modified.notify (loc->owner); | |
d0fe4701 XR |
13339 | } |
13340 | ||
13341 | /* Enable or disable a range of breakpoint locations. BP_NUM is the | |
13342 | number of the breakpoint, and BP_LOC_RANGE specifies the | |
13343 | (inclusive) range of location numbers of that breakpoint to | |
13344 | enable/disable. ENABLE specifies whether to enable or disable the | |
13345 | location. */ | |
13346 | ||
13347 | static void | |
13348 | enable_disable_breakpoint_location_range (int bp_num, | |
13349 | std::pair<int, int> &bp_loc_range, | |
13350 | bool enable) | |
13351 | { | |
13352 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) | |
13353 | enable_disable_bp_num_loc (bp_num, i, enable); | |
13354 | } | |
0d381245 | 13355 | |
1900040c MS |
13356 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
13357 | If from_tty is nonzero, it prints a message to that effect, | |
13358 | which ends with a period (no newline). */ | |
13359 | ||
c906108c | 13360 | void |
fba45db2 | 13361 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
13362 | { |
13363 | /* Never disable a watchpoint scope breakpoint; we want to | |
13364 | hit them when we leave scope so we can delete both the | |
13365 | watchpoint and its scope breakpoint at that time. */ | |
13366 | if (bpt->type == bp_watchpoint_scope) | |
13367 | return; | |
13368 | ||
b5de0fa7 | 13369 | bpt->enable_state = bp_disabled; |
c906108c | 13370 | |
b775012e LM |
13371 | /* Mark breakpoint locations modified. */ |
13372 | mark_breakpoint_modified (bpt); | |
13373 | ||
d248b706 KY |
13374 | if (target_supports_enable_disable_tracepoint () |
13375 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13376 | { | |
40cb8ca5 | 13377 | for (bp_location *location : bpt->locations ()) |
d248b706 KY |
13378 | target_disable_tracepoint (location); |
13379 | } | |
13380 | ||
44702360 | 13381 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 13382 | |
76727919 | 13383 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
13384 | } |
13385 | ||
d0fe4701 XR |
13386 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
13387 | specified in ARGS. ARGS may be in any of the formats handled by | |
13388 | extract_bp_number_and_location. ENABLE specifies whether to enable | |
13389 | or disable the breakpoints/locations. */ | |
13390 | ||
c906108c | 13391 | static void |
d0fe4701 | 13392 | enable_disable_command (const char *args, int from_tty, bool enable) |
c906108c | 13393 | { |
c906108c | 13394 | if (args == 0) |
46c6471b | 13395 | { |
43892fdf | 13396 | for (breakpoint *bpt : all_breakpoints ()) |
46c6471b | 13397 | if (user_breakpoint_p (bpt)) |
d0fe4701 XR |
13398 | { |
13399 | if (enable) | |
13400 | enable_breakpoint (bpt); | |
13401 | else | |
13402 | disable_breakpoint (bpt); | |
13403 | } | |
46c6471b | 13404 | } |
9eaabc75 | 13405 | else |
0d381245 | 13406 | { |
cb791d59 | 13407 | std::string num = extract_arg (&args); |
9eaabc75 | 13408 | |
cb791d59 | 13409 | while (!num.empty ()) |
d248b706 | 13410 | { |
d0fe4701 | 13411 | std::pair<int, int> bp_num_range, bp_loc_range; |
9eaabc75 | 13412 | |
cc638e86 PA |
13413 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
13414 | ||
13415 | if (bp_loc_range.first == bp_loc_range.second | |
13416 | && bp_loc_range.first == 0) | |
d0fe4701 | 13417 | { |
cc638e86 PA |
13418 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
13419 | map_breakpoint_number_range (bp_num_range, | |
13420 | enable | |
13421 | ? enable_breakpoint | |
13422 | : disable_breakpoint); | |
13423 | } | |
13424 | else | |
13425 | { | |
13426 | /* Handle breakpoint ids with formats 'x.y' or | |
13427 | 'x.y-z'. */ | |
13428 | enable_disable_breakpoint_location_range | |
13429 | (bp_num_range.first, bp_loc_range, enable); | |
b775012e | 13430 | } |
9eaabc75 | 13431 | num = extract_arg (&args); |
d248b706 | 13432 | } |
0d381245 | 13433 | } |
c906108c SS |
13434 | } |
13435 | ||
d0fe4701 XR |
13436 | /* The disable command disables the specified breakpoints/locations |
13437 | (or all defined breakpoints) so they're no longer effective in | |
13438 | stopping the inferior. ARGS may be in any of the forms defined in | |
13439 | extract_bp_number_and_location. */ | |
13440 | ||
13441 | static void | |
13442 | disable_command (const char *args, int from_tty) | |
13443 | { | |
13444 | enable_disable_command (args, from_tty, false); | |
13445 | } | |
13446 | ||
c906108c | 13447 | static void |
816338b5 SS |
13448 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
13449 | int count) | |
c906108c | 13450 | { |
afe38095 | 13451 | int target_resources_ok; |
c906108c SS |
13452 | |
13453 | if (bpt->type == bp_hardware_breakpoint) | |
13454 | { | |
13455 | int i; | |
c5aa993b | 13456 | i = hw_breakpoint_used_count (); |
53a5351d | 13457 | target_resources_ok = |
d92524f1 | 13458 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 13459 | i + 1, 0); |
c906108c | 13460 | if (target_resources_ok == 0) |
8a3fe4f8 | 13461 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 13462 | else if (target_resources_ok < 0) |
8a3fe4f8 | 13463 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
13464 | } |
13465 | ||
cc60f2e3 | 13466 | if (is_watchpoint (bpt)) |
c906108c | 13467 | { |
d07205c2 | 13468 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 13469 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 13470 | |
a70b8144 | 13471 | try |
c906108c | 13472 | { |
3a5c3e22 PA |
13473 | struct watchpoint *w = (struct watchpoint *) bpt; |
13474 | ||
1e718ff1 TJB |
13475 | orig_enable_state = bpt->enable_state; |
13476 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 13477 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 13478 | } |
230d2906 | 13479 | catch (const gdb_exception &e) |
c5aa993b | 13480 | { |
1e718ff1 | 13481 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
13482 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
13483 | bpt->number); | |
13484 | return; | |
c5aa993b | 13485 | } |
c906108c | 13486 | } |
0101ce28 | 13487 | |
b775012e LM |
13488 | bpt->enable_state = bp_enabled; |
13489 | ||
13490 | /* Mark breakpoint locations modified. */ | |
13491 | mark_breakpoint_modified (bpt); | |
13492 | ||
d248b706 KY |
13493 | if (target_supports_enable_disable_tracepoint () |
13494 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
13495 | { | |
40cb8ca5 | 13496 | for (bp_location *location : bpt->locations ()) |
d248b706 KY |
13497 | target_enable_tracepoint (location); |
13498 | } | |
13499 | ||
b4c291bb | 13500 | bpt->disposition = disposition; |
816338b5 | 13501 | bpt->enable_count = count; |
44702360 | 13502 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 13503 | |
76727919 | 13504 | gdb::observers::breakpoint_modified.notify (bpt); |
c906108c SS |
13505 | } |
13506 | ||
fe3f5fa8 | 13507 | |
c906108c | 13508 | void |
fba45db2 | 13509 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 13510 | { |
816338b5 | 13511 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
13512 | } |
13513 | ||
d0fe4701 XR |
13514 | /* The enable command enables the specified breakpoints/locations (or |
13515 | all defined breakpoints) so they once again become (or continue to | |
13516 | be) effective in stopping the inferior. ARGS may be in any of the | |
13517 | forms defined in extract_bp_number_and_location. */ | |
c906108c | 13518 | |
c906108c | 13519 | static void |
981a3fb3 | 13520 | enable_command (const char *args, int from_tty) |
c906108c | 13521 | { |
d0fe4701 | 13522 | enable_disable_command (args, from_tty, true); |
c906108c SS |
13523 | } |
13524 | ||
c906108c | 13525 | static void |
4495129a | 13526 | enable_once_command (const char *args, int from_tty) |
c906108c | 13527 | { |
48649e1b TT |
13528 | map_breakpoint_numbers |
13529 | (args, [&] (breakpoint *b) | |
13530 | { | |
13531 | iterate_over_related_breakpoints | |
13532 | (b, [&] (breakpoint *bpt) | |
13533 | { | |
13534 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
13535 | }); | |
13536 | }); | |
816338b5 SS |
13537 | } |
13538 | ||
13539 | static void | |
4495129a | 13540 | enable_count_command (const char *args, int from_tty) |
816338b5 | 13541 | { |
b9d61307 SM |
13542 | int count; |
13543 | ||
13544 | if (args == NULL) | |
13545 | error_no_arg (_("hit count")); | |
13546 | ||
13547 | count = get_number (&args); | |
816338b5 | 13548 | |
48649e1b TT |
13549 | map_breakpoint_numbers |
13550 | (args, [&] (breakpoint *b) | |
13551 | { | |
13552 | iterate_over_related_breakpoints | |
13553 | (b, [&] (breakpoint *bpt) | |
13554 | { | |
13555 | enable_breakpoint_disp (bpt, disp_disable, count); | |
13556 | }); | |
13557 | }); | |
c906108c SS |
13558 | } |
13559 | ||
c906108c | 13560 | static void |
4495129a | 13561 | enable_delete_command (const char *args, int from_tty) |
c906108c | 13562 | { |
48649e1b TT |
13563 | map_breakpoint_numbers |
13564 | (args, [&] (breakpoint *b) | |
13565 | { | |
13566 | iterate_over_related_breakpoints | |
13567 | (b, [&] (breakpoint *bpt) | |
13568 | { | |
13569 | enable_breakpoint_disp (bpt, disp_del, 1); | |
13570 | }); | |
13571 | }); | |
c906108c SS |
13572 | } |
13573 | \f | |
1f3b5d1b PP |
13574 | /* Invalidate last known value of any hardware watchpoint if |
13575 | the memory which that value represents has been written to by | |
13576 | GDB itself. */ | |
13577 | ||
13578 | static void | |
8de0566d YQ |
13579 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
13580 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
13581 | const bfd_byte *data) |
13582 | { | |
43892fdf | 13583 | for (breakpoint *bp : all_breakpoints ()) |
1f3b5d1b | 13584 | if (bp->enable_state == bp_enabled |
3a5c3e22 | 13585 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 13586 | { |
3a5c3e22 | 13587 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 13588 | |
850645cf | 13589 | if (wp->val_valid && wp->val != nullptr) |
3a5c3e22 | 13590 | { |
40cb8ca5 | 13591 | for (bp_location *loc : bp->locations ()) |
3a5c3e22 PA |
13592 | if (loc->loc_type == bp_loc_hardware_watchpoint |
13593 | && loc->address + loc->length > addr | |
13594 | && addr + len > loc->address) | |
13595 | { | |
3a5c3e22 | 13596 | wp->val = NULL; |
4c1d86d9 | 13597 | wp->val_valid = false; |
3a5c3e22 PA |
13598 | } |
13599 | } | |
1f3b5d1b PP |
13600 | } |
13601 | } | |
13602 | ||
8181d85f DJ |
13603 | /* Create and insert a breakpoint for software single step. */ |
13604 | ||
13605 | void | |
6c95b8df | 13606 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
accd0bcd | 13607 | const address_space *aspace, |
4a64f543 | 13608 | CORE_ADDR next_pc) |
8181d85f | 13609 | { |
7c16b83e PA |
13610 | struct thread_info *tp = inferior_thread (); |
13611 | struct symtab_and_line sal; | |
13612 | CORE_ADDR pc = next_pc; | |
8181d85f | 13613 | |
34b7e8a6 PA |
13614 | if (tp->control.single_step_breakpoints == NULL) |
13615 | { | |
13616 | tp->control.single_step_breakpoints | |
5d5658a1 | 13617 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 13618 | } |
8181d85f | 13619 | |
7c16b83e PA |
13620 | sal = find_pc_line (pc, 0); |
13621 | sal.pc = pc; | |
13622 | sal.section = find_pc_overlay (pc); | |
13623 | sal.explicit_pc = 1; | |
34b7e8a6 | 13624 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 13625 | |
7c16b83e | 13626 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
13627 | } |
13628 | ||
93f9a11f YQ |
13629 | /* Insert single step breakpoints according to the current state. */ |
13630 | ||
13631 | int | |
13632 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
13633 | { | |
f5ea389a | 13634 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 13635 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 13636 | |
f5ea389a | 13637 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 13638 | |
a0ff9e1a | 13639 | if (!next_pcs.empty ()) |
93f9a11f | 13640 | { |
f5ea389a | 13641 | struct frame_info *frame = get_current_frame (); |
8b86c959 | 13642 | const address_space *aspace = get_frame_address_space (frame); |
93f9a11f | 13643 | |
a0ff9e1a | 13644 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
13645 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
13646 | ||
93f9a11f YQ |
13647 | return 1; |
13648 | } | |
13649 | else | |
13650 | return 0; | |
13651 | } | |
13652 | ||
34b7e8a6 | 13653 | /* See breakpoint.h. */ |
f02253f1 HZ |
13654 | |
13655 | int | |
7c16b83e | 13656 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
accd0bcd | 13657 | const address_space *aspace, |
7c16b83e | 13658 | CORE_ADDR pc) |
1aafd4da | 13659 | { |
40cb8ca5 | 13660 | for (bp_location *loc : bp->locations ()) |
7c16b83e PA |
13661 | if (loc->inserted |
13662 | && breakpoint_location_address_match (loc, aspace, pc)) | |
13663 | return 1; | |
1aafd4da | 13664 | |
7c16b83e | 13665 | return 0; |
ef370185 JB |
13666 | } |
13667 | ||
13668 | /* Check whether a software single-step breakpoint is inserted at | |
13669 | PC. */ | |
13670 | ||
13671 | int | |
accd0bcd | 13672 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
ef370185 JB |
13673 | CORE_ADDR pc) |
13674 | { | |
43892fdf | 13675 | for (breakpoint *bpt : all_breakpoints ()) |
34b7e8a6 PA |
13676 | { |
13677 | if (bpt->type == bp_single_step | |
13678 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
13679 | return 1; | |
13680 | } | |
13681 | return 0; | |
1aafd4da UW |
13682 | } |
13683 | ||
1042e4c0 SS |
13684 | /* Tracepoint-specific operations. */ |
13685 | ||
13686 | /* Set tracepoint count to NUM. */ | |
13687 | static void | |
13688 | set_tracepoint_count (int num) | |
13689 | { | |
13690 | tracepoint_count = num; | |
4fa62494 | 13691 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
13692 | } |
13693 | ||
70221824 | 13694 | static void |
0b39b52e | 13695 | trace_command (const char *arg, int from_tty) |
1042e4c0 | 13696 | { |
ffc2605c TT |
13697 | event_location_up location = string_to_event_location (&arg, |
13698 | current_language); | |
bac7c5cf GB |
13699 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
13700 | (location.get (), true /* is_tracepoint */); | |
55aa24fb | 13701 | |
558a9d82 | 13702 | create_breakpoint (get_current_arch (), |
ffc2605c | 13703 | location.get (), |
10a636cc | 13704 | NULL, 0, arg, false, 1 /* parse arg */, |
558a9d82 YQ |
13705 | 0 /* tempflag */, |
13706 | bp_tracepoint /* type_wanted */, | |
13707 | 0 /* Ignore count */, | |
13708 | pending_break_support, | |
13709 | ops, | |
13710 | from_tty, | |
13711 | 1 /* enabled */, | |
13712 | 0 /* internal */, 0); | |
1042e4c0 SS |
13713 | } |
13714 | ||
70221824 | 13715 | static void |
0b39b52e | 13716 | ftrace_command (const char *arg, int from_tty) |
7a697b8d | 13717 | { |
ffc2605c TT |
13718 | event_location_up location = string_to_event_location (&arg, |
13719 | current_language); | |
558a9d82 | 13720 | create_breakpoint (get_current_arch (), |
ffc2605c | 13721 | location.get (), |
10a636cc | 13722 | NULL, 0, arg, false, 1 /* parse arg */, |
558a9d82 YQ |
13723 | 0 /* tempflag */, |
13724 | bp_fast_tracepoint /* type_wanted */, | |
13725 | 0 /* Ignore count */, | |
13726 | pending_break_support, | |
a0cd5f08 | 13727 | &base_breakpoint_ops, |
558a9d82 YQ |
13728 | from_tty, |
13729 | 1 /* enabled */, | |
13730 | 0 /* internal */, 0); | |
0fb4aa4b PA |
13731 | } |
13732 | ||
13733 | /* strace command implementation. Creates a static tracepoint. */ | |
13734 | ||
70221824 | 13735 | static void |
0b39b52e | 13736 | strace_command (const char *arg, int from_tty) |
0fb4aa4b | 13737 | { |
a678887d | 13738 | const struct breakpoint_ops *ops; |
ffc2605c | 13739 | event_location_up location; |
7b572efb | 13740 | enum bptype type; |
983af33b SDJ |
13741 | |
13742 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
13743 | or with a normal static tracepoint. */ | |
61012eef | 13744 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
13745 | { |
13746 | ops = &strace_marker_breakpoint_ops; | |
a20714ff | 13747 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
7b572efb | 13748 | type = bp_static_marker_tracepoint; |
f00aae0f | 13749 | } |
983af33b | 13750 | else |
f00aae0f | 13751 | { |
a0cd5f08 | 13752 | ops = &base_breakpoint_ops; |
f00aae0f | 13753 | location = string_to_event_location (&arg, current_language); |
7b572efb | 13754 | type = bp_static_tracepoint; |
f00aae0f | 13755 | } |
983af33b | 13756 | |
558a9d82 | 13757 | create_breakpoint (get_current_arch (), |
ffc2605c | 13758 | location.get (), |
10a636cc | 13759 | NULL, 0, arg, false, 1 /* parse arg */, |
558a9d82 | 13760 | 0 /* tempflag */, |
7b572efb | 13761 | type /* type_wanted */, |
558a9d82 YQ |
13762 | 0 /* Ignore count */, |
13763 | pending_break_support, | |
13764 | ops, | |
13765 | from_tty, | |
13766 | 1 /* enabled */, | |
13767 | 0 /* internal */, 0); | |
7a697b8d SS |
13768 | } |
13769 | ||
409873ef SS |
13770 | /* Set up a fake reader function that gets command lines from a linked |
13771 | list that was acquired during tracepoint uploading. */ | |
13772 | ||
13773 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 13774 | static int next_cmd; |
409873ef SS |
13775 | |
13776 | static char * | |
13777 | read_uploaded_action (void) | |
13778 | { | |
a18ba4e4 | 13779 | char *rslt = nullptr; |
409873ef | 13780 | |
a18ba4e4 SM |
13781 | if (next_cmd < this_utp->cmd_strings.size ()) |
13782 | { | |
67aa1f3c | 13783 | rslt = this_utp->cmd_strings[next_cmd].get (); |
a18ba4e4 SM |
13784 | next_cmd++; |
13785 | } | |
409873ef SS |
13786 | |
13787 | return rslt; | |
13788 | } | |
13789 | ||
00bf0b85 SS |
13790 | /* Given information about a tracepoint as recorded on a target (which |
13791 | can be either a live system or a trace file), attempt to create an | |
13792 | equivalent GDB tracepoint. This is not a reliable process, since | |
13793 | the target does not necessarily have all the information used when | |
13794 | the tracepoint was originally defined. */ | |
13795 | ||
d9b3f62e | 13796 | struct tracepoint * |
00bf0b85 | 13797 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 13798 | { |
f2fc3015 TT |
13799 | const char *addr_str; |
13800 | char small_buf[100]; | |
d9b3f62e | 13801 | struct tracepoint *tp; |
fd9b8c24 | 13802 | |
409873ef | 13803 | if (utp->at_string) |
67aa1f3c | 13804 | addr_str = utp->at_string.get (); |
409873ef SS |
13805 | else |
13806 | { | |
13807 | /* In the absence of a source location, fall back to raw | |
13808 | address. Since there is no way to confirm that the address | |
13809 | means the same thing as when the trace was started, warn the | |
13810 | user. */ | |
3e43a32a MS |
13811 | warning (_("Uploaded tracepoint %d has no " |
13812 | "source location, using raw address"), | |
409873ef | 13813 | utp->number); |
8c042590 | 13814 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
13815 | addr_str = small_buf; |
13816 | } | |
13817 | ||
13818 | /* There's not much we can do with a sequence of bytecodes. */ | |
13819 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
13820 | warning (_("Uploaded tracepoint %d condition " |
13821 | "has no source form, ignoring it"), | |
409873ef | 13822 | utp->number); |
d5551862 | 13823 | |
ffc2605c TT |
13824 | event_location_up location = string_to_event_location (&addr_str, |
13825 | current_language); | |
8cdf0e15 | 13826 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 13827 | location.get (), |
67aa1f3c | 13828 | utp->cond_string.get (), -1, addr_str, |
10a636cc | 13829 | false /* force_condition */, |
e7e0cddf | 13830 | 0 /* parse cond/thread */, |
8cdf0e15 | 13831 | 0 /* tempflag */, |
0fb4aa4b | 13832 | utp->type /* type_wanted */, |
8cdf0e15 VP |
13833 | 0 /* Ignore count */, |
13834 | pending_break_support, | |
a0cd5f08 | 13835 | &base_breakpoint_ops, |
8cdf0e15 | 13836 | 0 /* from_tty */, |
84f4c1fe | 13837 | utp->enabled /* enabled */, |
44f238bb PA |
13838 | 0 /* internal */, |
13839 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 13840 | return NULL; |
fd9b8c24 | 13841 | |
409873ef | 13842 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
13843 | tp = get_tracepoint (tracepoint_count); |
13844 | gdb_assert (tp != NULL); | |
d5551862 | 13845 | |
00bf0b85 SS |
13846 | if (utp->pass > 0) |
13847 | { | |
8c042590 | 13848 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 13849 | tp->number); |
00bf0b85 | 13850 | |
409873ef | 13851 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
13852 | } |
13853 | ||
409873ef SS |
13854 | /* If we have uploaded versions of the original commands, set up a |
13855 | special-purpose "reader" function and call the usual command line | |
13856 | reader, then pass the result to the breakpoint command-setting | |
13857 | function. */ | |
a18ba4e4 | 13858 | if (!utp->cmd_strings.empty ()) |
00bf0b85 | 13859 | { |
12973681 | 13860 | counted_command_line cmd_list; |
00bf0b85 | 13861 | |
409873ef | 13862 | this_utp = utp; |
3149d8c1 | 13863 | next_cmd = 0; |
d5551862 | 13864 | |
60b3cef2 | 13865 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
409873ef | 13866 | |
c1fc2657 | 13867 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 13868 | } |
a18ba4e4 SM |
13869 | else if (!utp->actions.empty () |
13870 | || !utp->step_actions.empty ()) | |
3e43a32a MS |
13871 | warning (_("Uploaded tracepoint %d actions " |
13872 | "have no source form, ignoring them"), | |
409873ef | 13873 | utp->number); |
00bf0b85 | 13874 | |
f196051f | 13875 | /* Copy any status information that might be available. */ |
c1fc2657 | 13876 | tp->hit_count = utp->hit_count; |
f196051f SS |
13877 | tp->traceframe_usage = utp->traceframe_usage; |
13878 | ||
00bf0b85 | 13879 | return tp; |
d9b3f62e | 13880 | } |
00bf0b85 | 13881 | |
1042e4c0 SS |
13882 | /* Print information on tracepoint number TPNUM_EXP, or all if |
13883 | omitted. */ | |
13884 | ||
13885 | static void | |
1d12d88f | 13886 | info_tracepoints_command (const char *args, int from_tty) |
1042e4c0 | 13887 | { |
79a45e25 | 13888 | struct ui_out *uiout = current_uiout; |
e5a67952 | 13889 | int num_printed; |
1042e4c0 | 13890 | |
5c458ae8 | 13891 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
d77f58be SS |
13892 | |
13893 | if (num_printed == 0) | |
1042e4c0 | 13894 | { |
e5a67952 | 13895 | if (args == NULL || *args == '\0') |
112e8700 | 13896 | uiout->message ("No tracepoints.\n"); |
d77f58be | 13897 | else |
112e8700 | 13898 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 13899 | } |
ad443146 SS |
13900 | |
13901 | default_collect_info (); | |
1042e4c0 SS |
13902 | } |
13903 | ||
4a64f543 | 13904 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
13905 | Not supported by all targets. */ |
13906 | static void | |
5fed81ff | 13907 | enable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
13908 | { |
13909 | enable_command (args, from_tty); | |
13910 | } | |
13911 | ||
4a64f543 | 13912 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
13913 | Not supported by all targets. */ |
13914 | static void | |
5fed81ff | 13915 | disable_trace_command (const char *args, int from_tty) |
1042e4c0 SS |
13916 | { |
13917 | disable_command (args, from_tty); | |
13918 | } | |
13919 | ||
4a64f543 | 13920 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 | 13921 | static void |
4495129a | 13922 | delete_trace_command (const char *arg, int from_tty) |
1042e4c0 | 13923 | { |
1042e4c0 SS |
13924 | dont_repeat (); |
13925 | ||
13926 | if (arg == 0) | |
13927 | { | |
13928 | int breaks_to_delete = 0; | |
13929 | ||
13930 | /* Delete all breakpoints if no argument. | |
dda83cd7 SM |
13931 | Do not delete internal or call-dummy breakpoints, these |
13932 | have to be deleted with an explicit breakpoint number | |
4a64f543 | 13933 | argument. */ |
f6d17b2b | 13934 | for (breakpoint *tp : all_tracepoints ()) |
1428b37a | 13935 | if (is_tracepoint (tp) && user_breakpoint_p (tp)) |
1042e4c0 SS |
13936 | { |
13937 | breaks_to_delete = 1; | |
13938 | break; | |
13939 | } | |
1042e4c0 SS |
13940 | |
13941 | /* Ask user only if there are some breakpoints to delete. */ | |
13942 | if (!from_tty | |
13943 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
13944 | { | |
1428b37a | 13945 | for (breakpoint *b : all_breakpoints_safe ()) |
46c6471b | 13946 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 13947 | delete_breakpoint (b); |
1042e4c0 SS |
13948 | } |
13949 | } | |
13950 | else | |
48649e1b | 13951 | map_breakpoint_numbers |
b926417a | 13952 | (arg, [&] (breakpoint *br) |
48649e1b | 13953 | { |
b926417a | 13954 | iterate_over_related_breakpoints (br, delete_breakpoint); |
48649e1b | 13955 | }); |
1042e4c0 SS |
13956 | } |
13957 | ||
197f0a60 TT |
13958 | /* Helper function for trace_pass_command. */ |
13959 | ||
13960 | static void | |
d9b3f62e | 13961 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 13962 | { |
d9b3f62e | 13963 | tp->pass_count = count; |
76727919 | 13964 | gdb::observers::breakpoint_modified.notify (tp); |
197f0a60 | 13965 | if (from_tty) |
6cb06a8c TT |
13966 | gdb_printf (_("Setting tracepoint %d's passcount to %d\n"), |
13967 | tp->number, count); | |
197f0a60 TT |
13968 | } |
13969 | ||
1042e4c0 SS |
13970 | /* Set passcount for tracepoint. |
13971 | ||
13972 | First command argument is passcount, second is tracepoint number. | |
13973 | If tracepoint number omitted, apply to most recently defined. | |
13974 | Also accepts special argument "all". */ | |
13975 | ||
13976 | static void | |
0b39b52e | 13977 | trace_pass_command (const char *args, int from_tty) |
1042e4c0 | 13978 | { |
d9b3f62e | 13979 | struct tracepoint *t1; |
0b39b52e | 13980 | ULONGEST count; |
1042e4c0 SS |
13981 | |
13982 | if (args == 0 || *args == 0) | |
3e43a32a MS |
13983 | error (_("passcount command requires an " |
13984 | "argument (count + optional TP num)")); | |
1042e4c0 | 13985 | |
0b39b52e | 13986 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 13987 | |
529480d0 | 13988 | args = skip_spaces (args); |
1042e4c0 SS |
13989 | if (*args && strncasecmp (args, "all", 3) == 0) |
13990 | { | |
13991 | args += 3; /* Skip special argument "all". */ | |
1042e4c0 SS |
13992 | if (*args) |
13993 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 13994 | |
f6d17b2b | 13995 | for (breakpoint *b : all_tracepoints ()) |
01add95b SM |
13996 | { |
13997 | t1 = (struct tracepoint *) b; | |
13998 | trace_pass_set_count (t1, count, from_tty); | |
13999 | } | |
197f0a60 TT |
14000 | } |
14001 | else if (*args == '\0') | |
1042e4c0 | 14002 | { |
5fa1d40e | 14003 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 14004 | if (t1) |
197f0a60 TT |
14005 | trace_pass_set_count (t1, count, from_tty); |
14006 | } | |
14007 | else | |
14008 | { | |
bfd28288 PA |
14009 | number_or_range_parser parser (args); |
14010 | while (!parser.finished ()) | |
1042e4c0 | 14011 | { |
bfd28288 | 14012 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
14013 | if (t1) |
14014 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
14015 | } |
14016 | } | |
1042e4c0 SS |
14017 | } |
14018 | ||
d9b3f62e | 14019 | struct tracepoint * |
1042e4c0 SS |
14020 | get_tracepoint (int num) |
14021 | { | |
f6d17b2b | 14022 | for (breakpoint *t : all_tracepoints ()) |
1042e4c0 | 14023 | if (t->number == num) |
d9b3f62e | 14024 | return (struct tracepoint *) t; |
1042e4c0 SS |
14025 | |
14026 | return NULL; | |
14027 | } | |
14028 | ||
d5551862 SS |
14029 | /* Find the tracepoint with the given target-side number (which may be |
14030 | different from the tracepoint number after disconnecting and | |
14031 | reconnecting). */ | |
14032 | ||
d9b3f62e | 14033 | struct tracepoint * |
d5551862 SS |
14034 | get_tracepoint_by_number_on_target (int num) |
14035 | { | |
f6d17b2b | 14036 | for (breakpoint *b : all_tracepoints ()) |
d9b3f62e PA |
14037 | { |
14038 | struct tracepoint *t = (struct tracepoint *) b; | |
14039 | ||
14040 | if (t->number_on_target == num) | |
14041 | return t; | |
14042 | } | |
d5551862 SS |
14043 | |
14044 | return NULL; | |
14045 | } | |
14046 | ||
1042e4c0 | 14047 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 14048 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
14049 | If the argument is missing, the most recent tracepoint |
14050 | (tracepoint_count) is returned. */ | |
14051 | ||
d9b3f62e | 14052 | struct tracepoint * |
0b39b52e | 14053 | get_tracepoint_by_number (const char **arg, |
bfd28288 | 14054 | number_or_range_parser *parser) |
1042e4c0 | 14055 | { |
1042e4c0 | 14056 | int tpnum; |
0b39b52e | 14057 | const char *instring = arg == NULL ? NULL : *arg; |
1042e4c0 | 14058 | |
bfd28288 | 14059 | if (parser != NULL) |
197f0a60 | 14060 | { |
bfd28288 PA |
14061 | gdb_assert (!parser->finished ()); |
14062 | tpnum = parser->get_number (); | |
197f0a60 TT |
14063 | } |
14064 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 14065 | tpnum = tracepoint_count; |
1042e4c0 | 14066 | else |
197f0a60 | 14067 | tpnum = get_number (arg); |
1042e4c0 SS |
14068 | |
14069 | if (tpnum <= 0) | |
14070 | { | |
14071 | if (instring && *instring) | |
6cb06a8c TT |
14072 | gdb_printf (_("bad tracepoint number at or near '%s'\n"), |
14073 | instring); | |
1042e4c0 | 14074 | else |
6cb06a8c | 14075 | gdb_printf (_("No previous tracepoint\n")); |
1042e4c0 SS |
14076 | return NULL; |
14077 | } | |
14078 | ||
f6d17b2b | 14079 | for (breakpoint *t : all_tracepoints ()) |
1042e4c0 | 14080 | if (t->number == tpnum) |
d9b3f62e | 14081 | return (struct tracepoint *) t; |
1042e4c0 | 14082 | |
6cb06a8c | 14083 | gdb_printf ("No tracepoint number %d.\n", tpnum); |
1042e4c0 SS |
14084 | return NULL; |
14085 | } | |
14086 | ||
d9b3f62e PA |
14087 | void |
14088 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
14089 | { | |
14090 | if (b->thread != -1) | |
6cb06a8c | 14091 | gdb_printf (fp, " thread %d", b->thread); |
d9b3f62e PA |
14092 | |
14093 | if (b->task != 0) | |
6cb06a8c | 14094 | gdb_printf (fp, " task %d", b->task); |
d9b3f62e | 14095 | |
6cb06a8c | 14096 | gdb_printf (fp, "\n"); |
d9b3f62e PA |
14097 | } |
14098 | ||
6149aea9 PA |
14099 | /* Save information on user settable breakpoints (watchpoints, etc) to |
14100 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
14101 | on each breakpoint and only include the ones for which it returns | |
f2478a7e | 14102 | true. */ |
6149aea9 | 14103 | |
1042e4c0 | 14104 | static void |
4495129a | 14105 | save_breakpoints (const char *filename, int from_tty, |
f2478a7e | 14106 | bool (*filter) (const struct breakpoint *)) |
1042e4c0 | 14107 | { |
6149aea9 | 14108 | int any = 0; |
6149aea9 | 14109 | int extra_trace_bits = 0; |
1042e4c0 | 14110 | |
6149aea9 PA |
14111 | if (filename == 0 || *filename == 0) |
14112 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
14113 | |
14114 | /* See if we have anything to save. */ | |
43892fdf | 14115 | for (breakpoint *tp : all_breakpoints ()) |
01add95b SM |
14116 | { |
14117 | /* Skip internal and momentary breakpoints. */ | |
14118 | if (!user_breakpoint_p (tp)) | |
14119 | continue; | |
6149aea9 | 14120 | |
01add95b SM |
14121 | /* If we have a filter, only save the breakpoints it accepts. */ |
14122 | if (filter && !filter (tp)) | |
14123 | continue; | |
6149aea9 | 14124 | |
01add95b | 14125 | any = 1; |
6149aea9 | 14126 | |
01add95b SM |
14127 | if (is_tracepoint (tp)) |
14128 | { | |
14129 | extra_trace_bits = 1; | |
6149aea9 | 14130 | |
01add95b SM |
14131 | /* We can stop searching. */ |
14132 | break; | |
14133 | } | |
14134 | } | |
6149aea9 PA |
14135 | |
14136 | if (!any) | |
1042e4c0 | 14137 | { |
6149aea9 | 14138 | warning (_("Nothing to save.")); |
1042e4c0 SS |
14139 | return; |
14140 | } | |
14141 | ||
ee0c3293 | 14142 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
14143 | |
14144 | stdio_file fp; | |
14145 | ||
ee0c3293 | 14146 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 14147 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 14148 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 14149 | |
6149aea9 | 14150 | if (extra_trace_bits) |
d7e74731 | 14151 | save_trace_state_variables (&fp); |
8bf6485c | 14152 | |
43892fdf | 14153 | for (breakpoint *tp : all_breakpoints ()) |
01add95b SM |
14154 | { |
14155 | /* Skip internal and momentary breakpoints. */ | |
14156 | if (!user_breakpoint_p (tp)) | |
14157 | continue; | |
8bf6485c | 14158 | |
01add95b SM |
14159 | /* If we have a filter, only save the breakpoints it accepts. */ |
14160 | if (filter && !filter (tp)) | |
14161 | continue; | |
6149aea9 | 14162 | |
c47614fe | 14163 | tp->print_recreate (&fp); |
1042e4c0 | 14164 | |
01add95b SM |
14165 | /* Note, we can't rely on tp->number for anything, as we can't |
14166 | assume the recreated breakpoint numbers will match. Use $bpnum | |
14167 | instead. */ | |
6149aea9 | 14168 | |
01add95b | 14169 | if (tp->cond_string) |
6f781ee3 | 14170 | fp.printf (" condition $bpnum %s\n", tp->cond_string.get ()); |
6149aea9 | 14171 | |
01add95b SM |
14172 | if (tp->ignore_count) |
14173 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); | |
6149aea9 | 14174 | |
01add95b SM |
14175 | if (tp->type != bp_dprintf && tp->commands) |
14176 | { | |
14177 | fp.puts (" commands\n"); | |
1042e4c0 | 14178 | |
01add95b SM |
14179 | current_uiout->redirect (&fp); |
14180 | try | |
14181 | { | |
14182 | print_command_lines (current_uiout, tp->commands.get (), 2); | |
14183 | } | |
14184 | catch (const gdb_exception &ex) | |
14185 | { | |
14186 | current_uiout->redirect (NULL); | |
14187 | throw; | |
14188 | } | |
6149aea9 | 14189 | |
01add95b SM |
14190 | current_uiout->redirect (NULL); |
14191 | fp.puts (" end\n"); | |
14192 | } | |
6149aea9 | 14193 | |
01add95b SM |
14194 | if (tp->enable_state == bp_disabled) |
14195 | fp.puts ("disable $bpnum\n"); | |
6149aea9 | 14196 | |
01add95b SM |
14197 | /* If this is a multi-location breakpoint, check if the locations |
14198 | should be individually disabled. Watchpoint locations are | |
14199 | special, and not user visible. */ | |
14200 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
14201 | { | |
14202 | int n = 1; | |
40cb8ca5 | 14203 | |
01add95b SM |
14204 | for (bp_location *loc : tp->locations ()) |
14205 | { | |
14206 | if (!loc->enabled) | |
14207 | fp.printf ("disable $bpnum.%d\n", n); | |
14208 | ||
14209 | n++; | |
14210 | } | |
14211 | } | |
14212 | } | |
8bf6485c | 14213 | |
e0700ba4 SM |
14214 | if (extra_trace_bits && !default_collect.empty ()) |
14215 | fp.printf ("set default-collect %s\n", default_collect.c_str ()); | |
8bf6485c | 14216 | |
1042e4c0 | 14217 | if (from_tty) |
6cb06a8c | 14218 | gdb_printf (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
14219 | } |
14220 | ||
14221 | /* The `save breakpoints' command. */ | |
14222 | ||
14223 | static void | |
4495129a | 14224 | save_breakpoints_command (const char *args, int from_tty) |
6149aea9 PA |
14225 | { |
14226 | save_breakpoints (args, from_tty, NULL); | |
14227 | } | |
14228 | ||
14229 | /* The `save tracepoints' command. */ | |
14230 | ||
14231 | static void | |
4495129a | 14232 | save_tracepoints_command (const char *args, int from_tty) |
6149aea9 PA |
14233 | { |
14234 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
14235 | } |
14236 | ||
c906108c | 14237 | \f |
629500fa KS |
14238 | /* This help string is used to consolidate all the help string for specifying |
14239 | locations used by several commands. */ | |
14240 | ||
14241 | #define LOCATION_HELP_STRING \ | |
14242 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
14243 | source filename, function name, label name, and line number.\n\ | |
14244 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
14245 | function \"fact\" in the file \"factorial.c\", use\n\ | |
14246 | \"factorial.c:fact:the_top\".\n\ | |
14247 | \n\ | |
14248 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
14249 | program. Example: To specify the fourth byte past the start function\n\ | |
14250 | \"main\", use \"*main + 4\".\n\ | |
14251 | \n\ | |
14252 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
14253 | syntax to specify location parameters.\n\ | |
14254 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
14255 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
a20714ff PA |
14256 | -function fact -label the_top\".\n\ |
14257 | \n\ | |
14258 | By default, a specified function is matched against the program's\n\ | |
14259 | functions in all scopes. For C++, this means in all namespaces and\n\ | |
14260 | classes. For Ada, this means in all packages. E.g., in C++,\n\ | |
14261 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ | |
14262 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ | |
89549d7f | 14263 | specified name as a complete fully-qualified name instead." |
629500fa | 14264 | |
4a64f543 MS |
14265 | /* This help string is used for the break, hbreak, tbreak and thbreak |
14266 | commands. It is defined as a macro to prevent duplication. | |
14267 | COMMAND should be a string constant containing the name of the | |
14268 | command. */ | |
629500fa | 14269 | |
31e2b00f | 14270 | #define BREAK_ARGS_HELP(command) \ |
733d554a TBA |
14271 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM]\n\ |
14272 | \t[-force-condition] [if CONDITION]\n\ | |
fb7b5af4 SDJ |
14273 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ |
14274 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
14275 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
14276 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
14277 | LOCATION may be a linespec, address, or explicit location as described\n\ |
14278 | below.\n\ | |
14279 | \n\ | |
dc10affe PA |
14280 | With no LOCATION, uses current execution address of the selected\n\ |
14281 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
14282 | \n\ |
14283 | THREADNUM is the number from \"info threads\".\n\ | |
14284 | CONDITION is a boolean expression.\n\ | |
733d554a TBA |
14285 | \n\ |
14286 | With the \"-force-condition\" flag, the condition is defined even when\n\ | |
14287 | it is invalid for all current locations.\n\ | |
89549d7f | 14288 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
14289 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
14290 | conditions are different.\n\ | |
31e2b00f AS |
14291 | \n\ |
14292 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
14293 | ||
44feb3ce TT |
14294 | /* List of subcommands for "catch". */ |
14295 | static struct cmd_list_element *catch_cmdlist; | |
14296 | ||
14297 | /* List of subcommands for "tcatch". */ | |
14298 | static struct cmd_list_element *tcatch_cmdlist; | |
14299 | ||
9ac4176b | 14300 | void |
a121b7c1 | 14301 | add_catch_command (const char *name, const char *docstring, |
5538b03c | 14302 | cmd_func_ftype *func, |
625e8578 | 14303 | completer_ftype *completer, |
44feb3ce TT |
14304 | void *user_data_catch, |
14305 | void *user_data_tcatch) | |
14306 | { | |
14307 | struct cmd_list_element *command; | |
14308 | ||
0450cc4c | 14309 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce | 14310 | &catch_cmdlist); |
5538b03c | 14311 | command->func = func; |
0f8e2034 | 14312 | command->set_context (user_data_catch); |
a96d9b2e | 14313 | set_cmd_completer (command, completer); |
44feb3ce | 14314 | |
0450cc4c | 14315 | command = add_cmd (name, class_breakpoint, docstring, |
44feb3ce | 14316 | &tcatch_cmdlist); |
5538b03c | 14317 | command->func = func; |
0f8e2034 | 14318 | command->set_context (user_data_tcatch); |
a96d9b2e | 14319 | set_cmd_completer (command, completer); |
44feb3ce TT |
14320 | } |
14321 | ||
0574c78f GB |
14322 | /* Zero if any of the breakpoint's locations could be a location where |
14323 | functions have been inlined, nonzero otherwise. */ | |
14324 | ||
14325 | static int | |
14326 | is_non_inline_function (struct breakpoint *b) | |
14327 | { | |
14328 | /* The shared library event breakpoint is set on the address of a | |
14329 | non-inline function. */ | |
14330 | if (b->type == bp_shlib_event) | |
14331 | return 1; | |
14332 | ||
14333 | return 0; | |
14334 | } | |
14335 | ||
14336 | /* Nonzero if the specified PC cannot be a location where functions | |
14337 | have been inlined. */ | |
14338 | ||
14339 | int | |
accd0bcd | 14340 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
c272a98c | 14341 | const target_waitstatus &ws) |
0574c78f | 14342 | { |
43892fdf | 14343 | for (breakpoint *b : all_breakpoints ()) |
0574c78f GB |
14344 | { |
14345 | if (!is_non_inline_function (b)) | |
14346 | continue; | |
14347 | ||
40cb8ca5 | 14348 | for (bp_location *bl : b->locations ()) |
0574c78f GB |
14349 | { |
14350 | if (!bl->shlib_disabled | |
09ac7c10 | 14351 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
14352 | return 1; |
14353 | } | |
14354 | } | |
14355 | ||
14356 | return 0; | |
14357 | } | |
14358 | ||
2f202fde JK |
14359 | /* Remove any references to OBJFILE which is going to be freed. */ |
14360 | ||
14361 | void | |
14362 | breakpoint_free_objfile (struct objfile *objfile) | |
14363 | { | |
48d7020b | 14364 | for (bp_location *loc : all_bp_locations ()) |
3c86fae3 | 14365 | if (loc->symtab != NULL && loc->symtab->compunit ()->objfile () == objfile) |
2f202fde JK |
14366 | loc->symtab = NULL; |
14367 | } | |
14368 | ||
8bfd80db YQ |
14369 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
14370 | ||
14371 | static struct cmd_list_element *enablebreaklist = NULL; | |
14372 | ||
8588b356 SM |
14373 | /* See breakpoint.h. */ |
14374 | ||
14375 | cmd_list_element *commands_cmd_element = nullptr; | |
14376 | ||
6c265988 | 14377 | void _initialize_breakpoint (); |
c906108c | 14378 | void |
6c265988 | 14379 | _initialize_breakpoint () |
c906108c SS |
14380 | { |
14381 | struct cmd_list_element *c; | |
14382 | ||
c90e7d63 SM |
14383 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib, |
14384 | "breakpoint"); | |
14385 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile, | |
14386 | "breakpoint"); | |
14387 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change, | |
14388 | "breakpoint"); | |
84acb35a | 14389 | |
c906108c SS |
14390 | breakpoint_chain = 0; |
14391 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
14392 | before a breakpoint is set. */ | |
14393 | breakpoint_count = 0; | |
14394 | ||
1042e4c0 SS |
14395 | tracepoint_count = 0; |
14396 | ||
1bedd215 AC |
14397 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
14398 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
14399 | Usage is `ignore N COUNT'.")); | |
c906108c | 14400 | |
8588b356 SM |
14401 | commands_cmd_element = add_com ("commands", class_breakpoint, |
14402 | commands_command, _("\ | |
18da0c51 MG |
14403 | Set commands to be executed when the given breakpoints are hit.\n\ |
14404 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
14405 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
14406 | (e.g. `5-7').\n\ | |
c906108c SS |
14407 | With no argument, the targeted breakpoint is the last one set.\n\ |
14408 | The commands themselves follow starting on the next line.\n\ | |
14409 | Type a line containing \"end\" to indicate the end of them.\n\ | |
14410 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 14411 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 14412 | |
b1d4d8d1 TBA |
14413 | const auto cc_opts = make_condition_command_options_def_group (nullptr); |
14414 | static std::string condition_command_help | |
14415 | = gdb::option::build_help (_("\ | |
1bedd215 | 14416 | Specify breakpoint number N to break only if COND is true.\n\ |
b1d4d8d1 | 14417 | Usage is `condition [OPTION] N COND', where N is an integer and COND\n\ |
733d554a | 14418 | is an expression to be evaluated whenever breakpoint N is reached.\n\ |
b1d4d8d1 TBA |
14419 | \n\ |
14420 | Options:\n\ | |
14421 | %OPTIONS%"), cc_opts); | |
14422 | ||
14423 | c = add_com ("condition", class_breakpoint, condition_command, | |
14424 | condition_command_help.c_str ()); | |
14425 | set_cmd_completer_handle_brkchars (c, condition_completer); | |
c906108c | 14426 | |
1bedd215 | 14427 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 14428 | Set a temporary breakpoint.\n\ |
c906108c SS |
14429 | Like \"break\" except the breakpoint is only temporary,\n\ |
14430 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
14431 | by using \"enable delete\" on the breakpoint number.\n\ |
14432 | \n" | |
14433 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 14434 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 14435 | |
1bedd215 | 14436 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 14437 | Set a hardware assisted breakpoint.\n\ |
c906108c | 14438 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
14439 | some target hardware may not have this support.\n\ |
14440 | \n" | |
14441 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 14442 | set_cmd_completer (c, location_completer); |
c906108c | 14443 | |
1bedd215 | 14444 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 14445 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 14446 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
14447 | so it will be deleted when hit.\n\ |
14448 | \n" | |
14449 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 14450 | set_cmd_completer (c, location_completer); |
c906108c | 14451 | |
3947f654 SM |
14452 | cmd_list_element *enable_cmd |
14453 | = add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ | |
590042fc PW |
14454 | Enable all or some breakpoints.\n\ |
14455 | Usage: enable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
14456 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
14457 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
14458 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 14459 | With a subcommand you can enable temporarily."), |
3947f654 | 14460 | &enablelist, 1, &cmdlist); |
c906108c | 14461 | |
3947f654 | 14462 | add_com_alias ("en", enable_cmd, class_breakpoint, 1); |
c906108c | 14463 | |
84951ab5 | 14464 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
590042fc PW |
14465 | Enable all or some breakpoints.\n\ |
14466 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
14467 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
14468 | This is used to cancel the effect of the \"disable\" command.\n\ | |
89549d7f | 14469 | May be abbreviated to simply \"enable\"."), |
2f822da5 | 14470 | &enablebreaklist, 1, &enablelist); |
c906108c | 14471 | |
1a966eab | 14472 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
14473 | Enable some breakpoints for one hit.\n\ |
14474 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ | |
1a966eab | 14475 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
c906108c SS |
14476 | &enablebreaklist); |
14477 | ||
1a966eab | 14478 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
14479 | Enable some breakpoints and delete when hit.\n\ |
14480 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ | |
1a966eab | 14481 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
14482 | &enablebreaklist); |
14483 | ||
816338b5 | 14484 | add_cmd ("count", no_class, enable_count_command, _("\ |
590042fc PW |
14485 | Enable some breakpoints for COUNT hits.\n\ |
14486 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
14487 | If a breakpoint is hit while enabled in this fashion,\n\ |
14488 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
14489 | &enablebreaklist); | |
14490 | ||
1a966eab | 14491 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
590042fc PW |
14492 | Enable some breakpoints and delete when hit.\n\ |
14493 | Usage: enable delete BREAKPOINTNUM...\n\ | |
1a966eab | 14494 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
c906108c SS |
14495 | &enablelist); |
14496 | ||
1a966eab | 14497 | add_cmd ("once", no_class, enable_once_command, _("\ |
590042fc PW |
14498 | Enable some breakpoints for one hit.\n\ |
14499 | Usage: enable once BREAKPOINTNUM...\n\ | |
1a966eab | 14500 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
816338b5 SS |
14501 | &enablelist); |
14502 | ||
14503 | add_cmd ("count", no_class, enable_count_command, _("\ | |
590042fc PW |
14504 | Enable some breakpoints for COUNT hits.\n\ |
14505 | Usage: enable count COUNT BREAKPOINTNUM...\n\ | |
816338b5 SS |
14506 | If a breakpoint is hit while enabled in this fashion,\n\ |
14507 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
14508 | &enablelist); |
14509 | ||
3947f654 SM |
14510 | cmd_list_element *disable_cmd |
14511 | = add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ | |
590042fc PW |
14512 | Disable all or some breakpoints.\n\ |
14513 | Usage: disable [BREAKPOINTNUM]...\n\ | |
c906108c SS |
14514 | Arguments are breakpoint numbers with spaces in between.\n\ |
14515 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 14516 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
3947f654 SM |
14517 | &disablelist, 1, &cmdlist); |
14518 | add_com_alias ("dis", disable_cmd, class_breakpoint, 1); | |
14519 | add_com_alias ("disa", disable_cmd, class_breakpoint, 1); | |
c906108c | 14520 | |
57b4f16e | 14521 | add_cmd ("breakpoints", class_breakpoint, disable_command, _("\ |
590042fc PW |
14522 | Disable all or some breakpoints.\n\ |
14523 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
14524 | Arguments are breakpoint numbers with spaces in between.\n\ |
14525 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 14526 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 14527 | This command may be abbreviated \"disable\"."), |
c906108c SS |
14528 | &disablelist); |
14529 | ||
3947f654 SM |
14530 | cmd_list_element *delete_cmd |
14531 | = add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ | |
590042fc PW |
14532 | Delete all or some breakpoints.\n\ |
14533 | Usage: delete [BREAKPOINTNUM]...\n\ | |
c906108c SS |
14534 | Arguments are breakpoint numbers with spaces in between.\n\ |
14535 | To delete all breakpoints, give no argument.\n\ | |
14536 | \n\ | |
590042fc | 14537 | Also a prefix command for deletion of other GDB objects."), |
3947f654 SM |
14538 | &deletelist, 1, &cmdlist); |
14539 | add_com_alias ("d", delete_cmd, class_breakpoint, 1); | |
14540 | add_com_alias ("del", delete_cmd, class_breakpoint, 1); | |
c906108c | 14541 | |
57b4f16e | 14542 | add_cmd ("breakpoints", class_breakpoint, delete_command, _("\ |
590042fc PW |
14543 | Delete all or some breakpoints or auto-display expressions.\n\ |
14544 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ | |
c906108c SS |
14545 | Arguments are breakpoint numbers with spaces in between.\n\ |
14546 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 14547 | This command may be abbreviated \"delete\"."), |
c906108c SS |
14548 | &deletelist); |
14549 | ||
3947f654 SM |
14550 | cmd_list_element *clear_cmd |
14551 | = add_com ("clear", class_breakpoint, clear_command, _("\ | |
629500fa KS |
14552 | Clear breakpoint at specified location.\n\ |
14553 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
14554 | \n\ |
14555 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa | 14556 | is executing in.\n" |
89549d7f | 14557 | "\n" LOCATION_HELP_STRING "\n\n\ |
1bedd215 | 14558 | See also the \"delete\" command which clears breakpoints by number.")); |
3947f654 | 14559 | add_com_alias ("cl", clear_cmd, class_breakpoint, 1); |
c906108c | 14560 | |
3947f654 SM |
14561 | cmd_list_element *break_cmd |
14562 | = add_com ("break", class_breakpoint, break_command, _("\ | |
629500fa | 14563 | Set breakpoint at specified location.\n" |
31e2b00f | 14564 | BREAK_ARGS_HELP ("break"))); |
3947f654 | 14565 | set_cmd_completer (break_cmd, location_completer); |
c94fdfd0 | 14566 | |
3947f654 SM |
14567 | add_com_alias ("b", break_cmd, class_run, 1); |
14568 | add_com_alias ("br", break_cmd, class_run, 1); | |
14569 | add_com_alias ("bre", break_cmd, class_run, 1); | |
14570 | add_com_alias ("brea", break_cmd, class_run, 1); | |
c906108c | 14571 | |
e0f25bd9 SM |
14572 | cmd_list_element *info_breakpoints_cmd |
14573 | = add_info ("breakpoints", info_breakpoints_command, _("\ | |
e5a67952 | 14574 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
14575 | The \"Type\" column indicates one of:\n\ |
14576 | \tbreakpoint - normal breakpoint\n\ | |
14577 | \twatchpoint - watchpoint\n\ | |
14578 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
14579 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
14580 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
14581 | address and file/line number respectively.\n\ |
14582 | \n\ | |
14583 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14584 | are set to the address of the last breakpoint listed unless the command\n\ |
14585 | is prefixed with \"server \".\n\n\ | |
c906108c | 14586 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 14587 | breakpoint set.")); |
c906108c | 14588 | |
e0f25bd9 | 14589 | add_info_alias ("b", info_breakpoints_cmd, 1); |
6b04bdb7 | 14590 | |
1a966eab AC |
14591 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
14592 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
14593 | The \"Type\" column indicates one of:\n\ |
14594 | \tbreakpoint - normal breakpoint\n\ | |
14595 | \twatchpoint - watchpoint\n\ | |
14596 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
14597 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
14598 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
14599 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
14600 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
14601 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
14602 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
14603 | address and file/line number respectively.\n\ |
14604 | \n\ | |
14605 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
14606 | are set to the address of the last breakpoint listed unless the command\n\ |
14607 | is prefixed with \"server \".\n\n\ | |
c906108c | 14608 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 14609 | breakpoint set."), |
c906108c SS |
14610 | &maintenanceinfolist); |
14611 | ||
3b6acaee | 14612 | add_basic_prefix_cmd ("catch", class_breakpoint, _("\ |
44feb3ce | 14613 | Set catchpoints to catch events."), |
2f822da5 | 14614 | &catch_cmdlist, |
3b6acaee | 14615 | 0/*allow-unknown*/, &cmdlist); |
44feb3ce | 14616 | |
3b6acaee | 14617 | add_basic_prefix_cmd ("tcatch", class_breakpoint, _("\ |
44feb3ce | 14618 | Set temporary catchpoints to catch events."), |
2f822da5 | 14619 | &tcatch_cmdlist, |
3b6acaee | 14620 | 0/*allow-unknown*/, &cmdlist); |
44feb3ce | 14621 | |
a15a5258 AB |
14622 | const auto opts = make_watch_options_def_group (nullptr); |
14623 | ||
14624 | static const std::string watch_help = gdb::option::build_help (_("\ | |
14625 | Set a watchpoint for EXPRESSION.\n\ | |
14626 | Usage: watch [-location] EXPRESSION\n\ | |
14627 | \n\ | |
14628 | Options:\n\ | |
14629 | %OPTIONS%\n\ | |
14630 | \n\ | |
c906108c | 14631 | A watchpoint stops execution of your program whenever the value of\n\ |
a15a5258 AB |
14632 | an expression changes."), opts); |
14633 | c = add_com ("watch", class_breakpoint, watch_command, | |
14634 | watch_help.c_str ()); | |
14635 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
14636 | ||
14637 | static const std::string rwatch_help = gdb::option::build_help (_("\ | |
14638 | Set a read watchpoint for EXPRESSION.\n\ | |
14639 | Usage: rwatch [-location] EXPRESSION\n\ | |
14640 | \n\ | |
14641 | Options:\n\ | |
14642 | %OPTIONS%\n\ | |
14643 | \n\ | |
14644 | A read watchpoint stops execution of your program whenever the value of\n\ | |
14645 | an expression is read."), opts); | |
14646 | c = add_com ("rwatch", class_breakpoint, rwatch_command, | |
14647 | rwatch_help.c_str ()); | |
14648 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
14649 | ||
14650 | static const std::string awatch_help = gdb::option::build_help (_("\ | |
14651 | Set an access watchpoint for EXPRESSION.\n\ | |
14652 | Usage: awatch [-location] EXPRESSION\n\ | |
14653 | \n\ | |
14654 | Options:\n\ | |
14655 | %OPTIONS%\n\ | |
14656 | \n\ | |
14657 | An access watchpoint stops execution of your program whenever the value\n\ | |
14658 | of an expression is either read or written."), opts); | |
14659 | c = add_com ("awatch", class_breakpoint, awatch_command, | |
14660 | awatch_help.c_str ()); | |
14661 | set_cmd_completer_handle_brkchars (c, watch_command_completer); | |
c906108c | 14662 | |
11db9430 | 14663 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 14664 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 14665 | |
920d2a44 AC |
14666 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
14667 | respond to changes - contrary to the description. */ | |
85c07804 AC |
14668 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
14669 | &can_use_hw_watchpoints, _("\ | |
14670 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
14671 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
14672 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
14673 | such is available. (However, any hardware watchpoints that were\n\ | |
14674 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
14675 | hardware.)"), |
14676 | NULL, | |
920d2a44 | 14677 | show_can_use_hw_watchpoints, |
85c07804 | 14678 | &setlist, &showlist); |
c906108c SS |
14679 | |
14680 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 14681 | |
1042e4c0 SS |
14682 | /* Tracepoint manipulation commands. */ |
14683 | ||
3947f654 SM |
14684 | cmd_list_element *trace_cmd |
14685 | = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 14686 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
14687 | \n" |
14688 | BREAK_ARGS_HELP ("trace") "\n\ | |
14689 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
3947f654 | 14690 | set_cmd_completer (trace_cmd, location_completer); |
1042e4c0 | 14691 | |
3947f654 SM |
14692 | add_com_alias ("tp", trace_cmd, class_breakpoint, 0); |
14693 | add_com_alias ("tr", trace_cmd, class_breakpoint, 1); | |
14694 | add_com_alias ("tra", trace_cmd, class_breakpoint, 1); | |
14695 | add_com_alias ("trac", trace_cmd, class_breakpoint, 1); | |
1042e4c0 | 14696 | |
7a697b8d | 14697 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 14698 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
14699 | \n" |
14700 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
14701 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14702 | set_cmd_completer (c, location_completer); | |
14703 | ||
0fb4aa4b | 14704 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 14705 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
14706 | \n\ |
14707 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
14708 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
14709 | or -m MARKER_ID.\n\n\ | |
14710 | If a marker id is specified, probe the marker with that name. With\n\ | |
14711 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
14712 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
14713 | This collects arbitrary user data passed in the probe point call to the\n\ | |
14714 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
14715 | by printing the $_sdata variable like any other convenience variable.\n\ | |
14716 | \n\ | |
14717 | CONDITION is a boolean expression.\n\ | |
89549d7f | 14718 | \n" LOCATION_HELP_STRING "\n\n\ |
d41c0fc8 PA |
14719 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
14720 | conditions are different.\n\ | |
0fb4aa4b PA |
14721 | \n\ |
14722 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
14723 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
14724 | set_cmd_completer (c, location_completer); | |
14725 | ||
e0f25bd9 SM |
14726 | cmd_list_element *info_tracepoints_cmd |
14727 | = add_info ("tracepoints", info_tracepoints_command, _("\ | |
e5a67952 | 14728 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
14729 | Convenience variable \"$tpnum\" contains the number of the\n\ |
14730 | last tracepoint set.")); | |
14731 | ||
e0f25bd9 | 14732 | add_info_alias ("tp", info_tracepoints_cmd, 1); |
1042e4c0 | 14733 | |
5e84b7ee SM |
14734 | cmd_list_element *delete_tracepoints_cmd |
14735 | = add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
1042e4c0 SS |
14736 | Delete specified tracepoints.\n\ |
14737 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14738 | No argument means delete all tracepoints."), | |
14739 | &deletelist); | |
5e84b7ee | 14740 | add_alias_cmd ("tr", delete_tracepoints_cmd, class_trace, 1, &deletelist); |
1042e4c0 SS |
14741 | |
14742 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
14743 | Disable specified tracepoints.\n\ | |
14744 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14745 | No argument means disable all tracepoints."), | |
14746 | &disablelist); | |
14747 | deprecate_cmd (c, "disable"); | |
14748 | ||
14749 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
14750 | Enable specified tracepoints.\n\ | |
14751 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
14752 | No argument means enable all tracepoints."), | |
14753 | &enablelist); | |
14754 | deprecate_cmd (c, "enable"); | |
14755 | ||
14756 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
14757 | Set the passcount for a tracepoint.\n\ | |
14758 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
14759 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
14760 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
14761 | ||
0743fc83 TT |
14762 | add_basic_prefix_cmd ("save", class_breakpoint, |
14763 | _("Save breakpoint definitions as a script."), | |
2f822da5 | 14764 | &save_cmdlist, |
0743fc83 | 14765 | 0/*allow-unknown*/, &cmdlist); |
6149aea9 PA |
14766 | |
14767 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
14768 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 14769 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
14770 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
14771 | session to restore them."), | |
14772 | &save_cmdlist); | |
14773 | set_cmd_completer (c, filename_completer); | |
14774 | ||
3947f654 SM |
14775 | cmd_list_element *save_tracepoints_cmd |
14776 | = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 14777 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
14778 | Use the 'source' command in another debug session to restore them."), |
14779 | &save_cmdlist); | |
3947f654 | 14780 | set_cmd_completer (save_tracepoints_cmd, filename_completer); |
1042e4c0 | 14781 | |
3947f654 | 14782 | c = add_com_alias ("save-tracepoints", save_tracepoints_cmd, class_trace, 0); |
6149aea9 PA |
14783 | deprecate_cmd (c, "save tracepoints"); |
14784 | ||
f54bdb6d SM |
14785 | add_setshow_prefix_cmd ("breakpoint", class_maintenance, |
14786 | _("\ | |
590042fc | 14787 | Breakpoint specific settings.\n\ |
fa8d40ab | 14788 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 14789 | pending breakpoint behavior."), |
f54bdb6d | 14790 | _("\ |
590042fc | 14791 | Breakpoint specific settings.\n\ |
fa8d40ab | 14792 | Configure various breakpoint-specific variables such as\n\ |
590042fc | 14793 | pending breakpoint behavior."), |
f54bdb6d SM |
14794 | &breakpoint_set_cmdlist, &breakpoint_show_cmdlist, |
14795 | &setlist, &showlist); | |
fa8d40ab | 14796 | |
7915a72c AC |
14797 | add_setshow_auto_boolean_cmd ("pending", no_class, |
14798 | &pending_break_support, _("\ | |
14799 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
14800 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
14801 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
14802 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
14803 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 14804 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 14805 | NULL, |
920d2a44 | 14806 | show_pending_break_support, |
6e1d7d6c AC |
14807 | &breakpoint_set_cmdlist, |
14808 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
14809 | |
14810 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
14811 | |
14812 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
14813 | &automatic_hardware_breakpoints, _("\ | |
14814 | Set automatic usage of hardware breakpoints."), _("\ | |
14815 | Show automatic usage of hardware breakpoints."), _("\ | |
14816 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
14817 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
14818 | a warning will be emitted for such breakpoints."), | |
14819 | NULL, | |
14820 | show_automatic_hardware_breakpoints, | |
14821 | &breakpoint_set_cmdlist, | |
14822 | &breakpoint_show_cmdlist); | |
74960c60 | 14823 | |
a25a5a45 PA |
14824 | add_setshow_boolean_cmd ("always-inserted", class_support, |
14825 | &always_inserted_mode, _("\ | |
74960c60 VP |
14826 | Set mode for inserting breakpoints."), _("\ |
14827 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
14828 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
14829 | they're created, kept inserted even when execution stops, and removed\n\ | |
14830 | only when the user deletes them. When this mode is off (the default),\n\ | |
14831 | breakpoints are inserted only when execution continues, and removed\n\ | |
14832 | when execution stops."), | |
72d0e2c5 YQ |
14833 | NULL, |
14834 | &show_always_inserted_mode, | |
14835 | &breakpoint_set_cmdlist, | |
14836 | &breakpoint_show_cmdlist); | |
f1310107 | 14837 | |
b775012e LM |
14838 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
14839 | condition_evaluation_enums, | |
14840 | &condition_evaluation_mode_1, _("\ | |
14841 | Set mode of breakpoint condition evaluation."), _("\ | |
14842 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 14843 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
14844 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
14845 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
14846 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
14847 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
14848 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
7a4e8e7d | 14849 | be set to \"host\"."), |
b775012e LM |
14850 | &set_condition_evaluation_mode, |
14851 | &show_condition_evaluation_mode, | |
14852 | &breakpoint_set_cmdlist, | |
14853 | &breakpoint_show_cmdlist); | |
14854 | ||
f1310107 TJB |
14855 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
14856 | Set a breakpoint for an address range.\n\ | |
14857 | break-range START-LOCATION, END-LOCATION\n\ | |
14858 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
14859 | LINENUM, for that line in the current file,\n\ | |
14860 | FILE:LINENUM, for that line in that file,\n\ | |
14861 | +OFFSET, for that number of lines after the current line\n\ | |
dda83cd7 | 14862 | or the start of the range\n\ |
f1310107 TJB |
14863 | FUNCTION, for the first line in that function,\n\ |
14864 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
14865 | *ADDRESS, for the instruction at that address.\n\ | |
14866 | \n\ | |
14867 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
14868 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
14869 | range (including START-LOCATION and END-LOCATION).")); | |
14870 | ||
e7e0cddf | 14871 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 14872 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 14873 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
14874 | location may be a linespec, explicit, or address location.\n" |
14875 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
14876 | set_cmd_completer (c, location_completer); |
14877 | ||
14878 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
14879 | dprintf_style_enums, &dprintf_style, _("\ | |
14880 | Set the style of usage for dynamic printf."), _("\ | |
14881 | Show the style of usage for dynamic printf."), _("\ | |
14882 | This setting chooses how GDB will do a dynamic printf.\n\ | |
14883 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
14884 | console, as with the \"printf\" command.\n\ | |
14885 | If the value is \"call\", the print is done by calling a function in your\n\ | |
14886 | program; by default printf(), but you can choose a different function or\n\ | |
14887 | output stream by setting dprintf-function and dprintf-channel."), | |
14888 | update_dprintf_commands, NULL, | |
14889 | &setlist, &showlist); | |
14890 | ||
e7e0cddf SS |
14891 | add_setshow_string_cmd ("dprintf-function", class_support, |
14892 | &dprintf_function, _("\ | |
590042fc PW |
14893 | Set the function to use for dynamic printf."), _("\ |
14894 | Show the function to use for dynamic printf."), NULL, | |
e7e0cddf SS |
14895 | update_dprintf_commands, NULL, |
14896 | &setlist, &showlist); | |
14897 | ||
e7e0cddf SS |
14898 | add_setshow_string_cmd ("dprintf-channel", class_support, |
14899 | &dprintf_channel, _("\ | |
590042fc PW |
14900 | Set the channel to use for dynamic printf."), _("\ |
14901 | Show the channel to use for dynamic printf."), NULL, | |
e7e0cddf SS |
14902 | update_dprintf_commands, NULL, |
14903 | &setlist, &showlist); | |
14904 | ||
d3ce09f5 SS |
14905 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
14906 | &disconnected_dprintf, _("\ | |
14907 | Set whether dprintf continues after GDB disconnects."), _("\ | |
14908 | Show whether dprintf continues after GDB disconnects."), _("\ | |
14909 | Use this to let dprintf commands continue to hit and produce output\n\ | |
14910 | even if GDB disconnects or detaches from the target."), | |
14911 | NULL, | |
14912 | NULL, | |
14913 | &setlist, &showlist); | |
14914 | ||
14915 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
590042fc PW |
14916 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
14917 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ | |
14918 | This supports most C printf format specifications, like %s, %d, etc.\n\ | |
14919 | This is useful for formatted output in user-defined commands.")); | |
d3ce09f5 | 14920 | |
491144b5 | 14921 | automatic_hardware_breakpoints = true; |
f3b1572e | 14922 | |
c90e7d63 SM |
14923 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed, |
14924 | "breakpoint"); | |
14925 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints, | |
14926 | "breakpoint"); | |
c906108c | 14927 | } |