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 | struct command_line * |
363 | breakpoint_commands (struct breakpoint *b) | |
364 | { | |
d1b0a7bf | 365 | return b->commands ? b->commands.get () : NULL; |
5cea2a26 | 366 | } |
3daf8fe5 | 367 | |
f3b1572e PA |
368 | /* Flag indicating that a command has proceeded the inferior past the |
369 | current breakpoint. */ | |
370 | ||
371 | static int breakpoint_proceeded; | |
372 | ||
956a9fb9 | 373 | const char * |
2cec12e5 AR |
374 | bpdisp_text (enum bpdisp disp) |
375 | { | |
4a64f543 MS |
376 | /* NOTE: the following values are a part of MI protocol and |
377 | represent values of 'disp' field returned when inferior stops at | |
378 | a breakpoint. */ | |
bc043ef3 | 379 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 380 | |
2cec12e5 AR |
381 | return bpdisps[(int) disp]; |
382 | } | |
c906108c | 383 | |
4a64f543 | 384 | /* Prototypes for exported functions. */ |
c906108c | 385 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 386 | if such is available. */ |
c906108c SS |
387 | static int can_use_hw_watchpoints; |
388 | ||
920d2a44 AC |
389 | static void |
390 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
391 | struct cmd_list_element *c, | |
392 | const char *value) | |
393 | { | |
3e43a32a MS |
394 | fprintf_filtered (file, |
395 | _("Debugger's willingness to use " | |
396 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
397 | value); |
398 | } | |
399 | ||
fa8d40ab JJ |
400 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
401 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 402 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
403 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
404 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
405 | static void |
406 | show_pending_break_support (struct ui_file *file, int from_tty, | |
407 | struct cmd_list_element *c, | |
408 | const char *value) | |
409 | { | |
3e43a32a MS |
410 | fprintf_filtered (file, |
411 | _("Debugger's behavior regarding " | |
412 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
413 | value); |
414 | } | |
fa8d40ab | 415 | |
765dc015 | 416 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 417 | set with "break" but falling in read-only memory. |
765dc015 VP |
418 | If 0, gdb will warn about such breakpoints, but won't automatically |
419 | use hardware breakpoints. */ | |
420 | static int automatic_hardware_breakpoints; | |
421 | static void | |
422 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
423 | struct cmd_list_element *c, | |
424 | const char *value) | |
425 | { | |
3e43a32a MS |
426 | fprintf_filtered (file, |
427 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
428 | value); |
429 | } | |
430 | ||
a25a5a45 PA |
431 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
432 | stopped, and immediately inserts any new breakpoints as soon as | |
433 | they're created. If off (default), GDB keeps breakpoints off of | |
434 | the target as long as possible. That is, it delays inserting | |
435 | breakpoints until the next resume, and removes them again when the | |
436 | target fully stops. This is a bit safer in case GDB crashes while | |
437 | processing user input. */ | |
438 | static int always_inserted_mode = 0; | |
72d0e2c5 | 439 | |
33e5cbd6 | 440 | static void |
74960c60 | 441 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 442 | struct cmd_list_element *c, const char *value) |
74960c60 | 443 | { |
a25a5a45 PA |
444 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
445 | value); | |
74960c60 VP |
446 | } |
447 | ||
b57bacec PA |
448 | /* See breakpoint.h. */ |
449 | ||
33e5cbd6 | 450 | int |
a25a5a45 | 451 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 452 | { |
a25a5a45 PA |
453 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
454 | { | |
455 | /* If breakpoints are global, they should be inserted even if no | |
456 | thread under gdb's control is running, or even if there are | |
457 | no threads under GDB's control yet. */ | |
458 | return 1; | |
459 | } | |
460 | else if (target_has_execution) | |
461 | { | |
372316f1 PA |
462 | struct thread_info *tp; |
463 | ||
a25a5a45 PA |
464 | if (always_inserted_mode) |
465 | { | |
466 | /* The user wants breakpoints inserted even if all threads | |
467 | are stopped. */ | |
468 | return 1; | |
469 | } | |
470 | ||
b57bacec PA |
471 | if (threads_are_executing ()) |
472 | return 1; | |
372316f1 PA |
473 | |
474 | /* Don't remove breakpoints yet if, even though all threads are | |
475 | stopped, we still have events to process. */ | |
476 | ALL_NON_EXITED_THREADS (tp) | |
477 | if (tp->resumed | |
478 | && tp->suspend.waitstatus_pending_p) | |
479 | return 1; | |
a25a5a45 PA |
480 | } |
481 | return 0; | |
33e5cbd6 | 482 | } |
765dc015 | 483 | |
b775012e LM |
484 | static const char condition_evaluation_both[] = "host or target"; |
485 | ||
486 | /* Modes for breakpoint condition evaluation. */ | |
487 | static const char condition_evaluation_auto[] = "auto"; | |
488 | static const char condition_evaluation_host[] = "host"; | |
489 | static const char condition_evaluation_target[] = "target"; | |
490 | static const char *const condition_evaluation_enums[] = { | |
491 | condition_evaluation_auto, | |
492 | condition_evaluation_host, | |
493 | condition_evaluation_target, | |
494 | NULL | |
495 | }; | |
496 | ||
497 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
498 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
499 | ||
500 | /* Global that we use to display information to the user (gets its value from | |
501 | condition_evaluation_mode_1. */ | |
502 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
503 | ||
504 | /* Translate a condition evaluation mode MODE into either "host" | |
505 | or "target". This is used mostly to translate from "auto" to the | |
506 | real setting that is being used. It returns the translated | |
507 | evaluation mode. */ | |
508 | ||
509 | static const char * | |
510 | translate_condition_evaluation_mode (const char *mode) | |
511 | { | |
512 | if (mode == condition_evaluation_auto) | |
513 | { | |
514 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
515 | return condition_evaluation_target; | |
516 | else | |
517 | return condition_evaluation_host; | |
518 | } | |
519 | else | |
520 | return mode; | |
521 | } | |
522 | ||
523 | /* Discovers what condition_evaluation_auto translates to. */ | |
524 | ||
525 | static const char * | |
526 | breakpoint_condition_evaluation_mode (void) | |
527 | { | |
528 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
529 | } | |
530 | ||
531 | /* Return true if GDB should evaluate breakpoint conditions or false | |
532 | otherwise. */ | |
533 | ||
534 | static int | |
535 | gdb_evaluates_breakpoint_condition_p (void) | |
536 | { | |
537 | const char *mode = breakpoint_condition_evaluation_mode (); | |
538 | ||
539 | return (mode == condition_evaluation_host); | |
540 | } | |
541 | ||
c906108c SS |
542 | /* Are we executing breakpoint commands? */ |
543 | static int executing_breakpoint_commands; | |
544 | ||
c02f5703 MS |
545 | /* Are overlay event breakpoints enabled? */ |
546 | static int overlay_events_enabled; | |
547 | ||
e09342b5 TJB |
548 | /* See description in breakpoint.h. */ |
549 | int target_exact_watchpoints = 0; | |
550 | ||
c906108c | 551 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 552 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 553 | current breakpoint. */ |
c906108c | 554 | |
5c44784c | 555 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 556 | |
5c44784c JM |
557 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
558 | for (B = breakpoint_chain; \ | |
559 | B ? (TMP=B->next, 1): 0; \ | |
560 | B = TMP) | |
c906108c | 561 | |
4a64f543 MS |
562 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
563 | not provided so update_global_location_list must not be called | |
564 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 565 | |
876fa593 | 566 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
567 | for (BP_TMP = bp_locations; \ |
568 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 569 | BP_TMP++) |
7cc221ef | 570 | |
b775012e LM |
571 | /* Iterates through locations with address ADDRESS for the currently selected |
572 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
573 | to where the loop should start from. | |
574 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
575 | appropriate location to start with. */ | |
576 | ||
577 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
578 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
579 | BP_LOCP_TMP = BP_LOCP_START; \ | |
580 | BP_LOCP_START \ | |
f5336ca5 | 581 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
582 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
583 | BP_LOCP_TMP++) | |
584 | ||
1042e4c0 SS |
585 | /* Iterator for tracepoints only. */ |
586 | ||
587 | #define ALL_TRACEPOINTS(B) \ | |
588 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 589 | if (is_tracepoint (B)) |
1042e4c0 | 590 | |
7cc221ef | 591 | /* Chains of all breakpoints defined. */ |
c906108c SS |
592 | |
593 | struct breakpoint *breakpoint_chain; | |
594 | ||
f5336ca5 | 595 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 596 | |
f5336ca5 | 597 | static struct bp_location **bp_locations; |
876fa593 | 598 | |
f5336ca5 | 599 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 600 | |
f5336ca5 | 601 | static unsigned bp_locations_count; |
876fa593 | 602 | |
4a64f543 | 603 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 604 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 605 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 606 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 607 | an address you need to read. */ |
876fa593 | 608 | |
f5336ca5 | 609 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 610 | |
4a64f543 MS |
611 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
612 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
613 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
614 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 615 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 616 | |
f5336ca5 | 617 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 618 | |
4a64f543 | 619 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
620 | from the bp_locations array, but for which a hit may still be |
621 | reported by a target. */ | |
20874c92 VP |
622 | VEC(bp_location_p) *moribund_locations = NULL; |
623 | ||
c906108c SS |
624 | /* Number of last breakpoint made. */ |
625 | ||
95a42b64 TT |
626 | static int breakpoint_count; |
627 | ||
86b17b60 PA |
628 | /* The value of `breakpoint_count' before the last command that |
629 | created breakpoints. If the last (break-like) command created more | |
630 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
631 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
632 | static int prev_breakpoint_count; | |
c906108c | 633 | |
1042e4c0 SS |
634 | /* Number of last tracepoint made. */ |
635 | ||
95a42b64 | 636 | static int tracepoint_count; |
1042e4c0 | 637 | |
6149aea9 PA |
638 | static struct cmd_list_element *breakpoint_set_cmdlist; |
639 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 640 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 641 | |
badd37ce SDJ |
642 | /* See declaration at breakpoint.h. */ |
643 | ||
644 | struct breakpoint * | |
645 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
646 | void *user_data) | |
647 | { | |
648 | struct breakpoint *b = NULL; | |
649 | ||
650 | ALL_BREAKPOINTS (b) | |
651 | { | |
652 | if (func (b, user_data) != 0) | |
653 | break; | |
654 | } | |
655 | ||
656 | return b; | |
657 | } | |
658 | ||
468d015d JJ |
659 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
660 | static int | |
661 | breakpoint_enabled (struct breakpoint *b) | |
662 | { | |
0d381245 | 663 | return (b->enable_state == bp_enabled); |
468d015d JJ |
664 | } |
665 | ||
c906108c SS |
666 | /* Set breakpoint count to NUM. */ |
667 | ||
95a42b64 | 668 | static void |
fba45db2 | 669 | set_breakpoint_count (int num) |
c906108c | 670 | { |
86b17b60 | 671 | prev_breakpoint_count = breakpoint_count; |
c906108c | 672 | breakpoint_count = num; |
4fa62494 | 673 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
674 | } |
675 | ||
86b17b60 PA |
676 | /* Used by `start_rbreak_breakpoints' below, to record the current |
677 | breakpoint count before "rbreak" creates any breakpoint. */ | |
678 | static int rbreak_start_breakpoint_count; | |
679 | ||
95a42b64 TT |
680 | /* Called at the start an "rbreak" command to record the first |
681 | breakpoint made. */ | |
86b17b60 | 682 | |
95a42b64 TT |
683 | void |
684 | start_rbreak_breakpoints (void) | |
685 | { | |
86b17b60 | 686 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
687 | } |
688 | ||
689 | /* Called at the end of an "rbreak" command to record the last | |
690 | breakpoint made. */ | |
86b17b60 | 691 | |
95a42b64 TT |
692 | void |
693 | end_rbreak_breakpoints (void) | |
694 | { | |
86b17b60 | 695 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
696 | } |
697 | ||
4a64f543 | 698 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
699 | |
700 | void | |
fba45db2 | 701 | clear_breakpoint_hit_counts (void) |
c906108c SS |
702 | { |
703 | struct breakpoint *b; | |
704 | ||
705 | ALL_BREAKPOINTS (b) | |
706 | b->hit_count = 0; | |
707 | } | |
708 | ||
c906108c | 709 | \f |
48cb2d85 VP |
710 | /* Return the breakpoint with the specified number, or NULL |
711 | if the number does not refer to an existing breakpoint. */ | |
712 | ||
713 | struct breakpoint * | |
714 | get_breakpoint (int num) | |
715 | { | |
716 | struct breakpoint *b; | |
717 | ||
718 | ALL_BREAKPOINTS (b) | |
719 | if (b->number == num) | |
720 | return b; | |
721 | ||
722 | return NULL; | |
723 | } | |
5c44784c | 724 | |
c906108c | 725 | \f |
adc36818 | 726 | |
b775012e LM |
727 | /* Mark locations as "conditions have changed" in case the target supports |
728 | evaluating conditions on its side. */ | |
729 | ||
730 | static void | |
731 | mark_breakpoint_modified (struct breakpoint *b) | |
732 | { | |
733 | struct bp_location *loc; | |
734 | ||
735 | /* This is only meaningful if the target is | |
736 | evaluating conditions and if the user has | |
737 | opted for condition evaluation on the target's | |
738 | side. */ | |
739 | if (gdb_evaluates_breakpoint_condition_p () | |
740 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
741 | return; | |
742 | ||
743 | if (!is_breakpoint (b)) | |
744 | return; | |
745 | ||
746 | for (loc = b->loc; loc; loc = loc->next) | |
747 | loc->condition_changed = condition_modified; | |
748 | } | |
749 | ||
750 | /* Mark location as "conditions have changed" in case the target supports | |
751 | evaluating conditions on its side. */ | |
752 | ||
753 | static void | |
754 | mark_breakpoint_location_modified (struct bp_location *loc) | |
755 | { | |
756 | /* This is only meaningful if the target is | |
757 | evaluating conditions and if the user has | |
758 | opted for condition evaluation on the target's | |
759 | side. */ | |
760 | if (gdb_evaluates_breakpoint_condition_p () | |
761 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
762 | ||
763 | return; | |
764 | ||
765 | if (!is_breakpoint (loc->owner)) | |
766 | return; | |
767 | ||
768 | loc->condition_changed = condition_modified; | |
769 | } | |
770 | ||
771 | /* Sets the condition-evaluation mode using the static global | |
772 | condition_evaluation_mode. */ | |
773 | ||
774 | static void | |
775 | set_condition_evaluation_mode (char *args, int from_tty, | |
776 | struct cmd_list_element *c) | |
777 | { | |
b775012e LM |
778 | const char *old_mode, *new_mode; |
779 | ||
780 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
781 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
782 | { | |
783 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
784 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
785 | "Using host evaluation mode instead.")); | |
786 | return; | |
787 | } | |
788 | ||
789 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
790 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
791 | ||
abf1152a JK |
792 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
793 | settings was "auto". */ | |
794 | condition_evaluation_mode = condition_evaluation_mode_1; | |
795 | ||
b775012e LM |
796 | /* Only update the mode if the user picked a different one. */ |
797 | if (new_mode != old_mode) | |
798 | { | |
799 | struct bp_location *loc, **loc_tmp; | |
800 | /* If the user switched to a different evaluation mode, we | |
801 | need to synch the changes with the target as follows: | |
802 | ||
803 | "host" -> "target": Send all (valid) conditions to the target. | |
804 | "target" -> "host": Remove all the conditions from the target. | |
805 | */ | |
806 | ||
b775012e LM |
807 | if (new_mode == condition_evaluation_target) |
808 | { | |
809 | /* Mark everything modified and synch conditions with the | |
810 | target. */ | |
811 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
812 | mark_breakpoint_location_modified (loc); | |
813 | } | |
814 | else | |
815 | { | |
816 | /* Manually mark non-duplicate locations to synch conditions | |
817 | with the target. We do this to remove all the conditions the | |
818 | target knows about. */ | |
819 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
820 | if (is_breakpoint (loc->owner) && loc->inserted) | |
821 | loc->needs_update = 1; | |
822 | } | |
823 | ||
824 | /* Do the update. */ | |
44702360 | 825 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
826 | } |
827 | ||
828 | return; | |
829 | } | |
830 | ||
831 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
832 | what "auto" is translating to. */ | |
833 | ||
834 | static void | |
835 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
836 | struct cmd_list_element *c, const char *value) | |
837 | { | |
838 | if (condition_evaluation_mode == condition_evaluation_auto) | |
839 | fprintf_filtered (file, | |
840 | _("Breakpoint condition evaluation " | |
841 | "mode is %s (currently %s).\n"), | |
842 | value, | |
843 | breakpoint_condition_evaluation_mode ()); | |
844 | else | |
845 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
846 | value); | |
847 | } | |
848 | ||
849 | /* A comparison function for bp_location AP and BP that is used by | |
850 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 851 | the more general bp_locations_compare function. */ |
b775012e LM |
852 | |
853 | static int | |
f5336ca5 | 854 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 855 | { |
9a3c8263 SM |
856 | const struct bp_location *a = *(const struct bp_location **) ap; |
857 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
858 | |
859 | if (a->address == b->address) | |
860 | return 0; | |
861 | else | |
862 | return ((a->address > b->address) - (a->address < b->address)); | |
863 | } | |
864 | ||
865 | /* Helper function to skip all bp_locations with addresses | |
866 | less than ADDRESS. It returns the first bp_location that | |
867 | is greater than or equal to ADDRESS. If none is found, just | |
868 | return NULL. */ | |
869 | ||
870 | static struct bp_location ** | |
871 | get_first_locp_gte_addr (CORE_ADDR address) | |
872 | { | |
873 | struct bp_location dummy_loc; | |
874 | struct bp_location *dummy_locp = &dummy_loc; | |
875 | struct bp_location **locp_found = NULL; | |
876 | ||
877 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
878 | dummy_loc.address = address; |
879 | ||
880 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 881 | locp_found = ((struct bp_location **) |
f5336ca5 | 882 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 883 | sizeof (struct bp_location **), |
f5336ca5 | 884 | bp_locations_compare_addrs)); |
b775012e LM |
885 | |
886 | /* Nothing was found, nothing left to do. */ | |
887 | if (locp_found == NULL) | |
888 | return NULL; | |
889 | ||
890 | /* We may have found a location that is at ADDRESS but is not the first in the | |
891 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 892 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
893 | && (*(locp_found - 1))->address == address) |
894 | locp_found--; | |
895 | ||
896 | return locp_found; | |
897 | } | |
898 | ||
adc36818 | 899 | void |
7a26bd4d | 900 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
901 | int from_tty) |
902 | { | |
3a5c3e22 PA |
903 | xfree (b->cond_string); |
904 | b->cond_string = NULL; | |
adc36818 | 905 | |
3a5c3e22 | 906 | if (is_watchpoint (b)) |
adc36818 | 907 | { |
3a5c3e22 PA |
908 | struct watchpoint *w = (struct watchpoint *) b; |
909 | ||
4d01a485 | 910 | w->cond_exp.reset (); |
3a5c3e22 PA |
911 | } |
912 | else | |
913 | { | |
914 | struct bp_location *loc; | |
915 | ||
916 | for (loc = b->loc; loc; loc = loc->next) | |
917 | { | |
4d01a485 | 918 | loc->cond.reset (); |
b775012e LM |
919 | |
920 | /* No need to free the condition agent expression | |
921 | bytecode (if we have one). We will handle this | |
922 | when we go through update_global_location_list. */ | |
3a5c3e22 | 923 | } |
adc36818 | 924 | } |
adc36818 PM |
925 | |
926 | if (*exp == 0) | |
927 | { | |
928 | if (from_tty) | |
929 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
930 | } | |
931 | else | |
932 | { | |
bbc13ae3 | 933 | const char *arg = exp; |
cc59ec59 | 934 | |
adc36818 PM |
935 | /* I don't know if it matters whether this is the string the user |
936 | typed in or the decompiled expression. */ | |
937 | b->cond_string = xstrdup (arg); | |
938 | b->condition_not_parsed = 0; | |
939 | ||
940 | if (is_watchpoint (b)) | |
941 | { | |
3a5c3e22 PA |
942 | struct watchpoint *w = (struct watchpoint *) b; |
943 | ||
adc36818 PM |
944 | innermost_block = NULL; |
945 | arg = exp; | |
1bb9788d | 946 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
947 | if (*arg) |
948 | error (_("Junk at end of expression")); | |
3a5c3e22 | 949 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
950 | } |
951 | else | |
952 | { | |
3a5c3e22 PA |
953 | struct bp_location *loc; |
954 | ||
adc36818 PM |
955 | for (loc = b->loc; loc; loc = loc->next) |
956 | { | |
957 | arg = exp; | |
958 | loc->cond = | |
1bb9788d TT |
959 | parse_exp_1 (&arg, loc->address, |
960 | block_for_pc (loc->address), 0); | |
adc36818 PM |
961 | if (*arg) |
962 | error (_("Junk at end of expression")); | |
963 | } | |
964 | } | |
965 | } | |
b775012e LM |
966 | mark_breakpoint_modified (b); |
967 | ||
8d3788bd | 968 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
969 | } |
970 | ||
d55637df TT |
971 | /* Completion for the "condition" command. */ |
972 | ||
eb3ff9a5 | 973 | static void |
6f937416 | 974 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 975 | completion_tracker &tracker, |
6f937416 | 976 | const char *text, const char *word) |
d55637df | 977 | { |
6f937416 | 978 | const char *space; |
d55637df | 979 | |
f1735a53 TT |
980 | text = skip_spaces (text); |
981 | space = skip_to_space (text); | |
d55637df TT |
982 | if (*space == '\0') |
983 | { | |
984 | int len; | |
985 | struct breakpoint *b; | |
986 | VEC (char_ptr) *result = NULL; | |
987 | ||
988 | if (text[0] == '$') | |
989 | { | |
990 | /* We don't support completion of history indices. */ | |
eb3ff9a5 PA |
991 | if (!isdigit (text[1])) |
992 | complete_internalvar (tracker, &text[1]); | |
993 | return; | |
d55637df TT |
994 | } |
995 | ||
996 | /* We're completing the breakpoint number. */ | |
997 | len = strlen (text); | |
998 | ||
999 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1000 | { |
1001 | char number[50]; | |
1002 | ||
1003 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1004 | ||
1005 | if (strncmp (number, text, len) == 0) | |
eb3ff9a5 PA |
1006 | { |
1007 | gdb::unique_xmalloc_ptr<char> copy (xstrdup (number)); | |
1008 | tracker.add_completion (std::move (copy)); | |
1009 | } | |
58ce7251 | 1010 | } |
d55637df | 1011 | |
eb3ff9a5 | 1012 | return; |
d55637df TT |
1013 | } |
1014 | ||
1015 | /* We're completing the expression part. */ | |
f1735a53 | 1016 | text = skip_spaces (space); |
eb3ff9a5 | 1017 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
1018 | } |
1019 | ||
c906108c SS |
1020 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1021 | ||
1022 | static void | |
fba45db2 | 1023 | condition_command (char *arg, int from_tty) |
c906108c | 1024 | { |
52f0bd74 | 1025 | struct breakpoint *b; |
c906108c | 1026 | char *p; |
52f0bd74 | 1027 | int bnum; |
c906108c SS |
1028 | |
1029 | if (arg == 0) | |
e2e0b3e5 | 1030 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1031 | |
1032 | p = arg; | |
1033 | bnum = get_number (&p); | |
5c44784c | 1034 | if (bnum == 0) |
8a3fe4f8 | 1035 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1036 | |
1037 | ALL_BREAKPOINTS (b) | |
1038 | if (b->number == bnum) | |
2f069f6f | 1039 | { |
6dddc817 DE |
1040 | /* Check if this breakpoint has a "stop" method implemented in an |
1041 | extension language. This method and conditions entered into GDB | |
1042 | from the CLI are mutually exclusive. */ | |
1043 | const struct extension_language_defn *extlang | |
1044 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1045 | ||
1046 | if (extlang != NULL) | |
1047 | { | |
1048 | error (_("Only one stop condition allowed. There is currently" | |
1049 | " a %s stop condition defined for this breakpoint."), | |
1050 | ext_lang_capitalized_name (extlang)); | |
1051 | } | |
2566ad2d | 1052 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1053 | |
1054 | if (is_breakpoint (b)) | |
44702360 | 1055 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1056 | |
2f069f6f JB |
1057 | return; |
1058 | } | |
c906108c | 1059 | |
8a3fe4f8 | 1060 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1061 | } |
1062 | ||
a7bdde9e VP |
1063 | /* Check that COMMAND do not contain commands that are suitable |
1064 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1065 | Throw if any such commands is found. */ |
1066 | ||
a7bdde9e VP |
1067 | static void |
1068 | check_no_tracepoint_commands (struct command_line *commands) | |
1069 | { | |
1070 | struct command_line *c; | |
cc59ec59 | 1071 | |
a7bdde9e VP |
1072 | for (c = commands; c; c = c->next) |
1073 | { | |
1074 | int i; | |
1075 | ||
1076 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1077 | error (_("The 'while-stepping' command can " |
1078 | "only be used for tracepoints")); | |
a7bdde9e VP |
1079 | |
1080 | for (i = 0; i < c->body_count; ++i) | |
1081 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1082 | ||
1083 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1084 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1085 | command directly. */ |
1086 | if (strstr (c->line, "collect ") == c->line) | |
1087 | error (_("The 'collect' command can only be used for tracepoints")); | |
1088 | ||
51661e93 VP |
1089 | if (strstr (c->line, "teval ") == c->line) |
1090 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1091 | } |
1092 | } | |
1093 | ||
c1fc2657 | 1094 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1095 | { |
c1fc2657 | 1096 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1097 | }; |
1098 | ||
d77f58be SS |
1099 | /* Encapsulate tests for different types of tracepoints. */ |
1100 | ||
3b0871f4 SM |
1101 | static bool |
1102 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1103 | { |
1104 | return (type == bp_tracepoint | |
1105 | || type == bp_fast_tracepoint | |
1106 | || type == bp_static_tracepoint); | |
1107 | } | |
1108 | ||
3b0871f4 SM |
1109 | static bool |
1110 | is_longjmp_type (bptype type) | |
1111 | { | |
1112 | return type == bp_longjmp || type == bp_exception; | |
1113 | } | |
1114 | ||
a7bdde9e | 1115 | int |
d77f58be | 1116 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1117 | { |
d9b3f62e | 1118 | return is_tracepoint_type (b->type); |
a7bdde9e | 1119 | } |
d9b3f62e | 1120 | |
a5e364af SM |
1121 | /* Factory function to create an appropriate instance of breakpoint given |
1122 | TYPE. */ | |
1123 | ||
1124 | static std::unique_ptr<breakpoint> | |
1125 | new_breakpoint_from_type (bptype type) | |
1126 | { | |
1127 | breakpoint *b; | |
1128 | ||
1129 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1130 | b = new tracepoint (); |
3b0871f4 | 1131 | else if (is_longjmp_type (type)) |
c1fc2657 | 1132 | b = new longjmp_breakpoint (); |
a5e364af SM |
1133 | else |
1134 | b = new breakpoint (); | |
1135 | ||
1136 | return std::unique_ptr<breakpoint> (b); | |
1137 | } | |
1138 | ||
e5dd4106 | 1139 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1140 | breakpoint. This function will throw an exception if a problem is |
1141 | found. */ | |
48cb2d85 | 1142 | |
95a42b64 TT |
1143 | static void |
1144 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1145 | struct command_line *commands) | |
48cb2d85 | 1146 | { |
d77f58be | 1147 | if (is_tracepoint (b)) |
a7bdde9e | 1148 | { |
c9a6ce02 | 1149 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1150 | struct command_line *c; |
1151 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1152 | |
1153 | /* Reset the while-stepping step count. The previous commands | |
1154 | might have included a while-stepping action, while the new | |
1155 | ones might not. */ | |
1156 | t->step_count = 0; | |
1157 | ||
1158 | /* We need to verify that each top-level element of commands is | |
1159 | valid for tracepoints, that there's at most one | |
1160 | while-stepping element, and that the while-stepping's body | |
1161 | has valid tracing commands excluding nested while-stepping. | |
1162 | We also need to validate the tracepoint action line in the | |
1163 | context of the tracepoint --- validate_actionline actually | |
1164 | has side effects, like setting the tracepoint's | |
1165 | while-stepping STEP_COUNT, in addition to checking if the | |
1166 | collect/teval actions parse and make sense in the | |
1167 | tracepoint's context. */ | |
a7bdde9e VP |
1168 | for (c = commands; c; c = c->next) |
1169 | { | |
a7bdde9e VP |
1170 | if (c->control_type == while_stepping_control) |
1171 | { | |
1172 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1173 | error (_("The 'while-stepping' command " |
1174 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1175 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1176 | error (_("The 'while-stepping' command " |
1177 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1178 | |
1179 | if (while_stepping) | |
3e43a32a MS |
1180 | error (_("The 'while-stepping' command " |
1181 | "can be used only once")); | |
a7bdde9e VP |
1182 | else |
1183 | while_stepping = c; | |
1184 | } | |
c9a6ce02 PA |
1185 | |
1186 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1187 | } |
1188 | if (while_stepping) | |
1189 | { | |
1190 | struct command_line *c2; | |
1191 | ||
1192 | gdb_assert (while_stepping->body_count == 1); | |
1193 | c2 = while_stepping->body_list[0]; | |
1194 | for (; c2; c2 = c2->next) | |
1195 | { | |
a7bdde9e VP |
1196 | if (c2->control_type == while_stepping_control) |
1197 | error (_("The 'while-stepping' command cannot be nested")); | |
1198 | } | |
1199 | } | |
1200 | } | |
1201 | else | |
1202 | { | |
1203 | check_no_tracepoint_commands (commands); | |
1204 | } | |
95a42b64 TT |
1205 | } |
1206 | ||
0fb4aa4b PA |
1207 | /* Return a vector of all the static tracepoints set at ADDR. The |
1208 | caller is responsible for releasing the vector. */ | |
1209 | ||
1210 | VEC(breakpoint_p) * | |
1211 | static_tracepoints_here (CORE_ADDR addr) | |
1212 | { | |
1213 | struct breakpoint *b; | |
1214 | VEC(breakpoint_p) *found = 0; | |
1215 | struct bp_location *loc; | |
1216 | ||
1217 | ALL_BREAKPOINTS (b) | |
1218 | if (b->type == bp_static_tracepoint) | |
1219 | { | |
1220 | for (loc = b->loc; loc; loc = loc->next) | |
1221 | if (loc->address == addr) | |
1222 | VEC_safe_push(breakpoint_p, found, b); | |
1223 | } | |
1224 | ||
1225 | return found; | |
1226 | } | |
1227 | ||
95a42b64 | 1228 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1229 | validate that only allowed commands are included. */ |
95a42b64 TT |
1230 | |
1231 | void | |
4a64f543 | 1232 | breakpoint_set_commands (struct breakpoint *b, |
93921405 | 1233 | command_line_up &&commands) |
95a42b64 | 1234 | { |
93921405 | 1235 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1236 | |
d1b0a7bf | 1237 | b->commands = std::move (commands); |
8d3788bd | 1238 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1239 | } |
1240 | ||
45a43567 TT |
1241 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1242 | is not the same as the "silent" that may appear in the breakpoint's | |
1243 | commands. */ | |
1244 | ||
1245 | void | |
1246 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1247 | { | |
1248 | int old_silent = b->silent; | |
1249 | ||
1250 | b->silent = silent; | |
1251 | if (old_silent != silent) | |
8d3788bd | 1252 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1253 | } |
1254 | ||
1255 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1256 | breakpoint work for any thread. */ | |
1257 | ||
1258 | void | |
1259 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1260 | { | |
1261 | int old_thread = b->thread; | |
1262 | ||
1263 | b->thread = thread; | |
1264 | if (old_thread != thread) | |
8d3788bd | 1265 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1266 | } |
1267 | ||
1268 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1269 | breakpoint work for any task. */ | |
1270 | ||
1271 | void | |
1272 | breakpoint_set_task (struct breakpoint *b, int task) | |
1273 | { | |
1274 | int old_task = b->task; | |
1275 | ||
1276 | b->task = task; | |
1277 | if (old_task != task) | |
8d3788bd | 1278 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1279 | } |
1280 | ||
95a42b64 TT |
1281 | void |
1282 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1283 | { |
9a3c8263 | 1284 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1285 | |
6f937416 | 1286 | validate_actionline (line, b); |
a7bdde9e VP |
1287 | } |
1288 | ||
95a42b64 | 1289 | static void |
896b6bda | 1290 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1291 | struct command_line *control) |
95a42b64 | 1292 | { |
d1b0a7bf | 1293 | counted_command_line cmd; |
95a42b64 | 1294 | |
896b6bda PA |
1295 | std::string new_arg; |
1296 | ||
95a42b64 TT |
1297 | if (arg == NULL || !*arg) |
1298 | { | |
86b17b60 | 1299 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1300 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1301 | breakpoint_count); | |
95a42b64 | 1302 | else if (breakpoint_count > 0) |
896b6bda | 1303 | new_arg = string_printf ("%d", breakpoint_count); |
48649e1b TT |
1304 | arg = new_arg.c_str (); |
1305 | } | |
1306 | ||
1307 | map_breakpoint_numbers | |
1308 | (arg, [&] (breakpoint *b) | |
1309 | { | |
1310 | if (cmd == NULL) | |
1311 | { | |
48649e1b | 1312 | if (control != NULL) |
d1b0a7bf | 1313 | cmd = copy_command_lines (control->body_list[0]); |
48649e1b TT |
1314 | else |
1315 | { | |
1316 | struct cleanup *old_chain; | |
1317 | char *str; | |
1318 | ||
1319 | str = xstrprintf (_("Type commands for breakpoint(s) " | |
1320 | "%s, one per line."), | |
1321 | arg); | |
1322 | ||
1323 | old_chain = make_cleanup (xfree, str); | |
1324 | ||
d1b0a7bf TT |
1325 | cmd = read_command_lines (str, |
1326 | from_tty, 1, | |
1327 | (is_tracepoint (b) | |
1328 | ? check_tracepoint_command : 0), | |
1329 | b); | |
48649e1b TT |
1330 | |
1331 | do_cleanups (old_chain); | |
1332 | } | |
48649e1b TT |
1333 | } |
1334 | ||
1335 | /* If a breakpoint was on the list more than once, we don't need to | |
1336 | do anything. */ | |
1337 | if (b->commands != cmd) | |
1338 | { | |
d1b0a7bf | 1339 | validate_commands_for_breakpoint (b, cmd.get ()); |
48649e1b TT |
1340 | b->commands = cmd; |
1341 | observer_notify_breakpoint_modified (b); | |
1342 | } | |
1343 | }); | |
95a42b64 | 1344 | |
48649e1b | 1345 | if (cmd == NULL) |
95a42b64 | 1346 | error (_("No breakpoints specified.")); |
95a42b64 TT |
1347 | } |
1348 | ||
1349 | static void | |
1350 | commands_command (char *arg, int from_tty) | |
1351 | { | |
1352 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1353 | } |
40c03ae8 EZ |
1354 | |
1355 | /* Like commands_command, but instead of reading the commands from | |
1356 | input stream, takes them from an already parsed command structure. | |
1357 | ||
1358 | This is used by cli-script.c to DTRT with breakpoint commands | |
1359 | that are part of if and while bodies. */ | |
1360 | enum command_control_type | |
896b6bda | 1361 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1362 | { |
95a42b64 TT |
1363 | commands_command_1 (arg, 0, cmd); |
1364 | return simple_control; | |
40c03ae8 | 1365 | } |
876fa593 JK |
1366 | |
1367 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1368 | ||
1369 | static int | |
1370 | bp_location_has_shadow (struct bp_location *bl) | |
1371 | { | |
1372 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1373 | return 0; | |
1374 | if (!bl->inserted) | |
1375 | return 0; | |
1376 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1377 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1378 | return 0; |
1379 | return 1; | |
1380 | } | |
1381 | ||
9d497a19 PA |
1382 | /* Update BUF, which is LEN bytes read from the target address |
1383 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1384 | contents. | |
1385 | ||
1386 | If READBUF is not NULL, this buffer must not overlap with the of | |
1387 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1388 | failed assertion internal error will be raised. */ | |
1389 | ||
1390 | static void | |
1391 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1392 | const gdb_byte *writebuf_org, | |
1393 | ULONGEST memaddr, LONGEST len, | |
1394 | struct bp_target_info *target_info, | |
1395 | struct gdbarch *gdbarch) | |
1396 | { | |
1397 | /* Now do full processing of the found relevant range of elements. */ | |
1398 | CORE_ADDR bp_addr = 0; | |
1399 | int bp_size = 0; | |
1400 | int bptoffset = 0; | |
1401 | ||
1402 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1403 | current_program_space->aspace, 0)) | |
1404 | { | |
1405 | /* The breakpoint is inserted in a different address space. */ | |
1406 | return; | |
1407 | } | |
1408 | ||
1409 | /* Addresses and length of the part of the breakpoint that | |
1410 | we need to copy. */ | |
1411 | bp_addr = target_info->placed_address; | |
1412 | bp_size = target_info->shadow_len; | |
1413 | ||
1414 | if (bp_addr + bp_size <= memaddr) | |
1415 | { | |
1416 | /* The breakpoint is entirely before the chunk of memory we are | |
1417 | reading. */ | |
1418 | return; | |
1419 | } | |
1420 | ||
1421 | if (bp_addr >= memaddr + len) | |
1422 | { | |
1423 | /* The breakpoint is entirely after the chunk of memory we are | |
1424 | reading. */ | |
1425 | return; | |
1426 | } | |
1427 | ||
1428 | /* Offset within shadow_contents. */ | |
1429 | if (bp_addr < memaddr) | |
1430 | { | |
1431 | /* Only copy the second part of the breakpoint. */ | |
1432 | bp_size -= memaddr - bp_addr; | |
1433 | bptoffset = memaddr - bp_addr; | |
1434 | bp_addr = memaddr; | |
1435 | } | |
1436 | ||
1437 | if (bp_addr + bp_size > memaddr + len) | |
1438 | { | |
1439 | /* Only copy the first part of the breakpoint. */ | |
1440 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1441 | } | |
1442 | ||
1443 | if (readbuf != NULL) | |
1444 | { | |
1445 | /* Verify that the readbuf buffer does not overlap with the | |
1446 | shadow_contents buffer. */ | |
1447 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1448 | || readbuf >= (target_info->shadow_contents | |
1449 | + target_info->shadow_len)); | |
1450 | ||
1451 | /* Update the read buffer with this inserted breakpoint's | |
1452 | shadow. */ | |
1453 | memcpy (readbuf + bp_addr - memaddr, | |
1454 | target_info->shadow_contents + bptoffset, bp_size); | |
1455 | } | |
1456 | else | |
1457 | { | |
1458 | const unsigned char *bp; | |
0d5ed153 MR |
1459 | CORE_ADDR addr = target_info->reqstd_address; |
1460 | int placed_size; | |
9d497a19 PA |
1461 | |
1462 | /* Update the shadow with what we want to write to memory. */ | |
1463 | memcpy (target_info->shadow_contents + bptoffset, | |
1464 | writebuf_org + bp_addr - memaddr, bp_size); | |
1465 | ||
1466 | /* Determine appropriate breakpoint contents and size for this | |
1467 | address. */ | |
0d5ed153 | 1468 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1469 | |
1470 | /* Update the final write buffer with this inserted | |
1471 | breakpoint's INSN. */ | |
1472 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1473 | } | |
1474 | } | |
1475 | ||
8defab1a | 1476 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1477 | by replacing any memory breakpoints with their shadowed contents. |
1478 | ||
35c63cd8 JB |
1479 | If READBUF is not NULL, this buffer must not overlap with any of |
1480 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1481 | a failed assertion internal error will be raised. | |
1482 | ||
876fa593 | 1483 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1484 | bl->address - bp_locations_placed_address_before_address_max |
1485 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1486 | The range we were requested to resolve shadows for is: |
1487 | memaddr ... memaddr + len | |
1488 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1489 | memaddr + len <= (bl->address |
f5336ca5 | 1490 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1491 | and: |
f5336ca5 | 1492 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1493 | |
8defab1a | 1494 | void |
f0ba3972 PA |
1495 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1496 | const gdb_byte *writebuf_org, | |
1497 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1498 | { |
4a64f543 MS |
1499 | /* Left boundary, right boundary and median element of our binary |
1500 | search. */ | |
876fa593 JK |
1501 | unsigned bc_l, bc_r, bc; |
1502 | ||
4a64f543 MS |
1503 | /* Find BC_L which is a leftmost element which may affect BUF |
1504 | content. It is safe to report lower value but a failure to | |
1505 | report higher one. */ | |
876fa593 JK |
1506 | |
1507 | bc_l = 0; | |
f5336ca5 | 1508 | bc_r = bp_locations_count; |
876fa593 JK |
1509 | while (bc_l + 1 < bc_r) |
1510 | { | |
35df4500 | 1511 | struct bp_location *bl; |
876fa593 JK |
1512 | |
1513 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1514 | bl = bp_locations[bc]; |
876fa593 | 1515 | |
4a64f543 MS |
1516 | /* Check first BL->ADDRESS will not overflow due to the added |
1517 | constant. Then advance the left boundary only if we are sure | |
1518 | the BC element can in no way affect the BUF content (MEMADDR | |
1519 | to MEMADDR + LEN range). | |
876fa593 | 1520 | |
f5336ca5 | 1521 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1522 | offset so that we cannot miss a breakpoint with its shadow |
1523 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1524 | |
f5336ca5 | 1525 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1526 | >= bl->address) |
f5336ca5 | 1527 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1528 | <= memaddr)) |
876fa593 JK |
1529 | bc_l = bc; |
1530 | else | |
1531 | bc_r = bc; | |
1532 | } | |
1533 | ||
128070bb PA |
1534 | /* Due to the binary search above, we need to make sure we pick the |
1535 | first location that's at BC_L's address. E.g., if there are | |
1536 | multiple locations at the same address, BC_L may end up pointing | |
1537 | at a duplicate location, and miss the "master"/"inserted" | |
1538 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1539 | B: | |
1540 | ||
1541 | L1@A, L2@A, L3@B, ... | |
1542 | ||
1543 | BC_L could end up pointing at location L2, while the "master" | |
1544 | location could be L1. Since the `loc->inserted' flag is only set | |
1545 | on "master" locations, we'd forget to restore the shadow of L1 | |
1546 | and L2. */ | |
1547 | while (bc_l > 0 | |
f5336ca5 | 1548 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1549 | bc_l--; |
1550 | ||
876fa593 JK |
1551 | /* Now do full processing of the found relevant range of elements. */ |
1552 | ||
f5336ca5 | 1553 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1554 | { |
f5336ca5 | 1555 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1556 | |
35df4500 TJB |
1557 | /* bp_location array has BL->OWNER always non-NULL. */ |
1558 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1559 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1560 | bl->owner->number); |
ffce0d52 | 1561 | |
e5dd4106 | 1562 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1563 | content. */ |
1564 | ||
f5336ca5 PA |
1565 | if (bl->address >= bp_locations_placed_address_before_address_max |
1566 | && memaddr + len <= (bl->address | |
1567 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1568 | break; |
1569 | ||
35df4500 | 1570 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1571 | continue; |
6c95b8df | 1572 | |
9d497a19 PA |
1573 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1574 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1575 | } | |
c906108c | 1576 | } |
9d497a19 | 1577 | |
c906108c | 1578 | \f |
c5aa993b | 1579 | |
b775012e LM |
1580 | /* Return true if BPT is either a software breakpoint or a hardware |
1581 | breakpoint. */ | |
1582 | ||
1583 | int | |
1584 | is_breakpoint (const struct breakpoint *bpt) | |
1585 | { | |
1586 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1587 | || bpt->type == bp_hardware_breakpoint |
1588 | || bpt->type == bp_dprintf); | |
b775012e LM |
1589 | } |
1590 | ||
60e1c644 PA |
1591 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1592 | ||
a5606eee | 1593 | static int |
d77f58be | 1594 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1595 | { |
1596 | return (bpt->type == bp_hardware_watchpoint | |
1597 | || bpt->type == bp_read_watchpoint | |
1598 | || bpt->type == bp_access_watchpoint); | |
1599 | } | |
7270d8f2 | 1600 | |
60e1c644 PA |
1601 | /* Return true if BPT is of any watchpoint kind, hardware or |
1602 | software. */ | |
1603 | ||
3a5c3e22 | 1604 | int |
d77f58be | 1605 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1606 | { |
1607 | return (is_hardware_watchpoint (bpt) | |
1608 | || bpt->type == bp_watchpoint); | |
1609 | } | |
1610 | ||
3a5c3e22 PA |
1611 | /* Returns true if the current thread and its running state are safe |
1612 | to evaluate or update watchpoint B. Watchpoints on local | |
1613 | expressions need to be evaluated in the context of the thread that | |
1614 | was current when the watchpoint was created, and, that thread needs | |
1615 | to be stopped to be able to select the correct frame context. | |
1616 | Watchpoints on global expressions can be evaluated on any thread, | |
1617 | and in any state. It is presently left to the target allowing | |
1618 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1619 | |
1620 | static int | |
3a5c3e22 | 1621 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1622 | { |
c1fc2657 | 1623 | return (b->pspace == current_program_space |
d0d8b0c6 JK |
1624 | && (ptid_equal (b->watchpoint_thread, null_ptid) |
1625 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1626 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1627 | } |
1628 | ||
d0fb5eae JK |
1629 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1630 | associated bp_watchpoint_scope breakpoint. */ | |
1631 | ||
1632 | static void | |
3a5c3e22 | 1633 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1634 | { |
c1fc2657 | 1635 | if (w->related_breakpoint != w) |
d0fb5eae | 1636 | { |
c1fc2657 SM |
1637 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1638 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1639 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1640 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1641 | w->related_breakpoint = w; | |
d0fb5eae | 1642 | } |
c1fc2657 | 1643 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1644 | } |
1645 | ||
bb9d5f81 PP |
1646 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1647 | watchpoint W. */ | |
1648 | ||
1649 | static struct value * | |
1650 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1651 | { | |
1652 | struct value *bit_val; | |
1653 | ||
1654 | if (val == NULL) | |
1655 | return NULL; | |
1656 | ||
1657 | bit_val = allocate_value (value_type (val)); | |
1658 | ||
1659 | unpack_value_bitfield (bit_val, | |
1660 | w->val_bitpos, | |
1661 | w->val_bitsize, | |
1662 | value_contents_for_printing (val), | |
1663 | value_offset (val), | |
1664 | val); | |
1665 | ||
1666 | return bit_val; | |
1667 | } | |
1668 | ||
c6d81124 PA |
1669 | /* Allocate a dummy location and add it to B, which must be a software |
1670 | watchpoint. This is required because even if a software watchpoint | |
1671 | is not watching any memory, bpstat_stop_status requires a location | |
1672 | to be able to report stops. */ | |
1673 | ||
1674 | static void | |
1675 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1676 | struct program_space *pspace) | |
1677 | { | |
1678 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1679 | ||
1680 | b->loc = allocate_bp_location (b); | |
1681 | b->loc->pspace = pspace; | |
1682 | b->loc->address = -1; | |
1683 | b->loc->length = -1; | |
1684 | } | |
1685 | ||
1686 | /* Returns true if B is a software watchpoint that is not watching any | |
1687 | memory (e.g., "watch $pc"). */ | |
1688 | ||
1689 | static int | |
1690 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1691 | { | |
1692 | return (b->type == bp_watchpoint | |
1693 | && b->loc != NULL | |
1694 | && b->loc->next == NULL | |
1695 | && b->loc->address == -1 | |
1696 | && b->loc->length == -1); | |
1697 | } | |
1698 | ||
567e1b4e JB |
1699 | /* Assuming that B is a watchpoint: |
1700 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1701 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1702 | - Evaluate the condition if there is one, and store the result |
1703 | in b->loc->cond. | |
a5606eee VP |
1704 | - Update the list of values that must be watched in B->loc. |
1705 | ||
4a64f543 MS |
1706 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1707 | nothing. If this is local watchpoint that is out of scope, delete | |
1708 | it. | |
1709 | ||
1710 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1711 | removed + inserted on each stop here. Normal breakpoints must | |
1712 | never be removed because they might be missed by a running thread | |
1713 | when debugging in non-stop mode. On the other hand, hardware | |
1714 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1715 | to each LWP since they are stored in each LWP's hardware debug | |
1716 | registers. Therefore, such LWP must be stopped first in order to | |
1717 | be able to modify its hardware watchpoints. | |
1718 | ||
1719 | Hardware watchpoints must be reset exactly once after being | |
1720 | presented to the user. It cannot be done sooner, because it would | |
1721 | reset the data used to present the watchpoint hit to the user. And | |
1722 | it must not be done later because it could display the same single | |
1723 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1724 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1725 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1726 | not user-visible - its hit is suppressed if the memory content has | |
1727 | not changed. | |
1728 | ||
1729 | The following constraints influence the location where we can reset | |
1730 | hardware watchpoints: | |
1731 | ||
1732 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1733 | called several times when GDB stops. | |
1734 | ||
1735 | [linux] | |
1736 | * Multiple hardware watchpoints can be hit at the same time, | |
1737 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1738 | hit at a time as the reason for stopping, and all the other hits | |
1739 | are presented later, one after the other, each time the user | |
1740 | requests the execution to be resumed. Execution is not resumed | |
1741 | for the threads still having pending hit event stored in | |
1742 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1743 | the inferior on the first stop the thread hit event is kept being | |
1744 | reported from its cached value by linux_nat_stopped_data_address | |
1745 | until the real thread resume happens after the watchpoint gets | |
1746 | presented and thus its LWP_INFO->STATUS gets reset. | |
1747 | ||
1748 | Therefore the hardware watchpoint hit can get safely reset on the | |
1749 | watchpoint removal from inferior. */ | |
a79d3c27 | 1750 | |
b40ce68a | 1751 | static void |
3a5c3e22 | 1752 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1753 | { |
a5606eee | 1754 | int within_current_scope; |
a5606eee | 1755 | struct frame_id saved_frame_id; |
66076460 | 1756 | int frame_saved; |
a5606eee | 1757 | |
f6bc2008 PA |
1758 | /* If this is a local watchpoint, we only want to check if the |
1759 | watchpoint frame is in scope if the current thread is the thread | |
1760 | that was used to create the watchpoint. */ | |
1761 | if (!watchpoint_in_thread_scope (b)) | |
1762 | return; | |
1763 | ||
c1fc2657 | 1764 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1765 | return; |
1766 | ||
66076460 | 1767 | frame_saved = 0; |
a5606eee VP |
1768 | |
1769 | /* Determine if the watchpoint is within scope. */ | |
1770 | if (b->exp_valid_block == NULL) | |
1771 | within_current_scope = 1; | |
1772 | else | |
1773 | { | |
b5db5dfc UW |
1774 | struct frame_info *fi = get_current_frame (); |
1775 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1776 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1777 | ||
c9cf6e20 MG |
1778 | /* If we're at a point where the stack has been destroyed |
1779 | (e.g. in a function epilogue), unwinding may not work | |
1780 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1781 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1782 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1783 | return; |
66076460 DJ |
1784 | |
1785 | /* Save the current frame's ID so we can restore it after | |
1786 | evaluating the watchpoint expression on its own frame. */ | |
1787 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1788 | took a frame parameter, so that we didn't have to change the | |
1789 | selected frame. */ | |
1790 | frame_saved = 1; | |
1791 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1792 | ||
a5606eee VP |
1793 | fi = frame_find_by_id (b->watchpoint_frame); |
1794 | within_current_scope = (fi != NULL); | |
1795 | if (within_current_scope) | |
1796 | select_frame (fi); | |
1797 | } | |
1798 | ||
b5db5dfc UW |
1799 | /* We don't free locations. They are stored in the bp_location array |
1800 | and update_global_location_list will eventually delete them and | |
1801 | remove breakpoints if needed. */ | |
c1fc2657 | 1802 | b->loc = NULL; |
b5db5dfc | 1803 | |
a5606eee VP |
1804 | if (within_current_scope && reparse) |
1805 | { | |
bbc13ae3 | 1806 | const char *s; |
d63d0675 | 1807 | |
4d01a485 | 1808 | b->exp.reset (); |
d63d0675 | 1809 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1810 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1811 | /* If the meaning of expression itself changed, the old value is |
1812 | no longer relevant. We don't want to report a watchpoint hit | |
1813 | to the user when the old value and the new value may actually | |
1814 | be completely different objects. */ | |
1815 | value_free (b->val); | |
fa4727a6 DJ |
1816 | b->val = NULL; |
1817 | b->val_valid = 0; | |
60e1c644 PA |
1818 | |
1819 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1820 | expression is stored in the breakpoint object, not in the | |
1821 | locations (re)created below. */ | |
c1fc2657 | 1822 | if (b->cond_string != NULL) |
60e1c644 | 1823 | { |
4d01a485 | 1824 | b->cond_exp.reset (); |
60e1c644 | 1825 | |
c1fc2657 | 1826 | s = b->cond_string; |
1bb9788d | 1827 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1828 | } |
a5606eee | 1829 | } |
a5606eee VP |
1830 | |
1831 | /* If we failed to parse the expression, for example because | |
1832 | it refers to a global variable in a not-yet-loaded shared library, | |
1833 | don't try to insert watchpoint. We don't automatically delete | |
1834 | such watchpoint, though, since failure to parse expression | |
1835 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1836 | if (!target_has_execution) |
2d134ed3 PA |
1837 | { |
1838 | /* Without execution, memory can't change. No use to try and | |
1839 | set watchpoint locations. The watchpoint will be reset when | |
1840 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1841 | if (!can_use_hw_watchpoints) |
1842 | { | |
c1fc2657 SM |
1843 | if (b->ops->works_in_software_mode (b)) |
1844 | b->type = bp_watchpoint; | |
e8369a73 | 1845 | else |
638aa5a1 AB |
1846 | error (_("Can't set read/access watchpoint when " |
1847 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1848 | } |
2d134ed3 PA |
1849 | } |
1850 | else if (within_current_scope && b->exp) | |
a5606eee | 1851 | { |
0cf6dd15 | 1852 | int pc = 0; |
fa4727a6 | 1853 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1854 | struct program_space *frame_pspace; |
a5606eee | 1855 | |
4d01a485 | 1856 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1857 | |
a5606eee VP |
1858 | /* Avoid setting b->val if it's already set. The meaning of |
1859 | b->val is 'the last value' user saw, and we should update | |
1860 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1861 | happens, the code that reports it updates b->val directly. |
1862 | We don't keep track of the memory value for masked | |
1863 | watchpoints. */ | |
c1fc2657 | 1864 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1865 | { |
bb9d5f81 PP |
1866 | if (b->val_bitsize != 0) |
1867 | { | |
1868 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1869 | if (v != NULL) | |
1870 | release_value (v); | |
1871 | } | |
fa4727a6 DJ |
1872 | b->val = v; |
1873 | b->val_valid = 1; | |
1874 | } | |
a5606eee | 1875 | |
2d134ed3 PA |
1876 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1877 | ||
a5606eee | 1878 | /* Look at each value on the value chain. */ |
9fa40276 | 1879 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1880 | { |
1881 | /* If it's a memory location, and GDB actually needed | |
1882 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1883 | must watch it. If the first value returned is |
1884 | still lazy, that means an error occurred reading it; | |
1885 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1886 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1887 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1888 | { |
1889 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1890 | |
a5606eee VP |
1891 | /* We only watch structs and arrays if user asked |
1892 | for it explicitly, never if they just happen to | |
1893 | appear in the middle of some value chain. */ | |
fa4727a6 | 1894 | if (v == result |
a5606eee VP |
1895 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1896 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1897 | { | |
1898 | CORE_ADDR addr; | |
f486487f | 1899 | enum target_hw_bp_type type; |
a5606eee | 1900 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
1901 | int bitpos = 0, bitsize = 0; |
1902 | ||
1903 | if (value_bitsize (v) != 0) | |
1904 | { | |
1905 | /* Extract the bit parameters out from the bitfield | |
1906 | sub-expression. */ | |
1907 | bitpos = value_bitpos (v); | |
1908 | bitsize = value_bitsize (v); | |
1909 | } | |
1910 | else if (v == result && b->val_bitsize != 0) | |
1911 | { | |
1912 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
1913 | lvalue whose bit parameters are saved in the fields | |
1914 | VAL_BITPOS and VAL_BITSIZE. */ | |
1915 | bitpos = b->val_bitpos; | |
1916 | bitsize = b->val_bitsize; | |
1917 | } | |
a5606eee | 1918 | |
42ae5230 | 1919 | addr = value_address (v); |
bb9d5f81 PP |
1920 | if (bitsize != 0) |
1921 | { | |
1922 | /* Skip the bytes that don't contain the bitfield. */ | |
1923 | addr += bitpos / 8; | |
1924 | } | |
1925 | ||
a5606eee | 1926 | type = hw_write; |
c1fc2657 | 1927 | if (b->type == bp_read_watchpoint) |
a5606eee | 1928 | type = hw_read; |
c1fc2657 | 1929 | else if (b->type == bp_access_watchpoint) |
a5606eee | 1930 | type = hw_access; |
3a5c3e22 | 1931 | |
c1fc2657 SM |
1932 | loc = allocate_bp_location (b); |
1933 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1934 | ; |
1935 | *tmp = loc; | |
a6d9a66e | 1936 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1937 | |
1938 | loc->pspace = frame_pspace; | |
a5606eee | 1939 | loc->address = addr; |
bb9d5f81 PP |
1940 | |
1941 | if (bitsize != 0) | |
1942 | { | |
1943 | /* Just cover the bytes that make up the bitfield. */ | |
1944 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
1945 | } | |
1946 | else | |
1947 | loc->length = TYPE_LENGTH (value_type (v)); | |
1948 | ||
a5606eee VP |
1949 | loc->watchpoint_type = type; |
1950 | } | |
1951 | } | |
9fa40276 TJB |
1952 | } |
1953 | ||
1954 | /* Change the type of breakpoint between hardware assisted or | |
1955 | an ordinary watchpoint depending on the hardware support | |
1956 | and free hardware slots. REPARSE is set when the inferior | |
1957 | is started. */ | |
a9634178 | 1958 | if (reparse) |
9fa40276 | 1959 | { |
e09342b5 | 1960 | int reg_cnt; |
9fa40276 TJB |
1961 | enum bp_loc_type loc_type; |
1962 | struct bp_location *bl; | |
a5606eee | 1963 | |
a9634178 | 1964 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1965 | |
1966 | if (reg_cnt) | |
9fa40276 TJB |
1967 | { |
1968 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 1969 | enum bptype type; |
9fa40276 | 1970 | |
a9634178 TJB |
1971 | /* Use an exact watchpoint when there's only one memory region to be |
1972 | watched, and only one debug register is needed to watch it. */ | |
1973 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1974 | ||
9fa40276 | 1975 | /* We need to determine how many resources are already |
e09342b5 TJB |
1976 | used for all other hardware watchpoints plus this one |
1977 | to see if we still have enough resources to also fit | |
a1398e0c PA |
1978 | this watchpoint in as well. */ |
1979 | ||
1980 | /* If this is a software watchpoint, we try to turn it | |
1981 | to a hardware one -- count resources as if B was of | |
1982 | hardware watchpoint type. */ | |
c1fc2657 | 1983 | type = b->type; |
a1398e0c PA |
1984 | if (type == bp_watchpoint) |
1985 | type = bp_hardware_watchpoint; | |
1986 | ||
1987 | /* This watchpoint may or may not have been placed on | |
1988 | the list yet at this point (it won't be in the list | |
1989 | if we're trying to create it for the first time, | |
1990 | through watch_command), so always account for it | |
1991 | manually. */ | |
1992 | ||
1993 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 1994 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
1995 | |
1996 | /* Add in the resources needed for B. */ | |
c1fc2657 | 1997 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
1998 | |
1999 | target_resources_ok | |
2000 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2001 | if (target_resources_ok <= 0) |
a9634178 | 2002 | { |
c1fc2657 | 2003 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
2004 | |
2005 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2006 | error (_("Target does not support this type of " |
2007 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2008 | else if (target_resources_ok < 0 && !sw_mode) |
2009 | error (_("There are not enough available hardware " | |
2010 | "resources for this watchpoint.")); | |
a1398e0c PA |
2011 | |
2012 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 2013 | b->type = bp_watchpoint; |
a1398e0c PA |
2014 | } |
2015 | else | |
2016 | { | |
2017 | /* If this was a software watchpoint, we've just | |
2018 | found we have enough resources to turn it to a | |
2019 | hardware watchpoint. Otherwise, this is a | |
2020 | nop. */ | |
c1fc2657 | 2021 | b->type = type; |
a9634178 | 2022 | } |
9fa40276 | 2023 | } |
c1fc2657 | 2024 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
2025 | { |
2026 | if (!can_use_hw_watchpoints) | |
2027 | error (_("Can't set read/access watchpoint when " | |
2028 | "hardware watchpoints are disabled.")); | |
2029 | else | |
2030 | error (_("Expression cannot be implemented with " | |
2031 | "read/access watchpoint.")); | |
2032 | } | |
9fa40276 | 2033 | else |
c1fc2657 | 2034 | b->type = bp_watchpoint; |
9fa40276 | 2035 | |
c1fc2657 | 2036 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2037 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 2038 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
2039 | bl->loc_type = loc_type; |
2040 | } | |
2041 | ||
2042 | for (v = val_chain; v; v = next) | |
2043 | { | |
a5606eee VP |
2044 | next = value_next (v); |
2045 | if (v != b->val) | |
2046 | value_free (v); | |
2047 | } | |
2048 | ||
c7437ca6 PA |
2049 | /* If a software watchpoint is not watching any memory, then the |
2050 | above left it without any location set up. But, | |
2051 | bpstat_stop_status requires a location to be able to report | |
2052 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2053 | if (b->type == bp_watchpoint && b->loc == NULL) |
2054 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2055 | } |
2056 | else if (!within_current_scope) | |
7270d8f2 | 2057 | { |
ac74f770 MS |
2058 | printf_filtered (_("\ |
2059 | Watchpoint %d deleted because the program has left the block\n\ | |
2060 | in which its expression is valid.\n"), | |
c1fc2657 | 2061 | b->number); |
d0fb5eae | 2062 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2063 | } |
a5606eee VP |
2064 | |
2065 | /* Restore the selected frame. */ | |
66076460 DJ |
2066 | if (frame_saved) |
2067 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2068 | } |
2069 | ||
a5606eee | 2070 | |
74960c60 | 2071 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2072 | inserted in the inferior. We don't differentiate the type of BL's owner |
2073 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2074 | breakpoint_ops is not defined, because in insert_bp_location, | |
2075 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2076 | static int |
35df4500 | 2077 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2078 | { |
35df4500 | 2079 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2080 | return 0; |
2081 | ||
35df4500 | 2082 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2083 | return 0; |
2084 | ||
35df4500 | 2085 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2086 | return 0; |
2087 | ||
f8eba3c6 TT |
2088 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2089 | return 0; | |
2090 | ||
56710373 PA |
2091 | /* This is set for example, when we're attached to the parent of a |
2092 | vfork, and have detached from the child. The child is running | |
2093 | free, and we expect it to do an exec or exit, at which point the | |
2094 | OS makes the parent schedulable again (and the target reports | |
2095 | that the vfork is done). Until the child is done with the shared | |
2096 | memory region, do not insert breakpoints in the parent, otherwise | |
2097 | the child could still trip on the parent's breakpoints. Since | |
2098 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2099 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2100 | return 0; |
2101 | ||
31e77af2 | 2102 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2103 | location, except if the breakpoint is a single-step breakpoint, |
2104 | and the breakpoint's thread is the thread which is stepping past | |
2105 | a breakpoint. */ | |
31e77af2 PA |
2106 | if ((bl->loc_type == bp_loc_software_breakpoint |
2107 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2108 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2109 | bl->address) |
2110 | /* The single-step breakpoint may be inserted at the location | |
2111 | we're trying to step if the instruction branches to itself. | |
2112 | However, the instruction won't be executed at all and it may | |
2113 | break the semantics of the instruction, for example, the | |
2114 | instruction is a conditional branch or updates some flags. | |
2115 | We can't fix it unless GDB is able to emulate the instruction | |
2116 | or switch to displaced stepping. */ | |
2117 | && !(bl->owner->type == bp_single_step | |
2118 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2119 | { |
2120 | if (debug_infrun) | |
2121 | { | |
2122 | fprintf_unfiltered (gdb_stdlog, | |
2123 | "infrun: skipping breakpoint: " | |
2124 | "stepping past insn at: %s\n", | |
2125 | paddress (bl->gdbarch, bl->address)); | |
2126 | } | |
2127 | return 0; | |
2128 | } | |
31e77af2 | 2129 | |
963f9c80 PA |
2130 | /* Don't insert watchpoints if we're trying to step past the |
2131 | instruction that triggered one. */ | |
2132 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2133 | && stepping_past_nonsteppable_watchpoint ()) | |
2134 | { | |
2135 | if (debug_infrun) | |
2136 | { | |
2137 | fprintf_unfiltered (gdb_stdlog, | |
2138 | "infrun: stepping past non-steppable watchpoint. " | |
2139 | "skipping watchpoint at %s:%d\n", | |
2140 | paddress (bl->gdbarch, bl->address), | |
2141 | bl->length); | |
2142 | } | |
2143 | return 0; | |
2144 | } | |
2145 | ||
74960c60 VP |
2146 | return 1; |
2147 | } | |
2148 | ||
934709f0 PW |
2149 | /* Same as should_be_inserted but does the check assuming |
2150 | that the location is not duplicated. */ | |
2151 | ||
2152 | static int | |
2153 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2154 | { | |
2155 | int result; | |
2156 | const int save_duplicate = bl->duplicate; | |
2157 | ||
2158 | bl->duplicate = 0; | |
2159 | result = should_be_inserted (bl); | |
2160 | bl->duplicate = save_duplicate; | |
2161 | return result; | |
2162 | } | |
2163 | ||
b775012e LM |
2164 | /* Parses a conditional described by an expression COND into an |
2165 | agent expression bytecode suitable for evaluation | |
2166 | by the bytecode interpreter. Return NULL if there was | |
2167 | any error during parsing. */ | |
2168 | ||
833177a4 | 2169 | static agent_expr_up |
b775012e LM |
2170 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2171 | { | |
833177a4 | 2172 | if (cond == NULL) |
b775012e LM |
2173 | return NULL; |
2174 | ||
833177a4 PA |
2175 | agent_expr_up aexpr; |
2176 | ||
b775012e LM |
2177 | /* We don't want to stop processing, so catch any errors |
2178 | that may show up. */ | |
492d29ea | 2179 | TRY |
b775012e | 2180 | { |
036e657b | 2181 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2182 | } |
2183 | ||
492d29ea | 2184 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2185 | { |
2186 | /* If we got here, it means the condition could not be parsed to a valid | |
2187 | bytecode expression and thus can't be evaluated on the target's side. | |
2188 | It's no use iterating through the conditions. */ | |
b775012e | 2189 | } |
492d29ea | 2190 | END_CATCH |
b775012e LM |
2191 | |
2192 | /* We have a valid agent expression. */ | |
2193 | return aexpr; | |
2194 | } | |
2195 | ||
2196 | /* Based on location BL, create a list of breakpoint conditions to be | |
2197 | passed on to the target. If we have duplicated locations with different | |
2198 | conditions, we will add such conditions to the list. The idea is that the | |
2199 | target will evaluate the list of conditions and will only notify GDB when | |
2200 | one of them is true. */ | |
2201 | ||
2202 | static void | |
2203 | build_target_condition_list (struct bp_location *bl) | |
2204 | { | |
2205 | struct bp_location **locp = NULL, **loc2p; | |
2206 | int null_condition_or_parse_error = 0; | |
2207 | int modified = bl->needs_update; | |
2208 | struct bp_location *loc; | |
2209 | ||
8b4f3082 | 2210 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2211 | bl->target_info.conditions.clear (); |
8b4f3082 | 2212 | |
b775012e LM |
2213 | /* This is only meaningful if the target is |
2214 | evaluating conditions and if the user has | |
2215 | opted for condition evaluation on the target's | |
2216 | side. */ | |
2217 | if (gdb_evaluates_breakpoint_condition_p () | |
2218 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2219 | return; | |
2220 | ||
2221 | /* Do a first pass to check for locations with no assigned | |
2222 | conditions or conditions that fail to parse to a valid agent expression | |
2223 | bytecode. If any of these happen, then it's no use to send conditions | |
2224 | to the target since this location will always trigger and generate a | |
2225 | response back to GDB. */ | |
2226 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2227 | { | |
2228 | loc = (*loc2p); | |
2229 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2230 | { | |
2231 | if (modified) | |
2232 | { | |
b775012e LM |
2233 | /* Re-parse the conditions since something changed. In that |
2234 | case we already freed the condition bytecodes (see | |
2235 | force_breakpoint_reinsertion). We just | |
2236 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2237 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2238 | loc->cond.get ()); | |
b775012e LM |
2239 | } |
2240 | ||
2241 | /* If we have a NULL bytecode expression, it means something | |
2242 | went wrong or we have a null condition expression. */ | |
2243 | if (!loc->cond_bytecode) | |
2244 | { | |
2245 | null_condition_or_parse_error = 1; | |
2246 | break; | |
2247 | } | |
2248 | } | |
2249 | } | |
2250 | ||
2251 | /* If any of these happened, it means we will have to evaluate the conditions | |
2252 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2253 | for all the other duplicate locations, thus we free all of them here. | |
2254 | ||
2255 | This is so we have a finer control over which locations' conditions are | |
2256 | being evaluated by GDB or the remote stub. */ | |
2257 | if (null_condition_or_parse_error) | |
2258 | { | |
2259 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2260 | { | |
2261 | loc = (*loc2p); | |
2262 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2263 | { | |
2264 | /* Only go as far as the first NULL bytecode is | |
2265 | located. */ | |
2266 | if (!loc->cond_bytecode) | |
2267 | return; | |
2268 | ||
833177a4 | 2269 | loc->cond_bytecode.reset (); |
b775012e LM |
2270 | } |
2271 | } | |
2272 | } | |
2273 | ||
2274 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2275 | for this location's address. */ | |
2276 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2277 | { | |
2278 | loc = (*loc2p); | |
2279 | if (loc->cond | |
2280 | && is_breakpoint (loc->owner) | |
2281 | && loc->pspace->num == bl->pspace->num | |
2282 | && loc->owner->enable_state == bp_enabled | |
2283 | && loc->enabled) | |
3cde5c42 PA |
2284 | { |
2285 | /* Add the condition to the vector. This will be used later | |
2286 | to send the conditions to the target. */ | |
2287 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2288 | } | |
b775012e LM |
2289 | } |
2290 | ||
2291 | return; | |
2292 | } | |
2293 | ||
d3ce09f5 SS |
2294 | /* Parses a command described by string CMD into an agent expression |
2295 | bytecode suitable for evaluation by the bytecode interpreter. | |
2296 | Return NULL if there was any error during parsing. */ | |
2297 | ||
833177a4 | 2298 | static agent_expr_up |
d3ce09f5 SS |
2299 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2300 | { | |
2301 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2302 | struct expression **argvec; |
bbc13ae3 KS |
2303 | const char *cmdrest; |
2304 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2305 | struct format_piece *fpieces; |
2306 | int nargs; | |
2307 | struct gdbarch *gdbarch = get_current_arch (); | |
2308 | ||
833177a4 | 2309 | if (cmd == NULL) |
d3ce09f5 SS |
2310 | return NULL; |
2311 | ||
2312 | cmdrest = cmd; | |
2313 | ||
2314 | if (*cmdrest == ',') | |
2315 | ++cmdrest; | |
f1735a53 | 2316 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2317 | |
2318 | if (*cmdrest++ != '"') | |
2319 | error (_("No format string following the location")); | |
2320 | ||
2321 | format_start = cmdrest; | |
2322 | ||
2323 | fpieces = parse_format_string (&cmdrest); | |
2324 | ||
2325 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2326 | ||
2327 | format_end = cmdrest; | |
2328 | ||
2329 | if (*cmdrest++ != '"') | |
2330 | error (_("Bad format string, non-terminated '\"'.")); | |
2331 | ||
f1735a53 | 2332 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2333 | |
2334 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2335 | error (_("Invalid argument syntax")); | |
2336 | ||
2337 | if (*cmdrest == ',') | |
2338 | cmdrest++; | |
f1735a53 | 2339 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2340 | |
2341 | /* For each argument, make an expression. */ | |
2342 | ||
2343 | argvec = (struct expression **) alloca (strlen (cmd) | |
2344 | * sizeof (struct expression *)); | |
2345 | ||
2346 | nargs = 0; | |
2347 | while (*cmdrest != '\0') | |
2348 | { | |
bbc13ae3 | 2349 | const char *cmd1; |
d3ce09f5 SS |
2350 | |
2351 | cmd1 = cmdrest; | |
4d01a485 PA |
2352 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2353 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2354 | cmdrest = cmd1; |
2355 | if (*cmdrest == ',') | |
2356 | ++cmdrest; | |
2357 | } | |
2358 | ||
833177a4 PA |
2359 | agent_expr_up aexpr; |
2360 | ||
d3ce09f5 SS |
2361 | /* We don't want to stop processing, so catch any errors |
2362 | that may show up. */ | |
492d29ea | 2363 | TRY |
d3ce09f5 | 2364 | { |
036e657b JB |
2365 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2366 | format_start, format_end - format_start, | |
2367 | fpieces, nargs, argvec); | |
d3ce09f5 | 2368 | } |
492d29ea | 2369 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2370 | { |
2371 | /* If we got here, it means the command could not be parsed to a valid | |
2372 | bytecode expression and thus can't be evaluated on the target's side. | |
2373 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2374 | } |
492d29ea PA |
2375 | END_CATCH |
2376 | ||
2377 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2378 | |
d3ce09f5 SS |
2379 | /* We have a valid agent expression, return it. */ |
2380 | return aexpr; | |
2381 | } | |
2382 | ||
2383 | /* Based on location BL, create a list of breakpoint commands to be | |
2384 | passed on to the target. If we have duplicated locations with | |
2385 | different commands, we will add any such to the list. */ | |
2386 | ||
2387 | static void | |
2388 | build_target_command_list (struct bp_location *bl) | |
2389 | { | |
2390 | struct bp_location **locp = NULL, **loc2p; | |
2391 | int null_command_or_parse_error = 0; | |
2392 | int modified = bl->needs_update; | |
2393 | struct bp_location *loc; | |
2394 | ||
3cde5c42 PA |
2395 | /* Clear commands left over from a previous insert. */ |
2396 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2397 | |
41fac0cf | 2398 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2399 | return; |
2400 | ||
41fac0cf PA |
2401 | /* For now, limit to agent-style dprintf breakpoints. */ |
2402 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2403 | return; |
2404 | ||
41fac0cf PA |
2405 | /* For now, if we have any duplicate location that isn't a dprintf, |
2406 | don't install the target-side commands, as that would make the | |
2407 | breakpoint not be reported to the core, and we'd lose | |
2408 | control. */ | |
2409 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2410 | { | |
2411 | loc = (*loc2p); | |
2412 | if (is_breakpoint (loc->owner) | |
2413 | && loc->pspace->num == bl->pspace->num | |
2414 | && loc->owner->type != bp_dprintf) | |
2415 | return; | |
2416 | } | |
2417 | ||
d3ce09f5 SS |
2418 | /* Do a first pass to check for locations with no assigned |
2419 | conditions or conditions that fail to parse to a valid agent expression | |
2420 | bytecode. If any of these happen, then it's no use to send conditions | |
2421 | to the target since this location will always trigger and generate a | |
2422 | response back to GDB. */ | |
2423 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2424 | { | |
2425 | loc = (*loc2p); | |
2426 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2427 | { | |
2428 | if (modified) | |
2429 | { | |
d3ce09f5 SS |
2430 | /* Re-parse the commands since something changed. In that |
2431 | case we already freed the command bytecodes (see | |
2432 | force_breakpoint_reinsertion). We just | |
2433 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2434 | loc->cmd_bytecode |
2435 | = parse_cmd_to_aexpr (bl->address, | |
2436 | loc->owner->extra_string); | |
d3ce09f5 SS |
2437 | } |
2438 | ||
2439 | /* If we have a NULL bytecode expression, it means something | |
2440 | went wrong or we have a null command expression. */ | |
2441 | if (!loc->cmd_bytecode) | |
2442 | { | |
2443 | null_command_or_parse_error = 1; | |
2444 | break; | |
2445 | } | |
2446 | } | |
2447 | } | |
2448 | ||
2449 | /* If anything failed, then we're not doing target-side commands, | |
2450 | and so clean up. */ | |
2451 | if (null_command_or_parse_error) | |
2452 | { | |
2453 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2454 | { | |
2455 | loc = (*loc2p); | |
2456 | if (is_breakpoint (loc->owner) | |
2457 | && loc->pspace->num == bl->pspace->num) | |
2458 | { | |
2459 | /* Only go as far as the first NULL bytecode is | |
2460 | located. */ | |
40fb6c5e | 2461 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2462 | return; |
2463 | ||
833177a4 | 2464 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2465 | } |
2466 | } | |
2467 | } | |
2468 | ||
2469 | /* No NULL commands or failed bytecode generation. Build a command list | |
2470 | for this location's address. */ | |
2471 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2472 | { | |
2473 | loc = (*loc2p); | |
2474 | if (loc->owner->extra_string | |
2475 | && is_breakpoint (loc->owner) | |
2476 | && loc->pspace->num == bl->pspace->num | |
2477 | && loc->owner->enable_state == bp_enabled | |
2478 | && loc->enabled) | |
3cde5c42 PA |
2479 | { |
2480 | /* Add the command to the vector. This will be used later | |
2481 | to send the commands to the target. */ | |
2482 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2483 | } | |
d3ce09f5 SS |
2484 | } |
2485 | ||
2486 | bl->target_info.persist = 0; | |
2487 | /* Maybe flag this location as persistent. */ | |
2488 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2489 | bl->target_info.persist = 1; | |
2490 | } | |
2491 | ||
833b7ab5 YQ |
2492 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2493 | of breakpoint according to ADDR except single-step breakpoint. | |
2494 | Get the kind of single-step breakpoint according to the current | |
2495 | registers state. */ | |
cd6c3b4f YQ |
2496 | |
2497 | static int | |
2498 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2499 | { | |
833b7ab5 YQ |
2500 | if (bl->owner->type == bp_single_step) |
2501 | { | |
2502 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2503 | struct regcache *regcache; | |
2504 | ||
2505 | regcache = get_thread_regcache (thr->ptid); | |
2506 | ||
2507 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2508 | regcache, addr); | |
2509 | } | |
2510 | else | |
2511 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2512 | } |
2513 | ||
35df4500 TJB |
2514 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2515 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2516 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2517 | Returns 0 for success, 1 if the bp_location type is not supported or |
2518 | -1 for failure. | |
879bfdc2 | 2519 | |
4a64f543 MS |
2520 | NOTE drow/2003-09-09: This routine could be broken down to an |
2521 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2522 | static int |
35df4500 | 2523 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2524 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2525 | int *disabled_breaks, |
dd61ec5c MW |
2526 | int *hw_breakpoint_error, |
2527 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2528 | { |
0000e5cc PA |
2529 | enum errors bp_err = GDB_NO_ERROR; |
2530 | const char *bp_err_message = NULL; | |
879bfdc2 | 2531 | |
b775012e | 2532 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2533 | return 0; |
2534 | ||
35c63cd8 JB |
2535 | /* Note we don't initialize bl->target_info, as that wipes out |
2536 | the breakpoint location's shadow_contents if the breakpoint | |
2537 | is still inserted at that location. This in turn breaks | |
2538 | target_read_memory which depends on these buffers when | |
2539 | a memory read is requested at the breakpoint location: | |
2540 | Once the target_info has been wiped, we fail to see that | |
2541 | we have a breakpoint inserted at that address and thus | |
2542 | read the breakpoint instead of returning the data saved in | |
2543 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2544 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2545 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2546 | bl->target_info.length = bl->length; |
8181d85f | 2547 | |
b775012e LM |
2548 | /* When working with target-side conditions, we must pass all the conditions |
2549 | for the same breakpoint address down to the target since GDB will not | |
2550 | insert those locations. With a list of breakpoint conditions, the target | |
2551 | can decide when to stop and notify GDB. */ | |
2552 | ||
2553 | if (is_breakpoint (bl->owner)) | |
2554 | { | |
2555 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2556 | build_target_command_list (bl); |
2557 | /* Reset the modification marker. */ | |
b775012e LM |
2558 | bl->needs_update = 0; |
2559 | } | |
2560 | ||
35df4500 TJB |
2561 | if (bl->loc_type == bp_loc_software_breakpoint |
2562 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2563 | { |
35df4500 | 2564 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2565 | { |
2566 | /* If the explicitly specified breakpoint type | |
2567 | is not hardware breakpoint, check the memory map to see | |
2568 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2569 | |
765dc015 VP |
2570 | Two important cases are: |
2571 | - location type is not hardware breakpoint, memory | |
2572 | is readonly. We change the type of the location to | |
2573 | hardware breakpoint. | |
4a64f543 MS |
2574 | - location type is hardware breakpoint, memory is |
2575 | read-write. This means we've previously made the | |
2576 | location hardware one, but then the memory map changed, | |
2577 | so we undo. | |
765dc015 | 2578 | |
4a64f543 MS |
2579 | When breakpoints are removed, remove_breakpoints will use |
2580 | location types we've just set here, the only possible | |
2581 | problem is that memory map has changed during running | |
2582 | program, but it's not going to work anyway with current | |
2583 | gdb. */ | |
765dc015 | 2584 | struct mem_region *mr |
0d5ed153 | 2585 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2586 | |
2587 | if (mr) | |
2588 | { | |
2589 | if (automatic_hardware_breakpoints) | |
2590 | { | |
765dc015 VP |
2591 | enum bp_loc_type new_type; |
2592 | ||
2593 | if (mr->attrib.mode != MEM_RW) | |
2594 | new_type = bp_loc_hardware_breakpoint; | |
2595 | else | |
2596 | new_type = bp_loc_software_breakpoint; | |
2597 | ||
35df4500 | 2598 | if (new_type != bl->loc_type) |
765dc015 VP |
2599 | { |
2600 | static int said = 0; | |
cc59ec59 | 2601 | |
35df4500 | 2602 | bl->loc_type = new_type; |
765dc015 VP |
2603 | if (!said) |
2604 | { | |
3e43a32a MS |
2605 | fprintf_filtered (gdb_stdout, |
2606 | _("Note: automatically using " | |
2607 | "hardware breakpoints for " | |
2608 | "read-only addresses.\n")); | |
765dc015 VP |
2609 | said = 1; |
2610 | } | |
2611 | } | |
2612 | } | |
35df4500 | 2613 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2614 | && mr->attrib.mode != MEM_RW) |
2615 | { | |
2616 | fprintf_unfiltered (tmp_error_stream, | |
2617 | _("Cannot insert breakpoint %d.\n" | |
2618 | "Cannot set software breakpoint " | |
2619 | "at read-only address %s\n"), | |
2620 | bl->owner->number, | |
2621 | paddress (bl->gdbarch, bl->address)); | |
2622 | return 1; | |
2623 | } | |
765dc015 VP |
2624 | } |
2625 | } | |
2626 | ||
879bfdc2 DJ |
2627 | /* First check to see if we have to handle an overlay. */ |
2628 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2629 | || bl->section == NULL |
2630 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2631 | { |
2632 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2633 | TRY |
dd61ec5c | 2634 | { |
0000e5cc PA |
2635 | int val; |
2636 | ||
dd61ec5c | 2637 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2638 | if (val) |
2639 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2640 | } |
492d29ea | 2641 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2642 | { |
0000e5cc PA |
2643 | bp_err = e.error; |
2644 | bp_err_message = e.message; | |
dd61ec5c | 2645 | } |
492d29ea | 2646 | END_CATCH |
879bfdc2 DJ |
2647 | } |
2648 | else | |
2649 | { | |
4a64f543 | 2650 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2651 | Shall we set a breakpoint at the LMA? */ |
2652 | if (!overlay_events_enabled) | |
2653 | { | |
2654 | /* Yes -- overlay event support is not active, | |
2655 | so we must try to set a breakpoint at the LMA. | |
2656 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2657 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2658 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2659 | bl->owner->number); |
879bfdc2 DJ |
2660 | else |
2661 | { | |
35df4500 TJB |
2662 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2663 | bl->section); | |
879bfdc2 | 2664 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2665 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2666 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2667 | |
2668 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2669 | TRY |
0000e5cc PA |
2670 | { |
2671 | int val; | |
2672 | ||
579c6ad9 | 2673 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2674 | = breakpoint_kind (bl, &addr); |
2675 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2676 | val = target_insert_breakpoint (bl->gdbarch, |
2677 | &bl->overlay_target_info); | |
2678 | if (val) | |
2679 | bp_err = GENERIC_ERROR; | |
2680 | } | |
492d29ea | 2681 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2682 | { |
2683 | bp_err = e.error; | |
2684 | bp_err_message = e.message; | |
2685 | } | |
492d29ea | 2686 | END_CATCH |
0000e5cc PA |
2687 | |
2688 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2689 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2690 | "Overlay breakpoint %d " |
2691 | "failed: in ROM?\n", | |
35df4500 | 2692 | bl->owner->number); |
879bfdc2 DJ |
2693 | } |
2694 | } | |
2695 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2696 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2697 | { |
2698 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2699 | TRY |
dd61ec5c | 2700 | { |
0000e5cc PA |
2701 | int val; |
2702 | ||
dd61ec5c | 2703 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2704 | if (val) |
2705 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2706 | } |
492d29ea | 2707 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2708 | { |
0000e5cc PA |
2709 | bp_err = e.error; |
2710 | bp_err_message = e.message; | |
dd61ec5c | 2711 | } |
492d29ea | 2712 | END_CATCH |
879bfdc2 DJ |
2713 | } |
2714 | else | |
2715 | { | |
2716 | /* No. This breakpoint will not be inserted. | |
2717 | No error, but do not mark the bp as 'inserted'. */ | |
2718 | return 0; | |
2719 | } | |
2720 | } | |
2721 | ||
0000e5cc | 2722 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2723 | { |
2724 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2725 | |
2726 | /* In some cases, we might not be able to insert a | |
2727 | breakpoint in a shared library that has already been | |
2728 | removed, but we have not yet processed the shlib unload | |
2729 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2730 | breakpoint insertion themselves can't tell why the |
2731 | breakpoint insertion failed (e.g., the remote target | |
2732 | doesn't define error codes), so we must treat generic | |
2733 | errors as memory errors. */ | |
0000e5cc | 2734 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2735 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2736 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2737 | || shared_objfile_contains_address_p (bl->pspace, |
2738 | bl->address))) | |
879bfdc2 | 2739 | { |
4a64f543 | 2740 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2741 | bl->shlib_disabled = 1; |
8d3788bd | 2742 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2743 | if (!*disabled_breaks) |
2744 | { | |
2745 | fprintf_unfiltered (tmp_error_stream, | |
2746 | "Cannot insert breakpoint %d.\n", | |
2747 | bl->owner->number); | |
2748 | fprintf_unfiltered (tmp_error_stream, | |
2749 | "Temporarily disabling shared " | |
2750 | "library breakpoints:\n"); | |
2751 | } | |
2752 | *disabled_breaks = 1; | |
879bfdc2 | 2753 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2754 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2755 | return 0; |
879bfdc2 DJ |
2756 | } |
2757 | else | |
879bfdc2 | 2758 | { |
35df4500 | 2759 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2760 | { |
0000e5cc PA |
2761 | *hw_breakpoint_error = 1; |
2762 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2763 | fprintf_unfiltered (tmp_error_stream, |
2764 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2765 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2766 | if (bp_err_message != NULL) | |
2767 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2768 | } |
2769 | else | |
2770 | { | |
0000e5cc PA |
2771 | if (bp_err_message == NULL) |
2772 | { | |
1ccbe998 | 2773 | std::string message |
0000e5cc PA |
2774 | = memory_error_message (TARGET_XFER_E_IO, |
2775 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2776 | |
2777 | fprintf_unfiltered (tmp_error_stream, | |
2778 | "Cannot insert breakpoint %d.\n" | |
2779 | "%s\n", | |
1ccbe998 | 2780 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2781 | } |
2782 | else | |
2783 | { | |
2784 | fprintf_unfiltered (tmp_error_stream, | |
2785 | "Cannot insert breakpoint %d: %s\n", | |
2786 | bl->owner->number, | |
2787 | bp_err_message); | |
2788 | } | |
879bfdc2 | 2789 | } |
0000e5cc | 2790 | return 1; |
879bfdc2 DJ |
2791 | |
2792 | } | |
2793 | } | |
2794 | else | |
35df4500 | 2795 | bl->inserted = 1; |
879bfdc2 | 2796 | |
0000e5cc | 2797 | return 0; |
879bfdc2 DJ |
2798 | } |
2799 | ||
35df4500 | 2800 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2801 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2802 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2803 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2804 | { |
0000e5cc PA |
2805 | int val; |
2806 | ||
77b06cd7 TJB |
2807 | gdb_assert (bl->owner->ops != NULL |
2808 | && bl->owner->ops->insert_location != NULL); | |
2809 | ||
2810 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2811 | |
2812 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2813 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2814 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2815 | { |
2816 | struct bp_location *loc, **loc_temp; | |
2817 | ||
2818 | /* But don't try to insert it, if there's already another | |
2819 | hw_access location that would be considered a duplicate | |
2820 | of this one. */ | |
2821 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2822 | if (loc != bl |
85d721b8 | 2823 | && loc->watchpoint_type == hw_access |
35df4500 | 2824 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2825 | { |
35df4500 TJB |
2826 | bl->duplicate = 1; |
2827 | bl->inserted = 1; | |
2828 | bl->target_info = loc->target_info; | |
2829 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2830 | val = 0; |
2831 | break; | |
2832 | } | |
2833 | ||
2834 | if (val == 1) | |
2835 | { | |
77b06cd7 TJB |
2836 | bl->watchpoint_type = hw_access; |
2837 | val = bl->owner->ops->insert_location (bl); | |
2838 | ||
2839 | if (val) | |
2840 | /* Back to the original value. */ | |
2841 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2842 | } |
2843 | } | |
2844 | ||
35df4500 | 2845 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2846 | } |
2847 | ||
35df4500 | 2848 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2849 | { |
0000e5cc PA |
2850 | int val; |
2851 | ||
77b06cd7 TJB |
2852 | gdb_assert (bl->owner->ops != NULL |
2853 | && bl->owner->ops->insert_location != NULL); | |
2854 | ||
2855 | val = bl->owner->ops->insert_location (bl); | |
2856 | if (val) | |
2857 | { | |
2858 | bl->owner->enable_state = bp_disabled; | |
2859 | ||
2860 | if (val == 1) | |
2861 | warning (_("\ | |
2862 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2863 | of catchpoint."), bl->owner->number); | |
2864 | else | |
2865 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2866 | } | |
2867 | ||
2868 | bl->inserted = (val == 0); | |
1640b821 DJ |
2869 | |
2870 | /* We've already printed an error message if there was a problem | |
2871 | inserting this catchpoint, and we've disabled the catchpoint, | |
2872 | so just return success. */ | |
2873 | return 0; | |
879bfdc2 DJ |
2874 | } |
2875 | ||
2876 | return 0; | |
2877 | } | |
2878 | ||
6c95b8df PA |
2879 | /* This function is called when program space PSPACE is about to be |
2880 | deleted. It takes care of updating breakpoints to not reference | |
2881 | PSPACE anymore. */ | |
2882 | ||
2883 | void | |
2884 | breakpoint_program_space_exit (struct program_space *pspace) | |
2885 | { | |
2886 | struct breakpoint *b, *b_temp; | |
876fa593 | 2887 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2888 | |
2889 | /* Remove any breakpoint that was set through this program space. */ | |
2890 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2891 | { | |
2892 | if (b->pspace == pspace) | |
2893 | delete_breakpoint (b); | |
2894 | } | |
2895 | ||
2896 | /* Breakpoints set through other program spaces could have locations | |
2897 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2898 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2899 | { |
2900 | struct bp_location *tmp; | |
2901 | ||
2902 | if (loc->pspace == pspace) | |
2903 | { | |
2bdf28a0 | 2904 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2905 | if (loc->owner->loc == loc) |
2906 | loc->owner->loc = loc->next; | |
2907 | else | |
2908 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2909 | if (tmp->next == loc) | |
2910 | { | |
2911 | tmp->next = loc->next; | |
2912 | break; | |
2913 | } | |
2914 | } | |
2915 | } | |
2916 | ||
2917 | /* Now update the global location list to permanently delete the | |
2918 | removed locations above. */ | |
44702360 | 2919 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
2920 | } |
2921 | ||
74960c60 VP |
2922 | /* Make sure all breakpoints are inserted in inferior. |
2923 | Throws exception on any error. | |
2924 | A breakpoint that is already inserted won't be inserted | |
2925 | again, so calling this function twice is safe. */ | |
2926 | void | |
2927 | insert_breakpoints (void) | |
2928 | { | |
2929 | struct breakpoint *bpt; | |
2930 | ||
2931 | ALL_BREAKPOINTS (bpt) | |
2932 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
2933 | { |
2934 | struct watchpoint *w = (struct watchpoint *) bpt; | |
2935 | ||
2936 | update_watchpoint (w, 0 /* don't reparse. */); | |
2937 | } | |
74960c60 | 2938 | |
04086b45 PA |
2939 | /* Updating watchpoints creates new locations, so update the global |
2940 | location list. Explicitly tell ugll to insert locations and | |
2941 | ignore breakpoints_always_inserted_mode. */ | |
2942 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
2943 | } |
2944 | ||
20388dd6 YQ |
2945 | /* Invoke CALLBACK for each of bp_location. */ |
2946 | ||
2947 | void | |
2948 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
2949 | { | |
2950 | struct bp_location *loc, **loc_tmp; | |
2951 | ||
2952 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
2953 | { | |
2954 | callback (loc, NULL); | |
2955 | } | |
2956 | } | |
2957 | ||
b775012e LM |
2958 | /* This is used when we need to synch breakpoint conditions between GDB and the |
2959 | target. It is the case with deleting and disabling of breakpoints when using | |
2960 | always-inserted mode. */ | |
2961 | ||
2962 | static void | |
2963 | update_inserted_breakpoint_locations (void) | |
2964 | { | |
2965 | struct bp_location *bl, **blp_tmp; | |
2966 | int error_flag = 0; | |
2967 | int val = 0; | |
2968 | int disabled_breaks = 0; | |
2969 | int hw_breakpoint_error = 0; | |
dd61ec5c | 2970 | int hw_bp_details_reported = 0; |
b775012e | 2971 | |
d7e74731 | 2972 | string_file tmp_error_stream; |
b775012e LM |
2973 | |
2974 | /* Explicitly mark the warning -- this will only be printed if | |
2975 | there was an error. */ | |
d7e74731 | 2976 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 2977 | |
5ed8105e | 2978 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
2979 | |
2980 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
2981 | { | |
2982 | /* We only want to update software breakpoints and hardware | |
2983 | breakpoints. */ | |
2984 | if (!is_breakpoint (bl->owner)) | |
2985 | continue; | |
2986 | ||
2987 | /* We only want to update locations that are already inserted | |
2988 | and need updating. This is to avoid unwanted insertion during | |
2989 | deletion of breakpoints. */ | |
2990 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
2991 | continue; | |
2992 | ||
2993 | switch_to_program_space_and_thread (bl->pspace); | |
2994 | ||
2995 | /* For targets that support global breakpoints, there's no need | |
2996 | to select an inferior to insert breakpoint to. In fact, even | |
2997 | if we aren't attached to any process yet, we should still | |
2998 | insert breakpoints. */ | |
f5656ead | 2999 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3000 | && ptid_equal (inferior_ptid, null_ptid)) |
3001 | continue; | |
3002 | ||
d7e74731 | 3003 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3004 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3005 | if (val) |
3006 | error_flag = val; | |
3007 | } | |
3008 | ||
3009 | if (error_flag) | |
3010 | { | |
223ffa71 | 3011 | target_terminal::ours_for_output (); |
b775012e LM |
3012 | error_stream (tmp_error_stream); |
3013 | } | |
b775012e LM |
3014 | } |
3015 | ||
c30eee59 | 3016 | /* Used when starting or continuing the program. */ |
c906108c | 3017 | |
74960c60 VP |
3018 | static void |
3019 | insert_breakpoint_locations (void) | |
c906108c | 3020 | { |
a5606eee | 3021 | struct breakpoint *bpt; |
35df4500 | 3022 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3023 | int error_flag = 0; |
c906108c | 3024 | int val = 0; |
3fbb6ffa | 3025 | int disabled_breaks = 0; |
81d0cc19 | 3026 | int hw_breakpoint_error = 0; |
dd61ec5c | 3027 | int hw_bp_error_explained_already = 0; |
c906108c | 3028 | |
d7e74731 PA |
3029 | string_file tmp_error_stream; |
3030 | ||
81d0cc19 GS |
3031 | /* Explicitly mark the warning -- this will only be printed if |
3032 | there was an error. */ | |
d7e74731 | 3033 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3034 | |
5ed8105e | 3035 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3036 | |
35df4500 | 3037 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3038 | { |
b775012e | 3039 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3040 | continue; |
3041 | ||
4a64f543 MS |
3042 | /* There is no point inserting thread-specific breakpoints if |
3043 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3044 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3045 | if (bl->owner->thread != -1 |
5d5658a1 | 3046 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3047 | continue; |
3048 | ||
35df4500 | 3049 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3050 | |
3051 | /* For targets that support global breakpoints, there's no need | |
3052 | to select an inferior to insert breakpoint to. In fact, even | |
3053 | if we aren't attached to any process yet, we should still | |
3054 | insert breakpoints. */ | |
f5656ead | 3055 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3056 | && ptid_equal (inferior_ptid, null_ptid)) |
3057 | continue; | |
3058 | ||
d7e74731 | 3059 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3060 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3061 | if (val) |
eacd795a | 3062 | error_flag = val; |
879bfdc2 | 3063 | } |
c906108c | 3064 | |
4a64f543 MS |
3065 | /* If we failed to insert all locations of a watchpoint, remove |
3066 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3067 | ALL_BREAKPOINTS (bpt) |
3068 | { | |
3069 | int some_failed = 0; | |
3070 | struct bp_location *loc; | |
3071 | ||
3072 | if (!is_hardware_watchpoint (bpt)) | |
3073 | continue; | |
3074 | ||
d6b74ac4 | 3075 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3076 | continue; |
74960c60 VP |
3077 | |
3078 | if (bpt->disposition == disp_del_at_next_stop) | |
3079 | continue; | |
a5606eee VP |
3080 | |
3081 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3082 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3083 | { |
3084 | some_failed = 1; | |
3085 | break; | |
3086 | } | |
3087 | if (some_failed) | |
3088 | { | |
3089 | for (loc = bpt->loc; loc; loc = loc->next) | |
3090 | if (loc->inserted) | |
834c0d03 | 3091 | remove_breakpoint (loc); |
a5606eee VP |
3092 | |
3093 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3094 | tmp_error_stream.printf ("Could not insert " |
3095 | "hardware watchpoint %d.\n", | |
3096 | bpt->number); | |
eacd795a | 3097 | error_flag = -1; |
a5606eee VP |
3098 | } |
3099 | } | |
3100 | ||
eacd795a | 3101 | if (error_flag) |
81d0cc19 GS |
3102 | { |
3103 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3104 | message about possibly exhausted resources. */ | |
dd61ec5c | 3105 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3106 | { |
d7e74731 | 3107 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3108 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3109 | } |
223ffa71 | 3110 | target_terminal::ours_for_output (); |
81d0cc19 GS |
3111 | error_stream (tmp_error_stream); |
3112 | } | |
c906108c SS |
3113 | } |
3114 | ||
c30eee59 TJB |
3115 | /* Used when the program stops. |
3116 | Returns zero if successful, or non-zero if there was a problem | |
3117 | removing a breakpoint location. */ | |
3118 | ||
c906108c | 3119 | int |
fba45db2 | 3120 | remove_breakpoints (void) |
c906108c | 3121 | { |
35df4500 | 3122 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3123 | int val = 0; |
c906108c | 3124 | |
35df4500 | 3125 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3126 | { |
1e4d1764 | 3127 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3128 | val |= remove_breakpoint (bl); |
c5aa993b | 3129 | } |
3a1bae8e | 3130 | return val; |
c906108c SS |
3131 | } |
3132 | ||
49fa26b0 PA |
3133 | /* When a thread exits, remove breakpoints that are related to |
3134 | that thread. */ | |
3135 | ||
3136 | static void | |
3137 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3138 | { | |
3139 | struct breakpoint *b, *b_tmp; | |
3140 | ||
3141 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3142 | { | |
5d5658a1 | 3143 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3144 | { |
3145 | b->disposition = disp_del_at_next_stop; | |
3146 | ||
3147 | printf_filtered (_("\ | |
43792cf0 PA |
3148 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3149 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3150 | |
3151 | /* Hide it from the user. */ | |
3152 | b->number = 0; | |
3153 | } | |
3154 | } | |
3155 | } | |
3156 | ||
6c95b8df PA |
3157 | /* Remove breakpoints of process PID. */ |
3158 | ||
3159 | int | |
3160 | remove_breakpoints_pid (int pid) | |
3161 | { | |
35df4500 | 3162 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3163 | int val; |
3164 | struct inferior *inf = find_inferior_pid (pid); | |
3165 | ||
35df4500 | 3166 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3167 | { |
35df4500 | 3168 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3169 | continue; |
3170 | ||
fc126975 | 3171 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3172 | { |
834c0d03 | 3173 | val = remove_breakpoint (bl); |
6c95b8df PA |
3174 | if (val != 0) |
3175 | return val; | |
3176 | } | |
3177 | } | |
3178 | return 0; | |
3179 | } | |
3180 | ||
c906108c | 3181 | int |
fba45db2 | 3182 | reattach_breakpoints (int pid) |
c906108c | 3183 | { |
35df4500 | 3184 | struct bp_location *bl, **blp_tmp; |
c906108c | 3185 | int val; |
dd61ec5c | 3186 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3187 | struct inferior *inf; |
3188 | struct thread_info *tp; | |
3189 | ||
3190 | tp = any_live_thread_of_process (pid); | |
3191 | if (tp == NULL) | |
3192 | return 1; | |
3193 | ||
3194 | inf = find_inferior_pid (pid); | |
6c95b8df | 3195 | |
2989a365 | 3196 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3197 | inferior_ptid = tp->ptid; |
a4954f26 | 3198 | |
d7e74731 | 3199 | string_file tmp_error_stream; |
c906108c | 3200 | |
35df4500 | 3201 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3202 | { |
35df4500 | 3203 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3204 | continue; |
3205 | ||
35df4500 | 3206 | if (bl->inserted) |
c5aa993b | 3207 | { |
35df4500 | 3208 | bl->inserted = 0; |
d7e74731 | 3209 | val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b | 3210 | if (val != 0) |
2989a365 | 3211 | return val; |
c5aa993b JM |
3212 | } |
3213 | } | |
c906108c SS |
3214 | return 0; |
3215 | } | |
3216 | ||
e58b0e63 PA |
3217 | static int internal_breakpoint_number = -1; |
3218 | ||
84f4c1fe PM |
3219 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3220 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3221 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3222 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3223 | breakpoint_count and that value incremented. Internal breakpoints |
3224 | do not set the internal var bpnum. */ | |
3225 | static void | |
3226 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3227 | { | |
3228 | if (internal) | |
3229 | b->number = internal_breakpoint_number--; | |
3230 | else | |
3231 | { | |
3232 | set_breakpoint_count (breakpoint_count + 1); | |
3233 | b->number = breakpoint_count; | |
3234 | } | |
3235 | } | |
3236 | ||
e62c965a | 3237 | static struct breakpoint * |
a6d9a66e | 3238 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3239 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3240 | const struct breakpoint_ops *ops) |
e62c965a | 3241 | { |
51abb421 | 3242 | symtab_and_line sal; |
e62c965a PP |
3243 | sal.pc = address; |
3244 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3245 | sal.pspace = current_program_space; |
e62c965a | 3246 | |
51abb421 | 3247 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3248 | b->number = internal_breakpoint_number--; |
3249 | b->disposition = disp_donttouch; | |
3250 | ||
3251 | return b; | |
3252 | } | |
3253 | ||
17450429 PP |
3254 | static const char *const longjmp_names[] = |
3255 | { | |
3256 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3257 | }; | |
3258 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3259 | ||
3260 | /* Per-objfile data private to breakpoint.c. */ | |
3261 | struct breakpoint_objfile_data | |
3262 | { | |
3263 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3264 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3265 | |
3266 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3267 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3268 | |
28106bc2 SDJ |
3269 | /* True if we have looked for longjmp probes. */ |
3270 | int longjmp_searched; | |
3271 | ||
3272 | /* SystemTap probe points for longjmp (if any). */ | |
3273 | VEC (probe_p) *longjmp_probes; | |
3274 | ||
17450429 | 3275 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3276 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3277 | |
3278 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3279 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3280 | |
3281 | /* True if we have looked for exception probes. */ | |
3282 | int exception_searched; | |
3283 | ||
3284 | /* SystemTap probe points for unwinding (if any). */ | |
3285 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3286 | }; |
3287 | ||
3288 | static const struct objfile_data *breakpoint_objfile_key; | |
3289 | ||
3290 | /* Minimal symbol not found sentinel. */ | |
3291 | static struct minimal_symbol msym_not_found; | |
3292 | ||
3293 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3294 | ||
3295 | static int | |
3296 | msym_not_found_p (const struct minimal_symbol *msym) | |
3297 | { | |
3298 | return msym == &msym_not_found; | |
3299 | } | |
3300 | ||
3301 | /* Return per-objfile data needed by breakpoint.c. | |
3302 | Allocate the data if necessary. */ | |
3303 | ||
3304 | static struct breakpoint_objfile_data * | |
3305 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3306 | { | |
3307 | struct breakpoint_objfile_data *bp_objfile_data; | |
3308 | ||
9a3c8263 SM |
3309 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3310 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3311 | if (bp_objfile_data == NULL) |
3312 | { | |
8d749320 SM |
3313 | bp_objfile_data = |
3314 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3315 | |
3316 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3317 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3318 | } | |
3319 | return bp_objfile_data; | |
3320 | } | |
3321 | ||
28106bc2 SDJ |
3322 | static void |
3323 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3324 | { | |
9a3c8263 SM |
3325 | struct breakpoint_objfile_data *bp_objfile_data |
3326 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3327 | |
3328 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3329 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3330 | } | |
3331 | ||
e62c965a | 3332 | static void |
af02033e | 3333 | create_overlay_event_breakpoint (void) |
e62c965a | 3334 | { |
69de3c6a | 3335 | struct objfile *objfile; |
af02033e | 3336 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3337 | |
69de3c6a PP |
3338 | ALL_OBJFILES (objfile) |
3339 | { | |
3340 | struct breakpoint *b; | |
17450429 PP |
3341 | struct breakpoint_objfile_data *bp_objfile_data; |
3342 | CORE_ADDR addr; | |
67994074 | 3343 | struct explicit_location explicit_loc; |
69de3c6a | 3344 | |
17450429 PP |
3345 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3346 | ||
3b7344d5 | 3347 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3348 | continue; |
3349 | ||
3b7344d5 | 3350 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3351 | { |
3b7344d5 | 3352 | struct bound_minimal_symbol m; |
17450429 PP |
3353 | |
3354 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3355 | if (m.minsym == NULL) |
17450429 PP |
3356 | { |
3357 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3358 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3359 | continue; |
3360 | } | |
3361 | bp_objfile_data->overlay_msym = m; | |
3362 | } | |
e62c965a | 3363 | |
77e371c0 | 3364 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3365 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3366 | bp_overlay_event, |
3367 | &internal_breakpoint_ops); | |
67994074 KS |
3368 | initialize_explicit_location (&explicit_loc); |
3369 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3370 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3371 | |
69de3c6a PP |
3372 | if (overlay_debugging == ovly_auto) |
3373 | { | |
3374 | b->enable_state = bp_enabled; | |
3375 | overlay_events_enabled = 1; | |
3376 | } | |
3377 | else | |
3378 | { | |
3379 | b->enable_state = bp_disabled; | |
3380 | overlay_events_enabled = 0; | |
3381 | } | |
e62c965a | 3382 | } |
e62c965a PP |
3383 | } |
3384 | ||
0fd8e87f | 3385 | static void |
af02033e | 3386 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3387 | { |
6c95b8df | 3388 | struct program_space *pspace; |
6c95b8df | 3389 | |
5ed8105e | 3390 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3391 | |
6c95b8df | 3392 | ALL_PSPACES (pspace) |
af02033e PP |
3393 | { |
3394 | struct objfile *objfile; | |
3395 | ||
3396 | set_current_program_space (pspace); | |
3397 | ||
3398 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3399 | { |
af02033e PP |
3400 | int i; |
3401 | struct gdbarch *gdbarch; | |
17450429 | 3402 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3403 | |
af02033e | 3404 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3405 | |
17450429 PP |
3406 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3407 | ||
28106bc2 SDJ |
3408 | if (!bp_objfile_data->longjmp_searched) |
3409 | { | |
25f9533e SDJ |
3410 | VEC (probe_p) *ret; |
3411 | ||
3412 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3413 | if (ret != NULL) | |
3414 | { | |
3415 | /* We are only interested in checking one element. */ | |
3416 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3417 | ||
3418 | if (!can_evaluate_probe_arguments (p)) | |
3419 | { | |
3420 | /* We cannot use the probe interface here, because it does | |
3421 | not know how to evaluate arguments. */ | |
3422 | VEC_free (probe_p, ret); | |
3423 | ret = NULL; | |
3424 | } | |
3425 | } | |
3426 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3427 | bp_objfile_data->longjmp_searched = 1; |
3428 | } | |
3429 | ||
3430 | if (bp_objfile_data->longjmp_probes != NULL) | |
3431 | { | |
3432 | int i; | |
3433 | struct probe *probe; | |
3434 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3435 | ||
3436 | for (i = 0; | |
3437 | VEC_iterate (probe_p, | |
3438 | bp_objfile_data->longjmp_probes, | |
3439 | i, probe); | |
3440 | ++i) | |
3441 | { | |
3442 | struct breakpoint *b; | |
3443 | ||
729662a5 TT |
3444 | b = create_internal_breakpoint (gdbarch, |
3445 | get_probe_address (probe, | |
3446 | objfile), | |
28106bc2 SDJ |
3447 | bp_longjmp_master, |
3448 | &internal_breakpoint_ops); | |
d28cd78a | 3449 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
28106bc2 SDJ |
3450 | b->enable_state = bp_disabled; |
3451 | } | |
3452 | ||
3453 | continue; | |
3454 | } | |
3455 | ||
0569175e TSD |
3456 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3457 | continue; | |
3458 | ||
17450429 | 3459 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3460 | { |
3461 | struct breakpoint *b; | |
af02033e | 3462 | const char *func_name; |
17450429 | 3463 | CORE_ADDR addr; |
67994074 | 3464 | struct explicit_location explicit_loc; |
6c95b8df | 3465 | |
3b7344d5 | 3466 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3467 | continue; |
0fd8e87f | 3468 | |
17450429 | 3469 | func_name = longjmp_names[i]; |
3b7344d5 | 3470 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3471 | { |
3b7344d5 | 3472 | struct bound_minimal_symbol m; |
17450429 PP |
3473 | |
3474 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3475 | if (m.minsym == NULL) |
17450429 PP |
3476 | { |
3477 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3478 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3479 | continue; |
3480 | } | |
3481 | bp_objfile_data->longjmp_msym[i] = m; | |
3482 | } | |
3483 | ||
77e371c0 | 3484 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3485 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3486 | &internal_breakpoint_ops); | |
67994074 KS |
3487 | initialize_explicit_location (&explicit_loc); |
3488 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3489 | b->location = new_explicit_location (&explicit_loc); |
af02033e PP |
3490 | b->enable_state = bp_disabled; |
3491 | } | |
0fd8e87f | 3492 | } |
af02033e | 3493 | } |
0fd8e87f UW |
3494 | } |
3495 | ||
af02033e | 3496 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3497 | static void |
af02033e | 3498 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3499 | { |
3500 | struct program_space *pspace; | |
af02033e | 3501 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3502 | |
5ed8105e | 3503 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3504 | |
3505 | ALL_PSPACES (pspace) | |
17450429 PP |
3506 | { |
3507 | struct objfile *objfile; | |
3508 | CORE_ADDR addr; | |
3509 | ||
3510 | set_current_program_space (pspace); | |
3511 | ||
aa7d318d TT |
3512 | ALL_OBJFILES (objfile) |
3513 | { | |
3514 | struct breakpoint *b; | |
17450429 | 3515 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3516 | struct explicit_location explicit_loc; |
aa7d318d | 3517 | |
17450429 | 3518 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3519 | |
3b7344d5 | 3520 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3521 | continue; |
3522 | ||
3b7344d5 | 3523 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3524 | { |
3b7344d5 | 3525 | struct bound_minimal_symbol m; |
17450429 PP |
3526 | |
3527 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3528 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3529 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3530 | { |
3531 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3532 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3533 | continue; |
3534 | } | |
3535 | bp_objfile_data->terminate_msym = m; | |
3536 | } | |
aa7d318d | 3537 | |
77e371c0 | 3538 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3539 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3540 | bp_std_terminate_master, |
3541 | &internal_breakpoint_ops); | |
67994074 KS |
3542 | initialize_explicit_location (&explicit_loc); |
3543 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3544 | b->location = new_explicit_location (&explicit_loc); |
aa7d318d TT |
3545 | b->enable_state = bp_disabled; |
3546 | } | |
17450429 | 3547 | } |
aa7d318d TT |
3548 | } |
3549 | ||
186c406b TT |
3550 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3551 | ||
70221824 | 3552 | static void |
186c406b TT |
3553 | create_exception_master_breakpoint (void) |
3554 | { | |
3555 | struct objfile *objfile; | |
17450429 | 3556 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3557 | |
3558 | ALL_OBJFILES (objfile) | |
3559 | { | |
17450429 PP |
3560 | struct breakpoint *b; |
3561 | struct gdbarch *gdbarch; | |
3562 | struct breakpoint_objfile_data *bp_objfile_data; | |
3563 | CORE_ADDR addr; | |
67994074 | 3564 | struct explicit_location explicit_loc; |
17450429 PP |
3565 | |
3566 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3567 | ||
28106bc2 SDJ |
3568 | /* We prefer the SystemTap probe point if it exists. */ |
3569 | if (!bp_objfile_data->exception_searched) | |
3570 | { | |
25f9533e SDJ |
3571 | VEC (probe_p) *ret; |
3572 | ||
3573 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3574 | ||
3575 | if (ret != NULL) | |
3576 | { | |
3577 | /* We are only interested in checking one element. */ | |
3578 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3579 | ||
3580 | if (!can_evaluate_probe_arguments (p)) | |
3581 | { | |
3582 | /* We cannot use the probe interface here, because it does | |
3583 | not know how to evaluate arguments. */ | |
3584 | VEC_free (probe_p, ret); | |
3585 | ret = NULL; | |
3586 | } | |
3587 | } | |
3588 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3589 | bp_objfile_data->exception_searched = 1; |
3590 | } | |
3591 | ||
3592 | if (bp_objfile_data->exception_probes != NULL) | |
3593 | { | |
3594 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3595 | int i; | |
3596 | struct probe *probe; | |
3597 | ||
3598 | for (i = 0; | |
3599 | VEC_iterate (probe_p, | |
3600 | bp_objfile_data->exception_probes, | |
3601 | i, probe); | |
3602 | ++i) | |
3603 | { | |
3604 | struct breakpoint *b; | |
3605 | ||
729662a5 TT |
3606 | b = create_internal_breakpoint (gdbarch, |
3607 | get_probe_address (probe, | |
3608 | objfile), | |
28106bc2 SDJ |
3609 | bp_exception_master, |
3610 | &internal_breakpoint_ops); | |
d28cd78a | 3611 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3612 | b->enable_state = bp_disabled; |
3613 | } | |
3614 | ||
3615 | continue; | |
3616 | } | |
3617 | ||
3618 | /* Otherwise, try the hook function. */ | |
3619 | ||
3b7344d5 | 3620 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3621 | continue; |
3622 | ||
3623 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3624 | |
3b7344d5 | 3625 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3626 | { |
3b7344d5 | 3627 | struct bound_minimal_symbol debug_hook; |
186c406b | 3628 | |
17450429 | 3629 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3630 | if (debug_hook.minsym == NULL) |
17450429 | 3631 | { |
3b7344d5 | 3632 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3633 | continue; |
3634 | } | |
3635 | ||
3636 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3637 | } |
17450429 | 3638 | |
77e371c0 | 3639 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3640 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3641 | ¤t_target); | |
06edf0c0 PA |
3642 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3643 | &internal_breakpoint_ops); | |
67994074 KS |
3644 | initialize_explicit_location (&explicit_loc); |
3645 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3646 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3647 | b->enable_state = bp_disabled; |
186c406b | 3648 | } |
186c406b TT |
3649 | } |
3650 | ||
9ef9e6a6 KS |
3651 | /* Does B have a location spec? */ |
3652 | ||
3653 | static int | |
3654 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3655 | { | |
d28cd78a | 3656 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3657 | } |
3658 | ||
c906108c | 3659 | void |
fba45db2 | 3660 | update_breakpoints_after_exec (void) |
c906108c | 3661 | { |
35df4500 | 3662 | struct breakpoint *b, *b_tmp; |
876fa593 | 3663 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3664 | |
25b22b0a PA |
3665 | /* We're about to delete breakpoints from GDB's lists. If the |
3666 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3667 | writing the breakpoints' "shadow contents" back into memory. The | |
3668 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3669 | do that. Instead, the target is responsible from marking | |
3670 | breakpoints out as soon as it detects an exec. We don't do that | |
3671 | here instead, because there may be other attempts to delete | |
3672 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3673 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3674 | if (bploc->pspace == current_program_space) |
3675 | gdb_assert (!bploc->inserted); | |
c906108c | 3676 | |
35df4500 | 3677 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3678 | { |
6c95b8df PA |
3679 | if (b->pspace != current_program_space) |
3680 | continue; | |
3681 | ||
4a64f543 | 3682 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3683 | if (b->type == bp_shlib_event) |
3684 | { | |
3685 | delete_breakpoint (b); | |
3686 | continue; | |
3687 | } | |
c906108c | 3688 | |
4a64f543 | 3689 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3690 | if (b->type == bp_jit_event) |
3691 | { | |
3692 | delete_breakpoint (b); | |
3693 | continue; | |
3694 | } | |
3695 | ||
1900040c | 3696 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3697 | as must overlay event and longjmp master breakpoints. */ |
3698 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3699 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3700 | || b->type == bp_exception_master) | |
c4093a6a JM |
3701 | { |
3702 | delete_breakpoint (b); | |
3703 | continue; | |
3704 | } | |
3705 | ||
4a64f543 | 3706 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3707 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3708 | { |
3709 | delete_breakpoint (b); | |
3710 | continue; | |
3711 | } | |
3712 | ||
7c16b83e PA |
3713 | /* Just like single-step breakpoints. */ |
3714 | if (b->type == bp_single_step) | |
3715 | { | |
3716 | delete_breakpoint (b); | |
3717 | continue; | |
3718 | } | |
3719 | ||
611c83ae PA |
3720 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3721 | after an exec. */ | |
186c406b | 3722 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3723 | || b->type == bp_longjmp_call_dummy |
186c406b | 3724 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3725 | { |
3726 | delete_breakpoint (b); | |
3727 | continue; | |
3728 | } | |
3729 | ||
ce78b96d JB |
3730 | if (b->type == bp_catchpoint) |
3731 | { | |
3732 | /* For now, none of the bp_catchpoint breakpoints need to | |
3733 | do anything at this point. In the future, if some of | |
3734 | the catchpoints need to something, we will need to add | |
3735 | a new method, and call this method from here. */ | |
3736 | continue; | |
3737 | } | |
3738 | ||
c5aa993b JM |
3739 | /* bp_finish is a special case. The only way we ought to be able |
3740 | to see one of these when an exec() has happened, is if the user | |
3741 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3742 | carries them to the call-site of the current callee, by setting | |
3743 | a temporary bp there and resuming. But in this case, the finish | |
3744 | will carry them entirely through the vfork & exec. | |
3745 | ||
3746 | We don't want to allow a bp_finish to remain inserted now. But | |
3747 | we can't safely delete it, 'cause finish_command has a handle to | |
3748 | the bp on a bpstat, and will later want to delete it. There's a | |
3749 | chance (and I've seen it happen) that if we delete the bp_finish | |
3750 | here, that its storage will get reused by the time finish_command | |
3751 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3752 | We really must allow finish_command to delete a bp_finish. | |
3753 | ||
e5dd4106 | 3754 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3755 | it's safe to delete something others may have handles to?" |
3756 | problem, what we'll do here is just uninsert the bp_finish, and | |
3757 | let finish_command delete it. | |
3758 | ||
3759 | (We know the bp_finish is "doomed" in the sense that it's | |
3760 | momentary, and will be deleted as soon as finish_command sees | |
3761 | the inferior stopped. So it doesn't matter that the bp's | |
3762 | address is probably bogus in the new a.out, unlike e.g., the | |
3763 | solib breakpoints.) */ | |
c5aa993b | 3764 | |
c5aa993b JM |
3765 | if (b->type == bp_finish) |
3766 | { | |
3767 | continue; | |
3768 | } | |
3769 | ||
3770 | /* Without a symbolic address, we have little hope of the | |
3771 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3772 | a.out. */ |
9ef9e6a6 | 3773 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3774 | { |
3775 | delete_breakpoint (b); | |
3776 | continue; | |
3777 | } | |
c5aa993b | 3778 | } |
c906108c SS |
3779 | } |
3780 | ||
3781 | int | |
d80ee84f | 3782 | detach_breakpoints (ptid_t ptid) |
c906108c | 3783 | { |
35df4500 | 3784 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3785 | int val = 0; |
2989a365 | 3786 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3787 | struct inferior *inf = current_inferior (); |
c5aa993b | 3788 | |
dfd4cc63 | 3789 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3790 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3791 | |
6c95b8df | 3792 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3793 | inferior_ptid = ptid; |
35df4500 | 3794 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3795 | { |
35df4500 | 3796 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3797 | continue; |
3798 | ||
bd9673a4 PW |
3799 | /* This function must physically remove breakpoints locations |
3800 | from the specified ptid, without modifying the breakpoint | |
3801 | package's state. Locations of type bp_loc_other are only | |
3802 | maintained at GDB side. So, there is no need to remove | |
3803 | these bp_loc_other locations. Moreover, removing these | |
3804 | would modify the breakpoint package's state. */ | |
3805 | if (bl->loc_type == bp_loc_other) | |
3806 | continue; | |
3807 | ||
35df4500 | 3808 | if (bl->inserted) |
b2b6a7da | 3809 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3810 | } |
d03285ec | 3811 | |
3a1bae8e | 3812 | return val; |
c906108c SS |
3813 | } |
3814 | ||
35df4500 | 3815 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3816 | Note that this is used to detach breakpoints from a child fork. |
3817 | When we get here, the child isn't in the inferior list, and neither | |
3818 | do we have objects to represent its address space --- we should | |
35df4500 | 3819 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3820 | |
c906108c | 3821 | static int |
b2b6a7da | 3822 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3823 | { |
3824 | int val; | |
c5aa993b | 3825 | |
35df4500 TJB |
3826 | /* BL is never in moribund_locations by our callers. */ |
3827 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3828 | |
74960c60 VP |
3829 | /* The type of none suggests that owner is actually deleted. |
3830 | This should not ever happen. */ | |
35df4500 | 3831 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3832 | |
35df4500 TJB |
3833 | if (bl->loc_type == bp_loc_software_breakpoint |
3834 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3835 | { |
c02f5703 MS |
3836 | /* "Normal" instruction breakpoint: either the standard |
3837 | trap-instruction bp (bp_breakpoint), or a | |
3838 | bp_hardware_breakpoint. */ | |
3839 | ||
3840 | /* First check to see if we have to handle an overlay. */ | |
3841 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3842 | || bl->section == NULL |
3843 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3844 | { |
3845 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3846 | |
3847 | /* If we're trying to uninsert a memory breakpoint that we | |
3848 | know is set in a dynamic object that is marked | |
3849 | shlib_disabled, then either the dynamic object was | |
3850 | removed with "remove-symbol-file" or with | |
3851 | "nosharedlibrary". In the former case, we don't know | |
3852 | whether another dynamic object might have loaded over the | |
3853 | breakpoint's address -- the user might well let us know | |
3854 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3855 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3856 | list of dynamically loaded objects). If we have the |
3857 | breakpoint's shadow memory, that is, this is a software | |
3858 | breakpoint managed by GDB, check whether the breakpoint | |
3859 | is still inserted in memory, to avoid overwriting wrong | |
3860 | code with stale saved shadow contents. Note that HW | |
3861 | breakpoints don't have shadow memory, as they're | |
3862 | implemented using a mechanism that is not dependent on | |
3863 | being able to modify the target's memory, and as such | |
3864 | they should always be removed. */ | |
3865 | if (bl->shlib_disabled | |
3866 | && bl->target_info.shadow_len != 0 | |
3867 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3868 | val = 0; | |
3869 | else | |
73971819 | 3870 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3871 | } |
c906108c SS |
3872 | else |
3873 | { | |
4a64f543 | 3874 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3875 | Did we set a breakpoint at the LMA? */ |
3876 | if (!overlay_events_enabled) | |
3877 | { | |
3878 | /* Yes -- overlay event support is not active, so we | |
3879 | should have set a breakpoint at the LMA. Remove it. | |
3880 | */ | |
c02f5703 MS |
3881 | /* Ignore any failures: if the LMA is in ROM, we will |
3882 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3883 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3884 | target_remove_hw_breakpoint (bl->gdbarch, | |
3885 | &bl->overlay_target_info); | |
c02f5703 | 3886 | else |
35df4500 | 3887 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
3888 | &bl->overlay_target_info, |
3889 | reason); | |
c02f5703 MS |
3890 | } |
3891 | /* Did we set a breakpoint at the VMA? | |
3892 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 3893 | if (bl->inserted) |
c906108c | 3894 | { |
c02f5703 MS |
3895 | /* Yes -- remove it. Previously we did not bother to |
3896 | remove the breakpoint if the section had been | |
3897 | unmapped, but let's not rely on that being safe. We | |
3898 | don't know what the overlay manager might do. */ | |
aa67235e UW |
3899 | |
3900 | /* However, we should remove *software* breakpoints only | |
3901 | if the section is still mapped, or else we overwrite | |
3902 | wrong code with the saved shadow contents. */ | |
348d480f PA |
3903 | if (bl->loc_type == bp_loc_hardware_breakpoint |
3904 | || section_is_mapped (bl->section)) | |
73971819 | 3905 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
3906 | else |
3907 | val = 0; | |
c906108c | 3908 | } |
c02f5703 MS |
3909 | else |
3910 | { | |
3911 | /* No -- not inserted, so no need to remove. No error. */ | |
3912 | val = 0; | |
3913 | } | |
c906108c | 3914 | } |
879d1e6b | 3915 | |
08351840 PA |
3916 | /* In some cases, we might not be able to remove a breakpoint in |
3917 | a shared library that has already been removed, but we have | |
3918 | not yet processed the shlib unload event. Similarly for an | |
3919 | unloaded add-symbol-file object - the user might not yet have | |
3920 | had the chance to remove-symbol-file it. shlib_disabled will | |
3921 | be set if the library/object has already been removed, but | |
3922 | the breakpoint hasn't been uninserted yet, e.g., after | |
3923 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
3924 | always-inserted mode. */ | |
076855f9 | 3925 | if (val |
08351840 PA |
3926 | && (bl->loc_type == bp_loc_software_breakpoint |
3927 | && (bl->shlib_disabled | |
3928 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
3929 | || shared_objfile_contains_address_p (bl->pspace, |
3930 | bl->address)))) | |
879d1e6b UW |
3931 | val = 0; |
3932 | ||
c906108c SS |
3933 | if (val) |
3934 | return val; | |
b2b6a7da | 3935 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 3936 | } |
35df4500 | 3937 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 3938 | { |
77b06cd7 TJB |
3939 | gdb_assert (bl->owner->ops != NULL |
3940 | && bl->owner->ops->remove_location != NULL); | |
3941 | ||
b2b6a7da | 3942 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 3943 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 3944 | |
c906108c | 3945 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 3946 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 3947 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 3948 | bl->owner->number); |
c906108c | 3949 | } |
35df4500 TJB |
3950 | else if (bl->owner->type == bp_catchpoint |
3951 | && breakpoint_enabled (bl->owner) | |
3952 | && !bl->duplicate) | |
ce78b96d | 3953 | { |
77b06cd7 TJB |
3954 | gdb_assert (bl->owner->ops != NULL |
3955 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 3956 | |
73971819 | 3957 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
3958 | if (val) |
3959 | return val; | |
77b06cd7 | 3960 | |
b2b6a7da | 3961 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 3962 | } |
c906108c SS |
3963 | |
3964 | return 0; | |
3965 | } | |
3966 | ||
6c95b8df | 3967 | static int |
834c0d03 | 3968 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 3969 | { |
35df4500 TJB |
3970 | /* BL is never in moribund_locations by our callers. */ |
3971 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3972 | |
6c95b8df PA |
3973 | /* The type of none suggests that owner is actually deleted. |
3974 | This should not ever happen. */ | |
35df4500 | 3975 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 3976 | |
5ed8105e | 3977 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3978 | |
35df4500 | 3979 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 3980 | |
5ed8105e | 3981 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
3982 | } |
3983 | ||
c906108c SS |
3984 | /* Clear the "inserted" flag in all breakpoints. */ |
3985 | ||
25b22b0a | 3986 | void |
fba45db2 | 3987 | mark_breakpoints_out (void) |
c906108c | 3988 | { |
35df4500 | 3989 | struct bp_location *bl, **blp_tmp; |
c906108c | 3990 | |
35df4500 | 3991 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 3992 | if (bl->pspace == current_program_space) |
35df4500 | 3993 | bl->inserted = 0; |
c906108c SS |
3994 | } |
3995 | ||
53a5351d JM |
3996 | /* Clear the "inserted" flag in all breakpoints and delete any |
3997 | breakpoints which should go away between runs of the program. | |
c906108c SS |
3998 | |
3999 | Plus other such housekeeping that has to be done for breakpoints | |
4000 | between runs. | |
4001 | ||
53a5351d JM |
4002 | Note: this function gets called at the end of a run (by |
4003 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4004 | init_wait_for_inferior). */ |
c906108c SS |
4005 | |
4006 | ||
4007 | ||
4008 | void | |
fba45db2 | 4009 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4010 | { |
35df4500 | 4011 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4012 | struct bp_location *bl; |
1c5cfe86 | 4013 | int ix; |
6c95b8df | 4014 | struct program_space *pspace = current_program_space; |
c906108c | 4015 | |
50c71eaf PA |
4016 | /* If breakpoint locations are shared across processes, then there's |
4017 | nothing to do. */ | |
f5656ead | 4018 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4019 | return; |
4020 | ||
1a853c52 | 4021 | mark_breakpoints_out (); |
075f6582 | 4022 | |
35df4500 | 4023 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4024 | { |
6c95b8df PA |
4025 | if (b->loc && b->loc->pspace != pspace) |
4026 | continue; | |
4027 | ||
c5aa993b JM |
4028 | switch (b->type) |
4029 | { | |
4030 | case bp_call_dummy: | |
e2e4d78b | 4031 | case bp_longjmp_call_dummy: |
c906108c | 4032 | |
c5aa993b | 4033 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4034 | cause problems when the inferior is rerun, so we better get |
4035 | rid of it. */ | |
4036 | ||
4037 | case bp_watchpoint_scope: | |
4038 | ||
4039 | /* Also get rid of scope breakpoints. */ | |
4040 | ||
4041 | case bp_shlib_event: | |
4042 | ||
4043 | /* Also remove solib event breakpoints. Their addresses may | |
4044 | have changed since the last time we ran the program. | |
4045 | Actually we may now be debugging against different target; | |
4046 | and so the solib backend that installed this breakpoint may | |
4047 | not be used in by the target. E.g., | |
4048 | ||
4049 | (gdb) file prog-linux | |
4050 | (gdb) run # native linux target | |
4051 | ... | |
4052 | (gdb) kill | |
4053 | (gdb) file prog-win.exe | |
4054 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4055 | */ | |
c906108c | 4056 | |
f59f708a PA |
4057 | case bp_step_resume: |
4058 | ||
4059 | /* Also remove step-resume breakpoints. */ | |
4060 | ||
7c16b83e PA |
4061 | case bp_single_step: |
4062 | ||
4063 | /* Also remove single-step breakpoints. */ | |
4064 | ||
c5aa993b JM |
4065 | delete_breakpoint (b); |
4066 | break; | |
c906108c | 4067 | |
c5aa993b JM |
4068 | case bp_watchpoint: |
4069 | case bp_hardware_watchpoint: | |
4070 | case bp_read_watchpoint: | |
4071 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4072 | { |
4073 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4074 | |
3a5c3e22 PA |
4075 | /* Likewise for watchpoints on local expressions. */ |
4076 | if (w->exp_valid_block != NULL) | |
4077 | delete_breakpoint (b); | |
63000888 | 4078 | else |
3a5c3e22 | 4079 | { |
63000888 PA |
4080 | /* Get rid of existing locations, which are no longer |
4081 | valid. New ones will be created in | |
4082 | update_watchpoint, when the inferior is restarted. | |
4083 | The next update_global_location_list call will | |
4084 | garbage collect them. */ | |
4085 | b->loc = NULL; | |
4086 | ||
4087 | if (context == inf_starting) | |
4088 | { | |
4089 | /* Reset val field to force reread of starting value in | |
4090 | insert_breakpoints. */ | |
4091 | if (w->val) | |
4092 | value_free (w->val); | |
4093 | w->val = NULL; | |
4094 | w->val_valid = 0; | |
4095 | } | |
4096 | } | |
3a5c3e22 | 4097 | } |
c5aa993b JM |
4098 | break; |
4099 | default: | |
c5aa993b JM |
4100 | break; |
4101 | } | |
4102 | } | |
1c5cfe86 PA |
4103 | |
4104 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4105 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4106 | decref_bp_location (&bl); | |
1c5cfe86 | 4107 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4108 | } |
4109 | ||
6c95b8df PA |
4110 | /* These functions concern about actual breakpoints inserted in the |
4111 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4112 | we need to hop over the bkpt --- so we check for address space | |
4113 | match, not program space. */ | |
4114 | ||
c2c6d25f JM |
4115 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4116 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4117 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4118 | permanent breakpoint. | |
4119 | - When continuing from a location with an ordinary breakpoint, we | |
4120 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4121 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4122 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4123 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4124 | |
c2c6d25f | 4125 | enum breakpoint_here |
6c95b8df | 4126 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4127 | { |
35df4500 | 4128 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4129 | int any_breakpoint_here = 0; |
c906108c | 4130 | |
35df4500 | 4131 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4132 | { |
35df4500 TJB |
4133 | if (bl->loc_type != bp_loc_software_breakpoint |
4134 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4135 | continue; |
4136 | ||
f1310107 | 4137 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4138 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4139 | || bl->permanent) |
f1310107 | 4140 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4141 | { |
4142 | if (overlay_debugging | |
35df4500 TJB |
4143 | && section_is_overlay (bl->section) |
4144 | && !section_is_mapped (bl->section)) | |
075f6582 | 4145 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4146 | else if (bl->permanent) |
075f6582 DJ |
4147 | return permanent_breakpoint_here; |
4148 | else | |
4149 | any_breakpoint_here = 1; | |
4150 | } | |
4151 | } | |
c906108c | 4152 | |
f486487f | 4153 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4154 | } |
4155 | ||
d35ae833 PA |
4156 | /* See breakpoint.h. */ |
4157 | ||
4158 | int | |
4159 | breakpoint_in_range_p (struct address_space *aspace, | |
4160 | CORE_ADDR addr, ULONGEST len) | |
4161 | { | |
4162 | struct bp_location *bl, **blp_tmp; | |
4163 | ||
4164 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4165 | { | |
4166 | if (bl->loc_type != bp_loc_software_breakpoint | |
4167 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4168 | continue; | |
4169 | ||
4170 | if ((breakpoint_enabled (bl->owner) | |
4171 | || bl->permanent) | |
4172 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4173 | addr, len)) | |
4174 | { | |
4175 | if (overlay_debugging | |
4176 | && section_is_overlay (bl->section) | |
4177 | && !section_is_mapped (bl->section)) | |
4178 | { | |
4179 | /* Unmapped overlay -- can't be a match. */ | |
4180 | continue; | |
4181 | } | |
4182 | ||
4183 | return 1; | |
4184 | } | |
4185 | } | |
4186 | ||
4187 | return 0; | |
4188 | } | |
4189 | ||
1c5cfe86 PA |
4190 | /* Return true if there's a moribund breakpoint at PC. */ |
4191 | ||
4192 | int | |
6c95b8df | 4193 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4194 | { |
4195 | struct bp_location *loc; | |
4196 | int ix; | |
4197 | ||
4198 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4199 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4200 | return 1; |
4201 | ||
4202 | return 0; | |
4203 | } | |
c2c6d25f | 4204 | |
f7ce857f PA |
4205 | /* Returns non-zero iff BL is inserted at PC, in address space |
4206 | ASPACE. */ | |
4207 | ||
4208 | static int | |
4209 | bp_location_inserted_here_p (struct bp_location *bl, | |
4210 | struct address_space *aspace, CORE_ADDR pc) | |
4211 | { | |
4212 | if (bl->inserted | |
4213 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4214 | aspace, pc)) | |
4215 | { | |
4216 | if (overlay_debugging | |
4217 | && section_is_overlay (bl->section) | |
4218 | && !section_is_mapped (bl->section)) | |
4219 | return 0; /* unmapped overlay -- can't be a match */ | |
4220 | else | |
4221 | return 1; | |
4222 | } | |
4223 | return 0; | |
4224 | } | |
4225 | ||
a1fd2fa5 | 4226 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4227 | |
4228 | int | |
a1fd2fa5 | 4229 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4230 | { |
f7ce857f | 4231 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4232 | |
f7ce857f | 4233 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4234 | { |
f7ce857f PA |
4235 | struct bp_location *bl = *blp; |
4236 | ||
35df4500 TJB |
4237 | if (bl->loc_type != bp_loc_software_breakpoint |
4238 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4239 | continue; |
4240 | ||
f7ce857f PA |
4241 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4242 | return 1; | |
c5aa993b | 4243 | } |
c36b740a VP |
4244 | return 0; |
4245 | } | |
4246 | ||
a1fd2fa5 PA |
4247 | /* This function returns non-zero iff there is a software breakpoint |
4248 | inserted at PC. */ | |
c36b740a VP |
4249 | |
4250 | int | |
a1fd2fa5 PA |
4251 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4252 | CORE_ADDR pc) | |
4fa8626c | 4253 | { |
f7ce857f | 4254 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4255 | |
f7ce857f | 4256 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4257 | { |
f7ce857f PA |
4258 | struct bp_location *bl = *blp; |
4259 | ||
35df4500 | 4260 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4261 | continue; |
4262 | ||
f7ce857f PA |
4263 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4264 | return 1; | |
4fa8626c DJ |
4265 | } |
4266 | ||
4267 | return 0; | |
9c02b525 PA |
4268 | } |
4269 | ||
4270 | /* See breakpoint.h. */ | |
4271 | ||
4272 | int | |
4273 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4274 | CORE_ADDR pc) | |
4275 | { | |
4276 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4277 | |
4278 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4279 | { | |
4280 | struct bp_location *bl = *blp; | |
4281 | ||
4282 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4283 | continue; | |
4284 | ||
4285 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4286 | return 1; | |
4287 | } | |
4288 | ||
4289 | return 0; | |
4fa8626c DJ |
4290 | } |
4291 | ||
9093389c PA |
4292 | int |
4293 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4294 | CORE_ADDR addr, ULONGEST len) | |
4295 | { | |
4296 | struct breakpoint *bpt; | |
4297 | ||
4298 | ALL_BREAKPOINTS (bpt) | |
4299 | { | |
4300 | struct bp_location *loc; | |
4301 | ||
4302 | if (bpt->type != bp_hardware_watchpoint | |
4303 | && bpt->type != bp_access_watchpoint) | |
4304 | continue; | |
4305 | ||
4306 | if (!breakpoint_enabled (bpt)) | |
4307 | continue; | |
4308 | ||
4309 | for (loc = bpt->loc; loc; loc = loc->next) | |
4310 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4311 | { | |
4312 | CORE_ADDR l, h; | |
4313 | ||
4314 | /* Check for intersection. */ | |
768adc05 PA |
4315 | l = std::max<CORE_ADDR> (loc->address, addr); |
4316 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4317 | if (l < h) |
4318 | return 1; | |
4319 | } | |
4320 | } | |
4321 | return 0; | |
4322 | } | |
c906108c | 4323 | \f |
c5aa993b | 4324 | |
c906108c SS |
4325 | /* bpstat stuff. External routines' interfaces are documented |
4326 | in breakpoint.h. */ | |
4327 | ||
4328 | int | |
c326b90e | 4329 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4330 | { |
533be4dd | 4331 | return (ep->type == bp_catchpoint); |
c906108c SS |
4332 | } |
4333 | ||
f431efe5 PA |
4334 | /* Frees any storage that is part of a bpstat. Does not walk the |
4335 | 'next' chain. */ | |
4336 | ||
04afa70c | 4337 | bpstats::~bpstats () |
198757a8 | 4338 | { |
04afa70c TT |
4339 | if (old_val != NULL) |
4340 | value_free (old_val); | |
04afa70c TT |
4341 | if (bp_location_at != NULL) |
4342 | decref_bp_location (&bp_location_at); | |
198757a8 VP |
4343 | } |
4344 | ||
c906108c SS |
4345 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4346 | Also free any storage that is part of a bpstat. */ | |
4347 | ||
4348 | void | |
fba45db2 | 4349 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4350 | { |
4351 | bpstat p; | |
4352 | bpstat q; | |
4353 | ||
4354 | if (bsp == 0) | |
4355 | return; | |
4356 | p = *bsp; | |
4357 | while (p != NULL) | |
4358 | { | |
4359 | q = p->next; | |
04afa70c | 4360 | delete p; |
c906108c SS |
4361 | p = q; |
4362 | } | |
4363 | *bsp = NULL; | |
4364 | } | |
4365 | ||
04afa70c TT |
4366 | bpstats::bpstats (const bpstats &other) |
4367 | : next (NULL), | |
4368 | bp_location_at (other.bp_location_at), | |
4369 | breakpoint_at (other.breakpoint_at), | |
4370 | commands (other.commands), | |
4371 | old_val (other.old_val), | |
4372 | print (other.print), | |
4373 | stop (other.stop), | |
4374 | print_it (other.print_it) | |
4375 | { | |
4376 | if (old_val != NULL) | |
4377 | { | |
4378 | old_val = value_copy (old_val); | |
4379 | release_value (old_val); | |
4380 | } | |
4381 | incref_bp_location (bp_location_at); | |
04afa70c TT |
4382 | } |
4383 | ||
c906108c SS |
4384 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
4385 | is part of the bpstat is copied as well. */ | |
4386 | ||
4387 | bpstat | |
fba45db2 | 4388 | bpstat_copy (bpstat bs) |
c906108c SS |
4389 | { |
4390 | bpstat p = NULL; | |
4391 | bpstat tmp; | |
4392 | bpstat retval = NULL; | |
4393 | ||
4394 | if (bs == NULL) | |
4395 | return bs; | |
4396 | ||
4397 | for (; bs != NULL; bs = bs->next) | |
4398 | { | |
04afa70c | 4399 | tmp = new bpstats (*bs); |
31cc81e9 | 4400 | |
c906108c SS |
4401 | if (p == NULL) |
4402 | /* This is the first thing in the chain. */ | |
4403 | retval = tmp; | |
4404 | else | |
4405 | p->next = tmp; | |
4406 | p = tmp; | |
4407 | } | |
4408 | p->next = NULL; | |
4409 | return retval; | |
4410 | } | |
4411 | ||
4a64f543 | 4412 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4413 | |
4414 | bpstat | |
fba45db2 | 4415 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4416 | { |
c5aa993b JM |
4417 | if (bsp == NULL) |
4418 | return NULL; | |
c906108c | 4419 | |
c5aa993b JM |
4420 | for (; bsp != NULL; bsp = bsp->next) |
4421 | { | |
f431efe5 | 4422 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4423 | return bsp; |
4424 | } | |
c906108c SS |
4425 | return NULL; |
4426 | } | |
4427 | ||
ab04a2af TT |
4428 | /* See breakpoint.h. */ |
4429 | ||
47591c29 | 4430 | int |
427cd150 | 4431 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4432 | { |
ab04a2af TT |
4433 | for (; bsp != NULL; bsp = bsp->next) |
4434 | { | |
427cd150 TT |
4435 | if (bsp->breakpoint_at == NULL) |
4436 | { | |
4437 | /* A moribund location can never explain a signal other than | |
4438 | GDB_SIGNAL_TRAP. */ | |
4439 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4440 | return 1; |
427cd150 TT |
4441 | } |
4442 | else | |
47591c29 PA |
4443 | { |
4444 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4445 | sig)) | |
4446 | return 1; | |
4447 | } | |
ab04a2af TT |
4448 | } |
4449 | ||
47591c29 | 4450 | return 0; |
ab04a2af TT |
4451 | } |
4452 | ||
4a64f543 MS |
4453 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4454 | stopped at. *BSP upon return is a bpstat which points to the | |
4455 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4456 | good for anything but further calls to bpstat_num). | |
4457 | ||
8671a17b PA |
4458 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4459 | Return -1 if stopped at a breakpoint that has been deleted since | |
4460 | we set it. | |
4461 | Return 1 otherwise. */ | |
c906108c SS |
4462 | |
4463 | int | |
8671a17b | 4464 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4465 | { |
4466 | struct breakpoint *b; | |
4467 | ||
4468 | if ((*bsp) == NULL) | |
4469 | return 0; /* No more breakpoint values */ | |
8671a17b | 4470 | |
4a64f543 MS |
4471 | /* We assume we'll never have several bpstats that correspond to a |
4472 | single breakpoint -- otherwise, this function might return the | |
4473 | same number more than once and this will look ugly. */ | |
f431efe5 | 4474 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4475 | *bsp = (*bsp)->next; |
4476 | if (b == NULL) | |
4477 | return -1; /* breakpoint that's been deleted since */ | |
4478 | ||
4479 | *num = b->number; /* We have its number */ | |
4480 | return 1; | |
c906108c SS |
4481 | } |
4482 | ||
e93ca019 | 4483 | /* See breakpoint.h. */ |
c906108c SS |
4484 | |
4485 | void | |
e93ca019 | 4486 | bpstat_clear_actions (void) |
c906108c | 4487 | { |
e93ca019 JK |
4488 | struct thread_info *tp; |
4489 | bpstat bs; | |
4490 | ||
4491 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4492 | return; | |
4493 | ||
4494 | tp = find_thread_ptid (inferior_ptid); | |
4495 | if (tp == NULL) | |
4496 | return; | |
4497 | ||
4498 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4499 | { |
d1b0a7bf | 4500 | bs->commands = NULL; |
abf85f46 | 4501 | |
c906108c SS |
4502 | if (bs->old_val != NULL) |
4503 | { | |
4504 | value_free (bs->old_val); | |
4505 | bs->old_val = NULL; | |
4506 | } | |
4507 | } | |
4508 | } | |
4509 | ||
f3b1572e PA |
4510 | /* Called when a command is about to proceed the inferior. */ |
4511 | ||
4512 | static void | |
4513 | breakpoint_about_to_proceed (void) | |
4514 | { | |
4515 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4516 | { | |
4517 | struct thread_info *tp = inferior_thread (); | |
4518 | ||
4519 | /* Allow inferior function calls in breakpoint commands to not | |
4520 | interrupt the command list. When the call finishes | |
4521 | successfully, the inferior will be standing at the same | |
4522 | breakpoint as if nothing happened. */ | |
16c381f0 | 4523 | if (tp->control.in_infcall) |
f3b1572e PA |
4524 | return; |
4525 | } | |
4526 | ||
4527 | breakpoint_proceeded = 1; | |
4528 | } | |
4529 | ||
4a64f543 MS |
4530 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4531 | command. */ | |
c906108c | 4532 | static void |
4efb68b1 | 4533 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4534 | { |
4535 | executing_breakpoint_commands = 0; | |
4536 | } | |
4537 | ||
abf85f46 JK |
4538 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4539 | or its equivalent. */ | |
4540 | ||
4541 | static int | |
4542 | command_line_is_silent (struct command_line *cmd) | |
4543 | { | |
4f45d445 | 4544 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4545 | } |
4546 | ||
4a64f543 MS |
4547 | /* Execute all the commands associated with all the breakpoints at |
4548 | this location. Any of these commands could cause the process to | |
4549 | proceed beyond this point, etc. We look out for such changes by | |
4550 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4551 | |
347bddb7 PA |
4552 | Returns true if a breakpoint command resumed the inferior. In that |
4553 | case, it is the caller's responsibility to recall it again with the | |
4554 | bpstat of the current thread. */ | |
4555 | ||
4556 | static int | |
4557 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4558 | { |
4559 | bpstat bs; | |
4560 | struct cleanup *old_chain; | |
347bddb7 | 4561 | int again = 0; |
c906108c SS |
4562 | |
4563 | /* Avoid endless recursion if a `source' command is contained | |
4564 | in bs->commands. */ | |
4565 | if (executing_breakpoint_commands) | |
347bddb7 | 4566 | return 0; |
c906108c SS |
4567 | |
4568 | executing_breakpoint_commands = 1; | |
4569 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4570 | ||
1ac32117 | 4571 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4572 | |
4a64f543 | 4573 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4574 | bs = *bsp; |
4575 | ||
4576 | breakpoint_proceeded = 0; | |
4577 | for (; bs != NULL; bs = bs->next) | |
4578 | { | |
d1b0a7bf | 4579 | struct command_line *cmd = NULL; |
6c50ab1c JB |
4580 | |
4581 | /* Take ownership of the BSP's command tree, if it has one. | |
4582 | ||
4583 | The command tree could legitimately contain commands like | |
4584 | 'step' and 'next', which call clear_proceed_status, which | |
4585 | frees stop_bpstat's command tree. To make sure this doesn't | |
4586 | free the tree we're executing out from under us, we need to | |
4587 | take ownership of the tree ourselves. Since a given bpstat's | |
4588 | commands are only executed once, we don't need to copy it; we | |
4589 | can clear the pointer in the bpstat, and make sure we free | |
4590 | the tree when we're done. */ | |
d1b0a7bf | 4591 | counted_command_line ccmd = bs->commands; |
9add0f1b | 4592 | bs->commands = NULL; |
d1b0a7bf TT |
4593 | if (ccmd != NULL) |
4594 | cmd = ccmd.get (); | |
abf85f46 JK |
4595 | if (command_line_is_silent (cmd)) |
4596 | { | |
4597 | /* The action has been already done by bpstat_stop_status. */ | |
4598 | cmd = cmd->next; | |
4599 | } | |
6c50ab1c | 4600 | |
c906108c SS |
4601 | while (cmd != NULL) |
4602 | { | |
4603 | execute_control_command (cmd); | |
4604 | ||
4605 | if (breakpoint_proceeded) | |
4606 | break; | |
4607 | else | |
4608 | cmd = cmd->next; | |
4609 | } | |
6c50ab1c | 4610 | |
c906108c | 4611 | if (breakpoint_proceeded) |
32c1e744 | 4612 | { |
cb814510 | 4613 | if (current_ui->async) |
347bddb7 PA |
4614 | /* If we are in async mode, then the target might be still |
4615 | running, not stopped at any breakpoint, so nothing for | |
4616 | us to do here -- just return to the event loop. */ | |
4617 | ; | |
32c1e744 VP |
4618 | else |
4619 | /* In sync mode, when execute_control_command returns | |
4620 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4621 | Breakpoint commands for that stop were not run, since |
4622 | execute_command does not run breakpoint commands -- | |
4623 | only command_line_handler does, but that one is not | |
4624 | involved in execution of breakpoint commands. So, we | |
4625 | can now execute breakpoint commands. It should be | |
4626 | noted that making execute_command do bpstat actions is | |
4627 | not an option -- in this case we'll have recursive | |
4628 | invocation of bpstat for each breakpoint with a | |
4629 | command, and can easily blow up GDB stack. Instead, we | |
4630 | return true, which will trigger the caller to recall us | |
4631 | with the new stop_bpstat. */ | |
4632 | again = 1; | |
4633 | break; | |
32c1e744 | 4634 | } |
c906108c | 4635 | } |
c2b8ed2c | 4636 | do_cleanups (old_chain); |
347bddb7 PA |
4637 | return again; |
4638 | } | |
4639 | ||
4640 | void | |
4641 | bpstat_do_actions (void) | |
4642 | { | |
353d1d73 JK |
4643 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4644 | ||
347bddb7 PA |
4645 | /* Do any commands attached to breakpoint we are stopped at. */ |
4646 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4647 | && target_has_execution | |
4648 | && !is_exited (inferior_ptid) | |
4649 | && !is_executing (inferior_ptid)) | |
4650 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4651 | and only return when it is stopped at the next breakpoint, we | |
4652 | keep doing breakpoint actions until it returns false to | |
4653 | indicate the inferior was not resumed. */ | |
16c381f0 | 4654 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4655 | break; |
353d1d73 JK |
4656 | |
4657 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4658 | } |
4659 | ||
fa4727a6 DJ |
4660 | /* Print out the (old or new) value associated with a watchpoint. */ |
4661 | ||
4662 | static void | |
4663 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4664 | { | |
4665 | if (val == NULL) | |
4666 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4667 | else | |
79a45b7d TT |
4668 | { |
4669 | struct value_print_options opts; | |
4670 | get_user_print_options (&opts); | |
4671 | value_print (val, stream, &opts); | |
4672 | } | |
fa4727a6 DJ |
4673 | } |
4674 | ||
f303dbd6 PA |
4675 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4676 | debugging multiple threads. */ | |
4677 | ||
4678 | void | |
4679 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4680 | { | |
112e8700 | 4681 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4682 | return; |
4683 | ||
112e8700 | 4684 | uiout->text ("\n"); |
f303dbd6 PA |
4685 | |
4686 | if (show_thread_that_caused_stop ()) | |
4687 | { | |
4688 | const char *name; | |
4689 | struct thread_info *thr = inferior_thread (); | |
4690 | ||
112e8700 SM |
4691 | uiout->text ("Thread "); |
4692 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4693 | |
4694 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4695 | if (name != NULL) | |
4696 | { | |
112e8700 SM |
4697 | uiout->text (" \""); |
4698 | uiout->field_fmt ("name", "%s", name); | |
4699 | uiout->text ("\""); | |
f303dbd6 PA |
4700 | } |
4701 | ||
112e8700 | 4702 | uiout->text (" hit "); |
f303dbd6 PA |
4703 | } |
4704 | } | |
4705 | ||
e514a9d6 | 4706 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4707 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4708 | 'print_it' in the bpstat structure. Under some circumstances we |
4709 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4710 | normal_stop(). */ |
e514a9d6 JM |
4711 | |
4712 | static enum print_stop_action | |
4713 | print_bp_stop_message (bpstat bs) | |
4714 | { | |
4715 | switch (bs->print_it) | |
4716 | { | |
4717 | case print_it_noop: | |
4a64f543 | 4718 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4719 | return PRINT_UNKNOWN; |
4720 | break; | |
4721 | ||
4722 | case print_it_done: | |
4723 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4724 | relevant messages. */ |
e514a9d6 JM |
4725 | return PRINT_SRC_AND_LOC; |
4726 | break; | |
4727 | ||
4728 | case print_it_normal: | |
4f8d1dc6 | 4729 | { |
f431efe5 PA |
4730 | struct breakpoint *b = bs->breakpoint_at; |
4731 | ||
1a6a67de TJB |
4732 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4733 | which has since been deleted. */ | |
4734 | if (b == NULL) | |
4735 | return PRINT_UNKNOWN; | |
4736 | ||
348d480f PA |
4737 | /* Normal case. Call the breakpoint's print_it method. */ |
4738 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4739 | } |
348d480f | 4740 | break; |
3086aeae | 4741 | |
e514a9d6 | 4742 | default: |
8e65ff28 | 4743 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4744 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4745 | break; |
c906108c | 4746 | } |
c906108c SS |
4747 | } |
4748 | ||
edcc5120 TT |
4749 | /* A helper function that prints a shared library stopped event. */ |
4750 | ||
4751 | static void | |
4752 | print_solib_event (int is_catchpoint) | |
4753 | { | |
4754 | int any_deleted | |
4755 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4756 | int any_added | |
4757 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4758 | ||
4759 | if (!is_catchpoint) | |
4760 | { | |
4761 | if (any_added || any_deleted) | |
112e8700 | 4762 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4763 | else |
112e8700 SM |
4764 | current_uiout->text (_("Stopped due to shared library event (no " |
4765 | "libraries added or removed)\n")); | |
edcc5120 TT |
4766 | } |
4767 | ||
112e8700 SM |
4768 | if (current_uiout->is_mi_like_p ()) |
4769 | current_uiout->field_string ("reason", | |
4770 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4771 | |
4772 | if (any_deleted) | |
4773 | { | |
edcc5120 TT |
4774 | char *name; |
4775 | int ix; | |
4776 | ||
112e8700 | 4777 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4778 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
edcc5120 TT |
4779 | for (ix = 0; |
4780 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4781 | ix, name); | |
4782 | ++ix) | |
4783 | { | |
4784 | if (ix > 0) | |
112e8700 SM |
4785 | current_uiout->text (" "); |
4786 | current_uiout->field_string ("library", name); | |
4787 | current_uiout->text ("\n"); | |
edcc5120 | 4788 | } |
edcc5120 TT |
4789 | } |
4790 | ||
4791 | if (any_added) | |
4792 | { | |
4793 | struct so_list *iter; | |
4794 | int ix; | |
edcc5120 | 4795 | |
112e8700 | 4796 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4797 | ui_out_emit_list list_emitter (current_uiout, "added"); |
edcc5120 TT |
4798 | for (ix = 0; |
4799 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4800 | ix, iter); | |
4801 | ++ix) | |
4802 | { | |
4803 | if (ix > 0) | |
112e8700 SM |
4804 | current_uiout->text (" "); |
4805 | current_uiout->field_string ("library", iter->so_name); | |
4806 | current_uiout->text ("\n"); | |
edcc5120 | 4807 | } |
edcc5120 TT |
4808 | } |
4809 | } | |
4810 | ||
e514a9d6 JM |
4811 | /* Print a message indicating what happened. This is called from |
4812 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4813 | list - a list of the eventpoints that caused this stop. KIND is |
4814 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4815 | routine calls the generic print routine for printing a message |
4816 | about reasons for stopping. This will print (for example) the | |
4817 | "Breakpoint n," part of the output. The return value of this | |
4818 | routine is one of: | |
c906108c | 4819 | |
4a64f543 | 4820 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4821 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4822 | code to print the location. An example is |
c5aa993b JM |
4823 | "Breakpoint 1, " which should be followed by |
4824 | the location. | |
917317f4 | 4825 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4826 | to also print the location part of the message. |
4827 | An example is the catch/throw messages, which | |
4a64f543 | 4828 | don't require a location appended to the end. |
917317f4 | 4829 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4830 | further info to be printed. */ |
c906108c | 4831 | |
917317f4 | 4832 | enum print_stop_action |
36dfb11c | 4833 | bpstat_print (bpstat bs, int kind) |
c906108c | 4834 | { |
f486487f | 4835 | enum print_stop_action val; |
c5aa993b | 4836 | |
c906108c | 4837 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4838 | (Currently all watchpoints go on the bpstat whether hit or not. |
4839 | That probably could (should) be changed, provided care is taken | |
c906108c | 4840 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4841 | for (; bs; bs = bs->next) |
4842 | { | |
4843 | val = print_bp_stop_message (bs); | |
4844 | if (val == PRINT_SRC_ONLY | |
4845 | || val == PRINT_SRC_AND_LOC | |
4846 | || val == PRINT_NOTHING) | |
4847 | return val; | |
4848 | } | |
c906108c | 4849 | |
36dfb11c TT |
4850 | /* If we had hit a shared library event breakpoint, |
4851 | print_bp_stop_message would print out this message. If we hit an | |
4852 | OS-level shared library event, do the same thing. */ | |
4853 | if (kind == TARGET_WAITKIND_LOADED) | |
4854 | { | |
edcc5120 | 4855 | print_solib_event (0); |
36dfb11c TT |
4856 | return PRINT_NOTHING; |
4857 | } | |
4858 | ||
e514a9d6 | 4859 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4860 | with and nothing was printed. */ |
917317f4 | 4861 | return PRINT_UNKNOWN; |
c906108c SS |
4862 | } |
4863 | ||
c42bd95a DE |
4864 | /* Evaluate the expression EXP and return 1 if value is zero. |
4865 | This returns the inverse of the condition because it is called | |
4866 | from catch_errors which returns 0 if an exception happened, and if an | |
4867 | exception happens we want execution to stop. | |
4a64f543 | 4868 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4869 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4870 | |
4871 | static int | |
4efb68b1 | 4872 | breakpoint_cond_eval (void *exp) |
c906108c | 4873 | { |
278cd55f | 4874 | struct value *mark = value_mark (); |
c5aa993b | 4875 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4876 | |
c906108c SS |
4877 | value_free_to_mark (mark); |
4878 | return i; | |
4879 | } | |
4880 | ||
5760d0ab | 4881 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c | 4882 | |
04afa70c TT |
4883 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
4884 | : next (NULL), | |
4885 | bp_location_at (bl), | |
4886 | breakpoint_at (bl->owner), | |
4887 | commands (NULL), | |
4888 | old_val (NULL), | |
4889 | print (0), | |
4890 | stop (0), | |
4891 | print_it (print_it_normal) | |
c906108c | 4892 | { |
f431efe5 | 4893 | incref_bp_location (bl); |
04afa70c TT |
4894 | **bs_link_pointer = this; |
4895 | *bs_link_pointer = &next; | |
4896 | } | |
4897 | ||
4898 | bpstats::bpstats () | |
4899 | : next (NULL), | |
4900 | bp_location_at (NULL), | |
4901 | breakpoint_at (NULL), | |
4902 | commands (NULL), | |
4903 | old_val (NULL), | |
4904 | print (0), | |
4905 | stop (0), | |
4906 | print_it (print_it_normal) | |
4907 | { | |
c906108c SS |
4908 | } |
4909 | \f | |
d983da9c DJ |
4910 | /* The target has stopped with waitstatus WS. Check if any hardware |
4911 | watchpoints have triggered, according to the target. */ | |
4912 | ||
4913 | int | |
4914 | watchpoints_triggered (struct target_waitstatus *ws) | |
4915 | { | |
d92524f1 | 4916 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
4917 | CORE_ADDR addr; |
4918 | struct breakpoint *b; | |
4919 | ||
4920 | if (!stopped_by_watchpoint) | |
4921 | { | |
4922 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
4923 | as not triggered. */ | |
4924 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4925 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4926 | { |
4927 | struct watchpoint *w = (struct watchpoint *) b; | |
4928 | ||
4929 | w->watchpoint_triggered = watch_triggered_no; | |
4930 | } | |
d983da9c DJ |
4931 | |
4932 | return 0; | |
4933 | } | |
4934 | ||
4935 | if (!target_stopped_data_address (¤t_target, &addr)) | |
4936 | { | |
4937 | /* We were stopped by a watchpoint, but we don't know where. | |
4938 | Mark all watchpoints as unknown. */ | |
4939 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4940 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
4941 | { |
4942 | struct watchpoint *w = (struct watchpoint *) b; | |
4943 | ||
4944 | w->watchpoint_triggered = watch_triggered_unknown; | |
4945 | } | |
d983da9c | 4946 | |
3c4797ba | 4947 | return 1; |
d983da9c DJ |
4948 | } |
4949 | ||
4950 | /* The target could report the data address. Mark watchpoints | |
4951 | affected by this data address as triggered, and all others as not | |
4952 | triggered. */ | |
4953 | ||
4954 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 4955 | if (is_hardware_watchpoint (b)) |
d983da9c | 4956 | { |
3a5c3e22 | 4957 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 4958 | struct bp_location *loc; |
d983da9c | 4959 | |
3a5c3e22 | 4960 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 4961 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 4962 | { |
3a5c3e22 | 4963 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 4964 | { |
3a5c3e22 PA |
4965 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
4966 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
4967 | |
4968 | if (newaddr == start) | |
4969 | { | |
3a5c3e22 | 4970 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4971 | break; |
4972 | } | |
4973 | } | |
4974 | /* Exact match not required. Within range is sufficient. */ | |
4975 | else if (target_watchpoint_addr_within_range (¤t_target, | |
4976 | addr, loc->address, | |
4977 | loc->length)) | |
4978 | { | |
3a5c3e22 | 4979 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
4980 | break; |
4981 | } | |
4982 | } | |
d983da9c DJ |
4983 | } |
4984 | ||
4985 | return 1; | |
4986 | } | |
4987 | ||
c906108c SS |
4988 | /* Possible return values for watchpoint_check (this can't be an enum |
4989 | because of check_errors). */ | |
4990 | /* The watchpoint has been deleted. */ | |
4991 | #define WP_DELETED 1 | |
4992 | /* The value has changed. */ | |
4993 | #define WP_VALUE_CHANGED 2 | |
4994 | /* The value has not changed. */ | |
4995 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
4996 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
4997 | #define WP_IGNORE 4 | |
c906108c SS |
4998 | |
4999 | #define BP_TEMPFLAG 1 | |
5000 | #define BP_HARDWAREFLAG 2 | |
5001 | ||
4a64f543 MS |
5002 | /* Evaluate watchpoint condition expression and check if its value |
5003 | changed. | |
553e4c11 JB |
5004 | |
5005 | P should be a pointer to struct bpstat, but is defined as a void * | |
5006 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5007 | |
5008 | static int | |
4efb68b1 | 5009 | watchpoint_check (void *p) |
c906108c SS |
5010 | { |
5011 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5012 | struct watchpoint *b; |
c906108c SS |
5013 | struct frame_info *fr; |
5014 | int within_current_scope; | |
5015 | ||
f431efe5 | 5016 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5017 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5018 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5019 | |
f6bc2008 PA |
5020 | /* If this is a local watchpoint, we only want to check if the |
5021 | watchpoint frame is in scope if the current thread is the thread | |
5022 | that was used to create the watchpoint. */ | |
5023 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5024 | return WP_IGNORE; |
f6bc2008 | 5025 | |
c906108c SS |
5026 | if (b->exp_valid_block == NULL) |
5027 | within_current_scope = 1; | |
5028 | else | |
5029 | { | |
edb3359d DJ |
5030 | struct frame_info *frame = get_current_frame (); |
5031 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5032 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5033 | ||
c9cf6e20 | 5034 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5035 | still in the function but the stack frame has already been |
5036 | invalidated. Since we can't rely on the values of local | |
5037 | variables after the stack has been destroyed, we are treating | |
5038 | the watchpoint in that state as `not changed' without further | |
5039 | checking. Don't mark watchpoints as changed if the current | |
5040 | frame is in an epilogue - even if they are in some other | |
5041 | frame, our view of the stack is likely to be wrong and | |
5042 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5043 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5044 | return WP_IGNORE; |
a0f49112 | 5045 | |
101dcfbe | 5046 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5047 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5048 | |
5049 | /* If we've gotten confused in the unwinder, we might have | |
5050 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5051 | if (within_current_scope) |
5052 | { | |
5053 | struct symbol *function; | |
5054 | ||
5055 | function = get_frame_function (fr); | |
5056 | if (function == NULL | |
5057 | || !contained_in (b->exp_valid_block, | |
5058 | SYMBOL_BLOCK_VALUE (function))) | |
5059 | within_current_scope = 0; | |
5060 | } | |
69fbadd5 | 5061 | |
edb3359d | 5062 | if (within_current_scope) |
c906108c SS |
5063 | /* If we end up stopping, the current frame will get selected |
5064 | in normal_stop. So this call to select_frame won't affect | |
5065 | the user. */ | |
0f7d239c | 5066 | select_frame (fr); |
c906108c | 5067 | } |
c5aa993b | 5068 | |
c906108c SS |
5069 | if (within_current_scope) |
5070 | { | |
4a64f543 MS |
5071 | /* We use value_{,free_to_}mark because it could be a *long* |
5072 | time before we return to the command level and call | |
5073 | free_all_values. We can't call free_all_values because we | |
5074 | might be in the middle of evaluating a function call. */ | |
c906108c | 5075 | |
0cf6dd15 | 5076 | int pc = 0; |
9c06b0b4 | 5077 | struct value *mark; |
fa4727a6 DJ |
5078 | struct value *new_val; |
5079 | ||
c1fc2657 | 5080 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
5081 | /* Since we don't know the exact trigger address (from |
5082 | stopped_data_address), just tell the user we've triggered | |
5083 | a mask watchpoint. */ | |
5084 | return WP_VALUE_CHANGED; | |
5085 | ||
5086 | mark = value_mark (); | |
4d01a485 | 5087 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5088 | |
bb9d5f81 PP |
5089 | if (b->val_bitsize != 0) |
5090 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5091 | ||
4a64f543 MS |
5092 | /* We use value_equal_contents instead of value_equal because |
5093 | the latter coerces an array to a pointer, thus comparing just | |
5094 | the address of the array instead of its contents. This is | |
5095 | not what we want. */ | |
fa4727a6 | 5096 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5097 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5098 | { |
fa4727a6 DJ |
5099 | if (new_val != NULL) |
5100 | { | |
5101 | release_value (new_val); | |
5102 | value_free_to_mark (mark); | |
5103 | } | |
c906108c SS |
5104 | bs->old_val = b->val; |
5105 | b->val = new_val; | |
fa4727a6 | 5106 | b->val_valid = 1; |
c906108c SS |
5107 | return WP_VALUE_CHANGED; |
5108 | } | |
5109 | else | |
5110 | { | |
60e1c644 | 5111 | /* Nothing changed. */ |
c906108c | 5112 | value_free_to_mark (mark); |
c906108c SS |
5113 | return WP_VALUE_NOT_CHANGED; |
5114 | } | |
5115 | } | |
5116 | else | |
5117 | { | |
5118 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5119 | if we temporarily ignored the watchpoint, then when |
5120 | we reenter the block in which it is valid it contains | |
5121 | garbage (in the case of a function, it may have two | |
5122 | garbage values, one before and one after the prologue). | |
5123 | So we can't even detect the first assignment to it and | |
5124 | watch after that (since the garbage may or may not equal | |
5125 | the first value assigned). */ | |
348d480f PA |
5126 | /* We print all the stop information in |
5127 | breakpoint_ops->print_it, but in this case, by the time we | |
5128 | call breakpoint_ops->print_it this bp will be deleted | |
5129 | already. So we have no choice but print the information | |
5130 | here. */ | |
468afe6c | 5131 | |
0e454242 | 5132 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5133 | { |
5134 | struct ui_out *uiout = current_uiout; | |
5135 | ||
112e8700 SM |
5136 | if (uiout->is_mi_like_p ()) |
5137 | uiout->field_string | |
5138 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5139 | uiout->text ("\nWatchpoint "); | |
c1fc2657 | 5140 | uiout->field_int ("wpnum", b->number); |
112e8700 | 5141 | uiout->text (" deleted because the program has left the block in\n" |
468afe6c PA |
5142 | "which its expression is valid.\n"); |
5143 | } | |
4ce44c66 | 5144 | |
cdac0397 | 5145 | /* Make sure the watchpoint's commands aren't executed. */ |
d1b0a7bf | 5146 | b->commands = NULL; |
d0fb5eae | 5147 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5148 | |
5149 | return WP_DELETED; | |
5150 | } | |
5151 | } | |
5152 | ||
18a18393 | 5153 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5154 | breakpoint location BL. This function does not check if we should |
5155 | stop, only if BL explains the stop. */ | |
5156 | ||
18a18393 | 5157 | static int |
6c95b8df | 5158 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5159 | struct address_space *aspace, CORE_ADDR bp_addr, |
5160 | const struct target_waitstatus *ws) | |
18a18393 VP |
5161 | { |
5162 | struct breakpoint *b = bl->owner; | |
5163 | ||
348d480f | 5164 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5165 | gdb_assert (b != NULL); |
5166 | ||
09ac7c10 | 5167 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5168 | } |
5169 | ||
3a5c3e22 PA |
5170 | /* Determine if the watched values have actually changed, and we |
5171 | should stop. If not, set BS->stop to 0. */ | |
5172 | ||
18a18393 VP |
5173 | static void |
5174 | bpstat_check_watchpoint (bpstat bs) | |
5175 | { | |
2bdf28a0 | 5176 | const struct bp_location *bl; |
3a5c3e22 | 5177 | struct watchpoint *b; |
2bdf28a0 JK |
5178 | |
5179 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5180 | bl = bs->bp_location_at; |
2bdf28a0 | 5181 | gdb_assert (bl != NULL); |
3a5c3e22 | 5182 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5183 | gdb_assert (b != NULL); |
18a18393 | 5184 | |
18a18393 | 5185 | { |
18a18393 VP |
5186 | int must_check_value = 0; |
5187 | ||
c1fc2657 | 5188 | if (b->type == bp_watchpoint) |
18a18393 VP |
5189 | /* For a software watchpoint, we must always check the |
5190 | watched value. */ | |
5191 | must_check_value = 1; | |
5192 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5193 | /* We have a hardware watchpoint (read, write, or access) | |
5194 | and the target earlier reported an address watched by | |
5195 | this watchpoint. */ | |
5196 | must_check_value = 1; | |
5197 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5198 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5199 | /* We were stopped by a hardware watchpoint, but the target could |
5200 | not report the data address. We must check the watchpoint's | |
5201 | value. Access and read watchpoints are out of luck; without | |
5202 | a data address, we can't figure it out. */ | |
5203 | must_check_value = 1; | |
3a5c3e22 | 5204 | |
18a18393 VP |
5205 | if (must_check_value) |
5206 | { | |
3e43a32a MS |
5207 | char *message |
5208 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
c1fc2657 | 5209 | b->number); |
18a18393 VP |
5210 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5211 | int e = catch_errors (watchpoint_check, bs, message, | |
5212 | RETURN_MASK_ALL); | |
5213 | do_cleanups (cleanups); | |
5214 | switch (e) | |
5215 | { | |
5216 | case WP_DELETED: | |
5217 | /* We've already printed what needs to be printed. */ | |
5218 | bs->print_it = print_it_done; | |
5219 | /* Stop. */ | |
5220 | break; | |
60e1c644 PA |
5221 | case WP_IGNORE: |
5222 | bs->print_it = print_it_noop; | |
5223 | bs->stop = 0; | |
5224 | break; | |
18a18393 | 5225 | case WP_VALUE_CHANGED: |
c1fc2657 | 5226 | if (b->type == bp_read_watchpoint) |
18a18393 | 5227 | { |
85d721b8 PA |
5228 | /* There are two cases to consider here: |
5229 | ||
4a64f543 | 5230 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5231 | In that case, trust the target, and always report |
5232 | the watchpoint hit to the user. Even though | |
5233 | reads don't cause value changes, the value may | |
5234 | have changed since the last time it was read, and | |
5235 | since we're not trapping writes, we will not see | |
5236 | those, and as such we should ignore our notion of | |
5237 | old value. | |
5238 | ||
4a64f543 | 5239 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5240 | reads and writes. There are two ways this may |
5241 | happen: | |
5242 | ||
4a64f543 | 5243 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5244 | reads only, but can break on accesses (reads or |
5245 | writes), such as e.g., x86. We detect this case | |
5246 | at the time we try to insert read watchpoints. | |
5247 | ||
4a64f543 | 5248 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5249 | watchpoints, but, the user set an access or write |
5250 | watchpoint watching the same memory as this read | |
5251 | watchpoint. | |
5252 | ||
5253 | If we're watching memory writes as well as reads, | |
5254 | ignore watchpoint hits when we find that the | |
5255 | value hasn't changed, as reads don't cause | |
5256 | changes. This still gives false positives when | |
5257 | the program writes the same value to memory as | |
5258 | what there was already in memory (we will confuse | |
5259 | it for a read), but it's much better than | |
5260 | nothing. */ | |
5261 | ||
5262 | int other_write_watchpoint = 0; | |
5263 | ||
5264 | if (bl->watchpoint_type == hw_read) | |
5265 | { | |
5266 | struct breakpoint *other_b; | |
5267 | ||
5268 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5269 | if (other_b->type == bp_hardware_watchpoint |
5270 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5271 | { |
3a5c3e22 PA |
5272 | struct watchpoint *other_w = |
5273 | (struct watchpoint *) other_b; | |
5274 | ||
5275 | if (other_w->watchpoint_triggered | |
5276 | == watch_triggered_yes) | |
5277 | { | |
5278 | other_write_watchpoint = 1; | |
5279 | break; | |
5280 | } | |
85d721b8 PA |
5281 | } |
5282 | } | |
5283 | ||
5284 | if (other_write_watchpoint | |
5285 | || bl->watchpoint_type == hw_access) | |
5286 | { | |
5287 | /* We're watching the same memory for writes, | |
5288 | and the value changed since the last time we | |
5289 | updated it, so this trap must be for a write. | |
5290 | Ignore it. */ | |
5291 | bs->print_it = print_it_noop; | |
5292 | bs->stop = 0; | |
5293 | } | |
18a18393 VP |
5294 | } |
5295 | break; | |
5296 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5297 | if (b->type == bp_hardware_watchpoint |
5298 | || b->type == bp_watchpoint) | |
18a18393 VP |
5299 | { |
5300 | /* Don't stop: write watchpoints shouldn't fire if | |
5301 | the value hasn't changed. */ | |
5302 | bs->print_it = print_it_noop; | |
5303 | bs->stop = 0; | |
5304 | } | |
5305 | /* Stop. */ | |
5306 | break; | |
5307 | default: | |
5308 | /* Can't happen. */ | |
5309 | case 0: | |
5310 | /* Error from catch_errors. */ | |
468afe6c | 5311 | { |
0e454242 | 5312 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5313 | { |
5314 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
c1fc2657 | 5315 | b->number); |
468afe6c PA |
5316 | } |
5317 | watchpoint_del_at_next_stop (b); | |
5318 | /* We've already printed what needs to be printed. */ | |
5319 | bs->print_it = print_it_done; | |
5320 | } | |
18a18393 VP |
5321 | break; |
5322 | } | |
5323 | } | |
5324 | else /* must_check_value == 0 */ | |
5325 | { | |
5326 | /* This is a case where some watchpoint(s) triggered, but | |
5327 | not at the address of this watchpoint, or else no | |
5328 | watchpoint triggered after all. So don't print | |
5329 | anything for this watchpoint. */ | |
5330 | bs->print_it = print_it_noop; | |
5331 | bs->stop = 0; | |
5332 | } | |
5333 | } | |
5334 | } | |
5335 | ||
7d4df6a4 DE |
5336 | /* For breakpoints that are currently marked as telling gdb to stop, |
5337 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5338 | of breakpoint referred to by BS. If we should not stop for this |
5339 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5340 | |
18a18393 VP |
5341 | static void |
5342 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5343 | { | |
2bdf28a0 JK |
5344 | const struct bp_location *bl; |
5345 | struct breakpoint *b; | |
7d4df6a4 DE |
5346 | int value_is_zero = 0; |
5347 | struct expression *cond; | |
5348 | ||
5349 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5350 | |
5351 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5352 | bl = bs->bp_location_at; |
2bdf28a0 | 5353 | gdb_assert (bl != NULL); |
f431efe5 | 5354 | b = bs->breakpoint_at; |
2bdf28a0 | 5355 | gdb_assert (b != NULL); |
18a18393 | 5356 | |
b775012e LM |
5357 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5358 | need to do so again since GDB does not know if we stopped due to a | |
5359 | breakpoint or a single step breakpoint. */ | |
5360 | ||
18a18393 | 5361 | if (frame_id_p (b->frame_id) |
edb3359d | 5362 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5363 | { |
7d4df6a4 DE |
5364 | bs->stop = 0; |
5365 | return; | |
5366 | } | |
60e1c644 | 5367 | |
12ab52e9 PA |
5368 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5369 | evaluating the condition if this isn't the specified | |
5370 | thread/task. */ | |
5d5658a1 | 5371 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5372 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5373 | ||
6c1b0f7b DE |
5374 | { |
5375 | bs->stop = 0; | |
5376 | return; | |
5377 | } | |
5378 | ||
6dddc817 DE |
5379 | /* Evaluate extension language breakpoints that have a "stop" method |
5380 | implemented. */ | |
5381 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5382 | |
7d4df6a4 DE |
5383 | if (is_watchpoint (b)) |
5384 | { | |
5385 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5386 | |
4d01a485 | 5387 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5388 | } |
5389 | else | |
4d01a485 | 5390 | cond = bl->cond.get (); |
60e1c644 | 5391 | |
7d4df6a4 DE |
5392 | if (cond && b->disposition != disp_del_at_next_stop) |
5393 | { | |
5394 | int within_current_scope = 1; | |
5395 | struct watchpoint * w; | |
60e1c644 | 5396 | |
7d4df6a4 DE |
5397 | /* We use value_mark and value_free_to_mark because it could |
5398 | be a long time before we return to the command level and | |
5399 | call free_all_values. We can't call free_all_values | |
5400 | because we might be in the middle of evaluating a | |
5401 | function call. */ | |
5402 | struct value *mark = value_mark (); | |
5403 | ||
5404 | if (is_watchpoint (b)) | |
5405 | w = (struct watchpoint *) b; | |
5406 | else | |
5407 | w = NULL; | |
5408 | ||
5409 | /* Need to select the frame, with all that implies so that | |
5410 | the conditions will have the right context. Because we | |
5411 | use the frame, we will not see an inlined function's | |
5412 | variables when we arrive at a breakpoint at the start | |
5413 | of the inlined function; the current frame will be the | |
5414 | call site. */ | |
5415 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5416 | select_frame (get_current_frame ()); | |
5417 | else | |
18a18393 | 5418 | { |
7d4df6a4 DE |
5419 | struct frame_info *frame; |
5420 | ||
5421 | /* For local watchpoint expressions, which particular | |
5422 | instance of a local is being watched matters, so we | |
5423 | keep track of the frame to evaluate the expression | |
5424 | in. To evaluate the condition however, it doesn't | |
5425 | really matter which instantiation of the function | |
5426 | where the condition makes sense triggers the | |
5427 | watchpoint. This allows an expression like "watch | |
5428 | global if q > 10" set in `func', catch writes to | |
5429 | global on all threads that call `func', or catch | |
5430 | writes on all recursive calls of `func' by a single | |
5431 | thread. We simply always evaluate the condition in | |
5432 | the innermost frame that's executing where it makes | |
5433 | sense to evaluate the condition. It seems | |
5434 | intuitive. */ | |
5435 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5436 | if (frame != NULL) | |
5437 | select_frame (frame); | |
5438 | else | |
5439 | within_current_scope = 0; | |
18a18393 | 5440 | } |
7d4df6a4 DE |
5441 | if (within_current_scope) |
5442 | value_is_zero | |
5443 | = catch_errors (breakpoint_cond_eval, cond, | |
5444 | "Error in testing breakpoint condition:\n", | |
5445 | RETURN_MASK_ALL); | |
5446 | else | |
18a18393 | 5447 | { |
7d4df6a4 DE |
5448 | warning (_("Watchpoint condition cannot be tested " |
5449 | "in the current scope")); | |
5450 | /* If we failed to set the right context for this | |
5451 | watchpoint, unconditionally report it. */ | |
5452 | value_is_zero = 0; | |
18a18393 | 5453 | } |
7d4df6a4 DE |
5454 | /* FIXME-someday, should give breakpoint #. */ |
5455 | value_free_to_mark (mark); | |
18a18393 | 5456 | } |
7d4df6a4 DE |
5457 | |
5458 | if (cond && value_is_zero) | |
5459 | { | |
5460 | bs->stop = 0; | |
5461 | } | |
7d4df6a4 DE |
5462 | else if (b->ignore_count > 0) |
5463 | { | |
5464 | b->ignore_count--; | |
5465 | bs->stop = 0; | |
5466 | /* Increase the hit count even though we don't stop. */ | |
5467 | ++(b->hit_count); | |
5468 | observer_notify_breakpoint_modified (b); | |
5469 | } | |
18a18393 VP |
5470 | } |
5471 | ||
1cf4d951 PA |
5472 | /* Returns true if we need to track moribund locations of LOC's type |
5473 | on the current target. */ | |
5474 | ||
5475 | static int | |
5476 | need_moribund_for_location_type (struct bp_location *loc) | |
5477 | { | |
5478 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5479 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5480 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5481 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5482 | } | |
5483 | ||
18a18393 | 5484 | |
9709f61c | 5485 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5486 | BP_ADDR in thread PTID. |
c906108c | 5487 | |
d983da9c | 5488 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5489 | don't understand this stop. Result is a chain of bpstat's such |
5490 | that: | |
c906108c | 5491 | |
c5aa993b | 5492 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5493 | |
c5aa993b | 5494 | if we understand why we stopped, the result is not null. |
c906108c | 5495 | |
c5aa993b JM |
5496 | Each element of the chain refers to a particular breakpoint or |
5497 | watchpoint at which we have stopped. (We may have stopped for | |
5498 | several reasons concurrently.) | |
c906108c | 5499 | |
c5aa993b JM |
5500 | Each element of the chain has valid next, breakpoint_at, |
5501 | commands, FIXME??? fields. */ | |
c906108c SS |
5502 | |
5503 | bpstat | |
6c95b8df | 5504 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5505 | CORE_ADDR bp_addr, ptid_t ptid, |
5506 | const struct target_waitstatus *ws) | |
c906108c | 5507 | { |
0d381245 | 5508 | struct breakpoint *b = NULL; |
afe38095 | 5509 | struct bp_location *bl; |
20874c92 | 5510 | struct bp_location *loc; |
5760d0ab JK |
5511 | /* First item of allocated bpstat's. */ |
5512 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5513 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5514 | bpstat bs; |
20874c92 | 5515 | int ix; |
429374b8 | 5516 | int need_remove_insert; |
f431efe5 | 5517 | int removed_any; |
c906108c | 5518 | |
f431efe5 PA |
5519 | /* First, build the bpstat chain with locations that explain a |
5520 | target stop, while being careful to not set the target running, | |
5521 | as that may invalidate locations (in particular watchpoint | |
5522 | locations are recreated). Resuming will happen here with | |
5523 | breakpoint conditions or watchpoint expressions that include | |
5524 | inferior function calls. */ | |
c5aa993b | 5525 | |
429374b8 JK |
5526 | ALL_BREAKPOINTS (b) |
5527 | { | |
1a853c52 | 5528 | if (!breakpoint_enabled (b)) |
429374b8 | 5529 | continue; |
a5606eee | 5530 | |
429374b8 JK |
5531 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5532 | { | |
4a64f543 MS |
5533 | /* For hardware watchpoints, we look only at the first |
5534 | location. The watchpoint_check function will work on the | |
5535 | entire expression, not the individual locations. For | |
5536 | read watchpoints, the watchpoints_triggered function has | |
5537 | checked all locations already. */ | |
429374b8 JK |
5538 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5539 | break; | |
18a18393 | 5540 | |
f6592439 | 5541 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5542 | continue; |
c5aa993b | 5543 | |
09ac7c10 | 5544 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5545 | continue; |
c5aa993b | 5546 | |
4a64f543 MS |
5547 | /* Come here if it's a watchpoint, or if the break address |
5548 | matches. */ | |
c5aa993b | 5549 | |
04afa70c | 5550 | bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
4a64f543 | 5551 | explain stop. */ |
c5aa993b | 5552 | |
f431efe5 PA |
5553 | /* Assume we stop. Should we find a watchpoint that is not |
5554 | actually triggered, or if the condition of the breakpoint | |
5555 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5556 | bs->stop = 1; |
5557 | bs->print = 1; | |
d983da9c | 5558 | |
f431efe5 PA |
5559 | /* If this is a scope breakpoint, mark the associated |
5560 | watchpoint as triggered so that we will handle the | |
5561 | out-of-scope event. We'll get to the watchpoint next | |
5562 | iteration. */ | |
d0fb5eae | 5563 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5564 | { |
5565 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5566 | ||
5567 | w->watchpoint_triggered = watch_triggered_yes; | |
5568 | } | |
f431efe5 PA |
5569 | } |
5570 | } | |
5571 | ||
7c16b83e | 5572 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5573 | if (!target_supports_stopped_by_sw_breakpoint () |
5574 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5575 | { |
1cf4d951 | 5576 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5577 | { |
1cf4d951 PA |
5578 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5579 | && need_moribund_for_location_type (loc)) | |
5580 | { | |
04afa70c | 5581 | bs = new bpstats (loc, &bs_link); |
1cf4d951 PA |
5582 | /* For hits of moribund locations, we should just proceed. */ |
5583 | bs->stop = 0; | |
5584 | bs->print = 0; | |
5585 | bs->print_it = print_it_noop; | |
5586 | } | |
f431efe5 PA |
5587 | } |
5588 | } | |
5589 | ||
edcc5120 TT |
5590 | /* A bit of special processing for shlib breakpoints. We need to |
5591 | process solib loading here, so that the lists of loaded and | |
5592 | unloaded libraries are correct before we handle "catch load" and | |
5593 | "catch unload". */ | |
5594 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5595 | { | |
5d268276 | 5596 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5597 | { |
5598 | handle_solib_event (); | |
5599 | break; | |
5600 | } | |
5601 | } | |
5602 | ||
f431efe5 PA |
5603 | /* Now go through the locations that caused the target to stop, and |
5604 | check whether we're interested in reporting this stop to higher | |
5605 | layers, or whether we should resume the target transparently. */ | |
5606 | ||
5607 | removed_any = 0; | |
5608 | ||
5760d0ab | 5609 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5610 | { |
5611 | if (!bs->stop) | |
5612 | continue; | |
5613 | ||
f431efe5 | 5614 | b = bs->breakpoint_at; |
348d480f PA |
5615 | b->ops->check_status (bs); |
5616 | if (bs->stop) | |
28010a5d | 5617 | { |
348d480f | 5618 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5619 | |
429374b8 JK |
5620 | if (bs->stop) |
5621 | { | |
5622 | ++(b->hit_count); | |
8d3788bd | 5623 | observer_notify_breakpoint_modified (b); |
c906108c | 5624 | |
4a64f543 | 5625 | /* We will stop here. */ |
429374b8 JK |
5626 | if (b->disposition == disp_disable) |
5627 | { | |
816338b5 | 5628 | --(b->enable_count); |
1a853c52 | 5629 | if (b->enable_count <= 0) |
429374b8 | 5630 | b->enable_state = bp_disabled; |
f431efe5 | 5631 | removed_any = 1; |
429374b8 JK |
5632 | } |
5633 | if (b->silent) | |
5634 | bs->print = 0; | |
5635 | bs->commands = b->commands; | |
abf85f46 | 5636 | if (command_line_is_silent (bs->commands |
d1b0a7bf | 5637 | ? bs->commands.get () : NULL)) |
abf85f46 | 5638 | bs->print = 0; |
9d6e6e84 HZ |
5639 | |
5640 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5641 | } |
5642 | ||
348d480f | 5643 | } |
a9b3a50f PA |
5644 | |
5645 | /* Print nothing for this entry if we don't stop or don't | |
5646 | print. */ | |
5647 | if (!bs->stop || !bs->print) | |
5648 | bs->print_it = print_it_noop; | |
429374b8 | 5649 | } |
876fa593 | 5650 | |
d983da9c DJ |
5651 | /* If we aren't stopping, the value of some hardware watchpoint may |
5652 | not have changed, but the intermediate memory locations we are | |
5653 | watching may have. Don't bother if we're stopping; this will get | |
5654 | done later. */ | |
d832cb68 | 5655 | need_remove_insert = 0; |
5760d0ab JK |
5656 | if (! bpstat_causes_stop (bs_head)) |
5657 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5658 | if (!bs->stop |
f431efe5 PA |
5659 | && bs->breakpoint_at |
5660 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5661 | { |
3a5c3e22 PA |
5662 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5663 | ||
5664 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5665 | need_remove_insert = 1; |
d983da9c DJ |
5666 | } |
5667 | ||
d832cb68 | 5668 | if (need_remove_insert) |
44702360 | 5669 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5670 | else if (removed_any) |
44702360 | 5671 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5672 | |
5760d0ab | 5673 | return bs_head; |
c906108c | 5674 | } |
628fe4e4 JK |
5675 | |
5676 | static void | |
5677 | handle_jit_event (void) | |
5678 | { | |
5679 | struct frame_info *frame; | |
5680 | struct gdbarch *gdbarch; | |
5681 | ||
243a9253 PA |
5682 | if (debug_infrun) |
5683 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5684 | ||
628fe4e4 JK |
5685 | /* Switch terminal for any messages produced by |
5686 | breakpoint_re_set. */ | |
223ffa71 | 5687 | target_terminal::ours_for_output (); |
628fe4e4 JK |
5688 | |
5689 | frame = get_current_frame (); | |
5690 | gdbarch = get_frame_arch (frame); | |
5691 | ||
5692 | jit_event_handler (gdbarch); | |
5693 | ||
223ffa71 | 5694 | target_terminal::inferior (); |
628fe4e4 JK |
5695 | } |
5696 | ||
5697 | /* Prepare WHAT final decision for infrun. */ | |
5698 | ||
5699 | /* Decide what infrun needs to do with this bpstat. */ | |
5700 | ||
c906108c | 5701 | struct bpstat_what |
0e30163f | 5702 | bpstat_what (bpstat bs_head) |
c906108c | 5703 | { |
c906108c | 5704 | struct bpstat_what retval; |
0e30163f | 5705 | bpstat bs; |
c906108c | 5706 | |
628fe4e4 | 5707 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5708 | retval.call_dummy = STOP_NONE; |
186c406b | 5709 | retval.is_longjmp = 0; |
628fe4e4 | 5710 | |
0e30163f | 5711 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5712 | { |
628fe4e4 JK |
5713 | /* Extract this BS's action. After processing each BS, we check |
5714 | if its action overrides all we've seem so far. */ | |
5715 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5716 | enum bptype bptype; | |
5717 | ||
c906108c | 5718 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5719 | { |
5720 | /* I suspect this can happen if it was a momentary | |
5721 | breakpoint which has since been deleted. */ | |
5722 | bptype = bp_none; | |
5723 | } | |
20874c92 | 5724 | else |
f431efe5 | 5725 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5726 | |
5727 | switch (bptype) | |
c906108c SS |
5728 | { |
5729 | case bp_none: | |
628fe4e4 | 5730 | break; |
c906108c SS |
5731 | case bp_breakpoint: |
5732 | case bp_hardware_breakpoint: | |
7c16b83e | 5733 | case bp_single_step: |
c906108c SS |
5734 | case bp_until: |
5735 | case bp_finish: | |
a9b3a50f | 5736 | case bp_shlib_event: |
c906108c SS |
5737 | if (bs->stop) |
5738 | { | |
5739 | if (bs->print) | |
628fe4e4 | 5740 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5741 | else |
628fe4e4 | 5742 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5743 | } |
5744 | else | |
628fe4e4 | 5745 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5746 | break; |
5747 | case bp_watchpoint: | |
5748 | case bp_hardware_watchpoint: | |
5749 | case bp_read_watchpoint: | |
5750 | case bp_access_watchpoint: | |
5751 | if (bs->stop) | |
5752 | { | |
5753 | if (bs->print) | |
628fe4e4 | 5754 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5755 | else |
628fe4e4 | 5756 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5757 | } |
5758 | else | |
628fe4e4 JK |
5759 | { |
5760 | /* There was a watchpoint, but we're not stopping. | |
5761 | This requires no further action. */ | |
5762 | } | |
c906108c SS |
5763 | break; |
5764 | case bp_longjmp: | |
e2e4d78b | 5765 | case bp_longjmp_call_dummy: |
186c406b | 5766 | case bp_exception: |
0a39bb32 PA |
5767 | if (bs->stop) |
5768 | { | |
5769 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5770 | retval.is_longjmp = bptype != bp_exception; | |
5771 | } | |
5772 | else | |
5773 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5774 | break; |
5775 | case bp_longjmp_resume: | |
186c406b | 5776 | case bp_exception_resume: |
0a39bb32 PA |
5777 | if (bs->stop) |
5778 | { | |
5779 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5780 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5781 | } | |
5782 | else | |
5783 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5784 | break; |
5785 | case bp_step_resume: | |
5786 | if (bs->stop) | |
628fe4e4 JK |
5787 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5788 | else | |
c906108c | 5789 | { |
628fe4e4 JK |
5790 | /* It is for the wrong frame. */ |
5791 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5792 | } |
c906108c | 5793 | break; |
2c03e5be PA |
5794 | case bp_hp_step_resume: |
5795 | if (bs->stop) | |
5796 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5797 | else | |
5798 | { | |
5799 | /* It is for the wrong frame. */ | |
5800 | this_action = BPSTAT_WHAT_SINGLE; | |
5801 | } | |
5802 | break; | |
c906108c | 5803 | case bp_watchpoint_scope: |
c4093a6a | 5804 | case bp_thread_event: |
1900040c | 5805 | case bp_overlay_event: |
0fd8e87f | 5806 | case bp_longjmp_master: |
aa7d318d | 5807 | case bp_std_terminate_master: |
186c406b | 5808 | case bp_exception_master: |
628fe4e4 | 5809 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5810 | break; |
ce78b96d | 5811 | case bp_catchpoint: |
c5aa993b JM |
5812 | if (bs->stop) |
5813 | { | |
5814 | if (bs->print) | |
628fe4e4 | 5815 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5816 | else |
628fe4e4 | 5817 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5818 | } |
5819 | else | |
628fe4e4 JK |
5820 | { |
5821 | /* There was a catchpoint, but we're not stopping. | |
5822 | This requires no further action. */ | |
5823 | } | |
5824 | break; | |
628fe4e4 | 5825 | case bp_jit_event: |
628fe4e4 | 5826 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5827 | break; |
c906108c | 5828 | case bp_call_dummy: |
53a5351d JM |
5829 | /* Make sure the action is stop (silent or noisy), |
5830 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5831 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5832 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5833 | break; |
5834 | case bp_std_terminate: | |
5835 | /* Make sure the action is stop (silent or noisy), | |
5836 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5837 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5838 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5839 | break; |
1042e4c0 | 5840 | case bp_tracepoint: |
7a697b8d | 5841 | case bp_fast_tracepoint: |
0fb4aa4b | 5842 | case bp_static_tracepoint: |
1042e4c0 SS |
5843 | /* Tracepoint hits should not be reported back to GDB, and |
5844 | if one got through somehow, it should have been filtered | |
5845 | out already. */ | |
5846 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5847 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5848 | break; |
5849 | case bp_gnu_ifunc_resolver: | |
5850 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5851 | this_action = BPSTAT_WHAT_SINGLE; | |
5852 | break; | |
5853 | case bp_gnu_ifunc_resolver_return: | |
5854 | /* The breakpoint will be removed, execution will restart from the | |
5855 | PC of the former breakpoint. */ | |
5856 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5857 | break; | |
e7e0cddf SS |
5858 | |
5859 | case bp_dprintf: | |
a11cfd87 HZ |
5860 | if (bs->stop) |
5861 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5862 | else | |
5863 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5864 | break; |
5865 | ||
628fe4e4 JK |
5866 | default: |
5867 | internal_error (__FILE__, __LINE__, | |
5868 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5869 | } |
628fe4e4 | 5870 | |
325fac50 | 5871 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5872 | } |
628fe4e4 | 5873 | |
243a9253 PA |
5874 | return retval; |
5875 | } | |
628fe4e4 | 5876 | |
243a9253 PA |
5877 | void |
5878 | bpstat_run_callbacks (bpstat bs_head) | |
5879 | { | |
5880 | bpstat bs; | |
628fe4e4 | 5881 | |
0e30163f JK |
5882 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5883 | { | |
5884 | struct breakpoint *b = bs->breakpoint_at; | |
5885 | ||
5886 | if (b == NULL) | |
5887 | continue; | |
5888 | switch (b->type) | |
5889 | { | |
243a9253 PA |
5890 | case bp_jit_event: |
5891 | handle_jit_event (); | |
5892 | break; | |
0e30163f JK |
5893 | case bp_gnu_ifunc_resolver: |
5894 | gnu_ifunc_resolver_stop (b); | |
5895 | break; | |
5896 | case bp_gnu_ifunc_resolver_return: | |
5897 | gnu_ifunc_resolver_return_stop (b); | |
5898 | break; | |
5899 | } | |
5900 | } | |
c906108c SS |
5901 | } |
5902 | ||
5903 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
5904 | without hardware support). This isn't related to a specific bpstat, | |
5905 | just to things like whether watchpoints are set. */ | |
5906 | ||
c5aa993b | 5907 | int |
fba45db2 | 5908 | bpstat_should_step (void) |
c906108c SS |
5909 | { |
5910 | struct breakpoint *b; | |
cc59ec59 | 5911 | |
c906108c | 5912 | ALL_BREAKPOINTS (b) |
717a8278 | 5913 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 5914 | return 1; |
c906108c SS |
5915 | return 0; |
5916 | } | |
5917 | ||
67822962 PA |
5918 | int |
5919 | bpstat_causes_stop (bpstat bs) | |
5920 | { | |
5921 | for (; bs != NULL; bs = bs->next) | |
5922 | if (bs->stop) | |
5923 | return 1; | |
5924 | ||
5925 | return 0; | |
5926 | } | |
5927 | ||
c906108c | 5928 | \f |
c5aa993b | 5929 | |
170b53b2 UW |
5930 | /* Compute a string of spaces suitable to indent the next line |
5931 | so it starts at the position corresponding to the table column | |
5932 | named COL_NAME in the currently active table of UIOUT. */ | |
5933 | ||
5934 | static char * | |
5935 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
5936 | { | |
5937 | static char wrap_indent[80]; | |
5938 | int i, total_width, width, align; | |
c5209615 | 5939 | const char *text; |
170b53b2 UW |
5940 | |
5941 | total_width = 0; | |
112e8700 | 5942 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
5943 | { |
5944 | if (strcmp (text, col_name) == 0) | |
5945 | { | |
5946 | gdb_assert (total_width < sizeof wrap_indent); | |
5947 | memset (wrap_indent, ' ', total_width); | |
5948 | wrap_indent[total_width] = 0; | |
5949 | ||
5950 | return wrap_indent; | |
5951 | } | |
5952 | ||
5953 | total_width += width + 1; | |
5954 | } | |
5955 | ||
5956 | return NULL; | |
5957 | } | |
5958 | ||
b775012e LM |
5959 | /* Determine if the locations of this breakpoint will have their conditions |
5960 | evaluated by the target, host or a mix of both. Returns the following: | |
5961 | ||
5962 | "host": Host evals condition. | |
5963 | "host or target": Host or Target evals condition. | |
5964 | "target": Target evals condition. | |
5965 | */ | |
5966 | ||
5967 | static const char * | |
5968 | bp_condition_evaluator (struct breakpoint *b) | |
5969 | { | |
5970 | struct bp_location *bl; | |
5971 | char host_evals = 0; | |
5972 | char target_evals = 0; | |
5973 | ||
5974 | if (!b) | |
5975 | return NULL; | |
5976 | ||
5977 | if (!is_breakpoint (b)) | |
5978 | return NULL; | |
5979 | ||
5980 | if (gdb_evaluates_breakpoint_condition_p () | |
5981 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
5982 | return condition_evaluation_host; | |
5983 | ||
5984 | for (bl = b->loc; bl; bl = bl->next) | |
5985 | { | |
5986 | if (bl->cond_bytecode) | |
5987 | target_evals++; | |
5988 | else | |
5989 | host_evals++; | |
5990 | } | |
5991 | ||
5992 | if (host_evals && target_evals) | |
5993 | return condition_evaluation_both; | |
5994 | else if (target_evals) | |
5995 | return condition_evaluation_target; | |
5996 | else | |
5997 | return condition_evaluation_host; | |
5998 | } | |
5999 | ||
6000 | /* Determine the breakpoint location's condition evaluator. This is | |
6001 | similar to bp_condition_evaluator, but for locations. */ | |
6002 | ||
6003 | static const char * | |
6004 | bp_location_condition_evaluator (struct bp_location *bl) | |
6005 | { | |
6006 | if (bl && !is_breakpoint (bl->owner)) | |
6007 | return NULL; | |
6008 | ||
6009 | if (gdb_evaluates_breakpoint_condition_p () | |
6010 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6011 | return condition_evaluation_host; | |
6012 | ||
6013 | if (bl && bl->cond_bytecode) | |
6014 | return condition_evaluation_target; | |
6015 | else | |
6016 | return condition_evaluation_host; | |
6017 | } | |
6018 | ||
859825b8 JK |
6019 | /* Print the LOC location out of the list of B->LOC locations. */ |
6020 | ||
170b53b2 UW |
6021 | static void |
6022 | print_breakpoint_location (struct breakpoint *b, | |
6023 | struct bp_location *loc) | |
0d381245 | 6024 | { |
79a45e25 | 6025 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
6026 | |
6027 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 6028 | |
859825b8 JK |
6029 | if (loc != NULL && loc->shlib_disabled) |
6030 | loc = NULL; | |
6031 | ||
6c95b8df PA |
6032 | if (loc != NULL) |
6033 | set_current_program_space (loc->pspace); | |
6034 | ||
56435ebe | 6035 | if (b->display_canonical) |
d28cd78a | 6036 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 6037 | else if (loc && loc->symtab) |
0d381245 VP |
6038 | { |
6039 | struct symbol *sym | |
6040 | = find_pc_sect_function (loc->address, loc->section); | |
6041 | if (sym) | |
6042 | { | |
112e8700 SM |
6043 | uiout->text ("in "); |
6044 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); | |
6045 | uiout->text (" "); | |
6046 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
6047 | uiout->text ("at "); | |
0d381245 | 6048 | } |
112e8700 | 6049 | uiout->field_string ("file", |
05cba821 | 6050 | symtab_to_filename_for_display (loc->symtab)); |
112e8700 | 6051 | uiout->text (":"); |
05cba821 | 6052 | |
112e8700 SM |
6053 | if (uiout->is_mi_like_p ()) |
6054 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6055 | |
112e8700 | 6056 | uiout->field_int ("line", loc->line_number); |
0d381245 | 6057 | } |
859825b8 | 6058 | else if (loc) |
0d381245 | 6059 | { |
d7e74731 | 6060 | string_file stb; |
170b53b2 | 6061 | |
d7e74731 | 6062 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6063 | demangle, ""); |
112e8700 | 6064 | uiout->field_stream ("at", stb); |
0d381245 | 6065 | } |
859825b8 | 6066 | else |
f00aae0f | 6067 | { |
d28cd78a TT |
6068 | uiout->field_string ("pending", |
6069 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
6070 | /* If extra_string is available, it could be holding a condition |
6071 | or dprintf arguments. In either case, make sure it is printed, | |
6072 | too, but only for non-MI streams. */ | |
112e8700 | 6073 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6074 | { |
6075 | if (b->type == bp_dprintf) | |
112e8700 | 6076 | uiout->text (","); |
f00aae0f | 6077 | else |
112e8700 SM |
6078 | uiout->text (" "); |
6079 | uiout->text (b->extra_string); | |
f00aae0f KS |
6080 | } |
6081 | } | |
6c95b8df | 6082 | |
b775012e LM |
6083 | if (loc && is_breakpoint (b) |
6084 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6085 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6086 | { | |
112e8700 SM |
6087 | uiout->text (" ("); |
6088 | uiout->field_string ("evaluated-by", | |
b775012e | 6089 | bp_location_condition_evaluator (loc)); |
112e8700 | 6090 | uiout->text (")"); |
b775012e | 6091 | } |
0d381245 VP |
6092 | } |
6093 | ||
269b11a2 PA |
6094 | static const char * |
6095 | bptype_string (enum bptype type) | |
c906108c | 6096 | { |
c4093a6a JM |
6097 | struct ep_type_description |
6098 | { | |
6099 | enum bptype type; | |
a121b7c1 | 6100 | const char *description; |
c4093a6a JM |
6101 | }; |
6102 | static struct ep_type_description bptypes[] = | |
c906108c | 6103 | { |
c5aa993b JM |
6104 | {bp_none, "?deleted?"}, |
6105 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6106 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6107 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6108 | {bp_until, "until"}, |
6109 | {bp_finish, "finish"}, | |
6110 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6111 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6112 | {bp_read_watchpoint, "read watchpoint"}, |
6113 | {bp_access_watchpoint, "acc watchpoint"}, | |
6114 | {bp_longjmp, "longjmp"}, | |
6115 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6116 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6117 | {bp_exception, "exception"}, |
6118 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6119 | {bp_step_resume, "step resume"}, |
2c03e5be | 6120 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6121 | {bp_watchpoint_scope, "watchpoint scope"}, |
6122 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6123 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6124 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6125 | {bp_thread_event, "thread events"}, |
1900040c | 6126 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6127 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6128 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6129 | {bp_exception_master, "exception master"}, |
ce78b96d | 6130 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6131 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6132 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6133 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6134 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6135 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6136 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6137 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6138 | }; |
269b11a2 PA |
6139 | |
6140 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6141 | || ((int) type != bptypes[(int) type].type)) | |
6142 | internal_error (__FILE__, __LINE__, | |
6143 | _("bptypes table does not describe type #%d."), | |
6144 | (int) type); | |
6145 | ||
6146 | return bptypes[(int) type].description; | |
6147 | } | |
6148 | ||
998580f1 MK |
6149 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6150 | For CLI, prefix the list with the string 'inf'. */ | |
6151 | ||
6152 | static void | |
6153 | output_thread_groups (struct ui_out *uiout, | |
6154 | const char *field_name, | |
6155 | VEC(int) *inf_num, | |
6156 | int mi_only) | |
6157 | { | |
112e8700 | 6158 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6159 | int inf; |
6160 | int i; | |
6161 | ||
6162 | /* For backward compatibility, don't display inferiors in CLI unless | |
6163 | there are several. Always display them for MI. */ | |
6164 | if (!is_mi && mi_only) | |
6165 | return; | |
6166 | ||
10f489e5 | 6167 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6168 | |
998580f1 MK |
6169 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6170 | { | |
6171 | if (is_mi) | |
6172 | { | |
6173 | char mi_group[10]; | |
6174 | ||
6175 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
112e8700 | 6176 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6177 | } |
6178 | else | |
6179 | { | |
6180 | if (i == 0) | |
112e8700 | 6181 | uiout->text (" inf "); |
998580f1 | 6182 | else |
112e8700 | 6183 | uiout->text (", "); |
998580f1 | 6184 | |
112e8700 | 6185 | uiout->text (plongest (inf)); |
998580f1 MK |
6186 | } |
6187 | } | |
998580f1 MK |
6188 | } |
6189 | ||
269b11a2 PA |
6190 | /* Print B to gdb_stdout. */ |
6191 | ||
6192 | static void | |
6193 | print_one_breakpoint_location (struct breakpoint *b, | |
6194 | struct bp_location *loc, | |
6195 | int loc_number, | |
6196 | struct bp_location **last_loc, | |
269b11a2 PA |
6197 | int allflag) |
6198 | { | |
6199 | struct command_line *l; | |
c2c6d25f | 6200 | static char bpenables[] = "nynny"; |
c906108c | 6201 | |
79a45e25 | 6202 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6203 | int header_of_multiple = 0; |
6204 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6205 | struct value_print_options opts; |
6206 | ||
6207 | get_user_print_options (&opts); | |
0d381245 VP |
6208 | |
6209 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6210 | /* See comment in print_one_breakpoint concerning treatment of |
6211 | breakpoints with single disabled location. */ | |
0d381245 VP |
6212 | if (loc == NULL |
6213 | && (b->loc != NULL | |
6214 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6215 | header_of_multiple = 1; | |
6216 | if (loc == NULL) | |
6217 | loc = b->loc; | |
6218 | ||
c4093a6a JM |
6219 | annotate_record (); |
6220 | ||
6221 | /* 1 */ | |
6222 | annotate_field (0); | |
0d381245 VP |
6223 | if (part_of_multiple) |
6224 | { | |
6225 | char *formatted; | |
0c6773c1 | 6226 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
112e8700 | 6227 | uiout->field_string ("number", formatted); |
0d381245 VP |
6228 | xfree (formatted); |
6229 | } | |
6230 | else | |
6231 | { | |
112e8700 | 6232 | uiout->field_int ("number", b->number); |
0d381245 | 6233 | } |
c4093a6a JM |
6234 | |
6235 | /* 2 */ | |
6236 | annotate_field (1); | |
0d381245 | 6237 | if (part_of_multiple) |
112e8700 | 6238 | uiout->field_skip ("type"); |
269b11a2 | 6239 | else |
112e8700 | 6240 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6241 | |
6242 | /* 3 */ | |
6243 | annotate_field (2); | |
0d381245 | 6244 | if (part_of_multiple) |
112e8700 | 6245 | uiout->field_skip ("disp"); |
0d381245 | 6246 | else |
112e8700 | 6247 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6248 | |
c4093a6a JM |
6249 | |
6250 | /* 4 */ | |
6251 | annotate_field (3); | |
0d381245 | 6252 | if (part_of_multiple) |
112e8700 | 6253 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6254 | else |
112e8700 SM |
6255 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
6256 | uiout->spaces (2); | |
0d381245 | 6257 | |
c4093a6a JM |
6258 | |
6259 | /* 5 and 6 */ | |
3086aeae | 6260 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6261 | { |
4a64f543 MS |
6262 | /* Although the print_one can possibly print all locations, |
6263 | calling it here is not likely to get any nice result. So, | |
6264 | make sure there's just one location. */ | |
0d381245 | 6265 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6266 | b->ops->print_one (b, last_loc); |
0d381245 | 6267 | } |
3086aeae DJ |
6268 | else |
6269 | switch (b->type) | |
6270 | { | |
6271 | case bp_none: | |
6272 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6273 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6274 | break; |
c906108c | 6275 | |
3086aeae DJ |
6276 | case bp_watchpoint: |
6277 | case bp_hardware_watchpoint: | |
6278 | case bp_read_watchpoint: | |
6279 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6280 | { |
6281 | struct watchpoint *w = (struct watchpoint *) b; | |
6282 | ||
6283 | /* Field 4, the address, is omitted (which makes the columns | |
6284 | not line up too nicely with the headers, but the effect | |
6285 | is relatively readable). */ | |
6286 | if (opts.addressprint) | |
112e8700 | 6287 | uiout->field_skip ("addr"); |
3a5c3e22 | 6288 | annotate_field (5); |
112e8700 | 6289 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6290 | } |
3086aeae DJ |
6291 | break; |
6292 | ||
3086aeae DJ |
6293 | case bp_breakpoint: |
6294 | case bp_hardware_breakpoint: | |
7c16b83e | 6295 | case bp_single_step: |
3086aeae DJ |
6296 | case bp_until: |
6297 | case bp_finish: | |
6298 | case bp_longjmp: | |
6299 | case bp_longjmp_resume: | |
e2e4d78b | 6300 | case bp_longjmp_call_dummy: |
186c406b TT |
6301 | case bp_exception: |
6302 | case bp_exception_resume: | |
3086aeae | 6303 | case bp_step_resume: |
2c03e5be | 6304 | case bp_hp_step_resume: |
3086aeae DJ |
6305 | case bp_watchpoint_scope: |
6306 | case bp_call_dummy: | |
aa7d318d | 6307 | case bp_std_terminate: |
3086aeae DJ |
6308 | case bp_shlib_event: |
6309 | case bp_thread_event: | |
6310 | case bp_overlay_event: | |
0fd8e87f | 6311 | case bp_longjmp_master: |
aa7d318d | 6312 | case bp_std_terminate_master: |
186c406b | 6313 | case bp_exception_master: |
1042e4c0 | 6314 | case bp_tracepoint: |
7a697b8d | 6315 | case bp_fast_tracepoint: |
0fb4aa4b | 6316 | case bp_static_tracepoint: |
e7e0cddf | 6317 | case bp_dprintf: |
4efc6507 | 6318 | case bp_jit_event: |
0e30163f JK |
6319 | case bp_gnu_ifunc_resolver: |
6320 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6321 | if (opts.addressprint) |
3086aeae DJ |
6322 | { |
6323 | annotate_field (4); | |
54e52265 | 6324 | if (header_of_multiple) |
112e8700 | 6325 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6326 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6327 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6328 | else |
112e8700 | 6329 | uiout->field_core_addr ("addr", |
5af949e3 | 6330 | loc->gdbarch, loc->address); |
3086aeae DJ |
6331 | } |
6332 | annotate_field (5); | |
0d381245 | 6333 | if (!header_of_multiple) |
170b53b2 | 6334 | print_breakpoint_location (b, loc); |
0d381245 | 6335 | if (b->loc) |
a6d9a66e | 6336 | *last_loc = b->loc; |
3086aeae DJ |
6337 | break; |
6338 | } | |
c906108c | 6339 | |
6c95b8df | 6340 | |
998580f1 | 6341 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6342 | { |
6343 | struct inferior *inf; | |
998580f1 MK |
6344 | VEC(int) *inf_num = NULL; |
6345 | int mi_only = 1; | |
6c95b8df | 6346 | |
998580f1 | 6347 | ALL_INFERIORS (inf) |
6c95b8df PA |
6348 | { |
6349 | if (inf->pspace == loc->pspace) | |
998580f1 | 6350 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6351 | } |
998580f1 MK |
6352 | |
6353 | /* For backward compatibility, don't display inferiors in CLI unless | |
6354 | there are several. Always display for MI. */ | |
6355 | if (allflag | |
6356 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6357 | && (number_of_program_spaces () > 1 | |
6358 | || number_of_inferiors () > 1) | |
6359 | /* LOC is for existing B, it cannot be in | |
6360 | moribund_locations and thus having NULL OWNER. */ | |
6361 | && loc->owner->type != bp_catchpoint)) | |
6362 | mi_only = 0; | |
6363 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6364 | VEC_free (int, inf_num); | |
6c95b8df PA |
6365 | } |
6366 | ||
4a306c9a | 6367 | if (!part_of_multiple) |
c4093a6a | 6368 | { |
4a306c9a JB |
6369 | if (b->thread != -1) |
6370 | { | |
6371 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6372 | "stop only in" line a little further down. */ |
112e8700 SM |
6373 | uiout->text (" thread "); |
6374 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6375 | } |
6376 | else if (b->task != 0) | |
6377 | { | |
112e8700 SM |
6378 | uiout->text (" task "); |
6379 | uiout->field_int ("task", b->task); | |
4a306c9a | 6380 | } |
c4093a6a | 6381 | } |
f1310107 | 6382 | |
112e8700 | 6383 | uiout->text ("\n"); |
f1310107 | 6384 | |
348d480f | 6385 | if (!part_of_multiple) |
f1310107 TJB |
6386 | b->ops->print_one_detail (b, uiout); |
6387 | ||
0d381245 | 6388 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6389 | { |
6390 | annotate_field (6); | |
112e8700 | 6391 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6392 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6393 | the frame ID. */ |
112e8700 | 6394 | uiout->field_core_addr ("frame", |
5af949e3 | 6395 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6396 | uiout->text ("\n"); |
c4093a6a JM |
6397 | } |
6398 | ||
28010a5d | 6399 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6400 | { |
6401 | annotate_field (7); | |
d77f58be | 6402 | if (is_tracepoint (b)) |
112e8700 | 6403 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6404 | else |
112e8700 SM |
6405 | uiout->text ("\tstop only if "); |
6406 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6407 | |
6408 | /* Print whether the target is doing the breakpoint's condition | |
6409 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6410 | if (is_breakpoint (b) | |
6411 | && breakpoint_condition_evaluation_mode () | |
6412 | == condition_evaluation_target) | |
6413 | { | |
112e8700 SM |
6414 | uiout->text (" ("); |
6415 | uiout->field_string ("evaluated-by", | |
b775012e | 6416 | bp_condition_evaluator (b)); |
112e8700 | 6417 | uiout->text (" evals)"); |
b775012e | 6418 | } |
112e8700 | 6419 | uiout->text ("\n"); |
0101ce28 JJ |
6420 | } |
6421 | ||
0d381245 | 6422 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6423 | { |
4a64f543 | 6424 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6425 | uiout->text ("\tstop only in thread "); |
6426 | if (uiout->is_mi_like_p ()) | |
6427 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6428 | else |
6429 | { | |
6430 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6431 | ||
112e8700 | 6432 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6433 | } |
112e8700 | 6434 | uiout->text ("\n"); |
c4093a6a JM |
6435 | } |
6436 | ||
556ec64d YQ |
6437 | if (!part_of_multiple) |
6438 | { | |
6439 | if (b->hit_count) | |
31f56a27 YQ |
6440 | { |
6441 | /* FIXME should make an annotation for this. */ | |
6442 | if (is_catchpoint (b)) | |
112e8700 | 6443 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6444 | else if (is_tracepoint (b)) |
112e8700 | 6445 | uiout->text ("\ttracepoint"); |
31f56a27 | 6446 | else |
112e8700 SM |
6447 | uiout->text ("\tbreakpoint"); |
6448 | uiout->text (" already hit "); | |
6449 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6450 | if (b->hit_count == 1) |
112e8700 | 6451 | uiout->text (" time\n"); |
31f56a27 | 6452 | else |
112e8700 | 6453 | uiout->text (" times\n"); |
31f56a27 | 6454 | } |
556ec64d YQ |
6455 | else |
6456 | { | |
31f56a27 | 6457 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6458 | if (uiout->is_mi_like_p ()) |
6459 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6460 | } |
6461 | } | |
8b93c638 | 6462 | |
0d381245 | 6463 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6464 | { |
6465 | annotate_field (8); | |
112e8700 SM |
6466 | uiout->text ("\tignore next "); |
6467 | uiout->field_int ("ignore", b->ignore_count); | |
6468 | uiout->text (" hits\n"); | |
c4093a6a | 6469 | } |
059fb39f | 6470 | |
816338b5 SS |
6471 | /* Note that an enable count of 1 corresponds to "enable once" |
6472 | behavior, which is reported by the combination of enablement and | |
6473 | disposition, so we don't need to mention it here. */ | |
6474 | if (!part_of_multiple && b->enable_count > 1) | |
6475 | { | |
6476 | annotate_field (8); | |
112e8700 | 6477 | uiout->text ("\tdisable after "); |
816338b5 SS |
6478 | /* Tweak the wording to clarify that ignore and enable counts |
6479 | are distinct, and have additive effect. */ | |
6480 | if (b->ignore_count) | |
112e8700 | 6481 | uiout->text ("additional "); |
816338b5 | 6482 | else |
112e8700 SM |
6483 | uiout->text ("next "); |
6484 | uiout->field_int ("enable", b->enable_count); | |
6485 | uiout->text (" hits\n"); | |
816338b5 SS |
6486 | } |
6487 | ||
f196051f SS |
6488 | if (!part_of_multiple && is_tracepoint (b)) |
6489 | { | |
6490 | struct tracepoint *tp = (struct tracepoint *) b; | |
6491 | ||
6492 | if (tp->traceframe_usage) | |
6493 | { | |
112e8700 SM |
6494 | uiout->text ("\ttrace buffer usage "); |
6495 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6496 | uiout->text (" bytes\n"); | |
f196051f SS |
6497 | } |
6498 | } | |
d3ce09f5 | 6499 | |
d1b0a7bf | 6500 | l = b->commands ? b->commands.get () : NULL; |
059fb39f | 6501 | if (!part_of_multiple && l) |
c4093a6a JM |
6502 | { |
6503 | annotate_field (9); | |
2e783024 | 6504 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6505 | print_command_lines (uiout, l, 4); |
c4093a6a | 6506 | } |
d24317b4 | 6507 | |
d9b3f62e | 6508 | if (is_tracepoint (b)) |
1042e4c0 | 6509 | { |
d9b3f62e PA |
6510 | struct tracepoint *t = (struct tracepoint *) b; |
6511 | ||
6512 | if (!part_of_multiple && t->pass_count) | |
6513 | { | |
6514 | annotate_field (10); | |
112e8700 SM |
6515 | uiout->text ("\tpass count "); |
6516 | uiout->field_int ("pass", t->pass_count); | |
6517 | uiout->text (" \n"); | |
d9b3f62e | 6518 | } |
f2a8bc8a YQ |
6519 | |
6520 | /* Don't display it when tracepoint or tracepoint location is | |
6521 | pending. */ | |
6522 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6523 | { | |
6524 | annotate_field (11); | |
6525 | ||
112e8700 SM |
6526 | if (uiout->is_mi_like_p ()) |
6527 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6528 | loc->inserted ? "y" : "n"); |
6529 | else | |
6530 | { | |
6531 | if (loc->inserted) | |
112e8700 | 6532 | uiout->text ("\t"); |
f2a8bc8a | 6533 | else |
112e8700 SM |
6534 | uiout->text ("\tnot "); |
6535 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6536 | } |
6537 | } | |
1042e4c0 SS |
6538 | } |
6539 | ||
112e8700 | 6540 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6541 | { |
3a5c3e22 PA |
6542 | if (is_watchpoint (b)) |
6543 | { | |
6544 | struct watchpoint *w = (struct watchpoint *) b; | |
6545 | ||
112e8700 | 6546 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6547 | } |
f00aae0f | 6548 | else if (b->location != NULL |
d28cd78a | 6549 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6550 | uiout->field_string ("original-location", |
d28cd78a | 6551 | event_location_to_string (b->location.get ())); |
d24317b4 | 6552 | } |
c4093a6a | 6553 | } |
c5aa993b | 6554 | |
0d381245 VP |
6555 | static void |
6556 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6557 | struct bp_location **last_loc, |
6c95b8df | 6558 | int allflag) |
0d381245 | 6559 | { |
79a45e25 | 6560 | struct ui_out *uiout = current_uiout; |
8d3788bd | 6561 | |
2e783024 TT |
6562 | { |
6563 | ui_out_emit_tuple tuple_emitter (uiout, "bkpt"); | |
8d3788bd | 6564 | |
2e783024 TT |
6565 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
6566 | } | |
0d381245 VP |
6567 | |
6568 | /* If this breakpoint has custom print function, | |
6569 | it's already printed. Otherwise, print individual | |
6570 | locations, if any. */ | |
6571 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6572 | { | |
4a64f543 MS |
6573 | /* If breakpoint has a single location that is disabled, we |
6574 | print it as if it had several locations, since otherwise it's | |
6575 | hard to represent "breakpoint enabled, location disabled" | |
6576 | situation. | |
6577 | ||
6578 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6579 | internally, that's not a property exposed to user. */ |
0d381245 | 6580 | if (b->loc |
a5606eee | 6581 | && !is_hardware_watchpoint (b) |
8d3788bd | 6582 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6583 | { |
6584 | struct bp_location *loc; | |
6585 | int n = 1; | |
8d3788bd | 6586 | |
0d381245 | 6587 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd | 6588 | { |
2e783024 | 6589 | ui_out_emit_tuple tuple_emitter (uiout, NULL); |
8d3788bd | 6590 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
8d3788bd | 6591 | } |
0d381245 VP |
6592 | } |
6593 | } | |
6594 | } | |
6595 | ||
a6d9a66e UW |
6596 | static int |
6597 | breakpoint_address_bits (struct breakpoint *b) | |
6598 | { | |
6599 | int print_address_bits = 0; | |
6600 | struct bp_location *loc; | |
6601 | ||
c6d81124 PA |
6602 | /* Software watchpoints that aren't watching memory don't have an |
6603 | address to print. */ | |
6604 | if (is_no_memory_software_watchpoint (b)) | |
6605 | return 0; | |
6606 | ||
a6d9a66e UW |
6607 | for (loc = b->loc; loc; loc = loc->next) |
6608 | { | |
c7437ca6 PA |
6609 | int addr_bit; |
6610 | ||
c7437ca6 | 6611 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6612 | if (addr_bit > print_address_bits) |
6613 | print_address_bits = addr_bit; | |
6614 | } | |
6615 | ||
6616 | return print_address_bits; | |
6617 | } | |
0d381245 | 6618 | |
c4093a6a JM |
6619 | struct captured_breakpoint_query_args |
6620 | { | |
6621 | int bnum; | |
6622 | }; | |
c5aa993b | 6623 | |
c4093a6a | 6624 | static int |
2b65245e | 6625 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6626 | { |
9a3c8263 SM |
6627 | struct captured_breakpoint_query_args *args |
6628 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6629 | struct breakpoint *b; |
a6d9a66e | 6630 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6631 | |
c4093a6a JM |
6632 | ALL_BREAKPOINTS (b) |
6633 | { | |
6634 | if (args->bnum == b->number) | |
c5aa993b | 6635 | { |
12c5a436 | 6636 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6637 | return GDB_RC_OK; |
c5aa993b | 6638 | } |
c4093a6a JM |
6639 | } |
6640 | return GDB_RC_NONE; | |
6641 | } | |
c5aa993b | 6642 | |
c4093a6a | 6643 | enum gdb_rc |
4a64f543 MS |
6644 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6645 | char **error_message) | |
c4093a6a JM |
6646 | { |
6647 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6648 | |
c4093a6a JM |
6649 | args.bnum = bnum; |
6650 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6651 | an error. */ |
b0b13bb4 DJ |
6652 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6653 | error_message, RETURN_MASK_ALL) < 0) | |
6654 | return GDB_RC_FAIL; | |
6655 | else | |
6656 | return GDB_RC_OK; | |
c4093a6a | 6657 | } |
c5aa993b | 6658 | |
09d682a4 TT |
6659 | /* Return true if this breakpoint was set by the user, false if it is |
6660 | internal or momentary. */ | |
6661 | ||
6662 | int | |
6663 | user_breakpoint_p (struct breakpoint *b) | |
6664 | { | |
46c6471b | 6665 | return b->number > 0; |
09d682a4 TT |
6666 | } |
6667 | ||
93daf339 TT |
6668 | /* See breakpoint.h. */ |
6669 | ||
6670 | int | |
6671 | pending_breakpoint_p (struct breakpoint *b) | |
6672 | { | |
6673 | return b->loc == NULL; | |
6674 | } | |
6675 | ||
7f3b0473 | 6676 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6677 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6678 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6679 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6680 | ones for which it returns non-zero. Return the total number of | |
6681 | breakpoints listed. */ | |
c906108c | 6682 | |
d77f58be | 6683 | static int |
e5a67952 | 6684 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6685 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6686 | { |
52f0bd74 | 6687 | struct breakpoint *b; |
a6d9a66e | 6688 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6689 | int nr_printable_breakpoints; |
79a45b7d | 6690 | struct value_print_options opts; |
a6d9a66e | 6691 | int print_address_bits = 0; |
269b11a2 | 6692 | int print_type_col_width = 14; |
79a45e25 | 6693 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6694 | |
79a45b7d TT |
6695 | get_user_print_options (&opts); |
6696 | ||
4a64f543 MS |
6697 | /* Compute the number of rows in the table, as well as the size |
6698 | required for address fields. */ | |
7f3b0473 AC |
6699 | nr_printable_breakpoints = 0; |
6700 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6701 | { |
6702 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6703 | if (filter && !filter (b)) | |
6704 | continue; | |
6705 | ||
6706 | /* If we have an "args" string, it is a list of breakpoints to | |
6707 | accept. Skip the others. */ | |
6708 | if (args != NULL && *args != '\0') | |
6709 | { | |
6710 | if (allflag && parse_and_eval_long (args) != b->number) | |
6711 | continue; | |
6712 | if (!allflag && !number_is_in_list (args, b->number)) | |
6713 | continue; | |
6714 | } | |
269b11a2 | 6715 | |
e5a67952 MS |
6716 | if (allflag || user_breakpoint_p (b)) |
6717 | { | |
6718 | int addr_bit, type_len; | |
a6d9a66e | 6719 | |
e5a67952 MS |
6720 | addr_bit = breakpoint_address_bits (b); |
6721 | if (addr_bit > print_address_bits) | |
6722 | print_address_bits = addr_bit; | |
269b11a2 | 6723 | |
e5a67952 MS |
6724 | type_len = strlen (bptype_string (b->type)); |
6725 | if (type_len > print_type_col_width) | |
6726 | print_type_col_width = type_len; | |
6727 | ||
6728 | nr_printable_breakpoints++; | |
6729 | } | |
6730 | } | |
7f3b0473 | 6731 | |
4a2b031d TT |
6732 | { |
6733 | ui_out_emit_table table_emitter (uiout, | |
6734 | opts.addressprint ? 6 : 5, | |
6735 | nr_printable_breakpoints, | |
6736 | "BreakpointTable"); | |
6737 | ||
6738 | if (nr_printable_breakpoints > 0) | |
6739 | annotate_breakpoints_headers (); | |
6740 | if (nr_printable_breakpoints > 0) | |
6741 | annotate_field (0); | |
6742 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6743 | if (nr_printable_breakpoints > 0) | |
6744 | annotate_field (1); | |
6745 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6746 | if (nr_printable_breakpoints > 0) | |
6747 | annotate_field (2); | |
6748 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6749 | if (nr_printable_breakpoints > 0) | |
6750 | annotate_field (3); | |
6751 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6752 | if (opts.addressprint) | |
6753 | { | |
6754 | if (nr_printable_breakpoints > 0) | |
6755 | annotate_field (4); | |
6756 | if (print_address_bits <= 32) | |
6757 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6758 | else | |
6759 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6760 | } | |
6761 | if (nr_printable_breakpoints > 0) | |
6762 | annotate_field (5); | |
6763 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6764 | uiout->table_body (); | |
6765 | if (nr_printable_breakpoints > 0) | |
6766 | annotate_breakpoints_table (); | |
6767 | ||
6768 | ALL_BREAKPOINTS (b) | |
6769 | { | |
6770 | QUIT; | |
6771 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6772 | if (filter && !filter (b)) | |
6773 | continue; | |
e5a67952 | 6774 | |
4a2b031d TT |
6775 | /* If we have an "args" string, it is a list of breakpoints to |
6776 | accept. Skip the others. */ | |
e5a67952 | 6777 | |
4a2b031d TT |
6778 | if (args != NULL && *args != '\0') |
6779 | { | |
6780 | if (allflag) /* maintenance info breakpoint */ | |
6781 | { | |
6782 | if (parse_and_eval_long (args) != b->number) | |
6783 | continue; | |
6784 | } | |
6785 | else /* all others */ | |
6786 | { | |
6787 | if (!number_is_in_list (args, b->number)) | |
6788 | continue; | |
6789 | } | |
6790 | } | |
6791 | /* We only print out user settable breakpoints unless the | |
6792 | allflag is set. */ | |
6793 | if (allflag || user_breakpoint_p (b)) | |
6794 | print_one_breakpoint (b, &last_loc, allflag); | |
6795 | } | |
6796 | } | |
698384cd | 6797 | |
7f3b0473 | 6798 | if (nr_printable_breakpoints == 0) |
c906108c | 6799 | { |
4a64f543 MS |
6800 | /* If there's a filter, let the caller decide how to report |
6801 | empty list. */ | |
d77f58be SS |
6802 | if (!filter) |
6803 | { | |
e5a67952 | 6804 | if (args == NULL || *args == '\0') |
112e8700 | 6805 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6806 | else |
112e8700 | 6807 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6808 | args); |
d77f58be | 6809 | } |
c906108c SS |
6810 | } |
6811 | else | |
c4093a6a | 6812 | { |
a6d9a66e UW |
6813 | if (last_loc && !server_command) |
6814 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6815 | } |
c906108c | 6816 | |
4a64f543 | 6817 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6818 | there have been breakpoints? */ |
c906108c | 6819 | annotate_breakpoints_table_end (); |
d77f58be SS |
6820 | |
6821 | return nr_printable_breakpoints; | |
c906108c SS |
6822 | } |
6823 | ||
ad443146 SS |
6824 | /* Display the value of default-collect in a way that is generally |
6825 | compatible with the breakpoint list. */ | |
6826 | ||
6827 | static void | |
6828 | default_collect_info (void) | |
6829 | { | |
79a45e25 PA |
6830 | struct ui_out *uiout = current_uiout; |
6831 | ||
ad443146 SS |
6832 | /* If it has no value (which is frequently the case), say nothing; a |
6833 | message like "No default-collect." gets in user's face when it's | |
6834 | not wanted. */ | |
6835 | if (!*default_collect) | |
6836 | return; | |
6837 | ||
6838 | /* The following phrase lines up nicely with per-tracepoint collect | |
6839 | actions. */ | |
112e8700 SM |
6840 | uiout->text ("default collect "); |
6841 | uiout->field_string ("default-collect", default_collect); | |
6842 | uiout->text (" \n"); | |
ad443146 SS |
6843 | } |
6844 | ||
c906108c | 6845 | static void |
11db9430 | 6846 | info_breakpoints_command (char *args, int from_tty) |
c906108c | 6847 | { |
e5a67952 | 6848 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6849 | |
6850 | default_collect_info (); | |
d77f58be SS |
6851 | } |
6852 | ||
6853 | static void | |
11db9430 | 6854 | info_watchpoints_command (char *args, int from_tty) |
d77f58be | 6855 | { |
e5a67952 | 6856 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6857 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6858 | |
6859 | if (num_printed == 0) | |
6860 | { | |
e5a67952 | 6861 | if (args == NULL || *args == '\0') |
112e8700 | 6862 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6863 | else |
112e8700 | 6864 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6865 | } |
c906108c SS |
6866 | } |
6867 | ||
7a292a7a | 6868 | static void |
e5a67952 | 6869 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6870 | { |
e5a67952 | 6871 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6872 | |
6873 | default_collect_info (); | |
c906108c SS |
6874 | } |
6875 | ||
0d381245 | 6876 | static int |
714835d5 | 6877 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6878 | struct program_space *pspace, |
714835d5 | 6879 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6880 | { |
6881 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6882 | |
0d381245 VP |
6883 | for (; bl; bl = bl->next) |
6884 | { | |
6c95b8df PA |
6885 | if (bl->pspace == pspace |
6886 | && bl->address == pc | |
0d381245 VP |
6887 | && (!overlay_debugging || bl->section == section)) |
6888 | return 1; | |
6889 | } | |
6890 | return 0; | |
6891 | } | |
6892 | ||
672f9b60 | 6893 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
6894 | concerns with logical breakpoints, so we match program spaces, not |
6895 | address spaces. */ | |
c906108c SS |
6896 | |
6897 | static void | |
6c95b8df PA |
6898 | describe_other_breakpoints (struct gdbarch *gdbarch, |
6899 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 6900 | struct obj_section *section, int thread) |
c906108c | 6901 | { |
52f0bd74 AC |
6902 | int others = 0; |
6903 | struct breakpoint *b; | |
c906108c SS |
6904 | |
6905 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
6906 | others += (user_breakpoint_p (b) |
6907 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
6908 | if (others > 0) |
6909 | { | |
a3f17187 AC |
6910 | if (others == 1) |
6911 | printf_filtered (_("Note: breakpoint ")); | |
6912 | else /* if (others == ???) */ | |
6913 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 6914 | ALL_BREAKPOINTS (b) |
672f9b60 | 6915 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
6916 | { |
6917 | others--; | |
6918 | printf_filtered ("%d", b->number); | |
6919 | if (b->thread == -1 && thread != -1) | |
6920 | printf_filtered (" (all threads)"); | |
6921 | else if (b->thread != -1) | |
6922 | printf_filtered (" (thread %d)", b->thread); | |
6923 | printf_filtered ("%s%s ", | |
059fb39f | 6924 | ((b->enable_state == bp_disabled |
f8eba3c6 | 6925 | || b->enable_state == bp_call_disabled) |
0d381245 | 6926 | ? " (disabled)" |
0d381245 VP |
6927 | : ""), |
6928 | (others > 1) ? "," | |
6929 | : ((others == 1) ? " and" : "")); | |
6930 | } | |
a3f17187 | 6931 | printf_filtered (_("also set at pc ")); |
5af949e3 | 6932 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
6933 | printf_filtered (".\n"); |
6934 | } | |
6935 | } | |
6936 | \f | |
c906108c | 6937 | |
e4f237da | 6938 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
6939 | BPT locations. For some breakpoint types, the locations' address members |
6940 | are irrelevant and it makes no sense to attempt to compare them to other | |
6941 | addresses (or use them for any other purpose either). | |
e4f237da | 6942 | |
4a64f543 | 6943 | More specifically, each of the following breakpoint types will |
244558af | 6944 | always have a zero valued location address and we don't want to mark |
4a64f543 | 6945 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 6946 | breakpoint location at address zero: |
e4f237da KB |
6947 | |
6948 | bp_watchpoint | |
2d134ed3 PA |
6949 | bp_catchpoint |
6950 | ||
6951 | */ | |
e4f237da KB |
6952 | |
6953 | static int | |
6954 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
6955 | { | |
6956 | enum bptype type = bpt->type; | |
6957 | ||
2d134ed3 PA |
6958 | return (type != bp_watchpoint && type != bp_catchpoint); |
6959 | } | |
6960 | ||
6961 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
6962 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
6963 | ||
6964 | static int | |
4a64f543 MS |
6965 | watchpoint_locations_match (struct bp_location *loc1, |
6966 | struct bp_location *loc2) | |
2d134ed3 | 6967 | { |
3a5c3e22 PA |
6968 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
6969 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
6970 | ||
6971 | /* Both of them must exist. */ | |
6972 | gdb_assert (w1 != NULL); | |
6973 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 6974 | |
4a64f543 MS |
6975 | /* If the target can evaluate the condition expression in hardware, |
6976 | then we we need to insert both watchpoints even if they are at | |
6977 | the same place. Otherwise the watchpoint will only trigger when | |
6978 | the condition of whichever watchpoint was inserted evaluates to | |
6979 | true, not giving a chance for GDB to check the condition of the | |
6980 | other watchpoint. */ | |
3a5c3e22 | 6981 | if ((w1->cond_exp |
4a64f543 MS |
6982 | && target_can_accel_watchpoint_condition (loc1->address, |
6983 | loc1->length, | |
0cf6dd15 | 6984 | loc1->watchpoint_type, |
4d01a485 | 6985 | w1->cond_exp.get ())) |
3a5c3e22 | 6986 | || (w2->cond_exp |
4a64f543 MS |
6987 | && target_can_accel_watchpoint_condition (loc2->address, |
6988 | loc2->length, | |
0cf6dd15 | 6989 | loc2->watchpoint_type, |
4d01a485 | 6990 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
6991 | return 0; |
6992 | ||
85d721b8 PA |
6993 | /* Note that this checks the owner's type, not the location's. In |
6994 | case the target does not support read watchpoints, but does | |
6995 | support access watchpoints, we'll have bp_read_watchpoint | |
6996 | watchpoints with hw_access locations. Those should be considered | |
6997 | duplicates of hw_read locations. The hw_read locations will | |
6998 | become hw_access locations later. */ | |
2d134ed3 PA |
6999 | return (loc1->owner->type == loc2->owner->type |
7000 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7001 | && loc1->address == loc2->address | |
7002 | && loc1->length == loc2->length); | |
e4f237da KB |
7003 | } |
7004 | ||
31e77af2 | 7005 | /* See breakpoint.h. */ |
6c95b8df | 7006 | |
31e77af2 | 7007 | int |
6c95b8df PA |
7008 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7009 | struct address_space *aspace2, CORE_ADDR addr2) | |
7010 | { | |
f5656ead | 7011 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7012 | || aspace1 == aspace2) |
7013 | && addr1 == addr2); | |
7014 | } | |
7015 | ||
f1310107 TJB |
7016 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7017 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7018 | matches ASPACE2. On targets that have global breakpoints, the address | |
7019 | space doesn't really matter. */ | |
7020 | ||
7021 | static int | |
7022 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7023 | int len1, struct address_space *aspace2, | |
7024 | CORE_ADDR addr2) | |
7025 | { | |
f5656ead | 7026 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7027 | || aspace1 == aspace2) |
7028 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7029 | } | |
7030 | ||
7031 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7032 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7033 | matches the breakpoint's address space. On targets that have global | |
7034 | breakpoints, the address space doesn't really matter. */ | |
7035 | ||
7036 | static int | |
7037 | breakpoint_location_address_match (struct bp_location *bl, | |
7038 | struct address_space *aspace, | |
7039 | CORE_ADDR addr) | |
7040 | { | |
7041 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7042 | aspace, addr) | |
7043 | || (bl->length | |
7044 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7045 | bl->address, bl->length, | |
7046 | aspace, addr))); | |
7047 | } | |
7048 | ||
d35ae833 PA |
7049 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7050 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7051 | match happens only if ASPACE matches the breakpoint's address | |
7052 | space. On targets that have global breakpoints, the address space | |
7053 | doesn't really matter. */ | |
7054 | ||
7055 | static int | |
7056 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7057 | struct address_space *aspace, | |
7058 | CORE_ADDR addr, int len) | |
7059 | { | |
7060 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7061 | || bl->pspace->aspace == aspace) | |
7062 | { | |
7063 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7064 | ||
7065 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7066 | return 1; | |
7067 | } | |
7068 | return 0; | |
7069 | } | |
7070 | ||
1e4d1764 YQ |
7071 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7072 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7073 | true, otherwise returns false. */ | |
7074 | ||
7075 | static int | |
7076 | tracepoint_locations_match (struct bp_location *loc1, | |
7077 | struct bp_location *loc2) | |
7078 | { | |
7079 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7080 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7081 | locations at the same address of different tracepoints are regarded as | |
7082 | different locations. */ | |
7083 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7084 | else | |
7085 | return 0; | |
7086 | } | |
7087 | ||
2d134ed3 PA |
7088 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7089 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7090 | represent the same location. */ | |
7091 | ||
7092 | static int | |
4a64f543 MS |
7093 | breakpoint_locations_match (struct bp_location *loc1, |
7094 | struct bp_location *loc2) | |
2d134ed3 | 7095 | { |
2bdf28a0 JK |
7096 | int hw_point1, hw_point2; |
7097 | ||
7098 | /* Both of them must not be in moribund_locations. */ | |
7099 | gdb_assert (loc1->owner != NULL); | |
7100 | gdb_assert (loc2->owner != NULL); | |
7101 | ||
7102 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7103 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7104 | |
7105 | if (hw_point1 != hw_point2) | |
7106 | return 0; | |
7107 | else if (hw_point1) | |
7108 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7109 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7110 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7111 | else |
f1310107 TJB |
7112 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7113 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7114 | loc2->pspace->aspace, loc2->address) | |
7115 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7116 | } |
7117 | ||
76897487 KB |
7118 | static void |
7119 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7120 | int bnum, int have_bnum) | |
7121 | { | |
f63fbe86 MS |
7122 | /* The longest string possibly returned by hex_string_custom |
7123 | is 50 chars. These must be at least that big for safety. */ | |
7124 | char astr1[64]; | |
7125 | char astr2[64]; | |
76897487 | 7126 | |
bb599908 PH |
7127 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7128 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7129 | if (have_bnum) |
8a3fe4f8 | 7130 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7131 | bnum, astr1, astr2); |
7132 | else | |
8a3fe4f8 | 7133 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7134 | } |
7135 | ||
4a64f543 MS |
7136 | /* Adjust a breakpoint's address to account for architectural |
7137 | constraints on breakpoint placement. Return the adjusted address. | |
7138 | Note: Very few targets require this kind of adjustment. For most | |
7139 | targets, this function is simply the identity function. */ | |
76897487 KB |
7140 | |
7141 | static CORE_ADDR | |
a6d9a66e UW |
7142 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7143 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7144 | { |
a6d9a66e | 7145 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7146 | { |
7147 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7148 | return bpaddr; | |
7149 | } | |
88f7da05 KB |
7150 | else if (bptype == bp_watchpoint |
7151 | || bptype == bp_hardware_watchpoint | |
7152 | || bptype == bp_read_watchpoint | |
7153 | || bptype == bp_access_watchpoint | |
fe798b75 | 7154 | || bptype == bp_catchpoint) |
88f7da05 KB |
7155 | { |
7156 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7157 | have their addresses modified. */ | |
7158 | return bpaddr; | |
7159 | } | |
7c16b83e PA |
7160 | else if (bptype == bp_single_step) |
7161 | { | |
7162 | /* Single-step breakpoints should not have their addresses | |
7163 | modified. If there's any architectural constrain that | |
7164 | applies to this address, then it should have already been | |
7165 | taken into account when the breakpoint was created in the | |
7166 | first place. If we didn't do this, stepping through e.g., | |
7167 | Thumb-2 IT blocks would break. */ | |
7168 | return bpaddr; | |
7169 | } | |
76897487 KB |
7170 | else |
7171 | { | |
7172 | CORE_ADDR adjusted_bpaddr; | |
7173 | ||
7174 | /* Some targets have architectural constraints on the placement | |
7175 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7176 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7177 | |
7178 | /* An adjusted breakpoint address can significantly alter | |
7179 | a user's expectations. Print a warning if an adjustment | |
7180 | is required. */ | |
7181 | if (adjusted_bpaddr != bpaddr) | |
7182 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7183 | ||
7184 | return adjusted_bpaddr; | |
7185 | } | |
7186 | } | |
7187 | ||
5625a286 | 7188 | bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner) |
7cc221ef | 7189 | { |
5625a286 | 7190 | bp_location *loc = this; |
7cc221ef | 7191 | |
348d480f PA |
7192 | gdb_assert (ops != NULL); |
7193 | ||
28010a5d PA |
7194 | loc->ops = ops; |
7195 | loc->owner = owner; | |
b775012e | 7196 | loc->cond_bytecode = NULL; |
0d381245 VP |
7197 | loc->shlib_disabled = 0; |
7198 | loc->enabled = 1; | |
e049a4b5 | 7199 | |
28010a5d | 7200 | switch (owner->type) |
e049a4b5 DJ |
7201 | { |
7202 | case bp_breakpoint: | |
7c16b83e | 7203 | case bp_single_step: |
e049a4b5 DJ |
7204 | case bp_until: |
7205 | case bp_finish: | |
7206 | case bp_longjmp: | |
7207 | case bp_longjmp_resume: | |
e2e4d78b | 7208 | case bp_longjmp_call_dummy: |
186c406b TT |
7209 | case bp_exception: |
7210 | case bp_exception_resume: | |
e049a4b5 | 7211 | case bp_step_resume: |
2c03e5be | 7212 | case bp_hp_step_resume: |
e049a4b5 DJ |
7213 | case bp_watchpoint_scope: |
7214 | case bp_call_dummy: | |
aa7d318d | 7215 | case bp_std_terminate: |
e049a4b5 DJ |
7216 | case bp_shlib_event: |
7217 | case bp_thread_event: | |
7218 | case bp_overlay_event: | |
4efc6507 | 7219 | case bp_jit_event: |
0fd8e87f | 7220 | case bp_longjmp_master: |
aa7d318d | 7221 | case bp_std_terminate_master: |
186c406b | 7222 | case bp_exception_master: |
0e30163f JK |
7223 | case bp_gnu_ifunc_resolver: |
7224 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7225 | case bp_dprintf: |
e049a4b5 | 7226 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7227 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7228 | break; |
7229 | case bp_hardware_breakpoint: | |
7230 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7231 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7232 | break; |
7233 | case bp_hardware_watchpoint: | |
7234 | case bp_read_watchpoint: | |
7235 | case bp_access_watchpoint: | |
7236 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7237 | break; | |
7238 | case bp_watchpoint: | |
ce78b96d | 7239 | case bp_catchpoint: |
15c3d785 PA |
7240 | case bp_tracepoint: |
7241 | case bp_fast_tracepoint: | |
0fb4aa4b | 7242 | case bp_static_tracepoint: |
e049a4b5 DJ |
7243 | loc->loc_type = bp_loc_other; |
7244 | break; | |
7245 | default: | |
e2e0b3e5 | 7246 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7247 | } |
7248 | ||
f431efe5 | 7249 | loc->refc = 1; |
28010a5d PA |
7250 | } |
7251 | ||
7252 | /* Allocate a struct bp_location. */ | |
7253 | ||
7254 | static struct bp_location * | |
7255 | allocate_bp_location (struct breakpoint *bpt) | |
7256 | { | |
348d480f PA |
7257 | return bpt->ops->allocate_location (bpt); |
7258 | } | |
7cc221ef | 7259 | |
f431efe5 PA |
7260 | static void |
7261 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7262 | { |
348d480f | 7263 | loc->ops->dtor (loc); |
4d01a485 | 7264 | delete loc; |
fe3f5fa8 VP |
7265 | } |
7266 | ||
f431efe5 PA |
7267 | /* Increment reference count. */ |
7268 | ||
7269 | static void | |
7270 | incref_bp_location (struct bp_location *bl) | |
7271 | { | |
7272 | ++bl->refc; | |
7273 | } | |
7274 | ||
7275 | /* Decrement reference count. If the reference count reaches 0, | |
7276 | destroy the bp_location. Sets *BLP to NULL. */ | |
7277 | ||
7278 | static void | |
7279 | decref_bp_location (struct bp_location **blp) | |
7280 | { | |
0807b50c PA |
7281 | gdb_assert ((*blp)->refc > 0); |
7282 | ||
f431efe5 PA |
7283 | if (--(*blp)->refc == 0) |
7284 | free_bp_location (*blp); | |
7285 | *blp = NULL; | |
7286 | } | |
7287 | ||
346774a9 | 7288 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7289 | |
b270e6f9 TT |
7290 | static breakpoint * |
7291 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7292 | { |
346774a9 | 7293 | struct breakpoint *b1; |
b270e6f9 | 7294 | struct breakpoint *result = b.get (); |
c906108c | 7295 | |
346774a9 PA |
7296 | /* Add this breakpoint to the end of the chain so that a list of |
7297 | breakpoints will come out in order of increasing numbers. */ | |
7298 | ||
7299 | b1 = breakpoint_chain; | |
7300 | if (b1 == 0) | |
b270e6f9 | 7301 | breakpoint_chain = b.release (); |
346774a9 PA |
7302 | else |
7303 | { | |
7304 | while (b1->next) | |
7305 | b1 = b1->next; | |
b270e6f9 | 7306 | b1->next = b.release (); |
346774a9 | 7307 | } |
b270e6f9 TT |
7308 | |
7309 | return result; | |
346774a9 PA |
7310 | } |
7311 | ||
7312 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7313 | ||
7314 | static void | |
7315 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7316 | struct gdbarch *gdbarch, | |
28010a5d | 7317 | enum bptype bptype, |
c0a91b2b | 7318 | const struct breakpoint_ops *ops) |
346774a9 | 7319 | { |
348d480f PA |
7320 | gdb_assert (ops != NULL); |
7321 | ||
28010a5d | 7322 | b->ops = ops; |
4d28f7a8 | 7323 | b->type = bptype; |
a6d9a66e | 7324 | b->gdbarch = gdbarch; |
c906108c SS |
7325 | b->language = current_language->la_language; |
7326 | b->input_radix = input_radix; | |
d0fb5eae | 7327 | b->related_breakpoint = b; |
346774a9 PA |
7328 | } |
7329 | ||
7330 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7331 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7332 | |
7333 | static struct breakpoint * | |
7334 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7335 | enum bptype bptype, |
c0a91b2b | 7336 | const struct breakpoint_ops *ops) |
346774a9 | 7337 | { |
3b0871f4 | 7338 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7339 | |
3b0871f4 | 7340 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7341 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7342 | } |
7343 | ||
0e30163f JK |
7344 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7345 | resolutions should be made as the user specified the location explicitly | |
7346 | enough. */ | |
7347 | ||
0d381245 | 7348 | static void |
0e30163f | 7349 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7350 | { |
2bdf28a0 JK |
7351 | gdb_assert (loc->owner != NULL); |
7352 | ||
0d381245 | 7353 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7354 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7355 | || is_tracepoint (loc->owner)) |
0d381245 | 7356 | { |
0e30163f | 7357 | int is_gnu_ifunc; |
2c02bd72 | 7358 | const char *function_name; |
6a3a010b | 7359 | CORE_ADDR func_addr; |
0e30163f | 7360 | |
2c02bd72 | 7361 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7362 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7363 | |
7364 | if (is_gnu_ifunc && !explicit_loc) | |
7365 | { | |
7366 | struct breakpoint *b = loc->owner; | |
7367 | ||
7368 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7369 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7370 | &loc->requested_address)) |
7371 | { | |
7372 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7373 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7374 | loc->requested_address, | |
7375 | b->type); | |
7376 | } | |
7377 | else if (b->type == bp_breakpoint && b->loc == loc | |
7378 | && loc->next == NULL && b->related_breakpoint == b) | |
7379 | { | |
7380 | /* Create only the whole new breakpoint of this type but do not | |
7381 | mess more complicated breakpoints with multiple locations. */ | |
7382 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7383 | /* Remember the resolver's address for use by the return |
7384 | breakpoint. */ | |
7385 | loc->related_address = func_addr; | |
0e30163f JK |
7386 | } |
7387 | } | |
7388 | ||
2c02bd72 DE |
7389 | if (function_name) |
7390 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7391 | } |
7392 | } | |
7393 | ||
a6d9a66e | 7394 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7395 | struct gdbarch * |
a6d9a66e UW |
7396 | get_sal_arch (struct symtab_and_line sal) |
7397 | { | |
7398 | if (sal.section) | |
7399 | return get_objfile_arch (sal.section->objfile); | |
7400 | if (sal.symtab) | |
eb822aa6 | 7401 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7402 | |
7403 | return NULL; | |
7404 | } | |
7405 | ||
346774a9 PA |
7406 | /* Low level routine for partially initializing a breakpoint of type |
7407 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7408 | file name, and line number are provided by SAL. |
0d381245 VP |
7409 | |
7410 | It is expected that the caller will complete the initialization of | |
7411 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7412 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7413 | |
346774a9 PA |
7414 | static void |
7415 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7416 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7417 | const struct breakpoint_ops *ops) |
0d381245 | 7418 | { |
28010a5d | 7419 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7420 | |
3742cc8b | 7421 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7422 | |
6c95b8df PA |
7423 | if (bptype != bp_catchpoint) |
7424 | gdb_assert (sal.pspace != NULL); | |
7425 | ||
f8eba3c6 TT |
7426 | /* Store the program space that was used to set the breakpoint, |
7427 | except for ordinary breakpoints, which are independent of the | |
7428 | program space. */ | |
7429 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7430 | b->pspace = sal.pspace; | |
346774a9 | 7431 | } |
c906108c | 7432 | |
346774a9 PA |
7433 | /* set_raw_breakpoint is a low level routine for allocating and |
7434 | partially initializing a breakpoint of type BPTYPE. The newly | |
7435 | created breakpoint's address, section, source file name, and line | |
7436 | number are provided by SAL. The newly created and partially | |
7437 | initialized breakpoint is added to the breakpoint chain and | |
7438 | is also returned as the value of this function. | |
7439 | ||
7440 | It is expected that the caller will complete the initialization of | |
7441 | the newly created breakpoint struct as well as output any status | |
7442 | information regarding the creation of a new breakpoint. In | |
7443 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7444 | number! Care should be taken to not allow an error to occur | |
7445 | prior to completing the initialization of the breakpoint. If this | |
7446 | should happen, a bogus breakpoint will be left on the chain. */ | |
7447 | ||
7448 | struct breakpoint * | |
7449 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7450 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7451 | const struct breakpoint_ops *ops) |
346774a9 | 7452 | { |
3b0871f4 | 7453 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7454 | |
3b0871f4 | 7455 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7456 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7457 | } |
7458 | ||
53a5351d | 7459 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7460 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7461 | initiated the operation. */ | |
c906108c SS |
7462 | |
7463 | void | |
186c406b | 7464 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7465 | { |
35df4500 | 7466 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7467 | int thread = tp->global_num; |
0fd8e87f UW |
7468 | |
7469 | /* To avoid having to rescan all objfile symbols at every step, | |
7470 | we maintain a list of continually-inserted but always disabled | |
7471 | longjmp "master" breakpoints. Here, we simply create momentary | |
7472 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7473 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7474 | if (b->pspace == current_program_space |
186c406b TT |
7475 | && (b->type == bp_longjmp_master |
7476 | || b->type == bp_exception_master)) | |
0fd8e87f | 7477 | { |
06edf0c0 PA |
7478 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7479 | struct breakpoint *clone; | |
cc59ec59 | 7480 | |
e2e4d78b JK |
7481 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7482 | after their removal. */ | |
06edf0c0 | 7483 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7484 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7485 | clone->thread = thread; |
7486 | } | |
186c406b TT |
7487 | |
7488 | tp->initiating_frame = frame; | |
c906108c SS |
7489 | } |
7490 | ||
611c83ae | 7491 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7492 | void |
611c83ae | 7493 | delete_longjmp_breakpoint (int thread) |
c906108c | 7494 | { |
35df4500 | 7495 | struct breakpoint *b, *b_tmp; |
c906108c | 7496 | |
35df4500 | 7497 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7498 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7499 | { |
7500 | if (b->thread == thread) | |
7501 | delete_breakpoint (b); | |
7502 | } | |
c906108c SS |
7503 | } |
7504 | ||
f59f708a PA |
7505 | void |
7506 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7507 | { | |
7508 | struct breakpoint *b, *b_tmp; | |
7509 | ||
7510 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7511 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7512 | { | |
7513 | if (b->thread == thread) | |
7514 | b->disposition = disp_del_at_next_stop; | |
7515 | } | |
7516 | } | |
7517 | ||
e2e4d78b JK |
7518 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7519 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7520 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7521 | breakpoints. */ | |
7522 | ||
7523 | struct breakpoint * | |
7524 | set_longjmp_breakpoint_for_call_dummy (void) | |
7525 | { | |
7526 | struct breakpoint *b, *retval = NULL; | |
7527 | ||
7528 | ALL_BREAKPOINTS (b) | |
7529 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7530 | { | |
7531 | struct breakpoint *new_b; | |
7532 | ||
7533 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7534 | &momentary_breakpoint_ops, |
7535 | 1); | |
5d5658a1 | 7536 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7537 | |
7538 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7539 | ||
7540 | gdb_assert (new_b->related_breakpoint == new_b); | |
7541 | if (retval == NULL) | |
7542 | retval = new_b; | |
7543 | new_b->related_breakpoint = retval; | |
7544 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7545 | retval = retval->related_breakpoint; | |
7546 | retval->related_breakpoint = new_b; | |
7547 | } | |
7548 | ||
7549 | return retval; | |
7550 | } | |
7551 | ||
7552 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7553 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7554 | stack. |
7555 | ||
7556 | You should call this function only at places where it is safe to currently | |
7557 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7558 | frames. */ | |
7559 | ||
7560 | void | |
b67a2c6f | 7561 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7562 | { |
7563 | struct breakpoint *b, *b_tmp; | |
7564 | ||
7565 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7566 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7567 | { |
7568 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7569 | ||
7570 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7571 | dummy_b = dummy_b->related_breakpoint; | |
7572 | if (dummy_b->type != bp_call_dummy | |
7573 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7574 | continue; | |
7575 | ||
b67a2c6f | 7576 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7577 | |
7578 | while (b->related_breakpoint != b) | |
7579 | { | |
7580 | if (b_tmp == b->related_breakpoint) | |
7581 | b_tmp = b->related_breakpoint->next; | |
7582 | delete_breakpoint (b->related_breakpoint); | |
7583 | } | |
7584 | delete_breakpoint (b); | |
7585 | } | |
7586 | } | |
7587 | ||
1900040c MS |
7588 | void |
7589 | enable_overlay_breakpoints (void) | |
7590 | { | |
52f0bd74 | 7591 | struct breakpoint *b; |
1900040c MS |
7592 | |
7593 | ALL_BREAKPOINTS (b) | |
7594 | if (b->type == bp_overlay_event) | |
7595 | { | |
7596 | b->enable_state = bp_enabled; | |
44702360 | 7597 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7598 | overlay_events_enabled = 1; |
1900040c MS |
7599 | } |
7600 | } | |
7601 | ||
7602 | void | |
7603 | disable_overlay_breakpoints (void) | |
7604 | { | |
52f0bd74 | 7605 | struct breakpoint *b; |
1900040c MS |
7606 | |
7607 | ALL_BREAKPOINTS (b) | |
7608 | if (b->type == bp_overlay_event) | |
7609 | { | |
7610 | b->enable_state = bp_disabled; | |
44702360 | 7611 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7612 | overlay_events_enabled = 0; |
1900040c MS |
7613 | } |
7614 | } | |
7615 | ||
aa7d318d TT |
7616 | /* Set an active std::terminate breakpoint for each std::terminate |
7617 | master breakpoint. */ | |
7618 | void | |
7619 | set_std_terminate_breakpoint (void) | |
7620 | { | |
35df4500 | 7621 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7622 | |
35df4500 | 7623 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7624 | if (b->pspace == current_program_space |
7625 | && b->type == bp_std_terminate_master) | |
7626 | { | |
06edf0c0 | 7627 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7628 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7629 | } |
7630 | } | |
7631 | ||
7632 | /* Delete all the std::terminate breakpoints. */ | |
7633 | void | |
7634 | delete_std_terminate_breakpoint (void) | |
7635 | { | |
35df4500 | 7636 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7637 | |
35df4500 | 7638 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7639 | if (b->type == bp_std_terminate) |
7640 | delete_breakpoint (b); | |
7641 | } | |
7642 | ||
c4093a6a | 7643 | struct breakpoint * |
a6d9a66e | 7644 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7645 | { |
7646 | struct breakpoint *b; | |
c4093a6a | 7647 | |
06edf0c0 PA |
7648 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7649 | &internal_breakpoint_ops); | |
7650 | ||
b5de0fa7 | 7651 | b->enable_state = bp_enabled; |
f00aae0f | 7652 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7653 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7654 | |
44702360 | 7655 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7656 | |
c4093a6a JM |
7657 | return b; |
7658 | } | |
7659 | ||
0101ce28 JJ |
7660 | struct lang_and_radix |
7661 | { | |
7662 | enum language lang; | |
7663 | int radix; | |
7664 | }; | |
7665 | ||
4efc6507 DE |
7666 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7667 | ||
7668 | struct breakpoint * | |
7669 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7670 | { | |
2a7f3dff PA |
7671 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7672 | &internal_breakpoint_ops); | |
4efc6507 | 7673 | } |
0101ce28 | 7674 | |
03673fc7 PP |
7675 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7676 | ||
7677 | void | |
7678 | remove_jit_event_breakpoints (void) | |
7679 | { | |
7680 | struct breakpoint *b, *b_tmp; | |
7681 | ||
7682 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7683 | if (b->type == bp_jit_event | |
7684 | && b->loc->pspace == current_program_space) | |
7685 | delete_breakpoint (b); | |
7686 | } | |
7687 | ||
cae688ec JJ |
7688 | void |
7689 | remove_solib_event_breakpoints (void) | |
7690 | { | |
35df4500 | 7691 | struct breakpoint *b, *b_tmp; |
cae688ec | 7692 | |
35df4500 | 7693 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7694 | if (b->type == bp_shlib_event |
7695 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7696 | delete_breakpoint (b); |
7697 | } | |
7698 | ||
f37f681c PA |
7699 | /* See breakpoint.h. */ |
7700 | ||
7701 | void | |
7702 | remove_solib_event_breakpoints_at_next_stop (void) | |
7703 | { | |
7704 | struct breakpoint *b, *b_tmp; | |
7705 | ||
7706 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7707 | if (b->type == bp_shlib_event | |
7708 | && b->loc->pspace == current_program_space) | |
7709 | b->disposition = disp_del_at_next_stop; | |
7710 | } | |
7711 | ||
04086b45 PA |
7712 | /* Helper for create_solib_event_breakpoint / |
7713 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7714 | INSERT_MODE to pass through to update_global_location_list. */ | |
7715 | ||
7716 | static struct breakpoint * | |
7717 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7718 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7719 | { |
7720 | struct breakpoint *b; | |
7721 | ||
06edf0c0 PA |
7722 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7723 | &internal_breakpoint_ops); | |
04086b45 | 7724 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7725 | return b; |
7726 | } | |
7727 | ||
04086b45 PA |
7728 | struct breakpoint * |
7729 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7730 | { | |
7731 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7732 | } | |
7733 | ||
f37f681c PA |
7734 | /* See breakpoint.h. */ |
7735 | ||
7736 | struct breakpoint * | |
7737 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7738 | { | |
7739 | struct breakpoint *b; | |
7740 | ||
04086b45 PA |
7741 | /* Explicitly tell update_global_location_list to insert |
7742 | locations. */ | |
7743 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7744 | if (!b->loc->inserted) |
7745 | { | |
7746 | delete_breakpoint (b); | |
7747 | return NULL; | |
7748 | } | |
7749 | return b; | |
7750 | } | |
7751 | ||
cae688ec JJ |
7752 | /* Disable any breakpoints that are on code in shared libraries. Only |
7753 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7754 | ||
7755 | void | |
cb851954 | 7756 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7757 | { |
876fa593 | 7758 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7759 | |
876fa593 | 7760 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7761 | { |
2bdf28a0 | 7762 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7763 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7764 | |
4a64f543 MS |
7765 | /* We apply the check to all breakpoints, including disabled for |
7766 | those with loc->duplicate set. This is so that when breakpoint | |
7767 | becomes enabled, or the duplicate is removed, gdb will try to | |
7768 | insert all breakpoints. If we don't set shlib_disabled here, | |
7769 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7770 | if (((b->type == bp_breakpoint) |
508ccb1f | 7771 | || (b->type == bp_jit_event) |
1042e4c0 | 7772 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7773 | || (is_tracepoint (b))) |
6c95b8df | 7774 | && loc->pspace == current_program_space |
0d381245 | 7775 | && !loc->shlib_disabled |
6c95b8df | 7776 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7777 | ) |
0d381245 VP |
7778 | { |
7779 | loc->shlib_disabled = 1; | |
7780 | } | |
cae688ec JJ |
7781 | } |
7782 | } | |
7783 | ||
63644780 NB |
7784 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7785 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7786 | disabled ones can just stay disabled. */ | |
84acb35a | 7787 | |
75149521 | 7788 | static void |
84acb35a JJ |
7789 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7790 | { | |
876fa593 | 7791 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7792 | int disabled_shlib_breaks = 0; |
7793 | ||
876fa593 | 7794 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7795 | { |
2bdf28a0 | 7796 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7797 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7798 | |
1e4d1764 | 7799 | if (solib->pspace == loc->pspace |
e2dd7057 | 7800 | && !loc->shlib_disabled |
1e4d1764 YQ |
7801 | && (((b->type == bp_breakpoint |
7802 | || b->type == bp_jit_event | |
7803 | || b->type == bp_hardware_breakpoint) | |
7804 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7805 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7806 | || is_tracepoint (b)) | |
e2dd7057 | 7807 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7808 | { |
e2dd7057 PP |
7809 | loc->shlib_disabled = 1; |
7810 | /* At this point, we cannot rely on remove_breakpoint | |
7811 | succeeding so we must mark the breakpoint as not inserted | |
7812 | to prevent future errors occurring in remove_breakpoints. */ | |
7813 | loc->inserted = 0; | |
8d3788bd VP |
7814 | |
7815 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7816 | observer_notify_breakpoint_modified (b); | |
7817 | ||
e2dd7057 PP |
7818 | if (!disabled_shlib_breaks) |
7819 | { | |
223ffa71 | 7820 | target_terminal::ours_for_output (); |
3e43a32a MS |
7821 | warning (_("Temporarily disabling breakpoints " |
7822 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7823 | solib->so_name); |
84acb35a | 7824 | } |
e2dd7057 | 7825 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7826 | } |
7827 | } | |
84acb35a JJ |
7828 | } |
7829 | ||
63644780 NB |
7830 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7831 | notification of free_objfile. Only apply to enabled breakpoints, | |
7832 | disabled ones can just stay disabled. */ | |
7833 | ||
7834 | static void | |
7835 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7836 | { | |
7837 | struct breakpoint *b; | |
7838 | ||
7839 | if (objfile == NULL) | |
7840 | return; | |
7841 | ||
d03de421 PA |
7842 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7843 | managed by the user with add-symbol-file/remove-symbol-file. | |
7844 | Similarly to how breakpoints in shared libraries are handled in | |
7845 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7846 | shlib_disabled so they end up uninserted on the next global |
7847 | location list update. Shared libraries not loaded by the user | |
7848 | aren't handled here -- they're already handled in | |
7849 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7850 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7851 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7852 | main objfile). */ | |
7853 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7854 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7855 | return; |
7856 | ||
7857 | ALL_BREAKPOINTS (b) | |
7858 | { | |
7859 | struct bp_location *loc; | |
7860 | int bp_modified = 0; | |
7861 | ||
7862 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7863 | continue; | |
7864 | ||
7865 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7866 | { | |
7867 | CORE_ADDR loc_addr = loc->address; | |
7868 | ||
7869 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7870 | && loc->loc_type != bp_loc_software_breakpoint) | |
7871 | continue; | |
7872 | ||
7873 | if (loc->shlib_disabled != 0) | |
7874 | continue; | |
7875 | ||
7876 | if (objfile->pspace != loc->pspace) | |
7877 | continue; | |
7878 | ||
7879 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7880 | && loc->loc_type != bp_loc_software_breakpoint) | |
7881 | continue; | |
7882 | ||
7883 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7884 | { | |
7885 | loc->shlib_disabled = 1; | |
08351840 PA |
7886 | /* At this point, we don't know whether the object was |
7887 | unmapped from the inferior or not, so leave the | |
7888 | inserted flag alone. We'll handle failure to | |
7889 | uninsert quietly, in case the object was indeed | |
7890 | unmapped. */ | |
63644780 NB |
7891 | |
7892 | mark_breakpoint_location_modified (loc); | |
7893 | ||
7894 | bp_modified = 1; | |
7895 | } | |
7896 | } | |
7897 | ||
7898 | if (bp_modified) | |
7899 | observer_notify_breakpoint_modified (b); | |
7900 | } | |
7901 | } | |
7902 | ||
ce78b96d JB |
7903 | /* FORK & VFORK catchpoints. */ |
7904 | ||
e29a4733 | 7905 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
7906 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
7907 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 7908 | |
c1fc2657 | 7909 | struct fork_catchpoint : public breakpoint |
e29a4733 | 7910 | { |
e29a4733 PA |
7911 | /* Process id of a child process whose forking triggered this |
7912 | catchpoint. This field is only valid immediately after this | |
7913 | catchpoint has triggered. */ | |
7914 | ptid_t forked_inferior_pid; | |
7915 | }; | |
7916 | ||
4a64f543 MS |
7917 | /* Implement the "insert" breakpoint_ops method for fork |
7918 | catchpoints. */ | |
ce78b96d | 7919 | |
77b06cd7 TJB |
7920 | static int |
7921 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 7922 | { |
dfd4cc63 | 7923 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7924 | } |
7925 | ||
4a64f543 MS |
7926 | /* Implement the "remove" breakpoint_ops method for fork |
7927 | catchpoints. */ | |
ce78b96d JB |
7928 | |
7929 | static int | |
73971819 | 7930 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 7931 | { |
dfd4cc63 | 7932 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
7933 | } |
7934 | ||
7935 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
7936 | catchpoints. */ | |
7937 | ||
7938 | static int | |
f1310107 | 7939 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
7940 | struct address_space *aspace, CORE_ADDR bp_addr, |
7941 | const struct target_waitstatus *ws) | |
ce78b96d | 7942 | { |
e29a4733 PA |
7943 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
7944 | ||
f90263c1 TT |
7945 | if (ws->kind != TARGET_WAITKIND_FORKED) |
7946 | return 0; | |
7947 | ||
7948 | c->forked_inferior_pid = ws->value.related_pid; | |
7949 | return 1; | |
ce78b96d JB |
7950 | } |
7951 | ||
4a64f543 MS |
7952 | /* Implement the "print_it" breakpoint_ops method for fork |
7953 | catchpoints. */ | |
ce78b96d JB |
7954 | |
7955 | static enum print_stop_action | |
348d480f | 7956 | print_it_catch_fork (bpstat bs) |
ce78b96d | 7957 | { |
36dfb11c | 7958 | struct ui_out *uiout = current_uiout; |
348d480f PA |
7959 | struct breakpoint *b = bs->breakpoint_at; |
7960 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 7961 | |
ce78b96d | 7962 | annotate_catchpoint (b->number); |
f303dbd6 | 7963 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 7964 | if (b->disposition == disp_del) |
112e8700 | 7965 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 7966 | else |
112e8700 SM |
7967 | uiout->text ("Catchpoint "); |
7968 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 7969 | { |
112e8700 SM |
7970 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
7971 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 7972 | } |
112e8700 SM |
7973 | uiout->field_int ("bkptno", b->number); |
7974 | uiout->text (" (forked process "); | |
7975 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
7976 | uiout->text ("), "); | |
ce78b96d JB |
7977 | return PRINT_SRC_AND_LOC; |
7978 | } | |
7979 | ||
4a64f543 MS |
7980 | /* Implement the "print_one" breakpoint_ops method for fork |
7981 | catchpoints. */ | |
ce78b96d JB |
7982 | |
7983 | static void | |
a6d9a66e | 7984 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 7985 | { |
e29a4733 | 7986 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 7987 | struct value_print_options opts; |
79a45e25 | 7988 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
7989 | |
7990 | get_user_print_options (&opts); | |
7991 | ||
4a64f543 MS |
7992 | /* Field 4, the address, is omitted (which makes the columns not |
7993 | line up too nicely with the headers, but the effect is relatively | |
7994 | readable). */ | |
79a45b7d | 7995 | if (opts.addressprint) |
112e8700 | 7996 | uiout->field_skip ("addr"); |
ce78b96d | 7997 | annotate_field (5); |
112e8700 | 7998 | uiout->text ("fork"); |
e29a4733 | 7999 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8000 | { |
112e8700 SM |
8001 | uiout->text (", process "); |
8002 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8003 | uiout->spaces (1); | |
ce78b96d | 8004 | } |
8ac3646f | 8005 | |
112e8700 SM |
8006 | if (uiout->is_mi_like_p ()) |
8007 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
8008 | } |
8009 | ||
8010 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8011 | catchpoints. */ | |
8012 | ||
8013 | static void | |
8014 | print_mention_catch_fork (struct breakpoint *b) | |
8015 | { | |
8016 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8017 | } | |
8018 | ||
6149aea9 PA |
8019 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8020 | catchpoints. */ | |
8021 | ||
8022 | static void | |
8023 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8024 | { | |
8025 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8026 | print_recreate_thread (b, fp); |
6149aea9 PA |
8027 | } |
8028 | ||
ce78b96d JB |
8029 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8030 | ||
2060206e | 8031 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8032 | |
4a64f543 MS |
8033 | /* Implement the "insert" breakpoint_ops method for vfork |
8034 | catchpoints. */ | |
ce78b96d | 8035 | |
77b06cd7 TJB |
8036 | static int |
8037 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8038 | { |
dfd4cc63 | 8039 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8040 | } |
8041 | ||
4a64f543 MS |
8042 | /* Implement the "remove" breakpoint_ops method for vfork |
8043 | catchpoints. */ | |
ce78b96d JB |
8044 | |
8045 | static int | |
73971819 | 8046 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8047 | { |
dfd4cc63 | 8048 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8049 | } |
8050 | ||
8051 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8052 | catchpoints. */ | |
8053 | ||
8054 | static int | |
f1310107 | 8055 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8056 | struct address_space *aspace, CORE_ADDR bp_addr, |
8057 | const struct target_waitstatus *ws) | |
ce78b96d | 8058 | { |
e29a4733 PA |
8059 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8060 | ||
f90263c1 TT |
8061 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8062 | return 0; | |
8063 | ||
8064 | c->forked_inferior_pid = ws->value.related_pid; | |
8065 | return 1; | |
ce78b96d JB |
8066 | } |
8067 | ||
4a64f543 MS |
8068 | /* Implement the "print_it" breakpoint_ops method for vfork |
8069 | catchpoints. */ | |
ce78b96d JB |
8070 | |
8071 | static enum print_stop_action | |
348d480f | 8072 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8073 | { |
36dfb11c | 8074 | struct ui_out *uiout = current_uiout; |
348d480f | 8075 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8076 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8077 | ||
ce78b96d | 8078 | annotate_catchpoint (b->number); |
f303dbd6 | 8079 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8080 | if (b->disposition == disp_del) |
112e8700 | 8081 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8082 | else |
112e8700 SM |
8083 | uiout->text ("Catchpoint "); |
8084 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8085 | { |
112e8700 SM |
8086 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
8087 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8088 | } |
112e8700 SM |
8089 | uiout->field_int ("bkptno", b->number); |
8090 | uiout->text (" (vforked process "); | |
8091 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8092 | uiout->text ("), "); | |
ce78b96d JB |
8093 | return PRINT_SRC_AND_LOC; |
8094 | } | |
8095 | ||
4a64f543 MS |
8096 | /* Implement the "print_one" breakpoint_ops method for vfork |
8097 | catchpoints. */ | |
ce78b96d JB |
8098 | |
8099 | static void | |
a6d9a66e | 8100 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8101 | { |
e29a4733 | 8102 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8103 | struct value_print_options opts; |
79a45e25 | 8104 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8105 | |
8106 | get_user_print_options (&opts); | |
4a64f543 MS |
8107 | /* Field 4, the address, is omitted (which makes the columns not |
8108 | line up too nicely with the headers, but the effect is relatively | |
8109 | readable). */ | |
79a45b7d | 8110 | if (opts.addressprint) |
112e8700 | 8111 | uiout->field_skip ("addr"); |
ce78b96d | 8112 | annotate_field (5); |
112e8700 | 8113 | uiout->text ("vfork"); |
e29a4733 | 8114 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8115 | { |
112e8700 SM |
8116 | uiout->text (", process "); |
8117 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8118 | uiout->spaces (1); | |
ce78b96d | 8119 | } |
8ac3646f | 8120 | |
112e8700 SM |
8121 | if (uiout->is_mi_like_p ()) |
8122 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
8123 | } |
8124 | ||
8125 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8126 | catchpoints. */ | |
8127 | ||
8128 | static void | |
8129 | print_mention_catch_vfork (struct breakpoint *b) | |
8130 | { | |
8131 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8132 | } | |
8133 | ||
6149aea9 PA |
8134 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8135 | catchpoints. */ | |
8136 | ||
8137 | static void | |
8138 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8139 | { | |
8140 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8141 | print_recreate_thread (b, fp); |
6149aea9 PA |
8142 | } |
8143 | ||
ce78b96d JB |
8144 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8145 | ||
2060206e | 8146 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8147 | |
edcc5120 | 8148 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 8149 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
8150 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
8151 | ||
c1fc2657 | 8152 | struct solib_catchpoint : public breakpoint |
edcc5120 | 8153 | { |
c1fc2657 | 8154 | ~solib_catchpoint () override; |
edcc5120 TT |
8155 | |
8156 | /* True for "catch load", false for "catch unload". */ | |
8157 | unsigned char is_load; | |
8158 | ||
8159 | /* Regular expression to match, if any. COMPILED is only valid when | |
8160 | REGEX is non-NULL. */ | |
8161 | char *regex; | |
2d7cc5c7 | 8162 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
8163 | }; |
8164 | ||
c1fc2657 | 8165 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 8166 | { |
c1fc2657 | 8167 | xfree (this->regex); |
edcc5120 TT |
8168 | } |
8169 | ||
8170 | static int | |
8171 | insert_catch_solib (struct bp_location *ignore) | |
8172 | { | |
8173 | return 0; | |
8174 | } | |
8175 | ||
8176 | static int | |
73971819 | 8177 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8178 | { |
8179 | return 0; | |
8180 | } | |
8181 | ||
8182 | static int | |
8183 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8184 | struct address_space *aspace, | |
8185 | CORE_ADDR bp_addr, | |
8186 | const struct target_waitstatus *ws) | |
8187 | { | |
8188 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8189 | struct breakpoint *other; | |
8190 | ||
8191 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8192 | return 1; | |
8193 | ||
8194 | ALL_BREAKPOINTS (other) | |
8195 | { | |
8196 | struct bp_location *other_bl; | |
8197 | ||
8198 | if (other == bl->owner) | |
8199 | continue; | |
8200 | ||
8201 | if (other->type != bp_shlib_event) | |
8202 | continue; | |
8203 | ||
c1fc2657 | 8204 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
8205 | continue; |
8206 | ||
8207 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8208 | { | |
8209 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8210 | return 1; | |
8211 | } | |
8212 | } | |
8213 | ||
8214 | return 0; | |
8215 | } | |
8216 | ||
8217 | static void | |
8218 | check_status_catch_solib (struct bpstats *bs) | |
8219 | { | |
8220 | struct solib_catchpoint *self | |
8221 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8222 | int ix; | |
8223 | ||
8224 | if (self->is_load) | |
8225 | { | |
8226 | struct so_list *iter; | |
8227 | ||
8228 | for (ix = 0; | |
8229 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8230 | ix, iter); | |
8231 | ++ix) | |
8232 | { | |
8233 | if (!self->regex | |
2d7cc5c7 | 8234 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
8235 | return; |
8236 | } | |
8237 | } | |
8238 | else | |
8239 | { | |
8240 | char *iter; | |
8241 | ||
8242 | for (ix = 0; | |
8243 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8244 | ix, iter); | |
8245 | ++ix) | |
8246 | { | |
8247 | if (!self->regex | |
2d7cc5c7 | 8248 | || self->compiled->exec (iter, 0, NULL, 0) == 0) |
edcc5120 TT |
8249 | return; |
8250 | } | |
8251 | } | |
8252 | ||
8253 | bs->stop = 0; | |
8254 | bs->print_it = print_it_noop; | |
8255 | } | |
8256 | ||
8257 | static enum print_stop_action | |
8258 | print_it_catch_solib (bpstat bs) | |
8259 | { | |
8260 | struct breakpoint *b = bs->breakpoint_at; | |
8261 | struct ui_out *uiout = current_uiout; | |
8262 | ||
8263 | annotate_catchpoint (b->number); | |
f303dbd6 | 8264 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8265 | if (b->disposition == disp_del) |
112e8700 | 8266 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8267 | else |
112e8700 SM |
8268 | uiout->text ("Catchpoint "); |
8269 | uiout->field_int ("bkptno", b->number); | |
8270 | uiout->text ("\n"); | |
8271 | if (uiout->is_mi_like_p ()) | |
8272 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8273 | print_solib_event (1); |
8274 | return PRINT_SRC_AND_LOC; | |
8275 | } | |
8276 | ||
8277 | static void | |
8278 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8279 | { | |
8280 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8281 | struct value_print_options opts; | |
8282 | struct ui_out *uiout = current_uiout; | |
8283 | char *msg; | |
8284 | ||
8285 | get_user_print_options (&opts); | |
8286 | /* Field 4, the address, is omitted (which makes the columns not | |
8287 | line up too nicely with the headers, but the effect is relatively | |
8288 | readable). */ | |
8289 | if (opts.addressprint) | |
8290 | { | |
8291 | annotate_field (4); | |
112e8700 | 8292 | uiout->field_skip ("addr"); |
edcc5120 TT |
8293 | } |
8294 | ||
8295 | annotate_field (5); | |
8296 | if (self->is_load) | |
8297 | { | |
8298 | if (self->regex) | |
8299 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8300 | else | |
8301 | msg = xstrdup (_("load of library")); | |
8302 | } | |
8303 | else | |
8304 | { | |
8305 | if (self->regex) | |
8306 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8307 | else | |
8308 | msg = xstrdup (_("unload of library")); | |
8309 | } | |
112e8700 | 8310 | uiout->field_string ("what", msg); |
edcc5120 | 8311 | xfree (msg); |
8ac3646f | 8312 | |
112e8700 SM |
8313 | if (uiout->is_mi_like_p ()) |
8314 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8315 | } |
8316 | ||
8317 | static void | |
8318 | print_mention_catch_solib (struct breakpoint *b) | |
8319 | { | |
8320 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8321 | ||
8322 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8323 | self->is_load ? "load" : "unload"); | |
8324 | } | |
8325 | ||
8326 | static void | |
8327 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8328 | { | |
8329 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8330 | ||
8331 | fprintf_unfiltered (fp, "%s %s", | |
8332 | b->disposition == disp_del ? "tcatch" : "catch", | |
8333 | self->is_load ? "load" : "unload"); | |
8334 | if (self->regex) | |
8335 | fprintf_unfiltered (fp, " %s", self->regex); | |
8336 | fprintf_unfiltered (fp, "\n"); | |
8337 | } | |
8338 | ||
8339 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8340 | ||
91985142 MG |
8341 | /* Shared helper function (MI and CLI) for creating and installing |
8342 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8343 | the events to be caught are load events, otherwise they are | |
8344 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8345 | temporary one. If ENABLED is non-zero the catchpoint is | |
8346 | created in an enabled state. */ | |
edcc5120 | 8347 | |
91985142 | 8348 | void |
a121b7c1 | 8349 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8350 | { |
edcc5120 | 8351 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8352 | |
edcc5120 TT |
8353 | if (!arg) |
8354 | arg = ""; | |
f1735a53 | 8355 | arg = skip_spaces (arg); |
edcc5120 | 8356 | |
36bd8eaa | 8357 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8358 | |
8359 | if (*arg != '\0') | |
8360 | { | |
2d7cc5c7 PA |
8361 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8362 | _("Invalid regexp"))); | |
edcc5120 TT |
8363 | c->regex = xstrdup (arg); |
8364 | } | |
8365 | ||
8366 | c->is_load = is_load; | |
36bd8eaa | 8367 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8368 | &catch_solib_breakpoint_ops); |
8369 | ||
c1fc2657 | 8370 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8371 | |
b270e6f9 | 8372 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8373 | } |
8374 | ||
91985142 MG |
8375 | /* A helper function that does all the work for "catch load" and |
8376 | "catch unload". */ | |
8377 | ||
8378 | static void | |
8379 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8380 | struct cmd_list_element *command) | |
8381 | { | |
8382 | int tempflag; | |
8383 | const int enabled = 1; | |
8384 | ||
8385 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8386 | ||
8387 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8388 | } | |
8389 | ||
edcc5120 TT |
8390 | static void |
8391 | catch_load_command_1 (char *arg, int from_tty, | |
8392 | struct cmd_list_element *command) | |
8393 | { | |
8394 | catch_load_or_unload (arg, from_tty, 1, command); | |
8395 | } | |
8396 | ||
8397 | static void | |
8398 | catch_unload_command_1 (char *arg, int from_tty, | |
8399 | struct cmd_list_element *command) | |
8400 | { | |
8401 | catch_load_or_unload (arg, from_tty, 0, command); | |
8402 | } | |
8403 | ||
346774a9 PA |
8404 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8405 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8406 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8407 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8408 | |
ab04a2af | 8409 | void |
346774a9 PA |
8410 | init_catchpoint (struct breakpoint *b, |
8411 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8412 | const char *cond_string, |
c0a91b2b | 8413 | const struct breakpoint_ops *ops) |
c906108c | 8414 | { |
51abb421 | 8415 | symtab_and_line sal; |
6c95b8df | 8416 | sal.pspace = current_program_space; |
c5aa993b | 8417 | |
28010a5d | 8418 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8419 | |
1b36a34b | 8420 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8421 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8422 | } |
8423 | ||
28010a5d | 8424 | void |
b270e6f9 | 8425 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8426 | { |
b270e6f9 | 8427 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8428 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8429 | if (is_tracepoint (b)) |
8430 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8431 | if (!internal) |
8432 | mention (b); | |
c56053d2 | 8433 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8434 | |
8435 | if (update_gll) | |
44702360 | 8436 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8437 | } |
8438 | ||
9b70b993 | 8439 | static void |
a6d9a66e | 8440 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8441 | int tempflag, const char *cond_string, |
c0a91b2b | 8442 | const struct breakpoint_ops *ops) |
c906108c | 8443 | { |
b270e6f9 | 8444 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8445 | |
b270e6f9 | 8446 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8447 | |
8448 | c->forked_inferior_pid = null_ptid; | |
8449 | ||
b270e6f9 | 8450 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8451 | } |
8452 | ||
fe798b75 JB |
8453 | /* Exec catchpoints. */ |
8454 | ||
b4d90040 | 8455 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8456 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8457 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8458 | ||
c1fc2657 | 8459 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8460 | { |
c1fc2657 | 8461 | ~exec_catchpoint () override; |
b4d90040 PA |
8462 | |
8463 | /* Filename of a program whose exec triggered this catchpoint. | |
8464 | This field is only valid immediately after this catchpoint has | |
8465 | triggered. */ | |
8466 | char *exec_pathname; | |
8467 | }; | |
8468 | ||
c1fc2657 | 8469 | /* Exec catchpoint destructor. */ |
b4d90040 | 8470 | |
c1fc2657 | 8471 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8472 | { |
c1fc2657 | 8473 | xfree (this->exec_pathname); |
b4d90040 PA |
8474 | } |
8475 | ||
77b06cd7 TJB |
8476 | static int |
8477 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8478 | { |
dfd4cc63 | 8479 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8480 | } |
c906108c | 8481 | |
fe798b75 | 8482 | static int |
73971819 | 8483 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8484 | { |
dfd4cc63 | 8485 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8486 | } |
c906108c | 8487 | |
fe798b75 | 8488 | static int |
f1310107 | 8489 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8490 | struct address_space *aspace, CORE_ADDR bp_addr, |
8491 | const struct target_waitstatus *ws) | |
fe798b75 | 8492 | { |
b4d90040 PA |
8493 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8494 | ||
f90263c1 TT |
8495 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8496 | return 0; | |
8497 | ||
8498 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8499 | return 1; | |
fe798b75 | 8500 | } |
c906108c | 8501 | |
fe798b75 | 8502 | static enum print_stop_action |
348d480f | 8503 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8504 | { |
36dfb11c | 8505 | struct ui_out *uiout = current_uiout; |
348d480f | 8506 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8507 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8508 | ||
fe798b75 | 8509 | annotate_catchpoint (b->number); |
f303dbd6 | 8510 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8511 | if (b->disposition == disp_del) |
112e8700 | 8512 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8513 | else |
112e8700 SM |
8514 | uiout->text ("Catchpoint "); |
8515 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8516 | { |
112e8700 SM |
8517 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8518 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8519 | } |
112e8700 SM |
8520 | uiout->field_int ("bkptno", b->number); |
8521 | uiout->text (" (exec'd "); | |
8522 | uiout->field_string ("new-exec", c->exec_pathname); | |
8523 | uiout->text ("), "); | |
36dfb11c | 8524 | |
fe798b75 | 8525 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8526 | } |
8527 | ||
fe798b75 | 8528 | static void |
a6d9a66e | 8529 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8530 | { |
b4d90040 | 8531 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8532 | struct value_print_options opts; |
79a45e25 | 8533 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8534 | |
8535 | get_user_print_options (&opts); | |
8536 | ||
8537 | /* Field 4, the address, is omitted (which makes the columns | |
8538 | not line up too nicely with the headers, but the effect | |
8539 | is relatively readable). */ | |
8540 | if (opts.addressprint) | |
112e8700 | 8541 | uiout->field_skip ("addr"); |
fe798b75 | 8542 | annotate_field (5); |
112e8700 | 8543 | uiout->text ("exec"); |
b4d90040 | 8544 | if (c->exec_pathname != NULL) |
fe798b75 | 8545 | { |
112e8700 SM |
8546 | uiout->text (", program \""); |
8547 | uiout->field_string ("what", c->exec_pathname); | |
8548 | uiout->text ("\" "); | |
fe798b75 | 8549 | } |
8ac3646f | 8550 | |
112e8700 SM |
8551 | if (uiout->is_mi_like_p ()) |
8552 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8553 | } |
8554 | ||
8555 | static void | |
8556 | print_mention_catch_exec (struct breakpoint *b) | |
8557 | { | |
8558 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8559 | } | |
8560 | ||
6149aea9 PA |
8561 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8562 | catchpoints. */ | |
8563 | ||
8564 | static void | |
8565 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8566 | { | |
8567 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8568 | print_recreate_thread (b, fp); |
6149aea9 PA |
8569 | } |
8570 | ||
2060206e | 8571 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8572 | |
c906108c | 8573 | static int |
fba45db2 | 8574 | hw_breakpoint_used_count (void) |
c906108c | 8575 | { |
c906108c | 8576 | int i = 0; |
f1310107 TJB |
8577 | struct breakpoint *b; |
8578 | struct bp_location *bl; | |
c906108c SS |
8579 | |
8580 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8581 | { |
d6b74ac4 | 8582 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8583 | for (bl = b->loc; bl; bl = bl->next) |
8584 | { | |
8585 | /* Special types of hardware breakpoints may use more than | |
8586 | one register. */ | |
348d480f | 8587 | i += b->ops->resources_needed (bl); |
f1310107 | 8588 | } |
c5aa993b | 8589 | } |
c906108c SS |
8590 | |
8591 | return i; | |
8592 | } | |
8593 | ||
a1398e0c PA |
8594 | /* Returns the resources B would use if it were a hardware |
8595 | watchpoint. */ | |
8596 | ||
c906108c | 8597 | static int |
a1398e0c | 8598 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8599 | { |
c906108c | 8600 | int i = 0; |
e09342b5 | 8601 | struct bp_location *bl; |
c906108c | 8602 | |
a1398e0c PA |
8603 | if (!breakpoint_enabled (b)) |
8604 | return 0; | |
8605 | ||
8606 | for (bl = b->loc; bl; bl = bl->next) | |
8607 | { | |
8608 | /* Special types of hardware watchpoints may use more than | |
8609 | one register. */ | |
8610 | i += b->ops->resources_needed (bl); | |
8611 | } | |
8612 | ||
8613 | return i; | |
8614 | } | |
8615 | ||
8616 | /* Returns the sum the used resources of all hardware watchpoints of | |
8617 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8618 | the sum of the used resources of all hardware watchpoints of other | |
8619 | types _not_ TYPE. */ | |
8620 | ||
8621 | static int | |
8622 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8623 | enum bptype type, int *other_type_used) | |
8624 | { | |
8625 | int i = 0; | |
8626 | struct breakpoint *b; | |
8627 | ||
c906108c SS |
8628 | *other_type_used = 0; |
8629 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8630 | { |
a1398e0c PA |
8631 | if (b == except) |
8632 | continue; | |
e09342b5 TJB |
8633 | if (!breakpoint_enabled (b)) |
8634 | continue; | |
8635 | ||
a1398e0c PA |
8636 | if (b->type == type) |
8637 | i += hw_watchpoint_use_count (b); | |
8638 | else if (is_hardware_watchpoint (b)) | |
8639 | *other_type_used = 1; | |
e09342b5 TJB |
8640 | } |
8641 | ||
c906108c SS |
8642 | return i; |
8643 | } | |
8644 | ||
c906108c | 8645 | void |
fba45db2 | 8646 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8647 | { |
c5aa993b | 8648 | struct breakpoint *b; |
c906108c SS |
8649 | |
8650 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8651 | { |
cc60f2e3 | 8652 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8653 | { |
b5de0fa7 | 8654 | b->enable_state = bp_call_disabled; |
44702360 | 8655 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8656 | } |
8657 | } | |
c906108c SS |
8658 | } |
8659 | ||
8660 | void | |
fba45db2 | 8661 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8662 | { |
c5aa993b | 8663 | struct breakpoint *b; |
c906108c SS |
8664 | |
8665 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8666 | { |
cc60f2e3 | 8667 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8668 | { |
b5de0fa7 | 8669 | b->enable_state = bp_enabled; |
44702360 | 8670 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8671 | } |
8672 | } | |
c906108c SS |
8673 | } |
8674 | ||
8bea4e01 UW |
8675 | void |
8676 | disable_breakpoints_before_startup (void) | |
8677 | { | |
6c95b8df | 8678 | current_program_space->executing_startup = 1; |
44702360 | 8679 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8680 | } |
8681 | ||
8682 | void | |
8683 | enable_breakpoints_after_startup (void) | |
8684 | { | |
6c95b8df | 8685 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8686 | breakpoint_re_set (); |
8bea4e01 UW |
8687 | } |
8688 | ||
7c16b83e PA |
8689 | /* Create a new single-step breakpoint for thread THREAD, with no |
8690 | locations. */ | |
c906108c | 8691 | |
7c16b83e PA |
8692 | static struct breakpoint * |
8693 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8694 | { | |
b270e6f9 | 8695 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8696 | |
b270e6f9 | 8697 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8698 | &momentary_breakpoint_ops); |
8699 | ||
8700 | b->disposition = disp_donttouch; | |
8701 | b->frame_id = null_frame_id; | |
8702 | ||
8703 | b->thread = thread; | |
8704 | gdb_assert (b->thread != 0); | |
8705 | ||
b270e6f9 | 8706 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8707 | } |
8708 | ||
8709 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8710 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8711 | frame. */ | |
c906108c SS |
8712 | |
8713 | struct breakpoint * | |
a6d9a66e UW |
8714 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8715 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8716 | { |
52f0bd74 | 8717 | struct breakpoint *b; |
edb3359d | 8718 | |
193facb3 JK |
8719 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8720 | tail-called one. */ | |
8721 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8722 | |
06edf0c0 | 8723 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8724 | b->enable_state = bp_enabled; |
8725 | b->disposition = disp_donttouch; | |
818dd999 | 8726 | b->frame_id = frame_id; |
c906108c | 8727 | |
4a64f543 MS |
8728 | /* If we're debugging a multi-threaded program, then we want |
8729 | momentary breakpoints to be active in only a single thread of | |
8730 | control. */ | |
39f77062 | 8731 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8732 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8733 | |
44702360 | 8734 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8735 | |
c906108c SS |
8736 | return b; |
8737 | } | |
611c83ae | 8738 | |
06edf0c0 | 8739 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8740 | The new breakpoint will have type TYPE, use OPS as its |
8741 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8742 | |
06edf0c0 PA |
8743 | static struct breakpoint * |
8744 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8745 | enum bptype type, | |
a1aa2221 LM |
8746 | const struct breakpoint_ops *ops, |
8747 | int loc_enabled) | |
e58b0e63 PA |
8748 | { |
8749 | struct breakpoint *copy; | |
8750 | ||
06edf0c0 | 8751 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8752 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8753 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8754 | |
a6d9a66e | 8755 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8756 | copy->loc->requested_address = orig->loc->requested_address; |
8757 | copy->loc->address = orig->loc->address; | |
8758 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8759 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8760 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8761 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8762 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8763 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8764 | copy->frame_id = orig->frame_id; |
8765 | copy->thread = orig->thread; | |
6c95b8df | 8766 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8767 | |
8768 | copy->enable_state = bp_enabled; | |
8769 | copy->disposition = disp_donttouch; | |
8770 | copy->number = internal_breakpoint_number--; | |
8771 | ||
44702360 | 8772 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8773 | return copy; |
8774 | } | |
8775 | ||
06edf0c0 PA |
8776 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8777 | ORIG is NULL. */ | |
8778 | ||
8779 | struct breakpoint * | |
8780 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8781 | { | |
8782 | /* If there's nothing to clone, then return nothing. */ | |
8783 | if (orig == NULL) | |
8784 | return NULL; | |
8785 | ||
a1aa2221 | 8786 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8787 | } |
8788 | ||
611c83ae | 8789 | struct breakpoint * |
a6d9a66e UW |
8790 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8791 | enum bptype type) | |
611c83ae PA |
8792 | { |
8793 | struct symtab_and_line sal; | |
8794 | ||
8795 | sal = find_pc_line (pc, 0); | |
8796 | sal.pc = pc; | |
8797 | sal.section = find_pc_overlay (pc); | |
8798 | sal.explicit_pc = 1; | |
8799 | ||
a6d9a66e | 8800 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8801 | } |
c906108c | 8802 | \f |
c5aa993b | 8803 | |
c906108c SS |
8804 | /* Tell the user we have just set a breakpoint B. */ |
8805 | ||
8806 | static void | |
fba45db2 | 8807 | mention (struct breakpoint *b) |
c906108c | 8808 | { |
348d480f | 8809 | b->ops->print_mention (b); |
112e8700 | 8810 | if (current_uiout->is_mi_like_p ()) |
fb40c209 | 8811 | return; |
c906108c SS |
8812 | printf_filtered ("\n"); |
8813 | } | |
c906108c | 8814 | \f |
c5aa993b | 8815 | |
1a853c52 PA |
8816 | static int bp_loc_is_permanent (struct bp_location *loc); |
8817 | ||
0d381245 | 8818 | static struct bp_location * |
39d61571 | 8819 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8820 | const struct symtab_and_line *sal) |
8821 | { | |
8822 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8823 | CORE_ADDR adjusted_address; |
8824 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8825 | ||
8826 | if (loc_gdbarch == NULL) | |
8827 | loc_gdbarch = b->gdbarch; | |
8828 | ||
8829 | /* Adjust the breakpoint's address prior to allocating a location. | |
8830 | Once we call allocate_bp_location(), that mostly uninitialized | |
8831 | location will be placed on the location chain. Adjustment of the | |
8832 | breakpoint may cause target_read_memory() to be called and we do | |
8833 | not want its scan of the location chain to find a breakpoint and | |
8834 | location that's only been partially initialized. */ | |
8835 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8836 | sal->pc, b->type); | |
0d381245 | 8837 | |
d30113d4 | 8838 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8839 | loc = allocate_bp_location (b); |
d30113d4 JK |
8840 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8841 | tmp = &((*tmp)->next)) | |
0d381245 | 8842 | ; |
d30113d4 | 8843 | loc->next = *tmp; |
0d381245 | 8844 | *tmp = loc; |
3742cc8b | 8845 | |
0d381245 | 8846 | loc->requested_address = sal->pc; |
3742cc8b | 8847 | loc->address = adjusted_address; |
6c95b8df | 8848 | loc->pspace = sal->pspace; |
729662a5 TT |
8849 | loc->probe.probe = sal->probe; |
8850 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 8851 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8852 | loc->section = sal->section; |
3742cc8b | 8853 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8854 | loc->line_number = sal->line; |
2f202fde | 8855 | loc->symtab = sal->symtab; |
f8eba3c6 | 8856 | |
0e30163f JK |
8857 | set_breakpoint_location_function (loc, |
8858 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 8859 | |
6ae88661 LM |
8860 | /* While by definition, permanent breakpoints are already present in the |
8861 | code, we don't mark the location as inserted. Normally one would expect | |
8862 | that GDB could rely on that breakpoint instruction to stop the program, | |
8863 | thus removing the need to insert its own breakpoint, except that executing | |
8864 | the breakpoint instruction can kill the target instead of reporting a | |
8865 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8866 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8867 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8868 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8869 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8870 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8871 | it manually increments the PC, thus avoiding executing the breakpoint | |
8872 | instruction.) */ | |
1a853c52 | 8873 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8874 | loc->permanent = 1; |
1a853c52 | 8875 | |
0d381245 VP |
8876 | return loc; |
8877 | } | |
514f746b AR |
8878 | \f |
8879 | ||
1cf4d951 | 8880 | /* See breakpoint.h. */ |
514f746b | 8881 | |
1cf4d951 PA |
8882 | int |
8883 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8884 | { |
8885 | int len; | |
8886 | CORE_ADDR addr; | |
1afeeb75 | 8887 | const gdb_byte *bpoint; |
514f746b AR |
8888 | gdb_byte *target_mem; |
8889 | ||
1cf4d951 PA |
8890 | addr = address; |
8891 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
8892 | ||
8893 | /* Software breakpoints unsupported? */ | |
8894 | if (bpoint == NULL) | |
8895 | return 0; | |
8896 | ||
224c3ddb | 8897 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
8898 | |
8899 | /* Enable the automatic memory restoration from breakpoints while | |
8900 | we read the memory. Otherwise we could say about our temporary | |
8901 | breakpoints they are permanent. */ | |
cb85b21b TT |
8902 | scoped_restore restore_memory |
8903 | = make_scoped_restore_show_memory_breakpoints (0); | |
1cf4d951 PA |
8904 | |
8905 | if (target_read_memory (address, target_mem, len) == 0 | |
8906 | && memcmp (target_mem, bpoint, len) == 0) | |
cb85b21b | 8907 | return 1; |
1cf4d951 | 8908 | |
cb85b21b | 8909 | return 0; |
1cf4d951 PA |
8910 | } |
8911 | ||
8912 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
8913 | return 0 otherwise. */ | |
8914 | ||
8915 | static int | |
8916 | bp_loc_is_permanent (struct bp_location *loc) | |
8917 | { | |
514f746b AR |
8918 | gdb_assert (loc != NULL); |
8919 | ||
244558af LM |
8920 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
8921 | attempt to read from the addresses the locations of these breakpoint types | |
8922 | point to. program_breakpoint_here_p, below, will attempt to read | |
8923 | memory. */ | |
8924 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
8925 | return 0; | |
8926 | ||
5ed8105e | 8927 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 8928 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 8929 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
8930 | } |
8931 | ||
e7e0cddf SS |
8932 | /* Build a command list for the dprintf corresponding to the current |
8933 | settings of the dprintf style options. */ | |
8934 | ||
8935 | static void | |
8936 | update_dprintf_command_list (struct breakpoint *b) | |
8937 | { | |
8938 | char *dprintf_args = b->extra_string; | |
8939 | char *printf_line = NULL; | |
8940 | ||
8941 | if (!dprintf_args) | |
8942 | return; | |
8943 | ||
8944 | dprintf_args = skip_spaces (dprintf_args); | |
8945 | ||
8946 | /* Allow a comma, as it may have terminated a location, but don't | |
8947 | insist on it. */ | |
8948 | if (*dprintf_args == ',') | |
8949 | ++dprintf_args; | |
8950 | dprintf_args = skip_spaces (dprintf_args); | |
8951 | ||
8952 | if (*dprintf_args != '"') | |
8953 | error (_("Bad format string, missing '\"'.")); | |
8954 | ||
d3ce09f5 | 8955 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 8956 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 8957 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
8958 | { |
8959 | if (!dprintf_function) | |
8960 | error (_("No function supplied for dprintf call")); | |
8961 | ||
8962 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
8963 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
8964 | dprintf_function, | |
8965 | dprintf_channel, | |
8966 | dprintf_args); | |
8967 | else | |
8968 | printf_line = xstrprintf ("call (void) %s (%s)", | |
8969 | dprintf_function, | |
8970 | dprintf_args); | |
8971 | } | |
d3ce09f5 SS |
8972 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
8973 | { | |
8974 | if (target_can_run_breakpoint_commands ()) | |
8975 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
8976 | else | |
8977 | { | |
8978 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
8979 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
8980 | } | |
8981 | } | |
e7e0cddf SS |
8982 | else |
8983 | internal_error (__FILE__, __LINE__, | |
8984 | _("Invalid dprintf style.")); | |
8985 | ||
f28045c2 | 8986 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 8987 | /* Manufacture a printf sequence. */ |
f28045c2 | 8988 | { |
8d749320 | 8989 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 8990 | |
f28045c2 YQ |
8991 | printf_cmd_line->control_type = simple_control; |
8992 | printf_cmd_line->body_count = 0; | |
8993 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 8994 | printf_cmd_line->next = NULL; |
f28045c2 | 8995 | printf_cmd_line->line = printf_line; |
e7e0cddf | 8996 | |
93921405 | 8997 | breakpoint_set_commands (b, command_line_up (printf_cmd_line)); |
f28045c2 | 8998 | } |
e7e0cddf SS |
8999 | } |
9000 | ||
9001 | /* Update all dprintf commands, making their command lists reflect | |
9002 | current style settings. */ | |
9003 | ||
9004 | static void | |
9005 | update_dprintf_commands (char *args, int from_tty, | |
9006 | struct cmd_list_element *c) | |
9007 | { | |
9008 | struct breakpoint *b; | |
9009 | ||
9010 | ALL_BREAKPOINTS (b) | |
9011 | { | |
9012 | if (b->type == bp_dprintf) | |
9013 | update_dprintf_command_list (b); | |
9014 | } | |
9015 | } | |
c3f6f71d | 9016 | |
f00aae0f KS |
9017 | /* Create a breakpoint with SAL as location. Use LOCATION |
9018 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9019 | as condition expression. If LOCATION is NULL then create an |
9020 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9021 | |
9022 | static void | |
d9b3f62e | 9023 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 9024 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9025 | event_location_up &&location, |
e1e01040 PA |
9026 | gdb::unique_xmalloc_ptr<char> filter, |
9027 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9028 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9029 | enum bptype type, enum bpdisp disposition, |
9030 | int thread, int task, int ignore_count, | |
c0a91b2b | 9031 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9032 | int enabled, int internal, unsigned flags, |
9033 | int display_canonical) | |
018d34a4 | 9034 | { |
0d381245 | 9035 | int i; |
018d34a4 VP |
9036 | |
9037 | if (type == bp_hardware_breakpoint) | |
9038 | { | |
fbbd034e AS |
9039 | int target_resources_ok; |
9040 | ||
9041 | i = hw_breakpoint_used_count (); | |
9042 | target_resources_ok = | |
9043 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9044 | i + 1, 0); |
9045 | if (target_resources_ok == 0) | |
9046 | error (_("No hardware breakpoint support in the target.")); | |
9047 | else if (target_resources_ok < 0) | |
9048 | error (_("Hardware breakpoints used exceeds limit.")); | |
9049 | } | |
9050 | ||
6c5b2ebe | 9051 | gdb_assert (!sals.empty ()); |
6c95b8df | 9052 | |
6c5b2ebe | 9053 | for (const auto &sal : sals) |
0d381245 | 9054 | { |
0d381245 VP |
9055 | struct bp_location *loc; |
9056 | ||
9057 | if (from_tty) | |
5af949e3 UW |
9058 | { |
9059 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9060 | if (!loc_gdbarch) | |
9061 | loc_gdbarch = gdbarch; | |
9062 | ||
9063 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9064 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9065 | } |
0d381245 | 9066 | |
6c5b2ebe | 9067 | if (&sal == &sals[0]) |
0d381245 | 9068 | { |
d9b3f62e | 9069 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9070 | b->thread = thread; |
4a306c9a | 9071 | b->task = task; |
855a6e68 | 9072 | |
e1e01040 PA |
9073 | b->cond_string = cond_string.release (); |
9074 | b->extra_string = extra_string.release (); | |
0d381245 | 9075 | b->ignore_count = ignore_count; |
41447f92 | 9076 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9077 | b->disposition = disposition; |
6c95b8df | 9078 | |
44f238bb PA |
9079 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9080 | b->loc->inserted = 1; | |
9081 | ||
0fb4aa4b PA |
9082 | if (type == bp_static_tracepoint) |
9083 | { | |
d9b3f62e | 9084 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9085 | struct static_tracepoint_marker marker; |
9086 | ||
983af33b | 9087 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9088 | { |
9089 | /* We already know the marker exists, otherwise, we | |
9090 | wouldn't see a sal for it. */ | |
d28cd78a TT |
9091 | const char *p |
9092 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 9093 | const char *endp; |
0fb4aa4b | 9094 | char *marker_str; |
0fb4aa4b | 9095 | |
f1735a53 | 9096 | p = skip_spaces (p); |
0fb4aa4b | 9097 | |
f1735a53 | 9098 | endp = skip_to_space (p); |
0fb4aa4b PA |
9099 | |
9100 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9101 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9102 | |
3e43a32a MS |
9103 | printf_filtered (_("Probed static tracepoint " |
9104 | "marker \"%s\"\n"), | |
d9b3f62e | 9105 | t->static_trace_marker_id); |
0fb4aa4b PA |
9106 | } |
9107 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9108 | { | |
d9b3f62e | 9109 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9110 | release_static_tracepoint_marker (&marker); |
9111 | ||
3e43a32a MS |
9112 | printf_filtered (_("Probed static tracepoint " |
9113 | "marker \"%s\"\n"), | |
d9b3f62e | 9114 | t->static_trace_marker_id); |
0fb4aa4b PA |
9115 | } |
9116 | else | |
3e43a32a MS |
9117 | warning (_("Couldn't determine the static " |
9118 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9119 | } |
9120 | ||
0d381245 VP |
9121 | loc = b->loc; |
9122 | } | |
9123 | else | |
018d34a4 | 9124 | { |
39d61571 | 9125 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9126 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9127 | loc->inserted = 1; | |
0d381245 VP |
9128 | } |
9129 | ||
9130 | if (b->cond_string) | |
9131 | { | |
bbc13ae3 KS |
9132 | const char *arg = b->cond_string; |
9133 | ||
1bb9788d TT |
9134 | loc->cond = parse_exp_1 (&arg, loc->address, |
9135 | block_for_pc (loc->address), 0); | |
0d381245 | 9136 | if (*arg) |
588ae58c | 9137 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9138 | } |
e7e0cddf SS |
9139 | |
9140 | /* Dynamic printf requires and uses additional arguments on the | |
9141 | command line, otherwise it's an error. */ | |
9142 | if (type == bp_dprintf) | |
9143 | { | |
9144 | if (b->extra_string) | |
9145 | update_dprintf_command_list (b); | |
9146 | else | |
9147 | error (_("Format string required")); | |
9148 | } | |
9149 | else if (b->extra_string) | |
588ae58c | 9150 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9151 | } |
018d34a4 | 9152 | |
56435ebe | 9153 | b->display_canonical = display_canonical; |
f00aae0f | 9154 | if (location != NULL) |
d28cd78a | 9155 | b->location = std::move (location); |
018d34a4 | 9156 | else |
d28cd78a | 9157 | b->location = new_address_location (b->loc->address, NULL, 0); |
e1e01040 | 9158 | b->filter = filter.release (); |
d9b3f62e | 9159 | } |
018d34a4 | 9160 | |
d9b3f62e PA |
9161 | static void |
9162 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 9163 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9164 | event_location_up &&location, |
e1e01040 PA |
9165 | gdb::unique_xmalloc_ptr<char> filter, |
9166 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9167 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9168 | enum bptype type, enum bpdisp disposition, |
9169 | int thread, int task, int ignore_count, | |
c0a91b2b | 9170 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9171 | int enabled, int internal, unsigned flags, |
9172 | int display_canonical) | |
d9b3f62e | 9173 | { |
a5e364af | 9174 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 9175 | |
a5e364af | 9176 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 9177 | sals, std::move (location), |
e1e01040 PA |
9178 | std::move (filter), |
9179 | std::move (cond_string), | |
9180 | std::move (extra_string), | |
d9b3f62e PA |
9181 | type, disposition, |
9182 | thread, task, ignore_count, | |
9183 | ops, from_tty, | |
44f238bb PA |
9184 | enabled, internal, flags, |
9185 | display_canonical); | |
d9b3f62e | 9186 | |
b270e6f9 | 9187 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
9188 | } |
9189 | ||
9190 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9191 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9192 | value. COND_STRING, if not NULL, specified the condition to be | |
9193 | used for all breakpoints. Essentially the only case where | |
9194 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9195 | function. In that case, it's still not possible to specify | |
9196 | separate conditions for different overloaded functions, so | |
9197 | we take just a single condition string. | |
9198 | ||
c3f6f71d | 9199 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9200 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9201 | array contents). If the function fails (error() is called), the |
9202 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9203 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9204 | |
9205 | static void | |
8cdf0e15 | 9206 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9207 | struct linespec_result *canonical, |
e1e01040 PA |
9208 | gdb::unique_xmalloc_ptr<char> cond_string, |
9209 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
9210 | enum bptype type, enum bpdisp disposition, |
9211 | int thread, int task, int ignore_count, | |
c0a91b2b | 9212 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9213 | int enabled, int internal, unsigned flags) |
c906108c | 9214 | { |
f8eba3c6 | 9215 | if (canonical->pre_expanded) |
6c5b2ebe | 9216 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 9217 | |
6c5b2ebe | 9218 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 9219 | { |
f00aae0f | 9220 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9221 | 'break', without arguments. */ |
ffc2605c | 9222 | event_location_up location |
f00aae0f | 9223 | = (canonical->location != NULL |
8e9e35b1 | 9224 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 9225 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 9226 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 9227 | |
6c5b2ebe | 9228 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 9229 | std::move (location), |
e1e01040 PA |
9230 | std::move (filter_string), |
9231 | std::move (cond_string), | |
9232 | std::move (extra_string), | |
e7e0cddf | 9233 | type, disposition, |
84f4c1fe | 9234 | thread, task, ignore_count, ops, |
44f238bb | 9235 | from_tty, enabled, internal, flags, |
56435ebe | 9236 | canonical->special_display); |
c3f6f71d | 9237 | } |
c3f6f71d | 9238 | } |
c906108c | 9239 | |
f00aae0f | 9240 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9241 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9242 | addresses found. LOCATION points to the end of the SAL (for |
9243 | linespec locations). | |
9998af43 TJB |
9244 | |
9245 | The array and the line spec strings are allocated on the heap, it is | |
9246 | the caller's responsibility to free them. */ | |
c906108c | 9247 | |
b9362cc7 | 9248 | static void |
f00aae0f | 9249 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9250 | struct linespec_result *canonical) |
c3f6f71d | 9251 | { |
f00aae0f KS |
9252 | struct symtab_and_line cursal; |
9253 | ||
9254 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9255 | { | |
9256 | const char *address = get_linespec_location (location); | |
9257 | ||
9258 | if (address == NULL) | |
9259 | { | |
9260 | /* The last displayed codepoint, if it's valid, is our default | |
9261 | breakpoint address. */ | |
9262 | if (last_displayed_sal_is_valid ()) | |
9263 | { | |
f00aae0f KS |
9264 | /* Set sal's pspace, pc, symtab, and line to the values |
9265 | corresponding to the last call to print_frame_info. | |
9266 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9267 | as the breakpoint line number is inappropriate otherwise. | |
9268 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
9269 | symtab_and_line sal = get_last_displayed_sal (); |
9270 | CORE_ADDR pc = sal.pc; | |
9271 | ||
f00aae0f KS |
9272 | sal = find_pc_line (pc, 0); |
9273 | ||
9274 | /* "break" without arguments is equivalent to "break *PC" | |
9275 | where PC is the last displayed codepoint's address. So | |
9276 | make sure to set sal.explicit_pc to prevent GDB from | |
9277 | trying to expand the list of sals to include all other | |
9278 | instances with the same symtab and line. */ | |
9279 | sal.pc = pc; | |
9280 | sal.explicit_pc = 1; | |
9281 | ||
6c5b2ebe PA |
9282 | struct linespec_sals lsal; |
9283 | lsal.sals = {sal}; | |
f00aae0f KS |
9284 | lsal.canonical = NULL; |
9285 | ||
6c5b2ebe | 9286 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
9287 | return; |
9288 | } | |
9289 | else | |
9290 | error (_("No default breakpoint address now.")); | |
c906108c | 9291 | } |
c906108c | 9292 | } |
f00aae0f KS |
9293 | |
9294 | /* Force almost all breakpoints to be in terms of the | |
9295 | current_source_symtab (which is decode_line_1's default). | |
9296 | This should produce the results we want almost all of the | |
9297 | time while leaving default_breakpoint_* alone. | |
9298 | ||
9299 | ObjC: However, don't match an Objective-C method name which | |
9300 | may have a '+' or '-' succeeded by a '['. */ | |
9301 | cursal = get_current_source_symtab_and_line (); | |
9302 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9303 | { |
f00aae0f | 9304 | const char *address = NULL; |
cc80f267 | 9305 | |
f00aae0f KS |
9306 | if (event_location_type (location) == LINESPEC_LOCATION) |
9307 | address = get_linespec_location (location); | |
cc80f267 | 9308 | |
f00aae0f KS |
9309 | if (!cursal.symtab |
9310 | || (address != NULL | |
9311 | && strchr ("+-", address[0]) != NULL | |
9312 | && address[1] != '[')) | |
9313 | { | |
c2f4122d | 9314 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9315 | get_last_displayed_symtab (), |
9316 | get_last_displayed_line (), | |
9317 | canonical, NULL, NULL); | |
9318 | return; | |
9319 | } | |
c906108c | 9320 | } |
f00aae0f | 9321 | |
c2f4122d | 9322 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9323 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9324 | } |
c906108c | 9325 | |
c906108c | 9326 | |
c3f6f71d | 9327 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9328 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9329 | |
b9362cc7 | 9330 | static void |
6c5b2ebe | 9331 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9332 | { |
6c5b2ebe PA |
9333 | for (auto &sal : sals) |
9334 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9335 | } |
9336 | ||
7a697b8d SS |
9337 | /* Fast tracepoints may have restrictions on valid locations. For |
9338 | instance, a fast tracepoint using a jump instead of a trap will | |
9339 | likely have to overwrite more bytes than a trap would, and so can | |
9340 | only be placed where the instruction is longer than the jump, or a | |
9341 | multi-instruction sequence does not have a jump into the middle of | |
9342 | it, etc. */ | |
9343 | ||
9344 | static void | |
9345 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9346 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9347 | { |
6c5b2ebe | 9348 | int rslt; |
7a697b8d SS |
9349 | char *msg; |
9350 | struct cleanup *old_chain; | |
9351 | ||
6c5b2ebe | 9352 | for (const auto &sal : sals) |
7a697b8d | 9353 | { |
f8eba3c6 TT |
9354 | struct gdbarch *sarch; |
9355 | ||
6c5b2ebe | 9356 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9357 | /* We fall back to GDBARCH if there is no architecture |
9358 | associated with SAL. */ | |
9359 | if (sarch == NULL) | |
9360 | sarch = gdbarch; | |
6c5b2ebe | 9361 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg); |
7a697b8d SS |
9362 | old_chain = make_cleanup (xfree, msg); |
9363 | ||
9364 | if (!rslt) | |
53c3572a | 9365 | error (_("May not have a fast tracepoint at %s%s"), |
6c5b2ebe | 9366 | paddress (sarch, sal.pc), (msg ? msg : "")); |
7a697b8d SS |
9367 | |
9368 | do_cleanups (old_chain); | |
9369 | } | |
9370 | } | |
9371 | ||
018d34a4 VP |
9372 | /* Given TOK, a string specification of condition and thread, as |
9373 | accepted by the 'break' command, extract the condition | |
9374 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9375 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9376 | If no condition is found, *COND_STRING is set to NULL. |
9377 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9378 | |
9379 | static void | |
bbc13ae3 | 9380 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9381 | char **cond_string, int *thread, int *task, |
9382 | char **rest) | |
018d34a4 VP |
9383 | { |
9384 | *cond_string = NULL; | |
9385 | *thread = -1; | |
ed1d1739 KS |
9386 | *task = 0; |
9387 | *rest = NULL; | |
9388 | ||
018d34a4 VP |
9389 | while (tok && *tok) |
9390 | { | |
bbc13ae3 | 9391 | const char *end_tok; |
018d34a4 | 9392 | int toklen; |
bbc13ae3 KS |
9393 | const char *cond_start = NULL; |
9394 | const char *cond_end = NULL; | |
cc59ec59 | 9395 | |
f1735a53 | 9396 | tok = skip_spaces (tok); |
e7e0cddf SS |
9397 | |
9398 | if ((*tok == '"' || *tok == ',') && rest) | |
9399 | { | |
9400 | *rest = savestring (tok, strlen (tok)); | |
9401 | return; | |
9402 | } | |
9403 | ||
f1735a53 | 9404 | end_tok = skip_to_space (tok); |
d634f2de | 9405 | |
018d34a4 | 9406 | toklen = end_tok - tok; |
d634f2de | 9407 | |
018d34a4 VP |
9408 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9409 | { | |
9410 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9411 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9412 | cond_end = tok; |
d634f2de | 9413 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9414 | } |
9415 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9416 | { | |
5d5658a1 PA |
9417 | const char *tmptok; |
9418 | struct thread_info *thr; | |
d634f2de | 9419 | |
018d34a4 | 9420 | tok = end_tok + 1; |
5d5658a1 | 9421 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9422 | if (tok == tmptok) |
9423 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9424 | *thread = thr->global_num; |
bbc13ae3 | 9425 | tok = tmptok; |
018d34a4 | 9426 | } |
4a306c9a JB |
9427 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9428 | { | |
9429 | char *tmptok; | |
9430 | ||
9431 | tok = end_tok + 1; | |
bbc13ae3 | 9432 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9433 | if (tok == tmptok) |
9434 | error (_("Junk after task keyword.")); | |
9435 | if (!valid_task_id (*task)) | |
b6199126 | 9436 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9437 | tok = tmptok; |
4a306c9a | 9438 | } |
e7e0cddf SS |
9439 | else if (rest) |
9440 | { | |
9441 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9442 | return; |
e7e0cddf | 9443 | } |
018d34a4 VP |
9444 | else |
9445 | error (_("Junk at end of arguments.")); | |
9446 | } | |
9447 | } | |
9448 | ||
0fb4aa4b PA |
9449 | /* Decode a static tracepoint marker spec. */ |
9450 | ||
6c5b2ebe | 9451 | static std::vector<symtab_and_line> |
f00aae0f | 9452 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9453 | { |
9454 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
0fb4aa4b | 9455 | struct cleanup *old_chain; |
f00aae0f KS |
9456 | const char *p = &(*arg_p)[3]; |
9457 | const char *endp; | |
0fb4aa4b PA |
9458 | char *marker_str; |
9459 | int i; | |
9460 | ||
f1735a53 | 9461 | p = skip_spaces (p); |
0fb4aa4b | 9462 | |
f1735a53 | 9463 | endp = skip_to_space (p); |
0fb4aa4b PA |
9464 | |
9465 | marker_str = savestring (p, endp - p); | |
9466 | old_chain = make_cleanup (xfree, marker_str); | |
9467 | ||
9468 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9469 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9470 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9471 | ||
6c5b2ebe PA |
9472 | std::vector<symtab_and_line> sals; |
9473 | sals.reserve (VEC_length(static_tracepoint_marker_p, markers)); | |
0fb4aa4b | 9474 | |
6c5b2ebe | 9475 | for (i = 0; i < VEC_length(static_tracepoint_marker_p, markers); i++) |
0fb4aa4b PA |
9476 | { |
9477 | struct static_tracepoint_marker *marker; | |
9478 | ||
9479 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9480 | ||
51abb421 | 9481 | symtab_and_line sal = find_pc_line (marker->address, 0); |
6c5b2ebe PA |
9482 | sal.pc = marker->address; |
9483 | sals.push_back (sal); | |
0fb4aa4b PA |
9484 | |
9485 | release_static_tracepoint_marker (marker); | |
9486 | } | |
9487 | ||
9488 | do_cleanups (old_chain); | |
9489 | ||
9490 | *arg_p = endp; | |
9491 | return sals; | |
9492 | } | |
9493 | ||
f00aae0f | 9494 | /* See breakpoint.h. */ |
0101ce28 | 9495 | |
8cdf0e15 VP |
9496 | int |
9497 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9498 | const struct event_location *location, |
9499 | const char *cond_string, | |
9500 | int thread, const char *extra_string, | |
f00aae0f | 9501 | int parse_extra, |
0fb4aa4b | 9502 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9503 | int ignore_count, |
9504 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9505 | const struct breakpoint_ops *ops, |
44f238bb PA |
9506 | int from_tty, int enabled, int internal, |
9507 | unsigned flags) | |
c3f6f71d | 9508 | { |
7efd8fc2 | 9509 | struct linespec_result canonical; |
80c99de1 | 9510 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9511 | int pending = 0; |
4a306c9a | 9512 | int task = 0; |
86b17b60 | 9513 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9514 | |
348d480f PA |
9515 | gdb_assert (ops != NULL); |
9516 | ||
f00aae0f KS |
9517 | /* If extra_string isn't useful, set it to NULL. */ |
9518 | if (extra_string != NULL && *extra_string == '\0') | |
9519 | extra_string = NULL; | |
9520 | ||
492d29ea | 9521 | TRY |
b78a6381 | 9522 | { |
f00aae0f | 9523 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9524 | } |
492d29ea | 9525 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9526 | { |
492d29ea PA |
9527 | /* If caller is interested in rc value from parse, set |
9528 | value. */ | |
9529 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9530 | { |
05ff989b AC |
9531 | /* If pending breakpoint support is turned off, throw |
9532 | error. */ | |
fa8d40ab JJ |
9533 | |
9534 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9535 | throw_exception (e); |
9536 | ||
9537 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9538 | |
05ff989b AC |
9539 | /* If pending breakpoint support is auto query and the user |
9540 | selects no, then simply return the error code. */ | |
059fb39f | 9541 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9542 | && !nquery (_("Make %s pending on future shared library load? "), |
9543 | bptype_string (type_wanted))) | |
fd9b8c24 | 9544 | return 0; |
fa8d40ab | 9545 | |
05ff989b AC |
9546 | /* At this point, either the user was queried about setting |
9547 | a pending breakpoint and selected yes, or pending | |
9548 | breakpoint behavior is on and thus a pending breakpoint | |
9549 | is defaulted on behalf of the user. */ | |
f00aae0f | 9550 | pending = 1; |
0101ce28 | 9551 | } |
492d29ea PA |
9552 | else |
9553 | throw_exception (e); | |
0101ce28 | 9554 | } |
492d29ea PA |
9555 | END_CATCH |
9556 | ||
6c5b2ebe | 9557 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9558 | return 0; |
c3f6f71d | 9559 | |
c3f6f71d JM |
9560 | /* ----------------------------- SNIP ----------------------------- |
9561 | Anything added to the cleanup chain beyond this point is assumed | |
9562 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9563 | then the memory is not reclaimed. */ |
9564 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9565 | |
c3f6f71d JM |
9566 | /* Resolve all line numbers to PC's and verify that the addresses |
9567 | are ok for the target. */ | |
0101ce28 | 9568 | if (!pending) |
f8eba3c6 | 9569 | { |
6c5b2ebe PA |
9570 | for (auto &lsal : canonical.lsals) |
9571 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9572 | } |
c3f6f71d | 9573 | |
7a697b8d | 9574 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9575 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9576 | { |
6c5b2ebe PA |
9577 | for (const auto &lsal : canonical.lsals) |
9578 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9579 | } |
7a697b8d | 9580 | |
c3f6f71d JM |
9581 | /* Verify that condition can be parsed, before setting any |
9582 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9583 | breakpoint. */ |
0101ce28 | 9584 | if (!pending) |
c3f6f71d | 9585 | { |
e1e01040 PA |
9586 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9587 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9588 | ||
f00aae0f | 9589 | if (parse_extra) |
72b2ff0e | 9590 | { |
0878d0fa | 9591 | char *rest; |
e1e01040 | 9592 | char *cond; |
52d361e1 | 9593 | |
6c5b2ebe | 9594 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9595 | |
0878d0fa YQ |
9596 | /* Here we only parse 'arg' to separate condition |
9597 | from thread number, so parsing in context of first | |
9598 | sal is OK. When setting the breakpoint we'll | |
9599 | re-parse it in context of each sal. */ | |
9600 | ||
6c5b2ebe | 9601 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9602 | &cond, &thread, &task, &rest); |
9603 | cond_string_copy.reset (cond); | |
9604 | extra_string_copy.reset (rest); | |
72b2ff0e | 9605 | } |
2f069f6f | 9606 | else |
72b2ff0e | 9607 | { |
f00aae0f KS |
9608 | if (type_wanted != bp_dprintf |
9609 | && extra_string != NULL && *extra_string != '\0') | |
9610 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9611 | |
9612 | /* Create a private copy of condition string. */ | |
9613 | if (cond_string) | |
e1e01040 | 9614 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9615 | /* Create a private copy of any extra string. */ |
9616 | if (extra_string) | |
e1e01040 | 9617 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9618 | } |
0fb4aa4b | 9619 | |
52d361e1 | 9620 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9621 | std::move (cond_string_copy), |
9622 | std::move (extra_string_copy), | |
9623 | type_wanted, | |
d9b3f62e PA |
9624 | tempflag ? disp_del : disp_donttouch, |
9625 | thread, task, ignore_count, ops, | |
44f238bb | 9626 | from_tty, enabled, internal, flags); |
c906108c | 9627 | } |
0101ce28 JJ |
9628 | else |
9629 | { | |
a5e364af | 9630 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9631 | |
a5e364af | 9632 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9633 | b->location = copy_event_location (location); |
bfccc43c | 9634 | |
f00aae0f KS |
9635 | if (parse_extra) |
9636 | b->cond_string = NULL; | |
e12c7713 MK |
9637 | else |
9638 | { | |
9639 | /* Create a private copy of condition string. */ | |
e1e01040 | 9640 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9641 | b->thread = thread; |
e12c7713 | 9642 | } |
f00aae0f KS |
9643 | |
9644 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9645 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9646 | b->ignore_count = ignore_count; |
0101ce28 | 9647 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9648 | b->condition_not_parsed = 1; |
41447f92 | 9649 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9650 | if ((type_wanted != bp_breakpoint |
9651 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9652 | b->pspace = current_program_space; |
8bea4e01 | 9653 | |
b270e6f9 | 9654 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9655 | } |
9656 | ||
6c5b2ebe | 9657 | if (canonical.lsals.size () > 1) |
95a42b64 | 9658 | { |
3e43a32a MS |
9659 | warning (_("Multiple breakpoints were set.\nUse the " |
9660 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9661 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9662 | } |
9663 | ||
80c99de1 PA |
9664 | /* That's it. Discard the cleanups for data inserted into the |
9665 | breakpoint. */ | |
9666 | discard_cleanups (bkpt_chain); | |
217dc9e2 | 9667 | |
80c99de1 | 9668 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9669 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9670 | |
9671 | return 1; | |
c3f6f71d | 9672 | } |
c906108c | 9673 | |
348d480f | 9674 | /* Set a breakpoint. |
72b2ff0e VP |
9675 | ARG is a string describing breakpoint address, |
9676 | condition, and thread. | |
9677 | FLAG specifies if a breakpoint is hardware on, | |
9678 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9679 | and BP_TEMPFLAG. */ | |
348d480f | 9680 | |
98deb0da | 9681 | static void |
72b2ff0e | 9682 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9683 | { |
72b2ff0e | 9684 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9685 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9686 | ? bp_hardware_breakpoint | |
9687 | : bp_breakpoint); | |
55aa24fb | 9688 | struct breakpoint_ops *ops; |
f00aae0f | 9689 | |
ffc2605c | 9690 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9691 | |
9692 | /* Matching breakpoints on probes. */ | |
5b56227b | 9693 | if (location != NULL |
ffc2605c | 9694 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9695 | ops = &bkpt_probe_breakpoint_ops; |
9696 | else | |
9697 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9698 | |
8cdf0e15 | 9699 | create_breakpoint (get_current_arch (), |
ffc2605c | 9700 | location.get (), |
f00aae0f | 9701 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9702 | tempflag, type_wanted, |
8cdf0e15 VP |
9703 | 0 /* Ignore count */, |
9704 | pending_break_support, | |
55aa24fb | 9705 | ops, |
8cdf0e15 | 9706 | from_tty, |
84f4c1fe | 9707 | 1 /* enabled */, |
44f238bb PA |
9708 | 0 /* internal */, |
9709 | 0); | |
c906108c SS |
9710 | } |
9711 | ||
c906108c SS |
9712 | /* Helper function for break_command_1 and disassemble_command. */ |
9713 | ||
9714 | void | |
fba45db2 | 9715 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9716 | { |
9717 | CORE_ADDR pc; | |
9718 | ||
9719 | if (sal->pc == 0 && sal->symtab != NULL) | |
9720 | { | |
9721 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9722 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9723 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9724 | sal->pc = pc; |
6a048695 | 9725 | |
4a64f543 MS |
9726 | /* If this SAL corresponds to a breakpoint inserted using a line |
9727 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9728 | if (sal->explicit_line) |
059acae7 | 9729 | skip_prologue_sal (sal); |
c906108c SS |
9730 | } |
9731 | ||
9732 | if (sal->section == 0 && sal->symtab != NULL) | |
9733 | { | |
346d1dfe | 9734 | const struct blockvector *bv; |
3977b71f | 9735 | const struct block *b; |
c5aa993b | 9736 | struct symbol *sym; |
c906108c | 9737 | |
43f3e411 DE |
9738 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9739 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9740 | if (bv != NULL) |
9741 | { | |
7f0df278 | 9742 | sym = block_linkage_function (b); |
c906108c SS |
9743 | if (sym != NULL) |
9744 | { | |
eb822aa6 DE |
9745 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9746 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9747 | sym); | |
c906108c SS |
9748 | } |
9749 | else | |
9750 | { | |
4a64f543 MS |
9751 | /* It really is worthwhile to have the section, so we'll |
9752 | just have to look harder. This case can be executed | |
9753 | if we have line numbers but no functions (as can | |
9754 | happen in assembly source). */ | |
c906108c | 9755 | |
5ed8105e | 9756 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9757 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9758 | |
5ed8105e | 9759 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9760 | if (msym.minsym) |
efd66ac6 | 9761 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9762 | } |
9763 | } | |
9764 | } | |
9765 | } | |
9766 | ||
9767 | void | |
fba45db2 | 9768 | break_command (char *arg, int from_tty) |
c906108c | 9769 | { |
db107f19 | 9770 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9771 | } |
9772 | ||
c906108c | 9773 | void |
fba45db2 | 9774 | tbreak_command (char *arg, int from_tty) |
c906108c | 9775 | { |
db107f19 | 9776 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9777 | } |
9778 | ||
c906108c | 9779 | static void |
fba45db2 | 9780 | hbreak_command (char *arg, int from_tty) |
c906108c | 9781 | { |
db107f19 | 9782 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9783 | } |
9784 | ||
9785 | static void | |
fba45db2 | 9786 | thbreak_command (char *arg, int from_tty) |
c906108c | 9787 | { |
db107f19 | 9788 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9789 | } |
9790 | ||
9791 | static void | |
fba45db2 | 9792 | stop_command (char *arg, int from_tty) |
c906108c | 9793 | { |
a3f17187 | 9794 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9795 | Usage: stop in <function | address>\n\ |
a3f17187 | 9796 | stop at <line>\n")); |
c906108c SS |
9797 | } |
9798 | ||
9799 | static void | |
fba45db2 | 9800 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9801 | { |
9802 | int badInput = 0; | |
9803 | ||
c5aa993b | 9804 | if (arg == (char *) NULL) |
c906108c SS |
9805 | badInput = 1; |
9806 | else if (*arg != '*') | |
9807 | { | |
9808 | char *argptr = arg; | |
9809 | int hasColon = 0; | |
9810 | ||
4a64f543 | 9811 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9812 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9813 | function/method name. */ |
c906108c | 9814 | while (*argptr && !hasColon) |
c5aa993b JM |
9815 | { |
9816 | hasColon = (*argptr == ':'); | |
9817 | argptr++; | |
9818 | } | |
c906108c SS |
9819 | |
9820 | if (hasColon) | |
c5aa993b | 9821 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9822 | else |
c5aa993b | 9823 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9824 | } |
9825 | ||
9826 | if (badInput) | |
a3f17187 | 9827 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9828 | else |
db107f19 | 9829 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9830 | } |
9831 | ||
9832 | static void | |
fba45db2 | 9833 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9834 | { |
9835 | int badInput = 0; | |
9836 | ||
c5aa993b | 9837 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9838 | badInput = 1; |
9839 | else | |
9840 | { | |
9841 | char *argptr = arg; | |
9842 | int hasColon = 0; | |
9843 | ||
4a64f543 MS |
9844 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9845 | it is probably a line number. */ | |
c906108c | 9846 | while (*argptr && !hasColon) |
c5aa993b JM |
9847 | { |
9848 | hasColon = (*argptr == ':'); | |
9849 | argptr++; | |
9850 | } | |
c906108c SS |
9851 | |
9852 | if (hasColon) | |
c5aa993b | 9853 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9854 | else |
c5aa993b | 9855 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9856 | } |
9857 | ||
9858 | if (badInput) | |
a3f17187 | 9859 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9860 | else |
db107f19 | 9861 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9862 | } |
9863 | ||
e7e0cddf SS |
9864 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9865 | with a prewired command list consisting of a single output command, | |
9866 | built from extra arguments supplied on the dprintf command | |
9867 | line. */ | |
9868 | ||
da821c7b | 9869 | static void |
e7e0cddf SS |
9870 | dprintf_command (char *arg, int from_tty) |
9871 | { | |
ffc2605c | 9872 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9873 | |
9874 | /* If non-NULL, ARG should have been advanced past the location; | |
9875 | the next character must be ','. */ | |
9876 | if (arg != NULL) | |
9877 | { | |
9878 | if (arg[0] != ',' || arg[1] == '\0') | |
9879 | error (_("Format string required")); | |
9880 | else | |
9881 | { | |
9882 | /* Skip the comma. */ | |
9883 | ++arg; | |
9884 | } | |
9885 | } | |
9886 | ||
e7e0cddf | 9887 | create_breakpoint (get_current_arch (), |
ffc2605c | 9888 | location.get (), |
f00aae0f | 9889 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9890 | 0, bp_dprintf, |
9891 | 0 /* Ignore count */, | |
9892 | pending_break_support, | |
9893 | &dprintf_breakpoint_ops, | |
9894 | from_tty, | |
9895 | 1 /* enabled */, | |
9896 | 0 /* internal */, | |
9897 | 0); | |
9898 | } | |
9899 | ||
d3ce09f5 SS |
9900 | static void |
9901 | agent_printf_command (char *arg, int from_tty) | |
9902 | { | |
9903 | error (_("May only run agent-printf on the target")); | |
9904 | } | |
9905 | ||
f1310107 TJB |
9906 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
9907 | ranged breakpoints. */ | |
9908 | ||
9909 | static int | |
9910 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
9911 | struct address_space *aspace, | |
09ac7c10 TT |
9912 | CORE_ADDR bp_addr, |
9913 | const struct target_waitstatus *ws) | |
f1310107 | 9914 | { |
09ac7c10 | 9915 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 9916 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
9917 | return 0; |
9918 | ||
f1310107 TJB |
9919 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
9920 | bl->length, aspace, bp_addr); | |
9921 | } | |
9922 | ||
9923 | /* Implement the "resources_needed" breakpoint_ops method for | |
9924 | ranged breakpoints. */ | |
9925 | ||
9926 | static int | |
9927 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
9928 | { | |
9929 | return target_ranged_break_num_registers (); | |
9930 | } | |
9931 | ||
9932 | /* Implement the "print_it" breakpoint_ops method for | |
9933 | ranged breakpoints. */ | |
9934 | ||
9935 | static enum print_stop_action | |
348d480f | 9936 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 9937 | { |
348d480f | 9938 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 9939 | struct bp_location *bl = b->loc; |
79a45e25 | 9940 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9941 | |
9942 | gdb_assert (b->type == bp_hardware_breakpoint); | |
9943 | ||
9944 | /* Ranged breakpoints have only one location. */ | |
9945 | gdb_assert (bl && bl->next == NULL); | |
9946 | ||
9947 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
9948 | |
9949 | maybe_print_thread_hit_breakpoint (uiout); | |
9950 | ||
f1310107 | 9951 | if (b->disposition == disp_del) |
112e8700 | 9952 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 9953 | else |
112e8700 SM |
9954 | uiout->text ("Ranged breakpoint "); |
9955 | if (uiout->is_mi_like_p ()) | |
f1310107 | 9956 | { |
112e8700 | 9957 | uiout->field_string ("reason", |
f1310107 | 9958 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 9959 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 9960 | } |
112e8700 SM |
9961 | uiout->field_int ("bkptno", b->number); |
9962 | uiout->text (", "); | |
f1310107 TJB |
9963 | |
9964 | return PRINT_SRC_AND_LOC; | |
9965 | } | |
9966 | ||
9967 | /* Implement the "print_one" breakpoint_ops method for | |
9968 | ranged breakpoints. */ | |
9969 | ||
9970 | static void | |
9971 | print_one_ranged_breakpoint (struct breakpoint *b, | |
9972 | struct bp_location **last_loc) | |
9973 | { | |
9974 | struct bp_location *bl = b->loc; | |
9975 | struct value_print_options opts; | |
79a45e25 | 9976 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
9977 | |
9978 | /* Ranged breakpoints have only one location. */ | |
9979 | gdb_assert (bl && bl->next == NULL); | |
9980 | ||
9981 | get_user_print_options (&opts); | |
9982 | ||
9983 | if (opts.addressprint) | |
9984 | /* We don't print the address range here, it will be printed later | |
9985 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 9986 | uiout->field_skip ("addr"); |
f1310107 TJB |
9987 | annotate_field (5); |
9988 | print_breakpoint_location (b, bl); | |
9989 | *last_loc = bl; | |
9990 | } | |
9991 | ||
9992 | /* Implement the "print_one_detail" breakpoint_ops method for | |
9993 | ranged breakpoints. */ | |
9994 | ||
9995 | static void | |
9996 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
9997 | struct ui_out *uiout) | |
9998 | { | |
9999 | CORE_ADDR address_start, address_end; | |
10000 | struct bp_location *bl = b->loc; | |
d7e74731 | 10001 | string_file stb; |
f1310107 TJB |
10002 | |
10003 | gdb_assert (bl); | |
10004 | ||
10005 | address_start = bl->address; | |
10006 | address_end = address_start + bl->length - 1; | |
10007 | ||
112e8700 | 10008 | uiout->text ("\taddress range: "); |
d7e74731 PA |
10009 | stb.printf ("[%s, %s]", |
10010 | print_core_address (bl->gdbarch, address_start), | |
10011 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
10012 | uiout->field_stream ("addr", stb); |
10013 | uiout->text ("\n"); | |
f1310107 TJB |
10014 | } |
10015 | ||
10016 | /* Implement the "print_mention" breakpoint_ops method for | |
10017 | ranged breakpoints. */ | |
10018 | ||
10019 | static void | |
10020 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10021 | { | |
10022 | struct bp_location *bl = b->loc; | |
79a45e25 | 10023 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10024 | |
10025 | gdb_assert (bl); | |
10026 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10027 | ||
112e8700 | 10028 | if (uiout->is_mi_like_p ()) |
f1310107 TJB |
10029 | return; |
10030 | ||
10031 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10032 | b->number, paddress (bl->gdbarch, bl->address), | |
10033 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10034 | } | |
10035 | ||
10036 | /* Implement the "print_recreate" breakpoint_ops method for | |
10037 | ranged breakpoints. */ | |
10038 | ||
10039 | static void | |
10040 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10041 | { | |
f00aae0f | 10042 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
10043 | event_location_to_string (b->location.get ()), |
10044 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 10045 | print_recreate_thread (b, fp); |
f1310107 TJB |
10046 | } |
10047 | ||
10048 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10049 | ||
2060206e | 10050 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10051 | |
10052 | /* Find the address where the end of the breakpoint range should be | |
10053 | placed, given the SAL of the end of the range. This is so that if | |
10054 | the user provides a line number, the end of the range is set to the | |
10055 | last instruction of the given line. */ | |
10056 | ||
10057 | static CORE_ADDR | |
10058 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10059 | { | |
10060 | CORE_ADDR end; | |
10061 | ||
10062 | /* If the user provided a PC value, use it. Otherwise, | |
10063 | find the address of the end of the given location. */ | |
10064 | if (sal.explicit_pc) | |
10065 | end = sal.pc; | |
10066 | else | |
10067 | { | |
10068 | int ret; | |
10069 | CORE_ADDR start; | |
10070 | ||
10071 | ret = find_line_pc_range (sal, &start, &end); | |
10072 | if (!ret) | |
10073 | error (_("Could not find location of the end of the range.")); | |
10074 | ||
10075 | /* find_line_pc_range returns the start of the next line. */ | |
10076 | end--; | |
10077 | } | |
10078 | ||
10079 | return end; | |
10080 | } | |
10081 | ||
10082 | /* Implement the "break-range" CLI command. */ | |
10083 | ||
10084 | static void | |
10085 | break_range_command (char *arg, int from_tty) | |
10086 | { | |
870f88f7 | 10087 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10088 | struct linespec_result canonical_start, canonical_end; |
10089 | int bp_count, can_use_bp, length; | |
10090 | CORE_ADDR end; | |
10091 | struct breakpoint *b; | |
f1310107 TJB |
10092 | struct cleanup *cleanup_bkpt; |
10093 | ||
10094 | /* We don't support software ranged breakpoints. */ | |
10095 | if (target_ranged_break_num_registers () < 0) | |
10096 | error (_("This target does not support hardware ranged breakpoints.")); | |
10097 | ||
10098 | bp_count = hw_breakpoint_used_count (); | |
10099 | bp_count += target_ranged_break_num_registers (); | |
10100 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10101 | bp_count, 0); | |
10102 | if (can_use_bp < 0) | |
10103 | error (_("Hardware breakpoints used exceeds limit.")); | |
10104 | ||
f8eba3c6 | 10105 | arg = skip_spaces (arg); |
f1310107 TJB |
10106 | if (arg == NULL || arg[0] == '\0') |
10107 | error(_("No address range specified.")); | |
10108 | ||
f8eba3c6 | 10109 | arg_start = arg; |
ffc2605c TT |
10110 | event_location_up start_location = string_to_event_location (&arg, |
10111 | current_language); | |
10112 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
10113 | |
10114 | if (arg[0] != ',') | |
10115 | error (_("Too few arguments.")); | |
6c5b2ebe | 10116 | else if (canonical_start.lsals.empty ()) |
f1310107 | 10117 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 10118 | |
6c5b2ebe | 10119 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 10120 | |
6c5b2ebe PA |
10121 | if (canonical_start.lsals.size () > 1 |
10122 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
10123 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10124 | ||
6c5b2ebe | 10125 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
f8eba3c6 | 10126 | addr_string_start = savestring (arg_start, arg - arg_start); |
16e802b9 | 10127 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); |
f1310107 TJB |
10128 | |
10129 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10130 | arg = skip_spaces (arg); |
f1310107 TJB |
10131 | |
10132 | /* Parse the end location. */ | |
10133 | ||
f1310107 TJB |
10134 | arg_start = arg; |
10135 | ||
f8eba3c6 | 10136 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10137 | parse_breakpoint_sals because we need to specify the start location's |
10138 | symtab and line as the default symtab and line for the end of the | |
10139 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10140 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10141 | event_location_up end_location = string_to_event_location (&arg, |
10142 | current_language); | |
10143 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10144 | sal_start.symtab, sal_start.line, |
10145 | &canonical_end, NULL, NULL); | |
10146 | ||
6c5b2ebe | 10147 | if (canonical_end.lsals.empty ()) |
f1310107 | 10148 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 10149 | |
6c5b2ebe PA |
10150 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
10151 | if (canonical_end.lsals.size () > 1 | |
10152 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
10153 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10154 | ||
6c5b2ebe | 10155 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
10156 | |
10157 | end = find_breakpoint_range_end (sal_end); | |
10158 | if (sal_start.pc > end) | |
177b42fe | 10159 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10160 | |
10161 | length = end - sal_start.pc + 1; | |
10162 | if (length < 0) | |
10163 | /* Length overflowed. */ | |
10164 | error (_("Address range too large.")); | |
10165 | else if (length == 1) | |
10166 | { | |
10167 | /* This range is simple enough to be handled by | |
10168 | the `hbreak' command. */ | |
10169 | hbreak_command (addr_string_start, 1); | |
10170 | ||
10171 | do_cleanups (cleanup_bkpt); | |
10172 | ||
10173 | return; | |
10174 | } | |
10175 | ||
10176 | /* Now set up the breakpoint. */ | |
10177 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10178 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10179 | set_breakpoint_count (breakpoint_count + 1); |
10180 | b->number = breakpoint_count; | |
10181 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10182 | b->location = std::move (start_location); |
10183 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10184 | b->loc->length = length; |
10185 | ||
f8eba3c6 | 10186 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10187 | |
10188 | mention (b); | |
8d3788bd | 10189 | observer_notify_breakpoint_created (b); |
44702360 | 10190 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10191 | } |
10192 | ||
4a64f543 MS |
10193 | /* Return non-zero if EXP is verified as constant. Returned zero |
10194 | means EXP is variable. Also the constant detection may fail for | |
10195 | some constant expressions and in such case still falsely return | |
10196 | zero. */ | |
2e6e3d9c | 10197 | |
65d79d4b SDJ |
10198 | static int |
10199 | watchpoint_exp_is_const (const struct expression *exp) | |
10200 | { | |
10201 | int i = exp->nelts; | |
10202 | ||
10203 | while (i > 0) | |
10204 | { | |
10205 | int oplenp, argsp; | |
10206 | ||
10207 | /* We are only interested in the descriptor of each element. */ | |
10208 | operator_length (exp, i, &oplenp, &argsp); | |
10209 | i -= oplenp; | |
10210 | ||
10211 | switch (exp->elts[i].opcode) | |
10212 | { | |
10213 | case BINOP_ADD: | |
10214 | case BINOP_SUB: | |
10215 | case BINOP_MUL: | |
10216 | case BINOP_DIV: | |
10217 | case BINOP_REM: | |
10218 | case BINOP_MOD: | |
10219 | case BINOP_LSH: | |
10220 | case BINOP_RSH: | |
10221 | case BINOP_LOGICAL_AND: | |
10222 | case BINOP_LOGICAL_OR: | |
10223 | case BINOP_BITWISE_AND: | |
10224 | case BINOP_BITWISE_IOR: | |
10225 | case BINOP_BITWISE_XOR: | |
10226 | case BINOP_EQUAL: | |
10227 | case BINOP_NOTEQUAL: | |
10228 | case BINOP_LESS: | |
10229 | case BINOP_GTR: | |
10230 | case BINOP_LEQ: | |
10231 | case BINOP_GEQ: | |
10232 | case BINOP_REPEAT: | |
10233 | case BINOP_COMMA: | |
10234 | case BINOP_EXP: | |
10235 | case BINOP_MIN: | |
10236 | case BINOP_MAX: | |
10237 | case BINOP_INTDIV: | |
10238 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10239 | case TERNOP_COND: |
10240 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10241 | |
10242 | case OP_LONG: | |
10243 | case OP_DOUBLE: | |
10244 | case OP_DECFLOAT: | |
10245 | case OP_LAST: | |
10246 | case OP_COMPLEX: | |
10247 | case OP_STRING: | |
65d79d4b SDJ |
10248 | case OP_ARRAY: |
10249 | case OP_TYPE: | |
608b4967 TT |
10250 | case OP_TYPEOF: |
10251 | case OP_DECLTYPE: | |
6e72ca20 | 10252 | case OP_TYPEID: |
65d79d4b SDJ |
10253 | case OP_NAME: |
10254 | case OP_OBJC_NSSTRING: | |
10255 | ||
10256 | case UNOP_NEG: | |
10257 | case UNOP_LOGICAL_NOT: | |
10258 | case UNOP_COMPLEMENT: | |
10259 | case UNOP_ADDR: | |
10260 | case UNOP_HIGH: | |
aeaa2474 | 10261 | case UNOP_CAST: |
9eaf6705 TT |
10262 | |
10263 | case UNOP_CAST_TYPE: | |
10264 | case UNOP_REINTERPRET_CAST: | |
10265 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10266 | /* Unary, binary and ternary operators: We have to check |
10267 | their operands. If they are constant, then so is the | |
10268 | result of that operation. For instance, if A and B are | |
10269 | determined to be constants, then so is "A + B". | |
10270 | ||
10271 | UNOP_IND is one exception to the rule above, because the | |
10272 | value of *ADDR is not necessarily a constant, even when | |
10273 | ADDR is. */ | |
65d79d4b SDJ |
10274 | break; |
10275 | ||
10276 | case OP_VAR_VALUE: | |
10277 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10278 | |
65d79d4b | 10279 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10280 | possible that a buggy compiler could mark a variable as |
10281 | constant even when it is not, and TYPE_CONST would return | |
10282 | true in this case, while SYMBOL_CLASS wouldn't. | |
10283 | ||
10284 | We also have to check for function symbols because they | |
10285 | are always constant. */ | |
65d79d4b SDJ |
10286 | { |
10287 | struct symbol *s = exp->elts[i + 2].symbol; | |
10288 | ||
10289 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10290 | && SYMBOL_CLASS (s) != LOC_CONST | |
10291 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10292 | return 0; | |
10293 | break; | |
10294 | } | |
10295 | ||
10296 | /* The default action is to return 0 because we are using | |
10297 | the optimistic approach here: If we don't know something, | |
10298 | then it is not a constant. */ | |
10299 | default: | |
10300 | return 0; | |
10301 | } | |
10302 | } | |
10303 | ||
10304 | return 1; | |
10305 | } | |
10306 | ||
c1fc2657 | 10307 | /* Watchpoint destructor. */ |
3a5c3e22 | 10308 | |
c1fc2657 | 10309 | watchpoint::~watchpoint () |
3a5c3e22 | 10310 | { |
c1fc2657 SM |
10311 | xfree (this->exp_string); |
10312 | xfree (this->exp_string_reparse); | |
10313 | value_free (this->val); | |
3a5c3e22 PA |
10314 | } |
10315 | ||
348d480f PA |
10316 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10317 | ||
10318 | static void | |
10319 | re_set_watchpoint (struct breakpoint *b) | |
10320 | { | |
3a5c3e22 PA |
10321 | struct watchpoint *w = (struct watchpoint *) b; |
10322 | ||
348d480f PA |
10323 | /* Watchpoint can be either on expression using entirely global |
10324 | variables, or it can be on local variables. | |
10325 | ||
10326 | Watchpoints of the first kind are never auto-deleted, and even | |
10327 | persist across program restarts. Since they can use variables | |
10328 | from shared libraries, we need to reparse expression as libraries | |
10329 | are loaded and unloaded. | |
10330 | ||
10331 | Watchpoints on local variables can also change meaning as result | |
10332 | of solib event. For example, if a watchpoint uses both a local | |
10333 | and a global variables in expression, it's a local watchpoint, | |
10334 | but unloading of a shared library will make the expression | |
10335 | invalid. This is not a very common use case, but we still | |
10336 | re-evaluate expression, to avoid surprises to the user. | |
10337 | ||
10338 | Note that for local watchpoints, we re-evaluate it only if | |
10339 | watchpoints frame id is still valid. If it's not, it means the | |
10340 | watchpoint is out of scope and will be deleted soon. In fact, | |
10341 | I'm not sure we'll ever be called in this case. | |
10342 | ||
10343 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10344 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10345 | |
3a5c3e22 PA |
10346 | Don't do anything about disabled watchpoints, since they will be |
10347 | reevaluated again when enabled. */ | |
10348 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10349 | } |
10350 | ||
77b06cd7 TJB |
10351 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10352 | ||
10353 | static int | |
10354 | insert_watchpoint (struct bp_location *bl) | |
10355 | { | |
3a5c3e22 PA |
10356 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10357 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10358 | |
10359 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10360 | w->cond_exp.get ()); |
77b06cd7 TJB |
10361 | } |
10362 | ||
10363 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10364 | ||
10365 | static int | |
73971819 | 10366 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10367 | { |
3a5c3e22 PA |
10368 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10369 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10370 | |
10371 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10372 | w->cond_exp.get ()); |
e09342b5 TJB |
10373 | } |
10374 | ||
e09342b5 | 10375 | static int |
348d480f | 10376 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10377 | struct address_space *aspace, CORE_ADDR bp_addr, |
10378 | const struct target_waitstatus *ws) | |
e09342b5 | 10379 | { |
348d480f | 10380 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10381 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10382 | |
348d480f PA |
10383 | /* Continuable hardware watchpoints are treated as non-existent if the |
10384 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10385 | some data address). Otherwise gdb won't stop on a break instruction | |
10386 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10387 | been defined. Also skip watchpoints which we know did not trigger | |
10388 | (did not match the data address). */ | |
10389 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10390 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10391 | return 0; |
9c06b0b4 | 10392 | |
348d480f | 10393 | return 1; |
9c06b0b4 TJB |
10394 | } |
10395 | ||
348d480f PA |
10396 | static void |
10397 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10398 | { |
348d480f | 10399 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10400 | |
348d480f | 10401 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10402 | } |
10403 | ||
10404 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10405 | hardware watchpoints. */ |
9c06b0b4 TJB |
10406 | |
10407 | static int | |
348d480f | 10408 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10409 | { |
3a5c3e22 PA |
10410 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10411 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10412 | |
10413 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10414 | } |
10415 | ||
10416 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10417 | hardware watchpoints. */ |
9c06b0b4 TJB |
10418 | |
10419 | static int | |
348d480f | 10420 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10421 | { |
efa80663 PA |
10422 | /* Read and access watchpoints only work with hardware support. */ |
10423 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10424 | } |
10425 | ||
9c06b0b4 | 10426 | static enum print_stop_action |
348d480f | 10427 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10428 | { |
348d480f | 10429 | struct breakpoint *b; |
348d480f | 10430 | enum print_stop_action result; |
3a5c3e22 | 10431 | struct watchpoint *w; |
79a45e25 | 10432 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10433 | |
10434 | gdb_assert (bs->bp_location_at != NULL); | |
10435 | ||
348d480f | 10436 | b = bs->breakpoint_at; |
3a5c3e22 | 10437 | w = (struct watchpoint *) b; |
348d480f | 10438 | |
f303dbd6 PA |
10439 | annotate_watchpoint (b->number); |
10440 | maybe_print_thread_hit_breakpoint (uiout); | |
10441 | ||
d7e74731 PA |
10442 | string_file stb; |
10443 | ||
76f9c9cf | 10444 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10445 | switch (b->type) |
10446 | { | |
348d480f | 10447 | case bp_watchpoint: |
9c06b0b4 | 10448 | case bp_hardware_watchpoint: |
112e8700 SM |
10449 | if (uiout->is_mi_like_p ()) |
10450 | uiout->field_string | |
10451 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10452 | mention (b); |
76f9c9cf | 10453 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10454 | uiout->text ("\nOld value = "); |
d7e74731 | 10455 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10456 | uiout->field_stream ("old", stb); |
10457 | uiout->text ("\nNew value = "); | |
d7e74731 | 10458 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10459 | uiout->field_stream ("new", stb); |
10460 | uiout->text ("\n"); | |
348d480f PA |
10461 | /* More than one watchpoint may have been triggered. */ |
10462 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10463 | break; |
10464 | ||
10465 | case bp_read_watchpoint: | |
112e8700 SM |
10466 | if (uiout->is_mi_like_p ()) |
10467 | uiout->field_string | |
10468 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10469 | mention (b); |
76f9c9cf | 10470 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10471 | uiout->text ("\nValue = "); |
d7e74731 | 10472 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10473 | uiout->field_stream ("value", stb); |
10474 | uiout->text ("\n"); | |
348d480f | 10475 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10476 | break; |
10477 | ||
10478 | case bp_access_watchpoint: | |
348d480f PA |
10479 | if (bs->old_val != NULL) |
10480 | { | |
112e8700 SM |
10481 | if (uiout->is_mi_like_p ()) |
10482 | uiout->field_string | |
10483 | ("reason", | |
348d480f PA |
10484 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10485 | mention (b); | |
76f9c9cf | 10486 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10487 | uiout->text ("\nOld value = "); |
d7e74731 | 10488 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10489 | uiout->field_stream ("old", stb); |
10490 | uiout->text ("\nNew value = "); | |
348d480f PA |
10491 | } |
10492 | else | |
10493 | { | |
10494 | mention (b); | |
112e8700 SM |
10495 | if (uiout->is_mi_like_p ()) |
10496 | uiout->field_string | |
10497 | ("reason", | |
348d480f | 10498 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10499 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10500 | uiout->text ("\nValue = "); |
348d480f | 10501 | } |
d7e74731 | 10502 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10503 | uiout->field_stream ("new", stb); |
10504 | uiout->text ("\n"); | |
348d480f | 10505 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10506 | break; |
10507 | default: | |
348d480f | 10508 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10509 | } |
10510 | ||
348d480f PA |
10511 | return result; |
10512 | } | |
10513 | ||
10514 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10515 | watchpoints. */ | |
10516 | ||
10517 | static void | |
10518 | print_mention_watchpoint (struct breakpoint *b) | |
10519 | { | |
3a5c3e22 | 10520 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10521 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10522 | const char *tuple_name; |
348d480f PA |
10523 | |
10524 | switch (b->type) | |
10525 | { | |
10526 | case bp_watchpoint: | |
112e8700 | 10527 | uiout->text ("Watchpoint "); |
46b9c129 | 10528 | tuple_name = "wpt"; |
348d480f PA |
10529 | break; |
10530 | case bp_hardware_watchpoint: | |
112e8700 | 10531 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10532 | tuple_name = "wpt"; |
348d480f PA |
10533 | break; |
10534 | case bp_read_watchpoint: | |
112e8700 | 10535 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10536 | tuple_name = "hw-rwpt"; |
348d480f PA |
10537 | break; |
10538 | case bp_access_watchpoint: | |
112e8700 | 10539 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10540 | tuple_name = "hw-awpt"; |
348d480f PA |
10541 | break; |
10542 | default: | |
10543 | internal_error (__FILE__, __LINE__, | |
10544 | _("Invalid hardware watchpoint type.")); | |
10545 | } | |
10546 | ||
46b9c129 | 10547 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10548 | uiout->field_int ("number", b->number); |
10549 | uiout->text (": "); | |
10550 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10551 | } |
10552 | ||
10553 | /* Implement the "print_recreate" breakpoint_ops method for | |
10554 | watchpoints. */ | |
10555 | ||
10556 | static void | |
10557 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10558 | { | |
3a5c3e22 PA |
10559 | struct watchpoint *w = (struct watchpoint *) b; |
10560 | ||
348d480f PA |
10561 | switch (b->type) |
10562 | { | |
10563 | case bp_watchpoint: | |
10564 | case bp_hardware_watchpoint: | |
10565 | fprintf_unfiltered (fp, "watch"); | |
10566 | break; | |
10567 | case bp_read_watchpoint: | |
10568 | fprintf_unfiltered (fp, "rwatch"); | |
10569 | break; | |
10570 | case bp_access_watchpoint: | |
10571 | fprintf_unfiltered (fp, "awatch"); | |
10572 | break; | |
10573 | default: | |
10574 | internal_error (__FILE__, __LINE__, | |
10575 | _("Invalid watchpoint type.")); | |
10576 | } | |
10577 | ||
3a5c3e22 | 10578 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10579 | print_recreate_thread (b, fp); |
348d480f PA |
10580 | } |
10581 | ||
427cd150 TT |
10582 | /* Implement the "explains_signal" breakpoint_ops method for |
10583 | watchpoints. */ | |
10584 | ||
47591c29 | 10585 | static int |
427cd150 TT |
10586 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10587 | { | |
10588 | /* A software watchpoint cannot cause a signal other than | |
10589 | GDB_SIGNAL_TRAP. */ | |
10590 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10591 | return 0; |
427cd150 | 10592 | |
47591c29 | 10593 | return 1; |
427cd150 TT |
10594 | } |
10595 | ||
348d480f PA |
10596 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10597 | ||
2060206e | 10598 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10599 | |
10600 | /* Implement the "insert" breakpoint_ops method for | |
10601 | masked hardware watchpoints. */ | |
10602 | ||
10603 | static int | |
10604 | insert_masked_watchpoint (struct bp_location *bl) | |
10605 | { | |
3a5c3e22 PA |
10606 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10607 | ||
10608 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10609 | bl->watchpoint_type); |
10610 | } | |
10611 | ||
10612 | /* Implement the "remove" breakpoint_ops method for | |
10613 | masked hardware watchpoints. */ | |
10614 | ||
10615 | static int | |
73971819 | 10616 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10617 | { |
3a5c3e22 PA |
10618 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10619 | ||
10620 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10621 | bl->watchpoint_type); |
10622 | } | |
10623 | ||
10624 | /* Implement the "resources_needed" breakpoint_ops method for | |
10625 | masked hardware watchpoints. */ | |
10626 | ||
10627 | static int | |
10628 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10629 | { | |
3a5c3e22 PA |
10630 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10631 | ||
10632 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10633 | } |
10634 | ||
10635 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10636 | masked hardware watchpoints. */ | |
10637 | ||
10638 | static int | |
10639 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10640 | { | |
10641 | return 0; | |
10642 | } | |
10643 | ||
10644 | /* Implement the "print_it" breakpoint_ops method for | |
10645 | masked hardware watchpoints. */ | |
10646 | ||
10647 | static enum print_stop_action | |
10648 | print_it_masked_watchpoint (bpstat bs) | |
10649 | { | |
10650 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10651 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10652 | |
10653 | /* Masked watchpoints have only one location. */ | |
10654 | gdb_assert (b->loc && b->loc->next == NULL); | |
10655 | ||
f303dbd6 PA |
10656 | annotate_watchpoint (b->number); |
10657 | maybe_print_thread_hit_breakpoint (uiout); | |
10658 | ||
348d480f PA |
10659 | switch (b->type) |
10660 | { | |
10661 | case bp_hardware_watchpoint: | |
112e8700 SM |
10662 | if (uiout->is_mi_like_p ()) |
10663 | uiout->field_string | |
10664 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10665 | break; |
10666 | ||
10667 | case bp_read_watchpoint: | |
112e8700 SM |
10668 | if (uiout->is_mi_like_p ()) |
10669 | uiout->field_string | |
10670 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10671 | break; |
10672 | ||
10673 | case bp_access_watchpoint: | |
112e8700 SM |
10674 | if (uiout->is_mi_like_p ()) |
10675 | uiout->field_string | |
10676 | ("reason", | |
348d480f PA |
10677 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10678 | break; | |
10679 | default: | |
10680 | internal_error (__FILE__, __LINE__, | |
10681 | _("Invalid hardware watchpoint type.")); | |
10682 | } | |
10683 | ||
10684 | mention (b); | |
112e8700 | 10685 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10686 | Check the underlying instruction at PC for the memory\n\ |
10687 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10688 | uiout->text ("\n"); |
9c06b0b4 TJB |
10689 | |
10690 | /* More than one watchpoint may have been triggered. */ | |
10691 | return PRINT_UNKNOWN; | |
10692 | } | |
10693 | ||
10694 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10695 | masked hardware watchpoints. */ | |
10696 | ||
10697 | static void | |
10698 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10699 | struct ui_out *uiout) | |
10700 | { | |
3a5c3e22 PA |
10701 | struct watchpoint *w = (struct watchpoint *) b; |
10702 | ||
9c06b0b4 TJB |
10703 | /* Masked watchpoints have only one location. */ |
10704 | gdb_assert (b->loc && b->loc->next == NULL); | |
10705 | ||
112e8700 SM |
10706 | uiout->text ("\tmask "); |
10707 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10708 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10709 | } |
10710 | ||
10711 | /* Implement the "print_mention" breakpoint_ops method for | |
10712 | masked hardware watchpoints. */ | |
10713 | ||
10714 | static void | |
10715 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10716 | { | |
3a5c3e22 | 10717 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10718 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10719 | const char *tuple_name; |
9c06b0b4 TJB |
10720 | |
10721 | switch (b->type) | |
10722 | { | |
10723 | case bp_hardware_watchpoint: | |
112e8700 | 10724 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10725 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10726 | break; |
10727 | case bp_read_watchpoint: | |
112e8700 | 10728 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10729 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10730 | break; |
10731 | case bp_access_watchpoint: | |
112e8700 | 10732 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10733 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10734 | break; |
10735 | default: | |
10736 | internal_error (__FILE__, __LINE__, | |
10737 | _("Invalid hardware watchpoint type.")); | |
10738 | } | |
10739 | ||
46b9c129 | 10740 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10741 | uiout->field_int ("number", b->number); |
10742 | uiout->text (": "); | |
10743 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10744 | } |
10745 | ||
10746 | /* Implement the "print_recreate" breakpoint_ops method for | |
10747 | masked hardware watchpoints. */ | |
10748 | ||
10749 | static void | |
10750 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10751 | { | |
3a5c3e22 | 10752 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10753 | char tmp[40]; |
10754 | ||
10755 | switch (b->type) | |
10756 | { | |
10757 | case bp_hardware_watchpoint: | |
10758 | fprintf_unfiltered (fp, "watch"); | |
10759 | break; | |
10760 | case bp_read_watchpoint: | |
10761 | fprintf_unfiltered (fp, "rwatch"); | |
10762 | break; | |
10763 | case bp_access_watchpoint: | |
10764 | fprintf_unfiltered (fp, "awatch"); | |
10765 | break; | |
10766 | default: | |
10767 | internal_error (__FILE__, __LINE__, | |
10768 | _("Invalid hardware watchpoint type.")); | |
10769 | } | |
10770 | ||
3a5c3e22 PA |
10771 | sprintf_vma (tmp, w->hw_wp_mask); |
10772 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10773 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10774 | } |
10775 | ||
10776 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10777 | ||
2060206e | 10778 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10779 | |
10780 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10781 | ||
10782 | static int | |
10783 | is_masked_watchpoint (const struct breakpoint *b) | |
10784 | { | |
10785 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10786 | } | |
10787 | ||
53a5351d JM |
10788 | /* accessflag: hw_write: watch write, |
10789 | hw_read: watch read, | |
10790 | hw_access: watch access (read or write) */ | |
c906108c | 10791 | static void |
bbc13ae3 | 10792 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10793 | int just_location, int internal) |
c906108c | 10794 | { |
c1fc2657 | 10795 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10796 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10797 | struct value *val, *mark, *result; |
bb9d5f81 | 10798 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10799 | const char *exp_start = NULL; |
10800 | const char *exp_end = NULL; | |
10801 | const char *tok, *end_tok; | |
9c06b0b4 | 10802 | int toklen = -1; |
bbc13ae3 KS |
10803 | const char *cond_start = NULL; |
10804 | const char *cond_end = NULL; | |
c906108c | 10805 | enum bptype bp_type; |
37e4754d | 10806 | int thread = -1; |
0cf6dd15 | 10807 | int pc = 0; |
9c06b0b4 TJB |
10808 | /* Flag to indicate whether we are going to use masks for |
10809 | the hardware watchpoint. */ | |
10810 | int use_mask = 0; | |
10811 | CORE_ADDR mask = 0; | |
bbc13ae3 KS |
10812 | char *expression; |
10813 | struct cleanup *back_to; | |
c906108c | 10814 | |
37e4754d LM |
10815 | /* Make sure that we actually have parameters to parse. */ |
10816 | if (arg != NULL && arg[0] != '\0') | |
10817 | { | |
bbc13ae3 KS |
10818 | const char *value_start; |
10819 | ||
10820 | exp_end = arg + strlen (arg); | |
37e4754d | 10821 | |
9c06b0b4 TJB |
10822 | /* Look for "parameter value" pairs at the end |
10823 | of the arguments string. */ | |
bbc13ae3 | 10824 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10825 | { |
10826 | /* Skip whitespace at the end of the argument list. */ | |
10827 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10828 | tok--; | |
10829 | ||
10830 | /* Find the beginning of the last token. | |
10831 | This is the value of the parameter. */ | |
10832 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10833 | tok--; | |
10834 | value_start = tok + 1; | |
10835 | ||
10836 | /* Skip whitespace. */ | |
10837 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10838 | tok--; | |
10839 | ||
10840 | end_tok = tok; | |
10841 | ||
10842 | /* Find the beginning of the second to last token. | |
10843 | This is the parameter itself. */ | |
10844 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10845 | tok--; | |
10846 | tok++; | |
10847 | toklen = end_tok - tok + 1; | |
10848 | ||
61012eef | 10849 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10850 | { |
5d5658a1 | 10851 | struct thread_info *thr; |
9c06b0b4 TJB |
10852 | /* At this point we've found a "thread" token, which means |
10853 | the user is trying to set a watchpoint that triggers | |
10854 | only in a specific thread. */ | |
5d5658a1 | 10855 | const char *endp; |
37e4754d | 10856 | |
9c06b0b4 TJB |
10857 | if (thread != -1) |
10858 | error(_("You can specify only one thread.")); | |
37e4754d | 10859 | |
9c06b0b4 | 10860 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10861 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10862 | |
5d5658a1 | 10863 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10864 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10865 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10866 | |
5d5658a1 | 10867 | thread = thr->global_num; |
9c06b0b4 | 10868 | } |
61012eef | 10869 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10870 | { |
10871 | /* We've found a "mask" token, which means the user wants to | |
10872 | create a hardware watchpoint that is going to have the mask | |
10873 | facility. */ | |
10874 | struct value *mask_value, *mark; | |
37e4754d | 10875 | |
9c06b0b4 TJB |
10876 | if (use_mask) |
10877 | error(_("You can specify only one mask.")); | |
37e4754d | 10878 | |
9c06b0b4 | 10879 | use_mask = just_location = 1; |
37e4754d | 10880 | |
9c06b0b4 TJB |
10881 | mark = value_mark (); |
10882 | mask_value = parse_to_comma_and_eval (&value_start); | |
10883 | mask = value_as_address (mask_value); | |
10884 | value_free_to_mark (mark); | |
10885 | } | |
10886 | else | |
10887 | /* We didn't recognize what we found. We should stop here. */ | |
10888 | break; | |
37e4754d | 10889 | |
9c06b0b4 TJB |
10890 | /* Truncate the string and get rid of the "parameter value" pair before |
10891 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 10892 | exp_end = tok; |
9c06b0b4 | 10893 | } |
37e4754d | 10894 | } |
bbc13ae3 KS |
10895 | else |
10896 | exp_end = arg; | |
37e4754d | 10897 | |
bbc13ae3 KS |
10898 | /* Parse the rest of the arguments. From here on out, everything |
10899 | is in terms of a newly allocated string instead of the original | |
10900 | ARG. */ | |
c906108c | 10901 | innermost_block = NULL; |
bbc13ae3 KS |
10902 | expression = savestring (arg, exp_end - arg); |
10903 | back_to = make_cleanup (xfree, expression); | |
10904 | exp_start = arg = expression; | |
4d01a485 | 10905 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 10906 | exp_end = arg; |
fa8a61dc TT |
10907 | /* Remove trailing whitespace from the expression before saving it. |
10908 | This makes the eventual display of the expression string a bit | |
10909 | prettier. */ | |
10910 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
10911 | --exp_end; | |
10912 | ||
65d79d4b | 10913 | /* Checking if the expression is not constant. */ |
4d01a485 | 10914 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
10915 | { |
10916 | int len; | |
10917 | ||
10918 | len = exp_end - exp_start; | |
10919 | while (len > 0 && isspace (exp_start[len - 1])) | |
10920 | len--; | |
10921 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
10922 | } | |
10923 | ||
c906108c SS |
10924 | exp_valid_block = innermost_block; |
10925 | mark = value_mark (); | |
4d01a485 | 10926 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 10927 | |
bb9d5f81 PP |
10928 | if (val != NULL && just_location) |
10929 | { | |
10930 | saved_bitpos = value_bitpos (val); | |
10931 | saved_bitsize = value_bitsize (val); | |
10932 | } | |
10933 | ||
06a64a0b TT |
10934 | if (just_location) |
10935 | { | |
9c06b0b4 TJB |
10936 | int ret; |
10937 | ||
06a64a0b | 10938 | exp_valid_block = NULL; |
a1442452 | 10939 | val = value_addr (result); |
06a64a0b TT |
10940 | release_value (val); |
10941 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
10942 | |
10943 | if (use_mask) | |
10944 | { | |
10945 | ret = target_masked_watch_num_registers (value_as_address (val), | |
10946 | mask); | |
10947 | if (ret == -1) | |
10948 | error (_("This target does not support masked watchpoints.")); | |
10949 | else if (ret == -2) | |
10950 | error (_("Invalid mask or memory region.")); | |
10951 | } | |
06a64a0b TT |
10952 | } |
10953 | else if (val != NULL) | |
fa4727a6 | 10954 | release_value (val); |
c906108c | 10955 | |
f1735a53 TT |
10956 | tok = skip_spaces (arg); |
10957 | end_tok = skip_to_space (tok); | |
c906108c SS |
10958 | |
10959 | toklen = end_tok - tok; | |
10960 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
10961 | { | |
60e1c644 | 10962 | innermost_block = NULL; |
c906108c | 10963 | tok = cond_start = end_tok + 1; |
4d01a485 | 10964 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
10965 | |
10966 | /* The watchpoint expression may not be local, but the condition | |
10967 | may still be. E.g.: `watch global if local > 0'. */ | |
10968 | cond_exp_valid_block = innermost_block; | |
10969 | ||
c906108c SS |
10970 | cond_end = tok; |
10971 | } | |
10972 | if (*tok) | |
8a3fe4f8 | 10973 | error (_("Junk at end of command.")); |
c906108c | 10974 | |
441d7c93 PA |
10975 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
10976 | ||
10977 | /* Save this because create_internal_breakpoint below invalidates | |
10978 | 'wp_frame'. */ | |
10979 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
10980 | |
10981 | /* If the expression is "local", then set up a "watchpoint scope" | |
10982 | breakpoint at the point where we've left the scope of the watchpoint | |
10983 | expression. Create the scope breakpoint before the watchpoint, so | |
10984 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 10985 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 10986 | { |
441d7c93 PA |
10987 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
10988 | ||
10989 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 10990 | { |
441d7c93 PA |
10991 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
10992 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
10993 | ||
edb3359d | 10994 | scope_breakpoint |
441d7c93 | 10995 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
10996 | bp_watchpoint_scope, |
10997 | &momentary_breakpoint_ops); | |
d983da9c | 10998 | |
441d7c93 PA |
10999 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
11000 | wp_frame = NULL; | |
11001 | ||
edb3359d | 11002 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11003 | |
edb3359d DJ |
11004 | /* Automatically delete the breakpoint when it hits. */ |
11005 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11006 | |
edb3359d | 11007 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 11008 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 11009 | |
edb3359d | 11010 | /* Set the address at which we will stop. */ |
441d7c93 PA |
11011 | scope_breakpoint->loc->gdbarch = caller_arch; |
11012 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 11013 | scope_breakpoint->loc->address |
a6d9a66e UW |
11014 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11015 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11016 | scope_breakpoint->type); |
11017 | } | |
d983da9c DJ |
11018 | } |
11019 | ||
e8369a73 AB |
11020 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11021 | watchpoints here even if hardware watchpoints are turned off, a call | |
11022 | to update_watchpoint later in this function will cause the type to | |
11023 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11024 | ||
11025 | if (accessflag == hw_read) | |
11026 | bp_type = bp_read_watchpoint; | |
11027 | else if (accessflag == hw_access) | |
11028 | bp_type = bp_access_watchpoint; | |
11029 | else | |
11030 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 11031 | |
b270e6f9 | 11032 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 11033 | |
348d480f | 11034 | if (use_mask) |
b270e6f9 | 11035 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 11036 | &masked_watchpoint_breakpoint_ops); |
348d480f | 11037 | else |
b270e6f9 | 11038 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 11039 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
11040 | w->thread = thread; |
11041 | w->disposition = disp_donttouch; | |
11042 | w->pspace = current_program_space; | |
b22e99fd | 11043 | w->exp = std::move (exp); |
3a5c3e22 PA |
11044 | w->exp_valid_block = exp_valid_block; |
11045 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11046 | if (just_location) |
11047 | { | |
11048 | struct type *t = value_type (val); | |
11049 | CORE_ADDR addr = value_as_address (val); | |
06a64a0b | 11050 | |
43cc5389 TT |
11051 | w->exp_string_reparse |
11052 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 11053 | |
3a5c3e22 | 11054 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 11055 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
11056 | } |
11057 | else | |
3a5c3e22 | 11058 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11059 | |
11060 | if (use_mask) | |
11061 | { | |
3a5c3e22 | 11062 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11063 | } |
11064 | else | |
11065 | { | |
3a5c3e22 | 11066 | w->val = val; |
bb9d5f81 PP |
11067 | w->val_bitpos = saved_bitpos; |
11068 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11069 | w->val_valid = 1; |
9c06b0b4 | 11070 | } |
77b06cd7 | 11071 | |
c906108c | 11072 | if (cond_start) |
c1fc2657 | 11073 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 11074 | else |
c1fc2657 | 11075 | w->cond_string = 0; |
c5aa993b | 11076 | |
441d7c93 | 11077 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 11078 | { |
441d7c93 | 11079 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 11080 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 11081 | } |
c906108c | 11082 | else |
f6bc2008 | 11083 | { |
3a5c3e22 PA |
11084 | w->watchpoint_frame = null_frame_id; |
11085 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11086 | } |
c906108c | 11087 | |
d983da9c | 11088 | if (scope_breakpoint != NULL) |
c906108c | 11089 | { |
d983da9c DJ |
11090 | /* The scope breakpoint is related to the watchpoint. We will |
11091 | need to act on them together. */ | |
c1fc2657 | 11092 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 11093 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 11094 | } |
d983da9c | 11095 | |
06a64a0b TT |
11096 | if (!just_location) |
11097 | value_free_to_mark (mark); | |
2d134ed3 | 11098 | |
b270e6f9 TT |
11099 | /* Finally update the new watchpoint. This creates the locations |
11100 | that should be inserted. */ | |
11101 | update_watchpoint (w.get (), 1); | |
a9634178 | 11102 | |
b270e6f9 | 11103 | install_breakpoint (internal, std::move (w), 1); |
bbc13ae3 | 11104 | do_cleanups (back_to); |
c906108c SS |
11105 | } |
11106 | ||
e09342b5 | 11107 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11108 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11109 | |
c906108c | 11110 | static int |
a9634178 | 11111 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11112 | { |
11113 | int found_memory_cnt = 0; | |
2e70b7b9 | 11114 | struct value *head = v; |
c906108c SS |
11115 | |
11116 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11117 | if (!can_use_hw_watchpoints) |
c906108c | 11118 | return 0; |
c5aa993b | 11119 | |
5c44784c JM |
11120 | /* Make sure that the value of the expression depends only upon |
11121 | memory contents, and values computed from them within GDB. If we | |
11122 | find any register references or function calls, we can't use a | |
11123 | hardware watchpoint. | |
11124 | ||
11125 | The idea here is that evaluating an expression generates a series | |
11126 | of values, one holding the value of every subexpression. (The | |
11127 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11128 | a*b+c.) GDB's values hold almost enough information to establish | |
11129 | the criteria given above --- they identify memory lvalues, | |
11130 | register lvalues, computed values, etcetera. So we can evaluate | |
11131 | the expression, and then scan the chain of values that leaves | |
11132 | behind to decide whether we can detect any possible change to the | |
11133 | expression's final value using only hardware watchpoints. | |
11134 | ||
11135 | However, I don't think that the values returned by inferior | |
11136 | function calls are special in any way. So this function may not | |
11137 | notice that an expression involving an inferior function call | |
11138 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11139 | for (; v; v = value_next (v)) |
c906108c | 11140 | { |
5c44784c | 11141 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11142 | { |
8464be76 DJ |
11143 | if (v != head && value_lazy (v)) |
11144 | /* A lazy memory lvalue in the chain is one that GDB never | |
11145 | needed to fetch; we either just used its address (e.g., | |
11146 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11147 | in `a,b'). This doesn't apply to HEAD; if that is | |
11148 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11149 | ; |
53a5351d | 11150 | else |
5c44784c JM |
11151 | { |
11152 | /* Ahh, memory we actually used! Check if we can cover | |
11153 | it with hardware watchpoints. */ | |
df407dfe | 11154 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11155 | |
11156 | /* We only watch structs and arrays if user asked for it | |
11157 | explicitly, never if they just happen to appear in a | |
11158 | middle of some value chain. */ | |
11159 | if (v == head | |
11160 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11161 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11162 | { | |
42ae5230 | 11163 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11164 | int len; |
11165 | int num_regs; | |
11166 | ||
a9634178 | 11167 | len = (target_exact_watchpoints |
e09342b5 TJB |
11168 | && is_scalar_type_recursive (vtype))? |
11169 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11170 | |
e09342b5 TJB |
11171 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11172 | if (!num_regs) | |
2e70b7b9 MS |
11173 | return 0; |
11174 | else | |
e09342b5 | 11175 | found_memory_cnt += num_regs; |
2e70b7b9 | 11176 | } |
5c44784c | 11177 | } |
c5aa993b | 11178 | } |
5086187c AC |
11179 | else if (VALUE_LVAL (v) != not_lval |
11180 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11181 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11182 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11183 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11184 | } |
11185 | ||
11186 | /* The expression itself looks suitable for using a hardware | |
11187 | watchpoint, but give the target machine a chance to reject it. */ | |
11188 | return found_memory_cnt; | |
11189 | } | |
11190 | ||
8b93c638 | 11191 | void |
84f4c1fe | 11192 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11193 | { |
84f4c1fe | 11194 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11195 | } |
11196 | ||
06a64a0b TT |
11197 | /* A helper function that looks for the "-location" argument and then |
11198 | calls watch_command_1. */ | |
11199 | ||
11200 | static void | |
11201 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11202 | { | |
11203 | int just_location = 0; | |
11204 | ||
11205 | if (arg | |
11206 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11207 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11208 | { | |
e9cafbcc | 11209 | arg = skip_spaces (arg); |
06a64a0b TT |
11210 | just_location = 1; |
11211 | } | |
11212 | ||
84f4c1fe | 11213 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11214 | } |
8926118c | 11215 | |
c5aa993b | 11216 | static void |
fba45db2 | 11217 | watch_command (char *arg, int from_tty) |
c906108c | 11218 | { |
06a64a0b | 11219 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11220 | } |
11221 | ||
8b93c638 | 11222 | void |
84f4c1fe | 11223 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11224 | { |
84f4c1fe | 11225 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11226 | } |
8926118c | 11227 | |
c5aa993b | 11228 | static void |
fba45db2 | 11229 | rwatch_command (char *arg, int from_tty) |
c906108c | 11230 | { |
06a64a0b | 11231 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11232 | } |
11233 | ||
8b93c638 | 11234 | void |
84f4c1fe | 11235 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11236 | { |
84f4c1fe | 11237 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11238 | } |
8926118c | 11239 | |
c5aa993b | 11240 | static void |
fba45db2 | 11241 | awatch_command (char *arg, int from_tty) |
c906108c | 11242 | { |
06a64a0b | 11243 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11244 | } |
c906108c | 11245 | \f |
c5aa993b | 11246 | |
cfc31633 PA |
11247 | /* Data for the FSM that manages the until(location)/advance commands |
11248 | in infcmd.c. Here because it uses the mechanisms of | |
11249 | breakpoints. */ | |
c906108c | 11250 | |
cfc31633 | 11251 | struct until_break_fsm |
bfec99b2 | 11252 | { |
cfc31633 PA |
11253 | /* The base class. */ |
11254 | struct thread_fsm thread_fsm; | |
11255 | ||
11256 | /* The thread that as current when the command was executed. */ | |
11257 | int thread; | |
11258 | ||
11259 | /* The breakpoint set at the destination location. */ | |
11260 | struct breakpoint *location_breakpoint; | |
11261 | ||
11262 | /* Breakpoint set at the return address in the caller frame. May be | |
11263 | NULL. */ | |
11264 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11265 | }; |
11266 | ||
8980e177 PA |
11267 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11268 | struct thread_info *thread); | |
11269 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11270 | struct thread_info *thread); | |
cfc31633 PA |
11271 | static enum async_reply_reason |
11272 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11273 | ||
11274 | /* until_break_fsm's vtable. */ | |
11275 | ||
11276 | static struct thread_fsm_ops until_break_fsm_ops = | |
11277 | { | |
11278 | NULL, /* dtor */ | |
11279 | until_break_fsm_clean_up, | |
11280 | until_break_fsm_should_stop, | |
11281 | NULL, /* return_value */ | |
11282 | until_break_fsm_async_reply_reason, | |
11283 | }; | |
11284 | ||
11285 | /* Allocate a new until_break_command_fsm. */ | |
11286 | ||
11287 | static struct until_break_fsm * | |
8980e177 | 11288 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11289 | struct breakpoint *location_breakpoint, |
11290 | struct breakpoint *caller_breakpoint) | |
11291 | { | |
11292 | struct until_break_fsm *sm; | |
11293 | ||
11294 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11295 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11296 | |
11297 | sm->thread = thread; | |
11298 | sm->location_breakpoint = location_breakpoint; | |
11299 | sm->caller_breakpoint = caller_breakpoint; | |
11300 | ||
11301 | return sm; | |
11302 | } | |
11303 | ||
11304 | /* Implementation of the 'should_stop' FSM method for the | |
11305 | until(location)/advance commands. */ | |
11306 | ||
11307 | static int | |
8980e177 PA |
11308 | until_break_fsm_should_stop (struct thread_fsm *self, |
11309 | struct thread_info *tp) | |
cfc31633 PA |
11310 | { |
11311 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11312 | |
11313 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11314 | sm->location_breakpoint) != NULL | |
11315 | || (sm->caller_breakpoint != NULL | |
11316 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11317 | sm->caller_breakpoint) != NULL)) | |
11318 | thread_fsm_set_finished (self); | |
11319 | ||
11320 | return 1; | |
11321 | } | |
11322 | ||
11323 | /* Implementation of the 'clean_up' FSM method for the | |
11324 | until(location)/advance commands. */ | |
11325 | ||
c2c6d25f | 11326 | static void |
8980e177 PA |
11327 | until_break_fsm_clean_up (struct thread_fsm *self, |
11328 | struct thread_info *thread) | |
43ff13b4 | 11329 | { |
cfc31633 | 11330 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11331 | |
cfc31633 PA |
11332 | /* Clean up our temporary breakpoints. */ |
11333 | if (sm->location_breakpoint != NULL) | |
11334 | { | |
11335 | delete_breakpoint (sm->location_breakpoint); | |
11336 | sm->location_breakpoint = NULL; | |
11337 | } | |
11338 | if (sm->caller_breakpoint != NULL) | |
11339 | { | |
11340 | delete_breakpoint (sm->caller_breakpoint); | |
11341 | sm->caller_breakpoint = NULL; | |
11342 | } | |
11343 | delete_longjmp_breakpoint (sm->thread); | |
11344 | } | |
11345 | ||
11346 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11347 | until(location)/advance commands. */ | |
11348 | ||
11349 | static enum async_reply_reason | |
11350 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11351 | { | |
11352 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11353 | } |
11354 | ||
c906108c | 11355 | void |
ae66c1fc | 11356 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c | 11357 | { |
8556afb4 PA |
11358 | struct frame_info *frame; |
11359 | struct gdbarch *frame_gdbarch; | |
11360 | struct frame_id stack_frame_id; | |
11361 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11362 | struct breakpoint *location_breakpoint; |
11363 | struct breakpoint *caller_breakpoint = NULL; | |
ffc2605c | 11364 | struct cleanup *old_chain; |
186c406b TT |
11365 | int thread; |
11366 | struct thread_info *tp; | |
cfc31633 | 11367 | struct until_break_fsm *sm; |
c906108c | 11368 | |
70509625 | 11369 | clear_proceed_status (0); |
c906108c SS |
11370 | |
11371 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11372 | this function. */ |
c5aa993b | 11373 | |
ffc2605c | 11374 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11375 | |
6c5b2ebe PA |
11376 | std::vector<symtab_and_line> sals |
11377 | = (last_displayed_sal_is_valid () | |
11378 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11379 | get_last_displayed_symtab (), | |
11380 | get_last_displayed_line ()) | |
11381 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
11382 | NULL, (struct symtab *) NULL, 0)); | |
c5aa993b | 11383 | |
6c5b2ebe | 11384 | if (sals.size () != 1) |
8a3fe4f8 | 11385 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11386 | |
6c5b2ebe | 11387 | symtab_and_line &sal = sals[0]; |
c5aa993b | 11388 | |
c906108c | 11389 | if (*arg) |
8a3fe4f8 | 11390 | error (_("Junk at end of arguments.")); |
c5aa993b | 11391 | |
c906108c | 11392 | resolve_sal_pc (&sal); |
c5aa993b | 11393 | |
186c406b | 11394 | tp = inferior_thread (); |
5d5658a1 | 11395 | thread = tp->global_num; |
186c406b | 11396 | |
883bc8d1 PA |
11397 | old_chain = make_cleanup (null_cleanup, NULL); |
11398 | ||
8556afb4 PA |
11399 | /* Note linespec handling above invalidates the frame chain. |
11400 | Installing a breakpoint also invalidates the frame chain (as it | |
11401 | may need to switch threads), so do any frame handling before | |
11402 | that. */ | |
11403 | ||
11404 | frame = get_selected_frame (NULL); | |
11405 | frame_gdbarch = get_frame_arch (frame); | |
11406 | stack_frame_id = get_stack_frame_id (frame); | |
11407 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11408 | |
ae66c1fc EZ |
11409 | /* Keep within the current frame, or in frames called by the current |
11410 | one. */ | |
edb3359d | 11411 | |
883bc8d1 | 11412 | if (frame_id_p (caller_frame_id)) |
c906108c | 11413 | { |
883bc8d1 | 11414 | struct symtab_and_line sal2; |
cfc31633 | 11415 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11416 | |
11417 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11418 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11419 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11420 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11421 | sal2, | |
11422 | caller_frame_id, | |
11423 | bp_until); | |
11424 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11425 | |
883bc8d1 | 11426 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11427 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11428 | } |
c5aa993b | 11429 | |
c70a6932 JK |
11430 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11431 | frame = NULL; | |
11432 | ||
883bc8d1 PA |
11433 | if (anywhere) |
11434 | /* If the user told us to continue until a specified location, | |
11435 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11436 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11437 | null_frame_id, bp_until); | |
883bc8d1 PA |
11438 | else |
11439 | /* Otherwise, specify the selected frame, because we want to stop | |
11440 | only at the very same frame. */ | |
cfc31633 PA |
11441 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11442 | stack_frame_id, bp_until); | |
11443 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11444 | |
8980e177 | 11445 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11446 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11447 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11448 | |
cfc31633 | 11449 | discard_cleanups (old_chain); |
f107f563 | 11450 | |
cfc31633 | 11451 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11452 | } |
ae66c1fc | 11453 | |
c906108c SS |
11454 | /* This function attempts to parse an optional "if <cond>" clause |
11455 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11456 | |
c906108c SS |
11457 | Else, it returns a pointer to the condition string. (It does not |
11458 | attempt to evaluate the string against a particular block.) And, | |
11459 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11460 | if clause in the arg string. */ |
53a5351d | 11461 | |
63160a43 PA |
11462 | const char * |
11463 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11464 | { |
63160a43 | 11465 | const char *cond_string; |
c5aa993b JM |
11466 | |
11467 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11468 | return NULL; |
c5aa993b | 11469 | |
4a64f543 | 11470 | /* Skip the "if" keyword. */ |
c906108c | 11471 | (*arg) += 2; |
c5aa993b | 11472 | |
c906108c | 11473 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11474 | condition string. */ |
f1735a53 | 11475 | *arg = skip_spaces (*arg); |
c906108c | 11476 | cond_string = *arg; |
c5aa993b | 11477 | |
4a64f543 MS |
11478 | /* Assume that the condition occupies the remainder of the arg |
11479 | string. */ | |
c906108c | 11480 | (*arg) += strlen (cond_string); |
c5aa993b | 11481 | |
c906108c SS |
11482 | return cond_string; |
11483 | } | |
c5aa993b | 11484 | |
c906108c SS |
11485 | /* Commands to deal with catching events, such as signals, exceptions, |
11486 | process start/exit, etc. */ | |
c5aa993b JM |
11487 | |
11488 | typedef enum | |
11489 | { | |
44feb3ce TT |
11490 | catch_fork_temporary, catch_vfork_temporary, |
11491 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11492 | } |
11493 | catch_fork_kind; | |
11494 | ||
c906108c | 11495 | static void |
63160a43 | 11496 | catch_fork_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11497 | struct cmd_list_element *command) |
c906108c | 11498 | { |
63160a43 | 11499 | const char *arg = arg_entry; |
a6d9a66e | 11500 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11501 | const char *cond_string = NULL; |
44feb3ce TT |
11502 | catch_fork_kind fork_kind; |
11503 | int tempflag; | |
11504 | ||
11505 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11506 | tempflag = (fork_kind == catch_fork_temporary | |
11507 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11508 | |
44feb3ce TT |
11509 | if (!arg) |
11510 | arg = ""; | |
f1735a53 | 11511 | arg = skip_spaces (arg); |
c5aa993b | 11512 | |
c906108c | 11513 | /* The allowed syntax is: |
c5aa993b JM |
11514 | catch [v]fork |
11515 | catch [v]fork if <cond> | |
11516 | ||
4a64f543 | 11517 | First, check if there's an if clause. */ |
c906108c | 11518 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11519 | |
c906108c | 11520 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11521 | error (_("Junk at end of arguments.")); |
c5aa993b | 11522 | |
c906108c | 11523 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11524 | and enable reporting of such events. */ |
c5aa993b JM |
11525 | switch (fork_kind) |
11526 | { | |
44feb3ce TT |
11527 | case catch_fork_temporary: |
11528 | case catch_fork_permanent: | |
a6d9a66e | 11529 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11530 | &catch_fork_breakpoint_ops); |
c906108c | 11531 | break; |
44feb3ce TT |
11532 | case catch_vfork_temporary: |
11533 | case catch_vfork_permanent: | |
a6d9a66e | 11534 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11535 | &catch_vfork_breakpoint_ops); |
c906108c | 11536 | break; |
c5aa993b | 11537 | default: |
8a3fe4f8 | 11538 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11539 | break; |
c5aa993b | 11540 | } |
c906108c SS |
11541 | } |
11542 | ||
11543 | static void | |
63160a43 | 11544 | catch_exec_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11545 | struct cmd_list_element *command) |
c906108c | 11546 | { |
63160a43 | 11547 | const char *arg = arg_entry; |
a6d9a66e | 11548 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11549 | int tempflag; |
63160a43 | 11550 | const char *cond_string = NULL; |
c906108c | 11551 | |
44feb3ce TT |
11552 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11553 | ||
11554 | if (!arg) | |
11555 | arg = ""; | |
f1735a53 | 11556 | arg = skip_spaces (arg); |
c906108c SS |
11557 | |
11558 | /* The allowed syntax is: | |
c5aa993b JM |
11559 | catch exec |
11560 | catch exec if <cond> | |
c906108c | 11561 | |
4a64f543 | 11562 | First, check if there's an if clause. */ |
c906108c SS |
11563 | cond_string = ep_parse_optional_if_clause (&arg); |
11564 | ||
11565 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11566 | error (_("Junk at end of arguments.")); |
c906108c | 11567 | |
b270e6f9 TT |
11568 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11569 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11570 | &catch_exec_breakpoint_ops); |
11571 | c->exec_pathname = NULL; | |
11572 | ||
b270e6f9 | 11573 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11574 | } |
c5aa993b | 11575 | |
9ac4176b | 11576 | void |
28010a5d PA |
11577 | init_ada_exception_breakpoint (struct breakpoint *b, |
11578 | struct gdbarch *gdbarch, | |
11579 | struct symtab_and_line sal, | |
11580 | char *addr_string, | |
c0a91b2b | 11581 | const struct breakpoint_ops *ops, |
28010a5d | 11582 | int tempflag, |
349774ef | 11583 | int enabled, |
28010a5d | 11584 | int from_tty) |
f7f9143b | 11585 | { |
f7f9143b JB |
11586 | if (from_tty) |
11587 | { | |
5af949e3 UW |
11588 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11589 | if (!loc_gdbarch) | |
11590 | loc_gdbarch = gdbarch; | |
11591 | ||
6c95b8df PA |
11592 | describe_other_breakpoints (loc_gdbarch, |
11593 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11594 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11595 | version for exception catchpoints, because two catchpoints | |
11596 | used for different exception names will use the same address. | |
11597 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11598 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11599 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11600 | the user what type of catchpoint it is. The above is good |
11601 | enough for now, though. */ | |
11602 | } | |
11603 | ||
28010a5d | 11604 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11605 | |
349774ef | 11606 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11607 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11608 | b->location = string_to_event_location (&addr_string, |
11609 | language_def (language_ada)); | |
f7f9143b | 11610 | b->language = language_ada; |
f7f9143b JB |
11611 | } |
11612 | ||
c906108c | 11613 | static void |
fba45db2 | 11614 | catch_command (char *arg, int from_tty) |
c906108c | 11615 | { |
44feb3ce | 11616 | error (_("Catch requires an event name.")); |
c906108c SS |
11617 | } |
11618 | \f | |
11619 | ||
11620 | static void | |
fba45db2 | 11621 | tcatch_command (char *arg, int from_tty) |
c906108c | 11622 | { |
44feb3ce | 11623 | error (_("Catch requires an event name.")); |
c906108c SS |
11624 | } |
11625 | ||
8a2c437b TT |
11626 | /* A qsort comparison function that sorts breakpoints in order. */ |
11627 | ||
11628 | static int | |
11629 | compare_breakpoints (const void *a, const void *b) | |
11630 | { | |
9a3c8263 | 11631 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11632 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11633 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11634 | uintptr_t ub = (uintptr_t) *bb; |
11635 | ||
11636 | if ((*ba)->number < (*bb)->number) | |
11637 | return -1; | |
11638 | else if ((*ba)->number > (*bb)->number) | |
11639 | return 1; | |
11640 | ||
11641 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11642 | the number 0. */ | |
11643 | if (ua < ub) | |
11644 | return -1; | |
94b0e70d | 11645 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11646 | } |
11647 | ||
80f8a6eb | 11648 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11649 | |
11650 | static void | |
fba45db2 | 11651 | clear_command (char *arg, int from_tty) |
c906108c | 11652 | { |
8a2c437b | 11653 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11654 | VEC(breakpoint_p) *found = 0; |
11655 | int ix; | |
c906108c | 11656 | int default_match; |
c906108c | 11657 | int i; |
8a2c437b | 11658 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c | 11659 | |
6c5b2ebe PA |
11660 | std::vector<symtab_and_line> decoded_sals; |
11661 | symtab_and_line last_sal; | |
11662 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11663 | if (arg) |
11664 | { | |
6c5b2ebe PA |
11665 | decoded_sals |
11666 | = decode_line_with_current_source (arg, | |
11667 | (DECODE_LINE_FUNFIRSTLINE | |
11668 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11669 | default_match = 0; |
6c5b2ebe | 11670 | sals = decoded_sals; |
c906108c SS |
11671 | } |
11672 | else | |
11673 | { | |
1bfeeb0f JL |
11674 | /* Set sal's line, symtab, pc, and pspace to the values |
11675 | corresponding to the last call to print_frame_info. If the | |
11676 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11677 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11678 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11679 | error (_("No source file specified.")); |
c906108c | 11680 | |
c906108c | 11681 | default_match = 1; |
6c5b2ebe | 11682 | sals = last_sal; |
c906108c SS |
11683 | } |
11684 | ||
4a64f543 MS |
11685 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11686 | seems, because all existing breakpoints typically have both | |
11687 | file/line and pc set. So, if clear is given file/line, we can | |
11688 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11689 | |
11690 | We only support clearing given the address explicitly | |
11691 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11692 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11693 | due to optimization, all in one block. |
4a64f543 MS |
11694 | |
11695 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11696 | PC corresponding to the same file:line, the breakpoint won't |
11697 | be cleared. We probably can still clear the breakpoint, but | |
11698 | since the other PC value is never presented to user, user | |
11699 | can only find it by guessing, and it does not seem important | |
11700 | to support that. */ | |
11701 | ||
4a64f543 MS |
11702 | /* For each line spec given, delete bps which correspond to it. Do |
11703 | it in two passes, solely to preserve the current behavior that | |
11704 | from_tty is forced true if we delete more than one | |
11705 | breakpoint. */ | |
c906108c | 11706 | |
80f8a6eb | 11707 | found = NULL; |
8a2c437b | 11708 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
6c5b2ebe | 11709 | for (const auto &sal : sals) |
c906108c | 11710 | { |
05cba821 JK |
11711 | const char *sal_fullname; |
11712 | ||
c906108c | 11713 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11714 | If line given (pc == 0), clear all bpts on specified line. |
11715 | If defaulting, clear all bpts on default line | |
c906108c | 11716 | or at default pc. |
c5aa993b JM |
11717 | |
11718 | defaulting sal.pc != 0 tests to do | |
11719 | ||
11720 | 0 1 pc | |
11721 | 1 1 pc _and_ line | |
11722 | 0 0 line | |
11723 | 1 0 <can't happen> */ | |
c906108c | 11724 | |
05cba821 JK |
11725 | sal_fullname = (sal.symtab == NULL |
11726 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11727 | |
4a64f543 | 11728 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11729 | ALL_BREAKPOINTS (b) |
c5aa993b | 11730 | { |
0d381245 | 11731 | int match = 0; |
4a64f543 | 11732 | /* Are we going to delete b? */ |
cc60f2e3 | 11733 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11734 | { |
11735 | struct bp_location *loc = b->loc; | |
11736 | for (; loc; loc = loc->next) | |
11737 | { | |
f8eba3c6 TT |
11738 | /* If the user specified file:line, don't allow a PC |
11739 | match. This matches historical gdb behavior. */ | |
11740 | int pc_match = (!sal.explicit_line | |
11741 | && sal.pc | |
11742 | && (loc->pspace == sal.pspace) | |
11743 | && (loc->address == sal.pc) | |
11744 | && (!section_is_overlay (loc->section) | |
11745 | || loc->section == sal.section)); | |
4aac40c8 TT |
11746 | int line_match = 0; |
11747 | ||
11748 | if ((default_match || sal.explicit_line) | |
2f202fde | 11749 | && loc->symtab != NULL |
05cba821 | 11750 | && sal_fullname != NULL |
4aac40c8 | 11751 | && sal.pspace == loc->pspace |
05cba821 JK |
11752 | && loc->line_number == sal.line |
11753 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11754 | sal_fullname) == 0) | |
11755 | line_match = 1; | |
4aac40c8 | 11756 | |
0d381245 VP |
11757 | if (pc_match || line_match) |
11758 | { | |
11759 | match = 1; | |
11760 | break; | |
11761 | } | |
11762 | } | |
11763 | } | |
11764 | ||
11765 | if (match) | |
d6e956e5 | 11766 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11767 | } |
80f8a6eb | 11768 | } |
8a2c437b | 11769 | |
80f8a6eb | 11770 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11771 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11772 | { |
11773 | if (arg) | |
8a3fe4f8 | 11774 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11775 | else |
8a3fe4f8 | 11776 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11777 | } |
c906108c | 11778 | |
8a2c437b TT |
11779 | /* Remove duplicates from the vec. */ |
11780 | qsort (VEC_address (breakpoint_p, found), | |
11781 | VEC_length (breakpoint_p, found), | |
11782 | sizeof (breakpoint_p), | |
11783 | compare_breakpoints); | |
11784 | prev = VEC_index (breakpoint_p, found, 0); | |
11785 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11786 | { | |
11787 | if (b == prev) | |
11788 | { | |
11789 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11790 | --ix; | |
11791 | } | |
11792 | } | |
11793 | ||
d6e956e5 | 11794 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11795 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11796 | if (from_tty) |
a3f17187 | 11797 | { |
d6e956e5 | 11798 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11799 | printf_unfiltered (_("Deleted breakpoint ")); |
11800 | else | |
11801 | printf_unfiltered (_("Deleted breakpoints ")); | |
11802 | } | |
d6e956e5 VP |
11803 | |
11804 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11805 | { |
c5aa993b | 11806 | if (from_tty) |
d6e956e5 VP |
11807 | printf_unfiltered ("%d ", b->number); |
11808 | delete_breakpoint (b); | |
c906108c | 11809 | } |
80f8a6eb MS |
11810 | if (from_tty) |
11811 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11812 | |
11813 | do_cleanups (cleanups); | |
c906108c SS |
11814 | } |
11815 | \f | |
11816 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11817 | all breakpoints that are marked for deletion, whether hit or not. | |
11818 | This is called after any breakpoint is hit, or after errors. */ | |
11819 | ||
11820 | void | |
fba45db2 | 11821 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11822 | { |
35df4500 | 11823 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11824 | |
11825 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11826 | if (bs->breakpoint_at |
11827 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11828 | && bs->stop) |
f431efe5 | 11829 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11830 | |
35df4500 | 11831 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11832 | { |
b5de0fa7 | 11833 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11834 | delete_breakpoint (b); |
11835 | } | |
c906108c SS |
11836 | } |
11837 | ||
4a64f543 MS |
11838 | /* A comparison function for bp_location AP and BP being interfaced to |
11839 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11840 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 11841 | secondarily by ordering first permanent elements and |
4a64f543 | 11842 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 11843 | qsort being an unstable algorithm. */ |
876fa593 JK |
11844 | |
11845 | static int | |
f5336ca5 | 11846 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 11847 | { |
9a3c8263 SM |
11848 | const struct bp_location *a = *(const struct bp_location **) ap; |
11849 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
11850 | |
11851 | if (a->address != b->address) | |
11852 | return (a->address > b->address) - (a->address < b->address); | |
11853 | ||
dea2aa5f LM |
11854 | /* Sort locations at the same address by their pspace number, keeping |
11855 | locations of the same inferior (in a multi-inferior environment) | |
11856 | grouped. */ | |
11857 | ||
11858 | if (a->pspace->num != b->pspace->num) | |
11859 | return ((a->pspace->num > b->pspace->num) | |
11860 | - (a->pspace->num < b->pspace->num)); | |
11861 | ||
876fa593 | 11862 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11863 | if (a->permanent != b->permanent) |
11864 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11865 | |
c56a97f9 JK |
11866 | /* Make the internal GDB representation stable across GDB runs |
11867 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11868 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11869 | |
11870 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11871 | return ((a->owner->number > b->owner->number) |
11872 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11873 | |
11874 | return (a > b) - (a < b); | |
11875 | } | |
11876 | ||
f5336ca5 PA |
11877 | /* Set bp_locations_placed_address_before_address_max and |
11878 | bp_locations_shadow_len_after_address_max according to the current | |
11879 | content of the bp_locations array. */ | |
f7545552 TT |
11880 | |
11881 | static void | |
f5336ca5 | 11882 | bp_locations_target_extensions_update (void) |
f7545552 | 11883 | { |
876fa593 JK |
11884 | struct bp_location *bl, **blp_tmp; |
11885 | ||
f5336ca5 PA |
11886 | bp_locations_placed_address_before_address_max = 0; |
11887 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11888 | |
11889 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11890 | { | |
11891 | CORE_ADDR start, end, addr; | |
11892 | ||
11893 | if (!bp_location_has_shadow (bl)) | |
11894 | continue; | |
11895 | ||
11896 | start = bl->target_info.placed_address; | |
11897 | end = start + bl->target_info.shadow_len; | |
11898 | ||
11899 | gdb_assert (bl->address >= start); | |
11900 | addr = bl->address - start; | |
f5336ca5 PA |
11901 | if (addr > bp_locations_placed_address_before_address_max) |
11902 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
11903 | |
11904 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
11905 | ||
11906 | gdb_assert (bl->address < end); | |
11907 | addr = end - bl->address; | |
f5336ca5 PA |
11908 | if (addr > bp_locations_shadow_len_after_address_max) |
11909 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 11910 | } |
f7545552 TT |
11911 | } |
11912 | ||
1e4d1764 YQ |
11913 | /* Download tracepoint locations if they haven't been. */ |
11914 | ||
11915 | static void | |
11916 | download_tracepoint_locations (void) | |
11917 | { | |
7ed2c994 | 11918 | struct breakpoint *b; |
dd2e65cc | 11919 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 11920 | |
5ed8105e | 11921 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 11922 | |
7ed2c994 | 11923 | ALL_TRACEPOINTS (b) |
1e4d1764 | 11924 | { |
7ed2c994 | 11925 | struct bp_location *bl; |
1e4d1764 | 11926 | struct tracepoint *t; |
f2a8bc8a | 11927 | int bp_location_downloaded = 0; |
1e4d1764 | 11928 | |
7ed2c994 | 11929 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
11930 | ? !may_insert_fast_tracepoints |
11931 | : !may_insert_tracepoints)) | |
11932 | continue; | |
11933 | ||
dd2e65cc YQ |
11934 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
11935 | { | |
11936 | if (target_can_download_tracepoint ()) | |
11937 | can_download_tracepoint = TRIBOOL_TRUE; | |
11938 | else | |
11939 | can_download_tracepoint = TRIBOOL_FALSE; | |
11940 | } | |
11941 | ||
11942 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
11943 | break; | |
11944 | ||
7ed2c994 YQ |
11945 | for (bl = b->loc; bl; bl = bl->next) |
11946 | { | |
11947 | /* In tracepoint, locations are _never_ duplicated, so | |
11948 | should_be_inserted is equivalent to | |
11949 | unduplicated_should_be_inserted. */ | |
11950 | if (!should_be_inserted (bl) || bl->inserted) | |
11951 | continue; | |
1e4d1764 | 11952 | |
7ed2c994 | 11953 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 11954 | |
7ed2c994 | 11955 | target_download_tracepoint (bl); |
1e4d1764 | 11956 | |
7ed2c994 | 11957 | bl->inserted = 1; |
f2a8bc8a | 11958 | bp_location_downloaded = 1; |
7ed2c994 YQ |
11959 | } |
11960 | t = (struct tracepoint *) b; | |
11961 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
11962 | if (bp_location_downloaded) |
11963 | observer_notify_breakpoint_modified (b); | |
1e4d1764 | 11964 | } |
1e4d1764 YQ |
11965 | } |
11966 | ||
934709f0 PW |
11967 | /* Swap the insertion/duplication state between two locations. */ |
11968 | ||
11969 | static void | |
11970 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
11971 | { | |
11972 | const int left_inserted = left->inserted; | |
11973 | const int left_duplicate = left->duplicate; | |
b775012e | 11974 | const int left_needs_update = left->needs_update; |
934709f0 PW |
11975 | const struct bp_target_info left_target_info = left->target_info; |
11976 | ||
1e4d1764 YQ |
11977 | /* Locations of tracepoints can never be duplicated. */ |
11978 | if (is_tracepoint (left->owner)) | |
11979 | gdb_assert (!left->duplicate); | |
11980 | if (is_tracepoint (right->owner)) | |
11981 | gdb_assert (!right->duplicate); | |
11982 | ||
934709f0 PW |
11983 | left->inserted = right->inserted; |
11984 | left->duplicate = right->duplicate; | |
b775012e | 11985 | left->needs_update = right->needs_update; |
934709f0 PW |
11986 | left->target_info = right->target_info; |
11987 | right->inserted = left_inserted; | |
11988 | right->duplicate = left_duplicate; | |
b775012e | 11989 | right->needs_update = left_needs_update; |
934709f0 PW |
11990 | right->target_info = left_target_info; |
11991 | } | |
11992 | ||
b775012e LM |
11993 | /* Force the re-insertion of the locations at ADDRESS. This is called |
11994 | once a new/deleted/modified duplicate location is found and we are evaluating | |
11995 | conditions on the target's side. Such conditions need to be updated on | |
11996 | the target. */ | |
11997 | ||
11998 | static void | |
11999 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12000 | { | |
12001 | struct bp_location **locp = NULL, **loc2p; | |
12002 | struct bp_location *loc; | |
12003 | CORE_ADDR address = 0; | |
12004 | int pspace_num; | |
12005 | ||
12006 | address = bl->address; | |
12007 | pspace_num = bl->pspace->num; | |
12008 | ||
12009 | /* This is only meaningful if the target is | |
12010 | evaluating conditions and if the user has | |
12011 | opted for condition evaluation on the target's | |
12012 | side. */ | |
12013 | if (gdb_evaluates_breakpoint_condition_p () | |
12014 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12015 | return; | |
12016 | ||
12017 | /* Flag all breakpoint locations with this address and | |
12018 | the same program space as the location | |
12019 | as "its condition has changed". We need to | |
12020 | update the conditions on the target's side. */ | |
12021 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12022 | { | |
12023 | loc = *loc2p; | |
12024 | ||
12025 | if (!is_breakpoint (loc->owner) | |
12026 | || pspace_num != loc->pspace->num) | |
12027 | continue; | |
12028 | ||
12029 | /* Flag the location appropriately. We use a different state to | |
12030 | let everyone know that we already updated the set of locations | |
12031 | with addr bl->address and program space bl->pspace. This is so | |
12032 | we don't have to keep calling these functions just to mark locations | |
12033 | that have already been marked. */ | |
12034 | loc->condition_changed = condition_updated; | |
12035 | ||
12036 | /* Free the agent expression bytecode as well. We will compute | |
12037 | it later on. */ | |
833177a4 | 12038 | loc->cond_bytecode.reset (); |
b775012e LM |
12039 | } |
12040 | } | |
44702360 PA |
12041 | /* Called whether new breakpoints are created, or existing breakpoints |
12042 | deleted, to update the global location list and recompute which | |
12043 | locations are duplicate of which. | |
b775012e | 12044 | |
04086b45 PA |
12045 | The INSERT_MODE flag determines whether locations may not, may, or |
12046 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12047 | info. */ | |
b60e7edf | 12048 | |
0d381245 | 12049 | static void |
44702360 | 12050 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12051 | { |
74960c60 | 12052 | struct breakpoint *b; |
876fa593 | 12053 | struct bp_location **locp, *loc; |
f7545552 | 12054 | struct cleanup *cleanups; |
b775012e LM |
12055 | /* Last breakpoint location address that was marked for update. */ |
12056 | CORE_ADDR last_addr = 0; | |
12057 | /* Last breakpoint location program space that was marked for update. */ | |
12058 | int last_pspace_num = -1; | |
f7545552 | 12059 | |
2d134ed3 PA |
12060 | /* Used in the duplicates detection below. When iterating over all |
12061 | bp_locations, points to the first bp_location of a given address. | |
12062 | Breakpoints and watchpoints of different types are never | |
12063 | duplicates of each other. Keep one pointer for each type of | |
12064 | breakpoint/watchpoint, so we only need to loop over all locations | |
12065 | once. */ | |
12066 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12067 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12068 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12069 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12070 | |
f5336ca5 PA |
12071 | /* Saved former bp_locations array which we compare against the newly |
12072 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
12073 | struct bp_location **old_locations, **old_locp; | |
12074 | unsigned old_locations_count; | |
876fa593 | 12075 | |
f5336ca5 PA |
12076 | old_locations = bp_locations; |
12077 | old_locations_count = bp_locations_count; | |
12078 | bp_locations = NULL; | |
12079 | bp_locations_count = 0; | |
12080 | cleanups = make_cleanup (xfree, old_locations); | |
0d381245 | 12081 | |
74960c60 | 12082 | ALL_BREAKPOINTS (b) |
876fa593 | 12083 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 12084 | bp_locations_count++; |
876fa593 | 12085 | |
f5336ca5 PA |
12086 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
12087 | locp = bp_locations; | |
876fa593 JK |
12088 | ALL_BREAKPOINTS (b) |
12089 | for (loc = b->loc; loc; loc = loc->next) | |
12090 | *locp++ = loc; | |
f5336ca5 PA |
12091 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
12092 | bp_locations_compare); | |
876fa593 | 12093 | |
f5336ca5 | 12094 | bp_locations_target_extensions_update (); |
74960c60 | 12095 | |
4a64f543 MS |
12096 | /* Identify bp_location instances that are no longer present in the |
12097 | new list, and therefore should be freed. Note that it's not | |
12098 | necessary that those locations should be removed from inferior -- | |
12099 | if there's another location at the same address (previously | |
12100 | marked as duplicate), we don't need to remove/insert the | |
12101 | location. | |
876fa593 | 12102 | |
4a64f543 MS |
12103 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12104 | and former bp_location array state respectively. */ | |
876fa593 | 12105 | |
f5336ca5 PA |
12106 | locp = bp_locations; |
12107 | for (old_locp = old_locations; | |
12108 | old_locp < old_locations + old_locations_count; | |
876fa593 | 12109 | old_locp++) |
74960c60 | 12110 | { |
876fa593 | 12111 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12112 | struct bp_location **loc2p; |
876fa593 | 12113 | |
e5dd4106 | 12114 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12115 | not, we have to free it. */ |
c7d46a38 | 12116 | int found_object = 0; |
20874c92 VP |
12117 | /* Tells if the location should remain inserted in the target. */ |
12118 | int keep_in_target = 0; | |
12119 | int removed = 0; | |
876fa593 | 12120 | |
4a64f543 MS |
12121 | /* Skip LOCP entries which will definitely never be needed. |
12122 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 12123 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 12124 | && (*locp)->address < old_loc->address) |
876fa593 | 12125 | locp++; |
c7d46a38 PA |
12126 | |
12127 | for (loc2p = locp; | |
f5336ca5 | 12128 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
12129 | && (*loc2p)->address == old_loc->address); |
12130 | loc2p++) | |
12131 | { | |
b775012e LM |
12132 | /* Check if this is a new/duplicated location or a duplicated |
12133 | location that had its condition modified. If so, we want to send | |
12134 | its condition to the target if evaluation of conditions is taking | |
12135 | place there. */ | |
12136 | if ((*loc2p)->condition_changed == condition_modified | |
12137 | && (last_addr != old_loc->address | |
12138 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12139 | { |
b775012e LM |
12140 | force_breakpoint_reinsertion (*loc2p); |
12141 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12142 | } |
b775012e LM |
12143 | |
12144 | if (*loc2p == old_loc) | |
12145 | found_object = 1; | |
c7d46a38 | 12146 | } |
74960c60 | 12147 | |
b775012e LM |
12148 | /* We have already handled this address, update it so that we don't |
12149 | have to go through updates again. */ | |
12150 | last_addr = old_loc->address; | |
12151 | ||
12152 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12153 | if (!found_object) | |
12154 | force_breakpoint_reinsertion (old_loc); | |
12155 | ||
4a64f543 MS |
12156 | /* If this location is no longer present, and inserted, look if |
12157 | there's maybe a new location at the same address. If so, | |
12158 | mark that one inserted, and don't remove this one. This is | |
12159 | needed so that we don't have a time window where a breakpoint | |
12160 | at certain location is not inserted. */ | |
74960c60 | 12161 | |
876fa593 | 12162 | if (old_loc->inserted) |
0d381245 | 12163 | { |
4a64f543 MS |
12164 | /* If the location is inserted now, we might have to remove |
12165 | it. */ | |
74960c60 | 12166 | |
876fa593 | 12167 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12168 | { |
4a64f543 MS |
12169 | /* The location is still present in the location list, |
12170 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12171 | keep_in_target = 1; |
74960c60 VP |
12172 | } |
12173 | else | |
12174 | { | |
b775012e LM |
12175 | /* This location still exists, but it won't be kept in the |
12176 | target since it may have been disabled. We proceed to | |
12177 | remove its target-side condition. */ | |
12178 | ||
4a64f543 MS |
12179 | /* The location is either no longer present, or got |
12180 | disabled. See if there's another location at the | |
12181 | same address, in which case we don't need to remove | |
12182 | this one from the target. */ | |
876fa593 | 12183 | |
2bdf28a0 | 12184 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12185 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12186 | { | |
876fa593 | 12187 | for (loc2p = locp; |
f5336ca5 | 12188 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12189 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12190 | loc2p++) |
12191 | { | |
12192 | struct bp_location *loc2 = *loc2p; | |
12193 | ||
2d134ed3 | 12194 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12195 | { |
85d721b8 PA |
12196 | /* Read watchpoint locations are switched to |
12197 | access watchpoints, if the former are not | |
12198 | supported, but the latter are. */ | |
12199 | if (is_hardware_watchpoint (old_loc->owner)) | |
12200 | { | |
12201 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12202 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12203 | } | |
12204 | ||
934709f0 PW |
12205 | /* loc2 is a duplicated location. We need to check |
12206 | if it should be inserted in case it will be | |
12207 | unduplicated. */ | |
12208 | if (loc2 != old_loc | |
12209 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12210 | { |
934709f0 | 12211 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12212 | keep_in_target = 1; |
12213 | break; | |
12214 | } | |
876fa593 JK |
12215 | } |
12216 | } | |
12217 | } | |
74960c60 VP |
12218 | } |
12219 | ||
20874c92 VP |
12220 | if (!keep_in_target) |
12221 | { | |
834c0d03 | 12222 | if (remove_breakpoint (old_loc)) |
20874c92 | 12223 | { |
4a64f543 MS |
12224 | /* This is just about all we can do. We could keep |
12225 | this location on the global list, and try to | |
12226 | remove it next time, but there's no particular | |
12227 | reason why we will succeed next time. | |
20874c92 | 12228 | |
4a64f543 MS |
12229 | Note that at this point, old_loc->owner is still |
12230 | valid, as delete_breakpoint frees the breakpoint | |
12231 | only after calling us. */ | |
3e43a32a MS |
12232 | printf_filtered (_("warning: Error removing " |
12233 | "breakpoint %d\n"), | |
876fa593 | 12234 | old_loc->owner->number); |
20874c92 VP |
12235 | } |
12236 | removed = 1; | |
12237 | } | |
0d381245 | 12238 | } |
74960c60 VP |
12239 | |
12240 | if (!found_object) | |
1c5cfe86 | 12241 | { |
fbea99ea | 12242 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12243 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12244 | { |
db82e815 PA |
12245 | /* This location was removed from the target. In |
12246 | non-stop mode, a race condition is possible where | |
12247 | we've removed a breakpoint, but stop events for that | |
12248 | breakpoint are already queued and will arrive later. | |
12249 | We apply an heuristic to be able to distinguish such | |
12250 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12251 | breakpoint location for a bit, and will retire it | |
12252 | after we see some number of events. The theory here | |
12253 | is that reporting of events should, "on the average", | |
12254 | be fair, so after a while we'll see events from all | |
12255 | threads that have anything of interest, and no longer | |
12256 | need to keep this breakpoint location around. We | |
12257 | don't hold locations forever so to reduce chances of | |
12258 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12259 | SIGTRAP. | |
12260 | ||
12261 | The heuristic failing can be disastrous on | |
12262 | decr_pc_after_break targets. | |
12263 | ||
12264 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12265 | if we fail to recognize a late breakpoint SIGTRAP, | |
12266 | because events_till_retirement has reached 0 too | |
12267 | soon, we'll fail to do the PC adjustment, and report | |
12268 | a random SIGTRAP to the user. When the user resumes | |
12269 | the inferior, it will most likely immediately crash | |
2dec564e | 12270 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12271 | corrupted, because of being resumed e.g., in the |
12272 | middle of a multi-byte instruction, or skipped a | |
12273 | one-byte instruction. This was actually seen happen | |
12274 | on native x86-linux, and should be less rare on | |
12275 | targets that do not support new thread events, like | |
12276 | remote, due to the heuristic depending on | |
12277 | thread_count. | |
12278 | ||
12279 | Mistaking a random SIGTRAP for a breakpoint trap | |
12280 | causes similar symptoms (PC adjustment applied when | |
12281 | it shouldn't), but then again, playing with SIGTRAPs | |
12282 | behind the debugger's back is asking for trouble. | |
12283 | ||
12284 | Since hardware watchpoint traps are always | |
12285 | distinguishable from other traps, so we don't need to | |
12286 | apply keep hardware watchpoint moribund locations | |
12287 | around. We simply always ignore hardware watchpoint | |
12288 | traps we can no longer explain. */ | |
12289 | ||
876fa593 JK |
12290 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12291 | old_loc->owner = NULL; | |
20874c92 | 12292 | |
876fa593 | 12293 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12294 | } |
12295 | else | |
f431efe5 PA |
12296 | { |
12297 | old_loc->owner = NULL; | |
12298 | decref_bp_location (&old_loc); | |
12299 | } | |
20874c92 | 12300 | } |
74960c60 | 12301 | } |
1c5cfe86 | 12302 | |
348d480f PA |
12303 | /* Rescan breakpoints at the same address and section, marking the |
12304 | first one as "first" and any others as "duplicates". This is so | |
12305 | that the bpt instruction is only inserted once. If we have a | |
12306 | permanent breakpoint at the same place as BPT, make that one the | |
12307 | official one, and the rest as duplicates. Permanent breakpoints | |
12308 | are sorted first for the same address. | |
12309 | ||
12310 | Do the same for hardware watchpoints, but also considering the | |
12311 | watchpoint's type (regular/access/read) and length. */ | |
12312 | ||
12313 | bp_loc_first = NULL; | |
12314 | wp_loc_first = NULL; | |
12315 | awp_loc_first = NULL; | |
12316 | rwp_loc_first = NULL; | |
12317 | ALL_BP_LOCATIONS (loc, locp) | |
12318 | { | |
12319 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12320 | non-NULL. */ | |
348d480f | 12321 | struct bp_location **loc_first_p; |
d3fbdd86 | 12322 | b = loc->owner; |
348d480f | 12323 | |
6f380991 | 12324 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12325 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12326 | /* Don't detect duplicate for tracepoint locations because they are |
12327 | never duplicated. See the comments in field `duplicate' of | |
12328 | `struct bp_location'. */ | |
348d480f | 12329 | || is_tracepoint (b)) |
b775012e LM |
12330 | { |
12331 | /* Clear the condition modification flag. */ | |
12332 | loc->condition_changed = condition_unchanged; | |
12333 | continue; | |
12334 | } | |
348d480f | 12335 | |
348d480f PA |
12336 | if (b->type == bp_hardware_watchpoint) |
12337 | loc_first_p = &wp_loc_first; | |
12338 | else if (b->type == bp_read_watchpoint) | |
12339 | loc_first_p = &rwp_loc_first; | |
12340 | else if (b->type == bp_access_watchpoint) | |
12341 | loc_first_p = &awp_loc_first; | |
12342 | else | |
12343 | loc_first_p = &bp_loc_first; | |
12344 | ||
12345 | if (*loc_first_p == NULL | |
12346 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12347 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12348 | { | |
12349 | *loc_first_p = loc; | |
12350 | loc->duplicate = 0; | |
b775012e LM |
12351 | |
12352 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12353 | { | |
12354 | loc->needs_update = 1; | |
12355 | /* Clear the condition modification flag. */ | |
12356 | loc->condition_changed = condition_unchanged; | |
12357 | } | |
348d480f PA |
12358 | continue; |
12359 | } | |
12360 | ||
934709f0 PW |
12361 | |
12362 | /* This and the above ensure the invariant that the first location | |
12363 | is not duplicated, and is the inserted one. | |
12364 | All following are marked as duplicated, and are not inserted. */ | |
12365 | if (loc->inserted) | |
12366 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12367 | loc->duplicate = 1; |
12368 | ||
b775012e LM |
12369 | /* Clear the condition modification flag. */ |
12370 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12371 | } |
12372 | ||
a25a5a45 | 12373 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12374 | { |
04086b45 | 12375 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12376 | insert_breakpoint_locations (); |
12377 | else | |
12378 | { | |
44702360 PA |
12379 | /* Even though the caller told us to not insert new |
12380 | locations, we may still need to update conditions on the | |
12381 | target's side of breakpoints that were already inserted | |
12382 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12383 | only update conditions for locations that are marked |
12384 | "needs_update". */ | |
12385 | update_inserted_breakpoint_locations (); | |
12386 | } | |
12387 | } | |
348d480f | 12388 | |
04086b45 | 12389 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12390 | download_tracepoint_locations (); |
12391 | ||
348d480f PA |
12392 | do_cleanups (cleanups); |
12393 | } | |
12394 | ||
12395 | void | |
12396 | breakpoint_retire_moribund (void) | |
12397 | { | |
12398 | struct bp_location *loc; | |
12399 | int ix; | |
12400 | ||
12401 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12402 | if (--(loc->events_till_retirement) == 0) | |
12403 | { | |
12404 | decref_bp_location (&loc); | |
12405 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12406 | --ix; | |
12407 | } | |
12408 | } | |
12409 | ||
12410 | static void | |
44702360 | 12411 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12412 | { |
348d480f | 12413 | |
492d29ea PA |
12414 | TRY |
12415 | { | |
12416 | update_global_location_list (insert_mode); | |
12417 | } | |
12418 | CATCH (e, RETURN_MASK_ERROR) | |
12419 | { | |
12420 | } | |
12421 | END_CATCH | |
348d480f PA |
12422 | } |
12423 | ||
12424 | /* Clear BKP from a BPS. */ | |
12425 | ||
12426 | static void | |
12427 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12428 | { | |
12429 | bpstat bs; | |
12430 | ||
12431 | for (bs = bps; bs; bs = bs->next) | |
12432 | if (bs->breakpoint_at == bpt) | |
12433 | { | |
12434 | bs->breakpoint_at = NULL; | |
12435 | bs->old_val = NULL; | |
12436 | /* bs->commands will be freed later. */ | |
12437 | } | |
12438 | } | |
12439 | ||
12440 | /* Callback for iterate_over_threads. */ | |
12441 | static int | |
12442 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12443 | { | |
9a3c8263 | 12444 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12445 | |
12446 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12447 | return 0; | |
12448 | } | |
12449 | ||
12450 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12451 | callbacks. */ | |
12452 | ||
12453 | static void | |
12454 | say_where (struct breakpoint *b) | |
12455 | { | |
12456 | struct value_print_options opts; | |
12457 | ||
12458 | get_user_print_options (&opts); | |
12459 | ||
12460 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12461 | single string. */ | |
12462 | if (b->loc == NULL) | |
12463 | { | |
f00aae0f KS |
12464 | /* For pending locations, the output differs slightly based |
12465 | on b->extra_string. If this is non-NULL, it contains either | |
12466 | a condition or dprintf arguments. */ | |
12467 | if (b->extra_string == NULL) | |
12468 | { | |
12469 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12470 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12471 | } |
12472 | else if (b->type == bp_dprintf) | |
12473 | { | |
12474 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12475 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12476 | b->extra_string); |
12477 | } | |
12478 | else | |
12479 | { | |
12480 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12481 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12482 | b->extra_string); |
12483 | } | |
348d480f PA |
12484 | } |
12485 | else | |
12486 | { | |
2f202fde | 12487 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12488 | { |
12489 | printf_filtered (" at "); | |
12490 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12491 | gdb_stdout); | |
12492 | } | |
2f202fde | 12493 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12494 | { |
12495 | /* If there is a single location, we can print the location | |
12496 | more nicely. */ | |
12497 | if (b->loc->next == NULL) | |
12498 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12499 | symtab_to_filename_for_display (b->loc->symtab), |
12500 | b->loc->line_number); | |
f8eba3c6 TT |
12501 | else |
12502 | /* This is not ideal, but each location may have a | |
12503 | different file name, and this at least reflects the | |
12504 | real situation somewhat. */ | |
f00aae0f | 12505 | printf_filtered (": %s.", |
d28cd78a | 12506 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12507 | } |
348d480f PA |
12508 | |
12509 | if (b->loc->next) | |
12510 | { | |
12511 | struct bp_location *loc = b->loc; | |
12512 | int n = 0; | |
12513 | for (; loc; loc = loc->next) | |
12514 | ++n; | |
12515 | printf_filtered (" (%d locations)", n); | |
12516 | } | |
12517 | } | |
12518 | } | |
12519 | ||
348d480f PA |
12520 | /* Default bp_location_ops methods. */ |
12521 | ||
12522 | static void | |
12523 | bp_location_dtor (struct bp_location *self) | |
12524 | { | |
348d480f PA |
12525 | xfree (self->function_name); |
12526 | } | |
12527 | ||
12528 | static const struct bp_location_ops bp_location_ops = | |
12529 | { | |
12530 | bp_location_dtor | |
12531 | }; | |
12532 | ||
c1fc2657 | 12533 | /* Destructor for the breakpoint base class. */ |
348d480f | 12534 | |
c1fc2657 | 12535 | breakpoint::~breakpoint () |
348d480f | 12536 | { |
c1fc2657 SM |
12537 | xfree (this->cond_string); |
12538 | xfree (this->extra_string); | |
12539 | xfree (this->filter); | |
348d480f PA |
12540 | } |
12541 | ||
2060206e PA |
12542 | static struct bp_location * |
12543 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12544 | { |
5625a286 | 12545 | return new bp_location (&bp_location_ops, self); |
348d480f PA |
12546 | } |
12547 | ||
2060206e PA |
12548 | static void |
12549 | base_breakpoint_re_set (struct breakpoint *b) | |
12550 | { | |
12551 | /* Nothing to re-set. */ | |
12552 | } | |
12553 | ||
12554 | #define internal_error_pure_virtual_called() \ | |
12555 | gdb_assert_not_reached ("pure virtual function called") | |
12556 | ||
12557 | static int | |
12558 | base_breakpoint_insert_location (struct bp_location *bl) | |
12559 | { | |
12560 | internal_error_pure_virtual_called (); | |
12561 | } | |
12562 | ||
12563 | static int | |
73971819 PA |
12564 | base_breakpoint_remove_location (struct bp_location *bl, |
12565 | enum remove_bp_reason reason) | |
2060206e PA |
12566 | { |
12567 | internal_error_pure_virtual_called (); | |
12568 | } | |
12569 | ||
12570 | static int | |
12571 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12572 | struct address_space *aspace, | |
09ac7c10 TT |
12573 | CORE_ADDR bp_addr, |
12574 | const struct target_waitstatus *ws) | |
2060206e PA |
12575 | { |
12576 | internal_error_pure_virtual_called (); | |
12577 | } | |
12578 | ||
12579 | static void | |
12580 | base_breakpoint_check_status (bpstat bs) | |
12581 | { | |
12582 | /* Always stop. */ | |
12583 | } | |
12584 | ||
12585 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12586 | errors. */ | |
12587 | ||
12588 | static int | |
12589 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12590 | { | |
12591 | internal_error_pure_virtual_called (); | |
12592 | } | |
12593 | ||
12594 | /* A "resources_needed" breakpoint_ops method that just internal | |
12595 | errors. */ | |
12596 | ||
12597 | static int | |
12598 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12599 | { | |
12600 | internal_error_pure_virtual_called (); | |
12601 | } | |
12602 | ||
12603 | static enum print_stop_action | |
12604 | base_breakpoint_print_it (bpstat bs) | |
12605 | { | |
12606 | internal_error_pure_virtual_called (); | |
12607 | } | |
12608 | ||
12609 | static void | |
12610 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12611 | struct ui_out *uiout) | |
12612 | { | |
12613 | /* nothing */ | |
12614 | } | |
12615 | ||
12616 | static void | |
12617 | base_breakpoint_print_mention (struct breakpoint *b) | |
12618 | { | |
12619 | internal_error_pure_virtual_called (); | |
12620 | } | |
12621 | ||
12622 | static void | |
12623 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12624 | { | |
12625 | internal_error_pure_virtual_called (); | |
12626 | } | |
12627 | ||
983af33b | 12628 | static void |
f00aae0f KS |
12629 | base_breakpoint_create_sals_from_location |
12630 | (const struct event_location *location, | |
12631 | struct linespec_result *canonical, | |
12632 | enum bptype type_wanted) | |
983af33b SDJ |
12633 | { |
12634 | internal_error_pure_virtual_called (); | |
12635 | } | |
12636 | ||
12637 | static void | |
12638 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12639 | struct linespec_result *c, | |
e1e01040 PA |
12640 | gdb::unique_xmalloc_ptr<char> cond_string, |
12641 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12642 | enum bptype type_wanted, |
12643 | enum bpdisp disposition, | |
12644 | int thread, | |
12645 | int task, int ignore_count, | |
12646 | const struct breakpoint_ops *o, | |
12647 | int from_tty, int enabled, | |
44f238bb | 12648 | int internal, unsigned flags) |
983af33b SDJ |
12649 | { |
12650 | internal_error_pure_virtual_called (); | |
12651 | } | |
12652 | ||
6c5b2ebe | 12653 | static std::vector<symtab_and_line> |
f00aae0f KS |
12654 | base_breakpoint_decode_location (struct breakpoint *b, |
12655 | const struct event_location *location, | |
6c5b2ebe | 12656 | struct program_space *search_pspace) |
983af33b SDJ |
12657 | { |
12658 | internal_error_pure_virtual_called (); | |
12659 | } | |
12660 | ||
ab04a2af TT |
12661 | /* The default 'explains_signal' method. */ |
12662 | ||
47591c29 | 12663 | static int |
427cd150 | 12664 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12665 | { |
47591c29 | 12666 | return 1; |
ab04a2af TT |
12667 | } |
12668 | ||
9d6e6e84 HZ |
12669 | /* The default "after_condition_true" method. */ |
12670 | ||
12671 | static void | |
12672 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12673 | { | |
12674 | /* Nothing to do. */ | |
12675 | } | |
12676 | ||
ab04a2af | 12677 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12678 | { |
2060206e PA |
12679 | base_breakpoint_allocate_location, |
12680 | base_breakpoint_re_set, | |
12681 | base_breakpoint_insert_location, | |
12682 | base_breakpoint_remove_location, | |
12683 | base_breakpoint_breakpoint_hit, | |
12684 | base_breakpoint_check_status, | |
12685 | base_breakpoint_resources_needed, | |
12686 | base_breakpoint_works_in_software_mode, | |
12687 | base_breakpoint_print_it, | |
12688 | NULL, | |
12689 | base_breakpoint_print_one_detail, | |
12690 | base_breakpoint_print_mention, | |
983af33b | 12691 | base_breakpoint_print_recreate, |
5f700d83 | 12692 | base_breakpoint_create_sals_from_location, |
983af33b | 12693 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12694 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12695 | base_breakpoint_explains_signal, |
12696 | base_breakpoint_after_condition_true, | |
2060206e PA |
12697 | }; |
12698 | ||
12699 | /* Default breakpoint_ops methods. */ | |
12700 | ||
12701 | static void | |
348d480f PA |
12702 | bkpt_re_set (struct breakpoint *b) |
12703 | { | |
06edf0c0 | 12704 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12705 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12706 | { |
f00aae0f | 12707 | /* Anything without a location can't be re-set. */ |
348d480f | 12708 | delete_breakpoint (b); |
06edf0c0 | 12709 | return; |
348d480f | 12710 | } |
06edf0c0 PA |
12711 | |
12712 | breakpoint_re_set_default (b); | |
348d480f PA |
12713 | } |
12714 | ||
2060206e | 12715 | static int |
348d480f PA |
12716 | bkpt_insert_location (struct bp_location *bl) |
12717 | { | |
cd6c3b4f YQ |
12718 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12719 | ||
579c6ad9 | 12720 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12721 | bl->target_info.placed_address = addr; |
12722 | ||
348d480f | 12723 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12724 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12725 | else |
7c16b83e | 12726 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12727 | } |
12728 | ||
2060206e | 12729 | static int |
73971819 | 12730 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12731 | { |
12732 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12733 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12734 | else | |
73971819 | 12735 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12736 | } |
12737 | ||
2060206e | 12738 | static int |
348d480f | 12739 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12740 | struct address_space *aspace, CORE_ADDR bp_addr, |
12741 | const struct target_waitstatus *ws) | |
348d480f | 12742 | { |
09ac7c10 | 12743 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12744 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12745 | return 0; |
12746 | ||
348d480f PA |
12747 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12748 | aspace, bp_addr)) | |
12749 | return 0; | |
12750 | ||
12751 | if (overlay_debugging /* unmapped overlay section */ | |
12752 | && section_is_overlay (bl->section) | |
12753 | && !section_is_mapped (bl->section)) | |
12754 | return 0; | |
12755 | ||
12756 | return 1; | |
12757 | } | |
12758 | ||
cd1608cc PA |
12759 | static int |
12760 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
12761 | struct address_space *aspace, CORE_ADDR bp_addr, | |
12762 | const struct target_waitstatus *ws) | |
12763 | { | |
12764 | if (dprintf_style == dprintf_style_agent | |
12765 | && target_can_run_breakpoint_commands ()) | |
12766 | { | |
12767 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12768 | for this address it must be for a breakpoint that happens to | |
12769 | be set at the same address. */ | |
12770 | return 0; | |
12771 | } | |
12772 | ||
12773 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12774 | } | |
12775 | ||
2060206e | 12776 | static int |
348d480f PA |
12777 | bkpt_resources_needed (const struct bp_location *bl) |
12778 | { | |
12779 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12780 | ||
12781 | return 1; | |
12782 | } | |
12783 | ||
2060206e | 12784 | static enum print_stop_action |
348d480f PA |
12785 | bkpt_print_it (bpstat bs) |
12786 | { | |
348d480f PA |
12787 | struct breakpoint *b; |
12788 | const struct bp_location *bl; | |
001c8c33 | 12789 | int bp_temp; |
79a45e25 | 12790 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12791 | |
12792 | gdb_assert (bs->bp_location_at != NULL); | |
12793 | ||
12794 | bl = bs->bp_location_at; | |
12795 | b = bs->breakpoint_at; | |
12796 | ||
001c8c33 PA |
12797 | bp_temp = b->disposition == disp_del; |
12798 | if (bl->address != bl->requested_address) | |
12799 | breakpoint_adjustment_warning (bl->requested_address, | |
12800 | bl->address, | |
12801 | b->number, 1); | |
12802 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12803 | maybe_print_thread_hit_breakpoint (uiout); |
12804 | ||
001c8c33 | 12805 | if (bp_temp) |
112e8700 | 12806 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 12807 | else |
112e8700 SM |
12808 | uiout->text ("Breakpoint "); |
12809 | if (uiout->is_mi_like_p ()) | |
348d480f | 12810 | { |
112e8700 | 12811 | uiout->field_string ("reason", |
001c8c33 | 12812 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12813 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12814 | } |
112e8700 SM |
12815 | uiout->field_int ("bkptno", b->number); |
12816 | uiout->text (", "); | |
06edf0c0 | 12817 | |
001c8c33 | 12818 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12819 | } |
12820 | ||
2060206e | 12821 | static void |
06edf0c0 PA |
12822 | bkpt_print_mention (struct breakpoint *b) |
12823 | { | |
112e8700 | 12824 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12825 | return; |
12826 | ||
12827 | switch (b->type) | |
12828 | { | |
12829 | case bp_breakpoint: | |
12830 | case bp_gnu_ifunc_resolver: | |
12831 | if (b->disposition == disp_del) | |
12832 | printf_filtered (_("Temporary breakpoint")); | |
12833 | else | |
12834 | printf_filtered (_("Breakpoint")); | |
12835 | printf_filtered (_(" %d"), b->number); | |
12836 | if (b->type == bp_gnu_ifunc_resolver) | |
12837 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12838 | break; | |
12839 | case bp_hardware_breakpoint: | |
12840 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12841 | break; | |
e7e0cddf SS |
12842 | case bp_dprintf: |
12843 | printf_filtered (_("Dprintf %d"), b->number); | |
12844 | break; | |
06edf0c0 PA |
12845 | } |
12846 | ||
12847 | say_where (b); | |
12848 | } | |
12849 | ||
2060206e | 12850 | static void |
06edf0c0 PA |
12851 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12852 | { | |
12853 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12854 | fprintf_unfiltered (fp, "tbreak"); | |
12855 | else if (tp->type == bp_breakpoint) | |
12856 | fprintf_unfiltered (fp, "break"); | |
12857 | else if (tp->type == bp_hardware_breakpoint | |
12858 | && tp->disposition == disp_del) | |
12859 | fprintf_unfiltered (fp, "thbreak"); | |
12860 | else if (tp->type == bp_hardware_breakpoint) | |
12861 | fprintf_unfiltered (fp, "hbreak"); | |
12862 | else | |
12863 | internal_error (__FILE__, __LINE__, | |
12864 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12865 | ||
f00aae0f | 12866 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12867 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12868 | |
12869 | /* Print out extra_string if this breakpoint is pending. It might | |
12870 | contain, for example, conditions that were set by the user. */ | |
12871 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12872 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12873 | ||
dd11a36c | 12874 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12875 | } |
12876 | ||
983af33b | 12877 | static void |
f00aae0f KS |
12878 | bkpt_create_sals_from_location (const struct event_location *location, |
12879 | struct linespec_result *canonical, | |
12880 | enum bptype type_wanted) | |
983af33b | 12881 | { |
f00aae0f | 12882 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12883 | } |
12884 | ||
12885 | static void | |
12886 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12887 | struct linespec_result *canonical, | |
e1e01040 PA |
12888 | gdb::unique_xmalloc_ptr<char> cond_string, |
12889 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12890 | enum bptype type_wanted, |
12891 | enum bpdisp disposition, | |
12892 | int thread, | |
12893 | int task, int ignore_count, | |
12894 | const struct breakpoint_ops *ops, | |
12895 | int from_tty, int enabled, | |
44f238bb | 12896 | int internal, unsigned flags) |
983af33b | 12897 | { |
023fa29b | 12898 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
12899 | std::move (cond_string), |
12900 | std::move (extra_string), | |
e7e0cddf | 12901 | type_wanted, |
983af33b SDJ |
12902 | disposition, thread, task, |
12903 | ignore_count, ops, from_tty, | |
44f238bb | 12904 | enabled, internal, flags); |
983af33b SDJ |
12905 | } |
12906 | ||
6c5b2ebe | 12907 | static std::vector<symtab_and_line> |
f00aae0f KS |
12908 | bkpt_decode_location (struct breakpoint *b, |
12909 | const struct event_location *location, | |
6c5b2ebe | 12910 | struct program_space *search_pspace) |
983af33b | 12911 | { |
6c5b2ebe | 12912 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
12913 | } |
12914 | ||
06edf0c0 PA |
12915 | /* Virtual table for internal breakpoints. */ |
12916 | ||
12917 | static void | |
12918 | internal_bkpt_re_set (struct breakpoint *b) | |
12919 | { | |
12920 | switch (b->type) | |
12921 | { | |
12922 | /* Delete overlay event and longjmp master breakpoints; they | |
12923 | will be reset later by breakpoint_re_set. */ | |
12924 | case bp_overlay_event: | |
12925 | case bp_longjmp_master: | |
12926 | case bp_std_terminate_master: | |
12927 | case bp_exception_master: | |
12928 | delete_breakpoint (b); | |
12929 | break; | |
12930 | ||
12931 | /* This breakpoint is special, it's set up when the inferior | |
12932 | starts and we really don't want to touch it. */ | |
12933 | case bp_shlib_event: | |
12934 | ||
12935 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
12936 | it is set up, we do not want to touch it. */ | |
12937 | case bp_thread_event: | |
12938 | break; | |
12939 | } | |
12940 | } | |
12941 | ||
12942 | static void | |
12943 | internal_bkpt_check_status (bpstat bs) | |
12944 | { | |
a9b3a50f PA |
12945 | if (bs->breakpoint_at->type == bp_shlib_event) |
12946 | { | |
12947 | /* If requested, stop when the dynamic linker notifies GDB of | |
12948 | events. This allows the user to get control and place | |
12949 | breakpoints in initializer routines for dynamically loaded | |
12950 | objects (among other things). */ | |
12951 | bs->stop = stop_on_solib_events; | |
12952 | bs->print = stop_on_solib_events; | |
12953 | } | |
12954 | else | |
12955 | bs->stop = 0; | |
06edf0c0 PA |
12956 | } |
12957 | ||
12958 | static enum print_stop_action | |
12959 | internal_bkpt_print_it (bpstat bs) | |
12960 | { | |
06edf0c0 | 12961 | struct breakpoint *b; |
06edf0c0 | 12962 | |
06edf0c0 PA |
12963 | b = bs->breakpoint_at; |
12964 | ||
06edf0c0 PA |
12965 | switch (b->type) |
12966 | { | |
348d480f PA |
12967 | case bp_shlib_event: |
12968 | /* Did we stop because the user set the stop_on_solib_events | |
12969 | variable? (If so, we report this as a generic, "Stopped due | |
12970 | to shlib event" message.) */ | |
edcc5120 | 12971 | print_solib_event (0); |
348d480f PA |
12972 | break; |
12973 | ||
12974 | case bp_thread_event: | |
12975 | /* Not sure how we will get here. | |
12976 | GDB should not stop for these breakpoints. */ | |
12977 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12978 | break; |
12979 | ||
12980 | case bp_overlay_event: | |
12981 | /* By analogy with the thread event, GDB should not stop for these. */ | |
12982 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12983 | break; |
12984 | ||
12985 | case bp_longjmp_master: | |
12986 | /* These should never be enabled. */ | |
12987 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
12988 | break; |
12989 | ||
12990 | case bp_std_terminate_master: | |
12991 | /* These should never be enabled. */ | |
12992 | printf_filtered (_("std::terminate Master Breakpoint: " | |
12993 | "gdb should not stop!\n")); | |
348d480f PA |
12994 | break; |
12995 | ||
12996 | case bp_exception_master: | |
12997 | /* These should never be enabled. */ | |
12998 | printf_filtered (_("Exception Master Breakpoint: " | |
12999 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13000 | break; |
13001 | } | |
13002 | ||
001c8c33 | 13003 | return PRINT_NOTHING; |
06edf0c0 PA |
13004 | } |
13005 | ||
13006 | static void | |
13007 | internal_bkpt_print_mention (struct breakpoint *b) | |
13008 | { | |
13009 | /* Nothing to mention. These breakpoints are internal. */ | |
13010 | } | |
13011 | ||
06edf0c0 PA |
13012 | /* Virtual table for momentary breakpoints */ |
13013 | ||
13014 | static void | |
13015 | momentary_bkpt_re_set (struct breakpoint *b) | |
13016 | { | |
13017 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13018 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13019 | Otherwise these should have been blown away via the cleanup chain |
13020 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13021 | } | |
13022 | ||
13023 | static void | |
13024 | momentary_bkpt_check_status (bpstat bs) | |
13025 | { | |
13026 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13027 | } | |
13028 | ||
13029 | static enum print_stop_action | |
13030 | momentary_bkpt_print_it (bpstat bs) | |
13031 | { | |
001c8c33 | 13032 | return PRINT_UNKNOWN; |
348d480f PA |
13033 | } |
13034 | ||
06edf0c0 PA |
13035 | static void |
13036 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13037 | { |
06edf0c0 | 13038 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13039 | } |
13040 | ||
e2e4d78b JK |
13041 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13042 | ||
13043 | It gets cleared already on the removal of the first one of such placed | |
13044 | breakpoints. This is OK as they get all removed altogether. */ | |
13045 | ||
c1fc2657 | 13046 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 13047 | { |
c1fc2657 | 13048 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 13049 | |
c1fc2657 | 13050 | if (tp != NULL) |
e2e4d78b | 13051 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
13052 | } |
13053 | ||
55aa24fb SDJ |
13054 | /* Specific methods for probe breakpoints. */ |
13055 | ||
13056 | static int | |
13057 | bkpt_probe_insert_location (struct bp_location *bl) | |
13058 | { | |
13059 | int v = bkpt_insert_location (bl); | |
13060 | ||
13061 | if (v == 0) | |
13062 | { | |
13063 | /* The insertion was successful, now let's set the probe's semaphore | |
13064 | if needed. */ | |
0ea5cda8 SDJ |
13065 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13066 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13067 | bl->probe.objfile, | |
13068 | bl->gdbarch); | |
55aa24fb SDJ |
13069 | } |
13070 | ||
13071 | return v; | |
13072 | } | |
13073 | ||
13074 | static int | |
73971819 PA |
13075 | bkpt_probe_remove_location (struct bp_location *bl, |
13076 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13077 | { |
13078 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13079 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13080 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13081 | bl->probe.objfile, | |
13082 | bl->gdbarch); | |
55aa24fb | 13083 | |
73971819 | 13084 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13085 | } |
13086 | ||
13087 | static void | |
f00aae0f | 13088 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13089 | struct linespec_result *canonical, |
f00aae0f | 13090 | enum bptype type_wanted) |
55aa24fb SDJ |
13091 | { |
13092 | struct linespec_sals lsal; | |
13093 | ||
c2f4122d | 13094 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
13095 | lsal.canonical |
13096 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13097 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
13098 | } |
13099 | ||
6c5b2ebe | 13100 | static std::vector<symtab_and_line> |
f00aae0f KS |
13101 | bkpt_probe_decode_location (struct breakpoint *b, |
13102 | const struct event_location *location, | |
6c5b2ebe | 13103 | struct program_space *search_pspace) |
55aa24fb | 13104 | { |
6c5b2ebe PA |
13105 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
13106 | if (sals.empty ()) | |
55aa24fb | 13107 | error (_("probe not found")); |
6c5b2ebe | 13108 | return sals; |
55aa24fb SDJ |
13109 | } |
13110 | ||
348d480f | 13111 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13112 | |
348d480f PA |
13113 | static void |
13114 | tracepoint_re_set (struct breakpoint *b) | |
13115 | { | |
13116 | breakpoint_re_set_default (b); | |
13117 | } | |
876fa593 | 13118 | |
348d480f PA |
13119 | static int |
13120 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13121 | struct address_space *aspace, CORE_ADDR bp_addr, |
13122 | const struct target_waitstatus *ws) | |
348d480f PA |
13123 | { |
13124 | /* By definition, the inferior does not report stops at | |
13125 | tracepoints. */ | |
13126 | return 0; | |
74960c60 VP |
13127 | } |
13128 | ||
13129 | static void | |
348d480f PA |
13130 | tracepoint_print_one_detail (const struct breakpoint *self, |
13131 | struct ui_out *uiout) | |
74960c60 | 13132 | { |
d9b3f62e PA |
13133 | struct tracepoint *tp = (struct tracepoint *) self; |
13134 | if (tp->static_trace_marker_id) | |
348d480f PA |
13135 | { |
13136 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13137 | |
112e8700 SM |
13138 | uiout->text ("\tmarker id is "); |
13139 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 13140 | tp->static_trace_marker_id); |
112e8700 | 13141 | uiout->text ("\n"); |
348d480f | 13142 | } |
0d381245 VP |
13143 | } |
13144 | ||
a474d7c2 | 13145 | static void |
348d480f | 13146 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13147 | { |
112e8700 | 13148 | if (current_uiout->is_mi_like_p ()) |
348d480f | 13149 | return; |
cc59ec59 | 13150 | |
348d480f PA |
13151 | switch (b->type) |
13152 | { | |
13153 | case bp_tracepoint: | |
13154 | printf_filtered (_("Tracepoint")); | |
13155 | printf_filtered (_(" %d"), b->number); | |
13156 | break; | |
13157 | case bp_fast_tracepoint: | |
13158 | printf_filtered (_("Fast tracepoint")); | |
13159 | printf_filtered (_(" %d"), b->number); | |
13160 | break; | |
13161 | case bp_static_tracepoint: | |
13162 | printf_filtered (_("Static tracepoint")); | |
13163 | printf_filtered (_(" %d"), b->number); | |
13164 | break; | |
13165 | default: | |
13166 | internal_error (__FILE__, __LINE__, | |
13167 | _("unhandled tracepoint type %d"), (int) b->type); | |
13168 | } | |
13169 | ||
13170 | say_where (b); | |
a474d7c2 PA |
13171 | } |
13172 | ||
348d480f | 13173 | static void |
d9b3f62e | 13174 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13175 | { |
d9b3f62e PA |
13176 | struct tracepoint *tp = (struct tracepoint *) self; |
13177 | ||
13178 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13179 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13180 | else if (self->type == bp_static_tracepoint) |
348d480f | 13181 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13182 | else if (self->type == bp_tracepoint) |
348d480f PA |
13183 | fprintf_unfiltered (fp, "trace"); |
13184 | else | |
13185 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13186 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13187 | |
f00aae0f | 13188 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13189 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
13190 | print_recreate_thread (self, fp); |
13191 | ||
13192 | if (tp->pass_count) | |
13193 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13194 | } |
13195 | ||
983af33b | 13196 | static void |
f00aae0f KS |
13197 | tracepoint_create_sals_from_location (const struct event_location *location, |
13198 | struct linespec_result *canonical, | |
13199 | enum bptype type_wanted) | |
983af33b | 13200 | { |
f00aae0f | 13201 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13202 | } |
13203 | ||
13204 | static void | |
13205 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13206 | struct linespec_result *canonical, | |
e1e01040 PA |
13207 | gdb::unique_xmalloc_ptr<char> cond_string, |
13208 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13209 | enum bptype type_wanted, |
13210 | enum bpdisp disposition, | |
13211 | int thread, | |
13212 | int task, int ignore_count, | |
13213 | const struct breakpoint_ops *ops, | |
13214 | int from_tty, int enabled, | |
44f238bb | 13215 | int internal, unsigned flags) |
983af33b | 13216 | { |
023fa29b | 13217 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13218 | std::move (cond_string), |
13219 | std::move (extra_string), | |
e7e0cddf | 13220 | type_wanted, |
983af33b SDJ |
13221 | disposition, thread, task, |
13222 | ignore_count, ops, from_tty, | |
44f238bb | 13223 | enabled, internal, flags); |
983af33b SDJ |
13224 | } |
13225 | ||
6c5b2ebe | 13226 | static std::vector<symtab_and_line> |
f00aae0f KS |
13227 | tracepoint_decode_location (struct breakpoint *b, |
13228 | const struct event_location *location, | |
6c5b2ebe | 13229 | struct program_space *search_pspace) |
983af33b | 13230 | { |
6c5b2ebe | 13231 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13232 | } |
13233 | ||
2060206e | 13234 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13235 | |
55aa24fb SDJ |
13236 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13237 | static probe. */ | |
13238 | ||
13239 | static void | |
f00aae0f KS |
13240 | tracepoint_probe_create_sals_from_location |
13241 | (const struct event_location *location, | |
13242 | struct linespec_result *canonical, | |
13243 | enum bptype type_wanted) | |
55aa24fb SDJ |
13244 | { |
13245 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13246 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13247 | } |
13248 | ||
6c5b2ebe | 13249 | static std::vector<symtab_and_line> |
f00aae0f KS |
13250 | tracepoint_probe_decode_location (struct breakpoint *b, |
13251 | const struct event_location *location, | |
6c5b2ebe | 13252 | struct program_space *search_pspace) |
55aa24fb SDJ |
13253 | { |
13254 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 13255 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
13256 | } |
13257 | ||
13258 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13259 | ||
5c2b4418 HZ |
13260 | /* Dprintf breakpoint_ops methods. */ |
13261 | ||
13262 | static void | |
13263 | dprintf_re_set (struct breakpoint *b) | |
13264 | { | |
13265 | breakpoint_re_set_default (b); | |
13266 | ||
f00aae0f KS |
13267 | /* extra_string should never be non-NULL for dprintf. */ |
13268 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13269 | |
13270 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13271 | 2 - create a dprintf, which resolves fine. | |
13272 | 3 - disconnect from target 1 | |
13273 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13274 | ||
13275 | After steps #3/#4, you'll want the dprintf command list to | |
13276 | be updated, because target 1 and 2 may well return different | |
13277 | answers for target_can_run_breakpoint_commands(). | |
13278 | Given absence of finer grained resetting, we get to do | |
13279 | it all the time. */ | |
13280 | if (b->extra_string != NULL) | |
13281 | update_dprintf_command_list (b); | |
13282 | } | |
13283 | ||
2d9442cc HZ |
13284 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13285 | ||
13286 | static void | |
13287 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13288 | { | |
f00aae0f | 13289 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13290 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13291 | tp->extra_string); |
13292 | print_recreate_thread (tp, fp); | |
13293 | } | |
13294 | ||
9d6e6e84 HZ |
13295 | /* Implement the "after_condition_true" breakpoint_ops method for |
13296 | dprintf. | |
13297 | ||
13298 | dprintf's are implemented with regular commands in their command | |
13299 | list, but we run the commands here instead of before presenting the | |
13300 | stop to the user, as dprintf's don't actually cause a stop. This | |
13301 | also makes it so that the commands of multiple dprintfs at the same | |
13302 | address are all handled. */ | |
13303 | ||
13304 | static void | |
13305 | dprintf_after_condition_true (struct bpstats *bs) | |
13306 | { | |
04afa70c | 13307 | struct bpstats tmp_bs; |
9d6e6e84 HZ |
13308 | struct bpstats *tmp_bs_p = &tmp_bs; |
13309 | ||
13310 | /* dprintf's never cause a stop. This wasn't set in the | |
13311 | check_status hook instead because that would make the dprintf's | |
13312 | condition not be evaluated. */ | |
13313 | bs->stop = 0; | |
13314 | ||
13315 | /* Run the command list here. Take ownership of it instead of | |
13316 | copying. We never want these commands to run later in | |
13317 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13318 | be set at same address as this dprintf, or even if running the | |
13319 | commands here throws. */ | |
13320 | tmp_bs.commands = bs->commands; | |
13321 | bs->commands = NULL; | |
9d6e6e84 HZ |
13322 | |
13323 | bpstat_do_actions_1 (&tmp_bs_p); | |
13324 | ||
13325 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13326 | bpstat_do_actions_1 may return early without processing the whole | |
13327 | list. */ | |
9d6e6e84 HZ |
13328 | } |
13329 | ||
983af33b SDJ |
13330 | /* The breakpoint_ops structure to be used on static tracepoints with |
13331 | markers (`-m'). */ | |
13332 | ||
13333 | static void | |
f00aae0f | 13334 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13335 | struct linespec_result *canonical, |
f00aae0f | 13336 | enum bptype type_wanted) |
983af33b SDJ |
13337 | { |
13338 | struct linespec_sals lsal; | |
f00aae0f KS |
13339 | const char *arg_start, *arg; |
13340 | char *str; | |
13341 | struct cleanup *cleanup; | |
983af33b | 13342 | |
f00aae0f KS |
13343 | arg = arg_start = get_linespec_location (location); |
13344 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13345 | |
f00aae0f KS |
13346 | str = savestring (arg_start, arg - arg_start); |
13347 | cleanup = make_cleanup (xfree, str); | |
8e9e35b1 | 13348 | canonical->location = new_linespec_location (&str); |
f00aae0f | 13349 | do_cleanups (cleanup); |
983af33b | 13350 | |
8e9e35b1 TT |
13351 | lsal.canonical |
13352 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13353 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
13354 | } |
13355 | ||
13356 | static void | |
13357 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13358 | struct linespec_result *canonical, | |
e1e01040 PA |
13359 | gdb::unique_xmalloc_ptr<char> cond_string, |
13360 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13361 | enum bptype type_wanted, |
13362 | enum bpdisp disposition, | |
13363 | int thread, | |
13364 | int task, int ignore_count, | |
13365 | const struct breakpoint_ops *ops, | |
13366 | int from_tty, int enabled, | |
44f238bb | 13367 | int internal, unsigned flags) |
983af33b | 13368 | { |
6c5b2ebe | 13369 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
13370 | |
13371 | /* If the user is creating a static tracepoint by marker id | |
13372 | (strace -m MARKER_ID), then store the sals index, so that | |
13373 | breakpoint_re_set can try to match up which of the newly | |
13374 | found markers corresponds to this one, and, don't try to | |
13375 | expand multiple locations for each sal, given than SALS | |
13376 | already should contain all sals for MARKER_ID. */ | |
13377 | ||
6c5b2ebe | 13378 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 13379 | { |
6c5b2ebe PA |
13380 | event_location_up location |
13381 | = copy_event_location (canonical->location.get ()); | |
983af33b | 13382 | |
b270e6f9 | 13383 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 13384 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 13385 | std::move (location), NULL, |
e1e01040 PA |
13386 | std::move (cond_string), |
13387 | std::move (extra_string), | |
e7e0cddf | 13388 | type_wanted, disposition, |
983af33b | 13389 | thread, task, ignore_count, ops, |
44f238bb | 13390 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13391 | canonical->special_display); |
13392 | /* Given that its possible to have multiple markers with | |
13393 | the same string id, if the user is creating a static | |
13394 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13395 | store the sals index, so that breakpoint_re_set can | |
13396 | try to match up which of the newly found markers | |
13397 | corresponds to this one */ | |
13398 | tp->static_trace_marker_id_idx = i; | |
13399 | ||
b270e6f9 | 13400 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13401 | } |
13402 | } | |
13403 | ||
6c5b2ebe | 13404 | static std::vector<symtab_and_line> |
f00aae0f KS |
13405 | strace_marker_decode_location (struct breakpoint *b, |
13406 | const struct event_location *location, | |
6c5b2ebe | 13407 | struct program_space *search_pspace) |
983af33b SDJ |
13408 | { |
13409 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13410 | const char *s = get_linespec_location (location); |
983af33b | 13411 | |
6c5b2ebe PA |
13412 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13413 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13414 | { |
6c5b2ebe PA |
13415 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13416 | sals.resize (1); | |
13417 | return sals; | |
983af33b SDJ |
13418 | } |
13419 | else | |
13420 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13421 | } | |
13422 | ||
13423 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13424 | ||
13425 | static int | |
13426 | strace_marker_p (struct breakpoint *b) | |
13427 | { | |
13428 | return b->ops == &strace_marker_breakpoint_ops; | |
13429 | } | |
13430 | ||
53a5351d | 13431 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13432 | structures. */ |
c906108c SS |
13433 | |
13434 | void | |
fba45db2 | 13435 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13436 | { |
52f0bd74 | 13437 | struct breakpoint *b; |
c906108c | 13438 | |
8a3fe4f8 | 13439 | gdb_assert (bpt != NULL); |
c906108c | 13440 | |
4a64f543 MS |
13441 | /* Has this bp already been deleted? This can happen because |
13442 | multiple lists can hold pointers to bp's. bpstat lists are | |
13443 | especial culprits. | |
13444 | ||
13445 | One example of this happening is a watchpoint's scope bp. When | |
13446 | the scope bp triggers, we notice that the watchpoint is out of | |
13447 | scope, and delete it. We also delete its scope bp. But the | |
13448 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13449 | That bpstat is then checked for auto-deleting bp's, which are | |
13450 | deleted. | |
13451 | ||
13452 | A real solution to this problem might involve reference counts in | |
13453 | bp's, and/or giving them pointers back to their referencing | |
13454 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13455 | storage when no more references were extent. A cheaper bandaid | |
13456 | was chosen. */ | |
c906108c SS |
13457 | if (bpt->type == bp_none) |
13458 | return; | |
13459 | ||
4a64f543 MS |
13460 | /* At least avoid this stale reference until the reference counting |
13461 | of breakpoints gets resolved. */ | |
d0fb5eae | 13462 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13463 | { |
d0fb5eae | 13464 | struct breakpoint *related; |
3a5c3e22 | 13465 | struct watchpoint *w; |
d0fb5eae JK |
13466 | |
13467 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13468 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13469 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13470 | w = (struct watchpoint *) bpt; |
13471 | else | |
13472 | w = NULL; | |
13473 | if (w != NULL) | |
13474 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13475 | |
13476 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13477 | for (related = bpt; related->related_breakpoint != bpt; | |
13478 | related = related->related_breakpoint); | |
13479 | related->related_breakpoint = bpt->related_breakpoint; | |
13480 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13481 | } |
13482 | ||
a9634178 TJB |
13483 | /* watch_command_1 creates a watchpoint but only sets its number if |
13484 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13485 | a problem in that process, we'll be asked to delete the half-created | |
13486 | watchpoint. In that case, don't announce the deletion. */ | |
13487 | if (bpt->number) | |
13488 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13489 | |
c906108c SS |
13490 | if (breakpoint_chain == bpt) |
13491 | breakpoint_chain = bpt->next; | |
13492 | ||
c906108c SS |
13493 | ALL_BREAKPOINTS (b) |
13494 | if (b->next == bpt) | |
c5aa993b JM |
13495 | { |
13496 | b->next = bpt->next; | |
13497 | break; | |
13498 | } | |
c906108c | 13499 | |
f431efe5 PA |
13500 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13501 | been freed. */ | |
13502 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13503 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13504 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13505 | commands are associated with the bpstat; if we remove it here, | |
13506 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13507 | event-top.c won't do anything, and temporary breakpoints with | |
13508 | commands won't work. */ | |
13509 | ||
13510 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13511 | ||
4a64f543 MS |
13512 | /* Now that breakpoint is removed from breakpoint list, update the |
13513 | global location list. This will remove locations that used to | |
13514 | belong to this breakpoint. Do this before freeing the breakpoint | |
13515 | itself, since remove_breakpoint looks at location's owner. It | |
13516 | might be better design to have location completely | |
13517 | self-contained, but it's not the case now. */ | |
44702360 | 13518 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13519 | |
4a64f543 MS |
13520 | /* On the chance that someone will soon try again to delete this |
13521 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13522 | bpt->type = bp_none; |
4d01a485 | 13523 | delete bpt; |
c906108c SS |
13524 | } |
13525 | ||
4d6140d9 AC |
13526 | static void |
13527 | do_delete_breakpoint_cleanup (void *b) | |
13528 | { | |
9a3c8263 | 13529 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13530 | } |
13531 | ||
13532 | struct cleanup * | |
13533 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13534 | { | |
13535 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13536 | } | |
13537 | ||
51be5b68 PA |
13538 | /* Iterator function to call a user-provided callback function once |
13539 | for each of B and its related breakpoints. */ | |
13540 | ||
13541 | static void | |
13542 | iterate_over_related_breakpoints (struct breakpoint *b, | |
48649e1b | 13543 | gdb::function_view<void (breakpoint *)> function) |
51be5b68 PA |
13544 | { |
13545 | struct breakpoint *related; | |
13546 | ||
13547 | related = b; | |
13548 | do | |
13549 | { | |
13550 | struct breakpoint *next; | |
13551 | ||
13552 | /* FUNCTION may delete RELATED. */ | |
13553 | next = related->related_breakpoint; | |
13554 | ||
13555 | if (next == related) | |
13556 | { | |
13557 | /* RELATED is the last ring entry. */ | |
48649e1b | 13558 | function (related); |
51be5b68 PA |
13559 | |
13560 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13561 | B. There's nothing left to do anyway, so just break | |
13562 | out. */ | |
13563 | break; | |
13564 | } | |
13565 | else | |
48649e1b | 13566 | function (related); |
51be5b68 PA |
13567 | |
13568 | related = next; | |
13569 | } | |
13570 | while (related != b); | |
13571 | } | |
95a42b64 | 13572 | |
c906108c | 13573 | void |
fba45db2 | 13574 | delete_command (char *arg, int from_tty) |
c906108c | 13575 | { |
35df4500 | 13576 | struct breakpoint *b, *b_tmp; |
c906108c | 13577 | |
ea9365bb TT |
13578 | dont_repeat (); |
13579 | ||
c906108c SS |
13580 | if (arg == 0) |
13581 | { | |
13582 | int breaks_to_delete = 0; | |
13583 | ||
46c6471b PA |
13584 | /* Delete all breakpoints if no argument. Do not delete |
13585 | internal breakpoints, these have to be deleted with an | |
13586 | explicit breakpoint number argument. */ | |
c5aa993b | 13587 | ALL_BREAKPOINTS (b) |
46c6471b | 13588 | if (user_breakpoint_p (b)) |
973d738b DJ |
13589 | { |
13590 | breaks_to_delete = 1; | |
13591 | break; | |
13592 | } | |
c906108c SS |
13593 | |
13594 | /* Ask user only if there are some breakpoints to delete. */ | |
13595 | if (!from_tty | |
e2e0b3e5 | 13596 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13597 | { |
35df4500 | 13598 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13599 | if (user_breakpoint_p (b)) |
c5aa993b | 13600 | delete_breakpoint (b); |
c906108c SS |
13601 | } |
13602 | } | |
13603 | else | |
48649e1b TT |
13604 | map_breakpoint_numbers |
13605 | (arg, [&] (breakpoint *b) | |
13606 | { | |
13607 | iterate_over_related_breakpoints (b, delete_breakpoint); | |
13608 | }); | |
c906108c SS |
13609 | } |
13610 | ||
c2f4122d PA |
13611 | /* Return true if all locations of B bound to PSPACE are pending. If |
13612 | PSPACE is NULL, all locations of all program spaces are | |
13613 | considered. */ | |
13614 | ||
0d381245 | 13615 | static int |
c2f4122d | 13616 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13617 | { |
c2f4122d PA |
13618 | struct bp_location *loc; |
13619 | ||
13620 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13621 | if ((pspace == NULL | |
13622 | || loc->pspace == pspace) | |
13623 | && !loc->shlib_disabled | |
8645ff69 | 13624 | && !loc->pspace->executing_startup) |
0d381245 VP |
13625 | return 0; |
13626 | return 1; | |
fe3f5fa8 VP |
13627 | } |
13628 | ||
776592bf DE |
13629 | /* Subroutine of update_breakpoint_locations to simplify it. |
13630 | Return non-zero if multiple fns in list LOC have the same name. | |
13631 | Null names are ignored. */ | |
13632 | ||
13633 | static int | |
13634 | ambiguous_names_p (struct bp_location *loc) | |
13635 | { | |
13636 | struct bp_location *l; | |
13637 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13638 | (int (*) (const void *, |
13639 | const void *)) streq, | |
776592bf DE |
13640 | NULL, xcalloc, xfree); |
13641 | ||
13642 | for (l = loc; l != NULL; l = l->next) | |
13643 | { | |
13644 | const char **slot; | |
13645 | const char *name = l->function_name; | |
13646 | ||
13647 | /* Allow for some names to be NULL, ignore them. */ | |
13648 | if (name == NULL) | |
13649 | continue; | |
13650 | ||
13651 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13652 | INSERT); | |
4a64f543 MS |
13653 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13654 | returns NULL. */ | |
776592bf DE |
13655 | if (*slot != NULL) |
13656 | { | |
13657 | htab_delete (htab); | |
13658 | return 1; | |
13659 | } | |
13660 | *slot = name; | |
13661 | } | |
13662 | ||
13663 | htab_delete (htab); | |
13664 | return 0; | |
13665 | } | |
13666 | ||
0fb4aa4b PA |
13667 | /* When symbols change, it probably means the sources changed as well, |
13668 | and it might mean the static tracepoint markers are no longer at | |
13669 | the same address or line numbers they used to be at last we | |
13670 | checked. Losing your static tracepoints whenever you rebuild is | |
13671 | undesirable. This function tries to resync/rematch gdb static | |
13672 | tracepoints with the markers on the target, for static tracepoints | |
13673 | that have not been set by marker id. Static tracepoint that have | |
13674 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13675 | The heuristic is: | |
13676 | ||
13677 | 1) For a tracepoint set at a specific address, look for a marker at | |
13678 | the old PC. If one is found there, assume to be the same marker. | |
13679 | If the name / string id of the marker found is different from the | |
13680 | previous known name, assume that means the user renamed the marker | |
13681 | in the sources, and output a warning. | |
13682 | ||
13683 | 2) For a tracepoint set at a given line number, look for a marker | |
13684 | at the new address of the old line number. If one is found there, | |
13685 | assume to be the same marker. If the name / string id of the | |
13686 | marker found is different from the previous known name, assume that | |
13687 | means the user renamed the marker in the sources, and output a | |
13688 | warning. | |
13689 | ||
13690 | 3) If a marker is no longer found at the same address or line, it | |
13691 | may mean the marker no longer exists. But it may also just mean | |
13692 | the code changed a bit. Maybe the user added a few lines of code | |
13693 | that made the marker move up or down (in line number terms). Ask | |
13694 | the target for info about the marker with the string id as we knew | |
13695 | it. If found, update line number and address in the matching | |
13696 | static tracepoint. This will get confused if there's more than one | |
13697 | marker with the same ID (possible in UST, although unadvised | |
13698 | precisely because it confuses tools). */ | |
13699 | ||
13700 | static struct symtab_and_line | |
13701 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13702 | { | |
d9b3f62e | 13703 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13704 | struct static_tracepoint_marker marker; |
13705 | CORE_ADDR pc; | |
0fb4aa4b PA |
13706 | |
13707 | pc = sal.pc; | |
13708 | if (sal.line) | |
13709 | find_line_pc (sal.symtab, sal.line, &pc); | |
13710 | ||
13711 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13712 | { | |
d9b3f62e | 13713 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13714 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13715 | b->number, | |
d9b3f62e | 13716 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13717 | |
d9b3f62e PA |
13718 | xfree (tp->static_trace_marker_id); |
13719 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13720 | release_static_tracepoint_marker (&marker); |
13721 | ||
13722 | return sal; | |
13723 | } | |
13724 | ||
13725 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13726 | by string ID. */ | |
13727 | if (!sal.explicit_pc | |
13728 | && sal.line != 0 | |
13729 | && sal.symtab != NULL | |
d9b3f62e | 13730 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13731 | { |
13732 | VEC(static_tracepoint_marker_p) *markers; | |
13733 | ||
13734 | markers | |
d9b3f62e | 13735 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13736 | |
13737 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13738 | { | |
0fb4aa4b | 13739 | struct symbol *sym; |
80e1d417 | 13740 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13741 | struct ui_out *uiout = current_uiout; |
67994074 | 13742 | struct explicit_location explicit_loc; |
0fb4aa4b | 13743 | |
80e1d417 | 13744 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13745 | |
d9b3f62e | 13746 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13747 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13748 | |
13749 | warning (_("marker for static tracepoint %d (%s) not " | |
13750 | "found at previous line number"), | |
d9b3f62e | 13751 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13752 | |
51abb421 | 13753 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13754 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13755 | uiout->text ("Now in "); |
0fb4aa4b PA |
13756 | if (sym) |
13757 | { | |
112e8700 SM |
13758 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); |
13759 | uiout->text (" at "); | |
0fb4aa4b | 13760 | } |
112e8700 | 13761 | uiout->field_string ("file", |
05cba821 | 13762 | symtab_to_filename_for_display (sal2.symtab)); |
112e8700 | 13763 | uiout->text (":"); |
0fb4aa4b | 13764 | |
112e8700 | 13765 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13766 | { |
0b0865da | 13767 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13768 | |
112e8700 | 13769 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13770 | } |
13771 | ||
112e8700 SM |
13772 | uiout->field_int ("line", sal2.line); |
13773 | uiout->text ("\n"); | |
0fb4aa4b | 13774 | |
80e1d417 | 13775 | b->loc->line_number = sal2.line; |
2f202fde | 13776 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13777 | |
d28cd78a | 13778 | b->location.reset (NULL); |
67994074 KS |
13779 | initialize_explicit_location (&explicit_loc); |
13780 | explicit_loc.source_filename | |
00e52e53 | 13781 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13782 | explicit_loc.line_offset.offset = b->loc->line_number; |
13783 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13784 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13785 | |
13786 | /* Might be nice to check if function changed, and warn if | |
13787 | so. */ | |
13788 | ||
80e1d417 | 13789 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13790 | } |
13791 | } | |
13792 | return sal; | |
13793 | } | |
13794 | ||
8d3788bd VP |
13795 | /* Returns 1 iff locations A and B are sufficiently same that |
13796 | we don't need to report breakpoint as changed. */ | |
13797 | ||
13798 | static int | |
13799 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13800 | { | |
13801 | while (a && b) | |
13802 | { | |
13803 | if (a->address != b->address) | |
13804 | return 0; | |
13805 | ||
13806 | if (a->shlib_disabled != b->shlib_disabled) | |
13807 | return 0; | |
13808 | ||
13809 | if (a->enabled != b->enabled) | |
13810 | return 0; | |
13811 | ||
13812 | a = a->next; | |
13813 | b = b->next; | |
13814 | } | |
13815 | ||
13816 | if ((a == NULL) != (b == NULL)) | |
13817 | return 0; | |
13818 | ||
13819 | return 1; | |
13820 | } | |
13821 | ||
c2f4122d PA |
13822 | /* Split all locations of B that are bound to PSPACE out of B's |
13823 | location list to a separate list and return that list's head. If | |
13824 | PSPACE is NULL, hoist out all locations of B. */ | |
13825 | ||
13826 | static struct bp_location * | |
13827 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13828 | { | |
13829 | struct bp_location head; | |
13830 | struct bp_location *i = b->loc; | |
13831 | struct bp_location **i_link = &b->loc; | |
13832 | struct bp_location *hoisted = &head; | |
13833 | ||
13834 | if (pspace == NULL) | |
13835 | { | |
13836 | i = b->loc; | |
13837 | b->loc = NULL; | |
13838 | return i; | |
13839 | } | |
13840 | ||
13841 | head.next = NULL; | |
13842 | ||
13843 | while (i != NULL) | |
13844 | { | |
13845 | if (i->pspace == pspace) | |
13846 | { | |
13847 | *i_link = i->next; | |
13848 | i->next = NULL; | |
13849 | hoisted->next = i; | |
13850 | hoisted = i; | |
13851 | } | |
13852 | else | |
13853 | i_link = &i->next; | |
13854 | i = *i_link; | |
13855 | } | |
13856 | ||
13857 | return head.next; | |
13858 | } | |
13859 | ||
13860 | /* Create new breakpoint locations for B (a hardware or software | |
13861 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13862 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13863 | FILTER_PSPACE. Locations of other program spaces are left | |
13864 | untouched. */ | |
f1310107 | 13865 | |
0e30163f | 13866 | void |
0d381245 | 13867 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13868 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13869 | gdb::array_view<const symtab_and_line> sals, |
13870 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 VP |
13871 | { |
13872 | int i; | |
c2f4122d | 13873 | struct bp_location *existing_locations; |
0d381245 | 13874 | |
6c5b2ebe | 13875 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
13876 | { |
13877 | /* Ranged breakpoints have only one start location and one end | |
13878 | location. */ | |
13879 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
13880 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
13881 | "multiple locations found\n"), | |
13882 | b->number); | |
13883 | return; | |
13884 | } | |
f1310107 | 13885 | |
4a64f543 MS |
13886 | /* If there's no new locations, and all existing locations are |
13887 | pending, don't do anything. This optimizes the common case where | |
13888 | all locations are in the same shared library, that was unloaded. | |
13889 | We'd like to retain the location, so that when the library is | |
13890 | loaded again, we don't loose the enabled/disabled status of the | |
13891 | individual locations. */ | |
6c5b2ebe | 13892 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
13893 | return; |
13894 | ||
c2f4122d | 13895 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 13896 | |
6c5b2ebe | 13897 | for (const auto &sal : sals) |
fe3f5fa8 | 13898 | { |
f8eba3c6 TT |
13899 | struct bp_location *new_loc; |
13900 | ||
6c5b2ebe | 13901 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 13902 | |
6c5b2ebe | 13903 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 13904 | |
0d381245 VP |
13905 | /* Reparse conditions, they might contain references to the |
13906 | old symtab. */ | |
13907 | if (b->cond_string != NULL) | |
13908 | { | |
bbc13ae3 | 13909 | const char *s; |
fe3f5fa8 | 13910 | |
0d381245 | 13911 | s = b->cond_string; |
492d29ea | 13912 | TRY |
0d381245 | 13913 | { |
6c5b2ebe PA |
13914 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
13915 | block_for_pc (sal.pc), | |
0d381245 VP |
13916 | 0); |
13917 | } | |
492d29ea | 13918 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 13919 | { |
3e43a32a MS |
13920 | warning (_("failed to reevaluate condition " |
13921 | "for breakpoint %d: %s"), | |
0d381245 VP |
13922 | b->number, e.message); |
13923 | new_loc->enabled = 0; | |
13924 | } | |
492d29ea | 13925 | END_CATCH |
0d381245 | 13926 | } |
fe3f5fa8 | 13927 | |
6c5b2ebe | 13928 | if (!sals_end.empty ()) |
f1310107 | 13929 | { |
6c5b2ebe | 13930 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 13931 | |
6c5b2ebe | 13932 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 13933 | } |
0d381245 | 13934 | } |
fe3f5fa8 | 13935 | |
4a64f543 MS |
13936 | /* If possible, carry over 'disable' status from existing |
13937 | breakpoints. */ | |
0d381245 VP |
13938 | { |
13939 | struct bp_location *e = existing_locations; | |
776592bf DE |
13940 | /* If there are multiple breakpoints with the same function name, |
13941 | e.g. for inline functions, comparing function names won't work. | |
13942 | Instead compare pc addresses; this is just a heuristic as things | |
13943 | may have moved, but in practice it gives the correct answer | |
13944 | often enough until a better solution is found. */ | |
13945 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
13946 | ||
0d381245 VP |
13947 | for (; e; e = e->next) |
13948 | { | |
13949 | if (!e->enabled && e->function_name) | |
13950 | { | |
13951 | struct bp_location *l = b->loc; | |
776592bf DE |
13952 | if (have_ambiguous_names) |
13953 | { | |
13954 | for (; l; l = l->next) | |
f1310107 | 13955 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
13956 | { |
13957 | l->enabled = 0; | |
13958 | break; | |
13959 | } | |
13960 | } | |
13961 | else | |
13962 | { | |
13963 | for (; l; l = l->next) | |
13964 | if (l->function_name | |
13965 | && strcmp (e->function_name, l->function_name) == 0) | |
13966 | { | |
13967 | l->enabled = 0; | |
13968 | break; | |
13969 | } | |
13970 | } | |
0d381245 VP |
13971 | } |
13972 | } | |
13973 | } | |
fe3f5fa8 | 13974 | |
8d3788bd VP |
13975 | if (!locations_are_equal (existing_locations, b->loc)) |
13976 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
13977 | } |
13978 | ||
f00aae0f | 13979 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
13980 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
13981 | ||
6c5b2ebe | 13982 | static std::vector<symtab_and_line> |
f00aae0f | 13983 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 13984 | struct program_space *search_pspace, int *found) |
ef23e705 | 13985 | { |
492d29ea | 13986 | struct gdb_exception exception = exception_none; |
ef23e705 | 13987 | |
983af33b | 13988 | gdb_assert (b->ops != NULL); |
ef23e705 | 13989 | |
6c5b2ebe PA |
13990 | std::vector<symtab_and_line> sals; |
13991 | ||
492d29ea | 13992 | TRY |
ef23e705 | 13993 | { |
6c5b2ebe | 13994 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 13995 | } |
492d29ea | 13996 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
13997 | { |
13998 | int not_found_and_ok = 0; | |
492d29ea PA |
13999 | |
14000 | exception = e; | |
14001 | ||
ef23e705 TJB |
14002 | /* For pending breakpoints, it's expected that parsing will |
14003 | fail until the right shared library is loaded. User has | |
14004 | already told to create pending breakpoints and don't need | |
14005 | extra messages. If breakpoint is in bp_shlib_disabled | |
14006 | state, then user already saw the message about that | |
14007 | breakpoint being disabled, and don't want to see more | |
14008 | errors. */ | |
58438ac1 | 14009 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14010 | && (b->condition_not_parsed |
14011 | || (b->loc != NULL | |
14012 | && search_pspace != NULL | |
14013 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14014 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14015 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14016 | || b->enable_state == bp_disabled)) |
14017 | not_found_and_ok = 1; | |
14018 | ||
14019 | if (!not_found_and_ok) | |
14020 | { | |
14021 | /* We surely don't want to warn about the same breakpoint | |
14022 | 10 times. One solution, implemented here, is disable | |
14023 | the breakpoint on error. Another solution would be to | |
14024 | have separate 'warning emitted' flag. Since this | |
14025 | happens only when a binary has changed, I don't know | |
14026 | which approach is better. */ | |
14027 | b->enable_state = bp_disabled; | |
14028 | throw_exception (e); | |
14029 | } | |
14030 | } | |
492d29ea | 14031 | END_CATCH |
ef23e705 | 14032 | |
492d29ea | 14033 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14034 | { |
6c5b2ebe PA |
14035 | for (auto &sal : sals) |
14036 | resolve_sal_pc (&sal); | |
f00aae0f | 14037 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14038 | { |
ed1d1739 KS |
14039 | char *cond_string, *extra_string; |
14040 | int thread, task; | |
ef23e705 | 14041 | |
6c5b2ebe | 14042 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
14043 | &cond_string, &thread, &task, |
14044 | &extra_string); | |
f00aae0f | 14045 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14046 | if (cond_string) |
14047 | b->cond_string = cond_string; | |
14048 | b->thread = thread; | |
14049 | b->task = task; | |
e7e0cddf | 14050 | if (extra_string) |
f00aae0f KS |
14051 | { |
14052 | xfree (b->extra_string); | |
14053 | b->extra_string = extra_string; | |
14054 | } | |
ef23e705 TJB |
14055 | b->condition_not_parsed = 0; |
14056 | } | |
14057 | ||
983af33b | 14058 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 14059 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 14060 | |
58438ac1 TT |
14061 | *found = 1; |
14062 | } | |
14063 | else | |
14064 | *found = 0; | |
ef23e705 TJB |
14065 | |
14066 | return sals; | |
14067 | } | |
14068 | ||
348d480f PA |
14069 | /* The default re_set method, for typical hardware or software |
14070 | breakpoints. Reevaluate the breakpoint and recreate its | |
14071 | locations. */ | |
14072 | ||
14073 | static void | |
28010a5d | 14074 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 14075 | { |
c2f4122d | 14076 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 14077 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 14078 | |
6c5b2ebe PA |
14079 | int found; |
14080 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
14081 | filter_pspace, &found); | |
ef23e705 | 14082 | if (found) |
6c5b2ebe | 14083 | expanded = std::move (sals); |
ef23e705 | 14084 | |
f00aae0f | 14085 | if (b->location_range_end != NULL) |
f1310107 | 14086 | { |
6c5b2ebe PA |
14087 | std::vector<symtab_and_line> sals_end |
14088 | = location_to_sals (b, b->location_range_end.get (), | |
14089 | filter_pspace, &found); | |
f1310107 | 14090 | if (found) |
6c5b2ebe | 14091 | expanded_end = std::move (sals_end); |
f1310107 TJB |
14092 | } |
14093 | ||
c2f4122d | 14094 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14095 | } |
14096 | ||
983af33b SDJ |
14097 | /* Default method for creating SALs from an address string. It basically |
14098 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14099 | ||
14100 | static void | |
f00aae0f KS |
14101 | create_sals_from_location_default (const struct event_location *location, |
14102 | struct linespec_result *canonical, | |
14103 | enum bptype type_wanted) | |
983af33b | 14104 | { |
f00aae0f | 14105 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14106 | } |
14107 | ||
14108 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14109 | function for the `create_breakpoints_sal' method of | |
14110 | breakpoint_ops. */ | |
14111 | ||
14112 | static void | |
14113 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14114 | struct linespec_result *canonical, | |
e1e01040 PA |
14115 | gdb::unique_xmalloc_ptr<char> cond_string, |
14116 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
14117 | enum bptype type_wanted, |
14118 | enum bpdisp disposition, | |
14119 | int thread, | |
14120 | int task, int ignore_count, | |
14121 | const struct breakpoint_ops *ops, | |
14122 | int from_tty, int enabled, | |
44f238bb | 14123 | int internal, unsigned flags) |
983af33b | 14124 | { |
e1e01040 PA |
14125 | create_breakpoints_sal (gdbarch, canonical, |
14126 | std::move (cond_string), | |
14127 | std::move (extra_string), | |
983af33b SDJ |
14128 | type_wanted, disposition, |
14129 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14130 | enabled, internal, flags); |
983af33b SDJ |
14131 | } |
14132 | ||
14133 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14134 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 14135 | |
6c5b2ebe | 14136 | static std::vector<symtab_and_line> |
f00aae0f KS |
14137 | decode_location_default (struct breakpoint *b, |
14138 | const struct event_location *location, | |
6c5b2ebe | 14139 | struct program_space *search_pspace) |
983af33b SDJ |
14140 | { |
14141 | struct linespec_result canonical; | |
14142 | ||
c2f4122d | 14143 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14144 | (struct symtab *) NULL, 0, |
14145 | &canonical, multiple_symbols_all, | |
14146 | b->filter); | |
14147 | ||
14148 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 14149 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 14150 | |
6c5b2ebe | 14151 | if (!canonical.lsals.empty ()) |
983af33b | 14152 | { |
6c5b2ebe PA |
14153 | const linespec_sals &lsal = canonical.lsals[0]; |
14154 | return std::move (lsal.sals); | |
983af33b | 14155 | } |
6c5b2ebe | 14156 | return {}; |
983af33b SDJ |
14157 | } |
14158 | ||
28010a5d PA |
14159 | /* Prepare the global context for a re-set of breakpoint B. */ |
14160 | ||
14161 | static struct cleanup * | |
14162 | prepare_re_set_context (struct breakpoint *b) | |
14163 | { | |
28010a5d | 14164 | input_radix = b->input_radix; |
28010a5d PA |
14165 | set_language (b->language); |
14166 | ||
c2f4122d | 14167 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14168 | } |
14169 | ||
c906108c SS |
14170 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14171 | The value we return ends up being the return value from catch_errors. | |
14172 | Unused in this case. */ | |
14173 | ||
14174 | static int | |
4efb68b1 | 14175 | breakpoint_re_set_one (void *bint) |
c906108c | 14176 | { |
4a64f543 | 14177 | /* Get past catch_errs. */ |
53a5351d | 14178 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14179 | struct cleanup *cleanups; |
c906108c | 14180 | |
348d480f PA |
14181 | cleanups = prepare_re_set_context (b); |
14182 | b->ops->re_set (b); | |
14183 | do_cleanups (cleanups); | |
c906108c SS |
14184 | return 0; |
14185 | } | |
14186 | ||
c2f4122d PA |
14187 | /* Re-set breakpoint locations for the current program space. |
14188 | Locations bound to other program spaces are left untouched. */ | |
14189 | ||
c906108c | 14190 | void |
69de3c6a | 14191 | breakpoint_re_set (void) |
c906108c | 14192 | { |
35df4500 | 14193 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14194 | enum language save_language; |
14195 | int save_input_radix; | |
c5aa993b | 14196 | |
c906108c SS |
14197 | save_language = current_language->la_language; |
14198 | save_input_radix = input_radix; | |
2a7f3dff | 14199 | |
c5aa993b | 14200 | { |
5ed8105e | 14201 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 14202 | |
5ed8105e PA |
14203 | /* Note: we must not try to insert locations until after all |
14204 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14205 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14206 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 14207 | |
5ed8105e PA |
14208 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
14209 | { | |
14210 | /* Format possible error msg. */ | |
14211 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", | |
14212 | b->number); | |
14213 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
14214 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); | |
14215 | do_cleanups (cleanups); | |
14216 | } | |
14217 | set_language (save_language); | |
14218 | input_radix = save_input_radix; | |
14219 | ||
14220 | jit_breakpoint_re_set (); | |
14221 | } | |
6c95b8df | 14222 | |
af02033e PP |
14223 | create_overlay_event_breakpoint (); |
14224 | create_longjmp_master_breakpoint (); | |
14225 | create_std_terminate_master_breakpoint (); | |
186c406b | 14226 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14227 | |
14228 | /* Now we can insert. */ | |
14229 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14230 | } |
14231 | \f | |
c906108c SS |
14232 | /* Reset the thread number of this breakpoint: |
14233 | ||
14234 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14235 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14236 | void |
fba45db2 | 14237 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14238 | { |
14239 | if (b->thread != -1) | |
14240 | { | |
39f77062 | 14241 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14242 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14243 | |
14244 | /* We're being called after following a fork. The new fork is | |
14245 | selected as current, and unless this was a vfork will have a | |
14246 | different program space from the original thread. Reset that | |
14247 | as well. */ | |
14248 | b->loc->pspace = current_program_space; | |
c906108c SS |
14249 | } |
14250 | } | |
14251 | ||
03ac34d5 MS |
14252 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14253 | If from_tty is nonzero, it prints a message to that effect, | |
14254 | which ends with a period (no newline). */ | |
14255 | ||
c906108c | 14256 | void |
fba45db2 | 14257 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14258 | { |
52f0bd74 | 14259 | struct breakpoint *b; |
c906108c SS |
14260 | |
14261 | if (count < 0) | |
14262 | count = 0; | |
14263 | ||
14264 | ALL_BREAKPOINTS (b) | |
14265 | if (b->number == bptnum) | |
c5aa993b | 14266 | { |
d77f58be SS |
14267 | if (is_tracepoint (b)) |
14268 | { | |
14269 | if (from_tty && count != 0) | |
14270 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14271 | bptnum); | |
14272 | return; | |
14273 | } | |
14274 | ||
c5aa993b | 14275 | b->ignore_count = count; |
221ea385 KS |
14276 | if (from_tty) |
14277 | { | |
14278 | if (count == 0) | |
3e43a32a MS |
14279 | printf_filtered (_("Will stop next time " |
14280 | "breakpoint %d is reached."), | |
221ea385 KS |
14281 | bptnum); |
14282 | else if (count == 1) | |
a3f17187 | 14283 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14284 | bptnum); |
14285 | else | |
3e43a32a MS |
14286 | printf_filtered (_("Will ignore next %d " |
14287 | "crossings of breakpoint %d."), | |
221ea385 KS |
14288 | count, bptnum); |
14289 | } | |
8d3788bd | 14290 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14291 | return; |
14292 | } | |
c906108c | 14293 | |
8a3fe4f8 | 14294 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14295 | } |
14296 | ||
c906108c SS |
14297 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14298 | ||
14299 | static void | |
fba45db2 | 14300 | ignore_command (char *args, int from_tty) |
c906108c SS |
14301 | { |
14302 | char *p = args; | |
52f0bd74 | 14303 | int num; |
c906108c SS |
14304 | |
14305 | if (p == 0) | |
e2e0b3e5 | 14306 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14307 | |
c906108c | 14308 | num = get_number (&p); |
5c44784c | 14309 | if (num == 0) |
8a3fe4f8 | 14310 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14311 | if (*p == 0) |
8a3fe4f8 | 14312 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14313 | |
14314 | set_ignore_count (num, | |
14315 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14316 | from_tty); | |
221ea385 KS |
14317 | if (from_tty) |
14318 | printf_filtered ("\n"); | |
c906108c SS |
14319 | } |
14320 | \f | |
14321 | /* Call FUNCTION on each of the breakpoints | |
14322 | whose numbers are given in ARGS. */ | |
14323 | ||
14324 | static void | |
896b6bda | 14325 | map_breakpoint_numbers (const char *args, |
48649e1b | 14326 | gdb::function_view<void (breakpoint *)> function) |
c906108c | 14327 | { |
52f0bd74 AC |
14328 | int num; |
14329 | struct breakpoint *b, *tmp; | |
c906108c | 14330 | |
b9d61307 | 14331 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14332 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14333 | |
bfd28288 | 14334 | number_or_range_parser parser (args); |
197f0a60 | 14335 | |
bfd28288 | 14336 | while (!parser.finished ()) |
c906108c | 14337 | { |
bfd28288 PA |
14338 | const char *p = parser.cur_tok (); |
14339 | bool match = false; | |
197f0a60 | 14340 | |
bfd28288 | 14341 | num = parser.get_number (); |
5c44784c | 14342 | if (num == 0) |
c5aa993b | 14343 | { |
8a3fe4f8 | 14344 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14345 | } |
14346 | else | |
14347 | { | |
14348 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14349 | if (b->number == num) | |
14350 | { | |
bfd28288 | 14351 | match = true; |
48649e1b | 14352 | function (b); |
11cf8741 | 14353 | break; |
5c44784c | 14354 | } |
bfd28288 | 14355 | if (!match) |
a3f17187 | 14356 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14357 | } |
c906108c SS |
14358 | } |
14359 | } | |
14360 | ||
0d381245 | 14361 | static struct bp_location * |
cb791d59 | 14362 | find_location_by_number (const char *number) |
0d381245 | 14363 | { |
cb791d59 | 14364 | const char *p1; |
0d381245 VP |
14365 | int bp_num; |
14366 | int loc_num; | |
14367 | struct breakpoint *b; | |
14368 | struct bp_location *loc; | |
14369 | ||
0d381245 | 14370 | p1 = number; |
cb791d59 TT |
14371 | bp_num = get_number_trailer (&p1, '.'); |
14372 | if (bp_num == 0 || p1[0] != '.') | |
0d381245 VP |
14373 | error (_("Bad breakpoint number '%s'"), number); |
14374 | ||
14375 | ALL_BREAKPOINTS (b) | |
14376 | if (b->number == bp_num) | |
14377 | { | |
14378 | break; | |
14379 | } | |
14380 | ||
14381 | if (!b || b->number != bp_num) | |
14382 | error (_("Bad breakpoint number '%s'"), number); | |
14383 | ||
cb791d59 TT |
14384 | /* Skip the dot. */ |
14385 | ++p1; | |
14386 | const char *save = p1; | |
197f0a60 | 14387 | loc_num = get_number (&p1); |
0d381245 VP |
14388 | if (loc_num == 0) |
14389 | error (_("Bad breakpoint location number '%s'"), number); | |
14390 | ||
14391 | --loc_num; | |
14392 | loc = b->loc; | |
14393 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14394 | ; | |
14395 | if (!loc) | |
cb791d59 | 14396 | error (_("Bad breakpoint location number '%s'"), save); |
0d381245 VP |
14397 | |
14398 | return loc; | |
14399 | } | |
14400 | ||
14401 | ||
1900040c MS |
14402 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14403 | If from_tty is nonzero, it prints a message to that effect, | |
14404 | which ends with a period (no newline). */ | |
14405 | ||
c906108c | 14406 | void |
fba45db2 | 14407 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14408 | { |
14409 | /* Never disable a watchpoint scope breakpoint; we want to | |
14410 | hit them when we leave scope so we can delete both the | |
14411 | watchpoint and its scope breakpoint at that time. */ | |
14412 | if (bpt->type == bp_watchpoint_scope) | |
14413 | return; | |
14414 | ||
b5de0fa7 | 14415 | bpt->enable_state = bp_disabled; |
c906108c | 14416 | |
b775012e LM |
14417 | /* Mark breakpoint locations modified. */ |
14418 | mark_breakpoint_modified (bpt); | |
14419 | ||
d248b706 KY |
14420 | if (target_supports_enable_disable_tracepoint () |
14421 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14422 | { | |
14423 | struct bp_location *location; | |
14424 | ||
14425 | for (location = bpt->loc; location; location = location->next) | |
14426 | target_disable_tracepoint (location); | |
14427 | } | |
14428 | ||
44702360 | 14429 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14430 | |
8d3788bd | 14431 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14432 | } |
14433 | ||
c906108c | 14434 | static void |
fba45db2 | 14435 | disable_command (char *args, int from_tty) |
c906108c | 14436 | { |
c906108c | 14437 | if (args == 0) |
46c6471b PA |
14438 | { |
14439 | struct breakpoint *bpt; | |
14440 | ||
14441 | ALL_BREAKPOINTS (bpt) | |
14442 | if (user_breakpoint_p (bpt)) | |
14443 | disable_breakpoint (bpt); | |
14444 | } | |
9eaabc75 | 14445 | else |
0d381245 | 14446 | { |
cb791d59 | 14447 | std::string num = extract_arg (&args); |
9eaabc75 | 14448 | |
cb791d59 | 14449 | while (!num.empty ()) |
d248b706 | 14450 | { |
cb791d59 | 14451 | if (num.find ('.') != std::string::npos) |
b775012e | 14452 | { |
cb791d59 | 14453 | struct bp_location *loc = find_location_by_number (num.c_str ()); |
9eaabc75 MW |
14454 | |
14455 | if (loc) | |
14456 | { | |
14457 | if (loc->enabled) | |
14458 | { | |
14459 | loc->enabled = 0; | |
14460 | mark_breakpoint_location_modified (loc); | |
14461 | } | |
14462 | if (target_supports_enable_disable_tracepoint () | |
14463 | && current_trace_status ()->running && loc->owner | |
14464 | && is_tracepoint (loc->owner)) | |
14465 | target_disable_tracepoint (loc); | |
14466 | } | |
44702360 | 14467 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14468 | } |
9eaabc75 | 14469 | else |
48649e1b TT |
14470 | map_breakpoint_numbers |
14471 | (num.c_str (), [&] (breakpoint *b) | |
14472 | { | |
14473 | iterate_over_related_breakpoints (b, disable_breakpoint); | |
14474 | }); | |
9eaabc75 | 14475 | num = extract_arg (&args); |
d248b706 | 14476 | } |
0d381245 | 14477 | } |
c906108c SS |
14478 | } |
14479 | ||
14480 | static void | |
816338b5 SS |
14481 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14482 | int count) | |
c906108c | 14483 | { |
afe38095 | 14484 | int target_resources_ok; |
c906108c SS |
14485 | |
14486 | if (bpt->type == bp_hardware_breakpoint) | |
14487 | { | |
14488 | int i; | |
c5aa993b | 14489 | i = hw_breakpoint_used_count (); |
53a5351d | 14490 | target_resources_ok = |
d92524f1 | 14491 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14492 | i + 1, 0); |
c906108c | 14493 | if (target_resources_ok == 0) |
8a3fe4f8 | 14494 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14495 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14496 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14497 | } |
14498 | ||
cc60f2e3 | 14499 | if (is_watchpoint (bpt)) |
c906108c | 14500 | { |
d07205c2 | 14501 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14502 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14503 | |
492d29ea | 14504 | TRY |
c906108c | 14505 | { |
3a5c3e22 PA |
14506 | struct watchpoint *w = (struct watchpoint *) bpt; |
14507 | ||
1e718ff1 TJB |
14508 | orig_enable_state = bpt->enable_state; |
14509 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14510 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14511 | } |
492d29ea | 14512 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14513 | { |
1e718ff1 | 14514 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14515 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14516 | bpt->number); | |
14517 | return; | |
c5aa993b | 14518 | } |
492d29ea | 14519 | END_CATCH |
c906108c | 14520 | } |
0101ce28 | 14521 | |
b775012e LM |
14522 | bpt->enable_state = bp_enabled; |
14523 | ||
14524 | /* Mark breakpoint locations modified. */ | |
14525 | mark_breakpoint_modified (bpt); | |
14526 | ||
d248b706 KY |
14527 | if (target_supports_enable_disable_tracepoint () |
14528 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14529 | { | |
14530 | struct bp_location *location; | |
14531 | ||
14532 | for (location = bpt->loc; location; location = location->next) | |
14533 | target_enable_tracepoint (location); | |
14534 | } | |
14535 | ||
b4c291bb | 14536 | bpt->disposition = disposition; |
816338b5 | 14537 | bpt->enable_count = count; |
44702360 | 14538 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14539 | |
8d3788bd | 14540 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14541 | } |
14542 | ||
fe3f5fa8 | 14543 | |
c906108c | 14544 | void |
fba45db2 | 14545 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14546 | { |
816338b5 | 14547 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14548 | } |
14549 | ||
c906108c SS |
14550 | /* The enable command enables the specified breakpoints (or all defined |
14551 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14552 | in stopping the inferior. */ |
c906108c | 14553 | |
c906108c | 14554 | static void |
fba45db2 | 14555 | enable_command (char *args, int from_tty) |
c906108c | 14556 | { |
c906108c | 14557 | if (args == 0) |
46c6471b PA |
14558 | { |
14559 | struct breakpoint *bpt; | |
14560 | ||
14561 | ALL_BREAKPOINTS (bpt) | |
14562 | if (user_breakpoint_p (bpt)) | |
14563 | enable_breakpoint (bpt); | |
14564 | } | |
9eaabc75 | 14565 | else |
0d381245 | 14566 | { |
cb791d59 | 14567 | std::string num = extract_arg (&args); |
9eaabc75 | 14568 | |
cb791d59 | 14569 | while (!num.empty ()) |
d248b706 | 14570 | { |
cb791d59 | 14571 | if (num.find ('.') != std::string::npos) |
b775012e | 14572 | { |
cb791d59 | 14573 | struct bp_location *loc = find_location_by_number (num.c_str ()); |
9eaabc75 MW |
14574 | |
14575 | if (loc) | |
14576 | { | |
14577 | if (!loc->enabled) | |
14578 | { | |
14579 | loc->enabled = 1; | |
14580 | mark_breakpoint_location_modified (loc); | |
14581 | } | |
14582 | if (target_supports_enable_disable_tracepoint () | |
14583 | && current_trace_status ()->running && loc->owner | |
14584 | && is_tracepoint (loc->owner)) | |
14585 | target_enable_tracepoint (loc); | |
14586 | } | |
44702360 | 14587 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14588 | } |
9eaabc75 | 14589 | else |
48649e1b TT |
14590 | map_breakpoint_numbers |
14591 | (num.c_str (), [&] (breakpoint *b) | |
14592 | { | |
14593 | iterate_over_related_breakpoints (b, enable_breakpoint); | |
14594 | }); | |
9eaabc75 | 14595 | num = extract_arg (&args); |
d248b706 | 14596 | } |
0d381245 | 14597 | } |
c906108c SS |
14598 | } |
14599 | ||
c906108c | 14600 | static void |
fba45db2 | 14601 | enable_once_command (char *args, int from_tty) |
c906108c | 14602 | { |
48649e1b TT |
14603 | map_breakpoint_numbers |
14604 | (args, [&] (breakpoint *b) | |
14605 | { | |
14606 | iterate_over_related_breakpoints | |
14607 | (b, [&] (breakpoint *bpt) | |
14608 | { | |
14609 | enable_breakpoint_disp (bpt, disp_disable, 1); | |
14610 | }); | |
14611 | }); | |
816338b5 SS |
14612 | } |
14613 | ||
14614 | static void | |
14615 | enable_count_command (char *args, int from_tty) | |
14616 | { | |
b9d61307 SM |
14617 | int count; |
14618 | ||
14619 | if (args == NULL) | |
14620 | error_no_arg (_("hit count")); | |
14621 | ||
14622 | count = get_number (&args); | |
816338b5 | 14623 | |
48649e1b TT |
14624 | map_breakpoint_numbers |
14625 | (args, [&] (breakpoint *b) | |
14626 | { | |
14627 | iterate_over_related_breakpoints | |
14628 | (b, [&] (breakpoint *bpt) | |
14629 | { | |
14630 | enable_breakpoint_disp (bpt, disp_disable, count); | |
14631 | }); | |
14632 | }); | |
c906108c SS |
14633 | } |
14634 | ||
c906108c | 14635 | static void |
fba45db2 | 14636 | enable_delete_command (char *args, int from_tty) |
c906108c | 14637 | { |
48649e1b TT |
14638 | map_breakpoint_numbers |
14639 | (args, [&] (breakpoint *b) | |
14640 | { | |
14641 | iterate_over_related_breakpoints | |
14642 | (b, [&] (breakpoint *bpt) | |
14643 | { | |
14644 | enable_breakpoint_disp (bpt, disp_del, 1); | |
14645 | }); | |
14646 | }); | |
c906108c SS |
14647 | } |
14648 | \f | |
fa8d40ab JJ |
14649 | static void |
14650 | set_breakpoint_cmd (char *args, int from_tty) | |
14651 | { | |
14652 | } | |
14653 | ||
14654 | static void | |
14655 | show_breakpoint_cmd (char *args, int from_tty) | |
14656 | { | |
14657 | } | |
14658 | ||
1f3b5d1b PP |
14659 | /* Invalidate last known value of any hardware watchpoint if |
14660 | the memory which that value represents has been written to by | |
14661 | GDB itself. */ | |
14662 | ||
14663 | static void | |
8de0566d YQ |
14664 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14665 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14666 | const bfd_byte *data) |
14667 | { | |
14668 | struct breakpoint *bp; | |
14669 | ||
14670 | ALL_BREAKPOINTS (bp) | |
14671 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14672 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14673 | { |
3a5c3e22 | 14674 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14675 | |
3a5c3e22 PA |
14676 | if (wp->val_valid && wp->val) |
14677 | { | |
14678 | struct bp_location *loc; | |
14679 | ||
14680 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14681 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14682 | && loc->address + loc->length > addr | |
14683 | && addr + len > loc->address) | |
14684 | { | |
14685 | value_free (wp->val); | |
14686 | wp->val = NULL; | |
14687 | wp->val_valid = 0; | |
14688 | } | |
14689 | } | |
1f3b5d1b PP |
14690 | } |
14691 | } | |
14692 | ||
8181d85f DJ |
14693 | /* Create and insert a breakpoint for software single step. */ |
14694 | ||
14695 | void | |
6c95b8df | 14696 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14697 | struct address_space *aspace, |
14698 | CORE_ADDR next_pc) | |
8181d85f | 14699 | { |
7c16b83e PA |
14700 | struct thread_info *tp = inferior_thread (); |
14701 | struct symtab_and_line sal; | |
14702 | CORE_ADDR pc = next_pc; | |
8181d85f | 14703 | |
34b7e8a6 PA |
14704 | if (tp->control.single_step_breakpoints == NULL) |
14705 | { | |
14706 | tp->control.single_step_breakpoints | |
5d5658a1 | 14707 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14708 | } |
8181d85f | 14709 | |
7c16b83e PA |
14710 | sal = find_pc_line (pc, 0); |
14711 | sal.pc = pc; | |
14712 | sal.section = find_pc_overlay (pc); | |
14713 | sal.explicit_pc = 1; | |
34b7e8a6 | 14714 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14715 | |
7c16b83e | 14716 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14717 | } |
14718 | ||
93f9a11f YQ |
14719 | /* Insert single step breakpoints according to the current state. */ |
14720 | ||
14721 | int | |
14722 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14723 | { | |
f5ea389a | 14724 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14725 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14726 | |
f5ea389a | 14727 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14728 | |
a0ff9e1a | 14729 | if (!next_pcs.empty ()) |
93f9a11f | 14730 | { |
f5ea389a | 14731 | struct frame_info *frame = get_current_frame (); |
93f9a11f YQ |
14732 | struct address_space *aspace = get_frame_address_space (frame); |
14733 | ||
a0ff9e1a | 14734 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14735 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14736 | ||
93f9a11f YQ |
14737 | return 1; |
14738 | } | |
14739 | else | |
14740 | return 0; | |
14741 | } | |
14742 | ||
34b7e8a6 | 14743 | /* See breakpoint.h. */ |
f02253f1 HZ |
14744 | |
14745 | int | |
7c16b83e PA |
14746 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
14747 | struct address_space *aspace, | |
14748 | CORE_ADDR pc) | |
1aafd4da | 14749 | { |
7c16b83e | 14750 | struct bp_location *loc; |
1aafd4da | 14751 | |
7c16b83e PA |
14752 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14753 | if (loc->inserted | |
14754 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14755 | return 1; | |
1aafd4da | 14756 | |
7c16b83e | 14757 | return 0; |
ef370185 JB |
14758 | } |
14759 | ||
14760 | /* Check whether a software single-step breakpoint is inserted at | |
14761 | PC. */ | |
14762 | ||
14763 | int | |
14764 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
14765 | CORE_ADDR pc) | |
14766 | { | |
34b7e8a6 PA |
14767 | struct breakpoint *bpt; |
14768 | ||
14769 | ALL_BREAKPOINTS (bpt) | |
14770 | { | |
14771 | if (bpt->type == bp_single_step | |
14772 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14773 | return 1; | |
14774 | } | |
14775 | return 0; | |
1aafd4da UW |
14776 | } |
14777 | ||
1042e4c0 SS |
14778 | /* Tracepoint-specific operations. */ |
14779 | ||
14780 | /* Set tracepoint count to NUM. */ | |
14781 | static void | |
14782 | set_tracepoint_count (int num) | |
14783 | { | |
14784 | tracepoint_count = num; | |
4fa62494 | 14785 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14786 | } |
14787 | ||
70221824 | 14788 | static void |
1042e4c0 SS |
14789 | trace_command (char *arg, int from_tty) |
14790 | { | |
55aa24fb | 14791 | struct breakpoint_ops *ops; |
55aa24fb | 14792 | |
ffc2605c TT |
14793 | event_location_up location = string_to_event_location (&arg, |
14794 | current_language); | |
5b56227b | 14795 | if (location != NULL |
ffc2605c | 14796 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
14797 | ops = &tracepoint_probe_breakpoint_ops; |
14798 | else | |
14799 | ops = &tracepoint_breakpoint_ops; | |
14800 | ||
558a9d82 | 14801 | create_breakpoint (get_current_arch (), |
ffc2605c | 14802 | location.get (), |
f00aae0f | 14803 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14804 | 0 /* tempflag */, |
14805 | bp_tracepoint /* type_wanted */, | |
14806 | 0 /* Ignore count */, | |
14807 | pending_break_support, | |
14808 | ops, | |
14809 | from_tty, | |
14810 | 1 /* enabled */, | |
14811 | 0 /* internal */, 0); | |
1042e4c0 SS |
14812 | } |
14813 | ||
70221824 | 14814 | static void |
7a697b8d SS |
14815 | ftrace_command (char *arg, int from_tty) |
14816 | { | |
ffc2605c TT |
14817 | event_location_up location = string_to_event_location (&arg, |
14818 | current_language); | |
558a9d82 | 14819 | create_breakpoint (get_current_arch (), |
ffc2605c | 14820 | location.get (), |
f00aae0f | 14821 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14822 | 0 /* tempflag */, |
14823 | bp_fast_tracepoint /* type_wanted */, | |
14824 | 0 /* Ignore count */, | |
14825 | pending_break_support, | |
14826 | &tracepoint_breakpoint_ops, | |
14827 | from_tty, | |
14828 | 1 /* enabled */, | |
14829 | 0 /* internal */, 0); | |
0fb4aa4b PA |
14830 | } |
14831 | ||
14832 | /* strace command implementation. Creates a static tracepoint. */ | |
14833 | ||
70221824 | 14834 | static void |
0fb4aa4b PA |
14835 | strace_command (char *arg, int from_tty) |
14836 | { | |
983af33b | 14837 | struct breakpoint_ops *ops; |
ffc2605c | 14838 | event_location_up location; |
f00aae0f | 14839 | struct cleanup *back_to; |
983af33b SDJ |
14840 | |
14841 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
14842 | or with a normal static tracepoint. */ | |
61012eef | 14843 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
14844 | { |
14845 | ops = &strace_marker_breakpoint_ops; | |
14846 | location = new_linespec_location (&arg); | |
14847 | } | |
983af33b | 14848 | else |
f00aae0f KS |
14849 | { |
14850 | ops = &tracepoint_breakpoint_ops; | |
14851 | location = string_to_event_location (&arg, current_language); | |
14852 | } | |
983af33b | 14853 | |
558a9d82 | 14854 | create_breakpoint (get_current_arch (), |
ffc2605c | 14855 | location.get (), |
f00aae0f | 14856 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14857 | 0 /* tempflag */, |
14858 | bp_static_tracepoint /* type_wanted */, | |
14859 | 0 /* Ignore count */, | |
14860 | pending_break_support, | |
14861 | ops, | |
14862 | from_tty, | |
14863 | 1 /* enabled */, | |
14864 | 0 /* internal */, 0); | |
7a697b8d SS |
14865 | } |
14866 | ||
409873ef SS |
14867 | /* Set up a fake reader function that gets command lines from a linked |
14868 | list that was acquired during tracepoint uploading. */ | |
14869 | ||
14870 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 14871 | static int next_cmd; |
409873ef SS |
14872 | |
14873 | static char * | |
14874 | read_uploaded_action (void) | |
14875 | { | |
14876 | char *rslt; | |
14877 | ||
3149d8c1 | 14878 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 14879 | |
3149d8c1 | 14880 | next_cmd++; |
409873ef SS |
14881 | |
14882 | return rslt; | |
14883 | } | |
14884 | ||
00bf0b85 SS |
14885 | /* Given information about a tracepoint as recorded on a target (which |
14886 | can be either a live system or a trace file), attempt to create an | |
14887 | equivalent GDB tracepoint. This is not a reliable process, since | |
14888 | the target does not necessarily have all the information used when | |
14889 | the tracepoint was originally defined. */ | |
14890 | ||
d9b3f62e | 14891 | struct tracepoint * |
00bf0b85 | 14892 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 14893 | { |
409873ef | 14894 | char *addr_str, small_buf[100]; |
d9b3f62e | 14895 | struct tracepoint *tp; |
fd9b8c24 | 14896 | |
409873ef SS |
14897 | if (utp->at_string) |
14898 | addr_str = utp->at_string; | |
14899 | else | |
14900 | { | |
14901 | /* In the absence of a source location, fall back to raw | |
14902 | address. Since there is no way to confirm that the address | |
14903 | means the same thing as when the trace was started, warn the | |
14904 | user. */ | |
3e43a32a MS |
14905 | warning (_("Uploaded tracepoint %d has no " |
14906 | "source location, using raw address"), | |
409873ef | 14907 | utp->number); |
8c042590 | 14908 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
14909 | addr_str = small_buf; |
14910 | } | |
14911 | ||
14912 | /* There's not much we can do with a sequence of bytecodes. */ | |
14913 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
14914 | warning (_("Uploaded tracepoint %d condition " |
14915 | "has no source form, ignoring it"), | |
409873ef | 14916 | utp->number); |
d5551862 | 14917 | |
ffc2605c TT |
14918 | event_location_up location = string_to_event_location (&addr_str, |
14919 | current_language); | |
8cdf0e15 | 14920 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 14921 | location.get (), |
f00aae0f | 14922 | utp->cond_string, -1, addr_str, |
e7e0cddf | 14923 | 0 /* parse cond/thread */, |
8cdf0e15 | 14924 | 0 /* tempflag */, |
0fb4aa4b | 14925 | utp->type /* type_wanted */, |
8cdf0e15 VP |
14926 | 0 /* Ignore count */, |
14927 | pending_break_support, | |
348d480f | 14928 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 14929 | 0 /* from_tty */, |
84f4c1fe | 14930 | utp->enabled /* enabled */, |
44f238bb PA |
14931 | 0 /* internal */, |
14932 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 14933 | return NULL; |
fd9b8c24 | 14934 | |
409873ef | 14935 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
14936 | tp = get_tracepoint (tracepoint_count); |
14937 | gdb_assert (tp != NULL); | |
d5551862 | 14938 | |
00bf0b85 SS |
14939 | if (utp->pass > 0) |
14940 | { | |
8c042590 | 14941 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 14942 | tp->number); |
00bf0b85 | 14943 | |
409873ef | 14944 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
14945 | } |
14946 | ||
409873ef SS |
14947 | /* If we have uploaded versions of the original commands, set up a |
14948 | special-purpose "reader" function and call the usual command line | |
14949 | reader, then pass the result to the breakpoint command-setting | |
14950 | function. */ | |
3149d8c1 | 14951 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 14952 | { |
93921405 | 14953 | command_line_up cmd_list; |
00bf0b85 | 14954 | |
409873ef | 14955 | this_utp = utp; |
3149d8c1 | 14956 | next_cmd = 0; |
d5551862 | 14957 | |
409873ef SS |
14958 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
14959 | ||
c1fc2657 | 14960 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 14961 | } |
3149d8c1 SS |
14962 | else if (!VEC_empty (char_ptr, utp->actions) |
14963 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
14964 | warning (_("Uploaded tracepoint %d actions " |
14965 | "have no source form, ignoring them"), | |
409873ef | 14966 | utp->number); |
00bf0b85 | 14967 | |
f196051f | 14968 | /* Copy any status information that might be available. */ |
c1fc2657 | 14969 | tp->hit_count = utp->hit_count; |
f196051f SS |
14970 | tp->traceframe_usage = utp->traceframe_usage; |
14971 | ||
00bf0b85 | 14972 | return tp; |
d9b3f62e | 14973 | } |
00bf0b85 | 14974 | |
1042e4c0 SS |
14975 | /* Print information on tracepoint number TPNUM_EXP, or all if |
14976 | omitted. */ | |
14977 | ||
14978 | static void | |
11db9430 | 14979 | info_tracepoints_command (char *args, int from_tty) |
1042e4c0 | 14980 | { |
79a45e25 | 14981 | struct ui_out *uiout = current_uiout; |
e5a67952 | 14982 | int num_printed; |
1042e4c0 | 14983 | |
e5a67952 | 14984 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
14985 | |
14986 | if (num_printed == 0) | |
1042e4c0 | 14987 | { |
e5a67952 | 14988 | if (args == NULL || *args == '\0') |
112e8700 | 14989 | uiout->message ("No tracepoints.\n"); |
d77f58be | 14990 | else |
112e8700 | 14991 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 14992 | } |
ad443146 SS |
14993 | |
14994 | default_collect_info (); | |
1042e4c0 SS |
14995 | } |
14996 | ||
4a64f543 | 14997 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
14998 | Not supported by all targets. */ |
14999 | static void | |
15000 | enable_trace_command (char *args, int from_tty) | |
15001 | { | |
15002 | enable_command (args, from_tty); | |
15003 | } | |
15004 | ||
4a64f543 | 15005 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15006 | Not supported by all targets. */ |
15007 | static void | |
15008 | disable_trace_command (char *args, int from_tty) | |
15009 | { | |
15010 | disable_command (args, from_tty); | |
15011 | } | |
15012 | ||
4a64f543 | 15013 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15014 | static void |
15015 | delete_trace_command (char *arg, int from_tty) | |
15016 | { | |
35df4500 | 15017 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15018 | |
15019 | dont_repeat (); | |
15020 | ||
15021 | if (arg == 0) | |
15022 | { | |
15023 | int breaks_to_delete = 0; | |
15024 | ||
15025 | /* Delete all breakpoints if no argument. | |
15026 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15027 | have to be deleted with an explicit breakpoint number |
15028 | argument. */ | |
1042e4c0 | 15029 | ALL_TRACEPOINTS (b) |
46c6471b | 15030 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15031 | { |
15032 | breaks_to_delete = 1; | |
15033 | break; | |
15034 | } | |
1042e4c0 SS |
15035 | |
15036 | /* Ask user only if there are some breakpoints to delete. */ | |
15037 | if (!from_tty | |
15038 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15039 | { | |
35df4500 | 15040 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15041 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15042 | delete_breakpoint (b); |
1042e4c0 SS |
15043 | } |
15044 | } | |
15045 | else | |
48649e1b TT |
15046 | map_breakpoint_numbers |
15047 | (arg, [&] (breakpoint *b) | |
15048 | { | |
15049 | iterate_over_related_breakpoints (b, delete_breakpoint); | |
15050 | }); | |
1042e4c0 SS |
15051 | } |
15052 | ||
197f0a60 TT |
15053 | /* Helper function for trace_pass_command. */ |
15054 | ||
15055 | static void | |
d9b3f62e | 15056 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15057 | { |
d9b3f62e | 15058 | tp->pass_count = count; |
c1fc2657 | 15059 | observer_notify_breakpoint_modified (tp); |
197f0a60 TT |
15060 | if (from_tty) |
15061 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 15062 | tp->number, count); |
197f0a60 TT |
15063 | } |
15064 | ||
1042e4c0 SS |
15065 | /* Set passcount for tracepoint. |
15066 | ||
15067 | First command argument is passcount, second is tracepoint number. | |
15068 | If tracepoint number omitted, apply to most recently defined. | |
15069 | Also accepts special argument "all". */ | |
15070 | ||
15071 | static void | |
15072 | trace_pass_command (char *args, int from_tty) | |
15073 | { | |
d9b3f62e | 15074 | struct tracepoint *t1; |
1042e4c0 | 15075 | unsigned int count; |
1042e4c0 SS |
15076 | |
15077 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15078 | error (_("passcount command requires an " |
15079 | "argument (count + optional TP num)")); | |
1042e4c0 | 15080 | |
4a64f543 | 15081 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15082 | |
529480d0 | 15083 | args = skip_spaces (args); |
1042e4c0 SS |
15084 | if (*args && strncasecmp (args, "all", 3) == 0) |
15085 | { | |
d9b3f62e PA |
15086 | struct breakpoint *b; |
15087 | ||
1042e4c0 | 15088 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15089 | if (*args) |
15090 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15091 | |
d9b3f62e | 15092 | ALL_TRACEPOINTS (b) |
197f0a60 | 15093 | { |
d9b3f62e | 15094 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15095 | trace_pass_set_count (t1, count, from_tty); |
15096 | } | |
15097 | } | |
15098 | else if (*args == '\0') | |
1042e4c0 | 15099 | { |
5fa1d40e | 15100 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15101 | if (t1) |
197f0a60 TT |
15102 | trace_pass_set_count (t1, count, from_tty); |
15103 | } | |
15104 | else | |
15105 | { | |
bfd28288 PA |
15106 | number_or_range_parser parser (args); |
15107 | while (!parser.finished ()) | |
1042e4c0 | 15108 | { |
bfd28288 | 15109 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15110 | if (t1) |
15111 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15112 | } |
15113 | } | |
1042e4c0 SS |
15114 | } |
15115 | ||
d9b3f62e | 15116 | struct tracepoint * |
1042e4c0 SS |
15117 | get_tracepoint (int num) |
15118 | { | |
15119 | struct breakpoint *t; | |
15120 | ||
15121 | ALL_TRACEPOINTS (t) | |
15122 | if (t->number == num) | |
d9b3f62e | 15123 | return (struct tracepoint *) t; |
1042e4c0 SS |
15124 | |
15125 | return NULL; | |
15126 | } | |
15127 | ||
d5551862 SS |
15128 | /* Find the tracepoint with the given target-side number (which may be |
15129 | different from the tracepoint number after disconnecting and | |
15130 | reconnecting). */ | |
15131 | ||
d9b3f62e | 15132 | struct tracepoint * |
d5551862 SS |
15133 | get_tracepoint_by_number_on_target (int num) |
15134 | { | |
d9b3f62e | 15135 | struct breakpoint *b; |
d5551862 | 15136 | |
d9b3f62e PA |
15137 | ALL_TRACEPOINTS (b) |
15138 | { | |
15139 | struct tracepoint *t = (struct tracepoint *) b; | |
15140 | ||
15141 | if (t->number_on_target == num) | |
15142 | return t; | |
15143 | } | |
d5551862 SS |
15144 | |
15145 | return NULL; | |
15146 | } | |
15147 | ||
1042e4c0 | 15148 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15149 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15150 | If the argument is missing, the most recent tracepoint |
15151 | (tracepoint_count) is returned. */ | |
15152 | ||
d9b3f62e | 15153 | struct tracepoint * |
197f0a60 | 15154 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15155 | number_or_range_parser *parser) |
1042e4c0 | 15156 | { |
1042e4c0 SS |
15157 | struct breakpoint *t; |
15158 | int tpnum; | |
15159 | char *instring = arg == NULL ? NULL : *arg; | |
15160 | ||
bfd28288 | 15161 | if (parser != NULL) |
197f0a60 | 15162 | { |
bfd28288 PA |
15163 | gdb_assert (!parser->finished ()); |
15164 | tpnum = parser->get_number (); | |
197f0a60 TT |
15165 | } |
15166 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15167 | tpnum = tracepoint_count; |
1042e4c0 | 15168 | else |
197f0a60 | 15169 | tpnum = get_number (arg); |
1042e4c0 SS |
15170 | |
15171 | if (tpnum <= 0) | |
15172 | { | |
15173 | if (instring && *instring) | |
15174 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15175 | instring); | |
15176 | else | |
5fa1d40e | 15177 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15178 | return NULL; |
15179 | } | |
15180 | ||
15181 | ALL_TRACEPOINTS (t) | |
15182 | if (t->number == tpnum) | |
15183 | { | |
d9b3f62e | 15184 | return (struct tracepoint *) t; |
1042e4c0 SS |
15185 | } |
15186 | ||
1042e4c0 SS |
15187 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15188 | return NULL; | |
15189 | } | |
15190 | ||
d9b3f62e PA |
15191 | void |
15192 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15193 | { | |
15194 | if (b->thread != -1) | |
15195 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15196 | ||
15197 | if (b->task != 0) | |
15198 | fprintf_unfiltered (fp, " task %d", b->task); | |
15199 | ||
15200 | fprintf_unfiltered (fp, "\n"); | |
15201 | } | |
15202 | ||
6149aea9 PA |
15203 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15204 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15205 | on each breakpoint and only include the ones for which it returns | |
15206 | non-zero. */ | |
15207 | ||
1042e4c0 | 15208 | static void |
6149aea9 PA |
15209 | save_breakpoints (char *filename, int from_tty, |
15210 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15211 | { |
15212 | struct breakpoint *tp; | |
6149aea9 | 15213 | int any = 0; |
6149aea9 | 15214 | int extra_trace_bits = 0; |
1042e4c0 | 15215 | |
6149aea9 PA |
15216 | if (filename == 0 || *filename == 0) |
15217 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15218 | |
15219 | /* See if we have anything to save. */ | |
6149aea9 | 15220 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15221 | { |
6149aea9 | 15222 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15223 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15224 | continue; |
15225 | ||
15226 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15227 | if (filter && !filter (tp)) | |
15228 | continue; | |
15229 | ||
15230 | any = 1; | |
15231 | ||
15232 | if (is_tracepoint (tp)) | |
15233 | { | |
15234 | extra_trace_bits = 1; | |
15235 | ||
15236 | /* We can stop searching. */ | |
15237 | break; | |
15238 | } | |
1042e4c0 | 15239 | } |
6149aea9 PA |
15240 | |
15241 | if (!any) | |
1042e4c0 | 15242 | { |
6149aea9 | 15243 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15244 | return; |
15245 | } | |
15246 | ||
ee0c3293 | 15247 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
15248 | |
15249 | stdio_file fp; | |
15250 | ||
ee0c3293 | 15251 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 15252 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 15253 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 15254 | |
6149aea9 | 15255 | if (extra_trace_bits) |
d7e74731 | 15256 | save_trace_state_variables (&fp); |
8bf6485c | 15257 | |
6149aea9 | 15258 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15259 | { |
6149aea9 | 15260 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15261 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15262 | continue; |
8bf6485c | 15263 | |
6149aea9 PA |
15264 | /* If we have a filter, only save the breakpoints it accepts. */ |
15265 | if (filter && !filter (tp)) | |
15266 | continue; | |
15267 | ||
d7e74731 | 15268 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15269 | |
6149aea9 PA |
15270 | /* Note, we can't rely on tp->number for anything, as we can't |
15271 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15272 | instead. */ | |
15273 | ||
15274 | if (tp->cond_string) | |
d7e74731 | 15275 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15276 | |
15277 | if (tp->ignore_count) | |
d7e74731 | 15278 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15279 | |
2d9442cc | 15280 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15281 | { |
d7e74731 | 15282 | fp.puts (" commands\n"); |
a7bdde9e | 15283 | |
d7e74731 | 15284 | current_uiout->redirect (&fp); |
492d29ea | 15285 | TRY |
1042e4c0 | 15286 | { |
d1b0a7bf | 15287 | print_command_lines (current_uiout, tp->commands.get (), 2); |
a7bdde9e | 15288 | } |
492d29ea PA |
15289 | CATCH (ex, RETURN_MASK_ALL) |
15290 | { | |
112e8700 | 15291 | current_uiout->redirect (NULL); |
492d29ea PA |
15292 | throw_exception (ex); |
15293 | } | |
15294 | END_CATCH | |
1042e4c0 | 15295 | |
112e8700 | 15296 | current_uiout->redirect (NULL); |
d7e74731 | 15297 | fp.puts (" end\n"); |
1042e4c0 | 15298 | } |
6149aea9 PA |
15299 | |
15300 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15301 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15302 | |
15303 | /* If this is a multi-location breakpoint, check if the locations | |
15304 | should be individually disabled. Watchpoint locations are | |
15305 | special, and not user visible. */ | |
15306 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15307 | { | |
15308 | struct bp_location *loc; | |
15309 | int n = 1; | |
15310 | ||
15311 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15312 | if (!loc->enabled) | |
d7e74731 | 15313 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15314 | } |
1042e4c0 | 15315 | } |
8bf6485c | 15316 | |
6149aea9 | 15317 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15318 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15319 | |
1042e4c0 | 15320 | if (from_tty) |
ee0c3293 | 15321 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15322 | } |
15323 | ||
15324 | /* The `save breakpoints' command. */ | |
15325 | ||
15326 | static void | |
15327 | save_breakpoints_command (char *args, int from_tty) | |
15328 | { | |
15329 | save_breakpoints (args, from_tty, NULL); | |
15330 | } | |
15331 | ||
15332 | /* The `save tracepoints' command. */ | |
15333 | ||
15334 | static void | |
15335 | save_tracepoints_command (char *args, int from_tty) | |
15336 | { | |
15337 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15338 | } |
15339 | ||
15340 | /* Create a vector of all tracepoints. */ | |
15341 | ||
15342 | VEC(breakpoint_p) * | |
eeae04df | 15343 | all_tracepoints (void) |
1042e4c0 SS |
15344 | { |
15345 | VEC(breakpoint_p) *tp_vec = 0; | |
15346 | struct breakpoint *tp; | |
15347 | ||
15348 | ALL_TRACEPOINTS (tp) | |
15349 | { | |
15350 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15351 | } | |
15352 | ||
15353 | return tp_vec; | |
15354 | } | |
15355 | ||
c906108c | 15356 | \f |
629500fa KS |
15357 | /* This help string is used to consolidate all the help string for specifying |
15358 | locations used by several commands. */ | |
15359 | ||
15360 | #define LOCATION_HELP_STRING \ | |
15361 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15362 | source filename, function name, label name, and line number.\n\ | |
15363 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15364 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15365 | \"factorial.c:fact:the_top\".\n\ | |
15366 | \n\ | |
15367 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15368 | program. Example: To specify the fourth byte past the start function\n\ | |
15369 | \"main\", use \"*main + 4\".\n\ | |
15370 | \n\ | |
15371 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15372 | syntax to specify location parameters.\n\ | |
15373 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15374 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15375 | -function fact -label the_top\".\n" | |
15376 | ||
4a64f543 MS |
15377 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15378 | commands. It is defined as a macro to prevent duplication. | |
15379 | COMMAND should be a string constant containing the name of the | |
15380 | command. */ | |
629500fa | 15381 | |
31e2b00f | 15382 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15383 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15384 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15385 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15386 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15387 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15388 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15389 | below.\n\ | |
15390 | \n\ | |
dc10affe PA |
15391 | With no LOCATION, uses current execution address of the selected\n\ |
15392 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15393 | \n\ |
15394 | THREADNUM is the number from \"info threads\".\n\ | |
15395 | CONDITION is a boolean expression.\n\ | |
629500fa | 15396 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15397 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15398 | conditions are different.\n\ | |
31e2b00f AS |
15399 | \n\ |
15400 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15401 | ||
44feb3ce TT |
15402 | /* List of subcommands for "catch". */ |
15403 | static struct cmd_list_element *catch_cmdlist; | |
15404 | ||
15405 | /* List of subcommands for "tcatch". */ | |
15406 | static struct cmd_list_element *tcatch_cmdlist; | |
15407 | ||
9ac4176b | 15408 | void |
a121b7c1 | 15409 | add_catch_command (const char *name, const char *docstring, |
82ae6c8d | 15410 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15411 | completer_ftype *completer, |
44feb3ce TT |
15412 | void *user_data_catch, |
15413 | void *user_data_tcatch) | |
15414 | { | |
15415 | struct cmd_list_element *command; | |
15416 | ||
15417 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15418 | &catch_cmdlist); | |
15419 | set_cmd_sfunc (command, sfunc); | |
15420 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15421 | set_cmd_completer (command, completer); |
44feb3ce TT |
15422 | |
15423 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15424 | &tcatch_cmdlist); | |
15425 | set_cmd_sfunc (command, sfunc); | |
15426 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15427 | set_cmd_completer (command, completer); |
44feb3ce TT |
15428 | } |
15429 | ||
6149aea9 PA |
15430 | static void |
15431 | save_command (char *arg, int from_tty) | |
15432 | { | |
3e43a32a MS |
15433 | printf_unfiltered (_("\"save\" must be followed by " |
15434 | "the name of a save subcommand.\n")); | |
635c7e8a | 15435 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15436 | } |
15437 | ||
84f4c1fe PM |
15438 | struct breakpoint * |
15439 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15440 | void *data) | |
15441 | { | |
35df4500 | 15442 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15443 | |
35df4500 | 15444 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15445 | { |
15446 | if ((*callback) (b, data)) | |
15447 | return b; | |
15448 | } | |
15449 | ||
15450 | return NULL; | |
15451 | } | |
15452 | ||
0574c78f GB |
15453 | /* Zero if any of the breakpoint's locations could be a location where |
15454 | functions have been inlined, nonzero otherwise. */ | |
15455 | ||
15456 | static int | |
15457 | is_non_inline_function (struct breakpoint *b) | |
15458 | { | |
15459 | /* The shared library event breakpoint is set on the address of a | |
15460 | non-inline function. */ | |
15461 | if (b->type == bp_shlib_event) | |
15462 | return 1; | |
15463 | ||
15464 | return 0; | |
15465 | } | |
15466 | ||
15467 | /* Nonzero if the specified PC cannot be a location where functions | |
15468 | have been inlined. */ | |
15469 | ||
15470 | int | |
09ac7c10 TT |
15471 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15472 | const struct target_waitstatus *ws) | |
0574c78f GB |
15473 | { |
15474 | struct breakpoint *b; | |
15475 | struct bp_location *bl; | |
15476 | ||
15477 | ALL_BREAKPOINTS (b) | |
15478 | { | |
15479 | if (!is_non_inline_function (b)) | |
15480 | continue; | |
15481 | ||
15482 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15483 | { | |
15484 | if (!bl->shlib_disabled | |
09ac7c10 | 15485 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15486 | return 1; |
15487 | } | |
15488 | } | |
15489 | ||
15490 | return 0; | |
15491 | } | |
15492 | ||
2f202fde JK |
15493 | /* Remove any references to OBJFILE which is going to be freed. */ |
15494 | ||
15495 | void | |
15496 | breakpoint_free_objfile (struct objfile *objfile) | |
15497 | { | |
15498 | struct bp_location **locp, *loc; | |
15499 | ||
15500 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15501 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15502 | loc->symtab = NULL; |
15503 | } | |
15504 | ||
2060206e PA |
15505 | void |
15506 | initialize_breakpoint_ops (void) | |
15507 | { | |
15508 | static int initialized = 0; | |
15509 | ||
15510 | struct breakpoint_ops *ops; | |
15511 | ||
15512 | if (initialized) | |
15513 | return; | |
15514 | initialized = 1; | |
15515 | ||
15516 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15517 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15518 | internal and momentary breakpoints, etc.). */ | |
15519 | ops = &bkpt_base_breakpoint_ops; | |
15520 | *ops = base_breakpoint_ops; | |
15521 | ops->re_set = bkpt_re_set; | |
15522 | ops->insert_location = bkpt_insert_location; | |
15523 | ops->remove_location = bkpt_remove_location; | |
15524 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15525 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15526 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15527 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15528 | |
15529 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15530 | ops = &bkpt_breakpoint_ops; | |
15531 | *ops = bkpt_base_breakpoint_ops; | |
15532 | ops->re_set = bkpt_re_set; | |
15533 | ops->resources_needed = bkpt_resources_needed; | |
15534 | ops->print_it = bkpt_print_it; | |
15535 | ops->print_mention = bkpt_print_mention; | |
15536 | ops->print_recreate = bkpt_print_recreate; | |
15537 | ||
15538 | /* Ranged breakpoints. */ | |
15539 | ops = &ranged_breakpoint_ops; | |
15540 | *ops = bkpt_breakpoint_ops; | |
15541 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15542 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15543 | ops->print_it = print_it_ranged_breakpoint; | |
15544 | ops->print_one = print_one_ranged_breakpoint; | |
15545 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15546 | ops->print_mention = print_mention_ranged_breakpoint; | |
15547 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15548 | ||
15549 | /* Internal breakpoints. */ | |
15550 | ops = &internal_breakpoint_ops; | |
15551 | *ops = bkpt_base_breakpoint_ops; | |
15552 | ops->re_set = internal_bkpt_re_set; | |
15553 | ops->check_status = internal_bkpt_check_status; | |
15554 | ops->print_it = internal_bkpt_print_it; | |
15555 | ops->print_mention = internal_bkpt_print_mention; | |
15556 | ||
15557 | /* Momentary breakpoints. */ | |
15558 | ops = &momentary_breakpoint_ops; | |
15559 | *ops = bkpt_base_breakpoint_ops; | |
15560 | ops->re_set = momentary_bkpt_re_set; | |
15561 | ops->check_status = momentary_bkpt_check_status; | |
15562 | ops->print_it = momentary_bkpt_print_it; | |
15563 | ops->print_mention = momentary_bkpt_print_mention; | |
15564 | ||
55aa24fb SDJ |
15565 | /* Probe breakpoints. */ |
15566 | ops = &bkpt_probe_breakpoint_ops; | |
15567 | *ops = bkpt_breakpoint_ops; | |
15568 | ops->insert_location = bkpt_probe_insert_location; | |
15569 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15570 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15571 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15572 | |
2060206e PA |
15573 | /* Watchpoints. */ |
15574 | ops = &watchpoint_breakpoint_ops; | |
15575 | *ops = base_breakpoint_ops; | |
15576 | ops->re_set = re_set_watchpoint; | |
15577 | ops->insert_location = insert_watchpoint; | |
15578 | ops->remove_location = remove_watchpoint; | |
15579 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15580 | ops->check_status = check_status_watchpoint; | |
15581 | ops->resources_needed = resources_needed_watchpoint; | |
15582 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15583 | ops->print_it = print_it_watchpoint; | |
15584 | ops->print_mention = print_mention_watchpoint; | |
15585 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15586 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15587 | |
15588 | /* Masked watchpoints. */ | |
15589 | ops = &masked_watchpoint_breakpoint_ops; | |
15590 | *ops = watchpoint_breakpoint_ops; | |
15591 | ops->insert_location = insert_masked_watchpoint; | |
15592 | ops->remove_location = remove_masked_watchpoint; | |
15593 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15594 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15595 | ops->print_it = print_it_masked_watchpoint; | |
15596 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15597 | ops->print_mention = print_mention_masked_watchpoint; | |
15598 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15599 | ||
15600 | /* Tracepoints. */ | |
15601 | ops = &tracepoint_breakpoint_ops; | |
15602 | *ops = base_breakpoint_ops; | |
15603 | ops->re_set = tracepoint_re_set; | |
15604 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15605 | ops->print_one_detail = tracepoint_print_one_detail; | |
15606 | ops->print_mention = tracepoint_print_mention; | |
15607 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15608 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15609 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15610 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15611 | |
55aa24fb SDJ |
15612 | /* Probe tracepoints. */ |
15613 | ops = &tracepoint_probe_breakpoint_ops; | |
15614 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15615 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15616 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15617 | |
983af33b SDJ |
15618 | /* Static tracepoints with marker (`-m'). */ |
15619 | ops = &strace_marker_breakpoint_ops; | |
15620 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15621 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15622 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15623 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15624 | |
15625 | /* Fork catchpoints. */ | |
15626 | ops = &catch_fork_breakpoint_ops; | |
15627 | *ops = base_breakpoint_ops; | |
15628 | ops->insert_location = insert_catch_fork; | |
15629 | ops->remove_location = remove_catch_fork; | |
15630 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15631 | ops->print_it = print_it_catch_fork; | |
15632 | ops->print_one = print_one_catch_fork; | |
15633 | ops->print_mention = print_mention_catch_fork; | |
15634 | ops->print_recreate = print_recreate_catch_fork; | |
15635 | ||
15636 | /* Vfork catchpoints. */ | |
15637 | ops = &catch_vfork_breakpoint_ops; | |
15638 | *ops = base_breakpoint_ops; | |
15639 | ops->insert_location = insert_catch_vfork; | |
15640 | ops->remove_location = remove_catch_vfork; | |
15641 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15642 | ops->print_it = print_it_catch_vfork; | |
15643 | ops->print_one = print_one_catch_vfork; | |
15644 | ops->print_mention = print_mention_catch_vfork; | |
15645 | ops->print_recreate = print_recreate_catch_vfork; | |
15646 | ||
15647 | /* Exec catchpoints. */ | |
15648 | ops = &catch_exec_breakpoint_ops; | |
15649 | *ops = base_breakpoint_ops; | |
2060206e PA |
15650 | ops->insert_location = insert_catch_exec; |
15651 | ops->remove_location = remove_catch_exec; | |
15652 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15653 | ops->print_it = print_it_catch_exec; | |
15654 | ops->print_one = print_one_catch_exec; | |
15655 | ops->print_mention = print_mention_catch_exec; | |
15656 | ops->print_recreate = print_recreate_catch_exec; | |
15657 | ||
edcc5120 TT |
15658 | /* Solib-related catchpoints. */ |
15659 | ops = &catch_solib_breakpoint_ops; | |
15660 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15661 | ops->insert_location = insert_catch_solib; |
15662 | ops->remove_location = remove_catch_solib; | |
15663 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15664 | ops->check_status = check_status_catch_solib; | |
15665 | ops->print_it = print_it_catch_solib; | |
15666 | ops->print_one = print_one_catch_solib; | |
15667 | ops->print_mention = print_mention_catch_solib; | |
15668 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15669 | |
15670 | ops = &dprintf_breakpoint_ops; | |
15671 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15672 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15673 | ops->resources_needed = bkpt_resources_needed; |
15674 | ops->print_it = bkpt_print_it; | |
15675 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15676 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15677 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15678 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15679 | } |
15680 | ||
8bfd80db YQ |
15681 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15682 | ||
15683 | static struct cmd_list_element *enablebreaklist = NULL; | |
15684 | ||
c906108c | 15685 | void |
fba45db2 | 15686 | _initialize_breakpoint (void) |
c906108c SS |
15687 | { |
15688 | struct cmd_list_element *c; | |
15689 | ||
2060206e PA |
15690 | initialize_breakpoint_ops (); |
15691 | ||
84acb35a | 15692 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15693 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15694 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15695 | |
55aa24fb SDJ |
15696 | breakpoint_objfile_key |
15697 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 15698 | |
c906108c SS |
15699 | breakpoint_chain = 0; |
15700 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15701 | before a breakpoint is set. */ | |
15702 | breakpoint_count = 0; | |
15703 | ||
1042e4c0 SS |
15704 | tracepoint_count = 0; |
15705 | ||
1bedd215 AC |
15706 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15707 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15708 | Usage is `ignore N COUNT'.")); | |
c906108c | 15709 | |
1bedd215 | 15710 | add_com ("commands", class_breakpoint, commands_command, _("\ |
18da0c51 MG |
15711 | Set commands to be executed when the given breakpoints are hit.\n\ |
15712 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15713 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15714 | (e.g. `5-7').\n\ | |
c906108c SS |
15715 | With no argument, the targeted breakpoint is the last one set.\n\ |
15716 | The commands themselves follow starting on the next line.\n\ | |
15717 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15718 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15719 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15720 | |
d55637df | 15721 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15722 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15723 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15724 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15725 | set_cmd_completer (c, condition_completer); |
c906108c | 15726 | |
1bedd215 | 15727 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15728 | Set a temporary breakpoint.\n\ |
c906108c SS |
15729 | Like \"break\" except the breakpoint is only temporary,\n\ |
15730 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15731 | by using \"enable delete\" on the breakpoint number.\n\ |
15732 | \n" | |
15733 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15734 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15735 | |
1bedd215 | 15736 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15737 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15738 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15739 | some target hardware may not have this support.\n\ |
15740 | \n" | |
15741 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15742 | set_cmd_completer (c, location_completer); |
c906108c | 15743 | |
1bedd215 | 15744 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15745 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15746 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15747 | so it will be deleted when hit.\n\ |
15748 | \n" | |
15749 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15750 | set_cmd_completer (c, location_completer); |
c906108c | 15751 | |
1bedd215 AC |
15752 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15753 | Enable some breakpoints.\n\ | |
c906108c SS |
15754 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15755 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15756 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15757 | With a subcommand you can enable temporarily."), |
c906108c | 15758 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15759 | |
15760 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15761 | ||
84951ab5 | 15762 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15763 | Enable some breakpoints.\n\ |
c906108c SS |
15764 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15765 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15766 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15767 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15768 | |
1a966eab AC |
15769 | add_cmd ("once", no_class, enable_once_command, _("\ |
15770 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15771 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15772 | &enablebreaklist); |
15773 | ||
1a966eab AC |
15774 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15775 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15776 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15777 | &enablebreaklist); |
15778 | ||
816338b5 SS |
15779 | add_cmd ("count", no_class, enable_count_command, _("\ |
15780 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15781 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15782 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15783 | &enablebreaklist); | |
15784 | ||
1a966eab AC |
15785 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15786 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15787 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15788 | &enablelist); |
15789 | ||
1a966eab AC |
15790 | add_cmd ("once", no_class, enable_once_command, _("\ |
15791 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15792 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15793 | &enablelist); |
15794 | ||
15795 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15796 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15797 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15798 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15799 | &enablelist); |
15800 | ||
1bedd215 AC |
15801 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15802 | Disable some breakpoints.\n\ | |
c906108c SS |
15803 | Arguments are breakpoint numbers with spaces in between.\n\ |
15804 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15805 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15806 | &disablelist, "disable ", 1, &cmdlist); |
15807 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15808 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15809 | |
1a966eab AC |
15810 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15811 | Disable some breakpoints.\n\ | |
c906108c SS |
15812 | Arguments are breakpoint numbers with spaces in between.\n\ |
15813 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15814 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15815 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15816 | &disablelist); |
15817 | ||
1bedd215 AC |
15818 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15819 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15820 | Arguments are breakpoint numbers with spaces in between.\n\ |
15821 | To delete all breakpoints, give no argument.\n\ | |
15822 | \n\ | |
15823 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15824 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15825 | &deletelist, "delete ", 1, &cmdlist); |
15826 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15827 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15828 | |
1a966eab AC |
15829 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15830 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15831 | Arguments are breakpoint numbers with spaces in between.\n\ |
15832 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15833 | This command may be abbreviated \"delete\"."), |
c906108c SS |
15834 | &deletelist); |
15835 | ||
1bedd215 | 15836 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
15837 | Clear breakpoint at specified location.\n\ |
15838 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
15839 | \n\ |
15840 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
15841 | is executing in.\n" |
15842 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 15843 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 15844 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 15845 | |
1bedd215 | 15846 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 15847 | Set breakpoint at specified location.\n" |
31e2b00f | 15848 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 15849 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15850 | |
c906108c SS |
15851 | add_com_alias ("b", "break", class_run, 1); |
15852 | add_com_alias ("br", "break", class_run, 1); | |
15853 | add_com_alias ("bre", "break", class_run, 1); | |
15854 | add_com_alias ("brea", "break", class_run, 1); | |
15855 | ||
c906108c SS |
15856 | if (dbx_commands) |
15857 | { | |
1bedd215 AC |
15858 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
15859 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
15860 | &stoplist, "stop ", 1, &cmdlist); |
15861 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 15862 | _("Break in function or address."), &stoplist); |
c5aa993b | 15863 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 15864 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 15865 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 15866 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
15867 | The \"Type\" column indicates one of:\n\ |
15868 | \tbreakpoint - normal breakpoint\n\ | |
15869 | \twatchpoint - watchpoint\n\ | |
15870 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15871 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15872 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15873 | address and file/line number respectively.\n\ |
15874 | \n\ | |
15875 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15876 | are set to the address of the last breakpoint listed unless the command\n\ |
15877 | is prefixed with \"server \".\n\n\ | |
c906108c | 15878 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15879 | breakpoint set.")); |
c906108c SS |
15880 | } |
15881 | ||
11db9430 | 15882 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 15883 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
15884 | The \"Type\" column indicates one of:\n\ |
15885 | \tbreakpoint - normal breakpoint\n\ | |
15886 | \twatchpoint - watchpoint\n\ | |
15887 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
15888 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
15889 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
15890 | address and file/line number respectively.\n\ |
15891 | \n\ | |
15892 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15893 | are set to the address of the last breakpoint listed unless the command\n\ |
15894 | is prefixed with \"server \".\n\n\ | |
c906108c | 15895 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 15896 | breakpoint set.")); |
c906108c | 15897 | |
6b04bdb7 MS |
15898 | add_info_alias ("b", "breakpoints", 1); |
15899 | ||
1a966eab AC |
15900 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
15901 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
15902 | The \"Type\" column indicates one of:\n\ |
15903 | \tbreakpoint - normal breakpoint\n\ | |
15904 | \twatchpoint - watchpoint\n\ | |
15905 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
15906 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
15907 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
15908 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
15909 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
15910 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
15911 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
15912 | address and file/line number respectively.\n\ |
15913 | \n\ | |
15914 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
15915 | are set to the address of the last breakpoint listed unless the command\n\ |
15916 | is prefixed with \"server \".\n\n\ | |
c906108c | 15917 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 15918 | breakpoint set."), |
c906108c SS |
15919 | &maintenanceinfolist); |
15920 | ||
44feb3ce TT |
15921 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
15922 | Set catchpoints to catch events."), | |
15923 | &catch_cmdlist, "catch ", | |
15924 | 0/*allow-unknown*/, &cmdlist); | |
15925 | ||
15926 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
15927 | Set temporary catchpoints to catch events."), | |
15928 | &tcatch_cmdlist, "tcatch ", | |
15929 | 0/*allow-unknown*/, &cmdlist); | |
15930 | ||
44feb3ce TT |
15931 | add_catch_command ("fork", _("Catch calls to fork."), |
15932 | catch_fork_command_1, | |
a96d9b2e | 15933 | NULL, |
44feb3ce TT |
15934 | (void *) (uintptr_t) catch_fork_permanent, |
15935 | (void *) (uintptr_t) catch_fork_temporary); | |
15936 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
15937 | catch_fork_command_1, | |
a96d9b2e | 15938 | NULL, |
44feb3ce TT |
15939 | (void *) (uintptr_t) catch_vfork_permanent, |
15940 | (void *) (uintptr_t) catch_vfork_temporary); | |
15941 | add_catch_command ("exec", _("Catch calls to exec."), | |
15942 | catch_exec_command_1, | |
a96d9b2e SDJ |
15943 | NULL, |
15944 | CATCH_PERMANENT, | |
15945 | CATCH_TEMPORARY); | |
edcc5120 TT |
15946 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
15947 | Usage: catch load [REGEX]\n\ | |
15948 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15949 | catch_load_command_1, | |
15950 | NULL, | |
15951 | CATCH_PERMANENT, | |
15952 | CATCH_TEMPORARY); | |
15953 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
15954 | Usage: catch unload [REGEX]\n\ | |
15955 | If REGEX is given, only stop for libraries matching the regular expression."), | |
15956 | catch_unload_command_1, | |
15957 | NULL, | |
15958 | CATCH_PERMANENT, | |
15959 | CATCH_TEMPORARY); | |
c5aa993b | 15960 | |
1bedd215 AC |
15961 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
15962 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15963 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 15964 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15965 | an expression changes.\n\ |
15966 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15967 | the memory to which it refers.")); | |
65d12d83 | 15968 | set_cmd_completer (c, expression_completer); |
c906108c | 15969 | |
1bedd215 AC |
15970 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
15971 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 15972 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 15973 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15974 | an expression is read.\n\ |
15975 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15976 | the memory to which it refers.")); | |
65d12d83 | 15977 | set_cmd_completer (c, expression_completer); |
c906108c | 15978 | |
1bedd215 AC |
15979 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
15980 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 15981 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 15982 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
15983 | an expression is either read or written.\n\ |
15984 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
15985 | the memory to which it refers.")); | |
65d12d83 | 15986 | set_cmd_completer (c, expression_completer); |
c906108c | 15987 | |
11db9430 | 15988 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 15989 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 15990 | |
920d2a44 AC |
15991 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
15992 | respond to changes - contrary to the description. */ | |
85c07804 AC |
15993 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
15994 | &can_use_hw_watchpoints, _("\ | |
15995 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
15996 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
15997 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
15998 | such is available. (However, any hardware watchpoints that were\n\ | |
15999 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16000 | hardware.)"), |
16001 | NULL, | |
920d2a44 | 16002 | show_can_use_hw_watchpoints, |
85c07804 | 16003 | &setlist, &showlist); |
c906108c SS |
16004 | |
16005 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16006 | |
1042e4c0 SS |
16007 | /* Tracepoint manipulation commands. */ |
16008 | ||
16009 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16010 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16011 | \n" |
16012 | BREAK_ARGS_HELP ("trace") "\n\ | |
16013 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16014 | set_cmd_completer (c, location_completer); | |
16015 | ||
16016 | add_com_alias ("tp", "trace", class_alias, 0); | |
16017 | add_com_alias ("tr", "trace", class_alias, 1); | |
16018 | add_com_alias ("tra", "trace", class_alias, 1); | |
16019 | add_com_alias ("trac", "trace", class_alias, 1); | |
16020 | ||
7a697b8d | 16021 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16022 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16023 | \n" |
16024 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16025 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16026 | set_cmd_completer (c, location_completer); | |
16027 | ||
0fb4aa4b | 16028 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16029 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16030 | \n\ |
16031 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16032 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16033 | or -m MARKER_ID.\n\n\ | |
16034 | If a marker id is specified, probe the marker with that name. With\n\ | |
16035 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16036 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16037 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16038 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16039 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16040 | \n\ | |
16041 | CONDITION is a boolean expression.\n\ | |
629500fa | 16042 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16043 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16044 | conditions are different.\n\ | |
0fb4aa4b PA |
16045 | \n\ |
16046 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16047 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16048 | set_cmd_completer (c, location_completer); | |
16049 | ||
11db9430 | 16050 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 16051 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16052 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16053 | last tracepoint set.")); | |
16054 | ||
16055 | add_info_alias ("tp", "tracepoints", 1); | |
16056 | ||
16057 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16058 | Delete specified tracepoints.\n\ | |
16059 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16060 | No argument means delete all tracepoints."), | |
16061 | &deletelist); | |
7e20dfcd | 16062 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16063 | |
16064 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16065 | Disable specified tracepoints.\n\ | |
16066 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16067 | No argument means disable all tracepoints."), | |
16068 | &disablelist); | |
16069 | deprecate_cmd (c, "disable"); | |
16070 | ||
16071 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16072 | Enable specified tracepoints.\n\ | |
16073 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16074 | No argument means enable all tracepoints."), | |
16075 | &enablelist); | |
16076 | deprecate_cmd (c, "enable"); | |
16077 | ||
16078 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16079 | Set the passcount for a tracepoint.\n\ | |
16080 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16081 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16082 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16083 | ||
6149aea9 PA |
16084 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16085 | _("Save breakpoint definitions as a script."), | |
16086 | &save_cmdlist, "save ", | |
16087 | 0/*allow-unknown*/, &cmdlist); | |
16088 | ||
16089 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16090 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16091 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16092 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16093 | session to restore them."), | |
16094 | &save_cmdlist); | |
16095 | set_cmd_completer (c, filename_completer); | |
16096 | ||
16097 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16098 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16099 | Use the 'source' command in another debug session to restore them."), |
16100 | &save_cmdlist); | |
1042e4c0 SS |
16101 | set_cmd_completer (c, filename_completer); |
16102 | ||
6149aea9 PA |
16103 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16104 | deprecate_cmd (c, "save tracepoints"); | |
16105 | ||
1bedd215 | 16106 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16107 | Breakpoint specific settings\n\ |
16108 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16109 | pending breakpoint behavior"), |
fa8d40ab JJ |
16110 | &breakpoint_set_cmdlist, "set breakpoint ", |
16111 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16112 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16113 | Breakpoint specific settings\n\ |
16114 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16115 | pending breakpoint behavior"), |
fa8d40ab JJ |
16116 | &breakpoint_show_cmdlist, "show breakpoint ", |
16117 | 0/*allow-unknown*/, &showlist); | |
16118 | ||
7915a72c AC |
16119 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16120 | &pending_break_support, _("\ | |
16121 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16122 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16123 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16124 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16125 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16126 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16127 | NULL, |
920d2a44 | 16128 | show_pending_break_support, |
6e1d7d6c AC |
16129 | &breakpoint_set_cmdlist, |
16130 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16131 | |
16132 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16133 | |
16134 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16135 | &automatic_hardware_breakpoints, _("\ | |
16136 | Set automatic usage of hardware breakpoints."), _("\ | |
16137 | Show automatic usage of hardware breakpoints."), _("\ | |
16138 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16139 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16140 | a warning will be emitted for such breakpoints."), | |
16141 | NULL, | |
16142 | show_automatic_hardware_breakpoints, | |
16143 | &breakpoint_set_cmdlist, | |
16144 | &breakpoint_show_cmdlist); | |
74960c60 | 16145 | |
a25a5a45 PA |
16146 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16147 | &always_inserted_mode, _("\ | |
74960c60 VP |
16148 | Set mode for inserting breakpoints."), _("\ |
16149 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16150 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16151 | they're created, kept inserted even when execution stops, and removed\n\ | |
16152 | only when the user deletes them. When this mode is off (the default),\n\ | |
16153 | breakpoints are inserted only when execution continues, and removed\n\ | |
16154 | when execution stops."), | |
72d0e2c5 YQ |
16155 | NULL, |
16156 | &show_always_inserted_mode, | |
16157 | &breakpoint_set_cmdlist, | |
16158 | &breakpoint_show_cmdlist); | |
f1310107 | 16159 | |
b775012e LM |
16160 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16161 | condition_evaluation_enums, | |
16162 | &condition_evaluation_mode_1, _("\ | |
16163 | Set mode of breakpoint condition evaluation."), _("\ | |
16164 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16165 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16166 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16167 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16168 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16169 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16170 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16171 | be set to \"gdb\""), | |
16172 | &set_condition_evaluation_mode, | |
16173 | &show_condition_evaluation_mode, | |
16174 | &breakpoint_set_cmdlist, | |
16175 | &breakpoint_show_cmdlist); | |
16176 | ||
f1310107 TJB |
16177 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16178 | Set a breakpoint for an address range.\n\ | |
16179 | break-range START-LOCATION, END-LOCATION\n\ | |
16180 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16181 | LINENUM, for that line in the current file,\n\ | |
16182 | FILE:LINENUM, for that line in that file,\n\ | |
16183 | +OFFSET, for that number of lines after the current line\n\ | |
16184 | or the start of the range\n\ | |
16185 | FUNCTION, for the first line in that function,\n\ | |
16186 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16187 | *ADDRESS, for the instruction at that address.\n\ | |
16188 | \n\ | |
16189 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16190 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16191 | range (including START-LOCATION and END-LOCATION).")); | |
16192 | ||
e7e0cddf | 16193 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16194 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16195 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16196 | location may be a linespec, explicit, or address location.\n" |
16197 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16198 | set_cmd_completer (c, location_completer); |
16199 | ||
16200 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16201 | dprintf_style_enums, &dprintf_style, _("\ | |
16202 | Set the style of usage for dynamic printf."), _("\ | |
16203 | Show the style of usage for dynamic printf."), _("\ | |
16204 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16205 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16206 | console, as with the \"printf\" command.\n\ | |
16207 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16208 | program; by default printf(), but you can choose a different function or\n\ | |
16209 | output stream by setting dprintf-function and dprintf-channel."), | |
16210 | update_dprintf_commands, NULL, | |
16211 | &setlist, &showlist); | |
16212 | ||
16213 | dprintf_function = xstrdup ("printf"); | |
16214 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16215 | &dprintf_function, _("\ | |
16216 | Set the function to use for dynamic printf"), _("\ | |
16217 | Show the function to use for dynamic printf"), NULL, | |
16218 | update_dprintf_commands, NULL, | |
16219 | &setlist, &showlist); | |
16220 | ||
16221 | dprintf_channel = xstrdup (""); | |
16222 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16223 | &dprintf_channel, _("\ | |
16224 | Set the channel to use for dynamic printf"), _("\ | |
16225 | Show the channel to use for dynamic printf"), NULL, | |
16226 | update_dprintf_commands, NULL, | |
16227 | &setlist, &showlist); | |
16228 | ||
d3ce09f5 SS |
16229 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16230 | &disconnected_dprintf, _("\ | |
16231 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16232 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16233 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16234 | even if GDB disconnects or detaches from the target."), | |
16235 | NULL, | |
16236 | NULL, | |
16237 | &setlist, &showlist); | |
16238 | ||
16239 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16240 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16241 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16242 | ||
765dc015 | 16243 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16244 | |
16245 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16246 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16247 | } |