Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
61baf725 | 3 | Copyright (C) 1986-2017 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" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
765dc015 | 54 | #include "memattr.h" |
f7f9143b | 55 | #include "ada-lang.h" |
d1aa2f50 | 56 | #include "top.h" |
79a45b7d | 57 | #include "valprint.h" |
4efc6507 | 58 | #include "jit.h" |
65d79d4b | 59 | #include "parser-defs.h" |
55aa24fb SDJ |
60 | #include "gdb_regex.h" |
61 | #include "probe.h" | |
e9cafbcc | 62 | #include "cli/cli-utils.h" |
be34f849 | 63 | #include "continuations.h" |
1bfeeb0f JL |
64 | #include "stack.h" |
65 | #include "skip.h" | |
b775012e | 66 | #include "ax-gdb.h" |
e2e4d78b | 67 | #include "dummy-frame.h" |
5589af0e | 68 | #include "interps.h" |
d3ce09f5 | 69 | #include "format.h" |
cfc31633 | 70 | #include "thread-fsm.h" |
5d5658a1 | 71 | #include "tid-parse.h" |
d3ce09f5 | 72 | |
1042e4c0 SS |
73 | /* readline include files */ |
74 | #include "readline/readline.h" | |
75 | #include "readline/history.h" | |
76 | ||
77 | /* readline defines this. */ | |
78 | #undef savestring | |
79 | ||
034dad6f | 80 | #include "mi/mi-common.h" |
6dddc817 | 81 | #include "extension.h" |
325fac50 | 82 | #include <algorithm> |
5ed8105e | 83 | #include "progspace-and-thread.h" |
6c5b2ebe | 84 | #include "common/array-view.h" |
76f9c9cf | 85 | #include "common/gdb_optional.h" |
104c1213 | 86 | |
e7e8980f YQ |
87 | /* Enums for exception-handling support. */ |
88 | enum exception_event_kind | |
89 | { | |
90 | EX_EVENT_THROW, | |
591f19e8 | 91 | EX_EVENT_RETHROW, |
e7e8980f YQ |
92 | EX_EVENT_CATCH |
93 | }; | |
94 | ||
4a64f543 | 95 | /* Prototypes for local functions. */ |
c906108c | 96 | |
a14ed312 | 97 | static void enable_delete_command (char *, int); |
c906108c | 98 | |
a14ed312 | 99 | static void enable_once_command (char *, int); |
c906108c | 100 | |
816338b5 SS |
101 | static void enable_count_command (char *, int); |
102 | ||
a14ed312 | 103 | static void disable_command (char *, int); |
c906108c | 104 | |
a14ed312 | 105 | static void enable_command (char *, int); |
c906108c | 106 | |
896b6bda | 107 | static void map_breakpoint_numbers (const char *, |
48649e1b | 108 | gdb::function_view<void (breakpoint *)>); |
c906108c | 109 | |
a14ed312 | 110 | static void ignore_command (char *, int); |
c906108c | 111 | |
4efb68b1 | 112 | static int breakpoint_re_set_one (void *); |
c906108c | 113 | |
348d480f PA |
114 | static void breakpoint_re_set_default (struct breakpoint *); |
115 | ||
f00aae0f KS |
116 | static void |
117 | create_sals_from_location_default (const struct event_location *location, | |
118 | struct linespec_result *canonical, | |
119 | enum bptype type_wanted); | |
983af33b SDJ |
120 | |
121 | static void create_breakpoints_sal_default (struct gdbarch *, | |
122 | struct linespec_result *, | |
e1e01040 PA |
123 | gdb::unique_xmalloc_ptr<char>, |
124 | gdb::unique_xmalloc_ptr<char>, | |
125 | enum bptype, | |
983af33b SDJ |
126 | enum bpdisp, int, int, |
127 | int, | |
128 | const struct breakpoint_ops *, | |
44f238bb | 129 | int, int, int, unsigned); |
983af33b | 130 | |
6c5b2ebe PA |
131 | static std::vector<symtab_and_line> decode_location_default |
132 | (struct breakpoint *b, const struct event_location *location, | |
133 | struct program_space *search_pspace); | |
983af33b | 134 | |
a14ed312 | 135 | static void clear_command (char *, int); |
c906108c | 136 | |
a14ed312 | 137 | static void catch_command (char *, int); |
c906108c | 138 | |
a9634178 | 139 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 140 | |
98deb0da | 141 | static void break_command_1 (char *, int, int); |
c906108c | 142 | |
a14ed312 | 143 | static void mention (struct breakpoint *); |
c906108c | 144 | |
348d480f PA |
145 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
146 | enum bptype, | |
c0a91b2b | 147 | const struct breakpoint_ops *); |
3742cc8b YQ |
148 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
149 | const struct symtab_and_line *); | |
150 | ||
4a64f543 MS |
151 | /* This function is used in gdbtk sources and thus can not be made |
152 | static. */ | |
63c252f8 | 153 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 154 | struct symtab_and_line, |
c0a91b2b TT |
155 | enum bptype, |
156 | const struct breakpoint_ops *); | |
c906108c | 157 | |
06edf0c0 PA |
158 | static struct breakpoint * |
159 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
160 | enum bptype type, | |
a1aa2221 LM |
161 | const struct breakpoint_ops *ops, |
162 | int loc_enabled); | |
06edf0c0 | 163 | |
76897487 KB |
164 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
165 | ||
a6d9a66e UW |
166 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
167 | CORE_ADDR bpaddr, | |
88f7da05 | 168 | enum bptype bptype); |
76897487 | 169 | |
6c95b8df PA |
170 | static void describe_other_breakpoints (struct gdbarch *, |
171 | struct program_space *, CORE_ADDR, | |
5af949e3 | 172 | struct obj_section *, int); |
c906108c | 173 | |
85d721b8 PA |
174 | static int watchpoint_locations_match (struct bp_location *loc1, |
175 | struct bp_location *loc2); | |
176 | ||
f1310107 TJB |
177 | static int breakpoint_location_address_match (struct bp_location *bl, |
178 | struct address_space *aspace, | |
179 | CORE_ADDR addr); | |
180 | ||
d35ae833 PA |
181 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
182 | struct address_space *, | |
183 | CORE_ADDR, int); | |
184 | ||
11db9430 | 185 | static void info_breakpoints_command (char *, int); |
c906108c | 186 | |
11db9430 | 187 | static void info_watchpoints_command (char *, int); |
d77f58be | 188 | |
e5a67952 MS |
189 | static int breakpoint_1 (char *, int, |
190 | int (*) (const struct breakpoint *)); | |
c906108c | 191 | |
4efb68b1 | 192 | static int breakpoint_cond_eval (void *); |
c906108c | 193 | |
4efb68b1 | 194 | static void cleanup_executing_breakpoints (void *); |
c906108c | 195 | |
a14ed312 | 196 | static void commands_command (char *, int); |
c906108c | 197 | |
a14ed312 | 198 | static void condition_command (char *, int); |
c906108c | 199 | |
834c0d03 | 200 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 201 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 202 | |
e514a9d6 | 203 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 204 | |
4efb68b1 | 205 | static int watchpoint_check (void *); |
c906108c | 206 | |
a14ed312 | 207 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 208 | |
a14ed312 | 209 | static int hw_breakpoint_used_count (void); |
c906108c | 210 | |
a1398e0c PA |
211 | static int hw_watchpoint_use_count (struct breakpoint *); |
212 | ||
213 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
214 | enum bptype type, | |
215 | int *other_type_used); | |
c906108c | 216 | |
a14ed312 | 217 | static void hbreak_command (char *, int); |
c906108c | 218 | |
a14ed312 | 219 | static void thbreak_command (char *, int); |
c906108c | 220 | |
816338b5 SS |
221 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
222 | int count); | |
c906108c | 223 | |
a14ed312 | 224 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 225 | |
a14ed312 | 226 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 227 | |
a14ed312 | 228 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 229 | |
a14ed312 | 230 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 231 | |
fe3f5fa8 | 232 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
233 | static void incref_bp_location (struct bp_location *loc); |
234 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 235 | |
39d61571 | 236 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 237 | |
44702360 PA |
238 | /* update_global_location_list's modes of operation wrt to whether to |
239 | insert locations now. */ | |
240 | enum ugll_insert_mode | |
241 | { | |
242 | /* Don't insert any breakpoint locations into the inferior, only | |
243 | remove already-inserted locations that no longer should be | |
244 | inserted. Functions that delete a breakpoint or breakpoints | |
245 | should specify this mode, so that deleting a breakpoint doesn't | |
246 | have the side effect of inserting the locations of other | |
247 | breakpoints that are marked not-inserted, but should_be_inserted | |
248 | returns true on them. | |
249 | ||
250 | This behavior is useful is situations close to tear-down -- e.g., | |
251 | after an exec, while the target still has execution, but | |
252 | breakpoint shadows of the previous executable image should *NOT* | |
253 | be restored to the new image; or before detaching, where the | |
254 | target still has execution and wants to delete breakpoints from | |
255 | GDB's lists, and all breakpoints had already been removed from | |
256 | the inferior. */ | |
257 | UGLL_DONT_INSERT, | |
258 | ||
a25a5a45 PA |
259 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
260 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
261 | UGLL_MAY_INSERT, |
262 | ||
a25a5a45 PA |
263 | /* Insert locations now, irrespective of |
264 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
265 | stopped right now, and the user did "continue". We need to | |
266 | insert breakpoints _before_ resuming the target, but | |
267 | UGLL_MAY_INSERT wouldn't insert them, because | |
268 | breakpoints_should_be_inserted_now returns false at that point, | |
269 | as no thread is running yet. */ | |
04086b45 | 270 | UGLL_INSERT |
44702360 PA |
271 | }; |
272 | ||
273 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 274 | |
44702360 | 275 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 276 | |
d77f58be | 277 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
278 | |
279 | static void insert_breakpoint_locations (void); | |
a5606eee | 280 | |
11db9430 | 281 | static void info_tracepoints_command (char *, int); |
1042e4c0 SS |
282 | |
283 | static void delete_trace_command (char *, int); | |
284 | ||
285 | static void enable_trace_command (char *, int); | |
286 | ||
287 | static void disable_trace_command (char *, int); | |
288 | ||
289 | static void trace_pass_command (char *, int); | |
290 | ||
558a9d82 YQ |
291 | static void set_tracepoint_count (int num); |
292 | ||
9c06b0b4 TJB |
293 | static int is_masked_watchpoint (const struct breakpoint *b); |
294 | ||
b775012e LM |
295 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
296 | ||
983af33b SDJ |
297 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
298 | otherwise. */ | |
299 | ||
300 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 301 | |
2060206e PA |
302 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
303 | that are implemented on top of software or hardware breakpoints | |
304 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
305 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
306 | ||
307 | /* Internal breakpoints class type. */ | |
06edf0c0 | 308 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
309 | |
310 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
311 | static struct breakpoint_ops momentary_breakpoint_ops; |
312 | ||
2060206e PA |
313 | /* The breakpoint_ops structure to be used in regular user created |
314 | breakpoints. */ | |
315 | struct breakpoint_ops bkpt_breakpoint_ops; | |
316 | ||
55aa24fb SDJ |
317 | /* Breakpoints set on probes. */ |
318 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
319 | ||
e7e0cddf | 320 | /* Dynamic printf class type. */ |
c5867ab6 | 321 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 322 | |
d3ce09f5 SS |
323 | /* The style in which to perform a dynamic printf. This is a user |
324 | option because different output options have different tradeoffs; | |
325 | if GDB does the printing, there is better error handling if there | |
326 | is a problem with any of the arguments, but using an inferior | |
327 | function lets you have special-purpose printers and sending of | |
328 | output to the same place as compiled-in print functions. */ | |
329 | ||
330 | static const char dprintf_style_gdb[] = "gdb"; | |
331 | static const char dprintf_style_call[] = "call"; | |
332 | static const char dprintf_style_agent[] = "agent"; | |
333 | static const char *const dprintf_style_enums[] = { | |
334 | dprintf_style_gdb, | |
335 | dprintf_style_call, | |
336 | dprintf_style_agent, | |
337 | NULL | |
338 | }; | |
339 | static const char *dprintf_style = dprintf_style_gdb; | |
340 | ||
341 | /* The function to use for dynamic printf if the preferred style is to | |
342 | call into the inferior. The value is simply a string that is | |
343 | copied into the command, so it can be anything that GDB can | |
344 | evaluate to a callable address, not necessarily a function name. */ | |
345 | ||
bde6261a | 346 | static char *dprintf_function; |
d3ce09f5 SS |
347 | |
348 | /* The channel to use for dynamic printf if the preferred style is to | |
349 | call into the inferior; if a nonempty string, it will be passed to | |
350 | the call as the first argument, with the format string as the | |
351 | second. As with the dprintf function, this can be anything that | |
352 | GDB knows how to evaluate, so in addition to common choices like | |
353 | "stderr", this could be an app-specific expression like | |
354 | "mystreams[curlogger]". */ | |
355 | ||
bde6261a | 356 | static char *dprintf_channel; |
d3ce09f5 SS |
357 | |
358 | /* True if dprintf commands should continue to operate even if GDB | |
359 | has disconnected. */ | |
360 | static int disconnected_dprintf = 1; | |
361 | ||
5cea2a26 PA |
362 | /* A reference-counted struct command_line. This lets multiple |
363 | breakpoints share a single command list. */ | |
364 | struct counted_command_line | |
365 | { | |
366 | /* The reference count. */ | |
367 | int refc; | |
368 | ||
369 | /* The command list. */ | |
370 | struct command_line *commands; | |
371 | }; | |
372 | ||
373 | struct command_line * | |
374 | breakpoint_commands (struct breakpoint *b) | |
375 | { | |
376 | return b->commands ? b->commands->commands : NULL; | |
377 | } | |
3daf8fe5 | 378 | |
f3b1572e PA |
379 | /* Flag indicating that a command has proceeded the inferior past the |
380 | current breakpoint. */ | |
381 | ||
382 | static int breakpoint_proceeded; | |
383 | ||
956a9fb9 | 384 | const char * |
2cec12e5 AR |
385 | bpdisp_text (enum bpdisp disp) |
386 | { | |
4a64f543 MS |
387 | /* NOTE: the following values are a part of MI protocol and |
388 | represent values of 'disp' field returned when inferior stops at | |
389 | a breakpoint. */ | |
bc043ef3 | 390 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 391 | |
2cec12e5 AR |
392 | return bpdisps[(int) disp]; |
393 | } | |
c906108c | 394 | |
4a64f543 | 395 | /* Prototypes for exported functions. */ |
c906108c | 396 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 397 | if such is available. */ |
c906108c SS |
398 | static int can_use_hw_watchpoints; |
399 | ||
920d2a44 AC |
400 | static void |
401 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
402 | struct cmd_list_element *c, | |
403 | const char *value) | |
404 | { | |
3e43a32a MS |
405 | fprintf_filtered (file, |
406 | _("Debugger's willingness to use " | |
407 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
408 | value); |
409 | } | |
410 | ||
fa8d40ab JJ |
411 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
412 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 413 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
414 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
415 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
416 | static void |
417 | show_pending_break_support (struct ui_file *file, int from_tty, | |
418 | struct cmd_list_element *c, | |
419 | const char *value) | |
420 | { | |
3e43a32a MS |
421 | fprintf_filtered (file, |
422 | _("Debugger's behavior regarding " | |
423 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
424 | value); |
425 | } | |
fa8d40ab | 426 | |
765dc015 | 427 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 428 | set with "break" but falling in read-only memory. |
765dc015 VP |
429 | If 0, gdb will warn about such breakpoints, but won't automatically |
430 | use hardware breakpoints. */ | |
431 | static int automatic_hardware_breakpoints; | |
432 | static void | |
433 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
434 | struct cmd_list_element *c, | |
435 | const char *value) | |
436 | { | |
3e43a32a MS |
437 | fprintf_filtered (file, |
438 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
439 | value); |
440 | } | |
441 | ||
a25a5a45 PA |
442 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
443 | stopped, and immediately inserts any new breakpoints as soon as | |
444 | they're created. If off (default), GDB keeps breakpoints off of | |
445 | the target as long as possible. That is, it delays inserting | |
446 | breakpoints until the next resume, and removes them again when the | |
447 | target fully stops. This is a bit safer in case GDB crashes while | |
448 | processing user input. */ | |
449 | static int always_inserted_mode = 0; | |
72d0e2c5 | 450 | |
33e5cbd6 | 451 | static void |
74960c60 | 452 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 453 | struct cmd_list_element *c, const char *value) |
74960c60 | 454 | { |
a25a5a45 PA |
455 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
456 | value); | |
74960c60 VP |
457 | } |
458 | ||
b57bacec PA |
459 | /* See breakpoint.h. */ |
460 | ||
33e5cbd6 | 461 | int |
a25a5a45 | 462 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 463 | { |
a25a5a45 PA |
464 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
465 | { | |
466 | /* If breakpoints are global, they should be inserted even if no | |
467 | thread under gdb's control is running, or even if there are | |
468 | no threads under GDB's control yet. */ | |
469 | return 1; | |
470 | } | |
471 | else if (target_has_execution) | |
472 | { | |
372316f1 PA |
473 | struct thread_info *tp; |
474 | ||
a25a5a45 PA |
475 | if (always_inserted_mode) |
476 | { | |
477 | /* The user wants breakpoints inserted even if all threads | |
478 | are stopped. */ | |
479 | return 1; | |
480 | } | |
481 | ||
b57bacec PA |
482 | if (threads_are_executing ()) |
483 | return 1; | |
372316f1 PA |
484 | |
485 | /* Don't remove breakpoints yet if, even though all threads are | |
486 | stopped, we still have events to process. */ | |
487 | ALL_NON_EXITED_THREADS (tp) | |
488 | if (tp->resumed | |
489 | && tp->suspend.waitstatus_pending_p) | |
490 | return 1; | |
a25a5a45 PA |
491 | } |
492 | return 0; | |
33e5cbd6 | 493 | } |
765dc015 | 494 | |
b775012e LM |
495 | static const char condition_evaluation_both[] = "host or target"; |
496 | ||
497 | /* Modes for breakpoint condition evaluation. */ | |
498 | static const char condition_evaluation_auto[] = "auto"; | |
499 | static const char condition_evaluation_host[] = "host"; | |
500 | static const char condition_evaluation_target[] = "target"; | |
501 | static const char *const condition_evaluation_enums[] = { | |
502 | condition_evaluation_auto, | |
503 | condition_evaluation_host, | |
504 | condition_evaluation_target, | |
505 | NULL | |
506 | }; | |
507 | ||
508 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
509 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
510 | ||
511 | /* Global that we use to display information to the user (gets its value from | |
512 | condition_evaluation_mode_1. */ | |
513 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
514 | ||
515 | /* Translate a condition evaluation mode MODE into either "host" | |
516 | or "target". This is used mostly to translate from "auto" to the | |
517 | real setting that is being used. It returns the translated | |
518 | evaluation mode. */ | |
519 | ||
520 | static const char * | |
521 | translate_condition_evaluation_mode (const char *mode) | |
522 | { | |
523 | if (mode == condition_evaluation_auto) | |
524 | { | |
525 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
526 | return condition_evaluation_target; | |
527 | else | |
528 | return condition_evaluation_host; | |
529 | } | |
530 | else | |
531 | return mode; | |
532 | } | |
533 | ||
534 | /* Discovers what condition_evaluation_auto translates to. */ | |
535 | ||
536 | static const char * | |
537 | breakpoint_condition_evaluation_mode (void) | |
538 | { | |
539 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
540 | } | |
541 | ||
542 | /* Return true if GDB should evaluate breakpoint conditions or false | |
543 | otherwise. */ | |
544 | ||
545 | static int | |
546 | gdb_evaluates_breakpoint_condition_p (void) | |
547 | { | |
548 | const char *mode = breakpoint_condition_evaluation_mode (); | |
549 | ||
550 | return (mode == condition_evaluation_host); | |
551 | } | |
552 | ||
c906108c SS |
553 | /* Are we executing breakpoint commands? */ |
554 | static int executing_breakpoint_commands; | |
555 | ||
c02f5703 MS |
556 | /* Are overlay event breakpoints enabled? */ |
557 | static int overlay_events_enabled; | |
558 | ||
e09342b5 TJB |
559 | /* See description in breakpoint.h. */ |
560 | int target_exact_watchpoints = 0; | |
561 | ||
c906108c | 562 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 563 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 564 | current breakpoint. */ |
c906108c | 565 | |
5c44784c | 566 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 567 | |
5c44784c JM |
568 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
569 | for (B = breakpoint_chain; \ | |
570 | B ? (TMP=B->next, 1): 0; \ | |
571 | B = TMP) | |
c906108c | 572 | |
4a64f543 MS |
573 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
574 | not provided so update_global_location_list must not be called | |
575 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 576 | |
876fa593 | 577 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
578 | for (BP_TMP = bp_locations; \ |
579 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 580 | BP_TMP++) |
7cc221ef | 581 | |
b775012e LM |
582 | /* Iterates through locations with address ADDRESS for the currently selected |
583 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
584 | to where the loop should start from. | |
585 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
586 | appropriate location to start with. */ | |
587 | ||
588 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
589 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
590 | BP_LOCP_TMP = BP_LOCP_START; \ | |
591 | BP_LOCP_START \ | |
f5336ca5 | 592 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
593 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
594 | BP_LOCP_TMP++) | |
595 | ||
1042e4c0 SS |
596 | /* Iterator for tracepoints only. */ |
597 | ||
598 | #define ALL_TRACEPOINTS(B) \ | |
599 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 600 | if (is_tracepoint (B)) |
1042e4c0 | 601 | |
7cc221ef | 602 | /* Chains of all breakpoints defined. */ |
c906108c SS |
603 | |
604 | struct breakpoint *breakpoint_chain; | |
605 | ||
f5336ca5 | 606 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 607 | |
f5336ca5 | 608 | static struct bp_location **bp_locations; |
876fa593 | 609 | |
f5336ca5 | 610 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 611 | |
f5336ca5 | 612 | static unsigned bp_locations_count; |
876fa593 | 613 | |
4a64f543 | 614 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 615 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 616 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 617 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 618 | an address you need to read. */ |
876fa593 | 619 | |
f5336ca5 | 620 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 621 | |
4a64f543 MS |
622 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
623 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
624 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
625 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 626 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 627 | |
f5336ca5 | 628 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 629 | |
4a64f543 | 630 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
631 | from the bp_locations array, but for which a hit may still be |
632 | reported by a target. */ | |
20874c92 VP |
633 | VEC(bp_location_p) *moribund_locations = NULL; |
634 | ||
c906108c SS |
635 | /* Number of last breakpoint made. */ |
636 | ||
95a42b64 TT |
637 | static int breakpoint_count; |
638 | ||
86b17b60 PA |
639 | /* The value of `breakpoint_count' before the last command that |
640 | created breakpoints. If the last (break-like) command created more | |
641 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
642 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
643 | static int prev_breakpoint_count; | |
c906108c | 644 | |
1042e4c0 SS |
645 | /* Number of last tracepoint made. */ |
646 | ||
95a42b64 | 647 | static int tracepoint_count; |
1042e4c0 | 648 | |
6149aea9 PA |
649 | static struct cmd_list_element *breakpoint_set_cmdlist; |
650 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 651 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 652 | |
badd37ce SDJ |
653 | /* See declaration at breakpoint.h. */ |
654 | ||
655 | struct breakpoint * | |
656 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
657 | void *user_data) | |
658 | { | |
659 | struct breakpoint *b = NULL; | |
660 | ||
661 | ALL_BREAKPOINTS (b) | |
662 | { | |
663 | if (func (b, user_data) != 0) | |
664 | break; | |
665 | } | |
666 | ||
667 | return b; | |
668 | } | |
669 | ||
468d015d JJ |
670 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
671 | static int | |
672 | breakpoint_enabled (struct breakpoint *b) | |
673 | { | |
0d381245 | 674 | return (b->enable_state == bp_enabled); |
468d015d JJ |
675 | } |
676 | ||
c906108c SS |
677 | /* Set breakpoint count to NUM. */ |
678 | ||
95a42b64 | 679 | static void |
fba45db2 | 680 | set_breakpoint_count (int num) |
c906108c | 681 | { |
86b17b60 | 682 | prev_breakpoint_count = breakpoint_count; |
c906108c | 683 | breakpoint_count = num; |
4fa62494 | 684 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
685 | } |
686 | ||
86b17b60 PA |
687 | /* Used by `start_rbreak_breakpoints' below, to record the current |
688 | breakpoint count before "rbreak" creates any breakpoint. */ | |
689 | static int rbreak_start_breakpoint_count; | |
690 | ||
95a42b64 TT |
691 | /* Called at the start an "rbreak" command to record the first |
692 | breakpoint made. */ | |
86b17b60 | 693 | |
95a42b64 TT |
694 | void |
695 | start_rbreak_breakpoints (void) | |
696 | { | |
86b17b60 | 697 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
698 | } |
699 | ||
700 | /* Called at the end of an "rbreak" command to record the last | |
701 | breakpoint made. */ | |
86b17b60 | 702 | |
95a42b64 TT |
703 | void |
704 | end_rbreak_breakpoints (void) | |
705 | { | |
86b17b60 | 706 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
707 | } |
708 | ||
4a64f543 | 709 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
710 | |
711 | void | |
fba45db2 | 712 | clear_breakpoint_hit_counts (void) |
c906108c SS |
713 | { |
714 | struct breakpoint *b; | |
715 | ||
716 | ALL_BREAKPOINTS (b) | |
717 | b->hit_count = 0; | |
718 | } | |
719 | ||
9add0f1b TT |
720 | /* Allocate a new counted_command_line with reference count of 1. |
721 | The new structure owns COMMANDS. */ | |
722 | ||
723 | static struct counted_command_line * | |
724 | alloc_counted_command_line (struct command_line *commands) | |
725 | { | |
8d749320 | 726 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 727 | |
9add0f1b TT |
728 | result->refc = 1; |
729 | result->commands = commands; | |
8d749320 | 730 | |
9add0f1b TT |
731 | return result; |
732 | } | |
733 | ||
734 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
735 | ||
736 | static void | |
737 | incref_counted_command_line (struct counted_command_line *cmd) | |
738 | { | |
739 | if (cmd) | |
740 | ++cmd->refc; | |
741 | } | |
742 | ||
743 | /* Decrement reference count. If the reference count reaches 0, | |
744 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
745 | nothing if *CMDP is NULL. */ | |
746 | ||
747 | static void | |
748 | decref_counted_command_line (struct counted_command_line **cmdp) | |
749 | { | |
750 | if (*cmdp) | |
751 | { | |
752 | if (--(*cmdp)->refc == 0) | |
753 | { | |
754 | free_command_lines (&(*cmdp)->commands); | |
755 | xfree (*cmdp); | |
756 | } | |
757 | *cmdp = NULL; | |
758 | } | |
759 | } | |
760 | ||
761 | /* A cleanup function that calls decref_counted_command_line. */ | |
762 | ||
763 | static void | |
764 | do_cleanup_counted_command_line (void *arg) | |
765 | { | |
9a3c8263 | 766 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
767 | } |
768 | ||
769 | /* Create a cleanup that calls decref_counted_command_line on the | |
770 | argument. */ | |
771 | ||
772 | static struct cleanup * | |
773 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
774 | { | |
775 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
776 | } | |
777 | ||
c906108c | 778 | \f |
48cb2d85 VP |
779 | /* Return the breakpoint with the specified number, or NULL |
780 | if the number does not refer to an existing breakpoint. */ | |
781 | ||
782 | struct breakpoint * | |
783 | get_breakpoint (int num) | |
784 | { | |
785 | struct breakpoint *b; | |
786 | ||
787 | ALL_BREAKPOINTS (b) | |
788 | if (b->number == num) | |
789 | return b; | |
790 | ||
791 | return NULL; | |
792 | } | |
5c44784c | 793 | |
c906108c | 794 | \f |
adc36818 | 795 | |
b775012e LM |
796 | /* Mark locations as "conditions have changed" in case the target supports |
797 | evaluating conditions on its side. */ | |
798 | ||
799 | static void | |
800 | mark_breakpoint_modified (struct breakpoint *b) | |
801 | { | |
802 | struct bp_location *loc; | |
803 | ||
804 | /* This is only meaningful if the target is | |
805 | evaluating conditions and if the user has | |
806 | opted for condition evaluation on the target's | |
807 | side. */ | |
808 | if (gdb_evaluates_breakpoint_condition_p () | |
809 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
810 | return; | |
811 | ||
812 | if (!is_breakpoint (b)) | |
813 | return; | |
814 | ||
815 | for (loc = b->loc; loc; loc = loc->next) | |
816 | loc->condition_changed = condition_modified; | |
817 | } | |
818 | ||
819 | /* Mark location as "conditions have changed" in case the target supports | |
820 | evaluating conditions on its side. */ | |
821 | ||
822 | static void | |
823 | mark_breakpoint_location_modified (struct bp_location *loc) | |
824 | { | |
825 | /* This is only meaningful if the target is | |
826 | evaluating conditions and if the user has | |
827 | opted for condition evaluation on the target's | |
828 | side. */ | |
829 | if (gdb_evaluates_breakpoint_condition_p () | |
830 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
831 | ||
832 | return; | |
833 | ||
834 | if (!is_breakpoint (loc->owner)) | |
835 | return; | |
836 | ||
837 | loc->condition_changed = condition_modified; | |
838 | } | |
839 | ||
840 | /* Sets the condition-evaluation mode using the static global | |
841 | condition_evaluation_mode. */ | |
842 | ||
843 | static void | |
844 | set_condition_evaluation_mode (char *args, int from_tty, | |
845 | struct cmd_list_element *c) | |
846 | { | |
b775012e LM |
847 | const char *old_mode, *new_mode; |
848 | ||
849 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
850 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
851 | { | |
852 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
853 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
854 | "Using host evaluation mode instead.")); | |
855 | return; | |
856 | } | |
857 | ||
858 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
859 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
860 | ||
abf1152a JK |
861 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
862 | settings was "auto". */ | |
863 | condition_evaluation_mode = condition_evaluation_mode_1; | |
864 | ||
b775012e LM |
865 | /* Only update the mode if the user picked a different one. */ |
866 | if (new_mode != old_mode) | |
867 | { | |
868 | struct bp_location *loc, **loc_tmp; | |
869 | /* If the user switched to a different evaluation mode, we | |
870 | need to synch the changes with the target as follows: | |
871 | ||
872 | "host" -> "target": Send all (valid) conditions to the target. | |
873 | "target" -> "host": Remove all the conditions from the target. | |
874 | */ | |
875 | ||
b775012e LM |
876 | if (new_mode == condition_evaluation_target) |
877 | { | |
878 | /* Mark everything modified and synch conditions with the | |
879 | target. */ | |
880 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
881 | mark_breakpoint_location_modified (loc); | |
882 | } | |
883 | else | |
884 | { | |
885 | /* Manually mark non-duplicate locations to synch conditions | |
886 | with the target. We do this to remove all the conditions the | |
887 | target knows about. */ | |
888 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
889 | if (is_breakpoint (loc->owner) && loc->inserted) | |
890 | loc->needs_update = 1; | |
891 | } | |
892 | ||
893 | /* Do the update. */ | |
44702360 | 894 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
895 | } |
896 | ||
897 | return; | |
898 | } | |
899 | ||
900 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
901 | what "auto" is translating to. */ | |
902 | ||
903 | static void | |
904 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
905 | struct cmd_list_element *c, const char *value) | |
906 | { | |
907 | if (condition_evaluation_mode == condition_evaluation_auto) | |
908 | fprintf_filtered (file, | |
909 | _("Breakpoint condition evaluation " | |
910 | "mode is %s (currently %s).\n"), | |
911 | value, | |
912 | breakpoint_condition_evaluation_mode ()); | |
913 | else | |
914 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
915 | value); | |
916 | } | |
917 | ||
918 | /* A comparison function for bp_location AP and BP that is used by | |
919 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 920 | the more general bp_locations_compare function. */ |
b775012e LM |
921 | |
922 | static int | |
f5336ca5 | 923 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 924 | { |
9a3c8263 SM |
925 | const struct bp_location *a = *(const struct bp_location **) ap; |
926 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
927 | |
928 | if (a->address == b->address) | |
929 | return 0; | |
930 | else | |
931 | return ((a->address > b->address) - (a->address < b->address)); | |
932 | } | |
933 | ||
934 | /* Helper function to skip all bp_locations with addresses | |
935 | less than ADDRESS. It returns the first bp_location that | |
936 | is greater than or equal to ADDRESS. If none is found, just | |
937 | return NULL. */ | |
938 | ||
939 | static struct bp_location ** | |
940 | get_first_locp_gte_addr (CORE_ADDR address) | |
941 | { | |
942 | struct bp_location dummy_loc; | |
943 | struct bp_location *dummy_locp = &dummy_loc; | |
944 | struct bp_location **locp_found = NULL; | |
945 | ||
946 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
947 | dummy_loc.address = address; |
948 | ||
949 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 950 | locp_found = ((struct bp_location **) |
f5336ca5 | 951 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 952 | sizeof (struct bp_location **), |
f5336ca5 | 953 | bp_locations_compare_addrs)); |
b775012e LM |
954 | |
955 | /* Nothing was found, nothing left to do. */ | |
956 | if (locp_found == NULL) | |
957 | return NULL; | |
958 | ||
959 | /* We may have found a location that is at ADDRESS but is not the first in the | |
960 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 961 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
962 | && (*(locp_found - 1))->address == address) |
963 | locp_found--; | |
964 | ||
965 | return locp_found; | |
966 | } | |
967 | ||
adc36818 | 968 | void |
7a26bd4d | 969 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
970 | int from_tty) |
971 | { | |
3a5c3e22 PA |
972 | xfree (b->cond_string); |
973 | b->cond_string = NULL; | |
adc36818 | 974 | |
3a5c3e22 | 975 | if (is_watchpoint (b)) |
adc36818 | 976 | { |
3a5c3e22 PA |
977 | struct watchpoint *w = (struct watchpoint *) b; |
978 | ||
4d01a485 | 979 | w->cond_exp.reset (); |
3a5c3e22 PA |
980 | } |
981 | else | |
982 | { | |
983 | struct bp_location *loc; | |
984 | ||
985 | for (loc = b->loc; loc; loc = loc->next) | |
986 | { | |
4d01a485 | 987 | loc->cond.reset (); |
b775012e LM |
988 | |
989 | /* No need to free the condition agent expression | |
990 | bytecode (if we have one). We will handle this | |
991 | when we go through update_global_location_list. */ | |
3a5c3e22 | 992 | } |
adc36818 | 993 | } |
adc36818 PM |
994 | |
995 | if (*exp == 0) | |
996 | { | |
997 | if (from_tty) | |
998 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
999 | } | |
1000 | else | |
1001 | { | |
bbc13ae3 | 1002 | const char *arg = exp; |
cc59ec59 | 1003 | |
adc36818 PM |
1004 | /* I don't know if it matters whether this is the string the user |
1005 | typed in or the decompiled expression. */ | |
1006 | b->cond_string = xstrdup (arg); | |
1007 | b->condition_not_parsed = 0; | |
1008 | ||
1009 | if (is_watchpoint (b)) | |
1010 | { | |
3a5c3e22 PA |
1011 | struct watchpoint *w = (struct watchpoint *) b; |
1012 | ||
adc36818 PM |
1013 | innermost_block = NULL; |
1014 | arg = exp; | |
1bb9788d | 1015 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1016 | if (*arg) |
1017 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1018 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1019 | } |
1020 | else | |
1021 | { | |
3a5c3e22 PA |
1022 | struct bp_location *loc; |
1023 | ||
adc36818 PM |
1024 | for (loc = b->loc; loc; loc = loc->next) |
1025 | { | |
1026 | arg = exp; | |
1027 | loc->cond = | |
1bb9788d TT |
1028 | parse_exp_1 (&arg, loc->address, |
1029 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1030 | if (*arg) |
1031 | error (_("Junk at end of expression")); | |
1032 | } | |
1033 | } | |
1034 | } | |
b775012e LM |
1035 | mark_breakpoint_modified (b); |
1036 | ||
8d3788bd | 1037 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1038 | } |
1039 | ||
d55637df TT |
1040 | /* Completion for the "condition" command. */ |
1041 | ||
eb3ff9a5 | 1042 | static void |
6f937416 | 1043 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 1044 | completion_tracker &tracker, |
6f937416 | 1045 | const char *text, const char *word) |
d55637df | 1046 | { |
6f937416 | 1047 | const char *space; |
d55637df | 1048 | |
f1735a53 TT |
1049 | text = skip_spaces (text); |
1050 | space = skip_to_space (text); | |
d55637df TT |
1051 | if (*space == '\0') |
1052 | { | |
1053 | int len; | |
1054 | struct breakpoint *b; | |
1055 | VEC (char_ptr) *result = NULL; | |
1056 | ||
1057 | if (text[0] == '$') | |
1058 | { | |
1059 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
1060 | if (!isdigit (text[1])) |
1061 | complete_internalvar (tracker, &text[1]); | |
1062 | return; | |
d55637df TT |
1063 | } |
1064 | ||
1065 | /* We're completing the breakpoint number. */ | |
1066 | len = strlen (text); | |
1067 | ||
1068 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1069 | { |
1070 | char number[50]; | |
1071 | ||
1072 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1073 | ||
1074 | if (strncmp (number, text, len) == 0) | |
eb3ff9a5 PA |
1075 | { |
1076 | gdb::unique_xmalloc_ptr<char> copy (xstrdup (number)); | |
1077 | tracker.add_completion (std::move (copy)); | |
1078 | } | |
58ce7251 | 1079 | } |
d55637df | 1080 | |
eb3ff9a5 | 1081 | return; |
d55637df TT |
1082 | } |
1083 | ||
1084 | /* We're completing the expression part. */ | |
f1735a53 | 1085 | text = skip_spaces (space); |
eb3ff9a5 | 1086 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
1087 | } |
1088 | ||
c906108c SS |
1089 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1090 | ||
1091 | static void | |
fba45db2 | 1092 | condition_command (char *arg, int from_tty) |
c906108c | 1093 | { |
52f0bd74 | 1094 | struct breakpoint *b; |
c906108c | 1095 | char *p; |
52f0bd74 | 1096 | int bnum; |
c906108c SS |
1097 | |
1098 | if (arg == 0) | |
e2e0b3e5 | 1099 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1100 | |
1101 | p = arg; | |
1102 | bnum = get_number (&p); | |
5c44784c | 1103 | if (bnum == 0) |
8a3fe4f8 | 1104 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1105 | |
1106 | ALL_BREAKPOINTS (b) | |
1107 | if (b->number == bnum) | |
2f069f6f | 1108 | { |
6dddc817 DE |
1109 | /* Check if this breakpoint has a "stop" method implemented in an |
1110 | extension language. This method and conditions entered into GDB | |
1111 | from the CLI are mutually exclusive. */ | |
1112 | const struct extension_language_defn *extlang | |
1113 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1114 | ||
1115 | if (extlang != NULL) | |
1116 | { | |
1117 | error (_("Only one stop condition allowed. There is currently" | |
1118 | " a %s stop condition defined for this breakpoint."), | |
1119 | ext_lang_capitalized_name (extlang)); | |
1120 | } | |
2566ad2d | 1121 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1122 | |
1123 | if (is_breakpoint (b)) | |
44702360 | 1124 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1125 | |
2f069f6f JB |
1126 | return; |
1127 | } | |
c906108c | 1128 | |
8a3fe4f8 | 1129 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1130 | } |
1131 | ||
a7bdde9e VP |
1132 | /* Check that COMMAND do not contain commands that are suitable |
1133 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1134 | Throw if any such commands is found. */ |
1135 | ||
a7bdde9e VP |
1136 | static void |
1137 | check_no_tracepoint_commands (struct command_line *commands) | |
1138 | { | |
1139 | struct command_line *c; | |
cc59ec59 | 1140 | |
a7bdde9e VP |
1141 | for (c = commands; c; c = c->next) |
1142 | { | |
1143 | int i; | |
1144 | ||
1145 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1146 | error (_("The 'while-stepping' command can " |
1147 | "only be used for tracepoints")); | |
a7bdde9e VP |
1148 | |
1149 | for (i = 0; i < c->body_count; ++i) | |
1150 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1151 | ||
1152 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1153 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1154 | command directly. */ |
1155 | if (strstr (c->line, "collect ") == c->line) | |
1156 | error (_("The 'collect' command can only be used for tracepoints")); | |
1157 | ||
51661e93 VP |
1158 | if (strstr (c->line, "teval ") == c->line) |
1159 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1160 | } |
1161 | } | |
1162 | ||
c1fc2657 | 1163 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1164 | { |
c1fc2657 | 1165 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1166 | }; |
1167 | ||
d77f58be SS |
1168 | /* Encapsulate tests for different types of tracepoints. */ |
1169 | ||
3b0871f4 SM |
1170 | static bool |
1171 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1172 | { |
1173 | return (type == bp_tracepoint | |
1174 | || type == bp_fast_tracepoint | |
1175 | || type == bp_static_tracepoint); | |
1176 | } | |
1177 | ||
3b0871f4 SM |
1178 | static bool |
1179 | is_longjmp_type (bptype type) | |
1180 | { | |
1181 | return type == bp_longjmp || type == bp_exception; | |
1182 | } | |
1183 | ||
a7bdde9e | 1184 | int |
d77f58be | 1185 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1186 | { |
d9b3f62e | 1187 | return is_tracepoint_type (b->type); |
a7bdde9e | 1188 | } |
d9b3f62e | 1189 | |
a5e364af SM |
1190 | /* Factory function to create an appropriate instance of breakpoint given |
1191 | TYPE. */ | |
1192 | ||
1193 | static std::unique_ptr<breakpoint> | |
1194 | new_breakpoint_from_type (bptype type) | |
1195 | { | |
1196 | breakpoint *b; | |
1197 | ||
1198 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1199 | b = new tracepoint (); |
3b0871f4 | 1200 | else if (is_longjmp_type (type)) |
c1fc2657 | 1201 | b = new longjmp_breakpoint (); |
a5e364af SM |
1202 | else |
1203 | b = new breakpoint (); | |
1204 | ||
1205 | return std::unique_ptr<breakpoint> (b); | |
1206 | } | |
1207 | ||
e5dd4106 | 1208 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1209 | breakpoint. This function will throw an exception if a problem is |
1210 | found. */ | |
48cb2d85 | 1211 | |
95a42b64 TT |
1212 | static void |
1213 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1214 | struct command_line *commands) | |
48cb2d85 | 1215 | { |
d77f58be | 1216 | if (is_tracepoint (b)) |
a7bdde9e | 1217 | { |
c9a6ce02 | 1218 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1219 | struct command_line *c; |
1220 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1221 | |
1222 | /* Reset the while-stepping step count. The previous commands | |
1223 | might have included a while-stepping action, while the new | |
1224 | ones might not. */ | |
1225 | t->step_count = 0; | |
1226 | ||
1227 | /* We need to verify that each top-level element of commands is | |
1228 | valid for tracepoints, that there's at most one | |
1229 | while-stepping element, and that the while-stepping's body | |
1230 | has valid tracing commands excluding nested while-stepping. | |
1231 | We also need to validate the tracepoint action line in the | |
1232 | context of the tracepoint --- validate_actionline actually | |
1233 | has side effects, like setting the tracepoint's | |
1234 | while-stepping STEP_COUNT, in addition to checking if the | |
1235 | collect/teval actions parse and make sense in the | |
1236 | tracepoint's context. */ | |
a7bdde9e VP |
1237 | for (c = commands; c; c = c->next) |
1238 | { | |
a7bdde9e VP |
1239 | if (c->control_type == while_stepping_control) |
1240 | { | |
1241 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1242 | error (_("The 'while-stepping' command " |
1243 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1244 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1245 | error (_("The 'while-stepping' command " |
1246 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1247 | |
1248 | if (while_stepping) | |
3e43a32a MS |
1249 | error (_("The 'while-stepping' command " |
1250 | "can be used only once")); | |
a7bdde9e VP |
1251 | else |
1252 | while_stepping = c; | |
1253 | } | |
c9a6ce02 PA |
1254 | |
1255 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1256 | } |
1257 | if (while_stepping) | |
1258 | { | |
1259 | struct command_line *c2; | |
1260 | ||
1261 | gdb_assert (while_stepping->body_count == 1); | |
1262 | c2 = while_stepping->body_list[0]; | |
1263 | for (; c2; c2 = c2->next) | |
1264 | { | |
a7bdde9e VP |
1265 | if (c2->control_type == while_stepping_control) |
1266 | error (_("The 'while-stepping' command cannot be nested")); | |
1267 | } | |
1268 | } | |
1269 | } | |
1270 | else | |
1271 | { | |
1272 | check_no_tracepoint_commands (commands); | |
1273 | } | |
95a42b64 TT |
1274 | } |
1275 | ||
0fb4aa4b PA |
1276 | /* Return a vector of all the static tracepoints set at ADDR. The |
1277 | caller is responsible for releasing the vector. */ | |
1278 | ||
1279 | VEC(breakpoint_p) * | |
1280 | static_tracepoints_here (CORE_ADDR addr) | |
1281 | { | |
1282 | struct breakpoint *b; | |
1283 | VEC(breakpoint_p) *found = 0; | |
1284 | struct bp_location *loc; | |
1285 | ||
1286 | ALL_BREAKPOINTS (b) | |
1287 | if (b->type == bp_static_tracepoint) | |
1288 | { | |
1289 | for (loc = b->loc; loc; loc = loc->next) | |
1290 | if (loc->address == addr) | |
1291 | VEC_safe_push(breakpoint_p, found, b); | |
1292 | } | |
1293 | ||
1294 | return found; | |
1295 | } | |
1296 | ||
95a42b64 | 1297 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1298 | validate that only allowed commands are included. */ |
95a42b64 TT |
1299 | |
1300 | void | |
4a64f543 | 1301 | breakpoint_set_commands (struct breakpoint *b, |
93921405 | 1302 | command_line_up &&commands) |
95a42b64 | 1303 | { |
93921405 | 1304 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1305 | |
9add0f1b | 1306 | decref_counted_command_line (&b->commands); |
93921405 | 1307 | b->commands = alloc_counted_command_line (commands.release ()); |
8d3788bd | 1308 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1309 | } |
1310 | ||
45a43567 TT |
1311 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1312 | is not the same as the "silent" that may appear in the breakpoint's | |
1313 | commands. */ | |
1314 | ||
1315 | void | |
1316 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1317 | { | |
1318 | int old_silent = b->silent; | |
1319 | ||
1320 | b->silent = silent; | |
1321 | if (old_silent != silent) | |
8d3788bd | 1322 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1323 | } |
1324 | ||
1325 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1326 | breakpoint work for any thread. */ | |
1327 | ||
1328 | void | |
1329 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1330 | { | |
1331 | int old_thread = b->thread; | |
1332 | ||
1333 | b->thread = thread; | |
1334 | if (old_thread != thread) | |
8d3788bd | 1335 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1336 | } |
1337 | ||
1338 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1339 | breakpoint work for any task. */ | |
1340 | ||
1341 | void | |
1342 | breakpoint_set_task (struct breakpoint *b, int task) | |
1343 | { | |
1344 | int old_task = b->task; | |
1345 | ||
1346 | b->task = task; | |
1347 | if (old_task != task) | |
8d3788bd | 1348 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1349 | } |
1350 | ||
95a42b64 TT |
1351 | void |
1352 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1353 | { |
9a3c8263 | 1354 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1355 | |
6f937416 | 1356 | validate_actionline (line, b); |
a7bdde9e VP |
1357 | } |
1358 | ||
95a42b64 | 1359 | static void |
896b6bda | 1360 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1361 | struct command_line *control) |
95a42b64 TT |
1362 | { |
1363 | struct cleanup *cleanups; | |
48649e1b | 1364 | struct counted_command_line *cmd = NULL; |
95a42b64 | 1365 | |
95a42b64 TT |
1366 | /* If we read command lines from the user, then `info' will hold an |
1367 | extra reference to the commands that we must clean up. */ | |
48649e1b | 1368 | cleanups = make_cleanup_decref_counted_command_line (&cmd); |
95a42b64 | 1369 | |
896b6bda PA |
1370 | std::string new_arg; |
1371 | ||
95a42b64 TT |
1372 | if (arg == NULL || !*arg) |
1373 | { | |
86b17b60 | 1374 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1375 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1376 | breakpoint_count); | |
95a42b64 | 1377 | else if (breakpoint_count > 0) |
896b6bda | 1378 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1379 | arg = new_arg.c_str (); |
1380 | } | |
1381 | ||
1382 | map_breakpoint_numbers | |
1383 | (arg, [&] (breakpoint *b) | |
1384 | { | |
1385 | if (cmd == NULL) | |
1386 | { | |
1387 | command_line_up l; | |
1388 | ||
1389 | if (control != NULL) | |
1390 | l = copy_command_lines (control->body_list[0]); | |
1391 | else | |
1392 | { | |
1393 | struct cleanup *old_chain; | |
1394 | char *str; | |
1395 | ||
1396 | str = xstrprintf (_("Type commands for breakpoint(s) " | |
1397 | "%s, one per line."), | |
1398 | arg); | |
1399 | ||
1400 | old_chain = make_cleanup (xfree, str); | |
1401 | ||
1402 | l = read_command_lines (str, | |
1403 | from_tty, 1, | |
1404 | (is_tracepoint (b) | |
1405 | ? check_tracepoint_command : 0), | |
1406 | b); | |
1407 | ||
1408 | do_cleanups (old_chain); | |
1409 | } | |
1410 | ||
1411 | cmd = alloc_counted_command_line (l.release ()); | |
1412 | } | |
1413 | ||
1414 | /* If a breakpoint was on the list more than once, we don't need to | |
1415 | do anything. */ | |
1416 | if (b->commands != cmd) | |
1417 | { | |
1418 | validate_commands_for_breakpoint (b, cmd->commands); | |
1419 | incref_counted_command_line (cmd); | |
1420 | decref_counted_command_line (&b->commands); | |
1421 | b->commands = cmd; | |
1422 | observer_notify_breakpoint_modified (b); | |
1423 | } | |
1424 | }); | |
95a42b64 | 1425 | |
48649e1b | 1426 | if (cmd == NULL) |
95a42b64 TT |
1427 | error (_("No breakpoints specified.")); |
1428 | ||
1429 | do_cleanups (cleanups); | |
1430 | } | |
1431 | ||
1432 | static void | |
1433 | commands_command (char *arg, int from_tty) | |
1434 | { | |
1435 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1436 | } |
40c03ae8 EZ |
1437 | |
1438 | /* Like commands_command, but instead of reading the commands from | |
1439 | input stream, takes them from an already parsed command structure. | |
1440 | ||
1441 | This is used by cli-script.c to DTRT with breakpoint commands | |
1442 | that are part of if and while bodies. */ | |
1443 | enum command_control_type | |
896b6bda | 1444 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1445 | { |
95a42b64 TT |
1446 | commands_command_1 (arg, 0, cmd); |
1447 | return simple_control; | |
40c03ae8 | 1448 | } |
876fa593 JK |
1449 | |
1450 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1451 | ||
1452 | static int | |
1453 | bp_location_has_shadow (struct bp_location *bl) | |
1454 | { | |
1455 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1456 | return 0; | |
1457 | if (!bl->inserted) | |
1458 | return 0; | |
1459 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1460 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1461 | return 0; |
1462 | return 1; | |
1463 | } | |
1464 | ||
9d497a19 PA |
1465 | /* Update BUF, which is LEN bytes read from the target address |
1466 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1467 | contents. | |
1468 | ||
1469 | If READBUF is not NULL, this buffer must not overlap with the of | |
1470 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1471 | failed assertion internal error will be raised. */ | |
1472 | ||
1473 | static void | |
1474 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1475 | const gdb_byte *writebuf_org, | |
1476 | ULONGEST memaddr, LONGEST len, | |
1477 | struct bp_target_info *target_info, | |
1478 | struct gdbarch *gdbarch) | |
1479 | { | |
1480 | /* Now do full processing of the found relevant range of elements. */ | |
1481 | CORE_ADDR bp_addr = 0; | |
1482 | int bp_size = 0; | |
1483 | int bptoffset = 0; | |
1484 | ||
1485 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1486 | current_program_space->aspace, 0)) | |
1487 | { | |
1488 | /* The breakpoint is inserted in a different address space. */ | |
1489 | return; | |
1490 | } | |
1491 | ||
1492 | /* Addresses and length of the part of the breakpoint that | |
1493 | we need to copy. */ | |
1494 | bp_addr = target_info->placed_address; | |
1495 | bp_size = target_info->shadow_len; | |
1496 | ||
1497 | if (bp_addr + bp_size <= memaddr) | |
1498 | { | |
1499 | /* The breakpoint is entirely before the chunk of memory we are | |
1500 | reading. */ | |
1501 | return; | |
1502 | } | |
1503 | ||
1504 | if (bp_addr >= memaddr + len) | |
1505 | { | |
1506 | /* The breakpoint is entirely after the chunk of memory we are | |
1507 | reading. */ | |
1508 | return; | |
1509 | } | |
1510 | ||
1511 | /* Offset within shadow_contents. */ | |
1512 | if (bp_addr < memaddr) | |
1513 | { | |
1514 | /* Only copy the second part of the breakpoint. */ | |
1515 | bp_size -= memaddr - bp_addr; | |
1516 | bptoffset = memaddr - bp_addr; | |
1517 | bp_addr = memaddr; | |
1518 | } | |
1519 | ||
1520 | if (bp_addr + bp_size > memaddr + len) | |
1521 | { | |
1522 | /* Only copy the first part of the breakpoint. */ | |
1523 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1524 | } | |
1525 | ||
1526 | if (readbuf != NULL) | |
1527 | { | |
1528 | /* Verify that the readbuf buffer does not overlap with the | |
1529 | shadow_contents buffer. */ | |
1530 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1531 | || readbuf >= (target_info->shadow_contents | |
1532 | + target_info->shadow_len)); | |
1533 | ||
1534 | /* Update the read buffer with this inserted breakpoint's | |
1535 | shadow. */ | |
1536 | memcpy (readbuf + bp_addr - memaddr, | |
1537 | target_info->shadow_contents + bptoffset, bp_size); | |
1538 | } | |
1539 | else | |
1540 | { | |
1541 | const unsigned char *bp; | |
0d5ed153 MR |
1542 | CORE_ADDR addr = target_info->reqstd_address; |
1543 | int placed_size; | |
9d497a19 PA |
1544 | |
1545 | /* Update the shadow with what we want to write to memory. */ | |
1546 | memcpy (target_info->shadow_contents + bptoffset, | |
1547 | writebuf_org + bp_addr - memaddr, bp_size); | |
1548 | ||
1549 | /* Determine appropriate breakpoint contents and size for this | |
1550 | address. */ | |
0d5ed153 | 1551 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1552 | |
1553 | /* Update the final write buffer with this inserted | |
1554 | breakpoint's INSN. */ | |
1555 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1556 | } | |
1557 | } | |
1558 | ||
8defab1a | 1559 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1560 | by replacing any memory breakpoints with their shadowed contents. |
1561 | ||
35c63cd8 JB |
1562 | If READBUF is not NULL, this buffer must not overlap with any of |
1563 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1564 | a failed assertion internal error will be raised. | |
1565 | ||
876fa593 | 1566 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1567 | bl->address - bp_locations_placed_address_before_address_max |
1568 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1569 | The range we were requested to resolve shadows for is: |
1570 | memaddr ... memaddr + len | |
1571 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1572 | memaddr + len <= (bl->address |
f5336ca5 | 1573 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1574 | and: |
f5336ca5 | 1575 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1576 | |
8defab1a | 1577 | void |
f0ba3972 PA |
1578 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1579 | const gdb_byte *writebuf_org, | |
1580 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1581 | { |
4a64f543 MS |
1582 | /* Left boundary, right boundary and median element of our binary |
1583 | search. */ | |
876fa593 JK |
1584 | unsigned bc_l, bc_r, bc; |
1585 | ||
4a64f543 MS |
1586 | /* Find BC_L which is a leftmost element which may affect BUF |
1587 | content. It is safe to report lower value but a failure to | |
1588 | report higher one. */ | |
876fa593 JK |
1589 | |
1590 | bc_l = 0; | |
f5336ca5 | 1591 | bc_r = bp_locations_count; |
876fa593 JK |
1592 | while (bc_l + 1 < bc_r) |
1593 | { | |
35df4500 | 1594 | struct bp_location *bl; |
876fa593 JK |
1595 | |
1596 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1597 | bl = bp_locations[bc]; |
876fa593 | 1598 | |
4a64f543 MS |
1599 | /* Check first BL->ADDRESS will not overflow due to the added |
1600 | constant. Then advance the left boundary only if we are sure | |
1601 | the BC element can in no way affect the BUF content (MEMADDR | |
1602 | to MEMADDR + LEN range). | |
876fa593 | 1603 | |
f5336ca5 | 1604 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1605 | offset so that we cannot miss a breakpoint with its shadow |
1606 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1607 | |
f5336ca5 | 1608 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1609 | >= bl->address) |
f5336ca5 | 1610 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1611 | <= memaddr)) |
876fa593 JK |
1612 | bc_l = bc; |
1613 | else | |
1614 | bc_r = bc; | |
1615 | } | |
1616 | ||
128070bb PA |
1617 | /* Due to the binary search above, we need to make sure we pick the |
1618 | first location that's at BC_L's address. E.g., if there are | |
1619 | multiple locations at the same address, BC_L may end up pointing | |
1620 | at a duplicate location, and miss the "master"/"inserted" | |
1621 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1622 | B: | |
1623 | ||
1624 | L1@A, L2@A, L3@B, ... | |
1625 | ||
1626 | BC_L could end up pointing at location L2, while the "master" | |
1627 | location could be L1. Since the `loc->inserted' flag is only set | |
1628 | on "master" locations, we'd forget to restore the shadow of L1 | |
1629 | and L2. */ | |
1630 | while (bc_l > 0 | |
f5336ca5 | 1631 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1632 | bc_l--; |
1633 | ||
876fa593 JK |
1634 | /* Now do full processing of the found relevant range of elements. */ |
1635 | ||
f5336ca5 | 1636 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1637 | { |
f5336ca5 | 1638 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1639 | |
35df4500 TJB |
1640 | /* bp_location array has BL->OWNER always non-NULL. */ |
1641 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1642 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1643 | bl->owner->number); |
ffce0d52 | 1644 | |
e5dd4106 | 1645 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1646 | content. */ |
1647 | ||
f5336ca5 PA |
1648 | if (bl->address >= bp_locations_placed_address_before_address_max |
1649 | && memaddr + len <= (bl->address | |
1650 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1651 | break; |
1652 | ||
35df4500 | 1653 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1654 | continue; |
6c95b8df | 1655 | |
9d497a19 PA |
1656 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1657 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1658 | } | |
c906108c | 1659 | } |
9d497a19 | 1660 | |
c906108c | 1661 | \f |
c5aa993b | 1662 | |
b775012e LM |
1663 | /* Return true if BPT is either a software breakpoint or a hardware |
1664 | breakpoint. */ | |
1665 | ||
1666 | int | |
1667 | is_breakpoint (const struct breakpoint *bpt) | |
1668 | { | |
1669 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1670 | || bpt->type == bp_hardware_breakpoint |
1671 | || bpt->type == bp_dprintf); | |
b775012e LM |
1672 | } |
1673 | ||
60e1c644 PA |
1674 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1675 | ||
a5606eee | 1676 | static int |
d77f58be | 1677 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1678 | { |
1679 | return (bpt->type == bp_hardware_watchpoint | |
1680 | || bpt->type == bp_read_watchpoint | |
1681 | || bpt->type == bp_access_watchpoint); | |
1682 | } | |
7270d8f2 | 1683 | |
60e1c644 PA |
1684 | /* Return true if BPT is of any watchpoint kind, hardware or |
1685 | software. */ | |
1686 | ||
3a5c3e22 | 1687 | int |
d77f58be | 1688 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1689 | { |
1690 | return (is_hardware_watchpoint (bpt) | |
1691 | || bpt->type == bp_watchpoint); | |
1692 | } | |
1693 | ||
3a5c3e22 PA |
1694 | /* Returns true if the current thread and its running state are safe |
1695 | to evaluate or update watchpoint B. Watchpoints on local | |
1696 | expressions need to be evaluated in the context of the thread that | |
1697 | was current when the watchpoint was created, and, that thread needs | |
1698 | to be stopped to be able to select the correct frame context. | |
1699 | Watchpoints on global expressions can be evaluated on any thread, | |
1700 | and in any state. It is presently left to the target allowing | |
1701 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1702 | |
1703 | static int | |
3a5c3e22 | 1704 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1705 | { |
c1fc2657 | 1706 | return (b->pspace == current_program_space |
d0d8b0c6 JK |
1707 | && (ptid_equal (b->watchpoint_thread, null_ptid) |
1708 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1709 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1710 | } |
1711 | ||
d0fb5eae JK |
1712 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1713 | associated bp_watchpoint_scope breakpoint. */ | |
1714 | ||
1715 | static void | |
3a5c3e22 | 1716 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1717 | { |
c1fc2657 | 1718 | if (w->related_breakpoint != w) |
d0fb5eae | 1719 | { |
c1fc2657 SM |
1720 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1721 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1722 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1723 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1724 | w->related_breakpoint = w; | |
d0fb5eae | 1725 | } |
c1fc2657 | 1726 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1727 | } |
1728 | ||
bb9d5f81 PP |
1729 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1730 | watchpoint W. */ | |
1731 | ||
1732 | static struct value * | |
1733 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1734 | { | |
1735 | struct value *bit_val; | |
1736 | ||
1737 | if (val == NULL) | |
1738 | return NULL; | |
1739 | ||
1740 | bit_val = allocate_value (value_type (val)); | |
1741 | ||
1742 | unpack_value_bitfield (bit_val, | |
1743 | w->val_bitpos, | |
1744 | w->val_bitsize, | |
1745 | value_contents_for_printing (val), | |
1746 | value_offset (val), | |
1747 | val); | |
1748 | ||
1749 | return bit_val; | |
1750 | } | |
1751 | ||
c6d81124 PA |
1752 | /* Allocate a dummy location and add it to B, which must be a software |
1753 | watchpoint. This is required because even if a software watchpoint | |
1754 | is not watching any memory, bpstat_stop_status requires a location | |
1755 | to be able to report stops. */ | |
1756 | ||
1757 | static void | |
1758 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1759 | struct program_space *pspace) | |
1760 | { | |
1761 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1762 | ||
1763 | b->loc = allocate_bp_location (b); | |
1764 | b->loc->pspace = pspace; | |
1765 | b->loc->address = -1; | |
1766 | b->loc->length = -1; | |
1767 | } | |
1768 | ||
1769 | /* Returns true if B is a software watchpoint that is not watching any | |
1770 | memory (e.g., "watch $pc"). */ | |
1771 | ||
1772 | static int | |
1773 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1774 | { | |
1775 | return (b->type == bp_watchpoint | |
1776 | && b->loc != NULL | |
1777 | && b->loc->next == NULL | |
1778 | && b->loc->address == -1 | |
1779 | && b->loc->length == -1); | |
1780 | } | |
1781 | ||
567e1b4e JB |
1782 | /* Assuming that B is a watchpoint: |
1783 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1784 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1785 | - Evaluate the condition if there is one, and store the result |
1786 | in b->loc->cond. | |
a5606eee VP |
1787 | - Update the list of values that must be watched in B->loc. |
1788 | ||
4a64f543 MS |
1789 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1790 | nothing. If this is local watchpoint that is out of scope, delete | |
1791 | it. | |
1792 | ||
1793 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1794 | removed + inserted on each stop here. Normal breakpoints must | |
1795 | never be removed because they might be missed by a running thread | |
1796 | when debugging in non-stop mode. On the other hand, hardware | |
1797 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1798 | to each LWP since they are stored in each LWP's hardware debug | |
1799 | registers. Therefore, such LWP must be stopped first in order to | |
1800 | be able to modify its hardware watchpoints. | |
1801 | ||
1802 | Hardware watchpoints must be reset exactly once after being | |
1803 | presented to the user. It cannot be done sooner, because it would | |
1804 | reset the data used to present the watchpoint hit to the user. And | |
1805 | it must not be done later because it could display the same single | |
1806 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1807 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1808 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1809 | not user-visible - its hit is suppressed if the memory content has | |
1810 | not changed. | |
1811 | ||
1812 | The following constraints influence the location where we can reset | |
1813 | hardware watchpoints: | |
1814 | ||
1815 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1816 | called several times when GDB stops. | |
1817 | ||
1818 | [linux] | |
1819 | * Multiple hardware watchpoints can be hit at the same time, | |
1820 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1821 | hit at a time as the reason for stopping, and all the other hits | |
1822 | are presented later, one after the other, each time the user | |
1823 | requests the execution to be resumed. Execution is not resumed | |
1824 | for the threads still having pending hit event stored in | |
1825 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1826 | the inferior on the first stop the thread hit event is kept being | |
1827 | reported from its cached value by linux_nat_stopped_data_address | |
1828 | until the real thread resume happens after the watchpoint gets | |
1829 | presented and thus its LWP_INFO->STATUS gets reset. | |
1830 | ||
1831 | Therefore the hardware watchpoint hit can get safely reset on the | |
1832 | watchpoint removal from inferior. */ | |
a79d3c27 | 1833 | |
b40ce68a | 1834 | static void |
3a5c3e22 | 1835 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1836 | { |
a5606eee | 1837 | int within_current_scope; |
a5606eee | 1838 | struct frame_id saved_frame_id; |
66076460 | 1839 | int frame_saved; |
a5606eee | 1840 | |
f6bc2008 PA |
1841 | /* If this is a local watchpoint, we only want to check if the |
1842 | watchpoint frame is in scope if the current thread is the thread | |
1843 | that was used to create the watchpoint. */ | |
1844 | if (!watchpoint_in_thread_scope (b)) | |
1845 | return; | |
1846 | ||
c1fc2657 | 1847 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1848 | return; |
1849 | ||
66076460 | 1850 | frame_saved = 0; |
a5606eee VP |
1851 | |
1852 | /* Determine if the watchpoint is within scope. */ | |
1853 | if (b->exp_valid_block == NULL) | |
1854 | within_current_scope = 1; | |
1855 | else | |
1856 | { | |
b5db5dfc UW |
1857 | struct frame_info *fi = get_current_frame (); |
1858 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1859 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1860 | ||
c9cf6e20 MG |
1861 | /* If we're at a point where the stack has been destroyed |
1862 | (e.g. in a function epilogue), unwinding may not work | |
1863 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1864 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1865 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1866 | return; |
66076460 DJ |
1867 | |
1868 | /* Save the current frame's ID so we can restore it after | |
1869 | evaluating the watchpoint expression on its own frame. */ | |
1870 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1871 | took a frame parameter, so that we didn't have to change the | |
1872 | selected frame. */ | |
1873 | frame_saved = 1; | |
1874 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1875 | ||
a5606eee VP |
1876 | fi = frame_find_by_id (b->watchpoint_frame); |
1877 | within_current_scope = (fi != NULL); | |
1878 | if (within_current_scope) | |
1879 | select_frame (fi); | |
1880 | } | |
1881 | ||
b5db5dfc UW |
1882 | /* We don't free locations. They are stored in the bp_location array |
1883 | and update_global_location_list will eventually delete them and | |
1884 | remove breakpoints if needed. */ | |
c1fc2657 | 1885 | b->loc = NULL; |
b5db5dfc | 1886 | |
a5606eee VP |
1887 | if (within_current_scope && reparse) |
1888 | { | |
bbc13ae3 | 1889 | const char *s; |
d63d0675 | 1890 | |
4d01a485 | 1891 | b->exp.reset (); |
d63d0675 | 1892 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1893 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1894 | /* If the meaning of expression itself changed, the old value is |
1895 | no longer relevant. We don't want to report a watchpoint hit | |
1896 | to the user when the old value and the new value may actually | |
1897 | be completely different objects. */ | |
1898 | value_free (b->val); | |
fa4727a6 DJ |
1899 | b->val = NULL; |
1900 | b->val_valid = 0; | |
60e1c644 PA |
1901 | |
1902 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1903 | expression is stored in the breakpoint object, not in the | |
1904 | locations (re)created below. */ | |
c1fc2657 | 1905 | if (b->cond_string != NULL) |
60e1c644 | 1906 | { |
4d01a485 | 1907 | b->cond_exp.reset (); |
60e1c644 | 1908 | |
c1fc2657 | 1909 | s = b->cond_string; |
1bb9788d | 1910 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1911 | } |
a5606eee | 1912 | } |
a5606eee VP |
1913 | |
1914 | /* If we failed to parse the expression, for example because | |
1915 | it refers to a global variable in a not-yet-loaded shared library, | |
1916 | don't try to insert watchpoint. We don't automatically delete | |
1917 | such watchpoint, though, since failure to parse expression | |
1918 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1919 | if (!target_has_execution) |
2d134ed3 PA |
1920 | { |
1921 | /* Without execution, memory can't change. No use to try and | |
1922 | set watchpoint locations. The watchpoint will be reset when | |
1923 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1924 | if (!can_use_hw_watchpoints) |
1925 | { | |
c1fc2657 SM |
1926 | if (b->ops->works_in_software_mode (b)) |
1927 | b->type = bp_watchpoint; | |
e8369a73 | 1928 | else |
638aa5a1 AB |
1929 | error (_("Can't set read/access watchpoint when " |
1930 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1931 | } |
2d134ed3 PA |
1932 | } |
1933 | else if (within_current_scope && b->exp) | |
a5606eee | 1934 | { |
0cf6dd15 | 1935 | int pc = 0; |
fa4727a6 | 1936 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1937 | struct program_space *frame_pspace; |
a5606eee | 1938 | |
4d01a485 | 1939 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1940 | |
a5606eee VP |
1941 | /* Avoid setting b->val if it's already set. The meaning of |
1942 | b->val is 'the last value' user saw, and we should update | |
1943 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1944 | happens, the code that reports it updates b->val directly. |
1945 | We don't keep track of the memory value for masked | |
1946 | watchpoints. */ | |
c1fc2657 | 1947 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1948 | { |
bb9d5f81 PP |
1949 | if (b->val_bitsize != 0) |
1950 | { | |
1951 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1952 | if (v != NULL) | |
1953 | release_value (v); | |
1954 | } | |
fa4727a6 DJ |
1955 | b->val = v; |
1956 | b->val_valid = 1; | |
1957 | } | |
a5606eee | 1958 | |
2d134ed3 PA |
1959 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1960 | ||
a5606eee | 1961 | /* Look at each value on the value chain. */ |
9fa40276 | 1962 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1963 | { |
1964 | /* If it's a memory location, and GDB actually needed | |
1965 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1966 | must watch it. If the first value returned is |
1967 | still lazy, that means an error occurred reading it; | |
1968 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1969 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1970 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1971 | { |
1972 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1973 | |
a5606eee VP |
1974 | /* We only watch structs and arrays if user asked |
1975 | for it explicitly, never if they just happen to | |
1976 | appear in the middle of some value chain. */ | |
fa4727a6 | 1977 | if (v == result |
a5606eee VP |
1978 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1979 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1980 | { | |
1981 | CORE_ADDR addr; | |
f486487f | 1982 | enum target_hw_bp_type type; |
a5606eee | 1983 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1984 | int bitpos = 0, bitsize = 0; |
1985 | ||
1986 | if (value_bitsize (v) != 0) | |
1987 | { | |
1988 | /* Extract the bit parameters out from the bitfield | |
1989 | sub-expression. */ | |
1990 | bitpos = value_bitpos (v); | |
1991 | bitsize = value_bitsize (v); | |
1992 | } | |
1993 | else if (v == result && b->val_bitsize != 0) | |
1994 | { | |
1995 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1996 | lvalue whose bit parameters are saved in the fields | |
1997 | VAL_BITPOS and VAL_BITSIZE. */ | |
1998 | bitpos = b->val_bitpos; | |
1999 | bitsize = b->val_bitsize; | |
2000 | } | |
a5606eee | 2001 | |
42ae5230 | 2002 | addr = value_address (v); |
bb9d5f81 PP |
2003 | if (bitsize != 0) |
2004 | { | |
2005 | /* Skip the bytes that don't contain the bitfield. */ | |
2006 | addr += bitpos / 8; | |
2007 | } | |
2008 | ||
a5606eee | 2009 | type = hw_write; |
c1fc2657 | 2010 | if (b->type == bp_read_watchpoint) |
a5606eee | 2011 | type = hw_read; |
c1fc2657 | 2012 | else if (b->type == bp_access_watchpoint) |
a5606eee | 2013 | type = hw_access; |
3a5c3e22 | 2014 | |
c1fc2657 SM |
2015 | loc = allocate_bp_location (b); |
2016 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2017 | ; |
2018 | *tmp = loc; | |
a6d9a66e | 2019 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2020 | |
2021 | loc->pspace = frame_pspace; | |
a5606eee | 2022 | loc->address = addr; |
bb9d5f81 PP |
2023 | |
2024 | if (bitsize != 0) | |
2025 | { | |
2026 | /* Just cover the bytes that make up the bitfield. */ | |
2027 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2028 | } | |
2029 | else | |
2030 | loc->length = TYPE_LENGTH (value_type (v)); | |
2031 | ||
a5606eee VP |
2032 | loc->watchpoint_type = type; |
2033 | } | |
2034 | } | |
9fa40276 TJB |
2035 | } |
2036 | ||
2037 | /* Change the type of breakpoint between hardware assisted or | |
2038 | an ordinary watchpoint depending on the hardware support | |
2039 | and free hardware slots. REPARSE is set when the inferior | |
2040 | is started. */ | |
a9634178 | 2041 | if (reparse) |
9fa40276 | 2042 | { |
e09342b5 | 2043 | int reg_cnt; |
9fa40276 TJB |
2044 | enum bp_loc_type loc_type; |
2045 | struct bp_location *bl; | |
a5606eee | 2046 | |
a9634178 | 2047 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2048 | |
2049 | if (reg_cnt) | |
9fa40276 TJB |
2050 | { |
2051 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2052 | enum bptype type; |
9fa40276 | 2053 | |
a9634178 TJB |
2054 | /* Use an exact watchpoint when there's only one memory region to be |
2055 | watched, and only one debug register is needed to watch it. */ | |
2056 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2057 | ||
9fa40276 | 2058 | /* We need to determine how many resources are already |
e09342b5 TJB |
2059 | used for all other hardware watchpoints plus this one |
2060 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2061 | this watchpoint in as well. */ |
2062 | ||
2063 | /* If this is a software watchpoint, we try to turn it | |
2064 | to a hardware one -- count resources as if B was of | |
2065 | hardware watchpoint type. */ | |
c1fc2657 | 2066 | type = b->type; |
a1398e0c PA |
2067 | if (type == bp_watchpoint) |
2068 | type = bp_hardware_watchpoint; | |
2069 | ||
2070 | /* This watchpoint may or may not have been placed on | |
2071 | the list yet at this point (it won't be in the list | |
2072 | if we're trying to create it for the first time, | |
2073 | through watch_command), so always account for it | |
2074 | manually. */ | |
2075 | ||
2076 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 2077 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
2078 | |
2079 | /* Add in the resources needed for B. */ | |
c1fc2657 | 2080 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
2081 | |
2082 | target_resources_ok | |
2083 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2084 | if (target_resources_ok <= 0) |
a9634178 | 2085 | { |
c1fc2657 | 2086 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
2087 | |
2088 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2089 | error (_("Target does not support this type of " |
2090 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2091 | else if (target_resources_ok < 0 && !sw_mode) |
2092 | error (_("There are not enough available hardware " | |
2093 | "resources for this watchpoint.")); | |
a1398e0c PA |
2094 | |
2095 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 2096 | b->type = bp_watchpoint; |
a1398e0c PA |
2097 | } |
2098 | else | |
2099 | { | |
2100 | /* If this was a software watchpoint, we've just | |
2101 | found we have enough resources to turn it to a | |
2102 | hardware watchpoint. Otherwise, this is a | |
2103 | nop. */ | |
c1fc2657 | 2104 | b->type = type; |
a9634178 | 2105 | } |
9fa40276 | 2106 | } |
c1fc2657 | 2107 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
2108 | { |
2109 | if (!can_use_hw_watchpoints) | |
2110 | error (_("Can't set read/access watchpoint when " | |
2111 | "hardware watchpoints are disabled.")); | |
2112 | else | |
2113 | error (_("Expression cannot be implemented with " | |
2114 | "read/access watchpoint.")); | |
2115 | } | |
9fa40276 | 2116 | else |
c1fc2657 | 2117 | b->type = bp_watchpoint; |
9fa40276 | 2118 | |
c1fc2657 | 2119 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2120 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 2121 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
2122 | bl->loc_type = loc_type; |
2123 | } | |
2124 | ||
2125 | for (v = val_chain; v; v = next) | |
2126 | { | |
a5606eee VP |
2127 | next = value_next (v); |
2128 | if (v != b->val) | |
2129 | value_free (v); | |
2130 | } | |
2131 | ||
c7437ca6 PA |
2132 | /* If a software watchpoint is not watching any memory, then the |
2133 | above left it without any location set up. But, | |
2134 | bpstat_stop_status requires a location to be able to report | |
2135 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2136 | if (b->type == bp_watchpoint && b->loc == NULL) |
2137 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2138 | } |
2139 | else if (!within_current_scope) | |
7270d8f2 | 2140 | { |
ac74f770 MS |
2141 | printf_filtered (_("\ |
2142 | Watchpoint %d deleted because the program has left the block\n\ | |
2143 | in which its expression is valid.\n"), | |
c1fc2657 | 2144 | b->number); |
d0fb5eae | 2145 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2146 | } |
a5606eee VP |
2147 | |
2148 | /* Restore the selected frame. */ | |
66076460 DJ |
2149 | if (frame_saved) |
2150 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2151 | } |
2152 | ||
a5606eee | 2153 | |
74960c60 | 2154 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2155 | inserted in the inferior. We don't differentiate the type of BL's owner |
2156 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2157 | breakpoint_ops is not defined, because in insert_bp_location, | |
2158 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2159 | static int |
35df4500 | 2160 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2161 | { |
35df4500 | 2162 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2163 | return 0; |
2164 | ||
35df4500 | 2165 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2166 | return 0; |
2167 | ||
35df4500 | 2168 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2169 | return 0; |
2170 | ||
f8eba3c6 TT |
2171 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2172 | return 0; | |
2173 | ||
56710373 PA |
2174 | /* This is set for example, when we're attached to the parent of a |
2175 | vfork, and have detached from the child. The child is running | |
2176 | free, and we expect it to do an exec or exit, at which point the | |
2177 | OS makes the parent schedulable again (and the target reports | |
2178 | that the vfork is done). Until the child is done with the shared | |
2179 | memory region, do not insert breakpoints in the parent, otherwise | |
2180 | the child could still trip on the parent's breakpoints. Since | |
2181 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2182 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2183 | return 0; |
2184 | ||
31e77af2 | 2185 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2186 | location, except if the breakpoint is a single-step breakpoint, |
2187 | and the breakpoint's thread is the thread which is stepping past | |
2188 | a breakpoint. */ | |
31e77af2 PA |
2189 | if ((bl->loc_type == bp_loc_software_breakpoint |
2190 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2191 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2192 | bl->address) |
2193 | /* The single-step breakpoint may be inserted at the location | |
2194 | we're trying to step if the instruction branches to itself. | |
2195 | However, the instruction won't be executed at all and it may | |
2196 | break the semantics of the instruction, for example, the | |
2197 | instruction is a conditional branch or updates some flags. | |
2198 | We can't fix it unless GDB is able to emulate the instruction | |
2199 | or switch to displaced stepping. */ | |
2200 | && !(bl->owner->type == bp_single_step | |
2201 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2202 | { |
2203 | if (debug_infrun) | |
2204 | { | |
2205 | fprintf_unfiltered (gdb_stdlog, | |
2206 | "infrun: skipping breakpoint: " | |
2207 | "stepping past insn at: %s\n", | |
2208 | paddress (bl->gdbarch, bl->address)); | |
2209 | } | |
2210 | return 0; | |
2211 | } | |
31e77af2 | 2212 | |
963f9c80 PA |
2213 | /* Don't insert watchpoints if we're trying to step past the |
2214 | instruction that triggered one. */ | |
2215 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2216 | && stepping_past_nonsteppable_watchpoint ()) | |
2217 | { | |
2218 | if (debug_infrun) | |
2219 | { | |
2220 | fprintf_unfiltered (gdb_stdlog, | |
2221 | "infrun: stepping past non-steppable watchpoint. " | |
2222 | "skipping watchpoint at %s:%d\n", | |
2223 | paddress (bl->gdbarch, bl->address), | |
2224 | bl->length); | |
2225 | } | |
2226 | return 0; | |
2227 | } | |
2228 | ||
74960c60 VP |
2229 | return 1; |
2230 | } | |
2231 | ||
934709f0 PW |
2232 | /* Same as should_be_inserted but does the check assuming |
2233 | that the location is not duplicated. */ | |
2234 | ||
2235 | static int | |
2236 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2237 | { | |
2238 | int result; | |
2239 | const int save_duplicate = bl->duplicate; | |
2240 | ||
2241 | bl->duplicate = 0; | |
2242 | result = should_be_inserted (bl); | |
2243 | bl->duplicate = save_duplicate; | |
2244 | return result; | |
2245 | } | |
2246 | ||
b775012e LM |
2247 | /* Parses a conditional described by an expression COND into an |
2248 | agent expression bytecode suitable for evaluation | |
2249 | by the bytecode interpreter. Return NULL if there was | |
2250 | any error during parsing. */ | |
2251 | ||
833177a4 | 2252 | static agent_expr_up |
b775012e LM |
2253 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2254 | { | |
833177a4 | 2255 | if (cond == NULL) |
b775012e LM |
2256 | return NULL; |
2257 | ||
833177a4 PA |
2258 | agent_expr_up aexpr; |
2259 | ||
b775012e LM |
2260 | /* We don't want to stop processing, so catch any errors |
2261 | that may show up. */ | |
492d29ea | 2262 | TRY |
b775012e | 2263 | { |
036e657b | 2264 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2265 | } |
2266 | ||
492d29ea | 2267 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2268 | { |
2269 | /* If we got here, it means the condition could not be parsed to a valid | |
2270 | bytecode expression and thus can't be evaluated on the target's side. | |
2271 | It's no use iterating through the conditions. */ | |
b775012e | 2272 | } |
492d29ea | 2273 | END_CATCH |
b775012e LM |
2274 | |
2275 | /* We have a valid agent expression. */ | |
2276 | return aexpr; | |
2277 | } | |
2278 | ||
2279 | /* Based on location BL, create a list of breakpoint conditions to be | |
2280 | passed on to the target. If we have duplicated locations with different | |
2281 | conditions, we will add such conditions to the list. The idea is that the | |
2282 | target will evaluate the list of conditions and will only notify GDB when | |
2283 | one of them is true. */ | |
2284 | ||
2285 | static void | |
2286 | build_target_condition_list (struct bp_location *bl) | |
2287 | { | |
2288 | struct bp_location **locp = NULL, **loc2p; | |
2289 | int null_condition_or_parse_error = 0; | |
2290 | int modified = bl->needs_update; | |
2291 | struct bp_location *loc; | |
2292 | ||
8b4f3082 | 2293 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2294 | bl->target_info.conditions.clear (); |
8b4f3082 | 2295 | |
b775012e LM |
2296 | /* This is only meaningful if the target is |
2297 | evaluating conditions and if the user has | |
2298 | opted for condition evaluation on the target's | |
2299 | side. */ | |
2300 | if (gdb_evaluates_breakpoint_condition_p () | |
2301 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2302 | return; | |
2303 | ||
2304 | /* Do a first pass to check for locations with no assigned | |
2305 | conditions or conditions that fail to parse to a valid agent expression | |
2306 | bytecode. If any of these happen, then it's no use to send conditions | |
2307 | to the target since this location will always trigger and generate a | |
2308 | response back to GDB. */ | |
2309 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2310 | { | |
2311 | loc = (*loc2p); | |
2312 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2313 | { | |
2314 | if (modified) | |
2315 | { | |
b775012e LM |
2316 | /* Re-parse the conditions since something changed. In that |
2317 | case we already freed the condition bytecodes (see | |
2318 | force_breakpoint_reinsertion). We just | |
2319 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2320 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2321 | loc->cond.get ()); | |
b775012e LM |
2322 | } |
2323 | ||
2324 | /* If we have a NULL bytecode expression, it means something | |
2325 | went wrong or we have a null condition expression. */ | |
2326 | if (!loc->cond_bytecode) | |
2327 | { | |
2328 | null_condition_or_parse_error = 1; | |
2329 | break; | |
2330 | } | |
2331 | } | |
2332 | } | |
2333 | ||
2334 | /* If any of these happened, it means we will have to evaluate the conditions | |
2335 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2336 | for all the other duplicate locations, thus we free all of them here. | |
2337 | ||
2338 | This is so we have a finer control over which locations' conditions are | |
2339 | being evaluated by GDB or the remote stub. */ | |
2340 | if (null_condition_or_parse_error) | |
2341 | { | |
2342 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2343 | { | |
2344 | loc = (*loc2p); | |
2345 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2346 | { | |
2347 | /* Only go as far as the first NULL bytecode is | |
2348 | located. */ | |
2349 | if (!loc->cond_bytecode) | |
2350 | return; | |
2351 | ||
833177a4 | 2352 | loc->cond_bytecode.reset (); |
b775012e LM |
2353 | } |
2354 | } | |
2355 | } | |
2356 | ||
2357 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2358 | for this location's address. */ | |
2359 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2360 | { | |
2361 | loc = (*loc2p); | |
2362 | if (loc->cond | |
2363 | && is_breakpoint (loc->owner) | |
2364 | && loc->pspace->num == bl->pspace->num | |
2365 | && loc->owner->enable_state == bp_enabled | |
2366 | && loc->enabled) | |
3cde5c42 PA |
2367 | { |
2368 | /* Add the condition to the vector. This will be used later | |
2369 | to send the conditions to the target. */ | |
2370 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2371 | } | |
b775012e LM |
2372 | } |
2373 | ||
2374 | return; | |
2375 | } | |
2376 | ||
d3ce09f5 SS |
2377 | /* Parses a command described by string CMD into an agent expression |
2378 | bytecode suitable for evaluation by the bytecode interpreter. | |
2379 | Return NULL if there was any error during parsing. */ | |
2380 | ||
833177a4 | 2381 | static agent_expr_up |
d3ce09f5 SS |
2382 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2383 | { | |
2384 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2385 | struct expression **argvec; |
bbc13ae3 KS |
2386 | const char *cmdrest; |
2387 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2388 | struct format_piece *fpieces; |
2389 | int nargs; | |
2390 | struct gdbarch *gdbarch = get_current_arch (); | |
2391 | ||
833177a4 | 2392 | if (cmd == NULL) |
d3ce09f5 SS |
2393 | return NULL; |
2394 | ||
2395 | cmdrest = cmd; | |
2396 | ||
2397 | if (*cmdrest == ',') | |
2398 | ++cmdrest; | |
f1735a53 | 2399 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2400 | |
2401 | if (*cmdrest++ != '"') | |
2402 | error (_("No format string following the location")); | |
2403 | ||
2404 | format_start = cmdrest; | |
2405 | ||
2406 | fpieces = parse_format_string (&cmdrest); | |
2407 | ||
2408 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2409 | ||
2410 | format_end = cmdrest; | |
2411 | ||
2412 | if (*cmdrest++ != '"') | |
2413 | error (_("Bad format string, non-terminated '\"'.")); | |
2414 | ||
f1735a53 | 2415 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2416 | |
2417 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2418 | error (_("Invalid argument syntax")); | |
2419 | ||
2420 | if (*cmdrest == ',') | |
2421 | cmdrest++; | |
f1735a53 | 2422 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2423 | |
2424 | /* For each argument, make an expression. */ | |
2425 | ||
2426 | argvec = (struct expression **) alloca (strlen (cmd) | |
2427 | * sizeof (struct expression *)); | |
2428 | ||
2429 | nargs = 0; | |
2430 | while (*cmdrest != '\0') | |
2431 | { | |
bbc13ae3 | 2432 | const char *cmd1; |
d3ce09f5 SS |
2433 | |
2434 | cmd1 = cmdrest; | |
4d01a485 PA |
2435 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2436 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2437 | cmdrest = cmd1; |
2438 | if (*cmdrest == ',') | |
2439 | ++cmdrest; | |
2440 | } | |
2441 | ||
833177a4 PA |
2442 | agent_expr_up aexpr; |
2443 | ||
d3ce09f5 SS |
2444 | /* We don't want to stop processing, so catch any errors |
2445 | that may show up. */ | |
492d29ea | 2446 | TRY |
d3ce09f5 | 2447 | { |
036e657b JB |
2448 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2449 | format_start, format_end - format_start, | |
2450 | fpieces, nargs, argvec); | |
d3ce09f5 | 2451 | } |
492d29ea | 2452 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2453 | { |
2454 | /* If we got here, it means the command could not be parsed to a valid | |
2455 | bytecode expression and thus can't be evaluated on the target's side. | |
2456 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2457 | } |
492d29ea PA |
2458 | END_CATCH |
2459 | ||
2460 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2461 | |
d3ce09f5 SS |
2462 | /* We have a valid agent expression, return it. */ |
2463 | return aexpr; | |
2464 | } | |
2465 | ||
2466 | /* Based on location BL, create a list of breakpoint commands to be | |
2467 | passed on to the target. If we have duplicated locations with | |
2468 | different commands, we will add any such to the list. */ | |
2469 | ||
2470 | static void | |
2471 | build_target_command_list (struct bp_location *bl) | |
2472 | { | |
2473 | struct bp_location **locp = NULL, **loc2p; | |
2474 | int null_command_or_parse_error = 0; | |
2475 | int modified = bl->needs_update; | |
2476 | struct bp_location *loc; | |
2477 | ||
3cde5c42 PA |
2478 | /* Clear commands left over from a previous insert. */ |
2479 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2480 | |
41fac0cf | 2481 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2482 | return; |
2483 | ||
41fac0cf PA |
2484 | /* For now, limit to agent-style dprintf breakpoints. */ |
2485 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2486 | return; |
2487 | ||
41fac0cf PA |
2488 | /* For now, if we have any duplicate location that isn't a dprintf, |
2489 | don't install the target-side commands, as that would make the | |
2490 | breakpoint not be reported to the core, and we'd lose | |
2491 | control. */ | |
2492 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2493 | { | |
2494 | loc = (*loc2p); | |
2495 | if (is_breakpoint (loc->owner) | |
2496 | && loc->pspace->num == bl->pspace->num | |
2497 | && loc->owner->type != bp_dprintf) | |
2498 | return; | |
2499 | } | |
2500 | ||
d3ce09f5 SS |
2501 | /* Do a first pass to check for locations with no assigned |
2502 | conditions or conditions that fail to parse to a valid agent expression | |
2503 | bytecode. If any of these happen, then it's no use to send conditions | |
2504 | to the target since this location will always trigger and generate a | |
2505 | response back to GDB. */ | |
2506 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2507 | { | |
2508 | loc = (*loc2p); | |
2509 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2510 | { | |
2511 | if (modified) | |
2512 | { | |
d3ce09f5 SS |
2513 | /* Re-parse the commands since something changed. In that |
2514 | case we already freed the command bytecodes (see | |
2515 | force_breakpoint_reinsertion). We just | |
2516 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2517 | loc->cmd_bytecode |
2518 | = parse_cmd_to_aexpr (bl->address, | |
2519 | loc->owner->extra_string); | |
d3ce09f5 SS |
2520 | } |
2521 | ||
2522 | /* If we have a NULL bytecode expression, it means something | |
2523 | went wrong or we have a null command expression. */ | |
2524 | if (!loc->cmd_bytecode) | |
2525 | { | |
2526 | null_command_or_parse_error = 1; | |
2527 | break; | |
2528 | } | |
2529 | } | |
2530 | } | |
2531 | ||
2532 | /* If anything failed, then we're not doing target-side commands, | |
2533 | and so clean up. */ | |
2534 | if (null_command_or_parse_error) | |
2535 | { | |
2536 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2537 | { | |
2538 | loc = (*loc2p); | |
2539 | if (is_breakpoint (loc->owner) | |
2540 | && loc->pspace->num == bl->pspace->num) | |
2541 | { | |
2542 | /* Only go as far as the first NULL bytecode is | |
2543 | located. */ | |
40fb6c5e | 2544 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2545 | return; |
2546 | ||
833177a4 | 2547 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2548 | } |
2549 | } | |
2550 | } | |
2551 | ||
2552 | /* No NULL commands or failed bytecode generation. Build a command list | |
2553 | for this location's address. */ | |
2554 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2555 | { | |
2556 | loc = (*loc2p); | |
2557 | if (loc->owner->extra_string | |
2558 | && is_breakpoint (loc->owner) | |
2559 | && loc->pspace->num == bl->pspace->num | |
2560 | && loc->owner->enable_state == bp_enabled | |
2561 | && loc->enabled) | |
3cde5c42 PA |
2562 | { |
2563 | /* Add the command to the vector. This will be used later | |
2564 | to send the commands to the target. */ | |
2565 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2566 | } | |
d3ce09f5 SS |
2567 | } |
2568 | ||
2569 | bl->target_info.persist = 0; | |
2570 | /* Maybe flag this location as persistent. */ | |
2571 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2572 | bl->target_info.persist = 1; | |
2573 | } | |
2574 | ||
833b7ab5 YQ |
2575 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2576 | of breakpoint according to ADDR except single-step breakpoint. | |
2577 | Get the kind of single-step breakpoint according to the current | |
2578 | registers state. */ | |
cd6c3b4f YQ |
2579 | |
2580 | static int | |
2581 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2582 | { | |
833b7ab5 YQ |
2583 | if (bl->owner->type == bp_single_step) |
2584 | { | |
2585 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2586 | struct regcache *regcache; | |
2587 | ||
2588 | regcache = get_thread_regcache (thr->ptid); | |
2589 | ||
2590 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2591 | regcache, addr); | |
2592 | } | |
2593 | else | |
2594 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2595 | } |
2596 | ||
35df4500 TJB |
2597 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2598 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2599 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2600 | Returns 0 for success, 1 if the bp_location type is not supported or |
2601 | -1 for failure. | |
879bfdc2 | 2602 | |
4a64f543 MS |
2603 | NOTE drow/2003-09-09: This routine could be broken down to an |
2604 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2605 | static int |
35df4500 | 2606 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2607 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2608 | int *disabled_breaks, |
dd61ec5c MW |
2609 | int *hw_breakpoint_error, |
2610 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2611 | { |
0000e5cc PA |
2612 | enum errors bp_err = GDB_NO_ERROR; |
2613 | const char *bp_err_message = NULL; | |
879bfdc2 | 2614 | |
b775012e | 2615 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2616 | return 0; |
2617 | ||
35c63cd8 JB |
2618 | /* Note we don't initialize bl->target_info, as that wipes out |
2619 | the breakpoint location's shadow_contents if the breakpoint | |
2620 | is still inserted at that location. This in turn breaks | |
2621 | target_read_memory which depends on these buffers when | |
2622 | a memory read is requested at the breakpoint location: | |
2623 | Once the target_info has been wiped, we fail to see that | |
2624 | we have a breakpoint inserted at that address and thus | |
2625 | read the breakpoint instead of returning the data saved in | |
2626 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2627 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2628 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2629 | bl->target_info.length = bl->length; |
8181d85f | 2630 | |
b775012e LM |
2631 | /* When working with target-side conditions, we must pass all the conditions |
2632 | for the same breakpoint address down to the target since GDB will not | |
2633 | insert those locations. With a list of breakpoint conditions, the target | |
2634 | can decide when to stop and notify GDB. */ | |
2635 | ||
2636 | if (is_breakpoint (bl->owner)) | |
2637 | { | |
2638 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2639 | build_target_command_list (bl); |
2640 | /* Reset the modification marker. */ | |
b775012e LM |
2641 | bl->needs_update = 0; |
2642 | } | |
2643 | ||
35df4500 TJB |
2644 | if (bl->loc_type == bp_loc_software_breakpoint |
2645 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2646 | { |
35df4500 | 2647 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2648 | { |
2649 | /* If the explicitly specified breakpoint type | |
2650 | is not hardware breakpoint, check the memory map to see | |
2651 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2652 | |
765dc015 VP |
2653 | Two important cases are: |
2654 | - location type is not hardware breakpoint, memory | |
2655 | is readonly. We change the type of the location to | |
2656 | hardware breakpoint. | |
4a64f543 MS |
2657 | - location type is hardware breakpoint, memory is |
2658 | read-write. This means we've previously made the | |
2659 | location hardware one, but then the memory map changed, | |
2660 | so we undo. | |
765dc015 | 2661 | |
4a64f543 MS |
2662 | When breakpoints are removed, remove_breakpoints will use |
2663 | location types we've just set here, the only possible | |
2664 | problem is that memory map has changed during running | |
2665 | program, but it's not going to work anyway with current | |
2666 | gdb. */ | |
765dc015 | 2667 | struct mem_region *mr |
0d5ed153 | 2668 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2669 | |
2670 | if (mr) | |
2671 | { | |
2672 | if (automatic_hardware_breakpoints) | |
2673 | { | |
765dc015 VP |
2674 | enum bp_loc_type new_type; |
2675 | ||
2676 | if (mr->attrib.mode != MEM_RW) | |
2677 | new_type = bp_loc_hardware_breakpoint; | |
2678 | else | |
2679 | new_type = bp_loc_software_breakpoint; | |
2680 | ||
35df4500 | 2681 | if (new_type != bl->loc_type) |
765dc015 VP |
2682 | { |
2683 | static int said = 0; | |
cc59ec59 | 2684 | |
35df4500 | 2685 | bl->loc_type = new_type; |
765dc015 VP |
2686 | if (!said) |
2687 | { | |
3e43a32a MS |
2688 | fprintf_filtered (gdb_stdout, |
2689 | _("Note: automatically using " | |
2690 | "hardware breakpoints for " | |
2691 | "read-only addresses.\n")); | |
765dc015 VP |
2692 | said = 1; |
2693 | } | |
2694 | } | |
2695 | } | |
35df4500 | 2696 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2697 | && mr->attrib.mode != MEM_RW) |
2698 | { | |
2699 | fprintf_unfiltered (tmp_error_stream, | |
2700 | _("Cannot insert breakpoint %d.\n" | |
2701 | "Cannot set software breakpoint " | |
2702 | "at read-only address %s\n"), | |
2703 | bl->owner->number, | |
2704 | paddress (bl->gdbarch, bl->address)); | |
2705 | return 1; | |
2706 | } | |
765dc015 VP |
2707 | } |
2708 | } | |
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. */ | |
492d29ea | 2716 | TRY |
dd61ec5c | 2717 | { |
0000e5cc PA |
2718 | int val; |
2719 | ||
dd61ec5c | 2720 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2721 | if (val) |
2722 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2723 | } |
492d29ea | 2724 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2725 | { |
0000e5cc PA |
2726 | bp_err = e.error; |
2727 | bp_err_message = e.message; | |
dd61ec5c | 2728 | } |
492d29ea | 2729 | END_CATCH |
879bfdc2 DJ |
2730 | } |
2731 | else | |
2732 | { | |
4a64f543 | 2733 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2734 | Shall we set a breakpoint at the LMA? */ |
2735 | if (!overlay_events_enabled) | |
2736 | { | |
2737 | /* Yes -- overlay event support is not active, | |
2738 | so we must try to set a breakpoint at the LMA. | |
2739 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2740 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2741 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2742 | bl->owner->number); |
879bfdc2 DJ |
2743 | else |
2744 | { | |
35df4500 TJB |
2745 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2746 | bl->section); | |
879bfdc2 | 2747 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2748 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2749 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2750 | |
2751 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2752 | TRY |
0000e5cc PA |
2753 | { |
2754 | int val; | |
2755 | ||
579c6ad9 | 2756 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2757 | = breakpoint_kind (bl, &addr); |
2758 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2759 | val = target_insert_breakpoint (bl->gdbarch, |
2760 | &bl->overlay_target_info); | |
2761 | if (val) | |
2762 | bp_err = GENERIC_ERROR; | |
2763 | } | |
492d29ea | 2764 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2765 | { |
2766 | bp_err = e.error; | |
2767 | bp_err_message = e.message; | |
2768 | } | |
492d29ea | 2769 | END_CATCH |
0000e5cc PA |
2770 | |
2771 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2772 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2773 | "Overlay breakpoint %d " |
2774 | "failed: in ROM?\n", | |
35df4500 | 2775 | bl->owner->number); |
879bfdc2 DJ |
2776 | } |
2777 | } | |
2778 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2779 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2780 | { |
2781 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2782 | TRY |
dd61ec5c | 2783 | { |
0000e5cc PA |
2784 | int val; |
2785 | ||
dd61ec5c | 2786 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2787 | if (val) |
2788 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2789 | } |
492d29ea | 2790 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2791 | { |
0000e5cc PA |
2792 | bp_err = e.error; |
2793 | bp_err_message = e.message; | |
dd61ec5c | 2794 | } |
492d29ea | 2795 | END_CATCH |
879bfdc2 DJ |
2796 | } |
2797 | else | |
2798 | { | |
2799 | /* No. This breakpoint will not be inserted. | |
2800 | No error, but do not mark the bp as 'inserted'. */ | |
2801 | return 0; | |
2802 | } | |
2803 | } | |
2804 | ||
0000e5cc | 2805 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2806 | { |
2807 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2808 | |
2809 | /* In some cases, we might not be able to insert a | |
2810 | breakpoint in a shared library that has already been | |
2811 | removed, but we have not yet processed the shlib unload | |
2812 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2813 | breakpoint insertion themselves can't tell why the |
2814 | breakpoint insertion failed (e.g., the remote target | |
2815 | doesn't define error codes), so we must treat generic | |
2816 | errors as memory errors. */ | |
0000e5cc | 2817 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2818 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2819 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2820 | || shared_objfile_contains_address_p (bl->pspace, |
2821 | bl->address))) | |
879bfdc2 | 2822 | { |
4a64f543 | 2823 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2824 | bl->shlib_disabled = 1; |
8d3788bd | 2825 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2826 | if (!*disabled_breaks) |
2827 | { | |
2828 | fprintf_unfiltered (tmp_error_stream, | |
2829 | "Cannot insert breakpoint %d.\n", | |
2830 | bl->owner->number); | |
2831 | fprintf_unfiltered (tmp_error_stream, | |
2832 | "Temporarily disabling shared " | |
2833 | "library breakpoints:\n"); | |
2834 | } | |
2835 | *disabled_breaks = 1; | |
879bfdc2 | 2836 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2837 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2838 | return 0; |
879bfdc2 DJ |
2839 | } |
2840 | else | |
879bfdc2 | 2841 | { |
35df4500 | 2842 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2843 | { |
0000e5cc PA |
2844 | *hw_breakpoint_error = 1; |
2845 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2846 | fprintf_unfiltered (tmp_error_stream, |
2847 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2848 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2849 | if (bp_err_message != NULL) | |
2850 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2851 | } |
2852 | else | |
2853 | { | |
0000e5cc PA |
2854 | if (bp_err_message == NULL) |
2855 | { | |
1ccbe998 | 2856 | std::string message |
0000e5cc PA |
2857 | = memory_error_message (TARGET_XFER_E_IO, |
2858 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2859 | |
2860 | fprintf_unfiltered (tmp_error_stream, | |
2861 | "Cannot insert breakpoint %d.\n" | |
2862 | "%s\n", | |
1ccbe998 | 2863 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2864 | } |
2865 | else | |
2866 | { | |
2867 | fprintf_unfiltered (tmp_error_stream, | |
2868 | "Cannot insert breakpoint %d: %s\n", | |
2869 | bl->owner->number, | |
2870 | bp_err_message); | |
2871 | } | |
879bfdc2 | 2872 | } |
0000e5cc | 2873 | return 1; |
879bfdc2 DJ |
2874 | |
2875 | } | |
2876 | } | |
2877 | else | |
35df4500 | 2878 | bl->inserted = 1; |
879bfdc2 | 2879 | |
0000e5cc | 2880 | return 0; |
879bfdc2 DJ |
2881 | } |
2882 | ||
35df4500 | 2883 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2884 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2885 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2886 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2887 | { |
0000e5cc PA |
2888 | int val; |
2889 | ||
77b06cd7 TJB |
2890 | gdb_assert (bl->owner->ops != NULL |
2891 | && bl->owner->ops->insert_location != NULL); | |
2892 | ||
2893 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2894 | |
2895 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2896 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2897 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2898 | { |
2899 | struct bp_location *loc, **loc_temp; | |
2900 | ||
2901 | /* But don't try to insert it, if there's already another | |
2902 | hw_access location that would be considered a duplicate | |
2903 | of this one. */ | |
2904 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2905 | if (loc != bl |
85d721b8 | 2906 | && loc->watchpoint_type == hw_access |
35df4500 | 2907 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2908 | { |
35df4500 TJB |
2909 | bl->duplicate = 1; |
2910 | bl->inserted = 1; | |
2911 | bl->target_info = loc->target_info; | |
2912 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2913 | val = 0; |
2914 | break; | |
2915 | } | |
2916 | ||
2917 | if (val == 1) | |
2918 | { | |
77b06cd7 TJB |
2919 | bl->watchpoint_type = hw_access; |
2920 | val = bl->owner->ops->insert_location (bl); | |
2921 | ||
2922 | if (val) | |
2923 | /* Back to the original value. */ | |
2924 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2925 | } |
2926 | } | |
2927 | ||
35df4500 | 2928 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2929 | } |
2930 | ||
35df4500 | 2931 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2932 | { |
0000e5cc PA |
2933 | int val; |
2934 | ||
77b06cd7 TJB |
2935 | gdb_assert (bl->owner->ops != NULL |
2936 | && bl->owner->ops->insert_location != NULL); | |
2937 | ||
2938 | val = bl->owner->ops->insert_location (bl); | |
2939 | if (val) | |
2940 | { | |
2941 | bl->owner->enable_state = bp_disabled; | |
2942 | ||
2943 | if (val == 1) | |
2944 | warning (_("\ | |
2945 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2946 | of catchpoint."), bl->owner->number); | |
2947 | else | |
2948 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2949 | } | |
2950 | ||
2951 | bl->inserted = (val == 0); | |
1640b821 DJ |
2952 | |
2953 | /* We've already printed an error message if there was a problem | |
2954 | inserting this catchpoint, and we've disabled the catchpoint, | |
2955 | so just return success. */ | |
2956 | return 0; | |
879bfdc2 DJ |
2957 | } |
2958 | ||
2959 | return 0; | |
2960 | } | |
2961 | ||
6c95b8df PA |
2962 | /* This function is called when program space PSPACE is about to be |
2963 | deleted. It takes care of updating breakpoints to not reference | |
2964 | PSPACE anymore. */ | |
2965 | ||
2966 | void | |
2967 | breakpoint_program_space_exit (struct program_space *pspace) | |
2968 | { | |
2969 | struct breakpoint *b, *b_temp; | |
876fa593 | 2970 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2971 | |
2972 | /* Remove any breakpoint that was set through this program space. */ | |
2973 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2974 | { | |
2975 | if (b->pspace == pspace) | |
2976 | delete_breakpoint (b); | |
2977 | } | |
2978 | ||
2979 | /* Breakpoints set through other program spaces could have locations | |
2980 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2981 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2982 | { |
2983 | struct bp_location *tmp; | |
2984 | ||
2985 | if (loc->pspace == pspace) | |
2986 | { | |
2bdf28a0 | 2987 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2988 | if (loc->owner->loc == loc) |
2989 | loc->owner->loc = loc->next; | |
2990 | else | |
2991 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2992 | if (tmp->next == loc) | |
2993 | { | |
2994 | tmp->next = loc->next; | |
2995 | break; | |
2996 | } | |
2997 | } | |
2998 | } | |
2999 | ||
3000 | /* Now update the global location list to permanently delete the | |
3001 | removed locations above. */ | |
44702360 | 3002 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3003 | } |
3004 | ||
74960c60 VP |
3005 | /* Make sure all breakpoints are inserted in inferior. |
3006 | Throws exception on any error. | |
3007 | A breakpoint that is already inserted won't be inserted | |
3008 | again, so calling this function twice is safe. */ | |
3009 | void | |
3010 | insert_breakpoints (void) | |
3011 | { | |
3012 | struct breakpoint *bpt; | |
3013 | ||
3014 | ALL_BREAKPOINTS (bpt) | |
3015 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3016 | { |
3017 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3018 | ||
3019 | update_watchpoint (w, 0 /* don't reparse. */); | |
3020 | } | |
74960c60 | 3021 | |
04086b45 PA |
3022 | /* Updating watchpoints creates new locations, so update the global |
3023 | location list. Explicitly tell ugll to insert locations and | |
3024 | ignore breakpoints_always_inserted_mode. */ | |
3025 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3026 | } |
3027 | ||
20388dd6 YQ |
3028 | /* Invoke CALLBACK for each of bp_location. */ |
3029 | ||
3030 | void | |
3031 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3032 | { | |
3033 | struct bp_location *loc, **loc_tmp; | |
3034 | ||
3035 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3036 | { | |
3037 | callback (loc, NULL); | |
3038 | } | |
3039 | } | |
3040 | ||
b775012e LM |
3041 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3042 | target. It is the case with deleting and disabling of breakpoints when using | |
3043 | always-inserted mode. */ | |
3044 | ||
3045 | static void | |
3046 | update_inserted_breakpoint_locations (void) | |
3047 | { | |
3048 | struct bp_location *bl, **blp_tmp; | |
3049 | int error_flag = 0; | |
3050 | int val = 0; | |
3051 | int disabled_breaks = 0; | |
3052 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3053 | int hw_bp_details_reported = 0; |
b775012e | 3054 | |
d7e74731 | 3055 | string_file tmp_error_stream; |
b775012e LM |
3056 | |
3057 | /* Explicitly mark the warning -- this will only be printed if | |
3058 | there was an error. */ | |
d7e74731 | 3059 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 3060 | |
5ed8105e | 3061 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
3062 | |
3063 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3064 | { | |
3065 | /* We only want to update software breakpoints and hardware | |
3066 | breakpoints. */ | |
3067 | if (!is_breakpoint (bl->owner)) | |
3068 | continue; | |
3069 | ||
3070 | /* We only want to update locations that are already inserted | |
3071 | and need updating. This is to avoid unwanted insertion during | |
3072 | deletion of breakpoints. */ | |
3073 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3074 | continue; | |
3075 | ||
3076 | switch_to_program_space_and_thread (bl->pspace); | |
3077 | ||
3078 | /* For targets that support global breakpoints, there's no need | |
3079 | to select an inferior to insert breakpoint to. In fact, even | |
3080 | if we aren't attached to any process yet, we should still | |
3081 | insert breakpoints. */ | |
f5656ead | 3082 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3083 | && ptid_equal (inferior_ptid, null_ptid)) |
3084 | continue; | |
3085 | ||
d7e74731 | 3086 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3087 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3088 | if (val) |
3089 | error_flag = val; | |
3090 | } | |
3091 | ||
3092 | if (error_flag) | |
3093 | { | |
223ffa71 | 3094 | target_terminal::ours_for_output (); |
b775012e LM |
3095 | error_stream (tmp_error_stream); |
3096 | } | |
b775012e LM |
3097 | } |
3098 | ||
c30eee59 | 3099 | /* Used when starting or continuing the program. */ |
c906108c | 3100 | |
74960c60 VP |
3101 | static void |
3102 | insert_breakpoint_locations (void) | |
c906108c | 3103 | { |
a5606eee | 3104 | struct breakpoint *bpt; |
35df4500 | 3105 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3106 | int error_flag = 0; |
c906108c | 3107 | int val = 0; |
3fbb6ffa | 3108 | int disabled_breaks = 0; |
81d0cc19 | 3109 | int hw_breakpoint_error = 0; |
dd61ec5c | 3110 | int hw_bp_error_explained_already = 0; |
c906108c | 3111 | |
d7e74731 PA |
3112 | string_file tmp_error_stream; |
3113 | ||
81d0cc19 GS |
3114 | /* Explicitly mark the warning -- this will only be printed if |
3115 | there was an error. */ | |
d7e74731 | 3116 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3117 | |
5ed8105e | 3118 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3119 | |
35df4500 | 3120 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3121 | { |
b775012e | 3122 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3123 | continue; |
3124 | ||
4a64f543 MS |
3125 | /* There is no point inserting thread-specific breakpoints if |
3126 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3127 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3128 | if (bl->owner->thread != -1 |
5d5658a1 | 3129 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3130 | continue; |
3131 | ||
35df4500 | 3132 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3133 | |
3134 | /* For targets that support global breakpoints, there's no need | |
3135 | to select an inferior to insert breakpoint to. In fact, even | |
3136 | if we aren't attached to any process yet, we should still | |
3137 | insert breakpoints. */ | |
f5656ead | 3138 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3139 | && ptid_equal (inferior_ptid, null_ptid)) |
3140 | continue; | |
3141 | ||
d7e74731 | 3142 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3143 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3144 | if (val) |
eacd795a | 3145 | error_flag = val; |
879bfdc2 | 3146 | } |
c906108c | 3147 | |
4a64f543 MS |
3148 | /* If we failed to insert all locations of a watchpoint, remove |
3149 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3150 | ALL_BREAKPOINTS (bpt) |
3151 | { | |
3152 | int some_failed = 0; | |
3153 | struct bp_location *loc; | |
3154 | ||
3155 | if (!is_hardware_watchpoint (bpt)) | |
3156 | continue; | |
3157 | ||
d6b74ac4 | 3158 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3159 | continue; |
74960c60 VP |
3160 | |
3161 | if (bpt->disposition == disp_del_at_next_stop) | |
3162 | continue; | |
a5606eee VP |
3163 | |
3164 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3165 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3166 | { |
3167 | some_failed = 1; | |
3168 | break; | |
3169 | } | |
3170 | if (some_failed) | |
3171 | { | |
3172 | for (loc = bpt->loc; loc; loc = loc->next) | |
3173 | if (loc->inserted) | |
834c0d03 | 3174 | remove_breakpoint (loc); |
a5606eee VP |
3175 | |
3176 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3177 | tmp_error_stream.printf ("Could not insert " |
3178 | "hardware watchpoint %d.\n", | |
3179 | bpt->number); | |
eacd795a | 3180 | error_flag = -1; |
a5606eee VP |
3181 | } |
3182 | } | |
3183 | ||
eacd795a | 3184 | if (error_flag) |
81d0cc19 GS |
3185 | { |
3186 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3187 | message about possibly exhausted resources. */ | |
dd61ec5c | 3188 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3189 | { |
d7e74731 | 3190 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3191 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3192 | } |
223ffa71 | 3193 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3194 | error_stream (tmp_error_stream); |
3195 | } | |
c906108c SS |
3196 | } |
3197 | ||
c30eee59 TJB |
3198 | /* Used when the program stops. |
3199 | Returns zero if successful, or non-zero if there was a problem | |
3200 | removing a breakpoint location. */ | |
3201 | ||
c906108c | 3202 | int |
fba45db2 | 3203 | remove_breakpoints (void) |
c906108c | 3204 | { |
35df4500 | 3205 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3206 | int val = 0; |
c906108c | 3207 | |
35df4500 | 3208 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3209 | { |
1e4d1764 | 3210 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3211 | val |= remove_breakpoint (bl); |
c5aa993b | 3212 | } |
3a1bae8e | 3213 | return val; |
c906108c SS |
3214 | } |
3215 | ||
49fa26b0 PA |
3216 | /* When a thread exits, remove breakpoints that are related to |
3217 | that thread. */ | |
3218 | ||
3219 | static void | |
3220 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3221 | { | |
3222 | struct breakpoint *b, *b_tmp; | |
3223 | ||
3224 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3225 | { | |
5d5658a1 | 3226 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3227 | { |
3228 | b->disposition = disp_del_at_next_stop; | |
3229 | ||
3230 | printf_filtered (_("\ | |
43792cf0 PA |
3231 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3232 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3233 | |
3234 | /* Hide it from the user. */ | |
3235 | b->number = 0; | |
3236 | } | |
3237 | } | |
3238 | } | |
3239 | ||
6c95b8df PA |
3240 | /* Remove breakpoints of process PID. */ |
3241 | ||
3242 | int | |
3243 | remove_breakpoints_pid (int pid) | |
3244 | { | |
35df4500 | 3245 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3246 | int val; |
3247 | struct inferior *inf = find_inferior_pid (pid); | |
3248 | ||
35df4500 | 3249 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3250 | { |
35df4500 | 3251 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3252 | continue; |
3253 | ||
fc126975 | 3254 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3255 | { |
834c0d03 | 3256 | val = remove_breakpoint (bl); |
6c95b8df PA |
3257 | if (val != 0) |
3258 | return val; | |
3259 | } | |
3260 | } | |
3261 | return 0; | |
3262 | } | |
3263 | ||
c906108c | 3264 | int |
fba45db2 | 3265 | reattach_breakpoints (int pid) |
c906108c | 3266 | { |
35df4500 | 3267 | struct bp_location *bl, **blp_tmp; |
c906108c | 3268 | int val; |
dd61ec5c | 3269 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3270 | struct inferior *inf; |
3271 | struct thread_info *tp; | |
3272 | ||
3273 | tp = any_live_thread_of_process (pid); | |
3274 | if (tp == NULL) | |
3275 | return 1; | |
3276 | ||
3277 | inf = find_inferior_pid (pid); | |
6c95b8df | 3278 | |
2989a365 | 3279 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3280 | inferior_ptid = tp->ptid; |
a4954f26 | 3281 | |
d7e74731 | 3282 | string_file tmp_error_stream; |
c906108c | 3283 | |
35df4500 | 3284 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3285 | { |
35df4500 | 3286 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3287 | continue; |
3288 | ||
35df4500 | 3289 | if (bl->inserted) |
c5aa993b | 3290 | { |
35df4500 | 3291 | bl->inserted = 0; |
d7e74731 | 3292 | val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b | 3293 | if (val != 0) |
2989a365 | 3294 | return val; |
c5aa993b JM |
3295 | } |
3296 | } | |
c906108c SS |
3297 | return 0; |
3298 | } | |
3299 | ||
e58b0e63 PA |
3300 | static int internal_breakpoint_number = -1; |
3301 | ||
84f4c1fe PM |
3302 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3303 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3304 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3305 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3306 | breakpoint_count and that value incremented. Internal breakpoints |
3307 | do not set the internal var bpnum. */ | |
3308 | static void | |
3309 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3310 | { | |
3311 | if (internal) | |
3312 | b->number = internal_breakpoint_number--; | |
3313 | else | |
3314 | { | |
3315 | set_breakpoint_count (breakpoint_count + 1); | |
3316 | b->number = breakpoint_count; | |
3317 | } | |
3318 | } | |
3319 | ||
e62c965a | 3320 | static struct breakpoint * |
a6d9a66e | 3321 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3322 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3323 | const struct breakpoint_ops *ops) |
e62c965a | 3324 | { |
51abb421 | 3325 | symtab_and_line sal; |
e62c965a PP |
3326 | sal.pc = address; |
3327 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3328 | sal.pspace = current_program_space; |
e62c965a | 3329 | |
51abb421 | 3330 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3331 | b->number = internal_breakpoint_number--; |
3332 | b->disposition = disp_donttouch; | |
3333 | ||
3334 | return b; | |
3335 | } | |
3336 | ||
17450429 PP |
3337 | static const char *const longjmp_names[] = |
3338 | { | |
3339 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3340 | }; | |
3341 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3342 | ||
3343 | /* Per-objfile data private to breakpoint.c. */ | |
3344 | struct breakpoint_objfile_data | |
3345 | { | |
3346 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3347 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3348 | |
3349 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3350 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3351 | |
28106bc2 SDJ |
3352 | /* True if we have looked for longjmp probes. */ |
3353 | int longjmp_searched; | |
3354 | ||
3355 | /* SystemTap probe points for longjmp (if any). */ | |
3356 | VEC (probe_p) *longjmp_probes; | |
3357 | ||
17450429 | 3358 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3359 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3360 | |
3361 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3362 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3363 | |
3364 | /* True if we have looked for exception probes. */ | |
3365 | int exception_searched; | |
3366 | ||
3367 | /* SystemTap probe points for unwinding (if any). */ | |
3368 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3369 | }; |
3370 | ||
3371 | static const struct objfile_data *breakpoint_objfile_key; | |
3372 | ||
3373 | /* Minimal symbol not found sentinel. */ | |
3374 | static struct minimal_symbol msym_not_found; | |
3375 | ||
3376 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3377 | ||
3378 | static int | |
3379 | msym_not_found_p (const struct minimal_symbol *msym) | |
3380 | { | |
3381 | return msym == &msym_not_found; | |
3382 | } | |
3383 | ||
3384 | /* Return per-objfile data needed by breakpoint.c. | |
3385 | Allocate the data if necessary. */ | |
3386 | ||
3387 | static struct breakpoint_objfile_data * | |
3388 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3389 | { | |
3390 | struct breakpoint_objfile_data *bp_objfile_data; | |
3391 | ||
9a3c8263 SM |
3392 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3393 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3394 | if (bp_objfile_data == NULL) |
3395 | { | |
8d749320 SM |
3396 | bp_objfile_data = |
3397 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3398 | |
3399 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3400 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3401 | } | |
3402 | return bp_objfile_data; | |
3403 | } | |
3404 | ||
28106bc2 SDJ |
3405 | static void |
3406 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3407 | { | |
9a3c8263 SM |
3408 | struct breakpoint_objfile_data *bp_objfile_data |
3409 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3410 | |
3411 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3412 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3413 | } | |
3414 | ||
e62c965a | 3415 | static void |
af02033e | 3416 | create_overlay_event_breakpoint (void) |
e62c965a | 3417 | { |
69de3c6a | 3418 | struct objfile *objfile; |
af02033e | 3419 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3420 | |
69de3c6a PP |
3421 | ALL_OBJFILES (objfile) |
3422 | { | |
3423 | struct breakpoint *b; | |
17450429 PP |
3424 | struct breakpoint_objfile_data *bp_objfile_data; |
3425 | CORE_ADDR addr; | |
67994074 | 3426 | struct explicit_location explicit_loc; |
69de3c6a | 3427 | |
17450429 PP |
3428 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3429 | ||
3b7344d5 | 3430 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3431 | continue; |
3432 | ||
3b7344d5 | 3433 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3434 | { |
3b7344d5 | 3435 | struct bound_minimal_symbol m; |
17450429 PP |
3436 | |
3437 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3438 | if (m.minsym == NULL) |
17450429 PP |
3439 | { |
3440 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3441 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3442 | continue; |
3443 | } | |
3444 | bp_objfile_data->overlay_msym = m; | |
3445 | } | |
e62c965a | 3446 | |
77e371c0 | 3447 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3448 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3449 | bp_overlay_event, |
3450 | &internal_breakpoint_ops); | |
67994074 KS |
3451 | initialize_explicit_location (&explicit_loc); |
3452 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3453 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3454 | |
69de3c6a PP |
3455 | if (overlay_debugging == ovly_auto) |
3456 | { | |
3457 | b->enable_state = bp_enabled; | |
3458 | overlay_events_enabled = 1; | |
3459 | } | |
3460 | else | |
3461 | { | |
3462 | b->enable_state = bp_disabled; | |
3463 | overlay_events_enabled = 0; | |
3464 | } | |
e62c965a | 3465 | } |
e62c965a PP |
3466 | } |
3467 | ||
0fd8e87f | 3468 | static void |
af02033e | 3469 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3470 | { |
6c95b8df | 3471 | struct program_space *pspace; |
6c95b8df | 3472 | |
5ed8105e | 3473 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3474 | |
6c95b8df | 3475 | ALL_PSPACES (pspace) |
af02033e PP |
3476 | { |
3477 | struct objfile *objfile; | |
3478 | ||
3479 | set_current_program_space (pspace); | |
3480 | ||
3481 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3482 | { |
af02033e PP |
3483 | int i; |
3484 | struct gdbarch *gdbarch; | |
17450429 | 3485 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3486 | |
af02033e | 3487 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3488 | |
17450429 PP |
3489 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3490 | ||
28106bc2 SDJ |
3491 | if (!bp_objfile_data->longjmp_searched) |
3492 | { | |
25f9533e SDJ |
3493 | VEC (probe_p) *ret; |
3494 | ||
3495 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3496 | if (ret != NULL) | |
3497 | { | |
3498 | /* We are only interested in checking one element. */ | |
3499 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3500 | ||
3501 | if (!can_evaluate_probe_arguments (p)) | |
3502 | { | |
3503 | /* We cannot use the probe interface here, because it does | |
3504 | not know how to evaluate arguments. */ | |
3505 | VEC_free (probe_p, ret); | |
3506 | ret = NULL; | |
3507 | } | |
3508 | } | |
3509 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3510 | bp_objfile_data->longjmp_searched = 1; |
3511 | } | |
3512 | ||
3513 | if (bp_objfile_data->longjmp_probes != NULL) | |
3514 | { | |
3515 | int i; | |
3516 | struct probe *probe; | |
3517 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3518 | ||
3519 | for (i = 0; | |
3520 | VEC_iterate (probe_p, | |
3521 | bp_objfile_data->longjmp_probes, | |
3522 | i, probe); | |
3523 | ++i) | |
3524 | { | |
3525 | struct breakpoint *b; | |
3526 | ||
729662a5 TT |
3527 | b = create_internal_breakpoint (gdbarch, |
3528 | get_probe_address (probe, | |
3529 | objfile), | |
28106bc2 SDJ |
3530 | bp_longjmp_master, |
3531 | &internal_breakpoint_ops); | |
d28cd78a | 3532 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
28106bc2 SDJ |
3533 | b->enable_state = bp_disabled; |
3534 | } | |
3535 | ||
3536 | continue; | |
3537 | } | |
3538 | ||
0569175e TSD |
3539 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3540 | continue; | |
3541 | ||
17450429 | 3542 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3543 | { |
3544 | struct breakpoint *b; | |
af02033e | 3545 | const char *func_name; |
17450429 | 3546 | CORE_ADDR addr; |
67994074 | 3547 | struct explicit_location explicit_loc; |
6c95b8df | 3548 | |
3b7344d5 | 3549 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3550 | continue; |
0fd8e87f | 3551 | |
17450429 | 3552 | func_name = longjmp_names[i]; |
3b7344d5 | 3553 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3554 | { |
3b7344d5 | 3555 | struct bound_minimal_symbol m; |
17450429 PP |
3556 | |
3557 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3558 | if (m.minsym == NULL) |
17450429 PP |
3559 | { |
3560 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3561 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3562 | continue; |
3563 | } | |
3564 | bp_objfile_data->longjmp_msym[i] = m; | |
3565 | } | |
3566 | ||
77e371c0 | 3567 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3568 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3569 | &internal_breakpoint_ops); | |
67994074 KS |
3570 | initialize_explicit_location (&explicit_loc); |
3571 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3572 | b->location = new_explicit_location (&explicit_loc); |
af02033e PP |
3573 | b->enable_state = bp_disabled; |
3574 | } | |
0fd8e87f | 3575 | } |
af02033e | 3576 | } |
0fd8e87f UW |
3577 | } |
3578 | ||
af02033e | 3579 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3580 | static void |
af02033e | 3581 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3582 | { |
3583 | struct program_space *pspace; | |
af02033e | 3584 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3585 | |
5ed8105e | 3586 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3587 | |
3588 | ALL_PSPACES (pspace) | |
17450429 PP |
3589 | { |
3590 | struct objfile *objfile; | |
3591 | CORE_ADDR addr; | |
3592 | ||
3593 | set_current_program_space (pspace); | |
3594 | ||
aa7d318d TT |
3595 | ALL_OBJFILES (objfile) |
3596 | { | |
3597 | struct breakpoint *b; | |
17450429 | 3598 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3599 | struct explicit_location explicit_loc; |
aa7d318d | 3600 | |
17450429 | 3601 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3602 | |
3b7344d5 | 3603 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3604 | continue; |
3605 | ||
3b7344d5 | 3606 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3607 | { |
3b7344d5 | 3608 | struct bound_minimal_symbol m; |
17450429 PP |
3609 | |
3610 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3611 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3612 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3613 | { |
3614 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3615 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3616 | continue; |
3617 | } | |
3618 | bp_objfile_data->terminate_msym = m; | |
3619 | } | |
aa7d318d | 3620 | |
77e371c0 | 3621 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3622 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3623 | bp_std_terminate_master, |
3624 | &internal_breakpoint_ops); | |
67994074 KS |
3625 | initialize_explicit_location (&explicit_loc); |
3626 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3627 | b->location = new_explicit_location (&explicit_loc); |
aa7d318d TT |
3628 | b->enable_state = bp_disabled; |
3629 | } | |
17450429 | 3630 | } |
aa7d318d TT |
3631 | } |
3632 | ||
186c406b TT |
3633 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3634 | ||
70221824 | 3635 | static void |
186c406b TT |
3636 | create_exception_master_breakpoint (void) |
3637 | { | |
3638 | struct objfile *objfile; | |
17450429 | 3639 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3640 | |
3641 | ALL_OBJFILES (objfile) | |
3642 | { | |
17450429 PP |
3643 | struct breakpoint *b; |
3644 | struct gdbarch *gdbarch; | |
3645 | struct breakpoint_objfile_data *bp_objfile_data; | |
3646 | CORE_ADDR addr; | |
67994074 | 3647 | struct explicit_location explicit_loc; |
17450429 PP |
3648 | |
3649 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3650 | ||
28106bc2 SDJ |
3651 | /* We prefer the SystemTap probe point if it exists. */ |
3652 | if (!bp_objfile_data->exception_searched) | |
3653 | { | |
25f9533e SDJ |
3654 | VEC (probe_p) *ret; |
3655 | ||
3656 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3657 | ||
3658 | if (ret != NULL) | |
3659 | { | |
3660 | /* We are only interested in checking one element. */ | |
3661 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3662 | ||
3663 | if (!can_evaluate_probe_arguments (p)) | |
3664 | { | |
3665 | /* We cannot use the probe interface here, because it does | |
3666 | not know how to evaluate arguments. */ | |
3667 | VEC_free (probe_p, ret); | |
3668 | ret = NULL; | |
3669 | } | |
3670 | } | |
3671 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3672 | bp_objfile_data->exception_searched = 1; |
3673 | } | |
3674 | ||
3675 | if (bp_objfile_data->exception_probes != NULL) | |
3676 | { | |
3677 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3678 | int i; | |
3679 | struct probe *probe; | |
3680 | ||
3681 | for (i = 0; | |
3682 | VEC_iterate (probe_p, | |
3683 | bp_objfile_data->exception_probes, | |
3684 | i, probe); | |
3685 | ++i) | |
3686 | { | |
3687 | struct breakpoint *b; | |
3688 | ||
729662a5 TT |
3689 | b = create_internal_breakpoint (gdbarch, |
3690 | get_probe_address (probe, | |
3691 | objfile), | |
28106bc2 SDJ |
3692 | bp_exception_master, |
3693 | &internal_breakpoint_ops); | |
d28cd78a | 3694 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3695 | b->enable_state = bp_disabled; |
3696 | } | |
3697 | ||
3698 | continue; | |
3699 | } | |
3700 | ||
3701 | /* Otherwise, try the hook function. */ | |
3702 | ||
3b7344d5 | 3703 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3704 | continue; |
3705 | ||
3706 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3707 | |
3b7344d5 | 3708 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3709 | { |
3b7344d5 | 3710 | struct bound_minimal_symbol debug_hook; |
186c406b | 3711 | |
17450429 | 3712 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3713 | if (debug_hook.minsym == NULL) |
17450429 | 3714 | { |
3b7344d5 | 3715 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3716 | continue; |
3717 | } | |
3718 | ||
3719 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3720 | } |
17450429 | 3721 | |
77e371c0 | 3722 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3723 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3724 | ¤t_target); | |
06edf0c0 PA |
3725 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3726 | &internal_breakpoint_ops); | |
67994074 KS |
3727 | initialize_explicit_location (&explicit_loc); |
3728 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3729 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3730 | b->enable_state = bp_disabled; |
186c406b | 3731 | } |
186c406b TT |
3732 | } |
3733 | ||
9ef9e6a6 KS |
3734 | /* Does B have a location spec? */ |
3735 | ||
3736 | static int | |
3737 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3738 | { | |
d28cd78a | 3739 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3740 | } |
3741 | ||
c906108c | 3742 | void |
fba45db2 | 3743 | update_breakpoints_after_exec (void) |
c906108c | 3744 | { |
35df4500 | 3745 | struct breakpoint *b, *b_tmp; |
876fa593 | 3746 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3747 | |
25b22b0a PA |
3748 | /* We're about to delete breakpoints from GDB's lists. If the |
3749 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3750 | writing the breakpoints' "shadow contents" back into memory. The | |
3751 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3752 | do that. Instead, the target is responsible from marking | |
3753 | breakpoints out as soon as it detects an exec. We don't do that | |
3754 | here instead, because there may be other attempts to delete | |
3755 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3756 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3757 | if (bploc->pspace == current_program_space) |
3758 | gdb_assert (!bploc->inserted); | |
c906108c | 3759 | |
35df4500 | 3760 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3761 | { |
6c95b8df PA |
3762 | if (b->pspace != current_program_space) |
3763 | continue; | |
3764 | ||
4a64f543 | 3765 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3766 | if (b->type == bp_shlib_event) |
3767 | { | |
3768 | delete_breakpoint (b); | |
3769 | continue; | |
3770 | } | |
c906108c | 3771 | |
4a64f543 | 3772 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3773 | if (b->type == bp_jit_event) |
3774 | { | |
3775 | delete_breakpoint (b); | |
3776 | continue; | |
3777 | } | |
3778 | ||
1900040c | 3779 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3780 | as must overlay event and longjmp master breakpoints. */ |
3781 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3782 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3783 | || b->type == bp_exception_master) | |
c4093a6a JM |
3784 | { |
3785 | delete_breakpoint (b); | |
3786 | continue; | |
3787 | } | |
3788 | ||
4a64f543 | 3789 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3790 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3791 | { |
3792 | delete_breakpoint (b); | |
3793 | continue; | |
3794 | } | |
3795 | ||
7c16b83e PA |
3796 | /* Just like single-step breakpoints. */ |
3797 | if (b->type == bp_single_step) | |
3798 | { | |
3799 | delete_breakpoint (b); | |
3800 | continue; | |
3801 | } | |
3802 | ||
611c83ae PA |
3803 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3804 | after an exec. */ | |
186c406b | 3805 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3806 | || b->type == bp_longjmp_call_dummy |
186c406b | 3807 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3808 | { |
3809 | delete_breakpoint (b); | |
3810 | continue; | |
3811 | } | |
3812 | ||
ce78b96d JB |
3813 | if (b->type == bp_catchpoint) |
3814 | { | |
3815 | /* For now, none of the bp_catchpoint breakpoints need to | |
3816 | do anything at this point. In the future, if some of | |
3817 | the catchpoints need to something, we will need to add | |
3818 | a new method, and call this method from here. */ | |
3819 | continue; | |
3820 | } | |
3821 | ||
c5aa993b JM |
3822 | /* bp_finish is a special case. The only way we ought to be able |
3823 | to see one of these when an exec() has happened, is if the user | |
3824 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3825 | carries them to the call-site of the current callee, by setting | |
3826 | a temporary bp there and resuming. But in this case, the finish | |
3827 | will carry them entirely through the vfork & exec. | |
3828 | ||
3829 | We don't want to allow a bp_finish to remain inserted now. But | |
3830 | we can't safely delete it, 'cause finish_command has a handle to | |
3831 | the bp on a bpstat, and will later want to delete it. There's a | |
3832 | chance (and I've seen it happen) that if we delete the bp_finish | |
3833 | here, that its storage will get reused by the time finish_command | |
3834 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3835 | We really must allow finish_command to delete a bp_finish. | |
3836 | ||
e5dd4106 | 3837 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3838 | it's safe to delete something others may have handles to?" |
3839 | problem, what we'll do here is just uninsert the bp_finish, and | |
3840 | let finish_command delete it. | |
3841 | ||
3842 | (We know the bp_finish is "doomed" in the sense that it's | |
3843 | momentary, and will be deleted as soon as finish_command sees | |
3844 | the inferior stopped. So it doesn't matter that the bp's | |
3845 | address is probably bogus in the new a.out, unlike e.g., the | |
3846 | solib breakpoints.) */ | |
c5aa993b | 3847 | |
c5aa993b JM |
3848 | if (b->type == bp_finish) |
3849 | { | |
3850 | continue; | |
3851 | } | |
3852 | ||
3853 | /* Without a symbolic address, we have little hope of the | |
3854 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3855 | a.out. */ |
9ef9e6a6 | 3856 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3857 | { |
3858 | delete_breakpoint (b); | |
3859 | continue; | |
3860 | } | |
c5aa993b | 3861 | } |
c906108c SS |
3862 | } |
3863 | ||
3864 | int | |
d80ee84f | 3865 | detach_breakpoints (ptid_t ptid) |
c906108c | 3866 | { |
35df4500 | 3867 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3868 | int val = 0; |
2989a365 | 3869 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3870 | struct inferior *inf = current_inferior (); |
c5aa993b | 3871 | |
dfd4cc63 | 3872 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3873 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3874 | |
6c95b8df | 3875 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3876 | inferior_ptid = ptid; |
35df4500 | 3877 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3878 | { |
35df4500 | 3879 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3880 | continue; |
3881 | ||
bd9673a4 PW |
3882 | /* This function must physically remove breakpoints locations |
3883 | from the specified ptid, without modifying the breakpoint | |
3884 | package's state. Locations of type bp_loc_other are only | |
3885 | maintained at GDB side. So, there is no need to remove | |
3886 | these bp_loc_other locations. Moreover, removing these | |
3887 | would modify the breakpoint package's state. */ | |
3888 | if (bl->loc_type == bp_loc_other) | |
3889 | continue; | |
3890 | ||
35df4500 | 3891 | if (bl->inserted) |
b2b6a7da | 3892 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3893 | } |
d03285ec | 3894 | |
3a1bae8e | 3895 | return val; |
c906108c SS |
3896 | } |
3897 | ||
35df4500 | 3898 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3899 | Note that this is used to detach breakpoints from a child fork. |
3900 | When we get here, the child isn't in the inferior list, and neither | |
3901 | do we have objects to represent its address space --- we should | |
35df4500 | 3902 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3903 | |
c906108c | 3904 | static int |
b2b6a7da | 3905 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3906 | { |
3907 | int val; | |
c5aa993b | 3908 | |
35df4500 TJB |
3909 | /* BL is never in moribund_locations by our callers. */ |
3910 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3911 | |
74960c60 VP |
3912 | /* The type of none suggests that owner is actually deleted. |
3913 | This should not ever happen. */ | |
35df4500 | 3914 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3915 | |
35df4500 TJB |
3916 | if (bl->loc_type == bp_loc_software_breakpoint |
3917 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3918 | { |
c02f5703 MS |
3919 | /* "Normal" instruction breakpoint: either the standard |
3920 | trap-instruction bp (bp_breakpoint), or a | |
3921 | bp_hardware_breakpoint. */ | |
3922 | ||
3923 | /* First check to see if we have to handle an overlay. */ | |
3924 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3925 | || bl->section == NULL |
3926 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3927 | { |
3928 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3929 | |
3930 | /* If we're trying to uninsert a memory breakpoint that we | |
3931 | know is set in a dynamic object that is marked | |
3932 | shlib_disabled, then either the dynamic object was | |
3933 | removed with "remove-symbol-file" or with | |
3934 | "nosharedlibrary". In the former case, we don't know | |
3935 | whether another dynamic object might have loaded over the | |
3936 | breakpoint's address -- the user might well let us know | |
3937 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3938 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3939 | list of dynamically loaded objects). If we have the |
3940 | breakpoint's shadow memory, that is, this is a software | |
3941 | breakpoint managed by GDB, check whether the breakpoint | |
3942 | is still inserted in memory, to avoid overwriting wrong | |
3943 | code with stale saved shadow contents. Note that HW | |
3944 | breakpoints don't have shadow memory, as they're | |
3945 | implemented using a mechanism that is not dependent on | |
3946 | being able to modify the target's memory, and as such | |
3947 | they should always be removed. */ | |
3948 | if (bl->shlib_disabled | |
3949 | && bl->target_info.shadow_len != 0 | |
3950 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3951 | val = 0; | |
3952 | else | |
73971819 | 3953 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3954 | } |
c906108c SS |
3955 | else |
3956 | { | |
4a64f543 | 3957 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3958 | Did we set a breakpoint at the LMA? */ |
3959 | if (!overlay_events_enabled) | |
3960 | { | |
3961 | /* Yes -- overlay event support is not active, so we | |
3962 | should have set a breakpoint at the LMA. Remove it. | |
3963 | */ | |
c02f5703 MS |
3964 | /* Ignore any failures: if the LMA is in ROM, we will |
3965 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3966 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3967 | target_remove_hw_breakpoint (bl->gdbarch, | |
3968 | &bl->overlay_target_info); | |
c02f5703 | 3969 | else |
35df4500 | 3970 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3971 | &bl->overlay_target_info, |
3972 | reason); | |
c02f5703 MS |
3973 | } |
3974 | /* Did we set a breakpoint at the VMA? | |
3975 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3976 | if (bl->inserted) |
c906108c | 3977 | { |
c02f5703 MS |
3978 | /* Yes -- remove it. Previously we did not bother to |
3979 | remove the breakpoint if the section had been | |
3980 | unmapped, but let's not rely on that being safe. We | |
3981 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3982 | |
3983 | /* However, we should remove *software* breakpoints only | |
3984 | if the section is still mapped, or else we overwrite | |
3985 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3986 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3987 | || section_is_mapped (bl->section)) | |
73971819 | 3988 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3989 | else |
3990 | val = 0; | |
c906108c | 3991 | } |
c02f5703 MS |
3992 | else |
3993 | { | |
3994 | /* No -- not inserted, so no need to remove. No error. */ | |
3995 | val = 0; | |
3996 | } | |
c906108c | 3997 | } |
879d1e6b | 3998 | |
08351840 PA |
3999 | /* In some cases, we might not be able to remove a breakpoint in |
4000 | a shared library that has already been removed, but we have | |
4001 | not yet processed the shlib unload event. Similarly for an | |
4002 | unloaded add-symbol-file object - the user might not yet have | |
4003 | had the chance to remove-symbol-file it. shlib_disabled will | |
4004 | be set if the library/object has already been removed, but | |
4005 | the breakpoint hasn't been uninserted yet, e.g., after | |
4006 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4007 | always-inserted mode. */ | |
076855f9 | 4008 | if (val |
08351840 PA |
4009 | && (bl->loc_type == bp_loc_software_breakpoint |
4010 | && (bl->shlib_disabled | |
4011 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4012 | || shared_objfile_contains_address_p (bl->pspace, |
4013 | bl->address)))) | |
879d1e6b UW |
4014 | val = 0; |
4015 | ||
c906108c SS |
4016 | if (val) |
4017 | return val; | |
b2b6a7da | 4018 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4019 | } |
35df4500 | 4020 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4021 | { |
77b06cd7 TJB |
4022 | gdb_assert (bl->owner->ops != NULL |
4023 | && bl->owner->ops->remove_location != NULL); | |
4024 | ||
b2b6a7da | 4025 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4026 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4027 | |
c906108c | 4028 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4029 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4030 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4031 | bl->owner->number); |
c906108c | 4032 | } |
35df4500 TJB |
4033 | else if (bl->owner->type == bp_catchpoint |
4034 | && breakpoint_enabled (bl->owner) | |
4035 | && !bl->duplicate) | |
ce78b96d | 4036 | { |
77b06cd7 TJB |
4037 | gdb_assert (bl->owner->ops != NULL |
4038 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4039 | |
73971819 | 4040 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4041 | if (val) |
4042 | return val; | |
77b06cd7 | 4043 | |
b2b6a7da | 4044 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4045 | } |
c906108c SS |
4046 | |
4047 | return 0; | |
4048 | } | |
4049 | ||
6c95b8df | 4050 | static int |
834c0d03 | 4051 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 4052 | { |
35df4500 TJB |
4053 | /* BL is never in moribund_locations by our callers. */ |
4054 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4055 | |
6c95b8df PA |
4056 | /* The type of none suggests that owner is actually deleted. |
4057 | This should not ever happen. */ | |
35df4500 | 4058 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 4059 | |
5ed8105e | 4060 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 4061 | |
35df4500 | 4062 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4063 | |
5ed8105e | 4064 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4065 | } |
4066 | ||
c906108c SS |
4067 | /* Clear the "inserted" flag in all breakpoints. */ |
4068 | ||
25b22b0a | 4069 | void |
fba45db2 | 4070 | mark_breakpoints_out (void) |
c906108c | 4071 | { |
35df4500 | 4072 | struct bp_location *bl, **blp_tmp; |
c906108c | 4073 | |
35df4500 | 4074 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4075 | if (bl->pspace == current_program_space) |
35df4500 | 4076 | bl->inserted = 0; |
c906108c SS |
4077 | } |
4078 | ||
53a5351d JM |
4079 | /* Clear the "inserted" flag in all breakpoints and delete any |
4080 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4081 | |
4082 | Plus other such housekeeping that has to be done for breakpoints | |
4083 | between runs. | |
4084 | ||
53a5351d JM |
4085 | Note: this function gets called at the end of a run (by |
4086 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4087 | init_wait_for_inferior). */ |
c906108c SS |
4088 | |
4089 | ||
4090 | ||
4091 | void | |
fba45db2 | 4092 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4093 | { |
35df4500 | 4094 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4095 | struct bp_location *bl; |
1c5cfe86 | 4096 | int ix; |
6c95b8df | 4097 | struct program_space *pspace = current_program_space; |
c906108c | 4098 | |
50c71eaf PA |
4099 | /* If breakpoint locations are shared across processes, then there's |
4100 | nothing to do. */ | |
f5656ead | 4101 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4102 | return; |
4103 | ||
1a853c52 | 4104 | mark_breakpoints_out (); |
075f6582 | 4105 | |
35df4500 | 4106 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4107 | { |
6c95b8df PA |
4108 | if (b->loc && b->loc->pspace != pspace) |
4109 | continue; | |
4110 | ||
c5aa993b JM |
4111 | switch (b->type) |
4112 | { | |
4113 | case bp_call_dummy: | |
e2e4d78b | 4114 | case bp_longjmp_call_dummy: |
c906108c | 4115 | |
c5aa993b | 4116 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4117 | cause problems when the inferior is rerun, so we better get |
4118 | rid of it. */ | |
4119 | ||
4120 | case bp_watchpoint_scope: | |
4121 | ||
4122 | /* Also get rid of scope breakpoints. */ | |
4123 | ||
4124 | case bp_shlib_event: | |
4125 | ||
4126 | /* Also remove solib event breakpoints. Their addresses may | |
4127 | have changed since the last time we ran the program. | |
4128 | Actually we may now be debugging against different target; | |
4129 | and so the solib backend that installed this breakpoint may | |
4130 | not be used in by the target. E.g., | |
4131 | ||
4132 | (gdb) file prog-linux | |
4133 | (gdb) run # native linux target | |
4134 | ... | |
4135 | (gdb) kill | |
4136 | (gdb) file prog-win.exe | |
4137 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4138 | */ | |
c906108c | 4139 | |
f59f708a PA |
4140 | case bp_step_resume: |
4141 | ||
4142 | /* Also remove step-resume breakpoints. */ | |
4143 | ||
7c16b83e PA |
4144 | case bp_single_step: |
4145 | ||
4146 | /* Also remove single-step breakpoints. */ | |
4147 | ||
c5aa993b JM |
4148 | delete_breakpoint (b); |
4149 | break; | |
c906108c | 4150 | |
c5aa993b JM |
4151 | case bp_watchpoint: |
4152 | case bp_hardware_watchpoint: | |
4153 | case bp_read_watchpoint: | |
4154 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4155 | { |
4156 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4157 | |
3a5c3e22 PA |
4158 | /* Likewise for watchpoints on local expressions. */ |
4159 | if (w->exp_valid_block != NULL) | |
4160 | delete_breakpoint (b); | |
63000888 | 4161 | else |
3a5c3e22 | 4162 | { |
63000888 PA |
4163 | /* Get rid of existing locations, which are no longer |
4164 | valid. New ones will be created in | |
4165 | update_watchpoint, when the inferior is restarted. | |
4166 | The next update_global_location_list call will | |
4167 | garbage collect them. */ | |
4168 | b->loc = NULL; | |
4169 | ||
4170 | if (context == inf_starting) | |
4171 | { | |
4172 | /* Reset val field to force reread of starting value in | |
4173 | insert_breakpoints. */ | |
4174 | if (w->val) | |
4175 | value_free (w->val); | |
4176 | w->val = NULL; | |
4177 | w->val_valid = 0; | |
4178 | } | |
4179 | } | |
3a5c3e22 | 4180 | } |
c5aa993b JM |
4181 | break; |
4182 | default: | |
c5aa993b JM |
4183 | break; |
4184 | } | |
4185 | } | |
1c5cfe86 PA |
4186 | |
4187 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4188 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4189 | decref_bp_location (&bl); | |
1c5cfe86 | 4190 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4191 | } |
4192 | ||
6c95b8df PA |
4193 | /* These functions concern about actual breakpoints inserted in the |
4194 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4195 | we need to hop over the bkpt --- so we check for address space | |
4196 | match, not program space. */ | |
4197 | ||
c2c6d25f JM |
4198 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4199 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4200 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4201 | permanent breakpoint. | |
4202 | - When continuing from a location with an ordinary breakpoint, we | |
4203 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4204 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4205 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4206 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4207 | |
c2c6d25f | 4208 | enum breakpoint_here |
6c95b8df | 4209 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4210 | { |
35df4500 | 4211 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4212 | int any_breakpoint_here = 0; |
c906108c | 4213 | |
35df4500 | 4214 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4215 | { |
35df4500 TJB |
4216 | if (bl->loc_type != bp_loc_software_breakpoint |
4217 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4218 | continue; |
4219 | ||
f1310107 | 4220 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4221 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4222 | || bl->permanent) |
f1310107 | 4223 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4224 | { |
4225 | if (overlay_debugging | |
35df4500 TJB |
4226 | && section_is_overlay (bl->section) |
4227 | && !section_is_mapped (bl->section)) | |
075f6582 | 4228 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4229 | else if (bl->permanent) |
075f6582 DJ |
4230 | return permanent_breakpoint_here; |
4231 | else | |
4232 | any_breakpoint_here = 1; | |
4233 | } | |
4234 | } | |
c906108c | 4235 | |
f486487f | 4236 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4237 | } |
4238 | ||
d35ae833 PA |
4239 | /* See breakpoint.h. */ |
4240 | ||
4241 | int | |
4242 | breakpoint_in_range_p (struct address_space *aspace, | |
4243 | CORE_ADDR addr, ULONGEST len) | |
4244 | { | |
4245 | struct bp_location *bl, **blp_tmp; | |
4246 | ||
4247 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4248 | { | |
4249 | if (bl->loc_type != bp_loc_software_breakpoint | |
4250 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4251 | continue; | |
4252 | ||
4253 | if ((breakpoint_enabled (bl->owner) | |
4254 | || bl->permanent) | |
4255 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4256 | addr, len)) | |
4257 | { | |
4258 | if (overlay_debugging | |
4259 | && section_is_overlay (bl->section) | |
4260 | && !section_is_mapped (bl->section)) | |
4261 | { | |
4262 | /* Unmapped overlay -- can't be a match. */ | |
4263 | continue; | |
4264 | } | |
4265 | ||
4266 | return 1; | |
4267 | } | |
4268 | } | |
4269 | ||
4270 | return 0; | |
4271 | } | |
4272 | ||
1c5cfe86 PA |
4273 | /* Return true if there's a moribund breakpoint at PC. */ |
4274 | ||
4275 | int | |
6c95b8df | 4276 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4277 | { |
4278 | struct bp_location *loc; | |
4279 | int ix; | |
4280 | ||
4281 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4282 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4283 | return 1; |
4284 | ||
4285 | return 0; | |
4286 | } | |
c2c6d25f | 4287 | |
f7ce857f PA |
4288 | /* Returns non-zero iff BL is inserted at PC, in address space |
4289 | ASPACE. */ | |
4290 | ||
4291 | static int | |
4292 | bp_location_inserted_here_p (struct bp_location *bl, | |
4293 | struct address_space *aspace, CORE_ADDR pc) | |
4294 | { | |
4295 | if (bl->inserted | |
4296 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4297 | aspace, pc)) | |
4298 | { | |
4299 | if (overlay_debugging | |
4300 | && section_is_overlay (bl->section) | |
4301 | && !section_is_mapped (bl->section)) | |
4302 | return 0; /* unmapped overlay -- can't be a match */ | |
4303 | else | |
4304 | return 1; | |
4305 | } | |
4306 | return 0; | |
4307 | } | |
4308 | ||
a1fd2fa5 | 4309 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4310 | |
4311 | int | |
a1fd2fa5 | 4312 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4313 | { |
f7ce857f | 4314 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4315 | |
f7ce857f | 4316 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4317 | { |
f7ce857f PA |
4318 | struct bp_location *bl = *blp; |
4319 | ||
35df4500 TJB |
4320 | if (bl->loc_type != bp_loc_software_breakpoint |
4321 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4322 | continue; |
4323 | ||
f7ce857f PA |
4324 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4325 | return 1; | |
c5aa993b | 4326 | } |
c36b740a VP |
4327 | return 0; |
4328 | } | |
4329 | ||
a1fd2fa5 PA |
4330 | /* This function returns non-zero iff there is a software breakpoint |
4331 | inserted at PC. */ | |
c36b740a VP |
4332 | |
4333 | int | |
a1fd2fa5 PA |
4334 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4335 | CORE_ADDR pc) | |
4fa8626c | 4336 | { |
f7ce857f | 4337 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4338 | |
f7ce857f | 4339 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4340 | { |
f7ce857f PA |
4341 | struct bp_location *bl = *blp; |
4342 | ||
35df4500 | 4343 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4344 | continue; |
4345 | ||
f7ce857f PA |
4346 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4347 | return 1; | |
4fa8626c DJ |
4348 | } |
4349 | ||
4350 | return 0; | |
9c02b525 PA |
4351 | } |
4352 | ||
4353 | /* See breakpoint.h. */ | |
4354 | ||
4355 | int | |
4356 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4357 | CORE_ADDR pc) | |
4358 | { | |
4359 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4360 | |
4361 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4362 | { | |
4363 | struct bp_location *bl = *blp; | |
4364 | ||
4365 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4366 | continue; | |
4367 | ||
4368 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4369 | return 1; | |
4370 | } | |
4371 | ||
4372 | return 0; | |
4fa8626c DJ |
4373 | } |
4374 | ||
9093389c PA |
4375 | int |
4376 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4377 | CORE_ADDR addr, ULONGEST len) | |
4378 | { | |
4379 | struct breakpoint *bpt; | |
4380 | ||
4381 | ALL_BREAKPOINTS (bpt) | |
4382 | { | |
4383 | struct bp_location *loc; | |
4384 | ||
4385 | if (bpt->type != bp_hardware_watchpoint | |
4386 | && bpt->type != bp_access_watchpoint) | |
4387 | continue; | |
4388 | ||
4389 | if (!breakpoint_enabled (bpt)) | |
4390 | continue; | |
4391 | ||
4392 | for (loc = bpt->loc; loc; loc = loc->next) | |
4393 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4394 | { | |
4395 | CORE_ADDR l, h; | |
4396 | ||
4397 | /* Check for intersection. */ | |
768adc05 PA |
4398 | l = std::max<CORE_ADDR> (loc->address, addr); |
4399 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4400 | if (l < h) |
4401 | return 1; | |
4402 | } | |
4403 | } | |
4404 | return 0; | |
4405 | } | |
c906108c | 4406 | \f |
c5aa993b | 4407 | |
c906108c SS |
4408 | /* bpstat stuff. External routines' interfaces are documented |
4409 | in breakpoint.h. */ | |
4410 | ||
4411 | int | |
c326b90e | 4412 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4413 | { |
533be4dd | 4414 | return (ep->type == bp_catchpoint); |
c906108c SS |
4415 | } |
4416 | ||
f431efe5 PA |
4417 | /* Frees any storage that is part of a bpstat. Does not walk the |
4418 | 'next' chain. */ | |
4419 | ||
04afa70c | 4420 | bpstats::~bpstats () |
198757a8 | 4421 | { |
04afa70c TT |
4422 | if (old_val != NULL) |
4423 | value_free (old_val); | |
4424 | decref_counted_command_line (&commands); | |
4425 | if (bp_location_at != NULL) | |
4426 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4427 | } |
4428 | ||
c906108c SS |
4429 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4430 | Also free any storage that is part of a bpstat. */ | |
4431 | ||
4432 | void | |
fba45db2 | 4433 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4434 | { |
4435 | bpstat p; | |
4436 | bpstat q; | |
4437 | ||
4438 | if (bsp == 0) | |
4439 | return; | |
4440 | p = *bsp; | |
4441 | while (p != NULL) | |
4442 | { | |
4443 | q = p->next; | |
04afa70c | 4444 | delete p; |
c906108c SS |
4445 | p = q; |
4446 | } | |
4447 | *bsp = NULL; | |
4448 | } | |
4449 | ||
04afa70c TT |
4450 | bpstats::bpstats (const bpstats &other) |
4451 | : next (NULL), | |
4452 | bp_location_at (other.bp_location_at), | |
4453 | breakpoint_at (other.breakpoint_at), | |
4454 | commands (other.commands), | |
4455 | old_val (other.old_val), | |
4456 | print (other.print), | |
4457 | stop (other.stop), | |
4458 | print_it (other.print_it) | |
4459 | { | |
4460 | if (old_val != NULL) | |
4461 | { | |
4462 | old_val = value_copy (old_val); | |
4463 | release_value (old_val); | |
4464 | } | |
4465 | incref_bp_location (bp_location_at); | |
4466 | incref_counted_command_line (commands); | |
4467 | } | |
4468 | ||
c906108c SS |
4469 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4470 | is part of the bpstat is copied as well. */ | |
4471 | ||
4472 | bpstat | |
fba45db2 | 4473 | bpstat_copy (bpstat bs) |
c906108c SS |
4474 | { |
4475 | bpstat p = NULL; | |
4476 | bpstat tmp; | |
4477 | bpstat retval = NULL; | |
4478 | ||
4479 | if (bs == NULL) | |
4480 | return bs; | |
4481 | ||
4482 | for (; bs != NULL; bs = bs->next) | |
4483 | { | |
04afa70c | 4484 | tmp = new bpstats (*bs); |
31cc81e9 | 4485 | |
c906108c SS |
4486 | if (p == NULL) |
4487 | /* This is the first thing in the chain. */ | |
4488 | retval = tmp; | |
4489 | else | |
4490 | p->next = tmp; | |
4491 | p = tmp; | |
4492 | } | |
4493 | p->next = NULL; | |
4494 | return retval; | |
4495 | } | |
4496 | ||
4a64f543 | 4497 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4498 | |
4499 | bpstat | |
fba45db2 | 4500 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4501 | { |
c5aa993b JM |
4502 | if (bsp == NULL) |
4503 | return NULL; | |
c906108c | 4504 | |
c5aa993b JM |
4505 | for (; bsp != NULL; bsp = bsp->next) |
4506 | { | |
f431efe5 | 4507 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4508 | return bsp; |
4509 | } | |
c906108c SS |
4510 | return NULL; |
4511 | } | |
4512 | ||
ab04a2af TT |
4513 | /* See breakpoint.h. */ |
4514 | ||
47591c29 | 4515 | int |
427cd150 | 4516 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4517 | { |
ab04a2af TT |
4518 | for (; bsp != NULL; bsp = bsp->next) |
4519 | { | |
427cd150 TT |
4520 | if (bsp->breakpoint_at == NULL) |
4521 | { | |
4522 | /* A moribund location can never explain a signal other than | |
4523 | GDB_SIGNAL_TRAP. */ | |
4524 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4525 | return 1; |
427cd150 TT |
4526 | } |
4527 | else | |
47591c29 PA |
4528 | { |
4529 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4530 | sig)) | |
4531 | return 1; | |
4532 | } | |
ab04a2af TT |
4533 | } |
4534 | ||
47591c29 | 4535 | return 0; |
ab04a2af TT |
4536 | } |
4537 | ||
4a64f543 MS |
4538 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4539 | stopped at. *BSP upon return is a bpstat which points to the | |
4540 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4541 | good for anything but further calls to bpstat_num). | |
4542 | ||
8671a17b PA |
4543 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4544 | Return -1 if stopped at a breakpoint that has been deleted since | |
4545 | we set it. | |
4546 | Return 1 otherwise. */ | |
c906108c SS |
4547 | |
4548 | int | |
8671a17b | 4549 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4550 | { |
4551 | struct breakpoint *b; | |
4552 | ||
4553 | if ((*bsp) == NULL) | |
4554 | return 0; /* No more breakpoint values */ | |
8671a17b | 4555 | |
4a64f543 MS |
4556 | /* We assume we'll never have several bpstats that correspond to a |
4557 | single breakpoint -- otherwise, this function might return the | |
4558 | same number more than once and this will look ugly. */ | |
f431efe5 | 4559 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4560 | *bsp = (*bsp)->next; |
4561 | if (b == NULL) | |
4562 | return -1; /* breakpoint that's been deleted since */ | |
4563 | ||
4564 | *num = b->number; /* We have its number */ | |
4565 | return 1; | |
c906108c SS |
4566 | } |
4567 | ||
e93ca019 | 4568 | /* See breakpoint.h. */ |
c906108c SS |
4569 | |
4570 | void | |
e93ca019 | 4571 | bpstat_clear_actions (void) |
c906108c | 4572 | { |
e93ca019 JK |
4573 | struct thread_info *tp; |
4574 | bpstat bs; | |
4575 | ||
4576 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4577 | return; | |
4578 | ||
4579 | tp = find_thread_ptid (inferior_ptid); | |
4580 | if (tp == NULL) | |
4581 | return; | |
4582 | ||
4583 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4584 | { |
9add0f1b | 4585 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4586 | |
c906108c SS |
4587 | if (bs->old_val != NULL) |
4588 | { | |
4589 | value_free (bs->old_val); | |
4590 | bs->old_val = NULL; | |
4591 | } | |
4592 | } | |
4593 | } | |
4594 | ||
f3b1572e PA |
4595 | /* Called when a command is about to proceed the inferior. */ |
4596 | ||
4597 | static void | |
4598 | breakpoint_about_to_proceed (void) | |
4599 | { | |
4600 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4601 | { | |
4602 | struct thread_info *tp = inferior_thread (); | |
4603 | ||
4604 | /* Allow inferior function calls in breakpoint commands to not | |
4605 | interrupt the command list. When the call finishes | |
4606 | successfully, the inferior will be standing at the same | |
4607 | breakpoint as if nothing happened. */ | |
16c381f0 | 4608 | if (tp->control.in_infcall) |
f3b1572e PA |
4609 | return; |
4610 | } | |
4611 | ||
4612 | breakpoint_proceeded = 1; | |
4613 | } | |
4614 | ||
4a64f543 MS |
4615 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4616 | command. */ | |
c906108c | 4617 | static void |
4efb68b1 | 4618 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4619 | { |
4620 | executing_breakpoint_commands = 0; | |
4621 | } | |
4622 | ||
abf85f46 JK |
4623 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4624 | or its equivalent. */ | |
4625 | ||
4626 | static int | |
4627 | command_line_is_silent (struct command_line *cmd) | |
4628 | { | |
4f45d445 | 4629 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4630 | } |
4631 | ||
4a64f543 MS |
4632 | /* Execute all the commands associated with all the breakpoints at |
4633 | this location. Any of these commands could cause the process to | |
4634 | proceed beyond this point, etc. We look out for such changes by | |
4635 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4636 | |
347bddb7 PA |
4637 | Returns true if a breakpoint command resumed the inferior. In that |
4638 | case, it is the caller's responsibility to recall it again with the | |
4639 | bpstat of the current thread. */ | |
4640 | ||
4641 | static int | |
4642 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4643 | { |
4644 | bpstat bs; | |
4645 | struct cleanup *old_chain; | |
347bddb7 | 4646 | int again = 0; |
c906108c SS |
4647 | |
4648 | /* Avoid endless recursion if a `source' command is contained | |
4649 | in bs->commands. */ | |
4650 | if (executing_breakpoint_commands) | |
347bddb7 | 4651 | return 0; |
c906108c SS |
4652 | |
4653 | executing_breakpoint_commands = 1; | |
4654 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4655 | ||
1ac32117 | 4656 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4657 | |
4a64f543 | 4658 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4659 | bs = *bsp; |
4660 | ||
4661 | breakpoint_proceeded = 0; | |
4662 | for (; bs != NULL; bs = bs->next) | |
4663 | { | |
9add0f1b | 4664 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4665 | struct command_line *cmd; |
4666 | struct cleanup *this_cmd_tree_chain; | |
4667 | ||
4668 | /* Take ownership of the BSP's command tree, if it has one. | |
4669 | ||
4670 | The command tree could legitimately contain commands like | |
4671 | 'step' and 'next', which call clear_proceed_status, which | |
4672 | frees stop_bpstat's command tree. To make sure this doesn't | |
4673 | free the tree we're executing out from under us, we need to | |
4674 | take ownership of the tree ourselves. Since a given bpstat's | |
4675 | commands are only executed once, we don't need to copy it; we | |
4676 | can clear the pointer in the bpstat, and make sure we free | |
4677 | the tree when we're done. */ | |
9add0f1b TT |
4678 | ccmd = bs->commands; |
4679 | bs->commands = NULL; | |
abf85f46 JK |
4680 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4681 | cmd = ccmd ? ccmd->commands : NULL; | |
4682 | if (command_line_is_silent (cmd)) | |
4683 | { | |
4684 | /* The action has been already done by bpstat_stop_status. */ | |
4685 | cmd = cmd->next; | |
4686 | } | |
6c50ab1c | 4687 | |
c906108c SS |
4688 | while (cmd != NULL) |
4689 | { | |
4690 | execute_control_command (cmd); | |
4691 | ||
4692 | if (breakpoint_proceeded) | |
4693 | break; | |
4694 | else | |
4695 | cmd = cmd->next; | |
4696 | } | |
6c50ab1c JB |
4697 | |
4698 | /* We can free this command tree now. */ | |
4699 | do_cleanups (this_cmd_tree_chain); | |
4700 | ||
c906108c | 4701 | if (breakpoint_proceeded) |
32c1e744 | 4702 | { |
cb814510 | 4703 | if (current_ui->async) |
347bddb7 PA |
4704 | /* If we are in async mode, then the target might be still |
4705 | running, not stopped at any breakpoint, so nothing for | |
4706 | us to do here -- just return to the event loop. */ | |
4707 | ; | |
32c1e744 VP |
4708 | else |
4709 | /* In sync mode, when execute_control_command returns | |
4710 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4711 | Breakpoint commands for that stop were not run, since |
4712 | execute_command does not run breakpoint commands -- | |
4713 | only command_line_handler does, but that one is not | |
4714 | involved in execution of breakpoint commands. So, we | |
4715 | can now execute breakpoint commands. It should be | |
4716 | noted that making execute_command do bpstat actions is | |
4717 | not an option -- in this case we'll have recursive | |
4718 | invocation of bpstat for each breakpoint with a | |
4719 | command, and can easily blow up GDB stack. Instead, we | |
4720 | return true, which will trigger the caller to recall us | |
4721 | with the new stop_bpstat. */ | |
4722 | again = 1; | |
4723 | break; | |
32c1e744 | 4724 | } |
c906108c | 4725 | } |
c2b8ed2c | 4726 | do_cleanups (old_chain); |
347bddb7 PA |
4727 | return again; |
4728 | } | |
4729 | ||
4730 | void | |
4731 | bpstat_do_actions (void) | |
4732 | { | |
353d1d73 JK |
4733 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4734 | ||
347bddb7 PA |
4735 | /* Do any commands attached to breakpoint we are stopped at. */ |
4736 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4737 | && target_has_execution | |
4738 | && !is_exited (inferior_ptid) | |
4739 | && !is_executing (inferior_ptid)) | |
4740 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4741 | and only return when it is stopped at the next breakpoint, we | |
4742 | keep doing breakpoint actions until it returns false to | |
4743 | indicate the inferior was not resumed. */ | |
16c381f0 | 4744 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4745 | break; |
353d1d73 JK |
4746 | |
4747 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4748 | } |
4749 | ||
fa4727a6 DJ |
4750 | /* Print out the (old or new) value associated with a watchpoint. */ |
4751 | ||
4752 | static void | |
4753 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4754 | { | |
4755 | if (val == NULL) | |
4756 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4757 | else | |
79a45b7d TT |
4758 | { |
4759 | struct value_print_options opts; | |
4760 | get_user_print_options (&opts); | |
4761 | value_print (val, stream, &opts); | |
4762 | } | |
fa4727a6 DJ |
4763 | } |
4764 | ||
f303dbd6 PA |
4765 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4766 | debugging multiple threads. */ | |
4767 | ||
4768 | void | |
4769 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4770 | { | |
112e8700 | 4771 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4772 | return; |
4773 | ||
112e8700 | 4774 | uiout->text ("\n"); |
f303dbd6 PA |
4775 | |
4776 | if (show_thread_that_caused_stop ()) | |
4777 | { | |
4778 | const char *name; | |
4779 | struct thread_info *thr = inferior_thread (); | |
4780 | ||
112e8700 SM |
4781 | uiout->text ("Thread "); |
4782 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4783 | |
4784 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4785 | if (name != NULL) | |
4786 | { | |
112e8700 SM |
4787 | uiout->text (" \""); |
4788 | uiout->field_fmt ("name", "%s", name); | |
4789 | uiout->text ("\""); | |
f303dbd6 PA |
4790 | } |
4791 | ||
112e8700 | 4792 | uiout->text (" hit "); |
f303dbd6 PA |
4793 | } |
4794 | } | |
4795 | ||
e514a9d6 | 4796 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4797 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4798 | 'print_it' in the bpstat structure. Under some circumstances we |
4799 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4800 | normal_stop(). */ |
e514a9d6 JM |
4801 | |
4802 | static enum print_stop_action | |
4803 | print_bp_stop_message (bpstat bs) | |
4804 | { | |
4805 | switch (bs->print_it) | |
4806 | { | |
4807 | case print_it_noop: | |
4a64f543 | 4808 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4809 | return PRINT_UNKNOWN; |
4810 | break; | |
4811 | ||
4812 | case print_it_done: | |
4813 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4814 | relevant messages. */ |
e514a9d6 JM |
4815 | return PRINT_SRC_AND_LOC; |
4816 | break; | |
4817 | ||
4818 | case print_it_normal: | |
4f8d1dc6 | 4819 | { |
f431efe5 PA |
4820 | struct breakpoint *b = bs->breakpoint_at; |
4821 | ||
1a6a67de TJB |
4822 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4823 | which has since been deleted. */ | |
4824 | if (b == NULL) | |
4825 | return PRINT_UNKNOWN; | |
4826 | ||
348d480f PA |
4827 | /* Normal case. Call the breakpoint's print_it method. */ |
4828 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4829 | } |
348d480f | 4830 | break; |
3086aeae | 4831 | |
e514a9d6 | 4832 | default: |
8e65ff28 | 4833 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4834 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4835 | break; |
c906108c | 4836 | } |
c906108c SS |
4837 | } |
4838 | ||
edcc5120 TT |
4839 | /* A helper function that prints a shared library stopped event. */ |
4840 | ||
4841 | static void | |
4842 | print_solib_event (int is_catchpoint) | |
4843 | { | |
4844 | int any_deleted | |
4845 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4846 | int any_added | |
4847 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4848 | ||
4849 | if (!is_catchpoint) | |
4850 | { | |
4851 | if (any_added || any_deleted) | |
112e8700 | 4852 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4853 | else |
112e8700 SM |
4854 | current_uiout->text (_("Stopped due to shared library event (no " |
4855 | "libraries added or removed)\n")); | |
edcc5120 TT |
4856 | } |
4857 | ||
112e8700 SM |
4858 | if (current_uiout->is_mi_like_p ()) |
4859 | current_uiout->field_string ("reason", | |
4860 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4861 | |
4862 | if (any_deleted) | |
4863 | { | |
edcc5120 TT |
4864 | char *name; |
4865 | int ix; | |
4866 | ||
112e8700 | 4867 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4868 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
edcc5120 TT |
4869 | for (ix = 0; |
4870 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4871 | ix, name); | |
4872 | ++ix) | |
4873 | { | |
4874 | if (ix > 0) | |
112e8700 SM |
4875 | current_uiout->text (" "); |
4876 | current_uiout->field_string ("library", name); | |
4877 | current_uiout->text ("\n"); | |
edcc5120 | 4878 | } |
edcc5120 TT |
4879 | } |
4880 | ||
4881 | if (any_added) | |
4882 | { | |
4883 | struct so_list *iter; | |
4884 | int ix; | |
edcc5120 | 4885 | |
112e8700 | 4886 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4887 | ui_out_emit_list list_emitter (current_uiout, "added"); |
edcc5120 TT |
4888 | for (ix = 0; |
4889 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4890 | ix, iter); | |
4891 | ++ix) | |
4892 | { | |
4893 | if (ix > 0) | |
112e8700 SM |
4894 | current_uiout->text (" "); |
4895 | current_uiout->field_string ("library", iter->so_name); | |
4896 | current_uiout->text ("\n"); | |
edcc5120 | 4897 | } |
edcc5120 TT |
4898 | } |
4899 | } | |
4900 | ||
e514a9d6 JM |
4901 | /* Print a message indicating what happened. This is called from |
4902 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4903 | list - a list of the eventpoints that caused this stop. KIND is |
4904 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4905 | routine calls the generic print routine for printing a message |
4906 | about reasons for stopping. This will print (for example) the | |
4907 | "Breakpoint n," part of the output. The return value of this | |
4908 | routine is one of: | |
c906108c | 4909 | |
4a64f543 | 4910 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4911 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4912 | code to print the location. An example is |
c5aa993b JM |
4913 | "Breakpoint 1, " which should be followed by |
4914 | the location. | |
917317f4 | 4915 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4916 | to also print the location part of the message. |
4917 | An example is the catch/throw messages, which | |
4a64f543 | 4918 | don't require a location appended to the end. |
917317f4 | 4919 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4920 | further info to be printed. */ |
c906108c | 4921 | |
917317f4 | 4922 | enum print_stop_action |
36dfb11c | 4923 | bpstat_print (bpstat bs, int kind) |
c906108c | 4924 | { |
f486487f | 4925 | enum print_stop_action val; |
c5aa993b | 4926 | |
c906108c | 4927 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4928 | (Currently all watchpoints go on the bpstat whether hit or not. |
4929 | That probably could (should) be changed, provided care is taken | |
c906108c | 4930 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4931 | for (; bs; bs = bs->next) |
4932 | { | |
4933 | val = print_bp_stop_message (bs); | |
4934 | if (val == PRINT_SRC_ONLY | |
4935 | || val == PRINT_SRC_AND_LOC | |
4936 | || val == PRINT_NOTHING) | |
4937 | return val; | |
4938 | } | |
c906108c | 4939 | |
36dfb11c TT |
4940 | /* If we had hit a shared library event breakpoint, |
4941 | print_bp_stop_message would print out this message. If we hit an | |
4942 | OS-level shared library event, do the same thing. */ | |
4943 | if (kind == TARGET_WAITKIND_LOADED) | |
4944 | { | |
edcc5120 | 4945 | print_solib_event (0); |
36dfb11c TT |
4946 | return PRINT_NOTHING; |
4947 | } | |
4948 | ||
e514a9d6 | 4949 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4950 | with and nothing was printed. */ |
917317f4 | 4951 | return PRINT_UNKNOWN; |
c906108c SS |
4952 | } |
4953 | ||
c42bd95a DE |
4954 | /* Evaluate the expression EXP and return 1 if value is zero. |
4955 | This returns the inverse of the condition because it is called | |
4956 | from catch_errors which returns 0 if an exception happened, and if an | |
4957 | exception happens we want execution to stop. | |
4a64f543 | 4958 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4959 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4960 | |
4961 | static int | |
4efb68b1 | 4962 | breakpoint_cond_eval (void *exp) |
c906108c | 4963 | { |
278cd55f | 4964 | struct value *mark = value_mark (); |
c5aa993b | 4965 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4966 | |
c906108c SS |
4967 | value_free_to_mark (mark); |
4968 | return i; | |
4969 | } | |
4970 | ||
5760d0ab | 4971 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4972 | |
04afa70c TT |
4973 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4974 | : next (NULL), | |
4975 | bp_location_at (bl), | |
4976 | breakpoint_at (bl->owner), | |
4977 | commands (NULL), | |
4978 | old_val (NULL), | |
4979 | print (0), | |
4980 | stop (0), | |
4981 | print_it (print_it_normal) | |
c906108c | 4982 | { |
f431efe5 | 4983 | incref_bp_location (bl); |
04afa70c TT |
4984 | **bs_link_pointer = this; |
4985 | *bs_link_pointer = &next; | |
4986 | } | |
4987 | ||
4988 | bpstats::bpstats () | |
4989 | : next (NULL), | |
4990 | bp_location_at (NULL), | |
4991 | breakpoint_at (NULL), | |
4992 | commands (NULL), | |
4993 | old_val (NULL), | |
4994 | print (0), | |
4995 | stop (0), | |
4996 | print_it (print_it_normal) | |
4997 | { | |
c906108c SS |
4998 | } |
4999 | \f | |
d983da9c DJ |
5000 | /* The target has stopped with waitstatus WS. Check if any hardware |
5001 | watchpoints have triggered, according to the target. */ | |
5002 | ||
5003 | int | |
5004 | watchpoints_triggered (struct target_waitstatus *ws) | |
5005 | { | |
d92524f1 | 5006 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5007 | CORE_ADDR addr; |
5008 | struct breakpoint *b; | |
5009 | ||
5010 | if (!stopped_by_watchpoint) | |
5011 | { | |
5012 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5013 | as not triggered. */ | |
5014 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5015 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5016 | { |
5017 | struct watchpoint *w = (struct watchpoint *) b; | |
5018 | ||
5019 | w->watchpoint_triggered = watch_triggered_no; | |
5020 | } | |
d983da9c DJ |
5021 | |
5022 | return 0; | |
5023 | } | |
5024 | ||
5025 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5026 | { | |
5027 | /* We were stopped by a watchpoint, but we don't know where. | |
5028 | Mark all watchpoints as unknown. */ | |
5029 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5030 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5031 | { |
5032 | struct watchpoint *w = (struct watchpoint *) b; | |
5033 | ||
5034 | w->watchpoint_triggered = watch_triggered_unknown; | |
5035 | } | |
d983da9c | 5036 | |
3c4797ba | 5037 | return 1; |
d983da9c DJ |
5038 | } |
5039 | ||
5040 | /* The target could report the data address. Mark watchpoints | |
5041 | affected by this data address as triggered, and all others as not | |
5042 | triggered. */ | |
5043 | ||
5044 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5045 | if (is_hardware_watchpoint (b)) |
d983da9c | 5046 | { |
3a5c3e22 | 5047 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5048 | struct bp_location *loc; |
d983da9c | 5049 | |
3a5c3e22 | 5050 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5051 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5052 | { |
3a5c3e22 | 5053 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5054 | { |
3a5c3e22 PA |
5055 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5056 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5057 | |
5058 | if (newaddr == start) | |
5059 | { | |
3a5c3e22 | 5060 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5061 | break; |
5062 | } | |
5063 | } | |
5064 | /* Exact match not required. Within range is sufficient. */ | |
5065 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5066 | addr, loc->address, | |
5067 | loc->length)) | |
5068 | { | |
3a5c3e22 | 5069 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5070 | break; |
5071 | } | |
5072 | } | |
d983da9c DJ |
5073 | } |
5074 | ||
5075 | return 1; | |
5076 | } | |
5077 | ||
c906108c SS |
5078 | /* Possible return values for watchpoint_check (this can't be an enum |
5079 | because of check_errors). */ | |
5080 | /* The watchpoint has been deleted. */ | |
5081 | #define WP_DELETED 1 | |
5082 | /* The value has changed. */ | |
5083 | #define WP_VALUE_CHANGED 2 | |
5084 | /* The value has not changed. */ | |
5085 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5086 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5087 | #define WP_IGNORE 4 | |
c906108c SS |
5088 | |
5089 | #define BP_TEMPFLAG 1 | |
5090 | #define BP_HARDWAREFLAG 2 | |
5091 | ||
4a64f543 MS |
5092 | /* Evaluate watchpoint condition expression and check if its value |
5093 | changed. | |
553e4c11 JB |
5094 | |
5095 | P should be a pointer to struct bpstat, but is defined as a void * | |
5096 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5097 | |
5098 | static int | |
4efb68b1 | 5099 | watchpoint_check (void *p) |
c906108c SS |
5100 | { |
5101 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5102 | struct watchpoint *b; |
c906108c SS |
5103 | struct frame_info *fr; |
5104 | int within_current_scope; | |
5105 | ||
f431efe5 | 5106 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5107 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5108 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5109 | |
f6bc2008 PA |
5110 | /* If this is a local watchpoint, we only want to check if the |
5111 | watchpoint frame is in scope if the current thread is the thread | |
5112 | that was used to create the watchpoint. */ | |
5113 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5114 | return WP_IGNORE; |
f6bc2008 | 5115 | |
c906108c SS |
5116 | if (b->exp_valid_block == NULL) |
5117 | within_current_scope = 1; | |
5118 | else | |
5119 | { | |
edb3359d DJ |
5120 | struct frame_info *frame = get_current_frame (); |
5121 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5122 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5123 | ||
c9cf6e20 | 5124 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5125 | still in the function but the stack frame has already been |
5126 | invalidated. Since we can't rely on the values of local | |
5127 | variables after the stack has been destroyed, we are treating | |
5128 | the watchpoint in that state as `not changed' without further | |
5129 | checking. Don't mark watchpoints as changed if the current | |
5130 | frame is in an epilogue - even if they are in some other | |
5131 | frame, our view of the stack is likely to be wrong and | |
5132 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5133 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5134 | return WP_IGNORE; |
a0f49112 | 5135 | |
101dcfbe | 5136 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5137 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5138 | |
5139 | /* If we've gotten confused in the unwinder, we might have | |
5140 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5141 | if (within_current_scope) |
5142 | { | |
5143 | struct symbol *function; | |
5144 | ||
5145 | function = get_frame_function (fr); | |
5146 | if (function == NULL | |
5147 | || !contained_in (b->exp_valid_block, | |
5148 | SYMBOL_BLOCK_VALUE (function))) | |
5149 | within_current_scope = 0; | |
5150 | } | |
69fbadd5 | 5151 | |
edb3359d | 5152 | if (within_current_scope) |
c906108c SS |
5153 | /* If we end up stopping, the current frame will get selected |
5154 | in normal_stop. So this call to select_frame won't affect | |
5155 | the user. */ | |
0f7d239c | 5156 | select_frame (fr); |
c906108c | 5157 | } |
c5aa993b | 5158 | |
c906108c SS |
5159 | if (within_current_scope) |
5160 | { | |
4a64f543 MS |
5161 | /* We use value_{,free_to_}mark because it could be a *long* |
5162 | time before we return to the command level and call | |
5163 | free_all_values. We can't call free_all_values because we | |
5164 | might be in the middle of evaluating a function call. */ | |
c906108c | 5165 | |
0cf6dd15 | 5166 | int pc = 0; |
9c06b0b4 | 5167 | struct value *mark; |
fa4727a6 DJ |
5168 | struct value *new_val; |
5169 | ||
c1fc2657 | 5170 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
5171 | /* Since we don't know the exact trigger address (from |
5172 | stopped_data_address), just tell the user we've triggered | |
5173 | a mask watchpoint. */ | |
5174 | return WP_VALUE_CHANGED; | |
5175 | ||
5176 | mark = value_mark (); | |
4d01a485 | 5177 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5178 | |
bb9d5f81 PP |
5179 | if (b->val_bitsize != 0) |
5180 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5181 | ||
4a64f543 MS |
5182 | /* We use value_equal_contents instead of value_equal because |
5183 | the latter coerces an array to a pointer, thus comparing just | |
5184 | the address of the array instead of its contents. This is | |
5185 | not what we want. */ | |
fa4727a6 | 5186 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5187 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5188 | { |
fa4727a6 DJ |
5189 | if (new_val != NULL) |
5190 | { | |
5191 | release_value (new_val); | |
5192 | value_free_to_mark (mark); | |
5193 | } | |
c906108c SS |
5194 | bs->old_val = b->val; |
5195 | b->val = new_val; | |
fa4727a6 | 5196 | b->val_valid = 1; |
c906108c SS |
5197 | return WP_VALUE_CHANGED; |
5198 | } | |
5199 | else | |
5200 | { | |
60e1c644 | 5201 | /* Nothing changed. */ |
c906108c | 5202 | value_free_to_mark (mark); |
c906108c SS |
5203 | return WP_VALUE_NOT_CHANGED; |
5204 | } | |
5205 | } | |
5206 | else | |
5207 | { | |
5208 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5209 | if we temporarily ignored the watchpoint, then when |
5210 | we reenter the block in which it is valid it contains | |
5211 | garbage (in the case of a function, it may have two | |
5212 | garbage values, one before and one after the prologue). | |
5213 | So we can't even detect the first assignment to it and | |
5214 | watch after that (since the garbage may or may not equal | |
5215 | the first value assigned). */ | |
348d480f PA |
5216 | /* We print all the stop information in |
5217 | breakpoint_ops->print_it, but in this case, by the time we | |
5218 | call breakpoint_ops->print_it this bp will be deleted | |
5219 | already. So we have no choice but print the information | |
5220 | here. */ | |
468afe6c | 5221 | |
0e454242 | 5222 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5223 | { |
5224 | struct ui_out *uiout = current_uiout; | |
5225 | ||
112e8700 SM |
5226 | if (uiout->is_mi_like_p ()) |
5227 | uiout->field_string | |
5228 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5229 | uiout->text ("\nWatchpoint "); | |
c1fc2657 | 5230 | uiout->field_int ("wpnum", b->number); |
112e8700 | 5231 | uiout->text (" deleted because the program has left the block in\n" |
468afe6c PA |
5232 | "which its expression is valid.\n"); |
5233 | } | |
4ce44c66 | 5234 | |
cdac0397 | 5235 | /* Make sure the watchpoint's commands aren't executed. */ |
c1fc2657 | 5236 | decref_counted_command_line (&b->commands); |
d0fb5eae | 5237 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5238 | |
5239 | return WP_DELETED; | |
5240 | } | |
5241 | } | |
5242 | ||
18a18393 | 5243 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5244 | breakpoint location BL. This function does not check if we should |
5245 | stop, only if BL explains the stop. */ | |
5246 | ||
18a18393 | 5247 | static int |
6c95b8df | 5248 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5249 | struct address_space *aspace, CORE_ADDR bp_addr, |
5250 | const struct target_waitstatus *ws) | |
18a18393 VP |
5251 | { |
5252 | struct breakpoint *b = bl->owner; | |
5253 | ||
348d480f | 5254 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5255 | gdb_assert (b != NULL); |
5256 | ||
09ac7c10 | 5257 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5258 | } |
5259 | ||
3a5c3e22 PA |
5260 | /* Determine if the watched values have actually changed, and we |
5261 | should stop. If not, set BS->stop to 0. */ | |
5262 | ||
18a18393 VP |
5263 | static void |
5264 | bpstat_check_watchpoint (bpstat bs) | |
5265 | { | |
2bdf28a0 | 5266 | const struct bp_location *bl; |
3a5c3e22 | 5267 | struct watchpoint *b; |
2bdf28a0 JK |
5268 | |
5269 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5270 | bl = bs->bp_location_at; |
2bdf28a0 | 5271 | gdb_assert (bl != NULL); |
3a5c3e22 | 5272 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5273 | gdb_assert (b != NULL); |
18a18393 | 5274 | |
18a18393 | 5275 | { |
18a18393 VP |
5276 | int must_check_value = 0; |
5277 | ||
c1fc2657 | 5278 | if (b->type == bp_watchpoint) |
18a18393 VP |
5279 | /* For a software watchpoint, we must always check the |
5280 | watched value. */ | |
5281 | must_check_value = 1; | |
5282 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5283 | /* We have a hardware watchpoint (read, write, or access) | |
5284 | and the target earlier reported an address watched by | |
5285 | this watchpoint. */ | |
5286 | must_check_value = 1; | |
5287 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5288 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5289 | /* We were stopped by a hardware watchpoint, but the target could |
5290 | not report the data address. We must check the watchpoint's | |
5291 | value. Access and read watchpoints are out of luck; without | |
5292 | a data address, we can't figure it out. */ | |
5293 | must_check_value = 1; | |
3a5c3e22 | 5294 | |
18a18393 VP |
5295 | if (must_check_value) |
5296 | { | |
3e43a32a MS |
5297 | char *message |
5298 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
c1fc2657 | 5299 | b->number); |
18a18393 VP |
5300 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5301 | int e = catch_errors (watchpoint_check, bs, message, | |
5302 | RETURN_MASK_ALL); | |
5303 | do_cleanups (cleanups); | |
5304 | switch (e) | |
5305 | { | |
5306 | case WP_DELETED: | |
5307 | /* We've already printed what needs to be printed. */ | |
5308 | bs->print_it = print_it_done; | |
5309 | /* Stop. */ | |
5310 | break; | |
60e1c644 PA |
5311 | case WP_IGNORE: |
5312 | bs->print_it = print_it_noop; | |
5313 | bs->stop = 0; | |
5314 | break; | |
18a18393 | 5315 | case WP_VALUE_CHANGED: |
c1fc2657 | 5316 | if (b->type == bp_read_watchpoint) |
18a18393 | 5317 | { |
85d721b8 PA |
5318 | /* There are two cases to consider here: |
5319 | ||
4a64f543 | 5320 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5321 | In that case, trust the target, and always report |
5322 | the watchpoint hit to the user. Even though | |
5323 | reads don't cause value changes, the value may | |
5324 | have changed since the last time it was read, and | |
5325 | since we're not trapping writes, we will not see | |
5326 | those, and as such we should ignore our notion of | |
5327 | old value. | |
5328 | ||
4a64f543 | 5329 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5330 | reads and writes. There are two ways this may |
5331 | happen: | |
5332 | ||
4a64f543 | 5333 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5334 | reads only, but can break on accesses (reads or |
5335 | writes), such as e.g., x86. We detect this case | |
5336 | at the time we try to insert read watchpoints. | |
5337 | ||
4a64f543 | 5338 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5339 | watchpoints, but, the user set an access or write |
5340 | watchpoint watching the same memory as this read | |
5341 | watchpoint. | |
5342 | ||
5343 | If we're watching memory writes as well as reads, | |
5344 | ignore watchpoint hits when we find that the | |
5345 | value hasn't changed, as reads don't cause | |
5346 | changes. This still gives false positives when | |
5347 | the program writes the same value to memory as | |
5348 | what there was already in memory (we will confuse | |
5349 | it for a read), but it's much better than | |
5350 | nothing. */ | |
5351 | ||
5352 | int other_write_watchpoint = 0; | |
5353 | ||
5354 | if (bl->watchpoint_type == hw_read) | |
5355 | { | |
5356 | struct breakpoint *other_b; | |
5357 | ||
5358 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5359 | if (other_b->type == bp_hardware_watchpoint |
5360 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5361 | { |
3a5c3e22 PA |
5362 | struct watchpoint *other_w = |
5363 | (struct watchpoint *) other_b; | |
5364 | ||
5365 | if (other_w->watchpoint_triggered | |
5366 | == watch_triggered_yes) | |
5367 | { | |
5368 | other_write_watchpoint = 1; | |
5369 | break; | |
5370 | } | |
85d721b8 PA |
5371 | } |
5372 | } | |
5373 | ||
5374 | if (other_write_watchpoint | |
5375 | || bl->watchpoint_type == hw_access) | |
5376 | { | |
5377 | /* We're watching the same memory for writes, | |
5378 | and the value changed since the last time we | |
5379 | updated it, so this trap must be for a write. | |
5380 | Ignore it. */ | |
5381 | bs->print_it = print_it_noop; | |
5382 | bs->stop = 0; | |
5383 | } | |
18a18393 VP |
5384 | } |
5385 | break; | |
5386 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5387 | if (b->type == bp_hardware_watchpoint |
5388 | || b->type == bp_watchpoint) | |
18a18393 VP |
5389 | { |
5390 | /* Don't stop: write watchpoints shouldn't fire if | |
5391 | the value hasn't changed. */ | |
5392 | bs->print_it = print_it_noop; | |
5393 | bs->stop = 0; | |
5394 | } | |
5395 | /* Stop. */ | |
5396 | break; | |
5397 | default: | |
5398 | /* Can't happen. */ | |
5399 | case 0: | |
5400 | /* Error from catch_errors. */ | |
468afe6c | 5401 | { |
0e454242 | 5402 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5403 | { |
5404 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
c1fc2657 | 5405 | b->number); |
468afe6c PA |
5406 | } |
5407 | watchpoint_del_at_next_stop (b); | |
5408 | /* We've already printed what needs to be printed. */ | |
5409 | bs->print_it = print_it_done; | |
5410 | } | |
18a18393 VP |
5411 | break; |
5412 | } | |
5413 | } | |
5414 | else /* must_check_value == 0 */ | |
5415 | { | |
5416 | /* This is a case where some watchpoint(s) triggered, but | |
5417 | not at the address of this watchpoint, or else no | |
5418 | watchpoint triggered after all. So don't print | |
5419 | anything for this watchpoint. */ | |
5420 | bs->print_it = print_it_noop; | |
5421 | bs->stop = 0; | |
5422 | } | |
5423 | } | |
5424 | } | |
5425 | ||
7d4df6a4 DE |
5426 | /* For breakpoints that are currently marked as telling gdb to stop, |
5427 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5428 | of breakpoint referred to by BS. If we should not stop for this |
5429 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5430 | |
18a18393 VP |
5431 | static void |
5432 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5433 | { | |
2bdf28a0 JK |
5434 | const struct bp_location *bl; |
5435 | struct breakpoint *b; | |
7d4df6a4 DE |
5436 | int value_is_zero = 0; |
5437 | struct expression *cond; | |
5438 | ||
5439 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5440 | |
5441 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5442 | bl = bs->bp_location_at; |
2bdf28a0 | 5443 | gdb_assert (bl != NULL); |
f431efe5 | 5444 | b = bs->breakpoint_at; |
2bdf28a0 | 5445 | gdb_assert (b != NULL); |
18a18393 | 5446 | |
b775012e LM |
5447 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5448 | need to do so again since GDB does not know if we stopped due to a | |
5449 | breakpoint or a single step breakpoint. */ | |
5450 | ||
18a18393 | 5451 | if (frame_id_p (b->frame_id) |
edb3359d | 5452 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5453 | { |
7d4df6a4 DE |
5454 | bs->stop = 0; |
5455 | return; | |
5456 | } | |
60e1c644 | 5457 | |
12ab52e9 PA |
5458 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5459 | evaluating the condition if this isn't the specified | |
5460 | thread/task. */ | |
5d5658a1 | 5461 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5462 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5463 | ||
6c1b0f7b DE |
5464 | { |
5465 | bs->stop = 0; | |
5466 | return; | |
5467 | } | |
5468 | ||
6dddc817 DE |
5469 | /* Evaluate extension language breakpoints that have a "stop" method |
5470 | implemented. */ | |
5471 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5472 | |
7d4df6a4 DE |
5473 | if (is_watchpoint (b)) |
5474 | { | |
5475 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5476 | |
4d01a485 | 5477 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5478 | } |
5479 | else | |
4d01a485 | 5480 | cond = bl->cond.get (); |
60e1c644 | 5481 | |
7d4df6a4 DE |
5482 | if (cond && b->disposition != disp_del_at_next_stop) |
5483 | { | |
5484 | int within_current_scope = 1; | |
5485 | struct watchpoint * w; | |
60e1c644 | 5486 | |
7d4df6a4 DE |
5487 | /* We use value_mark and value_free_to_mark because it could |
5488 | be a long time before we return to the command level and | |
5489 | call free_all_values. We can't call free_all_values | |
5490 | because we might be in the middle of evaluating a | |
5491 | function call. */ | |
5492 | struct value *mark = value_mark (); | |
5493 | ||
5494 | if (is_watchpoint (b)) | |
5495 | w = (struct watchpoint *) b; | |
5496 | else | |
5497 | w = NULL; | |
5498 | ||
5499 | /* Need to select the frame, with all that implies so that | |
5500 | the conditions will have the right context. Because we | |
5501 | use the frame, we will not see an inlined function's | |
5502 | variables when we arrive at a breakpoint at the start | |
5503 | of the inlined function; the current frame will be the | |
5504 | call site. */ | |
5505 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5506 | select_frame (get_current_frame ()); | |
5507 | else | |
18a18393 | 5508 | { |
7d4df6a4 DE |
5509 | struct frame_info *frame; |
5510 | ||
5511 | /* For local watchpoint expressions, which particular | |
5512 | instance of a local is being watched matters, so we | |
5513 | keep track of the frame to evaluate the expression | |
5514 | in. To evaluate the condition however, it doesn't | |
5515 | really matter which instantiation of the function | |
5516 | where the condition makes sense triggers the | |
5517 | watchpoint. This allows an expression like "watch | |
5518 | global if q > 10" set in `func', catch writes to | |
5519 | global on all threads that call `func', or catch | |
5520 | writes on all recursive calls of `func' by a single | |
5521 | thread. We simply always evaluate the condition in | |
5522 | the innermost frame that's executing where it makes | |
5523 | sense to evaluate the condition. It seems | |
5524 | intuitive. */ | |
5525 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5526 | if (frame != NULL) | |
5527 | select_frame (frame); | |
5528 | else | |
5529 | within_current_scope = 0; | |
18a18393 | 5530 | } |
7d4df6a4 DE |
5531 | if (within_current_scope) |
5532 | value_is_zero | |
5533 | = catch_errors (breakpoint_cond_eval, cond, | |
5534 | "Error in testing breakpoint condition:\n", | |
5535 | RETURN_MASK_ALL); | |
5536 | else | |
18a18393 | 5537 | { |
7d4df6a4 DE |
5538 | warning (_("Watchpoint condition cannot be tested " |
5539 | "in the current scope")); | |
5540 | /* If we failed to set the right context for this | |
5541 | watchpoint, unconditionally report it. */ | |
5542 | value_is_zero = 0; | |
18a18393 | 5543 | } |
7d4df6a4 DE |
5544 | /* FIXME-someday, should give breakpoint #. */ |
5545 | value_free_to_mark (mark); | |
18a18393 | 5546 | } |
7d4df6a4 DE |
5547 | |
5548 | if (cond && value_is_zero) | |
5549 | { | |
5550 | bs->stop = 0; | |
5551 | } | |
7d4df6a4 DE |
5552 | else if (b->ignore_count > 0) |
5553 | { | |
5554 | b->ignore_count--; | |
5555 | bs->stop = 0; | |
5556 | /* Increase the hit count even though we don't stop. */ | |
5557 | ++(b->hit_count); | |
5558 | observer_notify_breakpoint_modified (b); | |
5559 | } | |
18a18393 VP |
5560 | } |
5561 | ||
1cf4d951 PA |
5562 | /* Returns true if we need to track moribund locations of LOC's type |
5563 | on the current target. */ | |
5564 | ||
5565 | static int | |
5566 | need_moribund_for_location_type (struct bp_location *loc) | |
5567 | { | |
5568 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5569 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5570 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5571 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5572 | } | |
5573 | ||
18a18393 | 5574 | |
9709f61c | 5575 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5576 | BP_ADDR in thread PTID. |
c906108c | 5577 | |
d983da9c | 5578 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5579 | don't understand this stop. Result is a chain of bpstat's such |
5580 | that: | |
c906108c | 5581 | |
c5aa993b | 5582 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5583 | |
c5aa993b | 5584 | if we understand why we stopped, the result is not null. |
c906108c | 5585 | |
c5aa993b JM |
5586 | Each element of the chain refers to a particular breakpoint or |
5587 | watchpoint at which we have stopped. (We may have stopped for | |
5588 | several reasons concurrently.) | |
c906108c | 5589 | |
c5aa993b JM |
5590 | Each element of the chain has valid next, breakpoint_at, |
5591 | commands, FIXME??? fields. */ | |
c906108c SS |
5592 | |
5593 | bpstat | |
6c95b8df | 5594 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5595 | CORE_ADDR bp_addr, ptid_t ptid, |
5596 | const struct target_waitstatus *ws) | |
c906108c | 5597 | { |
0d381245 | 5598 | struct breakpoint *b = NULL; |
afe38095 | 5599 | struct bp_location *bl; |
20874c92 | 5600 | struct bp_location *loc; |
5760d0ab JK |
5601 | /* First item of allocated bpstat's. */ |
5602 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5603 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5604 | bpstat bs; |
20874c92 | 5605 | int ix; |
429374b8 | 5606 | int need_remove_insert; |
f431efe5 | 5607 | int removed_any; |
c906108c | 5608 | |
f431efe5 PA |
5609 | /* First, build the bpstat chain with locations that explain a |
5610 | target stop, while being careful to not set the target running, | |
5611 | as that may invalidate locations (in particular watchpoint | |
5612 | locations are recreated). Resuming will happen here with | |
5613 | breakpoint conditions or watchpoint expressions that include | |
5614 | inferior function calls. */ | |
c5aa993b | 5615 | |
429374b8 JK |
5616 | ALL_BREAKPOINTS (b) |
5617 | { | |
1a853c52 | 5618 | if (!breakpoint_enabled (b)) |
429374b8 | 5619 | continue; |
a5606eee | 5620 | |
429374b8 JK |
5621 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5622 | { | |
4a64f543 MS |
5623 | /* For hardware watchpoints, we look only at the first |
5624 | location. The watchpoint_check function will work on the | |
5625 | entire expression, not the individual locations. For | |
5626 | read watchpoints, the watchpoints_triggered function has | |
5627 | checked all locations already. */ | |
429374b8 JK |
5628 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5629 | break; | |
18a18393 | 5630 | |
f6592439 | 5631 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5632 | continue; |
c5aa993b | 5633 | |
09ac7c10 | 5634 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5635 | continue; |
c5aa993b | 5636 | |
4a64f543 MS |
5637 | /* Come here if it's a watchpoint, or if the break address |
5638 | matches. */ | |
c5aa993b | 5639 | |
04afa70c | 5640 | bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
4a64f543 | 5641 | explain stop. */ |
c5aa993b | 5642 | |
f431efe5 PA |
5643 | /* Assume we stop. Should we find a watchpoint that is not |
5644 | actually triggered, or if the condition of the breakpoint | |
5645 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5646 | bs->stop = 1; |
5647 | bs->print = 1; | |
d983da9c | 5648 | |
f431efe5 PA |
5649 | /* If this is a scope breakpoint, mark the associated |
5650 | watchpoint as triggered so that we will handle the | |
5651 | out-of-scope event. We'll get to the watchpoint next | |
5652 | iteration. */ | |
d0fb5eae | 5653 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5654 | { |
5655 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5656 | ||
5657 | w->watchpoint_triggered = watch_triggered_yes; | |
5658 | } | |
f431efe5 PA |
5659 | } |
5660 | } | |
5661 | ||
7c16b83e | 5662 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5663 | if (!target_supports_stopped_by_sw_breakpoint () |
5664 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5665 | { |
1cf4d951 | 5666 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5667 | { |
1cf4d951 PA |
5668 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5669 | && need_moribund_for_location_type (loc)) | |
5670 | { | |
04afa70c | 5671 | bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5672 | /* For hits of moribund locations, we should just proceed. */ |
5673 | bs->stop = 0; | |
5674 | bs->print = 0; | |
5675 | bs->print_it = print_it_noop; | |
5676 | } | |
f431efe5 PA |
5677 | } |
5678 | } | |
5679 | ||
edcc5120 TT |
5680 | /* A bit of special processing for shlib breakpoints. We need to |
5681 | process solib loading here, so that the lists of loaded and | |
5682 | unloaded libraries are correct before we handle "catch load" and | |
5683 | "catch unload". */ | |
5684 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5685 | { | |
5d268276 | 5686 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5687 | { |
5688 | handle_solib_event (); | |
5689 | break; | |
5690 | } | |
5691 | } | |
5692 | ||
f431efe5 PA |
5693 | /* Now go through the locations that caused the target to stop, and |
5694 | check whether we're interested in reporting this stop to higher | |
5695 | layers, or whether we should resume the target transparently. */ | |
5696 | ||
5697 | removed_any = 0; | |
5698 | ||
5760d0ab | 5699 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5700 | { |
5701 | if (!bs->stop) | |
5702 | continue; | |
5703 | ||
f431efe5 | 5704 | b = bs->breakpoint_at; |
348d480f PA |
5705 | b->ops->check_status (bs); |
5706 | if (bs->stop) | |
28010a5d | 5707 | { |
348d480f | 5708 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5709 | |
429374b8 JK |
5710 | if (bs->stop) |
5711 | { | |
5712 | ++(b->hit_count); | |
8d3788bd | 5713 | observer_notify_breakpoint_modified (b); |
c906108c | 5714 | |
4a64f543 | 5715 | /* We will stop here. */ |
429374b8 JK |
5716 | if (b->disposition == disp_disable) |
5717 | { | |
816338b5 | 5718 | --(b->enable_count); |
1a853c52 | 5719 | if (b->enable_count <= 0) |
429374b8 | 5720 | b->enable_state = bp_disabled; |
f431efe5 | 5721 | removed_any = 1; |
429374b8 JK |
5722 | } |
5723 | if (b->silent) | |
5724 | bs->print = 0; | |
5725 | bs->commands = b->commands; | |
9add0f1b | 5726 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5727 | if (command_line_is_silent (bs->commands |
5728 | ? bs->commands->commands : NULL)) | |
5729 | bs->print = 0; | |
9d6e6e84 HZ |
5730 | |
5731 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5732 | } |
5733 | ||
348d480f | 5734 | } |
a9b3a50f PA |
5735 | |
5736 | /* Print nothing for this entry if we don't stop or don't | |
5737 | print. */ | |
5738 | if (!bs->stop || !bs->print) | |
5739 | bs->print_it = print_it_noop; | |
429374b8 | 5740 | } |
876fa593 | 5741 | |
d983da9c DJ |
5742 | /* If we aren't stopping, the value of some hardware watchpoint may |
5743 | not have changed, but the intermediate memory locations we are | |
5744 | watching may have. Don't bother if we're stopping; this will get | |
5745 | done later. */ | |
d832cb68 | 5746 | need_remove_insert = 0; |
5760d0ab JK |
5747 | if (! bpstat_causes_stop (bs_head)) |
5748 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5749 | if (!bs->stop |
f431efe5 PA |
5750 | && bs->breakpoint_at |
5751 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5752 | { |
3a5c3e22 PA |
5753 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5754 | ||
5755 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5756 | need_remove_insert = 1; |
d983da9c DJ |
5757 | } |
5758 | ||
d832cb68 | 5759 | if (need_remove_insert) |
44702360 | 5760 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5761 | else if (removed_any) |
44702360 | 5762 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5763 | |
5760d0ab | 5764 | return bs_head; |
c906108c | 5765 | } |
628fe4e4 JK |
5766 | |
5767 | static void | |
5768 | handle_jit_event (void) | |
5769 | { | |
5770 | struct frame_info *frame; | |
5771 | struct gdbarch *gdbarch; | |
5772 | ||
243a9253 PA |
5773 | if (debug_infrun) |
5774 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5775 | ||
628fe4e4 JK |
5776 | /* Switch terminal for any messages produced by |
5777 | breakpoint_re_set. */ | |
223ffa71 | 5778 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5779 | |
5780 | frame = get_current_frame (); | |
5781 | gdbarch = get_frame_arch (frame); | |
5782 | ||
5783 | jit_event_handler (gdbarch); | |
5784 | ||
223ffa71 | 5785 | target_terminal::inferior (); |
628fe4e4 JK |
5786 | } |
5787 | ||
5788 | /* Prepare WHAT final decision for infrun. */ | |
5789 | ||
5790 | /* Decide what infrun needs to do with this bpstat. */ | |
5791 | ||
c906108c | 5792 | struct bpstat_what |
0e30163f | 5793 | bpstat_what (bpstat bs_head) |
c906108c | 5794 | { |
c906108c | 5795 | struct bpstat_what retval; |
0e30163f | 5796 | bpstat bs; |
c906108c | 5797 | |
628fe4e4 | 5798 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5799 | retval.call_dummy = STOP_NONE; |
186c406b | 5800 | retval.is_longjmp = 0; |
628fe4e4 | 5801 | |
0e30163f | 5802 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5803 | { |
628fe4e4 JK |
5804 | /* Extract this BS's action. After processing each BS, we check |
5805 | if its action overrides all we've seem so far. */ | |
5806 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5807 | enum bptype bptype; | |
5808 | ||
c906108c | 5809 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5810 | { |
5811 | /* I suspect this can happen if it was a momentary | |
5812 | breakpoint which has since been deleted. */ | |
5813 | bptype = bp_none; | |
5814 | } | |
20874c92 | 5815 | else |
f431efe5 | 5816 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5817 | |
5818 | switch (bptype) | |
c906108c SS |
5819 | { |
5820 | case bp_none: | |
628fe4e4 | 5821 | break; |
c906108c SS |
5822 | case bp_breakpoint: |
5823 | case bp_hardware_breakpoint: | |
7c16b83e | 5824 | case bp_single_step: |
c906108c SS |
5825 | case bp_until: |
5826 | case bp_finish: | |
a9b3a50f | 5827 | case bp_shlib_event: |
c906108c SS |
5828 | if (bs->stop) |
5829 | { | |
5830 | if (bs->print) | |
628fe4e4 | 5831 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5832 | else |
628fe4e4 | 5833 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5834 | } |
5835 | else | |
628fe4e4 | 5836 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5837 | break; |
5838 | case bp_watchpoint: | |
5839 | case bp_hardware_watchpoint: | |
5840 | case bp_read_watchpoint: | |
5841 | case bp_access_watchpoint: | |
5842 | if (bs->stop) | |
5843 | { | |
5844 | if (bs->print) | |
628fe4e4 | 5845 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5846 | else |
628fe4e4 | 5847 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5848 | } |
5849 | else | |
628fe4e4 JK |
5850 | { |
5851 | /* There was a watchpoint, but we're not stopping. | |
5852 | This requires no further action. */ | |
5853 | } | |
c906108c SS |
5854 | break; |
5855 | case bp_longjmp: | |
e2e4d78b | 5856 | case bp_longjmp_call_dummy: |
186c406b | 5857 | case bp_exception: |
0a39bb32 PA |
5858 | if (bs->stop) |
5859 | { | |
5860 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5861 | retval.is_longjmp = bptype != bp_exception; | |
5862 | } | |
5863 | else | |
5864 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5865 | break; |
5866 | case bp_longjmp_resume: | |
186c406b | 5867 | case bp_exception_resume: |
0a39bb32 PA |
5868 | if (bs->stop) |
5869 | { | |
5870 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5871 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5872 | } | |
5873 | else | |
5874 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5875 | break; |
5876 | case bp_step_resume: | |
5877 | if (bs->stop) | |
628fe4e4 JK |
5878 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5879 | else | |
c906108c | 5880 | { |
628fe4e4 JK |
5881 | /* It is for the wrong frame. */ |
5882 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5883 | } |
c906108c | 5884 | break; |
2c03e5be PA |
5885 | case bp_hp_step_resume: |
5886 | if (bs->stop) | |
5887 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5888 | else | |
5889 | { | |
5890 | /* It is for the wrong frame. */ | |
5891 | this_action = BPSTAT_WHAT_SINGLE; | |
5892 | } | |
5893 | break; | |
c906108c | 5894 | case bp_watchpoint_scope: |
c4093a6a | 5895 | case bp_thread_event: |
1900040c | 5896 | case bp_overlay_event: |
0fd8e87f | 5897 | case bp_longjmp_master: |
aa7d318d | 5898 | case bp_std_terminate_master: |
186c406b | 5899 | case bp_exception_master: |
628fe4e4 | 5900 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5901 | break; |
ce78b96d | 5902 | case bp_catchpoint: |
c5aa993b JM |
5903 | if (bs->stop) |
5904 | { | |
5905 | if (bs->print) | |
628fe4e4 | 5906 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5907 | else |
628fe4e4 | 5908 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5909 | } |
5910 | else | |
628fe4e4 JK |
5911 | { |
5912 | /* There was a catchpoint, but we're not stopping. | |
5913 | This requires no further action. */ | |
5914 | } | |
5915 | break; | |
628fe4e4 | 5916 | case bp_jit_event: |
628fe4e4 | 5917 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5918 | break; |
c906108c | 5919 | case bp_call_dummy: |
53a5351d JM |
5920 | /* Make sure the action is stop (silent or noisy), |
5921 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5922 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5923 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5924 | break; |
5925 | case bp_std_terminate: | |
5926 | /* Make sure the action is stop (silent or noisy), | |
5927 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5928 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5929 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5930 | break; |
1042e4c0 | 5931 | case bp_tracepoint: |
7a697b8d | 5932 | case bp_fast_tracepoint: |
0fb4aa4b | 5933 | case bp_static_tracepoint: |
1042e4c0 SS |
5934 | /* Tracepoint hits should not be reported back to GDB, and |
5935 | if one got through somehow, it should have been filtered | |
5936 | out already. */ | |
5937 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5938 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5939 | break; |
5940 | case bp_gnu_ifunc_resolver: | |
5941 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5942 | this_action = BPSTAT_WHAT_SINGLE; | |
5943 | break; | |
5944 | case bp_gnu_ifunc_resolver_return: | |
5945 | /* The breakpoint will be removed, execution will restart from the | |
5946 | PC of the former breakpoint. */ | |
5947 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5948 | break; | |
e7e0cddf SS |
5949 | |
5950 | case bp_dprintf: | |
a11cfd87 HZ |
5951 | if (bs->stop) |
5952 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5953 | else | |
5954 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5955 | break; |
5956 | ||
628fe4e4 JK |
5957 | default: |
5958 | internal_error (__FILE__, __LINE__, | |
5959 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5960 | } |
628fe4e4 | 5961 | |
325fac50 | 5962 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5963 | } |
628fe4e4 | 5964 | |
243a9253 PA |
5965 | return retval; |
5966 | } | |
628fe4e4 | 5967 | |
243a9253 PA |
5968 | void |
5969 | bpstat_run_callbacks (bpstat bs_head) | |
5970 | { | |
5971 | bpstat bs; | |
628fe4e4 | 5972 | |
0e30163f JK |
5973 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5974 | { | |
5975 | struct breakpoint *b = bs->breakpoint_at; | |
5976 | ||
5977 | if (b == NULL) | |
5978 | continue; | |
5979 | switch (b->type) | |
5980 | { | |
243a9253 PA |
5981 | case bp_jit_event: |
5982 | handle_jit_event (); | |
5983 | break; | |
0e30163f JK |
5984 | case bp_gnu_ifunc_resolver: |
5985 | gnu_ifunc_resolver_stop (b); | |
5986 | break; | |
5987 | case bp_gnu_ifunc_resolver_return: | |
5988 | gnu_ifunc_resolver_return_stop (b); | |
5989 | break; | |
5990 | } | |
5991 | } | |
c906108c SS |
5992 | } |
5993 | ||
5994 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5995 | without hardware support). This isn't related to a specific bpstat, | |
5996 | just to things like whether watchpoints are set. */ | |
5997 | ||
c5aa993b | 5998 | int |
fba45db2 | 5999 | bpstat_should_step (void) |
c906108c SS |
6000 | { |
6001 | struct breakpoint *b; | |
cc59ec59 | 6002 | |
c906108c | 6003 | ALL_BREAKPOINTS (b) |
717a8278 | 6004 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6005 | return 1; |
c906108c SS |
6006 | return 0; |
6007 | } | |
6008 | ||
67822962 PA |
6009 | int |
6010 | bpstat_causes_stop (bpstat bs) | |
6011 | { | |
6012 | for (; bs != NULL; bs = bs->next) | |
6013 | if (bs->stop) | |
6014 | return 1; | |
6015 | ||
6016 | return 0; | |
6017 | } | |
6018 | ||
c906108c | 6019 | \f |
c5aa993b | 6020 | |
170b53b2 UW |
6021 | /* Compute a string of spaces suitable to indent the next line |
6022 | so it starts at the position corresponding to the table column | |
6023 | named COL_NAME in the currently active table of UIOUT. */ | |
6024 | ||
6025 | static char * | |
6026 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6027 | { | |
6028 | static char wrap_indent[80]; | |
6029 | int i, total_width, width, align; | |
c5209615 | 6030 | const char *text; |
170b53b2 UW |
6031 | |
6032 | total_width = 0; | |
112e8700 | 6033 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
6034 | { |
6035 | if (strcmp (text, col_name) == 0) | |
6036 | { | |
6037 | gdb_assert (total_width < sizeof wrap_indent); | |
6038 | memset (wrap_indent, ' ', total_width); | |
6039 | wrap_indent[total_width] = 0; | |
6040 | ||
6041 | return wrap_indent; | |
6042 | } | |
6043 | ||
6044 | total_width += width + 1; | |
6045 | } | |
6046 | ||
6047 | return NULL; | |
6048 | } | |
6049 | ||
b775012e LM |
6050 | /* Determine if the locations of this breakpoint will have their conditions |
6051 | evaluated by the target, host or a mix of both. Returns the following: | |
6052 | ||
6053 | "host": Host evals condition. | |
6054 | "host or target": Host or Target evals condition. | |
6055 | "target": Target evals condition. | |
6056 | */ | |
6057 | ||
6058 | static const char * | |
6059 | bp_condition_evaluator (struct breakpoint *b) | |
6060 | { | |
6061 | struct bp_location *bl; | |
6062 | char host_evals = 0; | |
6063 | char target_evals = 0; | |
6064 | ||
6065 | if (!b) | |
6066 | return NULL; | |
6067 | ||
6068 | if (!is_breakpoint (b)) | |
6069 | return NULL; | |
6070 | ||
6071 | if (gdb_evaluates_breakpoint_condition_p () | |
6072 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6073 | return condition_evaluation_host; | |
6074 | ||
6075 | for (bl = b->loc; bl; bl = bl->next) | |
6076 | { | |
6077 | if (bl->cond_bytecode) | |
6078 | target_evals++; | |
6079 | else | |
6080 | host_evals++; | |
6081 | } | |
6082 | ||
6083 | if (host_evals && target_evals) | |
6084 | return condition_evaluation_both; | |
6085 | else if (target_evals) | |
6086 | return condition_evaluation_target; | |
6087 | else | |
6088 | return condition_evaluation_host; | |
6089 | } | |
6090 | ||
6091 | /* Determine the breakpoint location's condition evaluator. This is | |
6092 | similar to bp_condition_evaluator, but for locations. */ | |
6093 | ||
6094 | static const char * | |
6095 | bp_location_condition_evaluator (struct bp_location *bl) | |
6096 | { | |
6097 | if (bl && !is_breakpoint (bl->owner)) | |
6098 | return NULL; | |
6099 | ||
6100 | if (gdb_evaluates_breakpoint_condition_p () | |
6101 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6102 | return condition_evaluation_host; | |
6103 | ||
6104 | if (bl && bl->cond_bytecode) | |
6105 | return condition_evaluation_target; | |
6106 | else | |
6107 | return condition_evaluation_host; | |
6108 | } | |
6109 | ||
859825b8 JK |
6110 | /* Print the LOC location out of the list of B->LOC locations. */ |
6111 | ||
170b53b2 UW |
6112 | static void |
6113 | print_breakpoint_location (struct breakpoint *b, | |
6114 | struct bp_location *loc) | |
0d381245 | 6115 | { |
79a45e25 | 6116 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
6117 | |
6118 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 6119 | |
859825b8 JK |
6120 | if (loc != NULL && loc->shlib_disabled) |
6121 | loc = NULL; | |
6122 | ||
6c95b8df PA |
6123 | if (loc != NULL) |
6124 | set_current_program_space (loc->pspace); | |
6125 | ||
56435ebe | 6126 | if (b->display_canonical) |
d28cd78a | 6127 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 6128 | else if (loc && loc->symtab) |
0d381245 VP |
6129 | { |
6130 | struct symbol *sym | |
6131 | = find_pc_sect_function (loc->address, loc->section); | |
6132 | if (sym) | |
6133 | { | |
112e8700 SM |
6134 | uiout->text ("in "); |
6135 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); | |
6136 | uiout->text (" "); | |
6137 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
6138 | uiout->text ("at "); | |
0d381245 | 6139 | } |
112e8700 | 6140 | uiout->field_string ("file", |
05cba821 | 6141 | symtab_to_filename_for_display (loc->symtab)); |
112e8700 | 6142 | uiout->text (":"); |
05cba821 | 6143 | |
112e8700 SM |
6144 | if (uiout->is_mi_like_p ()) |
6145 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6146 | |
112e8700 | 6147 | uiout->field_int ("line", loc->line_number); |
0d381245 | 6148 | } |
859825b8 | 6149 | else if (loc) |
0d381245 | 6150 | { |
d7e74731 | 6151 | string_file stb; |
170b53b2 | 6152 | |
d7e74731 | 6153 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6154 | demangle, ""); |
112e8700 | 6155 | uiout->field_stream ("at", stb); |
0d381245 | 6156 | } |
859825b8 | 6157 | else |
f00aae0f | 6158 | { |
d28cd78a TT |
6159 | uiout->field_string ("pending", |
6160 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
6161 | /* If extra_string is available, it could be holding a condition |
6162 | or dprintf arguments. In either case, make sure it is printed, | |
6163 | too, but only for non-MI streams. */ | |
112e8700 | 6164 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6165 | { |
6166 | if (b->type == bp_dprintf) | |
112e8700 | 6167 | uiout->text (","); |
f00aae0f | 6168 | else |
112e8700 SM |
6169 | uiout->text (" "); |
6170 | uiout->text (b->extra_string); | |
f00aae0f KS |
6171 | } |
6172 | } | |
6c95b8df | 6173 | |
b775012e LM |
6174 | if (loc && is_breakpoint (b) |
6175 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6176 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6177 | { | |
112e8700 SM |
6178 | uiout->text (" ("); |
6179 | uiout->field_string ("evaluated-by", | |
b775012e | 6180 | bp_location_condition_evaluator (loc)); |
112e8700 | 6181 | uiout->text (")"); |
b775012e | 6182 | } |
0d381245 VP |
6183 | } |
6184 | ||
269b11a2 PA |
6185 | static const char * |
6186 | bptype_string (enum bptype type) | |
c906108c | 6187 | { |
c4093a6a JM |
6188 | struct ep_type_description |
6189 | { | |
6190 | enum bptype type; | |
a121b7c1 | 6191 | const char *description; |
c4093a6a JM |
6192 | }; |
6193 | static struct ep_type_description bptypes[] = | |
c906108c | 6194 | { |
c5aa993b JM |
6195 | {bp_none, "?deleted?"}, |
6196 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6197 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6198 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6199 | {bp_until, "until"}, |
6200 | {bp_finish, "finish"}, | |
6201 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6202 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6203 | {bp_read_watchpoint, "read watchpoint"}, |
6204 | {bp_access_watchpoint, "acc watchpoint"}, | |
6205 | {bp_longjmp, "longjmp"}, | |
6206 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6207 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6208 | {bp_exception, "exception"}, |
6209 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6210 | {bp_step_resume, "step resume"}, |
2c03e5be | 6211 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6212 | {bp_watchpoint_scope, "watchpoint scope"}, |
6213 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6214 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6215 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6216 | {bp_thread_event, "thread events"}, |
1900040c | 6217 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6218 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6219 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6220 | {bp_exception_master, "exception master"}, |
ce78b96d | 6221 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6222 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6223 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6224 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6225 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6226 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6227 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6228 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6229 | }; |
269b11a2 PA |
6230 | |
6231 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6232 | || ((int) type != bptypes[(int) type].type)) | |
6233 | internal_error (__FILE__, __LINE__, | |
6234 | _("bptypes table does not describe type #%d."), | |
6235 | (int) type); | |
6236 | ||
6237 | return bptypes[(int) type].description; | |
6238 | } | |
6239 | ||
998580f1 MK |
6240 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6241 | For CLI, prefix the list with the string 'inf'. */ | |
6242 | ||
6243 | static void | |
6244 | output_thread_groups (struct ui_out *uiout, | |
6245 | const char *field_name, | |
6246 | VEC(int) *inf_num, | |
6247 | int mi_only) | |
6248 | { | |
112e8700 | 6249 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6250 | int inf; |
6251 | int i; | |
6252 | ||
6253 | /* For backward compatibility, don't display inferiors in CLI unless | |
6254 | there are several. Always display them for MI. */ | |
6255 | if (!is_mi && mi_only) | |
6256 | return; | |
6257 | ||
10f489e5 | 6258 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6259 | |
998580f1 MK |
6260 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6261 | { | |
6262 | if (is_mi) | |
6263 | { | |
6264 | char mi_group[10]; | |
6265 | ||
6266 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
112e8700 | 6267 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6268 | } |
6269 | else | |
6270 | { | |
6271 | if (i == 0) | |
112e8700 | 6272 | uiout->text (" inf "); |
998580f1 | 6273 | else |
112e8700 | 6274 | uiout->text (", "); |
998580f1 | 6275 | |
112e8700 | 6276 | uiout->text (plongest (inf)); |
998580f1 MK |
6277 | } |
6278 | } | |
998580f1 MK |
6279 | } |
6280 | ||
269b11a2 PA |
6281 | /* Print B to gdb_stdout. */ |
6282 | ||
6283 | static void | |
6284 | print_one_breakpoint_location (struct breakpoint *b, | |
6285 | struct bp_location *loc, | |
6286 | int loc_number, | |
6287 | struct bp_location **last_loc, | |
269b11a2 PA |
6288 | int allflag) |
6289 | { | |
6290 | struct command_line *l; | |
c2c6d25f | 6291 | static char bpenables[] = "nynny"; |
c906108c | 6292 | |
79a45e25 | 6293 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6294 | int header_of_multiple = 0; |
6295 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6296 | struct value_print_options opts; |
6297 | ||
6298 | get_user_print_options (&opts); | |
0d381245 VP |
6299 | |
6300 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6301 | /* See comment in print_one_breakpoint concerning treatment of |
6302 | breakpoints with single disabled location. */ | |
0d381245 VP |
6303 | if (loc == NULL |
6304 | && (b->loc != NULL | |
6305 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6306 | header_of_multiple = 1; | |
6307 | if (loc == NULL) | |
6308 | loc = b->loc; | |
6309 | ||
c4093a6a JM |
6310 | annotate_record (); |
6311 | ||
6312 | /* 1 */ | |
6313 | annotate_field (0); | |
0d381245 VP |
6314 | if (part_of_multiple) |
6315 | { | |
6316 | char *formatted; | |
0c6773c1 | 6317 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
112e8700 | 6318 | uiout->field_string ("number", formatted); |
0d381245 VP |
6319 | xfree (formatted); |
6320 | } | |
6321 | else | |
6322 | { | |
112e8700 | 6323 | uiout->field_int ("number", b->number); |
0d381245 | 6324 | } |
c4093a6a JM |
6325 | |
6326 | /* 2 */ | |
6327 | annotate_field (1); | |
0d381245 | 6328 | if (part_of_multiple) |
112e8700 | 6329 | uiout->field_skip ("type"); |
269b11a2 | 6330 | else |
112e8700 | 6331 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6332 | |
6333 | /* 3 */ | |
6334 | annotate_field (2); | |
0d381245 | 6335 | if (part_of_multiple) |
112e8700 | 6336 | uiout->field_skip ("disp"); |
0d381245 | 6337 | else |
112e8700 | 6338 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6339 | |
c4093a6a JM |
6340 | |
6341 | /* 4 */ | |
6342 | annotate_field (3); | |
0d381245 | 6343 | if (part_of_multiple) |
112e8700 | 6344 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6345 | else |
112e8700 SM |
6346 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
6347 | uiout->spaces (2); | |
0d381245 | 6348 | |
c4093a6a JM |
6349 | |
6350 | /* 5 and 6 */ | |
3086aeae | 6351 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6352 | { |
4a64f543 MS |
6353 | /* Although the print_one can possibly print all locations, |
6354 | calling it here is not likely to get any nice result. So, | |
6355 | make sure there's just one location. */ | |
0d381245 | 6356 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6357 | b->ops->print_one (b, last_loc); |
0d381245 | 6358 | } |
3086aeae DJ |
6359 | else |
6360 | switch (b->type) | |
6361 | { | |
6362 | case bp_none: | |
6363 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6364 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6365 | break; |
c906108c | 6366 | |
3086aeae DJ |
6367 | case bp_watchpoint: |
6368 | case bp_hardware_watchpoint: | |
6369 | case bp_read_watchpoint: | |
6370 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6371 | { |
6372 | struct watchpoint *w = (struct watchpoint *) b; | |
6373 | ||
6374 | /* Field 4, the address, is omitted (which makes the columns | |
6375 | not line up too nicely with the headers, but the effect | |
6376 | is relatively readable). */ | |
6377 | if (opts.addressprint) | |
112e8700 | 6378 | uiout->field_skip ("addr"); |
3a5c3e22 | 6379 | annotate_field (5); |
112e8700 | 6380 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6381 | } |
3086aeae DJ |
6382 | break; |
6383 | ||
3086aeae DJ |
6384 | case bp_breakpoint: |
6385 | case bp_hardware_breakpoint: | |
7c16b83e | 6386 | case bp_single_step: |
3086aeae DJ |
6387 | case bp_until: |
6388 | case bp_finish: | |
6389 | case bp_longjmp: | |
6390 | case bp_longjmp_resume: | |
e2e4d78b | 6391 | case bp_longjmp_call_dummy: |
186c406b TT |
6392 | case bp_exception: |
6393 | case bp_exception_resume: | |
3086aeae | 6394 | case bp_step_resume: |
2c03e5be | 6395 | case bp_hp_step_resume: |
3086aeae DJ |
6396 | case bp_watchpoint_scope: |
6397 | case bp_call_dummy: | |
aa7d318d | 6398 | case bp_std_terminate: |
3086aeae DJ |
6399 | case bp_shlib_event: |
6400 | case bp_thread_event: | |
6401 | case bp_overlay_event: | |
0fd8e87f | 6402 | case bp_longjmp_master: |
aa7d318d | 6403 | case bp_std_terminate_master: |
186c406b | 6404 | case bp_exception_master: |
1042e4c0 | 6405 | case bp_tracepoint: |
7a697b8d | 6406 | case bp_fast_tracepoint: |
0fb4aa4b | 6407 | case bp_static_tracepoint: |
e7e0cddf | 6408 | case bp_dprintf: |
4efc6507 | 6409 | case bp_jit_event: |
0e30163f JK |
6410 | case bp_gnu_ifunc_resolver: |
6411 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6412 | if (opts.addressprint) |
3086aeae DJ |
6413 | { |
6414 | annotate_field (4); | |
54e52265 | 6415 | if (header_of_multiple) |
112e8700 | 6416 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6417 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6418 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6419 | else |
112e8700 | 6420 | uiout->field_core_addr ("addr", |
5af949e3 | 6421 | loc->gdbarch, loc->address); |
3086aeae DJ |
6422 | } |
6423 | annotate_field (5); | |
0d381245 | 6424 | if (!header_of_multiple) |
170b53b2 | 6425 | print_breakpoint_location (b, loc); |
0d381245 | 6426 | if (b->loc) |
a6d9a66e | 6427 | *last_loc = b->loc; |
3086aeae DJ |
6428 | break; |
6429 | } | |
c906108c | 6430 | |
6c95b8df | 6431 | |
998580f1 | 6432 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6433 | { |
6434 | struct inferior *inf; | |
998580f1 MK |
6435 | VEC(int) *inf_num = NULL; |
6436 | int mi_only = 1; | |
6c95b8df | 6437 | |
998580f1 | 6438 | ALL_INFERIORS (inf) |
6c95b8df PA |
6439 | { |
6440 | if (inf->pspace == loc->pspace) | |
998580f1 | 6441 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6442 | } |
998580f1 MK |
6443 | |
6444 | /* For backward compatibility, don't display inferiors in CLI unless | |
6445 | there are several. Always display for MI. */ | |
6446 | if (allflag | |
6447 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6448 | && (number_of_program_spaces () > 1 | |
6449 | || number_of_inferiors () > 1) | |
6450 | /* LOC is for existing B, it cannot be in | |
6451 | moribund_locations and thus having NULL OWNER. */ | |
6452 | && loc->owner->type != bp_catchpoint)) | |
6453 | mi_only = 0; | |
6454 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6455 | VEC_free (int, inf_num); | |
6c95b8df PA |
6456 | } |
6457 | ||
4a306c9a | 6458 | if (!part_of_multiple) |
c4093a6a | 6459 | { |
4a306c9a JB |
6460 | if (b->thread != -1) |
6461 | { | |
6462 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6463 | "stop only in" line a little further down. */ |
112e8700 SM |
6464 | uiout->text (" thread "); |
6465 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6466 | } |
6467 | else if (b->task != 0) | |
6468 | { | |
112e8700 SM |
6469 | uiout->text (" task "); |
6470 | uiout->field_int ("task", b->task); | |
4a306c9a | 6471 | } |
c4093a6a | 6472 | } |
f1310107 | 6473 | |
112e8700 | 6474 | uiout->text ("\n"); |
f1310107 | 6475 | |
348d480f | 6476 | if (!part_of_multiple) |
f1310107 TJB |
6477 | b->ops->print_one_detail (b, uiout); |
6478 | ||
0d381245 | 6479 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6480 | { |
6481 | annotate_field (6); | |
112e8700 | 6482 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6483 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6484 | the frame ID. */ |
112e8700 | 6485 | uiout->field_core_addr ("frame", |
5af949e3 | 6486 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6487 | uiout->text ("\n"); |
c4093a6a JM |
6488 | } |
6489 | ||
28010a5d | 6490 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6491 | { |
6492 | annotate_field (7); | |
d77f58be | 6493 | if (is_tracepoint (b)) |
112e8700 | 6494 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6495 | else |
112e8700 SM |
6496 | uiout->text ("\tstop only if "); |
6497 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6498 | |
6499 | /* Print whether the target is doing the breakpoint's condition | |
6500 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6501 | if (is_breakpoint (b) | |
6502 | && breakpoint_condition_evaluation_mode () | |
6503 | == condition_evaluation_target) | |
6504 | { | |
112e8700 SM |
6505 | uiout->text (" ("); |
6506 | uiout->field_string ("evaluated-by", | |
b775012e | 6507 | bp_condition_evaluator (b)); |
112e8700 | 6508 | uiout->text (" evals)"); |
b775012e | 6509 | } |
112e8700 | 6510 | uiout->text ("\n"); |
0101ce28 JJ |
6511 | } |
6512 | ||
0d381245 | 6513 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6514 | { |
4a64f543 | 6515 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6516 | uiout->text ("\tstop only in thread "); |
6517 | if (uiout->is_mi_like_p ()) | |
6518 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6519 | else |
6520 | { | |
6521 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6522 | ||
112e8700 | 6523 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6524 | } |
112e8700 | 6525 | uiout->text ("\n"); |
c4093a6a JM |
6526 | } |
6527 | ||
556ec64d YQ |
6528 | if (!part_of_multiple) |
6529 | { | |
6530 | if (b->hit_count) | |
31f56a27 YQ |
6531 | { |
6532 | /* FIXME should make an annotation for this. */ | |
6533 | if (is_catchpoint (b)) | |
112e8700 | 6534 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6535 | else if (is_tracepoint (b)) |
112e8700 | 6536 | uiout->text ("\ttracepoint"); |
31f56a27 | 6537 | else |
112e8700 SM |
6538 | uiout->text ("\tbreakpoint"); |
6539 | uiout->text (" already hit "); | |
6540 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6541 | if (b->hit_count == 1) |
112e8700 | 6542 | uiout->text (" time\n"); |
31f56a27 | 6543 | else |
112e8700 | 6544 | uiout->text (" times\n"); |
31f56a27 | 6545 | } |
556ec64d YQ |
6546 | else |
6547 | { | |
31f56a27 | 6548 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6549 | if (uiout->is_mi_like_p ()) |
6550 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6551 | } |
6552 | } | |
8b93c638 | 6553 | |
0d381245 | 6554 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6555 | { |
6556 | annotate_field (8); | |
112e8700 SM |
6557 | uiout->text ("\tignore next "); |
6558 | uiout->field_int ("ignore", b->ignore_count); | |
6559 | uiout->text (" hits\n"); | |
c4093a6a | 6560 | } |
059fb39f | 6561 | |
816338b5 SS |
6562 | /* Note that an enable count of 1 corresponds to "enable once" |
6563 | behavior, which is reported by the combination of enablement and | |
6564 | disposition, so we don't need to mention it here. */ | |
6565 | if (!part_of_multiple && b->enable_count > 1) | |
6566 | { | |
6567 | annotate_field (8); | |
112e8700 | 6568 | uiout->text ("\tdisable after "); |
816338b5 SS |
6569 | /* Tweak the wording to clarify that ignore and enable counts |
6570 | are distinct, and have additive effect. */ | |
6571 | if (b->ignore_count) | |
112e8700 | 6572 | uiout->text ("additional "); |
816338b5 | 6573 | else |
112e8700 SM |
6574 | uiout->text ("next "); |
6575 | uiout->field_int ("enable", b->enable_count); | |
6576 | uiout->text (" hits\n"); | |
816338b5 SS |
6577 | } |
6578 | ||
f196051f SS |
6579 | if (!part_of_multiple && is_tracepoint (b)) |
6580 | { | |
6581 | struct tracepoint *tp = (struct tracepoint *) b; | |
6582 | ||
6583 | if (tp->traceframe_usage) | |
6584 | { | |
112e8700 SM |
6585 | uiout->text ("\ttrace buffer usage "); |
6586 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6587 | uiout->text (" bytes\n"); | |
f196051f SS |
6588 | } |
6589 | } | |
d3ce09f5 | 6590 | |
9add0f1b | 6591 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6592 | if (!part_of_multiple && l) |
c4093a6a JM |
6593 | { |
6594 | annotate_field (9); | |
2e783024 | 6595 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6596 | print_command_lines (uiout, l, 4); |
c4093a6a | 6597 | } |
d24317b4 | 6598 | |
d9b3f62e | 6599 | if (is_tracepoint (b)) |
1042e4c0 | 6600 | { |
d9b3f62e PA |
6601 | struct tracepoint *t = (struct tracepoint *) b; |
6602 | ||
6603 | if (!part_of_multiple && t->pass_count) | |
6604 | { | |
6605 | annotate_field (10); | |
112e8700 SM |
6606 | uiout->text ("\tpass count "); |
6607 | uiout->field_int ("pass", t->pass_count); | |
6608 | uiout->text (" \n"); | |
d9b3f62e | 6609 | } |
f2a8bc8a YQ |
6610 | |
6611 | /* Don't display it when tracepoint or tracepoint location is | |
6612 | pending. */ | |
6613 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6614 | { | |
6615 | annotate_field (11); | |
6616 | ||
112e8700 SM |
6617 | if (uiout->is_mi_like_p ()) |
6618 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6619 | loc->inserted ? "y" : "n"); |
6620 | else | |
6621 | { | |
6622 | if (loc->inserted) | |
112e8700 | 6623 | uiout->text ("\t"); |
f2a8bc8a | 6624 | else |
112e8700 SM |
6625 | uiout->text ("\tnot "); |
6626 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6627 | } |
6628 | } | |
1042e4c0 SS |
6629 | } |
6630 | ||
112e8700 | 6631 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6632 | { |
3a5c3e22 PA |
6633 | if (is_watchpoint (b)) |
6634 | { | |
6635 | struct watchpoint *w = (struct watchpoint *) b; | |
6636 | ||
112e8700 | 6637 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6638 | } |
f00aae0f | 6639 | else if (b->location != NULL |
d28cd78a | 6640 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6641 | uiout->field_string ("original-location", |
d28cd78a | 6642 | event_location_to_string (b->location.get ())); |
d24317b4 | 6643 | } |
c4093a6a | 6644 | } |
c5aa993b | 6645 | |
0d381245 VP |
6646 | static void |
6647 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6648 | struct bp_location **last_loc, |
6c95b8df | 6649 | int allflag) |
0d381245 | 6650 | { |
79a45e25 | 6651 | struct ui_out *uiout = current_uiout; |
8d3788bd | 6652 | |
2e783024 TT |
6653 | { |
6654 | ui_out_emit_tuple tuple_emitter (uiout, "bkpt"); | |
8d3788bd | 6655 | |
2e783024 TT |
6656 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
6657 | } | |
0d381245 VP |
6658 | |
6659 | /* If this breakpoint has custom print function, | |
6660 | it's already printed. Otherwise, print individual | |
6661 | locations, if any. */ | |
6662 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6663 | { | |
4a64f543 MS |
6664 | /* If breakpoint has a single location that is disabled, we |
6665 | print it as if it had several locations, since otherwise it's | |
6666 | hard to represent "breakpoint enabled, location disabled" | |
6667 | situation. | |
6668 | ||
6669 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6670 | internally, that's not a property exposed to user. */ |
0d381245 | 6671 | if (b->loc |
a5606eee | 6672 | && !is_hardware_watchpoint (b) |
8d3788bd | 6673 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6674 | { |
6675 | struct bp_location *loc; | |
6676 | int n = 1; | |
8d3788bd | 6677 | |
0d381245 | 6678 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd | 6679 | { |
2e783024 | 6680 | ui_out_emit_tuple tuple_emitter (uiout, NULL); |
8d3788bd | 6681 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
8d3788bd | 6682 | } |
0d381245 VP |
6683 | } |
6684 | } | |
6685 | } | |
6686 | ||
a6d9a66e UW |
6687 | static int |
6688 | breakpoint_address_bits (struct breakpoint *b) | |
6689 | { | |
6690 | int print_address_bits = 0; | |
6691 | struct bp_location *loc; | |
6692 | ||
c6d81124 PA |
6693 | /* Software watchpoints that aren't watching memory don't have an |
6694 | address to print. */ | |
6695 | if (is_no_memory_software_watchpoint (b)) | |
6696 | return 0; | |
6697 | ||
a6d9a66e UW |
6698 | for (loc = b->loc; loc; loc = loc->next) |
6699 | { | |
c7437ca6 PA |
6700 | int addr_bit; |
6701 | ||
c7437ca6 | 6702 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6703 | if (addr_bit > print_address_bits) |
6704 | print_address_bits = addr_bit; | |
6705 | } | |
6706 | ||
6707 | return print_address_bits; | |
6708 | } | |
0d381245 | 6709 | |
c4093a6a JM |
6710 | struct captured_breakpoint_query_args |
6711 | { | |
6712 | int bnum; | |
6713 | }; | |
c5aa993b | 6714 | |
c4093a6a | 6715 | static int |
2b65245e | 6716 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6717 | { |
9a3c8263 SM |
6718 | struct captured_breakpoint_query_args *args |
6719 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6720 | struct breakpoint *b; |
a6d9a66e | 6721 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6722 | |
c4093a6a JM |
6723 | ALL_BREAKPOINTS (b) |
6724 | { | |
6725 | if (args->bnum == b->number) | |
c5aa993b | 6726 | { |
12c5a436 | 6727 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6728 | return GDB_RC_OK; |
c5aa993b | 6729 | } |
c4093a6a JM |
6730 | } |
6731 | return GDB_RC_NONE; | |
6732 | } | |
c5aa993b | 6733 | |
c4093a6a | 6734 | enum gdb_rc |
4a64f543 MS |
6735 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6736 | char **error_message) | |
c4093a6a JM |
6737 | { |
6738 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6739 | |
c4093a6a JM |
6740 | args.bnum = bnum; |
6741 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6742 | an error. */ |
b0b13bb4 DJ |
6743 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6744 | error_message, RETURN_MASK_ALL) < 0) | |
6745 | return GDB_RC_FAIL; | |
6746 | else | |
6747 | return GDB_RC_OK; | |
c4093a6a | 6748 | } |
c5aa993b | 6749 | |
09d682a4 TT |
6750 | /* Return true if this breakpoint was set by the user, false if it is |
6751 | internal or momentary. */ | |
6752 | ||
6753 | int | |
6754 | user_breakpoint_p (struct breakpoint *b) | |
6755 | { | |
46c6471b | 6756 | return b->number > 0; |
09d682a4 TT |
6757 | } |
6758 | ||
93daf339 TT |
6759 | /* See breakpoint.h. */ |
6760 | ||
6761 | int | |
6762 | pending_breakpoint_p (struct breakpoint *b) | |
6763 | { | |
6764 | return b->loc == NULL; | |
6765 | } | |
6766 | ||
7f3b0473 | 6767 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6768 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6769 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6770 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6771 | ones for which it returns non-zero. Return the total number of | |
6772 | breakpoints listed. */ | |
c906108c | 6773 | |
d77f58be | 6774 | static int |
e5a67952 | 6775 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6776 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6777 | { |
52f0bd74 | 6778 | struct breakpoint *b; |
a6d9a66e | 6779 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6780 | int nr_printable_breakpoints; |
79a45b7d | 6781 | struct value_print_options opts; |
a6d9a66e | 6782 | int print_address_bits = 0; |
269b11a2 | 6783 | int print_type_col_width = 14; |
79a45e25 | 6784 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6785 | |
79a45b7d TT |
6786 | get_user_print_options (&opts); |
6787 | ||
4a64f543 MS |
6788 | /* Compute the number of rows in the table, as well as the size |
6789 | required for address fields. */ | |
7f3b0473 AC |
6790 | nr_printable_breakpoints = 0; |
6791 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6792 | { |
6793 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6794 | if (filter && !filter (b)) | |
6795 | continue; | |
6796 | ||
6797 | /* If we have an "args" string, it is a list of breakpoints to | |
6798 | accept. Skip the others. */ | |
6799 | if (args != NULL && *args != '\0') | |
6800 | { | |
6801 | if (allflag && parse_and_eval_long (args) != b->number) | |
6802 | continue; | |
6803 | if (!allflag && !number_is_in_list (args, b->number)) | |
6804 | continue; | |
6805 | } | |
269b11a2 | 6806 | |
e5a67952 MS |
6807 | if (allflag || user_breakpoint_p (b)) |
6808 | { | |
6809 | int addr_bit, type_len; | |
a6d9a66e | 6810 | |
e5a67952 MS |
6811 | addr_bit = breakpoint_address_bits (b); |
6812 | if (addr_bit > print_address_bits) | |
6813 | print_address_bits = addr_bit; | |
269b11a2 | 6814 | |
e5a67952 MS |
6815 | type_len = strlen (bptype_string (b->type)); |
6816 | if (type_len > print_type_col_width) | |
6817 | print_type_col_width = type_len; | |
6818 | ||
6819 | nr_printable_breakpoints++; | |
6820 | } | |
6821 | } | |
7f3b0473 | 6822 | |
4a2b031d TT |
6823 | { |
6824 | ui_out_emit_table table_emitter (uiout, | |
6825 | opts.addressprint ? 6 : 5, | |
6826 | nr_printable_breakpoints, | |
6827 | "BreakpointTable"); | |
6828 | ||
6829 | if (nr_printable_breakpoints > 0) | |
6830 | annotate_breakpoints_headers (); | |
6831 | if (nr_printable_breakpoints > 0) | |
6832 | annotate_field (0); | |
6833 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6834 | if (nr_printable_breakpoints > 0) | |
6835 | annotate_field (1); | |
6836 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6837 | if (nr_printable_breakpoints > 0) | |
6838 | annotate_field (2); | |
6839 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6840 | if (nr_printable_breakpoints > 0) | |
6841 | annotate_field (3); | |
6842 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6843 | if (opts.addressprint) | |
6844 | { | |
6845 | if (nr_printable_breakpoints > 0) | |
6846 | annotate_field (4); | |
6847 | if (print_address_bits <= 32) | |
6848 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6849 | else | |
6850 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6851 | } | |
6852 | if (nr_printable_breakpoints > 0) | |
6853 | annotate_field (5); | |
6854 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6855 | uiout->table_body (); | |
6856 | if (nr_printable_breakpoints > 0) | |
6857 | annotate_breakpoints_table (); | |
6858 | ||
6859 | ALL_BREAKPOINTS (b) | |
6860 | { | |
6861 | QUIT; | |
6862 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6863 | if (filter && !filter (b)) | |
6864 | continue; | |
e5a67952 | 6865 | |
4a2b031d TT |
6866 | /* If we have an "args" string, it is a list of breakpoints to |
6867 | accept. Skip the others. */ | |
e5a67952 | 6868 | |
4a2b031d TT |
6869 | if (args != NULL && *args != '\0') |
6870 | { | |
6871 | if (allflag) /* maintenance info breakpoint */ | |
6872 | { | |
6873 | if (parse_and_eval_long (args) != b->number) | |
6874 | continue; | |
6875 | } | |
6876 | else /* all others */ | |
6877 | { | |
6878 | if (!number_is_in_list (args, b->number)) | |
6879 | continue; | |
6880 | } | |
6881 | } | |
6882 | /* We only print out user settable breakpoints unless the | |
6883 | allflag is set. */ | |
6884 | if (allflag || user_breakpoint_p (b)) | |
6885 | print_one_breakpoint (b, &last_loc, allflag); | |
6886 | } | |
6887 | } | |
698384cd | 6888 | |
7f3b0473 | 6889 | if (nr_printable_breakpoints == 0) |
c906108c | 6890 | { |
4a64f543 MS |
6891 | /* If there's a filter, let the caller decide how to report |
6892 | empty list. */ | |
d77f58be SS |
6893 | if (!filter) |
6894 | { | |
e5a67952 | 6895 | if (args == NULL || *args == '\0') |
112e8700 | 6896 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6897 | else |
112e8700 | 6898 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6899 | args); |
d77f58be | 6900 | } |
c906108c SS |
6901 | } |
6902 | else | |
c4093a6a | 6903 | { |
a6d9a66e UW |
6904 | if (last_loc && !server_command) |
6905 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6906 | } |
c906108c | 6907 | |
4a64f543 | 6908 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6909 | there have been breakpoints? */ |
c906108c | 6910 | annotate_breakpoints_table_end (); |
d77f58be SS |
6911 | |
6912 | return nr_printable_breakpoints; | |
c906108c SS |
6913 | } |
6914 | ||
ad443146 SS |
6915 | /* Display the value of default-collect in a way that is generally |
6916 | compatible with the breakpoint list. */ | |
6917 | ||
6918 | static void | |
6919 | default_collect_info (void) | |
6920 | { | |
79a45e25 PA |
6921 | struct ui_out *uiout = current_uiout; |
6922 | ||
ad443146 SS |
6923 | /* If it has no value (which is frequently the case), say nothing; a |
6924 | message like "No default-collect." gets in user's face when it's | |
6925 | not wanted. */ | |
6926 | if (!*default_collect) | |
6927 | return; | |
6928 | ||
6929 | /* The following phrase lines up nicely with per-tracepoint collect | |
6930 | actions. */ | |
112e8700 SM |
6931 | uiout->text ("default collect "); |
6932 | uiout->field_string ("default-collect", default_collect); | |
6933 | uiout->text (" \n"); | |
ad443146 SS |
6934 | } |
6935 | ||
c906108c | 6936 | static void |
11db9430 | 6937 | info_breakpoints_command (char *args, int from_tty) |
c906108c | 6938 | { |
e5a67952 | 6939 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6940 | |
6941 | default_collect_info (); | |
d77f58be SS |
6942 | } |
6943 | ||
6944 | static void | |
11db9430 | 6945 | info_watchpoints_command (char *args, int from_tty) |
d77f58be | 6946 | { |
e5a67952 | 6947 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6948 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6949 | |
6950 | if (num_printed == 0) | |
6951 | { | |
e5a67952 | 6952 | if (args == NULL || *args == '\0') |
112e8700 | 6953 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6954 | else |
112e8700 | 6955 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6956 | } |
c906108c SS |
6957 | } |
6958 | ||
7a292a7a | 6959 | static void |
e5a67952 | 6960 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6961 | { |
e5a67952 | 6962 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6963 | |
6964 | default_collect_info (); | |
c906108c SS |
6965 | } |
6966 | ||
0d381245 | 6967 | static int |
714835d5 | 6968 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6969 | struct program_space *pspace, |
714835d5 | 6970 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6971 | { |
6972 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6973 | |
0d381245 VP |
6974 | for (; bl; bl = bl->next) |
6975 | { | |
6c95b8df PA |
6976 | if (bl->pspace == pspace |
6977 | && bl->address == pc | |
0d381245 VP |
6978 | && (!overlay_debugging || bl->section == section)) |
6979 | return 1; | |
6980 | } | |
6981 | return 0; | |
6982 | } | |
6983 | ||
672f9b60 | 6984 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6985 | concerns with logical breakpoints, so we match program spaces, not |
6986 | address spaces. */ | |
c906108c SS |
6987 | |
6988 | static void | |
6c95b8df PA |
6989 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6990 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6991 | struct obj_section *section, int thread) |
c906108c | 6992 | { |
52f0bd74 AC |
6993 | int others = 0; |
6994 | struct breakpoint *b; | |
c906108c SS |
6995 | |
6996 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6997 | others += (user_breakpoint_p (b) |
6998 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6999 | if (others > 0) |
7000 | { | |
a3f17187 AC |
7001 | if (others == 1) |
7002 | printf_filtered (_("Note: breakpoint ")); | |
7003 | else /* if (others == ???) */ | |
7004 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7005 | ALL_BREAKPOINTS (b) |
672f9b60 | 7006 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7007 | { |
7008 | others--; | |
7009 | printf_filtered ("%d", b->number); | |
7010 | if (b->thread == -1 && thread != -1) | |
7011 | printf_filtered (" (all threads)"); | |
7012 | else if (b->thread != -1) | |
7013 | printf_filtered (" (thread %d)", b->thread); | |
7014 | printf_filtered ("%s%s ", | |
059fb39f | 7015 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7016 | || b->enable_state == bp_call_disabled) |
0d381245 | 7017 | ? " (disabled)" |
0d381245 VP |
7018 | : ""), |
7019 | (others > 1) ? "," | |
7020 | : ((others == 1) ? " and" : "")); | |
7021 | } | |
a3f17187 | 7022 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7023 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7024 | printf_filtered (".\n"); |
7025 | } | |
7026 | } | |
7027 | \f | |
c906108c | 7028 | |
e4f237da | 7029 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7030 | BPT locations. For some breakpoint types, the locations' address members |
7031 | are irrelevant and it makes no sense to attempt to compare them to other | |
7032 | addresses (or use them for any other purpose either). | |
e4f237da | 7033 | |
4a64f543 | 7034 | More specifically, each of the following breakpoint types will |
244558af | 7035 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7036 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7037 | breakpoint location at address zero: |
e4f237da KB |
7038 | |
7039 | bp_watchpoint | |
2d134ed3 PA |
7040 | bp_catchpoint |
7041 | ||
7042 | */ | |
e4f237da KB |
7043 | |
7044 | static int | |
7045 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7046 | { | |
7047 | enum bptype type = bpt->type; | |
7048 | ||
2d134ed3 PA |
7049 | return (type != bp_watchpoint && type != bp_catchpoint); |
7050 | } | |
7051 | ||
7052 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7053 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7054 | ||
7055 | static int | |
4a64f543 MS |
7056 | watchpoint_locations_match (struct bp_location *loc1, |
7057 | struct bp_location *loc2) | |
2d134ed3 | 7058 | { |
3a5c3e22 PA |
7059 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7060 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7061 | ||
7062 | /* Both of them must exist. */ | |
7063 | gdb_assert (w1 != NULL); | |
7064 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7065 | |
4a64f543 MS |
7066 | /* If the target can evaluate the condition expression in hardware, |
7067 | then we we need to insert both watchpoints even if they are at | |
7068 | the same place. Otherwise the watchpoint will only trigger when | |
7069 | the condition of whichever watchpoint was inserted evaluates to | |
7070 | true, not giving a chance for GDB to check the condition of the | |
7071 | other watchpoint. */ | |
3a5c3e22 | 7072 | if ((w1->cond_exp |
4a64f543 MS |
7073 | && target_can_accel_watchpoint_condition (loc1->address, |
7074 | loc1->length, | |
0cf6dd15 | 7075 | loc1->watchpoint_type, |
4d01a485 | 7076 | w1->cond_exp.get ())) |
3a5c3e22 | 7077 | || (w2->cond_exp |
4a64f543 MS |
7078 | && target_can_accel_watchpoint_condition (loc2->address, |
7079 | loc2->length, | |
0cf6dd15 | 7080 | loc2->watchpoint_type, |
4d01a485 | 7081 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
7082 | return 0; |
7083 | ||
85d721b8 PA |
7084 | /* Note that this checks the owner's type, not the location's. In |
7085 | case the target does not support read watchpoints, but does | |
7086 | support access watchpoints, we'll have bp_read_watchpoint | |
7087 | watchpoints with hw_access locations. Those should be considered | |
7088 | duplicates of hw_read locations. The hw_read locations will | |
7089 | become hw_access locations later. */ | |
2d134ed3 PA |
7090 | return (loc1->owner->type == loc2->owner->type |
7091 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7092 | && loc1->address == loc2->address | |
7093 | && loc1->length == loc2->length); | |
e4f237da KB |
7094 | } |
7095 | ||
31e77af2 | 7096 | /* See breakpoint.h. */ |
6c95b8df | 7097 | |
31e77af2 | 7098 | int |
6c95b8df PA |
7099 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7100 | struct address_space *aspace2, CORE_ADDR addr2) | |
7101 | { | |
f5656ead | 7102 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7103 | || aspace1 == aspace2) |
7104 | && addr1 == addr2); | |
7105 | } | |
7106 | ||
f1310107 TJB |
7107 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7108 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7109 | matches ASPACE2. On targets that have global breakpoints, the address | |
7110 | space doesn't really matter. */ | |
7111 | ||
7112 | static int | |
7113 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7114 | int len1, struct address_space *aspace2, | |
7115 | CORE_ADDR addr2) | |
7116 | { | |
f5656ead | 7117 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7118 | || aspace1 == aspace2) |
7119 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7120 | } | |
7121 | ||
7122 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7123 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7124 | matches the breakpoint's address space. On targets that have global | |
7125 | breakpoints, the address space doesn't really matter. */ | |
7126 | ||
7127 | static int | |
7128 | breakpoint_location_address_match (struct bp_location *bl, | |
7129 | struct address_space *aspace, | |
7130 | CORE_ADDR addr) | |
7131 | { | |
7132 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7133 | aspace, addr) | |
7134 | || (bl->length | |
7135 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7136 | bl->address, bl->length, | |
7137 | aspace, addr))); | |
7138 | } | |
7139 | ||
d35ae833 PA |
7140 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7141 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7142 | match happens only if ASPACE matches the breakpoint's address | |
7143 | space. On targets that have global breakpoints, the address space | |
7144 | doesn't really matter. */ | |
7145 | ||
7146 | static int | |
7147 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7148 | struct address_space *aspace, | |
7149 | CORE_ADDR addr, int len) | |
7150 | { | |
7151 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7152 | || bl->pspace->aspace == aspace) | |
7153 | { | |
7154 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7155 | ||
7156 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7157 | return 1; | |
7158 | } | |
7159 | return 0; | |
7160 | } | |
7161 | ||
1e4d1764 YQ |
7162 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7163 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7164 | true, otherwise returns false. */ | |
7165 | ||
7166 | static int | |
7167 | tracepoint_locations_match (struct bp_location *loc1, | |
7168 | struct bp_location *loc2) | |
7169 | { | |
7170 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7171 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7172 | locations at the same address of different tracepoints are regarded as | |
7173 | different locations. */ | |
7174 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7175 | else | |
7176 | return 0; | |
7177 | } | |
7178 | ||
2d134ed3 PA |
7179 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7180 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7181 | represent the same location. */ | |
7182 | ||
7183 | static int | |
4a64f543 MS |
7184 | breakpoint_locations_match (struct bp_location *loc1, |
7185 | struct bp_location *loc2) | |
2d134ed3 | 7186 | { |
2bdf28a0 JK |
7187 | int hw_point1, hw_point2; |
7188 | ||
7189 | /* Both of them must not be in moribund_locations. */ | |
7190 | gdb_assert (loc1->owner != NULL); | |
7191 | gdb_assert (loc2->owner != NULL); | |
7192 | ||
7193 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7194 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7195 | |
7196 | if (hw_point1 != hw_point2) | |
7197 | return 0; | |
7198 | else if (hw_point1) | |
7199 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7200 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7201 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7202 | else |
f1310107 TJB |
7203 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7204 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7205 | loc2->pspace->aspace, loc2->address) | |
7206 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7207 | } |
7208 | ||
76897487 KB |
7209 | static void |
7210 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7211 | int bnum, int have_bnum) | |
7212 | { | |
f63fbe86 MS |
7213 | /* The longest string possibly returned by hex_string_custom |
7214 | is 50 chars. These must be at least that big for safety. */ | |
7215 | char astr1[64]; | |
7216 | char astr2[64]; | |
76897487 | 7217 | |
bb599908 PH |
7218 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7219 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7220 | if (have_bnum) |
8a3fe4f8 | 7221 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7222 | bnum, astr1, astr2); |
7223 | else | |
8a3fe4f8 | 7224 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7225 | } |
7226 | ||
4a64f543 MS |
7227 | /* Adjust a breakpoint's address to account for architectural |
7228 | constraints on breakpoint placement. Return the adjusted address. | |
7229 | Note: Very few targets require this kind of adjustment. For most | |
7230 | targets, this function is simply the identity function. */ | |
76897487 KB |
7231 | |
7232 | static CORE_ADDR | |
a6d9a66e UW |
7233 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7234 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7235 | { |
a6d9a66e | 7236 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7237 | { |
7238 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7239 | return bpaddr; | |
7240 | } | |
88f7da05 KB |
7241 | else if (bptype == bp_watchpoint |
7242 | || bptype == bp_hardware_watchpoint | |
7243 | || bptype == bp_read_watchpoint | |
7244 | || bptype == bp_access_watchpoint | |
fe798b75 | 7245 | || bptype == bp_catchpoint) |
88f7da05 KB |
7246 | { |
7247 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7248 | have their addresses modified. */ | |
7249 | return bpaddr; | |
7250 | } | |
7c16b83e PA |
7251 | else if (bptype == bp_single_step) |
7252 | { | |
7253 | /* Single-step breakpoints should not have their addresses | |
7254 | modified. If there's any architectural constrain that | |
7255 | applies to this address, then it should have already been | |
7256 | taken into account when the breakpoint was created in the | |
7257 | first place. If we didn't do this, stepping through e.g., | |
7258 | Thumb-2 IT blocks would break. */ | |
7259 | return bpaddr; | |
7260 | } | |
76897487 KB |
7261 | else |
7262 | { | |
7263 | CORE_ADDR adjusted_bpaddr; | |
7264 | ||
7265 | /* Some targets have architectural constraints on the placement | |
7266 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7267 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7268 | |
7269 | /* An adjusted breakpoint address can significantly alter | |
7270 | a user's expectations. Print a warning if an adjustment | |
7271 | is required. */ | |
7272 | if (adjusted_bpaddr != bpaddr) | |
7273 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7274 | ||
7275 | return adjusted_bpaddr; | |
7276 | } | |
7277 | } | |
7278 | ||
5625a286 | 7279 | bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner) |
7cc221ef | 7280 | { |
5625a286 | 7281 | bp_location *loc = this; |
7cc221ef | 7282 | |
348d480f PA |
7283 | gdb_assert (ops != NULL); |
7284 | ||
28010a5d PA |
7285 | loc->ops = ops; |
7286 | loc->owner = owner; | |
b775012e | 7287 | loc->cond_bytecode = NULL; |
0d381245 VP |
7288 | loc->shlib_disabled = 0; |
7289 | loc->enabled = 1; | |
e049a4b5 | 7290 | |
28010a5d | 7291 | switch (owner->type) |
e049a4b5 DJ |
7292 | { |
7293 | case bp_breakpoint: | |
7c16b83e | 7294 | case bp_single_step: |
e049a4b5 DJ |
7295 | case bp_until: |
7296 | case bp_finish: | |
7297 | case bp_longjmp: | |
7298 | case bp_longjmp_resume: | |
e2e4d78b | 7299 | case bp_longjmp_call_dummy: |
186c406b TT |
7300 | case bp_exception: |
7301 | case bp_exception_resume: | |
e049a4b5 | 7302 | case bp_step_resume: |
2c03e5be | 7303 | case bp_hp_step_resume: |
e049a4b5 DJ |
7304 | case bp_watchpoint_scope: |
7305 | case bp_call_dummy: | |
aa7d318d | 7306 | case bp_std_terminate: |
e049a4b5 DJ |
7307 | case bp_shlib_event: |
7308 | case bp_thread_event: | |
7309 | case bp_overlay_event: | |
4efc6507 | 7310 | case bp_jit_event: |
0fd8e87f | 7311 | case bp_longjmp_master: |
aa7d318d | 7312 | case bp_std_terminate_master: |
186c406b | 7313 | case bp_exception_master: |
0e30163f JK |
7314 | case bp_gnu_ifunc_resolver: |
7315 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7316 | case bp_dprintf: |
e049a4b5 | 7317 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7318 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7319 | break; |
7320 | case bp_hardware_breakpoint: | |
7321 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7322 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7323 | break; |
7324 | case bp_hardware_watchpoint: | |
7325 | case bp_read_watchpoint: | |
7326 | case bp_access_watchpoint: | |
7327 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7328 | break; | |
7329 | case bp_watchpoint: | |
ce78b96d | 7330 | case bp_catchpoint: |
15c3d785 PA |
7331 | case bp_tracepoint: |
7332 | case bp_fast_tracepoint: | |
0fb4aa4b | 7333 | case bp_static_tracepoint: |
e049a4b5 DJ |
7334 | loc->loc_type = bp_loc_other; |
7335 | break; | |
7336 | default: | |
e2e0b3e5 | 7337 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7338 | } |
7339 | ||
f431efe5 | 7340 | loc->refc = 1; |
28010a5d PA |
7341 | } |
7342 | ||
7343 | /* Allocate a struct bp_location. */ | |
7344 | ||
7345 | static struct bp_location * | |
7346 | allocate_bp_location (struct breakpoint *bpt) | |
7347 | { | |
348d480f PA |
7348 | return bpt->ops->allocate_location (bpt); |
7349 | } | |
7cc221ef | 7350 | |
f431efe5 PA |
7351 | static void |
7352 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7353 | { |
348d480f | 7354 | loc->ops->dtor (loc); |
4d01a485 | 7355 | delete loc; |
fe3f5fa8 VP |
7356 | } |
7357 | ||
f431efe5 PA |
7358 | /* Increment reference count. */ |
7359 | ||
7360 | static void | |
7361 | incref_bp_location (struct bp_location *bl) | |
7362 | { | |
7363 | ++bl->refc; | |
7364 | } | |
7365 | ||
7366 | /* Decrement reference count. If the reference count reaches 0, | |
7367 | destroy the bp_location. Sets *BLP to NULL. */ | |
7368 | ||
7369 | static void | |
7370 | decref_bp_location (struct bp_location **blp) | |
7371 | { | |
0807b50c PA |
7372 | gdb_assert ((*blp)->refc > 0); |
7373 | ||
f431efe5 PA |
7374 | if (--(*blp)->refc == 0) |
7375 | free_bp_location (*blp); | |
7376 | *blp = NULL; | |
7377 | } | |
7378 | ||
346774a9 | 7379 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7380 | |
b270e6f9 TT |
7381 | static breakpoint * |
7382 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7383 | { |
346774a9 | 7384 | struct breakpoint *b1; |
b270e6f9 | 7385 | struct breakpoint *result = b.get (); |
c906108c | 7386 | |
346774a9 PA |
7387 | /* Add this breakpoint to the end of the chain so that a list of |
7388 | breakpoints will come out in order of increasing numbers. */ | |
7389 | ||
7390 | b1 = breakpoint_chain; | |
7391 | if (b1 == 0) | |
b270e6f9 | 7392 | breakpoint_chain = b.release (); |
346774a9 PA |
7393 | else |
7394 | { | |
7395 | while (b1->next) | |
7396 | b1 = b1->next; | |
b270e6f9 | 7397 | b1->next = b.release (); |
346774a9 | 7398 | } |
b270e6f9 TT |
7399 | |
7400 | return result; | |
346774a9 PA |
7401 | } |
7402 | ||
7403 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7404 | ||
7405 | static void | |
7406 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7407 | struct gdbarch *gdbarch, | |
28010a5d | 7408 | enum bptype bptype, |
c0a91b2b | 7409 | const struct breakpoint_ops *ops) |
346774a9 | 7410 | { |
348d480f PA |
7411 | gdb_assert (ops != NULL); |
7412 | ||
28010a5d | 7413 | b->ops = ops; |
4d28f7a8 | 7414 | b->type = bptype; |
a6d9a66e | 7415 | b->gdbarch = gdbarch; |
c906108c SS |
7416 | b->language = current_language->la_language; |
7417 | b->input_radix = input_radix; | |
d0fb5eae | 7418 | b->related_breakpoint = b; |
346774a9 PA |
7419 | } |
7420 | ||
7421 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7422 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7423 | |
7424 | static struct breakpoint * | |
7425 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7426 | enum bptype bptype, |
c0a91b2b | 7427 | const struct breakpoint_ops *ops) |
346774a9 | 7428 | { |
3b0871f4 | 7429 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7430 | |
3b0871f4 | 7431 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7432 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7433 | } |
7434 | ||
0e30163f JK |
7435 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7436 | resolutions should be made as the user specified the location explicitly | |
7437 | enough. */ | |
7438 | ||
0d381245 | 7439 | static void |
0e30163f | 7440 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7441 | { |
2bdf28a0 JK |
7442 | gdb_assert (loc->owner != NULL); |
7443 | ||
0d381245 | 7444 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7445 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7446 | || is_tracepoint (loc->owner)) |
0d381245 | 7447 | { |
0e30163f | 7448 | int is_gnu_ifunc; |
2c02bd72 | 7449 | const char *function_name; |
6a3a010b | 7450 | CORE_ADDR func_addr; |
0e30163f | 7451 | |
2c02bd72 | 7452 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7453 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7454 | |
7455 | if (is_gnu_ifunc && !explicit_loc) | |
7456 | { | |
7457 | struct breakpoint *b = loc->owner; | |
7458 | ||
7459 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7460 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7461 | &loc->requested_address)) |
7462 | { | |
7463 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7464 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7465 | loc->requested_address, | |
7466 | b->type); | |
7467 | } | |
7468 | else if (b->type == bp_breakpoint && b->loc == loc | |
7469 | && loc->next == NULL && b->related_breakpoint == b) | |
7470 | { | |
7471 | /* Create only the whole new breakpoint of this type but do not | |
7472 | mess more complicated breakpoints with multiple locations. */ | |
7473 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7474 | /* Remember the resolver's address for use by the return |
7475 | breakpoint. */ | |
7476 | loc->related_address = func_addr; | |
0e30163f JK |
7477 | } |
7478 | } | |
7479 | ||
2c02bd72 DE |
7480 | if (function_name) |
7481 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7482 | } |
7483 | } | |
7484 | ||
a6d9a66e | 7485 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7486 | struct gdbarch * |
a6d9a66e UW |
7487 | get_sal_arch (struct symtab_and_line sal) |
7488 | { | |
7489 | if (sal.section) | |
7490 | return get_objfile_arch (sal.section->objfile); | |
7491 | if (sal.symtab) | |
eb822aa6 | 7492 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7493 | |
7494 | return NULL; | |
7495 | } | |
7496 | ||
346774a9 PA |
7497 | /* Low level routine for partially initializing a breakpoint of type |
7498 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7499 | file name, and line number are provided by SAL. |
0d381245 VP |
7500 | |
7501 | It is expected that the caller will complete the initialization of | |
7502 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7503 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7504 | |
346774a9 PA |
7505 | static void |
7506 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7507 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7508 | const struct breakpoint_ops *ops) |
0d381245 | 7509 | { |
28010a5d | 7510 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7511 | |
3742cc8b | 7512 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7513 | |
6c95b8df PA |
7514 | if (bptype != bp_catchpoint) |
7515 | gdb_assert (sal.pspace != NULL); | |
7516 | ||
f8eba3c6 TT |
7517 | /* Store the program space that was used to set the breakpoint, |
7518 | except for ordinary breakpoints, which are independent of the | |
7519 | program space. */ | |
7520 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7521 | b->pspace = sal.pspace; | |
346774a9 | 7522 | } |
c906108c | 7523 | |
346774a9 PA |
7524 | /* set_raw_breakpoint is a low level routine for allocating and |
7525 | partially initializing a breakpoint of type BPTYPE. The newly | |
7526 | created breakpoint's address, section, source file name, and line | |
7527 | number are provided by SAL. The newly created and partially | |
7528 | initialized breakpoint is added to the breakpoint chain and | |
7529 | is also returned as the value of this function. | |
7530 | ||
7531 | It is expected that the caller will complete the initialization of | |
7532 | the newly created breakpoint struct as well as output any status | |
7533 | information regarding the creation of a new breakpoint. In | |
7534 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7535 | number! Care should be taken to not allow an error to occur | |
7536 | prior to completing the initialization of the breakpoint. If this | |
7537 | should happen, a bogus breakpoint will be left on the chain. */ | |
7538 | ||
7539 | struct breakpoint * | |
7540 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7541 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7542 | const struct breakpoint_ops *ops) |
346774a9 | 7543 | { |
3b0871f4 | 7544 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7545 | |
3b0871f4 | 7546 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7547 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7548 | } |
7549 | ||
53a5351d | 7550 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7551 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7552 | initiated the operation. */ | |
c906108c SS |
7553 | |
7554 | void | |
186c406b | 7555 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7556 | { |
35df4500 | 7557 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7558 | int thread = tp->global_num; |
0fd8e87f UW |
7559 | |
7560 | /* To avoid having to rescan all objfile symbols at every step, | |
7561 | we maintain a list of continually-inserted but always disabled | |
7562 | longjmp "master" breakpoints. Here, we simply create momentary | |
7563 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7564 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7565 | if (b->pspace == current_program_space |
186c406b TT |
7566 | && (b->type == bp_longjmp_master |
7567 | || b->type == bp_exception_master)) | |
0fd8e87f | 7568 | { |
06edf0c0 PA |
7569 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7570 | struct breakpoint *clone; | |
cc59ec59 | 7571 | |
e2e4d78b JK |
7572 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7573 | after their removal. */ | |
06edf0c0 | 7574 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7575 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7576 | clone->thread = thread; |
7577 | } | |
186c406b TT |
7578 | |
7579 | tp->initiating_frame = frame; | |
c906108c SS |
7580 | } |
7581 | ||
611c83ae | 7582 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7583 | void |
611c83ae | 7584 | delete_longjmp_breakpoint (int thread) |
c906108c | 7585 | { |
35df4500 | 7586 | struct breakpoint *b, *b_tmp; |
c906108c | 7587 | |
35df4500 | 7588 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7589 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7590 | { |
7591 | if (b->thread == thread) | |
7592 | delete_breakpoint (b); | |
7593 | } | |
c906108c SS |
7594 | } |
7595 | ||
f59f708a PA |
7596 | void |
7597 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7598 | { | |
7599 | struct breakpoint *b, *b_tmp; | |
7600 | ||
7601 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7602 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7603 | { | |
7604 | if (b->thread == thread) | |
7605 | b->disposition = disp_del_at_next_stop; | |
7606 | } | |
7607 | } | |
7608 | ||
e2e4d78b JK |
7609 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7610 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7611 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7612 | breakpoints. */ | |
7613 | ||
7614 | struct breakpoint * | |
7615 | set_longjmp_breakpoint_for_call_dummy (void) | |
7616 | { | |
7617 | struct breakpoint *b, *retval = NULL; | |
7618 | ||
7619 | ALL_BREAKPOINTS (b) | |
7620 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7621 | { | |
7622 | struct breakpoint *new_b; | |
7623 | ||
7624 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7625 | &momentary_breakpoint_ops, |
7626 | 1); | |
5d5658a1 | 7627 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7628 | |
7629 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7630 | ||
7631 | gdb_assert (new_b->related_breakpoint == new_b); | |
7632 | if (retval == NULL) | |
7633 | retval = new_b; | |
7634 | new_b->related_breakpoint = retval; | |
7635 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7636 | retval = retval->related_breakpoint; | |
7637 | retval->related_breakpoint = new_b; | |
7638 | } | |
7639 | ||
7640 | return retval; | |
7641 | } | |
7642 | ||
7643 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7644 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7645 | stack. |
7646 | ||
7647 | You should call this function only at places where it is safe to currently | |
7648 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7649 | frames. */ | |
7650 | ||
7651 | void | |
b67a2c6f | 7652 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7653 | { |
7654 | struct breakpoint *b, *b_tmp; | |
7655 | ||
7656 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7657 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7658 | { |
7659 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7660 | ||
7661 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7662 | dummy_b = dummy_b->related_breakpoint; | |
7663 | if (dummy_b->type != bp_call_dummy | |
7664 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7665 | continue; | |
7666 | ||
b67a2c6f | 7667 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7668 | |
7669 | while (b->related_breakpoint != b) | |
7670 | { | |
7671 | if (b_tmp == b->related_breakpoint) | |
7672 | b_tmp = b->related_breakpoint->next; | |
7673 | delete_breakpoint (b->related_breakpoint); | |
7674 | } | |
7675 | delete_breakpoint (b); | |
7676 | } | |
7677 | } | |
7678 | ||
1900040c MS |
7679 | void |
7680 | enable_overlay_breakpoints (void) | |
7681 | { | |
52f0bd74 | 7682 | struct breakpoint *b; |
1900040c MS |
7683 | |
7684 | ALL_BREAKPOINTS (b) | |
7685 | if (b->type == bp_overlay_event) | |
7686 | { | |
7687 | b->enable_state = bp_enabled; | |
44702360 | 7688 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7689 | overlay_events_enabled = 1; |
1900040c MS |
7690 | } |
7691 | } | |
7692 | ||
7693 | void | |
7694 | disable_overlay_breakpoints (void) | |
7695 | { | |
52f0bd74 | 7696 | struct breakpoint *b; |
1900040c MS |
7697 | |
7698 | ALL_BREAKPOINTS (b) | |
7699 | if (b->type == bp_overlay_event) | |
7700 | { | |
7701 | b->enable_state = bp_disabled; | |
44702360 | 7702 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7703 | overlay_events_enabled = 0; |
1900040c MS |
7704 | } |
7705 | } | |
7706 | ||
aa7d318d TT |
7707 | /* Set an active std::terminate breakpoint for each std::terminate |
7708 | master breakpoint. */ | |
7709 | void | |
7710 | set_std_terminate_breakpoint (void) | |
7711 | { | |
35df4500 | 7712 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7713 | |
35df4500 | 7714 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7715 | if (b->pspace == current_program_space |
7716 | && b->type == bp_std_terminate_master) | |
7717 | { | |
06edf0c0 | 7718 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7719 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7720 | } |
7721 | } | |
7722 | ||
7723 | /* Delete all the std::terminate breakpoints. */ | |
7724 | void | |
7725 | delete_std_terminate_breakpoint (void) | |
7726 | { | |
35df4500 | 7727 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7728 | |
35df4500 | 7729 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7730 | if (b->type == bp_std_terminate) |
7731 | delete_breakpoint (b); | |
7732 | } | |
7733 | ||
c4093a6a | 7734 | struct breakpoint * |
a6d9a66e | 7735 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7736 | { |
7737 | struct breakpoint *b; | |
c4093a6a | 7738 | |
06edf0c0 PA |
7739 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7740 | &internal_breakpoint_ops); | |
7741 | ||
b5de0fa7 | 7742 | b->enable_state = bp_enabled; |
f00aae0f | 7743 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7744 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7745 | |
44702360 | 7746 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7747 | |
c4093a6a JM |
7748 | return b; |
7749 | } | |
7750 | ||
0101ce28 JJ |
7751 | struct lang_and_radix |
7752 | { | |
7753 | enum language lang; | |
7754 | int radix; | |
7755 | }; | |
7756 | ||
4efc6507 DE |
7757 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7758 | ||
7759 | struct breakpoint * | |
7760 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7761 | { | |
2a7f3dff PA |
7762 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7763 | &internal_breakpoint_ops); | |
4efc6507 | 7764 | } |
0101ce28 | 7765 | |
03673fc7 PP |
7766 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7767 | ||
7768 | void | |
7769 | remove_jit_event_breakpoints (void) | |
7770 | { | |
7771 | struct breakpoint *b, *b_tmp; | |
7772 | ||
7773 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7774 | if (b->type == bp_jit_event | |
7775 | && b->loc->pspace == current_program_space) | |
7776 | delete_breakpoint (b); | |
7777 | } | |
7778 | ||
cae688ec JJ |
7779 | void |
7780 | remove_solib_event_breakpoints (void) | |
7781 | { | |
35df4500 | 7782 | struct breakpoint *b, *b_tmp; |
cae688ec | 7783 | |
35df4500 | 7784 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7785 | if (b->type == bp_shlib_event |
7786 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7787 | delete_breakpoint (b); |
7788 | } | |
7789 | ||
f37f681c PA |
7790 | /* See breakpoint.h. */ |
7791 | ||
7792 | void | |
7793 | remove_solib_event_breakpoints_at_next_stop (void) | |
7794 | { | |
7795 | struct breakpoint *b, *b_tmp; | |
7796 | ||
7797 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7798 | if (b->type == bp_shlib_event | |
7799 | && b->loc->pspace == current_program_space) | |
7800 | b->disposition = disp_del_at_next_stop; | |
7801 | } | |
7802 | ||
04086b45 PA |
7803 | /* Helper for create_solib_event_breakpoint / |
7804 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7805 | INSERT_MODE to pass through to update_global_location_list. */ | |
7806 | ||
7807 | static struct breakpoint * | |
7808 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7809 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7810 | { |
7811 | struct breakpoint *b; | |
7812 | ||
06edf0c0 PA |
7813 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7814 | &internal_breakpoint_ops); | |
04086b45 | 7815 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7816 | return b; |
7817 | } | |
7818 | ||
04086b45 PA |
7819 | struct breakpoint * |
7820 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7821 | { | |
7822 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7823 | } | |
7824 | ||
f37f681c PA |
7825 | /* See breakpoint.h. */ |
7826 | ||
7827 | struct breakpoint * | |
7828 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7829 | { | |
7830 | struct breakpoint *b; | |
7831 | ||
04086b45 PA |
7832 | /* Explicitly tell update_global_location_list to insert |
7833 | locations. */ | |
7834 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7835 | if (!b->loc->inserted) |
7836 | { | |
7837 | delete_breakpoint (b); | |
7838 | return NULL; | |
7839 | } | |
7840 | return b; | |
7841 | } | |
7842 | ||
cae688ec JJ |
7843 | /* Disable any breakpoints that are on code in shared libraries. Only |
7844 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7845 | ||
7846 | void | |
cb851954 | 7847 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7848 | { |
876fa593 | 7849 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7850 | |
876fa593 | 7851 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7852 | { |
2bdf28a0 | 7853 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7854 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7855 | |
4a64f543 MS |
7856 | /* We apply the check to all breakpoints, including disabled for |
7857 | those with loc->duplicate set. This is so that when breakpoint | |
7858 | becomes enabled, or the duplicate is removed, gdb will try to | |
7859 | insert all breakpoints. If we don't set shlib_disabled here, | |
7860 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7861 | if (((b->type == bp_breakpoint) |
508ccb1f | 7862 | || (b->type == bp_jit_event) |
1042e4c0 | 7863 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7864 | || (is_tracepoint (b))) |
6c95b8df | 7865 | && loc->pspace == current_program_space |
0d381245 | 7866 | && !loc->shlib_disabled |
6c95b8df | 7867 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7868 | ) |
0d381245 VP |
7869 | { |
7870 | loc->shlib_disabled = 1; | |
7871 | } | |
cae688ec JJ |
7872 | } |
7873 | } | |
7874 | ||
63644780 NB |
7875 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7876 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7877 | disabled ones can just stay disabled. */ | |
84acb35a | 7878 | |
75149521 | 7879 | static void |
84acb35a JJ |
7880 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7881 | { | |
876fa593 | 7882 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7883 | int disabled_shlib_breaks = 0; |
7884 | ||
876fa593 | 7885 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7886 | { |
2bdf28a0 | 7887 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7888 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7889 | |
1e4d1764 | 7890 | if (solib->pspace == loc->pspace |
e2dd7057 | 7891 | && !loc->shlib_disabled |
1e4d1764 YQ |
7892 | && (((b->type == bp_breakpoint |
7893 | || b->type == bp_jit_event | |
7894 | || b->type == bp_hardware_breakpoint) | |
7895 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7896 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7897 | || is_tracepoint (b)) | |
e2dd7057 | 7898 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7899 | { |
e2dd7057 PP |
7900 | loc->shlib_disabled = 1; |
7901 | /* At this point, we cannot rely on remove_breakpoint | |
7902 | succeeding so we must mark the breakpoint as not inserted | |
7903 | to prevent future errors occurring in remove_breakpoints. */ | |
7904 | loc->inserted = 0; | |
8d3788bd VP |
7905 | |
7906 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7907 | observer_notify_breakpoint_modified (b); | |
7908 | ||
e2dd7057 PP |
7909 | if (!disabled_shlib_breaks) |
7910 | { | |
223ffa71 | 7911 | target_terminal::ours_for_output (); |
3e43a32a MS |
7912 | warning (_("Temporarily disabling breakpoints " |
7913 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7914 | solib->so_name); |
84acb35a | 7915 | } |
e2dd7057 | 7916 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7917 | } |
7918 | } | |
84acb35a JJ |
7919 | } |
7920 | ||
63644780 NB |
7921 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7922 | notification of free_objfile. Only apply to enabled breakpoints, | |
7923 | disabled ones can just stay disabled. */ | |
7924 | ||
7925 | static void | |
7926 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7927 | { | |
7928 | struct breakpoint *b; | |
7929 | ||
7930 | if (objfile == NULL) | |
7931 | return; | |
7932 | ||
d03de421 PA |
7933 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7934 | managed by the user with add-symbol-file/remove-symbol-file. | |
7935 | Similarly to how breakpoints in shared libraries are handled in | |
7936 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7937 | shlib_disabled so they end up uninserted on the next global |
7938 | location list update. Shared libraries not loaded by the user | |
7939 | aren't handled here -- they're already handled in | |
7940 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7941 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7942 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7943 | main objfile). */ | |
7944 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7945 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7946 | return; |
7947 | ||
7948 | ALL_BREAKPOINTS (b) | |
7949 | { | |
7950 | struct bp_location *loc; | |
7951 | int bp_modified = 0; | |
7952 | ||
7953 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7954 | continue; | |
7955 | ||
7956 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7957 | { | |
7958 | CORE_ADDR loc_addr = loc->address; | |
7959 | ||
7960 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7961 | && loc->loc_type != bp_loc_software_breakpoint) | |
7962 | continue; | |
7963 | ||
7964 | if (loc->shlib_disabled != 0) | |
7965 | continue; | |
7966 | ||
7967 | if (objfile->pspace != loc->pspace) | |
7968 | continue; | |
7969 | ||
7970 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7971 | && loc->loc_type != bp_loc_software_breakpoint) | |
7972 | continue; | |
7973 | ||
7974 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7975 | { | |
7976 | loc->shlib_disabled = 1; | |
08351840 PA |
7977 | /* At this point, we don't know whether the object was |
7978 | unmapped from the inferior or not, so leave the | |
7979 | inserted flag alone. We'll handle failure to | |
7980 | uninsert quietly, in case the object was indeed | |
7981 | unmapped. */ | |
63644780 NB |
7982 | |
7983 | mark_breakpoint_location_modified (loc); | |
7984 | ||
7985 | bp_modified = 1; | |
7986 | } | |
7987 | } | |
7988 | ||
7989 | if (bp_modified) | |
7990 | observer_notify_breakpoint_modified (b); | |
7991 | } | |
7992 | } | |
7993 | ||
ce78b96d JB |
7994 | /* FORK & VFORK catchpoints. */ |
7995 | ||
e29a4733 | 7996 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7997 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7998 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7999 | |
c1fc2657 | 8000 | struct fork_catchpoint : public breakpoint |
e29a4733 | 8001 | { |
e29a4733 PA |
8002 | /* Process id of a child process whose forking triggered this |
8003 | catchpoint. This field is only valid immediately after this | |
8004 | catchpoint has triggered. */ | |
8005 | ptid_t forked_inferior_pid; | |
8006 | }; | |
8007 | ||
4a64f543 MS |
8008 | /* Implement the "insert" breakpoint_ops method for fork |
8009 | catchpoints. */ | |
ce78b96d | 8010 | |
77b06cd7 TJB |
8011 | static int |
8012 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8013 | { |
dfd4cc63 | 8014 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8015 | } |
8016 | ||
4a64f543 MS |
8017 | /* Implement the "remove" breakpoint_ops method for fork |
8018 | catchpoints. */ | |
ce78b96d JB |
8019 | |
8020 | static int | |
73971819 | 8021 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8022 | { |
dfd4cc63 | 8023 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8024 | } |
8025 | ||
8026 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8027 | catchpoints. */ | |
8028 | ||
8029 | static int | |
f1310107 | 8030 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8031 | struct address_space *aspace, CORE_ADDR bp_addr, |
8032 | const struct target_waitstatus *ws) | |
ce78b96d | 8033 | { |
e29a4733 PA |
8034 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8035 | ||
f90263c1 TT |
8036 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8037 | return 0; | |
8038 | ||
8039 | c->forked_inferior_pid = ws->value.related_pid; | |
8040 | return 1; | |
ce78b96d JB |
8041 | } |
8042 | ||
4a64f543 MS |
8043 | /* Implement the "print_it" breakpoint_ops method for fork |
8044 | catchpoints. */ | |
ce78b96d JB |
8045 | |
8046 | static enum print_stop_action | |
348d480f | 8047 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8048 | { |
36dfb11c | 8049 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8050 | struct breakpoint *b = bs->breakpoint_at; |
8051 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8052 | |
ce78b96d | 8053 | annotate_catchpoint (b->number); |
f303dbd6 | 8054 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8055 | if (b->disposition == disp_del) |
112e8700 | 8056 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8057 | else |
112e8700 SM |
8058 | uiout->text ("Catchpoint "); |
8059 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8060 | { |
112e8700 SM |
8061 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
8062 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8063 | } |
112e8700 SM |
8064 | uiout->field_int ("bkptno", b->number); |
8065 | uiout->text (" (forked process "); | |
8066 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8067 | uiout->text ("), "); | |
ce78b96d JB |
8068 | return PRINT_SRC_AND_LOC; |
8069 | } | |
8070 | ||
4a64f543 MS |
8071 | /* Implement the "print_one" breakpoint_ops method for fork |
8072 | catchpoints. */ | |
ce78b96d JB |
8073 | |
8074 | static void | |
a6d9a66e | 8075 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8076 | { |
e29a4733 | 8077 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8078 | struct value_print_options opts; |
79a45e25 | 8079 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8080 | |
8081 | get_user_print_options (&opts); | |
8082 | ||
4a64f543 MS |
8083 | /* Field 4, the address, is omitted (which makes the columns not |
8084 | line up too nicely with the headers, but the effect is relatively | |
8085 | readable). */ | |
79a45b7d | 8086 | if (opts.addressprint) |
112e8700 | 8087 | uiout->field_skip ("addr"); |
ce78b96d | 8088 | annotate_field (5); |
112e8700 | 8089 | uiout->text ("fork"); |
e29a4733 | 8090 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8091 | { |
112e8700 SM |
8092 | uiout->text (", process "); |
8093 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8094 | uiout->spaces (1); | |
ce78b96d | 8095 | } |
8ac3646f | 8096 | |
112e8700 SM |
8097 | if (uiout->is_mi_like_p ()) |
8098 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
8099 | } |
8100 | ||
8101 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8102 | catchpoints. */ | |
8103 | ||
8104 | static void | |
8105 | print_mention_catch_fork (struct breakpoint *b) | |
8106 | { | |
8107 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8108 | } | |
8109 | ||
6149aea9 PA |
8110 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8111 | catchpoints. */ | |
8112 | ||
8113 | static void | |
8114 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8115 | { | |
8116 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8117 | print_recreate_thread (b, fp); |
6149aea9 PA |
8118 | } |
8119 | ||
ce78b96d JB |
8120 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8121 | ||
2060206e | 8122 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8123 | |
4a64f543 MS |
8124 | /* Implement the "insert" breakpoint_ops method for vfork |
8125 | catchpoints. */ | |
ce78b96d | 8126 | |
77b06cd7 TJB |
8127 | static int |
8128 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8129 | { |
dfd4cc63 | 8130 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8131 | } |
8132 | ||
4a64f543 MS |
8133 | /* Implement the "remove" breakpoint_ops method for vfork |
8134 | catchpoints. */ | |
ce78b96d JB |
8135 | |
8136 | static int | |
73971819 | 8137 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8138 | { |
dfd4cc63 | 8139 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8140 | } |
8141 | ||
8142 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8143 | catchpoints. */ | |
8144 | ||
8145 | static int | |
f1310107 | 8146 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8147 | struct address_space *aspace, CORE_ADDR bp_addr, |
8148 | const struct target_waitstatus *ws) | |
ce78b96d | 8149 | { |
e29a4733 PA |
8150 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8151 | ||
f90263c1 TT |
8152 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8153 | return 0; | |
8154 | ||
8155 | c->forked_inferior_pid = ws->value.related_pid; | |
8156 | return 1; | |
ce78b96d JB |
8157 | } |
8158 | ||
4a64f543 MS |
8159 | /* Implement the "print_it" breakpoint_ops method for vfork |
8160 | catchpoints. */ | |
ce78b96d JB |
8161 | |
8162 | static enum print_stop_action | |
348d480f | 8163 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8164 | { |
36dfb11c | 8165 | struct ui_out *uiout = current_uiout; |
348d480f | 8166 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8167 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8168 | ||
ce78b96d | 8169 | annotate_catchpoint (b->number); |
f303dbd6 | 8170 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8171 | if (b->disposition == disp_del) |
112e8700 | 8172 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8173 | else |
112e8700 SM |
8174 | uiout->text ("Catchpoint "); |
8175 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8176 | { |
112e8700 SM |
8177 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
8178 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8179 | } |
112e8700 SM |
8180 | uiout->field_int ("bkptno", b->number); |
8181 | uiout->text (" (vforked process "); | |
8182 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8183 | uiout->text ("), "); | |
ce78b96d JB |
8184 | return PRINT_SRC_AND_LOC; |
8185 | } | |
8186 | ||
4a64f543 MS |
8187 | /* Implement the "print_one" breakpoint_ops method for vfork |
8188 | catchpoints. */ | |
ce78b96d JB |
8189 | |
8190 | static void | |
a6d9a66e | 8191 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8192 | { |
e29a4733 | 8193 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8194 | struct value_print_options opts; |
79a45e25 | 8195 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8196 | |
8197 | get_user_print_options (&opts); | |
4a64f543 MS |
8198 | /* Field 4, the address, is omitted (which makes the columns not |
8199 | line up too nicely with the headers, but the effect is relatively | |
8200 | readable). */ | |
79a45b7d | 8201 | if (opts.addressprint) |
112e8700 | 8202 | uiout->field_skip ("addr"); |
ce78b96d | 8203 | annotate_field (5); |
112e8700 | 8204 | uiout->text ("vfork"); |
e29a4733 | 8205 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8206 | { |
112e8700 SM |
8207 | uiout->text (", process "); |
8208 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8209 | uiout->spaces (1); | |
ce78b96d | 8210 | } |
8ac3646f | 8211 | |
112e8700 SM |
8212 | if (uiout->is_mi_like_p ()) |
8213 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
8214 | } |
8215 | ||
8216 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8217 | catchpoints. */ | |
8218 | ||
8219 | static void | |
8220 | print_mention_catch_vfork (struct breakpoint *b) | |
8221 | { | |
8222 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8223 | } | |
8224 | ||
6149aea9 PA |
8225 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8226 | catchpoints. */ | |
8227 | ||
8228 | static void | |
8229 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8230 | { | |
8231 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8232 | print_recreate_thread (b, fp); |
6149aea9 PA |
8233 | } |
8234 | ||
ce78b96d JB |
8235 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8236 | ||
2060206e | 8237 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8238 | |
edcc5120 | 8239 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 8240 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
8241 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
8242 | ||
c1fc2657 | 8243 | struct solib_catchpoint : public breakpoint |
edcc5120 | 8244 | { |
c1fc2657 | 8245 | ~solib_catchpoint () override; |
edcc5120 TT |
8246 | |
8247 | /* True for "catch load", false for "catch unload". */ | |
8248 | unsigned char is_load; | |
8249 | ||
8250 | /* Regular expression to match, if any. COMPILED is only valid when | |
8251 | REGEX is non-NULL. */ | |
8252 | char *regex; | |
2d7cc5c7 | 8253 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
8254 | }; |
8255 | ||
c1fc2657 | 8256 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 8257 | { |
c1fc2657 | 8258 | xfree (this->regex); |
edcc5120 TT |
8259 | } |
8260 | ||
8261 | static int | |
8262 | insert_catch_solib (struct bp_location *ignore) | |
8263 | { | |
8264 | return 0; | |
8265 | } | |
8266 | ||
8267 | static int | |
73971819 | 8268 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8269 | { |
8270 | return 0; | |
8271 | } | |
8272 | ||
8273 | static int | |
8274 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8275 | struct address_space *aspace, | |
8276 | CORE_ADDR bp_addr, | |
8277 | const struct target_waitstatus *ws) | |
8278 | { | |
8279 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8280 | struct breakpoint *other; | |
8281 | ||
8282 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8283 | return 1; | |
8284 | ||
8285 | ALL_BREAKPOINTS (other) | |
8286 | { | |
8287 | struct bp_location *other_bl; | |
8288 | ||
8289 | if (other == bl->owner) | |
8290 | continue; | |
8291 | ||
8292 | if (other->type != bp_shlib_event) | |
8293 | continue; | |
8294 | ||
c1fc2657 | 8295 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
8296 | continue; |
8297 | ||
8298 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8299 | { | |
8300 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8301 | return 1; | |
8302 | } | |
8303 | } | |
8304 | ||
8305 | return 0; | |
8306 | } | |
8307 | ||
8308 | static void | |
8309 | check_status_catch_solib (struct bpstats *bs) | |
8310 | { | |
8311 | struct solib_catchpoint *self | |
8312 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8313 | int ix; | |
8314 | ||
8315 | if (self->is_load) | |
8316 | { | |
8317 | struct so_list *iter; | |
8318 | ||
8319 | for (ix = 0; | |
8320 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8321 | ix, iter); | |
8322 | ++ix) | |
8323 | { | |
8324 | if (!self->regex | |
2d7cc5c7 | 8325 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
8326 | return; |
8327 | } | |
8328 | } | |
8329 | else | |
8330 | { | |
8331 | char *iter; | |
8332 | ||
8333 | for (ix = 0; | |
8334 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8335 | ix, iter); | |
8336 | ++ix) | |
8337 | { | |
8338 | if (!self->regex | |
2d7cc5c7 | 8339 | || self->compiled->exec (iter, 0, NULL, 0) == 0) |
edcc5120 TT |
8340 | return; |
8341 | } | |
8342 | } | |
8343 | ||
8344 | bs->stop = 0; | |
8345 | bs->print_it = print_it_noop; | |
8346 | } | |
8347 | ||
8348 | static enum print_stop_action | |
8349 | print_it_catch_solib (bpstat bs) | |
8350 | { | |
8351 | struct breakpoint *b = bs->breakpoint_at; | |
8352 | struct ui_out *uiout = current_uiout; | |
8353 | ||
8354 | annotate_catchpoint (b->number); | |
f303dbd6 | 8355 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8356 | if (b->disposition == disp_del) |
112e8700 | 8357 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8358 | else |
112e8700 SM |
8359 | uiout->text ("Catchpoint "); |
8360 | uiout->field_int ("bkptno", b->number); | |
8361 | uiout->text ("\n"); | |
8362 | if (uiout->is_mi_like_p ()) | |
8363 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8364 | print_solib_event (1); |
8365 | return PRINT_SRC_AND_LOC; | |
8366 | } | |
8367 | ||
8368 | static void | |
8369 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8370 | { | |
8371 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8372 | struct value_print_options opts; | |
8373 | struct ui_out *uiout = current_uiout; | |
8374 | char *msg; | |
8375 | ||
8376 | get_user_print_options (&opts); | |
8377 | /* Field 4, the address, is omitted (which makes the columns not | |
8378 | line up too nicely with the headers, but the effect is relatively | |
8379 | readable). */ | |
8380 | if (opts.addressprint) | |
8381 | { | |
8382 | annotate_field (4); | |
112e8700 | 8383 | uiout->field_skip ("addr"); |
edcc5120 TT |
8384 | } |
8385 | ||
8386 | annotate_field (5); | |
8387 | if (self->is_load) | |
8388 | { | |
8389 | if (self->regex) | |
8390 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8391 | else | |
8392 | msg = xstrdup (_("load of library")); | |
8393 | } | |
8394 | else | |
8395 | { | |
8396 | if (self->regex) | |
8397 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8398 | else | |
8399 | msg = xstrdup (_("unload of library")); | |
8400 | } | |
112e8700 | 8401 | uiout->field_string ("what", msg); |
edcc5120 | 8402 | xfree (msg); |
8ac3646f | 8403 | |
112e8700 SM |
8404 | if (uiout->is_mi_like_p ()) |
8405 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8406 | } |
8407 | ||
8408 | static void | |
8409 | print_mention_catch_solib (struct breakpoint *b) | |
8410 | { | |
8411 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8412 | ||
8413 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8414 | self->is_load ? "load" : "unload"); | |
8415 | } | |
8416 | ||
8417 | static void | |
8418 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8419 | { | |
8420 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8421 | ||
8422 | fprintf_unfiltered (fp, "%s %s", | |
8423 | b->disposition == disp_del ? "tcatch" : "catch", | |
8424 | self->is_load ? "load" : "unload"); | |
8425 | if (self->regex) | |
8426 | fprintf_unfiltered (fp, " %s", self->regex); | |
8427 | fprintf_unfiltered (fp, "\n"); | |
8428 | } | |
8429 | ||
8430 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8431 | ||
91985142 MG |
8432 | /* Shared helper function (MI and CLI) for creating and installing |
8433 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8434 | the events to be caught are load events, otherwise they are | |
8435 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8436 | temporary one. If ENABLED is non-zero the catchpoint is | |
8437 | created in an enabled state. */ | |
edcc5120 | 8438 | |
91985142 | 8439 | void |
a121b7c1 | 8440 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8441 | { |
edcc5120 | 8442 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8443 | |
edcc5120 TT |
8444 | if (!arg) |
8445 | arg = ""; | |
f1735a53 | 8446 | arg = skip_spaces (arg); |
edcc5120 | 8447 | |
36bd8eaa | 8448 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8449 | |
8450 | if (*arg != '\0') | |
8451 | { | |
2d7cc5c7 PA |
8452 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8453 | _("Invalid regexp"))); | |
edcc5120 TT |
8454 | c->regex = xstrdup (arg); |
8455 | } | |
8456 | ||
8457 | c->is_load = is_load; | |
36bd8eaa | 8458 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8459 | &catch_solib_breakpoint_ops); |
8460 | ||
c1fc2657 | 8461 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8462 | |
b270e6f9 | 8463 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8464 | } |
8465 | ||
91985142 MG |
8466 | /* A helper function that does all the work for "catch load" and |
8467 | "catch unload". */ | |
8468 | ||
8469 | static void | |
8470 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8471 | struct cmd_list_element *command) | |
8472 | { | |
8473 | int tempflag; | |
8474 | const int enabled = 1; | |
8475 | ||
8476 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8477 | ||
8478 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8479 | } | |
8480 | ||
edcc5120 TT |
8481 | static void |
8482 | catch_load_command_1 (char *arg, int from_tty, | |
8483 | struct cmd_list_element *command) | |
8484 | { | |
8485 | catch_load_or_unload (arg, from_tty, 1, command); | |
8486 | } | |
8487 | ||
8488 | static void | |
8489 | catch_unload_command_1 (char *arg, int from_tty, | |
8490 | struct cmd_list_element *command) | |
8491 | { | |
8492 | catch_load_or_unload (arg, from_tty, 0, command); | |
8493 | } | |
8494 | ||
346774a9 PA |
8495 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8496 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8497 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8498 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8499 | |
ab04a2af | 8500 | void |
346774a9 PA |
8501 | init_catchpoint (struct breakpoint *b, |
8502 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8503 | const char *cond_string, |
c0a91b2b | 8504 | const struct breakpoint_ops *ops) |
c906108c | 8505 | { |
51abb421 | 8506 | symtab_and_line sal; |
6c95b8df | 8507 | sal.pspace = current_program_space; |
c5aa993b | 8508 | |
28010a5d | 8509 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8510 | |
1b36a34b | 8511 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8512 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8513 | } |
8514 | ||
28010a5d | 8515 | void |
b270e6f9 | 8516 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8517 | { |
b270e6f9 | 8518 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8519 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8520 | if (is_tracepoint (b)) |
8521 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8522 | if (!internal) |
8523 | mention (b); | |
c56053d2 | 8524 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8525 | |
8526 | if (update_gll) | |
44702360 | 8527 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8528 | } |
8529 | ||
9b70b993 | 8530 | static void |
a6d9a66e | 8531 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8532 | int tempflag, const char *cond_string, |
c0a91b2b | 8533 | const struct breakpoint_ops *ops) |
c906108c | 8534 | { |
b270e6f9 | 8535 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8536 | |
b270e6f9 | 8537 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8538 | |
8539 | c->forked_inferior_pid = null_ptid; | |
8540 | ||
b270e6f9 | 8541 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8542 | } |
8543 | ||
fe798b75 JB |
8544 | /* Exec catchpoints. */ |
8545 | ||
b4d90040 | 8546 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8547 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8548 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8549 | ||
c1fc2657 | 8550 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8551 | { |
c1fc2657 | 8552 | ~exec_catchpoint () override; |
b4d90040 PA |
8553 | |
8554 | /* Filename of a program whose exec triggered this catchpoint. | |
8555 | This field is only valid immediately after this catchpoint has | |
8556 | triggered. */ | |
8557 | char *exec_pathname; | |
8558 | }; | |
8559 | ||
c1fc2657 | 8560 | /* Exec catchpoint destructor. */ |
b4d90040 | 8561 | |
c1fc2657 | 8562 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8563 | { |
c1fc2657 | 8564 | xfree (this->exec_pathname); |
b4d90040 PA |
8565 | } |
8566 | ||
77b06cd7 TJB |
8567 | static int |
8568 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8569 | { |
dfd4cc63 | 8570 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8571 | } |
c906108c | 8572 | |
fe798b75 | 8573 | static int |
73971819 | 8574 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8575 | { |
dfd4cc63 | 8576 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8577 | } |
c906108c | 8578 | |
fe798b75 | 8579 | static int |
f1310107 | 8580 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8581 | struct address_space *aspace, CORE_ADDR bp_addr, |
8582 | const struct target_waitstatus *ws) | |
fe798b75 | 8583 | { |
b4d90040 PA |
8584 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8585 | ||
f90263c1 TT |
8586 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8587 | return 0; | |
8588 | ||
8589 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8590 | return 1; | |
fe798b75 | 8591 | } |
c906108c | 8592 | |
fe798b75 | 8593 | static enum print_stop_action |
348d480f | 8594 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8595 | { |
36dfb11c | 8596 | struct ui_out *uiout = current_uiout; |
348d480f | 8597 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8598 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8599 | ||
fe798b75 | 8600 | annotate_catchpoint (b->number); |
f303dbd6 | 8601 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8602 | if (b->disposition == disp_del) |
112e8700 | 8603 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8604 | else |
112e8700 SM |
8605 | uiout->text ("Catchpoint "); |
8606 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8607 | { |
112e8700 SM |
8608 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8609 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8610 | } |
112e8700 SM |
8611 | uiout->field_int ("bkptno", b->number); |
8612 | uiout->text (" (exec'd "); | |
8613 | uiout->field_string ("new-exec", c->exec_pathname); | |
8614 | uiout->text ("), "); | |
36dfb11c | 8615 | |
fe798b75 | 8616 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8617 | } |
8618 | ||
fe798b75 | 8619 | static void |
a6d9a66e | 8620 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8621 | { |
b4d90040 | 8622 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8623 | struct value_print_options opts; |
79a45e25 | 8624 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8625 | |
8626 | get_user_print_options (&opts); | |
8627 | ||
8628 | /* Field 4, the address, is omitted (which makes the columns | |
8629 | not line up too nicely with the headers, but the effect | |
8630 | is relatively readable). */ | |
8631 | if (opts.addressprint) | |
112e8700 | 8632 | uiout->field_skip ("addr"); |
fe798b75 | 8633 | annotate_field (5); |
112e8700 | 8634 | uiout->text ("exec"); |
b4d90040 | 8635 | if (c->exec_pathname != NULL) |
fe798b75 | 8636 | { |
112e8700 SM |
8637 | uiout->text (", program \""); |
8638 | uiout->field_string ("what", c->exec_pathname); | |
8639 | uiout->text ("\" "); | |
fe798b75 | 8640 | } |
8ac3646f | 8641 | |
112e8700 SM |
8642 | if (uiout->is_mi_like_p ()) |
8643 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8644 | } |
8645 | ||
8646 | static void | |
8647 | print_mention_catch_exec (struct breakpoint *b) | |
8648 | { | |
8649 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8650 | } | |
8651 | ||
6149aea9 PA |
8652 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8653 | catchpoints. */ | |
8654 | ||
8655 | static void | |
8656 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8657 | { | |
8658 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8659 | print_recreate_thread (b, fp); |
6149aea9 PA |
8660 | } |
8661 | ||
2060206e | 8662 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8663 | |
c906108c | 8664 | static int |
fba45db2 | 8665 | hw_breakpoint_used_count (void) |
c906108c | 8666 | { |
c906108c | 8667 | int i = 0; |
f1310107 TJB |
8668 | struct breakpoint *b; |
8669 | struct bp_location *bl; | |
c906108c SS |
8670 | |
8671 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8672 | { |
d6b74ac4 | 8673 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8674 | for (bl = b->loc; bl; bl = bl->next) |
8675 | { | |
8676 | /* Special types of hardware breakpoints may use more than | |
8677 | one register. */ | |
348d480f | 8678 | i += b->ops->resources_needed (bl); |
f1310107 | 8679 | } |
c5aa993b | 8680 | } |
c906108c SS |
8681 | |
8682 | return i; | |
8683 | } | |
8684 | ||
a1398e0c PA |
8685 | /* Returns the resources B would use if it were a hardware |
8686 | watchpoint. */ | |
8687 | ||
c906108c | 8688 | static int |
a1398e0c | 8689 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8690 | { |
c906108c | 8691 | int i = 0; |
e09342b5 | 8692 | struct bp_location *bl; |
c906108c | 8693 | |
a1398e0c PA |
8694 | if (!breakpoint_enabled (b)) |
8695 | return 0; | |
8696 | ||
8697 | for (bl = b->loc; bl; bl = bl->next) | |
8698 | { | |
8699 | /* Special types of hardware watchpoints may use more than | |
8700 | one register. */ | |
8701 | i += b->ops->resources_needed (bl); | |
8702 | } | |
8703 | ||
8704 | return i; | |
8705 | } | |
8706 | ||
8707 | /* Returns the sum the used resources of all hardware watchpoints of | |
8708 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8709 | the sum of the used resources of all hardware watchpoints of other | |
8710 | types _not_ TYPE. */ | |
8711 | ||
8712 | static int | |
8713 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8714 | enum bptype type, int *other_type_used) | |
8715 | { | |
8716 | int i = 0; | |
8717 | struct breakpoint *b; | |
8718 | ||
c906108c SS |
8719 | *other_type_used = 0; |
8720 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8721 | { |
a1398e0c PA |
8722 | if (b == except) |
8723 | continue; | |
e09342b5 TJB |
8724 | if (!breakpoint_enabled (b)) |
8725 | continue; | |
8726 | ||
a1398e0c PA |
8727 | if (b->type == type) |
8728 | i += hw_watchpoint_use_count (b); | |
8729 | else if (is_hardware_watchpoint (b)) | |
8730 | *other_type_used = 1; | |
e09342b5 TJB |
8731 | } |
8732 | ||
c906108c SS |
8733 | return i; |
8734 | } | |
8735 | ||
c906108c | 8736 | void |
fba45db2 | 8737 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8738 | { |
c5aa993b | 8739 | struct breakpoint *b; |
c906108c SS |
8740 | |
8741 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8742 | { |
cc60f2e3 | 8743 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8744 | { |
b5de0fa7 | 8745 | b->enable_state = bp_call_disabled; |
44702360 | 8746 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8747 | } |
8748 | } | |
c906108c SS |
8749 | } |
8750 | ||
8751 | void | |
fba45db2 | 8752 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8753 | { |
c5aa993b | 8754 | struct breakpoint *b; |
c906108c SS |
8755 | |
8756 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8757 | { |
cc60f2e3 | 8758 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8759 | { |
b5de0fa7 | 8760 | b->enable_state = bp_enabled; |
44702360 | 8761 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8762 | } |
8763 | } | |
c906108c SS |
8764 | } |
8765 | ||
8bea4e01 UW |
8766 | void |
8767 | disable_breakpoints_before_startup (void) | |
8768 | { | |
6c95b8df | 8769 | current_program_space->executing_startup = 1; |
44702360 | 8770 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8771 | } |
8772 | ||
8773 | void | |
8774 | enable_breakpoints_after_startup (void) | |
8775 | { | |
6c95b8df | 8776 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8777 | breakpoint_re_set (); |
8bea4e01 UW |
8778 | } |
8779 | ||
7c16b83e PA |
8780 | /* Create a new single-step breakpoint for thread THREAD, with no |
8781 | locations. */ | |
c906108c | 8782 | |
7c16b83e PA |
8783 | static struct breakpoint * |
8784 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8785 | { | |
b270e6f9 | 8786 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8787 | |
b270e6f9 | 8788 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8789 | &momentary_breakpoint_ops); |
8790 | ||
8791 | b->disposition = disp_donttouch; | |
8792 | b->frame_id = null_frame_id; | |
8793 | ||
8794 | b->thread = thread; | |
8795 | gdb_assert (b->thread != 0); | |
8796 | ||
b270e6f9 | 8797 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8798 | } |
8799 | ||
8800 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8801 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8802 | frame. */ | |
c906108c SS |
8803 | |
8804 | struct breakpoint * | |
a6d9a66e UW |
8805 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8806 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8807 | { |
52f0bd74 | 8808 | struct breakpoint *b; |
edb3359d | 8809 | |
193facb3 JK |
8810 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8811 | tail-called one. */ | |
8812 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8813 | |
06edf0c0 | 8814 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8815 | b->enable_state = bp_enabled; |
8816 | b->disposition = disp_donttouch; | |
818dd999 | 8817 | b->frame_id = frame_id; |
c906108c | 8818 | |
4a64f543 MS |
8819 | /* If we're debugging a multi-threaded program, then we want |
8820 | momentary breakpoints to be active in only a single thread of | |
8821 | control. */ | |
39f77062 | 8822 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8823 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8824 | |
44702360 | 8825 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8826 | |
c906108c SS |
8827 | return b; |
8828 | } | |
611c83ae | 8829 | |
06edf0c0 | 8830 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8831 | The new breakpoint will have type TYPE, use OPS as its |
8832 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8833 | |
06edf0c0 PA |
8834 | static struct breakpoint * |
8835 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8836 | enum bptype type, | |
a1aa2221 LM |
8837 | const struct breakpoint_ops *ops, |
8838 | int loc_enabled) | |
e58b0e63 PA |
8839 | { |
8840 | struct breakpoint *copy; | |
8841 | ||
06edf0c0 | 8842 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8843 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8844 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8845 | |
a6d9a66e | 8846 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8847 | copy->loc->requested_address = orig->loc->requested_address; |
8848 | copy->loc->address = orig->loc->address; | |
8849 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8850 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8851 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8852 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8853 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8854 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8855 | copy->frame_id = orig->frame_id; |
8856 | copy->thread = orig->thread; | |
6c95b8df | 8857 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8858 | |
8859 | copy->enable_state = bp_enabled; | |
8860 | copy->disposition = disp_donttouch; | |
8861 | copy->number = internal_breakpoint_number--; | |
8862 | ||
44702360 | 8863 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8864 | return copy; |
8865 | } | |
8866 | ||
06edf0c0 PA |
8867 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8868 | ORIG is NULL. */ | |
8869 | ||
8870 | struct breakpoint * | |
8871 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8872 | { | |
8873 | /* If there's nothing to clone, then return nothing. */ | |
8874 | if (orig == NULL) | |
8875 | return NULL; | |
8876 | ||
a1aa2221 | 8877 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8878 | } |
8879 | ||
611c83ae | 8880 | struct breakpoint * |
a6d9a66e UW |
8881 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8882 | enum bptype type) | |
611c83ae PA |
8883 | { |
8884 | struct symtab_and_line sal; | |
8885 | ||
8886 | sal = find_pc_line (pc, 0); | |
8887 | sal.pc = pc; | |
8888 | sal.section = find_pc_overlay (pc); | |
8889 | sal.explicit_pc = 1; | |
8890 | ||
a6d9a66e | 8891 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8892 | } |
c906108c | 8893 | \f |
c5aa993b | 8894 | |
c906108c SS |
8895 | /* Tell the user we have just set a breakpoint B. */ |
8896 | ||
8897 | static void | |
fba45db2 | 8898 | mention (struct breakpoint *b) |
c906108c | 8899 | { |
348d480f | 8900 | b->ops->print_mention (b); |
112e8700 | 8901 | if (current_uiout->is_mi_like_p ()) |
fb40c209 | 8902 | return; |
c906108c SS |
8903 | printf_filtered ("\n"); |
8904 | } | |
c906108c | 8905 | \f |
c5aa993b | 8906 | |
1a853c52 PA |
8907 | static int bp_loc_is_permanent (struct bp_location *loc); |
8908 | ||
0d381245 | 8909 | static struct bp_location * |
39d61571 | 8910 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8911 | const struct symtab_and_line *sal) |
8912 | { | |
8913 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8914 | CORE_ADDR adjusted_address; |
8915 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8916 | ||
8917 | if (loc_gdbarch == NULL) | |
8918 | loc_gdbarch = b->gdbarch; | |
8919 | ||
8920 | /* Adjust the breakpoint's address prior to allocating a location. | |
8921 | Once we call allocate_bp_location(), that mostly uninitialized | |
8922 | location will be placed on the location chain. Adjustment of the | |
8923 | breakpoint may cause target_read_memory() to be called and we do | |
8924 | not want its scan of the location chain to find a breakpoint and | |
8925 | location that's only been partially initialized. */ | |
8926 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8927 | sal->pc, b->type); | |
0d381245 | 8928 | |
d30113d4 | 8929 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8930 | loc = allocate_bp_location (b); |
d30113d4 JK |
8931 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8932 | tmp = &((*tmp)->next)) | |
0d381245 | 8933 | ; |
d30113d4 | 8934 | loc->next = *tmp; |
0d381245 | 8935 | *tmp = loc; |
3742cc8b | 8936 | |
0d381245 | 8937 | loc->requested_address = sal->pc; |
3742cc8b | 8938 | loc->address = adjusted_address; |
6c95b8df | 8939 | loc->pspace = sal->pspace; |
729662a5 TT |
8940 | loc->probe.probe = sal->probe; |
8941 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 8942 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8943 | loc->section = sal->section; |
3742cc8b | 8944 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8945 | loc->line_number = sal->line; |
2f202fde | 8946 | loc->symtab = sal->symtab; |
f8eba3c6 | 8947 | |
0e30163f JK |
8948 | set_breakpoint_location_function (loc, |
8949 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 8950 | |
6ae88661 LM |
8951 | /* While by definition, permanent breakpoints are already present in the |
8952 | code, we don't mark the location as inserted. Normally one would expect | |
8953 | that GDB could rely on that breakpoint instruction to stop the program, | |
8954 | thus removing the need to insert its own breakpoint, except that executing | |
8955 | the breakpoint instruction can kill the target instead of reporting a | |
8956 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8957 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8958 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8959 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8960 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8961 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8962 | it manually increments the PC, thus avoiding executing the breakpoint | |
8963 | instruction.) */ | |
1a853c52 | 8964 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8965 | loc->permanent = 1; |
1a853c52 | 8966 | |
0d381245 VP |
8967 | return loc; |
8968 | } | |
514f746b AR |
8969 | \f |
8970 | ||
1cf4d951 | 8971 | /* See breakpoint.h. */ |
514f746b | 8972 | |
1cf4d951 PA |
8973 | int |
8974 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8975 | { |
8976 | int len; | |
8977 | CORE_ADDR addr; | |
1afeeb75 | 8978 | const gdb_byte *bpoint; |
514f746b AR |
8979 | gdb_byte *target_mem; |
8980 | ||
1cf4d951 PA |
8981 | addr = address; |
8982 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8983 | ||
8984 | /* Software breakpoints unsupported? */ | |
8985 | if (bpoint == NULL) | |
8986 | return 0; | |
8987 | ||
224c3ddb | 8988 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
8989 | |
8990 | /* Enable the automatic memory restoration from breakpoints while | |
8991 | we read the memory. Otherwise we could say about our temporary | |
8992 | breakpoints they are permanent. */ | |
cb85b21b TT |
8993 | scoped_restore restore_memory |
8994 | = make_scoped_restore_show_memory_breakpoints (0); | |
1cf4d951 PA |
8995 | |
8996 | if (target_read_memory (address, target_mem, len) == 0 | |
8997 | && memcmp (target_mem, bpoint, len) == 0) | |
cb85b21b | 8998 | return 1; |
1cf4d951 | 8999 | |
cb85b21b | 9000 | return 0; |
1cf4d951 PA |
9001 | } |
9002 | ||
9003 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9004 | return 0 otherwise. */ | |
9005 | ||
9006 | static int | |
9007 | bp_loc_is_permanent (struct bp_location *loc) | |
9008 | { | |
514f746b AR |
9009 | gdb_assert (loc != NULL); |
9010 | ||
244558af LM |
9011 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9012 | attempt to read from the addresses the locations of these breakpoint types | |
9013 | point to. program_breakpoint_here_p, below, will attempt to read | |
9014 | memory. */ | |
9015 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9016 | return 0; | |
9017 | ||
5ed8105e | 9018 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9019 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 9020 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
9021 | } |
9022 | ||
e7e0cddf SS |
9023 | /* Build a command list for the dprintf corresponding to the current |
9024 | settings of the dprintf style options. */ | |
9025 | ||
9026 | static void | |
9027 | update_dprintf_command_list (struct breakpoint *b) | |
9028 | { | |
9029 | char *dprintf_args = b->extra_string; | |
9030 | char *printf_line = NULL; | |
9031 | ||
9032 | if (!dprintf_args) | |
9033 | return; | |
9034 | ||
9035 | dprintf_args = skip_spaces (dprintf_args); | |
9036 | ||
9037 | /* Allow a comma, as it may have terminated a location, but don't | |
9038 | insist on it. */ | |
9039 | if (*dprintf_args == ',') | |
9040 | ++dprintf_args; | |
9041 | dprintf_args = skip_spaces (dprintf_args); | |
9042 | ||
9043 | if (*dprintf_args != '"') | |
9044 | error (_("Bad format string, missing '\"'.")); | |
9045 | ||
d3ce09f5 | 9046 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9047 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9048 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9049 | { |
9050 | if (!dprintf_function) | |
9051 | error (_("No function supplied for dprintf call")); | |
9052 | ||
9053 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9054 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9055 | dprintf_function, | |
9056 | dprintf_channel, | |
9057 | dprintf_args); | |
9058 | else | |
9059 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9060 | dprintf_function, | |
9061 | dprintf_args); | |
9062 | } | |
d3ce09f5 SS |
9063 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9064 | { | |
9065 | if (target_can_run_breakpoint_commands ()) | |
9066 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9067 | else | |
9068 | { | |
9069 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9070 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9071 | } | |
9072 | } | |
e7e0cddf SS |
9073 | else |
9074 | internal_error (__FILE__, __LINE__, | |
9075 | _("Invalid dprintf style.")); | |
9076 | ||
f28045c2 | 9077 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9078 | /* Manufacture a printf sequence. */ |
f28045c2 | 9079 | { |
8d749320 | 9080 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9081 | |
f28045c2 YQ |
9082 | printf_cmd_line->control_type = simple_control; |
9083 | printf_cmd_line->body_count = 0; | |
9084 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9085 | printf_cmd_line->next = NULL; |
f28045c2 | 9086 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9087 | |
93921405 | 9088 | breakpoint_set_commands (b, command_line_up (printf_cmd_line)); |
f28045c2 | 9089 | } |
e7e0cddf SS |
9090 | } |
9091 | ||
9092 | /* Update all dprintf commands, making their command lists reflect | |
9093 | current style settings. */ | |
9094 | ||
9095 | static void | |
9096 | update_dprintf_commands (char *args, int from_tty, | |
9097 | struct cmd_list_element *c) | |
9098 | { | |
9099 | struct breakpoint *b; | |
9100 | ||
9101 | ALL_BREAKPOINTS (b) | |
9102 | { | |
9103 | if (b->type == bp_dprintf) | |
9104 | update_dprintf_command_list (b); | |
9105 | } | |
9106 | } | |
c3f6f71d | 9107 | |
f00aae0f KS |
9108 | /* Create a breakpoint with SAL as location. Use LOCATION |
9109 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9110 | as condition expression. If LOCATION is NULL then create an |
9111 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9112 | |
9113 | static void | |
d9b3f62e | 9114 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 9115 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9116 | event_location_up &&location, |
e1e01040 PA |
9117 | gdb::unique_xmalloc_ptr<char> filter, |
9118 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9119 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9120 | enum bptype type, enum bpdisp disposition, |
9121 | int thread, int task, int ignore_count, | |
c0a91b2b | 9122 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9123 | int enabled, int internal, unsigned flags, |
9124 | int display_canonical) | |
018d34a4 | 9125 | { |
0d381245 | 9126 | int i; |
018d34a4 VP |
9127 | |
9128 | if (type == bp_hardware_breakpoint) | |
9129 | { | |
fbbd034e AS |
9130 | int target_resources_ok; |
9131 | ||
9132 | i = hw_breakpoint_used_count (); | |
9133 | target_resources_ok = | |
9134 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9135 | i + 1, 0); |
9136 | if (target_resources_ok == 0) | |
9137 | error (_("No hardware breakpoint support in the target.")); | |
9138 | else if (target_resources_ok < 0) | |
9139 | error (_("Hardware breakpoints used exceeds limit.")); | |
9140 | } | |
9141 | ||
6c5b2ebe | 9142 | gdb_assert (!sals.empty ()); |
6c95b8df | 9143 | |
6c5b2ebe | 9144 | for (const auto &sal : sals) |
0d381245 | 9145 | { |
0d381245 VP |
9146 | struct bp_location *loc; |
9147 | ||
9148 | if (from_tty) | |
5af949e3 UW |
9149 | { |
9150 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9151 | if (!loc_gdbarch) | |
9152 | loc_gdbarch = gdbarch; | |
9153 | ||
9154 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9155 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9156 | } |
0d381245 | 9157 | |
6c5b2ebe | 9158 | if (&sal == &sals[0]) |
0d381245 | 9159 | { |
d9b3f62e | 9160 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9161 | b->thread = thread; |
4a306c9a | 9162 | b->task = task; |
855a6e68 | 9163 | |
e1e01040 PA |
9164 | b->cond_string = cond_string.release (); |
9165 | b->extra_string = extra_string.release (); | |
0d381245 | 9166 | b->ignore_count = ignore_count; |
41447f92 | 9167 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9168 | b->disposition = disposition; |
6c95b8df | 9169 | |
44f238bb PA |
9170 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9171 | b->loc->inserted = 1; | |
9172 | ||
0fb4aa4b PA |
9173 | if (type == bp_static_tracepoint) |
9174 | { | |
d9b3f62e | 9175 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9176 | struct static_tracepoint_marker marker; |
9177 | ||
983af33b | 9178 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9179 | { |
9180 | /* We already know the marker exists, otherwise, we | |
9181 | wouldn't see a sal for it. */ | |
d28cd78a TT |
9182 | const char *p |
9183 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 9184 | const char *endp; |
0fb4aa4b | 9185 | char *marker_str; |
0fb4aa4b | 9186 | |
f1735a53 | 9187 | p = skip_spaces (p); |
0fb4aa4b | 9188 | |
f1735a53 | 9189 | endp = skip_to_space (p); |
0fb4aa4b PA |
9190 | |
9191 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9192 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9193 | |
3e43a32a MS |
9194 | printf_filtered (_("Probed static tracepoint " |
9195 | "marker \"%s\"\n"), | |
d9b3f62e | 9196 | t->static_trace_marker_id); |
0fb4aa4b PA |
9197 | } |
9198 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9199 | { | |
d9b3f62e | 9200 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9201 | release_static_tracepoint_marker (&marker); |
9202 | ||
3e43a32a MS |
9203 | printf_filtered (_("Probed static tracepoint " |
9204 | "marker \"%s\"\n"), | |
d9b3f62e | 9205 | t->static_trace_marker_id); |
0fb4aa4b PA |
9206 | } |
9207 | else | |
3e43a32a MS |
9208 | warning (_("Couldn't determine the static " |
9209 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9210 | } |
9211 | ||
0d381245 VP |
9212 | loc = b->loc; |
9213 | } | |
9214 | else | |
018d34a4 | 9215 | { |
39d61571 | 9216 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9217 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9218 | loc->inserted = 1; | |
0d381245 VP |
9219 | } |
9220 | ||
9221 | if (b->cond_string) | |
9222 | { | |
bbc13ae3 KS |
9223 | const char *arg = b->cond_string; |
9224 | ||
1bb9788d TT |
9225 | loc->cond = parse_exp_1 (&arg, loc->address, |
9226 | block_for_pc (loc->address), 0); | |
0d381245 | 9227 | if (*arg) |
588ae58c | 9228 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9229 | } |
e7e0cddf SS |
9230 | |
9231 | /* Dynamic printf requires and uses additional arguments on the | |
9232 | command line, otherwise it's an error. */ | |
9233 | if (type == bp_dprintf) | |
9234 | { | |
9235 | if (b->extra_string) | |
9236 | update_dprintf_command_list (b); | |
9237 | else | |
9238 | error (_("Format string required")); | |
9239 | } | |
9240 | else if (b->extra_string) | |
588ae58c | 9241 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9242 | } |
018d34a4 | 9243 | |
56435ebe | 9244 | b->display_canonical = display_canonical; |
f00aae0f | 9245 | if (location != NULL) |
d28cd78a | 9246 | b->location = std::move (location); |
018d34a4 | 9247 | else |
d28cd78a | 9248 | b->location = new_address_location (b->loc->address, NULL, 0); |
e1e01040 | 9249 | b->filter = filter.release (); |
d9b3f62e | 9250 | } |
018d34a4 | 9251 | |
d9b3f62e PA |
9252 | static void |
9253 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 9254 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9255 | event_location_up &&location, |
e1e01040 PA |
9256 | gdb::unique_xmalloc_ptr<char> filter, |
9257 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9258 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9259 | enum bptype type, enum bpdisp disposition, |
9260 | int thread, int task, int ignore_count, | |
c0a91b2b | 9261 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9262 | int enabled, int internal, unsigned flags, |
9263 | int display_canonical) | |
d9b3f62e | 9264 | { |
a5e364af | 9265 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 9266 | |
a5e364af | 9267 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 9268 | sals, std::move (location), |
e1e01040 PA |
9269 | std::move (filter), |
9270 | std::move (cond_string), | |
9271 | std::move (extra_string), | |
d9b3f62e PA |
9272 | type, disposition, |
9273 | thread, task, ignore_count, | |
9274 | ops, from_tty, | |
44f238bb PA |
9275 | enabled, internal, flags, |
9276 | display_canonical); | |
d9b3f62e | 9277 | |
b270e6f9 | 9278 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
9279 | } |
9280 | ||
9281 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9282 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9283 | value. COND_STRING, if not NULL, specified the condition to be | |
9284 | used for all breakpoints. Essentially the only case where | |
9285 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9286 | function. In that case, it's still not possible to specify | |
9287 | separate conditions for different overloaded functions, so | |
9288 | we take just a single condition string. | |
9289 | ||
c3f6f71d | 9290 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9291 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9292 | array contents). If the function fails (error() is called), the |
9293 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9294 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9295 | |
9296 | static void | |
8cdf0e15 | 9297 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9298 | struct linespec_result *canonical, |
e1e01040 PA |
9299 | gdb::unique_xmalloc_ptr<char> cond_string, |
9300 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
9301 | enum bptype type, enum bpdisp disposition, |
9302 | int thread, int task, int ignore_count, | |
c0a91b2b | 9303 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9304 | int enabled, int internal, unsigned flags) |
c906108c | 9305 | { |
f8eba3c6 | 9306 | if (canonical->pre_expanded) |
6c5b2ebe | 9307 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 9308 | |
6c5b2ebe | 9309 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 9310 | { |
f00aae0f | 9311 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9312 | 'break', without arguments. */ |
ffc2605c | 9313 | event_location_up location |
f00aae0f | 9314 | = (canonical->location != NULL |
8e9e35b1 | 9315 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 9316 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 9317 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 9318 | |
6c5b2ebe | 9319 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 9320 | std::move (location), |
e1e01040 PA |
9321 | std::move (filter_string), |
9322 | std::move (cond_string), | |
9323 | std::move (extra_string), | |
e7e0cddf | 9324 | type, disposition, |
84f4c1fe | 9325 | thread, task, ignore_count, ops, |
44f238bb | 9326 | from_tty, enabled, internal, flags, |
56435ebe | 9327 | canonical->special_display); |
c3f6f71d | 9328 | } |
c3f6f71d | 9329 | } |
c906108c | 9330 | |
f00aae0f | 9331 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9332 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9333 | addresses found. LOCATION points to the end of the SAL (for |
9334 | linespec locations). | |
9998af43 TJB |
9335 | |
9336 | The array and the line spec strings are allocated on the heap, it is | |
9337 | the caller's responsibility to free them. */ | |
c906108c | 9338 | |
b9362cc7 | 9339 | static void |
f00aae0f | 9340 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9341 | struct linespec_result *canonical) |
c3f6f71d | 9342 | { |
f00aae0f KS |
9343 | struct symtab_and_line cursal; |
9344 | ||
9345 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9346 | { | |
9347 | const char *address = get_linespec_location (location); | |
9348 | ||
9349 | if (address == NULL) | |
9350 | { | |
9351 | /* The last displayed codepoint, if it's valid, is our default | |
9352 | breakpoint address. */ | |
9353 | if (last_displayed_sal_is_valid ()) | |
9354 | { | |
f00aae0f KS |
9355 | /* Set sal's pspace, pc, symtab, and line to the values |
9356 | corresponding to the last call to print_frame_info. | |
9357 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9358 | as the breakpoint line number is inappropriate otherwise. | |
9359 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
9360 | symtab_and_line sal = get_last_displayed_sal (); |
9361 | CORE_ADDR pc = sal.pc; | |
9362 | ||
f00aae0f KS |
9363 | sal = find_pc_line (pc, 0); |
9364 | ||
9365 | /* "break" without arguments is equivalent to "break *PC" | |
9366 | where PC is the last displayed codepoint's address. So | |
9367 | make sure to set sal.explicit_pc to prevent GDB from | |
9368 | trying to expand the list of sals to include all other | |
9369 | instances with the same symtab and line. */ | |
9370 | sal.pc = pc; | |
9371 | sal.explicit_pc = 1; | |
9372 | ||
6c5b2ebe PA |
9373 | struct linespec_sals lsal; |
9374 | lsal.sals = {sal}; | |
f00aae0f KS |
9375 | lsal.canonical = NULL; |
9376 | ||
6c5b2ebe | 9377 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
9378 | return; |
9379 | } | |
9380 | else | |
9381 | error (_("No default breakpoint address now.")); | |
c906108c | 9382 | } |
c906108c | 9383 | } |
f00aae0f KS |
9384 | |
9385 | /* Force almost all breakpoints to be in terms of the | |
9386 | current_source_symtab (which is decode_line_1's default). | |
9387 | This should produce the results we want almost all of the | |
9388 | time while leaving default_breakpoint_* alone. | |
9389 | ||
9390 | ObjC: However, don't match an Objective-C method name which | |
9391 | may have a '+' or '-' succeeded by a '['. */ | |
9392 | cursal = get_current_source_symtab_and_line (); | |
9393 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9394 | { |
f00aae0f | 9395 | const char *address = NULL; |
cc80f267 | 9396 | |
f00aae0f KS |
9397 | if (event_location_type (location) == LINESPEC_LOCATION) |
9398 | address = get_linespec_location (location); | |
cc80f267 | 9399 | |
f00aae0f KS |
9400 | if (!cursal.symtab |
9401 | || (address != NULL | |
9402 | && strchr ("+-", address[0]) != NULL | |
9403 | && address[1] != '[')) | |
9404 | { | |
c2f4122d | 9405 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9406 | get_last_displayed_symtab (), |
9407 | get_last_displayed_line (), | |
9408 | canonical, NULL, NULL); | |
9409 | return; | |
9410 | } | |
c906108c | 9411 | } |
f00aae0f | 9412 | |
c2f4122d | 9413 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9414 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9415 | } |
c906108c | 9416 | |
c906108c | 9417 | |
c3f6f71d | 9418 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9419 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9420 | |
b9362cc7 | 9421 | static void |
6c5b2ebe | 9422 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9423 | { |
6c5b2ebe PA |
9424 | for (auto &sal : sals) |
9425 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9426 | } |
9427 | ||
7a697b8d SS |
9428 | /* Fast tracepoints may have restrictions on valid locations. For |
9429 | instance, a fast tracepoint using a jump instead of a trap will | |
9430 | likely have to overwrite more bytes than a trap would, and so can | |
9431 | only be placed where the instruction is longer than the jump, or a | |
9432 | multi-instruction sequence does not have a jump into the middle of | |
9433 | it, etc. */ | |
9434 | ||
9435 | static void | |
9436 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9437 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9438 | { |
6c5b2ebe | 9439 | int rslt; |
7a697b8d SS |
9440 | char *msg; |
9441 | struct cleanup *old_chain; | |
9442 | ||
6c5b2ebe | 9443 | for (const auto &sal : sals) |
7a697b8d | 9444 | { |
f8eba3c6 TT |
9445 | struct gdbarch *sarch; |
9446 | ||
6c5b2ebe | 9447 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9448 | /* We fall back to GDBARCH if there is no architecture |
9449 | associated with SAL. */ | |
9450 | if (sarch == NULL) | |
9451 | sarch = gdbarch; | |
6c5b2ebe | 9452 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg); |
7a697b8d SS |
9453 | old_chain = make_cleanup (xfree, msg); |
9454 | ||
9455 | if (!rslt) | |
53c3572a | 9456 | error (_("May not have a fast tracepoint at %s%s"), |
6c5b2ebe | 9457 | paddress (sarch, sal.pc), (msg ? msg : "")); |
7a697b8d SS |
9458 | |
9459 | do_cleanups (old_chain); | |
9460 | } | |
9461 | } | |
9462 | ||
018d34a4 VP |
9463 | /* Given TOK, a string specification of condition and thread, as |
9464 | accepted by the 'break' command, extract the condition | |
9465 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9466 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9467 | If no condition is found, *COND_STRING is set to NULL. |
9468 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9469 | |
9470 | static void | |
bbc13ae3 | 9471 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9472 | char **cond_string, int *thread, int *task, |
9473 | char **rest) | |
018d34a4 VP |
9474 | { |
9475 | *cond_string = NULL; | |
9476 | *thread = -1; | |
ed1d1739 KS |
9477 | *task = 0; |
9478 | *rest = NULL; | |
9479 | ||
018d34a4 VP |
9480 | while (tok && *tok) |
9481 | { | |
bbc13ae3 | 9482 | const char *end_tok; |
018d34a4 | 9483 | int toklen; |
bbc13ae3 KS |
9484 | const char *cond_start = NULL; |
9485 | const char *cond_end = NULL; | |
cc59ec59 | 9486 | |
f1735a53 | 9487 | tok = skip_spaces (tok); |
e7e0cddf SS |
9488 | |
9489 | if ((*tok == '"' || *tok == ',') && rest) | |
9490 | { | |
9491 | *rest = savestring (tok, strlen (tok)); | |
9492 | return; | |
9493 | } | |
9494 | ||
f1735a53 | 9495 | end_tok = skip_to_space (tok); |
d634f2de | 9496 | |
018d34a4 | 9497 | toklen = end_tok - tok; |
d634f2de | 9498 | |
018d34a4 VP |
9499 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9500 | { | |
9501 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9502 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9503 | cond_end = tok; |
d634f2de | 9504 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9505 | } |
9506 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9507 | { | |
5d5658a1 PA |
9508 | const char *tmptok; |
9509 | struct thread_info *thr; | |
d634f2de | 9510 | |
018d34a4 | 9511 | tok = end_tok + 1; |
5d5658a1 | 9512 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9513 | if (tok == tmptok) |
9514 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9515 | *thread = thr->global_num; |
bbc13ae3 | 9516 | tok = tmptok; |
018d34a4 | 9517 | } |
4a306c9a JB |
9518 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9519 | { | |
9520 | char *tmptok; | |
9521 | ||
9522 | tok = end_tok + 1; | |
bbc13ae3 | 9523 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9524 | if (tok == tmptok) |
9525 | error (_("Junk after task keyword.")); | |
9526 | if (!valid_task_id (*task)) | |
b6199126 | 9527 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9528 | tok = tmptok; |
4a306c9a | 9529 | } |
e7e0cddf SS |
9530 | else if (rest) |
9531 | { | |
9532 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9533 | return; |
e7e0cddf | 9534 | } |
018d34a4 VP |
9535 | else |
9536 | error (_("Junk at end of arguments.")); | |
9537 | } | |
9538 | } | |
9539 | ||
0fb4aa4b PA |
9540 | /* Decode a static tracepoint marker spec. */ |
9541 | ||
6c5b2ebe | 9542 | static std::vector<symtab_and_line> |
f00aae0f | 9543 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9544 | { |
9545 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
0fb4aa4b | 9546 | struct cleanup *old_chain; |
f00aae0f KS |
9547 | const char *p = &(*arg_p)[3]; |
9548 | const char *endp; | |
0fb4aa4b PA |
9549 | char *marker_str; |
9550 | int i; | |
9551 | ||
f1735a53 | 9552 | p = skip_spaces (p); |
0fb4aa4b | 9553 | |
f1735a53 | 9554 | endp = skip_to_space (p); |
0fb4aa4b PA |
9555 | |
9556 | marker_str = savestring (p, endp - p); | |
9557 | old_chain = make_cleanup (xfree, marker_str); | |
9558 | ||
9559 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9560 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9561 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9562 | ||
6c5b2ebe PA |
9563 | std::vector<symtab_and_line> sals; |
9564 | sals.reserve (VEC_length(static_tracepoint_marker_p, markers)); | |
0fb4aa4b | 9565 | |
6c5b2ebe | 9566 | for (i = 0; i < VEC_length(static_tracepoint_marker_p, markers); i++) |
0fb4aa4b PA |
9567 | { |
9568 | struct static_tracepoint_marker *marker; | |
9569 | ||
9570 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9571 | ||
51abb421 | 9572 | symtab_and_line sal = find_pc_line (marker->address, 0); |
6c5b2ebe PA |
9573 | sal.pc = marker->address; |
9574 | sals.push_back (sal); | |
0fb4aa4b PA |
9575 | |
9576 | release_static_tracepoint_marker (marker); | |
9577 | } | |
9578 | ||
9579 | do_cleanups (old_chain); | |
9580 | ||
9581 | *arg_p = endp; | |
9582 | return sals; | |
9583 | } | |
9584 | ||
f00aae0f | 9585 | /* See breakpoint.h. */ |
0101ce28 | 9586 | |
8cdf0e15 VP |
9587 | int |
9588 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9589 | const struct event_location *location, |
9590 | const char *cond_string, | |
9591 | int thread, const char *extra_string, | |
f00aae0f | 9592 | int parse_extra, |
0fb4aa4b | 9593 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9594 | int ignore_count, |
9595 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9596 | const struct breakpoint_ops *ops, |
44f238bb PA |
9597 | int from_tty, int enabled, int internal, |
9598 | unsigned flags) | |
c3f6f71d | 9599 | { |
7efd8fc2 | 9600 | struct linespec_result canonical; |
80c99de1 | 9601 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9602 | int pending = 0; |
4a306c9a | 9603 | int task = 0; |
86b17b60 | 9604 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9605 | |
348d480f PA |
9606 | gdb_assert (ops != NULL); |
9607 | ||
f00aae0f KS |
9608 | /* If extra_string isn't useful, set it to NULL. */ |
9609 | if (extra_string != NULL && *extra_string == '\0') | |
9610 | extra_string = NULL; | |
9611 | ||
492d29ea | 9612 | TRY |
b78a6381 | 9613 | { |
f00aae0f | 9614 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9615 | } |
492d29ea | 9616 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9617 | { |
492d29ea PA |
9618 | /* If caller is interested in rc value from parse, set |
9619 | value. */ | |
9620 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9621 | { |
05ff989b AC |
9622 | /* If pending breakpoint support is turned off, throw |
9623 | error. */ | |
fa8d40ab JJ |
9624 | |
9625 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9626 | throw_exception (e); |
9627 | ||
9628 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9629 | |
05ff989b AC |
9630 | /* If pending breakpoint support is auto query and the user |
9631 | selects no, then simply return the error code. */ | |
059fb39f | 9632 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9633 | && !nquery (_("Make %s pending on future shared library load? "), |
9634 | bptype_string (type_wanted))) | |
fd9b8c24 | 9635 | return 0; |
fa8d40ab | 9636 | |
05ff989b AC |
9637 | /* At this point, either the user was queried about setting |
9638 | a pending breakpoint and selected yes, or pending | |
9639 | breakpoint behavior is on and thus a pending breakpoint | |
9640 | is defaulted on behalf of the user. */ | |
f00aae0f | 9641 | pending = 1; |
0101ce28 | 9642 | } |
492d29ea PA |
9643 | else |
9644 | throw_exception (e); | |
0101ce28 | 9645 | } |
492d29ea PA |
9646 | END_CATCH |
9647 | ||
6c5b2ebe | 9648 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9649 | return 0; |
c3f6f71d | 9650 | |
c3f6f71d JM |
9651 | /* ----------------------------- SNIP ----------------------------- |
9652 | Anything added to the cleanup chain beyond this point is assumed | |
9653 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9654 | then the memory is not reclaimed. */ |
9655 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9656 | |
c3f6f71d JM |
9657 | /* Resolve all line numbers to PC's and verify that the addresses |
9658 | are ok for the target. */ | |
0101ce28 | 9659 | if (!pending) |
f8eba3c6 | 9660 | { |
6c5b2ebe PA |
9661 | for (auto &lsal : canonical.lsals) |
9662 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9663 | } |
c3f6f71d | 9664 | |
7a697b8d | 9665 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9666 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9667 | { |
6c5b2ebe PA |
9668 | for (const auto &lsal : canonical.lsals) |
9669 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9670 | } |
7a697b8d | 9671 | |
c3f6f71d JM |
9672 | /* Verify that condition can be parsed, before setting any |
9673 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9674 | breakpoint. */ |
0101ce28 | 9675 | if (!pending) |
c3f6f71d | 9676 | { |
e1e01040 PA |
9677 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9678 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9679 | ||
f00aae0f | 9680 | if (parse_extra) |
72b2ff0e | 9681 | { |
0878d0fa | 9682 | char *rest; |
e1e01040 | 9683 | char *cond; |
52d361e1 | 9684 | |
6c5b2ebe | 9685 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9686 | |
0878d0fa YQ |
9687 | /* Here we only parse 'arg' to separate condition |
9688 | from thread number, so parsing in context of first | |
9689 | sal is OK. When setting the breakpoint we'll | |
9690 | re-parse it in context of each sal. */ | |
9691 | ||
6c5b2ebe | 9692 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9693 | &cond, &thread, &task, &rest); |
9694 | cond_string_copy.reset (cond); | |
9695 | extra_string_copy.reset (rest); | |
72b2ff0e | 9696 | } |
2f069f6f | 9697 | else |
72b2ff0e | 9698 | { |
f00aae0f KS |
9699 | if (type_wanted != bp_dprintf |
9700 | && extra_string != NULL && *extra_string != '\0') | |
9701 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9702 | |
9703 | /* Create a private copy of condition string. */ | |
9704 | if (cond_string) | |
e1e01040 | 9705 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9706 | /* Create a private copy of any extra string. */ |
9707 | if (extra_string) | |
e1e01040 | 9708 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9709 | } |
0fb4aa4b | 9710 | |
52d361e1 | 9711 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9712 | std::move (cond_string_copy), |
9713 | std::move (extra_string_copy), | |
9714 | type_wanted, | |
d9b3f62e PA |
9715 | tempflag ? disp_del : disp_donttouch, |
9716 | thread, task, ignore_count, ops, | |
44f238bb | 9717 | from_tty, enabled, internal, flags); |
c906108c | 9718 | } |
0101ce28 JJ |
9719 | else |
9720 | { | |
a5e364af | 9721 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9722 | |
a5e364af | 9723 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9724 | b->location = copy_event_location (location); |
bfccc43c | 9725 | |
f00aae0f KS |
9726 | if (parse_extra) |
9727 | b->cond_string = NULL; | |
e12c7713 MK |
9728 | else |
9729 | { | |
9730 | /* Create a private copy of condition string. */ | |
e1e01040 | 9731 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9732 | b->thread = thread; |
e12c7713 | 9733 | } |
f00aae0f KS |
9734 | |
9735 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9736 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9737 | b->ignore_count = ignore_count; |
0101ce28 | 9738 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9739 | b->condition_not_parsed = 1; |
41447f92 | 9740 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9741 | if ((type_wanted != bp_breakpoint |
9742 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9743 | b->pspace = current_program_space; |
8bea4e01 | 9744 | |
b270e6f9 | 9745 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9746 | } |
9747 | ||
6c5b2ebe | 9748 | if (canonical.lsals.size () > 1) |
95a42b64 | 9749 | { |
3e43a32a MS |
9750 | warning (_("Multiple breakpoints were set.\nUse the " |
9751 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9752 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9753 | } |
9754 | ||
80c99de1 PA |
9755 | /* That's it. Discard the cleanups for data inserted into the |
9756 | breakpoint. */ | |
9757 | discard_cleanups (bkpt_chain); | |
217dc9e2 | 9758 | |
80c99de1 | 9759 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9760 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9761 | |
9762 | return 1; | |
c3f6f71d | 9763 | } |
c906108c | 9764 | |
348d480f | 9765 | /* Set a breakpoint. |
72b2ff0e VP |
9766 | ARG is a string describing breakpoint address, |
9767 | condition, and thread. | |
9768 | FLAG specifies if a breakpoint is hardware on, | |
9769 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9770 | and BP_TEMPFLAG. */ | |
348d480f | 9771 | |
98deb0da | 9772 | static void |
72b2ff0e | 9773 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9774 | { |
72b2ff0e | 9775 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9776 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9777 | ? bp_hardware_breakpoint | |
9778 | : bp_breakpoint); | |
55aa24fb | 9779 | struct breakpoint_ops *ops; |
f00aae0f | 9780 | |
ffc2605c | 9781 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9782 | |
9783 | /* Matching breakpoints on probes. */ | |
5b56227b | 9784 | if (location != NULL |
ffc2605c | 9785 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9786 | ops = &bkpt_probe_breakpoint_ops; |
9787 | else | |
9788 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9789 | |
8cdf0e15 | 9790 | create_breakpoint (get_current_arch (), |
ffc2605c | 9791 | location.get (), |
f00aae0f | 9792 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9793 | tempflag, type_wanted, |
8cdf0e15 VP |
9794 | 0 /* Ignore count */, |
9795 | pending_break_support, | |
55aa24fb | 9796 | ops, |
8cdf0e15 | 9797 | from_tty, |
84f4c1fe | 9798 | 1 /* enabled */, |
44f238bb PA |
9799 | 0 /* internal */, |
9800 | 0); | |
c906108c SS |
9801 | } |
9802 | ||
c906108c SS |
9803 | /* Helper function for break_command_1 and disassemble_command. */ |
9804 | ||
9805 | void | |
fba45db2 | 9806 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9807 | { |
9808 | CORE_ADDR pc; | |
9809 | ||
9810 | if (sal->pc == 0 && sal->symtab != NULL) | |
9811 | { | |
9812 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9813 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9814 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9815 | sal->pc = pc; |
6a048695 | 9816 | |
4a64f543 MS |
9817 | /* If this SAL corresponds to a breakpoint inserted using a line |
9818 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9819 | if (sal->explicit_line) |
059acae7 | 9820 | skip_prologue_sal (sal); |
c906108c SS |
9821 | } |
9822 | ||
9823 | if (sal->section == 0 && sal->symtab != NULL) | |
9824 | { | |
346d1dfe | 9825 | const struct blockvector *bv; |
3977b71f | 9826 | const struct block *b; |
c5aa993b | 9827 | struct symbol *sym; |
c906108c | 9828 | |
43f3e411 DE |
9829 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9830 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9831 | if (bv != NULL) |
9832 | { | |
7f0df278 | 9833 | sym = block_linkage_function (b); |
c906108c SS |
9834 | if (sym != NULL) |
9835 | { | |
eb822aa6 DE |
9836 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9837 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9838 | sym); | |
c906108c SS |
9839 | } |
9840 | else | |
9841 | { | |
4a64f543 MS |
9842 | /* It really is worthwhile to have the section, so we'll |
9843 | just have to look harder. This case can be executed | |
9844 | if we have line numbers but no functions (as can | |
9845 | happen in assembly source). */ | |
c906108c | 9846 | |
5ed8105e | 9847 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9848 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9849 | |
5ed8105e | 9850 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9851 | if (msym.minsym) |
efd66ac6 | 9852 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9853 | } |
9854 | } | |
9855 | } | |
9856 | } | |
9857 | ||
9858 | void | |
fba45db2 | 9859 | break_command (char *arg, int from_tty) |
c906108c | 9860 | { |
db107f19 | 9861 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9862 | } |
9863 | ||
c906108c | 9864 | void |
fba45db2 | 9865 | tbreak_command (char *arg, int from_tty) |
c906108c | 9866 | { |
db107f19 | 9867 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9868 | } |
9869 | ||
c906108c | 9870 | static void |
fba45db2 | 9871 | hbreak_command (char *arg, int from_tty) |
c906108c | 9872 | { |
db107f19 | 9873 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9874 | } |
9875 | ||
9876 | static void | |
fba45db2 | 9877 | thbreak_command (char *arg, int from_tty) |
c906108c | 9878 | { |
db107f19 | 9879 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9880 | } |
9881 | ||
9882 | static void | |
fba45db2 | 9883 | stop_command (char *arg, int from_tty) |
c906108c | 9884 | { |
a3f17187 | 9885 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9886 | Usage: stop in <function | address>\n\ |
a3f17187 | 9887 | stop at <line>\n")); |
c906108c SS |
9888 | } |
9889 | ||
9890 | static void | |
fba45db2 | 9891 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9892 | { |
9893 | int badInput = 0; | |
9894 | ||
c5aa993b | 9895 | if (arg == (char *) NULL) |
c906108c SS |
9896 | badInput = 1; |
9897 | else if (*arg != '*') | |
9898 | { | |
9899 | char *argptr = arg; | |
9900 | int hasColon = 0; | |
9901 | ||
4a64f543 | 9902 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9903 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9904 | function/method name. */ |
c906108c | 9905 | while (*argptr && !hasColon) |
c5aa993b JM |
9906 | { |
9907 | hasColon = (*argptr == ':'); | |
9908 | argptr++; | |
9909 | } | |
c906108c SS |
9910 | |
9911 | if (hasColon) | |
c5aa993b | 9912 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9913 | else |
c5aa993b | 9914 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9915 | } |
9916 | ||
9917 | if (badInput) | |
a3f17187 | 9918 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9919 | else |
db107f19 | 9920 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9921 | } |
9922 | ||
9923 | static void | |
fba45db2 | 9924 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9925 | { |
9926 | int badInput = 0; | |
9927 | ||
c5aa993b | 9928 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9929 | badInput = 1; |
9930 | else | |
9931 | { | |
9932 | char *argptr = arg; | |
9933 | int hasColon = 0; | |
9934 | ||
4a64f543 MS |
9935 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9936 | it is probably a line number. */ | |
c906108c | 9937 | while (*argptr && !hasColon) |
c5aa993b JM |
9938 | { |
9939 | hasColon = (*argptr == ':'); | |
9940 | argptr++; | |
9941 | } | |
c906108c SS |
9942 | |
9943 | if (hasColon) | |
c5aa993b | 9944 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9945 | else |
c5aa993b | 9946 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9947 | } |
9948 | ||
9949 | if (badInput) | |
a3f17187 | 9950 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9951 | else |
db107f19 | 9952 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9953 | } |
9954 | ||
e7e0cddf SS |
9955 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9956 | with a prewired command list consisting of a single output command, | |
9957 | built from extra arguments supplied on the dprintf command | |
9958 | line. */ | |
9959 | ||
da821c7b | 9960 | static void |
e7e0cddf SS |
9961 | dprintf_command (char *arg, int from_tty) |
9962 | { | |
ffc2605c | 9963 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9964 | |
9965 | /* If non-NULL, ARG should have been advanced past the location; | |
9966 | the next character must be ','. */ | |
9967 | if (arg != NULL) | |
9968 | { | |
9969 | if (arg[0] != ',' || arg[1] == '\0') | |
9970 | error (_("Format string required")); | |
9971 | else | |
9972 | { | |
9973 | /* Skip the comma. */ | |
9974 | ++arg; | |
9975 | } | |
9976 | } | |
9977 | ||
e7e0cddf | 9978 | create_breakpoint (get_current_arch (), |
ffc2605c | 9979 | location.get (), |
f00aae0f | 9980 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9981 | 0, bp_dprintf, |
9982 | 0 /* Ignore count */, | |
9983 | pending_break_support, | |
9984 | &dprintf_breakpoint_ops, | |
9985 | from_tty, | |
9986 | 1 /* enabled */, | |
9987 | 0 /* internal */, | |
9988 | 0); | |
9989 | } | |
9990 | ||
d3ce09f5 SS |
9991 | static void |
9992 | agent_printf_command (char *arg, int from_tty) | |
9993 | { | |
9994 | error (_("May only run agent-printf on the target")); | |
9995 | } | |
9996 | ||
f1310107 TJB |
9997 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9998 | ranged breakpoints. */ | |
9999 | ||
10000 | static int | |
10001 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10002 | struct address_space *aspace, | |
09ac7c10 TT |
10003 | CORE_ADDR bp_addr, |
10004 | const struct target_waitstatus *ws) | |
f1310107 | 10005 | { |
09ac7c10 | 10006 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10007 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10008 | return 0; |
10009 | ||
f1310107 TJB |
10010 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10011 | bl->length, aspace, bp_addr); | |
10012 | } | |
10013 | ||
10014 | /* Implement the "resources_needed" breakpoint_ops method for | |
10015 | ranged breakpoints. */ | |
10016 | ||
10017 | static int | |
10018 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10019 | { | |
10020 | return target_ranged_break_num_registers (); | |
10021 | } | |
10022 | ||
10023 | /* Implement the "print_it" breakpoint_ops method for | |
10024 | ranged breakpoints. */ | |
10025 | ||
10026 | static enum print_stop_action | |
348d480f | 10027 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10028 | { |
348d480f | 10029 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10030 | struct bp_location *bl = b->loc; |
79a45e25 | 10031 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10032 | |
10033 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10034 | ||
10035 | /* Ranged breakpoints have only one location. */ | |
10036 | gdb_assert (bl && bl->next == NULL); | |
10037 | ||
10038 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10039 | |
10040 | maybe_print_thread_hit_breakpoint (uiout); | |
10041 | ||
f1310107 | 10042 | if (b->disposition == disp_del) |
112e8700 | 10043 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 10044 | else |
112e8700 SM |
10045 | uiout->text ("Ranged breakpoint "); |
10046 | if (uiout->is_mi_like_p ()) | |
f1310107 | 10047 | { |
112e8700 | 10048 | uiout->field_string ("reason", |
f1310107 | 10049 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 10050 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 10051 | } |
112e8700 SM |
10052 | uiout->field_int ("bkptno", b->number); |
10053 | uiout->text (", "); | |
f1310107 TJB |
10054 | |
10055 | return PRINT_SRC_AND_LOC; | |
10056 | } | |
10057 | ||
10058 | /* Implement the "print_one" breakpoint_ops method for | |
10059 | ranged breakpoints. */ | |
10060 | ||
10061 | static void | |
10062 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10063 | struct bp_location **last_loc) | |
10064 | { | |
10065 | struct bp_location *bl = b->loc; | |
10066 | struct value_print_options opts; | |
79a45e25 | 10067 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10068 | |
10069 | /* Ranged breakpoints have only one location. */ | |
10070 | gdb_assert (bl && bl->next == NULL); | |
10071 | ||
10072 | get_user_print_options (&opts); | |
10073 | ||
10074 | if (opts.addressprint) | |
10075 | /* We don't print the address range here, it will be printed later | |
10076 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 10077 | uiout->field_skip ("addr"); |
f1310107 TJB |
10078 | annotate_field (5); |
10079 | print_breakpoint_location (b, bl); | |
10080 | *last_loc = bl; | |
10081 | } | |
10082 | ||
10083 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10084 | ranged breakpoints. */ | |
10085 | ||
10086 | static void | |
10087 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10088 | struct ui_out *uiout) | |
10089 | { | |
10090 | CORE_ADDR address_start, address_end; | |
10091 | struct bp_location *bl = b->loc; | |
d7e74731 | 10092 | string_file stb; |
f1310107 TJB |
10093 | |
10094 | gdb_assert (bl); | |
10095 | ||
10096 | address_start = bl->address; | |
10097 | address_end = address_start + bl->length - 1; | |
10098 | ||
112e8700 | 10099 | uiout->text ("\taddress range: "); |
d7e74731 PA |
10100 | stb.printf ("[%s, %s]", |
10101 | print_core_address (bl->gdbarch, address_start), | |
10102 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
10103 | uiout->field_stream ("addr", stb); |
10104 | uiout->text ("\n"); | |
f1310107 TJB |
10105 | } |
10106 | ||
10107 | /* Implement the "print_mention" breakpoint_ops method for | |
10108 | ranged breakpoints. */ | |
10109 | ||
10110 | static void | |
10111 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10112 | { | |
10113 | struct bp_location *bl = b->loc; | |
79a45e25 | 10114 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10115 | |
10116 | gdb_assert (bl); | |
10117 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10118 | ||
112e8700 | 10119 | if (uiout->is_mi_like_p ()) |
f1310107 TJB |
10120 | return; |
10121 | ||
10122 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10123 | b->number, paddress (bl->gdbarch, bl->address), | |
10124 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10125 | } | |
10126 | ||
10127 | /* Implement the "print_recreate" breakpoint_ops method for | |
10128 | ranged breakpoints. */ | |
10129 | ||
10130 | static void | |
10131 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10132 | { | |
f00aae0f | 10133 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
10134 | event_location_to_string (b->location.get ()), |
10135 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 10136 | print_recreate_thread (b, fp); |
f1310107 TJB |
10137 | } |
10138 | ||
10139 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10140 | ||
2060206e | 10141 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10142 | |
10143 | /* Find the address where the end of the breakpoint range should be | |
10144 | placed, given the SAL of the end of the range. This is so that if | |
10145 | the user provides a line number, the end of the range is set to the | |
10146 | last instruction of the given line. */ | |
10147 | ||
10148 | static CORE_ADDR | |
10149 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10150 | { | |
10151 | CORE_ADDR end; | |
10152 | ||
10153 | /* If the user provided a PC value, use it. Otherwise, | |
10154 | find the address of the end of the given location. */ | |
10155 | if (sal.explicit_pc) | |
10156 | end = sal.pc; | |
10157 | else | |
10158 | { | |
10159 | int ret; | |
10160 | CORE_ADDR start; | |
10161 | ||
10162 | ret = find_line_pc_range (sal, &start, &end); | |
10163 | if (!ret) | |
10164 | error (_("Could not find location of the end of the range.")); | |
10165 | ||
10166 | /* find_line_pc_range returns the start of the next line. */ | |
10167 | end--; | |
10168 | } | |
10169 | ||
10170 | return end; | |
10171 | } | |
10172 | ||
10173 | /* Implement the "break-range" CLI command. */ | |
10174 | ||
10175 | static void | |
10176 | break_range_command (char *arg, int from_tty) | |
10177 | { | |
870f88f7 | 10178 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10179 | struct linespec_result canonical_start, canonical_end; |
10180 | int bp_count, can_use_bp, length; | |
10181 | CORE_ADDR end; | |
10182 | struct breakpoint *b; | |
f1310107 TJB |
10183 | struct cleanup *cleanup_bkpt; |
10184 | ||
10185 | /* We don't support software ranged breakpoints. */ | |
10186 | if (target_ranged_break_num_registers () < 0) | |
10187 | error (_("This target does not support hardware ranged breakpoints.")); | |
10188 | ||
10189 | bp_count = hw_breakpoint_used_count (); | |
10190 | bp_count += target_ranged_break_num_registers (); | |
10191 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10192 | bp_count, 0); | |
10193 | if (can_use_bp < 0) | |
10194 | error (_("Hardware breakpoints used exceeds limit.")); | |
10195 | ||
f8eba3c6 | 10196 | arg = skip_spaces (arg); |
f1310107 TJB |
10197 | if (arg == NULL || arg[0] == '\0') |
10198 | error(_("No address range specified.")); | |
10199 | ||
f8eba3c6 | 10200 | arg_start = arg; |
ffc2605c TT |
10201 | event_location_up start_location = string_to_event_location (&arg, |
10202 | current_language); | |
10203 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
10204 | |
10205 | if (arg[0] != ',') | |
10206 | error (_("Too few arguments.")); | |
6c5b2ebe | 10207 | else if (canonical_start.lsals.empty ()) |
f1310107 | 10208 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 10209 | |
6c5b2ebe | 10210 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 10211 | |
6c5b2ebe PA |
10212 | if (canonical_start.lsals.size () > 1 |
10213 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
10214 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10215 | ||
6c5b2ebe | 10216 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
f8eba3c6 | 10217 | addr_string_start = savestring (arg_start, arg - arg_start); |
16e802b9 | 10218 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); |
f1310107 TJB |
10219 | |
10220 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10221 | arg = skip_spaces (arg); |
f1310107 TJB |
10222 | |
10223 | /* Parse the end location. */ | |
10224 | ||
f1310107 TJB |
10225 | arg_start = arg; |
10226 | ||
f8eba3c6 | 10227 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10228 | parse_breakpoint_sals because we need to specify the start location's |
10229 | symtab and line as the default symtab and line for the end of the | |
10230 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10231 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10232 | event_location_up end_location = string_to_event_location (&arg, |
10233 | current_language); | |
10234 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10235 | sal_start.symtab, sal_start.line, |
10236 | &canonical_end, NULL, NULL); | |
10237 | ||
6c5b2ebe | 10238 | if (canonical_end.lsals.empty ()) |
f1310107 | 10239 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 10240 | |
6c5b2ebe PA |
10241 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
10242 | if (canonical_end.lsals.size () > 1 | |
10243 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
10244 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10245 | ||
6c5b2ebe | 10246 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
10247 | |
10248 | end = find_breakpoint_range_end (sal_end); | |
10249 | if (sal_start.pc > end) | |
177b42fe | 10250 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10251 | |
10252 | length = end - sal_start.pc + 1; | |
10253 | if (length < 0) | |
10254 | /* Length overflowed. */ | |
10255 | error (_("Address range too large.")); | |
10256 | else if (length == 1) | |
10257 | { | |
10258 | /* This range is simple enough to be handled by | |
10259 | the `hbreak' command. */ | |
10260 | hbreak_command (addr_string_start, 1); | |
10261 | ||
10262 | do_cleanups (cleanup_bkpt); | |
10263 | ||
10264 | return; | |
10265 | } | |
10266 | ||
10267 | /* Now set up the breakpoint. */ | |
10268 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10269 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10270 | set_breakpoint_count (breakpoint_count + 1); |
10271 | b->number = breakpoint_count; | |
10272 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10273 | b->location = std::move (start_location); |
10274 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10275 | b->loc->length = length; |
10276 | ||
f8eba3c6 | 10277 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10278 | |
10279 | mention (b); | |
8d3788bd | 10280 | observer_notify_breakpoint_created (b); |
44702360 | 10281 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10282 | } |
10283 | ||
4a64f543 MS |
10284 | /* Return non-zero if EXP is verified as constant. Returned zero |
10285 | means EXP is variable. Also the constant detection may fail for | |
10286 | some constant expressions and in such case still falsely return | |
10287 | zero. */ | |
2e6e3d9c | 10288 | |
65d79d4b SDJ |
10289 | static int |
10290 | watchpoint_exp_is_const (const struct expression *exp) | |
10291 | { | |
10292 | int i = exp->nelts; | |
10293 | ||
10294 | while (i > 0) | |
10295 | { | |
10296 | int oplenp, argsp; | |
10297 | ||
10298 | /* We are only interested in the descriptor of each element. */ | |
10299 | operator_length (exp, i, &oplenp, &argsp); | |
10300 | i -= oplenp; | |
10301 | ||
10302 | switch (exp->elts[i].opcode) | |
10303 | { | |
10304 | case BINOP_ADD: | |
10305 | case BINOP_SUB: | |
10306 | case BINOP_MUL: | |
10307 | case BINOP_DIV: | |
10308 | case BINOP_REM: | |
10309 | case BINOP_MOD: | |
10310 | case BINOP_LSH: | |
10311 | case BINOP_RSH: | |
10312 | case BINOP_LOGICAL_AND: | |
10313 | case BINOP_LOGICAL_OR: | |
10314 | case BINOP_BITWISE_AND: | |
10315 | case BINOP_BITWISE_IOR: | |
10316 | case BINOP_BITWISE_XOR: | |
10317 | case BINOP_EQUAL: | |
10318 | case BINOP_NOTEQUAL: | |
10319 | case BINOP_LESS: | |
10320 | case BINOP_GTR: | |
10321 | case BINOP_LEQ: | |
10322 | case BINOP_GEQ: | |
10323 | case BINOP_REPEAT: | |
10324 | case BINOP_COMMA: | |
10325 | case BINOP_EXP: | |
10326 | case BINOP_MIN: | |
10327 | case BINOP_MAX: | |
10328 | case BINOP_INTDIV: | |
10329 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10330 | case TERNOP_COND: |
10331 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10332 | |
10333 | case OP_LONG: | |
10334 | case OP_DOUBLE: | |
10335 | case OP_DECFLOAT: | |
10336 | case OP_LAST: | |
10337 | case OP_COMPLEX: | |
10338 | case OP_STRING: | |
65d79d4b SDJ |
10339 | case OP_ARRAY: |
10340 | case OP_TYPE: | |
608b4967 TT |
10341 | case OP_TYPEOF: |
10342 | case OP_DECLTYPE: | |
6e72ca20 | 10343 | case OP_TYPEID: |
65d79d4b SDJ |
10344 | case OP_NAME: |
10345 | case OP_OBJC_NSSTRING: | |
10346 | ||
10347 | case UNOP_NEG: | |
10348 | case UNOP_LOGICAL_NOT: | |
10349 | case UNOP_COMPLEMENT: | |
10350 | case UNOP_ADDR: | |
10351 | case UNOP_HIGH: | |
aeaa2474 | 10352 | case UNOP_CAST: |
9eaf6705 TT |
10353 | |
10354 | case UNOP_CAST_TYPE: | |
10355 | case UNOP_REINTERPRET_CAST: | |
10356 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10357 | /* Unary, binary and ternary operators: We have to check |
10358 | their operands. If they are constant, then so is the | |
10359 | result of that operation. For instance, if A and B are | |
10360 | determined to be constants, then so is "A + B". | |
10361 | ||
10362 | UNOP_IND is one exception to the rule above, because the | |
10363 | value of *ADDR is not necessarily a constant, even when | |
10364 | ADDR is. */ | |
65d79d4b SDJ |
10365 | break; |
10366 | ||
10367 | case OP_VAR_VALUE: | |
10368 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10369 | |
65d79d4b | 10370 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10371 | possible that a buggy compiler could mark a variable as |
10372 | constant even when it is not, and TYPE_CONST would return | |
10373 | true in this case, while SYMBOL_CLASS wouldn't. | |
10374 | ||
10375 | We also have to check for function symbols because they | |
10376 | are always constant. */ | |
65d79d4b SDJ |
10377 | { |
10378 | struct symbol *s = exp->elts[i + 2].symbol; | |
10379 | ||
10380 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10381 | && SYMBOL_CLASS (s) != LOC_CONST | |
10382 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10383 | return 0; | |
10384 | break; | |
10385 | } | |
10386 | ||
10387 | /* The default action is to return 0 because we are using | |
10388 | the optimistic approach here: If we don't know something, | |
10389 | then it is not a constant. */ | |
10390 | default: | |
10391 | return 0; | |
10392 | } | |
10393 | } | |
10394 | ||
10395 | return 1; | |
10396 | } | |
10397 | ||
c1fc2657 | 10398 | /* Watchpoint destructor. */ |
3a5c3e22 | 10399 | |
c1fc2657 | 10400 | watchpoint::~watchpoint () |
3a5c3e22 | 10401 | { |
c1fc2657 SM |
10402 | xfree (this->exp_string); |
10403 | xfree (this->exp_string_reparse); | |
10404 | value_free (this->val); | |
3a5c3e22 PA |
10405 | } |
10406 | ||
348d480f PA |
10407 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10408 | ||
10409 | static void | |
10410 | re_set_watchpoint (struct breakpoint *b) | |
10411 | { | |
3a5c3e22 PA |
10412 | struct watchpoint *w = (struct watchpoint *) b; |
10413 | ||
348d480f PA |
10414 | /* Watchpoint can be either on expression using entirely global |
10415 | variables, or it can be on local variables. | |
10416 | ||
10417 | Watchpoints of the first kind are never auto-deleted, and even | |
10418 | persist across program restarts. Since they can use variables | |
10419 | from shared libraries, we need to reparse expression as libraries | |
10420 | are loaded and unloaded. | |
10421 | ||
10422 | Watchpoints on local variables can also change meaning as result | |
10423 | of solib event. For example, if a watchpoint uses both a local | |
10424 | and a global variables in expression, it's a local watchpoint, | |
10425 | but unloading of a shared library will make the expression | |
10426 | invalid. This is not a very common use case, but we still | |
10427 | re-evaluate expression, to avoid surprises to the user. | |
10428 | ||
10429 | Note that for local watchpoints, we re-evaluate it only if | |
10430 | watchpoints frame id is still valid. If it's not, it means the | |
10431 | watchpoint is out of scope and will be deleted soon. In fact, | |
10432 | I'm not sure we'll ever be called in this case. | |
10433 | ||
10434 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10435 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10436 | |
3a5c3e22 PA |
10437 | Don't do anything about disabled watchpoints, since they will be |
10438 | reevaluated again when enabled. */ | |
10439 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10440 | } |
10441 | ||
77b06cd7 TJB |
10442 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10443 | ||
10444 | static int | |
10445 | insert_watchpoint (struct bp_location *bl) | |
10446 | { | |
3a5c3e22 PA |
10447 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10448 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10449 | |
10450 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10451 | w->cond_exp.get ()); |
77b06cd7 TJB |
10452 | } |
10453 | ||
10454 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10455 | ||
10456 | static int | |
73971819 | 10457 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10458 | { |
3a5c3e22 PA |
10459 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10460 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10461 | |
10462 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10463 | w->cond_exp.get ()); |
e09342b5 TJB |
10464 | } |
10465 | ||
e09342b5 | 10466 | static int |
348d480f | 10467 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10468 | struct address_space *aspace, CORE_ADDR bp_addr, |
10469 | const struct target_waitstatus *ws) | |
e09342b5 | 10470 | { |
348d480f | 10471 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10472 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10473 | |
348d480f PA |
10474 | /* Continuable hardware watchpoints are treated as non-existent if the |
10475 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10476 | some data address). Otherwise gdb won't stop on a break instruction | |
10477 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10478 | been defined. Also skip watchpoints which we know did not trigger | |
10479 | (did not match the data address). */ | |
10480 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10481 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10482 | return 0; |
9c06b0b4 | 10483 | |
348d480f | 10484 | return 1; |
9c06b0b4 TJB |
10485 | } |
10486 | ||
348d480f PA |
10487 | static void |
10488 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10489 | { |
348d480f | 10490 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10491 | |
348d480f | 10492 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10493 | } |
10494 | ||
10495 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10496 | hardware watchpoints. */ |
9c06b0b4 TJB |
10497 | |
10498 | static int | |
348d480f | 10499 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10500 | { |
3a5c3e22 PA |
10501 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10502 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10503 | |
10504 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10505 | } |
10506 | ||
10507 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10508 | hardware watchpoints. */ |
9c06b0b4 TJB |
10509 | |
10510 | static int | |
348d480f | 10511 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10512 | { |
efa80663 PA |
10513 | /* Read and access watchpoints only work with hardware support. */ |
10514 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10515 | } |
10516 | ||
9c06b0b4 | 10517 | static enum print_stop_action |
348d480f | 10518 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10519 | { |
348d480f | 10520 | struct breakpoint *b; |
348d480f | 10521 | enum print_stop_action result; |
3a5c3e22 | 10522 | struct watchpoint *w; |
79a45e25 | 10523 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10524 | |
10525 | gdb_assert (bs->bp_location_at != NULL); | |
10526 | ||
348d480f | 10527 | b = bs->breakpoint_at; |
3a5c3e22 | 10528 | w = (struct watchpoint *) b; |
348d480f | 10529 | |
f303dbd6 PA |
10530 | annotate_watchpoint (b->number); |
10531 | maybe_print_thread_hit_breakpoint (uiout); | |
10532 | ||
d7e74731 PA |
10533 | string_file stb; |
10534 | ||
76f9c9cf | 10535 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10536 | switch (b->type) |
10537 | { | |
348d480f | 10538 | case bp_watchpoint: |
9c06b0b4 | 10539 | case bp_hardware_watchpoint: |
112e8700 SM |
10540 | if (uiout->is_mi_like_p ()) |
10541 | uiout->field_string | |
10542 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10543 | mention (b); |
76f9c9cf | 10544 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10545 | uiout->text ("\nOld value = "); |
d7e74731 | 10546 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10547 | uiout->field_stream ("old", stb); |
10548 | uiout->text ("\nNew value = "); | |
d7e74731 | 10549 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10550 | uiout->field_stream ("new", stb); |
10551 | uiout->text ("\n"); | |
348d480f PA |
10552 | /* More than one watchpoint may have been triggered. */ |
10553 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10554 | break; |
10555 | ||
10556 | case bp_read_watchpoint: | |
112e8700 SM |
10557 | if (uiout->is_mi_like_p ()) |
10558 | uiout->field_string | |
10559 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10560 | mention (b); |
76f9c9cf | 10561 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10562 | uiout->text ("\nValue = "); |
d7e74731 | 10563 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10564 | uiout->field_stream ("value", stb); |
10565 | uiout->text ("\n"); | |
348d480f | 10566 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10567 | break; |
10568 | ||
10569 | case bp_access_watchpoint: | |
348d480f PA |
10570 | if (bs->old_val != NULL) |
10571 | { | |
112e8700 SM |
10572 | if (uiout->is_mi_like_p ()) |
10573 | uiout->field_string | |
10574 | ("reason", | |
348d480f PA |
10575 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10576 | mention (b); | |
76f9c9cf | 10577 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10578 | uiout->text ("\nOld value = "); |
d7e74731 | 10579 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10580 | uiout->field_stream ("old", stb); |
10581 | uiout->text ("\nNew value = "); | |
348d480f PA |
10582 | } |
10583 | else | |
10584 | { | |
10585 | mention (b); | |
112e8700 SM |
10586 | if (uiout->is_mi_like_p ()) |
10587 | uiout->field_string | |
10588 | ("reason", | |
348d480f | 10589 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10590 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10591 | uiout->text ("\nValue = "); |
348d480f | 10592 | } |
d7e74731 | 10593 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10594 | uiout->field_stream ("new", stb); |
10595 | uiout->text ("\n"); | |
348d480f | 10596 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10597 | break; |
10598 | default: | |
348d480f | 10599 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10600 | } |
10601 | ||
348d480f PA |
10602 | return result; |
10603 | } | |
10604 | ||
10605 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10606 | watchpoints. */ | |
10607 | ||
10608 | static void | |
10609 | print_mention_watchpoint (struct breakpoint *b) | |
10610 | { | |
3a5c3e22 | 10611 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10612 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10613 | const char *tuple_name; |
348d480f PA |
10614 | |
10615 | switch (b->type) | |
10616 | { | |
10617 | case bp_watchpoint: | |
112e8700 | 10618 | uiout->text ("Watchpoint "); |
46b9c129 | 10619 | tuple_name = "wpt"; |
348d480f PA |
10620 | break; |
10621 | case bp_hardware_watchpoint: | |
112e8700 | 10622 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10623 | tuple_name = "wpt"; |
348d480f PA |
10624 | break; |
10625 | case bp_read_watchpoint: | |
112e8700 | 10626 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10627 | tuple_name = "hw-rwpt"; |
348d480f PA |
10628 | break; |
10629 | case bp_access_watchpoint: | |
112e8700 | 10630 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10631 | tuple_name = "hw-awpt"; |
348d480f PA |
10632 | break; |
10633 | default: | |
10634 | internal_error (__FILE__, __LINE__, | |
10635 | _("Invalid hardware watchpoint type.")); | |
10636 | } | |
10637 | ||
46b9c129 | 10638 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10639 | uiout->field_int ("number", b->number); |
10640 | uiout->text (": "); | |
10641 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10642 | } |
10643 | ||
10644 | /* Implement the "print_recreate" breakpoint_ops method for | |
10645 | watchpoints. */ | |
10646 | ||
10647 | static void | |
10648 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10649 | { | |
3a5c3e22 PA |
10650 | struct watchpoint *w = (struct watchpoint *) b; |
10651 | ||
348d480f PA |
10652 | switch (b->type) |
10653 | { | |
10654 | case bp_watchpoint: | |
10655 | case bp_hardware_watchpoint: | |
10656 | fprintf_unfiltered (fp, "watch"); | |
10657 | break; | |
10658 | case bp_read_watchpoint: | |
10659 | fprintf_unfiltered (fp, "rwatch"); | |
10660 | break; | |
10661 | case bp_access_watchpoint: | |
10662 | fprintf_unfiltered (fp, "awatch"); | |
10663 | break; | |
10664 | default: | |
10665 | internal_error (__FILE__, __LINE__, | |
10666 | _("Invalid watchpoint type.")); | |
10667 | } | |
10668 | ||
3a5c3e22 | 10669 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10670 | print_recreate_thread (b, fp); |
348d480f PA |
10671 | } |
10672 | ||
427cd150 TT |
10673 | /* Implement the "explains_signal" breakpoint_ops method for |
10674 | watchpoints. */ | |
10675 | ||
47591c29 | 10676 | static int |
427cd150 TT |
10677 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10678 | { | |
10679 | /* A software watchpoint cannot cause a signal other than | |
10680 | GDB_SIGNAL_TRAP. */ | |
10681 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10682 | return 0; |
427cd150 | 10683 | |
47591c29 | 10684 | return 1; |
427cd150 TT |
10685 | } |
10686 | ||
348d480f PA |
10687 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10688 | ||
2060206e | 10689 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10690 | |
10691 | /* Implement the "insert" breakpoint_ops method for | |
10692 | masked hardware watchpoints. */ | |
10693 | ||
10694 | static int | |
10695 | insert_masked_watchpoint (struct bp_location *bl) | |
10696 | { | |
3a5c3e22 PA |
10697 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10698 | ||
10699 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10700 | bl->watchpoint_type); |
10701 | } | |
10702 | ||
10703 | /* Implement the "remove" breakpoint_ops method for | |
10704 | masked hardware watchpoints. */ | |
10705 | ||
10706 | static int | |
73971819 | 10707 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10708 | { |
3a5c3e22 PA |
10709 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10710 | ||
10711 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10712 | bl->watchpoint_type); |
10713 | } | |
10714 | ||
10715 | /* Implement the "resources_needed" breakpoint_ops method for | |
10716 | masked hardware watchpoints. */ | |
10717 | ||
10718 | static int | |
10719 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10720 | { | |
3a5c3e22 PA |
10721 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10722 | ||
10723 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10724 | } |
10725 | ||
10726 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10727 | masked hardware watchpoints. */ | |
10728 | ||
10729 | static int | |
10730 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10731 | { | |
10732 | return 0; | |
10733 | } | |
10734 | ||
10735 | /* Implement the "print_it" breakpoint_ops method for | |
10736 | masked hardware watchpoints. */ | |
10737 | ||
10738 | static enum print_stop_action | |
10739 | print_it_masked_watchpoint (bpstat bs) | |
10740 | { | |
10741 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10742 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10743 | |
10744 | /* Masked watchpoints have only one location. */ | |
10745 | gdb_assert (b->loc && b->loc->next == NULL); | |
10746 | ||
f303dbd6 PA |
10747 | annotate_watchpoint (b->number); |
10748 | maybe_print_thread_hit_breakpoint (uiout); | |
10749 | ||
348d480f PA |
10750 | switch (b->type) |
10751 | { | |
10752 | case bp_hardware_watchpoint: | |
112e8700 SM |
10753 | if (uiout->is_mi_like_p ()) |
10754 | uiout->field_string | |
10755 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10756 | break; |
10757 | ||
10758 | case bp_read_watchpoint: | |
112e8700 SM |
10759 | if (uiout->is_mi_like_p ()) |
10760 | uiout->field_string | |
10761 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10762 | break; |
10763 | ||
10764 | case bp_access_watchpoint: | |
112e8700 SM |
10765 | if (uiout->is_mi_like_p ()) |
10766 | uiout->field_string | |
10767 | ("reason", | |
348d480f PA |
10768 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10769 | break; | |
10770 | default: | |
10771 | internal_error (__FILE__, __LINE__, | |
10772 | _("Invalid hardware watchpoint type.")); | |
10773 | } | |
10774 | ||
10775 | mention (b); | |
112e8700 | 10776 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10777 | Check the underlying instruction at PC for the memory\n\ |
10778 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10779 | uiout->text ("\n"); |
9c06b0b4 TJB |
10780 | |
10781 | /* More than one watchpoint may have been triggered. */ | |
10782 | return PRINT_UNKNOWN; | |
10783 | } | |
10784 | ||
10785 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10786 | masked hardware watchpoints. */ | |
10787 | ||
10788 | static void | |
10789 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10790 | struct ui_out *uiout) | |
10791 | { | |
3a5c3e22 PA |
10792 | struct watchpoint *w = (struct watchpoint *) b; |
10793 | ||
9c06b0b4 TJB |
10794 | /* Masked watchpoints have only one location. */ |
10795 | gdb_assert (b->loc && b->loc->next == NULL); | |
10796 | ||
112e8700 SM |
10797 | uiout->text ("\tmask "); |
10798 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10799 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10800 | } |
10801 | ||
10802 | /* Implement the "print_mention" breakpoint_ops method for | |
10803 | masked hardware watchpoints. */ | |
10804 | ||
10805 | static void | |
10806 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10807 | { | |
3a5c3e22 | 10808 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10809 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10810 | const char *tuple_name; |
9c06b0b4 TJB |
10811 | |
10812 | switch (b->type) | |
10813 | { | |
10814 | case bp_hardware_watchpoint: | |
112e8700 | 10815 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10816 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10817 | break; |
10818 | case bp_read_watchpoint: | |
112e8700 | 10819 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10820 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10821 | break; |
10822 | case bp_access_watchpoint: | |
112e8700 | 10823 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10824 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10825 | break; |
10826 | default: | |
10827 | internal_error (__FILE__, __LINE__, | |
10828 | _("Invalid hardware watchpoint type.")); | |
10829 | } | |
10830 | ||
46b9c129 | 10831 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10832 | uiout->field_int ("number", b->number); |
10833 | uiout->text (": "); | |
10834 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10835 | } |
10836 | ||
10837 | /* Implement the "print_recreate" breakpoint_ops method for | |
10838 | masked hardware watchpoints. */ | |
10839 | ||
10840 | static void | |
10841 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10842 | { | |
3a5c3e22 | 10843 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10844 | char tmp[40]; |
10845 | ||
10846 | switch (b->type) | |
10847 | { | |
10848 | case bp_hardware_watchpoint: | |
10849 | fprintf_unfiltered (fp, "watch"); | |
10850 | break; | |
10851 | case bp_read_watchpoint: | |
10852 | fprintf_unfiltered (fp, "rwatch"); | |
10853 | break; | |
10854 | case bp_access_watchpoint: | |
10855 | fprintf_unfiltered (fp, "awatch"); | |
10856 | break; | |
10857 | default: | |
10858 | internal_error (__FILE__, __LINE__, | |
10859 | _("Invalid hardware watchpoint type.")); | |
10860 | } | |
10861 | ||
3a5c3e22 PA |
10862 | sprintf_vma (tmp, w->hw_wp_mask); |
10863 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10864 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10865 | } |
10866 | ||
10867 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10868 | ||
2060206e | 10869 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10870 | |
10871 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10872 | ||
10873 | static int | |
10874 | is_masked_watchpoint (const struct breakpoint *b) | |
10875 | { | |
10876 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10877 | } | |
10878 | ||
53a5351d JM |
10879 | /* accessflag: hw_write: watch write, |
10880 | hw_read: watch read, | |
10881 | hw_access: watch access (read or write) */ | |
c906108c | 10882 | static void |
bbc13ae3 | 10883 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10884 | int just_location, int internal) |
c906108c | 10885 | { |
c1fc2657 | 10886 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10887 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10888 | struct value *val, *mark, *result; |
bb9d5f81 | 10889 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10890 | const char *exp_start = NULL; |
10891 | const char *exp_end = NULL; | |
10892 | const char *tok, *end_tok; | |
9c06b0b4 | 10893 | int toklen = -1; |
bbc13ae3 KS |
10894 | const char *cond_start = NULL; |
10895 | const char *cond_end = NULL; | |
c906108c | 10896 | enum bptype bp_type; |
37e4754d | 10897 | int thread = -1; |
0cf6dd15 | 10898 | int pc = 0; |
9c06b0b4 TJB |
10899 | /* Flag to indicate whether we are going to use masks for |
10900 | the hardware watchpoint. */ | |
10901 | int use_mask = 0; | |
10902 | CORE_ADDR mask = 0; | |
bbc13ae3 KS |
10903 | char *expression; |
10904 | struct cleanup *back_to; | |
c906108c | 10905 | |
37e4754d LM |
10906 | /* Make sure that we actually have parameters to parse. */ |
10907 | if (arg != NULL && arg[0] != '\0') | |
10908 | { | |
bbc13ae3 KS |
10909 | const char *value_start; |
10910 | ||
10911 | exp_end = arg + strlen (arg); | |
37e4754d | 10912 | |
9c06b0b4 TJB |
10913 | /* Look for "parameter value" pairs at the end |
10914 | of the arguments string. */ | |
bbc13ae3 | 10915 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10916 | { |
10917 | /* Skip whitespace at the end of the argument list. */ | |
10918 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10919 | tok--; | |
10920 | ||
10921 | /* Find the beginning of the last token. | |
10922 | This is the value of the parameter. */ | |
10923 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10924 | tok--; | |
10925 | value_start = tok + 1; | |
10926 | ||
10927 | /* Skip whitespace. */ | |
10928 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10929 | tok--; | |
10930 | ||
10931 | end_tok = tok; | |
10932 | ||
10933 | /* Find the beginning of the second to last token. | |
10934 | This is the parameter itself. */ | |
10935 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10936 | tok--; | |
10937 | tok++; | |
10938 | toklen = end_tok - tok + 1; | |
10939 | ||
61012eef | 10940 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10941 | { |
5d5658a1 | 10942 | struct thread_info *thr; |
9c06b0b4 TJB |
10943 | /* At this point we've found a "thread" token, which means |
10944 | the user is trying to set a watchpoint that triggers | |
10945 | only in a specific thread. */ | |
5d5658a1 | 10946 | const char *endp; |
37e4754d | 10947 | |
9c06b0b4 TJB |
10948 | if (thread != -1) |
10949 | error(_("You can specify only one thread.")); | |
37e4754d | 10950 | |
9c06b0b4 | 10951 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10952 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10953 | |
5d5658a1 | 10954 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10955 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10956 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10957 | |
5d5658a1 | 10958 | thread = thr->global_num; |
9c06b0b4 | 10959 | } |
61012eef | 10960 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10961 | { |
10962 | /* We've found a "mask" token, which means the user wants to | |
10963 | create a hardware watchpoint that is going to have the mask | |
10964 | facility. */ | |
10965 | struct value *mask_value, *mark; | |
37e4754d | 10966 | |
9c06b0b4 TJB |
10967 | if (use_mask) |
10968 | error(_("You can specify only one mask.")); | |
37e4754d | 10969 | |
9c06b0b4 | 10970 | use_mask = just_location = 1; |
37e4754d | 10971 | |
9c06b0b4 TJB |
10972 | mark = value_mark (); |
10973 | mask_value = parse_to_comma_and_eval (&value_start); | |
10974 | mask = value_as_address (mask_value); | |
10975 | value_free_to_mark (mark); | |
10976 | } | |
10977 | else | |
10978 | /* We didn't recognize what we found. We should stop here. */ | |
10979 | break; | |
37e4754d | 10980 | |
9c06b0b4 TJB |
10981 | /* Truncate the string and get rid of the "parameter value" pair before |
10982 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10983 | exp_end = tok; |
9c06b0b4 | 10984 | } |
37e4754d | 10985 | } |
bbc13ae3 KS |
10986 | else |
10987 | exp_end = arg; | |
37e4754d | 10988 | |
bbc13ae3 KS |
10989 | /* Parse the rest of the arguments. From here on out, everything |
10990 | is in terms of a newly allocated string instead of the original | |
10991 | ARG. */ | |
c906108c | 10992 | innermost_block = NULL; |
bbc13ae3 KS |
10993 | expression = savestring (arg, exp_end - arg); |
10994 | back_to = make_cleanup (xfree, expression); | |
10995 | exp_start = arg = expression; | |
4d01a485 | 10996 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 10997 | exp_end = arg; |
fa8a61dc TT |
10998 | /* Remove trailing whitespace from the expression before saving it. |
10999 | This makes the eventual display of the expression string a bit | |
11000 | prettier. */ | |
11001 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11002 | --exp_end; | |
11003 | ||
65d79d4b | 11004 | /* Checking if the expression is not constant. */ |
4d01a485 | 11005 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
11006 | { |
11007 | int len; | |
11008 | ||
11009 | len = exp_end - exp_start; | |
11010 | while (len > 0 && isspace (exp_start[len - 1])) | |
11011 | len--; | |
11012 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11013 | } | |
11014 | ||
c906108c SS |
11015 | exp_valid_block = innermost_block; |
11016 | mark = value_mark (); | |
4d01a485 | 11017 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 11018 | |
bb9d5f81 PP |
11019 | if (val != NULL && just_location) |
11020 | { | |
11021 | saved_bitpos = value_bitpos (val); | |
11022 | saved_bitsize = value_bitsize (val); | |
11023 | } | |
11024 | ||
06a64a0b TT |
11025 | if (just_location) |
11026 | { | |
9c06b0b4 TJB |
11027 | int ret; |
11028 | ||
06a64a0b | 11029 | exp_valid_block = NULL; |
a1442452 | 11030 | val = value_addr (result); |
06a64a0b TT |
11031 | release_value (val); |
11032 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11033 | |
11034 | if (use_mask) | |
11035 | { | |
11036 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11037 | mask); | |
11038 | if (ret == -1) | |
11039 | error (_("This target does not support masked watchpoints.")); | |
11040 | else if (ret == -2) | |
11041 | error (_("Invalid mask or memory region.")); | |
11042 | } | |
06a64a0b TT |
11043 | } |
11044 | else if (val != NULL) | |
fa4727a6 | 11045 | release_value (val); |
c906108c | 11046 | |
f1735a53 TT |
11047 | tok = skip_spaces (arg); |
11048 | end_tok = skip_to_space (tok); | |
c906108c SS |
11049 | |
11050 | toklen = end_tok - tok; | |
11051 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11052 | { | |
60e1c644 | 11053 | innermost_block = NULL; |
c906108c | 11054 | tok = cond_start = end_tok + 1; |
4d01a485 | 11055 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11056 | |
11057 | /* The watchpoint expression may not be local, but the condition | |
11058 | may still be. E.g.: `watch global if local > 0'. */ | |
11059 | cond_exp_valid_block = innermost_block; | |
11060 | ||
c906108c SS |
11061 | cond_end = tok; |
11062 | } | |
11063 | if (*tok) | |
8a3fe4f8 | 11064 | error (_("Junk at end of command.")); |
c906108c | 11065 | |
441d7c93 PA |
11066 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
11067 | ||
11068 | /* Save this because create_internal_breakpoint below invalidates | |
11069 | 'wp_frame'. */ | |
11070 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
11071 | |
11072 | /* If the expression is "local", then set up a "watchpoint scope" | |
11073 | breakpoint at the point where we've left the scope of the watchpoint | |
11074 | expression. Create the scope breakpoint before the watchpoint, so | |
11075 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 11076 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 11077 | { |
441d7c93 PA |
11078 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
11079 | ||
11080 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 11081 | { |
441d7c93 PA |
11082 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
11083 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
11084 | ||
edb3359d | 11085 | scope_breakpoint |
441d7c93 | 11086 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
11087 | bp_watchpoint_scope, |
11088 | &momentary_breakpoint_ops); | |
d983da9c | 11089 | |
441d7c93 PA |
11090 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
11091 | wp_frame = NULL; | |
11092 | ||
edb3359d | 11093 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11094 | |
edb3359d DJ |
11095 | /* Automatically delete the breakpoint when it hits. */ |
11096 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11097 | |
edb3359d | 11098 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 11099 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 11100 | |
edb3359d | 11101 | /* Set the address at which we will stop. */ |
441d7c93 PA |
11102 | scope_breakpoint->loc->gdbarch = caller_arch; |
11103 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 11104 | scope_breakpoint->loc->address |
a6d9a66e UW |
11105 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11106 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11107 | scope_breakpoint->type); |
11108 | } | |
d983da9c DJ |
11109 | } |
11110 | ||
e8369a73 AB |
11111 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11112 | watchpoints here even if hardware watchpoints are turned off, a call | |
11113 | to update_watchpoint later in this function will cause the type to | |
11114 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11115 | ||
11116 | if (accessflag == hw_read) | |
11117 | bp_type = bp_read_watchpoint; | |
11118 | else if (accessflag == hw_access) | |
11119 | bp_type = bp_access_watchpoint; | |
11120 | else | |
11121 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 11122 | |
b270e6f9 | 11123 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 11124 | |
348d480f | 11125 | if (use_mask) |
b270e6f9 | 11126 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 11127 | &masked_watchpoint_breakpoint_ops); |
348d480f | 11128 | else |
b270e6f9 | 11129 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 11130 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
11131 | w->thread = thread; |
11132 | w->disposition = disp_donttouch; | |
11133 | w->pspace = current_program_space; | |
b22e99fd | 11134 | w->exp = std::move (exp); |
3a5c3e22 PA |
11135 | w->exp_valid_block = exp_valid_block; |
11136 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11137 | if (just_location) |
11138 | { | |
11139 | struct type *t = value_type (val); | |
11140 | CORE_ADDR addr = value_as_address (val); | |
06a64a0b | 11141 | |
43cc5389 TT |
11142 | w->exp_string_reparse |
11143 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 11144 | |
3a5c3e22 | 11145 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 11146 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
11147 | } |
11148 | else | |
3a5c3e22 | 11149 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11150 | |
11151 | if (use_mask) | |
11152 | { | |
3a5c3e22 | 11153 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11154 | } |
11155 | else | |
11156 | { | |
3a5c3e22 | 11157 | w->val = val; |
bb9d5f81 PP |
11158 | w->val_bitpos = saved_bitpos; |
11159 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11160 | w->val_valid = 1; |
9c06b0b4 | 11161 | } |
77b06cd7 | 11162 | |
c906108c | 11163 | if (cond_start) |
c1fc2657 | 11164 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 11165 | else |
c1fc2657 | 11166 | w->cond_string = 0; |
c5aa993b | 11167 | |
441d7c93 | 11168 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 11169 | { |
441d7c93 | 11170 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 11171 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 11172 | } |
c906108c | 11173 | else |
f6bc2008 | 11174 | { |
3a5c3e22 PA |
11175 | w->watchpoint_frame = null_frame_id; |
11176 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11177 | } |
c906108c | 11178 | |
d983da9c | 11179 | if (scope_breakpoint != NULL) |
c906108c | 11180 | { |
d983da9c DJ |
11181 | /* The scope breakpoint is related to the watchpoint. We will |
11182 | need to act on them together. */ | |
c1fc2657 | 11183 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 11184 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 11185 | } |
d983da9c | 11186 | |
06a64a0b TT |
11187 | if (!just_location) |
11188 | value_free_to_mark (mark); | |
2d134ed3 | 11189 | |
b270e6f9 TT |
11190 | /* Finally update the new watchpoint. This creates the locations |
11191 | that should be inserted. */ | |
11192 | update_watchpoint (w.get (), 1); | |
a9634178 | 11193 | |
b270e6f9 | 11194 | install_breakpoint (internal, std::move (w), 1); |
bbc13ae3 | 11195 | do_cleanups (back_to); |
c906108c SS |
11196 | } |
11197 | ||
e09342b5 | 11198 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11199 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11200 | |
c906108c | 11201 | static int |
a9634178 | 11202 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11203 | { |
11204 | int found_memory_cnt = 0; | |
2e70b7b9 | 11205 | struct value *head = v; |
c906108c SS |
11206 | |
11207 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11208 | if (!can_use_hw_watchpoints) |
c906108c | 11209 | return 0; |
c5aa993b | 11210 | |
5c44784c JM |
11211 | /* Make sure that the value of the expression depends only upon |
11212 | memory contents, and values computed from them within GDB. If we | |
11213 | find any register references or function calls, we can't use a | |
11214 | hardware watchpoint. | |
11215 | ||
11216 | The idea here is that evaluating an expression generates a series | |
11217 | of values, one holding the value of every subexpression. (The | |
11218 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11219 | a*b+c.) GDB's values hold almost enough information to establish | |
11220 | the criteria given above --- they identify memory lvalues, | |
11221 | register lvalues, computed values, etcetera. So we can evaluate | |
11222 | the expression, and then scan the chain of values that leaves | |
11223 | behind to decide whether we can detect any possible change to the | |
11224 | expression's final value using only hardware watchpoints. | |
11225 | ||
11226 | However, I don't think that the values returned by inferior | |
11227 | function calls are special in any way. So this function may not | |
11228 | notice that an expression involving an inferior function call | |
11229 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11230 | for (; v; v = value_next (v)) |
c906108c | 11231 | { |
5c44784c | 11232 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11233 | { |
8464be76 DJ |
11234 | if (v != head && value_lazy (v)) |
11235 | /* A lazy memory lvalue in the chain is one that GDB never | |
11236 | needed to fetch; we either just used its address (e.g., | |
11237 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11238 | in `a,b'). This doesn't apply to HEAD; if that is | |
11239 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11240 | ; |
53a5351d | 11241 | else |
5c44784c JM |
11242 | { |
11243 | /* Ahh, memory we actually used! Check if we can cover | |
11244 | it with hardware watchpoints. */ | |
df407dfe | 11245 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11246 | |
11247 | /* We only watch structs and arrays if user asked for it | |
11248 | explicitly, never if they just happen to appear in a | |
11249 | middle of some value chain. */ | |
11250 | if (v == head | |
11251 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11252 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11253 | { | |
42ae5230 | 11254 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11255 | int len; |
11256 | int num_regs; | |
11257 | ||
a9634178 | 11258 | len = (target_exact_watchpoints |
e09342b5 TJB |
11259 | && is_scalar_type_recursive (vtype))? |
11260 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11261 | |
e09342b5 TJB |
11262 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11263 | if (!num_regs) | |
2e70b7b9 MS |
11264 | return 0; |
11265 | else | |
e09342b5 | 11266 | found_memory_cnt += num_regs; |
2e70b7b9 | 11267 | } |
5c44784c | 11268 | } |
c5aa993b | 11269 | } |
5086187c AC |
11270 | else if (VALUE_LVAL (v) != not_lval |
11271 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11272 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11273 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11274 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11275 | } |
11276 | ||
11277 | /* The expression itself looks suitable for using a hardware | |
11278 | watchpoint, but give the target machine a chance to reject it. */ | |
11279 | return found_memory_cnt; | |
11280 | } | |
11281 | ||
8b93c638 | 11282 | void |
84f4c1fe | 11283 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11284 | { |
84f4c1fe | 11285 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11286 | } |
11287 | ||
06a64a0b TT |
11288 | /* A helper function that looks for the "-location" argument and then |
11289 | calls watch_command_1. */ | |
11290 | ||
11291 | static void | |
11292 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11293 | { | |
11294 | int just_location = 0; | |
11295 | ||
11296 | if (arg | |
11297 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11298 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11299 | { | |
e9cafbcc | 11300 | arg = skip_spaces (arg); |
06a64a0b TT |
11301 | just_location = 1; |
11302 | } | |
11303 | ||
84f4c1fe | 11304 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11305 | } |
8926118c | 11306 | |
c5aa993b | 11307 | static void |
fba45db2 | 11308 | watch_command (char *arg, int from_tty) |
c906108c | 11309 | { |
06a64a0b | 11310 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11311 | } |
11312 | ||
8b93c638 | 11313 | void |
84f4c1fe | 11314 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11315 | { |
84f4c1fe | 11316 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11317 | } |
8926118c | 11318 | |
c5aa993b | 11319 | static void |
fba45db2 | 11320 | rwatch_command (char *arg, int from_tty) |
c906108c | 11321 | { |
06a64a0b | 11322 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11323 | } |
11324 | ||
8b93c638 | 11325 | void |
84f4c1fe | 11326 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11327 | { |
84f4c1fe | 11328 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11329 | } |
8926118c | 11330 | |
c5aa993b | 11331 | static void |
fba45db2 | 11332 | awatch_command (char *arg, int from_tty) |
c906108c | 11333 | { |
06a64a0b | 11334 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11335 | } |
c906108c | 11336 | \f |
c5aa993b | 11337 | |
cfc31633 PA |
11338 | /* Data for the FSM that manages the until(location)/advance commands |
11339 | in infcmd.c. Here because it uses the mechanisms of | |
11340 | breakpoints. */ | |
c906108c | 11341 | |
cfc31633 | 11342 | struct until_break_fsm |
bfec99b2 | 11343 | { |
cfc31633 PA |
11344 | /* The base class. */ |
11345 | struct thread_fsm thread_fsm; | |
11346 | ||
11347 | /* The thread that as current when the command was executed. */ | |
11348 | int thread; | |
11349 | ||
11350 | /* The breakpoint set at the destination location. */ | |
11351 | struct breakpoint *location_breakpoint; | |
11352 | ||
11353 | /* Breakpoint set at the return address in the caller frame. May be | |
11354 | NULL. */ | |
11355 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11356 | }; |
11357 | ||
8980e177 PA |
11358 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11359 | struct thread_info *thread); | |
11360 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11361 | struct thread_info *thread); | |
cfc31633 PA |
11362 | static enum async_reply_reason |
11363 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11364 | ||
11365 | /* until_break_fsm's vtable. */ | |
11366 | ||
11367 | static struct thread_fsm_ops until_break_fsm_ops = | |
11368 | { | |
11369 | NULL, /* dtor */ | |
11370 | until_break_fsm_clean_up, | |
11371 | until_break_fsm_should_stop, | |
11372 | NULL, /* return_value */ | |
11373 | until_break_fsm_async_reply_reason, | |
11374 | }; | |
11375 | ||
11376 | /* Allocate a new until_break_command_fsm. */ | |
11377 | ||
11378 | static struct until_break_fsm * | |
8980e177 | 11379 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11380 | struct breakpoint *location_breakpoint, |
11381 | struct breakpoint *caller_breakpoint) | |
11382 | { | |
11383 | struct until_break_fsm *sm; | |
11384 | ||
11385 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11386 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11387 | |
11388 | sm->thread = thread; | |
11389 | sm->location_breakpoint = location_breakpoint; | |
11390 | sm->caller_breakpoint = caller_breakpoint; | |
11391 | ||
11392 | return sm; | |
11393 | } | |
11394 | ||
11395 | /* Implementation of the 'should_stop' FSM method for the | |
11396 | until(location)/advance commands. */ | |
11397 | ||
11398 | static int | |
8980e177 PA |
11399 | until_break_fsm_should_stop (struct thread_fsm *self, |
11400 | struct thread_info *tp) | |
cfc31633 PA |
11401 | { |
11402 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11403 | |
11404 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11405 | sm->location_breakpoint) != NULL | |
11406 | || (sm->caller_breakpoint != NULL | |
11407 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11408 | sm->caller_breakpoint) != NULL)) | |
11409 | thread_fsm_set_finished (self); | |
11410 | ||
11411 | return 1; | |
11412 | } | |
11413 | ||
11414 | /* Implementation of the 'clean_up' FSM method for the | |
11415 | until(location)/advance commands. */ | |
11416 | ||
c2c6d25f | 11417 | static void |
8980e177 PA |
11418 | until_break_fsm_clean_up (struct thread_fsm *self, |
11419 | struct thread_info *thread) | |
43ff13b4 | 11420 | { |
cfc31633 | 11421 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11422 | |
cfc31633 PA |
11423 | /* Clean up our temporary breakpoints. */ |
11424 | if (sm->location_breakpoint != NULL) | |
11425 | { | |
11426 | delete_breakpoint (sm->location_breakpoint); | |
11427 | sm->location_breakpoint = NULL; | |
11428 | } | |
11429 | if (sm->caller_breakpoint != NULL) | |
11430 | { | |
11431 | delete_breakpoint (sm->caller_breakpoint); | |
11432 | sm->caller_breakpoint = NULL; | |
11433 | } | |
11434 | delete_longjmp_breakpoint (sm->thread); | |
11435 | } | |
11436 | ||
11437 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11438 | until(location)/advance commands. */ | |
11439 | ||
11440 | static enum async_reply_reason | |
11441 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11442 | { | |
11443 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11444 | } |
11445 | ||
c906108c | 11446 | void |
ae66c1fc | 11447 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c | 11448 | { |
8556afb4 PA |
11449 | struct frame_info *frame; |
11450 | struct gdbarch *frame_gdbarch; | |
11451 | struct frame_id stack_frame_id; | |
11452 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11453 | struct breakpoint *location_breakpoint; |
11454 | struct breakpoint *caller_breakpoint = NULL; | |
ffc2605c | 11455 | struct cleanup *old_chain; |
186c406b TT |
11456 | int thread; |
11457 | struct thread_info *tp; | |
cfc31633 | 11458 | struct until_break_fsm *sm; |
c906108c | 11459 | |
70509625 | 11460 | clear_proceed_status (0); |
c906108c SS |
11461 | |
11462 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11463 | this function. */ |
c5aa993b | 11464 | |
ffc2605c | 11465 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11466 | |
6c5b2ebe PA |
11467 | std::vector<symtab_and_line> sals |
11468 | = (last_displayed_sal_is_valid () | |
11469 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11470 | get_last_displayed_symtab (), | |
11471 | get_last_displayed_line ()) | |
11472 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
11473 | NULL, (struct symtab *) NULL, 0)); | |
c5aa993b | 11474 | |
6c5b2ebe | 11475 | if (sals.size () != 1) |
8a3fe4f8 | 11476 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11477 | |
6c5b2ebe | 11478 | symtab_and_line &sal = sals[0]; |
c5aa993b | 11479 | |
c906108c | 11480 | if (*arg) |
8a3fe4f8 | 11481 | error (_("Junk at end of arguments.")); |
c5aa993b | 11482 | |
c906108c | 11483 | resolve_sal_pc (&sal); |
c5aa993b | 11484 | |
186c406b | 11485 | tp = inferior_thread (); |
5d5658a1 | 11486 | thread = tp->global_num; |
186c406b | 11487 | |
883bc8d1 PA |
11488 | old_chain = make_cleanup (null_cleanup, NULL); |
11489 | ||
8556afb4 PA |
11490 | /* Note linespec handling above invalidates the frame chain. |
11491 | Installing a breakpoint also invalidates the frame chain (as it | |
11492 | may need to switch threads), so do any frame handling before | |
11493 | that. */ | |
11494 | ||
11495 | frame = get_selected_frame (NULL); | |
11496 | frame_gdbarch = get_frame_arch (frame); | |
11497 | stack_frame_id = get_stack_frame_id (frame); | |
11498 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11499 | |
ae66c1fc EZ |
11500 | /* Keep within the current frame, or in frames called by the current |
11501 | one. */ | |
edb3359d | 11502 | |
883bc8d1 | 11503 | if (frame_id_p (caller_frame_id)) |
c906108c | 11504 | { |
883bc8d1 | 11505 | struct symtab_and_line sal2; |
cfc31633 | 11506 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11507 | |
11508 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11509 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11510 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11511 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11512 | sal2, | |
11513 | caller_frame_id, | |
11514 | bp_until); | |
11515 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11516 | |
883bc8d1 | 11517 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11518 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11519 | } |
c5aa993b | 11520 | |
c70a6932 JK |
11521 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11522 | frame = NULL; | |
11523 | ||
883bc8d1 PA |
11524 | if (anywhere) |
11525 | /* If the user told us to continue until a specified location, | |
11526 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11527 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11528 | null_frame_id, bp_until); | |
883bc8d1 PA |
11529 | else |
11530 | /* Otherwise, specify the selected frame, because we want to stop | |
11531 | only at the very same frame. */ | |
cfc31633 PA |
11532 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11533 | stack_frame_id, bp_until); | |
11534 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11535 | |
8980e177 | 11536 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11537 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11538 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11539 | |
cfc31633 | 11540 | discard_cleanups (old_chain); |
f107f563 | 11541 | |
cfc31633 | 11542 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11543 | } |
ae66c1fc | 11544 | |
c906108c SS |
11545 | /* This function attempts to parse an optional "if <cond>" clause |
11546 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11547 | |
c906108c SS |
11548 | Else, it returns a pointer to the condition string. (It does not |
11549 | attempt to evaluate the string against a particular block.) And, | |
11550 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11551 | if clause in the arg string. */ |
53a5351d | 11552 | |
63160a43 PA |
11553 | const char * |
11554 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11555 | { |
63160a43 | 11556 | const char *cond_string; |
c5aa993b JM |
11557 | |
11558 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11559 | return NULL; |
c5aa993b | 11560 | |
4a64f543 | 11561 | /* Skip the "if" keyword. */ |
c906108c | 11562 | (*arg) += 2; |
c5aa993b | 11563 | |
c906108c | 11564 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11565 | condition string. */ |
f1735a53 | 11566 | *arg = skip_spaces (*arg); |
c906108c | 11567 | cond_string = *arg; |
c5aa993b | 11568 | |
4a64f543 MS |
11569 | /* Assume that the condition occupies the remainder of the arg |
11570 | string. */ | |
c906108c | 11571 | (*arg) += strlen (cond_string); |
c5aa993b | 11572 | |
c906108c SS |
11573 | return cond_string; |
11574 | } | |
c5aa993b | 11575 | |
c906108c SS |
11576 | /* Commands to deal with catching events, such as signals, exceptions, |
11577 | process start/exit, etc. */ | |
c5aa993b JM |
11578 | |
11579 | typedef enum | |
11580 | { | |
44feb3ce TT |
11581 | catch_fork_temporary, catch_vfork_temporary, |
11582 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11583 | } |
11584 | catch_fork_kind; | |
11585 | ||
c906108c | 11586 | static void |
63160a43 | 11587 | catch_fork_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11588 | struct cmd_list_element *command) |
c906108c | 11589 | { |
63160a43 | 11590 | const char *arg = arg_entry; |
a6d9a66e | 11591 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11592 | const char *cond_string = NULL; |
44feb3ce TT |
11593 | catch_fork_kind fork_kind; |
11594 | int tempflag; | |
11595 | ||
11596 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11597 | tempflag = (fork_kind == catch_fork_temporary | |
11598 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11599 | |
44feb3ce TT |
11600 | if (!arg) |
11601 | arg = ""; | |
f1735a53 | 11602 | arg = skip_spaces (arg); |
c5aa993b | 11603 | |
c906108c | 11604 | /* The allowed syntax is: |
c5aa993b JM |
11605 | catch [v]fork |
11606 | catch [v]fork if <cond> | |
11607 | ||
4a64f543 | 11608 | First, check if there's an if clause. */ |
c906108c | 11609 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11610 | |
c906108c | 11611 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11612 | error (_("Junk at end of arguments.")); |
c5aa993b | 11613 | |
c906108c | 11614 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11615 | and enable reporting of such events. */ |
c5aa993b JM |
11616 | switch (fork_kind) |
11617 | { | |
44feb3ce TT |
11618 | case catch_fork_temporary: |
11619 | case catch_fork_permanent: | |
a6d9a66e | 11620 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11621 | &catch_fork_breakpoint_ops); |
c906108c | 11622 | break; |
44feb3ce TT |
11623 | case catch_vfork_temporary: |
11624 | case catch_vfork_permanent: | |
a6d9a66e | 11625 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11626 | &catch_vfork_breakpoint_ops); |
c906108c | 11627 | break; |
c5aa993b | 11628 | default: |
8a3fe4f8 | 11629 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11630 | break; |
c5aa993b | 11631 | } |
c906108c SS |
11632 | } |
11633 | ||
11634 | static void | |
63160a43 | 11635 | catch_exec_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11636 | struct cmd_list_element *command) |
c906108c | 11637 | { |
63160a43 | 11638 | const char *arg = arg_entry; |
a6d9a66e | 11639 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11640 | int tempflag; |
63160a43 | 11641 | const char *cond_string = NULL; |
c906108c | 11642 | |
44feb3ce TT |
11643 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11644 | ||
11645 | if (!arg) | |
11646 | arg = ""; | |
f1735a53 | 11647 | arg = skip_spaces (arg); |
c906108c SS |
11648 | |
11649 | /* The allowed syntax is: | |
c5aa993b JM |
11650 | catch exec |
11651 | catch exec if <cond> | |
c906108c | 11652 | |
4a64f543 | 11653 | First, check if there's an if clause. */ |
c906108c SS |
11654 | cond_string = ep_parse_optional_if_clause (&arg); |
11655 | ||
11656 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11657 | error (_("Junk at end of arguments.")); |
c906108c | 11658 | |
b270e6f9 TT |
11659 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11660 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11661 | &catch_exec_breakpoint_ops); |
11662 | c->exec_pathname = NULL; | |
11663 | ||
b270e6f9 | 11664 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11665 | } |
c5aa993b | 11666 | |
9ac4176b | 11667 | void |
28010a5d PA |
11668 | init_ada_exception_breakpoint (struct breakpoint *b, |
11669 | struct gdbarch *gdbarch, | |
11670 | struct symtab_and_line sal, | |
11671 | char *addr_string, | |
c0a91b2b | 11672 | const struct breakpoint_ops *ops, |
28010a5d | 11673 | int tempflag, |
349774ef | 11674 | int enabled, |
28010a5d | 11675 | int from_tty) |
f7f9143b | 11676 | { |
f7f9143b JB |
11677 | if (from_tty) |
11678 | { | |
5af949e3 UW |
11679 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11680 | if (!loc_gdbarch) | |
11681 | loc_gdbarch = gdbarch; | |
11682 | ||
6c95b8df PA |
11683 | describe_other_breakpoints (loc_gdbarch, |
11684 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11685 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11686 | version for exception catchpoints, because two catchpoints | |
11687 | used for different exception names will use the same address. | |
11688 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11689 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11690 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11691 | the user what type of catchpoint it is. The above is good |
11692 | enough for now, though. */ | |
11693 | } | |
11694 | ||
28010a5d | 11695 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11696 | |
349774ef | 11697 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11698 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11699 | b->location = string_to_event_location (&addr_string, |
11700 | language_def (language_ada)); | |
f7f9143b | 11701 | b->language = language_ada; |
f7f9143b JB |
11702 | } |
11703 | ||
c906108c | 11704 | static void |
fba45db2 | 11705 | catch_command (char *arg, int from_tty) |
c906108c | 11706 | { |
44feb3ce | 11707 | error (_("Catch requires an event name.")); |
c906108c SS |
11708 | } |
11709 | \f | |
11710 | ||
11711 | static void | |
fba45db2 | 11712 | tcatch_command (char *arg, int from_tty) |
c906108c | 11713 | { |
44feb3ce | 11714 | error (_("Catch requires an event name.")); |
c906108c SS |
11715 | } |
11716 | ||
8a2c437b TT |
11717 | /* A qsort comparison function that sorts breakpoints in order. */ |
11718 | ||
11719 | static int | |
11720 | compare_breakpoints (const void *a, const void *b) | |
11721 | { | |
9a3c8263 | 11722 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11723 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11724 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11725 | uintptr_t ub = (uintptr_t) *bb; |
11726 | ||
11727 | if ((*ba)->number < (*bb)->number) | |
11728 | return -1; | |
11729 | else if ((*ba)->number > (*bb)->number) | |
11730 | return 1; | |
11731 | ||
11732 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11733 | the number 0. */ | |
11734 | if (ua < ub) | |
11735 | return -1; | |
94b0e70d | 11736 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11737 | } |
11738 | ||
80f8a6eb | 11739 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11740 | |
11741 | static void | |
fba45db2 | 11742 | clear_command (char *arg, int from_tty) |
c906108c | 11743 | { |
8a2c437b | 11744 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11745 | VEC(breakpoint_p) *found = 0; |
11746 | int ix; | |
c906108c | 11747 | int default_match; |
c906108c | 11748 | int i; |
8a2c437b | 11749 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c | 11750 | |
6c5b2ebe PA |
11751 | std::vector<symtab_and_line> decoded_sals; |
11752 | symtab_and_line last_sal; | |
11753 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11754 | if (arg) |
11755 | { | |
6c5b2ebe PA |
11756 | decoded_sals |
11757 | = decode_line_with_current_source (arg, | |
11758 | (DECODE_LINE_FUNFIRSTLINE | |
11759 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11760 | default_match = 0; |
6c5b2ebe | 11761 | sals = decoded_sals; |
c906108c SS |
11762 | } |
11763 | else | |
11764 | { | |
1bfeeb0f JL |
11765 | /* Set sal's line, symtab, pc, and pspace to the values |
11766 | corresponding to the last call to print_frame_info. If the | |
11767 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11768 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11769 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11770 | error (_("No source file specified.")); |
c906108c | 11771 | |
c906108c | 11772 | default_match = 1; |
6c5b2ebe | 11773 | sals = last_sal; |
c906108c SS |
11774 | } |
11775 | ||
4a64f543 MS |
11776 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11777 | seems, because all existing breakpoints typically have both | |
11778 | file/line and pc set. So, if clear is given file/line, we can | |
11779 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11780 | |
11781 | We only support clearing given the address explicitly | |
11782 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11783 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11784 | due to optimization, all in one block. |
4a64f543 MS |
11785 | |
11786 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11787 | PC corresponding to the same file:line, the breakpoint won't |
11788 | be cleared. We probably can still clear the breakpoint, but | |
11789 | since the other PC value is never presented to user, user | |
11790 | can only find it by guessing, and it does not seem important | |
11791 | to support that. */ | |
11792 | ||
4a64f543 MS |
11793 | /* For each line spec given, delete bps which correspond to it. Do |
11794 | it in two passes, solely to preserve the current behavior that | |
11795 | from_tty is forced true if we delete more than one | |
11796 | breakpoint. */ | |
c906108c | 11797 | |
80f8a6eb | 11798 | found = NULL; |
8a2c437b | 11799 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
6c5b2ebe | 11800 | for (const auto &sal : sals) |
c906108c | 11801 | { |
05cba821 JK |
11802 | const char *sal_fullname; |
11803 | ||
c906108c | 11804 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11805 | If line given (pc == 0), clear all bpts on specified line. |
11806 | If defaulting, clear all bpts on default line | |
c906108c | 11807 | or at default pc. |
c5aa993b JM |
11808 | |
11809 | defaulting sal.pc != 0 tests to do | |
11810 | ||
11811 | 0 1 pc | |
11812 | 1 1 pc _and_ line | |
11813 | 0 0 line | |
11814 | 1 0 <can't happen> */ | |
c906108c | 11815 | |
05cba821 JK |
11816 | sal_fullname = (sal.symtab == NULL |
11817 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11818 | |
4a64f543 | 11819 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11820 | ALL_BREAKPOINTS (b) |
c5aa993b | 11821 | { |
0d381245 | 11822 | int match = 0; |
4a64f543 | 11823 | /* Are we going to delete b? */ |
cc60f2e3 | 11824 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11825 | { |
11826 | struct bp_location *loc = b->loc; | |
11827 | for (; loc; loc = loc->next) | |
11828 | { | |
f8eba3c6 TT |
11829 | /* If the user specified file:line, don't allow a PC |
11830 | match. This matches historical gdb behavior. */ | |
11831 | int pc_match = (!sal.explicit_line | |
11832 | && sal.pc | |
11833 | && (loc->pspace == sal.pspace) | |
11834 | && (loc->address == sal.pc) | |
11835 | && (!section_is_overlay (loc->section) | |
11836 | || loc->section == sal.section)); | |
4aac40c8 TT |
11837 | int line_match = 0; |
11838 | ||
11839 | if ((default_match || sal.explicit_line) | |
2f202fde | 11840 | && loc->symtab != NULL |
05cba821 | 11841 | && sal_fullname != NULL |
4aac40c8 | 11842 | && sal.pspace == loc->pspace |
05cba821 JK |
11843 | && loc->line_number == sal.line |
11844 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11845 | sal_fullname) == 0) | |
11846 | line_match = 1; | |
4aac40c8 | 11847 | |
0d381245 VP |
11848 | if (pc_match || line_match) |
11849 | { | |
11850 | match = 1; | |
11851 | break; | |
11852 | } | |
11853 | } | |
11854 | } | |
11855 | ||
11856 | if (match) | |
d6e956e5 | 11857 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11858 | } |
80f8a6eb | 11859 | } |
8a2c437b | 11860 | |
80f8a6eb | 11861 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11862 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11863 | { |
11864 | if (arg) | |
8a3fe4f8 | 11865 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11866 | else |
8a3fe4f8 | 11867 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11868 | } |
c906108c | 11869 | |
8a2c437b TT |
11870 | /* Remove duplicates from the vec. */ |
11871 | qsort (VEC_address (breakpoint_p, found), | |
11872 | VEC_length (breakpoint_p, found), | |
11873 | sizeof (breakpoint_p), | |
11874 | compare_breakpoints); | |
11875 | prev = VEC_index (breakpoint_p, found, 0); | |
11876 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11877 | { | |
11878 | if (b == prev) | |
11879 | { | |
11880 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11881 | --ix; | |
11882 | } | |
11883 | } | |
11884 | ||
d6e956e5 | 11885 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11886 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11887 | if (from_tty) |
a3f17187 | 11888 | { |
d6e956e5 | 11889 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11890 | printf_unfiltered (_("Deleted breakpoint ")); |
11891 | else | |
11892 | printf_unfiltered (_("Deleted breakpoints ")); | |
11893 | } | |
d6e956e5 VP |
11894 | |
11895 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11896 | { |
c5aa993b | 11897 | if (from_tty) |
d6e956e5 VP |
11898 | printf_unfiltered ("%d ", b->number); |
11899 | delete_breakpoint (b); | |
c906108c | 11900 | } |
80f8a6eb MS |
11901 | if (from_tty) |
11902 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11903 | |
11904 | do_cleanups (cleanups); | |
c906108c SS |
11905 | } |
11906 | \f | |
11907 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11908 | all breakpoints that are marked for deletion, whether hit or not. | |
11909 | This is called after any breakpoint is hit, or after errors. */ | |
11910 | ||
11911 | void | |
fba45db2 | 11912 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11913 | { |
35df4500 | 11914 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11915 | |
11916 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11917 | if (bs->breakpoint_at |
11918 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11919 | && bs->stop) |
f431efe5 | 11920 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11921 | |
35df4500 | 11922 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11923 | { |
b5de0fa7 | 11924 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11925 | delete_breakpoint (b); |
11926 | } | |
c906108c SS |
11927 | } |
11928 | ||
4a64f543 MS |
11929 | /* A comparison function for bp_location AP and BP being interfaced to |
11930 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11931 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 11932 | secondarily by ordering first permanent elements and |
4a64f543 | 11933 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 11934 | qsort being an unstable algorithm. */ |
876fa593 JK |
11935 | |
11936 | static int | |
f5336ca5 | 11937 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 11938 | { |
9a3c8263 SM |
11939 | const struct bp_location *a = *(const struct bp_location **) ap; |
11940 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
11941 | |
11942 | if (a->address != b->address) | |
11943 | return (a->address > b->address) - (a->address < b->address); | |
11944 | ||
dea2aa5f LM |
11945 | /* Sort locations at the same address by their pspace number, keeping |
11946 | locations of the same inferior (in a multi-inferior environment) | |
11947 | grouped. */ | |
11948 | ||
11949 | if (a->pspace->num != b->pspace->num) | |
11950 | return ((a->pspace->num > b->pspace->num) | |
11951 | - (a->pspace->num < b->pspace->num)); | |
11952 | ||
876fa593 | 11953 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11954 | if (a->permanent != b->permanent) |
11955 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11956 | |
c56a97f9 JK |
11957 | /* Make the internal GDB representation stable across GDB runs |
11958 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11959 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11960 | |
11961 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11962 | return ((a->owner->number > b->owner->number) |
11963 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11964 | |
11965 | return (a > b) - (a < b); | |
11966 | } | |
11967 | ||
f5336ca5 PA |
11968 | /* Set bp_locations_placed_address_before_address_max and |
11969 | bp_locations_shadow_len_after_address_max according to the current | |
11970 | content of the bp_locations array. */ | |
f7545552 TT |
11971 | |
11972 | static void | |
f5336ca5 | 11973 | bp_locations_target_extensions_update (void) |
f7545552 | 11974 | { |
876fa593 JK |
11975 | struct bp_location *bl, **blp_tmp; |
11976 | ||
f5336ca5 PA |
11977 | bp_locations_placed_address_before_address_max = 0; |
11978 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11979 | |
11980 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11981 | { | |
11982 | CORE_ADDR start, end, addr; | |
11983 | ||
11984 | if (!bp_location_has_shadow (bl)) | |
11985 | continue; | |
11986 | ||
11987 | start = bl->target_info.placed_address; | |
11988 | end = start + bl->target_info.shadow_len; | |
11989 | ||
11990 | gdb_assert (bl->address >= start); | |
11991 | addr = bl->address - start; | |
f5336ca5 PA |
11992 | if (addr > bp_locations_placed_address_before_address_max) |
11993 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11994 | |
11995 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11996 | ||
11997 | gdb_assert (bl->address < end); | |
11998 | addr = end - bl->address; | |
f5336ca5 PA |
11999 | if (addr > bp_locations_shadow_len_after_address_max) |
12000 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 12001 | } |
f7545552 TT |
12002 | } |
12003 | ||
1e4d1764 YQ |
12004 | /* Download tracepoint locations if they haven't been. */ |
12005 | ||
12006 | static void | |
12007 | download_tracepoint_locations (void) | |
12008 | { | |
7ed2c994 | 12009 | struct breakpoint *b; |
dd2e65cc | 12010 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 12011 | |
5ed8105e | 12012 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 12013 | |
7ed2c994 | 12014 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12015 | { |
7ed2c994 | 12016 | struct bp_location *bl; |
1e4d1764 | 12017 | struct tracepoint *t; |
f2a8bc8a | 12018 | int bp_location_downloaded = 0; |
1e4d1764 | 12019 | |
7ed2c994 | 12020 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12021 | ? !may_insert_fast_tracepoints |
12022 | : !may_insert_tracepoints)) | |
12023 | continue; | |
12024 | ||
dd2e65cc YQ |
12025 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12026 | { | |
12027 | if (target_can_download_tracepoint ()) | |
12028 | can_download_tracepoint = TRIBOOL_TRUE; | |
12029 | else | |
12030 | can_download_tracepoint = TRIBOOL_FALSE; | |
12031 | } | |
12032 | ||
12033 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12034 | break; | |
12035 | ||
7ed2c994 YQ |
12036 | for (bl = b->loc; bl; bl = bl->next) |
12037 | { | |
12038 | /* In tracepoint, locations are _never_ duplicated, so | |
12039 | should_be_inserted is equivalent to | |
12040 | unduplicated_should_be_inserted. */ | |
12041 | if (!should_be_inserted (bl) || bl->inserted) | |
12042 | continue; | |
1e4d1764 | 12043 | |
7ed2c994 | 12044 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12045 | |
7ed2c994 | 12046 | target_download_tracepoint (bl); |
1e4d1764 | 12047 | |
7ed2c994 | 12048 | bl->inserted = 1; |
f2a8bc8a | 12049 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12050 | } |
12051 | t = (struct tracepoint *) b; | |
12052 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12053 | if (bp_location_downloaded) |
12054 | observer_notify_breakpoint_modified (b); | |
1e4d1764 | 12055 | } |
1e4d1764 YQ |
12056 | } |
12057 | ||
934709f0 PW |
12058 | /* Swap the insertion/duplication state between two locations. */ |
12059 | ||
12060 | static void | |
12061 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12062 | { | |
12063 | const int left_inserted = left->inserted; | |
12064 | const int left_duplicate = left->duplicate; | |
b775012e | 12065 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12066 | const struct bp_target_info left_target_info = left->target_info; |
12067 | ||
1e4d1764 YQ |
12068 | /* Locations of tracepoints can never be duplicated. */ |
12069 | if (is_tracepoint (left->owner)) | |
12070 | gdb_assert (!left->duplicate); | |
12071 | if (is_tracepoint (right->owner)) | |
12072 | gdb_assert (!right->duplicate); | |
12073 | ||
934709f0 PW |
12074 | left->inserted = right->inserted; |
12075 | left->duplicate = right->duplicate; | |
b775012e | 12076 | left->needs_update = right->needs_update; |
934709f0 PW |
12077 | left->target_info = right->target_info; |
12078 | right->inserted = left_inserted; | |
12079 | right->duplicate = left_duplicate; | |
b775012e | 12080 | right->needs_update = left_needs_update; |
934709f0 PW |
12081 | right->target_info = left_target_info; |
12082 | } | |
12083 | ||
b775012e LM |
12084 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12085 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12086 | conditions on the target's side. Such conditions need to be updated on | |
12087 | the target. */ | |
12088 | ||
12089 | static void | |
12090 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12091 | { | |
12092 | struct bp_location **locp = NULL, **loc2p; | |
12093 | struct bp_location *loc; | |
12094 | CORE_ADDR address = 0; | |
12095 | int pspace_num; | |
12096 | ||
12097 | address = bl->address; | |
12098 | pspace_num = bl->pspace->num; | |
12099 | ||
12100 | /* This is only meaningful if the target is | |
12101 | evaluating conditions and if the user has | |
12102 | opted for condition evaluation on the target's | |
12103 | side. */ | |
12104 | if (gdb_evaluates_breakpoint_condition_p () | |
12105 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12106 | return; | |
12107 | ||
12108 | /* Flag all breakpoint locations with this address and | |
12109 | the same program space as the location | |
12110 | as "its condition has changed". We need to | |
12111 | update the conditions on the target's side. */ | |
12112 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12113 | { | |
12114 | loc = *loc2p; | |
12115 | ||
12116 | if (!is_breakpoint (loc->owner) | |
12117 | || pspace_num != loc->pspace->num) | |
12118 | continue; | |
12119 | ||
12120 | /* Flag the location appropriately. We use a different state to | |
12121 | let everyone know that we already updated the set of locations | |
12122 | with addr bl->address and program space bl->pspace. This is so | |
12123 | we don't have to keep calling these functions just to mark locations | |
12124 | that have already been marked. */ | |
12125 | loc->condition_changed = condition_updated; | |
12126 | ||
12127 | /* Free the agent expression bytecode as well. We will compute | |
12128 | it later on. */ | |
833177a4 | 12129 | loc->cond_bytecode.reset (); |
b775012e LM |
12130 | } |
12131 | } | |
44702360 PA |
12132 | /* Called whether new breakpoints are created, or existing breakpoints |
12133 | deleted, to update the global location list and recompute which | |
12134 | locations are duplicate of which. | |
b775012e | 12135 | |
04086b45 PA |
12136 | The INSERT_MODE flag determines whether locations may not, may, or |
12137 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12138 | info. */ | |
b60e7edf | 12139 | |
0d381245 | 12140 | static void |
44702360 | 12141 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12142 | { |
74960c60 | 12143 | struct breakpoint *b; |
876fa593 | 12144 | struct bp_location **locp, *loc; |
f7545552 | 12145 | struct cleanup *cleanups; |
b775012e LM |
12146 | /* Last breakpoint location address that was marked for update. */ |
12147 | CORE_ADDR last_addr = 0; | |
12148 | /* Last breakpoint location program space that was marked for update. */ | |
12149 | int last_pspace_num = -1; | |
f7545552 | 12150 | |
2d134ed3 PA |
12151 | /* Used in the duplicates detection below. When iterating over all |
12152 | bp_locations, points to the first bp_location of a given address. | |
12153 | Breakpoints and watchpoints of different types are never | |
12154 | duplicates of each other. Keep one pointer for each type of | |
12155 | breakpoint/watchpoint, so we only need to loop over all locations | |
12156 | once. */ | |
12157 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12158 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12159 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12160 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12161 | |
f5336ca5 PA |
12162 | /* Saved former bp_locations array which we compare against the newly |
12163 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
12164 | struct bp_location **old_locations, **old_locp; | |
12165 | unsigned old_locations_count; | |
876fa593 | 12166 | |
f5336ca5 PA |
12167 | old_locations = bp_locations; |
12168 | old_locations_count = bp_locations_count; | |
12169 | bp_locations = NULL; | |
12170 | bp_locations_count = 0; | |
12171 | cleanups = make_cleanup (xfree, old_locations); | |
0d381245 | 12172 | |
74960c60 | 12173 | ALL_BREAKPOINTS (b) |
876fa593 | 12174 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 12175 | bp_locations_count++; |
876fa593 | 12176 | |
f5336ca5 PA |
12177 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
12178 | locp = bp_locations; | |
876fa593 JK |
12179 | ALL_BREAKPOINTS (b) |
12180 | for (loc = b->loc; loc; loc = loc->next) | |
12181 | *locp++ = loc; | |
f5336ca5 PA |
12182 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
12183 | bp_locations_compare); | |
876fa593 | 12184 | |
f5336ca5 | 12185 | bp_locations_target_extensions_update (); |
74960c60 | 12186 | |
4a64f543 MS |
12187 | /* Identify bp_location instances that are no longer present in the |
12188 | new list, and therefore should be freed. Note that it's not | |
12189 | necessary that those locations should be removed from inferior -- | |
12190 | if there's another location at the same address (previously | |
12191 | marked as duplicate), we don't need to remove/insert the | |
12192 | location. | |
876fa593 | 12193 | |
4a64f543 MS |
12194 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12195 | and former bp_location array state respectively. */ | |
876fa593 | 12196 | |
f5336ca5 PA |
12197 | locp = bp_locations; |
12198 | for (old_locp = old_locations; | |
12199 | old_locp < old_locations + old_locations_count; | |
876fa593 | 12200 | old_locp++) |
74960c60 | 12201 | { |
876fa593 | 12202 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12203 | struct bp_location **loc2p; |
876fa593 | 12204 | |
e5dd4106 | 12205 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12206 | not, we have to free it. */ |
c7d46a38 | 12207 | int found_object = 0; |
20874c92 VP |
12208 | /* Tells if the location should remain inserted in the target. */ |
12209 | int keep_in_target = 0; | |
12210 | int removed = 0; | |
876fa593 | 12211 | |
4a64f543 MS |
12212 | /* Skip LOCP entries which will definitely never be needed. |
12213 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 12214 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 12215 | && (*locp)->address < old_loc->address) |
876fa593 | 12216 | locp++; |
c7d46a38 PA |
12217 | |
12218 | for (loc2p = locp; | |
f5336ca5 | 12219 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
12220 | && (*loc2p)->address == old_loc->address); |
12221 | loc2p++) | |
12222 | { | |
b775012e LM |
12223 | /* Check if this is a new/duplicated location or a duplicated |
12224 | location that had its condition modified. If so, we want to send | |
12225 | its condition to the target if evaluation of conditions is taking | |
12226 | place there. */ | |
12227 | if ((*loc2p)->condition_changed == condition_modified | |
12228 | && (last_addr != old_loc->address | |
12229 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12230 | { |
b775012e LM |
12231 | force_breakpoint_reinsertion (*loc2p); |
12232 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12233 | } |
b775012e LM |
12234 | |
12235 | if (*loc2p == old_loc) | |
12236 | found_object = 1; | |
c7d46a38 | 12237 | } |
74960c60 | 12238 | |
b775012e LM |
12239 | /* We have already handled this address, update it so that we don't |
12240 | have to go through updates again. */ | |
12241 | last_addr = old_loc->address; | |
12242 | ||
12243 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12244 | if (!found_object) | |
12245 | force_breakpoint_reinsertion (old_loc); | |
12246 | ||
4a64f543 MS |
12247 | /* If this location is no longer present, and inserted, look if |
12248 | there's maybe a new location at the same address. If so, | |
12249 | mark that one inserted, and don't remove this one. This is | |
12250 | needed so that we don't have a time window where a breakpoint | |
12251 | at certain location is not inserted. */ | |
74960c60 | 12252 | |
876fa593 | 12253 | if (old_loc->inserted) |
0d381245 | 12254 | { |
4a64f543 MS |
12255 | /* If the location is inserted now, we might have to remove |
12256 | it. */ | |
74960c60 | 12257 | |
876fa593 | 12258 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12259 | { |
4a64f543 MS |
12260 | /* The location is still present in the location list, |
12261 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12262 | keep_in_target = 1; |
74960c60 VP |
12263 | } |
12264 | else | |
12265 | { | |
b775012e LM |
12266 | /* This location still exists, but it won't be kept in the |
12267 | target since it may have been disabled. We proceed to | |
12268 | remove its target-side condition. */ | |
12269 | ||
4a64f543 MS |
12270 | /* The location is either no longer present, or got |
12271 | disabled. See if there's another location at the | |
12272 | same address, in which case we don't need to remove | |
12273 | this one from the target. */ | |
876fa593 | 12274 | |
2bdf28a0 | 12275 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12276 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12277 | { | |
876fa593 | 12278 | for (loc2p = locp; |
f5336ca5 | 12279 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12280 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12281 | loc2p++) |
12282 | { | |
12283 | struct bp_location *loc2 = *loc2p; | |
12284 | ||
2d134ed3 | 12285 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12286 | { |
85d721b8 PA |
12287 | /* Read watchpoint locations are switched to |
12288 | access watchpoints, if the former are not | |
12289 | supported, but the latter are. */ | |
12290 | if (is_hardware_watchpoint (old_loc->owner)) | |
12291 | { | |
12292 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12293 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12294 | } | |
12295 | ||
934709f0 PW |
12296 | /* loc2 is a duplicated location. We need to check |
12297 | if it should be inserted in case it will be | |
12298 | unduplicated. */ | |
12299 | if (loc2 != old_loc | |
12300 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12301 | { |
934709f0 | 12302 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12303 | keep_in_target = 1; |
12304 | break; | |
12305 | } | |
876fa593 JK |
12306 | } |
12307 | } | |
12308 | } | |
74960c60 VP |
12309 | } |
12310 | ||
20874c92 VP |
12311 | if (!keep_in_target) |
12312 | { | |
834c0d03 | 12313 | if (remove_breakpoint (old_loc)) |
20874c92 | 12314 | { |
4a64f543 MS |
12315 | /* This is just about all we can do. We could keep |
12316 | this location on the global list, and try to | |
12317 | remove it next time, but there's no particular | |
12318 | reason why we will succeed next time. | |
20874c92 | 12319 | |
4a64f543 MS |
12320 | Note that at this point, old_loc->owner is still |
12321 | valid, as delete_breakpoint frees the breakpoint | |
12322 | only after calling us. */ | |
3e43a32a MS |
12323 | printf_filtered (_("warning: Error removing " |
12324 | "breakpoint %d\n"), | |
876fa593 | 12325 | old_loc->owner->number); |
20874c92 VP |
12326 | } |
12327 | removed = 1; | |
12328 | } | |
0d381245 | 12329 | } |
74960c60 VP |
12330 | |
12331 | if (!found_object) | |
1c5cfe86 | 12332 | { |
fbea99ea | 12333 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12334 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12335 | { |
db82e815 PA |
12336 | /* This location was removed from the target. In |
12337 | non-stop mode, a race condition is possible where | |
12338 | we've removed a breakpoint, but stop events for that | |
12339 | breakpoint are already queued and will arrive later. | |
12340 | We apply an heuristic to be able to distinguish such | |
12341 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12342 | breakpoint location for a bit, and will retire it | |
12343 | after we see some number of events. The theory here | |
12344 | is that reporting of events should, "on the average", | |
12345 | be fair, so after a while we'll see events from all | |
12346 | threads that have anything of interest, and no longer | |
12347 | need to keep this breakpoint location around. We | |
12348 | don't hold locations forever so to reduce chances of | |
12349 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12350 | SIGTRAP. | |
12351 | ||
12352 | The heuristic failing can be disastrous on | |
12353 | decr_pc_after_break targets. | |
12354 | ||
12355 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12356 | if we fail to recognize a late breakpoint SIGTRAP, | |
12357 | because events_till_retirement has reached 0 too | |
12358 | soon, we'll fail to do the PC adjustment, and report | |
12359 | a random SIGTRAP to the user. When the user resumes | |
12360 | the inferior, it will most likely immediately crash | |
2dec564e | 12361 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12362 | corrupted, because of being resumed e.g., in the |
12363 | middle of a multi-byte instruction, or skipped a | |
12364 | one-byte instruction. This was actually seen happen | |
12365 | on native x86-linux, and should be less rare on | |
12366 | targets that do not support new thread events, like | |
12367 | remote, due to the heuristic depending on | |
12368 | thread_count. | |
12369 | ||
12370 | Mistaking a random SIGTRAP for a breakpoint trap | |
12371 | causes similar symptoms (PC adjustment applied when | |
12372 | it shouldn't), but then again, playing with SIGTRAPs | |
12373 | behind the debugger's back is asking for trouble. | |
12374 | ||
12375 | Since hardware watchpoint traps are always | |
12376 | distinguishable from other traps, so we don't need to | |
12377 | apply keep hardware watchpoint moribund locations | |
12378 | around. We simply always ignore hardware watchpoint | |
12379 | traps we can no longer explain. */ | |
12380 | ||
876fa593 JK |
12381 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12382 | old_loc->owner = NULL; | |
20874c92 | 12383 | |
876fa593 | 12384 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12385 | } |
12386 | else | |
f431efe5 PA |
12387 | { |
12388 | old_loc->owner = NULL; | |
12389 | decref_bp_location (&old_loc); | |
12390 | } | |
20874c92 | 12391 | } |
74960c60 | 12392 | } |
1c5cfe86 | 12393 | |
348d480f PA |
12394 | /* Rescan breakpoints at the same address and section, marking the |
12395 | first one as "first" and any others as "duplicates". This is so | |
12396 | that the bpt instruction is only inserted once. If we have a | |
12397 | permanent breakpoint at the same place as BPT, make that one the | |
12398 | official one, and the rest as duplicates. Permanent breakpoints | |
12399 | are sorted first for the same address. | |
12400 | ||
12401 | Do the same for hardware watchpoints, but also considering the | |
12402 | watchpoint's type (regular/access/read) and length. */ | |
12403 | ||
12404 | bp_loc_first = NULL; | |
12405 | wp_loc_first = NULL; | |
12406 | awp_loc_first = NULL; | |
12407 | rwp_loc_first = NULL; | |
12408 | ALL_BP_LOCATIONS (loc, locp) | |
12409 | { | |
12410 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12411 | non-NULL. */ | |
348d480f | 12412 | struct bp_location **loc_first_p; |
d3fbdd86 | 12413 | b = loc->owner; |
348d480f | 12414 | |
6f380991 | 12415 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12416 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12417 | /* Don't detect duplicate for tracepoint locations because they are |
12418 | never duplicated. See the comments in field `duplicate' of | |
12419 | `struct bp_location'. */ | |
348d480f | 12420 | || is_tracepoint (b)) |
b775012e LM |
12421 | { |
12422 | /* Clear the condition modification flag. */ | |
12423 | loc->condition_changed = condition_unchanged; | |
12424 | continue; | |
12425 | } | |
348d480f | 12426 | |
348d480f PA |
12427 | if (b->type == bp_hardware_watchpoint) |
12428 | loc_first_p = &wp_loc_first; | |
12429 | else if (b->type == bp_read_watchpoint) | |
12430 | loc_first_p = &rwp_loc_first; | |
12431 | else if (b->type == bp_access_watchpoint) | |
12432 | loc_first_p = &awp_loc_first; | |
12433 | else | |
12434 | loc_first_p = &bp_loc_first; | |
12435 | ||
12436 | if (*loc_first_p == NULL | |
12437 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12438 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12439 | { | |
12440 | *loc_first_p = loc; | |
12441 | loc->duplicate = 0; | |
b775012e LM |
12442 | |
12443 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12444 | { | |
12445 | loc->needs_update = 1; | |
12446 | /* Clear the condition modification flag. */ | |
12447 | loc->condition_changed = condition_unchanged; | |
12448 | } | |
348d480f PA |
12449 | continue; |
12450 | } | |
12451 | ||
934709f0 PW |
12452 | |
12453 | /* This and the above ensure the invariant that the first location | |
12454 | is not duplicated, and is the inserted one. | |
12455 | All following are marked as duplicated, and are not inserted. */ | |
12456 | if (loc->inserted) | |
12457 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12458 | loc->duplicate = 1; |
12459 | ||
b775012e LM |
12460 | /* Clear the condition modification flag. */ |
12461 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12462 | } |
12463 | ||
a25a5a45 | 12464 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12465 | { |
04086b45 | 12466 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12467 | insert_breakpoint_locations (); |
12468 | else | |
12469 | { | |
44702360 PA |
12470 | /* Even though the caller told us to not insert new |
12471 | locations, we may still need to update conditions on the | |
12472 | target's side of breakpoints that were already inserted | |
12473 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12474 | only update conditions for locations that are marked |
12475 | "needs_update". */ | |
12476 | update_inserted_breakpoint_locations (); | |
12477 | } | |
12478 | } | |
348d480f | 12479 | |
04086b45 | 12480 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12481 | download_tracepoint_locations (); |
12482 | ||
348d480f PA |
12483 | do_cleanups (cleanups); |
12484 | } | |
12485 | ||
12486 | void | |
12487 | breakpoint_retire_moribund (void) | |
12488 | { | |
12489 | struct bp_location *loc; | |
12490 | int ix; | |
12491 | ||
12492 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12493 | if (--(loc->events_till_retirement) == 0) | |
12494 | { | |
12495 | decref_bp_location (&loc); | |
12496 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12497 | --ix; | |
12498 | } | |
12499 | } | |
12500 | ||
12501 | static void | |
44702360 | 12502 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12503 | { |
348d480f | 12504 | |
492d29ea PA |
12505 | TRY |
12506 | { | |
12507 | update_global_location_list (insert_mode); | |
12508 | } | |
12509 | CATCH (e, RETURN_MASK_ERROR) | |
12510 | { | |
12511 | } | |
12512 | END_CATCH | |
348d480f PA |
12513 | } |
12514 | ||
12515 | /* Clear BKP from a BPS. */ | |
12516 | ||
12517 | static void | |
12518 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12519 | { | |
12520 | bpstat bs; | |
12521 | ||
12522 | for (bs = bps; bs; bs = bs->next) | |
12523 | if (bs->breakpoint_at == bpt) | |
12524 | { | |
12525 | bs->breakpoint_at = NULL; | |
12526 | bs->old_val = NULL; | |
12527 | /* bs->commands will be freed later. */ | |
12528 | } | |
12529 | } | |
12530 | ||
12531 | /* Callback for iterate_over_threads. */ | |
12532 | static int | |
12533 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12534 | { | |
9a3c8263 | 12535 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12536 | |
12537 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12538 | return 0; | |
12539 | } | |
12540 | ||
12541 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12542 | callbacks. */ | |
12543 | ||
12544 | static void | |
12545 | say_where (struct breakpoint *b) | |
12546 | { | |
12547 | struct value_print_options opts; | |
12548 | ||
12549 | get_user_print_options (&opts); | |
12550 | ||
12551 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12552 | single string. */ | |
12553 | if (b->loc == NULL) | |
12554 | { | |
f00aae0f KS |
12555 | /* For pending locations, the output differs slightly based |
12556 | on b->extra_string. If this is non-NULL, it contains either | |
12557 | a condition or dprintf arguments. */ | |
12558 | if (b->extra_string == NULL) | |
12559 | { | |
12560 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12561 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12562 | } |
12563 | else if (b->type == bp_dprintf) | |
12564 | { | |
12565 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12566 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12567 | b->extra_string); |
12568 | } | |
12569 | else | |
12570 | { | |
12571 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12572 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12573 | b->extra_string); |
12574 | } | |
348d480f PA |
12575 | } |
12576 | else | |
12577 | { | |
2f202fde | 12578 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12579 | { |
12580 | printf_filtered (" at "); | |
12581 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12582 | gdb_stdout); | |
12583 | } | |
2f202fde | 12584 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12585 | { |
12586 | /* If there is a single location, we can print the location | |
12587 | more nicely. */ | |
12588 | if (b->loc->next == NULL) | |
12589 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12590 | symtab_to_filename_for_display (b->loc->symtab), |
12591 | b->loc->line_number); | |
f8eba3c6 TT |
12592 | else |
12593 | /* This is not ideal, but each location may have a | |
12594 | different file name, and this at least reflects the | |
12595 | real situation somewhat. */ | |
f00aae0f | 12596 | printf_filtered (": %s.", |
d28cd78a | 12597 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12598 | } |
348d480f PA |
12599 | |
12600 | if (b->loc->next) | |
12601 | { | |
12602 | struct bp_location *loc = b->loc; | |
12603 | int n = 0; | |
12604 | for (; loc; loc = loc->next) | |
12605 | ++n; | |
12606 | printf_filtered (" (%d locations)", n); | |
12607 | } | |
12608 | } | |
12609 | } | |
12610 | ||
348d480f PA |
12611 | /* Default bp_location_ops methods. */ |
12612 | ||
12613 | static void | |
12614 | bp_location_dtor (struct bp_location *self) | |
12615 | { | |
348d480f PA |
12616 | xfree (self->function_name); |
12617 | } | |
12618 | ||
12619 | static const struct bp_location_ops bp_location_ops = | |
12620 | { | |
12621 | bp_location_dtor | |
12622 | }; | |
12623 | ||
c1fc2657 | 12624 | /* Destructor for the breakpoint base class. */ |
348d480f | 12625 | |
c1fc2657 | 12626 | breakpoint::~breakpoint () |
348d480f | 12627 | { |
c1fc2657 SM |
12628 | decref_counted_command_line (&this->commands); |
12629 | xfree (this->cond_string); | |
12630 | xfree (this->extra_string); | |
12631 | xfree (this->filter); | |
348d480f PA |
12632 | } |
12633 | ||
2060206e PA |
12634 | static struct bp_location * |
12635 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12636 | { |
5625a286 | 12637 | return new bp_location (&bp_location_ops, self); |
348d480f PA |
12638 | } |
12639 | ||
2060206e PA |
12640 | static void |
12641 | base_breakpoint_re_set (struct breakpoint *b) | |
12642 | { | |
12643 | /* Nothing to re-set. */ | |
12644 | } | |
12645 | ||
12646 | #define internal_error_pure_virtual_called() \ | |
12647 | gdb_assert_not_reached ("pure virtual function called") | |
12648 | ||
12649 | static int | |
12650 | base_breakpoint_insert_location (struct bp_location *bl) | |
12651 | { | |
12652 | internal_error_pure_virtual_called (); | |
12653 | } | |
12654 | ||
12655 | static int | |
73971819 PA |
12656 | base_breakpoint_remove_location (struct bp_location *bl, |
12657 | enum remove_bp_reason reason) | |
2060206e PA |
12658 | { |
12659 | internal_error_pure_virtual_called (); | |
12660 | } | |
12661 | ||
12662 | static int | |
12663 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12664 | struct address_space *aspace, | |
09ac7c10 TT |
12665 | CORE_ADDR bp_addr, |
12666 | const struct target_waitstatus *ws) | |
2060206e PA |
12667 | { |
12668 | internal_error_pure_virtual_called (); | |
12669 | } | |
12670 | ||
12671 | static void | |
12672 | base_breakpoint_check_status (bpstat bs) | |
12673 | { | |
12674 | /* Always stop. */ | |
12675 | } | |
12676 | ||
12677 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12678 | errors. */ | |
12679 | ||
12680 | static int | |
12681 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12682 | { | |
12683 | internal_error_pure_virtual_called (); | |
12684 | } | |
12685 | ||
12686 | /* A "resources_needed" breakpoint_ops method that just internal | |
12687 | errors. */ | |
12688 | ||
12689 | static int | |
12690 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12691 | { | |
12692 | internal_error_pure_virtual_called (); | |
12693 | } | |
12694 | ||
12695 | static enum print_stop_action | |
12696 | base_breakpoint_print_it (bpstat bs) | |
12697 | { | |
12698 | internal_error_pure_virtual_called (); | |
12699 | } | |
12700 | ||
12701 | static void | |
12702 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12703 | struct ui_out *uiout) | |
12704 | { | |
12705 | /* nothing */ | |
12706 | } | |
12707 | ||
12708 | static void | |
12709 | base_breakpoint_print_mention (struct breakpoint *b) | |
12710 | { | |
12711 | internal_error_pure_virtual_called (); | |
12712 | } | |
12713 | ||
12714 | static void | |
12715 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12716 | { | |
12717 | internal_error_pure_virtual_called (); | |
12718 | } | |
12719 | ||
983af33b | 12720 | static void |
f00aae0f KS |
12721 | base_breakpoint_create_sals_from_location |
12722 | (const struct event_location *location, | |
12723 | struct linespec_result *canonical, | |
12724 | enum bptype type_wanted) | |
983af33b SDJ |
12725 | { |
12726 | internal_error_pure_virtual_called (); | |
12727 | } | |
12728 | ||
12729 | static void | |
12730 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12731 | struct linespec_result *c, | |
e1e01040 PA |
12732 | gdb::unique_xmalloc_ptr<char> cond_string, |
12733 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12734 | enum bptype type_wanted, |
12735 | enum bpdisp disposition, | |
12736 | int thread, | |
12737 | int task, int ignore_count, | |
12738 | const struct breakpoint_ops *o, | |
12739 | int from_tty, int enabled, | |
44f238bb | 12740 | int internal, unsigned flags) |
983af33b SDJ |
12741 | { |
12742 | internal_error_pure_virtual_called (); | |
12743 | } | |
12744 | ||
6c5b2ebe | 12745 | static std::vector<symtab_and_line> |
f00aae0f KS |
12746 | base_breakpoint_decode_location (struct breakpoint *b, |
12747 | const struct event_location *location, | |
6c5b2ebe | 12748 | struct program_space *search_pspace) |
983af33b SDJ |
12749 | { |
12750 | internal_error_pure_virtual_called (); | |
12751 | } | |
12752 | ||
ab04a2af TT |
12753 | /* The default 'explains_signal' method. */ |
12754 | ||
47591c29 | 12755 | static int |
427cd150 | 12756 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12757 | { |
47591c29 | 12758 | return 1; |
ab04a2af TT |
12759 | } |
12760 | ||
9d6e6e84 HZ |
12761 | /* The default "after_condition_true" method. */ |
12762 | ||
12763 | static void | |
12764 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12765 | { | |
12766 | /* Nothing to do. */ | |
12767 | } | |
12768 | ||
ab04a2af | 12769 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12770 | { |
2060206e PA |
12771 | base_breakpoint_allocate_location, |
12772 | base_breakpoint_re_set, | |
12773 | base_breakpoint_insert_location, | |
12774 | base_breakpoint_remove_location, | |
12775 | base_breakpoint_breakpoint_hit, | |
12776 | base_breakpoint_check_status, | |
12777 | base_breakpoint_resources_needed, | |
12778 | base_breakpoint_works_in_software_mode, | |
12779 | base_breakpoint_print_it, | |
12780 | NULL, | |
12781 | base_breakpoint_print_one_detail, | |
12782 | base_breakpoint_print_mention, | |
983af33b | 12783 | base_breakpoint_print_recreate, |
5f700d83 | 12784 | base_breakpoint_create_sals_from_location, |
983af33b | 12785 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12786 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12787 | base_breakpoint_explains_signal, |
12788 | base_breakpoint_after_condition_true, | |
2060206e PA |
12789 | }; |
12790 | ||
12791 | /* Default breakpoint_ops methods. */ | |
12792 | ||
12793 | static void | |
348d480f PA |
12794 | bkpt_re_set (struct breakpoint *b) |
12795 | { | |
06edf0c0 | 12796 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12797 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12798 | { |
f00aae0f | 12799 | /* Anything without a location can't be re-set. */ |
348d480f | 12800 | delete_breakpoint (b); |
06edf0c0 | 12801 | return; |
348d480f | 12802 | } |
06edf0c0 PA |
12803 | |
12804 | breakpoint_re_set_default (b); | |
348d480f PA |
12805 | } |
12806 | ||
2060206e | 12807 | static int |
348d480f PA |
12808 | bkpt_insert_location (struct bp_location *bl) |
12809 | { | |
cd6c3b4f YQ |
12810 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12811 | ||
579c6ad9 | 12812 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12813 | bl->target_info.placed_address = addr; |
12814 | ||
348d480f | 12815 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12816 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12817 | else |
7c16b83e | 12818 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12819 | } |
12820 | ||
2060206e | 12821 | static int |
73971819 | 12822 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12823 | { |
12824 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12825 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12826 | else | |
73971819 | 12827 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12828 | } |
12829 | ||
2060206e | 12830 | static int |
348d480f | 12831 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12832 | struct address_space *aspace, CORE_ADDR bp_addr, |
12833 | const struct target_waitstatus *ws) | |
348d480f | 12834 | { |
09ac7c10 | 12835 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12836 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12837 | return 0; |
12838 | ||
348d480f PA |
12839 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12840 | aspace, bp_addr)) | |
12841 | return 0; | |
12842 | ||
12843 | if (overlay_debugging /* unmapped overlay section */ | |
12844 | && section_is_overlay (bl->section) | |
12845 | && !section_is_mapped (bl->section)) | |
12846 | return 0; | |
12847 | ||
12848 | return 1; | |
12849 | } | |
12850 | ||
cd1608cc PA |
12851 | static int |
12852 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
12853 | struct address_space *aspace, CORE_ADDR bp_addr, | |
12854 | const struct target_waitstatus *ws) | |
12855 | { | |
12856 | if (dprintf_style == dprintf_style_agent | |
12857 | && target_can_run_breakpoint_commands ()) | |
12858 | { | |
12859 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12860 | for this address it must be for a breakpoint that happens to | |
12861 | be set at the same address. */ | |
12862 | return 0; | |
12863 | } | |
12864 | ||
12865 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12866 | } | |
12867 | ||
2060206e | 12868 | static int |
348d480f PA |
12869 | bkpt_resources_needed (const struct bp_location *bl) |
12870 | { | |
12871 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12872 | ||
12873 | return 1; | |
12874 | } | |
12875 | ||
2060206e | 12876 | static enum print_stop_action |
348d480f PA |
12877 | bkpt_print_it (bpstat bs) |
12878 | { | |
348d480f PA |
12879 | struct breakpoint *b; |
12880 | const struct bp_location *bl; | |
001c8c33 | 12881 | int bp_temp; |
79a45e25 | 12882 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12883 | |
12884 | gdb_assert (bs->bp_location_at != NULL); | |
12885 | ||
12886 | bl = bs->bp_location_at; | |
12887 | b = bs->breakpoint_at; | |
12888 | ||
001c8c33 PA |
12889 | bp_temp = b->disposition == disp_del; |
12890 | if (bl->address != bl->requested_address) | |
12891 | breakpoint_adjustment_warning (bl->requested_address, | |
12892 | bl->address, | |
12893 | b->number, 1); | |
12894 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12895 | maybe_print_thread_hit_breakpoint (uiout); |
12896 | ||
001c8c33 | 12897 | if (bp_temp) |
112e8700 | 12898 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 12899 | else |
112e8700 SM |
12900 | uiout->text ("Breakpoint "); |
12901 | if (uiout->is_mi_like_p ()) | |
348d480f | 12902 | { |
112e8700 | 12903 | uiout->field_string ("reason", |
001c8c33 | 12904 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12905 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12906 | } |
112e8700 SM |
12907 | uiout->field_int ("bkptno", b->number); |
12908 | uiout->text (", "); | |
06edf0c0 | 12909 | |
001c8c33 | 12910 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12911 | } |
12912 | ||
2060206e | 12913 | static void |
06edf0c0 PA |
12914 | bkpt_print_mention (struct breakpoint *b) |
12915 | { | |
112e8700 | 12916 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12917 | return; |
12918 | ||
12919 | switch (b->type) | |
12920 | { | |
12921 | case bp_breakpoint: | |
12922 | case bp_gnu_ifunc_resolver: | |
12923 | if (b->disposition == disp_del) | |
12924 | printf_filtered (_("Temporary breakpoint")); | |
12925 | else | |
12926 | printf_filtered (_("Breakpoint")); | |
12927 | printf_filtered (_(" %d"), b->number); | |
12928 | if (b->type == bp_gnu_ifunc_resolver) | |
12929 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12930 | break; | |
12931 | case bp_hardware_breakpoint: | |
12932 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12933 | break; | |
e7e0cddf SS |
12934 | case bp_dprintf: |
12935 | printf_filtered (_("Dprintf %d"), b->number); | |
12936 | break; | |
06edf0c0 PA |
12937 | } |
12938 | ||
12939 | say_where (b); | |
12940 | } | |
12941 | ||
2060206e | 12942 | static void |
06edf0c0 PA |
12943 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12944 | { | |
12945 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12946 | fprintf_unfiltered (fp, "tbreak"); | |
12947 | else if (tp->type == bp_breakpoint) | |
12948 | fprintf_unfiltered (fp, "break"); | |
12949 | else if (tp->type == bp_hardware_breakpoint | |
12950 | && tp->disposition == disp_del) | |
12951 | fprintf_unfiltered (fp, "thbreak"); | |
12952 | else if (tp->type == bp_hardware_breakpoint) | |
12953 | fprintf_unfiltered (fp, "hbreak"); | |
12954 | else | |
12955 | internal_error (__FILE__, __LINE__, | |
12956 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12957 | ||
f00aae0f | 12958 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12959 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12960 | |
12961 | /* Print out extra_string if this breakpoint is pending. It might | |
12962 | contain, for example, conditions that were set by the user. */ | |
12963 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12964 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12965 | ||
dd11a36c | 12966 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12967 | } |
12968 | ||
983af33b | 12969 | static void |
f00aae0f KS |
12970 | bkpt_create_sals_from_location (const struct event_location *location, |
12971 | struct linespec_result *canonical, | |
12972 | enum bptype type_wanted) | |
983af33b | 12973 | { |
f00aae0f | 12974 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12975 | } |
12976 | ||
12977 | static void | |
12978 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12979 | struct linespec_result *canonical, | |
e1e01040 PA |
12980 | gdb::unique_xmalloc_ptr<char> cond_string, |
12981 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12982 | enum bptype type_wanted, |
12983 | enum bpdisp disposition, | |
12984 | int thread, | |
12985 | int task, int ignore_count, | |
12986 | const struct breakpoint_ops *ops, | |
12987 | int from_tty, int enabled, | |
44f238bb | 12988 | int internal, unsigned flags) |
983af33b | 12989 | { |
023fa29b | 12990 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12991 | std::move (cond_string), |
12992 | std::move (extra_string), | |
e7e0cddf | 12993 | type_wanted, |
983af33b SDJ |
12994 | disposition, thread, task, |
12995 | ignore_count, ops, from_tty, | |
44f238bb | 12996 | enabled, internal, flags); |
983af33b SDJ |
12997 | } |
12998 | ||
6c5b2ebe | 12999 | static std::vector<symtab_and_line> |
f00aae0f KS |
13000 | bkpt_decode_location (struct breakpoint *b, |
13001 | const struct event_location *location, | |
6c5b2ebe | 13002 | struct program_space *search_pspace) |
983af33b | 13003 | { |
6c5b2ebe | 13004 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13005 | } |
13006 | ||
06edf0c0 PA |
13007 | /* Virtual table for internal breakpoints. */ |
13008 | ||
13009 | static void | |
13010 | internal_bkpt_re_set (struct breakpoint *b) | |
13011 | { | |
13012 | switch (b->type) | |
13013 | { | |
13014 | /* Delete overlay event and longjmp master breakpoints; they | |
13015 | will be reset later by breakpoint_re_set. */ | |
13016 | case bp_overlay_event: | |
13017 | case bp_longjmp_master: | |
13018 | case bp_std_terminate_master: | |
13019 | case bp_exception_master: | |
13020 | delete_breakpoint (b); | |
13021 | break; | |
13022 | ||
13023 | /* This breakpoint is special, it's set up when the inferior | |
13024 | starts and we really don't want to touch it. */ | |
13025 | case bp_shlib_event: | |
13026 | ||
13027 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13028 | it is set up, we do not want to touch it. */ | |
13029 | case bp_thread_event: | |
13030 | break; | |
13031 | } | |
13032 | } | |
13033 | ||
13034 | static void | |
13035 | internal_bkpt_check_status (bpstat bs) | |
13036 | { | |
a9b3a50f PA |
13037 | if (bs->breakpoint_at->type == bp_shlib_event) |
13038 | { | |
13039 | /* If requested, stop when the dynamic linker notifies GDB of | |
13040 | events. This allows the user to get control and place | |
13041 | breakpoints in initializer routines for dynamically loaded | |
13042 | objects (among other things). */ | |
13043 | bs->stop = stop_on_solib_events; | |
13044 | bs->print = stop_on_solib_events; | |
13045 | } | |
13046 | else | |
13047 | bs->stop = 0; | |
06edf0c0 PA |
13048 | } |
13049 | ||
13050 | static enum print_stop_action | |
13051 | internal_bkpt_print_it (bpstat bs) | |
13052 | { | |
06edf0c0 | 13053 | struct breakpoint *b; |
06edf0c0 | 13054 | |
06edf0c0 PA |
13055 | b = bs->breakpoint_at; |
13056 | ||
06edf0c0 PA |
13057 | switch (b->type) |
13058 | { | |
348d480f PA |
13059 | case bp_shlib_event: |
13060 | /* Did we stop because the user set the stop_on_solib_events | |
13061 | variable? (If so, we report this as a generic, "Stopped due | |
13062 | to shlib event" message.) */ | |
edcc5120 | 13063 | print_solib_event (0); |
348d480f PA |
13064 | break; |
13065 | ||
13066 | case bp_thread_event: | |
13067 | /* Not sure how we will get here. | |
13068 | GDB should not stop for these breakpoints. */ | |
13069 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13070 | break; |
13071 | ||
13072 | case bp_overlay_event: | |
13073 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13074 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13075 | break; |
13076 | ||
13077 | case bp_longjmp_master: | |
13078 | /* These should never be enabled. */ | |
13079 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13080 | break; |
13081 | ||
13082 | case bp_std_terminate_master: | |
13083 | /* These should never be enabled. */ | |
13084 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13085 | "gdb should not stop!\n")); | |
348d480f PA |
13086 | break; |
13087 | ||
13088 | case bp_exception_master: | |
13089 | /* These should never be enabled. */ | |
13090 | printf_filtered (_("Exception Master Breakpoint: " | |
13091 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13092 | break; |
13093 | } | |
13094 | ||
001c8c33 | 13095 | return PRINT_NOTHING; |
06edf0c0 PA |
13096 | } |
13097 | ||
13098 | static void | |
13099 | internal_bkpt_print_mention (struct breakpoint *b) | |
13100 | { | |
13101 | /* Nothing to mention. These breakpoints are internal. */ | |
13102 | } | |
13103 | ||
06edf0c0 PA |
13104 | /* Virtual table for momentary breakpoints */ |
13105 | ||
13106 | static void | |
13107 | momentary_bkpt_re_set (struct breakpoint *b) | |
13108 | { | |
13109 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13110 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13111 | Otherwise these should have been blown away via the cleanup chain |
13112 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13113 | } | |
13114 | ||
13115 | static void | |
13116 | momentary_bkpt_check_status (bpstat bs) | |
13117 | { | |
13118 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13119 | } | |
13120 | ||
13121 | static enum print_stop_action | |
13122 | momentary_bkpt_print_it (bpstat bs) | |
13123 | { | |
001c8c33 | 13124 | return PRINT_UNKNOWN; |
348d480f PA |
13125 | } |
13126 | ||
06edf0c0 PA |
13127 | static void |
13128 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13129 | { |
06edf0c0 | 13130 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13131 | } |
13132 | ||
e2e4d78b JK |
13133 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13134 | ||
13135 | It gets cleared already on the removal of the first one of such placed | |
13136 | breakpoints. This is OK as they get all removed altogether. */ | |
13137 | ||
c1fc2657 | 13138 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 13139 | { |
c1fc2657 | 13140 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 13141 | |
c1fc2657 | 13142 | if (tp != NULL) |
e2e4d78b | 13143 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
13144 | } |
13145 | ||
55aa24fb SDJ |
13146 | /* Specific methods for probe breakpoints. */ |
13147 | ||
13148 | static int | |
13149 | bkpt_probe_insert_location (struct bp_location *bl) | |
13150 | { | |
13151 | int v = bkpt_insert_location (bl); | |
13152 | ||
13153 | if (v == 0) | |
13154 | { | |
13155 | /* The insertion was successful, now let's set the probe's semaphore | |
13156 | if needed. */ | |
0ea5cda8 SDJ |
13157 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13158 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13159 | bl->probe.objfile, | |
13160 | bl->gdbarch); | |
55aa24fb SDJ |
13161 | } |
13162 | ||
13163 | return v; | |
13164 | } | |
13165 | ||
13166 | static int | |
73971819 PA |
13167 | bkpt_probe_remove_location (struct bp_location *bl, |
13168 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13169 | { |
13170 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13171 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13172 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13173 | bl->probe.objfile, | |
13174 | bl->gdbarch); | |
55aa24fb | 13175 | |
73971819 | 13176 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13177 | } |
13178 | ||
13179 | static void | |
f00aae0f | 13180 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13181 | struct linespec_result *canonical, |
f00aae0f | 13182 | enum bptype type_wanted) |
55aa24fb SDJ |
13183 | { |
13184 | struct linespec_sals lsal; | |
13185 | ||
c2f4122d | 13186 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
13187 | lsal.canonical |
13188 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13189 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
13190 | } |
13191 | ||
6c5b2ebe | 13192 | static std::vector<symtab_and_line> |
f00aae0f KS |
13193 | bkpt_probe_decode_location (struct breakpoint *b, |
13194 | const struct event_location *location, | |
6c5b2ebe | 13195 | struct program_space *search_pspace) |
55aa24fb | 13196 | { |
6c5b2ebe PA |
13197 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
13198 | if (sals.empty ()) | |
55aa24fb | 13199 | error (_("probe not found")); |
6c5b2ebe | 13200 | return sals; |
55aa24fb SDJ |
13201 | } |
13202 | ||
348d480f | 13203 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13204 | |
348d480f PA |
13205 | static void |
13206 | tracepoint_re_set (struct breakpoint *b) | |
13207 | { | |
13208 | breakpoint_re_set_default (b); | |
13209 | } | |
876fa593 | 13210 | |
348d480f PA |
13211 | static int |
13212 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13213 | struct address_space *aspace, CORE_ADDR bp_addr, |
13214 | const struct target_waitstatus *ws) | |
348d480f PA |
13215 | { |
13216 | /* By definition, the inferior does not report stops at | |
13217 | tracepoints. */ | |
13218 | return 0; | |
74960c60 VP |
13219 | } |
13220 | ||
13221 | static void | |
348d480f PA |
13222 | tracepoint_print_one_detail (const struct breakpoint *self, |
13223 | struct ui_out *uiout) | |
74960c60 | 13224 | { |
d9b3f62e PA |
13225 | struct tracepoint *tp = (struct tracepoint *) self; |
13226 | if (tp->static_trace_marker_id) | |
348d480f PA |
13227 | { |
13228 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13229 | |
112e8700 SM |
13230 | uiout->text ("\tmarker id is "); |
13231 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 13232 | tp->static_trace_marker_id); |
112e8700 | 13233 | uiout->text ("\n"); |
348d480f | 13234 | } |
0d381245 VP |
13235 | } |
13236 | ||
a474d7c2 | 13237 | static void |
348d480f | 13238 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13239 | { |
112e8700 | 13240 | if (current_uiout->is_mi_like_p ()) |
348d480f | 13241 | return; |
cc59ec59 | 13242 | |
348d480f PA |
13243 | switch (b->type) |
13244 | { | |
13245 | case bp_tracepoint: | |
13246 | printf_filtered (_("Tracepoint")); | |
13247 | printf_filtered (_(" %d"), b->number); | |
13248 | break; | |
13249 | case bp_fast_tracepoint: | |
13250 | printf_filtered (_("Fast tracepoint")); | |
13251 | printf_filtered (_(" %d"), b->number); | |
13252 | break; | |
13253 | case bp_static_tracepoint: | |
13254 | printf_filtered (_("Static tracepoint")); | |
13255 | printf_filtered (_(" %d"), b->number); | |
13256 | break; | |
13257 | default: | |
13258 | internal_error (__FILE__, __LINE__, | |
13259 | _("unhandled tracepoint type %d"), (int) b->type); | |
13260 | } | |
13261 | ||
13262 | say_where (b); | |
a474d7c2 PA |
13263 | } |
13264 | ||
348d480f | 13265 | static void |
d9b3f62e | 13266 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13267 | { |
d9b3f62e PA |
13268 | struct tracepoint *tp = (struct tracepoint *) self; |
13269 | ||
13270 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13271 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13272 | else if (self->type == bp_static_tracepoint) |
348d480f | 13273 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13274 | else if (self->type == bp_tracepoint) |
348d480f PA |
13275 | fprintf_unfiltered (fp, "trace"); |
13276 | else | |
13277 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13278 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13279 | |
f00aae0f | 13280 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13281 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
13282 | print_recreate_thread (self, fp); |
13283 | ||
13284 | if (tp->pass_count) | |
13285 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13286 | } |
13287 | ||
983af33b | 13288 | static void |
f00aae0f KS |
13289 | tracepoint_create_sals_from_location (const struct event_location *location, |
13290 | struct linespec_result *canonical, | |
13291 | enum bptype type_wanted) | |
983af33b | 13292 | { |
f00aae0f | 13293 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13294 | } |
13295 | ||
13296 | static void | |
13297 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13298 | struct linespec_result *canonical, | |
e1e01040 PA |
13299 | gdb::unique_xmalloc_ptr<char> cond_string, |
13300 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13301 | enum bptype type_wanted, |
13302 | enum bpdisp disposition, | |
13303 | int thread, | |
13304 | int task, int ignore_count, | |
13305 | const struct breakpoint_ops *ops, | |
13306 | int from_tty, int enabled, | |
44f238bb | 13307 | int internal, unsigned flags) |
983af33b | 13308 | { |
023fa29b | 13309 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13310 | std::move (cond_string), |
13311 | std::move (extra_string), | |
e7e0cddf | 13312 | type_wanted, |
983af33b SDJ |
13313 | disposition, thread, task, |
13314 | ignore_count, ops, from_tty, | |
44f238bb | 13315 | enabled, internal, flags); |
983af33b SDJ |
13316 | } |
13317 | ||
6c5b2ebe | 13318 | static std::vector<symtab_and_line> |
f00aae0f KS |
13319 | tracepoint_decode_location (struct breakpoint *b, |
13320 | const struct event_location *location, | |
6c5b2ebe | 13321 | struct program_space *search_pspace) |
983af33b | 13322 | { |
6c5b2ebe | 13323 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13324 | } |
13325 | ||
2060206e | 13326 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13327 | |
55aa24fb SDJ |
13328 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13329 | static probe. */ | |
13330 | ||
13331 | static void | |
f00aae0f KS |
13332 | tracepoint_probe_create_sals_from_location |
13333 | (const struct event_location *location, | |
13334 | struct linespec_result *canonical, | |
13335 | enum bptype type_wanted) | |
55aa24fb SDJ |
13336 | { |
13337 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13338 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13339 | } |
13340 | ||
6c5b2ebe | 13341 | static std::vector<symtab_and_line> |
f00aae0f KS |
13342 | tracepoint_probe_decode_location (struct breakpoint *b, |
13343 | const struct event_location *location, | |
6c5b2ebe | 13344 | struct program_space *search_pspace) |
55aa24fb SDJ |
13345 | { |
13346 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 13347 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
13348 | } |
13349 | ||
13350 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13351 | ||
5c2b4418 HZ |
13352 | /* Dprintf breakpoint_ops methods. */ |
13353 | ||
13354 | static void | |
13355 | dprintf_re_set (struct breakpoint *b) | |
13356 | { | |
13357 | breakpoint_re_set_default (b); | |
13358 | ||
f00aae0f KS |
13359 | /* extra_string should never be non-NULL for dprintf. */ |
13360 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13361 | |
13362 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13363 | 2 - create a dprintf, which resolves fine. | |
13364 | 3 - disconnect from target 1 | |
13365 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13366 | ||
13367 | After steps #3/#4, you'll want the dprintf command list to | |
13368 | be updated, because target 1 and 2 may well return different | |
13369 | answers for target_can_run_breakpoint_commands(). | |
13370 | Given absence of finer grained resetting, we get to do | |
13371 | it all the time. */ | |
13372 | if (b->extra_string != NULL) | |
13373 | update_dprintf_command_list (b); | |
13374 | } | |
13375 | ||
2d9442cc HZ |
13376 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13377 | ||
13378 | static void | |
13379 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13380 | { | |
f00aae0f | 13381 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13382 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13383 | tp->extra_string); |
13384 | print_recreate_thread (tp, fp); | |
13385 | } | |
13386 | ||
9d6e6e84 HZ |
13387 | /* Implement the "after_condition_true" breakpoint_ops method for |
13388 | dprintf. | |
13389 | ||
13390 | dprintf's are implemented with regular commands in their command | |
13391 | list, but we run the commands here instead of before presenting the | |
13392 | stop to the user, as dprintf's don't actually cause a stop. This | |
13393 | also makes it so that the commands of multiple dprintfs at the same | |
13394 | address are all handled. */ | |
13395 | ||
13396 | static void | |
13397 | dprintf_after_condition_true (struct bpstats *bs) | |
13398 | { | |
04afa70c | 13399 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
13400 | struct bpstats *tmp_bs_p = &tmp_bs; |
13401 | ||
13402 | /* dprintf's never cause a stop. This wasn't set in the | |
13403 | check_status hook instead because that would make the dprintf's | |
13404 | condition not be evaluated. */ | |
13405 | bs->stop = 0; | |
13406 | ||
13407 | /* Run the command list here. Take ownership of it instead of | |
13408 | copying. We never want these commands to run later in | |
13409 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13410 | be set at same address as this dprintf, or even if running the | |
13411 | commands here throws. */ | |
13412 | tmp_bs.commands = bs->commands; | |
13413 | bs->commands = NULL; | |
9d6e6e84 HZ |
13414 | |
13415 | bpstat_do_actions_1 (&tmp_bs_p); | |
13416 | ||
13417 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13418 | bpstat_do_actions_1 may return early without processing the whole | |
13419 | list. */ | |
9d6e6e84 HZ |
13420 | } |
13421 | ||
983af33b SDJ |
13422 | /* The breakpoint_ops structure to be used on static tracepoints with |
13423 | markers (`-m'). */ | |
13424 | ||
13425 | static void | |
f00aae0f | 13426 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13427 | struct linespec_result *canonical, |
f00aae0f | 13428 | enum bptype type_wanted) |
983af33b SDJ |
13429 | { |
13430 | struct linespec_sals lsal; | |
f00aae0f KS |
13431 | const char *arg_start, *arg; |
13432 | char *str; | |
13433 | struct cleanup *cleanup; | |
983af33b | 13434 | |
f00aae0f KS |
13435 | arg = arg_start = get_linespec_location (location); |
13436 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13437 | |
f00aae0f KS |
13438 | str = savestring (arg_start, arg - arg_start); |
13439 | cleanup = make_cleanup (xfree, str); | |
8e9e35b1 | 13440 | canonical->location = new_linespec_location (&str); |
f00aae0f | 13441 | do_cleanups (cleanup); |
983af33b | 13442 | |
8e9e35b1 TT |
13443 | lsal.canonical |
13444 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13445 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
13446 | } |
13447 | ||
13448 | static void | |
13449 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13450 | struct linespec_result *canonical, | |
e1e01040 PA |
13451 | gdb::unique_xmalloc_ptr<char> cond_string, |
13452 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13453 | enum bptype type_wanted, |
13454 | enum bpdisp disposition, | |
13455 | int thread, | |
13456 | int task, int ignore_count, | |
13457 | const struct breakpoint_ops *ops, | |
13458 | int from_tty, int enabled, | |
44f238bb | 13459 | int internal, unsigned flags) |
983af33b | 13460 | { |
6c5b2ebe | 13461 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
13462 | |
13463 | /* If the user is creating a static tracepoint by marker id | |
13464 | (strace -m MARKER_ID), then store the sals index, so that | |
13465 | breakpoint_re_set can try to match up which of the newly | |
13466 | found markers corresponds to this one, and, don't try to | |
13467 | expand multiple locations for each sal, given than SALS | |
13468 | already should contain all sals for MARKER_ID. */ | |
13469 | ||
6c5b2ebe | 13470 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 13471 | { |
6c5b2ebe PA |
13472 | event_location_up location |
13473 | = copy_event_location (canonical->location.get ()); | |
983af33b | 13474 | |
b270e6f9 | 13475 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 13476 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 13477 | std::move (location), NULL, |
e1e01040 PA |
13478 | std::move (cond_string), |
13479 | std::move (extra_string), | |
e7e0cddf | 13480 | type_wanted, disposition, |
983af33b | 13481 | thread, task, ignore_count, ops, |
44f238bb | 13482 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13483 | canonical->special_display); |
13484 | /* Given that its possible to have multiple markers with | |
13485 | the same string id, if the user is creating a static | |
13486 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13487 | store the sals index, so that breakpoint_re_set can | |
13488 | try to match up which of the newly found markers | |
13489 | corresponds to this one */ | |
13490 | tp->static_trace_marker_id_idx = i; | |
13491 | ||
b270e6f9 | 13492 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13493 | } |
13494 | } | |
13495 | ||
6c5b2ebe | 13496 | static std::vector<symtab_and_line> |
f00aae0f KS |
13497 | strace_marker_decode_location (struct breakpoint *b, |
13498 | const struct event_location *location, | |
6c5b2ebe | 13499 | struct program_space *search_pspace) |
983af33b SDJ |
13500 | { |
13501 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13502 | const char *s = get_linespec_location (location); |
983af33b | 13503 | |
6c5b2ebe PA |
13504 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13505 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13506 | { |
6c5b2ebe PA |
13507 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13508 | sals.resize (1); | |
13509 | return sals; | |
983af33b SDJ |
13510 | } |
13511 | else | |
13512 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13513 | } | |
13514 | ||
13515 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13516 | ||
13517 | static int | |
13518 | strace_marker_p (struct breakpoint *b) | |
13519 | { | |
13520 | return b->ops == &strace_marker_breakpoint_ops; | |
13521 | } | |
13522 | ||
53a5351d | 13523 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13524 | structures. */ |
c906108c SS |
13525 | |
13526 | void | |
fba45db2 | 13527 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13528 | { |
52f0bd74 | 13529 | struct breakpoint *b; |
c906108c | 13530 | |
8a3fe4f8 | 13531 | gdb_assert (bpt != NULL); |
c906108c | 13532 | |
4a64f543 MS |
13533 | /* Has this bp already been deleted? This can happen because |
13534 | multiple lists can hold pointers to bp's. bpstat lists are | |
13535 | especial culprits. | |
13536 | ||
13537 | One example of this happening is a watchpoint's scope bp. When | |
13538 | the scope bp triggers, we notice that the watchpoint is out of | |
13539 | scope, and delete it. We also delete its scope bp. But the | |
13540 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13541 | That bpstat is then checked for auto-deleting bp's, which are | |
13542 | deleted. | |
13543 | ||
13544 | A real solution to this problem might involve reference counts in | |
13545 | bp's, and/or giving them pointers back to their referencing | |
13546 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13547 | storage when no more references were extent. A cheaper bandaid | |
13548 | was chosen. */ | |
c906108c SS |
13549 | if (bpt->type == bp_none) |
13550 | return; | |
13551 | ||
4a64f543 MS |
13552 | /* At least avoid this stale reference until the reference counting |
13553 | of breakpoints gets resolved. */ | |
d0fb5eae | 13554 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13555 | { |
d0fb5eae | 13556 | struct breakpoint *related; |
3a5c3e22 | 13557 | struct watchpoint *w; |
d0fb5eae JK |
13558 | |
13559 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13560 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13561 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13562 | w = (struct watchpoint *) bpt; |
13563 | else | |
13564 | w = NULL; | |
13565 | if (w != NULL) | |
13566 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13567 | |
13568 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13569 | for (related = bpt; related->related_breakpoint != bpt; | |
13570 | related = related->related_breakpoint); | |
13571 | related->related_breakpoint = bpt->related_breakpoint; | |
13572 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13573 | } |
13574 | ||
a9634178 TJB |
13575 | /* watch_command_1 creates a watchpoint but only sets its number if |
13576 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13577 | a problem in that process, we'll be asked to delete the half-created | |
13578 | watchpoint. In that case, don't announce the deletion. */ | |
13579 | if (bpt->number) | |
13580 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13581 | |
c906108c SS |
13582 | if (breakpoint_chain == bpt) |
13583 | breakpoint_chain = bpt->next; | |
13584 | ||
c906108c SS |
13585 | ALL_BREAKPOINTS (b) |
13586 | if (b->next == bpt) | |
c5aa993b JM |
13587 | { |
13588 | b->next = bpt->next; | |
13589 | break; | |
13590 | } | |
c906108c | 13591 | |
f431efe5 PA |
13592 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13593 | been freed. */ | |
13594 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13595 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13596 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13597 | commands are associated with the bpstat; if we remove it here, | |
13598 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13599 | event-top.c won't do anything, and temporary breakpoints with | |
13600 | commands won't work. */ | |
13601 | ||
13602 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13603 | ||
4a64f543 MS |
13604 | /* Now that breakpoint is removed from breakpoint list, update the |
13605 | global location list. This will remove locations that used to | |
13606 | belong to this breakpoint. Do this before freeing the breakpoint | |
13607 | itself, since remove_breakpoint looks at location's owner. It | |
13608 | might be better design to have location completely | |
13609 | self-contained, but it's not the case now. */ | |
44702360 | 13610 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13611 | |
4a64f543 MS |
13612 | /* On the chance that someone will soon try again to delete this |
13613 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13614 | bpt->type = bp_none; |
4d01a485 | 13615 | delete bpt; |
c906108c SS |
13616 | } |
13617 | ||
4d6140d9 AC |
13618 | static void |
13619 | do_delete_breakpoint_cleanup (void *b) | |
13620 | { | |
9a3c8263 | 13621 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13622 | } |
13623 | ||
13624 | struct cleanup * | |
13625 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13626 | { | |
13627 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13628 | } | |
13629 | ||
51be5b68 PA |
13630 | /* Iterator function to call a user-provided callback function once |
13631 | for each of B and its related breakpoints. */ | |
13632 | ||
13633 | static void | |
13634 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13635 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13636 | { |
13637 | struct breakpoint *related; | |
13638 | ||
13639 | related = b; | |
13640 | do | |
13641 | { | |
13642 | struct breakpoint *next; | |
13643 | ||
13644 | /* FUNCTION may delete RELATED. */ | |
13645 | next = related->related_breakpoint; | |
13646 | ||
13647 | if (next == related) | |
13648 | { | |
13649 | /* RELATED is the last ring entry. */ | |
48649e1b | 13650 | function (related); |
51be5b68 PA |
13651 | |
13652 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13653 | B. There's nothing left to do anyway, so just break | |
13654 | out. */ | |
13655 | break; | |
13656 | } | |
13657 | else | |
48649e1b | 13658 | function (related); |
51be5b68 PA |
13659 | |
13660 | related = next; | |
13661 | } | |
13662 | while (related != b); | |
13663 | } | |
95a42b64 | 13664 | |
c906108c | 13665 | void |
fba45db2 | 13666 | delete_command (char *arg, int from_tty) |
c906108c | 13667 | { |
35df4500 | 13668 | struct breakpoint *b, *b_tmp; |
c906108c | 13669 | |
ea9365bb TT |
13670 | dont_repeat (); |
13671 | ||
c906108c SS |
13672 | if (arg == 0) |
13673 | { | |
13674 | int breaks_to_delete = 0; | |
13675 | ||
46c6471b PA |
13676 | /* Delete all breakpoints if no argument. Do not delete |
13677 | internal breakpoints, these have to be deleted with an | |
13678 | explicit breakpoint number argument. */ | |
c5aa993b | 13679 | ALL_BREAKPOINTS (b) |
46c6471b | 13680 | if (user_breakpoint_p (b)) |
973d738b DJ |
13681 | { |
13682 | breaks_to_delete = 1; | |
13683 | break; | |
13684 | } | |
c906108c SS |
13685 | |
13686 | /* Ask user only if there are some breakpoints to delete. */ | |
13687 | if (!from_tty | |
e2e0b3e5 | 13688 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13689 | { |
35df4500 | 13690 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13691 | if (user_breakpoint_p (b)) |
c5aa993b | 13692 | delete_breakpoint (b); |
c906108c SS |
13693 | } |
13694 | } | |
13695 | else | |
48649e1b TT |
13696 | map_breakpoint_numbers |
13697 | (arg, [&] (breakpoint *b) | |
13698 | { | |
13699 | iterate_over_related_breakpoints (b, delete_breakpoint); | |
13700 | }); | |
c906108c SS |
13701 | } |
13702 | ||
c2f4122d PA |
13703 | /* Return true if all locations of B bound to PSPACE are pending. If |
13704 | PSPACE is NULL, all locations of all program spaces are | |
13705 | considered. */ | |
13706 | ||
0d381245 | 13707 | static int |
c2f4122d | 13708 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13709 | { |
c2f4122d PA |
13710 | struct bp_location *loc; |
13711 | ||
13712 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13713 | if ((pspace == NULL | |
13714 | || loc->pspace == pspace) | |
13715 | && !loc->shlib_disabled | |
8645ff69 | 13716 | && !loc->pspace->executing_startup) |
0d381245 VP |
13717 | return 0; |
13718 | return 1; | |
fe3f5fa8 VP |
13719 | } |
13720 | ||
776592bf DE |
13721 | /* Subroutine of update_breakpoint_locations to simplify it. |
13722 | Return non-zero if multiple fns in list LOC have the same name. | |
13723 | Null names are ignored. */ | |
13724 | ||
13725 | static int | |
13726 | ambiguous_names_p (struct bp_location *loc) | |
13727 | { | |
13728 | struct bp_location *l; | |
13729 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13730 | (int (*) (const void *, |
13731 | const void *)) streq, | |
776592bf DE |
13732 | NULL, xcalloc, xfree); |
13733 | ||
13734 | for (l = loc; l != NULL; l = l->next) | |
13735 | { | |
13736 | const char **slot; | |
13737 | const char *name = l->function_name; | |
13738 | ||
13739 | /* Allow for some names to be NULL, ignore them. */ | |
13740 | if (name == NULL) | |
13741 | continue; | |
13742 | ||
13743 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13744 | INSERT); | |
4a64f543 MS |
13745 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13746 | returns NULL. */ | |
776592bf DE |
13747 | if (*slot != NULL) |
13748 | { | |
13749 | htab_delete (htab); | |
13750 | return 1; | |
13751 | } | |
13752 | *slot = name; | |
13753 | } | |
13754 | ||
13755 | htab_delete (htab); | |
13756 | return 0; | |
13757 | } | |
13758 | ||
0fb4aa4b PA |
13759 | /* When symbols change, it probably means the sources changed as well, |
13760 | and it might mean the static tracepoint markers are no longer at | |
13761 | the same address or line numbers they used to be at last we | |
13762 | checked. Losing your static tracepoints whenever you rebuild is | |
13763 | undesirable. This function tries to resync/rematch gdb static | |
13764 | tracepoints with the markers on the target, for static tracepoints | |
13765 | that have not been set by marker id. Static tracepoint that have | |
13766 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13767 | The heuristic is: | |
13768 | ||
13769 | 1) For a tracepoint set at a specific address, look for a marker at | |
13770 | the old PC. If one is found there, assume to be the same marker. | |
13771 | If the name / string id of the marker found is different from the | |
13772 | previous known name, assume that means the user renamed the marker | |
13773 | in the sources, and output a warning. | |
13774 | ||
13775 | 2) For a tracepoint set at a given line number, look for a marker | |
13776 | at the new address of the old line number. If one is found there, | |
13777 | assume to be the same marker. If the name / string id of the | |
13778 | marker found is different from the previous known name, assume that | |
13779 | means the user renamed the marker in the sources, and output a | |
13780 | warning. | |
13781 | ||
13782 | 3) If a marker is no longer found at the same address or line, it | |
13783 | may mean the marker no longer exists. But it may also just mean | |
13784 | the code changed a bit. Maybe the user added a few lines of code | |
13785 | that made the marker move up or down (in line number terms). Ask | |
13786 | the target for info about the marker with the string id as we knew | |
13787 | it. If found, update line number and address in the matching | |
13788 | static tracepoint. This will get confused if there's more than one | |
13789 | marker with the same ID (possible in UST, although unadvised | |
13790 | precisely because it confuses tools). */ | |
13791 | ||
13792 | static struct symtab_and_line | |
13793 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13794 | { | |
d9b3f62e | 13795 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13796 | struct static_tracepoint_marker marker; |
13797 | CORE_ADDR pc; | |
0fb4aa4b PA |
13798 | |
13799 | pc = sal.pc; | |
13800 | if (sal.line) | |
13801 | find_line_pc (sal.symtab, sal.line, &pc); | |
13802 | ||
13803 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13804 | { | |
d9b3f62e | 13805 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13806 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13807 | b->number, | |
d9b3f62e | 13808 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13809 | |
d9b3f62e PA |
13810 | xfree (tp->static_trace_marker_id); |
13811 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13812 | release_static_tracepoint_marker (&marker); |
13813 | ||
13814 | return sal; | |
13815 | } | |
13816 | ||
13817 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13818 | by string ID. */ | |
13819 | if (!sal.explicit_pc | |
13820 | && sal.line != 0 | |
13821 | && sal.symtab != NULL | |
d9b3f62e | 13822 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13823 | { |
13824 | VEC(static_tracepoint_marker_p) *markers; | |
13825 | ||
13826 | markers | |
d9b3f62e | 13827 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13828 | |
13829 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13830 | { | |
0fb4aa4b | 13831 | struct symbol *sym; |
80e1d417 | 13832 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13833 | struct ui_out *uiout = current_uiout; |
67994074 | 13834 | struct explicit_location explicit_loc; |
0fb4aa4b | 13835 | |
80e1d417 | 13836 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13837 | |
d9b3f62e | 13838 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13839 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13840 | |
13841 | warning (_("marker for static tracepoint %d (%s) not " | |
13842 | "found at previous line number"), | |
d9b3f62e | 13843 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13844 | |
51abb421 | 13845 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13846 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13847 | uiout->text ("Now in "); |
0fb4aa4b PA |
13848 | if (sym) |
13849 | { | |
112e8700 SM |
13850 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); |
13851 | uiout->text (" at "); | |
0fb4aa4b | 13852 | } |
112e8700 | 13853 | uiout->field_string ("file", |
05cba821 | 13854 | symtab_to_filename_for_display (sal2.symtab)); |
112e8700 | 13855 | uiout->text (":"); |
0fb4aa4b | 13856 | |
112e8700 | 13857 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13858 | { |
0b0865da | 13859 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13860 | |
112e8700 | 13861 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13862 | } |
13863 | ||
112e8700 SM |
13864 | uiout->field_int ("line", sal2.line); |
13865 | uiout->text ("\n"); | |
0fb4aa4b | 13866 | |
80e1d417 | 13867 | b->loc->line_number = sal2.line; |
2f202fde | 13868 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13869 | |
d28cd78a | 13870 | b->location.reset (NULL); |
67994074 KS |
13871 | initialize_explicit_location (&explicit_loc); |
13872 | explicit_loc.source_filename | |
00e52e53 | 13873 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13874 | explicit_loc.line_offset.offset = b->loc->line_number; |
13875 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13876 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13877 | |
13878 | /* Might be nice to check if function changed, and warn if | |
13879 | so. */ | |
13880 | ||
80e1d417 | 13881 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13882 | } |
13883 | } | |
13884 | return sal; | |
13885 | } | |
13886 | ||
8d3788bd VP |
13887 | /* Returns 1 iff locations A and B are sufficiently same that |
13888 | we don't need to report breakpoint as changed. */ | |
13889 | ||
13890 | static int | |
13891 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13892 | { | |
13893 | while (a && b) | |
13894 | { | |
13895 | if (a->address != b->address) | |
13896 | return 0; | |
13897 | ||
13898 | if (a->shlib_disabled != b->shlib_disabled) | |
13899 | return 0; | |
13900 | ||
13901 | if (a->enabled != b->enabled) | |
13902 | return 0; | |
13903 | ||
13904 | a = a->next; | |
13905 | b = b->next; | |
13906 | } | |
13907 | ||
13908 | if ((a == NULL) != (b == NULL)) | |
13909 | return 0; | |
13910 | ||
13911 | return 1; | |
13912 | } | |
13913 | ||
c2f4122d PA |
13914 | /* Split all locations of B that are bound to PSPACE out of B's |
13915 | location list to a separate list and return that list's head. If | |
13916 | PSPACE is NULL, hoist out all locations of B. */ | |
13917 | ||
13918 | static struct bp_location * | |
13919 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13920 | { | |
13921 | struct bp_location head; | |
13922 | struct bp_location *i = b->loc; | |
13923 | struct bp_location **i_link = &b->loc; | |
13924 | struct bp_location *hoisted = &head; | |
13925 | ||
13926 | if (pspace == NULL) | |
13927 | { | |
13928 | i = b->loc; | |
13929 | b->loc = NULL; | |
13930 | return i; | |
13931 | } | |
13932 | ||
13933 | head.next = NULL; | |
13934 | ||
13935 | while (i != NULL) | |
13936 | { | |
13937 | if (i->pspace == pspace) | |
13938 | { | |
13939 | *i_link = i->next; | |
13940 | i->next = NULL; | |
13941 | hoisted->next = i; | |
13942 | hoisted = i; | |
13943 | } | |
13944 | else | |
13945 | i_link = &i->next; | |
13946 | i = *i_link; | |
13947 | } | |
13948 | ||
13949 | return head.next; | |
13950 | } | |
13951 | ||
13952 | /* Create new breakpoint locations for B (a hardware or software | |
13953 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13954 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13955 | FILTER_PSPACE. Locations of other program spaces are left | |
13956 | untouched. */ | |
f1310107 | 13957 | |
0e30163f | 13958 | void |
0d381245 | 13959 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13960 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13961 | gdb::array_view<const symtab_and_line> sals, |
13962 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 VP |
13963 | { |
13964 | int i; | |
c2f4122d | 13965 | struct bp_location *existing_locations; |
0d381245 | 13966 | |
6c5b2ebe | 13967 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13968 | { |
13969 | /* Ranged breakpoints have only one start location and one end | |
13970 | location. */ | |
13971 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13972 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13973 | "multiple locations found\n"), | |
13974 | b->number); | |
13975 | return; | |
13976 | } | |
f1310107 | 13977 | |
4a64f543 MS |
13978 | /* If there's no new locations, and all existing locations are |
13979 | pending, don't do anything. This optimizes the common case where | |
13980 | all locations are in the same shared library, that was unloaded. | |
13981 | We'd like to retain the location, so that when the library is | |
13982 | loaded again, we don't loose the enabled/disabled status of the | |
13983 | individual locations. */ | |
6c5b2ebe | 13984 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13985 | return; |
13986 | ||
c2f4122d | 13987 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13988 | |
6c5b2ebe | 13989 | for (const auto &sal : sals) |
fe3f5fa8 | 13990 | { |
f8eba3c6 TT |
13991 | struct bp_location *new_loc; |
13992 | ||
6c5b2ebe | 13993 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13994 | |
6c5b2ebe | 13995 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13996 | |
0d381245 VP |
13997 | /* Reparse conditions, they might contain references to the |
13998 | old symtab. */ | |
13999 | if (b->cond_string != NULL) | |
14000 | { | |
bbc13ae3 | 14001 | const char *s; |
fe3f5fa8 | 14002 | |
0d381245 | 14003 | s = b->cond_string; |
492d29ea | 14004 | TRY |
0d381245 | 14005 | { |
6c5b2ebe PA |
14006 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
14007 | block_for_pc (sal.pc), | |
0d381245 VP |
14008 | 0); |
14009 | } | |
492d29ea | 14010 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14011 | { |
3e43a32a MS |
14012 | warning (_("failed to reevaluate condition " |
14013 | "for breakpoint %d: %s"), | |
0d381245 VP |
14014 | b->number, e.message); |
14015 | new_loc->enabled = 0; | |
14016 | } | |
492d29ea | 14017 | END_CATCH |
0d381245 | 14018 | } |
fe3f5fa8 | 14019 | |
6c5b2ebe | 14020 | if (!sals_end.empty ()) |
f1310107 | 14021 | { |
6c5b2ebe | 14022 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 14023 | |
6c5b2ebe | 14024 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 14025 | } |
0d381245 | 14026 | } |
fe3f5fa8 | 14027 | |
4a64f543 MS |
14028 | /* If possible, carry over 'disable' status from existing |
14029 | breakpoints. */ | |
0d381245 VP |
14030 | { |
14031 | struct bp_location *e = existing_locations; | |
776592bf DE |
14032 | /* If there are multiple breakpoints with the same function name, |
14033 | e.g. for inline functions, comparing function names won't work. | |
14034 | Instead compare pc addresses; this is just a heuristic as things | |
14035 | may have moved, but in practice it gives the correct answer | |
14036 | often enough until a better solution is found. */ | |
14037 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14038 | ||
0d381245 VP |
14039 | for (; e; e = e->next) |
14040 | { | |
14041 | if (!e->enabled && e->function_name) | |
14042 | { | |
14043 | struct bp_location *l = b->loc; | |
776592bf DE |
14044 | if (have_ambiguous_names) |
14045 | { | |
14046 | for (; l; l = l->next) | |
f1310107 | 14047 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14048 | { |
14049 | l->enabled = 0; | |
14050 | break; | |
14051 | } | |
14052 | } | |
14053 | else | |
14054 | { | |
14055 | for (; l; l = l->next) | |
14056 | if (l->function_name | |
14057 | && strcmp (e->function_name, l->function_name) == 0) | |
14058 | { | |
14059 | l->enabled = 0; | |
14060 | break; | |
14061 | } | |
14062 | } | |
0d381245 VP |
14063 | } |
14064 | } | |
14065 | } | |
fe3f5fa8 | 14066 | |
8d3788bd VP |
14067 | if (!locations_are_equal (existing_locations, b->loc)) |
14068 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14069 | } |
14070 | ||
f00aae0f | 14071 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14072 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14073 | ||
6c5b2ebe | 14074 | static std::vector<symtab_and_line> |
f00aae0f | 14075 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14076 | struct program_space *search_pspace, int *found) |
ef23e705 | 14077 | { |
492d29ea | 14078 | struct gdb_exception exception = exception_none; |
ef23e705 | 14079 | |
983af33b | 14080 | gdb_assert (b->ops != NULL); |
ef23e705 | 14081 | |
6c5b2ebe PA |
14082 | std::vector<symtab_and_line> sals; |
14083 | ||
492d29ea | 14084 | TRY |
ef23e705 | 14085 | { |
6c5b2ebe | 14086 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 14087 | } |
492d29ea | 14088 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14089 | { |
14090 | int not_found_and_ok = 0; | |
492d29ea PA |
14091 | |
14092 | exception = e; | |
14093 | ||
ef23e705 TJB |
14094 | /* For pending breakpoints, it's expected that parsing will |
14095 | fail until the right shared library is loaded. User has | |
14096 | already told to create pending breakpoints and don't need | |
14097 | extra messages. If breakpoint is in bp_shlib_disabled | |
14098 | state, then user already saw the message about that | |
14099 | breakpoint being disabled, and don't want to see more | |
14100 | errors. */ | |
58438ac1 | 14101 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14102 | && (b->condition_not_parsed |
14103 | || (b->loc != NULL | |
14104 | && search_pspace != NULL | |
14105 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14106 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14107 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14108 | || b->enable_state == bp_disabled)) |
14109 | not_found_and_ok = 1; | |
14110 | ||
14111 | if (!not_found_and_ok) | |
14112 | { | |
14113 | /* We surely don't want to warn about the same breakpoint | |
14114 | 10 times. One solution, implemented here, is disable | |
14115 | the breakpoint on error. Another solution would be to | |
14116 | have separate 'warning emitted' flag. Since this | |
14117 | happens only when a binary has changed, I don't know | |
14118 | which approach is better. */ | |
14119 | b->enable_state = bp_disabled; | |
14120 | throw_exception (e); | |
14121 | } | |
14122 | } | |
492d29ea | 14123 | END_CATCH |
ef23e705 | 14124 | |
492d29ea | 14125 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14126 | { |
6c5b2ebe PA |
14127 | for (auto &sal : sals) |
14128 | resolve_sal_pc (&sal); | |
f00aae0f | 14129 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14130 | { |
ed1d1739 KS |
14131 | char *cond_string, *extra_string; |
14132 | int thread, task; | |
ef23e705 | 14133 | |
6c5b2ebe | 14134 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
14135 | &cond_string, &thread, &task, |
14136 | &extra_string); | |
f00aae0f | 14137 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14138 | if (cond_string) |
14139 | b->cond_string = cond_string; | |
14140 | b->thread = thread; | |
14141 | b->task = task; | |
e7e0cddf | 14142 | if (extra_string) |
f00aae0f KS |
14143 | { |
14144 | xfree (b->extra_string); | |
14145 | b->extra_string = extra_string; | |
14146 | } | |
ef23e705 TJB |
14147 | b->condition_not_parsed = 0; |
14148 | } | |
14149 | ||
983af33b | 14150 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 14151 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 14152 | |
58438ac1 TT |
14153 | *found = 1; |
14154 | } | |
14155 | else | |
14156 | *found = 0; | |
ef23e705 TJB |
14157 | |
14158 | return sals; | |
14159 | } | |
14160 | ||
348d480f PA |
14161 | /* The default re_set method, for typical hardware or software |
14162 | breakpoints. Reevaluate the breakpoint and recreate its | |
14163 | locations. */ | |
14164 | ||
14165 | static void | |
28010a5d | 14166 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 14167 | { |
c2f4122d | 14168 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 14169 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 14170 | |
6c5b2ebe PA |
14171 | int found; |
14172 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
14173 | filter_pspace, &found); | |
ef23e705 | 14174 | if (found) |
6c5b2ebe | 14175 | expanded = std::move (sals); |
ef23e705 | 14176 | |
f00aae0f | 14177 | if (b->location_range_end != NULL) |
f1310107 | 14178 | { |
6c5b2ebe PA |
14179 | std::vector<symtab_and_line> sals_end |
14180 | = location_to_sals (b, b->location_range_end.get (), | |
14181 | filter_pspace, &found); | |
f1310107 | 14182 | if (found) |
6c5b2ebe | 14183 | expanded_end = std::move (sals_end); |
f1310107 TJB |
14184 | } |
14185 | ||
c2f4122d | 14186 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14187 | } |
14188 | ||
983af33b SDJ |
14189 | /* Default method for creating SALs from an address string. It basically |
14190 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14191 | ||
14192 | static void | |
f00aae0f KS |
14193 | create_sals_from_location_default (const struct event_location *location, |
14194 | struct linespec_result *canonical, | |
14195 | enum bptype type_wanted) | |
983af33b | 14196 | { |
f00aae0f | 14197 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14198 | } |
14199 | ||
14200 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14201 | function for the `create_breakpoints_sal' method of | |
14202 | breakpoint_ops. */ | |
14203 | ||
14204 | static void | |
14205 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14206 | struct linespec_result *canonical, | |
e1e01040 PA |
14207 | gdb::unique_xmalloc_ptr<char> cond_string, |
14208 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
14209 | enum bptype type_wanted, |
14210 | enum bpdisp disposition, | |
14211 | int thread, | |
14212 | int task, int ignore_count, | |
14213 | const struct breakpoint_ops *ops, | |
14214 | int from_tty, int enabled, | |
44f238bb | 14215 | int internal, unsigned flags) |
983af33b | 14216 | { |
e1e01040 PA |
14217 | create_breakpoints_sal (gdbarch, canonical, |
14218 | std::move (cond_string), | |
14219 | std::move (extra_string), | |
983af33b SDJ |
14220 | type_wanted, disposition, |
14221 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14222 | enabled, internal, flags); |
983af33b SDJ |
14223 | } |
14224 | ||
14225 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14226 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 14227 | |
6c5b2ebe | 14228 | static std::vector<symtab_and_line> |
f00aae0f KS |
14229 | decode_location_default (struct breakpoint *b, |
14230 | const struct event_location *location, | |
6c5b2ebe | 14231 | struct program_space *search_pspace) |
983af33b SDJ |
14232 | { |
14233 | struct linespec_result canonical; | |
14234 | ||
c2f4122d | 14235 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14236 | (struct symtab *) NULL, 0, |
14237 | &canonical, multiple_symbols_all, | |
14238 | b->filter); | |
14239 | ||
14240 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 14241 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 14242 | |
6c5b2ebe | 14243 | if (!canonical.lsals.empty ()) |
983af33b | 14244 | { |
6c5b2ebe PA |
14245 | const linespec_sals &lsal = canonical.lsals[0]; |
14246 | return std::move (lsal.sals); | |
983af33b | 14247 | } |
6c5b2ebe | 14248 | return {}; |
983af33b SDJ |
14249 | } |
14250 | ||
28010a5d PA |
14251 | /* Prepare the global context for a re-set of breakpoint B. */ |
14252 | ||
14253 | static struct cleanup * | |
14254 | prepare_re_set_context (struct breakpoint *b) | |
14255 | { | |
28010a5d | 14256 | input_radix = b->input_radix; |
28010a5d PA |
14257 | set_language (b->language); |
14258 | ||
c2f4122d | 14259 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14260 | } |
14261 | ||
c906108c SS |
14262 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14263 | The value we return ends up being the return value from catch_errors. | |
14264 | Unused in this case. */ | |
14265 | ||
14266 | static int | |
4efb68b1 | 14267 | breakpoint_re_set_one (void *bint) |
c906108c | 14268 | { |
4a64f543 | 14269 | /* Get past catch_errs. */ |
53a5351d | 14270 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14271 | struct cleanup *cleanups; |
c906108c | 14272 | |
348d480f PA |
14273 | cleanups = prepare_re_set_context (b); |
14274 | b->ops->re_set (b); | |
14275 | do_cleanups (cleanups); | |
c906108c SS |
14276 | return 0; |
14277 | } | |
14278 | ||
c2f4122d PA |
14279 | /* Re-set breakpoint locations for the current program space. |
14280 | Locations bound to other program spaces are left untouched. */ | |
14281 | ||
c906108c | 14282 | void |
69de3c6a | 14283 | breakpoint_re_set (void) |
c906108c | 14284 | { |
35df4500 | 14285 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14286 | enum language save_language; |
14287 | int save_input_radix; | |
c5aa993b | 14288 | |
c906108c SS |
14289 | save_language = current_language->la_language; |
14290 | save_input_radix = input_radix; | |
2a7f3dff | 14291 | |
c5aa993b | 14292 | { |
5ed8105e | 14293 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 14294 | |
5ed8105e PA |
14295 | /* Note: we must not try to insert locations until after all |
14296 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14297 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14298 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 14299 | |
5ed8105e PA |
14300 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
14301 | { | |
14302 | /* Format possible error msg. */ | |
14303 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", | |
14304 | b->number); | |
14305 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
14306 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); | |
14307 | do_cleanups (cleanups); | |
14308 | } | |
14309 | set_language (save_language); | |
14310 | input_radix = save_input_radix; | |
14311 | ||
14312 | jit_breakpoint_re_set (); | |
14313 | } | |
6c95b8df | 14314 | |
af02033e PP |
14315 | create_overlay_event_breakpoint (); |
14316 | create_longjmp_master_breakpoint (); | |
14317 | create_std_terminate_master_breakpoint (); | |
186c406b | 14318 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14319 | |
14320 | /* Now we can insert. */ | |
14321 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14322 | } |
14323 | \f | |
c906108c SS |
14324 | /* Reset the thread number of this breakpoint: |
14325 | ||
14326 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14327 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14328 | void |
fba45db2 | 14329 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14330 | { |
14331 | if (b->thread != -1) | |
14332 | { | |
39f77062 | 14333 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14334 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14335 | |
14336 | /* We're being called after following a fork. The new fork is | |
14337 | selected as current, and unless this was a vfork will have a | |
14338 | different program space from the original thread. Reset that | |
14339 | as well. */ | |
14340 | b->loc->pspace = current_program_space; | |
c906108c SS |
14341 | } |
14342 | } | |
14343 | ||
03ac34d5 MS |
14344 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14345 | If from_tty is nonzero, it prints a message to that effect, | |
14346 | which ends with a period (no newline). */ | |
14347 | ||
c906108c | 14348 | void |
fba45db2 | 14349 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14350 | { |
52f0bd74 | 14351 | struct breakpoint *b; |
c906108c SS |
14352 | |
14353 | if (count < 0) | |
14354 | count = 0; | |
14355 | ||
14356 | ALL_BREAKPOINTS (b) | |
14357 | if (b->number == bptnum) | |
c5aa993b | 14358 | { |
d77f58be SS |
14359 | if (is_tracepoint (b)) |
14360 | { | |
14361 | if (from_tty && count != 0) | |
14362 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14363 | bptnum); | |
14364 | return; | |
14365 | } | |
14366 | ||
c5aa993b | 14367 | b->ignore_count = count; |
221ea385 KS |
14368 | if (from_tty) |
14369 | { | |
14370 | if (count == 0) | |
3e43a32a MS |
14371 | printf_filtered (_("Will stop next time " |
14372 | "breakpoint %d is reached."), | |
221ea385 KS |
14373 | bptnum); |
14374 | else if (count == 1) | |
a3f17187 | 14375 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14376 | bptnum); |
14377 | else | |
3e43a32a MS |
14378 | printf_filtered (_("Will ignore next %d " |
14379 | "crossings of breakpoint %d."), | |
221ea385 KS |
14380 | count, bptnum); |
14381 | } | |
8d3788bd | 14382 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14383 | return; |
14384 | } | |
c906108c | 14385 | |
8a3fe4f8 | 14386 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14387 | } |
14388 | ||
c906108c SS |
14389 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14390 | ||
14391 | static void | |
fba45db2 | 14392 | ignore_command (char *args, int from_tty) |
c906108c SS |
14393 | { |
14394 | char *p = args; | |
52f0bd74 | 14395 | int num; |
c906108c SS |
14396 | |
14397 | if (p == 0) | |
e2e0b3e5 | 14398 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14399 | |
c906108c | 14400 | num = get_number (&p); |
5c44784c | 14401 | if (num == 0) |
8a3fe4f8 | 14402 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14403 | if (*p == 0) |
8a3fe4f8 | 14404 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14405 | |
14406 | set_ignore_count (num, | |
14407 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14408 | from_tty); | |
221ea385 KS |
14409 | if (from_tty) |
14410 | printf_filtered ("\n"); | |
c906108c SS |
14411 | } |
14412 | \f | |
14413 | /* Call FUNCTION on each of the breakpoints | |
14414 | whose numbers are given in ARGS. */ | |
14415 | ||
14416 | static void | |
896b6bda | 14417 | map_breakpoint_numbers (const char *args, |
48649e1b | 14418 | gdb::function_view<void (breakpoint *)> function) |
c906108c | 14419 | { |
52f0bd74 AC |
14420 | int num; |
14421 | struct breakpoint *b, *tmp; | |
c906108c | 14422 | |
b9d61307 | 14423 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14424 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14425 | |
bfd28288 | 14426 | number_or_range_parser parser (args); |
197f0a60 | 14427 | |
bfd28288 | 14428 | while (!parser.finished ()) |
c906108c | 14429 | { |
bfd28288 PA |
14430 | const char *p = parser.cur_tok (); |
14431 | bool match = false; | |
197f0a60 | 14432 | |
bfd28288 | 14433 | num = parser.get_number (); |
5c44784c | 14434 | if (num == 0) |
c5aa993b | 14435 | { |
8a3fe4f8 | 14436 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14437 | } |
14438 | else | |
14439 | { | |
14440 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14441 | if (b->number == num) | |
14442 | { | |
bfd28288 | 14443 | match = true; |
48649e1b | 14444 | function (b); |
11cf8741 | 14445 | break; |
5c44784c | 14446 | } |
bfd28288 | 14447 | if (!match) |
a3f17187 | 14448 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14449 | } |
c906108c SS |
14450 | } |
14451 | } | |
14452 | ||
0d381245 | 14453 | static struct bp_location * |
cb791d59 | 14454 | find_location_by_number (const char *number) |
0d381245 | 14455 | { |
cb791d59 | 14456 | const char *p1; |
0d381245 VP |
14457 | int bp_num; |
14458 | int loc_num; | |
14459 | struct breakpoint *b; | |
14460 | struct bp_location *loc; | |
14461 | ||
0d381245 | 14462 | p1 = number; |
cb791d59 TT |
14463 | bp_num = get_number_trailer (&p1, '.'); |
14464 | if (bp_num == 0 || p1[0] != '.') | |
0d381245 VP |
14465 | error (_("Bad breakpoint number '%s'"), number); |
14466 | ||
14467 | ALL_BREAKPOINTS (b) | |
14468 | if (b->number == bp_num) | |
14469 | { | |
14470 | break; | |
14471 | } | |
14472 | ||
14473 | if (!b || b->number != bp_num) | |
14474 | error (_("Bad breakpoint number '%s'"), number); | |
14475 | ||
cb791d59 TT |
14476 | /* Skip the dot. */ |
14477 | ++p1; | |
14478 | const char *save = p1; | |
197f0a60 | 14479 | loc_num = get_number (&p1); |
0d381245 VP |
14480 | if (loc_num == 0) |
14481 | error (_("Bad breakpoint location number '%s'"), number); | |
14482 | ||
14483 | --loc_num; | |
14484 | loc = b->loc; | |
14485 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14486 | ; | |
14487 | if (!loc) | |
cb791d59 | 14488 | error (_("Bad breakpoint location number '%s'"), save); |
0d381245 VP |
14489 | |
14490 | return loc; | |
14491 | } | |
14492 | ||
14493 | ||
1900040c MS |
14494 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14495 | If from_tty is nonzero, it prints a message to that effect, | |
14496 | which ends with a period (no newline). */ | |
14497 | ||
c906108c | 14498 | void |
fba45db2 | 14499 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14500 | { |
14501 | /* Never disable a watchpoint scope breakpoint; we want to | |
14502 | hit them when we leave scope so we can delete both the | |
14503 | watchpoint and its scope breakpoint at that time. */ | |
14504 | if (bpt->type == bp_watchpoint_scope) | |
14505 | return; | |
14506 | ||
b5de0fa7 | 14507 | bpt->enable_state = bp_disabled; |
c906108c | 14508 | |
b775012e LM |
14509 | /* Mark breakpoint locations modified. */ |
14510 | mark_breakpoint_modified (bpt); | |
14511 | ||
d248b706 KY |
14512 | if (target_supports_enable_disable_tracepoint () |
14513 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14514 | { | |
14515 | struct bp_location *location; | |
14516 | ||
14517 | for (location = bpt->loc; location; location = location->next) | |
14518 | target_disable_tracepoint (location); | |
14519 | } | |
14520 | ||
44702360 | 14521 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14522 | |
8d3788bd | 14523 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14524 | } |
14525 | ||
c906108c | 14526 | static void |
fba45db2 | 14527 | disable_command (char *args, int from_tty) |
c906108c | 14528 | { |
c906108c | 14529 | if (args == 0) |
46c6471b PA |
14530 | { |
14531 | struct breakpoint *bpt; | |
14532 | ||
14533 | ALL_BREAKPOINTS (bpt) | |
14534 | if (user_breakpoint_p (bpt)) | |
14535 | disable_breakpoint (bpt); | |
14536 | } | |
9eaabc75 | 14537 | else |
0d381245 | 14538 | { |
cb791d59 | 14539 | std::string num = extract_arg (&args); |
9eaabc75 | 14540 | |
cb791d59 | 14541 | while (!num.empty ()) |
d248b706 | 14542 | { |
cb791d59 | 14543 | if (num.find ('.') != std::string::npos) |
b775012e | 14544 | { |
cb791d59 | 14545 | struct bp_location *loc = find_location_by_number (num.c_str ()); |
9eaabc75 MW |
14546 | |
14547 | if (loc) | |
14548 | { | |
14549 | if (loc->enabled) | |
14550 | { | |
14551 | loc->enabled = 0; | |
14552 | mark_breakpoint_location_modified (loc); | |
14553 | } | |
14554 | if (target_supports_enable_disable_tracepoint () | |
14555 | && current_trace_status ()->running && loc->owner | |
14556 | && is_tracepoint (loc->owner)) | |
14557 | target_disable_tracepoint (loc); | |
14558 | } | |
44702360 | 14559 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14560 | } |
9eaabc75 | 14561 | else |
48649e1b TT |
14562 | map_breakpoint_numbers |
14563 | (num.c_str (), [&] (breakpoint *b) | |
14564 | { | |
14565 | iterate_over_related_breakpoints (b, disable_breakpoint); | |
14566 | }); | |
9eaabc75 | 14567 | num = extract_arg (&args); |
d248b706 | 14568 | } |
0d381245 | 14569 | } |
c906108c SS |
14570 | } |
14571 | ||
14572 | static void | |
816338b5 SS |
14573 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14574 | int count) | |
c906108c | 14575 | { |
afe38095 | 14576 | int target_resources_ok; |
c906108c SS |
14577 | |
14578 | if (bpt->type == bp_hardware_breakpoint) | |
14579 | { | |
14580 | int i; | |
c5aa993b | 14581 | i = hw_breakpoint_used_count (); |
53a5351d | 14582 | target_resources_ok = |
d92524f1 | 14583 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14584 | i + 1, 0); |
c906108c | 14585 | if (target_resources_ok == 0) |
8a3fe4f8 | 14586 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14587 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14588 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14589 | } |
14590 | ||
cc60f2e3 | 14591 | if (is_watchpoint (bpt)) |
c906108c | 14592 | { |
d07205c2 | 14593 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14594 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14595 | |
492d29ea | 14596 | TRY |
c906108c | 14597 | { |
3a5c3e22 PA |
14598 | struct watchpoint *w = (struct watchpoint *) bpt; |
14599 | ||
1e718ff1 TJB |
14600 | orig_enable_state = bpt->enable_state; |
14601 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14602 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14603 | } |
492d29ea | 14604 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14605 | { |
1e718ff1 | 14606 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14607 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14608 | bpt->number); | |
14609 | return; | |
c5aa993b | 14610 | } |
492d29ea | 14611 | END_CATCH |
c906108c | 14612 | } |
0101ce28 | 14613 | |
b775012e LM |
14614 | bpt->enable_state = bp_enabled; |
14615 | ||
14616 | /* Mark breakpoint locations modified. */ | |
14617 | mark_breakpoint_modified (bpt); | |
14618 | ||
d248b706 KY |
14619 | if (target_supports_enable_disable_tracepoint () |
14620 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14621 | { | |
14622 | struct bp_location *location; | |
14623 | ||
14624 | for (location = bpt->loc; location; location = location->next) | |
14625 | target_enable_tracepoint (location); | |
14626 | } | |
14627 | ||
b4c291bb | 14628 | bpt->disposition = disposition; |
816338b5 | 14629 | bpt->enable_count = count; |
44702360 | 14630 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14631 | |
8d3788bd | 14632 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14633 | } |
14634 | ||
fe3f5fa8 | 14635 | |
c906108c | 14636 | void |
fba45db2 | 14637 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14638 | { |
816338b5 | 14639 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14640 | } |
14641 | ||
c906108c SS |
14642 | /* The enable command enables the specified breakpoints (or all defined |
14643 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14644 | in stopping the inferior. */ |
c906108c | 14645 | |
c906108c | 14646 | static void |
fba45db2 | 14647 | enable_command (char *args, int from_tty) |
c906108c | 14648 | { |
c906108c | 14649 | if (args == 0) |
46c6471b PA |
14650 | { |
14651 | struct breakpoint *bpt; | |
14652 | ||
14653 | ALL_BREAKPOINTS (bpt) | |
14654 | if (user_breakpoint_p (bpt)) | |
14655 | enable_breakpoint (bpt); | |
14656 | } | |
9eaabc75 | 14657 | else |
0d381245 | 14658 | { |
cb791d59 | 14659 | std::string num = extract_arg (&args); |
9eaabc75 | 14660 | |
cb791d59 | 14661 | while (!num.empty ()) |
d248b706 | 14662 | { |
cb791d59 | 14663 | if (num.find ('.') != std::string::npos) |
b775012e | 14664 | { |
cb791d59 | 14665 | struct bp_location *loc = find_location_by_number (num.c_str ()); |
9eaabc75 MW |
14666 | |
14667 | if (loc) | |
14668 | { | |
14669 | if (!loc->enabled) | |
14670 | { | |
14671 | loc->enabled = 1; | |
14672 | mark_breakpoint_location_modified (loc); | |
14673 | } | |
14674 | if (target_supports_enable_disable_tracepoint () | |
14675 | && current_trace_status ()->running && loc->owner | |
14676 | && is_tracepoint (loc->owner)) | |
14677 | target_enable_tracepoint (loc); | |
14678 | } | |
44702360 | 14679 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14680 | } |
9eaabc75 | 14681 | else |
48649e1b TT |
14682 | map_breakpoint_numbers |
14683 | (num.c_str (), [&] (breakpoint *b) | |
14684 | { | |
14685 | iterate_over_related_breakpoints (b, enable_breakpoint); | |
14686 | }); | |
9eaabc75 | 14687 | num = extract_arg (&args); |
d248b706 | 14688 | } |
0d381245 | 14689 | } |
c906108c SS |
14690 | } |
14691 | ||
c906108c | 14692 | static void |
fba45db2 | 14693 | enable_once_command (char *args, int from_tty) |
c906108c | 14694 | { |
48649e1b TT |
14695 | map_breakpoint_numbers |
14696 | (args, [&] (breakpoint *b) | |
14697 | { | |
14698 | iterate_over_related_breakpoints | |
14699 | (b, [&] (breakpoint *bpt) | |
14700 | { | |
14701 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14702 | }); | |
14703 | }); | |
816338b5 SS |
14704 | } |
14705 | ||
14706 | static void | |
14707 | enable_count_command (char *args, int from_tty) | |
14708 | { | |
b9d61307 SM |
14709 | int count; |
14710 | ||
14711 | if (args == NULL) | |
14712 | error_no_arg (_("hit count")); | |
14713 | ||
14714 | count = get_number (&args); | |
816338b5 | 14715 | |
48649e1b TT |
14716 | map_breakpoint_numbers |
14717 | (args, [&] (breakpoint *b) | |
14718 | { | |
14719 | iterate_over_related_breakpoints | |
14720 | (b, [&] (breakpoint *bpt) | |
14721 | { | |
14722 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14723 | }); | |
14724 | }); | |
c906108c SS |
14725 | } |
14726 | ||
c906108c | 14727 | static void |
fba45db2 | 14728 | enable_delete_command (char *args, int from_tty) |
c906108c | 14729 | { |
48649e1b TT |
14730 | map_breakpoint_numbers |
14731 | (args, [&] (breakpoint *b) | |
14732 | { | |
14733 | iterate_over_related_breakpoints | |
14734 | (b, [&] (breakpoint *bpt) | |
14735 | { | |
14736 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14737 | }); | |
14738 | }); | |
c906108c SS |
14739 | } |
14740 | \f | |
fa8d40ab JJ |
14741 | static void |
14742 | set_breakpoint_cmd (char *args, int from_tty) | |
14743 | { | |
14744 | } | |
14745 | ||
14746 | static void | |
14747 | show_breakpoint_cmd (char *args, int from_tty) | |
14748 | { | |
14749 | } | |
14750 | ||
1f3b5d1b PP |
14751 | /* Invalidate last known value of any hardware watchpoint if |
14752 | the memory which that value represents has been written to by | |
14753 | GDB itself. */ | |
14754 | ||
14755 | static void | |
8de0566d YQ |
14756 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14757 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14758 | const bfd_byte *data) |
14759 | { | |
14760 | struct breakpoint *bp; | |
14761 | ||
14762 | ALL_BREAKPOINTS (bp) | |
14763 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14764 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14765 | { |
3a5c3e22 | 14766 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14767 | |
3a5c3e22 PA |
14768 | if (wp->val_valid && wp->val) |
14769 | { | |
14770 | struct bp_location *loc; | |
14771 | ||
14772 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14773 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14774 | && loc->address + loc->length > addr | |
14775 | && addr + len > loc->address) | |
14776 | { | |
14777 | value_free (wp->val); | |
14778 | wp->val = NULL; | |
14779 | wp->val_valid = 0; | |
14780 | } | |
14781 | } | |
1f3b5d1b PP |
14782 | } |
14783 | } | |
14784 | ||
8181d85f DJ |
14785 | /* Create and insert a breakpoint for software single step. */ |
14786 | ||
14787 | void | |
6c95b8df | 14788 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14789 | struct address_space *aspace, |
14790 | CORE_ADDR next_pc) | |
8181d85f | 14791 | { |
7c16b83e PA |
14792 | struct thread_info *tp = inferior_thread (); |
14793 | struct symtab_and_line sal; | |
14794 | CORE_ADDR pc = next_pc; | |
8181d85f | 14795 | |
34b7e8a6 PA |
14796 | if (tp->control.single_step_breakpoints == NULL) |
14797 | { | |
14798 | tp->control.single_step_breakpoints | |
5d5658a1 | 14799 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14800 | } |
8181d85f | 14801 | |
7c16b83e PA |
14802 | sal = find_pc_line (pc, 0); |
14803 | sal.pc = pc; | |
14804 | sal.section = find_pc_overlay (pc); | |
14805 | sal.explicit_pc = 1; | |
34b7e8a6 | 14806 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14807 | |
7c16b83e | 14808 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14809 | } |
14810 | ||
93f9a11f YQ |
14811 | /* Insert single step breakpoints according to the current state. */ |
14812 | ||
14813 | int | |
14814 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14815 | { | |
f5ea389a | 14816 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14817 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14818 | |
f5ea389a | 14819 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14820 | |
a0ff9e1a | 14821 | if (!next_pcs.empty ()) |
93f9a11f | 14822 | { |
f5ea389a | 14823 | struct frame_info *frame = get_current_frame (); |
93f9a11f YQ |
14824 | struct address_space *aspace = get_frame_address_space (frame); |
14825 | ||
a0ff9e1a | 14826 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14827 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14828 | ||
93f9a11f YQ |
14829 | return 1; |
14830 | } | |
14831 | else | |
14832 | return 0; | |
14833 | } | |
14834 | ||
34b7e8a6 | 14835 | /* See breakpoint.h. */ |
f02253f1 HZ |
14836 | |
14837 | int | |
7c16b83e PA |
14838 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
14839 | struct address_space *aspace, | |
14840 | CORE_ADDR pc) | |
1aafd4da | 14841 | { |
7c16b83e | 14842 | struct bp_location *loc; |
1aafd4da | 14843 | |
7c16b83e PA |
14844 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14845 | if (loc->inserted | |
14846 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14847 | return 1; | |
1aafd4da | 14848 | |
7c16b83e | 14849 | return 0; |
ef370185 JB |
14850 | } |
14851 | ||
14852 | /* Check whether a software single-step breakpoint is inserted at | |
14853 | PC. */ | |
14854 | ||
14855 | int | |
14856 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
14857 | CORE_ADDR pc) | |
14858 | { | |
34b7e8a6 PA |
14859 | struct breakpoint *bpt; |
14860 | ||
14861 | ALL_BREAKPOINTS (bpt) | |
14862 | { | |
14863 | if (bpt->type == bp_single_step | |
14864 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14865 | return 1; | |
14866 | } | |
14867 | return 0; | |
1aafd4da UW |
14868 | } |
14869 | ||
1042e4c0 SS |
14870 | /* Tracepoint-specific operations. */ |
14871 | ||
14872 | /* Set tracepoint count to NUM. */ | |
14873 | static void | |
14874 | set_tracepoint_count (int num) | |
14875 | { | |
14876 | tracepoint_count = num; | |
4fa62494 | 14877 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14878 | } |
14879 | ||
70221824 | 14880 | static void |
1042e4c0 SS |
14881 | trace_command (char *arg, int from_tty) |
14882 | { | |
55aa24fb | 14883 | struct breakpoint_ops *ops; |
55aa24fb | 14884 | |
ffc2605c TT |
14885 | event_location_up location = string_to_event_location (&arg, |
14886 | current_language); | |
5b56227b | 14887 | if (location != NULL |
ffc2605c | 14888 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
14889 | ops = &tracepoint_probe_breakpoint_ops; |
14890 | else | |
14891 | ops = &tracepoint_breakpoint_ops; | |
14892 | ||
558a9d82 | 14893 | create_breakpoint (get_current_arch (), |
ffc2605c | 14894 | location.get (), |
f00aae0f | 14895 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14896 | 0 /* tempflag */, |
14897 | bp_tracepoint /* type_wanted */, | |
14898 | 0 /* Ignore count */, | |
14899 | pending_break_support, | |
14900 | ops, | |
14901 | from_tty, | |
14902 | 1 /* enabled */, | |
14903 | 0 /* internal */, 0); | |
1042e4c0 SS |
14904 | } |
14905 | ||
70221824 | 14906 | static void |
7a697b8d SS |
14907 | ftrace_command (char *arg, int from_tty) |
14908 | { | |
ffc2605c TT |
14909 | event_location_up location = string_to_event_location (&arg, |
14910 | current_language); | |
558a9d82 | 14911 | create_breakpoint (get_current_arch (), |
ffc2605c | 14912 | location.get (), |
f00aae0f | 14913 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14914 | 0 /* tempflag */, |
14915 | bp_fast_tracepoint /* type_wanted */, | |
14916 | 0 /* Ignore count */, | |
14917 | pending_break_support, | |
14918 | &tracepoint_breakpoint_ops, | |
14919 | from_tty, | |
14920 | 1 /* enabled */, | |
14921 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14922 | } |
14923 | ||
14924 | /* strace command implementation. Creates a static tracepoint. */ | |
14925 | ||
70221824 | 14926 | static void |
0fb4aa4b PA |
14927 | strace_command (char *arg, int from_tty) |
14928 | { | |
983af33b | 14929 | struct breakpoint_ops *ops; |
ffc2605c | 14930 | event_location_up location; |
f00aae0f | 14931 | struct cleanup *back_to; |
983af33b SDJ |
14932 | |
14933 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14934 | or with a normal static tracepoint. */ | |
61012eef | 14935 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14936 | { |
14937 | ops = &strace_marker_breakpoint_ops; | |
14938 | location = new_linespec_location (&arg); | |
14939 | } | |
983af33b | 14940 | else |
f00aae0f KS |
14941 | { |
14942 | ops = &tracepoint_breakpoint_ops; | |
14943 | location = string_to_event_location (&arg, current_language); | |
14944 | } | |
983af33b | 14945 | |
558a9d82 | 14946 | create_breakpoint (get_current_arch (), |
ffc2605c | 14947 | location.get (), |
f00aae0f | 14948 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14949 | 0 /* tempflag */, |
14950 | bp_static_tracepoint /* type_wanted */, | |
14951 | 0 /* Ignore count */, | |
14952 | pending_break_support, | |
14953 | ops, | |
14954 | from_tty, | |
14955 | 1 /* enabled */, | |
14956 | 0 /* internal */, 0); | |
7a697b8d SS |
14957 | } |
14958 | ||
409873ef SS |
14959 | /* Set up a fake reader function that gets command lines from a linked |
14960 | list that was acquired during tracepoint uploading. */ | |
14961 | ||
14962 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14963 | static int next_cmd; |
409873ef SS |
14964 | |
14965 | static char * | |
14966 | read_uploaded_action (void) | |
14967 | { | |
14968 | char *rslt; | |
14969 | ||
3149d8c1 | 14970 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14971 | |
3149d8c1 | 14972 | next_cmd++; |
409873ef SS |
14973 | |
14974 | return rslt; | |
14975 | } | |
14976 | ||
00bf0b85 SS |
14977 | /* Given information about a tracepoint as recorded on a target (which |
14978 | can be either a live system or a trace file), attempt to create an | |
14979 | equivalent GDB tracepoint. This is not a reliable process, since | |
14980 | the target does not necessarily have all the information used when | |
14981 | the tracepoint was originally defined. */ | |
14982 | ||
d9b3f62e | 14983 | struct tracepoint * |
00bf0b85 | 14984 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14985 | { |
409873ef | 14986 | char *addr_str, small_buf[100]; |
d9b3f62e | 14987 | struct tracepoint *tp; |
fd9b8c24 | 14988 | |
409873ef SS |
14989 | if (utp->at_string) |
14990 | addr_str = utp->at_string; | |
14991 | else | |
14992 | { | |
14993 | /* In the absence of a source location, fall back to raw | |
14994 | address. Since there is no way to confirm that the address | |
14995 | means the same thing as when the trace was started, warn the | |
14996 | user. */ | |
3e43a32a MS |
14997 | warning (_("Uploaded tracepoint %d has no " |
14998 | "source location, using raw address"), | |
409873ef | 14999 | utp->number); |
8c042590 | 15000 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15001 | addr_str = small_buf; |
15002 | } | |
15003 | ||
15004 | /* There's not much we can do with a sequence of bytecodes. */ | |
15005 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15006 | warning (_("Uploaded tracepoint %d condition " |
15007 | "has no source form, ignoring it"), | |
409873ef | 15008 | utp->number); |
d5551862 | 15009 | |
ffc2605c TT |
15010 | event_location_up location = string_to_event_location (&addr_str, |
15011 | current_language); | |
8cdf0e15 | 15012 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 15013 | location.get (), |
f00aae0f | 15014 | utp->cond_string, -1, addr_str, |
e7e0cddf | 15015 | 0 /* parse cond/thread */, |
8cdf0e15 | 15016 | 0 /* tempflag */, |
0fb4aa4b | 15017 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15018 | 0 /* Ignore count */, |
15019 | pending_break_support, | |
348d480f | 15020 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15021 | 0 /* from_tty */, |
84f4c1fe | 15022 | utp->enabled /* enabled */, |
44f238bb PA |
15023 | 0 /* internal */, |
15024 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 15025 | return NULL; |
fd9b8c24 | 15026 | |
409873ef | 15027 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15028 | tp = get_tracepoint (tracepoint_count); |
15029 | gdb_assert (tp != NULL); | |
d5551862 | 15030 | |
00bf0b85 SS |
15031 | if (utp->pass > 0) |
15032 | { | |
8c042590 | 15033 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 15034 | tp->number); |
00bf0b85 | 15035 | |
409873ef | 15036 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15037 | } |
15038 | ||
409873ef SS |
15039 | /* If we have uploaded versions of the original commands, set up a |
15040 | special-purpose "reader" function and call the usual command line | |
15041 | reader, then pass the result to the breakpoint command-setting | |
15042 | function. */ | |
3149d8c1 | 15043 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15044 | { |
93921405 | 15045 | command_line_up cmd_list; |
00bf0b85 | 15046 | |
409873ef | 15047 | this_utp = utp; |
3149d8c1 | 15048 | next_cmd = 0; |
d5551862 | 15049 | |
409873ef SS |
15050 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15051 | ||
c1fc2657 | 15052 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 15053 | } |
3149d8c1 SS |
15054 | else if (!VEC_empty (char_ptr, utp->actions) |
15055 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15056 | warning (_("Uploaded tracepoint %d actions " |
15057 | "have no source form, ignoring them"), | |
409873ef | 15058 | utp->number); |
00bf0b85 | 15059 | |
f196051f | 15060 | /* Copy any status information that might be available. */ |
c1fc2657 | 15061 | tp->hit_count = utp->hit_count; |
f196051f SS |
15062 | tp->traceframe_usage = utp->traceframe_usage; |
15063 | ||
00bf0b85 | 15064 | return tp; |
d9b3f62e | 15065 | } |
00bf0b85 | 15066 | |
1042e4c0 SS |
15067 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15068 | omitted. */ | |
15069 | ||
15070 | static void | |
11db9430 | 15071 | info_tracepoints_command (char *args, int from_tty) |
1042e4c0 | 15072 | { |
79a45e25 | 15073 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15074 | int num_printed; |
1042e4c0 | 15075 | |
e5a67952 | 15076 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15077 | |
15078 | if (num_printed == 0) | |
1042e4c0 | 15079 | { |
e5a67952 | 15080 | if (args == NULL || *args == '\0') |
112e8700 | 15081 | uiout->message ("No tracepoints.\n"); |
d77f58be | 15082 | else |
112e8700 | 15083 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15084 | } |
ad443146 SS |
15085 | |
15086 | default_collect_info (); | |
1042e4c0 SS |
15087 | } |
15088 | ||
4a64f543 | 15089 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15090 | Not supported by all targets. */ |
15091 | static void | |
15092 | enable_trace_command (char *args, int from_tty) | |
15093 | { | |
15094 | enable_command (args, from_tty); | |
15095 | } | |
15096 | ||
4a64f543 | 15097 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15098 | Not supported by all targets. */ |
15099 | static void | |
15100 | disable_trace_command (char *args, int from_tty) | |
15101 | { | |
15102 | disable_command (args, from_tty); | |
15103 | } | |
15104 | ||
4a64f543 | 15105 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15106 | static void |
15107 | delete_trace_command (char *arg, int from_tty) | |
15108 | { | |
35df4500 | 15109 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15110 | |
15111 | dont_repeat (); | |
15112 | ||
15113 | if (arg == 0) | |
15114 | { | |
15115 | int breaks_to_delete = 0; | |
15116 | ||
15117 | /* Delete all breakpoints if no argument. | |
15118 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15119 | have to be deleted with an explicit breakpoint number |
15120 | argument. */ | |
1042e4c0 | 15121 | ALL_TRACEPOINTS (b) |
46c6471b | 15122 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15123 | { |
15124 | breaks_to_delete = 1; | |
15125 | break; | |
15126 | } | |
1042e4c0 SS |
15127 | |
15128 | /* Ask user only if there are some breakpoints to delete. */ | |
15129 | if (!from_tty | |
15130 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15131 | { | |
35df4500 | 15132 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15133 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15134 | delete_breakpoint (b); |
1042e4c0 SS |
15135 | } |
15136 | } | |
15137 | else | |
48649e1b TT |
15138 | map_breakpoint_numbers |
15139 | (arg, [&] (breakpoint *b) | |
15140 | { | |
15141 | iterate_over_related_breakpoints (b, delete_breakpoint); | |
15142 | }); | |
1042e4c0 SS |
15143 | } |
15144 | ||
197f0a60 TT |
15145 | /* Helper function for trace_pass_command. */ |
15146 | ||
15147 | static void | |
d9b3f62e | 15148 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15149 | { |
d9b3f62e | 15150 | tp->pass_count = count; |
c1fc2657 | 15151 | observer_notify_breakpoint_modified (tp); |
197f0a60 TT |
15152 | if (from_tty) |
15153 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 15154 | tp->number, count); |
197f0a60 TT |
15155 | } |
15156 | ||
1042e4c0 SS |
15157 | /* Set passcount for tracepoint. |
15158 | ||
15159 | First command argument is passcount, second is tracepoint number. | |
15160 | If tracepoint number omitted, apply to most recently defined. | |
15161 | Also accepts special argument "all". */ | |
15162 | ||
15163 | static void | |
15164 | trace_pass_command (char *args, int from_tty) | |
15165 | { | |
d9b3f62e | 15166 | struct tracepoint *t1; |
1042e4c0 | 15167 | unsigned int count; |
1042e4c0 SS |
15168 | |
15169 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15170 | error (_("passcount command requires an " |
15171 | "argument (count + optional TP num)")); | |
1042e4c0 | 15172 | |
4a64f543 | 15173 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15174 | |
529480d0 | 15175 | args = skip_spaces (args); |
1042e4c0 SS |
15176 | if (*args && strncasecmp (args, "all", 3) == 0) |
15177 | { | |
d9b3f62e PA |
15178 | struct breakpoint *b; |
15179 | ||
1042e4c0 | 15180 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15181 | if (*args) |
15182 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15183 | |
d9b3f62e | 15184 | ALL_TRACEPOINTS (b) |
197f0a60 | 15185 | { |
d9b3f62e | 15186 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15187 | trace_pass_set_count (t1, count, from_tty); |
15188 | } | |
15189 | } | |
15190 | else if (*args == '\0') | |
1042e4c0 | 15191 | { |
5fa1d40e | 15192 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15193 | if (t1) |
197f0a60 TT |
15194 | trace_pass_set_count (t1, count, from_tty); |
15195 | } | |
15196 | else | |
15197 | { | |
bfd28288 PA |
15198 | number_or_range_parser parser (args); |
15199 | while (!parser.finished ()) | |
1042e4c0 | 15200 | { |
bfd28288 | 15201 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15202 | if (t1) |
15203 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15204 | } |
15205 | } | |
1042e4c0 SS |
15206 | } |
15207 | ||
d9b3f62e | 15208 | struct tracepoint * |
1042e4c0 SS |
15209 | get_tracepoint (int num) |
15210 | { | |
15211 | struct breakpoint *t; | |
15212 | ||
15213 | ALL_TRACEPOINTS (t) | |
15214 | if (t->number == num) | |
d9b3f62e | 15215 | return (struct tracepoint *) t; |
1042e4c0 SS |
15216 | |
15217 | return NULL; | |
15218 | } | |
15219 | ||
d5551862 SS |
15220 | /* Find the tracepoint with the given target-side number (which may be |
15221 | different from the tracepoint number after disconnecting and | |
15222 | reconnecting). */ | |
15223 | ||
d9b3f62e | 15224 | struct tracepoint * |
d5551862 SS |
15225 | get_tracepoint_by_number_on_target (int num) |
15226 | { | |
d9b3f62e | 15227 | struct breakpoint *b; |
d5551862 | 15228 | |
d9b3f62e PA |
15229 | ALL_TRACEPOINTS (b) |
15230 | { | |
15231 | struct tracepoint *t = (struct tracepoint *) b; | |
15232 | ||
15233 | if (t->number_on_target == num) | |
15234 | return t; | |
15235 | } | |
d5551862 SS |
15236 | |
15237 | return NULL; | |
15238 | } | |
15239 | ||
1042e4c0 | 15240 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15241 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15242 | If the argument is missing, the most recent tracepoint |
15243 | (tracepoint_count) is returned. */ | |
15244 | ||
d9b3f62e | 15245 | struct tracepoint * |
197f0a60 | 15246 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15247 | number_or_range_parser *parser) |
1042e4c0 | 15248 | { |
1042e4c0 SS |
15249 | struct breakpoint *t; |
15250 | int tpnum; | |
15251 | char *instring = arg == NULL ? NULL : *arg; | |
15252 | ||
bfd28288 | 15253 | if (parser != NULL) |
197f0a60 | 15254 | { |
bfd28288 PA |
15255 | gdb_assert (!parser->finished ()); |
15256 | tpnum = parser->get_number (); | |
197f0a60 TT |
15257 | } |
15258 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15259 | tpnum = tracepoint_count; |
1042e4c0 | 15260 | else |
197f0a60 | 15261 | tpnum = get_number (arg); |
1042e4c0 SS |
15262 | |
15263 | if (tpnum <= 0) | |
15264 | { | |
15265 | if (instring && *instring) | |
15266 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15267 | instring); | |
15268 | else | |
5fa1d40e | 15269 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15270 | return NULL; |
15271 | } | |
15272 | ||
15273 | ALL_TRACEPOINTS (t) | |
15274 | if (t->number == tpnum) | |
15275 | { | |
d9b3f62e | 15276 | return (struct tracepoint *) t; |
1042e4c0 SS |
15277 | } |
15278 | ||
1042e4c0 SS |
15279 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15280 | return NULL; | |
15281 | } | |
15282 | ||
d9b3f62e PA |
15283 | void |
15284 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15285 | { | |
15286 | if (b->thread != -1) | |
15287 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15288 | ||
15289 | if (b->task != 0) | |
15290 | fprintf_unfiltered (fp, " task %d", b->task); | |
15291 | ||
15292 | fprintf_unfiltered (fp, "\n"); | |
15293 | } | |
15294 | ||
6149aea9 PA |
15295 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15296 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15297 | on each breakpoint and only include the ones for which it returns | |
15298 | non-zero. */ | |
15299 | ||
1042e4c0 | 15300 | static void |
6149aea9 PA |
15301 | save_breakpoints (char *filename, int from_tty, |
15302 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15303 | { |
15304 | struct breakpoint *tp; | |
6149aea9 | 15305 | int any = 0; |
6149aea9 | 15306 | int extra_trace_bits = 0; |
1042e4c0 | 15307 | |
6149aea9 PA |
15308 | if (filename == 0 || *filename == 0) |
15309 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15310 | |
15311 | /* See if we have anything to save. */ | |
6149aea9 | 15312 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15313 | { |
6149aea9 | 15314 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15315 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15316 | continue; |
15317 | ||
15318 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15319 | if (filter && !filter (tp)) | |
15320 | continue; | |
15321 | ||
15322 | any = 1; | |
15323 | ||
15324 | if (is_tracepoint (tp)) | |
15325 | { | |
15326 | extra_trace_bits = 1; | |
15327 | ||
15328 | /* We can stop searching. */ | |
15329 | break; | |
15330 | } | |
1042e4c0 | 15331 | } |
6149aea9 PA |
15332 | |
15333 | if (!any) | |
1042e4c0 | 15334 | { |
6149aea9 | 15335 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15336 | return; |
15337 | } | |
15338 | ||
ee0c3293 | 15339 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
15340 | |
15341 | stdio_file fp; | |
15342 | ||
ee0c3293 | 15343 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 15344 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 15345 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 15346 | |
6149aea9 | 15347 | if (extra_trace_bits) |
d7e74731 | 15348 | save_trace_state_variables (&fp); |
8bf6485c | 15349 | |
6149aea9 | 15350 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15351 | { |
6149aea9 | 15352 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15353 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15354 | continue; |
8bf6485c | 15355 | |
6149aea9 PA |
15356 | /* If we have a filter, only save the breakpoints it accepts. */ |
15357 | if (filter && !filter (tp)) | |
15358 | continue; | |
15359 | ||
d7e74731 | 15360 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15361 | |
6149aea9 PA |
15362 | /* Note, we can't rely on tp->number for anything, as we can't |
15363 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15364 | instead. */ | |
15365 | ||
15366 | if (tp->cond_string) | |
d7e74731 | 15367 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15368 | |
15369 | if (tp->ignore_count) | |
d7e74731 | 15370 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15371 | |
2d9442cc | 15372 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15373 | { |
d7e74731 | 15374 | fp.puts (" commands\n"); |
a7bdde9e | 15375 | |
d7e74731 | 15376 | current_uiout->redirect (&fp); |
492d29ea | 15377 | TRY |
1042e4c0 | 15378 | { |
79a45e25 | 15379 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15380 | } |
492d29ea PA |
15381 | CATCH (ex, RETURN_MASK_ALL) |
15382 | { | |
112e8700 | 15383 | current_uiout->redirect (NULL); |
492d29ea PA |
15384 | throw_exception (ex); |
15385 | } | |
15386 | END_CATCH | |
1042e4c0 | 15387 | |
112e8700 | 15388 | current_uiout->redirect (NULL); |
d7e74731 | 15389 | fp.puts (" end\n"); |
1042e4c0 | 15390 | } |
6149aea9 PA |
15391 | |
15392 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15393 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15394 | |
15395 | /* If this is a multi-location breakpoint, check if the locations | |
15396 | should be individually disabled. Watchpoint locations are | |
15397 | special, and not user visible. */ | |
15398 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15399 | { | |
15400 | struct bp_location *loc; | |
15401 | int n = 1; | |
15402 | ||
15403 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15404 | if (!loc->enabled) | |
d7e74731 | 15405 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15406 | } |
1042e4c0 | 15407 | } |
8bf6485c | 15408 | |
6149aea9 | 15409 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15410 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15411 | |
1042e4c0 | 15412 | if (from_tty) |
ee0c3293 | 15413 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15414 | } |
15415 | ||
15416 | /* The `save breakpoints' command. */ | |
15417 | ||
15418 | static void | |
15419 | save_breakpoints_command (char *args, int from_tty) | |
15420 | { | |
15421 | save_breakpoints (args, from_tty, NULL); | |
15422 | } | |
15423 | ||
15424 | /* The `save tracepoints' command. */ | |
15425 | ||
15426 | static void | |
15427 | save_tracepoints_command (char *args, int from_tty) | |
15428 | { | |
15429 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15430 | } |
15431 | ||
15432 | /* Create a vector of all tracepoints. */ | |
15433 | ||
15434 | VEC(breakpoint_p) * | |
eeae04df | 15435 | all_tracepoints (void) |
1042e4c0 SS |
15436 | { |
15437 | VEC(breakpoint_p) *tp_vec = 0; | |
15438 | struct breakpoint *tp; | |
15439 | ||
15440 | ALL_TRACEPOINTS (tp) | |
15441 | { | |
15442 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15443 | } | |
15444 | ||
15445 | return tp_vec; | |
15446 | } | |
15447 | ||
c906108c | 15448 | \f |
629500fa KS |
15449 | /* This help string is used to consolidate all the help string for specifying |
15450 | locations used by several commands. */ | |
15451 | ||
15452 | #define LOCATION_HELP_STRING \ | |
15453 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15454 | source filename, function name, label name, and line number.\n\ | |
15455 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15456 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15457 | \"factorial.c:fact:the_top\".\n\ | |
15458 | \n\ | |
15459 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15460 | program. Example: To specify the fourth byte past the start function\n\ | |
15461 | \"main\", use \"*main + 4\".\n\ | |
15462 | \n\ | |
15463 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15464 | syntax to specify location parameters.\n\ | |
15465 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15466 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15467 | -function fact -label the_top\".\n" | |
15468 | ||
4a64f543 MS |
15469 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15470 | commands. It is defined as a macro to prevent duplication. | |
15471 | COMMAND should be a string constant containing the name of the | |
15472 | command. */ | |
629500fa | 15473 | |
31e2b00f | 15474 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15475 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15476 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15477 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15478 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15479 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15480 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15481 | below.\n\ | |
15482 | \n\ | |
dc10affe PA |
15483 | With no LOCATION, uses current execution address of the selected\n\ |
15484 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15485 | \n\ |
15486 | THREADNUM is the number from \"info threads\".\n\ | |
15487 | CONDITION is a boolean expression.\n\ | |
629500fa | 15488 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15489 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15490 | conditions are different.\n\ | |
31e2b00f AS |
15491 | \n\ |
15492 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15493 | ||
44feb3ce TT |
15494 | /* List of subcommands for "catch". */ |
15495 | static struct cmd_list_element *catch_cmdlist; | |
15496 | ||
15497 | /* List of subcommands for "tcatch". */ | |
15498 | static struct cmd_list_element *tcatch_cmdlist; | |
15499 | ||
9ac4176b | 15500 | void |
a121b7c1 | 15501 | add_catch_command (const char *name, const char *docstring, |
82ae6c8d | 15502 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15503 | completer_ftype *completer, |
44feb3ce TT |
15504 | void *user_data_catch, |
15505 | void *user_data_tcatch) | |
15506 | { | |
15507 | struct cmd_list_element *command; | |
15508 | ||
15509 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15510 | &catch_cmdlist); | |
15511 | set_cmd_sfunc (command, sfunc); | |
15512 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15513 | set_cmd_completer (command, completer); |
44feb3ce TT |
15514 | |
15515 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15516 | &tcatch_cmdlist); | |
15517 | set_cmd_sfunc (command, sfunc); | |
15518 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15519 | set_cmd_completer (command, completer); |
44feb3ce TT |
15520 | } |
15521 | ||
6149aea9 PA |
15522 | static void |
15523 | save_command (char *arg, int from_tty) | |
15524 | { | |
3e43a32a MS |
15525 | printf_unfiltered (_("\"save\" must be followed by " |
15526 | "the name of a save subcommand.\n")); | |
635c7e8a | 15527 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15528 | } |
15529 | ||
84f4c1fe PM |
15530 | struct breakpoint * |
15531 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15532 | void *data) | |
15533 | { | |
35df4500 | 15534 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15535 | |
35df4500 | 15536 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15537 | { |
15538 | if ((*callback) (b, data)) | |
15539 | return b; | |
15540 | } | |
15541 | ||
15542 | return NULL; | |
15543 | } | |
15544 | ||
0574c78f GB |
15545 | /* Zero if any of the breakpoint's locations could be a location where |
15546 | functions have been inlined, nonzero otherwise. */ | |
15547 | ||
15548 | static int | |
15549 | is_non_inline_function (struct breakpoint *b) | |
15550 | { | |
15551 | /* The shared library event breakpoint is set on the address of a | |
15552 | non-inline function. */ | |
15553 | if (b->type == bp_shlib_event) | |
15554 | return 1; | |
15555 | ||
15556 | return 0; | |
15557 | } | |
15558 | ||
15559 | /* Nonzero if the specified PC cannot be a location where functions | |
15560 | have been inlined. */ | |
15561 | ||
15562 | int | |
09ac7c10 TT |
15563 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15564 | const struct target_waitstatus *ws) | |
0574c78f GB |
15565 | { |
15566 | struct breakpoint *b; | |
15567 | struct bp_location *bl; | |
15568 | ||
15569 | ALL_BREAKPOINTS (b) | |
15570 | { | |
15571 | if (!is_non_inline_function (b)) | |
15572 | continue; | |
15573 | ||
15574 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15575 | { | |
15576 | if (!bl->shlib_disabled | |
09ac7c10 | 15577 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15578 | return 1; |
15579 | } | |
15580 | } | |
15581 | ||
15582 | return 0; | |
15583 | } | |
15584 | ||
2f202fde JK |
15585 | /* Remove any references to OBJFILE which is going to be freed. */ |
15586 | ||
15587 | void | |
15588 | breakpoint_free_objfile (struct objfile *objfile) | |
15589 | { | |
15590 | struct bp_location **locp, *loc; | |
15591 | ||
15592 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15593 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15594 | loc->symtab = NULL; |
15595 | } | |
15596 | ||
2060206e PA |
15597 | void |
15598 | initialize_breakpoint_ops (void) | |
15599 | { | |
15600 | static int initialized = 0; | |
15601 | ||
15602 | struct breakpoint_ops *ops; | |
15603 | ||
15604 | if (initialized) | |
15605 | return; | |
15606 | initialized = 1; | |
15607 | ||
15608 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15609 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15610 | internal and momentary breakpoints, etc.). */ | |
15611 | ops = &bkpt_base_breakpoint_ops; | |
15612 | *ops = base_breakpoint_ops; | |
15613 | ops->re_set = bkpt_re_set; | |
15614 | ops->insert_location = bkpt_insert_location; | |
15615 | ops->remove_location = bkpt_remove_location; | |
15616 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15617 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15618 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15619 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15620 | |
15621 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15622 | ops = &bkpt_breakpoint_ops; | |
15623 | *ops = bkpt_base_breakpoint_ops; | |
15624 | ops->re_set = bkpt_re_set; | |
15625 | ops->resources_needed = bkpt_resources_needed; | |
15626 | ops->print_it = bkpt_print_it; | |
15627 | ops->print_mention = bkpt_print_mention; | |
15628 | ops->print_recreate = bkpt_print_recreate; | |
15629 | ||
15630 | /* Ranged breakpoints. */ | |
15631 | ops = &ranged_breakpoint_ops; | |
15632 | *ops = bkpt_breakpoint_ops; | |
15633 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15634 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15635 | ops->print_it = print_it_ranged_breakpoint; | |
15636 | ops->print_one = print_one_ranged_breakpoint; | |
15637 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15638 | ops->print_mention = print_mention_ranged_breakpoint; | |
15639 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15640 | ||
15641 | /* Internal breakpoints. */ | |
15642 | ops = &internal_breakpoint_ops; | |
15643 | *ops = bkpt_base_breakpoint_ops; | |
15644 | ops->re_set = internal_bkpt_re_set; | |
15645 | ops->check_status = internal_bkpt_check_status; | |
15646 | ops->print_it = internal_bkpt_print_it; | |
15647 | ops->print_mention = internal_bkpt_print_mention; | |
15648 | ||
15649 | /* Momentary breakpoints. */ | |
15650 | ops = &momentary_breakpoint_ops; | |
15651 | *ops = bkpt_base_breakpoint_ops; | |
15652 | ops->re_set = momentary_bkpt_re_set; | |
15653 | ops->check_status = momentary_bkpt_check_status; | |
15654 | ops->print_it = momentary_bkpt_print_it; | |
15655 | ops->print_mention = momentary_bkpt_print_mention; | |
15656 | ||
55aa24fb SDJ |
15657 | /* Probe breakpoints. */ |
15658 | ops = &bkpt_probe_breakpoint_ops; | |
15659 | *ops = bkpt_breakpoint_ops; | |
15660 | ops->insert_location = bkpt_probe_insert_location; | |
15661 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15662 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15663 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15664 | |
2060206e PA |
15665 | /* Watchpoints. */ |
15666 | ops = &watchpoint_breakpoint_ops; | |
15667 | *ops = base_breakpoint_ops; | |
15668 | ops->re_set = re_set_watchpoint; | |
15669 | ops->insert_location = insert_watchpoint; | |
15670 | ops->remove_location = remove_watchpoint; | |
15671 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15672 | ops->check_status = check_status_watchpoint; | |
15673 | ops->resources_needed = resources_needed_watchpoint; | |
15674 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15675 | ops->print_it = print_it_watchpoint; | |
15676 | ops->print_mention = print_mention_watchpoint; | |
15677 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15678 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15679 | |
15680 | /* Masked watchpoints. */ | |
15681 | ops = &masked_watchpoint_breakpoint_ops; | |
15682 | *ops = watchpoint_breakpoint_ops; | |
15683 | ops->insert_location = insert_masked_watchpoint; | |
15684 | ops->remove_location = remove_masked_watchpoint; | |
15685 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15686 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15687 | ops->print_it = print_it_masked_watchpoint; | |
15688 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15689 | ops->print_mention = print_mention_masked_watchpoint; | |
15690 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15691 | ||
15692 | /* Tracepoints. */ | |
15693 | ops = &tracepoint_breakpoint_ops; | |
15694 | *ops = base_breakpoint_ops; | |
15695 | ops->re_set = tracepoint_re_set; | |
15696 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15697 | ops->print_one_detail = tracepoint_print_one_detail; | |
15698 | ops->print_mention = tracepoint_print_mention; | |
15699 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15700 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15701 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15702 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15703 | |
55aa24fb SDJ |
15704 | /* Probe tracepoints. */ |
15705 | ops = &tracepoint_probe_breakpoint_ops; | |
15706 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15707 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15708 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15709 | |
983af33b SDJ |
15710 | /* Static tracepoints with marker (`-m'). */ |
15711 | ops = &strace_marker_breakpoint_ops; | |
15712 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15713 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15714 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15715 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15716 | |
15717 | /* Fork catchpoints. */ | |
15718 | ops = &catch_fork_breakpoint_ops; | |
15719 | *ops = base_breakpoint_ops; | |
15720 | ops->insert_location = insert_catch_fork; | |
15721 | ops->remove_location = remove_catch_fork; | |
15722 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15723 | ops->print_it = print_it_catch_fork; | |
15724 | ops->print_one = print_one_catch_fork; | |
15725 | ops->print_mention = print_mention_catch_fork; | |
15726 | ops->print_recreate = print_recreate_catch_fork; | |
15727 | ||
15728 | /* Vfork catchpoints. */ | |
15729 | ops = &catch_vfork_breakpoint_ops; | |
15730 | *ops = base_breakpoint_ops; | |
15731 | ops->insert_location = insert_catch_vfork; | |
15732 | ops->remove_location = remove_catch_vfork; | |
15733 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15734 | ops->print_it = print_it_catch_vfork; | |
15735 | ops->print_one = print_one_catch_vfork; | |
15736 | ops->print_mention = print_mention_catch_vfork; | |
15737 | ops->print_recreate = print_recreate_catch_vfork; | |
15738 | ||
15739 | /* Exec catchpoints. */ | |
15740 | ops = &catch_exec_breakpoint_ops; | |
15741 | *ops = base_breakpoint_ops; | |
2060206e PA |
15742 | ops->insert_location = insert_catch_exec; |
15743 | ops->remove_location = remove_catch_exec; | |
15744 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15745 | ops->print_it = print_it_catch_exec; | |
15746 | ops->print_one = print_one_catch_exec; | |
15747 | ops->print_mention = print_mention_catch_exec; | |
15748 | ops->print_recreate = print_recreate_catch_exec; | |
15749 | ||
edcc5120 TT |
15750 | /* Solib-related catchpoints. */ |
15751 | ops = &catch_solib_breakpoint_ops; | |
15752 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15753 | ops->insert_location = insert_catch_solib; |
15754 | ops->remove_location = remove_catch_solib; | |
15755 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15756 | ops->check_status = check_status_catch_solib; | |
15757 | ops->print_it = print_it_catch_solib; | |
15758 | ops->print_one = print_one_catch_solib; | |
15759 | ops->print_mention = print_mention_catch_solib; | |
15760 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15761 | |
15762 | ops = &dprintf_breakpoint_ops; | |
15763 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15764 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15765 | ops->resources_needed = bkpt_resources_needed; |
15766 | ops->print_it = bkpt_print_it; | |
15767 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15768 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15769 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15770 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15771 | } |
15772 | ||
8bfd80db YQ |
15773 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15774 | ||
15775 | static struct cmd_list_element *enablebreaklist = NULL; | |
15776 | ||
c906108c | 15777 | void |
fba45db2 | 15778 | _initialize_breakpoint (void) |
c906108c SS |
15779 | { |
15780 | struct cmd_list_element *c; | |
15781 | ||
2060206e PA |
15782 | initialize_breakpoint_ops (); |
15783 | ||
84acb35a | 15784 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15785 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15786 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15787 | |
55aa24fb SDJ |
15788 | breakpoint_objfile_key |
15789 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 15790 | |
c906108c SS |
15791 | breakpoint_chain = 0; |
15792 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15793 | before a breakpoint is set. */ | |
15794 | breakpoint_count = 0; | |
15795 | ||
1042e4c0 SS |
15796 | tracepoint_count = 0; |
15797 | ||
1bedd215 AC |
15798 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15799 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15800 | Usage is `ignore N COUNT'.")); | |
c906108c | 15801 | |
1bedd215 | 15802 | add_com ("commands", class_breakpoint, commands_command, _("\ |
18da0c51 MG |
15803 | Set commands to be executed when the given breakpoints are hit.\n\ |
15804 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15805 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15806 | (e.g. `5-7').\n\ | |
c906108c SS |
15807 | With no argument, the targeted breakpoint is the last one set.\n\ |
15808 | The commands themselves follow starting on the next line.\n\ | |
15809 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15810 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15811 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15812 | |
d55637df | 15813 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15814 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15815 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15816 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15817 | set_cmd_completer (c, condition_completer); |
c906108c | 15818 | |
1bedd215 | 15819 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15820 | Set a temporary breakpoint.\n\ |
c906108c SS |
15821 | Like \"break\" except the breakpoint is only temporary,\n\ |
15822 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15823 | by using \"enable delete\" on the breakpoint number.\n\ |
15824 | \n" | |
15825 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15826 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15827 | |
1bedd215 | 15828 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15829 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15830 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15831 | some target hardware may not have this support.\n\ |
15832 | \n" | |
15833 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15834 | set_cmd_completer (c, location_completer); |
c906108c | 15835 | |
1bedd215 | 15836 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15837 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15838 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15839 | so it will be deleted when hit.\n\ |
15840 | \n" | |
15841 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15842 | set_cmd_completer (c, location_completer); |
c906108c | 15843 | |
1bedd215 AC |
15844 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15845 | Enable some breakpoints.\n\ | |
c906108c SS |
15846 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15847 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15848 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15849 | With a subcommand you can enable temporarily."), |
c906108c | 15850 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15851 | |
15852 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15853 | ||
84951ab5 | 15854 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15855 | Enable some breakpoints.\n\ |
c906108c SS |
15856 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15857 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15858 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15859 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15860 | |
1a966eab AC |
15861 | add_cmd ("once", no_class, enable_once_command, _("\ |
15862 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15863 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15864 | &enablebreaklist); |
15865 | ||
1a966eab AC |
15866 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15867 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15868 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15869 | &enablebreaklist); |
15870 | ||
816338b5 SS |
15871 | add_cmd ("count", no_class, enable_count_command, _("\ |
15872 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15873 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15874 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15875 | &enablebreaklist); | |
15876 | ||
1a966eab AC |
15877 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15878 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15879 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15880 | &enablelist); |
15881 | ||
1a966eab AC |
15882 | add_cmd ("once", no_class, enable_once_command, _("\ |
15883 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15884 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15885 | &enablelist); |
15886 | ||
15887 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15888 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15889 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15890 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15891 | &enablelist); |
15892 | ||
1bedd215 AC |
15893 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15894 | Disable some breakpoints.\n\ | |
c906108c SS |
15895 | Arguments are breakpoint numbers with spaces in between.\n\ |
15896 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15897 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15898 | &disablelist, "disable ", 1, &cmdlist); |
15899 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15900 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15901 | |
1a966eab AC |
15902 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15903 | Disable some breakpoints.\n\ | |
c906108c SS |
15904 | Arguments are breakpoint numbers with spaces in between.\n\ |
15905 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15906 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15907 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15908 | &disablelist); |
15909 | ||
1bedd215 AC |
15910 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15911 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15912 | Arguments are breakpoint numbers with spaces in between.\n\ |
15913 | To delete all breakpoints, give no argument.\n\ | |
15914 | \n\ | |
15915 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15916 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15917 | &deletelist, "delete ", 1, &cmdlist); |
15918 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15919 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15920 | |
1a966eab AC |
15921 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15922 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15923 | Arguments are breakpoint numbers with spaces in between.\n\ |
15924 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15925 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15926 | &deletelist); |
15927 | ||
1bedd215 | 15928 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15929 | Clear breakpoint at specified location.\n\ |
15930 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15931 | \n\ |
15932 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
15933 | is executing in.\n" |
15934 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 15935 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15936 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15937 | |
1bedd215 | 15938 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15939 | Set breakpoint at specified location.\n" |
31e2b00f | 15940 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15941 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15942 | |
c906108c SS |
15943 | add_com_alias ("b", "break", class_run, 1); |
15944 | add_com_alias ("br", "break", class_run, 1); | |
15945 | add_com_alias ("bre", "break", class_run, 1); | |
15946 | add_com_alias ("brea", "break", class_run, 1); | |
15947 | ||
c906108c SS |
15948 | if (dbx_commands) |
15949 | { | |
1bedd215 AC |
15950 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15951 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15952 | &stoplist, "stop ", 1, &cmdlist); |
15953 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15954 | _("Break in function or address."), &stoplist); |
c5aa993b | 15955 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15956 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15957 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15958 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15959 | The \"Type\" column indicates one of:\n\ |
15960 | \tbreakpoint - normal breakpoint\n\ | |
15961 | \twatchpoint - watchpoint\n\ | |
15962 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15963 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15964 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15965 | address and file/line number respectively.\n\ |
15966 | \n\ | |
15967 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15968 | are set to the address of the last breakpoint listed unless the command\n\ |
15969 | is prefixed with \"server \".\n\n\ | |
c906108c | 15970 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15971 | breakpoint set.")); |
c906108c SS |
15972 | } |
15973 | ||
11db9430 | 15974 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15975 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15976 | The \"Type\" column indicates one of:\n\ |
15977 | \tbreakpoint - normal breakpoint\n\ | |
15978 | \twatchpoint - watchpoint\n\ | |
15979 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15980 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15981 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15982 | address and file/line number respectively.\n\ |
15983 | \n\ | |
15984 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15985 | are set to the address of the last breakpoint listed unless the command\n\ |
15986 | is prefixed with \"server \".\n\n\ | |
c906108c | 15987 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15988 | breakpoint set.")); |
c906108c | 15989 | |
6b04bdb7 MS |
15990 | add_info_alias ("b", "breakpoints", 1); |
15991 | ||
1a966eab AC |
15992 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15993 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15994 | The \"Type\" column indicates one of:\n\ |
15995 | \tbreakpoint - normal breakpoint\n\ | |
15996 | \twatchpoint - watchpoint\n\ | |
15997 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15998 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15999 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16000 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16001 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16002 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16003 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16004 | address and file/line number respectively.\n\ |
16005 | \n\ | |
16006 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16007 | are set to the address of the last breakpoint listed unless the command\n\ |
16008 | is prefixed with \"server \".\n\n\ | |
c906108c | 16009 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16010 | breakpoint set."), |
c906108c SS |
16011 | &maintenanceinfolist); |
16012 | ||
44feb3ce TT |
16013 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16014 | Set catchpoints to catch events."), | |
16015 | &catch_cmdlist, "catch ", | |
16016 | 0/*allow-unknown*/, &cmdlist); | |
16017 | ||
16018 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16019 | Set temporary catchpoints to catch events."), | |
16020 | &tcatch_cmdlist, "tcatch ", | |
16021 | 0/*allow-unknown*/, &cmdlist); | |
16022 | ||
44feb3ce TT |
16023 | add_catch_command ("fork", _("Catch calls to fork."), |
16024 | catch_fork_command_1, | |
a96d9b2e | 16025 | NULL, |
44feb3ce TT |
16026 | (void *) (uintptr_t) catch_fork_permanent, |
16027 | (void *) (uintptr_t) catch_fork_temporary); | |
16028 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16029 | catch_fork_command_1, | |
a96d9b2e | 16030 | NULL, |
44feb3ce TT |
16031 | (void *) (uintptr_t) catch_vfork_permanent, |
16032 | (void *) (uintptr_t) catch_vfork_temporary); | |
16033 | add_catch_command ("exec", _("Catch calls to exec."), | |
16034 | catch_exec_command_1, | |
a96d9b2e SDJ |
16035 | NULL, |
16036 | CATCH_PERMANENT, | |
16037 | CATCH_TEMPORARY); | |
edcc5120 TT |
16038 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16039 | Usage: catch load [REGEX]\n\ | |
16040 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16041 | catch_load_command_1, | |
16042 | NULL, | |
16043 | CATCH_PERMANENT, | |
16044 | CATCH_TEMPORARY); | |
16045 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16046 | Usage: catch unload [REGEX]\n\ | |
16047 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16048 | catch_unload_command_1, | |
16049 | NULL, | |
16050 | CATCH_PERMANENT, | |
16051 | CATCH_TEMPORARY); | |
c5aa993b | 16052 | |
1bedd215 AC |
16053 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16054 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16055 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16056 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16057 | an expression changes.\n\ |
16058 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16059 | the memory to which it refers.")); | |
65d12d83 | 16060 | set_cmd_completer (c, expression_completer); |
c906108c | 16061 | |
1bedd215 AC |
16062 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16063 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16064 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16065 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16066 | an expression is read.\n\ |
16067 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16068 | the memory to which it refers.")); | |
65d12d83 | 16069 | set_cmd_completer (c, expression_completer); |
c906108c | 16070 | |
1bedd215 AC |
16071 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16072 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16073 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16074 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16075 | an expression is either read or written.\n\ |
16076 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16077 | the memory to which it refers.")); | |
65d12d83 | 16078 | set_cmd_completer (c, expression_completer); |
c906108c | 16079 | |
11db9430 | 16080 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 16081 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16082 | |
920d2a44 AC |
16083 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16084 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16085 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16086 | &can_use_hw_watchpoints, _("\ | |
16087 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16088 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16089 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16090 | such is available. (However, any hardware watchpoints that were\n\ | |
16091 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16092 | hardware.)"), |
16093 | NULL, | |
920d2a44 | 16094 | show_can_use_hw_watchpoints, |
85c07804 | 16095 | &setlist, &showlist); |
c906108c SS |
16096 | |
16097 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16098 | |
1042e4c0 SS |
16099 | /* Tracepoint manipulation commands. */ |
16100 | ||
16101 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16102 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16103 | \n" |
16104 | BREAK_ARGS_HELP ("trace") "\n\ | |
16105 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16106 | set_cmd_completer (c, location_completer); | |
16107 | ||
16108 | add_com_alias ("tp", "trace", class_alias, 0); | |
16109 | add_com_alias ("tr", "trace", class_alias, 1); | |
16110 | add_com_alias ("tra", "trace", class_alias, 1); | |
16111 | add_com_alias ("trac", "trace", class_alias, 1); | |
16112 | ||
7a697b8d | 16113 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16114 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16115 | \n" |
16116 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16117 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16118 | set_cmd_completer (c, location_completer); | |
16119 | ||
0fb4aa4b | 16120 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16121 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16122 | \n\ |
16123 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16124 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16125 | or -m MARKER_ID.\n\n\ | |
16126 | If a marker id is specified, probe the marker with that name. With\n\ | |
16127 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16128 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16129 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16130 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16131 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16132 | \n\ | |
16133 | CONDITION is a boolean expression.\n\ | |
629500fa | 16134 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16135 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16136 | conditions are different.\n\ | |
0fb4aa4b PA |
16137 | \n\ |
16138 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16139 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16140 | set_cmd_completer (c, location_completer); | |
16141 | ||
11db9430 | 16142 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 16143 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16144 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16145 | last tracepoint set.")); | |
16146 | ||
16147 | add_info_alias ("tp", "tracepoints", 1); | |
16148 | ||
16149 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16150 | Delete specified tracepoints.\n\ | |
16151 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16152 | No argument means delete all tracepoints."), | |
16153 | &deletelist); | |
7e20dfcd | 16154 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16155 | |
16156 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16157 | Disable specified tracepoints.\n\ | |
16158 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16159 | No argument means disable all tracepoints."), | |
16160 | &disablelist); | |
16161 | deprecate_cmd (c, "disable"); | |
16162 | ||
16163 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16164 | Enable specified tracepoints.\n\ | |
16165 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16166 | No argument means enable all tracepoints."), | |
16167 | &enablelist); | |
16168 | deprecate_cmd (c, "enable"); | |
16169 | ||
16170 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16171 | Set the passcount for a tracepoint.\n\ | |
16172 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16173 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16174 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16175 | ||
6149aea9 PA |
16176 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16177 | _("Save breakpoint definitions as a script."), | |
16178 | &save_cmdlist, "save ", | |
16179 | 0/*allow-unknown*/, &cmdlist); | |
16180 | ||
16181 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16182 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16183 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16184 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16185 | session to restore them."), | |
16186 | &save_cmdlist); | |
16187 | set_cmd_completer (c, filename_completer); | |
16188 | ||
16189 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16190 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16191 | Use the 'source' command in another debug session to restore them."), |
16192 | &save_cmdlist); | |
1042e4c0 SS |
16193 | set_cmd_completer (c, filename_completer); |
16194 | ||
6149aea9 PA |
16195 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16196 | deprecate_cmd (c, "save tracepoints"); | |
16197 | ||
1bedd215 | 16198 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16199 | Breakpoint specific settings\n\ |
16200 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16201 | pending breakpoint behavior"), |
fa8d40ab JJ |
16202 | &breakpoint_set_cmdlist, "set breakpoint ", |
16203 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16204 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16205 | Breakpoint specific settings\n\ |
16206 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16207 | pending breakpoint behavior"), |
fa8d40ab JJ |
16208 | &breakpoint_show_cmdlist, "show breakpoint ", |
16209 | 0/*allow-unknown*/, &showlist); | |
16210 | ||
7915a72c AC |
16211 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16212 | &pending_break_support, _("\ | |
16213 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16214 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16215 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16216 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16217 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16218 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16219 | NULL, |
920d2a44 | 16220 | show_pending_break_support, |
6e1d7d6c AC |
16221 | &breakpoint_set_cmdlist, |
16222 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16223 | |
16224 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16225 | |
16226 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16227 | &automatic_hardware_breakpoints, _("\ | |
16228 | Set automatic usage of hardware breakpoints."), _("\ | |
16229 | Show automatic usage of hardware breakpoints."), _("\ | |
16230 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16231 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16232 | a warning will be emitted for such breakpoints."), | |
16233 | NULL, | |
16234 | show_automatic_hardware_breakpoints, | |
16235 | &breakpoint_set_cmdlist, | |
16236 | &breakpoint_show_cmdlist); | |
74960c60 | 16237 | |
a25a5a45 PA |
16238 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16239 | &always_inserted_mode, _("\ | |
74960c60 VP |
16240 | Set mode for inserting breakpoints."), _("\ |
16241 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16242 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16243 | they're created, kept inserted even when execution stops, and removed\n\ | |
16244 | only when the user deletes them. When this mode is off (the default),\n\ | |
16245 | breakpoints are inserted only when execution continues, and removed\n\ | |
16246 | when execution stops."), | |
72d0e2c5 YQ |
16247 | NULL, |
16248 | &show_always_inserted_mode, | |
16249 | &breakpoint_set_cmdlist, | |
16250 | &breakpoint_show_cmdlist); | |
f1310107 | 16251 | |
b775012e LM |
16252 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16253 | condition_evaluation_enums, | |
16254 | &condition_evaluation_mode_1, _("\ | |
16255 | Set mode of breakpoint condition evaluation."), _("\ | |
16256 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16257 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16258 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16259 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16260 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16261 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16262 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16263 | be set to \"gdb\""), | |
16264 | &set_condition_evaluation_mode, | |
16265 | &show_condition_evaluation_mode, | |
16266 | &breakpoint_set_cmdlist, | |
16267 | &breakpoint_show_cmdlist); | |
16268 | ||
f1310107 TJB |
16269 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16270 | Set a breakpoint for an address range.\n\ | |
16271 | break-range START-LOCATION, END-LOCATION\n\ | |
16272 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16273 | LINENUM, for that line in the current file,\n\ | |
16274 | FILE:LINENUM, for that line in that file,\n\ | |
16275 | +OFFSET, for that number of lines after the current line\n\ | |
16276 | or the start of the range\n\ | |
16277 | FUNCTION, for the first line in that function,\n\ | |
16278 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16279 | *ADDRESS, for the instruction at that address.\n\ | |
16280 | \n\ | |
16281 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16282 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16283 | range (including START-LOCATION and END-LOCATION).")); | |
16284 | ||
e7e0cddf | 16285 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16286 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16287 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16288 | location may be a linespec, explicit, or address location.\n" |
16289 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16290 | set_cmd_completer (c, location_completer); |
16291 | ||
16292 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16293 | dprintf_style_enums, &dprintf_style, _("\ | |
16294 | Set the style of usage for dynamic printf."), _("\ | |
16295 | Show the style of usage for dynamic printf."), _("\ | |
16296 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16297 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16298 | console, as with the \"printf\" command.\n\ | |
16299 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16300 | program; by default printf(), but you can choose a different function or\n\ | |
16301 | output stream by setting dprintf-function and dprintf-channel."), | |
16302 | update_dprintf_commands, NULL, | |
16303 | &setlist, &showlist); | |
16304 | ||
16305 | dprintf_function = xstrdup ("printf"); | |
16306 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16307 | &dprintf_function, _("\ | |
16308 | Set the function to use for dynamic printf"), _("\ | |
16309 | Show the function to use for dynamic printf"), NULL, | |
16310 | update_dprintf_commands, NULL, | |
16311 | &setlist, &showlist); | |
16312 | ||
16313 | dprintf_channel = xstrdup (""); | |
16314 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16315 | &dprintf_channel, _("\ | |
16316 | Set the channel to use for dynamic printf"), _("\ | |
16317 | Show the channel to use for dynamic printf"), NULL, | |
16318 | update_dprintf_commands, NULL, | |
16319 | &setlist, &showlist); | |
16320 | ||
d3ce09f5 SS |
16321 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16322 | &disconnected_dprintf, _("\ | |
16323 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16324 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16325 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16326 | even if GDB disconnects or detaches from the target."), | |
16327 | NULL, | |
16328 | NULL, | |
16329 | &setlist, &showlist); | |
16330 | ||
16331 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16332 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16333 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16334 | ||
765dc015 | 16335 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16336 | |
16337 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16338 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16339 | } |