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" |
104c1213 | 84 | |
e7e8980f YQ |
85 | /* Enums for exception-handling support. */ |
86 | enum exception_event_kind | |
87 | { | |
88 | EX_EVENT_THROW, | |
591f19e8 | 89 | EX_EVENT_RETHROW, |
e7e8980f YQ |
90 | EX_EVENT_CATCH |
91 | }; | |
92 | ||
4a64f543 | 93 | /* Prototypes for local functions. */ |
c906108c | 94 | |
a14ed312 | 95 | static void enable_delete_command (char *, int); |
c906108c | 96 | |
a14ed312 | 97 | static void enable_once_command (char *, int); |
c906108c | 98 | |
816338b5 SS |
99 | static void enable_count_command (char *, int); |
100 | ||
a14ed312 | 101 | static void disable_command (char *, int); |
c906108c | 102 | |
a14ed312 | 103 | static void enable_command (char *, int); |
c906108c | 104 | |
896b6bda PA |
105 | static void map_breakpoint_numbers (const char *, |
106 | void (*) (struct breakpoint *, | |
107 | void *), | |
95a42b64 | 108 | void *); |
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 | |
f00aae0f KS |
131 | static void decode_location_default (struct breakpoint *b, |
132 | const struct event_location *location, | |
c2f4122d | 133 | struct program_space *search_pspace, |
f00aae0f | 134 | struct symtabs_and_lines *sals); |
983af33b | 135 | |
a14ed312 | 136 | static void clear_command (char *, int); |
c906108c | 137 | |
a14ed312 | 138 | static void catch_command (char *, int); |
c906108c | 139 | |
a9634178 | 140 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 141 | |
98deb0da | 142 | static void break_command_1 (char *, int, int); |
c906108c | 143 | |
a14ed312 | 144 | static void mention (struct breakpoint *); |
c906108c | 145 | |
348d480f PA |
146 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
147 | enum bptype, | |
c0a91b2b | 148 | const struct breakpoint_ops *); |
3742cc8b YQ |
149 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
150 | const struct symtab_and_line *); | |
151 | ||
4a64f543 MS |
152 | /* This function is used in gdbtk sources and thus can not be made |
153 | static. */ | |
63c252f8 | 154 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 155 | struct symtab_and_line, |
c0a91b2b TT |
156 | enum bptype, |
157 | const struct breakpoint_ops *); | |
c906108c | 158 | |
06edf0c0 PA |
159 | static struct breakpoint * |
160 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
161 | enum bptype type, | |
a1aa2221 LM |
162 | const struct breakpoint_ops *ops, |
163 | int loc_enabled); | |
06edf0c0 | 164 | |
76897487 KB |
165 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
166 | ||
a6d9a66e UW |
167 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
168 | CORE_ADDR bpaddr, | |
88f7da05 | 169 | enum bptype bptype); |
76897487 | 170 | |
6c95b8df PA |
171 | static void describe_other_breakpoints (struct gdbarch *, |
172 | struct program_space *, CORE_ADDR, | |
5af949e3 | 173 | struct obj_section *, int); |
c906108c | 174 | |
85d721b8 PA |
175 | static int watchpoint_locations_match (struct bp_location *loc1, |
176 | struct bp_location *loc2); | |
177 | ||
f1310107 TJB |
178 | static int breakpoint_location_address_match (struct bp_location *bl, |
179 | struct address_space *aspace, | |
180 | CORE_ADDR addr); | |
181 | ||
d35ae833 PA |
182 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
183 | struct address_space *, | |
184 | CORE_ADDR, int); | |
185 | ||
a14ed312 | 186 | static void breakpoints_info (char *, int); |
c906108c | 187 | |
d77f58be SS |
188 | static void watchpoints_info (char *, int); |
189 | ||
e5a67952 MS |
190 | static int breakpoint_1 (char *, int, |
191 | int (*) (const struct breakpoint *)); | |
c906108c | 192 | |
4efb68b1 | 193 | static int breakpoint_cond_eval (void *); |
c906108c | 194 | |
4efb68b1 | 195 | static void cleanup_executing_breakpoints (void *); |
c906108c | 196 | |
a14ed312 | 197 | static void commands_command (char *, int); |
c906108c | 198 | |
a14ed312 | 199 | static void condition_command (char *, int); |
c906108c | 200 | |
834c0d03 | 201 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 202 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 203 | |
e514a9d6 | 204 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 205 | |
4efb68b1 | 206 | static int watchpoint_check (void *); |
c906108c | 207 | |
a14ed312 | 208 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 209 | |
a14ed312 | 210 | static int hw_breakpoint_used_count (void); |
c906108c | 211 | |
a1398e0c PA |
212 | static int hw_watchpoint_use_count (struct breakpoint *); |
213 | ||
214 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
215 | enum bptype type, | |
216 | int *other_type_used); | |
c906108c | 217 | |
a14ed312 | 218 | static void hbreak_command (char *, int); |
c906108c | 219 | |
a14ed312 | 220 | static void thbreak_command (char *, int); |
c906108c | 221 | |
816338b5 SS |
222 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
223 | int count); | |
c906108c | 224 | |
a14ed312 | 225 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 226 | |
a14ed312 | 227 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 228 | |
a14ed312 | 229 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 230 | |
a14ed312 | 231 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 232 | |
fe3f5fa8 | 233 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
234 | static void incref_bp_location (struct bp_location *loc); |
235 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 236 | |
39d61571 | 237 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 238 | |
44702360 PA |
239 | /* update_global_location_list's modes of operation wrt to whether to |
240 | insert locations now. */ | |
241 | enum ugll_insert_mode | |
242 | { | |
243 | /* Don't insert any breakpoint locations into the inferior, only | |
244 | remove already-inserted locations that no longer should be | |
245 | inserted. Functions that delete a breakpoint or breakpoints | |
246 | should specify this mode, so that deleting a breakpoint doesn't | |
247 | have the side effect of inserting the locations of other | |
248 | breakpoints that are marked not-inserted, but should_be_inserted | |
249 | returns true on them. | |
250 | ||
251 | This behavior is useful is situations close to tear-down -- e.g., | |
252 | after an exec, while the target still has execution, but | |
253 | breakpoint shadows of the previous executable image should *NOT* | |
254 | be restored to the new image; or before detaching, where the | |
255 | target still has execution and wants to delete breakpoints from | |
256 | GDB's lists, and all breakpoints had already been removed from | |
257 | the inferior. */ | |
258 | UGLL_DONT_INSERT, | |
259 | ||
a25a5a45 PA |
260 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
261 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
262 | UGLL_MAY_INSERT, |
263 | ||
a25a5a45 PA |
264 | /* Insert locations now, irrespective of |
265 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
266 | stopped right now, and the user did "continue". We need to | |
267 | insert breakpoints _before_ resuming the target, but | |
268 | UGLL_MAY_INSERT wouldn't insert them, because | |
269 | breakpoints_should_be_inserted_now returns false at that point, | |
270 | as no thread is running yet. */ | |
04086b45 | 271 | UGLL_INSERT |
44702360 PA |
272 | }; |
273 | ||
274 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 275 | |
44702360 | 276 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 277 | |
d77f58be | 278 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
279 | |
280 | static void insert_breakpoint_locations (void); | |
a5606eee | 281 | |
1042e4c0 SS |
282 | static void tracepoints_info (char *, int); |
283 | ||
284 | static void delete_trace_command (char *, int); | |
285 | ||
286 | static void enable_trace_command (char *, int); | |
287 | ||
288 | static void disable_trace_command (char *, int); | |
289 | ||
290 | static void trace_pass_command (char *, int); | |
291 | ||
558a9d82 YQ |
292 | static void set_tracepoint_count (int num); |
293 | ||
9c06b0b4 TJB |
294 | static int is_masked_watchpoint (const struct breakpoint *b); |
295 | ||
b775012e LM |
296 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
297 | ||
983af33b SDJ |
298 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
299 | otherwise. */ | |
300 | ||
301 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 302 | |
2060206e PA |
303 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
304 | that are implemented on top of software or hardware breakpoints | |
305 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
306 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
307 | ||
308 | /* Internal breakpoints class type. */ | |
06edf0c0 | 309 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
310 | |
311 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
312 | static struct breakpoint_ops momentary_breakpoint_ops; |
313 | ||
2060206e PA |
314 | /* The breakpoint_ops structure to be used in regular user created |
315 | breakpoints. */ | |
316 | struct breakpoint_ops bkpt_breakpoint_ops; | |
317 | ||
55aa24fb SDJ |
318 | /* Breakpoints set on probes. */ |
319 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
320 | ||
e7e0cddf | 321 | /* Dynamic printf class type. */ |
c5867ab6 | 322 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 323 | |
d3ce09f5 SS |
324 | /* The style in which to perform a dynamic printf. This is a user |
325 | option because different output options have different tradeoffs; | |
326 | if GDB does the printing, there is better error handling if there | |
327 | is a problem with any of the arguments, but using an inferior | |
328 | function lets you have special-purpose printers and sending of | |
329 | output to the same place as compiled-in print functions. */ | |
330 | ||
331 | static const char dprintf_style_gdb[] = "gdb"; | |
332 | static const char dprintf_style_call[] = "call"; | |
333 | static const char dprintf_style_agent[] = "agent"; | |
334 | static const char *const dprintf_style_enums[] = { | |
335 | dprintf_style_gdb, | |
336 | dprintf_style_call, | |
337 | dprintf_style_agent, | |
338 | NULL | |
339 | }; | |
340 | static const char *dprintf_style = dprintf_style_gdb; | |
341 | ||
342 | /* The function to use for dynamic printf if the preferred style is to | |
343 | call into the inferior. The value is simply a string that is | |
344 | copied into the command, so it can be anything that GDB can | |
345 | evaluate to a callable address, not necessarily a function name. */ | |
346 | ||
bde6261a | 347 | static char *dprintf_function; |
d3ce09f5 SS |
348 | |
349 | /* The channel to use for dynamic printf if the preferred style is to | |
350 | call into the inferior; if a nonempty string, it will be passed to | |
351 | the call as the first argument, with the format string as the | |
352 | second. As with the dprintf function, this can be anything that | |
353 | GDB knows how to evaluate, so in addition to common choices like | |
354 | "stderr", this could be an app-specific expression like | |
355 | "mystreams[curlogger]". */ | |
356 | ||
bde6261a | 357 | static char *dprintf_channel; |
d3ce09f5 SS |
358 | |
359 | /* True if dprintf commands should continue to operate even if GDB | |
360 | has disconnected. */ | |
361 | static int disconnected_dprintf = 1; | |
362 | ||
5cea2a26 PA |
363 | /* A reference-counted struct command_line. This lets multiple |
364 | breakpoints share a single command list. */ | |
365 | struct counted_command_line | |
366 | { | |
367 | /* The reference count. */ | |
368 | int refc; | |
369 | ||
370 | /* The command list. */ | |
371 | struct command_line *commands; | |
372 | }; | |
373 | ||
374 | struct command_line * | |
375 | breakpoint_commands (struct breakpoint *b) | |
376 | { | |
377 | return b->commands ? b->commands->commands : NULL; | |
378 | } | |
3daf8fe5 | 379 | |
f3b1572e PA |
380 | /* Flag indicating that a command has proceeded the inferior past the |
381 | current breakpoint. */ | |
382 | ||
383 | static int breakpoint_proceeded; | |
384 | ||
956a9fb9 | 385 | const char * |
2cec12e5 AR |
386 | bpdisp_text (enum bpdisp disp) |
387 | { | |
4a64f543 MS |
388 | /* NOTE: the following values are a part of MI protocol and |
389 | represent values of 'disp' field returned when inferior stops at | |
390 | a breakpoint. */ | |
bc043ef3 | 391 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 392 | |
2cec12e5 AR |
393 | return bpdisps[(int) disp]; |
394 | } | |
c906108c | 395 | |
4a64f543 | 396 | /* Prototypes for exported functions. */ |
c906108c | 397 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 398 | if such is available. */ |
c906108c SS |
399 | static int can_use_hw_watchpoints; |
400 | ||
920d2a44 AC |
401 | static void |
402 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
403 | struct cmd_list_element *c, | |
404 | const char *value) | |
405 | { | |
3e43a32a MS |
406 | fprintf_filtered (file, |
407 | _("Debugger's willingness to use " | |
408 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
409 | value); |
410 | } | |
411 | ||
fa8d40ab JJ |
412 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
413 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 414 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
415 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
416 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
417 | static void |
418 | show_pending_break_support (struct ui_file *file, int from_tty, | |
419 | struct cmd_list_element *c, | |
420 | const char *value) | |
421 | { | |
3e43a32a MS |
422 | fprintf_filtered (file, |
423 | _("Debugger's behavior regarding " | |
424 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
425 | value); |
426 | } | |
fa8d40ab | 427 | |
765dc015 | 428 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 429 | set with "break" but falling in read-only memory. |
765dc015 VP |
430 | If 0, gdb will warn about such breakpoints, but won't automatically |
431 | use hardware breakpoints. */ | |
432 | static int automatic_hardware_breakpoints; | |
433 | static void | |
434 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
435 | struct cmd_list_element *c, | |
436 | const char *value) | |
437 | { | |
3e43a32a MS |
438 | fprintf_filtered (file, |
439 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
440 | value); |
441 | } | |
442 | ||
a25a5a45 PA |
443 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
444 | stopped, and immediately inserts any new breakpoints as soon as | |
445 | they're created. If off (default), GDB keeps breakpoints off of | |
446 | the target as long as possible. That is, it delays inserting | |
447 | breakpoints until the next resume, and removes them again when the | |
448 | target fully stops. This is a bit safer in case GDB crashes while | |
449 | processing user input. */ | |
450 | static int always_inserted_mode = 0; | |
72d0e2c5 | 451 | |
33e5cbd6 | 452 | static void |
74960c60 | 453 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 454 | struct cmd_list_element *c, const char *value) |
74960c60 | 455 | { |
a25a5a45 PA |
456 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
457 | value); | |
74960c60 VP |
458 | } |
459 | ||
b57bacec PA |
460 | /* See breakpoint.h. */ |
461 | ||
33e5cbd6 | 462 | int |
a25a5a45 | 463 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 464 | { |
a25a5a45 PA |
465 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
466 | { | |
467 | /* If breakpoints are global, they should be inserted even if no | |
468 | thread under gdb's control is running, or even if there are | |
469 | no threads under GDB's control yet. */ | |
470 | return 1; | |
471 | } | |
472 | else if (target_has_execution) | |
473 | { | |
372316f1 PA |
474 | struct thread_info *tp; |
475 | ||
a25a5a45 PA |
476 | if (always_inserted_mode) |
477 | { | |
478 | /* The user wants breakpoints inserted even if all threads | |
479 | are stopped. */ | |
480 | return 1; | |
481 | } | |
482 | ||
b57bacec PA |
483 | if (threads_are_executing ()) |
484 | return 1; | |
372316f1 PA |
485 | |
486 | /* Don't remove breakpoints yet if, even though all threads are | |
487 | stopped, we still have events to process. */ | |
488 | ALL_NON_EXITED_THREADS (tp) | |
489 | if (tp->resumed | |
490 | && tp->suspend.waitstatus_pending_p) | |
491 | return 1; | |
a25a5a45 PA |
492 | } |
493 | return 0; | |
33e5cbd6 | 494 | } |
765dc015 | 495 | |
b775012e LM |
496 | static const char condition_evaluation_both[] = "host or target"; |
497 | ||
498 | /* Modes for breakpoint condition evaluation. */ | |
499 | static const char condition_evaluation_auto[] = "auto"; | |
500 | static const char condition_evaluation_host[] = "host"; | |
501 | static const char condition_evaluation_target[] = "target"; | |
502 | static const char *const condition_evaluation_enums[] = { | |
503 | condition_evaluation_auto, | |
504 | condition_evaluation_host, | |
505 | condition_evaluation_target, | |
506 | NULL | |
507 | }; | |
508 | ||
509 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
510 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
511 | ||
512 | /* Global that we use to display information to the user (gets its value from | |
513 | condition_evaluation_mode_1. */ | |
514 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
515 | ||
516 | /* Translate a condition evaluation mode MODE into either "host" | |
517 | or "target". This is used mostly to translate from "auto" to the | |
518 | real setting that is being used. It returns the translated | |
519 | evaluation mode. */ | |
520 | ||
521 | static const char * | |
522 | translate_condition_evaluation_mode (const char *mode) | |
523 | { | |
524 | if (mode == condition_evaluation_auto) | |
525 | { | |
526 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
527 | return condition_evaluation_target; | |
528 | else | |
529 | return condition_evaluation_host; | |
530 | } | |
531 | else | |
532 | return mode; | |
533 | } | |
534 | ||
535 | /* Discovers what condition_evaluation_auto translates to. */ | |
536 | ||
537 | static const char * | |
538 | breakpoint_condition_evaluation_mode (void) | |
539 | { | |
540 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
541 | } | |
542 | ||
543 | /* Return true if GDB should evaluate breakpoint conditions or false | |
544 | otherwise. */ | |
545 | ||
546 | static int | |
547 | gdb_evaluates_breakpoint_condition_p (void) | |
548 | { | |
549 | const char *mode = breakpoint_condition_evaluation_mode (); | |
550 | ||
551 | return (mode == condition_evaluation_host); | |
552 | } | |
553 | ||
a14ed312 | 554 | void _initialize_breakpoint (void); |
c906108c | 555 | |
c906108c SS |
556 | /* Are we executing breakpoint commands? */ |
557 | static int executing_breakpoint_commands; | |
558 | ||
c02f5703 MS |
559 | /* Are overlay event breakpoints enabled? */ |
560 | static int overlay_events_enabled; | |
561 | ||
e09342b5 TJB |
562 | /* See description in breakpoint.h. */ |
563 | int target_exact_watchpoints = 0; | |
564 | ||
c906108c | 565 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 566 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 567 | current breakpoint. */ |
c906108c | 568 | |
5c44784c | 569 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 570 | |
5c44784c JM |
571 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
572 | for (B = breakpoint_chain; \ | |
573 | B ? (TMP=B->next, 1): 0; \ | |
574 | B = TMP) | |
c906108c | 575 | |
4a64f543 MS |
576 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
577 | not provided so update_global_location_list must not be called | |
578 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 579 | |
876fa593 | 580 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
581 | for (BP_TMP = bp_locations; \ |
582 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 583 | BP_TMP++) |
7cc221ef | 584 | |
b775012e LM |
585 | /* Iterates through locations with address ADDRESS for the currently selected |
586 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
587 | to where the loop should start from. | |
588 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
589 | appropriate location to start with. */ | |
590 | ||
591 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
592 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
593 | BP_LOCP_TMP = BP_LOCP_START; \ | |
594 | BP_LOCP_START \ | |
f5336ca5 | 595 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
596 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
597 | BP_LOCP_TMP++) | |
598 | ||
1042e4c0 SS |
599 | /* Iterator for tracepoints only. */ |
600 | ||
601 | #define ALL_TRACEPOINTS(B) \ | |
602 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 603 | if (is_tracepoint (B)) |
1042e4c0 | 604 | |
7cc221ef | 605 | /* Chains of all breakpoints defined. */ |
c906108c SS |
606 | |
607 | struct breakpoint *breakpoint_chain; | |
608 | ||
f5336ca5 | 609 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 610 | |
f5336ca5 | 611 | static struct bp_location **bp_locations; |
876fa593 | 612 | |
f5336ca5 | 613 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 614 | |
f5336ca5 | 615 | static unsigned bp_locations_count; |
876fa593 | 616 | |
4a64f543 | 617 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 618 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 619 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 620 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 621 | an address you need to read. */ |
876fa593 | 622 | |
f5336ca5 | 623 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 624 | |
4a64f543 MS |
625 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
626 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
627 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
628 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 629 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 630 | |
f5336ca5 | 631 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 632 | |
4a64f543 | 633 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
634 | from the bp_locations array, but for which a hit may still be |
635 | reported by a target. */ | |
20874c92 VP |
636 | VEC(bp_location_p) *moribund_locations = NULL; |
637 | ||
c906108c SS |
638 | /* Number of last breakpoint made. */ |
639 | ||
95a42b64 TT |
640 | static int breakpoint_count; |
641 | ||
86b17b60 PA |
642 | /* The value of `breakpoint_count' before the last command that |
643 | created breakpoints. If the last (break-like) command created more | |
644 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
645 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
646 | static int prev_breakpoint_count; | |
c906108c | 647 | |
1042e4c0 SS |
648 | /* Number of last tracepoint made. */ |
649 | ||
95a42b64 | 650 | static int tracepoint_count; |
1042e4c0 | 651 | |
6149aea9 PA |
652 | static struct cmd_list_element *breakpoint_set_cmdlist; |
653 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 654 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 655 | |
badd37ce SDJ |
656 | /* See declaration at breakpoint.h. */ |
657 | ||
658 | struct breakpoint * | |
659 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
660 | void *user_data) | |
661 | { | |
662 | struct breakpoint *b = NULL; | |
663 | ||
664 | ALL_BREAKPOINTS (b) | |
665 | { | |
666 | if (func (b, user_data) != 0) | |
667 | break; | |
668 | } | |
669 | ||
670 | return b; | |
671 | } | |
672 | ||
468d015d JJ |
673 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
674 | static int | |
675 | breakpoint_enabled (struct breakpoint *b) | |
676 | { | |
0d381245 | 677 | return (b->enable_state == bp_enabled); |
468d015d JJ |
678 | } |
679 | ||
c906108c SS |
680 | /* Set breakpoint count to NUM. */ |
681 | ||
95a42b64 | 682 | static void |
fba45db2 | 683 | set_breakpoint_count (int num) |
c906108c | 684 | { |
86b17b60 | 685 | prev_breakpoint_count = breakpoint_count; |
c906108c | 686 | breakpoint_count = num; |
4fa62494 | 687 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
688 | } |
689 | ||
86b17b60 PA |
690 | /* Used by `start_rbreak_breakpoints' below, to record the current |
691 | breakpoint count before "rbreak" creates any breakpoint. */ | |
692 | static int rbreak_start_breakpoint_count; | |
693 | ||
95a42b64 TT |
694 | /* Called at the start an "rbreak" command to record the first |
695 | breakpoint made. */ | |
86b17b60 | 696 | |
95a42b64 TT |
697 | void |
698 | start_rbreak_breakpoints (void) | |
699 | { | |
86b17b60 | 700 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
701 | } |
702 | ||
703 | /* Called at the end of an "rbreak" command to record the last | |
704 | breakpoint made. */ | |
86b17b60 | 705 | |
95a42b64 TT |
706 | void |
707 | end_rbreak_breakpoints (void) | |
708 | { | |
86b17b60 | 709 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
710 | } |
711 | ||
4a64f543 | 712 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
713 | |
714 | void | |
fba45db2 | 715 | clear_breakpoint_hit_counts (void) |
c906108c SS |
716 | { |
717 | struct breakpoint *b; | |
718 | ||
719 | ALL_BREAKPOINTS (b) | |
720 | b->hit_count = 0; | |
721 | } | |
722 | ||
9add0f1b TT |
723 | /* Allocate a new counted_command_line with reference count of 1. |
724 | The new structure owns COMMANDS. */ | |
725 | ||
726 | static struct counted_command_line * | |
727 | alloc_counted_command_line (struct command_line *commands) | |
728 | { | |
8d749320 | 729 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 730 | |
9add0f1b TT |
731 | result->refc = 1; |
732 | result->commands = commands; | |
8d749320 | 733 | |
9add0f1b TT |
734 | return result; |
735 | } | |
736 | ||
737 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
738 | ||
739 | static void | |
740 | incref_counted_command_line (struct counted_command_line *cmd) | |
741 | { | |
742 | if (cmd) | |
743 | ++cmd->refc; | |
744 | } | |
745 | ||
746 | /* Decrement reference count. If the reference count reaches 0, | |
747 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
748 | nothing if *CMDP is NULL. */ | |
749 | ||
750 | static void | |
751 | decref_counted_command_line (struct counted_command_line **cmdp) | |
752 | { | |
753 | if (*cmdp) | |
754 | { | |
755 | if (--(*cmdp)->refc == 0) | |
756 | { | |
757 | free_command_lines (&(*cmdp)->commands); | |
758 | xfree (*cmdp); | |
759 | } | |
760 | *cmdp = NULL; | |
761 | } | |
762 | } | |
763 | ||
764 | /* A cleanup function that calls decref_counted_command_line. */ | |
765 | ||
766 | static void | |
767 | do_cleanup_counted_command_line (void *arg) | |
768 | { | |
9a3c8263 | 769 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
770 | } |
771 | ||
772 | /* Create a cleanup that calls decref_counted_command_line on the | |
773 | argument. */ | |
774 | ||
775 | static struct cleanup * | |
776 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
777 | { | |
778 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
779 | } | |
780 | ||
c906108c | 781 | \f |
48cb2d85 VP |
782 | /* Return the breakpoint with the specified number, or NULL |
783 | if the number does not refer to an existing breakpoint. */ | |
784 | ||
785 | struct breakpoint * | |
786 | get_breakpoint (int num) | |
787 | { | |
788 | struct breakpoint *b; | |
789 | ||
790 | ALL_BREAKPOINTS (b) | |
791 | if (b->number == num) | |
792 | return b; | |
793 | ||
794 | return NULL; | |
795 | } | |
5c44784c | 796 | |
c906108c | 797 | \f |
adc36818 | 798 | |
b775012e LM |
799 | /* Mark locations as "conditions have changed" in case the target supports |
800 | evaluating conditions on its side. */ | |
801 | ||
802 | static void | |
803 | mark_breakpoint_modified (struct breakpoint *b) | |
804 | { | |
805 | struct bp_location *loc; | |
806 | ||
807 | /* This is only meaningful if the target is | |
808 | evaluating conditions and if the user has | |
809 | opted for condition evaluation on the target's | |
810 | side. */ | |
811 | if (gdb_evaluates_breakpoint_condition_p () | |
812 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
813 | return; | |
814 | ||
815 | if (!is_breakpoint (b)) | |
816 | return; | |
817 | ||
818 | for (loc = b->loc; loc; loc = loc->next) | |
819 | loc->condition_changed = condition_modified; | |
820 | } | |
821 | ||
822 | /* Mark location as "conditions have changed" in case the target supports | |
823 | evaluating conditions on its side. */ | |
824 | ||
825 | static void | |
826 | mark_breakpoint_location_modified (struct bp_location *loc) | |
827 | { | |
828 | /* This is only meaningful if the target is | |
829 | evaluating conditions and if the user has | |
830 | opted for condition evaluation on the target's | |
831 | side. */ | |
832 | if (gdb_evaluates_breakpoint_condition_p () | |
833 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
834 | ||
835 | return; | |
836 | ||
837 | if (!is_breakpoint (loc->owner)) | |
838 | return; | |
839 | ||
840 | loc->condition_changed = condition_modified; | |
841 | } | |
842 | ||
843 | /* Sets the condition-evaluation mode using the static global | |
844 | condition_evaluation_mode. */ | |
845 | ||
846 | static void | |
847 | set_condition_evaluation_mode (char *args, int from_tty, | |
848 | struct cmd_list_element *c) | |
849 | { | |
b775012e LM |
850 | const char *old_mode, *new_mode; |
851 | ||
852 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
853 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
854 | { | |
855 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
856 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
857 | "Using host evaluation mode instead.")); | |
858 | return; | |
859 | } | |
860 | ||
861 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
862 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
863 | ||
abf1152a JK |
864 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
865 | settings was "auto". */ | |
866 | condition_evaluation_mode = condition_evaluation_mode_1; | |
867 | ||
b775012e LM |
868 | /* Only update the mode if the user picked a different one. */ |
869 | if (new_mode != old_mode) | |
870 | { | |
871 | struct bp_location *loc, **loc_tmp; | |
872 | /* If the user switched to a different evaluation mode, we | |
873 | need to synch the changes with the target as follows: | |
874 | ||
875 | "host" -> "target": Send all (valid) conditions to the target. | |
876 | "target" -> "host": Remove all the conditions from the target. | |
877 | */ | |
878 | ||
b775012e LM |
879 | if (new_mode == condition_evaluation_target) |
880 | { | |
881 | /* Mark everything modified and synch conditions with the | |
882 | target. */ | |
883 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
884 | mark_breakpoint_location_modified (loc); | |
885 | } | |
886 | else | |
887 | { | |
888 | /* Manually mark non-duplicate locations to synch conditions | |
889 | with the target. We do this to remove all the conditions the | |
890 | target knows about. */ | |
891 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
892 | if (is_breakpoint (loc->owner) && loc->inserted) | |
893 | loc->needs_update = 1; | |
894 | } | |
895 | ||
896 | /* Do the update. */ | |
44702360 | 897 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
898 | } |
899 | ||
900 | return; | |
901 | } | |
902 | ||
903 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
904 | what "auto" is translating to. */ | |
905 | ||
906 | static void | |
907 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
908 | struct cmd_list_element *c, const char *value) | |
909 | { | |
910 | if (condition_evaluation_mode == condition_evaluation_auto) | |
911 | fprintf_filtered (file, | |
912 | _("Breakpoint condition evaluation " | |
913 | "mode is %s (currently %s).\n"), | |
914 | value, | |
915 | breakpoint_condition_evaluation_mode ()); | |
916 | else | |
917 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
918 | value); | |
919 | } | |
920 | ||
921 | /* A comparison function for bp_location AP and BP that is used by | |
922 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 923 | the more general bp_locations_compare function. */ |
b775012e LM |
924 | |
925 | static int | |
f5336ca5 | 926 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 927 | { |
9a3c8263 SM |
928 | const struct bp_location *a = *(const struct bp_location **) ap; |
929 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
930 | |
931 | if (a->address == b->address) | |
932 | return 0; | |
933 | else | |
934 | return ((a->address > b->address) - (a->address < b->address)); | |
935 | } | |
936 | ||
937 | /* Helper function to skip all bp_locations with addresses | |
938 | less than ADDRESS. It returns the first bp_location that | |
939 | is greater than or equal to ADDRESS. If none is found, just | |
940 | return NULL. */ | |
941 | ||
942 | static struct bp_location ** | |
943 | get_first_locp_gte_addr (CORE_ADDR address) | |
944 | { | |
945 | struct bp_location dummy_loc; | |
946 | struct bp_location *dummy_locp = &dummy_loc; | |
947 | struct bp_location **locp_found = NULL; | |
948 | ||
949 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
950 | dummy_loc.address = address; |
951 | ||
952 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 953 | locp_found = ((struct bp_location **) |
f5336ca5 | 954 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 955 | sizeof (struct bp_location **), |
f5336ca5 | 956 | bp_locations_compare_addrs)); |
b775012e LM |
957 | |
958 | /* Nothing was found, nothing left to do. */ | |
959 | if (locp_found == NULL) | |
960 | return NULL; | |
961 | ||
962 | /* We may have found a location that is at ADDRESS but is not the first in the | |
963 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 964 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
965 | && (*(locp_found - 1))->address == address) |
966 | locp_found--; | |
967 | ||
968 | return locp_found; | |
969 | } | |
970 | ||
adc36818 | 971 | void |
7a26bd4d | 972 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
973 | int from_tty) |
974 | { | |
3a5c3e22 PA |
975 | xfree (b->cond_string); |
976 | b->cond_string = NULL; | |
adc36818 | 977 | |
3a5c3e22 | 978 | if (is_watchpoint (b)) |
adc36818 | 979 | { |
3a5c3e22 PA |
980 | struct watchpoint *w = (struct watchpoint *) b; |
981 | ||
4d01a485 | 982 | w->cond_exp.reset (); |
3a5c3e22 PA |
983 | } |
984 | else | |
985 | { | |
986 | struct bp_location *loc; | |
987 | ||
988 | for (loc = b->loc; loc; loc = loc->next) | |
989 | { | |
4d01a485 | 990 | loc->cond.reset (); |
b775012e LM |
991 | |
992 | /* No need to free the condition agent expression | |
993 | bytecode (if we have one). We will handle this | |
994 | when we go through update_global_location_list. */ | |
3a5c3e22 | 995 | } |
adc36818 | 996 | } |
adc36818 PM |
997 | |
998 | if (*exp == 0) | |
999 | { | |
1000 | if (from_tty) | |
1001 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1002 | } | |
1003 | else | |
1004 | { | |
bbc13ae3 | 1005 | const char *arg = exp; |
cc59ec59 | 1006 | |
adc36818 PM |
1007 | /* I don't know if it matters whether this is the string the user |
1008 | typed in or the decompiled expression. */ | |
1009 | b->cond_string = xstrdup (arg); | |
1010 | b->condition_not_parsed = 0; | |
1011 | ||
1012 | if (is_watchpoint (b)) | |
1013 | { | |
3a5c3e22 PA |
1014 | struct watchpoint *w = (struct watchpoint *) b; |
1015 | ||
adc36818 PM |
1016 | innermost_block = NULL; |
1017 | arg = exp; | |
1bb9788d | 1018 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1019 | if (*arg) |
1020 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1021 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1022 | } |
1023 | else | |
1024 | { | |
3a5c3e22 PA |
1025 | struct bp_location *loc; |
1026 | ||
adc36818 PM |
1027 | for (loc = b->loc; loc; loc = loc->next) |
1028 | { | |
1029 | arg = exp; | |
1030 | loc->cond = | |
1bb9788d TT |
1031 | parse_exp_1 (&arg, loc->address, |
1032 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1033 | if (*arg) |
1034 | error (_("Junk at end of expression")); | |
1035 | } | |
1036 | } | |
1037 | } | |
b775012e LM |
1038 | mark_breakpoint_modified (b); |
1039 | ||
8d3788bd | 1040 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1041 | } |
1042 | ||
d55637df TT |
1043 | /* Completion for the "condition" command. */ |
1044 | ||
1045 | static VEC (char_ptr) * | |
6f937416 PA |
1046 | condition_completer (struct cmd_list_element *cmd, |
1047 | const char *text, const char *word) | |
d55637df | 1048 | { |
6f937416 | 1049 | const char *space; |
d55637df | 1050 | |
6f937416 PA |
1051 | text = skip_spaces_const (text); |
1052 | space = skip_to_space_const (text); | |
d55637df TT |
1053 | if (*space == '\0') |
1054 | { | |
1055 | int len; | |
1056 | struct breakpoint *b; | |
1057 | VEC (char_ptr) *result = NULL; | |
1058 | ||
1059 | if (text[0] == '$') | |
1060 | { | |
1061 | /* We don't support completion of history indices. */ | |
1062 | if (isdigit (text[1])) | |
1063 | return NULL; | |
1064 | return complete_internalvar (&text[1]); | |
1065 | } | |
1066 | ||
1067 | /* We're completing the breakpoint number. */ | |
1068 | len = strlen (text); | |
1069 | ||
1070 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1071 | { |
1072 | char number[50]; | |
1073 | ||
1074 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1075 | ||
1076 | if (strncmp (number, text, len) == 0) | |
1077 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1078 | } | |
d55637df TT |
1079 | |
1080 | return result; | |
1081 | } | |
1082 | ||
1083 | /* We're completing the expression part. */ | |
6f937416 | 1084 | text = skip_spaces_const (space); |
d55637df TT |
1085 | return expression_completer (cmd, text, word); |
1086 | } | |
1087 | ||
c906108c SS |
1088 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1089 | ||
1090 | static void | |
fba45db2 | 1091 | condition_command (char *arg, int from_tty) |
c906108c | 1092 | { |
52f0bd74 | 1093 | struct breakpoint *b; |
c906108c | 1094 | char *p; |
52f0bd74 | 1095 | int bnum; |
c906108c SS |
1096 | |
1097 | if (arg == 0) | |
e2e0b3e5 | 1098 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1099 | |
1100 | p = arg; | |
1101 | bnum = get_number (&p); | |
5c44784c | 1102 | if (bnum == 0) |
8a3fe4f8 | 1103 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1104 | |
1105 | ALL_BREAKPOINTS (b) | |
1106 | if (b->number == bnum) | |
2f069f6f | 1107 | { |
6dddc817 DE |
1108 | /* Check if this breakpoint has a "stop" method implemented in an |
1109 | extension language. This method and conditions entered into GDB | |
1110 | from the CLI are mutually exclusive. */ | |
1111 | const struct extension_language_defn *extlang | |
1112 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1113 | ||
1114 | if (extlang != NULL) | |
1115 | { | |
1116 | error (_("Only one stop condition allowed. There is currently" | |
1117 | " a %s stop condition defined for this breakpoint."), | |
1118 | ext_lang_capitalized_name (extlang)); | |
1119 | } | |
2566ad2d | 1120 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1121 | |
1122 | if (is_breakpoint (b)) | |
44702360 | 1123 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1124 | |
2f069f6f JB |
1125 | return; |
1126 | } | |
c906108c | 1127 | |
8a3fe4f8 | 1128 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1129 | } |
1130 | ||
a7bdde9e VP |
1131 | /* Check that COMMAND do not contain commands that are suitable |
1132 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1133 | Throw if any such commands is found. */ |
1134 | ||
a7bdde9e VP |
1135 | static void |
1136 | check_no_tracepoint_commands (struct command_line *commands) | |
1137 | { | |
1138 | struct command_line *c; | |
cc59ec59 | 1139 | |
a7bdde9e VP |
1140 | for (c = commands; c; c = c->next) |
1141 | { | |
1142 | int i; | |
1143 | ||
1144 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1145 | error (_("The 'while-stepping' command can " |
1146 | "only be used for tracepoints")); | |
a7bdde9e VP |
1147 | |
1148 | for (i = 0; i < c->body_count; ++i) | |
1149 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1150 | ||
1151 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1152 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1153 | command directly. */ |
1154 | if (strstr (c->line, "collect ") == c->line) | |
1155 | error (_("The 'collect' command can only be used for tracepoints")); | |
1156 | ||
51661e93 VP |
1157 | if (strstr (c->line, "teval ") == c->line) |
1158 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1159 | } |
1160 | } | |
1161 | ||
c1fc2657 | 1162 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1163 | { |
c1fc2657 | 1164 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1165 | }; |
1166 | ||
d77f58be SS |
1167 | /* Encapsulate tests for different types of tracepoints. */ |
1168 | ||
3b0871f4 SM |
1169 | static bool |
1170 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1171 | { |
1172 | return (type == bp_tracepoint | |
1173 | || type == bp_fast_tracepoint | |
1174 | || type == bp_static_tracepoint); | |
1175 | } | |
1176 | ||
3b0871f4 SM |
1177 | static bool |
1178 | is_longjmp_type (bptype type) | |
1179 | { | |
1180 | return type == bp_longjmp || type == bp_exception; | |
1181 | } | |
1182 | ||
a7bdde9e | 1183 | int |
d77f58be | 1184 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1185 | { |
d9b3f62e | 1186 | return is_tracepoint_type (b->type); |
a7bdde9e | 1187 | } |
d9b3f62e | 1188 | |
a5e364af SM |
1189 | /* Factory function to create an appropriate instance of breakpoint given |
1190 | TYPE. */ | |
1191 | ||
1192 | static std::unique_ptr<breakpoint> | |
1193 | new_breakpoint_from_type (bptype type) | |
1194 | { | |
1195 | breakpoint *b; | |
1196 | ||
1197 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1198 | b = new tracepoint (); |
3b0871f4 | 1199 | else if (is_longjmp_type (type)) |
c1fc2657 | 1200 | b = new longjmp_breakpoint (); |
a5e364af SM |
1201 | else |
1202 | b = new breakpoint (); | |
1203 | ||
1204 | return std::unique_ptr<breakpoint> (b); | |
1205 | } | |
1206 | ||
e5dd4106 | 1207 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1208 | breakpoint. This function will throw an exception if a problem is |
1209 | found. */ | |
48cb2d85 | 1210 | |
95a42b64 TT |
1211 | static void |
1212 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1213 | struct command_line *commands) | |
48cb2d85 | 1214 | { |
d77f58be | 1215 | if (is_tracepoint (b)) |
a7bdde9e | 1216 | { |
c9a6ce02 | 1217 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1218 | struct command_line *c; |
1219 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1220 | |
1221 | /* Reset the while-stepping step count. The previous commands | |
1222 | might have included a while-stepping action, while the new | |
1223 | ones might not. */ | |
1224 | t->step_count = 0; | |
1225 | ||
1226 | /* We need to verify that each top-level element of commands is | |
1227 | valid for tracepoints, that there's at most one | |
1228 | while-stepping element, and that the while-stepping's body | |
1229 | has valid tracing commands excluding nested while-stepping. | |
1230 | We also need to validate the tracepoint action line in the | |
1231 | context of the tracepoint --- validate_actionline actually | |
1232 | has side effects, like setting the tracepoint's | |
1233 | while-stepping STEP_COUNT, in addition to checking if the | |
1234 | collect/teval actions parse and make sense in the | |
1235 | tracepoint's context. */ | |
a7bdde9e VP |
1236 | for (c = commands; c; c = c->next) |
1237 | { | |
a7bdde9e VP |
1238 | if (c->control_type == while_stepping_control) |
1239 | { | |
1240 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1241 | error (_("The 'while-stepping' command " |
1242 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1243 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1244 | error (_("The 'while-stepping' command " |
1245 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1246 | |
1247 | if (while_stepping) | |
3e43a32a MS |
1248 | error (_("The 'while-stepping' command " |
1249 | "can be used only once")); | |
a7bdde9e VP |
1250 | else |
1251 | while_stepping = c; | |
1252 | } | |
c9a6ce02 PA |
1253 | |
1254 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1255 | } |
1256 | if (while_stepping) | |
1257 | { | |
1258 | struct command_line *c2; | |
1259 | ||
1260 | gdb_assert (while_stepping->body_count == 1); | |
1261 | c2 = while_stepping->body_list[0]; | |
1262 | for (; c2; c2 = c2->next) | |
1263 | { | |
a7bdde9e VP |
1264 | if (c2->control_type == while_stepping_control) |
1265 | error (_("The 'while-stepping' command cannot be nested")); | |
1266 | } | |
1267 | } | |
1268 | } | |
1269 | else | |
1270 | { | |
1271 | check_no_tracepoint_commands (commands); | |
1272 | } | |
95a42b64 TT |
1273 | } |
1274 | ||
0fb4aa4b PA |
1275 | /* Return a vector of all the static tracepoints set at ADDR. The |
1276 | caller is responsible for releasing the vector. */ | |
1277 | ||
1278 | VEC(breakpoint_p) * | |
1279 | static_tracepoints_here (CORE_ADDR addr) | |
1280 | { | |
1281 | struct breakpoint *b; | |
1282 | VEC(breakpoint_p) *found = 0; | |
1283 | struct bp_location *loc; | |
1284 | ||
1285 | ALL_BREAKPOINTS (b) | |
1286 | if (b->type == bp_static_tracepoint) | |
1287 | { | |
1288 | for (loc = b->loc; loc; loc = loc->next) | |
1289 | if (loc->address == addr) | |
1290 | VEC_safe_push(breakpoint_p, found, b); | |
1291 | } | |
1292 | ||
1293 | return found; | |
1294 | } | |
1295 | ||
95a42b64 | 1296 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1297 | validate that only allowed commands are included. */ |
95a42b64 TT |
1298 | |
1299 | void | |
4a64f543 | 1300 | breakpoint_set_commands (struct breakpoint *b, |
93921405 | 1301 | command_line_up &&commands) |
95a42b64 | 1302 | { |
93921405 | 1303 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1304 | |
9add0f1b | 1305 | decref_counted_command_line (&b->commands); |
93921405 | 1306 | b->commands = alloc_counted_command_line (commands.release ()); |
8d3788bd | 1307 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1308 | } |
1309 | ||
45a43567 TT |
1310 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1311 | is not the same as the "silent" that may appear in the breakpoint's | |
1312 | commands. */ | |
1313 | ||
1314 | void | |
1315 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1316 | { | |
1317 | int old_silent = b->silent; | |
1318 | ||
1319 | b->silent = silent; | |
1320 | if (old_silent != silent) | |
8d3788bd | 1321 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1322 | } |
1323 | ||
1324 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1325 | breakpoint work for any thread. */ | |
1326 | ||
1327 | void | |
1328 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1329 | { | |
1330 | int old_thread = b->thread; | |
1331 | ||
1332 | b->thread = thread; | |
1333 | if (old_thread != thread) | |
8d3788bd | 1334 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1335 | } |
1336 | ||
1337 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1338 | breakpoint work for any task. */ | |
1339 | ||
1340 | void | |
1341 | breakpoint_set_task (struct breakpoint *b, int task) | |
1342 | { | |
1343 | int old_task = b->task; | |
1344 | ||
1345 | b->task = task; | |
1346 | if (old_task != task) | |
8d3788bd | 1347 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1348 | } |
1349 | ||
95a42b64 TT |
1350 | void |
1351 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1352 | { |
9a3c8263 | 1353 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1354 | |
6f937416 | 1355 | validate_actionline (line, b); |
a7bdde9e VP |
1356 | } |
1357 | ||
95a42b64 TT |
1358 | /* A structure used to pass information through |
1359 | map_breakpoint_numbers. */ | |
1360 | ||
1361 | struct commands_info | |
1362 | { | |
1363 | /* True if the command was typed at a tty. */ | |
1364 | int from_tty; | |
86b17b60 PA |
1365 | |
1366 | /* The breakpoint range spec. */ | |
896b6bda | 1367 | const char *arg; |
86b17b60 | 1368 | |
95a42b64 TT |
1369 | /* Non-NULL if the body of the commands are being read from this |
1370 | already-parsed command. */ | |
1371 | struct command_line *control; | |
86b17b60 | 1372 | |
95a42b64 TT |
1373 | /* The command lines read from the user, or NULL if they have not |
1374 | yet been read. */ | |
1375 | struct counted_command_line *cmd; | |
1376 | }; | |
1377 | ||
1378 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1379 | commands_command. */ | |
1380 | ||
c906108c | 1381 | static void |
95a42b64 | 1382 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1383 | { |
9a3c8263 | 1384 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1385 | |
95a42b64 TT |
1386 | if (info->cmd == NULL) |
1387 | { | |
93921405 | 1388 | command_line_up l; |
5c44784c | 1389 | |
95a42b64 TT |
1390 | if (info->control != NULL) |
1391 | l = copy_command_lines (info->control->body_list[0]); | |
1392 | else | |
86b17b60 PA |
1393 | { |
1394 | struct cleanup *old_chain; | |
1395 | char *str; | |
c5aa993b | 1396 | |
3e43a32a MS |
1397 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1398 | "%s, one per line."), | |
86b17b60 PA |
1399 | info->arg); |
1400 | ||
1401 | old_chain = make_cleanup (xfree, str); | |
1402 | ||
1403 | l = read_command_lines (str, | |
1404 | info->from_tty, 1, | |
d77f58be | 1405 | (is_tracepoint (b) |
86b17b60 PA |
1406 | ? check_tracepoint_command : 0), |
1407 | b); | |
1408 | ||
1409 | do_cleanups (old_chain); | |
1410 | } | |
a7bdde9e | 1411 | |
93921405 | 1412 | info->cmd = alloc_counted_command_line (l.release ()); |
95a42b64 TT |
1413 | } |
1414 | ||
1415 | /* If a breakpoint was on the list more than once, we don't need to | |
1416 | do anything. */ | |
1417 | if (b->commands != info->cmd) | |
1418 | { | |
1419 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1420 | incref_counted_command_line (info->cmd); | |
1421 | decref_counted_command_line (&b->commands); | |
1422 | b->commands = info->cmd; | |
8d3788bd | 1423 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1424 | } |
95a42b64 TT |
1425 | } |
1426 | ||
1427 | static void | |
896b6bda | 1428 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1429 | struct command_line *control) |
95a42b64 TT |
1430 | { |
1431 | struct cleanup *cleanups; | |
1432 | struct commands_info info; | |
1433 | ||
1434 | info.from_tty = from_tty; | |
1435 | info.control = control; | |
1436 | info.cmd = NULL; | |
1437 | /* If we read command lines from the user, then `info' will hold an | |
1438 | extra reference to the commands that we must clean up. */ | |
1439 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1440 | ||
896b6bda PA |
1441 | std::string new_arg; |
1442 | ||
95a42b64 TT |
1443 | if (arg == NULL || !*arg) |
1444 | { | |
86b17b60 | 1445 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1446 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1447 | breakpoint_count); | |
95a42b64 | 1448 | else if (breakpoint_count > 0) |
896b6bda | 1449 | new_arg = string_printf ("%d", breakpoint_count); |
95a42b64 | 1450 | } |
9766ced4 | 1451 | else |
896b6bda | 1452 | new_arg = arg; |
86b17b60 | 1453 | |
896b6bda | 1454 | info.arg = new_arg.c_str (); |
95a42b64 | 1455 | |
896b6bda | 1456 | map_breakpoint_numbers (info.arg, do_map_commands_command, &info); |
95a42b64 TT |
1457 | |
1458 | if (info.cmd == NULL) | |
1459 | error (_("No breakpoints specified.")); | |
1460 | ||
1461 | do_cleanups (cleanups); | |
1462 | } | |
1463 | ||
1464 | static void | |
1465 | commands_command (char *arg, int from_tty) | |
1466 | { | |
1467 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1468 | } |
40c03ae8 EZ |
1469 | |
1470 | /* Like commands_command, but instead of reading the commands from | |
1471 | input stream, takes them from an already parsed command structure. | |
1472 | ||
1473 | This is used by cli-script.c to DTRT with breakpoint commands | |
1474 | that are part of if and while bodies. */ | |
1475 | enum command_control_type | |
896b6bda | 1476 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1477 | { |
95a42b64 TT |
1478 | commands_command_1 (arg, 0, cmd); |
1479 | return simple_control; | |
40c03ae8 | 1480 | } |
876fa593 JK |
1481 | |
1482 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1483 | ||
1484 | static int | |
1485 | bp_location_has_shadow (struct bp_location *bl) | |
1486 | { | |
1487 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1488 | return 0; | |
1489 | if (!bl->inserted) | |
1490 | return 0; | |
1491 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1492 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1493 | return 0; |
1494 | return 1; | |
1495 | } | |
1496 | ||
9d497a19 PA |
1497 | /* Update BUF, which is LEN bytes read from the target address |
1498 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1499 | contents. | |
1500 | ||
1501 | If READBUF is not NULL, this buffer must not overlap with the of | |
1502 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1503 | failed assertion internal error will be raised. */ | |
1504 | ||
1505 | static void | |
1506 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1507 | const gdb_byte *writebuf_org, | |
1508 | ULONGEST memaddr, LONGEST len, | |
1509 | struct bp_target_info *target_info, | |
1510 | struct gdbarch *gdbarch) | |
1511 | { | |
1512 | /* Now do full processing of the found relevant range of elements. */ | |
1513 | CORE_ADDR bp_addr = 0; | |
1514 | int bp_size = 0; | |
1515 | int bptoffset = 0; | |
1516 | ||
1517 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1518 | current_program_space->aspace, 0)) | |
1519 | { | |
1520 | /* The breakpoint is inserted in a different address space. */ | |
1521 | return; | |
1522 | } | |
1523 | ||
1524 | /* Addresses and length of the part of the breakpoint that | |
1525 | we need to copy. */ | |
1526 | bp_addr = target_info->placed_address; | |
1527 | bp_size = target_info->shadow_len; | |
1528 | ||
1529 | if (bp_addr + bp_size <= memaddr) | |
1530 | { | |
1531 | /* The breakpoint is entirely before the chunk of memory we are | |
1532 | reading. */ | |
1533 | return; | |
1534 | } | |
1535 | ||
1536 | if (bp_addr >= memaddr + len) | |
1537 | { | |
1538 | /* The breakpoint is entirely after the chunk of memory we are | |
1539 | reading. */ | |
1540 | return; | |
1541 | } | |
1542 | ||
1543 | /* Offset within shadow_contents. */ | |
1544 | if (bp_addr < memaddr) | |
1545 | { | |
1546 | /* Only copy the second part of the breakpoint. */ | |
1547 | bp_size -= memaddr - bp_addr; | |
1548 | bptoffset = memaddr - bp_addr; | |
1549 | bp_addr = memaddr; | |
1550 | } | |
1551 | ||
1552 | if (bp_addr + bp_size > memaddr + len) | |
1553 | { | |
1554 | /* Only copy the first part of the breakpoint. */ | |
1555 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1556 | } | |
1557 | ||
1558 | if (readbuf != NULL) | |
1559 | { | |
1560 | /* Verify that the readbuf buffer does not overlap with the | |
1561 | shadow_contents buffer. */ | |
1562 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1563 | || readbuf >= (target_info->shadow_contents | |
1564 | + target_info->shadow_len)); | |
1565 | ||
1566 | /* Update the read buffer with this inserted breakpoint's | |
1567 | shadow. */ | |
1568 | memcpy (readbuf + bp_addr - memaddr, | |
1569 | target_info->shadow_contents + bptoffset, bp_size); | |
1570 | } | |
1571 | else | |
1572 | { | |
1573 | const unsigned char *bp; | |
0d5ed153 MR |
1574 | CORE_ADDR addr = target_info->reqstd_address; |
1575 | int placed_size; | |
9d497a19 PA |
1576 | |
1577 | /* Update the shadow with what we want to write to memory. */ | |
1578 | memcpy (target_info->shadow_contents + bptoffset, | |
1579 | writebuf_org + bp_addr - memaddr, bp_size); | |
1580 | ||
1581 | /* Determine appropriate breakpoint contents and size for this | |
1582 | address. */ | |
0d5ed153 | 1583 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1584 | |
1585 | /* Update the final write buffer with this inserted | |
1586 | breakpoint's INSN. */ | |
1587 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1588 | } | |
1589 | } | |
1590 | ||
8defab1a | 1591 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1592 | by replacing any memory breakpoints with their shadowed contents. |
1593 | ||
35c63cd8 JB |
1594 | If READBUF is not NULL, this buffer must not overlap with any of |
1595 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1596 | a failed assertion internal error will be raised. | |
1597 | ||
876fa593 | 1598 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1599 | bl->address - bp_locations_placed_address_before_address_max |
1600 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1601 | The range we were requested to resolve shadows for is: |
1602 | memaddr ... memaddr + len | |
1603 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1604 | memaddr + len <= (bl->address |
f5336ca5 | 1605 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1606 | and: |
f5336ca5 | 1607 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1608 | |
8defab1a | 1609 | void |
f0ba3972 PA |
1610 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1611 | const gdb_byte *writebuf_org, | |
1612 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1613 | { |
4a64f543 MS |
1614 | /* Left boundary, right boundary and median element of our binary |
1615 | search. */ | |
876fa593 JK |
1616 | unsigned bc_l, bc_r, bc; |
1617 | ||
4a64f543 MS |
1618 | /* Find BC_L which is a leftmost element which may affect BUF |
1619 | content. It is safe to report lower value but a failure to | |
1620 | report higher one. */ | |
876fa593 JK |
1621 | |
1622 | bc_l = 0; | |
f5336ca5 | 1623 | bc_r = bp_locations_count; |
876fa593 JK |
1624 | while (bc_l + 1 < bc_r) |
1625 | { | |
35df4500 | 1626 | struct bp_location *bl; |
876fa593 JK |
1627 | |
1628 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1629 | bl = bp_locations[bc]; |
876fa593 | 1630 | |
4a64f543 MS |
1631 | /* Check first BL->ADDRESS will not overflow due to the added |
1632 | constant. Then advance the left boundary only if we are sure | |
1633 | the BC element can in no way affect the BUF content (MEMADDR | |
1634 | to MEMADDR + LEN range). | |
876fa593 | 1635 | |
f5336ca5 | 1636 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1637 | offset so that we cannot miss a breakpoint with its shadow |
1638 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1639 | |
f5336ca5 | 1640 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1641 | >= bl->address) |
f5336ca5 | 1642 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1643 | <= memaddr)) |
876fa593 JK |
1644 | bc_l = bc; |
1645 | else | |
1646 | bc_r = bc; | |
1647 | } | |
1648 | ||
128070bb PA |
1649 | /* Due to the binary search above, we need to make sure we pick the |
1650 | first location that's at BC_L's address. E.g., if there are | |
1651 | multiple locations at the same address, BC_L may end up pointing | |
1652 | at a duplicate location, and miss the "master"/"inserted" | |
1653 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1654 | B: | |
1655 | ||
1656 | L1@A, L2@A, L3@B, ... | |
1657 | ||
1658 | BC_L could end up pointing at location L2, while the "master" | |
1659 | location could be L1. Since the `loc->inserted' flag is only set | |
1660 | on "master" locations, we'd forget to restore the shadow of L1 | |
1661 | and L2. */ | |
1662 | while (bc_l > 0 | |
f5336ca5 | 1663 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1664 | bc_l--; |
1665 | ||
876fa593 JK |
1666 | /* Now do full processing of the found relevant range of elements. */ |
1667 | ||
f5336ca5 | 1668 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1669 | { |
f5336ca5 | 1670 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1671 | |
35df4500 TJB |
1672 | /* bp_location array has BL->OWNER always non-NULL. */ |
1673 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1674 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1675 | bl->owner->number); |
ffce0d52 | 1676 | |
e5dd4106 | 1677 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1678 | content. */ |
1679 | ||
f5336ca5 PA |
1680 | if (bl->address >= bp_locations_placed_address_before_address_max |
1681 | && memaddr + len <= (bl->address | |
1682 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1683 | break; |
1684 | ||
35df4500 | 1685 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1686 | continue; |
6c95b8df | 1687 | |
9d497a19 PA |
1688 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1689 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1690 | } | |
c906108c | 1691 | } |
9d497a19 | 1692 | |
c906108c | 1693 | \f |
c5aa993b | 1694 | |
b775012e LM |
1695 | /* Return true if BPT is either a software breakpoint or a hardware |
1696 | breakpoint. */ | |
1697 | ||
1698 | int | |
1699 | is_breakpoint (const struct breakpoint *bpt) | |
1700 | { | |
1701 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1702 | || bpt->type == bp_hardware_breakpoint |
1703 | || bpt->type == bp_dprintf); | |
b775012e LM |
1704 | } |
1705 | ||
60e1c644 PA |
1706 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1707 | ||
a5606eee | 1708 | static int |
d77f58be | 1709 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1710 | { |
1711 | return (bpt->type == bp_hardware_watchpoint | |
1712 | || bpt->type == bp_read_watchpoint | |
1713 | || bpt->type == bp_access_watchpoint); | |
1714 | } | |
7270d8f2 | 1715 | |
60e1c644 PA |
1716 | /* Return true if BPT is of any watchpoint kind, hardware or |
1717 | software. */ | |
1718 | ||
3a5c3e22 | 1719 | int |
d77f58be | 1720 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1721 | { |
1722 | return (is_hardware_watchpoint (bpt) | |
1723 | || bpt->type == bp_watchpoint); | |
1724 | } | |
1725 | ||
3a5c3e22 PA |
1726 | /* Returns true if the current thread and its running state are safe |
1727 | to evaluate or update watchpoint B. Watchpoints on local | |
1728 | expressions need to be evaluated in the context of the thread that | |
1729 | was current when the watchpoint was created, and, that thread needs | |
1730 | to be stopped to be able to select the correct frame context. | |
1731 | Watchpoints on global expressions can be evaluated on any thread, | |
1732 | and in any state. It is presently left to the target allowing | |
1733 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1734 | |
1735 | static int | |
3a5c3e22 | 1736 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1737 | { |
c1fc2657 | 1738 | return (b->pspace == current_program_space |
d0d8b0c6 JK |
1739 | && (ptid_equal (b->watchpoint_thread, null_ptid) |
1740 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1741 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1742 | } |
1743 | ||
d0fb5eae JK |
1744 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1745 | associated bp_watchpoint_scope breakpoint. */ | |
1746 | ||
1747 | static void | |
3a5c3e22 | 1748 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1749 | { |
c1fc2657 | 1750 | if (w->related_breakpoint != w) |
d0fb5eae | 1751 | { |
c1fc2657 SM |
1752 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1753 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1754 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1755 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1756 | w->related_breakpoint = w; | |
d0fb5eae | 1757 | } |
c1fc2657 | 1758 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1759 | } |
1760 | ||
bb9d5f81 PP |
1761 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1762 | watchpoint W. */ | |
1763 | ||
1764 | static struct value * | |
1765 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1766 | { | |
1767 | struct value *bit_val; | |
1768 | ||
1769 | if (val == NULL) | |
1770 | return NULL; | |
1771 | ||
1772 | bit_val = allocate_value (value_type (val)); | |
1773 | ||
1774 | unpack_value_bitfield (bit_val, | |
1775 | w->val_bitpos, | |
1776 | w->val_bitsize, | |
1777 | value_contents_for_printing (val), | |
1778 | value_offset (val), | |
1779 | val); | |
1780 | ||
1781 | return bit_val; | |
1782 | } | |
1783 | ||
c6d81124 PA |
1784 | /* Allocate a dummy location and add it to B, which must be a software |
1785 | watchpoint. This is required because even if a software watchpoint | |
1786 | is not watching any memory, bpstat_stop_status requires a location | |
1787 | to be able to report stops. */ | |
1788 | ||
1789 | static void | |
1790 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1791 | struct program_space *pspace) | |
1792 | { | |
1793 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1794 | ||
1795 | b->loc = allocate_bp_location (b); | |
1796 | b->loc->pspace = pspace; | |
1797 | b->loc->address = -1; | |
1798 | b->loc->length = -1; | |
1799 | } | |
1800 | ||
1801 | /* Returns true if B is a software watchpoint that is not watching any | |
1802 | memory (e.g., "watch $pc"). */ | |
1803 | ||
1804 | static int | |
1805 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1806 | { | |
1807 | return (b->type == bp_watchpoint | |
1808 | && b->loc != NULL | |
1809 | && b->loc->next == NULL | |
1810 | && b->loc->address == -1 | |
1811 | && b->loc->length == -1); | |
1812 | } | |
1813 | ||
567e1b4e JB |
1814 | /* Assuming that B is a watchpoint: |
1815 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1816 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1817 | - Evaluate the condition if there is one, and store the result |
1818 | in b->loc->cond. | |
a5606eee VP |
1819 | - Update the list of values that must be watched in B->loc. |
1820 | ||
4a64f543 MS |
1821 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1822 | nothing. If this is local watchpoint that is out of scope, delete | |
1823 | it. | |
1824 | ||
1825 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1826 | removed + inserted on each stop here. Normal breakpoints must | |
1827 | never be removed because they might be missed by a running thread | |
1828 | when debugging in non-stop mode. On the other hand, hardware | |
1829 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1830 | to each LWP since they are stored in each LWP's hardware debug | |
1831 | registers. Therefore, such LWP must be stopped first in order to | |
1832 | be able to modify its hardware watchpoints. | |
1833 | ||
1834 | Hardware watchpoints must be reset exactly once after being | |
1835 | presented to the user. It cannot be done sooner, because it would | |
1836 | reset the data used to present the watchpoint hit to the user. And | |
1837 | it must not be done later because it could display the same single | |
1838 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1839 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1840 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1841 | not user-visible - its hit is suppressed if the memory content has | |
1842 | not changed. | |
1843 | ||
1844 | The following constraints influence the location where we can reset | |
1845 | hardware watchpoints: | |
1846 | ||
1847 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1848 | called several times when GDB stops. | |
1849 | ||
1850 | [linux] | |
1851 | * Multiple hardware watchpoints can be hit at the same time, | |
1852 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1853 | hit at a time as the reason for stopping, and all the other hits | |
1854 | are presented later, one after the other, each time the user | |
1855 | requests the execution to be resumed. Execution is not resumed | |
1856 | for the threads still having pending hit event stored in | |
1857 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1858 | the inferior on the first stop the thread hit event is kept being | |
1859 | reported from its cached value by linux_nat_stopped_data_address | |
1860 | until the real thread resume happens after the watchpoint gets | |
1861 | presented and thus its LWP_INFO->STATUS gets reset. | |
1862 | ||
1863 | Therefore the hardware watchpoint hit can get safely reset on the | |
1864 | watchpoint removal from inferior. */ | |
a79d3c27 | 1865 | |
b40ce68a | 1866 | static void |
3a5c3e22 | 1867 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1868 | { |
a5606eee | 1869 | int within_current_scope; |
a5606eee | 1870 | struct frame_id saved_frame_id; |
66076460 | 1871 | int frame_saved; |
a5606eee | 1872 | |
f6bc2008 PA |
1873 | /* If this is a local watchpoint, we only want to check if the |
1874 | watchpoint frame is in scope if the current thread is the thread | |
1875 | that was used to create the watchpoint. */ | |
1876 | if (!watchpoint_in_thread_scope (b)) | |
1877 | return; | |
1878 | ||
c1fc2657 | 1879 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1880 | return; |
1881 | ||
66076460 | 1882 | frame_saved = 0; |
a5606eee VP |
1883 | |
1884 | /* Determine if the watchpoint is within scope. */ | |
1885 | if (b->exp_valid_block == NULL) | |
1886 | within_current_scope = 1; | |
1887 | else | |
1888 | { | |
b5db5dfc UW |
1889 | struct frame_info *fi = get_current_frame (); |
1890 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1891 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1892 | ||
c9cf6e20 MG |
1893 | /* If we're at a point where the stack has been destroyed |
1894 | (e.g. in a function epilogue), unwinding may not work | |
1895 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1896 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1897 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1898 | return; |
66076460 DJ |
1899 | |
1900 | /* Save the current frame's ID so we can restore it after | |
1901 | evaluating the watchpoint expression on its own frame. */ | |
1902 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1903 | took a frame parameter, so that we didn't have to change the | |
1904 | selected frame. */ | |
1905 | frame_saved = 1; | |
1906 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1907 | ||
a5606eee VP |
1908 | fi = frame_find_by_id (b->watchpoint_frame); |
1909 | within_current_scope = (fi != NULL); | |
1910 | if (within_current_scope) | |
1911 | select_frame (fi); | |
1912 | } | |
1913 | ||
b5db5dfc UW |
1914 | /* We don't free locations. They are stored in the bp_location array |
1915 | and update_global_location_list will eventually delete them and | |
1916 | remove breakpoints if needed. */ | |
c1fc2657 | 1917 | b->loc = NULL; |
b5db5dfc | 1918 | |
a5606eee VP |
1919 | if (within_current_scope && reparse) |
1920 | { | |
bbc13ae3 | 1921 | const char *s; |
d63d0675 | 1922 | |
4d01a485 | 1923 | b->exp.reset (); |
d63d0675 | 1924 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1925 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1926 | /* If the meaning of expression itself changed, the old value is |
1927 | no longer relevant. We don't want to report a watchpoint hit | |
1928 | to the user when the old value and the new value may actually | |
1929 | be completely different objects. */ | |
1930 | value_free (b->val); | |
fa4727a6 DJ |
1931 | b->val = NULL; |
1932 | b->val_valid = 0; | |
60e1c644 PA |
1933 | |
1934 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1935 | expression is stored in the breakpoint object, not in the | |
1936 | locations (re)created below. */ | |
c1fc2657 | 1937 | if (b->cond_string != NULL) |
60e1c644 | 1938 | { |
4d01a485 | 1939 | b->cond_exp.reset (); |
60e1c644 | 1940 | |
c1fc2657 | 1941 | s = b->cond_string; |
1bb9788d | 1942 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1943 | } |
a5606eee | 1944 | } |
a5606eee VP |
1945 | |
1946 | /* If we failed to parse the expression, for example because | |
1947 | it refers to a global variable in a not-yet-loaded shared library, | |
1948 | don't try to insert watchpoint. We don't automatically delete | |
1949 | such watchpoint, though, since failure to parse expression | |
1950 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1951 | if (!target_has_execution) |
2d134ed3 PA |
1952 | { |
1953 | /* Without execution, memory can't change. No use to try and | |
1954 | set watchpoint locations. The watchpoint will be reset when | |
1955 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1956 | if (!can_use_hw_watchpoints) |
1957 | { | |
c1fc2657 SM |
1958 | if (b->ops->works_in_software_mode (b)) |
1959 | b->type = bp_watchpoint; | |
e8369a73 | 1960 | else |
638aa5a1 AB |
1961 | error (_("Can't set read/access watchpoint when " |
1962 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1963 | } |
2d134ed3 PA |
1964 | } |
1965 | else if (within_current_scope && b->exp) | |
a5606eee | 1966 | { |
0cf6dd15 | 1967 | int pc = 0; |
fa4727a6 | 1968 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1969 | struct program_space *frame_pspace; |
a5606eee | 1970 | |
4d01a485 | 1971 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1972 | |
a5606eee VP |
1973 | /* Avoid setting b->val if it's already set. The meaning of |
1974 | b->val is 'the last value' user saw, and we should update | |
1975 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1976 | happens, the code that reports it updates b->val directly. |
1977 | We don't keep track of the memory value for masked | |
1978 | watchpoints. */ | |
c1fc2657 | 1979 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1980 | { |
bb9d5f81 PP |
1981 | if (b->val_bitsize != 0) |
1982 | { | |
1983 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1984 | if (v != NULL) | |
1985 | release_value (v); | |
1986 | } | |
fa4727a6 DJ |
1987 | b->val = v; |
1988 | b->val_valid = 1; | |
1989 | } | |
a5606eee | 1990 | |
2d134ed3 PA |
1991 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1992 | ||
a5606eee | 1993 | /* Look at each value on the value chain. */ |
9fa40276 | 1994 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1995 | { |
1996 | /* If it's a memory location, and GDB actually needed | |
1997 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1998 | must watch it. If the first value returned is |
1999 | still lazy, that means an error occurred reading it; | |
2000 | watch it anyway in case it becomes readable. */ | |
a5606eee | 2001 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 2002 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
2003 | { |
2004 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 2005 | |
a5606eee VP |
2006 | /* We only watch structs and arrays if user asked |
2007 | for it explicitly, never if they just happen to | |
2008 | appear in the middle of some value chain. */ | |
fa4727a6 | 2009 | if (v == result |
a5606eee VP |
2010 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
2011 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2012 | { | |
2013 | CORE_ADDR addr; | |
f486487f | 2014 | enum target_hw_bp_type type; |
a5606eee | 2015 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2016 | int bitpos = 0, bitsize = 0; |
2017 | ||
2018 | if (value_bitsize (v) != 0) | |
2019 | { | |
2020 | /* Extract the bit parameters out from the bitfield | |
2021 | sub-expression. */ | |
2022 | bitpos = value_bitpos (v); | |
2023 | bitsize = value_bitsize (v); | |
2024 | } | |
2025 | else if (v == result && b->val_bitsize != 0) | |
2026 | { | |
2027 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2028 | lvalue whose bit parameters are saved in the fields | |
2029 | VAL_BITPOS and VAL_BITSIZE. */ | |
2030 | bitpos = b->val_bitpos; | |
2031 | bitsize = b->val_bitsize; | |
2032 | } | |
a5606eee | 2033 | |
42ae5230 | 2034 | addr = value_address (v); |
bb9d5f81 PP |
2035 | if (bitsize != 0) |
2036 | { | |
2037 | /* Skip the bytes that don't contain the bitfield. */ | |
2038 | addr += bitpos / 8; | |
2039 | } | |
2040 | ||
a5606eee | 2041 | type = hw_write; |
c1fc2657 | 2042 | if (b->type == bp_read_watchpoint) |
a5606eee | 2043 | type = hw_read; |
c1fc2657 | 2044 | else if (b->type == bp_access_watchpoint) |
a5606eee | 2045 | type = hw_access; |
3a5c3e22 | 2046 | |
c1fc2657 SM |
2047 | loc = allocate_bp_location (b); |
2048 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2049 | ; |
2050 | *tmp = loc; | |
a6d9a66e | 2051 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2052 | |
2053 | loc->pspace = frame_pspace; | |
a5606eee | 2054 | loc->address = addr; |
bb9d5f81 PP |
2055 | |
2056 | if (bitsize != 0) | |
2057 | { | |
2058 | /* Just cover the bytes that make up the bitfield. */ | |
2059 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2060 | } | |
2061 | else | |
2062 | loc->length = TYPE_LENGTH (value_type (v)); | |
2063 | ||
a5606eee VP |
2064 | loc->watchpoint_type = type; |
2065 | } | |
2066 | } | |
9fa40276 TJB |
2067 | } |
2068 | ||
2069 | /* Change the type of breakpoint between hardware assisted or | |
2070 | an ordinary watchpoint depending on the hardware support | |
2071 | and free hardware slots. REPARSE is set when the inferior | |
2072 | is started. */ | |
a9634178 | 2073 | if (reparse) |
9fa40276 | 2074 | { |
e09342b5 | 2075 | int reg_cnt; |
9fa40276 TJB |
2076 | enum bp_loc_type loc_type; |
2077 | struct bp_location *bl; | |
a5606eee | 2078 | |
a9634178 | 2079 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2080 | |
2081 | if (reg_cnt) | |
9fa40276 TJB |
2082 | { |
2083 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2084 | enum bptype type; |
9fa40276 | 2085 | |
a9634178 TJB |
2086 | /* Use an exact watchpoint when there's only one memory region to be |
2087 | watched, and only one debug register is needed to watch it. */ | |
2088 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2089 | ||
9fa40276 | 2090 | /* We need to determine how many resources are already |
e09342b5 TJB |
2091 | used for all other hardware watchpoints plus this one |
2092 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2093 | this watchpoint in as well. */ |
2094 | ||
2095 | /* If this is a software watchpoint, we try to turn it | |
2096 | to a hardware one -- count resources as if B was of | |
2097 | hardware watchpoint type. */ | |
c1fc2657 | 2098 | type = b->type; |
a1398e0c PA |
2099 | if (type == bp_watchpoint) |
2100 | type = bp_hardware_watchpoint; | |
2101 | ||
2102 | /* This watchpoint may or may not have been placed on | |
2103 | the list yet at this point (it won't be in the list | |
2104 | if we're trying to create it for the first time, | |
2105 | through watch_command), so always account for it | |
2106 | manually. */ | |
2107 | ||
2108 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 2109 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
2110 | |
2111 | /* Add in the resources needed for B. */ | |
c1fc2657 | 2112 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
2113 | |
2114 | target_resources_ok | |
2115 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2116 | if (target_resources_ok <= 0) |
a9634178 | 2117 | { |
c1fc2657 | 2118 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
2119 | |
2120 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2121 | error (_("Target does not support this type of " |
2122 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2123 | else if (target_resources_ok < 0 && !sw_mode) |
2124 | error (_("There are not enough available hardware " | |
2125 | "resources for this watchpoint.")); | |
a1398e0c PA |
2126 | |
2127 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 2128 | b->type = bp_watchpoint; |
a1398e0c PA |
2129 | } |
2130 | else | |
2131 | { | |
2132 | /* If this was a software watchpoint, we've just | |
2133 | found we have enough resources to turn it to a | |
2134 | hardware watchpoint. Otherwise, this is a | |
2135 | nop. */ | |
c1fc2657 | 2136 | b->type = type; |
a9634178 | 2137 | } |
9fa40276 | 2138 | } |
c1fc2657 | 2139 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
2140 | { |
2141 | if (!can_use_hw_watchpoints) | |
2142 | error (_("Can't set read/access watchpoint when " | |
2143 | "hardware watchpoints are disabled.")); | |
2144 | else | |
2145 | error (_("Expression cannot be implemented with " | |
2146 | "read/access watchpoint.")); | |
2147 | } | |
9fa40276 | 2148 | else |
c1fc2657 | 2149 | b->type = bp_watchpoint; |
9fa40276 | 2150 | |
c1fc2657 | 2151 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2152 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 2153 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
2154 | bl->loc_type = loc_type; |
2155 | } | |
2156 | ||
2157 | for (v = val_chain; v; v = next) | |
2158 | { | |
a5606eee VP |
2159 | next = value_next (v); |
2160 | if (v != b->val) | |
2161 | value_free (v); | |
2162 | } | |
2163 | ||
c7437ca6 PA |
2164 | /* If a software watchpoint is not watching any memory, then the |
2165 | above left it without any location set up. But, | |
2166 | bpstat_stop_status requires a location to be able to report | |
2167 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2168 | if (b->type == bp_watchpoint && b->loc == NULL) |
2169 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2170 | } |
2171 | else if (!within_current_scope) | |
7270d8f2 | 2172 | { |
ac74f770 MS |
2173 | printf_filtered (_("\ |
2174 | Watchpoint %d deleted because the program has left the block\n\ | |
2175 | in which its expression is valid.\n"), | |
c1fc2657 | 2176 | b->number); |
d0fb5eae | 2177 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2178 | } |
a5606eee VP |
2179 | |
2180 | /* Restore the selected frame. */ | |
66076460 DJ |
2181 | if (frame_saved) |
2182 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2183 | } |
2184 | ||
a5606eee | 2185 | |
74960c60 | 2186 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2187 | inserted in the inferior. We don't differentiate the type of BL's owner |
2188 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2189 | breakpoint_ops is not defined, because in insert_bp_location, | |
2190 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2191 | static int |
35df4500 | 2192 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2193 | { |
35df4500 | 2194 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2195 | return 0; |
2196 | ||
35df4500 | 2197 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2198 | return 0; |
2199 | ||
35df4500 | 2200 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2201 | return 0; |
2202 | ||
f8eba3c6 TT |
2203 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2204 | return 0; | |
2205 | ||
56710373 PA |
2206 | /* This is set for example, when we're attached to the parent of a |
2207 | vfork, and have detached from the child. The child is running | |
2208 | free, and we expect it to do an exec or exit, at which point the | |
2209 | OS makes the parent schedulable again (and the target reports | |
2210 | that the vfork is done). Until the child is done with the shared | |
2211 | memory region, do not insert breakpoints in the parent, otherwise | |
2212 | the child could still trip on the parent's breakpoints. Since | |
2213 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2214 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2215 | return 0; |
2216 | ||
31e77af2 | 2217 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2218 | location, except if the breakpoint is a single-step breakpoint, |
2219 | and the breakpoint's thread is the thread which is stepping past | |
2220 | a breakpoint. */ | |
31e77af2 PA |
2221 | if ((bl->loc_type == bp_loc_software_breakpoint |
2222 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2223 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2224 | bl->address) |
2225 | /* The single-step breakpoint may be inserted at the location | |
2226 | we're trying to step if the instruction branches to itself. | |
2227 | However, the instruction won't be executed at all and it may | |
2228 | break the semantics of the instruction, for example, the | |
2229 | instruction is a conditional branch or updates some flags. | |
2230 | We can't fix it unless GDB is able to emulate the instruction | |
2231 | or switch to displaced stepping. */ | |
2232 | && !(bl->owner->type == bp_single_step | |
2233 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2234 | { |
2235 | if (debug_infrun) | |
2236 | { | |
2237 | fprintf_unfiltered (gdb_stdlog, | |
2238 | "infrun: skipping breakpoint: " | |
2239 | "stepping past insn at: %s\n", | |
2240 | paddress (bl->gdbarch, bl->address)); | |
2241 | } | |
2242 | return 0; | |
2243 | } | |
31e77af2 | 2244 | |
963f9c80 PA |
2245 | /* Don't insert watchpoints if we're trying to step past the |
2246 | instruction that triggered one. */ | |
2247 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2248 | && stepping_past_nonsteppable_watchpoint ()) | |
2249 | { | |
2250 | if (debug_infrun) | |
2251 | { | |
2252 | fprintf_unfiltered (gdb_stdlog, | |
2253 | "infrun: stepping past non-steppable watchpoint. " | |
2254 | "skipping watchpoint at %s:%d\n", | |
2255 | paddress (bl->gdbarch, bl->address), | |
2256 | bl->length); | |
2257 | } | |
2258 | return 0; | |
2259 | } | |
2260 | ||
74960c60 VP |
2261 | return 1; |
2262 | } | |
2263 | ||
934709f0 PW |
2264 | /* Same as should_be_inserted but does the check assuming |
2265 | that the location is not duplicated. */ | |
2266 | ||
2267 | static int | |
2268 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2269 | { | |
2270 | int result; | |
2271 | const int save_duplicate = bl->duplicate; | |
2272 | ||
2273 | bl->duplicate = 0; | |
2274 | result = should_be_inserted (bl); | |
2275 | bl->duplicate = save_duplicate; | |
2276 | return result; | |
2277 | } | |
2278 | ||
b775012e LM |
2279 | /* Parses a conditional described by an expression COND into an |
2280 | agent expression bytecode suitable for evaluation | |
2281 | by the bytecode interpreter. Return NULL if there was | |
2282 | any error during parsing. */ | |
2283 | ||
833177a4 | 2284 | static agent_expr_up |
b775012e LM |
2285 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2286 | { | |
833177a4 | 2287 | if (cond == NULL) |
b775012e LM |
2288 | return NULL; |
2289 | ||
833177a4 PA |
2290 | agent_expr_up aexpr; |
2291 | ||
b775012e LM |
2292 | /* We don't want to stop processing, so catch any errors |
2293 | that may show up. */ | |
492d29ea | 2294 | TRY |
b775012e | 2295 | { |
036e657b | 2296 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2297 | } |
2298 | ||
492d29ea | 2299 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2300 | { |
2301 | /* If we got here, it means the condition could not be parsed to a valid | |
2302 | bytecode expression and thus can't be evaluated on the target's side. | |
2303 | It's no use iterating through the conditions. */ | |
b775012e | 2304 | } |
492d29ea | 2305 | END_CATCH |
b775012e LM |
2306 | |
2307 | /* We have a valid agent expression. */ | |
2308 | return aexpr; | |
2309 | } | |
2310 | ||
2311 | /* Based on location BL, create a list of breakpoint conditions to be | |
2312 | passed on to the target. If we have duplicated locations with different | |
2313 | conditions, we will add such conditions to the list. The idea is that the | |
2314 | target will evaluate the list of conditions and will only notify GDB when | |
2315 | one of them is true. */ | |
2316 | ||
2317 | static void | |
2318 | build_target_condition_list (struct bp_location *bl) | |
2319 | { | |
2320 | struct bp_location **locp = NULL, **loc2p; | |
2321 | int null_condition_or_parse_error = 0; | |
2322 | int modified = bl->needs_update; | |
2323 | struct bp_location *loc; | |
2324 | ||
8b4f3082 | 2325 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2326 | bl->target_info.conditions.clear (); |
8b4f3082 | 2327 | |
b775012e LM |
2328 | /* This is only meaningful if the target is |
2329 | evaluating conditions and if the user has | |
2330 | opted for condition evaluation on the target's | |
2331 | side. */ | |
2332 | if (gdb_evaluates_breakpoint_condition_p () | |
2333 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2334 | return; | |
2335 | ||
2336 | /* Do a first pass to check for locations with no assigned | |
2337 | conditions or conditions that fail to parse to a valid agent expression | |
2338 | bytecode. If any of these happen, then it's no use to send conditions | |
2339 | to the target since this location will always trigger and generate a | |
2340 | response back to GDB. */ | |
2341 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2342 | { | |
2343 | loc = (*loc2p); | |
2344 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2345 | { | |
2346 | if (modified) | |
2347 | { | |
b775012e LM |
2348 | /* Re-parse the conditions since something changed. In that |
2349 | case we already freed the condition bytecodes (see | |
2350 | force_breakpoint_reinsertion). We just | |
2351 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2352 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2353 | loc->cond.get ()); | |
b775012e LM |
2354 | } |
2355 | ||
2356 | /* If we have a NULL bytecode expression, it means something | |
2357 | went wrong or we have a null condition expression. */ | |
2358 | if (!loc->cond_bytecode) | |
2359 | { | |
2360 | null_condition_or_parse_error = 1; | |
2361 | break; | |
2362 | } | |
2363 | } | |
2364 | } | |
2365 | ||
2366 | /* If any of these happened, it means we will have to evaluate the conditions | |
2367 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2368 | for all the other duplicate locations, thus we free all of them here. | |
2369 | ||
2370 | This is so we have a finer control over which locations' conditions are | |
2371 | being evaluated by GDB or the remote stub. */ | |
2372 | if (null_condition_or_parse_error) | |
2373 | { | |
2374 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2375 | { | |
2376 | loc = (*loc2p); | |
2377 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2378 | { | |
2379 | /* Only go as far as the first NULL bytecode is | |
2380 | located. */ | |
2381 | if (!loc->cond_bytecode) | |
2382 | return; | |
2383 | ||
833177a4 | 2384 | loc->cond_bytecode.reset (); |
b775012e LM |
2385 | } |
2386 | } | |
2387 | } | |
2388 | ||
2389 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2390 | for this location's address. */ | |
2391 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2392 | { | |
2393 | loc = (*loc2p); | |
2394 | if (loc->cond | |
2395 | && is_breakpoint (loc->owner) | |
2396 | && loc->pspace->num == bl->pspace->num | |
2397 | && loc->owner->enable_state == bp_enabled | |
2398 | && loc->enabled) | |
3cde5c42 PA |
2399 | { |
2400 | /* Add the condition to the vector. This will be used later | |
2401 | to send the conditions to the target. */ | |
2402 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2403 | } | |
b775012e LM |
2404 | } |
2405 | ||
2406 | return; | |
2407 | } | |
2408 | ||
d3ce09f5 SS |
2409 | /* Parses a command described by string CMD into an agent expression |
2410 | bytecode suitable for evaluation by the bytecode interpreter. | |
2411 | Return NULL if there was any error during parsing. */ | |
2412 | ||
833177a4 | 2413 | static agent_expr_up |
d3ce09f5 SS |
2414 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2415 | { | |
2416 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2417 | struct expression **argvec; |
bbc13ae3 KS |
2418 | const char *cmdrest; |
2419 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2420 | struct format_piece *fpieces; |
2421 | int nargs; | |
2422 | struct gdbarch *gdbarch = get_current_arch (); | |
2423 | ||
833177a4 | 2424 | if (cmd == NULL) |
d3ce09f5 SS |
2425 | return NULL; |
2426 | ||
2427 | cmdrest = cmd; | |
2428 | ||
2429 | if (*cmdrest == ',') | |
2430 | ++cmdrest; | |
bbc13ae3 | 2431 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2432 | |
2433 | if (*cmdrest++ != '"') | |
2434 | error (_("No format string following the location")); | |
2435 | ||
2436 | format_start = cmdrest; | |
2437 | ||
2438 | fpieces = parse_format_string (&cmdrest); | |
2439 | ||
2440 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2441 | ||
2442 | format_end = cmdrest; | |
2443 | ||
2444 | if (*cmdrest++ != '"') | |
2445 | error (_("Bad format string, non-terminated '\"'.")); | |
2446 | ||
bbc13ae3 | 2447 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2448 | |
2449 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2450 | error (_("Invalid argument syntax")); | |
2451 | ||
2452 | if (*cmdrest == ',') | |
2453 | cmdrest++; | |
bbc13ae3 | 2454 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2455 | |
2456 | /* For each argument, make an expression. */ | |
2457 | ||
2458 | argvec = (struct expression **) alloca (strlen (cmd) | |
2459 | * sizeof (struct expression *)); | |
2460 | ||
2461 | nargs = 0; | |
2462 | while (*cmdrest != '\0') | |
2463 | { | |
bbc13ae3 | 2464 | const char *cmd1; |
d3ce09f5 SS |
2465 | |
2466 | cmd1 = cmdrest; | |
4d01a485 PA |
2467 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2468 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2469 | cmdrest = cmd1; |
2470 | if (*cmdrest == ',') | |
2471 | ++cmdrest; | |
2472 | } | |
2473 | ||
833177a4 PA |
2474 | agent_expr_up aexpr; |
2475 | ||
d3ce09f5 SS |
2476 | /* We don't want to stop processing, so catch any errors |
2477 | that may show up. */ | |
492d29ea | 2478 | TRY |
d3ce09f5 | 2479 | { |
036e657b JB |
2480 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2481 | format_start, format_end - format_start, | |
2482 | fpieces, nargs, argvec); | |
d3ce09f5 | 2483 | } |
492d29ea | 2484 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2485 | { |
2486 | /* If we got here, it means the command could not be parsed to a valid | |
2487 | bytecode expression and thus can't be evaluated on the target's side. | |
2488 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2489 | } |
492d29ea PA |
2490 | END_CATCH |
2491 | ||
2492 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2493 | |
d3ce09f5 SS |
2494 | /* We have a valid agent expression, return it. */ |
2495 | return aexpr; | |
2496 | } | |
2497 | ||
2498 | /* Based on location BL, create a list of breakpoint commands to be | |
2499 | passed on to the target. If we have duplicated locations with | |
2500 | different commands, we will add any such to the list. */ | |
2501 | ||
2502 | static void | |
2503 | build_target_command_list (struct bp_location *bl) | |
2504 | { | |
2505 | struct bp_location **locp = NULL, **loc2p; | |
2506 | int null_command_or_parse_error = 0; | |
2507 | int modified = bl->needs_update; | |
2508 | struct bp_location *loc; | |
2509 | ||
3cde5c42 PA |
2510 | /* Clear commands left over from a previous insert. */ |
2511 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2512 | |
41fac0cf | 2513 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2514 | return; |
2515 | ||
41fac0cf PA |
2516 | /* For now, limit to agent-style dprintf breakpoints. */ |
2517 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2518 | return; |
2519 | ||
41fac0cf PA |
2520 | /* For now, if we have any duplicate location that isn't a dprintf, |
2521 | don't install the target-side commands, as that would make the | |
2522 | breakpoint not be reported to the core, and we'd lose | |
2523 | control. */ | |
2524 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2525 | { | |
2526 | loc = (*loc2p); | |
2527 | if (is_breakpoint (loc->owner) | |
2528 | && loc->pspace->num == bl->pspace->num | |
2529 | && loc->owner->type != bp_dprintf) | |
2530 | return; | |
2531 | } | |
2532 | ||
d3ce09f5 SS |
2533 | /* Do a first pass to check for locations with no assigned |
2534 | conditions or conditions that fail to parse to a valid agent expression | |
2535 | bytecode. If any of these happen, then it's no use to send conditions | |
2536 | to the target since this location will always trigger and generate a | |
2537 | response back to GDB. */ | |
2538 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2539 | { | |
2540 | loc = (*loc2p); | |
2541 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2542 | { | |
2543 | if (modified) | |
2544 | { | |
d3ce09f5 SS |
2545 | /* Re-parse the commands since something changed. In that |
2546 | case we already freed the command bytecodes (see | |
2547 | force_breakpoint_reinsertion). We just | |
2548 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2549 | loc->cmd_bytecode |
2550 | = parse_cmd_to_aexpr (bl->address, | |
2551 | loc->owner->extra_string); | |
d3ce09f5 SS |
2552 | } |
2553 | ||
2554 | /* If we have a NULL bytecode expression, it means something | |
2555 | went wrong or we have a null command expression. */ | |
2556 | if (!loc->cmd_bytecode) | |
2557 | { | |
2558 | null_command_or_parse_error = 1; | |
2559 | break; | |
2560 | } | |
2561 | } | |
2562 | } | |
2563 | ||
2564 | /* If anything failed, then we're not doing target-side commands, | |
2565 | and so clean up. */ | |
2566 | if (null_command_or_parse_error) | |
2567 | { | |
2568 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2569 | { | |
2570 | loc = (*loc2p); | |
2571 | if (is_breakpoint (loc->owner) | |
2572 | && loc->pspace->num == bl->pspace->num) | |
2573 | { | |
2574 | /* Only go as far as the first NULL bytecode is | |
2575 | located. */ | |
40fb6c5e | 2576 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2577 | return; |
2578 | ||
833177a4 | 2579 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2580 | } |
2581 | } | |
2582 | } | |
2583 | ||
2584 | /* No NULL commands or failed bytecode generation. Build a command list | |
2585 | for this location's address. */ | |
2586 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2587 | { | |
2588 | loc = (*loc2p); | |
2589 | if (loc->owner->extra_string | |
2590 | && is_breakpoint (loc->owner) | |
2591 | && loc->pspace->num == bl->pspace->num | |
2592 | && loc->owner->enable_state == bp_enabled | |
2593 | && loc->enabled) | |
3cde5c42 PA |
2594 | { |
2595 | /* Add the command to the vector. This will be used later | |
2596 | to send the commands to the target. */ | |
2597 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2598 | } | |
d3ce09f5 SS |
2599 | } |
2600 | ||
2601 | bl->target_info.persist = 0; | |
2602 | /* Maybe flag this location as persistent. */ | |
2603 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2604 | bl->target_info.persist = 1; | |
2605 | } | |
2606 | ||
833b7ab5 YQ |
2607 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2608 | of breakpoint according to ADDR except single-step breakpoint. | |
2609 | Get the kind of single-step breakpoint according to the current | |
2610 | registers state. */ | |
cd6c3b4f YQ |
2611 | |
2612 | static int | |
2613 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2614 | { | |
833b7ab5 YQ |
2615 | if (bl->owner->type == bp_single_step) |
2616 | { | |
2617 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2618 | struct regcache *regcache; | |
2619 | ||
2620 | regcache = get_thread_regcache (thr->ptid); | |
2621 | ||
2622 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2623 | regcache, addr); | |
2624 | } | |
2625 | else | |
2626 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2627 | } |
2628 | ||
35df4500 TJB |
2629 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2630 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2631 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2632 | Returns 0 for success, 1 if the bp_location type is not supported or |
2633 | -1 for failure. | |
879bfdc2 | 2634 | |
4a64f543 MS |
2635 | NOTE drow/2003-09-09: This routine could be broken down to an |
2636 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2637 | static int |
35df4500 | 2638 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2639 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2640 | int *disabled_breaks, |
dd61ec5c MW |
2641 | int *hw_breakpoint_error, |
2642 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2643 | { |
0000e5cc PA |
2644 | enum errors bp_err = GDB_NO_ERROR; |
2645 | const char *bp_err_message = NULL; | |
879bfdc2 | 2646 | |
b775012e | 2647 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2648 | return 0; |
2649 | ||
35c63cd8 JB |
2650 | /* Note we don't initialize bl->target_info, as that wipes out |
2651 | the breakpoint location's shadow_contents if the breakpoint | |
2652 | is still inserted at that location. This in turn breaks | |
2653 | target_read_memory which depends on these buffers when | |
2654 | a memory read is requested at the breakpoint location: | |
2655 | Once the target_info has been wiped, we fail to see that | |
2656 | we have a breakpoint inserted at that address and thus | |
2657 | read the breakpoint instead of returning the data saved in | |
2658 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2659 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2660 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2661 | bl->target_info.length = bl->length; |
8181d85f | 2662 | |
b775012e LM |
2663 | /* When working with target-side conditions, we must pass all the conditions |
2664 | for the same breakpoint address down to the target since GDB will not | |
2665 | insert those locations. With a list of breakpoint conditions, the target | |
2666 | can decide when to stop and notify GDB. */ | |
2667 | ||
2668 | if (is_breakpoint (bl->owner)) | |
2669 | { | |
2670 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2671 | build_target_command_list (bl); |
2672 | /* Reset the modification marker. */ | |
b775012e LM |
2673 | bl->needs_update = 0; |
2674 | } | |
2675 | ||
35df4500 TJB |
2676 | if (bl->loc_type == bp_loc_software_breakpoint |
2677 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2678 | { |
35df4500 | 2679 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2680 | { |
2681 | /* If the explicitly specified breakpoint type | |
2682 | is not hardware breakpoint, check the memory map to see | |
2683 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2684 | |
765dc015 VP |
2685 | Two important cases are: |
2686 | - location type is not hardware breakpoint, memory | |
2687 | is readonly. We change the type of the location to | |
2688 | hardware breakpoint. | |
4a64f543 MS |
2689 | - location type is hardware breakpoint, memory is |
2690 | read-write. This means we've previously made the | |
2691 | location hardware one, but then the memory map changed, | |
2692 | so we undo. | |
765dc015 | 2693 | |
4a64f543 MS |
2694 | When breakpoints are removed, remove_breakpoints will use |
2695 | location types we've just set here, the only possible | |
2696 | problem is that memory map has changed during running | |
2697 | program, but it's not going to work anyway with current | |
2698 | gdb. */ | |
765dc015 | 2699 | struct mem_region *mr |
0d5ed153 | 2700 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2701 | |
2702 | if (mr) | |
2703 | { | |
2704 | if (automatic_hardware_breakpoints) | |
2705 | { | |
765dc015 VP |
2706 | enum bp_loc_type new_type; |
2707 | ||
2708 | if (mr->attrib.mode != MEM_RW) | |
2709 | new_type = bp_loc_hardware_breakpoint; | |
2710 | else | |
2711 | new_type = bp_loc_software_breakpoint; | |
2712 | ||
35df4500 | 2713 | if (new_type != bl->loc_type) |
765dc015 VP |
2714 | { |
2715 | static int said = 0; | |
cc59ec59 | 2716 | |
35df4500 | 2717 | bl->loc_type = new_type; |
765dc015 VP |
2718 | if (!said) |
2719 | { | |
3e43a32a MS |
2720 | fprintf_filtered (gdb_stdout, |
2721 | _("Note: automatically using " | |
2722 | "hardware breakpoints for " | |
2723 | "read-only addresses.\n")); | |
765dc015 VP |
2724 | said = 1; |
2725 | } | |
2726 | } | |
2727 | } | |
35df4500 | 2728 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2729 | && mr->attrib.mode != MEM_RW) |
2730 | { | |
2731 | fprintf_unfiltered (tmp_error_stream, | |
2732 | _("Cannot insert breakpoint %d.\n" | |
2733 | "Cannot set software breakpoint " | |
2734 | "at read-only address %s\n"), | |
2735 | bl->owner->number, | |
2736 | paddress (bl->gdbarch, bl->address)); | |
2737 | return 1; | |
2738 | } | |
765dc015 VP |
2739 | } |
2740 | } | |
2741 | ||
879bfdc2 DJ |
2742 | /* First check to see if we have to handle an overlay. */ |
2743 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2744 | || bl->section == NULL |
2745 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2746 | { |
2747 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2748 | TRY |
dd61ec5c | 2749 | { |
0000e5cc PA |
2750 | int val; |
2751 | ||
dd61ec5c | 2752 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2753 | if (val) |
2754 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2755 | } |
492d29ea | 2756 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2757 | { |
0000e5cc PA |
2758 | bp_err = e.error; |
2759 | bp_err_message = e.message; | |
dd61ec5c | 2760 | } |
492d29ea | 2761 | END_CATCH |
879bfdc2 DJ |
2762 | } |
2763 | else | |
2764 | { | |
4a64f543 | 2765 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2766 | Shall we set a breakpoint at the LMA? */ |
2767 | if (!overlay_events_enabled) | |
2768 | { | |
2769 | /* Yes -- overlay event support is not active, | |
2770 | so we must try to set a breakpoint at the LMA. | |
2771 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2772 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2773 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2774 | bl->owner->number); |
879bfdc2 DJ |
2775 | else |
2776 | { | |
35df4500 TJB |
2777 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2778 | bl->section); | |
879bfdc2 | 2779 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2780 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2781 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2782 | |
2783 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2784 | TRY |
0000e5cc PA |
2785 | { |
2786 | int val; | |
2787 | ||
579c6ad9 | 2788 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2789 | = breakpoint_kind (bl, &addr); |
2790 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2791 | val = target_insert_breakpoint (bl->gdbarch, |
2792 | &bl->overlay_target_info); | |
2793 | if (val) | |
2794 | bp_err = GENERIC_ERROR; | |
2795 | } | |
492d29ea | 2796 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2797 | { |
2798 | bp_err = e.error; | |
2799 | bp_err_message = e.message; | |
2800 | } | |
492d29ea | 2801 | END_CATCH |
0000e5cc PA |
2802 | |
2803 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2804 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2805 | "Overlay breakpoint %d " |
2806 | "failed: in ROM?\n", | |
35df4500 | 2807 | bl->owner->number); |
879bfdc2 DJ |
2808 | } |
2809 | } | |
2810 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2811 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2812 | { |
2813 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2814 | TRY |
dd61ec5c | 2815 | { |
0000e5cc PA |
2816 | int val; |
2817 | ||
dd61ec5c | 2818 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2819 | if (val) |
2820 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2821 | } |
492d29ea | 2822 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2823 | { |
0000e5cc PA |
2824 | bp_err = e.error; |
2825 | bp_err_message = e.message; | |
dd61ec5c | 2826 | } |
492d29ea | 2827 | END_CATCH |
879bfdc2 DJ |
2828 | } |
2829 | else | |
2830 | { | |
2831 | /* No. This breakpoint will not be inserted. | |
2832 | No error, but do not mark the bp as 'inserted'. */ | |
2833 | return 0; | |
2834 | } | |
2835 | } | |
2836 | ||
0000e5cc | 2837 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2838 | { |
2839 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2840 | |
2841 | /* In some cases, we might not be able to insert a | |
2842 | breakpoint in a shared library that has already been | |
2843 | removed, but we have not yet processed the shlib unload | |
2844 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2845 | breakpoint insertion themselves can't tell why the |
2846 | breakpoint insertion failed (e.g., the remote target | |
2847 | doesn't define error codes), so we must treat generic | |
2848 | errors as memory errors. */ | |
0000e5cc | 2849 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2850 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2851 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2852 | || shared_objfile_contains_address_p (bl->pspace, |
2853 | bl->address))) | |
879bfdc2 | 2854 | { |
4a64f543 | 2855 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2856 | bl->shlib_disabled = 1; |
8d3788bd | 2857 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2858 | if (!*disabled_breaks) |
2859 | { | |
2860 | fprintf_unfiltered (tmp_error_stream, | |
2861 | "Cannot insert breakpoint %d.\n", | |
2862 | bl->owner->number); | |
2863 | fprintf_unfiltered (tmp_error_stream, | |
2864 | "Temporarily disabling shared " | |
2865 | "library breakpoints:\n"); | |
2866 | } | |
2867 | *disabled_breaks = 1; | |
879bfdc2 | 2868 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2869 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2870 | return 0; |
879bfdc2 DJ |
2871 | } |
2872 | else | |
879bfdc2 | 2873 | { |
35df4500 | 2874 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2875 | { |
0000e5cc PA |
2876 | *hw_breakpoint_error = 1; |
2877 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2878 | fprintf_unfiltered (tmp_error_stream, |
2879 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2880 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2881 | if (bp_err_message != NULL) | |
2882 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2883 | } |
2884 | else | |
2885 | { | |
0000e5cc PA |
2886 | if (bp_err_message == NULL) |
2887 | { | |
2888 | char *message | |
2889 | = memory_error_message (TARGET_XFER_E_IO, | |
2890 | bl->gdbarch, bl->address); | |
2891 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2892 | ||
2893 | fprintf_unfiltered (tmp_error_stream, | |
2894 | "Cannot insert breakpoint %d.\n" | |
2895 | "%s\n", | |
2896 | bl->owner->number, message); | |
2897 | do_cleanups (old_chain); | |
2898 | } | |
2899 | else | |
2900 | { | |
2901 | fprintf_unfiltered (tmp_error_stream, | |
2902 | "Cannot insert breakpoint %d: %s\n", | |
2903 | bl->owner->number, | |
2904 | bp_err_message); | |
2905 | } | |
879bfdc2 | 2906 | } |
0000e5cc | 2907 | return 1; |
879bfdc2 DJ |
2908 | |
2909 | } | |
2910 | } | |
2911 | else | |
35df4500 | 2912 | bl->inserted = 1; |
879bfdc2 | 2913 | |
0000e5cc | 2914 | return 0; |
879bfdc2 DJ |
2915 | } |
2916 | ||
35df4500 | 2917 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2918 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2919 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2920 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2921 | { |
0000e5cc PA |
2922 | int val; |
2923 | ||
77b06cd7 TJB |
2924 | gdb_assert (bl->owner->ops != NULL |
2925 | && bl->owner->ops->insert_location != NULL); | |
2926 | ||
2927 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2928 | |
2929 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2930 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2931 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2932 | { |
2933 | struct bp_location *loc, **loc_temp; | |
2934 | ||
2935 | /* But don't try to insert it, if there's already another | |
2936 | hw_access location that would be considered a duplicate | |
2937 | of this one. */ | |
2938 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2939 | if (loc != bl |
85d721b8 | 2940 | && loc->watchpoint_type == hw_access |
35df4500 | 2941 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2942 | { |
35df4500 TJB |
2943 | bl->duplicate = 1; |
2944 | bl->inserted = 1; | |
2945 | bl->target_info = loc->target_info; | |
2946 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2947 | val = 0; |
2948 | break; | |
2949 | } | |
2950 | ||
2951 | if (val == 1) | |
2952 | { | |
77b06cd7 TJB |
2953 | bl->watchpoint_type = hw_access; |
2954 | val = bl->owner->ops->insert_location (bl); | |
2955 | ||
2956 | if (val) | |
2957 | /* Back to the original value. */ | |
2958 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2959 | } |
2960 | } | |
2961 | ||
35df4500 | 2962 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2963 | } |
2964 | ||
35df4500 | 2965 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2966 | { |
0000e5cc PA |
2967 | int val; |
2968 | ||
77b06cd7 TJB |
2969 | gdb_assert (bl->owner->ops != NULL |
2970 | && bl->owner->ops->insert_location != NULL); | |
2971 | ||
2972 | val = bl->owner->ops->insert_location (bl); | |
2973 | if (val) | |
2974 | { | |
2975 | bl->owner->enable_state = bp_disabled; | |
2976 | ||
2977 | if (val == 1) | |
2978 | warning (_("\ | |
2979 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2980 | of catchpoint."), bl->owner->number); | |
2981 | else | |
2982 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2983 | } | |
2984 | ||
2985 | bl->inserted = (val == 0); | |
1640b821 DJ |
2986 | |
2987 | /* We've already printed an error message if there was a problem | |
2988 | inserting this catchpoint, and we've disabled the catchpoint, | |
2989 | so just return success. */ | |
2990 | return 0; | |
879bfdc2 DJ |
2991 | } |
2992 | ||
2993 | return 0; | |
2994 | } | |
2995 | ||
6c95b8df PA |
2996 | /* This function is called when program space PSPACE is about to be |
2997 | deleted. It takes care of updating breakpoints to not reference | |
2998 | PSPACE anymore. */ | |
2999 | ||
3000 | void | |
3001 | breakpoint_program_space_exit (struct program_space *pspace) | |
3002 | { | |
3003 | struct breakpoint *b, *b_temp; | |
876fa593 | 3004 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
3005 | |
3006 | /* Remove any breakpoint that was set through this program space. */ | |
3007 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
3008 | { | |
3009 | if (b->pspace == pspace) | |
3010 | delete_breakpoint (b); | |
3011 | } | |
3012 | ||
3013 | /* Breakpoints set through other program spaces could have locations | |
3014 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 3015 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
3016 | { |
3017 | struct bp_location *tmp; | |
3018 | ||
3019 | if (loc->pspace == pspace) | |
3020 | { | |
2bdf28a0 | 3021 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
3022 | if (loc->owner->loc == loc) |
3023 | loc->owner->loc = loc->next; | |
3024 | else | |
3025 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3026 | if (tmp->next == loc) | |
3027 | { | |
3028 | tmp->next = loc->next; | |
3029 | break; | |
3030 | } | |
3031 | } | |
3032 | } | |
3033 | ||
3034 | /* Now update the global location list to permanently delete the | |
3035 | removed locations above. */ | |
44702360 | 3036 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3037 | } |
3038 | ||
74960c60 VP |
3039 | /* Make sure all breakpoints are inserted in inferior. |
3040 | Throws exception on any error. | |
3041 | A breakpoint that is already inserted won't be inserted | |
3042 | again, so calling this function twice is safe. */ | |
3043 | void | |
3044 | insert_breakpoints (void) | |
3045 | { | |
3046 | struct breakpoint *bpt; | |
3047 | ||
3048 | ALL_BREAKPOINTS (bpt) | |
3049 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3050 | { |
3051 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3052 | ||
3053 | update_watchpoint (w, 0 /* don't reparse. */); | |
3054 | } | |
74960c60 | 3055 | |
04086b45 PA |
3056 | /* Updating watchpoints creates new locations, so update the global |
3057 | location list. Explicitly tell ugll to insert locations and | |
3058 | ignore breakpoints_always_inserted_mode. */ | |
3059 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3060 | } |
3061 | ||
20388dd6 YQ |
3062 | /* Invoke CALLBACK for each of bp_location. */ |
3063 | ||
3064 | void | |
3065 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3066 | { | |
3067 | struct bp_location *loc, **loc_tmp; | |
3068 | ||
3069 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3070 | { | |
3071 | callback (loc, NULL); | |
3072 | } | |
3073 | } | |
3074 | ||
b775012e LM |
3075 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3076 | target. It is the case with deleting and disabling of breakpoints when using | |
3077 | always-inserted mode. */ | |
3078 | ||
3079 | static void | |
3080 | update_inserted_breakpoint_locations (void) | |
3081 | { | |
3082 | struct bp_location *bl, **blp_tmp; | |
3083 | int error_flag = 0; | |
3084 | int val = 0; | |
3085 | int disabled_breaks = 0; | |
3086 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3087 | int hw_bp_details_reported = 0; |
b775012e | 3088 | |
d7e74731 | 3089 | string_file tmp_error_stream; |
b775012e LM |
3090 | |
3091 | /* Explicitly mark the warning -- this will only be printed if | |
3092 | there was an error. */ | |
d7e74731 | 3093 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 3094 | |
5ed8105e | 3095 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
3096 | |
3097 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3098 | { | |
3099 | /* We only want to update software breakpoints and hardware | |
3100 | breakpoints. */ | |
3101 | if (!is_breakpoint (bl->owner)) | |
3102 | continue; | |
3103 | ||
3104 | /* We only want to update locations that are already inserted | |
3105 | and need updating. This is to avoid unwanted insertion during | |
3106 | deletion of breakpoints. */ | |
3107 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3108 | continue; | |
3109 | ||
3110 | switch_to_program_space_and_thread (bl->pspace); | |
3111 | ||
3112 | /* For targets that support global breakpoints, there's no need | |
3113 | to select an inferior to insert breakpoint to. In fact, even | |
3114 | if we aren't attached to any process yet, we should still | |
3115 | insert breakpoints. */ | |
f5656ead | 3116 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3117 | && ptid_equal (inferior_ptid, null_ptid)) |
3118 | continue; | |
3119 | ||
d7e74731 | 3120 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3121 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3122 | if (val) |
3123 | error_flag = val; | |
3124 | } | |
3125 | ||
3126 | if (error_flag) | |
3127 | { | |
3128 | target_terminal_ours_for_output (); | |
3129 | error_stream (tmp_error_stream); | |
3130 | } | |
b775012e LM |
3131 | } |
3132 | ||
c30eee59 | 3133 | /* Used when starting or continuing the program. */ |
c906108c | 3134 | |
74960c60 VP |
3135 | static void |
3136 | insert_breakpoint_locations (void) | |
c906108c | 3137 | { |
a5606eee | 3138 | struct breakpoint *bpt; |
35df4500 | 3139 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3140 | int error_flag = 0; |
c906108c | 3141 | int val = 0; |
3fbb6ffa | 3142 | int disabled_breaks = 0; |
81d0cc19 | 3143 | int hw_breakpoint_error = 0; |
dd61ec5c | 3144 | int hw_bp_error_explained_already = 0; |
c906108c | 3145 | |
d7e74731 PA |
3146 | string_file tmp_error_stream; |
3147 | ||
81d0cc19 GS |
3148 | /* Explicitly mark the warning -- this will only be printed if |
3149 | there was an error. */ | |
d7e74731 | 3150 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3151 | |
5ed8105e | 3152 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3153 | |
35df4500 | 3154 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3155 | { |
b775012e | 3156 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3157 | continue; |
3158 | ||
4a64f543 MS |
3159 | /* There is no point inserting thread-specific breakpoints if |
3160 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3161 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3162 | if (bl->owner->thread != -1 |
5d5658a1 | 3163 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3164 | continue; |
3165 | ||
35df4500 | 3166 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3167 | |
3168 | /* For targets that support global breakpoints, there's no need | |
3169 | to select an inferior to insert breakpoint to. In fact, even | |
3170 | if we aren't attached to any process yet, we should still | |
3171 | insert breakpoints. */ | |
f5656ead | 3172 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3173 | && ptid_equal (inferior_ptid, null_ptid)) |
3174 | continue; | |
3175 | ||
d7e74731 | 3176 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3177 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3178 | if (val) |
eacd795a | 3179 | error_flag = val; |
879bfdc2 | 3180 | } |
c906108c | 3181 | |
4a64f543 MS |
3182 | /* If we failed to insert all locations of a watchpoint, remove |
3183 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3184 | ALL_BREAKPOINTS (bpt) |
3185 | { | |
3186 | int some_failed = 0; | |
3187 | struct bp_location *loc; | |
3188 | ||
3189 | if (!is_hardware_watchpoint (bpt)) | |
3190 | continue; | |
3191 | ||
d6b74ac4 | 3192 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3193 | continue; |
74960c60 VP |
3194 | |
3195 | if (bpt->disposition == disp_del_at_next_stop) | |
3196 | continue; | |
a5606eee VP |
3197 | |
3198 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3199 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3200 | { |
3201 | some_failed = 1; | |
3202 | break; | |
3203 | } | |
3204 | if (some_failed) | |
3205 | { | |
3206 | for (loc = bpt->loc; loc; loc = loc->next) | |
3207 | if (loc->inserted) | |
834c0d03 | 3208 | remove_breakpoint (loc); |
a5606eee VP |
3209 | |
3210 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3211 | tmp_error_stream.printf ("Could not insert " |
3212 | "hardware watchpoint %d.\n", | |
3213 | bpt->number); | |
eacd795a | 3214 | error_flag = -1; |
a5606eee VP |
3215 | } |
3216 | } | |
3217 | ||
eacd795a | 3218 | if (error_flag) |
81d0cc19 GS |
3219 | { |
3220 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3221 | message about possibly exhausted resources. */ | |
dd61ec5c | 3222 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3223 | { |
d7e74731 | 3224 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3225 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3226 | } |
81d0cc19 GS |
3227 | target_terminal_ours_for_output (); |
3228 | error_stream (tmp_error_stream); | |
3229 | } | |
c906108c SS |
3230 | } |
3231 | ||
c30eee59 TJB |
3232 | /* Used when the program stops. |
3233 | Returns zero if successful, or non-zero if there was a problem | |
3234 | removing a breakpoint location. */ | |
3235 | ||
c906108c | 3236 | int |
fba45db2 | 3237 | remove_breakpoints (void) |
c906108c | 3238 | { |
35df4500 | 3239 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3240 | int val = 0; |
c906108c | 3241 | |
35df4500 | 3242 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3243 | { |
1e4d1764 | 3244 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3245 | val |= remove_breakpoint (bl); |
c5aa993b | 3246 | } |
3a1bae8e | 3247 | return val; |
c906108c SS |
3248 | } |
3249 | ||
49fa26b0 PA |
3250 | /* When a thread exits, remove breakpoints that are related to |
3251 | that thread. */ | |
3252 | ||
3253 | static void | |
3254 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3255 | { | |
3256 | struct breakpoint *b, *b_tmp; | |
3257 | ||
3258 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3259 | { | |
5d5658a1 | 3260 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3261 | { |
3262 | b->disposition = disp_del_at_next_stop; | |
3263 | ||
3264 | printf_filtered (_("\ | |
43792cf0 PA |
3265 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3266 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3267 | |
3268 | /* Hide it from the user. */ | |
3269 | b->number = 0; | |
3270 | } | |
3271 | } | |
3272 | } | |
3273 | ||
6c95b8df PA |
3274 | /* Remove breakpoints of process PID. */ |
3275 | ||
3276 | int | |
3277 | remove_breakpoints_pid (int pid) | |
3278 | { | |
35df4500 | 3279 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3280 | int val; |
3281 | struct inferior *inf = find_inferior_pid (pid); | |
3282 | ||
35df4500 | 3283 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3284 | { |
35df4500 | 3285 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3286 | continue; |
3287 | ||
fc126975 | 3288 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3289 | { |
834c0d03 | 3290 | val = remove_breakpoint (bl); |
6c95b8df PA |
3291 | if (val != 0) |
3292 | return val; | |
3293 | } | |
3294 | } | |
3295 | return 0; | |
3296 | } | |
3297 | ||
c906108c | 3298 | int |
fba45db2 | 3299 | reattach_breakpoints (int pid) |
c906108c | 3300 | { |
6c95b8df | 3301 | struct cleanup *old_chain; |
35df4500 | 3302 | struct bp_location *bl, **blp_tmp; |
c906108c | 3303 | int val; |
dd61ec5c | 3304 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3305 | struct inferior *inf; |
3306 | struct thread_info *tp; | |
3307 | ||
3308 | tp = any_live_thread_of_process (pid); | |
3309 | if (tp == NULL) | |
3310 | return 1; | |
3311 | ||
3312 | inf = find_inferior_pid (pid); | |
3313 | old_chain = save_inferior_ptid (); | |
3314 | ||
3315 | inferior_ptid = tp->ptid; | |
a4954f26 | 3316 | |
d7e74731 | 3317 | string_file tmp_error_stream; |
c906108c | 3318 | |
35df4500 | 3319 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3320 | { |
35df4500 | 3321 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3322 | continue; |
3323 | ||
35df4500 | 3324 | if (bl->inserted) |
c5aa993b | 3325 | { |
35df4500 | 3326 | bl->inserted = 0; |
d7e74731 | 3327 | val = insert_bp_location (bl, &tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3328 | if (val != 0) |
3329 | { | |
ce696e05 | 3330 | do_cleanups (old_chain); |
c5aa993b JM |
3331 | return val; |
3332 | } | |
3333 | } | |
3334 | } | |
ce696e05 | 3335 | do_cleanups (old_chain); |
c906108c SS |
3336 | return 0; |
3337 | } | |
3338 | ||
e58b0e63 PA |
3339 | static int internal_breakpoint_number = -1; |
3340 | ||
84f4c1fe PM |
3341 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3342 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3343 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3344 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3345 | breakpoint_count and that value incremented. Internal breakpoints |
3346 | do not set the internal var bpnum. */ | |
3347 | static void | |
3348 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3349 | { | |
3350 | if (internal) | |
3351 | b->number = internal_breakpoint_number--; | |
3352 | else | |
3353 | { | |
3354 | set_breakpoint_count (breakpoint_count + 1); | |
3355 | b->number = breakpoint_count; | |
3356 | } | |
3357 | } | |
3358 | ||
e62c965a | 3359 | static struct breakpoint * |
a6d9a66e | 3360 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3361 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3362 | const struct breakpoint_ops *ops) |
e62c965a | 3363 | { |
e62c965a PP |
3364 | struct symtab_and_line sal; |
3365 | struct breakpoint *b; | |
3366 | ||
4a64f543 | 3367 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3368 | |
3369 | sal.pc = address; | |
3370 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3371 | sal.pspace = current_program_space; |
e62c965a | 3372 | |
06edf0c0 | 3373 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3374 | b->number = internal_breakpoint_number--; |
3375 | b->disposition = disp_donttouch; | |
3376 | ||
3377 | return b; | |
3378 | } | |
3379 | ||
17450429 PP |
3380 | static const char *const longjmp_names[] = |
3381 | { | |
3382 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3383 | }; | |
3384 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3385 | ||
3386 | /* Per-objfile data private to breakpoint.c. */ | |
3387 | struct breakpoint_objfile_data | |
3388 | { | |
3389 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3390 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3391 | |
3392 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3393 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3394 | |
28106bc2 SDJ |
3395 | /* True if we have looked for longjmp probes. */ |
3396 | int longjmp_searched; | |
3397 | ||
3398 | /* SystemTap probe points for longjmp (if any). */ | |
3399 | VEC (probe_p) *longjmp_probes; | |
3400 | ||
17450429 | 3401 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3402 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3403 | |
3404 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3405 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3406 | |
3407 | /* True if we have looked for exception probes. */ | |
3408 | int exception_searched; | |
3409 | ||
3410 | /* SystemTap probe points for unwinding (if any). */ | |
3411 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3412 | }; |
3413 | ||
3414 | static const struct objfile_data *breakpoint_objfile_key; | |
3415 | ||
3416 | /* Minimal symbol not found sentinel. */ | |
3417 | static struct minimal_symbol msym_not_found; | |
3418 | ||
3419 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3420 | ||
3421 | static int | |
3422 | msym_not_found_p (const struct minimal_symbol *msym) | |
3423 | { | |
3424 | return msym == &msym_not_found; | |
3425 | } | |
3426 | ||
3427 | /* Return per-objfile data needed by breakpoint.c. | |
3428 | Allocate the data if necessary. */ | |
3429 | ||
3430 | static struct breakpoint_objfile_data * | |
3431 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3432 | { | |
3433 | struct breakpoint_objfile_data *bp_objfile_data; | |
3434 | ||
9a3c8263 SM |
3435 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3436 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3437 | if (bp_objfile_data == NULL) |
3438 | { | |
8d749320 SM |
3439 | bp_objfile_data = |
3440 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3441 | |
3442 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3443 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3444 | } | |
3445 | return bp_objfile_data; | |
3446 | } | |
3447 | ||
28106bc2 SDJ |
3448 | static void |
3449 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3450 | { | |
9a3c8263 SM |
3451 | struct breakpoint_objfile_data *bp_objfile_data |
3452 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3453 | |
3454 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3455 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3456 | } | |
3457 | ||
e62c965a | 3458 | static void |
af02033e | 3459 | create_overlay_event_breakpoint (void) |
e62c965a | 3460 | { |
69de3c6a | 3461 | struct objfile *objfile; |
af02033e | 3462 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3463 | |
69de3c6a PP |
3464 | ALL_OBJFILES (objfile) |
3465 | { | |
3466 | struct breakpoint *b; | |
17450429 PP |
3467 | struct breakpoint_objfile_data *bp_objfile_data; |
3468 | CORE_ADDR addr; | |
67994074 | 3469 | struct explicit_location explicit_loc; |
69de3c6a | 3470 | |
17450429 PP |
3471 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3472 | ||
3b7344d5 | 3473 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3474 | continue; |
3475 | ||
3b7344d5 | 3476 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3477 | { |
3b7344d5 | 3478 | struct bound_minimal_symbol m; |
17450429 PP |
3479 | |
3480 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3481 | if (m.minsym == NULL) |
17450429 PP |
3482 | { |
3483 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3484 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3485 | continue; |
3486 | } | |
3487 | bp_objfile_data->overlay_msym = m; | |
3488 | } | |
e62c965a | 3489 | |
77e371c0 | 3490 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3491 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3492 | bp_overlay_event, |
3493 | &internal_breakpoint_ops); | |
67994074 KS |
3494 | initialize_explicit_location (&explicit_loc); |
3495 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3496 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3497 | |
69de3c6a PP |
3498 | if (overlay_debugging == ovly_auto) |
3499 | { | |
3500 | b->enable_state = bp_enabled; | |
3501 | overlay_events_enabled = 1; | |
3502 | } | |
3503 | else | |
3504 | { | |
3505 | b->enable_state = bp_disabled; | |
3506 | overlay_events_enabled = 0; | |
3507 | } | |
e62c965a | 3508 | } |
e62c965a PP |
3509 | } |
3510 | ||
0fd8e87f | 3511 | static void |
af02033e | 3512 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3513 | { |
6c95b8df | 3514 | struct program_space *pspace; |
6c95b8df | 3515 | |
5ed8105e | 3516 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3517 | |
6c95b8df | 3518 | ALL_PSPACES (pspace) |
af02033e PP |
3519 | { |
3520 | struct objfile *objfile; | |
3521 | ||
3522 | set_current_program_space (pspace); | |
3523 | ||
3524 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3525 | { |
af02033e PP |
3526 | int i; |
3527 | struct gdbarch *gdbarch; | |
17450429 | 3528 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3529 | |
af02033e | 3530 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3531 | |
17450429 PP |
3532 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3533 | ||
28106bc2 SDJ |
3534 | if (!bp_objfile_data->longjmp_searched) |
3535 | { | |
25f9533e SDJ |
3536 | VEC (probe_p) *ret; |
3537 | ||
3538 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3539 | if (ret != NULL) | |
3540 | { | |
3541 | /* We are only interested in checking one element. */ | |
3542 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3543 | ||
3544 | if (!can_evaluate_probe_arguments (p)) | |
3545 | { | |
3546 | /* We cannot use the probe interface here, because it does | |
3547 | not know how to evaluate arguments. */ | |
3548 | VEC_free (probe_p, ret); | |
3549 | ret = NULL; | |
3550 | } | |
3551 | } | |
3552 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3553 | bp_objfile_data->longjmp_searched = 1; |
3554 | } | |
3555 | ||
3556 | if (bp_objfile_data->longjmp_probes != NULL) | |
3557 | { | |
3558 | int i; | |
3559 | struct probe *probe; | |
3560 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3561 | ||
3562 | for (i = 0; | |
3563 | VEC_iterate (probe_p, | |
3564 | bp_objfile_data->longjmp_probes, | |
3565 | i, probe); | |
3566 | ++i) | |
3567 | { | |
3568 | struct breakpoint *b; | |
3569 | ||
729662a5 TT |
3570 | b = create_internal_breakpoint (gdbarch, |
3571 | get_probe_address (probe, | |
3572 | objfile), | |
28106bc2 SDJ |
3573 | bp_longjmp_master, |
3574 | &internal_breakpoint_ops); | |
d28cd78a | 3575 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
28106bc2 SDJ |
3576 | b->enable_state = bp_disabled; |
3577 | } | |
3578 | ||
3579 | continue; | |
3580 | } | |
3581 | ||
0569175e TSD |
3582 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3583 | continue; | |
3584 | ||
17450429 | 3585 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3586 | { |
3587 | struct breakpoint *b; | |
af02033e | 3588 | const char *func_name; |
17450429 | 3589 | CORE_ADDR addr; |
67994074 | 3590 | struct explicit_location explicit_loc; |
6c95b8df | 3591 | |
3b7344d5 | 3592 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3593 | continue; |
0fd8e87f | 3594 | |
17450429 | 3595 | func_name = longjmp_names[i]; |
3b7344d5 | 3596 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3597 | { |
3b7344d5 | 3598 | struct bound_minimal_symbol m; |
17450429 PP |
3599 | |
3600 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3601 | if (m.minsym == NULL) |
17450429 PP |
3602 | { |
3603 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3604 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3605 | continue; |
3606 | } | |
3607 | bp_objfile_data->longjmp_msym[i] = m; | |
3608 | } | |
3609 | ||
77e371c0 | 3610 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3611 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3612 | &internal_breakpoint_ops); | |
67994074 KS |
3613 | initialize_explicit_location (&explicit_loc); |
3614 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3615 | b->location = new_explicit_location (&explicit_loc); |
af02033e PP |
3616 | b->enable_state = bp_disabled; |
3617 | } | |
0fd8e87f | 3618 | } |
af02033e | 3619 | } |
0fd8e87f UW |
3620 | } |
3621 | ||
af02033e | 3622 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3623 | static void |
af02033e | 3624 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3625 | { |
3626 | struct program_space *pspace; | |
af02033e | 3627 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3628 | |
5ed8105e | 3629 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3630 | |
3631 | ALL_PSPACES (pspace) | |
17450429 PP |
3632 | { |
3633 | struct objfile *objfile; | |
3634 | CORE_ADDR addr; | |
3635 | ||
3636 | set_current_program_space (pspace); | |
3637 | ||
aa7d318d TT |
3638 | ALL_OBJFILES (objfile) |
3639 | { | |
3640 | struct breakpoint *b; | |
17450429 | 3641 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3642 | struct explicit_location explicit_loc; |
aa7d318d | 3643 | |
17450429 | 3644 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3645 | |
3b7344d5 | 3646 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3647 | continue; |
3648 | ||
3b7344d5 | 3649 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3650 | { |
3b7344d5 | 3651 | struct bound_minimal_symbol m; |
17450429 PP |
3652 | |
3653 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3654 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3655 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3656 | { |
3657 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3658 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3659 | continue; |
3660 | } | |
3661 | bp_objfile_data->terminate_msym = m; | |
3662 | } | |
aa7d318d | 3663 | |
77e371c0 | 3664 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3665 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3666 | bp_std_terminate_master, |
3667 | &internal_breakpoint_ops); | |
67994074 KS |
3668 | initialize_explicit_location (&explicit_loc); |
3669 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3670 | b->location = new_explicit_location (&explicit_loc); |
aa7d318d TT |
3671 | b->enable_state = bp_disabled; |
3672 | } | |
17450429 | 3673 | } |
aa7d318d TT |
3674 | } |
3675 | ||
186c406b TT |
3676 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3677 | ||
70221824 | 3678 | static void |
186c406b TT |
3679 | create_exception_master_breakpoint (void) |
3680 | { | |
3681 | struct objfile *objfile; | |
17450429 | 3682 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3683 | |
3684 | ALL_OBJFILES (objfile) | |
3685 | { | |
17450429 PP |
3686 | struct breakpoint *b; |
3687 | struct gdbarch *gdbarch; | |
3688 | struct breakpoint_objfile_data *bp_objfile_data; | |
3689 | CORE_ADDR addr; | |
67994074 | 3690 | struct explicit_location explicit_loc; |
17450429 PP |
3691 | |
3692 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3693 | ||
28106bc2 SDJ |
3694 | /* We prefer the SystemTap probe point if it exists. */ |
3695 | if (!bp_objfile_data->exception_searched) | |
3696 | { | |
25f9533e SDJ |
3697 | VEC (probe_p) *ret; |
3698 | ||
3699 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3700 | ||
3701 | if (ret != NULL) | |
3702 | { | |
3703 | /* We are only interested in checking one element. */ | |
3704 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3705 | ||
3706 | if (!can_evaluate_probe_arguments (p)) | |
3707 | { | |
3708 | /* We cannot use the probe interface here, because it does | |
3709 | not know how to evaluate arguments. */ | |
3710 | VEC_free (probe_p, ret); | |
3711 | ret = NULL; | |
3712 | } | |
3713 | } | |
3714 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3715 | bp_objfile_data->exception_searched = 1; |
3716 | } | |
3717 | ||
3718 | if (bp_objfile_data->exception_probes != NULL) | |
3719 | { | |
3720 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3721 | int i; | |
3722 | struct probe *probe; | |
3723 | ||
3724 | for (i = 0; | |
3725 | VEC_iterate (probe_p, | |
3726 | bp_objfile_data->exception_probes, | |
3727 | i, probe); | |
3728 | ++i) | |
3729 | { | |
3730 | struct breakpoint *b; | |
3731 | ||
729662a5 TT |
3732 | b = create_internal_breakpoint (gdbarch, |
3733 | get_probe_address (probe, | |
3734 | objfile), | |
28106bc2 SDJ |
3735 | bp_exception_master, |
3736 | &internal_breakpoint_ops); | |
d28cd78a | 3737 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3738 | b->enable_state = bp_disabled; |
3739 | } | |
3740 | ||
3741 | continue; | |
3742 | } | |
3743 | ||
3744 | /* Otherwise, try the hook function. */ | |
3745 | ||
3b7344d5 | 3746 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3747 | continue; |
3748 | ||
3749 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3750 | |
3b7344d5 | 3751 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3752 | { |
3b7344d5 | 3753 | struct bound_minimal_symbol debug_hook; |
186c406b | 3754 | |
17450429 | 3755 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3756 | if (debug_hook.minsym == NULL) |
17450429 | 3757 | { |
3b7344d5 | 3758 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3759 | continue; |
3760 | } | |
3761 | ||
3762 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3763 | } |
17450429 | 3764 | |
77e371c0 | 3765 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3766 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3767 | ¤t_target); | |
06edf0c0 PA |
3768 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3769 | &internal_breakpoint_ops); | |
67994074 KS |
3770 | initialize_explicit_location (&explicit_loc); |
3771 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3772 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3773 | b->enable_state = bp_disabled; |
186c406b | 3774 | } |
186c406b TT |
3775 | } |
3776 | ||
9ef9e6a6 KS |
3777 | /* Does B have a location spec? */ |
3778 | ||
3779 | static int | |
3780 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3781 | { | |
d28cd78a | 3782 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3783 | } |
3784 | ||
c906108c | 3785 | void |
fba45db2 | 3786 | update_breakpoints_after_exec (void) |
c906108c | 3787 | { |
35df4500 | 3788 | struct breakpoint *b, *b_tmp; |
876fa593 | 3789 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3790 | |
25b22b0a PA |
3791 | /* We're about to delete breakpoints from GDB's lists. If the |
3792 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3793 | writing the breakpoints' "shadow contents" back into memory. The | |
3794 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3795 | do that. Instead, the target is responsible from marking | |
3796 | breakpoints out as soon as it detects an exec. We don't do that | |
3797 | here instead, because there may be other attempts to delete | |
3798 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3799 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3800 | if (bploc->pspace == current_program_space) |
3801 | gdb_assert (!bploc->inserted); | |
c906108c | 3802 | |
35df4500 | 3803 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3804 | { |
6c95b8df PA |
3805 | if (b->pspace != current_program_space) |
3806 | continue; | |
3807 | ||
4a64f543 | 3808 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3809 | if (b->type == bp_shlib_event) |
3810 | { | |
3811 | delete_breakpoint (b); | |
3812 | continue; | |
3813 | } | |
c906108c | 3814 | |
4a64f543 | 3815 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3816 | if (b->type == bp_jit_event) |
3817 | { | |
3818 | delete_breakpoint (b); | |
3819 | continue; | |
3820 | } | |
3821 | ||
1900040c | 3822 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3823 | as must overlay event and longjmp master breakpoints. */ |
3824 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3825 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3826 | || b->type == bp_exception_master) | |
c4093a6a JM |
3827 | { |
3828 | delete_breakpoint (b); | |
3829 | continue; | |
3830 | } | |
3831 | ||
4a64f543 | 3832 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3833 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3834 | { |
3835 | delete_breakpoint (b); | |
3836 | continue; | |
3837 | } | |
3838 | ||
7c16b83e PA |
3839 | /* Just like single-step breakpoints. */ |
3840 | if (b->type == bp_single_step) | |
3841 | { | |
3842 | delete_breakpoint (b); | |
3843 | continue; | |
3844 | } | |
3845 | ||
611c83ae PA |
3846 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3847 | after an exec. */ | |
186c406b | 3848 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3849 | || b->type == bp_longjmp_call_dummy |
186c406b | 3850 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3851 | { |
3852 | delete_breakpoint (b); | |
3853 | continue; | |
3854 | } | |
3855 | ||
ce78b96d JB |
3856 | if (b->type == bp_catchpoint) |
3857 | { | |
3858 | /* For now, none of the bp_catchpoint breakpoints need to | |
3859 | do anything at this point. In the future, if some of | |
3860 | the catchpoints need to something, we will need to add | |
3861 | a new method, and call this method from here. */ | |
3862 | continue; | |
3863 | } | |
3864 | ||
c5aa993b JM |
3865 | /* bp_finish is a special case. The only way we ought to be able |
3866 | to see one of these when an exec() has happened, is if the user | |
3867 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3868 | carries them to the call-site of the current callee, by setting | |
3869 | a temporary bp there and resuming. But in this case, the finish | |
3870 | will carry them entirely through the vfork & exec. | |
3871 | ||
3872 | We don't want to allow a bp_finish to remain inserted now. But | |
3873 | we can't safely delete it, 'cause finish_command has a handle to | |
3874 | the bp on a bpstat, and will later want to delete it. There's a | |
3875 | chance (and I've seen it happen) that if we delete the bp_finish | |
3876 | here, that its storage will get reused by the time finish_command | |
3877 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3878 | We really must allow finish_command to delete a bp_finish. | |
3879 | ||
e5dd4106 | 3880 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3881 | it's safe to delete something others may have handles to?" |
3882 | problem, what we'll do here is just uninsert the bp_finish, and | |
3883 | let finish_command delete it. | |
3884 | ||
3885 | (We know the bp_finish is "doomed" in the sense that it's | |
3886 | momentary, and will be deleted as soon as finish_command sees | |
3887 | the inferior stopped. So it doesn't matter that the bp's | |
3888 | address is probably bogus in the new a.out, unlike e.g., the | |
3889 | solib breakpoints.) */ | |
c5aa993b | 3890 | |
c5aa993b JM |
3891 | if (b->type == bp_finish) |
3892 | { | |
3893 | continue; | |
3894 | } | |
3895 | ||
3896 | /* Without a symbolic address, we have little hope of the | |
3897 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3898 | a.out. */ |
9ef9e6a6 | 3899 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3900 | { |
3901 | delete_breakpoint (b); | |
3902 | continue; | |
3903 | } | |
c5aa993b | 3904 | } |
c906108c SS |
3905 | } |
3906 | ||
3907 | int | |
d80ee84f | 3908 | detach_breakpoints (ptid_t ptid) |
c906108c | 3909 | { |
35df4500 | 3910 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3911 | int val = 0; |
ce696e05 | 3912 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3913 | struct inferior *inf = current_inferior (); |
c5aa993b | 3914 | |
dfd4cc63 | 3915 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3916 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3917 | |
6c95b8df | 3918 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3919 | inferior_ptid = ptid; |
35df4500 | 3920 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3921 | { |
35df4500 | 3922 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3923 | continue; |
3924 | ||
bd9673a4 PW |
3925 | /* This function must physically remove breakpoints locations |
3926 | from the specified ptid, without modifying the breakpoint | |
3927 | package's state. Locations of type bp_loc_other are only | |
3928 | maintained at GDB side. So, there is no need to remove | |
3929 | these bp_loc_other locations. Moreover, removing these | |
3930 | would modify the breakpoint package's state. */ | |
3931 | if (bl->loc_type == bp_loc_other) | |
3932 | continue; | |
3933 | ||
35df4500 | 3934 | if (bl->inserted) |
b2b6a7da | 3935 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3936 | } |
d03285ec | 3937 | |
ce696e05 | 3938 | do_cleanups (old_chain); |
3a1bae8e | 3939 | return val; |
c906108c SS |
3940 | } |
3941 | ||
35df4500 | 3942 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3943 | Note that this is used to detach breakpoints from a child fork. |
3944 | When we get here, the child isn't in the inferior list, and neither | |
3945 | do we have objects to represent its address space --- we should | |
35df4500 | 3946 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3947 | |
c906108c | 3948 | static int |
b2b6a7da | 3949 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3950 | { |
3951 | int val; | |
c5aa993b | 3952 | |
35df4500 TJB |
3953 | /* BL is never in moribund_locations by our callers. */ |
3954 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3955 | |
74960c60 VP |
3956 | /* The type of none suggests that owner is actually deleted. |
3957 | This should not ever happen. */ | |
35df4500 | 3958 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3959 | |
35df4500 TJB |
3960 | if (bl->loc_type == bp_loc_software_breakpoint |
3961 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3962 | { |
c02f5703 MS |
3963 | /* "Normal" instruction breakpoint: either the standard |
3964 | trap-instruction bp (bp_breakpoint), or a | |
3965 | bp_hardware_breakpoint. */ | |
3966 | ||
3967 | /* First check to see if we have to handle an overlay. */ | |
3968 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3969 | || bl->section == NULL |
3970 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3971 | { |
3972 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3973 | |
3974 | /* If we're trying to uninsert a memory breakpoint that we | |
3975 | know is set in a dynamic object that is marked | |
3976 | shlib_disabled, then either the dynamic object was | |
3977 | removed with "remove-symbol-file" or with | |
3978 | "nosharedlibrary". In the former case, we don't know | |
3979 | whether another dynamic object might have loaded over the | |
3980 | breakpoint's address -- the user might well let us know | |
3981 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3982 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3983 | list of dynamically loaded objects). If we have the |
3984 | breakpoint's shadow memory, that is, this is a software | |
3985 | breakpoint managed by GDB, check whether the breakpoint | |
3986 | is still inserted in memory, to avoid overwriting wrong | |
3987 | code with stale saved shadow contents. Note that HW | |
3988 | breakpoints don't have shadow memory, as they're | |
3989 | implemented using a mechanism that is not dependent on | |
3990 | being able to modify the target's memory, and as such | |
3991 | they should always be removed. */ | |
3992 | if (bl->shlib_disabled | |
3993 | && bl->target_info.shadow_len != 0 | |
3994 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3995 | val = 0; | |
3996 | else | |
73971819 | 3997 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3998 | } |
c906108c SS |
3999 | else |
4000 | { | |
4a64f543 | 4001 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
4002 | Did we set a breakpoint at the LMA? */ |
4003 | if (!overlay_events_enabled) | |
4004 | { | |
4005 | /* Yes -- overlay event support is not active, so we | |
4006 | should have set a breakpoint at the LMA. Remove it. | |
4007 | */ | |
c02f5703 MS |
4008 | /* Ignore any failures: if the LMA is in ROM, we will |
4009 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4010 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4011 | target_remove_hw_breakpoint (bl->gdbarch, | |
4012 | &bl->overlay_target_info); | |
c02f5703 | 4013 | else |
35df4500 | 4014 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
4015 | &bl->overlay_target_info, |
4016 | reason); | |
c02f5703 MS |
4017 | } |
4018 | /* Did we set a breakpoint at the VMA? | |
4019 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4020 | if (bl->inserted) |
c906108c | 4021 | { |
c02f5703 MS |
4022 | /* Yes -- remove it. Previously we did not bother to |
4023 | remove the breakpoint if the section had been | |
4024 | unmapped, but let's not rely on that being safe. We | |
4025 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4026 | |
4027 | /* However, we should remove *software* breakpoints only | |
4028 | if the section is still mapped, or else we overwrite | |
4029 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4030 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4031 | || section_is_mapped (bl->section)) | |
73971819 | 4032 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
4033 | else |
4034 | val = 0; | |
c906108c | 4035 | } |
c02f5703 MS |
4036 | else |
4037 | { | |
4038 | /* No -- not inserted, so no need to remove. No error. */ | |
4039 | val = 0; | |
4040 | } | |
c906108c | 4041 | } |
879d1e6b | 4042 | |
08351840 PA |
4043 | /* In some cases, we might not be able to remove a breakpoint in |
4044 | a shared library that has already been removed, but we have | |
4045 | not yet processed the shlib unload event. Similarly for an | |
4046 | unloaded add-symbol-file object - the user might not yet have | |
4047 | had the chance to remove-symbol-file it. shlib_disabled will | |
4048 | be set if the library/object has already been removed, but | |
4049 | the breakpoint hasn't been uninserted yet, e.g., after | |
4050 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4051 | always-inserted mode. */ | |
076855f9 | 4052 | if (val |
08351840 PA |
4053 | && (bl->loc_type == bp_loc_software_breakpoint |
4054 | && (bl->shlib_disabled | |
4055 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4056 | || shared_objfile_contains_address_p (bl->pspace, |
4057 | bl->address)))) | |
879d1e6b UW |
4058 | val = 0; |
4059 | ||
c906108c SS |
4060 | if (val) |
4061 | return val; | |
b2b6a7da | 4062 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4063 | } |
35df4500 | 4064 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4065 | { |
77b06cd7 TJB |
4066 | gdb_assert (bl->owner->ops != NULL |
4067 | && bl->owner->ops->remove_location != NULL); | |
4068 | ||
b2b6a7da | 4069 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4070 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4071 | |
c906108c | 4072 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4073 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4074 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4075 | bl->owner->number); |
c906108c | 4076 | } |
35df4500 TJB |
4077 | else if (bl->owner->type == bp_catchpoint |
4078 | && breakpoint_enabled (bl->owner) | |
4079 | && !bl->duplicate) | |
ce78b96d | 4080 | { |
77b06cd7 TJB |
4081 | gdb_assert (bl->owner->ops != NULL |
4082 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4083 | |
73971819 | 4084 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4085 | if (val) |
4086 | return val; | |
77b06cd7 | 4087 | |
b2b6a7da | 4088 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4089 | } |
c906108c SS |
4090 | |
4091 | return 0; | |
4092 | } | |
4093 | ||
6c95b8df | 4094 | static int |
834c0d03 | 4095 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 4096 | { |
35df4500 TJB |
4097 | /* BL is never in moribund_locations by our callers. */ |
4098 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4099 | |
6c95b8df PA |
4100 | /* The type of none suggests that owner is actually deleted. |
4101 | This should not ever happen. */ | |
35df4500 | 4102 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 4103 | |
5ed8105e | 4104 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 4105 | |
35df4500 | 4106 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4107 | |
5ed8105e | 4108 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4109 | } |
4110 | ||
c906108c SS |
4111 | /* Clear the "inserted" flag in all breakpoints. */ |
4112 | ||
25b22b0a | 4113 | void |
fba45db2 | 4114 | mark_breakpoints_out (void) |
c906108c | 4115 | { |
35df4500 | 4116 | struct bp_location *bl, **blp_tmp; |
c906108c | 4117 | |
35df4500 | 4118 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4119 | if (bl->pspace == current_program_space) |
35df4500 | 4120 | bl->inserted = 0; |
c906108c SS |
4121 | } |
4122 | ||
53a5351d JM |
4123 | /* Clear the "inserted" flag in all breakpoints and delete any |
4124 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4125 | |
4126 | Plus other such housekeeping that has to be done for breakpoints | |
4127 | between runs. | |
4128 | ||
53a5351d JM |
4129 | Note: this function gets called at the end of a run (by |
4130 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4131 | init_wait_for_inferior). */ |
c906108c SS |
4132 | |
4133 | ||
4134 | ||
4135 | void | |
fba45db2 | 4136 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4137 | { |
35df4500 | 4138 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4139 | struct bp_location *bl; |
1c5cfe86 | 4140 | int ix; |
6c95b8df | 4141 | struct program_space *pspace = current_program_space; |
c906108c | 4142 | |
50c71eaf PA |
4143 | /* If breakpoint locations are shared across processes, then there's |
4144 | nothing to do. */ | |
f5656ead | 4145 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4146 | return; |
4147 | ||
1a853c52 | 4148 | mark_breakpoints_out (); |
075f6582 | 4149 | |
35df4500 | 4150 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4151 | { |
6c95b8df PA |
4152 | if (b->loc && b->loc->pspace != pspace) |
4153 | continue; | |
4154 | ||
c5aa993b JM |
4155 | switch (b->type) |
4156 | { | |
4157 | case bp_call_dummy: | |
e2e4d78b | 4158 | case bp_longjmp_call_dummy: |
c906108c | 4159 | |
c5aa993b | 4160 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4161 | cause problems when the inferior is rerun, so we better get |
4162 | rid of it. */ | |
4163 | ||
4164 | case bp_watchpoint_scope: | |
4165 | ||
4166 | /* Also get rid of scope breakpoints. */ | |
4167 | ||
4168 | case bp_shlib_event: | |
4169 | ||
4170 | /* Also remove solib event breakpoints. Their addresses may | |
4171 | have changed since the last time we ran the program. | |
4172 | Actually we may now be debugging against different target; | |
4173 | and so the solib backend that installed this breakpoint may | |
4174 | not be used in by the target. E.g., | |
4175 | ||
4176 | (gdb) file prog-linux | |
4177 | (gdb) run # native linux target | |
4178 | ... | |
4179 | (gdb) kill | |
4180 | (gdb) file prog-win.exe | |
4181 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4182 | */ | |
c906108c | 4183 | |
f59f708a PA |
4184 | case bp_step_resume: |
4185 | ||
4186 | /* Also remove step-resume breakpoints. */ | |
4187 | ||
7c16b83e PA |
4188 | case bp_single_step: |
4189 | ||
4190 | /* Also remove single-step breakpoints. */ | |
4191 | ||
c5aa993b JM |
4192 | delete_breakpoint (b); |
4193 | break; | |
c906108c | 4194 | |
c5aa993b JM |
4195 | case bp_watchpoint: |
4196 | case bp_hardware_watchpoint: | |
4197 | case bp_read_watchpoint: | |
4198 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4199 | { |
4200 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4201 | |
3a5c3e22 PA |
4202 | /* Likewise for watchpoints on local expressions. */ |
4203 | if (w->exp_valid_block != NULL) | |
4204 | delete_breakpoint (b); | |
63000888 | 4205 | else |
3a5c3e22 | 4206 | { |
63000888 PA |
4207 | /* Get rid of existing locations, which are no longer |
4208 | valid. New ones will be created in | |
4209 | update_watchpoint, when the inferior is restarted. | |
4210 | The next update_global_location_list call will | |
4211 | garbage collect them. */ | |
4212 | b->loc = NULL; | |
4213 | ||
4214 | if (context == inf_starting) | |
4215 | { | |
4216 | /* Reset val field to force reread of starting value in | |
4217 | insert_breakpoints. */ | |
4218 | if (w->val) | |
4219 | value_free (w->val); | |
4220 | w->val = NULL; | |
4221 | w->val_valid = 0; | |
4222 | } | |
4223 | } | |
3a5c3e22 | 4224 | } |
c5aa993b JM |
4225 | break; |
4226 | default: | |
c5aa993b JM |
4227 | break; |
4228 | } | |
4229 | } | |
1c5cfe86 PA |
4230 | |
4231 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4232 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4233 | decref_bp_location (&bl); | |
1c5cfe86 | 4234 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4235 | } |
4236 | ||
6c95b8df PA |
4237 | /* These functions concern about actual breakpoints inserted in the |
4238 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4239 | we need to hop over the bkpt --- so we check for address space | |
4240 | match, not program space. */ | |
4241 | ||
c2c6d25f JM |
4242 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4243 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4244 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4245 | permanent breakpoint. | |
4246 | - When continuing from a location with an ordinary breakpoint, we | |
4247 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4248 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4249 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4250 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4251 | |
c2c6d25f | 4252 | enum breakpoint_here |
6c95b8df | 4253 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4254 | { |
35df4500 | 4255 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4256 | int any_breakpoint_here = 0; |
c906108c | 4257 | |
35df4500 | 4258 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4259 | { |
35df4500 TJB |
4260 | if (bl->loc_type != bp_loc_software_breakpoint |
4261 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4262 | continue; |
4263 | ||
f1310107 | 4264 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4265 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4266 | || bl->permanent) |
f1310107 | 4267 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4268 | { |
4269 | if (overlay_debugging | |
35df4500 TJB |
4270 | && section_is_overlay (bl->section) |
4271 | && !section_is_mapped (bl->section)) | |
075f6582 | 4272 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4273 | else if (bl->permanent) |
075f6582 DJ |
4274 | return permanent_breakpoint_here; |
4275 | else | |
4276 | any_breakpoint_here = 1; | |
4277 | } | |
4278 | } | |
c906108c | 4279 | |
f486487f | 4280 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4281 | } |
4282 | ||
d35ae833 PA |
4283 | /* See breakpoint.h. */ |
4284 | ||
4285 | int | |
4286 | breakpoint_in_range_p (struct address_space *aspace, | |
4287 | CORE_ADDR addr, ULONGEST len) | |
4288 | { | |
4289 | struct bp_location *bl, **blp_tmp; | |
4290 | ||
4291 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4292 | { | |
4293 | if (bl->loc_type != bp_loc_software_breakpoint | |
4294 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4295 | continue; | |
4296 | ||
4297 | if ((breakpoint_enabled (bl->owner) | |
4298 | || bl->permanent) | |
4299 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4300 | addr, len)) | |
4301 | { | |
4302 | if (overlay_debugging | |
4303 | && section_is_overlay (bl->section) | |
4304 | && !section_is_mapped (bl->section)) | |
4305 | { | |
4306 | /* Unmapped overlay -- can't be a match. */ | |
4307 | continue; | |
4308 | } | |
4309 | ||
4310 | return 1; | |
4311 | } | |
4312 | } | |
4313 | ||
4314 | return 0; | |
4315 | } | |
4316 | ||
1c5cfe86 PA |
4317 | /* Return true if there's a moribund breakpoint at PC. */ |
4318 | ||
4319 | int | |
6c95b8df | 4320 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4321 | { |
4322 | struct bp_location *loc; | |
4323 | int ix; | |
4324 | ||
4325 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4326 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4327 | return 1; |
4328 | ||
4329 | return 0; | |
4330 | } | |
c2c6d25f | 4331 | |
f7ce857f PA |
4332 | /* Returns non-zero iff BL is inserted at PC, in address space |
4333 | ASPACE. */ | |
4334 | ||
4335 | static int | |
4336 | bp_location_inserted_here_p (struct bp_location *bl, | |
4337 | struct address_space *aspace, CORE_ADDR pc) | |
4338 | { | |
4339 | if (bl->inserted | |
4340 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4341 | aspace, pc)) | |
4342 | { | |
4343 | if (overlay_debugging | |
4344 | && section_is_overlay (bl->section) | |
4345 | && !section_is_mapped (bl->section)) | |
4346 | return 0; /* unmapped overlay -- can't be a match */ | |
4347 | else | |
4348 | return 1; | |
4349 | } | |
4350 | return 0; | |
4351 | } | |
4352 | ||
a1fd2fa5 | 4353 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4354 | |
4355 | int | |
a1fd2fa5 | 4356 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4357 | { |
f7ce857f | 4358 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4359 | |
f7ce857f | 4360 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4361 | { |
f7ce857f PA |
4362 | struct bp_location *bl = *blp; |
4363 | ||
35df4500 TJB |
4364 | if (bl->loc_type != bp_loc_software_breakpoint |
4365 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4366 | continue; |
4367 | ||
f7ce857f PA |
4368 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4369 | return 1; | |
c5aa993b | 4370 | } |
c36b740a VP |
4371 | return 0; |
4372 | } | |
4373 | ||
a1fd2fa5 PA |
4374 | /* This function returns non-zero iff there is a software breakpoint |
4375 | inserted at PC. */ | |
c36b740a VP |
4376 | |
4377 | int | |
a1fd2fa5 PA |
4378 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4379 | CORE_ADDR pc) | |
4fa8626c | 4380 | { |
f7ce857f | 4381 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4382 | |
f7ce857f | 4383 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4384 | { |
f7ce857f PA |
4385 | struct bp_location *bl = *blp; |
4386 | ||
35df4500 | 4387 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4388 | continue; |
4389 | ||
f7ce857f PA |
4390 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4391 | return 1; | |
4fa8626c DJ |
4392 | } |
4393 | ||
4394 | return 0; | |
9c02b525 PA |
4395 | } |
4396 | ||
4397 | /* See breakpoint.h. */ | |
4398 | ||
4399 | int | |
4400 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4401 | CORE_ADDR pc) | |
4402 | { | |
4403 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4404 | |
4405 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4406 | { | |
4407 | struct bp_location *bl = *blp; | |
4408 | ||
4409 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4410 | continue; | |
4411 | ||
4412 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4413 | return 1; | |
4414 | } | |
4415 | ||
4416 | return 0; | |
4fa8626c DJ |
4417 | } |
4418 | ||
9093389c PA |
4419 | int |
4420 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4421 | CORE_ADDR addr, ULONGEST len) | |
4422 | { | |
4423 | struct breakpoint *bpt; | |
4424 | ||
4425 | ALL_BREAKPOINTS (bpt) | |
4426 | { | |
4427 | struct bp_location *loc; | |
4428 | ||
4429 | if (bpt->type != bp_hardware_watchpoint | |
4430 | && bpt->type != bp_access_watchpoint) | |
4431 | continue; | |
4432 | ||
4433 | if (!breakpoint_enabled (bpt)) | |
4434 | continue; | |
4435 | ||
4436 | for (loc = bpt->loc; loc; loc = loc->next) | |
4437 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4438 | { | |
4439 | CORE_ADDR l, h; | |
4440 | ||
4441 | /* Check for intersection. */ | |
768adc05 PA |
4442 | l = std::max<CORE_ADDR> (loc->address, addr); |
4443 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4444 | if (l < h) |
4445 | return 1; | |
4446 | } | |
4447 | } | |
4448 | return 0; | |
4449 | } | |
c906108c | 4450 | \f |
c5aa993b | 4451 | |
c906108c SS |
4452 | /* bpstat stuff. External routines' interfaces are documented |
4453 | in breakpoint.h. */ | |
4454 | ||
4455 | int | |
c326b90e | 4456 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4457 | { |
533be4dd | 4458 | return (ep->type == bp_catchpoint); |
c906108c SS |
4459 | } |
4460 | ||
f431efe5 PA |
4461 | /* Frees any storage that is part of a bpstat. Does not walk the |
4462 | 'next' chain. */ | |
4463 | ||
4464 | static void | |
198757a8 VP |
4465 | bpstat_free (bpstat bs) |
4466 | { | |
4467 | if (bs->old_val != NULL) | |
4468 | value_free (bs->old_val); | |
9add0f1b | 4469 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4470 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4471 | xfree (bs); |
4472 | } | |
4473 | ||
c906108c SS |
4474 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4475 | Also free any storage that is part of a bpstat. */ | |
4476 | ||
4477 | void | |
fba45db2 | 4478 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4479 | { |
4480 | bpstat p; | |
4481 | bpstat q; | |
4482 | ||
4483 | if (bsp == 0) | |
4484 | return; | |
4485 | p = *bsp; | |
4486 | while (p != NULL) | |
4487 | { | |
4488 | q = p->next; | |
198757a8 | 4489 | bpstat_free (p); |
c906108c SS |
4490 | p = q; |
4491 | } | |
4492 | *bsp = NULL; | |
4493 | } | |
4494 | ||
4495 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4496 | is part of the bpstat is copied as well. */ | |
4497 | ||
4498 | bpstat | |
fba45db2 | 4499 | bpstat_copy (bpstat bs) |
c906108c SS |
4500 | { |
4501 | bpstat p = NULL; | |
4502 | bpstat tmp; | |
4503 | bpstat retval = NULL; | |
4504 | ||
4505 | if (bs == NULL) | |
4506 | return bs; | |
4507 | ||
4508 | for (; bs != NULL; bs = bs->next) | |
4509 | { | |
4510 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4511 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4512 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4513 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4514 | if (bs->old_val != NULL) |
3c3185ac JK |
4515 | { |
4516 | tmp->old_val = value_copy (bs->old_val); | |
4517 | release_value (tmp->old_val); | |
4518 | } | |
31cc81e9 | 4519 | |
c906108c SS |
4520 | if (p == NULL) |
4521 | /* This is the first thing in the chain. */ | |
4522 | retval = tmp; | |
4523 | else | |
4524 | p->next = tmp; | |
4525 | p = tmp; | |
4526 | } | |
4527 | p->next = NULL; | |
4528 | return retval; | |
4529 | } | |
4530 | ||
4a64f543 | 4531 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4532 | |
4533 | bpstat | |
fba45db2 | 4534 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4535 | { |
c5aa993b JM |
4536 | if (bsp == NULL) |
4537 | return NULL; | |
c906108c | 4538 | |
c5aa993b JM |
4539 | for (; bsp != NULL; bsp = bsp->next) |
4540 | { | |
f431efe5 | 4541 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4542 | return bsp; |
4543 | } | |
c906108c SS |
4544 | return NULL; |
4545 | } | |
4546 | ||
ab04a2af TT |
4547 | /* See breakpoint.h. */ |
4548 | ||
47591c29 | 4549 | int |
427cd150 | 4550 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4551 | { |
ab04a2af TT |
4552 | for (; bsp != NULL; bsp = bsp->next) |
4553 | { | |
427cd150 TT |
4554 | if (bsp->breakpoint_at == NULL) |
4555 | { | |
4556 | /* A moribund location can never explain a signal other than | |
4557 | GDB_SIGNAL_TRAP. */ | |
4558 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4559 | return 1; |
427cd150 TT |
4560 | } |
4561 | else | |
47591c29 PA |
4562 | { |
4563 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4564 | sig)) | |
4565 | return 1; | |
4566 | } | |
ab04a2af TT |
4567 | } |
4568 | ||
47591c29 | 4569 | return 0; |
ab04a2af TT |
4570 | } |
4571 | ||
4a64f543 MS |
4572 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4573 | stopped at. *BSP upon return is a bpstat which points to the | |
4574 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4575 | good for anything but further calls to bpstat_num). | |
4576 | ||
8671a17b PA |
4577 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4578 | Return -1 if stopped at a breakpoint that has been deleted since | |
4579 | we set it. | |
4580 | Return 1 otherwise. */ | |
c906108c SS |
4581 | |
4582 | int | |
8671a17b | 4583 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4584 | { |
4585 | struct breakpoint *b; | |
4586 | ||
4587 | if ((*bsp) == NULL) | |
4588 | return 0; /* No more breakpoint values */ | |
8671a17b | 4589 | |
4a64f543 MS |
4590 | /* We assume we'll never have several bpstats that correspond to a |
4591 | single breakpoint -- otherwise, this function might return the | |
4592 | same number more than once and this will look ugly. */ | |
f431efe5 | 4593 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4594 | *bsp = (*bsp)->next; |
4595 | if (b == NULL) | |
4596 | return -1; /* breakpoint that's been deleted since */ | |
4597 | ||
4598 | *num = b->number; /* We have its number */ | |
4599 | return 1; | |
c906108c SS |
4600 | } |
4601 | ||
e93ca019 | 4602 | /* See breakpoint.h. */ |
c906108c SS |
4603 | |
4604 | void | |
e93ca019 | 4605 | bpstat_clear_actions (void) |
c906108c | 4606 | { |
e93ca019 JK |
4607 | struct thread_info *tp; |
4608 | bpstat bs; | |
4609 | ||
4610 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4611 | return; | |
4612 | ||
4613 | tp = find_thread_ptid (inferior_ptid); | |
4614 | if (tp == NULL) | |
4615 | return; | |
4616 | ||
4617 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4618 | { |
9add0f1b | 4619 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4620 | |
c906108c SS |
4621 | if (bs->old_val != NULL) |
4622 | { | |
4623 | value_free (bs->old_val); | |
4624 | bs->old_val = NULL; | |
4625 | } | |
4626 | } | |
4627 | } | |
4628 | ||
f3b1572e PA |
4629 | /* Called when a command is about to proceed the inferior. */ |
4630 | ||
4631 | static void | |
4632 | breakpoint_about_to_proceed (void) | |
4633 | { | |
4634 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4635 | { | |
4636 | struct thread_info *tp = inferior_thread (); | |
4637 | ||
4638 | /* Allow inferior function calls in breakpoint commands to not | |
4639 | interrupt the command list. When the call finishes | |
4640 | successfully, the inferior will be standing at the same | |
4641 | breakpoint as if nothing happened. */ | |
16c381f0 | 4642 | if (tp->control.in_infcall) |
f3b1572e PA |
4643 | return; |
4644 | } | |
4645 | ||
4646 | breakpoint_proceeded = 1; | |
4647 | } | |
4648 | ||
4a64f543 MS |
4649 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4650 | command. */ | |
c906108c | 4651 | static void |
4efb68b1 | 4652 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4653 | { |
4654 | executing_breakpoint_commands = 0; | |
4655 | } | |
4656 | ||
abf85f46 JK |
4657 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4658 | or its equivalent. */ | |
4659 | ||
4660 | static int | |
4661 | command_line_is_silent (struct command_line *cmd) | |
4662 | { | |
4f45d445 | 4663 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4664 | } |
4665 | ||
4a64f543 MS |
4666 | /* Execute all the commands associated with all the breakpoints at |
4667 | this location. Any of these commands could cause the process to | |
4668 | proceed beyond this point, etc. We look out for such changes by | |
4669 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4670 | |
347bddb7 PA |
4671 | Returns true if a breakpoint command resumed the inferior. In that |
4672 | case, it is the caller's responsibility to recall it again with the | |
4673 | bpstat of the current thread. */ | |
4674 | ||
4675 | static int | |
4676 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4677 | { |
4678 | bpstat bs; | |
4679 | struct cleanup *old_chain; | |
347bddb7 | 4680 | int again = 0; |
c906108c SS |
4681 | |
4682 | /* Avoid endless recursion if a `source' command is contained | |
4683 | in bs->commands. */ | |
4684 | if (executing_breakpoint_commands) | |
347bddb7 | 4685 | return 0; |
c906108c SS |
4686 | |
4687 | executing_breakpoint_commands = 1; | |
4688 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4689 | ||
1ac32117 | 4690 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4691 | |
4a64f543 | 4692 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4693 | bs = *bsp; |
4694 | ||
4695 | breakpoint_proceeded = 0; | |
4696 | for (; bs != NULL; bs = bs->next) | |
4697 | { | |
9add0f1b | 4698 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4699 | struct command_line *cmd; |
4700 | struct cleanup *this_cmd_tree_chain; | |
4701 | ||
4702 | /* Take ownership of the BSP's command tree, if it has one. | |
4703 | ||
4704 | The command tree could legitimately contain commands like | |
4705 | 'step' and 'next', which call clear_proceed_status, which | |
4706 | frees stop_bpstat's command tree. To make sure this doesn't | |
4707 | free the tree we're executing out from under us, we need to | |
4708 | take ownership of the tree ourselves. Since a given bpstat's | |
4709 | commands are only executed once, we don't need to copy it; we | |
4710 | can clear the pointer in the bpstat, and make sure we free | |
4711 | the tree when we're done. */ | |
9add0f1b TT |
4712 | ccmd = bs->commands; |
4713 | bs->commands = NULL; | |
abf85f46 JK |
4714 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4715 | cmd = ccmd ? ccmd->commands : NULL; | |
4716 | if (command_line_is_silent (cmd)) | |
4717 | { | |
4718 | /* The action has been already done by bpstat_stop_status. */ | |
4719 | cmd = cmd->next; | |
4720 | } | |
6c50ab1c | 4721 | |
c906108c SS |
4722 | while (cmd != NULL) |
4723 | { | |
4724 | execute_control_command (cmd); | |
4725 | ||
4726 | if (breakpoint_proceeded) | |
4727 | break; | |
4728 | else | |
4729 | cmd = cmd->next; | |
4730 | } | |
6c50ab1c JB |
4731 | |
4732 | /* We can free this command tree now. */ | |
4733 | do_cleanups (this_cmd_tree_chain); | |
4734 | ||
c906108c | 4735 | if (breakpoint_proceeded) |
32c1e744 | 4736 | { |
cb814510 | 4737 | if (current_ui->async) |
347bddb7 PA |
4738 | /* If we are in async mode, then the target might be still |
4739 | running, not stopped at any breakpoint, so nothing for | |
4740 | us to do here -- just return to the event loop. */ | |
4741 | ; | |
32c1e744 VP |
4742 | else |
4743 | /* In sync mode, when execute_control_command returns | |
4744 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4745 | Breakpoint commands for that stop were not run, since |
4746 | execute_command does not run breakpoint commands -- | |
4747 | only command_line_handler does, but that one is not | |
4748 | involved in execution of breakpoint commands. So, we | |
4749 | can now execute breakpoint commands. It should be | |
4750 | noted that making execute_command do bpstat actions is | |
4751 | not an option -- in this case we'll have recursive | |
4752 | invocation of bpstat for each breakpoint with a | |
4753 | command, and can easily blow up GDB stack. Instead, we | |
4754 | return true, which will trigger the caller to recall us | |
4755 | with the new stop_bpstat. */ | |
4756 | again = 1; | |
4757 | break; | |
32c1e744 | 4758 | } |
c906108c | 4759 | } |
c2b8ed2c | 4760 | do_cleanups (old_chain); |
347bddb7 PA |
4761 | return again; |
4762 | } | |
4763 | ||
4764 | void | |
4765 | bpstat_do_actions (void) | |
4766 | { | |
353d1d73 JK |
4767 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4768 | ||
347bddb7 PA |
4769 | /* Do any commands attached to breakpoint we are stopped at. */ |
4770 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4771 | && target_has_execution | |
4772 | && !is_exited (inferior_ptid) | |
4773 | && !is_executing (inferior_ptid)) | |
4774 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4775 | and only return when it is stopped at the next breakpoint, we | |
4776 | keep doing breakpoint actions until it returns false to | |
4777 | indicate the inferior was not resumed. */ | |
16c381f0 | 4778 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4779 | break; |
353d1d73 JK |
4780 | |
4781 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4782 | } |
4783 | ||
fa4727a6 DJ |
4784 | /* Print out the (old or new) value associated with a watchpoint. */ |
4785 | ||
4786 | static void | |
4787 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4788 | { | |
4789 | if (val == NULL) | |
4790 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4791 | else | |
79a45b7d TT |
4792 | { |
4793 | struct value_print_options opts; | |
4794 | get_user_print_options (&opts); | |
4795 | value_print (val, stream, &opts); | |
4796 | } | |
fa4727a6 DJ |
4797 | } |
4798 | ||
f303dbd6 PA |
4799 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4800 | debugging multiple threads. */ | |
4801 | ||
4802 | void | |
4803 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4804 | { | |
112e8700 | 4805 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4806 | return; |
4807 | ||
112e8700 | 4808 | uiout->text ("\n"); |
f303dbd6 PA |
4809 | |
4810 | if (show_thread_that_caused_stop ()) | |
4811 | { | |
4812 | const char *name; | |
4813 | struct thread_info *thr = inferior_thread (); | |
4814 | ||
112e8700 SM |
4815 | uiout->text ("Thread "); |
4816 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4817 | |
4818 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4819 | if (name != NULL) | |
4820 | { | |
112e8700 SM |
4821 | uiout->text (" \""); |
4822 | uiout->field_fmt ("name", "%s", name); | |
4823 | uiout->text ("\""); | |
f303dbd6 PA |
4824 | } |
4825 | ||
112e8700 | 4826 | uiout->text (" hit "); |
f303dbd6 PA |
4827 | } |
4828 | } | |
4829 | ||
e514a9d6 | 4830 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4831 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4832 | 'print_it' in the bpstat structure. Under some circumstances we |
4833 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4834 | normal_stop(). */ |
e514a9d6 JM |
4835 | |
4836 | static enum print_stop_action | |
4837 | print_bp_stop_message (bpstat bs) | |
4838 | { | |
4839 | switch (bs->print_it) | |
4840 | { | |
4841 | case print_it_noop: | |
4a64f543 | 4842 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4843 | return PRINT_UNKNOWN; |
4844 | break; | |
4845 | ||
4846 | case print_it_done: | |
4847 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4848 | relevant messages. */ |
e514a9d6 JM |
4849 | return PRINT_SRC_AND_LOC; |
4850 | break; | |
4851 | ||
4852 | case print_it_normal: | |
4f8d1dc6 | 4853 | { |
f431efe5 PA |
4854 | struct breakpoint *b = bs->breakpoint_at; |
4855 | ||
1a6a67de TJB |
4856 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4857 | which has since been deleted. */ | |
4858 | if (b == NULL) | |
4859 | return PRINT_UNKNOWN; | |
4860 | ||
348d480f PA |
4861 | /* Normal case. Call the breakpoint's print_it method. */ |
4862 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4863 | } |
348d480f | 4864 | break; |
3086aeae | 4865 | |
e514a9d6 | 4866 | default: |
8e65ff28 | 4867 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4868 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4869 | break; |
c906108c | 4870 | } |
c906108c SS |
4871 | } |
4872 | ||
edcc5120 TT |
4873 | /* A helper function that prints a shared library stopped event. */ |
4874 | ||
4875 | static void | |
4876 | print_solib_event (int is_catchpoint) | |
4877 | { | |
4878 | int any_deleted | |
4879 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4880 | int any_added | |
4881 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4882 | ||
4883 | if (!is_catchpoint) | |
4884 | { | |
4885 | if (any_added || any_deleted) | |
112e8700 | 4886 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4887 | else |
112e8700 SM |
4888 | current_uiout->text (_("Stopped due to shared library event (no " |
4889 | "libraries added or removed)\n")); | |
edcc5120 TT |
4890 | } |
4891 | ||
112e8700 SM |
4892 | if (current_uiout->is_mi_like_p ()) |
4893 | current_uiout->field_string ("reason", | |
4894 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4895 | |
4896 | if (any_deleted) | |
4897 | { | |
edcc5120 TT |
4898 | char *name; |
4899 | int ix; | |
4900 | ||
112e8700 | 4901 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4902 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
edcc5120 TT |
4903 | for (ix = 0; |
4904 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4905 | ix, name); | |
4906 | ++ix) | |
4907 | { | |
4908 | if (ix > 0) | |
112e8700 SM |
4909 | current_uiout->text (" "); |
4910 | current_uiout->field_string ("library", name); | |
4911 | current_uiout->text ("\n"); | |
edcc5120 | 4912 | } |
edcc5120 TT |
4913 | } |
4914 | ||
4915 | if (any_added) | |
4916 | { | |
4917 | struct so_list *iter; | |
4918 | int ix; | |
edcc5120 | 4919 | |
112e8700 | 4920 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4921 | ui_out_emit_list list_emitter (current_uiout, "added"); |
edcc5120 TT |
4922 | for (ix = 0; |
4923 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4924 | ix, iter); | |
4925 | ++ix) | |
4926 | { | |
4927 | if (ix > 0) | |
112e8700 SM |
4928 | current_uiout->text (" "); |
4929 | current_uiout->field_string ("library", iter->so_name); | |
4930 | current_uiout->text ("\n"); | |
edcc5120 | 4931 | } |
edcc5120 TT |
4932 | } |
4933 | } | |
4934 | ||
e514a9d6 JM |
4935 | /* Print a message indicating what happened. This is called from |
4936 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4937 | list - a list of the eventpoints that caused this stop. KIND is |
4938 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4939 | routine calls the generic print routine for printing a message |
4940 | about reasons for stopping. This will print (for example) the | |
4941 | "Breakpoint n," part of the output. The return value of this | |
4942 | routine is one of: | |
c906108c | 4943 | |
4a64f543 | 4944 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4945 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4946 | code to print the location. An example is |
c5aa993b JM |
4947 | "Breakpoint 1, " which should be followed by |
4948 | the location. | |
917317f4 | 4949 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4950 | to also print the location part of the message. |
4951 | An example is the catch/throw messages, which | |
4a64f543 | 4952 | don't require a location appended to the end. |
917317f4 | 4953 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4954 | further info to be printed. */ |
c906108c | 4955 | |
917317f4 | 4956 | enum print_stop_action |
36dfb11c | 4957 | bpstat_print (bpstat bs, int kind) |
c906108c | 4958 | { |
f486487f | 4959 | enum print_stop_action val; |
c5aa993b | 4960 | |
c906108c | 4961 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4962 | (Currently all watchpoints go on the bpstat whether hit or not. |
4963 | That probably could (should) be changed, provided care is taken | |
c906108c | 4964 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4965 | for (; bs; bs = bs->next) |
4966 | { | |
4967 | val = print_bp_stop_message (bs); | |
4968 | if (val == PRINT_SRC_ONLY | |
4969 | || val == PRINT_SRC_AND_LOC | |
4970 | || val == PRINT_NOTHING) | |
4971 | return val; | |
4972 | } | |
c906108c | 4973 | |
36dfb11c TT |
4974 | /* If we had hit a shared library event breakpoint, |
4975 | print_bp_stop_message would print out this message. If we hit an | |
4976 | OS-level shared library event, do the same thing. */ | |
4977 | if (kind == TARGET_WAITKIND_LOADED) | |
4978 | { | |
edcc5120 | 4979 | print_solib_event (0); |
36dfb11c TT |
4980 | return PRINT_NOTHING; |
4981 | } | |
4982 | ||
e514a9d6 | 4983 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4984 | with and nothing was printed. */ |
917317f4 | 4985 | return PRINT_UNKNOWN; |
c906108c SS |
4986 | } |
4987 | ||
c42bd95a DE |
4988 | /* Evaluate the expression EXP and return 1 if value is zero. |
4989 | This returns the inverse of the condition because it is called | |
4990 | from catch_errors which returns 0 if an exception happened, and if an | |
4991 | exception happens we want execution to stop. | |
4a64f543 | 4992 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4993 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4994 | |
4995 | static int | |
4efb68b1 | 4996 | breakpoint_cond_eval (void *exp) |
c906108c | 4997 | { |
278cd55f | 4998 | struct value *mark = value_mark (); |
c5aa993b | 4999 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 5000 | |
c906108c SS |
5001 | value_free_to_mark (mark); |
5002 | return i; | |
5003 | } | |
5004 | ||
5760d0ab | 5005 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5006 | |
5007 | static bpstat | |
5760d0ab | 5008 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5009 | { |
5010 | bpstat bs; | |
5011 | ||
5012 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5013 | bs->next = NULL; |
5014 | **bs_link_pointer = bs; | |
5015 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5016 | bs->breakpoint_at = bl->owner; |
5017 | bs->bp_location_at = bl; | |
5018 | incref_bp_location (bl); | |
c906108c SS |
5019 | /* If the condition is false, etc., don't do the commands. */ |
5020 | bs->commands = NULL; | |
5021 | bs->old_val = NULL; | |
5022 | bs->print_it = print_it_normal; | |
5023 | return bs; | |
5024 | } | |
5025 | \f | |
d983da9c DJ |
5026 | /* The target has stopped with waitstatus WS. Check if any hardware |
5027 | watchpoints have triggered, according to the target. */ | |
5028 | ||
5029 | int | |
5030 | watchpoints_triggered (struct target_waitstatus *ws) | |
5031 | { | |
d92524f1 | 5032 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5033 | CORE_ADDR addr; |
5034 | struct breakpoint *b; | |
5035 | ||
5036 | if (!stopped_by_watchpoint) | |
5037 | { | |
5038 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5039 | as not triggered. */ | |
5040 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5041 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5042 | { |
5043 | struct watchpoint *w = (struct watchpoint *) b; | |
5044 | ||
5045 | w->watchpoint_triggered = watch_triggered_no; | |
5046 | } | |
d983da9c DJ |
5047 | |
5048 | return 0; | |
5049 | } | |
5050 | ||
5051 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5052 | { | |
5053 | /* We were stopped by a watchpoint, but we don't know where. | |
5054 | Mark all watchpoints as unknown. */ | |
5055 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5056 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5057 | { |
5058 | struct watchpoint *w = (struct watchpoint *) b; | |
5059 | ||
5060 | w->watchpoint_triggered = watch_triggered_unknown; | |
5061 | } | |
d983da9c | 5062 | |
3c4797ba | 5063 | return 1; |
d983da9c DJ |
5064 | } |
5065 | ||
5066 | /* The target could report the data address. Mark watchpoints | |
5067 | affected by this data address as triggered, and all others as not | |
5068 | triggered. */ | |
5069 | ||
5070 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5071 | if (is_hardware_watchpoint (b)) |
d983da9c | 5072 | { |
3a5c3e22 | 5073 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5074 | struct bp_location *loc; |
d983da9c | 5075 | |
3a5c3e22 | 5076 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5077 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5078 | { |
3a5c3e22 | 5079 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5080 | { |
3a5c3e22 PA |
5081 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5082 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5083 | |
5084 | if (newaddr == start) | |
5085 | { | |
3a5c3e22 | 5086 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5087 | break; |
5088 | } | |
5089 | } | |
5090 | /* Exact match not required. Within range is sufficient. */ | |
5091 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5092 | addr, loc->address, | |
5093 | loc->length)) | |
5094 | { | |
3a5c3e22 | 5095 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5096 | break; |
5097 | } | |
5098 | } | |
d983da9c DJ |
5099 | } |
5100 | ||
5101 | return 1; | |
5102 | } | |
5103 | ||
c906108c SS |
5104 | /* Possible return values for watchpoint_check (this can't be an enum |
5105 | because of check_errors). */ | |
5106 | /* The watchpoint has been deleted. */ | |
5107 | #define WP_DELETED 1 | |
5108 | /* The value has changed. */ | |
5109 | #define WP_VALUE_CHANGED 2 | |
5110 | /* The value has not changed. */ | |
5111 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5112 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5113 | #define WP_IGNORE 4 | |
c906108c SS |
5114 | |
5115 | #define BP_TEMPFLAG 1 | |
5116 | #define BP_HARDWAREFLAG 2 | |
5117 | ||
4a64f543 MS |
5118 | /* Evaluate watchpoint condition expression and check if its value |
5119 | changed. | |
553e4c11 JB |
5120 | |
5121 | P should be a pointer to struct bpstat, but is defined as a void * | |
5122 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5123 | |
5124 | static int | |
4efb68b1 | 5125 | watchpoint_check (void *p) |
c906108c SS |
5126 | { |
5127 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5128 | struct watchpoint *b; |
c906108c SS |
5129 | struct frame_info *fr; |
5130 | int within_current_scope; | |
5131 | ||
f431efe5 | 5132 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5133 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5134 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5135 | |
f6bc2008 PA |
5136 | /* If this is a local watchpoint, we only want to check if the |
5137 | watchpoint frame is in scope if the current thread is the thread | |
5138 | that was used to create the watchpoint. */ | |
5139 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5140 | return WP_IGNORE; |
f6bc2008 | 5141 | |
c906108c SS |
5142 | if (b->exp_valid_block == NULL) |
5143 | within_current_scope = 1; | |
5144 | else | |
5145 | { | |
edb3359d DJ |
5146 | struct frame_info *frame = get_current_frame (); |
5147 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5148 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5149 | ||
c9cf6e20 | 5150 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5151 | still in the function but the stack frame has already been |
5152 | invalidated. Since we can't rely on the values of local | |
5153 | variables after the stack has been destroyed, we are treating | |
5154 | the watchpoint in that state as `not changed' without further | |
5155 | checking. Don't mark watchpoints as changed if the current | |
5156 | frame is in an epilogue - even if they are in some other | |
5157 | frame, our view of the stack is likely to be wrong and | |
5158 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5159 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5160 | return WP_IGNORE; |
a0f49112 | 5161 | |
101dcfbe | 5162 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5163 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5164 | |
5165 | /* If we've gotten confused in the unwinder, we might have | |
5166 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5167 | if (within_current_scope) |
5168 | { | |
5169 | struct symbol *function; | |
5170 | ||
5171 | function = get_frame_function (fr); | |
5172 | if (function == NULL | |
5173 | || !contained_in (b->exp_valid_block, | |
5174 | SYMBOL_BLOCK_VALUE (function))) | |
5175 | within_current_scope = 0; | |
5176 | } | |
69fbadd5 | 5177 | |
edb3359d | 5178 | if (within_current_scope) |
c906108c SS |
5179 | /* If we end up stopping, the current frame will get selected |
5180 | in normal_stop. So this call to select_frame won't affect | |
5181 | the user. */ | |
0f7d239c | 5182 | select_frame (fr); |
c906108c | 5183 | } |
c5aa993b | 5184 | |
c906108c SS |
5185 | if (within_current_scope) |
5186 | { | |
4a64f543 MS |
5187 | /* We use value_{,free_to_}mark because it could be a *long* |
5188 | time before we return to the command level and call | |
5189 | free_all_values. We can't call free_all_values because we | |
5190 | might be in the middle of evaluating a function call. */ | |
c906108c | 5191 | |
0cf6dd15 | 5192 | int pc = 0; |
9c06b0b4 | 5193 | struct value *mark; |
fa4727a6 DJ |
5194 | struct value *new_val; |
5195 | ||
c1fc2657 | 5196 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
5197 | /* Since we don't know the exact trigger address (from |
5198 | stopped_data_address), just tell the user we've triggered | |
5199 | a mask watchpoint. */ | |
5200 | return WP_VALUE_CHANGED; | |
5201 | ||
5202 | mark = value_mark (); | |
4d01a485 | 5203 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5204 | |
bb9d5f81 PP |
5205 | if (b->val_bitsize != 0) |
5206 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5207 | ||
4a64f543 MS |
5208 | /* We use value_equal_contents instead of value_equal because |
5209 | the latter coerces an array to a pointer, thus comparing just | |
5210 | the address of the array instead of its contents. This is | |
5211 | not what we want. */ | |
fa4727a6 | 5212 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5213 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5214 | { |
fa4727a6 DJ |
5215 | if (new_val != NULL) |
5216 | { | |
5217 | release_value (new_val); | |
5218 | value_free_to_mark (mark); | |
5219 | } | |
c906108c SS |
5220 | bs->old_val = b->val; |
5221 | b->val = new_val; | |
fa4727a6 | 5222 | b->val_valid = 1; |
c906108c SS |
5223 | return WP_VALUE_CHANGED; |
5224 | } | |
5225 | else | |
5226 | { | |
60e1c644 | 5227 | /* Nothing changed. */ |
c906108c | 5228 | value_free_to_mark (mark); |
c906108c SS |
5229 | return WP_VALUE_NOT_CHANGED; |
5230 | } | |
5231 | } | |
5232 | else | |
5233 | { | |
5234 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5235 | if we temporarily ignored the watchpoint, then when |
5236 | we reenter the block in which it is valid it contains | |
5237 | garbage (in the case of a function, it may have two | |
5238 | garbage values, one before and one after the prologue). | |
5239 | So we can't even detect the first assignment to it and | |
5240 | watch after that (since the garbage may or may not equal | |
5241 | the first value assigned). */ | |
348d480f PA |
5242 | /* We print all the stop information in |
5243 | breakpoint_ops->print_it, but in this case, by the time we | |
5244 | call breakpoint_ops->print_it this bp will be deleted | |
5245 | already. So we have no choice but print the information | |
5246 | here. */ | |
468afe6c | 5247 | |
0e454242 | 5248 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5249 | { |
5250 | struct ui_out *uiout = current_uiout; | |
5251 | ||
112e8700 SM |
5252 | if (uiout->is_mi_like_p ()) |
5253 | uiout->field_string | |
5254 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5255 | uiout->text ("\nWatchpoint "); | |
c1fc2657 | 5256 | uiout->field_int ("wpnum", b->number); |
112e8700 | 5257 | uiout->text (" deleted because the program has left the block in\n" |
468afe6c PA |
5258 | "which its expression is valid.\n"); |
5259 | } | |
4ce44c66 | 5260 | |
cdac0397 | 5261 | /* Make sure the watchpoint's commands aren't executed. */ |
c1fc2657 | 5262 | decref_counted_command_line (&b->commands); |
d0fb5eae | 5263 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5264 | |
5265 | return WP_DELETED; | |
5266 | } | |
5267 | } | |
5268 | ||
18a18393 | 5269 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5270 | breakpoint location BL. This function does not check if we should |
5271 | stop, only if BL explains the stop. */ | |
5272 | ||
18a18393 | 5273 | static int |
6c95b8df | 5274 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5275 | struct address_space *aspace, CORE_ADDR bp_addr, |
5276 | const struct target_waitstatus *ws) | |
18a18393 VP |
5277 | { |
5278 | struct breakpoint *b = bl->owner; | |
5279 | ||
348d480f | 5280 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5281 | gdb_assert (b != NULL); |
5282 | ||
09ac7c10 | 5283 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5284 | } |
5285 | ||
3a5c3e22 PA |
5286 | /* Determine if the watched values have actually changed, and we |
5287 | should stop. If not, set BS->stop to 0. */ | |
5288 | ||
18a18393 VP |
5289 | static void |
5290 | bpstat_check_watchpoint (bpstat bs) | |
5291 | { | |
2bdf28a0 | 5292 | const struct bp_location *bl; |
3a5c3e22 | 5293 | struct watchpoint *b; |
2bdf28a0 JK |
5294 | |
5295 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5296 | bl = bs->bp_location_at; |
2bdf28a0 | 5297 | gdb_assert (bl != NULL); |
3a5c3e22 | 5298 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5299 | gdb_assert (b != NULL); |
18a18393 | 5300 | |
18a18393 | 5301 | { |
18a18393 VP |
5302 | int must_check_value = 0; |
5303 | ||
c1fc2657 | 5304 | if (b->type == bp_watchpoint) |
18a18393 VP |
5305 | /* For a software watchpoint, we must always check the |
5306 | watched value. */ | |
5307 | must_check_value = 1; | |
5308 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5309 | /* We have a hardware watchpoint (read, write, or access) | |
5310 | and the target earlier reported an address watched by | |
5311 | this watchpoint. */ | |
5312 | must_check_value = 1; | |
5313 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5314 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5315 | /* We were stopped by a hardware watchpoint, but the target could |
5316 | not report the data address. We must check the watchpoint's | |
5317 | value. Access and read watchpoints are out of luck; without | |
5318 | a data address, we can't figure it out. */ | |
5319 | must_check_value = 1; | |
3a5c3e22 | 5320 | |
18a18393 VP |
5321 | if (must_check_value) |
5322 | { | |
3e43a32a MS |
5323 | char *message |
5324 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
c1fc2657 | 5325 | b->number); |
18a18393 VP |
5326 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5327 | int e = catch_errors (watchpoint_check, bs, message, | |
5328 | RETURN_MASK_ALL); | |
5329 | do_cleanups (cleanups); | |
5330 | switch (e) | |
5331 | { | |
5332 | case WP_DELETED: | |
5333 | /* We've already printed what needs to be printed. */ | |
5334 | bs->print_it = print_it_done; | |
5335 | /* Stop. */ | |
5336 | break; | |
60e1c644 PA |
5337 | case WP_IGNORE: |
5338 | bs->print_it = print_it_noop; | |
5339 | bs->stop = 0; | |
5340 | break; | |
18a18393 | 5341 | case WP_VALUE_CHANGED: |
c1fc2657 | 5342 | if (b->type == bp_read_watchpoint) |
18a18393 | 5343 | { |
85d721b8 PA |
5344 | /* There are two cases to consider here: |
5345 | ||
4a64f543 | 5346 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5347 | In that case, trust the target, and always report |
5348 | the watchpoint hit to the user. Even though | |
5349 | reads don't cause value changes, the value may | |
5350 | have changed since the last time it was read, and | |
5351 | since we're not trapping writes, we will not see | |
5352 | those, and as such we should ignore our notion of | |
5353 | old value. | |
5354 | ||
4a64f543 | 5355 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5356 | reads and writes. There are two ways this may |
5357 | happen: | |
5358 | ||
4a64f543 | 5359 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5360 | reads only, but can break on accesses (reads or |
5361 | writes), such as e.g., x86. We detect this case | |
5362 | at the time we try to insert read watchpoints. | |
5363 | ||
4a64f543 | 5364 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5365 | watchpoints, but, the user set an access or write |
5366 | watchpoint watching the same memory as this read | |
5367 | watchpoint. | |
5368 | ||
5369 | If we're watching memory writes as well as reads, | |
5370 | ignore watchpoint hits when we find that the | |
5371 | value hasn't changed, as reads don't cause | |
5372 | changes. This still gives false positives when | |
5373 | the program writes the same value to memory as | |
5374 | what there was already in memory (we will confuse | |
5375 | it for a read), but it's much better than | |
5376 | nothing. */ | |
5377 | ||
5378 | int other_write_watchpoint = 0; | |
5379 | ||
5380 | if (bl->watchpoint_type == hw_read) | |
5381 | { | |
5382 | struct breakpoint *other_b; | |
5383 | ||
5384 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5385 | if (other_b->type == bp_hardware_watchpoint |
5386 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5387 | { |
3a5c3e22 PA |
5388 | struct watchpoint *other_w = |
5389 | (struct watchpoint *) other_b; | |
5390 | ||
5391 | if (other_w->watchpoint_triggered | |
5392 | == watch_triggered_yes) | |
5393 | { | |
5394 | other_write_watchpoint = 1; | |
5395 | break; | |
5396 | } | |
85d721b8 PA |
5397 | } |
5398 | } | |
5399 | ||
5400 | if (other_write_watchpoint | |
5401 | || bl->watchpoint_type == hw_access) | |
5402 | { | |
5403 | /* We're watching the same memory for writes, | |
5404 | and the value changed since the last time we | |
5405 | updated it, so this trap must be for a write. | |
5406 | Ignore it. */ | |
5407 | bs->print_it = print_it_noop; | |
5408 | bs->stop = 0; | |
5409 | } | |
18a18393 VP |
5410 | } |
5411 | break; | |
5412 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5413 | if (b->type == bp_hardware_watchpoint |
5414 | || b->type == bp_watchpoint) | |
18a18393 VP |
5415 | { |
5416 | /* Don't stop: write watchpoints shouldn't fire if | |
5417 | the value hasn't changed. */ | |
5418 | bs->print_it = print_it_noop; | |
5419 | bs->stop = 0; | |
5420 | } | |
5421 | /* Stop. */ | |
5422 | break; | |
5423 | default: | |
5424 | /* Can't happen. */ | |
5425 | case 0: | |
5426 | /* Error from catch_errors. */ | |
468afe6c | 5427 | { |
0e454242 | 5428 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5429 | { |
5430 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
c1fc2657 | 5431 | b->number); |
468afe6c PA |
5432 | } |
5433 | watchpoint_del_at_next_stop (b); | |
5434 | /* We've already printed what needs to be printed. */ | |
5435 | bs->print_it = print_it_done; | |
5436 | } | |
18a18393 VP |
5437 | break; |
5438 | } | |
5439 | } | |
5440 | else /* must_check_value == 0 */ | |
5441 | { | |
5442 | /* This is a case where some watchpoint(s) triggered, but | |
5443 | not at the address of this watchpoint, or else no | |
5444 | watchpoint triggered after all. So don't print | |
5445 | anything for this watchpoint. */ | |
5446 | bs->print_it = print_it_noop; | |
5447 | bs->stop = 0; | |
5448 | } | |
5449 | } | |
5450 | } | |
5451 | ||
7d4df6a4 DE |
5452 | /* For breakpoints that are currently marked as telling gdb to stop, |
5453 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5454 | of breakpoint referred to by BS. If we should not stop for this |
5455 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5456 | |
18a18393 VP |
5457 | static void |
5458 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5459 | { | |
2bdf28a0 JK |
5460 | const struct bp_location *bl; |
5461 | struct breakpoint *b; | |
7d4df6a4 DE |
5462 | int value_is_zero = 0; |
5463 | struct expression *cond; | |
5464 | ||
5465 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5466 | |
5467 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5468 | bl = bs->bp_location_at; |
2bdf28a0 | 5469 | gdb_assert (bl != NULL); |
f431efe5 | 5470 | b = bs->breakpoint_at; |
2bdf28a0 | 5471 | gdb_assert (b != NULL); |
18a18393 | 5472 | |
b775012e LM |
5473 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5474 | need to do so again since GDB does not know if we stopped due to a | |
5475 | breakpoint or a single step breakpoint. */ | |
5476 | ||
18a18393 | 5477 | if (frame_id_p (b->frame_id) |
edb3359d | 5478 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5479 | { |
7d4df6a4 DE |
5480 | bs->stop = 0; |
5481 | return; | |
5482 | } | |
60e1c644 | 5483 | |
12ab52e9 PA |
5484 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5485 | evaluating the condition if this isn't the specified | |
5486 | thread/task. */ | |
5d5658a1 | 5487 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5488 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5489 | ||
6c1b0f7b DE |
5490 | { |
5491 | bs->stop = 0; | |
5492 | return; | |
5493 | } | |
5494 | ||
6dddc817 DE |
5495 | /* Evaluate extension language breakpoints that have a "stop" method |
5496 | implemented. */ | |
5497 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5498 | |
7d4df6a4 DE |
5499 | if (is_watchpoint (b)) |
5500 | { | |
5501 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5502 | |
4d01a485 | 5503 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5504 | } |
5505 | else | |
4d01a485 | 5506 | cond = bl->cond.get (); |
60e1c644 | 5507 | |
7d4df6a4 DE |
5508 | if (cond && b->disposition != disp_del_at_next_stop) |
5509 | { | |
5510 | int within_current_scope = 1; | |
5511 | struct watchpoint * w; | |
60e1c644 | 5512 | |
7d4df6a4 DE |
5513 | /* We use value_mark and value_free_to_mark because it could |
5514 | be a long time before we return to the command level and | |
5515 | call free_all_values. We can't call free_all_values | |
5516 | because we might be in the middle of evaluating a | |
5517 | function call. */ | |
5518 | struct value *mark = value_mark (); | |
5519 | ||
5520 | if (is_watchpoint (b)) | |
5521 | w = (struct watchpoint *) b; | |
5522 | else | |
5523 | w = NULL; | |
5524 | ||
5525 | /* Need to select the frame, with all that implies so that | |
5526 | the conditions will have the right context. Because we | |
5527 | use the frame, we will not see an inlined function's | |
5528 | variables when we arrive at a breakpoint at the start | |
5529 | of the inlined function; the current frame will be the | |
5530 | call site. */ | |
5531 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5532 | select_frame (get_current_frame ()); | |
5533 | else | |
18a18393 | 5534 | { |
7d4df6a4 DE |
5535 | struct frame_info *frame; |
5536 | ||
5537 | /* For local watchpoint expressions, which particular | |
5538 | instance of a local is being watched matters, so we | |
5539 | keep track of the frame to evaluate the expression | |
5540 | in. To evaluate the condition however, it doesn't | |
5541 | really matter which instantiation of the function | |
5542 | where the condition makes sense triggers the | |
5543 | watchpoint. This allows an expression like "watch | |
5544 | global if q > 10" set in `func', catch writes to | |
5545 | global on all threads that call `func', or catch | |
5546 | writes on all recursive calls of `func' by a single | |
5547 | thread. We simply always evaluate the condition in | |
5548 | the innermost frame that's executing where it makes | |
5549 | sense to evaluate the condition. It seems | |
5550 | intuitive. */ | |
5551 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5552 | if (frame != NULL) | |
5553 | select_frame (frame); | |
5554 | else | |
5555 | within_current_scope = 0; | |
18a18393 | 5556 | } |
7d4df6a4 DE |
5557 | if (within_current_scope) |
5558 | value_is_zero | |
5559 | = catch_errors (breakpoint_cond_eval, cond, | |
5560 | "Error in testing breakpoint condition:\n", | |
5561 | RETURN_MASK_ALL); | |
5562 | else | |
18a18393 | 5563 | { |
7d4df6a4 DE |
5564 | warning (_("Watchpoint condition cannot be tested " |
5565 | "in the current scope")); | |
5566 | /* If we failed to set the right context for this | |
5567 | watchpoint, unconditionally report it. */ | |
5568 | value_is_zero = 0; | |
18a18393 | 5569 | } |
7d4df6a4 DE |
5570 | /* FIXME-someday, should give breakpoint #. */ |
5571 | value_free_to_mark (mark); | |
18a18393 | 5572 | } |
7d4df6a4 DE |
5573 | |
5574 | if (cond && value_is_zero) | |
5575 | { | |
5576 | bs->stop = 0; | |
5577 | } | |
7d4df6a4 DE |
5578 | else if (b->ignore_count > 0) |
5579 | { | |
5580 | b->ignore_count--; | |
5581 | bs->stop = 0; | |
5582 | /* Increase the hit count even though we don't stop. */ | |
5583 | ++(b->hit_count); | |
5584 | observer_notify_breakpoint_modified (b); | |
5585 | } | |
18a18393 VP |
5586 | } |
5587 | ||
1cf4d951 PA |
5588 | /* Returns true if we need to track moribund locations of LOC's type |
5589 | on the current target. */ | |
5590 | ||
5591 | static int | |
5592 | need_moribund_for_location_type (struct bp_location *loc) | |
5593 | { | |
5594 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5595 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5596 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5597 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5598 | } | |
5599 | ||
18a18393 | 5600 | |
9709f61c | 5601 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5602 | BP_ADDR in thread PTID. |
c906108c | 5603 | |
d983da9c | 5604 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5605 | don't understand this stop. Result is a chain of bpstat's such |
5606 | that: | |
c906108c | 5607 | |
c5aa993b | 5608 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5609 | |
c5aa993b | 5610 | if we understand why we stopped, the result is not null. |
c906108c | 5611 | |
c5aa993b JM |
5612 | Each element of the chain refers to a particular breakpoint or |
5613 | watchpoint at which we have stopped. (We may have stopped for | |
5614 | several reasons concurrently.) | |
c906108c | 5615 | |
c5aa993b JM |
5616 | Each element of the chain has valid next, breakpoint_at, |
5617 | commands, FIXME??? fields. */ | |
c906108c SS |
5618 | |
5619 | bpstat | |
6c95b8df | 5620 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5621 | CORE_ADDR bp_addr, ptid_t ptid, |
5622 | const struct target_waitstatus *ws) | |
c906108c | 5623 | { |
0d381245 | 5624 | struct breakpoint *b = NULL; |
afe38095 | 5625 | struct bp_location *bl; |
20874c92 | 5626 | struct bp_location *loc; |
5760d0ab JK |
5627 | /* First item of allocated bpstat's. */ |
5628 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5629 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5630 | bpstat bs; |
20874c92 | 5631 | int ix; |
429374b8 | 5632 | int need_remove_insert; |
f431efe5 | 5633 | int removed_any; |
c906108c | 5634 | |
f431efe5 PA |
5635 | /* First, build the bpstat chain with locations that explain a |
5636 | target stop, while being careful to not set the target running, | |
5637 | as that may invalidate locations (in particular watchpoint | |
5638 | locations are recreated). Resuming will happen here with | |
5639 | breakpoint conditions or watchpoint expressions that include | |
5640 | inferior function calls. */ | |
c5aa993b | 5641 | |
429374b8 JK |
5642 | ALL_BREAKPOINTS (b) |
5643 | { | |
1a853c52 | 5644 | if (!breakpoint_enabled (b)) |
429374b8 | 5645 | continue; |
a5606eee | 5646 | |
429374b8 JK |
5647 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5648 | { | |
4a64f543 MS |
5649 | /* For hardware watchpoints, we look only at the first |
5650 | location. The watchpoint_check function will work on the | |
5651 | entire expression, not the individual locations. For | |
5652 | read watchpoints, the watchpoints_triggered function has | |
5653 | checked all locations already. */ | |
429374b8 JK |
5654 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5655 | break; | |
18a18393 | 5656 | |
f6592439 | 5657 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5658 | continue; |
c5aa993b | 5659 | |
09ac7c10 | 5660 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5661 | continue; |
c5aa993b | 5662 | |
4a64f543 MS |
5663 | /* Come here if it's a watchpoint, or if the break address |
5664 | matches. */ | |
c5aa993b | 5665 | |
4a64f543 MS |
5666 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5667 | explain stop. */ | |
c5aa993b | 5668 | |
f431efe5 PA |
5669 | /* Assume we stop. Should we find a watchpoint that is not |
5670 | actually triggered, or if the condition of the breakpoint | |
5671 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5672 | bs->stop = 1; |
5673 | bs->print = 1; | |
d983da9c | 5674 | |
f431efe5 PA |
5675 | /* If this is a scope breakpoint, mark the associated |
5676 | watchpoint as triggered so that we will handle the | |
5677 | out-of-scope event. We'll get to the watchpoint next | |
5678 | iteration. */ | |
d0fb5eae | 5679 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5680 | { |
5681 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5682 | ||
5683 | w->watchpoint_triggered = watch_triggered_yes; | |
5684 | } | |
f431efe5 PA |
5685 | } |
5686 | } | |
5687 | ||
7c16b83e | 5688 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5689 | if (!target_supports_stopped_by_sw_breakpoint () |
5690 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5691 | { |
1cf4d951 | 5692 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5693 | { |
1cf4d951 PA |
5694 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5695 | && need_moribund_for_location_type (loc)) | |
5696 | { | |
5697 | bs = bpstat_alloc (loc, &bs_link); | |
5698 | /* For hits of moribund locations, we should just proceed. */ | |
5699 | bs->stop = 0; | |
5700 | bs->print = 0; | |
5701 | bs->print_it = print_it_noop; | |
5702 | } | |
f431efe5 PA |
5703 | } |
5704 | } | |
5705 | ||
edcc5120 TT |
5706 | /* A bit of special processing for shlib breakpoints. We need to |
5707 | process solib loading here, so that the lists of loaded and | |
5708 | unloaded libraries are correct before we handle "catch load" and | |
5709 | "catch unload". */ | |
5710 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5711 | { | |
5d268276 | 5712 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5713 | { |
5714 | handle_solib_event (); | |
5715 | break; | |
5716 | } | |
5717 | } | |
5718 | ||
f431efe5 PA |
5719 | /* Now go through the locations that caused the target to stop, and |
5720 | check whether we're interested in reporting this stop to higher | |
5721 | layers, or whether we should resume the target transparently. */ | |
5722 | ||
5723 | removed_any = 0; | |
5724 | ||
5760d0ab | 5725 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5726 | { |
5727 | if (!bs->stop) | |
5728 | continue; | |
5729 | ||
f431efe5 | 5730 | b = bs->breakpoint_at; |
348d480f PA |
5731 | b->ops->check_status (bs); |
5732 | if (bs->stop) | |
28010a5d | 5733 | { |
348d480f | 5734 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5735 | |
429374b8 JK |
5736 | if (bs->stop) |
5737 | { | |
5738 | ++(b->hit_count); | |
8d3788bd | 5739 | observer_notify_breakpoint_modified (b); |
c906108c | 5740 | |
4a64f543 | 5741 | /* We will stop here. */ |
429374b8 JK |
5742 | if (b->disposition == disp_disable) |
5743 | { | |
816338b5 | 5744 | --(b->enable_count); |
1a853c52 | 5745 | if (b->enable_count <= 0) |
429374b8 | 5746 | b->enable_state = bp_disabled; |
f431efe5 | 5747 | removed_any = 1; |
429374b8 JK |
5748 | } |
5749 | if (b->silent) | |
5750 | bs->print = 0; | |
5751 | bs->commands = b->commands; | |
9add0f1b | 5752 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5753 | if (command_line_is_silent (bs->commands |
5754 | ? bs->commands->commands : NULL)) | |
5755 | bs->print = 0; | |
9d6e6e84 HZ |
5756 | |
5757 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5758 | } |
5759 | ||
348d480f | 5760 | } |
a9b3a50f PA |
5761 | |
5762 | /* Print nothing for this entry if we don't stop or don't | |
5763 | print. */ | |
5764 | if (!bs->stop || !bs->print) | |
5765 | bs->print_it = print_it_noop; | |
429374b8 | 5766 | } |
876fa593 | 5767 | |
d983da9c DJ |
5768 | /* If we aren't stopping, the value of some hardware watchpoint may |
5769 | not have changed, but the intermediate memory locations we are | |
5770 | watching may have. Don't bother if we're stopping; this will get | |
5771 | done later. */ | |
d832cb68 | 5772 | need_remove_insert = 0; |
5760d0ab JK |
5773 | if (! bpstat_causes_stop (bs_head)) |
5774 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5775 | if (!bs->stop |
f431efe5 PA |
5776 | && bs->breakpoint_at |
5777 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5778 | { |
3a5c3e22 PA |
5779 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5780 | ||
5781 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5782 | need_remove_insert = 1; |
d983da9c DJ |
5783 | } |
5784 | ||
d832cb68 | 5785 | if (need_remove_insert) |
44702360 | 5786 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5787 | else if (removed_any) |
44702360 | 5788 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5789 | |
5760d0ab | 5790 | return bs_head; |
c906108c | 5791 | } |
628fe4e4 JK |
5792 | |
5793 | static void | |
5794 | handle_jit_event (void) | |
5795 | { | |
5796 | struct frame_info *frame; | |
5797 | struct gdbarch *gdbarch; | |
5798 | ||
243a9253 PA |
5799 | if (debug_infrun) |
5800 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5801 | ||
628fe4e4 JK |
5802 | /* Switch terminal for any messages produced by |
5803 | breakpoint_re_set. */ | |
5804 | target_terminal_ours_for_output (); | |
5805 | ||
5806 | frame = get_current_frame (); | |
5807 | gdbarch = get_frame_arch (frame); | |
5808 | ||
5809 | jit_event_handler (gdbarch); | |
5810 | ||
5811 | target_terminal_inferior (); | |
5812 | } | |
5813 | ||
5814 | /* Prepare WHAT final decision for infrun. */ | |
5815 | ||
5816 | /* Decide what infrun needs to do with this bpstat. */ | |
5817 | ||
c906108c | 5818 | struct bpstat_what |
0e30163f | 5819 | bpstat_what (bpstat bs_head) |
c906108c | 5820 | { |
c906108c | 5821 | struct bpstat_what retval; |
0e30163f | 5822 | bpstat bs; |
c906108c | 5823 | |
628fe4e4 | 5824 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5825 | retval.call_dummy = STOP_NONE; |
186c406b | 5826 | retval.is_longjmp = 0; |
628fe4e4 | 5827 | |
0e30163f | 5828 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5829 | { |
628fe4e4 JK |
5830 | /* Extract this BS's action. After processing each BS, we check |
5831 | if its action overrides all we've seem so far. */ | |
5832 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5833 | enum bptype bptype; | |
5834 | ||
c906108c | 5835 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5836 | { |
5837 | /* I suspect this can happen if it was a momentary | |
5838 | breakpoint which has since been deleted. */ | |
5839 | bptype = bp_none; | |
5840 | } | |
20874c92 | 5841 | else |
f431efe5 | 5842 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5843 | |
5844 | switch (bptype) | |
c906108c SS |
5845 | { |
5846 | case bp_none: | |
628fe4e4 | 5847 | break; |
c906108c SS |
5848 | case bp_breakpoint: |
5849 | case bp_hardware_breakpoint: | |
7c16b83e | 5850 | case bp_single_step: |
c906108c SS |
5851 | case bp_until: |
5852 | case bp_finish: | |
a9b3a50f | 5853 | case bp_shlib_event: |
c906108c SS |
5854 | if (bs->stop) |
5855 | { | |
5856 | if (bs->print) | |
628fe4e4 | 5857 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5858 | else |
628fe4e4 | 5859 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5860 | } |
5861 | else | |
628fe4e4 | 5862 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5863 | break; |
5864 | case bp_watchpoint: | |
5865 | case bp_hardware_watchpoint: | |
5866 | case bp_read_watchpoint: | |
5867 | case bp_access_watchpoint: | |
5868 | if (bs->stop) | |
5869 | { | |
5870 | if (bs->print) | |
628fe4e4 | 5871 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5872 | else |
628fe4e4 | 5873 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5874 | } |
5875 | else | |
628fe4e4 JK |
5876 | { |
5877 | /* There was a watchpoint, but we're not stopping. | |
5878 | This requires no further action. */ | |
5879 | } | |
c906108c SS |
5880 | break; |
5881 | case bp_longjmp: | |
e2e4d78b | 5882 | case bp_longjmp_call_dummy: |
186c406b | 5883 | case bp_exception: |
0a39bb32 PA |
5884 | if (bs->stop) |
5885 | { | |
5886 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5887 | retval.is_longjmp = bptype != bp_exception; | |
5888 | } | |
5889 | else | |
5890 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5891 | break; |
5892 | case bp_longjmp_resume: | |
186c406b | 5893 | case bp_exception_resume: |
0a39bb32 PA |
5894 | if (bs->stop) |
5895 | { | |
5896 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5897 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5898 | } | |
5899 | else | |
5900 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5901 | break; |
5902 | case bp_step_resume: | |
5903 | if (bs->stop) | |
628fe4e4 JK |
5904 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5905 | else | |
c906108c | 5906 | { |
628fe4e4 JK |
5907 | /* It is for the wrong frame. */ |
5908 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5909 | } |
c906108c | 5910 | break; |
2c03e5be PA |
5911 | case bp_hp_step_resume: |
5912 | if (bs->stop) | |
5913 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5914 | else | |
5915 | { | |
5916 | /* It is for the wrong frame. */ | |
5917 | this_action = BPSTAT_WHAT_SINGLE; | |
5918 | } | |
5919 | break; | |
c906108c | 5920 | case bp_watchpoint_scope: |
c4093a6a | 5921 | case bp_thread_event: |
1900040c | 5922 | case bp_overlay_event: |
0fd8e87f | 5923 | case bp_longjmp_master: |
aa7d318d | 5924 | case bp_std_terminate_master: |
186c406b | 5925 | case bp_exception_master: |
628fe4e4 | 5926 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5927 | break; |
ce78b96d | 5928 | case bp_catchpoint: |
c5aa993b JM |
5929 | if (bs->stop) |
5930 | { | |
5931 | if (bs->print) | |
628fe4e4 | 5932 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5933 | else |
628fe4e4 | 5934 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5935 | } |
5936 | else | |
628fe4e4 JK |
5937 | { |
5938 | /* There was a catchpoint, but we're not stopping. | |
5939 | This requires no further action. */ | |
5940 | } | |
5941 | break; | |
628fe4e4 | 5942 | case bp_jit_event: |
628fe4e4 | 5943 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5944 | break; |
c906108c | 5945 | case bp_call_dummy: |
53a5351d JM |
5946 | /* Make sure the action is stop (silent or noisy), |
5947 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5948 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5949 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5950 | break; |
5951 | case bp_std_terminate: | |
5952 | /* Make sure the action is stop (silent or noisy), | |
5953 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5954 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5955 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5956 | break; |
1042e4c0 | 5957 | case bp_tracepoint: |
7a697b8d | 5958 | case bp_fast_tracepoint: |
0fb4aa4b | 5959 | case bp_static_tracepoint: |
1042e4c0 SS |
5960 | /* Tracepoint hits should not be reported back to GDB, and |
5961 | if one got through somehow, it should have been filtered | |
5962 | out already. */ | |
5963 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5964 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5965 | break; |
5966 | case bp_gnu_ifunc_resolver: | |
5967 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5968 | this_action = BPSTAT_WHAT_SINGLE; | |
5969 | break; | |
5970 | case bp_gnu_ifunc_resolver_return: | |
5971 | /* The breakpoint will be removed, execution will restart from the | |
5972 | PC of the former breakpoint. */ | |
5973 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5974 | break; | |
e7e0cddf SS |
5975 | |
5976 | case bp_dprintf: | |
a11cfd87 HZ |
5977 | if (bs->stop) |
5978 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5979 | else | |
5980 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5981 | break; |
5982 | ||
628fe4e4 JK |
5983 | default: |
5984 | internal_error (__FILE__, __LINE__, | |
5985 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5986 | } |
628fe4e4 | 5987 | |
325fac50 | 5988 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5989 | } |
628fe4e4 | 5990 | |
243a9253 PA |
5991 | return retval; |
5992 | } | |
628fe4e4 | 5993 | |
243a9253 PA |
5994 | void |
5995 | bpstat_run_callbacks (bpstat bs_head) | |
5996 | { | |
5997 | bpstat bs; | |
628fe4e4 | 5998 | |
0e30163f JK |
5999 | for (bs = bs_head; bs != NULL; bs = bs->next) |
6000 | { | |
6001 | struct breakpoint *b = bs->breakpoint_at; | |
6002 | ||
6003 | if (b == NULL) | |
6004 | continue; | |
6005 | switch (b->type) | |
6006 | { | |
243a9253 PA |
6007 | case bp_jit_event: |
6008 | handle_jit_event (); | |
6009 | break; | |
0e30163f JK |
6010 | case bp_gnu_ifunc_resolver: |
6011 | gnu_ifunc_resolver_stop (b); | |
6012 | break; | |
6013 | case bp_gnu_ifunc_resolver_return: | |
6014 | gnu_ifunc_resolver_return_stop (b); | |
6015 | break; | |
6016 | } | |
6017 | } | |
c906108c SS |
6018 | } |
6019 | ||
6020 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6021 | without hardware support). This isn't related to a specific bpstat, | |
6022 | just to things like whether watchpoints are set. */ | |
6023 | ||
c5aa993b | 6024 | int |
fba45db2 | 6025 | bpstat_should_step (void) |
c906108c SS |
6026 | { |
6027 | struct breakpoint *b; | |
cc59ec59 | 6028 | |
c906108c | 6029 | ALL_BREAKPOINTS (b) |
717a8278 | 6030 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6031 | return 1; |
c906108c SS |
6032 | return 0; |
6033 | } | |
6034 | ||
67822962 PA |
6035 | int |
6036 | bpstat_causes_stop (bpstat bs) | |
6037 | { | |
6038 | for (; bs != NULL; bs = bs->next) | |
6039 | if (bs->stop) | |
6040 | return 1; | |
6041 | ||
6042 | return 0; | |
6043 | } | |
6044 | ||
c906108c | 6045 | \f |
c5aa993b | 6046 | |
170b53b2 UW |
6047 | /* Compute a string of spaces suitable to indent the next line |
6048 | so it starts at the position corresponding to the table column | |
6049 | named COL_NAME in the currently active table of UIOUT. */ | |
6050 | ||
6051 | static char * | |
6052 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6053 | { | |
6054 | static char wrap_indent[80]; | |
6055 | int i, total_width, width, align; | |
c5209615 | 6056 | const char *text; |
170b53b2 UW |
6057 | |
6058 | total_width = 0; | |
112e8700 | 6059 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
6060 | { |
6061 | if (strcmp (text, col_name) == 0) | |
6062 | { | |
6063 | gdb_assert (total_width < sizeof wrap_indent); | |
6064 | memset (wrap_indent, ' ', total_width); | |
6065 | wrap_indent[total_width] = 0; | |
6066 | ||
6067 | return wrap_indent; | |
6068 | } | |
6069 | ||
6070 | total_width += width + 1; | |
6071 | } | |
6072 | ||
6073 | return NULL; | |
6074 | } | |
6075 | ||
b775012e LM |
6076 | /* Determine if the locations of this breakpoint will have their conditions |
6077 | evaluated by the target, host or a mix of both. Returns the following: | |
6078 | ||
6079 | "host": Host evals condition. | |
6080 | "host or target": Host or Target evals condition. | |
6081 | "target": Target evals condition. | |
6082 | */ | |
6083 | ||
6084 | static const char * | |
6085 | bp_condition_evaluator (struct breakpoint *b) | |
6086 | { | |
6087 | struct bp_location *bl; | |
6088 | char host_evals = 0; | |
6089 | char target_evals = 0; | |
6090 | ||
6091 | if (!b) | |
6092 | return NULL; | |
6093 | ||
6094 | if (!is_breakpoint (b)) | |
6095 | return NULL; | |
6096 | ||
6097 | if (gdb_evaluates_breakpoint_condition_p () | |
6098 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6099 | return condition_evaluation_host; | |
6100 | ||
6101 | for (bl = b->loc; bl; bl = bl->next) | |
6102 | { | |
6103 | if (bl->cond_bytecode) | |
6104 | target_evals++; | |
6105 | else | |
6106 | host_evals++; | |
6107 | } | |
6108 | ||
6109 | if (host_evals && target_evals) | |
6110 | return condition_evaluation_both; | |
6111 | else if (target_evals) | |
6112 | return condition_evaluation_target; | |
6113 | else | |
6114 | return condition_evaluation_host; | |
6115 | } | |
6116 | ||
6117 | /* Determine the breakpoint location's condition evaluator. This is | |
6118 | similar to bp_condition_evaluator, but for locations. */ | |
6119 | ||
6120 | static const char * | |
6121 | bp_location_condition_evaluator (struct bp_location *bl) | |
6122 | { | |
6123 | if (bl && !is_breakpoint (bl->owner)) | |
6124 | return NULL; | |
6125 | ||
6126 | if (gdb_evaluates_breakpoint_condition_p () | |
6127 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6128 | return condition_evaluation_host; | |
6129 | ||
6130 | if (bl && bl->cond_bytecode) | |
6131 | return condition_evaluation_target; | |
6132 | else | |
6133 | return condition_evaluation_host; | |
6134 | } | |
6135 | ||
859825b8 JK |
6136 | /* Print the LOC location out of the list of B->LOC locations. */ |
6137 | ||
170b53b2 UW |
6138 | static void |
6139 | print_breakpoint_location (struct breakpoint *b, | |
6140 | struct bp_location *loc) | |
0d381245 | 6141 | { |
79a45e25 | 6142 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
6143 | |
6144 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 6145 | |
859825b8 JK |
6146 | if (loc != NULL && loc->shlib_disabled) |
6147 | loc = NULL; | |
6148 | ||
6c95b8df PA |
6149 | if (loc != NULL) |
6150 | set_current_program_space (loc->pspace); | |
6151 | ||
56435ebe | 6152 | if (b->display_canonical) |
d28cd78a | 6153 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 6154 | else if (loc && loc->symtab) |
0d381245 VP |
6155 | { |
6156 | struct symbol *sym | |
6157 | = find_pc_sect_function (loc->address, loc->section); | |
6158 | if (sym) | |
6159 | { | |
112e8700 SM |
6160 | uiout->text ("in "); |
6161 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); | |
6162 | uiout->text (" "); | |
6163 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
6164 | uiout->text ("at "); | |
0d381245 | 6165 | } |
112e8700 | 6166 | uiout->field_string ("file", |
05cba821 | 6167 | symtab_to_filename_for_display (loc->symtab)); |
112e8700 | 6168 | uiout->text (":"); |
05cba821 | 6169 | |
112e8700 SM |
6170 | if (uiout->is_mi_like_p ()) |
6171 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6172 | |
112e8700 | 6173 | uiout->field_int ("line", loc->line_number); |
0d381245 | 6174 | } |
859825b8 | 6175 | else if (loc) |
0d381245 | 6176 | { |
d7e74731 | 6177 | string_file stb; |
170b53b2 | 6178 | |
d7e74731 | 6179 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6180 | demangle, ""); |
112e8700 | 6181 | uiout->field_stream ("at", stb); |
0d381245 | 6182 | } |
859825b8 | 6183 | else |
f00aae0f | 6184 | { |
d28cd78a TT |
6185 | uiout->field_string ("pending", |
6186 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
6187 | /* If extra_string is available, it could be holding a condition |
6188 | or dprintf arguments. In either case, make sure it is printed, | |
6189 | too, but only for non-MI streams. */ | |
112e8700 | 6190 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6191 | { |
6192 | if (b->type == bp_dprintf) | |
112e8700 | 6193 | uiout->text (","); |
f00aae0f | 6194 | else |
112e8700 SM |
6195 | uiout->text (" "); |
6196 | uiout->text (b->extra_string); | |
f00aae0f KS |
6197 | } |
6198 | } | |
6c95b8df | 6199 | |
b775012e LM |
6200 | if (loc && is_breakpoint (b) |
6201 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6202 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6203 | { | |
112e8700 SM |
6204 | uiout->text (" ("); |
6205 | uiout->field_string ("evaluated-by", | |
b775012e | 6206 | bp_location_condition_evaluator (loc)); |
112e8700 | 6207 | uiout->text (")"); |
b775012e | 6208 | } |
0d381245 VP |
6209 | } |
6210 | ||
269b11a2 PA |
6211 | static const char * |
6212 | bptype_string (enum bptype type) | |
c906108c | 6213 | { |
c4093a6a JM |
6214 | struct ep_type_description |
6215 | { | |
6216 | enum bptype type; | |
a121b7c1 | 6217 | const char *description; |
c4093a6a JM |
6218 | }; |
6219 | static struct ep_type_description bptypes[] = | |
c906108c | 6220 | { |
c5aa993b JM |
6221 | {bp_none, "?deleted?"}, |
6222 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6223 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6224 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6225 | {bp_until, "until"}, |
6226 | {bp_finish, "finish"}, | |
6227 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6228 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6229 | {bp_read_watchpoint, "read watchpoint"}, |
6230 | {bp_access_watchpoint, "acc watchpoint"}, | |
6231 | {bp_longjmp, "longjmp"}, | |
6232 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6233 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6234 | {bp_exception, "exception"}, |
6235 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6236 | {bp_step_resume, "step resume"}, |
2c03e5be | 6237 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6238 | {bp_watchpoint_scope, "watchpoint scope"}, |
6239 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6240 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6241 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6242 | {bp_thread_event, "thread events"}, |
1900040c | 6243 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6244 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6245 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6246 | {bp_exception_master, "exception master"}, |
ce78b96d | 6247 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6248 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6249 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6250 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6251 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6252 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6253 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6254 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6255 | }; |
269b11a2 PA |
6256 | |
6257 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6258 | || ((int) type != bptypes[(int) type].type)) | |
6259 | internal_error (__FILE__, __LINE__, | |
6260 | _("bptypes table does not describe type #%d."), | |
6261 | (int) type); | |
6262 | ||
6263 | return bptypes[(int) type].description; | |
6264 | } | |
6265 | ||
998580f1 MK |
6266 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6267 | For CLI, prefix the list with the string 'inf'. */ | |
6268 | ||
6269 | static void | |
6270 | output_thread_groups (struct ui_out *uiout, | |
6271 | const char *field_name, | |
6272 | VEC(int) *inf_num, | |
6273 | int mi_only) | |
6274 | { | |
112e8700 | 6275 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6276 | int inf; |
6277 | int i; | |
6278 | ||
6279 | /* For backward compatibility, don't display inferiors in CLI unless | |
6280 | there are several. Always display them for MI. */ | |
6281 | if (!is_mi && mi_only) | |
6282 | return; | |
6283 | ||
10f489e5 | 6284 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6285 | |
998580f1 MK |
6286 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6287 | { | |
6288 | if (is_mi) | |
6289 | { | |
6290 | char mi_group[10]; | |
6291 | ||
6292 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
112e8700 | 6293 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6294 | } |
6295 | else | |
6296 | { | |
6297 | if (i == 0) | |
112e8700 | 6298 | uiout->text (" inf "); |
998580f1 | 6299 | else |
112e8700 | 6300 | uiout->text (", "); |
998580f1 | 6301 | |
112e8700 | 6302 | uiout->text (plongest (inf)); |
998580f1 MK |
6303 | } |
6304 | } | |
998580f1 MK |
6305 | } |
6306 | ||
269b11a2 PA |
6307 | /* Print B to gdb_stdout. */ |
6308 | ||
6309 | static void | |
6310 | print_one_breakpoint_location (struct breakpoint *b, | |
6311 | struct bp_location *loc, | |
6312 | int loc_number, | |
6313 | struct bp_location **last_loc, | |
269b11a2 PA |
6314 | int allflag) |
6315 | { | |
6316 | struct command_line *l; | |
c2c6d25f | 6317 | static char bpenables[] = "nynny"; |
c906108c | 6318 | |
79a45e25 | 6319 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6320 | int header_of_multiple = 0; |
6321 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6322 | struct value_print_options opts; |
6323 | ||
6324 | get_user_print_options (&opts); | |
0d381245 VP |
6325 | |
6326 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6327 | /* See comment in print_one_breakpoint concerning treatment of |
6328 | breakpoints with single disabled location. */ | |
0d381245 VP |
6329 | if (loc == NULL |
6330 | && (b->loc != NULL | |
6331 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6332 | header_of_multiple = 1; | |
6333 | if (loc == NULL) | |
6334 | loc = b->loc; | |
6335 | ||
c4093a6a JM |
6336 | annotate_record (); |
6337 | ||
6338 | /* 1 */ | |
6339 | annotate_field (0); | |
0d381245 VP |
6340 | if (part_of_multiple) |
6341 | { | |
6342 | char *formatted; | |
0c6773c1 | 6343 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
112e8700 | 6344 | uiout->field_string ("number", formatted); |
0d381245 VP |
6345 | xfree (formatted); |
6346 | } | |
6347 | else | |
6348 | { | |
112e8700 | 6349 | uiout->field_int ("number", b->number); |
0d381245 | 6350 | } |
c4093a6a JM |
6351 | |
6352 | /* 2 */ | |
6353 | annotate_field (1); | |
0d381245 | 6354 | if (part_of_multiple) |
112e8700 | 6355 | uiout->field_skip ("type"); |
269b11a2 | 6356 | else |
112e8700 | 6357 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6358 | |
6359 | /* 3 */ | |
6360 | annotate_field (2); | |
0d381245 | 6361 | if (part_of_multiple) |
112e8700 | 6362 | uiout->field_skip ("disp"); |
0d381245 | 6363 | else |
112e8700 | 6364 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6365 | |
c4093a6a JM |
6366 | |
6367 | /* 4 */ | |
6368 | annotate_field (3); | |
0d381245 | 6369 | if (part_of_multiple) |
112e8700 | 6370 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6371 | else |
112e8700 SM |
6372 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
6373 | uiout->spaces (2); | |
0d381245 | 6374 | |
c4093a6a JM |
6375 | |
6376 | /* 5 and 6 */ | |
3086aeae | 6377 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6378 | { |
4a64f543 MS |
6379 | /* Although the print_one can possibly print all locations, |
6380 | calling it here is not likely to get any nice result. So, | |
6381 | make sure there's just one location. */ | |
0d381245 | 6382 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6383 | b->ops->print_one (b, last_loc); |
0d381245 | 6384 | } |
3086aeae DJ |
6385 | else |
6386 | switch (b->type) | |
6387 | { | |
6388 | case bp_none: | |
6389 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6390 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6391 | break; |
c906108c | 6392 | |
3086aeae DJ |
6393 | case bp_watchpoint: |
6394 | case bp_hardware_watchpoint: | |
6395 | case bp_read_watchpoint: | |
6396 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6397 | { |
6398 | struct watchpoint *w = (struct watchpoint *) b; | |
6399 | ||
6400 | /* Field 4, the address, is omitted (which makes the columns | |
6401 | not line up too nicely with the headers, but the effect | |
6402 | is relatively readable). */ | |
6403 | if (opts.addressprint) | |
112e8700 | 6404 | uiout->field_skip ("addr"); |
3a5c3e22 | 6405 | annotate_field (5); |
112e8700 | 6406 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6407 | } |
3086aeae DJ |
6408 | break; |
6409 | ||
3086aeae DJ |
6410 | case bp_breakpoint: |
6411 | case bp_hardware_breakpoint: | |
7c16b83e | 6412 | case bp_single_step: |
3086aeae DJ |
6413 | case bp_until: |
6414 | case bp_finish: | |
6415 | case bp_longjmp: | |
6416 | case bp_longjmp_resume: | |
e2e4d78b | 6417 | case bp_longjmp_call_dummy: |
186c406b TT |
6418 | case bp_exception: |
6419 | case bp_exception_resume: | |
3086aeae | 6420 | case bp_step_resume: |
2c03e5be | 6421 | case bp_hp_step_resume: |
3086aeae DJ |
6422 | case bp_watchpoint_scope: |
6423 | case bp_call_dummy: | |
aa7d318d | 6424 | case bp_std_terminate: |
3086aeae DJ |
6425 | case bp_shlib_event: |
6426 | case bp_thread_event: | |
6427 | case bp_overlay_event: | |
0fd8e87f | 6428 | case bp_longjmp_master: |
aa7d318d | 6429 | case bp_std_terminate_master: |
186c406b | 6430 | case bp_exception_master: |
1042e4c0 | 6431 | case bp_tracepoint: |
7a697b8d | 6432 | case bp_fast_tracepoint: |
0fb4aa4b | 6433 | case bp_static_tracepoint: |
e7e0cddf | 6434 | case bp_dprintf: |
4efc6507 | 6435 | case bp_jit_event: |
0e30163f JK |
6436 | case bp_gnu_ifunc_resolver: |
6437 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6438 | if (opts.addressprint) |
3086aeae DJ |
6439 | { |
6440 | annotate_field (4); | |
54e52265 | 6441 | if (header_of_multiple) |
112e8700 | 6442 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6443 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6444 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6445 | else |
112e8700 | 6446 | uiout->field_core_addr ("addr", |
5af949e3 | 6447 | loc->gdbarch, loc->address); |
3086aeae DJ |
6448 | } |
6449 | annotate_field (5); | |
0d381245 | 6450 | if (!header_of_multiple) |
170b53b2 | 6451 | print_breakpoint_location (b, loc); |
0d381245 | 6452 | if (b->loc) |
a6d9a66e | 6453 | *last_loc = b->loc; |
3086aeae DJ |
6454 | break; |
6455 | } | |
c906108c | 6456 | |
6c95b8df | 6457 | |
998580f1 | 6458 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6459 | { |
6460 | struct inferior *inf; | |
998580f1 MK |
6461 | VEC(int) *inf_num = NULL; |
6462 | int mi_only = 1; | |
6c95b8df | 6463 | |
998580f1 | 6464 | ALL_INFERIORS (inf) |
6c95b8df PA |
6465 | { |
6466 | if (inf->pspace == loc->pspace) | |
998580f1 | 6467 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6468 | } |
998580f1 MK |
6469 | |
6470 | /* For backward compatibility, don't display inferiors in CLI unless | |
6471 | there are several. Always display for MI. */ | |
6472 | if (allflag | |
6473 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6474 | && (number_of_program_spaces () > 1 | |
6475 | || number_of_inferiors () > 1) | |
6476 | /* LOC is for existing B, it cannot be in | |
6477 | moribund_locations and thus having NULL OWNER. */ | |
6478 | && loc->owner->type != bp_catchpoint)) | |
6479 | mi_only = 0; | |
6480 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6481 | VEC_free (int, inf_num); | |
6c95b8df PA |
6482 | } |
6483 | ||
4a306c9a | 6484 | if (!part_of_multiple) |
c4093a6a | 6485 | { |
4a306c9a JB |
6486 | if (b->thread != -1) |
6487 | { | |
6488 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6489 | "stop only in" line a little further down. */ |
112e8700 SM |
6490 | uiout->text (" thread "); |
6491 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6492 | } |
6493 | else if (b->task != 0) | |
6494 | { | |
112e8700 SM |
6495 | uiout->text (" task "); |
6496 | uiout->field_int ("task", b->task); | |
4a306c9a | 6497 | } |
c4093a6a | 6498 | } |
f1310107 | 6499 | |
112e8700 | 6500 | uiout->text ("\n"); |
f1310107 | 6501 | |
348d480f | 6502 | if (!part_of_multiple) |
f1310107 TJB |
6503 | b->ops->print_one_detail (b, uiout); |
6504 | ||
0d381245 | 6505 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6506 | { |
6507 | annotate_field (6); | |
112e8700 | 6508 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6509 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6510 | the frame ID. */ |
112e8700 | 6511 | uiout->field_core_addr ("frame", |
5af949e3 | 6512 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6513 | uiout->text ("\n"); |
c4093a6a JM |
6514 | } |
6515 | ||
28010a5d | 6516 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6517 | { |
6518 | annotate_field (7); | |
d77f58be | 6519 | if (is_tracepoint (b)) |
112e8700 | 6520 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6521 | else |
112e8700 SM |
6522 | uiout->text ("\tstop only if "); |
6523 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6524 | |
6525 | /* Print whether the target is doing the breakpoint's condition | |
6526 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6527 | if (is_breakpoint (b) | |
6528 | && breakpoint_condition_evaluation_mode () | |
6529 | == condition_evaluation_target) | |
6530 | { | |
112e8700 SM |
6531 | uiout->text (" ("); |
6532 | uiout->field_string ("evaluated-by", | |
b775012e | 6533 | bp_condition_evaluator (b)); |
112e8700 | 6534 | uiout->text (" evals)"); |
b775012e | 6535 | } |
112e8700 | 6536 | uiout->text ("\n"); |
0101ce28 JJ |
6537 | } |
6538 | ||
0d381245 | 6539 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6540 | { |
4a64f543 | 6541 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6542 | uiout->text ("\tstop only in thread "); |
6543 | if (uiout->is_mi_like_p ()) | |
6544 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6545 | else |
6546 | { | |
6547 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6548 | ||
112e8700 | 6549 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6550 | } |
112e8700 | 6551 | uiout->text ("\n"); |
c4093a6a JM |
6552 | } |
6553 | ||
556ec64d YQ |
6554 | if (!part_of_multiple) |
6555 | { | |
6556 | if (b->hit_count) | |
31f56a27 YQ |
6557 | { |
6558 | /* FIXME should make an annotation for this. */ | |
6559 | if (is_catchpoint (b)) | |
112e8700 | 6560 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6561 | else if (is_tracepoint (b)) |
112e8700 | 6562 | uiout->text ("\ttracepoint"); |
31f56a27 | 6563 | else |
112e8700 SM |
6564 | uiout->text ("\tbreakpoint"); |
6565 | uiout->text (" already hit "); | |
6566 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6567 | if (b->hit_count == 1) |
112e8700 | 6568 | uiout->text (" time\n"); |
31f56a27 | 6569 | else |
112e8700 | 6570 | uiout->text (" times\n"); |
31f56a27 | 6571 | } |
556ec64d YQ |
6572 | else |
6573 | { | |
31f56a27 | 6574 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6575 | if (uiout->is_mi_like_p ()) |
6576 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6577 | } |
6578 | } | |
8b93c638 | 6579 | |
0d381245 | 6580 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6581 | { |
6582 | annotate_field (8); | |
112e8700 SM |
6583 | uiout->text ("\tignore next "); |
6584 | uiout->field_int ("ignore", b->ignore_count); | |
6585 | uiout->text (" hits\n"); | |
c4093a6a | 6586 | } |
059fb39f | 6587 | |
816338b5 SS |
6588 | /* Note that an enable count of 1 corresponds to "enable once" |
6589 | behavior, which is reported by the combination of enablement and | |
6590 | disposition, so we don't need to mention it here. */ | |
6591 | if (!part_of_multiple && b->enable_count > 1) | |
6592 | { | |
6593 | annotate_field (8); | |
112e8700 | 6594 | uiout->text ("\tdisable after "); |
816338b5 SS |
6595 | /* Tweak the wording to clarify that ignore and enable counts |
6596 | are distinct, and have additive effect. */ | |
6597 | if (b->ignore_count) | |
112e8700 | 6598 | uiout->text ("additional "); |
816338b5 | 6599 | else |
112e8700 SM |
6600 | uiout->text ("next "); |
6601 | uiout->field_int ("enable", b->enable_count); | |
6602 | uiout->text (" hits\n"); | |
816338b5 SS |
6603 | } |
6604 | ||
f196051f SS |
6605 | if (!part_of_multiple && is_tracepoint (b)) |
6606 | { | |
6607 | struct tracepoint *tp = (struct tracepoint *) b; | |
6608 | ||
6609 | if (tp->traceframe_usage) | |
6610 | { | |
112e8700 SM |
6611 | uiout->text ("\ttrace buffer usage "); |
6612 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6613 | uiout->text (" bytes\n"); | |
f196051f SS |
6614 | } |
6615 | } | |
d3ce09f5 | 6616 | |
9add0f1b | 6617 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6618 | if (!part_of_multiple && l) |
c4093a6a JM |
6619 | { |
6620 | annotate_field (9); | |
2e783024 | 6621 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6622 | print_command_lines (uiout, l, 4); |
c4093a6a | 6623 | } |
d24317b4 | 6624 | |
d9b3f62e | 6625 | if (is_tracepoint (b)) |
1042e4c0 | 6626 | { |
d9b3f62e PA |
6627 | struct tracepoint *t = (struct tracepoint *) b; |
6628 | ||
6629 | if (!part_of_multiple && t->pass_count) | |
6630 | { | |
6631 | annotate_field (10); | |
112e8700 SM |
6632 | uiout->text ("\tpass count "); |
6633 | uiout->field_int ("pass", t->pass_count); | |
6634 | uiout->text (" \n"); | |
d9b3f62e | 6635 | } |
f2a8bc8a YQ |
6636 | |
6637 | /* Don't display it when tracepoint or tracepoint location is | |
6638 | pending. */ | |
6639 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6640 | { | |
6641 | annotate_field (11); | |
6642 | ||
112e8700 SM |
6643 | if (uiout->is_mi_like_p ()) |
6644 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6645 | loc->inserted ? "y" : "n"); |
6646 | else | |
6647 | { | |
6648 | if (loc->inserted) | |
112e8700 | 6649 | uiout->text ("\t"); |
f2a8bc8a | 6650 | else |
112e8700 SM |
6651 | uiout->text ("\tnot "); |
6652 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6653 | } |
6654 | } | |
1042e4c0 SS |
6655 | } |
6656 | ||
112e8700 | 6657 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6658 | { |
3a5c3e22 PA |
6659 | if (is_watchpoint (b)) |
6660 | { | |
6661 | struct watchpoint *w = (struct watchpoint *) b; | |
6662 | ||
112e8700 | 6663 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6664 | } |
f00aae0f | 6665 | else if (b->location != NULL |
d28cd78a | 6666 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6667 | uiout->field_string ("original-location", |
d28cd78a | 6668 | event_location_to_string (b->location.get ())); |
d24317b4 | 6669 | } |
c4093a6a | 6670 | } |
c5aa993b | 6671 | |
0d381245 VP |
6672 | static void |
6673 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6674 | struct bp_location **last_loc, |
6c95b8df | 6675 | int allflag) |
0d381245 | 6676 | { |
79a45e25 | 6677 | struct ui_out *uiout = current_uiout; |
8d3788bd | 6678 | |
2e783024 TT |
6679 | { |
6680 | ui_out_emit_tuple tuple_emitter (uiout, "bkpt"); | |
8d3788bd | 6681 | |
2e783024 TT |
6682 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
6683 | } | |
0d381245 VP |
6684 | |
6685 | /* If this breakpoint has custom print function, | |
6686 | it's already printed. Otherwise, print individual | |
6687 | locations, if any. */ | |
6688 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6689 | { | |
4a64f543 MS |
6690 | /* If breakpoint has a single location that is disabled, we |
6691 | print it as if it had several locations, since otherwise it's | |
6692 | hard to represent "breakpoint enabled, location disabled" | |
6693 | situation. | |
6694 | ||
6695 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6696 | internally, that's not a property exposed to user. */ |
0d381245 | 6697 | if (b->loc |
a5606eee | 6698 | && !is_hardware_watchpoint (b) |
8d3788bd | 6699 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6700 | { |
6701 | struct bp_location *loc; | |
6702 | int n = 1; | |
8d3788bd | 6703 | |
0d381245 | 6704 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd | 6705 | { |
2e783024 | 6706 | ui_out_emit_tuple tuple_emitter (uiout, NULL); |
8d3788bd | 6707 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
8d3788bd | 6708 | } |
0d381245 VP |
6709 | } |
6710 | } | |
6711 | } | |
6712 | ||
a6d9a66e UW |
6713 | static int |
6714 | breakpoint_address_bits (struct breakpoint *b) | |
6715 | { | |
6716 | int print_address_bits = 0; | |
6717 | struct bp_location *loc; | |
6718 | ||
c6d81124 PA |
6719 | /* Software watchpoints that aren't watching memory don't have an |
6720 | address to print. */ | |
6721 | if (is_no_memory_software_watchpoint (b)) | |
6722 | return 0; | |
6723 | ||
a6d9a66e UW |
6724 | for (loc = b->loc; loc; loc = loc->next) |
6725 | { | |
c7437ca6 PA |
6726 | int addr_bit; |
6727 | ||
c7437ca6 | 6728 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6729 | if (addr_bit > print_address_bits) |
6730 | print_address_bits = addr_bit; | |
6731 | } | |
6732 | ||
6733 | return print_address_bits; | |
6734 | } | |
0d381245 | 6735 | |
c4093a6a JM |
6736 | struct captured_breakpoint_query_args |
6737 | { | |
6738 | int bnum; | |
6739 | }; | |
c5aa993b | 6740 | |
c4093a6a | 6741 | static int |
2b65245e | 6742 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6743 | { |
9a3c8263 SM |
6744 | struct captured_breakpoint_query_args *args |
6745 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6746 | struct breakpoint *b; |
a6d9a66e | 6747 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6748 | |
c4093a6a JM |
6749 | ALL_BREAKPOINTS (b) |
6750 | { | |
6751 | if (args->bnum == b->number) | |
c5aa993b | 6752 | { |
12c5a436 | 6753 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6754 | return GDB_RC_OK; |
c5aa993b | 6755 | } |
c4093a6a JM |
6756 | } |
6757 | return GDB_RC_NONE; | |
6758 | } | |
c5aa993b | 6759 | |
c4093a6a | 6760 | enum gdb_rc |
4a64f543 MS |
6761 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6762 | char **error_message) | |
c4093a6a JM |
6763 | { |
6764 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6765 | |
c4093a6a JM |
6766 | args.bnum = bnum; |
6767 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6768 | an error. */ |
b0b13bb4 DJ |
6769 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6770 | error_message, RETURN_MASK_ALL) < 0) | |
6771 | return GDB_RC_FAIL; | |
6772 | else | |
6773 | return GDB_RC_OK; | |
c4093a6a | 6774 | } |
c5aa993b | 6775 | |
09d682a4 TT |
6776 | /* Return true if this breakpoint was set by the user, false if it is |
6777 | internal or momentary. */ | |
6778 | ||
6779 | int | |
6780 | user_breakpoint_p (struct breakpoint *b) | |
6781 | { | |
46c6471b | 6782 | return b->number > 0; |
09d682a4 TT |
6783 | } |
6784 | ||
93daf339 TT |
6785 | /* See breakpoint.h. */ |
6786 | ||
6787 | int | |
6788 | pending_breakpoint_p (struct breakpoint *b) | |
6789 | { | |
6790 | return b->loc == NULL; | |
6791 | } | |
6792 | ||
7f3b0473 | 6793 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6794 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6795 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6796 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6797 | ones for which it returns non-zero. Return the total number of | |
6798 | breakpoints listed. */ | |
c906108c | 6799 | |
d77f58be | 6800 | static int |
e5a67952 | 6801 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6802 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6803 | { |
52f0bd74 | 6804 | struct breakpoint *b; |
a6d9a66e | 6805 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6806 | int nr_printable_breakpoints; |
3b31d625 | 6807 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6808 | struct value_print_options opts; |
a6d9a66e | 6809 | int print_address_bits = 0; |
269b11a2 | 6810 | int print_type_col_width = 14; |
79a45e25 | 6811 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6812 | |
79a45b7d TT |
6813 | get_user_print_options (&opts); |
6814 | ||
4a64f543 MS |
6815 | /* Compute the number of rows in the table, as well as the size |
6816 | required for address fields. */ | |
7f3b0473 AC |
6817 | nr_printable_breakpoints = 0; |
6818 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6819 | { |
6820 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6821 | if (filter && !filter (b)) | |
6822 | continue; | |
6823 | ||
6824 | /* If we have an "args" string, it is a list of breakpoints to | |
6825 | accept. Skip the others. */ | |
6826 | if (args != NULL && *args != '\0') | |
6827 | { | |
6828 | if (allflag && parse_and_eval_long (args) != b->number) | |
6829 | continue; | |
6830 | if (!allflag && !number_is_in_list (args, b->number)) | |
6831 | continue; | |
6832 | } | |
269b11a2 | 6833 | |
e5a67952 MS |
6834 | if (allflag || user_breakpoint_p (b)) |
6835 | { | |
6836 | int addr_bit, type_len; | |
a6d9a66e | 6837 | |
e5a67952 MS |
6838 | addr_bit = breakpoint_address_bits (b); |
6839 | if (addr_bit > print_address_bits) | |
6840 | print_address_bits = addr_bit; | |
269b11a2 | 6841 | |
e5a67952 MS |
6842 | type_len = strlen (bptype_string (b->type)); |
6843 | if (type_len > print_type_col_width) | |
6844 | print_type_col_width = type_len; | |
6845 | ||
6846 | nr_printable_breakpoints++; | |
6847 | } | |
6848 | } | |
7f3b0473 | 6849 | |
79a45b7d | 6850 | if (opts.addressprint) |
3b31d625 | 6851 | bkpttbl_chain |
3e43a32a MS |
6852 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6853 | nr_printable_breakpoints, | |
3b31d625 | 6854 | "BreakpointTable"); |
8b93c638 | 6855 | else |
3b31d625 | 6856 | bkpttbl_chain |
3e43a32a MS |
6857 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6858 | nr_printable_breakpoints, | |
3b31d625 | 6859 | "BreakpointTable"); |
8b93c638 | 6860 | |
7f3b0473 | 6861 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6862 | annotate_breakpoints_headers (); |
6863 | if (nr_printable_breakpoints > 0) | |
6864 | annotate_field (0); | |
112e8700 | 6865 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6866 | if (nr_printable_breakpoints > 0) |
6867 | annotate_field (1); | |
112e8700 | 6868 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6869 | if (nr_printable_breakpoints > 0) |
6870 | annotate_field (2); | |
112e8700 | 6871 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6872 | if (nr_printable_breakpoints > 0) |
6873 | annotate_field (3); | |
112e8700 | 6874 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6875 | if (opts.addressprint) |
e5a67952 MS |
6876 | { |
6877 | if (nr_printable_breakpoints > 0) | |
6878 | annotate_field (4); | |
6879 | if (print_address_bits <= 32) | |
112e8700 | 6880 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ |
e5a67952 | 6881 | else |
112e8700 | 6882 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ |
e5a67952 | 6883 | } |
d7faa9e7 AC |
6884 | if (nr_printable_breakpoints > 0) |
6885 | annotate_field (5); | |
112e8700 SM |
6886 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ |
6887 | uiout->table_body (); | |
d7faa9e7 AC |
6888 | if (nr_printable_breakpoints > 0) |
6889 | annotate_breakpoints_table (); | |
7f3b0473 | 6890 | |
c4093a6a | 6891 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6892 | { |
6893 | QUIT; | |
6894 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6895 | if (filter && !filter (b)) | |
6896 | continue; | |
6897 | ||
6898 | /* If we have an "args" string, it is a list of breakpoints to | |
6899 | accept. Skip the others. */ | |
6900 | ||
6901 | if (args != NULL && *args != '\0') | |
6902 | { | |
6903 | if (allflag) /* maintenance info breakpoint */ | |
6904 | { | |
6905 | if (parse_and_eval_long (args) != b->number) | |
6906 | continue; | |
6907 | } | |
6908 | else /* all others */ | |
6909 | { | |
6910 | if (!number_is_in_list (args, b->number)) | |
6911 | continue; | |
6912 | } | |
6913 | } | |
6914 | /* We only print out user settable breakpoints unless the | |
6915 | allflag is set. */ | |
6916 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6917 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6918 | } |
6919 | ||
3b31d625 | 6920 | do_cleanups (bkpttbl_chain); |
698384cd | 6921 | |
7f3b0473 | 6922 | if (nr_printable_breakpoints == 0) |
c906108c | 6923 | { |
4a64f543 MS |
6924 | /* If there's a filter, let the caller decide how to report |
6925 | empty list. */ | |
d77f58be SS |
6926 | if (!filter) |
6927 | { | |
e5a67952 | 6928 | if (args == NULL || *args == '\0') |
112e8700 | 6929 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6930 | else |
112e8700 | 6931 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6932 | args); |
d77f58be | 6933 | } |
c906108c SS |
6934 | } |
6935 | else | |
c4093a6a | 6936 | { |
a6d9a66e UW |
6937 | if (last_loc && !server_command) |
6938 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6939 | } |
c906108c | 6940 | |
4a64f543 | 6941 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6942 | there have been breakpoints? */ |
c906108c | 6943 | annotate_breakpoints_table_end (); |
d77f58be SS |
6944 | |
6945 | return nr_printable_breakpoints; | |
c906108c SS |
6946 | } |
6947 | ||
ad443146 SS |
6948 | /* Display the value of default-collect in a way that is generally |
6949 | compatible with the breakpoint list. */ | |
6950 | ||
6951 | static void | |
6952 | default_collect_info (void) | |
6953 | { | |
79a45e25 PA |
6954 | struct ui_out *uiout = current_uiout; |
6955 | ||
ad443146 SS |
6956 | /* If it has no value (which is frequently the case), say nothing; a |
6957 | message like "No default-collect." gets in user's face when it's | |
6958 | not wanted. */ | |
6959 | if (!*default_collect) | |
6960 | return; | |
6961 | ||
6962 | /* The following phrase lines up nicely with per-tracepoint collect | |
6963 | actions. */ | |
112e8700 SM |
6964 | uiout->text ("default collect "); |
6965 | uiout->field_string ("default-collect", default_collect); | |
6966 | uiout->text (" \n"); | |
ad443146 SS |
6967 | } |
6968 | ||
c906108c | 6969 | static void |
e5a67952 | 6970 | breakpoints_info (char *args, int from_tty) |
c906108c | 6971 | { |
e5a67952 | 6972 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6973 | |
6974 | default_collect_info (); | |
d77f58be SS |
6975 | } |
6976 | ||
6977 | static void | |
e5a67952 | 6978 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6979 | { |
e5a67952 | 6980 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6981 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6982 | |
6983 | if (num_printed == 0) | |
6984 | { | |
e5a67952 | 6985 | if (args == NULL || *args == '\0') |
112e8700 | 6986 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6987 | else |
112e8700 | 6988 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6989 | } |
c906108c SS |
6990 | } |
6991 | ||
7a292a7a | 6992 | static void |
e5a67952 | 6993 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6994 | { |
e5a67952 | 6995 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6996 | |
6997 | default_collect_info (); | |
c906108c SS |
6998 | } |
6999 | ||
0d381245 | 7000 | static int |
714835d5 | 7001 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7002 | struct program_space *pspace, |
714835d5 | 7003 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7004 | { |
7005 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7006 | |
0d381245 VP |
7007 | for (; bl; bl = bl->next) |
7008 | { | |
6c95b8df PA |
7009 | if (bl->pspace == pspace |
7010 | && bl->address == pc | |
0d381245 VP |
7011 | && (!overlay_debugging || bl->section == section)) |
7012 | return 1; | |
7013 | } | |
7014 | return 0; | |
7015 | } | |
7016 | ||
672f9b60 | 7017 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7018 | concerns with logical breakpoints, so we match program spaces, not |
7019 | address spaces. */ | |
c906108c SS |
7020 | |
7021 | static void | |
6c95b8df PA |
7022 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7023 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7024 | struct obj_section *section, int thread) |
c906108c | 7025 | { |
52f0bd74 AC |
7026 | int others = 0; |
7027 | struct breakpoint *b; | |
c906108c SS |
7028 | |
7029 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7030 | others += (user_breakpoint_p (b) |
7031 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7032 | if (others > 0) |
7033 | { | |
a3f17187 AC |
7034 | if (others == 1) |
7035 | printf_filtered (_("Note: breakpoint ")); | |
7036 | else /* if (others == ???) */ | |
7037 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7038 | ALL_BREAKPOINTS (b) |
672f9b60 | 7039 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7040 | { |
7041 | others--; | |
7042 | printf_filtered ("%d", b->number); | |
7043 | if (b->thread == -1 && thread != -1) | |
7044 | printf_filtered (" (all threads)"); | |
7045 | else if (b->thread != -1) | |
7046 | printf_filtered (" (thread %d)", b->thread); | |
7047 | printf_filtered ("%s%s ", | |
059fb39f | 7048 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7049 | || b->enable_state == bp_call_disabled) |
0d381245 | 7050 | ? " (disabled)" |
0d381245 VP |
7051 | : ""), |
7052 | (others > 1) ? "," | |
7053 | : ((others == 1) ? " and" : "")); | |
7054 | } | |
a3f17187 | 7055 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7056 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7057 | printf_filtered (".\n"); |
7058 | } | |
7059 | } | |
7060 | \f | |
c906108c | 7061 | |
e4f237da | 7062 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7063 | BPT locations. For some breakpoint types, the locations' address members |
7064 | are irrelevant and it makes no sense to attempt to compare them to other | |
7065 | addresses (or use them for any other purpose either). | |
e4f237da | 7066 | |
4a64f543 | 7067 | More specifically, each of the following breakpoint types will |
244558af | 7068 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7069 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7070 | breakpoint location at address zero: |
e4f237da KB |
7071 | |
7072 | bp_watchpoint | |
2d134ed3 PA |
7073 | bp_catchpoint |
7074 | ||
7075 | */ | |
e4f237da KB |
7076 | |
7077 | static int | |
7078 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7079 | { | |
7080 | enum bptype type = bpt->type; | |
7081 | ||
2d134ed3 PA |
7082 | return (type != bp_watchpoint && type != bp_catchpoint); |
7083 | } | |
7084 | ||
7085 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7086 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7087 | ||
7088 | static int | |
4a64f543 MS |
7089 | watchpoint_locations_match (struct bp_location *loc1, |
7090 | struct bp_location *loc2) | |
2d134ed3 | 7091 | { |
3a5c3e22 PA |
7092 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7093 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7094 | ||
7095 | /* Both of them must exist. */ | |
7096 | gdb_assert (w1 != NULL); | |
7097 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7098 | |
4a64f543 MS |
7099 | /* If the target can evaluate the condition expression in hardware, |
7100 | then we we need to insert both watchpoints even if they are at | |
7101 | the same place. Otherwise the watchpoint will only trigger when | |
7102 | the condition of whichever watchpoint was inserted evaluates to | |
7103 | true, not giving a chance for GDB to check the condition of the | |
7104 | other watchpoint. */ | |
3a5c3e22 | 7105 | if ((w1->cond_exp |
4a64f543 MS |
7106 | && target_can_accel_watchpoint_condition (loc1->address, |
7107 | loc1->length, | |
0cf6dd15 | 7108 | loc1->watchpoint_type, |
4d01a485 | 7109 | w1->cond_exp.get ())) |
3a5c3e22 | 7110 | || (w2->cond_exp |
4a64f543 MS |
7111 | && target_can_accel_watchpoint_condition (loc2->address, |
7112 | loc2->length, | |
0cf6dd15 | 7113 | loc2->watchpoint_type, |
4d01a485 | 7114 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
7115 | return 0; |
7116 | ||
85d721b8 PA |
7117 | /* Note that this checks the owner's type, not the location's. In |
7118 | case the target does not support read watchpoints, but does | |
7119 | support access watchpoints, we'll have bp_read_watchpoint | |
7120 | watchpoints with hw_access locations. Those should be considered | |
7121 | duplicates of hw_read locations. The hw_read locations will | |
7122 | become hw_access locations later. */ | |
2d134ed3 PA |
7123 | return (loc1->owner->type == loc2->owner->type |
7124 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7125 | && loc1->address == loc2->address | |
7126 | && loc1->length == loc2->length); | |
e4f237da KB |
7127 | } |
7128 | ||
31e77af2 | 7129 | /* See breakpoint.h. */ |
6c95b8df | 7130 | |
31e77af2 | 7131 | int |
6c95b8df PA |
7132 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7133 | struct address_space *aspace2, CORE_ADDR addr2) | |
7134 | { | |
f5656ead | 7135 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7136 | || aspace1 == aspace2) |
7137 | && addr1 == addr2); | |
7138 | } | |
7139 | ||
f1310107 TJB |
7140 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7141 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7142 | matches ASPACE2. On targets that have global breakpoints, the address | |
7143 | space doesn't really matter. */ | |
7144 | ||
7145 | static int | |
7146 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7147 | int len1, struct address_space *aspace2, | |
7148 | CORE_ADDR addr2) | |
7149 | { | |
f5656ead | 7150 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7151 | || aspace1 == aspace2) |
7152 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7153 | } | |
7154 | ||
7155 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7156 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7157 | matches the breakpoint's address space. On targets that have global | |
7158 | breakpoints, the address space doesn't really matter. */ | |
7159 | ||
7160 | static int | |
7161 | breakpoint_location_address_match (struct bp_location *bl, | |
7162 | struct address_space *aspace, | |
7163 | CORE_ADDR addr) | |
7164 | { | |
7165 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7166 | aspace, addr) | |
7167 | || (bl->length | |
7168 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7169 | bl->address, bl->length, | |
7170 | aspace, addr))); | |
7171 | } | |
7172 | ||
d35ae833 PA |
7173 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7174 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7175 | match happens only if ASPACE matches the breakpoint's address | |
7176 | space. On targets that have global breakpoints, the address space | |
7177 | doesn't really matter. */ | |
7178 | ||
7179 | static int | |
7180 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7181 | struct address_space *aspace, | |
7182 | CORE_ADDR addr, int len) | |
7183 | { | |
7184 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7185 | || bl->pspace->aspace == aspace) | |
7186 | { | |
7187 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7188 | ||
7189 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7190 | return 1; | |
7191 | } | |
7192 | return 0; | |
7193 | } | |
7194 | ||
1e4d1764 YQ |
7195 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7196 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7197 | true, otherwise returns false. */ | |
7198 | ||
7199 | static int | |
7200 | tracepoint_locations_match (struct bp_location *loc1, | |
7201 | struct bp_location *loc2) | |
7202 | { | |
7203 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7204 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7205 | locations at the same address of different tracepoints are regarded as | |
7206 | different locations. */ | |
7207 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7208 | else | |
7209 | return 0; | |
7210 | } | |
7211 | ||
2d134ed3 PA |
7212 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7213 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7214 | represent the same location. */ | |
7215 | ||
7216 | static int | |
4a64f543 MS |
7217 | breakpoint_locations_match (struct bp_location *loc1, |
7218 | struct bp_location *loc2) | |
2d134ed3 | 7219 | { |
2bdf28a0 JK |
7220 | int hw_point1, hw_point2; |
7221 | ||
7222 | /* Both of them must not be in moribund_locations. */ | |
7223 | gdb_assert (loc1->owner != NULL); | |
7224 | gdb_assert (loc2->owner != NULL); | |
7225 | ||
7226 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7227 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7228 | |
7229 | if (hw_point1 != hw_point2) | |
7230 | return 0; | |
7231 | else if (hw_point1) | |
7232 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7233 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7234 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7235 | else |
f1310107 TJB |
7236 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7237 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7238 | loc2->pspace->aspace, loc2->address) | |
7239 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7240 | } |
7241 | ||
76897487 KB |
7242 | static void |
7243 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7244 | int bnum, int have_bnum) | |
7245 | { | |
f63fbe86 MS |
7246 | /* The longest string possibly returned by hex_string_custom |
7247 | is 50 chars. These must be at least that big for safety. */ | |
7248 | char astr1[64]; | |
7249 | char astr2[64]; | |
76897487 | 7250 | |
bb599908 PH |
7251 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7252 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7253 | if (have_bnum) |
8a3fe4f8 | 7254 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7255 | bnum, astr1, astr2); |
7256 | else | |
8a3fe4f8 | 7257 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7258 | } |
7259 | ||
4a64f543 MS |
7260 | /* Adjust a breakpoint's address to account for architectural |
7261 | constraints on breakpoint placement. Return the adjusted address. | |
7262 | Note: Very few targets require this kind of adjustment. For most | |
7263 | targets, this function is simply the identity function. */ | |
76897487 KB |
7264 | |
7265 | static CORE_ADDR | |
a6d9a66e UW |
7266 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7267 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7268 | { |
a6d9a66e | 7269 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7270 | { |
7271 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7272 | return bpaddr; | |
7273 | } | |
88f7da05 KB |
7274 | else if (bptype == bp_watchpoint |
7275 | || bptype == bp_hardware_watchpoint | |
7276 | || bptype == bp_read_watchpoint | |
7277 | || bptype == bp_access_watchpoint | |
fe798b75 | 7278 | || bptype == bp_catchpoint) |
88f7da05 KB |
7279 | { |
7280 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7281 | have their addresses modified. */ | |
7282 | return bpaddr; | |
7283 | } | |
7c16b83e PA |
7284 | else if (bptype == bp_single_step) |
7285 | { | |
7286 | /* Single-step breakpoints should not have their addresses | |
7287 | modified. If there's any architectural constrain that | |
7288 | applies to this address, then it should have already been | |
7289 | taken into account when the breakpoint was created in the | |
7290 | first place. If we didn't do this, stepping through e.g., | |
7291 | Thumb-2 IT blocks would break. */ | |
7292 | return bpaddr; | |
7293 | } | |
76897487 KB |
7294 | else |
7295 | { | |
7296 | CORE_ADDR adjusted_bpaddr; | |
7297 | ||
7298 | /* Some targets have architectural constraints on the placement | |
7299 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7300 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7301 | |
7302 | /* An adjusted breakpoint address can significantly alter | |
7303 | a user's expectations. Print a warning if an adjustment | |
7304 | is required. */ | |
7305 | if (adjusted_bpaddr != bpaddr) | |
7306 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7307 | ||
7308 | return adjusted_bpaddr; | |
7309 | } | |
7310 | } | |
7311 | ||
5625a286 | 7312 | bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner) |
7cc221ef | 7313 | { |
5625a286 | 7314 | bp_location *loc = this; |
7cc221ef | 7315 | |
348d480f PA |
7316 | gdb_assert (ops != NULL); |
7317 | ||
28010a5d PA |
7318 | loc->ops = ops; |
7319 | loc->owner = owner; | |
b775012e | 7320 | loc->cond_bytecode = NULL; |
0d381245 VP |
7321 | loc->shlib_disabled = 0; |
7322 | loc->enabled = 1; | |
e049a4b5 | 7323 | |
28010a5d | 7324 | switch (owner->type) |
e049a4b5 DJ |
7325 | { |
7326 | case bp_breakpoint: | |
7c16b83e | 7327 | case bp_single_step: |
e049a4b5 DJ |
7328 | case bp_until: |
7329 | case bp_finish: | |
7330 | case bp_longjmp: | |
7331 | case bp_longjmp_resume: | |
e2e4d78b | 7332 | case bp_longjmp_call_dummy: |
186c406b TT |
7333 | case bp_exception: |
7334 | case bp_exception_resume: | |
e049a4b5 | 7335 | case bp_step_resume: |
2c03e5be | 7336 | case bp_hp_step_resume: |
e049a4b5 DJ |
7337 | case bp_watchpoint_scope: |
7338 | case bp_call_dummy: | |
aa7d318d | 7339 | case bp_std_terminate: |
e049a4b5 DJ |
7340 | case bp_shlib_event: |
7341 | case bp_thread_event: | |
7342 | case bp_overlay_event: | |
4efc6507 | 7343 | case bp_jit_event: |
0fd8e87f | 7344 | case bp_longjmp_master: |
aa7d318d | 7345 | case bp_std_terminate_master: |
186c406b | 7346 | case bp_exception_master: |
0e30163f JK |
7347 | case bp_gnu_ifunc_resolver: |
7348 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7349 | case bp_dprintf: |
e049a4b5 | 7350 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7351 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7352 | break; |
7353 | case bp_hardware_breakpoint: | |
7354 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7355 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7356 | break; |
7357 | case bp_hardware_watchpoint: | |
7358 | case bp_read_watchpoint: | |
7359 | case bp_access_watchpoint: | |
7360 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7361 | break; | |
7362 | case bp_watchpoint: | |
ce78b96d | 7363 | case bp_catchpoint: |
15c3d785 PA |
7364 | case bp_tracepoint: |
7365 | case bp_fast_tracepoint: | |
0fb4aa4b | 7366 | case bp_static_tracepoint: |
e049a4b5 DJ |
7367 | loc->loc_type = bp_loc_other; |
7368 | break; | |
7369 | default: | |
e2e0b3e5 | 7370 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7371 | } |
7372 | ||
f431efe5 | 7373 | loc->refc = 1; |
28010a5d PA |
7374 | } |
7375 | ||
7376 | /* Allocate a struct bp_location. */ | |
7377 | ||
7378 | static struct bp_location * | |
7379 | allocate_bp_location (struct breakpoint *bpt) | |
7380 | { | |
348d480f PA |
7381 | return bpt->ops->allocate_location (bpt); |
7382 | } | |
7cc221ef | 7383 | |
f431efe5 PA |
7384 | static void |
7385 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7386 | { |
348d480f | 7387 | loc->ops->dtor (loc); |
4d01a485 | 7388 | delete loc; |
fe3f5fa8 VP |
7389 | } |
7390 | ||
f431efe5 PA |
7391 | /* Increment reference count. */ |
7392 | ||
7393 | static void | |
7394 | incref_bp_location (struct bp_location *bl) | |
7395 | { | |
7396 | ++bl->refc; | |
7397 | } | |
7398 | ||
7399 | /* Decrement reference count. If the reference count reaches 0, | |
7400 | destroy the bp_location. Sets *BLP to NULL. */ | |
7401 | ||
7402 | static void | |
7403 | decref_bp_location (struct bp_location **blp) | |
7404 | { | |
0807b50c PA |
7405 | gdb_assert ((*blp)->refc > 0); |
7406 | ||
f431efe5 PA |
7407 | if (--(*blp)->refc == 0) |
7408 | free_bp_location (*blp); | |
7409 | *blp = NULL; | |
7410 | } | |
7411 | ||
346774a9 | 7412 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7413 | |
346774a9 PA |
7414 | static void |
7415 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7416 | { |
346774a9 | 7417 | struct breakpoint *b1; |
c906108c | 7418 | |
346774a9 PA |
7419 | /* Add this breakpoint to the end of the chain so that a list of |
7420 | breakpoints will come out in order of increasing numbers. */ | |
7421 | ||
7422 | b1 = breakpoint_chain; | |
7423 | if (b1 == 0) | |
7424 | breakpoint_chain = b; | |
7425 | else | |
7426 | { | |
7427 | while (b1->next) | |
7428 | b1 = b1->next; | |
7429 | b1->next = b; | |
7430 | } | |
7431 | } | |
7432 | ||
7433 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7434 | ||
7435 | static void | |
7436 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7437 | struct gdbarch *gdbarch, | |
28010a5d | 7438 | enum bptype bptype, |
c0a91b2b | 7439 | const struct breakpoint_ops *ops) |
346774a9 | 7440 | { |
348d480f PA |
7441 | gdb_assert (ops != NULL); |
7442 | ||
28010a5d | 7443 | b->ops = ops; |
4d28f7a8 | 7444 | b->type = bptype; |
a6d9a66e | 7445 | b->gdbarch = gdbarch; |
c906108c SS |
7446 | b->language = current_language->la_language; |
7447 | b->input_radix = input_radix; | |
d0fb5eae | 7448 | b->related_breakpoint = b; |
346774a9 PA |
7449 | } |
7450 | ||
7451 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7452 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7453 | |
7454 | static struct breakpoint * | |
7455 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7456 | enum bptype bptype, |
c0a91b2b | 7457 | const struct breakpoint_ops *ops) |
346774a9 | 7458 | { |
3b0871f4 | 7459 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7460 | |
3b0871f4 SM |
7461 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
7462 | add_to_breakpoint_chain (b.get ()); | |
7463 | ||
7464 | return b.release (); | |
0d381245 VP |
7465 | } |
7466 | ||
0e30163f JK |
7467 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7468 | resolutions should be made as the user specified the location explicitly | |
7469 | enough. */ | |
7470 | ||
0d381245 | 7471 | static void |
0e30163f | 7472 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7473 | { |
2bdf28a0 JK |
7474 | gdb_assert (loc->owner != NULL); |
7475 | ||
0d381245 | 7476 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7477 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7478 | || is_tracepoint (loc->owner)) |
0d381245 | 7479 | { |
0e30163f | 7480 | int is_gnu_ifunc; |
2c02bd72 | 7481 | const char *function_name; |
6a3a010b | 7482 | CORE_ADDR func_addr; |
0e30163f | 7483 | |
2c02bd72 | 7484 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7485 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7486 | |
7487 | if (is_gnu_ifunc && !explicit_loc) | |
7488 | { | |
7489 | struct breakpoint *b = loc->owner; | |
7490 | ||
7491 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7492 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7493 | &loc->requested_address)) |
7494 | { | |
7495 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7496 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7497 | loc->requested_address, | |
7498 | b->type); | |
7499 | } | |
7500 | else if (b->type == bp_breakpoint && b->loc == loc | |
7501 | && loc->next == NULL && b->related_breakpoint == b) | |
7502 | { | |
7503 | /* Create only the whole new breakpoint of this type but do not | |
7504 | mess more complicated breakpoints with multiple locations. */ | |
7505 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7506 | /* Remember the resolver's address for use by the return |
7507 | breakpoint. */ | |
7508 | loc->related_address = func_addr; | |
0e30163f JK |
7509 | } |
7510 | } | |
7511 | ||
2c02bd72 DE |
7512 | if (function_name) |
7513 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7514 | } |
7515 | } | |
7516 | ||
a6d9a66e | 7517 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7518 | struct gdbarch * |
a6d9a66e UW |
7519 | get_sal_arch (struct symtab_and_line sal) |
7520 | { | |
7521 | if (sal.section) | |
7522 | return get_objfile_arch (sal.section->objfile); | |
7523 | if (sal.symtab) | |
eb822aa6 | 7524 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7525 | |
7526 | return NULL; | |
7527 | } | |
7528 | ||
346774a9 PA |
7529 | /* Low level routine for partially initializing a breakpoint of type |
7530 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7531 | file name, and line number are provided by SAL. |
0d381245 VP |
7532 | |
7533 | It is expected that the caller will complete the initialization of | |
7534 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7535 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7536 | |
346774a9 PA |
7537 | static void |
7538 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7539 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7540 | const struct breakpoint_ops *ops) |
0d381245 | 7541 | { |
28010a5d | 7542 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7543 | |
3742cc8b | 7544 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7545 | |
6c95b8df PA |
7546 | if (bptype != bp_catchpoint) |
7547 | gdb_assert (sal.pspace != NULL); | |
7548 | ||
f8eba3c6 TT |
7549 | /* Store the program space that was used to set the breakpoint, |
7550 | except for ordinary breakpoints, which are independent of the | |
7551 | program space. */ | |
7552 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7553 | b->pspace = sal.pspace; | |
346774a9 | 7554 | } |
c906108c | 7555 | |
346774a9 PA |
7556 | /* set_raw_breakpoint is a low level routine for allocating and |
7557 | partially initializing a breakpoint of type BPTYPE. The newly | |
7558 | created breakpoint's address, section, source file name, and line | |
7559 | number are provided by SAL. The newly created and partially | |
7560 | initialized breakpoint is added to the breakpoint chain and | |
7561 | is also returned as the value of this function. | |
7562 | ||
7563 | It is expected that the caller will complete the initialization of | |
7564 | the newly created breakpoint struct as well as output any status | |
7565 | information regarding the creation of a new breakpoint. In | |
7566 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7567 | number! Care should be taken to not allow an error to occur | |
7568 | prior to completing the initialization of the breakpoint. If this | |
7569 | should happen, a bogus breakpoint will be left on the chain. */ | |
7570 | ||
7571 | struct breakpoint * | |
7572 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7573 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7574 | const struct breakpoint_ops *ops) |
346774a9 | 7575 | { |
3b0871f4 | 7576 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7577 | |
3b0871f4 SM |
7578 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
7579 | add_to_breakpoint_chain (b.get ()); | |
7580 | ||
7581 | return b.release (); | |
c906108c SS |
7582 | } |
7583 | ||
53a5351d | 7584 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7585 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7586 | initiated the operation. */ | |
c906108c SS |
7587 | |
7588 | void | |
186c406b | 7589 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7590 | { |
35df4500 | 7591 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7592 | int thread = tp->global_num; |
0fd8e87f UW |
7593 | |
7594 | /* To avoid having to rescan all objfile symbols at every step, | |
7595 | we maintain a list of continually-inserted but always disabled | |
7596 | longjmp "master" breakpoints. Here, we simply create momentary | |
7597 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7598 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7599 | if (b->pspace == current_program_space |
186c406b TT |
7600 | && (b->type == bp_longjmp_master |
7601 | || b->type == bp_exception_master)) | |
0fd8e87f | 7602 | { |
06edf0c0 PA |
7603 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7604 | struct breakpoint *clone; | |
cc59ec59 | 7605 | |
e2e4d78b JK |
7606 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7607 | after their removal. */ | |
06edf0c0 | 7608 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7609 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7610 | clone->thread = thread; |
7611 | } | |
186c406b TT |
7612 | |
7613 | tp->initiating_frame = frame; | |
c906108c SS |
7614 | } |
7615 | ||
611c83ae | 7616 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7617 | void |
611c83ae | 7618 | delete_longjmp_breakpoint (int thread) |
c906108c | 7619 | { |
35df4500 | 7620 | struct breakpoint *b, *b_tmp; |
c906108c | 7621 | |
35df4500 | 7622 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7623 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7624 | { |
7625 | if (b->thread == thread) | |
7626 | delete_breakpoint (b); | |
7627 | } | |
c906108c SS |
7628 | } |
7629 | ||
f59f708a PA |
7630 | void |
7631 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7632 | { | |
7633 | struct breakpoint *b, *b_tmp; | |
7634 | ||
7635 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7636 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7637 | { | |
7638 | if (b->thread == thread) | |
7639 | b->disposition = disp_del_at_next_stop; | |
7640 | } | |
7641 | } | |
7642 | ||
e2e4d78b JK |
7643 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7644 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7645 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7646 | breakpoints. */ | |
7647 | ||
7648 | struct breakpoint * | |
7649 | set_longjmp_breakpoint_for_call_dummy (void) | |
7650 | { | |
7651 | struct breakpoint *b, *retval = NULL; | |
7652 | ||
7653 | ALL_BREAKPOINTS (b) | |
7654 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7655 | { | |
7656 | struct breakpoint *new_b; | |
7657 | ||
7658 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7659 | &momentary_breakpoint_ops, |
7660 | 1); | |
5d5658a1 | 7661 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7662 | |
7663 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7664 | ||
7665 | gdb_assert (new_b->related_breakpoint == new_b); | |
7666 | if (retval == NULL) | |
7667 | retval = new_b; | |
7668 | new_b->related_breakpoint = retval; | |
7669 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7670 | retval = retval->related_breakpoint; | |
7671 | retval->related_breakpoint = new_b; | |
7672 | } | |
7673 | ||
7674 | return retval; | |
7675 | } | |
7676 | ||
7677 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7678 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7679 | stack. |
7680 | ||
7681 | You should call this function only at places where it is safe to currently | |
7682 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7683 | frames. */ | |
7684 | ||
7685 | void | |
b67a2c6f | 7686 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7687 | { |
7688 | struct breakpoint *b, *b_tmp; | |
7689 | ||
7690 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7691 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7692 | { |
7693 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7694 | ||
7695 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7696 | dummy_b = dummy_b->related_breakpoint; | |
7697 | if (dummy_b->type != bp_call_dummy | |
7698 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7699 | continue; | |
7700 | ||
b67a2c6f | 7701 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7702 | |
7703 | while (b->related_breakpoint != b) | |
7704 | { | |
7705 | if (b_tmp == b->related_breakpoint) | |
7706 | b_tmp = b->related_breakpoint->next; | |
7707 | delete_breakpoint (b->related_breakpoint); | |
7708 | } | |
7709 | delete_breakpoint (b); | |
7710 | } | |
7711 | } | |
7712 | ||
1900040c MS |
7713 | void |
7714 | enable_overlay_breakpoints (void) | |
7715 | { | |
52f0bd74 | 7716 | struct breakpoint *b; |
1900040c MS |
7717 | |
7718 | ALL_BREAKPOINTS (b) | |
7719 | if (b->type == bp_overlay_event) | |
7720 | { | |
7721 | b->enable_state = bp_enabled; | |
44702360 | 7722 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7723 | overlay_events_enabled = 1; |
1900040c MS |
7724 | } |
7725 | } | |
7726 | ||
7727 | void | |
7728 | disable_overlay_breakpoints (void) | |
7729 | { | |
52f0bd74 | 7730 | struct breakpoint *b; |
1900040c MS |
7731 | |
7732 | ALL_BREAKPOINTS (b) | |
7733 | if (b->type == bp_overlay_event) | |
7734 | { | |
7735 | b->enable_state = bp_disabled; | |
44702360 | 7736 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7737 | overlay_events_enabled = 0; |
1900040c MS |
7738 | } |
7739 | } | |
7740 | ||
aa7d318d TT |
7741 | /* Set an active std::terminate breakpoint for each std::terminate |
7742 | master breakpoint. */ | |
7743 | void | |
7744 | set_std_terminate_breakpoint (void) | |
7745 | { | |
35df4500 | 7746 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7747 | |
35df4500 | 7748 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7749 | if (b->pspace == current_program_space |
7750 | && b->type == bp_std_terminate_master) | |
7751 | { | |
06edf0c0 | 7752 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7753 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7754 | } |
7755 | } | |
7756 | ||
7757 | /* Delete all the std::terminate breakpoints. */ | |
7758 | void | |
7759 | delete_std_terminate_breakpoint (void) | |
7760 | { | |
35df4500 | 7761 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7762 | |
35df4500 | 7763 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7764 | if (b->type == bp_std_terminate) |
7765 | delete_breakpoint (b); | |
7766 | } | |
7767 | ||
c4093a6a | 7768 | struct breakpoint * |
a6d9a66e | 7769 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7770 | { |
7771 | struct breakpoint *b; | |
c4093a6a | 7772 | |
06edf0c0 PA |
7773 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7774 | &internal_breakpoint_ops); | |
7775 | ||
b5de0fa7 | 7776 | b->enable_state = bp_enabled; |
f00aae0f | 7777 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7778 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7779 | |
44702360 | 7780 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7781 | |
c4093a6a JM |
7782 | return b; |
7783 | } | |
7784 | ||
0101ce28 JJ |
7785 | struct lang_and_radix |
7786 | { | |
7787 | enum language lang; | |
7788 | int radix; | |
7789 | }; | |
7790 | ||
4efc6507 DE |
7791 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7792 | ||
7793 | struct breakpoint * | |
7794 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7795 | { | |
2a7f3dff PA |
7796 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7797 | &internal_breakpoint_ops); | |
4efc6507 | 7798 | } |
0101ce28 | 7799 | |
03673fc7 PP |
7800 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7801 | ||
7802 | void | |
7803 | remove_jit_event_breakpoints (void) | |
7804 | { | |
7805 | struct breakpoint *b, *b_tmp; | |
7806 | ||
7807 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7808 | if (b->type == bp_jit_event | |
7809 | && b->loc->pspace == current_program_space) | |
7810 | delete_breakpoint (b); | |
7811 | } | |
7812 | ||
cae688ec JJ |
7813 | void |
7814 | remove_solib_event_breakpoints (void) | |
7815 | { | |
35df4500 | 7816 | struct breakpoint *b, *b_tmp; |
cae688ec | 7817 | |
35df4500 | 7818 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7819 | if (b->type == bp_shlib_event |
7820 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7821 | delete_breakpoint (b); |
7822 | } | |
7823 | ||
f37f681c PA |
7824 | /* See breakpoint.h. */ |
7825 | ||
7826 | void | |
7827 | remove_solib_event_breakpoints_at_next_stop (void) | |
7828 | { | |
7829 | struct breakpoint *b, *b_tmp; | |
7830 | ||
7831 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7832 | if (b->type == bp_shlib_event | |
7833 | && b->loc->pspace == current_program_space) | |
7834 | b->disposition = disp_del_at_next_stop; | |
7835 | } | |
7836 | ||
04086b45 PA |
7837 | /* Helper for create_solib_event_breakpoint / |
7838 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7839 | INSERT_MODE to pass through to update_global_location_list. */ | |
7840 | ||
7841 | static struct breakpoint * | |
7842 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7843 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7844 | { |
7845 | struct breakpoint *b; | |
7846 | ||
06edf0c0 PA |
7847 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7848 | &internal_breakpoint_ops); | |
04086b45 | 7849 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7850 | return b; |
7851 | } | |
7852 | ||
04086b45 PA |
7853 | struct breakpoint * |
7854 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7855 | { | |
7856 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7857 | } | |
7858 | ||
f37f681c PA |
7859 | /* See breakpoint.h. */ |
7860 | ||
7861 | struct breakpoint * | |
7862 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7863 | { | |
7864 | struct breakpoint *b; | |
7865 | ||
04086b45 PA |
7866 | /* Explicitly tell update_global_location_list to insert |
7867 | locations. */ | |
7868 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7869 | if (!b->loc->inserted) |
7870 | { | |
7871 | delete_breakpoint (b); | |
7872 | return NULL; | |
7873 | } | |
7874 | return b; | |
7875 | } | |
7876 | ||
cae688ec JJ |
7877 | /* Disable any breakpoints that are on code in shared libraries. Only |
7878 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7879 | ||
7880 | void | |
cb851954 | 7881 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7882 | { |
876fa593 | 7883 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7884 | |
876fa593 | 7885 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7886 | { |
2bdf28a0 | 7887 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7888 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7889 | |
4a64f543 MS |
7890 | /* We apply the check to all breakpoints, including disabled for |
7891 | those with loc->duplicate set. This is so that when breakpoint | |
7892 | becomes enabled, or the duplicate is removed, gdb will try to | |
7893 | insert all breakpoints. If we don't set shlib_disabled here, | |
7894 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7895 | if (((b->type == bp_breakpoint) |
508ccb1f | 7896 | || (b->type == bp_jit_event) |
1042e4c0 | 7897 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7898 | || (is_tracepoint (b))) |
6c95b8df | 7899 | && loc->pspace == current_program_space |
0d381245 | 7900 | && !loc->shlib_disabled |
6c95b8df | 7901 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7902 | ) |
0d381245 VP |
7903 | { |
7904 | loc->shlib_disabled = 1; | |
7905 | } | |
cae688ec JJ |
7906 | } |
7907 | } | |
7908 | ||
63644780 NB |
7909 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7910 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7911 | disabled ones can just stay disabled. */ | |
84acb35a | 7912 | |
75149521 | 7913 | static void |
84acb35a JJ |
7914 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7915 | { | |
876fa593 | 7916 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7917 | int disabled_shlib_breaks = 0; |
7918 | ||
876fa593 | 7919 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7920 | { |
2bdf28a0 | 7921 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7922 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7923 | |
1e4d1764 | 7924 | if (solib->pspace == loc->pspace |
e2dd7057 | 7925 | && !loc->shlib_disabled |
1e4d1764 YQ |
7926 | && (((b->type == bp_breakpoint |
7927 | || b->type == bp_jit_event | |
7928 | || b->type == bp_hardware_breakpoint) | |
7929 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7930 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7931 | || is_tracepoint (b)) | |
e2dd7057 | 7932 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7933 | { |
e2dd7057 PP |
7934 | loc->shlib_disabled = 1; |
7935 | /* At this point, we cannot rely on remove_breakpoint | |
7936 | succeeding so we must mark the breakpoint as not inserted | |
7937 | to prevent future errors occurring in remove_breakpoints. */ | |
7938 | loc->inserted = 0; | |
8d3788bd VP |
7939 | |
7940 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7941 | observer_notify_breakpoint_modified (b); | |
7942 | ||
e2dd7057 PP |
7943 | if (!disabled_shlib_breaks) |
7944 | { | |
7945 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7946 | warning (_("Temporarily disabling breakpoints " |
7947 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7948 | solib->so_name); |
84acb35a | 7949 | } |
e2dd7057 | 7950 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7951 | } |
7952 | } | |
84acb35a JJ |
7953 | } |
7954 | ||
63644780 NB |
7955 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7956 | notification of free_objfile. Only apply to enabled breakpoints, | |
7957 | disabled ones can just stay disabled. */ | |
7958 | ||
7959 | static void | |
7960 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7961 | { | |
7962 | struct breakpoint *b; | |
7963 | ||
7964 | if (objfile == NULL) | |
7965 | return; | |
7966 | ||
d03de421 PA |
7967 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7968 | managed by the user with add-symbol-file/remove-symbol-file. | |
7969 | Similarly to how breakpoints in shared libraries are handled in | |
7970 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7971 | shlib_disabled so they end up uninserted on the next global |
7972 | location list update. Shared libraries not loaded by the user | |
7973 | aren't handled here -- they're already handled in | |
7974 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7975 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7976 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7977 | main objfile). */ | |
7978 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7979 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7980 | return; |
7981 | ||
7982 | ALL_BREAKPOINTS (b) | |
7983 | { | |
7984 | struct bp_location *loc; | |
7985 | int bp_modified = 0; | |
7986 | ||
7987 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7988 | continue; | |
7989 | ||
7990 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7991 | { | |
7992 | CORE_ADDR loc_addr = loc->address; | |
7993 | ||
7994 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7995 | && loc->loc_type != bp_loc_software_breakpoint) | |
7996 | continue; | |
7997 | ||
7998 | if (loc->shlib_disabled != 0) | |
7999 | continue; | |
8000 | ||
8001 | if (objfile->pspace != loc->pspace) | |
8002 | continue; | |
8003 | ||
8004 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8005 | && loc->loc_type != bp_loc_software_breakpoint) | |
8006 | continue; | |
8007 | ||
8008 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8009 | { | |
8010 | loc->shlib_disabled = 1; | |
08351840 PA |
8011 | /* At this point, we don't know whether the object was |
8012 | unmapped from the inferior or not, so leave the | |
8013 | inserted flag alone. We'll handle failure to | |
8014 | uninsert quietly, in case the object was indeed | |
8015 | unmapped. */ | |
63644780 NB |
8016 | |
8017 | mark_breakpoint_location_modified (loc); | |
8018 | ||
8019 | bp_modified = 1; | |
8020 | } | |
8021 | } | |
8022 | ||
8023 | if (bp_modified) | |
8024 | observer_notify_breakpoint_modified (b); | |
8025 | } | |
8026 | } | |
8027 | ||
ce78b96d JB |
8028 | /* FORK & VFORK catchpoints. */ |
8029 | ||
e29a4733 | 8030 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
8031 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
8032 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 8033 | |
c1fc2657 | 8034 | struct fork_catchpoint : public breakpoint |
e29a4733 | 8035 | { |
e29a4733 PA |
8036 | /* Process id of a child process whose forking triggered this |
8037 | catchpoint. This field is only valid immediately after this | |
8038 | catchpoint has triggered. */ | |
8039 | ptid_t forked_inferior_pid; | |
8040 | }; | |
8041 | ||
4a64f543 MS |
8042 | /* Implement the "insert" breakpoint_ops method for fork |
8043 | catchpoints. */ | |
ce78b96d | 8044 | |
77b06cd7 TJB |
8045 | static int |
8046 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8047 | { |
dfd4cc63 | 8048 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8049 | } |
8050 | ||
4a64f543 MS |
8051 | /* Implement the "remove" breakpoint_ops method for fork |
8052 | catchpoints. */ | |
ce78b96d JB |
8053 | |
8054 | static int | |
73971819 | 8055 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8056 | { |
dfd4cc63 | 8057 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8058 | } |
8059 | ||
8060 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8061 | catchpoints. */ | |
8062 | ||
8063 | static int | |
f1310107 | 8064 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8065 | struct address_space *aspace, CORE_ADDR bp_addr, |
8066 | const struct target_waitstatus *ws) | |
ce78b96d | 8067 | { |
e29a4733 PA |
8068 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8069 | ||
f90263c1 TT |
8070 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8071 | return 0; | |
8072 | ||
8073 | c->forked_inferior_pid = ws->value.related_pid; | |
8074 | return 1; | |
ce78b96d JB |
8075 | } |
8076 | ||
4a64f543 MS |
8077 | /* Implement the "print_it" breakpoint_ops method for fork |
8078 | catchpoints. */ | |
ce78b96d JB |
8079 | |
8080 | static enum print_stop_action | |
348d480f | 8081 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8082 | { |
36dfb11c | 8083 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8084 | struct breakpoint *b = bs->breakpoint_at; |
8085 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8086 | |
ce78b96d | 8087 | annotate_catchpoint (b->number); |
f303dbd6 | 8088 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8089 | if (b->disposition == disp_del) |
112e8700 | 8090 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8091 | else |
112e8700 SM |
8092 | uiout->text ("Catchpoint "); |
8093 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8094 | { |
112e8700 SM |
8095 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
8096 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8097 | } |
112e8700 SM |
8098 | uiout->field_int ("bkptno", b->number); |
8099 | uiout->text (" (forked process "); | |
8100 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8101 | uiout->text ("), "); | |
ce78b96d JB |
8102 | return PRINT_SRC_AND_LOC; |
8103 | } | |
8104 | ||
4a64f543 MS |
8105 | /* Implement the "print_one" breakpoint_ops method for fork |
8106 | catchpoints. */ | |
ce78b96d JB |
8107 | |
8108 | static void | |
a6d9a66e | 8109 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8110 | { |
e29a4733 | 8111 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8112 | struct value_print_options opts; |
79a45e25 | 8113 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8114 | |
8115 | get_user_print_options (&opts); | |
8116 | ||
4a64f543 MS |
8117 | /* Field 4, the address, is omitted (which makes the columns not |
8118 | line up too nicely with the headers, but the effect is relatively | |
8119 | readable). */ | |
79a45b7d | 8120 | if (opts.addressprint) |
112e8700 | 8121 | uiout->field_skip ("addr"); |
ce78b96d | 8122 | annotate_field (5); |
112e8700 | 8123 | uiout->text ("fork"); |
e29a4733 | 8124 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8125 | { |
112e8700 SM |
8126 | uiout->text (", process "); |
8127 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8128 | uiout->spaces (1); | |
ce78b96d | 8129 | } |
8ac3646f | 8130 | |
112e8700 SM |
8131 | if (uiout->is_mi_like_p ()) |
8132 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
8133 | } |
8134 | ||
8135 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8136 | catchpoints. */ | |
8137 | ||
8138 | static void | |
8139 | print_mention_catch_fork (struct breakpoint *b) | |
8140 | { | |
8141 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8142 | } | |
8143 | ||
6149aea9 PA |
8144 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8145 | catchpoints. */ | |
8146 | ||
8147 | static void | |
8148 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8149 | { | |
8150 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8151 | print_recreate_thread (b, fp); |
6149aea9 PA |
8152 | } |
8153 | ||
ce78b96d JB |
8154 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8155 | ||
2060206e | 8156 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8157 | |
4a64f543 MS |
8158 | /* Implement the "insert" breakpoint_ops method for vfork |
8159 | catchpoints. */ | |
ce78b96d | 8160 | |
77b06cd7 TJB |
8161 | static int |
8162 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8163 | { |
dfd4cc63 | 8164 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8165 | } |
8166 | ||
4a64f543 MS |
8167 | /* Implement the "remove" breakpoint_ops method for vfork |
8168 | catchpoints. */ | |
ce78b96d JB |
8169 | |
8170 | static int | |
73971819 | 8171 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8172 | { |
dfd4cc63 | 8173 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8174 | } |
8175 | ||
8176 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8177 | catchpoints. */ | |
8178 | ||
8179 | static int | |
f1310107 | 8180 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8181 | struct address_space *aspace, CORE_ADDR bp_addr, |
8182 | const struct target_waitstatus *ws) | |
ce78b96d | 8183 | { |
e29a4733 PA |
8184 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8185 | ||
f90263c1 TT |
8186 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8187 | return 0; | |
8188 | ||
8189 | c->forked_inferior_pid = ws->value.related_pid; | |
8190 | return 1; | |
ce78b96d JB |
8191 | } |
8192 | ||
4a64f543 MS |
8193 | /* Implement the "print_it" breakpoint_ops method for vfork |
8194 | catchpoints. */ | |
ce78b96d JB |
8195 | |
8196 | static enum print_stop_action | |
348d480f | 8197 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8198 | { |
36dfb11c | 8199 | struct ui_out *uiout = current_uiout; |
348d480f | 8200 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8201 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8202 | ||
ce78b96d | 8203 | annotate_catchpoint (b->number); |
f303dbd6 | 8204 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8205 | if (b->disposition == disp_del) |
112e8700 | 8206 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8207 | else |
112e8700 SM |
8208 | uiout->text ("Catchpoint "); |
8209 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8210 | { |
112e8700 SM |
8211 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
8212 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8213 | } |
112e8700 SM |
8214 | uiout->field_int ("bkptno", b->number); |
8215 | uiout->text (" (vforked process "); | |
8216 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8217 | uiout->text ("), "); | |
ce78b96d JB |
8218 | return PRINT_SRC_AND_LOC; |
8219 | } | |
8220 | ||
4a64f543 MS |
8221 | /* Implement the "print_one" breakpoint_ops method for vfork |
8222 | catchpoints. */ | |
ce78b96d JB |
8223 | |
8224 | static void | |
a6d9a66e | 8225 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8226 | { |
e29a4733 | 8227 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8228 | struct value_print_options opts; |
79a45e25 | 8229 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8230 | |
8231 | get_user_print_options (&opts); | |
4a64f543 MS |
8232 | /* Field 4, the address, is omitted (which makes the columns not |
8233 | line up too nicely with the headers, but the effect is relatively | |
8234 | readable). */ | |
79a45b7d | 8235 | if (opts.addressprint) |
112e8700 | 8236 | uiout->field_skip ("addr"); |
ce78b96d | 8237 | annotate_field (5); |
112e8700 | 8238 | uiout->text ("vfork"); |
e29a4733 | 8239 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8240 | { |
112e8700 SM |
8241 | uiout->text (", process "); |
8242 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8243 | uiout->spaces (1); | |
ce78b96d | 8244 | } |
8ac3646f | 8245 | |
112e8700 SM |
8246 | if (uiout->is_mi_like_p ()) |
8247 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
8248 | } |
8249 | ||
8250 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8251 | catchpoints. */ | |
8252 | ||
8253 | static void | |
8254 | print_mention_catch_vfork (struct breakpoint *b) | |
8255 | { | |
8256 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8257 | } | |
8258 | ||
6149aea9 PA |
8259 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8260 | catchpoints. */ | |
8261 | ||
8262 | static void | |
8263 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8264 | { | |
8265 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8266 | print_recreate_thread (b, fp); |
6149aea9 PA |
8267 | } |
8268 | ||
ce78b96d JB |
8269 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8270 | ||
2060206e | 8271 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8272 | |
edcc5120 | 8273 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 8274 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
8275 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
8276 | ||
c1fc2657 | 8277 | struct solib_catchpoint : public breakpoint |
edcc5120 | 8278 | { |
c1fc2657 | 8279 | ~solib_catchpoint () override; |
edcc5120 TT |
8280 | |
8281 | /* True for "catch load", false for "catch unload". */ | |
8282 | unsigned char is_load; | |
8283 | ||
8284 | /* Regular expression to match, if any. COMPILED is only valid when | |
8285 | REGEX is non-NULL. */ | |
8286 | char *regex; | |
8287 | regex_t compiled; | |
8288 | }; | |
8289 | ||
c1fc2657 | 8290 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 8291 | { |
c1fc2657 SM |
8292 | if (this->regex) |
8293 | regfree (&this->compiled); | |
8294 | xfree (this->regex); | |
edcc5120 TT |
8295 | } |
8296 | ||
8297 | static int | |
8298 | insert_catch_solib (struct bp_location *ignore) | |
8299 | { | |
8300 | return 0; | |
8301 | } | |
8302 | ||
8303 | static int | |
73971819 | 8304 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8305 | { |
8306 | return 0; | |
8307 | } | |
8308 | ||
8309 | static int | |
8310 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8311 | struct address_space *aspace, | |
8312 | CORE_ADDR bp_addr, | |
8313 | const struct target_waitstatus *ws) | |
8314 | { | |
8315 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8316 | struct breakpoint *other; | |
8317 | ||
8318 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8319 | return 1; | |
8320 | ||
8321 | ALL_BREAKPOINTS (other) | |
8322 | { | |
8323 | struct bp_location *other_bl; | |
8324 | ||
8325 | if (other == bl->owner) | |
8326 | continue; | |
8327 | ||
8328 | if (other->type != bp_shlib_event) | |
8329 | continue; | |
8330 | ||
c1fc2657 | 8331 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
8332 | continue; |
8333 | ||
8334 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8335 | { | |
8336 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8337 | return 1; | |
8338 | } | |
8339 | } | |
8340 | ||
8341 | return 0; | |
8342 | } | |
8343 | ||
8344 | static void | |
8345 | check_status_catch_solib (struct bpstats *bs) | |
8346 | { | |
8347 | struct solib_catchpoint *self | |
8348 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8349 | int ix; | |
8350 | ||
8351 | if (self->is_load) | |
8352 | { | |
8353 | struct so_list *iter; | |
8354 | ||
8355 | for (ix = 0; | |
8356 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8357 | ix, iter); | |
8358 | ++ix) | |
8359 | { | |
8360 | if (!self->regex | |
8361 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8362 | return; | |
8363 | } | |
8364 | } | |
8365 | else | |
8366 | { | |
8367 | char *iter; | |
8368 | ||
8369 | for (ix = 0; | |
8370 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8371 | ix, iter); | |
8372 | ++ix) | |
8373 | { | |
8374 | if (!self->regex | |
8375 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8376 | return; | |
8377 | } | |
8378 | } | |
8379 | ||
8380 | bs->stop = 0; | |
8381 | bs->print_it = print_it_noop; | |
8382 | } | |
8383 | ||
8384 | static enum print_stop_action | |
8385 | print_it_catch_solib (bpstat bs) | |
8386 | { | |
8387 | struct breakpoint *b = bs->breakpoint_at; | |
8388 | struct ui_out *uiout = current_uiout; | |
8389 | ||
8390 | annotate_catchpoint (b->number); | |
f303dbd6 | 8391 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8392 | if (b->disposition == disp_del) |
112e8700 | 8393 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8394 | else |
112e8700 SM |
8395 | uiout->text ("Catchpoint "); |
8396 | uiout->field_int ("bkptno", b->number); | |
8397 | uiout->text ("\n"); | |
8398 | if (uiout->is_mi_like_p ()) | |
8399 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8400 | print_solib_event (1); |
8401 | return PRINT_SRC_AND_LOC; | |
8402 | } | |
8403 | ||
8404 | static void | |
8405 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8406 | { | |
8407 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8408 | struct value_print_options opts; | |
8409 | struct ui_out *uiout = current_uiout; | |
8410 | char *msg; | |
8411 | ||
8412 | get_user_print_options (&opts); | |
8413 | /* Field 4, the address, is omitted (which makes the columns not | |
8414 | line up too nicely with the headers, but the effect is relatively | |
8415 | readable). */ | |
8416 | if (opts.addressprint) | |
8417 | { | |
8418 | annotate_field (4); | |
112e8700 | 8419 | uiout->field_skip ("addr"); |
edcc5120 TT |
8420 | } |
8421 | ||
8422 | annotate_field (5); | |
8423 | if (self->is_load) | |
8424 | { | |
8425 | if (self->regex) | |
8426 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8427 | else | |
8428 | msg = xstrdup (_("load of library")); | |
8429 | } | |
8430 | else | |
8431 | { | |
8432 | if (self->regex) | |
8433 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8434 | else | |
8435 | msg = xstrdup (_("unload of library")); | |
8436 | } | |
112e8700 | 8437 | uiout->field_string ("what", msg); |
edcc5120 | 8438 | xfree (msg); |
8ac3646f | 8439 | |
112e8700 SM |
8440 | if (uiout->is_mi_like_p ()) |
8441 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8442 | } |
8443 | ||
8444 | static void | |
8445 | print_mention_catch_solib (struct breakpoint *b) | |
8446 | { | |
8447 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8448 | ||
8449 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8450 | self->is_load ? "load" : "unload"); | |
8451 | } | |
8452 | ||
8453 | static void | |
8454 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8455 | { | |
8456 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8457 | ||
8458 | fprintf_unfiltered (fp, "%s %s", | |
8459 | b->disposition == disp_del ? "tcatch" : "catch", | |
8460 | self->is_load ? "load" : "unload"); | |
8461 | if (self->regex) | |
8462 | fprintf_unfiltered (fp, " %s", self->regex); | |
8463 | fprintf_unfiltered (fp, "\n"); | |
8464 | } | |
8465 | ||
8466 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8467 | ||
91985142 MG |
8468 | /* Shared helper function (MI and CLI) for creating and installing |
8469 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8470 | the events to be caught are load events, otherwise they are | |
8471 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8472 | temporary one. If ENABLED is non-zero the catchpoint is | |
8473 | created in an enabled state. */ | |
edcc5120 | 8474 | |
91985142 | 8475 | void |
a121b7c1 | 8476 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 TT |
8477 | { |
8478 | struct solib_catchpoint *c; | |
8479 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8480 | struct cleanup *cleanup; |
8481 | ||
edcc5120 TT |
8482 | if (!arg) |
8483 | arg = ""; | |
a121b7c1 | 8484 | arg = skip_spaces_const (arg); |
edcc5120 | 8485 | |
4d01a485 | 8486 | c = new solib_catchpoint (); |
edcc5120 TT |
8487 | cleanup = make_cleanup (xfree, c); |
8488 | ||
8489 | if (*arg != '\0') | |
8490 | { | |
8491 | int errcode; | |
8492 | ||
8493 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8494 | if (errcode != 0) | |
8495 | { | |
8496 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8497 | ||
8498 | make_cleanup (xfree, err); | |
8499 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8500 | } | |
8501 | c->regex = xstrdup (arg); | |
8502 | } | |
8503 | ||
8504 | c->is_load = is_load; | |
c1fc2657 | 8505 | init_catchpoint (c, gdbarch, is_temp, NULL, |
edcc5120 TT |
8506 | &catch_solib_breakpoint_ops); |
8507 | ||
c1fc2657 | 8508 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8509 | |
edcc5120 | 8510 | discard_cleanups (cleanup); |
c1fc2657 | 8511 | install_breakpoint (0, c, 1); |
edcc5120 TT |
8512 | } |
8513 | ||
91985142 MG |
8514 | /* A helper function that does all the work for "catch load" and |
8515 | "catch unload". */ | |
8516 | ||
8517 | static void | |
8518 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8519 | struct cmd_list_element *command) | |
8520 | { | |
8521 | int tempflag; | |
8522 | const int enabled = 1; | |
8523 | ||
8524 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8525 | ||
8526 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8527 | } | |
8528 | ||
edcc5120 TT |
8529 | static void |
8530 | catch_load_command_1 (char *arg, int from_tty, | |
8531 | struct cmd_list_element *command) | |
8532 | { | |
8533 | catch_load_or_unload (arg, from_tty, 1, command); | |
8534 | } | |
8535 | ||
8536 | static void | |
8537 | catch_unload_command_1 (char *arg, int from_tty, | |
8538 | struct cmd_list_element *command) | |
8539 | { | |
8540 | catch_load_or_unload (arg, from_tty, 0, command); | |
8541 | } | |
8542 | ||
346774a9 PA |
8543 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8544 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8545 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8546 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8547 | |
ab04a2af | 8548 | void |
346774a9 PA |
8549 | init_catchpoint (struct breakpoint *b, |
8550 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8551 | const char *cond_string, |
c0a91b2b | 8552 | const struct breakpoint_ops *ops) |
c906108c | 8553 | { |
c5aa993b | 8554 | struct symtab_and_line sal; |
346774a9 | 8555 | |
fe39c653 | 8556 | init_sal (&sal); |
6c95b8df | 8557 | sal.pspace = current_program_space; |
c5aa993b | 8558 | |
28010a5d | 8559 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8560 | |
1b36a34b | 8561 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8562 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8563 | } |
8564 | ||
28010a5d | 8565 | void |
3ea46bff | 8566 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8567 | { |
8568 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8569 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8570 | if (is_tracepoint (b)) |
8571 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8572 | if (!internal) |
8573 | mention (b); | |
c56053d2 | 8574 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8575 | |
8576 | if (update_gll) | |
44702360 | 8577 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8578 | } |
8579 | ||
9b70b993 | 8580 | static void |
a6d9a66e | 8581 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8582 | int tempflag, const char *cond_string, |
c0a91b2b | 8583 | const struct breakpoint_ops *ops) |
c906108c | 8584 | { |
4d01a485 | 8585 | struct fork_catchpoint *c = new fork_catchpoint (); |
ce78b96d | 8586 | |
c1fc2657 | 8587 | init_catchpoint (c, gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8588 | |
8589 | c->forked_inferior_pid = null_ptid; | |
8590 | ||
c1fc2657 | 8591 | install_breakpoint (0, c, 1); |
c906108c SS |
8592 | } |
8593 | ||
fe798b75 JB |
8594 | /* Exec catchpoints. */ |
8595 | ||
b4d90040 | 8596 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8597 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8598 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8599 | ||
c1fc2657 | 8600 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8601 | { |
c1fc2657 | 8602 | ~exec_catchpoint () override; |
b4d90040 PA |
8603 | |
8604 | /* Filename of a program whose exec triggered this catchpoint. | |
8605 | This field is only valid immediately after this catchpoint has | |
8606 | triggered. */ | |
8607 | char *exec_pathname; | |
8608 | }; | |
8609 | ||
c1fc2657 | 8610 | /* Exec catchpoint destructor. */ |
b4d90040 | 8611 | |
c1fc2657 | 8612 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8613 | { |
c1fc2657 | 8614 | xfree (this->exec_pathname); |
b4d90040 PA |
8615 | } |
8616 | ||
77b06cd7 TJB |
8617 | static int |
8618 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8619 | { |
dfd4cc63 | 8620 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8621 | } |
c906108c | 8622 | |
fe798b75 | 8623 | static int |
73971819 | 8624 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8625 | { |
dfd4cc63 | 8626 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8627 | } |
c906108c | 8628 | |
fe798b75 | 8629 | static int |
f1310107 | 8630 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8631 | struct address_space *aspace, CORE_ADDR bp_addr, |
8632 | const struct target_waitstatus *ws) | |
fe798b75 | 8633 | { |
b4d90040 PA |
8634 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8635 | ||
f90263c1 TT |
8636 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8637 | return 0; | |
8638 | ||
8639 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8640 | return 1; | |
fe798b75 | 8641 | } |
c906108c | 8642 | |
fe798b75 | 8643 | static enum print_stop_action |
348d480f | 8644 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8645 | { |
36dfb11c | 8646 | struct ui_out *uiout = current_uiout; |
348d480f | 8647 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8648 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8649 | ||
fe798b75 | 8650 | annotate_catchpoint (b->number); |
f303dbd6 | 8651 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8652 | if (b->disposition == disp_del) |
112e8700 | 8653 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8654 | else |
112e8700 SM |
8655 | uiout->text ("Catchpoint "); |
8656 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8657 | { |
112e8700 SM |
8658 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8659 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8660 | } |
112e8700 SM |
8661 | uiout->field_int ("bkptno", b->number); |
8662 | uiout->text (" (exec'd "); | |
8663 | uiout->field_string ("new-exec", c->exec_pathname); | |
8664 | uiout->text ("), "); | |
36dfb11c | 8665 | |
fe798b75 | 8666 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8667 | } |
8668 | ||
fe798b75 | 8669 | static void |
a6d9a66e | 8670 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8671 | { |
b4d90040 | 8672 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8673 | struct value_print_options opts; |
79a45e25 | 8674 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8675 | |
8676 | get_user_print_options (&opts); | |
8677 | ||
8678 | /* Field 4, the address, is omitted (which makes the columns | |
8679 | not line up too nicely with the headers, but the effect | |
8680 | is relatively readable). */ | |
8681 | if (opts.addressprint) | |
112e8700 | 8682 | uiout->field_skip ("addr"); |
fe798b75 | 8683 | annotate_field (5); |
112e8700 | 8684 | uiout->text ("exec"); |
b4d90040 | 8685 | if (c->exec_pathname != NULL) |
fe798b75 | 8686 | { |
112e8700 SM |
8687 | uiout->text (", program \""); |
8688 | uiout->field_string ("what", c->exec_pathname); | |
8689 | uiout->text ("\" "); | |
fe798b75 | 8690 | } |
8ac3646f | 8691 | |
112e8700 SM |
8692 | if (uiout->is_mi_like_p ()) |
8693 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8694 | } |
8695 | ||
8696 | static void | |
8697 | print_mention_catch_exec (struct breakpoint *b) | |
8698 | { | |
8699 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8700 | } | |
8701 | ||
6149aea9 PA |
8702 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8703 | catchpoints. */ | |
8704 | ||
8705 | static void | |
8706 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8707 | { | |
8708 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8709 | print_recreate_thread (b, fp); |
6149aea9 PA |
8710 | } |
8711 | ||
2060206e | 8712 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8713 | |
c906108c | 8714 | static int |
fba45db2 | 8715 | hw_breakpoint_used_count (void) |
c906108c | 8716 | { |
c906108c | 8717 | int i = 0; |
f1310107 TJB |
8718 | struct breakpoint *b; |
8719 | struct bp_location *bl; | |
c906108c SS |
8720 | |
8721 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8722 | { |
d6b74ac4 | 8723 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8724 | for (bl = b->loc; bl; bl = bl->next) |
8725 | { | |
8726 | /* Special types of hardware breakpoints may use more than | |
8727 | one register. */ | |
348d480f | 8728 | i += b->ops->resources_needed (bl); |
f1310107 | 8729 | } |
c5aa993b | 8730 | } |
c906108c SS |
8731 | |
8732 | return i; | |
8733 | } | |
8734 | ||
a1398e0c PA |
8735 | /* Returns the resources B would use if it were a hardware |
8736 | watchpoint. */ | |
8737 | ||
c906108c | 8738 | static int |
a1398e0c | 8739 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8740 | { |
c906108c | 8741 | int i = 0; |
e09342b5 | 8742 | struct bp_location *bl; |
c906108c | 8743 | |
a1398e0c PA |
8744 | if (!breakpoint_enabled (b)) |
8745 | return 0; | |
8746 | ||
8747 | for (bl = b->loc; bl; bl = bl->next) | |
8748 | { | |
8749 | /* Special types of hardware watchpoints may use more than | |
8750 | one register. */ | |
8751 | i += b->ops->resources_needed (bl); | |
8752 | } | |
8753 | ||
8754 | return i; | |
8755 | } | |
8756 | ||
8757 | /* Returns the sum the used resources of all hardware watchpoints of | |
8758 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8759 | the sum of the used resources of all hardware watchpoints of other | |
8760 | types _not_ TYPE. */ | |
8761 | ||
8762 | static int | |
8763 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8764 | enum bptype type, int *other_type_used) | |
8765 | { | |
8766 | int i = 0; | |
8767 | struct breakpoint *b; | |
8768 | ||
c906108c SS |
8769 | *other_type_used = 0; |
8770 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8771 | { |
a1398e0c PA |
8772 | if (b == except) |
8773 | continue; | |
e09342b5 TJB |
8774 | if (!breakpoint_enabled (b)) |
8775 | continue; | |
8776 | ||
a1398e0c PA |
8777 | if (b->type == type) |
8778 | i += hw_watchpoint_use_count (b); | |
8779 | else if (is_hardware_watchpoint (b)) | |
8780 | *other_type_used = 1; | |
e09342b5 TJB |
8781 | } |
8782 | ||
c906108c SS |
8783 | return i; |
8784 | } | |
8785 | ||
c906108c | 8786 | void |
fba45db2 | 8787 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8788 | { |
c5aa993b | 8789 | struct breakpoint *b; |
c906108c SS |
8790 | |
8791 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8792 | { |
cc60f2e3 | 8793 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8794 | { |
b5de0fa7 | 8795 | b->enable_state = bp_call_disabled; |
44702360 | 8796 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8797 | } |
8798 | } | |
c906108c SS |
8799 | } |
8800 | ||
8801 | void | |
fba45db2 | 8802 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8803 | { |
c5aa993b | 8804 | struct breakpoint *b; |
c906108c SS |
8805 | |
8806 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8807 | { |
cc60f2e3 | 8808 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8809 | { |
b5de0fa7 | 8810 | b->enable_state = bp_enabled; |
44702360 | 8811 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8812 | } |
8813 | } | |
c906108c SS |
8814 | } |
8815 | ||
8bea4e01 UW |
8816 | void |
8817 | disable_breakpoints_before_startup (void) | |
8818 | { | |
6c95b8df | 8819 | current_program_space->executing_startup = 1; |
44702360 | 8820 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8821 | } |
8822 | ||
8823 | void | |
8824 | enable_breakpoints_after_startup (void) | |
8825 | { | |
6c95b8df | 8826 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8827 | breakpoint_re_set (); |
8bea4e01 UW |
8828 | } |
8829 | ||
7c16b83e PA |
8830 | /* Create a new single-step breakpoint for thread THREAD, with no |
8831 | locations. */ | |
c906108c | 8832 | |
7c16b83e PA |
8833 | static struct breakpoint * |
8834 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8835 | { | |
4d01a485 | 8836 | struct breakpoint *b = new breakpoint (); |
7c16b83e PA |
8837 | |
8838 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8839 | &momentary_breakpoint_ops); | |
8840 | ||
8841 | b->disposition = disp_donttouch; | |
8842 | b->frame_id = null_frame_id; | |
8843 | ||
8844 | b->thread = thread; | |
8845 | gdb_assert (b->thread != 0); | |
8846 | ||
8847 | add_to_breakpoint_chain (b); | |
8848 | ||
8849 | return b; | |
8850 | } | |
8851 | ||
8852 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8853 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8854 | frame. */ | |
c906108c SS |
8855 | |
8856 | struct breakpoint * | |
a6d9a66e UW |
8857 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8858 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8859 | { |
52f0bd74 | 8860 | struct breakpoint *b; |
edb3359d | 8861 | |
193facb3 JK |
8862 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8863 | tail-called one. */ | |
8864 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8865 | |
06edf0c0 | 8866 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8867 | b->enable_state = bp_enabled; |
8868 | b->disposition = disp_donttouch; | |
818dd999 | 8869 | b->frame_id = frame_id; |
c906108c | 8870 | |
4a64f543 MS |
8871 | /* If we're debugging a multi-threaded program, then we want |
8872 | momentary breakpoints to be active in only a single thread of | |
8873 | control. */ | |
39f77062 | 8874 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8875 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8876 | |
44702360 | 8877 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8878 | |
c906108c SS |
8879 | return b; |
8880 | } | |
611c83ae | 8881 | |
06edf0c0 | 8882 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8883 | The new breakpoint will have type TYPE, use OPS as its |
8884 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8885 | |
06edf0c0 PA |
8886 | static struct breakpoint * |
8887 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8888 | enum bptype type, | |
a1aa2221 LM |
8889 | const struct breakpoint_ops *ops, |
8890 | int loc_enabled) | |
e58b0e63 PA |
8891 | { |
8892 | struct breakpoint *copy; | |
8893 | ||
06edf0c0 | 8894 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8895 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8896 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8897 | |
a6d9a66e | 8898 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8899 | copy->loc->requested_address = orig->loc->requested_address; |
8900 | copy->loc->address = orig->loc->address; | |
8901 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8902 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8903 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8904 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8905 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8906 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8907 | copy->frame_id = orig->frame_id; |
8908 | copy->thread = orig->thread; | |
6c95b8df | 8909 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8910 | |
8911 | copy->enable_state = bp_enabled; | |
8912 | copy->disposition = disp_donttouch; | |
8913 | copy->number = internal_breakpoint_number--; | |
8914 | ||
44702360 | 8915 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8916 | return copy; |
8917 | } | |
8918 | ||
06edf0c0 PA |
8919 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8920 | ORIG is NULL. */ | |
8921 | ||
8922 | struct breakpoint * | |
8923 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8924 | { | |
8925 | /* If there's nothing to clone, then return nothing. */ | |
8926 | if (orig == NULL) | |
8927 | return NULL; | |
8928 | ||
a1aa2221 | 8929 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8930 | } |
8931 | ||
611c83ae | 8932 | struct breakpoint * |
a6d9a66e UW |
8933 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8934 | enum bptype type) | |
611c83ae PA |
8935 | { |
8936 | struct symtab_and_line sal; | |
8937 | ||
8938 | sal = find_pc_line (pc, 0); | |
8939 | sal.pc = pc; | |
8940 | sal.section = find_pc_overlay (pc); | |
8941 | sal.explicit_pc = 1; | |
8942 | ||
a6d9a66e | 8943 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8944 | } |
c906108c | 8945 | \f |
c5aa993b | 8946 | |
c906108c SS |
8947 | /* Tell the user we have just set a breakpoint B. */ |
8948 | ||
8949 | static void | |
fba45db2 | 8950 | mention (struct breakpoint *b) |
c906108c | 8951 | { |
348d480f | 8952 | b->ops->print_mention (b); |
112e8700 | 8953 | if (current_uiout->is_mi_like_p ()) |
fb40c209 | 8954 | return; |
c906108c SS |
8955 | printf_filtered ("\n"); |
8956 | } | |
c906108c | 8957 | \f |
c5aa993b | 8958 | |
1a853c52 PA |
8959 | static int bp_loc_is_permanent (struct bp_location *loc); |
8960 | ||
0d381245 | 8961 | static struct bp_location * |
39d61571 | 8962 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8963 | const struct symtab_and_line *sal) |
8964 | { | |
8965 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8966 | CORE_ADDR adjusted_address; |
8967 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8968 | ||
8969 | if (loc_gdbarch == NULL) | |
8970 | loc_gdbarch = b->gdbarch; | |
8971 | ||
8972 | /* Adjust the breakpoint's address prior to allocating a location. | |
8973 | Once we call allocate_bp_location(), that mostly uninitialized | |
8974 | location will be placed on the location chain. Adjustment of the | |
8975 | breakpoint may cause target_read_memory() to be called and we do | |
8976 | not want its scan of the location chain to find a breakpoint and | |
8977 | location that's only been partially initialized. */ | |
8978 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8979 | sal->pc, b->type); | |
0d381245 | 8980 | |
d30113d4 | 8981 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8982 | loc = allocate_bp_location (b); |
d30113d4 JK |
8983 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8984 | tmp = &((*tmp)->next)) | |
0d381245 | 8985 | ; |
d30113d4 | 8986 | loc->next = *tmp; |
0d381245 | 8987 | *tmp = loc; |
3742cc8b | 8988 | |
0d381245 | 8989 | loc->requested_address = sal->pc; |
3742cc8b | 8990 | loc->address = adjusted_address; |
6c95b8df | 8991 | loc->pspace = sal->pspace; |
729662a5 TT |
8992 | loc->probe.probe = sal->probe; |
8993 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 8994 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8995 | loc->section = sal->section; |
3742cc8b | 8996 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8997 | loc->line_number = sal->line; |
2f202fde | 8998 | loc->symtab = sal->symtab; |
f8eba3c6 | 8999 | |
0e30163f JK |
9000 | set_breakpoint_location_function (loc, |
9001 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9002 | |
6ae88661 LM |
9003 | /* While by definition, permanent breakpoints are already present in the |
9004 | code, we don't mark the location as inserted. Normally one would expect | |
9005 | that GDB could rely on that breakpoint instruction to stop the program, | |
9006 | thus removing the need to insert its own breakpoint, except that executing | |
9007 | the breakpoint instruction can kill the target instead of reporting a | |
9008 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9009 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9010 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9011 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9012 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9013 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9014 | it manually increments the PC, thus avoiding executing the breakpoint | |
9015 | instruction.) */ | |
1a853c52 | 9016 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9017 | loc->permanent = 1; |
1a853c52 | 9018 | |
0d381245 VP |
9019 | return loc; |
9020 | } | |
514f746b AR |
9021 | \f |
9022 | ||
1cf4d951 | 9023 | /* See breakpoint.h. */ |
514f746b | 9024 | |
1cf4d951 PA |
9025 | int |
9026 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9027 | { |
9028 | int len; | |
9029 | CORE_ADDR addr; | |
1afeeb75 | 9030 | const gdb_byte *bpoint; |
514f746b | 9031 | gdb_byte *target_mem; |
939c61fa JK |
9032 | struct cleanup *cleanup; |
9033 | int retval = 0; | |
514f746b | 9034 | |
1cf4d951 PA |
9035 | addr = address; |
9036 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9037 | ||
9038 | /* Software breakpoints unsupported? */ | |
9039 | if (bpoint == NULL) | |
9040 | return 0; | |
9041 | ||
224c3ddb | 9042 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9043 | |
9044 | /* Enable the automatic memory restoration from breakpoints while | |
9045 | we read the memory. Otherwise we could say about our temporary | |
9046 | breakpoints they are permanent. */ | |
9047 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9048 | ||
9049 | if (target_read_memory (address, target_mem, len) == 0 | |
9050 | && memcmp (target_mem, bpoint, len) == 0) | |
9051 | retval = 1; | |
9052 | ||
9053 | do_cleanups (cleanup); | |
9054 | ||
9055 | return retval; | |
9056 | } | |
9057 | ||
9058 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9059 | return 0 otherwise. */ | |
9060 | ||
9061 | static int | |
9062 | bp_loc_is_permanent (struct bp_location *loc) | |
9063 | { | |
514f746b AR |
9064 | gdb_assert (loc != NULL); |
9065 | ||
244558af LM |
9066 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9067 | attempt to read from the addresses the locations of these breakpoint types | |
9068 | point to. program_breakpoint_here_p, below, will attempt to read | |
9069 | memory. */ | |
9070 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9071 | return 0; | |
9072 | ||
5ed8105e | 9073 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9074 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 9075 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
9076 | } |
9077 | ||
e7e0cddf SS |
9078 | /* Build a command list for the dprintf corresponding to the current |
9079 | settings of the dprintf style options. */ | |
9080 | ||
9081 | static void | |
9082 | update_dprintf_command_list (struct breakpoint *b) | |
9083 | { | |
9084 | char *dprintf_args = b->extra_string; | |
9085 | char *printf_line = NULL; | |
9086 | ||
9087 | if (!dprintf_args) | |
9088 | return; | |
9089 | ||
9090 | dprintf_args = skip_spaces (dprintf_args); | |
9091 | ||
9092 | /* Allow a comma, as it may have terminated a location, but don't | |
9093 | insist on it. */ | |
9094 | if (*dprintf_args == ',') | |
9095 | ++dprintf_args; | |
9096 | dprintf_args = skip_spaces (dprintf_args); | |
9097 | ||
9098 | if (*dprintf_args != '"') | |
9099 | error (_("Bad format string, missing '\"'.")); | |
9100 | ||
d3ce09f5 | 9101 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9102 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9103 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9104 | { |
9105 | if (!dprintf_function) | |
9106 | error (_("No function supplied for dprintf call")); | |
9107 | ||
9108 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9109 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9110 | dprintf_function, | |
9111 | dprintf_channel, | |
9112 | dprintf_args); | |
9113 | else | |
9114 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9115 | dprintf_function, | |
9116 | dprintf_args); | |
9117 | } | |
d3ce09f5 SS |
9118 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9119 | { | |
9120 | if (target_can_run_breakpoint_commands ()) | |
9121 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9122 | else | |
9123 | { | |
9124 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9125 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9126 | } | |
9127 | } | |
e7e0cddf SS |
9128 | else |
9129 | internal_error (__FILE__, __LINE__, | |
9130 | _("Invalid dprintf style.")); | |
9131 | ||
f28045c2 | 9132 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9133 | /* Manufacture a printf sequence. */ |
f28045c2 | 9134 | { |
8d749320 | 9135 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9136 | |
f28045c2 YQ |
9137 | printf_cmd_line->control_type = simple_control; |
9138 | printf_cmd_line->body_count = 0; | |
9139 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9140 | printf_cmd_line->next = NULL; |
f28045c2 | 9141 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9142 | |
93921405 | 9143 | breakpoint_set_commands (b, command_line_up (printf_cmd_line)); |
f28045c2 | 9144 | } |
e7e0cddf SS |
9145 | } |
9146 | ||
9147 | /* Update all dprintf commands, making their command lists reflect | |
9148 | current style settings. */ | |
9149 | ||
9150 | static void | |
9151 | update_dprintf_commands (char *args, int from_tty, | |
9152 | struct cmd_list_element *c) | |
9153 | { | |
9154 | struct breakpoint *b; | |
9155 | ||
9156 | ALL_BREAKPOINTS (b) | |
9157 | { | |
9158 | if (b->type == bp_dprintf) | |
9159 | update_dprintf_command_list (b); | |
9160 | } | |
9161 | } | |
c3f6f71d | 9162 | |
f00aae0f KS |
9163 | /* Create a breakpoint with SAL as location. Use LOCATION |
9164 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9165 | as condition expression. If LOCATION is NULL then create an |
9166 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9167 | |
9168 | static void | |
d9b3f62e | 9169 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f | 9170 | struct symtabs_and_lines sals, |
ffc2605c | 9171 | event_location_up &&location, |
e1e01040 PA |
9172 | gdb::unique_xmalloc_ptr<char> filter, |
9173 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9174 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9175 | enum bptype type, enum bpdisp disposition, |
9176 | int thread, int task, int ignore_count, | |
c0a91b2b | 9177 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9178 | int enabled, int internal, unsigned flags, |
9179 | int display_canonical) | |
018d34a4 | 9180 | { |
0d381245 | 9181 | int i; |
018d34a4 VP |
9182 | |
9183 | if (type == bp_hardware_breakpoint) | |
9184 | { | |
fbbd034e AS |
9185 | int target_resources_ok; |
9186 | ||
9187 | i = hw_breakpoint_used_count (); | |
9188 | target_resources_ok = | |
9189 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9190 | i + 1, 0); |
9191 | if (target_resources_ok == 0) | |
9192 | error (_("No hardware breakpoint support in the target.")); | |
9193 | else if (target_resources_ok < 0) | |
9194 | error (_("Hardware breakpoints used exceeds limit.")); | |
9195 | } | |
9196 | ||
6c95b8df PA |
9197 | gdb_assert (sals.nelts > 0); |
9198 | ||
0d381245 VP |
9199 | for (i = 0; i < sals.nelts; ++i) |
9200 | { | |
9201 | struct symtab_and_line sal = sals.sals[i]; | |
9202 | struct bp_location *loc; | |
9203 | ||
9204 | if (from_tty) | |
5af949e3 UW |
9205 | { |
9206 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9207 | if (!loc_gdbarch) | |
9208 | loc_gdbarch = gdbarch; | |
9209 | ||
9210 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9211 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9212 | } |
0d381245 VP |
9213 | |
9214 | if (i == 0) | |
9215 | { | |
d9b3f62e | 9216 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9217 | b->thread = thread; |
4a306c9a | 9218 | b->task = task; |
855a6e68 | 9219 | |
e1e01040 PA |
9220 | b->cond_string = cond_string.release (); |
9221 | b->extra_string = extra_string.release (); | |
0d381245 | 9222 | b->ignore_count = ignore_count; |
41447f92 | 9223 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9224 | b->disposition = disposition; |
6c95b8df | 9225 | |
44f238bb PA |
9226 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9227 | b->loc->inserted = 1; | |
9228 | ||
0fb4aa4b PA |
9229 | if (type == bp_static_tracepoint) |
9230 | { | |
d9b3f62e | 9231 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9232 | struct static_tracepoint_marker marker; |
9233 | ||
983af33b | 9234 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9235 | { |
9236 | /* We already know the marker exists, otherwise, we | |
9237 | wouldn't see a sal for it. */ | |
d28cd78a TT |
9238 | const char *p |
9239 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 9240 | const char *endp; |
0fb4aa4b | 9241 | char *marker_str; |
0fb4aa4b | 9242 | |
f00aae0f | 9243 | p = skip_spaces_const (p); |
0fb4aa4b | 9244 | |
f00aae0f | 9245 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9246 | |
9247 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9248 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9249 | |
3e43a32a MS |
9250 | printf_filtered (_("Probed static tracepoint " |
9251 | "marker \"%s\"\n"), | |
d9b3f62e | 9252 | t->static_trace_marker_id); |
0fb4aa4b PA |
9253 | } |
9254 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9255 | { | |
d9b3f62e | 9256 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9257 | release_static_tracepoint_marker (&marker); |
9258 | ||
3e43a32a MS |
9259 | printf_filtered (_("Probed static tracepoint " |
9260 | "marker \"%s\"\n"), | |
d9b3f62e | 9261 | t->static_trace_marker_id); |
0fb4aa4b PA |
9262 | } |
9263 | else | |
3e43a32a MS |
9264 | warning (_("Couldn't determine the static " |
9265 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9266 | } |
9267 | ||
0d381245 VP |
9268 | loc = b->loc; |
9269 | } | |
9270 | else | |
018d34a4 | 9271 | { |
39d61571 | 9272 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9273 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9274 | loc->inserted = 1; | |
0d381245 VP |
9275 | } |
9276 | ||
9277 | if (b->cond_string) | |
9278 | { | |
bbc13ae3 KS |
9279 | const char *arg = b->cond_string; |
9280 | ||
1bb9788d TT |
9281 | loc->cond = parse_exp_1 (&arg, loc->address, |
9282 | block_for_pc (loc->address), 0); | |
0d381245 | 9283 | if (*arg) |
588ae58c | 9284 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9285 | } |
e7e0cddf SS |
9286 | |
9287 | /* Dynamic printf requires and uses additional arguments on the | |
9288 | command line, otherwise it's an error. */ | |
9289 | if (type == bp_dprintf) | |
9290 | { | |
9291 | if (b->extra_string) | |
9292 | update_dprintf_command_list (b); | |
9293 | else | |
9294 | error (_("Format string required")); | |
9295 | } | |
9296 | else if (b->extra_string) | |
588ae58c | 9297 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9298 | } |
018d34a4 | 9299 | |
56435ebe | 9300 | b->display_canonical = display_canonical; |
f00aae0f | 9301 | if (location != NULL) |
d28cd78a | 9302 | b->location = std::move (location); |
018d34a4 | 9303 | else |
d28cd78a | 9304 | b->location = new_address_location (b->loc->address, NULL, 0); |
e1e01040 | 9305 | b->filter = filter.release (); |
d9b3f62e | 9306 | } |
018d34a4 | 9307 | |
d9b3f62e PA |
9308 | static void |
9309 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f | 9310 | struct symtabs_and_lines sals, |
ffc2605c | 9311 | event_location_up &&location, |
e1e01040 PA |
9312 | gdb::unique_xmalloc_ptr<char> filter, |
9313 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9314 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9315 | enum bptype type, enum bpdisp disposition, |
9316 | int thread, int task, int ignore_count, | |
c0a91b2b | 9317 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9318 | int enabled, int internal, unsigned flags, |
9319 | int display_canonical) | |
d9b3f62e | 9320 | { |
a5e364af | 9321 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 9322 | |
a5e364af | 9323 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 9324 | sals, std::move (location), |
e1e01040 PA |
9325 | std::move (filter), |
9326 | std::move (cond_string), | |
9327 | std::move (extra_string), | |
d9b3f62e PA |
9328 | type, disposition, |
9329 | thread, task, ignore_count, | |
9330 | ops, from_tty, | |
44f238bb PA |
9331 | enabled, internal, flags, |
9332 | display_canonical); | |
d9b3f62e | 9333 | |
a5e364af | 9334 | install_breakpoint (internal, b.release (), 0); |
018d34a4 VP |
9335 | } |
9336 | ||
9337 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9338 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9339 | value. COND_STRING, if not NULL, specified the condition to be | |
9340 | used for all breakpoints. Essentially the only case where | |
9341 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9342 | function. In that case, it's still not possible to specify | |
9343 | separate conditions for different overloaded functions, so | |
9344 | we take just a single condition string. | |
9345 | ||
c3f6f71d | 9346 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9347 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9348 | array contents). If the function fails (error() is called), the |
9349 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9350 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9351 | |
9352 | static void | |
8cdf0e15 | 9353 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9354 | struct linespec_result *canonical, |
e1e01040 PA |
9355 | gdb::unique_xmalloc_ptr<char> cond_string, |
9356 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
9357 | enum bptype type, enum bpdisp disposition, |
9358 | int thread, int task, int ignore_count, | |
c0a91b2b | 9359 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9360 | int enabled, int internal, unsigned flags) |
c906108c | 9361 | { |
018d34a4 | 9362 | int i; |
f8eba3c6 | 9363 | struct linespec_sals *lsal; |
cc59ec59 | 9364 | |
f8eba3c6 TT |
9365 | if (canonical->pre_expanded) |
9366 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9367 | ||
9368 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9369 | { |
f00aae0f | 9370 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9371 | 'break', without arguments. */ |
ffc2605c | 9372 | event_location_up location |
f00aae0f | 9373 | = (canonical->location != NULL |
8e9e35b1 | 9374 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 PA |
9375 | gdb::unique_xmalloc_ptr<char> filter_string |
9376 | (lsal->canonical != NULL ? xstrdup (lsal->canonical) : NULL); | |
0d381245 | 9377 | |
f8eba3c6 | 9378 | create_breakpoint_sal (gdbarch, lsal->sals, |
ffc2605c | 9379 | std::move (location), |
e1e01040 PA |
9380 | std::move (filter_string), |
9381 | std::move (cond_string), | |
9382 | std::move (extra_string), | |
e7e0cddf | 9383 | type, disposition, |
84f4c1fe | 9384 | thread, task, ignore_count, ops, |
44f238bb | 9385 | from_tty, enabled, internal, flags, |
56435ebe | 9386 | canonical->special_display); |
c3f6f71d | 9387 | } |
c3f6f71d | 9388 | } |
c906108c | 9389 | |
f00aae0f | 9390 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9391 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9392 | addresses found. LOCATION points to the end of the SAL (for |
9393 | linespec locations). | |
9998af43 TJB |
9394 | |
9395 | The array and the line spec strings are allocated on the heap, it is | |
9396 | the caller's responsibility to free them. */ | |
c906108c | 9397 | |
b9362cc7 | 9398 | static void |
f00aae0f | 9399 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9400 | struct linespec_result *canonical) |
c3f6f71d | 9401 | { |
f00aae0f KS |
9402 | struct symtab_and_line cursal; |
9403 | ||
9404 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9405 | { | |
9406 | const char *address = get_linespec_location (location); | |
9407 | ||
9408 | if (address == NULL) | |
9409 | { | |
9410 | /* The last displayed codepoint, if it's valid, is our default | |
9411 | breakpoint address. */ | |
9412 | if (last_displayed_sal_is_valid ()) | |
9413 | { | |
9414 | struct linespec_sals lsal; | |
9415 | struct symtab_and_line sal; | |
9416 | CORE_ADDR pc; | |
9417 | ||
9418 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9419 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9420 | |
9421 | /* Set sal's pspace, pc, symtab, and line to the values | |
9422 | corresponding to the last call to print_frame_info. | |
9423 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9424 | as the breakpoint line number is inappropriate otherwise. | |
9425 | find_pc_line would adjust PC, re-set it back. */ | |
9426 | get_last_displayed_sal (&sal); | |
9427 | pc = sal.pc; | |
9428 | sal = find_pc_line (pc, 0); | |
9429 | ||
9430 | /* "break" without arguments is equivalent to "break *PC" | |
9431 | where PC is the last displayed codepoint's address. So | |
9432 | make sure to set sal.explicit_pc to prevent GDB from | |
9433 | trying to expand the list of sals to include all other | |
9434 | instances with the same symtab and line. */ | |
9435 | sal.pc = pc; | |
9436 | sal.explicit_pc = 1; | |
9437 | ||
9438 | lsal.sals.sals[0] = sal; | |
9439 | lsal.sals.nelts = 1; | |
9440 | lsal.canonical = NULL; | |
9441 | ||
9442 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9443 | return; | |
9444 | } | |
9445 | else | |
9446 | error (_("No default breakpoint address now.")); | |
c906108c | 9447 | } |
c906108c | 9448 | } |
f00aae0f KS |
9449 | |
9450 | /* Force almost all breakpoints to be in terms of the | |
9451 | current_source_symtab (which is decode_line_1's default). | |
9452 | This should produce the results we want almost all of the | |
9453 | time while leaving default_breakpoint_* alone. | |
9454 | ||
9455 | ObjC: However, don't match an Objective-C method name which | |
9456 | may have a '+' or '-' succeeded by a '['. */ | |
9457 | cursal = get_current_source_symtab_and_line (); | |
9458 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9459 | { |
f00aae0f | 9460 | const char *address = NULL; |
cc80f267 | 9461 | |
f00aae0f KS |
9462 | if (event_location_type (location) == LINESPEC_LOCATION) |
9463 | address = get_linespec_location (location); | |
cc80f267 | 9464 | |
f00aae0f KS |
9465 | if (!cursal.symtab |
9466 | || (address != NULL | |
9467 | && strchr ("+-", address[0]) != NULL | |
9468 | && address[1] != '[')) | |
9469 | { | |
c2f4122d | 9470 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9471 | get_last_displayed_symtab (), |
9472 | get_last_displayed_line (), | |
9473 | canonical, NULL, NULL); | |
9474 | return; | |
9475 | } | |
c906108c | 9476 | } |
f00aae0f | 9477 | |
c2f4122d | 9478 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9479 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9480 | } |
c906108c | 9481 | |
c906108c | 9482 | |
c3f6f71d | 9483 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9484 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9485 | |
b9362cc7 | 9486 | static void |
23e7acfb | 9487 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9488 | { |
9489 | int i; | |
cc59ec59 | 9490 | |
c3f6f71d | 9491 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9492 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9493 | } |
9494 | ||
7a697b8d SS |
9495 | /* Fast tracepoints may have restrictions on valid locations. For |
9496 | instance, a fast tracepoint using a jump instead of a trap will | |
9497 | likely have to overwrite more bytes than a trap would, and so can | |
9498 | only be placed where the instruction is longer than the jump, or a | |
9499 | multi-instruction sequence does not have a jump into the middle of | |
9500 | it, etc. */ | |
9501 | ||
9502 | static void | |
9503 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9504 | struct symtabs_and_lines *sals) | |
9505 | { | |
9506 | int i, rslt; | |
9507 | struct symtab_and_line *sal; | |
9508 | char *msg; | |
9509 | struct cleanup *old_chain; | |
9510 | ||
9511 | for (i = 0; i < sals->nelts; i++) | |
9512 | { | |
f8eba3c6 TT |
9513 | struct gdbarch *sarch; |
9514 | ||
7a697b8d SS |
9515 | sal = &sals->sals[i]; |
9516 | ||
f8eba3c6 TT |
9517 | sarch = get_sal_arch (*sal); |
9518 | /* We fall back to GDBARCH if there is no architecture | |
9519 | associated with SAL. */ | |
9520 | if (sarch == NULL) | |
9521 | sarch = gdbarch; | |
6b940e6a | 9522 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9523 | old_chain = make_cleanup (xfree, msg); |
9524 | ||
9525 | if (!rslt) | |
53c3572a | 9526 | error (_("May not have a fast tracepoint at %s%s"), |
f8eba3c6 | 9527 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9528 | |
9529 | do_cleanups (old_chain); | |
9530 | } | |
9531 | } | |
9532 | ||
018d34a4 VP |
9533 | /* Given TOK, a string specification of condition and thread, as |
9534 | accepted by the 'break' command, extract the condition | |
9535 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9536 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9537 | If no condition is found, *COND_STRING is set to NULL. |
9538 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9539 | |
9540 | static void | |
bbc13ae3 | 9541 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9542 | char **cond_string, int *thread, int *task, |
9543 | char **rest) | |
018d34a4 VP |
9544 | { |
9545 | *cond_string = NULL; | |
9546 | *thread = -1; | |
ed1d1739 KS |
9547 | *task = 0; |
9548 | *rest = NULL; | |
9549 | ||
018d34a4 VP |
9550 | while (tok && *tok) |
9551 | { | |
bbc13ae3 | 9552 | const char *end_tok; |
018d34a4 | 9553 | int toklen; |
bbc13ae3 KS |
9554 | const char *cond_start = NULL; |
9555 | const char *cond_end = NULL; | |
cc59ec59 | 9556 | |
bbc13ae3 | 9557 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9558 | |
9559 | if ((*tok == '"' || *tok == ',') && rest) | |
9560 | { | |
9561 | *rest = savestring (tok, strlen (tok)); | |
9562 | return; | |
9563 | } | |
9564 | ||
bbc13ae3 | 9565 | end_tok = skip_to_space_const (tok); |
d634f2de | 9566 | |
018d34a4 | 9567 | toklen = end_tok - tok; |
d634f2de | 9568 | |
018d34a4 VP |
9569 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9570 | { | |
9571 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9572 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9573 | cond_end = tok; |
d634f2de | 9574 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9575 | } |
9576 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9577 | { | |
5d5658a1 PA |
9578 | const char *tmptok; |
9579 | struct thread_info *thr; | |
d634f2de | 9580 | |
018d34a4 | 9581 | tok = end_tok + 1; |
5d5658a1 | 9582 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9583 | if (tok == tmptok) |
9584 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9585 | *thread = thr->global_num; |
bbc13ae3 | 9586 | tok = tmptok; |
018d34a4 | 9587 | } |
4a306c9a JB |
9588 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9589 | { | |
9590 | char *tmptok; | |
9591 | ||
9592 | tok = end_tok + 1; | |
bbc13ae3 | 9593 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9594 | if (tok == tmptok) |
9595 | error (_("Junk after task keyword.")); | |
9596 | if (!valid_task_id (*task)) | |
b6199126 | 9597 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9598 | tok = tmptok; |
4a306c9a | 9599 | } |
e7e0cddf SS |
9600 | else if (rest) |
9601 | { | |
9602 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9603 | return; |
e7e0cddf | 9604 | } |
018d34a4 VP |
9605 | else |
9606 | error (_("Junk at end of arguments.")); | |
9607 | } | |
9608 | } | |
9609 | ||
0fb4aa4b PA |
9610 | /* Decode a static tracepoint marker spec. */ |
9611 | ||
9612 | static struct symtabs_and_lines | |
f00aae0f | 9613 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9614 | { |
9615 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9616 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9617 | struct cleanup *old_chain; |
f00aae0f KS |
9618 | const char *p = &(*arg_p)[3]; |
9619 | const char *endp; | |
0fb4aa4b PA |
9620 | char *marker_str; |
9621 | int i; | |
9622 | ||
f00aae0f | 9623 | p = skip_spaces_const (p); |
0fb4aa4b | 9624 | |
f00aae0f | 9625 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9626 | |
9627 | marker_str = savestring (p, endp - p); | |
9628 | old_chain = make_cleanup (xfree, marker_str); | |
9629 | ||
9630 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9631 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9632 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9633 | ||
9634 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9635 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9636 | |
9637 | for (i = 0; i < sals.nelts; i++) | |
9638 | { | |
9639 | struct static_tracepoint_marker *marker; | |
9640 | ||
9641 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9642 | ||
9643 | init_sal (&sals.sals[i]); | |
9644 | ||
9645 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9646 | sals.sals[i].pc = marker->address; | |
9647 | ||
9648 | release_static_tracepoint_marker (marker); | |
9649 | } | |
9650 | ||
9651 | do_cleanups (old_chain); | |
9652 | ||
9653 | *arg_p = endp; | |
9654 | return sals; | |
9655 | } | |
9656 | ||
f00aae0f | 9657 | /* See breakpoint.h. */ |
0101ce28 | 9658 | |
8cdf0e15 VP |
9659 | int |
9660 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9661 | const struct event_location *location, |
9662 | const char *cond_string, | |
9663 | int thread, const char *extra_string, | |
f00aae0f | 9664 | int parse_extra, |
0fb4aa4b | 9665 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9666 | int ignore_count, |
9667 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9668 | const struct breakpoint_ops *ops, |
44f238bb PA |
9669 | int from_tty, int enabled, int internal, |
9670 | unsigned flags) | |
c3f6f71d | 9671 | { |
7efd8fc2 | 9672 | struct linespec_result canonical; |
80c99de1 | 9673 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9674 | int pending = 0; |
4a306c9a | 9675 | int task = 0; |
86b17b60 | 9676 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9677 | |
348d480f PA |
9678 | gdb_assert (ops != NULL); |
9679 | ||
f00aae0f KS |
9680 | /* If extra_string isn't useful, set it to NULL. */ |
9681 | if (extra_string != NULL && *extra_string == '\0') | |
9682 | extra_string = NULL; | |
9683 | ||
492d29ea | 9684 | TRY |
b78a6381 | 9685 | { |
f00aae0f | 9686 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9687 | } |
492d29ea | 9688 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9689 | { |
492d29ea PA |
9690 | /* If caller is interested in rc value from parse, set |
9691 | value. */ | |
9692 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9693 | { |
05ff989b AC |
9694 | /* If pending breakpoint support is turned off, throw |
9695 | error. */ | |
fa8d40ab JJ |
9696 | |
9697 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9698 | throw_exception (e); |
9699 | ||
9700 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9701 | |
05ff989b AC |
9702 | /* If pending breakpoint support is auto query and the user |
9703 | selects no, then simply return the error code. */ | |
059fb39f | 9704 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9705 | && !nquery (_("Make %s pending on future shared library load? "), |
9706 | bptype_string (type_wanted))) | |
fd9b8c24 | 9707 | return 0; |
fa8d40ab | 9708 | |
05ff989b AC |
9709 | /* At this point, either the user was queried about setting |
9710 | a pending breakpoint and selected yes, or pending | |
9711 | breakpoint behavior is on and thus a pending breakpoint | |
9712 | is defaulted on behalf of the user. */ | |
f00aae0f | 9713 | pending = 1; |
0101ce28 | 9714 | } |
492d29ea PA |
9715 | else |
9716 | throw_exception (e); | |
0101ce28 | 9717 | } |
492d29ea PA |
9718 | END_CATCH |
9719 | ||
f00aae0f | 9720 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9721 | return 0; |
c3f6f71d | 9722 | |
c3f6f71d JM |
9723 | /* ----------------------------- SNIP ----------------------------- |
9724 | Anything added to the cleanup chain beyond this point is assumed | |
9725 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9726 | then the memory is not reclaimed. */ |
9727 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9728 | |
c3f6f71d JM |
9729 | /* Resolve all line numbers to PC's and verify that the addresses |
9730 | are ok for the target. */ | |
0101ce28 | 9731 | if (!pending) |
f8eba3c6 TT |
9732 | { |
9733 | int ix; | |
9734 | struct linespec_sals *iter; | |
9735 | ||
9736 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9737 | breakpoint_sals_to_pc (&iter->sals); | |
9738 | } | |
c3f6f71d | 9739 | |
7a697b8d | 9740 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9741 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9742 | { |
9743 | int ix; | |
9744 | struct linespec_sals *iter; | |
9745 | ||
9746 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9747 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9748 | } | |
7a697b8d | 9749 | |
c3f6f71d JM |
9750 | /* Verify that condition can be parsed, before setting any |
9751 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9752 | breakpoint. */ |
0101ce28 | 9753 | if (!pending) |
c3f6f71d | 9754 | { |
e1e01040 PA |
9755 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9756 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9757 | ||
f00aae0f | 9758 | if (parse_extra) |
72b2ff0e | 9759 | { |
0878d0fa | 9760 | char *rest; |
e1e01040 | 9761 | char *cond; |
52d361e1 YQ |
9762 | struct linespec_sals *lsal; |
9763 | ||
9764 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9765 | ||
0878d0fa YQ |
9766 | /* Here we only parse 'arg' to separate condition |
9767 | from thread number, so parsing in context of first | |
9768 | sal is OK. When setting the breakpoint we'll | |
9769 | re-parse it in context of each sal. */ | |
9770 | ||
f00aae0f | 9771 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
e1e01040 PA |
9772 | &cond, &thread, &task, &rest); |
9773 | cond_string_copy.reset (cond); | |
9774 | extra_string_copy.reset (rest); | |
72b2ff0e | 9775 | } |
2f069f6f | 9776 | else |
72b2ff0e | 9777 | { |
f00aae0f KS |
9778 | if (type_wanted != bp_dprintf |
9779 | && extra_string != NULL && *extra_string != '\0') | |
9780 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9781 | |
9782 | /* Create a private copy of condition string. */ | |
9783 | if (cond_string) | |
e1e01040 | 9784 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9785 | /* Create a private copy of any extra string. */ |
9786 | if (extra_string) | |
e1e01040 | 9787 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9788 | } |
0fb4aa4b | 9789 | |
52d361e1 | 9790 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9791 | std::move (cond_string_copy), |
9792 | std::move (extra_string_copy), | |
9793 | type_wanted, | |
d9b3f62e PA |
9794 | tempflag ? disp_del : disp_donttouch, |
9795 | thread, task, ignore_count, ops, | |
44f238bb | 9796 | from_tty, enabled, internal, flags); |
c906108c | 9797 | } |
0101ce28 JJ |
9798 | else |
9799 | { | |
a5e364af | 9800 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9801 | |
a5e364af | 9802 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9803 | b->location = copy_event_location (location); |
bfccc43c | 9804 | |
f00aae0f KS |
9805 | if (parse_extra) |
9806 | b->cond_string = NULL; | |
e12c7713 MK |
9807 | else |
9808 | { | |
9809 | /* Create a private copy of condition string. */ | |
e1e01040 | 9810 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9811 | b->thread = thread; |
e12c7713 | 9812 | } |
f00aae0f KS |
9813 | |
9814 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9815 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9816 | b->ignore_count = ignore_count; |
0101ce28 | 9817 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9818 | b->condition_not_parsed = 1; |
41447f92 | 9819 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9820 | if ((type_wanted != bp_breakpoint |
9821 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9822 | b->pspace = current_program_space; |
8bea4e01 | 9823 | |
a5e364af | 9824 | install_breakpoint (internal, b.release (), 0); |
0101ce28 JJ |
9825 | } |
9826 | ||
f8eba3c6 | 9827 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9828 | { |
3e43a32a MS |
9829 | warning (_("Multiple breakpoints were set.\nUse the " |
9830 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9831 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9832 | } |
9833 | ||
80c99de1 PA |
9834 | /* That's it. Discard the cleanups for data inserted into the |
9835 | breakpoint. */ | |
9836 | discard_cleanups (bkpt_chain); | |
217dc9e2 | 9837 | |
80c99de1 | 9838 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9839 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9840 | |
9841 | return 1; | |
c3f6f71d | 9842 | } |
c906108c | 9843 | |
348d480f | 9844 | /* Set a breakpoint. |
72b2ff0e VP |
9845 | ARG is a string describing breakpoint address, |
9846 | condition, and thread. | |
9847 | FLAG specifies if a breakpoint is hardware on, | |
9848 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9849 | and BP_TEMPFLAG. */ | |
348d480f | 9850 | |
98deb0da | 9851 | static void |
72b2ff0e | 9852 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9853 | { |
72b2ff0e | 9854 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9855 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9856 | ? bp_hardware_breakpoint | |
9857 | : bp_breakpoint); | |
55aa24fb | 9858 | struct breakpoint_ops *ops; |
f00aae0f | 9859 | |
ffc2605c | 9860 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9861 | |
9862 | /* Matching breakpoints on probes. */ | |
5b56227b | 9863 | if (location != NULL |
ffc2605c | 9864 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9865 | ops = &bkpt_probe_breakpoint_ops; |
9866 | else | |
9867 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9868 | |
8cdf0e15 | 9869 | create_breakpoint (get_current_arch (), |
ffc2605c | 9870 | location.get (), |
f00aae0f | 9871 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9872 | tempflag, type_wanted, |
8cdf0e15 VP |
9873 | 0 /* Ignore count */, |
9874 | pending_break_support, | |
55aa24fb | 9875 | ops, |
8cdf0e15 | 9876 | from_tty, |
84f4c1fe | 9877 | 1 /* enabled */, |
44f238bb PA |
9878 | 0 /* internal */, |
9879 | 0); | |
c906108c SS |
9880 | } |
9881 | ||
c906108c SS |
9882 | /* Helper function for break_command_1 and disassemble_command. */ |
9883 | ||
9884 | void | |
fba45db2 | 9885 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9886 | { |
9887 | CORE_ADDR pc; | |
9888 | ||
9889 | if (sal->pc == 0 && sal->symtab != NULL) | |
9890 | { | |
9891 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9892 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9893 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9894 | sal->pc = pc; |
6a048695 | 9895 | |
4a64f543 MS |
9896 | /* If this SAL corresponds to a breakpoint inserted using a line |
9897 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9898 | if (sal->explicit_line) |
059acae7 | 9899 | skip_prologue_sal (sal); |
c906108c SS |
9900 | } |
9901 | ||
9902 | if (sal->section == 0 && sal->symtab != NULL) | |
9903 | { | |
346d1dfe | 9904 | const struct blockvector *bv; |
3977b71f | 9905 | const struct block *b; |
c5aa993b | 9906 | struct symbol *sym; |
c906108c | 9907 | |
43f3e411 DE |
9908 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9909 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9910 | if (bv != NULL) |
9911 | { | |
7f0df278 | 9912 | sym = block_linkage_function (b); |
c906108c SS |
9913 | if (sym != NULL) |
9914 | { | |
eb822aa6 DE |
9915 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9916 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9917 | sym); | |
c906108c SS |
9918 | } |
9919 | else | |
9920 | { | |
4a64f543 MS |
9921 | /* It really is worthwhile to have the section, so we'll |
9922 | just have to look harder. This case can be executed | |
9923 | if we have line numbers but no functions (as can | |
9924 | happen in assembly source). */ | |
c906108c | 9925 | |
5ed8105e | 9926 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9927 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9928 | |
5ed8105e | 9929 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9930 | if (msym.minsym) |
efd66ac6 | 9931 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9932 | } |
9933 | } | |
9934 | } | |
9935 | } | |
9936 | ||
9937 | void | |
fba45db2 | 9938 | break_command (char *arg, int from_tty) |
c906108c | 9939 | { |
db107f19 | 9940 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9941 | } |
9942 | ||
c906108c | 9943 | void |
fba45db2 | 9944 | tbreak_command (char *arg, int from_tty) |
c906108c | 9945 | { |
db107f19 | 9946 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9947 | } |
9948 | ||
c906108c | 9949 | static void |
fba45db2 | 9950 | hbreak_command (char *arg, int from_tty) |
c906108c | 9951 | { |
db107f19 | 9952 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9953 | } |
9954 | ||
9955 | static void | |
fba45db2 | 9956 | thbreak_command (char *arg, int from_tty) |
c906108c | 9957 | { |
db107f19 | 9958 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9959 | } |
9960 | ||
9961 | static void | |
fba45db2 | 9962 | stop_command (char *arg, int from_tty) |
c906108c | 9963 | { |
a3f17187 | 9964 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9965 | Usage: stop in <function | address>\n\ |
a3f17187 | 9966 | stop at <line>\n")); |
c906108c SS |
9967 | } |
9968 | ||
9969 | static void | |
fba45db2 | 9970 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9971 | { |
9972 | int badInput = 0; | |
9973 | ||
c5aa993b | 9974 | if (arg == (char *) NULL) |
c906108c SS |
9975 | badInput = 1; |
9976 | else if (*arg != '*') | |
9977 | { | |
9978 | char *argptr = arg; | |
9979 | int hasColon = 0; | |
9980 | ||
4a64f543 | 9981 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9982 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9983 | function/method name. */ |
c906108c | 9984 | while (*argptr && !hasColon) |
c5aa993b JM |
9985 | { |
9986 | hasColon = (*argptr == ':'); | |
9987 | argptr++; | |
9988 | } | |
c906108c SS |
9989 | |
9990 | if (hasColon) | |
c5aa993b | 9991 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9992 | else |
c5aa993b | 9993 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9994 | } |
9995 | ||
9996 | if (badInput) | |
a3f17187 | 9997 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9998 | else |
db107f19 | 9999 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10000 | } |
10001 | ||
10002 | static void | |
fba45db2 | 10003 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10004 | { |
10005 | int badInput = 0; | |
10006 | ||
c5aa993b | 10007 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10008 | badInput = 1; |
10009 | else | |
10010 | { | |
10011 | char *argptr = arg; | |
10012 | int hasColon = 0; | |
10013 | ||
4a64f543 MS |
10014 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10015 | it is probably a line number. */ | |
c906108c | 10016 | while (*argptr && !hasColon) |
c5aa993b JM |
10017 | { |
10018 | hasColon = (*argptr == ':'); | |
10019 | argptr++; | |
10020 | } | |
c906108c SS |
10021 | |
10022 | if (hasColon) | |
c5aa993b | 10023 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10024 | else |
c5aa993b | 10025 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10026 | } |
10027 | ||
10028 | if (badInput) | |
a3f17187 | 10029 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10030 | else |
db107f19 | 10031 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10032 | } |
10033 | ||
e7e0cddf SS |
10034 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10035 | with a prewired command list consisting of a single output command, | |
10036 | built from extra arguments supplied on the dprintf command | |
10037 | line. */ | |
10038 | ||
da821c7b | 10039 | static void |
e7e0cddf SS |
10040 | dprintf_command (char *arg, int from_tty) |
10041 | { | |
ffc2605c | 10042 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
10043 | |
10044 | /* If non-NULL, ARG should have been advanced past the location; | |
10045 | the next character must be ','. */ | |
10046 | if (arg != NULL) | |
10047 | { | |
10048 | if (arg[0] != ',' || arg[1] == '\0') | |
10049 | error (_("Format string required")); | |
10050 | else | |
10051 | { | |
10052 | /* Skip the comma. */ | |
10053 | ++arg; | |
10054 | } | |
10055 | } | |
10056 | ||
e7e0cddf | 10057 | create_breakpoint (get_current_arch (), |
ffc2605c | 10058 | location.get (), |
f00aae0f | 10059 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
10060 | 0, bp_dprintf, |
10061 | 0 /* Ignore count */, | |
10062 | pending_break_support, | |
10063 | &dprintf_breakpoint_ops, | |
10064 | from_tty, | |
10065 | 1 /* enabled */, | |
10066 | 0 /* internal */, | |
10067 | 0); | |
10068 | } | |
10069 | ||
d3ce09f5 SS |
10070 | static void |
10071 | agent_printf_command (char *arg, int from_tty) | |
10072 | { | |
10073 | error (_("May only run agent-printf on the target")); | |
10074 | } | |
10075 | ||
f1310107 TJB |
10076 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10077 | ranged breakpoints. */ | |
10078 | ||
10079 | static int | |
10080 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10081 | struct address_space *aspace, | |
09ac7c10 TT |
10082 | CORE_ADDR bp_addr, |
10083 | const struct target_waitstatus *ws) | |
f1310107 | 10084 | { |
09ac7c10 | 10085 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10086 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10087 | return 0; |
10088 | ||
f1310107 TJB |
10089 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10090 | bl->length, aspace, bp_addr); | |
10091 | } | |
10092 | ||
10093 | /* Implement the "resources_needed" breakpoint_ops method for | |
10094 | ranged breakpoints. */ | |
10095 | ||
10096 | static int | |
10097 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10098 | { | |
10099 | return target_ranged_break_num_registers (); | |
10100 | } | |
10101 | ||
10102 | /* Implement the "print_it" breakpoint_ops method for | |
10103 | ranged breakpoints. */ | |
10104 | ||
10105 | static enum print_stop_action | |
348d480f | 10106 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10107 | { |
348d480f | 10108 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10109 | struct bp_location *bl = b->loc; |
79a45e25 | 10110 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10111 | |
10112 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10113 | ||
10114 | /* Ranged breakpoints have only one location. */ | |
10115 | gdb_assert (bl && bl->next == NULL); | |
10116 | ||
10117 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10118 | |
10119 | maybe_print_thread_hit_breakpoint (uiout); | |
10120 | ||
f1310107 | 10121 | if (b->disposition == disp_del) |
112e8700 | 10122 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 10123 | else |
112e8700 SM |
10124 | uiout->text ("Ranged breakpoint "); |
10125 | if (uiout->is_mi_like_p ()) | |
f1310107 | 10126 | { |
112e8700 | 10127 | uiout->field_string ("reason", |
f1310107 | 10128 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 10129 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 10130 | } |
112e8700 SM |
10131 | uiout->field_int ("bkptno", b->number); |
10132 | uiout->text (", "); | |
f1310107 TJB |
10133 | |
10134 | return PRINT_SRC_AND_LOC; | |
10135 | } | |
10136 | ||
10137 | /* Implement the "print_one" breakpoint_ops method for | |
10138 | ranged breakpoints. */ | |
10139 | ||
10140 | static void | |
10141 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10142 | struct bp_location **last_loc) | |
10143 | { | |
10144 | struct bp_location *bl = b->loc; | |
10145 | struct value_print_options opts; | |
79a45e25 | 10146 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10147 | |
10148 | /* Ranged breakpoints have only one location. */ | |
10149 | gdb_assert (bl && bl->next == NULL); | |
10150 | ||
10151 | get_user_print_options (&opts); | |
10152 | ||
10153 | if (opts.addressprint) | |
10154 | /* We don't print the address range here, it will be printed later | |
10155 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 10156 | uiout->field_skip ("addr"); |
f1310107 TJB |
10157 | annotate_field (5); |
10158 | print_breakpoint_location (b, bl); | |
10159 | *last_loc = bl; | |
10160 | } | |
10161 | ||
10162 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10163 | ranged breakpoints. */ | |
10164 | ||
10165 | static void | |
10166 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10167 | struct ui_out *uiout) | |
10168 | { | |
10169 | CORE_ADDR address_start, address_end; | |
10170 | struct bp_location *bl = b->loc; | |
d7e74731 | 10171 | string_file stb; |
f1310107 TJB |
10172 | |
10173 | gdb_assert (bl); | |
10174 | ||
10175 | address_start = bl->address; | |
10176 | address_end = address_start + bl->length - 1; | |
10177 | ||
112e8700 | 10178 | uiout->text ("\taddress range: "); |
d7e74731 PA |
10179 | stb.printf ("[%s, %s]", |
10180 | print_core_address (bl->gdbarch, address_start), | |
10181 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
10182 | uiout->field_stream ("addr", stb); |
10183 | uiout->text ("\n"); | |
f1310107 TJB |
10184 | } |
10185 | ||
10186 | /* Implement the "print_mention" breakpoint_ops method for | |
10187 | ranged breakpoints. */ | |
10188 | ||
10189 | static void | |
10190 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10191 | { | |
10192 | struct bp_location *bl = b->loc; | |
79a45e25 | 10193 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10194 | |
10195 | gdb_assert (bl); | |
10196 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10197 | ||
112e8700 | 10198 | if (uiout->is_mi_like_p ()) |
f1310107 TJB |
10199 | return; |
10200 | ||
10201 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10202 | b->number, paddress (bl->gdbarch, bl->address), | |
10203 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10204 | } | |
10205 | ||
10206 | /* Implement the "print_recreate" breakpoint_ops method for | |
10207 | ranged breakpoints. */ | |
10208 | ||
10209 | static void | |
10210 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10211 | { | |
f00aae0f | 10212 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
10213 | event_location_to_string (b->location.get ()), |
10214 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 10215 | print_recreate_thread (b, fp); |
f1310107 TJB |
10216 | } |
10217 | ||
10218 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10219 | ||
2060206e | 10220 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10221 | |
10222 | /* Find the address where the end of the breakpoint range should be | |
10223 | placed, given the SAL of the end of the range. This is so that if | |
10224 | the user provides a line number, the end of the range is set to the | |
10225 | last instruction of the given line. */ | |
10226 | ||
10227 | static CORE_ADDR | |
10228 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10229 | { | |
10230 | CORE_ADDR end; | |
10231 | ||
10232 | /* If the user provided a PC value, use it. Otherwise, | |
10233 | find the address of the end of the given location. */ | |
10234 | if (sal.explicit_pc) | |
10235 | end = sal.pc; | |
10236 | else | |
10237 | { | |
10238 | int ret; | |
10239 | CORE_ADDR start; | |
10240 | ||
10241 | ret = find_line_pc_range (sal, &start, &end); | |
10242 | if (!ret) | |
10243 | error (_("Could not find location of the end of the range.")); | |
10244 | ||
10245 | /* find_line_pc_range returns the start of the next line. */ | |
10246 | end--; | |
10247 | } | |
10248 | ||
10249 | return end; | |
10250 | } | |
10251 | ||
10252 | /* Implement the "break-range" CLI command. */ | |
10253 | ||
10254 | static void | |
10255 | break_range_command (char *arg, int from_tty) | |
10256 | { | |
870f88f7 | 10257 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10258 | struct linespec_result canonical_start, canonical_end; |
10259 | int bp_count, can_use_bp, length; | |
10260 | CORE_ADDR end; | |
10261 | struct breakpoint *b; | |
10262 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10263 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10264 | struct linespec_sals *lsal_start, *lsal_end; |
f1310107 TJB |
10265 | |
10266 | /* We don't support software ranged breakpoints. */ | |
10267 | if (target_ranged_break_num_registers () < 0) | |
10268 | error (_("This target does not support hardware ranged breakpoints.")); | |
10269 | ||
10270 | bp_count = hw_breakpoint_used_count (); | |
10271 | bp_count += target_ranged_break_num_registers (); | |
10272 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10273 | bp_count, 0); | |
10274 | if (can_use_bp < 0) | |
10275 | error (_("Hardware breakpoints used exceeds limit.")); | |
10276 | ||
f8eba3c6 | 10277 | arg = skip_spaces (arg); |
f1310107 TJB |
10278 | if (arg == NULL || arg[0] == '\0') |
10279 | error(_("No address range specified.")); | |
10280 | ||
f8eba3c6 | 10281 | arg_start = arg; |
ffc2605c TT |
10282 | event_location_up start_location = string_to_event_location (&arg, |
10283 | current_language); | |
10284 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
10285 | |
10286 | if (arg[0] != ',') | |
10287 | error (_("Too few arguments.")); | |
f8eba3c6 | 10288 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10289 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10290 | |
10291 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10292 | ||
10293 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10294 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10295 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10296 | ||
f8eba3c6 TT |
10297 | sal_start = lsal_start->sals.sals[0]; |
10298 | addr_string_start = savestring (arg_start, arg - arg_start); | |
16e802b9 | 10299 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); |
f1310107 TJB |
10300 | |
10301 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10302 | arg = skip_spaces (arg); |
f1310107 TJB |
10303 | |
10304 | /* Parse the end location. */ | |
10305 | ||
f1310107 TJB |
10306 | arg_start = arg; |
10307 | ||
f8eba3c6 | 10308 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10309 | parse_breakpoint_sals because we need to specify the start location's |
10310 | symtab and line as the default symtab and line for the end of the | |
10311 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10312 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10313 | event_location_up end_location = string_to_event_location (&arg, |
10314 | current_language); | |
10315 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10316 | sal_start.symtab, sal_start.line, |
10317 | &canonical_end, NULL, NULL); | |
10318 | ||
f8eba3c6 | 10319 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10320 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10321 | |
10322 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10323 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10324 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10325 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10326 | ||
f8eba3c6 | 10327 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10328 | |
10329 | end = find_breakpoint_range_end (sal_end); | |
10330 | if (sal_start.pc > end) | |
177b42fe | 10331 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10332 | |
10333 | length = end - sal_start.pc + 1; | |
10334 | if (length < 0) | |
10335 | /* Length overflowed. */ | |
10336 | error (_("Address range too large.")); | |
10337 | else if (length == 1) | |
10338 | { | |
10339 | /* This range is simple enough to be handled by | |
10340 | the `hbreak' command. */ | |
10341 | hbreak_command (addr_string_start, 1); | |
10342 | ||
10343 | do_cleanups (cleanup_bkpt); | |
10344 | ||
10345 | return; | |
10346 | } | |
10347 | ||
10348 | /* Now set up the breakpoint. */ | |
10349 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10350 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10351 | set_breakpoint_count (breakpoint_count + 1); |
10352 | b->number = breakpoint_count; | |
10353 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10354 | b->location = std::move (start_location); |
10355 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10356 | b->loc->length = length; |
10357 | ||
f8eba3c6 | 10358 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10359 | |
10360 | mention (b); | |
8d3788bd | 10361 | observer_notify_breakpoint_created (b); |
44702360 | 10362 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10363 | } |
10364 | ||
4a64f543 MS |
10365 | /* Return non-zero if EXP is verified as constant. Returned zero |
10366 | means EXP is variable. Also the constant detection may fail for | |
10367 | some constant expressions and in such case still falsely return | |
10368 | zero. */ | |
2e6e3d9c | 10369 | |
65d79d4b SDJ |
10370 | static int |
10371 | watchpoint_exp_is_const (const struct expression *exp) | |
10372 | { | |
10373 | int i = exp->nelts; | |
10374 | ||
10375 | while (i > 0) | |
10376 | { | |
10377 | int oplenp, argsp; | |
10378 | ||
10379 | /* We are only interested in the descriptor of each element. */ | |
10380 | operator_length (exp, i, &oplenp, &argsp); | |
10381 | i -= oplenp; | |
10382 | ||
10383 | switch (exp->elts[i].opcode) | |
10384 | { | |
10385 | case BINOP_ADD: | |
10386 | case BINOP_SUB: | |
10387 | case BINOP_MUL: | |
10388 | case BINOP_DIV: | |
10389 | case BINOP_REM: | |
10390 | case BINOP_MOD: | |
10391 | case BINOP_LSH: | |
10392 | case BINOP_RSH: | |
10393 | case BINOP_LOGICAL_AND: | |
10394 | case BINOP_LOGICAL_OR: | |
10395 | case BINOP_BITWISE_AND: | |
10396 | case BINOP_BITWISE_IOR: | |
10397 | case BINOP_BITWISE_XOR: | |
10398 | case BINOP_EQUAL: | |
10399 | case BINOP_NOTEQUAL: | |
10400 | case BINOP_LESS: | |
10401 | case BINOP_GTR: | |
10402 | case BINOP_LEQ: | |
10403 | case BINOP_GEQ: | |
10404 | case BINOP_REPEAT: | |
10405 | case BINOP_COMMA: | |
10406 | case BINOP_EXP: | |
10407 | case BINOP_MIN: | |
10408 | case BINOP_MAX: | |
10409 | case BINOP_INTDIV: | |
10410 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10411 | case TERNOP_COND: |
10412 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10413 | |
10414 | case OP_LONG: | |
10415 | case OP_DOUBLE: | |
10416 | case OP_DECFLOAT: | |
10417 | case OP_LAST: | |
10418 | case OP_COMPLEX: | |
10419 | case OP_STRING: | |
65d79d4b SDJ |
10420 | case OP_ARRAY: |
10421 | case OP_TYPE: | |
608b4967 TT |
10422 | case OP_TYPEOF: |
10423 | case OP_DECLTYPE: | |
6e72ca20 | 10424 | case OP_TYPEID: |
65d79d4b SDJ |
10425 | case OP_NAME: |
10426 | case OP_OBJC_NSSTRING: | |
10427 | ||
10428 | case UNOP_NEG: | |
10429 | case UNOP_LOGICAL_NOT: | |
10430 | case UNOP_COMPLEMENT: | |
10431 | case UNOP_ADDR: | |
10432 | case UNOP_HIGH: | |
aeaa2474 | 10433 | case UNOP_CAST: |
9eaf6705 TT |
10434 | |
10435 | case UNOP_CAST_TYPE: | |
10436 | case UNOP_REINTERPRET_CAST: | |
10437 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10438 | /* Unary, binary and ternary operators: We have to check |
10439 | their operands. If they are constant, then so is the | |
10440 | result of that operation. For instance, if A and B are | |
10441 | determined to be constants, then so is "A + B". | |
10442 | ||
10443 | UNOP_IND is one exception to the rule above, because the | |
10444 | value of *ADDR is not necessarily a constant, even when | |
10445 | ADDR is. */ | |
65d79d4b SDJ |
10446 | break; |
10447 | ||
10448 | case OP_VAR_VALUE: | |
10449 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10450 | |
65d79d4b | 10451 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10452 | possible that a buggy compiler could mark a variable as |
10453 | constant even when it is not, and TYPE_CONST would return | |
10454 | true in this case, while SYMBOL_CLASS wouldn't. | |
10455 | ||
10456 | We also have to check for function symbols because they | |
10457 | are always constant. */ | |
65d79d4b SDJ |
10458 | { |
10459 | struct symbol *s = exp->elts[i + 2].symbol; | |
10460 | ||
10461 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10462 | && SYMBOL_CLASS (s) != LOC_CONST | |
10463 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10464 | return 0; | |
10465 | break; | |
10466 | } | |
10467 | ||
10468 | /* The default action is to return 0 because we are using | |
10469 | the optimistic approach here: If we don't know something, | |
10470 | then it is not a constant. */ | |
10471 | default: | |
10472 | return 0; | |
10473 | } | |
10474 | } | |
10475 | ||
10476 | return 1; | |
10477 | } | |
10478 | ||
c1fc2657 | 10479 | /* Watchpoint destructor. */ |
3a5c3e22 | 10480 | |
c1fc2657 | 10481 | watchpoint::~watchpoint () |
3a5c3e22 | 10482 | { |
c1fc2657 SM |
10483 | xfree (this->exp_string); |
10484 | xfree (this->exp_string_reparse); | |
10485 | value_free (this->val); | |
3a5c3e22 PA |
10486 | } |
10487 | ||
348d480f PA |
10488 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10489 | ||
10490 | static void | |
10491 | re_set_watchpoint (struct breakpoint *b) | |
10492 | { | |
3a5c3e22 PA |
10493 | struct watchpoint *w = (struct watchpoint *) b; |
10494 | ||
348d480f PA |
10495 | /* Watchpoint can be either on expression using entirely global |
10496 | variables, or it can be on local variables. | |
10497 | ||
10498 | Watchpoints of the first kind are never auto-deleted, and even | |
10499 | persist across program restarts. Since they can use variables | |
10500 | from shared libraries, we need to reparse expression as libraries | |
10501 | are loaded and unloaded. | |
10502 | ||
10503 | Watchpoints on local variables can also change meaning as result | |
10504 | of solib event. For example, if a watchpoint uses both a local | |
10505 | and a global variables in expression, it's a local watchpoint, | |
10506 | but unloading of a shared library will make the expression | |
10507 | invalid. This is not a very common use case, but we still | |
10508 | re-evaluate expression, to avoid surprises to the user. | |
10509 | ||
10510 | Note that for local watchpoints, we re-evaluate it only if | |
10511 | watchpoints frame id is still valid. If it's not, it means the | |
10512 | watchpoint is out of scope and will be deleted soon. In fact, | |
10513 | I'm not sure we'll ever be called in this case. | |
10514 | ||
10515 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10516 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10517 | |
3a5c3e22 PA |
10518 | Don't do anything about disabled watchpoints, since they will be |
10519 | reevaluated again when enabled. */ | |
10520 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10521 | } |
10522 | ||
77b06cd7 TJB |
10523 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10524 | ||
10525 | static int | |
10526 | insert_watchpoint (struct bp_location *bl) | |
10527 | { | |
3a5c3e22 PA |
10528 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10529 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10530 | |
10531 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10532 | w->cond_exp.get ()); |
77b06cd7 TJB |
10533 | } |
10534 | ||
10535 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10536 | ||
10537 | static int | |
73971819 | 10538 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10539 | { |
3a5c3e22 PA |
10540 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10541 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10542 | |
10543 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10544 | w->cond_exp.get ()); |
e09342b5 TJB |
10545 | } |
10546 | ||
e09342b5 | 10547 | static int |
348d480f | 10548 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10549 | struct address_space *aspace, CORE_ADDR bp_addr, |
10550 | const struct target_waitstatus *ws) | |
e09342b5 | 10551 | { |
348d480f | 10552 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10553 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10554 | |
348d480f PA |
10555 | /* Continuable hardware watchpoints are treated as non-existent if the |
10556 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10557 | some data address). Otherwise gdb won't stop on a break instruction | |
10558 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10559 | been defined. Also skip watchpoints which we know did not trigger | |
10560 | (did not match the data address). */ | |
10561 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10562 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10563 | return 0; |
9c06b0b4 | 10564 | |
348d480f | 10565 | return 1; |
9c06b0b4 TJB |
10566 | } |
10567 | ||
348d480f PA |
10568 | static void |
10569 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10570 | { |
348d480f | 10571 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10572 | |
348d480f | 10573 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10574 | } |
10575 | ||
10576 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10577 | hardware watchpoints. */ |
9c06b0b4 TJB |
10578 | |
10579 | static int | |
348d480f | 10580 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10581 | { |
3a5c3e22 PA |
10582 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10583 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10584 | |
10585 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10586 | } |
10587 | ||
10588 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10589 | hardware watchpoints. */ |
9c06b0b4 TJB |
10590 | |
10591 | static int | |
348d480f | 10592 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10593 | { |
efa80663 PA |
10594 | /* Read and access watchpoints only work with hardware support. */ |
10595 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10596 | } |
10597 | ||
9c06b0b4 | 10598 | static enum print_stop_action |
348d480f | 10599 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10600 | { |
348d480f PA |
10601 | struct cleanup *old_chain; |
10602 | struct breakpoint *b; | |
348d480f | 10603 | enum print_stop_action result; |
3a5c3e22 | 10604 | struct watchpoint *w; |
79a45e25 | 10605 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10606 | |
10607 | gdb_assert (bs->bp_location_at != NULL); | |
10608 | ||
348d480f | 10609 | b = bs->breakpoint_at; |
3a5c3e22 | 10610 | w = (struct watchpoint *) b; |
348d480f | 10611 | |
d7e74731 | 10612 | old_chain = make_cleanup (null_cleanup, NULL); |
9c06b0b4 | 10613 | |
f303dbd6 PA |
10614 | annotate_watchpoint (b->number); |
10615 | maybe_print_thread_hit_breakpoint (uiout); | |
10616 | ||
d7e74731 PA |
10617 | string_file stb; |
10618 | ||
9c06b0b4 TJB |
10619 | switch (b->type) |
10620 | { | |
348d480f | 10621 | case bp_watchpoint: |
9c06b0b4 | 10622 | case bp_hardware_watchpoint: |
112e8700 SM |
10623 | if (uiout->is_mi_like_p ()) |
10624 | uiout->field_string | |
10625 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10626 | mention (b); |
10627 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10628 | uiout->text ("\nOld value = "); |
d7e74731 | 10629 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10630 | uiout->field_stream ("old", stb); |
10631 | uiout->text ("\nNew value = "); | |
d7e74731 | 10632 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10633 | uiout->field_stream ("new", stb); |
10634 | uiout->text ("\n"); | |
348d480f PA |
10635 | /* More than one watchpoint may have been triggered. */ |
10636 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10637 | break; |
10638 | ||
10639 | case bp_read_watchpoint: | |
112e8700 SM |
10640 | if (uiout->is_mi_like_p ()) |
10641 | uiout->field_string | |
10642 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10643 | mention (b); |
10644 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10645 | uiout->text ("\nValue = "); |
d7e74731 | 10646 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10647 | uiout->field_stream ("value", stb); |
10648 | uiout->text ("\n"); | |
348d480f | 10649 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10650 | break; |
10651 | ||
10652 | case bp_access_watchpoint: | |
348d480f PA |
10653 | if (bs->old_val != NULL) |
10654 | { | |
112e8700 SM |
10655 | if (uiout->is_mi_like_p ()) |
10656 | uiout->field_string | |
10657 | ("reason", | |
348d480f PA |
10658 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10659 | mention (b); | |
10660 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10661 | uiout->text ("\nOld value = "); |
d7e74731 | 10662 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10663 | uiout->field_stream ("old", stb); |
10664 | uiout->text ("\nNew value = "); | |
348d480f PA |
10665 | } |
10666 | else | |
10667 | { | |
10668 | mention (b); | |
112e8700 SM |
10669 | if (uiout->is_mi_like_p ()) |
10670 | uiout->field_string | |
10671 | ("reason", | |
348d480f PA |
10672 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10673 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
112e8700 | 10674 | uiout->text ("\nValue = "); |
348d480f | 10675 | } |
d7e74731 | 10676 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10677 | uiout->field_stream ("new", stb); |
10678 | uiout->text ("\n"); | |
348d480f | 10679 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10680 | break; |
10681 | default: | |
348d480f | 10682 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10683 | } |
10684 | ||
348d480f PA |
10685 | do_cleanups (old_chain); |
10686 | return result; | |
10687 | } | |
10688 | ||
10689 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10690 | watchpoints. */ | |
10691 | ||
10692 | static void | |
10693 | print_mention_watchpoint (struct breakpoint *b) | |
10694 | { | |
3a5c3e22 | 10695 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10696 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10697 | const char *tuple_name; |
348d480f PA |
10698 | |
10699 | switch (b->type) | |
10700 | { | |
10701 | case bp_watchpoint: | |
112e8700 | 10702 | uiout->text ("Watchpoint "); |
46b9c129 | 10703 | tuple_name = "wpt"; |
348d480f PA |
10704 | break; |
10705 | case bp_hardware_watchpoint: | |
112e8700 | 10706 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10707 | tuple_name = "wpt"; |
348d480f PA |
10708 | break; |
10709 | case bp_read_watchpoint: | |
112e8700 | 10710 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10711 | tuple_name = "hw-rwpt"; |
348d480f PA |
10712 | break; |
10713 | case bp_access_watchpoint: | |
112e8700 | 10714 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10715 | tuple_name = "hw-awpt"; |
348d480f PA |
10716 | break; |
10717 | default: | |
10718 | internal_error (__FILE__, __LINE__, | |
10719 | _("Invalid hardware watchpoint type.")); | |
10720 | } | |
10721 | ||
46b9c129 | 10722 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10723 | uiout->field_int ("number", b->number); |
10724 | uiout->text (": "); | |
10725 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10726 | } |
10727 | ||
10728 | /* Implement the "print_recreate" breakpoint_ops method for | |
10729 | watchpoints. */ | |
10730 | ||
10731 | static void | |
10732 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10733 | { | |
3a5c3e22 PA |
10734 | struct watchpoint *w = (struct watchpoint *) b; |
10735 | ||
348d480f PA |
10736 | switch (b->type) |
10737 | { | |
10738 | case bp_watchpoint: | |
10739 | case bp_hardware_watchpoint: | |
10740 | fprintf_unfiltered (fp, "watch"); | |
10741 | break; | |
10742 | case bp_read_watchpoint: | |
10743 | fprintf_unfiltered (fp, "rwatch"); | |
10744 | break; | |
10745 | case bp_access_watchpoint: | |
10746 | fprintf_unfiltered (fp, "awatch"); | |
10747 | break; | |
10748 | default: | |
10749 | internal_error (__FILE__, __LINE__, | |
10750 | _("Invalid watchpoint type.")); | |
10751 | } | |
10752 | ||
3a5c3e22 | 10753 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10754 | print_recreate_thread (b, fp); |
348d480f PA |
10755 | } |
10756 | ||
427cd150 TT |
10757 | /* Implement the "explains_signal" breakpoint_ops method for |
10758 | watchpoints. */ | |
10759 | ||
47591c29 | 10760 | static int |
427cd150 TT |
10761 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10762 | { | |
10763 | /* A software watchpoint cannot cause a signal other than | |
10764 | GDB_SIGNAL_TRAP. */ | |
10765 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10766 | return 0; |
427cd150 | 10767 | |
47591c29 | 10768 | return 1; |
427cd150 TT |
10769 | } |
10770 | ||
348d480f PA |
10771 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10772 | ||
2060206e | 10773 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10774 | |
10775 | /* Implement the "insert" breakpoint_ops method for | |
10776 | masked hardware watchpoints. */ | |
10777 | ||
10778 | static int | |
10779 | insert_masked_watchpoint (struct bp_location *bl) | |
10780 | { | |
3a5c3e22 PA |
10781 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10782 | ||
10783 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10784 | bl->watchpoint_type); |
10785 | } | |
10786 | ||
10787 | /* Implement the "remove" breakpoint_ops method for | |
10788 | masked hardware watchpoints. */ | |
10789 | ||
10790 | static int | |
73971819 | 10791 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10792 | { |
3a5c3e22 PA |
10793 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10794 | ||
10795 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10796 | bl->watchpoint_type); |
10797 | } | |
10798 | ||
10799 | /* Implement the "resources_needed" breakpoint_ops method for | |
10800 | masked hardware watchpoints. */ | |
10801 | ||
10802 | static int | |
10803 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10804 | { | |
3a5c3e22 PA |
10805 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10806 | ||
10807 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10808 | } |
10809 | ||
10810 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10811 | masked hardware watchpoints. */ | |
10812 | ||
10813 | static int | |
10814 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10815 | { | |
10816 | return 0; | |
10817 | } | |
10818 | ||
10819 | /* Implement the "print_it" breakpoint_ops method for | |
10820 | masked hardware watchpoints. */ | |
10821 | ||
10822 | static enum print_stop_action | |
10823 | print_it_masked_watchpoint (bpstat bs) | |
10824 | { | |
10825 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10826 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10827 | |
10828 | /* Masked watchpoints have only one location. */ | |
10829 | gdb_assert (b->loc && b->loc->next == NULL); | |
10830 | ||
f303dbd6 PA |
10831 | annotate_watchpoint (b->number); |
10832 | maybe_print_thread_hit_breakpoint (uiout); | |
10833 | ||
348d480f PA |
10834 | switch (b->type) |
10835 | { | |
10836 | case bp_hardware_watchpoint: | |
112e8700 SM |
10837 | if (uiout->is_mi_like_p ()) |
10838 | uiout->field_string | |
10839 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10840 | break; |
10841 | ||
10842 | case bp_read_watchpoint: | |
112e8700 SM |
10843 | if (uiout->is_mi_like_p ()) |
10844 | uiout->field_string | |
10845 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10846 | break; |
10847 | ||
10848 | case bp_access_watchpoint: | |
112e8700 SM |
10849 | if (uiout->is_mi_like_p ()) |
10850 | uiout->field_string | |
10851 | ("reason", | |
348d480f PA |
10852 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10853 | break; | |
10854 | default: | |
10855 | internal_error (__FILE__, __LINE__, | |
10856 | _("Invalid hardware watchpoint type.")); | |
10857 | } | |
10858 | ||
10859 | mention (b); | |
112e8700 | 10860 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10861 | Check the underlying instruction at PC for the memory\n\ |
10862 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10863 | uiout->text ("\n"); |
9c06b0b4 TJB |
10864 | |
10865 | /* More than one watchpoint may have been triggered. */ | |
10866 | return PRINT_UNKNOWN; | |
10867 | } | |
10868 | ||
10869 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10870 | masked hardware watchpoints. */ | |
10871 | ||
10872 | static void | |
10873 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10874 | struct ui_out *uiout) | |
10875 | { | |
3a5c3e22 PA |
10876 | struct watchpoint *w = (struct watchpoint *) b; |
10877 | ||
9c06b0b4 TJB |
10878 | /* Masked watchpoints have only one location. */ |
10879 | gdb_assert (b->loc && b->loc->next == NULL); | |
10880 | ||
112e8700 SM |
10881 | uiout->text ("\tmask "); |
10882 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10883 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10884 | } |
10885 | ||
10886 | /* Implement the "print_mention" breakpoint_ops method for | |
10887 | masked hardware watchpoints. */ | |
10888 | ||
10889 | static void | |
10890 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10891 | { | |
3a5c3e22 | 10892 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10893 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10894 | const char *tuple_name; |
9c06b0b4 TJB |
10895 | |
10896 | switch (b->type) | |
10897 | { | |
10898 | case bp_hardware_watchpoint: | |
112e8700 | 10899 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10900 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10901 | break; |
10902 | case bp_read_watchpoint: | |
112e8700 | 10903 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10904 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10905 | break; |
10906 | case bp_access_watchpoint: | |
112e8700 | 10907 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10908 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10909 | break; |
10910 | default: | |
10911 | internal_error (__FILE__, __LINE__, | |
10912 | _("Invalid hardware watchpoint type.")); | |
10913 | } | |
10914 | ||
46b9c129 | 10915 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10916 | uiout->field_int ("number", b->number); |
10917 | uiout->text (": "); | |
10918 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10919 | } |
10920 | ||
10921 | /* Implement the "print_recreate" breakpoint_ops method for | |
10922 | masked hardware watchpoints. */ | |
10923 | ||
10924 | static void | |
10925 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10926 | { | |
3a5c3e22 | 10927 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10928 | char tmp[40]; |
10929 | ||
10930 | switch (b->type) | |
10931 | { | |
10932 | case bp_hardware_watchpoint: | |
10933 | fprintf_unfiltered (fp, "watch"); | |
10934 | break; | |
10935 | case bp_read_watchpoint: | |
10936 | fprintf_unfiltered (fp, "rwatch"); | |
10937 | break; | |
10938 | case bp_access_watchpoint: | |
10939 | fprintf_unfiltered (fp, "awatch"); | |
10940 | break; | |
10941 | default: | |
10942 | internal_error (__FILE__, __LINE__, | |
10943 | _("Invalid hardware watchpoint type.")); | |
10944 | } | |
10945 | ||
3a5c3e22 PA |
10946 | sprintf_vma (tmp, w->hw_wp_mask); |
10947 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10948 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10949 | } |
10950 | ||
10951 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10952 | ||
2060206e | 10953 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10954 | |
10955 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10956 | ||
10957 | static int | |
10958 | is_masked_watchpoint (const struct breakpoint *b) | |
10959 | { | |
10960 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10961 | } | |
10962 | ||
53a5351d JM |
10963 | /* accessflag: hw_write: watch write, |
10964 | hw_read: watch read, | |
10965 | hw_access: watch access (read or write) */ | |
c906108c | 10966 | static void |
bbc13ae3 | 10967 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10968 | int just_location, int internal) |
c906108c | 10969 | { |
c1fc2657 | 10970 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10971 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10972 | struct value *val, *mark, *result; |
bb9d5f81 | 10973 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10974 | const char *exp_start = NULL; |
10975 | const char *exp_end = NULL; | |
10976 | const char *tok, *end_tok; | |
9c06b0b4 | 10977 | int toklen = -1; |
bbc13ae3 KS |
10978 | const char *cond_start = NULL; |
10979 | const char *cond_end = NULL; | |
c906108c | 10980 | enum bptype bp_type; |
37e4754d | 10981 | int thread = -1; |
0cf6dd15 | 10982 | int pc = 0; |
9c06b0b4 TJB |
10983 | /* Flag to indicate whether we are going to use masks for |
10984 | the hardware watchpoint. */ | |
10985 | int use_mask = 0; | |
10986 | CORE_ADDR mask = 0; | |
3a5c3e22 | 10987 | struct watchpoint *w; |
bbc13ae3 KS |
10988 | char *expression; |
10989 | struct cleanup *back_to; | |
c906108c | 10990 | |
37e4754d LM |
10991 | /* Make sure that we actually have parameters to parse. */ |
10992 | if (arg != NULL && arg[0] != '\0') | |
10993 | { | |
bbc13ae3 KS |
10994 | const char *value_start; |
10995 | ||
10996 | exp_end = arg + strlen (arg); | |
37e4754d | 10997 | |
9c06b0b4 TJB |
10998 | /* Look for "parameter value" pairs at the end |
10999 | of the arguments string. */ | |
bbc13ae3 | 11000 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11001 | { |
11002 | /* Skip whitespace at the end of the argument list. */ | |
11003 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11004 | tok--; | |
11005 | ||
11006 | /* Find the beginning of the last token. | |
11007 | This is the value of the parameter. */ | |
11008 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11009 | tok--; | |
11010 | value_start = tok + 1; | |
11011 | ||
11012 | /* Skip whitespace. */ | |
11013 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11014 | tok--; | |
11015 | ||
11016 | end_tok = tok; | |
11017 | ||
11018 | /* Find the beginning of the second to last token. | |
11019 | This is the parameter itself. */ | |
11020 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11021 | tok--; | |
11022 | tok++; | |
11023 | toklen = end_tok - tok + 1; | |
11024 | ||
61012eef | 11025 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11026 | { |
5d5658a1 | 11027 | struct thread_info *thr; |
9c06b0b4 TJB |
11028 | /* At this point we've found a "thread" token, which means |
11029 | the user is trying to set a watchpoint that triggers | |
11030 | only in a specific thread. */ | |
5d5658a1 | 11031 | const char *endp; |
37e4754d | 11032 | |
9c06b0b4 TJB |
11033 | if (thread != -1) |
11034 | error(_("You can specify only one thread.")); | |
37e4754d | 11035 | |
9c06b0b4 | 11036 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11037 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11038 | |
5d5658a1 | 11039 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11040 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11041 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11042 | |
5d5658a1 | 11043 | thread = thr->global_num; |
9c06b0b4 | 11044 | } |
61012eef | 11045 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11046 | { |
11047 | /* We've found a "mask" token, which means the user wants to | |
11048 | create a hardware watchpoint that is going to have the mask | |
11049 | facility. */ | |
11050 | struct value *mask_value, *mark; | |
37e4754d | 11051 | |
9c06b0b4 TJB |
11052 | if (use_mask) |
11053 | error(_("You can specify only one mask.")); | |
37e4754d | 11054 | |
9c06b0b4 | 11055 | use_mask = just_location = 1; |
37e4754d | 11056 | |
9c06b0b4 TJB |
11057 | mark = value_mark (); |
11058 | mask_value = parse_to_comma_and_eval (&value_start); | |
11059 | mask = value_as_address (mask_value); | |
11060 | value_free_to_mark (mark); | |
11061 | } | |
11062 | else | |
11063 | /* We didn't recognize what we found. We should stop here. */ | |
11064 | break; | |
37e4754d | 11065 | |
9c06b0b4 TJB |
11066 | /* Truncate the string and get rid of the "parameter value" pair before |
11067 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11068 | exp_end = tok; |
9c06b0b4 | 11069 | } |
37e4754d | 11070 | } |
bbc13ae3 KS |
11071 | else |
11072 | exp_end = arg; | |
37e4754d | 11073 | |
bbc13ae3 KS |
11074 | /* Parse the rest of the arguments. From here on out, everything |
11075 | is in terms of a newly allocated string instead of the original | |
11076 | ARG. */ | |
c906108c | 11077 | innermost_block = NULL; |
bbc13ae3 KS |
11078 | expression = savestring (arg, exp_end - arg); |
11079 | back_to = make_cleanup (xfree, expression); | |
11080 | exp_start = arg = expression; | |
4d01a485 | 11081 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11082 | exp_end = arg; |
fa8a61dc TT |
11083 | /* Remove trailing whitespace from the expression before saving it. |
11084 | This makes the eventual display of the expression string a bit | |
11085 | prettier. */ | |
11086 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11087 | --exp_end; | |
11088 | ||
65d79d4b | 11089 | /* Checking if the expression is not constant. */ |
4d01a485 | 11090 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
11091 | { |
11092 | int len; | |
11093 | ||
11094 | len = exp_end - exp_start; | |
11095 | while (len > 0 && isspace (exp_start[len - 1])) | |
11096 | len--; | |
11097 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11098 | } | |
11099 | ||
c906108c SS |
11100 | exp_valid_block = innermost_block; |
11101 | mark = value_mark (); | |
4d01a485 | 11102 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 11103 | |
bb9d5f81 PP |
11104 | if (val != NULL && just_location) |
11105 | { | |
11106 | saved_bitpos = value_bitpos (val); | |
11107 | saved_bitsize = value_bitsize (val); | |
11108 | } | |
11109 | ||
06a64a0b TT |
11110 | if (just_location) |
11111 | { | |
9c06b0b4 TJB |
11112 | int ret; |
11113 | ||
06a64a0b | 11114 | exp_valid_block = NULL; |
a1442452 | 11115 | val = value_addr (result); |
06a64a0b TT |
11116 | release_value (val); |
11117 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11118 | |
11119 | if (use_mask) | |
11120 | { | |
11121 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11122 | mask); | |
11123 | if (ret == -1) | |
11124 | error (_("This target does not support masked watchpoints.")); | |
11125 | else if (ret == -2) | |
11126 | error (_("Invalid mask or memory region.")); | |
11127 | } | |
06a64a0b TT |
11128 | } |
11129 | else if (val != NULL) | |
fa4727a6 | 11130 | release_value (val); |
c906108c | 11131 | |
bbc13ae3 KS |
11132 | tok = skip_spaces_const (arg); |
11133 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11134 | |
11135 | toklen = end_tok - tok; | |
11136 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11137 | { | |
60e1c644 | 11138 | innermost_block = NULL; |
c906108c | 11139 | tok = cond_start = end_tok + 1; |
4d01a485 | 11140 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11141 | |
11142 | /* The watchpoint expression may not be local, but the condition | |
11143 | may still be. E.g.: `watch global if local > 0'. */ | |
11144 | cond_exp_valid_block = innermost_block; | |
11145 | ||
c906108c SS |
11146 | cond_end = tok; |
11147 | } | |
11148 | if (*tok) | |
8a3fe4f8 | 11149 | error (_("Junk at end of command.")); |
c906108c | 11150 | |
441d7c93 PA |
11151 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
11152 | ||
11153 | /* Save this because create_internal_breakpoint below invalidates | |
11154 | 'wp_frame'. */ | |
11155 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
11156 | |
11157 | /* If the expression is "local", then set up a "watchpoint scope" | |
11158 | breakpoint at the point where we've left the scope of the watchpoint | |
11159 | expression. Create the scope breakpoint before the watchpoint, so | |
11160 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 11161 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 11162 | { |
441d7c93 PA |
11163 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
11164 | ||
11165 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 11166 | { |
441d7c93 PA |
11167 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
11168 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
11169 | ||
edb3359d | 11170 | scope_breakpoint |
441d7c93 | 11171 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
11172 | bp_watchpoint_scope, |
11173 | &momentary_breakpoint_ops); | |
d983da9c | 11174 | |
441d7c93 PA |
11175 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
11176 | wp_frame = NULL; | |
11177 | ||
edb3359d | 11178 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11179 | |
edb3359d DJ |
11180 | /* Automatically delete the breakpoint when it hits. */ |
11181 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11182 | |
edb3359d | 11183 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 11184 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 11185 | |
edb3359d | 11186 | /* Set the address at which we will stop. */ |
441d7c93 PA |
11187 | scope_breakpoint->loc->gdbarch = caller_arch; |
11188 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 11189 | scope_breakpoint->loc->address |
a6d9a66e UW |
11190 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11191 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11192 | scope_breakpoint->type); |
11193 | } | |
d983da9c DJ |
11194 | } |
11195 | ||
e8369a73 AB |
11196 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11197 | watchpoints here even if hardware watchpoints are turned off, a call | |
11198 | to update_watchpoint later in this function will cause the type to | |
11199 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11200 | ||
11201 | if (accessflag == hw_read) | |
11202 | bp_type = bp_read_watchpoint; | |
11203 | else if (accessflag == hw_access) | |
11204 | bp_type = bp_access_watchpoint; | |
11205 | else | |
11206 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 11207 | |
4d01a485 | 11208 | w = new watchpoint (); |
c1fc2657 | 11209 | |
348d480f | 11210 | if (use_mask) |
c1fc2657 | 11211 | init_raw_breakpoint_without_location (w, NULL, bp_type, |
3a5c3e22 | 11212 | &masked_watchpoint_breakpoint_ops); |
348d480f | 11213 | else |
c1fc2657 | 11214 | init_raw_breakpoint_without_location (w, NULL, bp_type, |
3a5c3e22 | 11215 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
11216 | w->thread = thread; |
11217 | w->disposition = disp_donttouch; | |
11218 | w->pspace = current_program_space; | |
b22e99fd | 11219 | w->exp = std::move (exp); |
3a5c3e22 PA |
11220 | w->exp_valid_block = exp_valid_block; |
11221 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11222 | if (just_location) |
11223 | { | |
11224 | struct type *t = value_type (val); | |
11225 | CORE_ADDR addr = value_as_address (val); | |
06a64a0b | 11226 | |
43cc5389 TT |
11227 | w->exp_string_reparse |
11228 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 11229 | |
3a5c3e22 | 11230 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 11231 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
11232 | } |
11233 | else | |
3a5c3e22 | 11234 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11235 | |
11236 | if (use_mask) | |
11237 | { | |
3a5c3e22 | 11238 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11239 | } |
11240 | else | |
11241 | { | |
3a5c3e22 | 11242 | w->val = val; |
bb9d5f81 PP |
11243 | w->val_bitpos = saved_bitpos; |
11244 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11245 | w->val_valid = 1; |
9c06b0b4 | 11246 | } |
77b06cd7 | 11247 | |
c906108c | 11248 | if (cond_start) |
c1fc2657 | 11249 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 11250 | else |
c1fc2657 | 11251 | w->cond_string = 0; |
c5aa993b | 11252 | |
441d7c93 | 11253 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 11254 | { |
441d7c93 | 11255 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 11256 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 11257 | } |
c906108c | 11258 | else |
f6bc2008 | 11259 | { |
3a5c3e22 PA |
11260 | w->watchpoint_frame = null_frame_id; |
11261 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11262 | } |
c906108c | 11263 | |
d983da9c | 11264 | if (scope_breakpoint != NULL) |
c906108c | 11265 | { |
d983da9c DJ |
11266 | /* The scope breakpoint is related to the watchpoint. We will |
11267 | need to act on them together. */ | |
c1fc2657 SM |
11268 | w->related_breakpoint = scope_breakpoint; |
11269 | scope_breakpoint->related_breakpoint = w; | |
c906108c | 11270 | } |
d983da9c | 11271 | |
06a64a0b TT |
11272 | if (!just_location) |
11273 | value_free_to_mark (mark); | |
2d134ed3 | 11274 | |
492d29ea | 11275 | TRY |
a9634178 TJB |
11276 | { |
11277 | /* Finally update the new watchpoint. This creates the locations | |
11278 | that should be inserted. */ | |
3a5c3e22 | 11279 | update_watchpoint (w, 1); |
a9634178 | 11280 | } |
492d29ea | 11281 | CATCH (e, RETURN_MASK_ALL) |
a9634178 | 11282 | { |
c1fc2657 | 11283 | delete_breakpoint (w); |
a9634178 TJB |
11284 | throw_exception (e); |
11285 | } | |
492d29ea | 11286 | END_CATCH |
a9634178 | 11287 | |
c1fc2657 | 11288 | install_breakpoint (internal, w, 1); |
bbc13ae3 | 11289 | do_cleanups (back_to); |
c906108c SS |
11290 | } |
11291 | ||
e09342b5 | 11292 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11293 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11294 | |
c906108c | 11295 | static int |
a9634178 | 11296 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11297 | { |
11298 | int found_memory_cnt = 0; | |
2e70b7b9 | 11299 | struct value *head = v; |
c906108c SS |
11300 | |
11301 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11302 | if (!can_use_hw_watchpoints) |
c906108c | 11303 | return 0; |
c5aa993b | 11304 | |
5c44784c JM |
11305 | /* Make sure that the value of the expression depends only upon |
11306 | memory contents, and values computed from them within GDB. If we | |
11307 | find any register references or function calls, we can't use a | |
11308 | hardware watchpoint. | |
11309 | ||
11310 | The idea here is that evaluating an expression generates a series | |
11311 | of values, one holding the value of every subexpression. (The | |
11312 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11313 | a*b+c.) GDB's values hold almost enough information to establish | |
11314 | the criteria given above --- they identify memory lvalues, | |
11315 | register lvalues, computed values, etcetera. So we can evaluate | |
11316 | the expression, and then scan the chain of values that leaves | |
11317 | behind to decide whether we can detect any possible change to the | |
11318 | expression's final value using only hardware watchpoints. | |
11319 | ||
11320 | However, I don't think that the values returned by inferior | |
11321 | function calls are special in any way. So this function may not | |
11322 | notice that an expression involving an inferior function call | |
11323 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11324 | for (; v; v = value_next (v)) |
c906108c | 11325 | { |
5c44784c | 11326 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11327 | { |
8464be76 DJ |
11328 | if (v != head && value_lazy (v)) |
11329 | /* A lazy memory lvalue in the chain is one that GDB never | |
11330 | needed to fetch; we either just used its address (e.g., | |
11331 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11332 | in `a,b'). This doesn't apply to HEAD; if that is | |
11333 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11334 | ; |
53a5351d | 11335 | else |
5c44784c JM |
11336 | { |
11337 | /* Ahh, memory we actually used! Check if we can cover | |
11338 | it with hardware watchpoints. */ | |
df407dfe | 11339 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11340 | |
11341 | /* We only watch structs and arrays if user asked for it | |
11342 | explicitly, never if they just happen to appear in a | |
11343 | middle of some value chain. */ | |
11344 | if (v == head | |
11345 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11346 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11347 | { | |
42ae5230 | 11348 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11349 | int len; |
11350 | int num_regs; | |
11351 | ||
a9634178 | 11352 | len = (target_exact_watchpoints |
e09342b5 TJB |
11353 | && is_scalar_type_recursive (vtype))? |
11354 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11355 | |
e09342b5 TJB |
11356 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11357 | if (!num_regs) | |
2e70b7b9 MS |
11358 | return 0; |
11359 | else | |
e09342b5 | 11360 | found_memory_cnt += num_regs; |
2e70b7b9 | 11361 | } |
5c44784c | 11362 | } |
c5aa993b | 11363 | } |
5086187c AC |
11364 | else if (VALUE_LVAL (v) != not_lval |
11365 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11366 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11367 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11368 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11369 | } |
11370 | ||
11371 | /* The expression itself looks suitable for using a hardware | |
11372 | watchpoint, but give the target machine a chance to reject it. */ | |
11373 | return found_memory_cnt; | |
11374 | } | |
11375 | ||
8b93c638 | 11376 | void |
84f4c1fe | 11377 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11378 | { |
84f4c1fe | 11379 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11380 | } |
11381 | ||
06a64a0b TT |
11382 | /* A helper function that looks for the "-location" argument and then |
11383 | calls watch_command_1. */ | |
11384 | ||
11385 | static void | |
11386 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11387 | { | |
11388 | int just_location = 0; | |
11389 | ||
11390 | if (arg | |
11391 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11392 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11393 | { | |
e9cafbcc | 11394 | arg = skip_spaces (arg); |
06a64a0b TT |
11395 | just_location = 1; |
11396 | } | |
11397 | ||
84f4c1fe | 11398 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11399 | } |
8926118c | 11400 | |
c5aa993b | 11401 | static void |
fba45db2 | 11402 | watch_command (char *arg, int from_tty) |
c906108c | 11403 | { |
06a64a0b | 11404 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11405 | } |
11406 | ||
8b93c638 | 11407 | void |
84f4c1fe | 11408 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11409 | { |
84f4c1fe | 11410 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11411 | } |
8926118c | 11412 | |
c5aa993b | 11413 | static void |
fba45db2 | 11414 | rwatch_command (char *arg, int from_tty) |
c906108c | 11415 | { |
06a64a0b | 11416 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11417 | } |
11418 | ||
8b93c638 | 11419 | void |
84f4c1fe | 11420 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11421 | { |
84f4c1fe | 11422 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11423 | } |
8926118c | 11424 | |
c5aa993b | 11425 | static void |
fba45db2 | 11426 | awatch_command (char *arg, int from_tty) |
c906108c | 11427 | { |
06a64a0b | 11428 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11429 | } |
c906108c | 11430 | \f |
c5aa993b | 11431 | |
cfc31633 PA |
11432 | /* Data for the FSM that manages the until(location)/advance commands |
11433 | in infcmd.c. Here because it uses the mechanisms of | |
11434 | breakpoints. */ | |
c906108c | 11435 | |
cfc31633 | 11436 | struct until_break_fsm |
bfec99b2 | 11437 | { |
cfc31633 PA |
11438 | /* The base class. */ |
11439 | struct thread_fsm thread_fsm; | |
11440 | ||
11441 | /* The thread that as current when the command was executed. */ | |
11442 | int thread; | |
11443 | ||
11444 | /* The breakpoint set at the destination location. */ | |
11445 | struct breakpoint *location_breakpoint; | |
11446 | ||
11447 | /* Breakpoint set at the return address in the caller frame. May be | |
11448 | NULL. */ | |
11449 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11450 | }; |
11451 | ||
8980e177 PA |
11452 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11453 | struct thread_info *thread); | |
11454 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11455 | struct thread_info *thread); | |
cfc31633 PA |
11456 | static enum async_reply_reason |
11457 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11458 | ||
11459 | /* until_break_fsm's vtable. */ | |
11460 | ||
11461 | static struct thread_fsm_ops until_break_fsm_ops = | |
11462 | { | |
11463 | NULL, /* dtor */ | |
11464 | until_break_fsm_clean_up, | |
11465 | until_break_fsm_should_stop, | |
11466 | NULL, /* return_value */ | |
11467 | until_break_fsm_async_reply_reason, | |
11468 | }; | |
11469 | ||
11470 | /* Allocate a new until_break_command_fsm. */ | |
11471 | ||
11472 | static struct until_break_fsm * | |
8980e177 | 11473 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11474 | struct breakpoint *location_breakpoint, |
11475 | struct breakpoint *caller_breakpoint) | |
11476 | { | |
11477 | struct until_break_fsm *sm; | |
11478 | ||
11479 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11480 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11481 | |
11482 | sm->thread = thread; | |
11483 | sm->location_breakpoint = location_breakpoint; | |
11484 | sm->caller_breakpoint = caller_breakpoint; | |
11485 | ||
11486 | return sm; | |
11487 | } | |
11488 | ||
11489 | /* Implementation of the 'should_stop' FSM method for the | |
11490 | until(location)/advance commands. */ | |
11491 | ||
11492 | static int | |
8980e177 PA |
11493 | until_break_fsm_should_stop (struct thread_fsm *self, |
11494 | struct thread_info *tp) | |
cfc31633 PA |
11495 | { |
11496 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11497 | |
11498 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11499 | sm->location_breakpoint) != NULL | |
11500 | || (sm->caller_breakpoint != NULL | |
11501 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11502 | sm->caller_breakpoint) != NULL)) | |
11503 | thread_fsm_set_finished (self); | |
11504 | ||
11505 | return 1; | |
11506 | } | |
11507 | ||
11508 | /* Implementation of the 'clean_up' FSM method for the | |
11509 | until(location)/advance commands. */ | |
11510 | ||
c2c6d25f | 11511 | static void |
8980e177 PA |
11512 | until_break_fsm_clean_up (struct thread_fsm *self, |
11513 | struct thread_info *thread) | |
43ff13b4 | 11514 | { |
cfc31633 | 11515 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11516 | |
cfc31633 PA |
11517 | /* Clean up our temporary breakpoints. */ |
11518 | if (sm->location_breakpoint != NULL) | |
11519 | { | |
11520 | delete_breakpoint (sm->location_breakpoint); | |
11521 | sm->location_breakpoint = NULL; | |
11522 | } | |
11523 | if (sm->caller_breakpoint != NULL) | |
11524 | { | |
11525 | delete_breakpoint (sm->caller_breakpoint); | |
11526 | sm->caller_breakpoint = NULL; | |
11527 | } | |
11528 | delete_longjmp_breakpoint (sm->thread); | |
11529 | } | |
11530 | ||
11531 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11532 | until(location)/advance commands. */ | |
11533 | ||
11534 | static enum async_reply_reason | |
11535 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11536 | { | |
11537 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11538 | } |
11539 | ||
c906108c | 11540 | void |
ae66c1fc | 11541 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11542 | { |
11543 | struct symtabs_and_lines sals; | |
11544 | struct symtab_and_line sal; | |
8556afb4 PA |
11545 | struct frame_info *frame; |
11546 | struct gdbarch *frame_gdbarch; | |
11547 | struct frame_id stack_frame_id; | |
11548 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11549 | struct breakpoint *location_breakpoint; |
11550 | struct breakpoint *caller_breakpoint = NULL; | |
ffc2605c | 11551 | struct cleanup *old_chain; |
186c406b TT |
11552 | int thread; |
11553 | struct thread_info *tp; | |
cfc31633 | 11554 | struct until_break_fsm *sm; |
c906108c | 11555 | |
70509625 | 11556 | clear_proceed_status (0); |
c906108c SS |
11557 | |
11558 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11559 | this function. */ |
c5aa993b | 11560 | |
ffc2605c | 11561 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11562 | |
1bfeeb0f | 11563 | if (last_displayed_sal_is_valid ()) |
ffc2605c | 11564 | sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11565 | get_last_displayed_symtab (), |
f8eba3c6 | 11566 | get_last_displayed_line ()); |
c906108c | 11567 | else |
ffc2605c | 11568 | sals = decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11569 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11570 | |
c906108c | 11571 | if (sals.nelts != 1) |
8a3fe4f8 | 11572 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11573 | |
c906108c | 11574 | sal = sals.sals[0]; |
4a64f543 | 11575 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11576 | |
c906108c | 11577 | if (*arg) |
8a3fe4f8 | 11578 | error (_("Junk at end of arguments.")); |
c5aa993b | 11579 | |
c906108c | 11580 | resolve_sal_pc (&sal); |
c5aa993b | 11581 | |
186c406b | 11582 | tp = inferior_thread (); |
5d5658a1 | 11583 | thread = tp->global_num; |
186c406b | 11584 | |
883bc8d1 PA |
11585 | old_chain = make_cleanup (null_cleanup, NULL); |
11586 | ||
8556afb4 PA |
11587 | /* Note linespec handling above invalidates the frame chain. |
11588 | Installing a breakpoint also invalidates the frame chain (as it | |
11589 | may need to switch threads), so do any frame handling before | |
11590 | that. */ | |
11591 | ||
11592 | frame = get_selected_frame (NULL); | |
11593 | frame_gdbarch = get_frame_arch (frame); | |
11594 | stack_frame_id = get_stack_frame_id (frame); | |
11595 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11596 | |
ae66c1fc EZ |
11597 | /* Keep within the current frame, or in frames called by the current |
11598 | one. */ | |
edb3359d | 11599 | |
883bc8d1 | 11600 | if (frame_id_p (caller_frame_id)) |
c906108c | 11601 | { |
883bc8d1 | 11602 | struct symtab_and_line sal2; |
cfc31633 | 11603 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11604 | |
11605 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11606 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11607 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11608 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11609 | sal2, | |
11610 | caller_frame_id, | |
11611 | bp_until); | |
11612 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11613 | |
883bc8d1 | 11614 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11615 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11616 | } |
c5aa993b | 11617 | |
c70a6932 JK |
11618 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11619 | frame = NULL; | |
11620 | ||
883bc8d1 PA |
11621 | if (anywhere) |
11622 | /* If the user told us to continue until a specified location, | |
11623 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11624 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11625 | null_frame_id, bp_until); | |
883bc8d1 PA |
11626 | else |
11627 | /* Otherwise, specify the selected frame, because we want to stop | |
11628 | only at the very same frame. */ | |
cfc31633 PA |
11629 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11630 | stack_frame_id, bp_until); | |
11631 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11632 | |
8980e177 | 11633 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11634 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11635 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11636 | |
cfc31633 | 11637 | discard_cleanups (old_chain); |
f107f563 | 11638 | |
cfc31633 | 11639 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11640 | } |
ae66c1fc | 11641 | |
c906108c SS |
11642 | /* This function attempts to parse an optional "if <cond>" clause |
11643 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11644 | |
c906108c SS |
11645 | Else, it returns a pointer to the condition string. (It does not |
11646 | attempt to evaluate the string against a particular block.) And, | |
11647 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11648 | if clause in the arg string. */ |
53a5351d | 11649 | |
63160a43 PA |
11650 | const char * |
11651 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11652 | { |
63160a43 | 11653 | const char *cond_string; |
c5aa993b JM |
11654 | |
11655 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11656 | return NULL; |
c5aa993b | 11657 | |
4a64f543 | 11658 | /* Skip the "if" keyword. */ |
c906108c | 11659 | (*arg) += 2; |
c5aa993b | 11660 | |
c906108c | 11661 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11662 | condition string. */ |
63160a43 | 11663 | *arg = skip_spaces_const (*arg); |
c906108c | 11664 | cond_string = *arg; |
c5aa993b | 11665 | |
4a64f543 MS |
11666 | /* Assume that the condition occupies the remainder of the arg |
11667 | string. */ | |
c906108c | 11668 | (*arg) += strlen (cond_string); |
c5aa993b | 11669 | |
c906108c SS |
11670 | return cond_string; |
11671 | } | |
c5aa993b | 11672 | |
c906108c SS |
11673 | /* Commands to deal with catching events, such as signals, exceptions, |
11674 | process start/exit, etc. */ | |
c5aa993b JM |
11675 | |
11676 | typedef enum | |
11677 | { | |
44feb3ce TT |
11678 | catch_fork_temporary, catch_vfork_temporary, |
11679 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11680 | } |
11681 | catch_fork_kind; | |
11682 | ||
c906108c | 11683 | static void |
63160a43 | 11684 | catch_fork_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11685 | struct cmd_list_element *command) |
c906108c | 11686 | { |
63160a43 | 11687 | const char *arg = arg_entry; |
a6d9a66e | 11688 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11689 | const char *cond_string = NULL; |
44feb3ce TT |
11690 | catch_fork_kind fork_kind; |
11691 | int tempflag; | |
11692 | ||
11693 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11694 | tempflag = (fork_kind == catch_fork_temporary | |
11695 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11696 | |
44feb3ce TT |
11697 | if (!arg) |
11698 | arg = ""; | |
63160a43 | 11699 | arg = skip_spaces_const (arg); |
c5aa993b | 11700 | |
c906108c | 11701 | /* The allowed syntax is: |
c5aa993b JM |
11702 | catch [v]fork |
11703 | catch [v]fork if <cond> | |
11704 | ||
4a64f543 | 11705 | First, check if there's an if clause. */ |
c906108c | 11706 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11707 | |
c906108c | 11708 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11709 | error (_("Junk at end of arguments.")); |
c5aa993b | 11710 | |
c906108c | 11711 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11712 | and enable reporting of such events. */ |
c5aa993b JM |
11713 | switch (fork_kind) |
11714 | { | |
44feb3ce TT |
11715 | case catch_fork_temporary: |
11716 | case catch_fork_permanent: | |
a6d9a66e | 11717 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11718 | &catch_fork_breakpoint_ops); |
c906108c | 11719 | break; |
44feb3ce TT |
11720 | case catch_vfork_temporary: |
11721 | case catch_vfork_permanent: | |
a6d9a66e | 11722 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11723 | &catch_vfork_breakpoint_ops); |
c906108c | 11724 | break; |
c5aa993b | 11725 | default: |
8a3fe4f8 | 11726 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11727 | break; |
c5aa993b | 11728 | } |
c906108c SS |
11729 | } |
11730 | ||
11731 | static void | |
63160a43 | 11732 | catch_exec_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11733 | struct cmd_list_element *command) |
c906108c | 11734 | { |
63160a43 | 11735 | const char *arg = arg_entry; |
b4d90040 | 11736 | struct exec_catchpoint *c; |
a6d9a66e | 11737 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11738 | int tempflag; |
63160a43 | 11739 | const char *cond_string = NULL; |
c906108c | 11740 | |
44feb3ce TT |
11741 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11742 | ||
11743 | if (!arg) | |
11744 | arg = ""; | |
63160a43 | 11745 | arg = skip_spaces_const (arg); |
c906108c SS |
11746 | |
11747 | /* The allowed syntax is: | |
c5aa993b JM |
11748 | catch exec |
11749 | catch exec if <cond> | |
c906108c | 11750 | |
4a64f543 | 11751 | First, check if there's an if clause. */ |
c906108c SS |
11752 | cond_string = ep_parse_optional_if_clause (&arg); |
11753 | ||
11754 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11755 | error (_("Junk at end of arguments.")); |
c906108c | 11756 | |
4d01a485 | 11757 | c = new exec_catchpoint (); |
c1fc2657 | 11758 | init_catchpoint (c, gdbarch, tempflag, cond_string, |
b4d90040 PA |
11759 | &catch_exec_breakpoint_ops); |
11760 | c->exec_pathname = NULL; | |
11761 | ||
c1fc2657 | 11762 | install_breakpoint (0, c, 1); |
c906108c | 11763 | } |
c5aa993b | 11764 | |
9ac4176b | 11765 | void |
28010a5d PA |
11766 | init_ada_exception_breakpoint (struct breakpoint *b, |
11767 | struct gdbarch *gdbarch, | |
11768 | struct symtab_and_line sal, | |
11769 | char *addr_string, | |
c0a91b2b | 11770 | const struct breakpoint_ops *ops, |
28010a5d | 11771 | int tempflag, |
349774ef | 11772 | int enabled, |
28010a5d | 11773 | int from_tty) |
f7f9143b | 11774 | { |
f7f9143b JB |
11775 | if (from_tty) |
11776 | { | |
5af949e3 UW |
11777 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11778 | if (!loc_gdbarch) | |
11779 | loc_gdbarch = gdbarch; | |
11780 | ||
6c95b8df PA |
11781 | describe_other_breakpoints (loc_gdbarch, |
11782 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11783 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11784 | version for exception catchpoints, because two catchpoints | |
11785 | used for different exception names will use the same address. | |
11786 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11787 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11788 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11789 | the user what type of catchpoint it is. The above is good |
11790 | enough for now, though. */ | |
11791 | } | |
11792 | ||
28010a5d | 11793 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11794 | |
349774ef | 11795 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11796 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11797 | b->location = string_to_event_location (&addr_string, |
11798 | language_def (language_ada)); | |
f7f9143b | 11799 | b->language = language_ada; |
f7f9143b JB |
11800 | } |
11801 | ||
c906108c | 11802 | static void |
fba45db2 | 11803 | catch_command (char *arg, int from_tty) |
c906108c | 11804 | { |
44feb3ce | 11805 | error (_("Catch requires an event name.")); |
c906108c SS |
11806 | } |
11807 | \f | |
11808 | ||
11809 | static void | |
fba45db2 | 11810 | tcatch_command (char *arg, int from_tty) |
c906108c | 11811 | { |
44feb3ce | 11812 | error (_("Catch requires an event name.")); |
c906108c SS |
11813 | } |
11814 | ||
8a2c437b TT |
11815 | /* A qsort comparison function that sorts breakpoints in order. */ |
11816 | ||
11817 | static int | |
11818 | compare_breakpoints (const void *a, const void *b) | |
11819 | { | |
9a3c8263 | 11820 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11821 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11822 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11823 | uintptr_t ub = (uintptr_t) *bb; |
11824 | ||
11825 | if ((*ba)->number < (*bb)->number) | |
11826 | return -1; | |
11827 | else if ((*ba)->number > (*bb)->number) | |
11828 | return 1; | |
11829 | ||
11830 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11831 | the number 0. */ | |
11832 | if (ua < ub) | |
11833 | return -1; | |
94b0e70d | 11834 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11835 | } |
11836 | ||
80f8a6eb | 11837 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11838 | |
11839 | static void | |
fba45db2 | 11840 | clear_command (char *arg, int from_tty) |
c906108c | 11841 | { |
8a2c437b | 11842 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11843 | VEC(breakpoint_p) *found = 0; |
11844 | int ix; | |
c906108c SS |
11845 | int default_match; |
11846 | struct symtabs_and_lines sals; | |
11847 | struct symtab_and_line sal; | |
c906108c | 11848 | int i; |
8a2c437b | 11849 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
11850 | |
11851 | if (arg) | |
11852 | { | |
39cf75f7 DE |
11853 | sals = decode_line_with_current_source (arg, |
11854 | (DECODE_LINE_FUNFIRSTLINE | |
11855 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 11856 | make_cleanup (xfree, sals.sals); |
c906108c SS |
11857 | default_match = 0; |
11858 | } | |
11859 | else | |
11860 | { | |
8d749320 | 11861 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 11862 | make_cleanup (xfree, sals.sals); |
4a64f543 | 11863 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
11864 | |
11865 | /* Set sal's line, symtab, pc, and pspace to the values | |
11866 | corresponding to the last call to print_frame_info. If the | |
11867 | codepoint is not valid, this will set all the fields to 0. */ | |
11868 | get_last_displayed_sal (&sal); | |
c906108c | 11869 | if (sal.symtab == 0) |
8a3fe4f8 | 11870 | error (_("No source file specified.")); |
c906108c SS |
11871 | |
11872 | sals.sals[0] = sal; | |
11873 | sals.nelts = 1; | |
11874 | ||
11875 | default_match = 1; | |
11876 | } | |
11877 | ||
4a64f543 MS |
11878 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11879 | seems, because all existing breakpoints typically have both | |
11880 | file/line and pc set. So, if clear is given file/line, we can | |
11881 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11882 | |
11883 | We only support clearing given the address explicitly | |
11884 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11885 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11886 | due to optimization, all in one block. |
4a64f543 MS |
11887 | |
11888 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11889 | PC corresponding to the same file:line, the breakpoint won't |
11890 | be cleared. We probably can still clear the breakpoint, but | |
11891 | since the other PC value is never presented to user, user | |
11892 | can only find it by guessing, and it does not seem important | |
11893 | to support that. */ | |
11894 | ||
4a64f543 MS |
11895 | /* For each line spec given, delete bps which correspond to it. Do |
11896 | it in two passes, solely to preserve the current behavior that | |
11897 | from_tty is forced true if we delete more than one | |
11898 | breakpoint. */ | |
c906108c | 11899 | |
80f8a6eb | 11900 | found = NULL; |
8a2c437b | 11901 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
11902 | for (i = 0; i < sals.nelts; i++) |
11903 | { | |
05cba821 JK |
11904 | const char *sal_fullname; |
11905 | ||
c906108c | 11906 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11907 | If line given (pc == 0), clear all bpts on specified line. |
11908 | If defaulting, clear all bpts on default line | |
c906108c | 11909 | or at default pc. |
c5aa993b JM |
11910 | |
11911 | defaulting sal.pc != 0 tests to do | |
11912 | ||
11913 | 0 1 pc | |
11914 | 1 1 pc _and_ line | |
11915 | 0 0 line | |
11916 | 1 0 <can't happen> */ | |
c906108c SS |
11917 | |
11918 | sal = sals.sals[i]; | |
05cba821 JK |
11919 | sal_fullname = (sal.symtab == NULL |
11920 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11921 | |
4a64f543 | 11922 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11923 | ALL_BREAKPOINTS (b) |
c5aa993b | 11924 | { |
0d381245 | 11925 | int match = 0; |
4a64f543 | 11926 | /* Are we going to delete b? */ |
cc60f2e3 | 11927 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11928 | { |
11929 | struct bp_location *loc = b->loc; | |
11930 | for (; loc; loc = loc->next) | |
11931 | { | |
f8eba3c6 TT |
11932 | /* If the user specified file:line, don't allow a PC |
11933 | match. This matches historical gdb behavior. */ | |
11934 | int pc_match = (!sal.explicit_line | |
11935 | && sal.pc | |
11936 | && (loc->pspace == sal.pspace) | |
11937 | && (loc->address == sal.pc) | |
11938 | && (!section_is_overlay (loc->section) | |
11939 | || loc->section == sal.section)); | |
4aac40c8 TT |
11940 | int line_match = 0; |
11941 | ||
11942 | if ((default_match || sal.explicit_line) | |
2f202fde | 11943 | && loc->symtab != NULL |
05cba821 | 11944 | && sal_fullname != NULL |
4aac40c8 | 11945 | && sal.pspace == loc->pspace |
05cba821 JK |
11946 | && loc->line_number == sal.line |
11947 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11948 | sal_fullname) == 0) | |
11949 | line_match = 1; | |
4aac40c8 | 11950 | |
0d381245 VP |
11951 | if (pc_match || line_match) |
11952 | { | |
11953 | match = 1; | |
11954 | break; | |
11955 | } | |
11956 | } | |
11957 | } | |
11958 | ||
11959 | if (match) | |
d6e956e5 | 11960 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11961 | } |
80f8a6eb | 11962 | } |
8a2c437b | 11963 | |
80f8a6eb | 11964 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11965 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11966 | { |
11967 | if (arg) | |
8a3fe4f8 | 11968 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11969 | else |
8a3fe4f8 | 11970 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11971 | } |
c906108c | 11972 | |
8a2c437b TT |
11973 | /* Remove duplicates from the vec. */ |
11974 | qsort (VEC_address (breakpoint_p, found), | |
11975 | VEC_length (breakpoint_p, found), | |
11976 | sizeof (breakpoint_p), | |
11977 | compare_breakpoints); | |
11978 | prev = VEC_index (breakpoint_p, found, 0); | |
11979 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11980 | { | |
11981 | if (b == prev) | |
11982 | { | |
11983 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11984 | --ix; | |
11985 | } | |
11986 | } | |
11987 | ||
d6e956e5 | 11988 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11989 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11990 | if (from_tty) |
a3f17187 | 11991 | { |
d6e956e5 | 11992 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11993 | printf_unfiltered (_("Deleted breakpoint ")); |
11994 | else | |
11995 | printf_unfiltered (_("Deleted breakpoints ")); | |
11996 | } | |
d6e956e5 VP |
11997 | |
11998 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11999 | { |
c5aa993b | 12000 | if (from_tty) |
d6e956e5 VP |
12001 | printf_unfiltered ("%d ", b->number); |
12002 | delete_breakpoint (b); | |
c906108c | 12003 | } |
80f8a6eb MS |
12004 | if (from_tty) |
12005 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12006 | |
12007 | do_cleanups (cleanups); | |
c906108c SS |
12008 | } |
12009 | \f | |
12010 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12011 | all breakpoints that are marked for deletion, whether hit or not. | |
12012 | This is called after any breakpoint is hit, or after errors. */ | |
12013 | ||
12014 | void | |
fba45db2 | 12015 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12016 | { |
35df4500 | 12017 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12018 | |
12019 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12020 | if (bs->breakpoint_at |
12021 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12022 | && bs->stop) |
f431efe5 | 12023 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12024 | |
35df4500 | 12025 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12026 | { |
b5de0fa7 | 12027 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12028 | delete_breakpoint (b); |
12029 | } | |
c906108c SS |
12030 | } |
12031 | ||
4a64f543 MS |
12032 | /* A comparison function for bp_location AP and BP being interfaced to |
12033 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12034 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12035 | secondarily by ordering first permanent elements and |
4a64f543 | 12036 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12037 | qsort being an unstable algorithm. */ |
876fa593 JK |
12038 | |
12039 | static int | |
f5336ca5 | 12040 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 12041 | { |
9a3c8263 SM |
12042 | const struct bp_location *a = *(const struct bp_location **) ap; |
12043 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12044 | |
12045 | if (a->address != b->address) | |
12046 | return (a->address > b->address) - (a->address < b->address); | |
12047 | ||
dea2aa5f LM |
12048 | /* Sort locations at the same address by their pspace number, keeping |
12049 | locations of the same inferior (in a multi-inferior environment) | |
12050 | grouped. */ | |
12051 | ||
12052 | if (a->pspace->num != b->pspace->num) | |
12053 | return ((a->pspace->num > b->pspace->num) | |
12054 | - (a->pspace->num < b->pspace->num)); | |
12055 | ||
876fa593 | 12056 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12057 | if (a->permanent != b->permanent) |
12058 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12059 | |
c56a97f9 JK |
12060 | /* Make the internal GDB representation stable across GDB runs |
12061 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12062 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12063 | |
12064 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12065 | return ((a->owner->number > b->owner->number) |
12066 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12067 | |
12068 | return (a > b) - (a < b); | |
12069 | } | |
12070 | ||
f5336ca5 PA |
12071 | /* Set bp_locations_placed_address_before_address_max and |
12072 | bp_locations_shadow_len_after_address_max according to the current | |
12073 | content of the bp_locations array. */ | |
f7545552 TT |
12074 | |
12075 | static void | |
f5336ca5 | 12076 | bp_locations_target_extensions_update (void) |
f7545552 | 12077 | { |
876fa593 JK |
12078 | struct bp_location *bl, **blp_tmp; |
12079 | ||
f5336ca5 PA |
12080 | bp_locations_placed_address_before_address_max = 0; |
12081 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
12082 | |
12083 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12084 | { | |
12085 | CORE_ADDR start, end, addr; | |
12086 | ||
12087 | if (!bp_location_has_shadow (bl)) | |
12088 | continue; | |
12089 | ||
12090 | start = bl->target_info.placed_address; | |
12091 | end = start + bl->target_info.shadow_len; | |
12092 | ||
12093 | gdb_assert (bl->address >= start); | |
12094 | addr = bl->address - start; | |
f5336ca5 PA |
12095 | if (addr > bp_locations_placed_address_before_address_max) |
12096 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
12097 | |
12098 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12099 | ||
12100 | gdb_assert (bl->address < end); | |
12101 | addr = end - bl->address; | |
f5336ca5 PA |
12102 | if (addr > bp_locations_shadow_len_after_address_max) |
12103 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 12104 | } |
f7545552 TT |
12105 | } |
12106 | ||
1e4d1764 YQ |
12107 | /* Download tracepoint locations if they haven't been. */ |
12108 | ||
12109 | static void | |
12110 | download_tracepoint_locations (void) | |
12111 | { | |
7ed2c994 | 12112 | struct breakpoint *b; |
dd2e65cc | 12113 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 12114 | |
5ed8105e | 12115 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 12116 | |
7ed2c994 | 12117 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12118 | { |
7ed2c994 | 12119 | struct bp_location *bl; |
1e4d1764 | 12120 | struct tracepoint *t; |
f2a8bc8a | 12121 | int bp_location_downloaded = 0; |
1e4d1764 | 12122 | |
7ed2c994 | 12123 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12124 | ? !may_insert_fast_tracepoints |
12125 | : !may_insert_tracepoints)) | |
12126 | continue; | |
12127 | ||
dd2e65cc YQ |
12128 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12129 | { | |
12130 | if (target_can_download_tracepoint ()) | |
12131 | can_download_tracepoint = TRIBOOL_TRUE; | |
12132 | else | |
12133 | can_download_tracepoint = TRIBOOL_FALSE; | |
12134 | } | |
12135 | ||
12136 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12137 | break; | |
12138 | ||
7ed2c994 YQ |
12139 | for (bl = b->loc; bl; bl = bl->next) |
12140 | { | |
12141 | /* In tracepoint, locations are _never_ duplicated, so | |
12142 | should_be_inserted is equivalent to | |
12143 | unduplicated_should_be_inserted. */ | |
12144 | if (!should_be_inserted (bl) || bl->inserted) | |
12145 | continue; | |
1e4d1764 | 12146 | |
7ed2c994 | 12147 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12148 | |
7ed2c994 | 12149 | target_download_tracepoint (bl); |
1e4d1764 | 12150 | |
7ed2c994 | 12151 | bl->inserted = 1; |
f2a8bc8a | 12152 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12153 | } |
12154 | t = (struct tracepoint *) b; | |
12155 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12156 | if (bp_location_downloaded) |
12157 | observer_notify_breakpoint_modified (b); | |
1e4d1764 | 12158 | } |
1e4d1764 YQ |
12159 | } |
12160 | ||
934709f0 PW |
12161 | /* Swap the insertion/duplication state between two locations. */ |
12162 | ||
12163 | static void | |
12164 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12165 | { | |
12166 | const int left_inserted = left->inserted; | |
12167 | const int left_duplicate = left->duplicate; | |
b775012e | 12168 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12169 | const struct bp_target_info left_target_info = left->target_info; |
12170 | ||
1e4d1764 YQ |
12171 | /* Locations of tracepoints can never be duplicated. */ |
12172 | if (is_tracepoint (left->owner)) | |
12173 | gdb_assert (!left->duplicate); | |
12174 | if (is_tracepoint (right->owner)) | |
12175 | gdb_assert (!right->duplicate); | |
12176 | ||
934709f0 PW |
12177 | left->inserted = right->inserted; |
12178 | left->duplicate = right->duplicate; | |
b775012e | 12179 | left->needs_update = right->needs_update; |
934709f0 PW |
12180 | left->target_info = right->target_info; |
12181 | right->inserted = left_inserted; | |
12182 | right->duplicate = left_duplicate; | |
b775012e | 12183 | right->needs_update = left_needs_update; |
934709f0 PW |
12184 | right->target_info = left_target_info; |
12185 | } | |
12186 | ||
b775012e LM |
12187 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12188 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12189 | conditions on the target's side. Such conditions need to be updated on | |
12190 | the target. */ | |
12191 | ||
12192 | static void | |
12193 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12194 | { | |
12195 | struct bp_location **locp = NULL, **loc2p; | |
12196 | struct bp_location *loc; | |
12197 | CORE_ADDR address = 0; | |
12198 | int pspace_num; | |
12199 | ||
12200 | address = bl->address; | |
12201 | pspace_num = bl->pspace->num; | |
12202 | ||
12203 | /* This is only meaningful if the target is | |
12204 | evaluating conditions and if the user has | |
12205 | opted for condition evaluation on the target's | |
12206 | side. */ | |
12207 | if (gdb_evaluates_breakpoint_condition_p () | |
12208 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12209 | return; | |
12210 | ||
12211 | /* Flag all breakpoint locations with this address and | |
12212 | the same program space as the location | |
12213 | as "its condition has changed". We need to | |
12214 | update the conditions on the target's side. */ | |
12215 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12216 | { | |
12217 | loc = *loc2p; | |
12218 | ||
12219 | if (!is_breakpoint (loc->owner) | |
12220 | || pspace_num != loc->pspace->num) | |
12221 | continue; | |
12222 | ||
12223 | /* Flag the location appropriately. We use a different state to | |
12224 | let everyone know that we already updated the set of locations | |
12225 | with addr bl->address and program space bl->pspace. This is so | |
12226 | we don't have to keep calling these functions just to mark locations | |
12227 | that have already been marked. */ | |
12228 | loc->condition_changed = condition_updated; | |
12229 | ||
12230 | /* Free the agent expression bytecode as well. We will compute | |
12231 | it later on. */ | |
833177a4 | 12232 | loc->cond_bytecode.reset (); |
b775012e LM |
12233 | } |
12234 | } | |
44702360 PA |
12235 | /* Called whether new breakpoints are created, or existing breakpoints |
12236 | deleted, to update the global location list and recompute which | |
12237 | locations are duplicate of which. | |
b775012e | 12238 | |
04086b45 PA |
12239 | The INSERT_MODE flag determines whether locations may not, may, or |
12240 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12241 | info. */ | |
b60e7edf | 12242 | |
0d381245 | 12243 | static void |
44702360 | 12244 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12245 | { |
74960c60 | 12246 | struct breakpoint *b; |
876fa593 | 12247 | struct bp_location **locp, *loc; |
f7545552 | 12248 | struct cleanup *cleanups; |
b775012e LM |
12249 | /* Last breakpoint location address that was marked for update. */ |
12250 | CORE_ADDR last_addr = 0; | |
12251 | /* Last breakpoint location program space that was marked for update. */ | |
12252 | int last_pspace_num = -1; | |
f7545552 | 12253 | |
2d134ed3 PA |
12254 | /* Used in the duplicates detection below. When iterating over all |
12255 | bp_locations, points to the first bp_location of a given address. | |
12256 | Breakpoints and watchpoints of different types are never | |
12257 | duplicates of each other. Keep one pointer for each type of | |
12258 | breakpoint/watchpoint, so we only need to loop over all locations | |
12259 | once. */ | |
12260 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12261 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12262 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12263 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12264 | |
f5336ca5 PA |
12265 | /* Saved former bp_locations array which we compare against the newly |
12266 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
12267 | struct bp_location **old_locations, **old_locp; | |
12268 | unsigned old_locations_count; | |
876fa593 | 12269 | |
f5336ca5 PA |
12270 | old_locations = bp_locations; |
12271 | old_locations_count = bp_locations_count; | |
12272 | bp_locations = NULL; | |
12273 | bp_locations_count = 0; | |
12274 | cleanups = make_cleanup (xfree, old_locations); | |
0d381245 | 12275 | |
74960c60 | 12276 | ALL_BREAKPOINTS (b) |
876fa593 | 12277 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 12278 | bp_locations_count++; |
876fa593 | 12279 | |
f5336ca5 PA |
12280 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
12281 | locp = bp_locations; | |
876fa593 JK |
12282 | ALL_BREAKPOINTS (b) |
12283 | for (loc = b->loc; loc; loc = loc->next) | |
12284 | *locp++ = loc; | |
f5336ca5 PA |
12285 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
12286 | bp_locations_compare); | |
876fa593 | 12287 | |
f5336ca5 | 12288 | bp_locations_target_extensions_update (); |
74960c60 | 12289 | |
4a64f543 MS |
12290 | /* Identify bp_location instances that are no longer present in the |
12291 | new list, and therefore should be freed. Note that it's not | |
12292 | necessary that those locations should be removed from inferior -- | |
12293 | if there's another location at the same address (previously | |
12294 | marked as duplicate), we don't need to remove/insert the | |
12295 | location. | |
876fa593 | 12296 | |
4a64f543 MS |
12297 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12298 | and former bp_location array state respectively. */ | |
876fa593 | 12299 | |
f5336ca5 PA |
12300 | locp = bp_locations; |
12301 | for (old_locp = old_locations; | |
12302 | old_locp < old_locations + old_locations_count; | |
876fa593 | 12303 | old_locp++) |
74960c60 | 12304 | { |
876fa593 | 12305 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12306 | struct bp_location **loc2p; |
876fa593 | 12307 | |
e5dd4106 | 12308 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12309 | not, we have to free it. */ |
c7d46a38 | 12310 | int found_object = 0; |
20874c92 VP |
12311 | /* Tells if the location should remain inserted in the target. */ |
12312 | int keep_in_target = 0; | |
12313 | int removed = 0; | |
876fa593 | 12314 | |
4a64f543 MS |
12315 | /* Skip LOCP entries which will definitely never be needed. |
12316 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 12317 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 12318 | && (*locp)->address < old_loc->address) |
876fa593 | 12319 | locp++; |
c7d46a38 PA |
12320 | |
12321 | for (loc2p = locp; | |
f5336ca5 | 12322 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
12323 | && (*loc2p)->address == old_loc->address); |
12324 | loc2p++) | |
12325 | { | |
b775012e LM |
12326 | /* Check if this is a new/duplicated location or a duplicated |
12327 | location that had its condition modified. If so, we want to send | |
12328 | its condition to the target if evaluation of conditions is taking | |
12329 | place there. */ | |
12330 | if ((*loc2p)->condition_changed == condition_modified | |
12331 | && (last_addr != old_loc->address | |
12332 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12333 | { |
b775012e LM |
12334 | force_breakpoint_reinsertion (*loc2p); |
12335 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12336 | } |
b775012e LM |
12337 | |
12338 | if (*loc2p == old_loc) | |
12339 | found_object = 1; | |
c7d46a38 | 12340 | } |
74960c60 | 12341 | |
b775012e LM |
12342 | /* We have already handled this address, update it so that we don't |
12343 | have to go through updates again. */ | |
12344 | last_addr = old_loc->address; | |
12345 | ||
12346 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12347 | if (!found_object) | |
12348 | force_breakpoint_reinsertion (old_loc); | |
12349 | ||
4a64f543 MS |
12350 | /* If this location is no longer present, and inserted, look if |
12351 | there's maybe a new location at the same address. If so, | |
12352 | mark that one inserted, and don't remove this one. This is | |
12353 | needed so that we don't have a time window where a breakpoint | |
12354 | at certain location is not inserted. */ | |
74960c60 | 12355 | |
876fa593 | 12356 | if (old_loc->inserted) |
0d381245 | 12357 | { |
4a64f543 MS |
12358 | /* If the location is inserted now, we might have to remove |
12359 | it. */ | |
74960c60 | 12360 | |
876fa593 | 12361 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12362 | { |
4a64f543 MS |
12363 | /* The location is still present in the location list, |
12364 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12365 | keep_in_target = 1; |
74960c60 VP |
12366 | } |
12367 | else | |
12368 | { | |
b775012e LM |
12369 | /* This location still exists, but it won't be kept in the |
12370 | target since it may have been disabled. We proceed to | |
12371 | remove its target-side condition. */ | |
12372 | ||
4a64f543 MS |
12373 | /* The location is either no longer present, or got |
12374 | disabled. See if there's another location at the | |
12375 | same address, in which case we don't need to remove | |
12376 | this one from the target. */ | |
876fa593 | 12377 | |
2bdf28a0 | 12378 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12379 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12380 | { | |
876fa593 | 12381 | for (loc2p = locp; |
f5336ca5 | 12382 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12383 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12384 | loc2p++) |
12385 | { | |
12386 | struct bp_location *loc2 = *loc2p; | |
12387 | ||
2d134ed3 | 12388 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12389 | { |
85d721b8 PA |
12390 | /* Read watchpoint locations are switched to |
12391 | access watchpoints, if the former are not | |
12392 | supported, but the latter are. */ | |
12393 | if (is_hardware_watchpoint (old_loc->owner)) | |
12394 | { | |
12395 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12396 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12397 | } | |
12398 | ||
934709f0 PW |
12399 | /* loc2 is a duplicated location. We need to check |
12400 | if it should be inserted in case it will be | |
12401 | unduplicated. */ | |
12402 | if (loc2 != old_loc | |
12403 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12404 | { |
934709f0 | 12405 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12406 | keep_in_target = 1; |
12407 | break; | |
12408 | } | |
876fa593 JK |
12409 | } |
12410 | } | |
12411 | } | |
74960c60 VP |
12412 | } |
12413 | ||
20874c92 VP |
12414 | if (!keep_in_target) |
12415 | { | |
834c0d03 | 12416 | if (remove_breakpoint (old_loc)) |
20874c92 | 12417 | { |
4a64f543 MS |
12418 | /* This is just about all we can do. We could keep |
12419 | this location on the global list, and try to | |
12420 | remove it next time, but there's no particular | |
12421 | reason why we will succeed next time. | |
20874c92 | 12422 | |
4a64f543 MS |
12423 | Note that at this point, old_loc->owner is still |
12424 | valid, as delete_breakpoint frees the breakpoint | |
12425 | only after calling us. */ | |
3e43a32a MS |
12426 | printf_filtered (_("warning: Error removing " |
12427 | "breakpoint %d\n"), | |
876fa593 | 12428 | old_loc->owner->number); |
20874c92 VP |
12429 | } |
12430 | removed = 1; | |
12431 | } | |
0d381245 | 12432 | } |
74960c60 VP |
12433 | |
12434 | if (!found_object) | |
1c5cfe86 | 12435 | { |
fbea99ea | 12436 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12437 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12438 | { |
db82e815 PA |
12439 | /* This location was removed from the target. In |
12440 | non-stop mode, a race condition is possible where | |
12441 | we've removed a breakpoint, but stop events for that | |
12442 | breakpoint are already queued and will arrive later. | |
12443 | We apply an heuristic to be able to distinguish such | |
12444 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12445 | breakpoint location for a bit, and will retire it | |
12446 | after we see some number of events. The theory here | |
12447 | is that reporting of events should, "on the average", | |
12448 | be fair, so after a while we'll see events from all | |
12449 | threads that have anything of interest, and no longer | |
12450 | need to keep this breakpoint location around. We | |
12451 | don't hold locations forever so to reduce chances of | |
12452 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12453 | SIGTRAP. | |
12454 | ||
12455 | The heuristic failing can be disastrous on | |
12456 | decr_pc_after_break targets. | |
12457 | ||
12458 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12459 | if we fail to recognize a late breakpoint SIGTRAP, | |
12460 | because events_till_retirement has reached 0 too | |
12461 | soon, we'll fail to do the PC adjustment, and report | |
12462 | a random SIGTRAP to the user. When the user resumes | |
12463 | the inferior, it will most likely immediately crash | |
2dec564e | 12464 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12465 | corrupted, because of being resumed e.g., in the |
12466 | middle of a multi-byte instruction, or skipped a | |
12467 | one-byte instruction. This was actually seen happen | |
12468 | on native x86-linux, and should be less rare on | |
12469 | targets that do not support new thread events, like | |
12470 | remote, due to the heuristic depending on | |
12471 | thread_count. | |
12472 | ||
12473 | Mistaking a random SIGTRAP for a breakpoint trap | |
12474 | causes similar symptoms (PC adjustment applied when | |
12475 | it shouldn't), but then again, playing with SIGTRAPs | |
12476 | behind the debugger's back is asking for trouble. | |
12477 | ||
12478 | Since hardware watchpoint traps are always | |
12479 | distinguishable from other traps, so we don't need to | |
12480 | apply keep hardware watchpoint moribund locations | |
12481 | around. We simply always ignore hardware watchpoint | |
12482 | traps we can no longer explain. */ | |
12483 | ||
876fa593 JK |
12484 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12485 | old_loc->owner = NULL; | |
20874c92 | 12486 | |
876fa593 | 12487 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12488 | } |
12489 | else | |
f431efe5 PA |
12490 | { |
12491 | old_loc->owner = NULL; | |
12492 | decref_bp_location (&old_loc); | |
12493 | } | |
20874c92 | 12494 | } |
74960c60 | 12495 | } |
1c5cfe86 | 12496 | |
348d480f PA |
12497 | /* Rescan breakpoints at the same address and section, marking the |
12498 | first one as "first" and any others as "duplicates". This is so | |
12499 | that the bpt instruction is only inserted once. If we have a | |
12500 | permanent breakpoint at the same place as BPT, make that one the | |
12501 | official one, and the rest as duplicates. Permanent breakpoints | |
12502 | are sorted first for the same address. | |
12503 | ||
12504 | Do the same for hardware watchpoints, but also considering the | |
12505 | watchpoint's type (regular/access/read) and length. */ | |
12506 | ||
12507 | bp_loc_first = NULL; | |
12508 | wp_loc_first = NULL; | |
12509 | awp_loc_first = NULL; | |
12510 | rwp_loc_first = NULL; | |
12511 | ALL_BP_LOCATIONS (loc, locp) | |
12512 | { | |
12513 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12514 | non-NULL. */ | |
348d480f | 12515 | struct bp_location **loc_first_p; |
d3fbdd86 | 12516 | b = loc->owner; |
348d480f | 12517 | |
6f380991 | 12518 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12519 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12520 | /* Don't detect duplicate for tracepoint locations because they are |
12521 | never duplicated. See the comments in field `duplicate' of | |
12522 | `struct bp_location'. */ | |
348d480f | 12523 | || is_tracepoint (b)) |
b775012e LM |
12524 | { |
12525 | /* Clear the condition modification flag. */ | |
12526 | loc->condition_changed = condition_unchanged; | |
12527 | continue; | |
12528 | } | |
348d480f | 12529 | |
348d480f PA |
12530 | if (b->type == bp_hardware_watchpoint) |
12531 | loc_first_p = &wp_loc_first; | |
12532 | else if (b->type == bp_read_watchpoint) | |
12533 | loc_first_p = &rwp_loc_first; | |
12534 | else if (b->type == bp_access_watchpoint) | |
12535 | loc_first_p = &awp_loc_first; | |
12536 | else | |
12537 | loc_first_p = &bp_loc_first; | |
12538 | ||
12539 | if (*loc_first_p == NULL | |
12540 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12541 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12542 | { | |
12543 | *loc_first_p = loc; | |
12544 | loc->duplicate = 0; | |
b775012e LM |
12545 | |
12546 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12547 | { | |
12548 | loc->needs_update = 1; | |
12549 | /* Clear the condition modification flag. */ | |
12550 | loc->condition_changed = condition_unchanged; | |
12551 | } | |
348d480f PA |
12552 | continue; |
12553 | } | |
12554 | ||
934709f0 PW |
12555 | |
12556 | /* This and the above ensure the invariant that the first location | |
12557 | is not duplicated, and is the inserted one. | |
12558 | All following are marked as duplicated, and are not inserted. */ | |
12559 | if (loc->inserted) | |
12560 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12561 | loc->duplicate = 1; |
12562 | ||
b775012e LM |
12563 | /* Clear the condition modification flag. */ |
12564 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12565 | } |
12566 | ||
a25a5a45 | 12567 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12568 | { |
04086b45 | 12569 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12570 | insert_breakpoint_locations (); |
12571 | else | |
12572 | { | |
44702360 PA |
12573 | /* Even though the caller told us to not insert new |
12574 | locations, we may still need to update conditions on the | |
12575 | target's side of breakpoints that were already inserted | |
12576 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12577 | only update conditions for locations that are marked |
12578 | "needs_update". */ | |
12579 | update_inserted_breakpoint_locations (); | |
12580 | } | |
12581 | } | |
348d480f | 12582 | |
04086b45 | 12583 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12584 | download_tracepoint_locations (); |
12585 | ||
348d480f PA |
12586 | do_cleanups (cleanups); |
12587 | } | |
12588 | ||
12589 | void | |
12590 | breakpoint_retire_moribund (void) | |
12591 | { | |
12592 | struct bp_location *loc; | |
12593 | int ix; | |
12594 | ||
12595 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12596 | if (--(loc->events_till_retirement) == 0) | |
12597 | { | |
12598 | decref_bp_location (&loc); | |
12599 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12600 | --ix; | |
12601 | } | |
12602 | } | |
12603 | ||
12604 | static void | |
44702360 | 12605 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12606 | { |
348d480f | 12607 | |
492d29ea PA |
12608 | TRY |
12609 | { | |
12610 | update_global_location_list (insert_mode); | |
12611 | } | |
12612 | CATCH (e, RETURN_MASK_ERROR) | |
12613 | { | |
12614 | } | |
12615 | END_CATCH | |
348d480f PA |
12616 | } |
12617 | ||
12618 | /* Clear BKP from a BPS. */ | |
12619 | ||
12620 | static void | |
12621 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12622 | { | |
12623 | bpstat bs; | |
12624 | ||
12625 | for (bs = bps; bs; bs = bs->next) | |
12626 | if (bs->breakpoint_at == bpt) | |
12627 | { | |
12628 | bs->breakpoint_at = NULL; | |
12629 | bs->old_val = NULL; | |
12630 | /* bs->commands will be freed later. */ | |
12631 | } | |
12632 | } | |
12633 | ||
12634 | /* Callback for iterate_over_threads. */ | |
12635 | static int | |
12636 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12637 | { | |
9a3c8263 | 12638 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12639 | |
12640 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12641 | return 0; | |
12642 | } | |
12643 | ||
12644 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12645 | callbacks. */ | |
12646 | ||
12647 | static void | |
12648 | say_where (struct breakpoint *b) | |
12649 | { | |
12650 | struct value_print_options opts; | |
12651 | ||
12652 | get_user_print_options (&opts); | |
12653 | ||
12654 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12655 | single string. */ | |
12656 | if (b->loc == NULL) | |
12657 | { | |
f00aae0f KS |
12658 | /* For pending locations, the output differs slightly based |
12659 | on b->extra_string. If this is non-NULL, it contains either | |
12660 | a condition or dprintf arguments. */ | |
12661 | if (b->extra_string == NULL) | |
12662 | { | |
12663 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12664 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12665 | } |
12666 | else if (b->type == bp_dprintf) | |
12667 | { | |
12668 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12669 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12670 | b->extra_string); |
12671 | } | |
12672 | else | |
12673 | { | |
12674 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12675 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12676 | b->extra_string); |
12677 | } | |
348d480f PA |
12678 | } |
12679 | else | |
12680 | { | |
2f202fde | 12681 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12682 | { |
12683 | printf_filtered (" at "); | |
12684 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12685 | gdb_stdout); | |
12686 | } | |
2f202fde | 12687 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12688 | { |
12689 | /* If there is a single location, we can print the location | |
12690 | more nicely. */ | |
12691 | if (b->loc->next == NULL) | |
12692 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12693 | symtab_to_filename_for_display (b->loc->symtab), |
12694 | b->loc->line_number); | |
f8eba3c6 TT |
12695 | else |
12696 | /* This is not ideal, but each location may have a | |
12697 | different file name, and this at least reflects the | |
12698 | real situation somewhat. */ | |
f00aae0f | 12699 | printf_filtered (": %s.", |
d28cd78a | 12700 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12701 | } |
348d480f PA |
12702 | |
12703 | if (b->loc->next) | |
12704 | { | |
12705 | struct bp_location *loc = b->loc; | |
12706 | int n = 0; | |
12707 | for (; loc; loc = loc->next) | |
12708 | ++n; | |
12709 | printf_filtered (" (%d locations)", n); | |
12710 | } | |
12711 | } | |
12712 | } | |
12713 | ||
348d480f PA |
12714 | /* Default bp_location_ops methods. */ |
12715 | ||
12716 | static void | |
12717 | bp_location_dtor (struct bp_location *self) | |
12718 | { | |
348d480f PA |
12719 | xfree (self->function_name); |
12720 | } | |
12721 | ||
12722 | static const struct bp_location_ops bp_location_ops = | |
12723 | { | |
12724 | bp_location_dtor | |
12725 | }; | |
12726 | ||
c1fc2657 | 12727 | /* Destructor for the breakpoint base class. */ |
348d480f | 12728 | |
c1fc2657 | 12729 | breakpoint::~breakpoint () |
348d480f | 12730 | { |
c1fc2657 SM |
12731 | decref_counted_command_line (&this->commands); |
12732 | xfree (this->cond_string); | |
12733 | xfree (this->extra_string); | |
12734 | xfree (this->filter); | |
348d480f PA |
12735 | } |
12736 | ||
2060206e PA |
12737 | static struct bp_location * |
12738 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12739 | { |
5625a286 | 12740 | return new bp_location (&bp_location_ops, self); |
348d480f PA |
12741 | } |
12742 | ||
2060206e PA |
12743 | static void |
12744 | base_breakpoint_re_set (struct breakpoint *b) | |
12745 | { | |
12746 | /* Nothing to re-set. */ | |
12747 | } | |
12748 | ||
12749 | #define internal_error_pure_virtual_called() \ | |
12750 | gdb_assert_not_reached ("pure virtual function called") | |
12751 | ||
12752 | static int | |
12753 | base_breakpoint_insert_location (struct bp_location *bl) | |
12754 | { | |
12755 | internal_error_pure_virtual_called (); | |
12756 | } | |
12757 | ||
12758 | static int | |
73971819 PA |
12759 | base_breakpoint_remove_location (struct bp_location *bl, |
12760 | enum remove_bp_reason reason) | |
2060206e PA |
12761 | { |
12762 | internal_error_pure_virtual_called (); | |
12763 | } | |
12764 | ||
12765 | static int | |
12766 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12767 | struct address_space *aspace, | |
09ac7c10 TT |
12768 | CORE_ADDR bp_addr, |
12769 | const struct target_waitstatus *ws) | |
2060206e PA |
12770 | { |
12771 | internal_error_pure_virtual_called (); | |
12772 | } | |
12773 | ||
12774 | static void | |
12775 | base_breakpoint_check_status (bpstat bs) | |
12776 | { | |
12777 | /* Always stop. */ | |
12778 | } | |
12779 | ||
12780 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12781 | errors. */ | |
12782 | ||
12783 | static int | |
12784 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12785 | { | |
12786 | internal_error_pure_virtual_called (); | |
12787 | } | |
12788 | ||
12789 | /* A "resources_needed" breakpoint_ops method that just internal | |
12790 | errors. */ | |
12791 | ||
12792 | static int | |
12793 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12794 | { | |
12795 | internal_error_pure_virtual_called (); | |
12796 | } | |
12797 | ||
12798 | static enum print_stop_action | |
12799 | base_breakpoint_print_it (bpstat bs) | |
12800 | { | |
12801 | internal_error_pure_virtual_called (); | |
12802 | } | |
12803 | ||
12804 | static void | |
12805 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12806 | struct ui_out *uiout) | |
12807 | { | |
12808 | /* nothing */ | |
12809 | } | |
12810 | ||
12811 | static void | |
12812 | base_breakpoint_print_mention (struct breakpoint *b) | |
12813 | { | |
12814 | internal_error_pure_virtual_called (); | |
12815 | } | |
12816 | ||
12817 | static void | |
12818 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12819 | { | |
12820 | internal_error_pure_virtual_called (); | |
12821 | } | |
12822 | ||
983af33b | 12823 | static void |
f00aae0f KS |
12824 | base_breakpoint_create_sals_from_location |
12825 | (const struct event_location *location, | |
12826 | struct linespec_result *canonical, | |
12827 | enum bptype type_wanted) | |
983af33b SDJ |
12828 | { |
12829 | internal_error_pure_virtual_called (); | |
12830 | } | |
12831 | ||
12832 | static void | |
12833 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12834 | struct linespec_result *c, | |
e1e01040 PA |
12835 | gdb::unique_xmalloc_ptr<char> cond_string, |
12836 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12837 | enum bptype type_wanted, |
12838 | enum bpdisp disposition, | |
12839 | int thread, | |
12840 | int task, int ignore_count, | |
12841 | const struct breakpoint_ops *o, | |
12842 | int from_tty, int enabled, | |
44f238bb | 12843 | int internal, unsigned flags) |
983af33b SDJ |
12844 | { |
12845 | internal_error_pure_virtual_called (); | |
12846 | } | |
12847 | ||
12848 | static void | |
f00aae0f KS |
12849 | base_breakpoint_decode_location (struct breakpoint *b, |
12850 | const struct event_location *location, | |
c2f4122d | 12851 | struct program_space *search_pspace, |
983af33b SDJ |
12852 | struct symtabs_and_lines *sals) |
12853 | { | |
12854 | internal_error_pure_virtual_called (); | |
12855 | } | |
12856 | ||
ab04a2af TT |
12857 | /* The default 'explains_signal' method. */ |
12858 | ||
47591c29 | 12859 | static int |
427cd150 | 12860 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12861 | { |
47591c29 | 12862 | return 1; |
ab04a2af TT |
12863 | } |
12864 | ||
9d6e6e84 HZ |
12865 | /* The default "after_condition_true" method. */ |
12866 | ||
12867 | static void | |
12868 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12869 | { | |
12870 | /* Nothing to do. */ | |
12871 | } | |
12872 | ||
ab04a2af | 12873 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12874 | { |
2060206e PA |
12875 | base_breakpoint_allocate_location, |
12876 | base_breakpoint_re_set, | |
12877 | base_breakpoint_insert_location, | |
12878 | base_breakpoint_remove_location, | |
12879 | base_breakpoint_breakpoint_hit, | |
12880 | base_breakpoint_check_status, | |
12881 | base_breakpoint_resources_needed, | |
12882 | base_breakpoint_works_in_software_mode, | |
12883 | base_breakpoint_print_it, | |
12884 | NULL, | |
12885 | base_breakpoint_print_one_detail, | |
12886 | base_breakpoint_print_mention, | |
983af33b | 12887 | base_breakpoint_print_recreate, |
5f700d83 | 12888 | base_breakpoint_create_sals_from_location, |
983af33b | 12889 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12890 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12891 | base_breakpoint_explains_signal, |
12892 | base_breakpoint_after_condition_true, | |
2060206e PA |
12893 | }; |
12894 | ||
12895 | /* Default breakpoint_ops methods. */ | |
12896 | ||
12897 | static void | |
348d480f PA |
12898 | bkpt_re_set (struct breakpoint *b) |
12899 | { | |
06edf0c0 | 12900 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12901 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12902 | { |
f00aae0f | 12903 | /* Anything without a location can't be re-set. */ |
348d480f | 12904 | delete_breakpoint (b); |
06edf0c0 | 12905 | return; |
348d480f | 12906 | } |
06edf0c0 PA |
12907 | |
12908 | breakpoint_re_set_default (b); | |
348d480f PA |
12909 | } |
12910 | ||
2060206e | 12911 | static int |
348d480f PA |
12912 | bkpt_insert_location (struct bp_location *bl) |
12913 | { | |
cd6c3b4f YQ |
12914 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12915 | ||
579c6ad9 | 12916 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12917 | bl->target_info.placed_address = addr; |
12918 | ||
348d480f | 12919 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12920 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12921 | else |
7c16b83e | 12922 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12923 | } |
12924 | ||
2060206e | 12925 | static int |
73971819 | 12926 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12927 | { |
12928 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12929 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12930 | else | |
73971819 | 12931 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12932 | } |
12933 | ||
2060206e | 12934 | static int |
348d480f | 12935 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12936 | struct address_space *aspace, CORE_ADDR bp_addr, |
12937 | const struct target_waitstatus *ws) | |
348d480f | 12938 | { |
09ac7c10 | 12939 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12940 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12941 | return 0; |
12942 | ||
348d480f PA |
12943 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12944 | aspace, bp_addr)) | |
12945 | return 0; | |
12946 | ||
12947 | if (overlay_debugging /* unmapped overlay section */ | |
12948 | && section_is_overlay (bl->section) | |
12949 | && !section_is_mapped (bl->section)) | |
12950 | return 0; | |
12951 | ||
12952 | return 1; | |
12953 | } | |
12954 | ||
cd1608cc PA |
12955 | static int |
12956 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
12957 | struct address_space *aspace, CORE_ADDR bp_addr, | |
12958 | const struct target_waitstatus *ws) | |
12959 | { | |
12960 | if (dprintf_style == dprintf_style_agent | |
12961 | && target_can_run_breakpoint_commands ()) | |
12962 | { | |
12963 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12964 | for this address it must be for a breakpoint that happens to | |
12965 | be set at the same address. */ | |
12966 | return 0; | |
12967 | } | |
12968 | ||
12969 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12970 | } | |
12971 | ||
2060206e | 12972 | static int |
348d480f PA |
12973 | bkpt_resources_needed (const struct bp_location *bl) |
12974 | { | |
12975 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12976 | ||
12977 | return 1; | |
12978 | } | |
12979 | ||
2060206e | 12980 | static enum print_stop_action |
348d480f PA |
12981 | bkpt_print_it (bpstat bs) |
12982 | { | |
348d480f PA |
12983 | struct breakpoint *b; |
12984 | const struct bp_location *bl; | |
001c8c33 | 12985 | int bp_temp; |
79a45e25 | 12986 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12987 | |
12988 | gdb_assert (bs->bp_location_at != NULL); | |
12989 | ||
12990 | bl = bs->bp_location_at; | |
12991 | b = bs->breakpoint_at; | |
12992 | ||
001c8c33 PA |
12993 | bp_temp = b->disposition == disp_del; |
12994 | if (bl->address != bl->requested_address) | |
12995 | breakpoint_adjustment_warning (bl->requested_address, | |
12996 | bl->address, | |
12997 | b->number, 1); | |
12998 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12999 | maybe_print_thread_hit_breakpoint (uiout); |
13000 | ||
001c8c33 | 13001 | if (bp_temp) |
112e8700 | 13002 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 13003 | else |
112e8700 SM |
13004 | uiout->text ("Breakpoint "); |
13005 | if (uiout->is_mi_like_p ()) | |
348d480f | 13006 | { |
112e8700 | 13007 | uiout->field_string ("reason", |
001c8c33 | 13008 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 13009 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 13010 | } |
112e8700 SM |
13011 | uiout->field_int ("bkptno", b->number); |
13012 | uiout->text (", "); | |
06edf0c0 | 13013 | |
001c8c33 | 13014 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13015 | } |
13016 | ||
2060206e | 13017 | static void |
06edf0c0 PA |
13018 | bkpt_print_mention (struct breakpoint *b) |
13019 | { | |
112e8700 | 13020 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
13021 | return; |
13022 | ||
13023 | switch (b->type) | |
13024 | { | |
13025 | case bp_breakpoint: | |
13026 | case bp_gnu_ifunc_resolver: | |
13027 | if (b->disposition == disp_del) | |
13028 | printf_filtered (_("Temporary breakpoint")); | |
13029 | else | |
13030 | printf_filtered (_("Breakpoint")); | |
13031 | printf_filtered (_(" %d"), b->number); | |
13032 | if (b->type == bp_gnu_ifunc_resolver) | |
13033 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13034 | break; | |
13035 | case bp_hardware_breakpoint: | |
13036 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13037 | break; | |
e7e0cddf SS |
13038 | case bp_dprintf: |
13039 | printf_filtered (_("Dprintf %d"), b->number); | |
13040 | break; | |
06edf0c0 PA |
13041 | } |
13042 | ||
13043 | say_where (b); | |
13044 | } | |
13045 | ||
2060206e | 13046 | static void |
06edf0c0 PA |
13047 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13048 | { | |
13049 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13050 | fprintf_unfiltered (fp, "tbreak"); | |
13051 | else if (tp->type == bp_breakpoint) | |
13052 | fprintf_unfiltered (fp, "break"); | |
13053 | else if (tp->type == bp_hardware_breakpoint | |
13054 | && tp->disposition == disp_del) | |
13055 | fprintf_unfiltered (fp, "thbreak"); | |
13056 | else if (tp->type == bp_hardware_breakpoint) | |
13057 | fprintf_unfiltered (fp, "hbreak"); | |
13058 | else | |
13059 | internal_error (__FILE__, __LINE__, | |
13060 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13061 | ||
f00aae0f | 13062 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13063 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
13064 | |
13065 | /* Print out extra_string if this breakpoint is pending. It might | |
13066 | contain, for example, conditions that were set by the user. */ | |
13067 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13068 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13069 | ||
dd11a36c | 13070 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13071 | } |
13072 | ||
983af33b | 13073 | static void |
f00aae0f KS |
13074 | bkpt_create_sals_from_location (const struct event_location *location, |
13075 | struct linespec_result *canonical, | |
13076 | enum bptype type_wanted) | |
983af33b | 13077 | { |
f00aae0f | 13078 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13079 | } |
13080 | ||
13081 | static void | |
13082 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13083 | struct linespec_result *canonical, | |
e1e01040 PA |
13084 | gdb::unique_xmalloc_ptr<char> cond_string, |
13085 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13086 | enum bptype type_wanted, |
13087 | enum bpdisp disposition, | |
13088 | int thread, | |
13089 | int task, int ignore_count, | |
13090 | const struct breakpoint_ops *ops, | |
13091 | int from_tty, int enabled, | |
44f238bb | 13092 | int internal, unsigned flags) |
983af33b | 13093 | { |
023fa29b | 13094 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13095 | std::move (cond_string), |
13096 | std::move (extra_string), | |
e7e0cddf | 13097 | type_wanted, |
983af33b SDJ |
13098 | disposition, thread, task, |
13099 | ignore_count, ops, from_tty, | |
44f238bb | 13100 | enabled, internal, flags); |
983af33b SDJ |
13101 | } |
13102 | ||
13103 | static void | |
f00aae0f KS |
13104 | bkpt_decode_location (struct breakpoint *b, |
13105 | const struct event_location *location, | |
c2f4122d | 13106 | struct program_space *search_pspace, |
983af33b SDJ |
13107 | struct symtabs_and_lines *sals) |
13108 | { | |
c2f4122d | 13109 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13110 | } |
13111 | ||
06edf0c0 PA |
13112 | /* Virtual table for internal breakpoints. */ |
13113 | ||
13114 | static void | |
13115 | internal_bkpt_re_set (struct breakpoint *b) | |
13116 | { | |
13117 | switch (b->type) | |
13118 | { | |
13119 | /* Delete overlay event and longjmp master breakpoints; they | |
13120 | will be reset later by breakpoint_re_set. */ | |
13121 | case bp_overlay_event: | |
13122 | case bp_longjmp_master: | |
13123 | case bp_std_terminate_master: | |
13124 | case bp_exception_master: | |
13125 | delete_breakpoint (b); | |
13126 | break; | |
13127 | ||
13128 | /* This breakpoint is special, it's set up when the inferior | |
13129 | starts and we really don't want to touch it. */ | |
13130 | case bp_shlib_event: | |
13131 | ||
13132 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13133 | it is set up, we do not want to touch it. */ | |
13134 | case bp_thread_event: | |
13135 | break; | |
13136 | } | |
13137 | } | |
13138 | ||
13139 | static void | |
13140 | internal_bkpt_check_status (bpstat bs) | |
13141 | { | |
a9b3a50f PA |
13142 | if (bs->breakpoint_at->type == bp_shlib_event) |
13143 | { | |
13144 | /* If requested, stop when the dynamic linker notifies GDB of | |
13145 | events. This allows the user to get control and place | |
13146 | breakpoints in initializer routines for dynamically loaded | |
13147 | objects (among other things). */ | |
13148 | bs->stop = stop_on_solib_events; | |
13149 | bs->print = stop_on_solib_events; | |
13150 | } | |
13151 | else | |
13152 | bs->stop = 0; | |
06edf0c0 PA |
13153 | } |
13154 | ||
13155 | static enum print_stop_action | |
13156 | internal_bkpt_print_it (bpstat bs) | |
13157 | { | |
06edf0c0 | 13158 | struct breakpoint *b; |
06edf0c0 | 13159 | |
06edf0c0 PA |
13160 | b = bs->breakpoint_at; |
13161 | ||
06edf0c0 PA |
13162 | switch (b->type) |
13163 | { | |
348d480f PA |
13164 | case bp_shlib_event: |
13165 | /* Did we stop because the user set the stop_on_solib_events | |
13166 | variable? (If so, we report this as a generic, "Stopped due | |
13167 | to shlib event" message.) */ | |
edcc5120 | 13168 | print_solib_event (0); |
348d480f PA |
13169 | break; |
13170 | ||
13171 | case bp_thread_event: | |
13172 | /* Not sure how we will get here. | |
13173 | GDB should not stop for these breakpoints. */ | |
13174 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13175 | break; |
13176 | ||
13177 | case bp_overlay_event: | |
13178 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13179 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13180 | break; |
13181 | ||
13182 | case bp_longjmp_master: | |
13183 | /* These should never be enabled. */ | |
13184 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13185 | break; |
13186 | ||
13187 | case bp_std_terminate_master: | |
13188 | /* These should never be enabled. */ | |
13189 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13190 | "gdb should not stop!\n")); | |
348d480f PA |
13191 | break; |
13192 | ||
13193 | case bp_exception_master: | |
13194 | /* These should never be enabled. */ | |
13195 | printf_filtered (_("Exception Master Breakpoint: " | |
13196 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13197 | break; |
13198 | } | |
13199 | ||
001c8c33 | 13200 | return PRINT_NOTHING; |
06edf0c0 PA |
13201 | } |
13202 | ||
13203 | static void | |
13204 | internal_bkpt_print_mention (struct breakpoint *b) | |
13205 | { | |
13206 | /* Nothing to mention. These breakpoints are internal. */ | |
13207 | } | |
13208 | ||
06edf0c0 PA |
13209 | /* Virtual table for momentary breakpoints */ |
13210 | ||
13211 | static void | |
13212 | momentary_bkpt_re_set (struct breakpoint *b) | |
13213 | { | |
13214 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13215 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13216 | Otherwise these should have been blown away via the cleanup chain |
13217 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13218 | } | |
13219 | ||
13220 | static void | |
13221 | momentary_bkpt_check_status (bpstat bs) | |
13222 | { | |
13223 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13224 | } | |
13225 | ||
13226 | static enum print_stop_action | |
13227 | momentary_bkpt_print_it (bpstat bs) | |
13228 | { | |
001c8c33 | 13229 | return PRINT_UNKNOWN; |
348d480f PA |
13230 | } |
13231 | ||
06edf0c0 PA |
13232 | static void |
13233 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13234 | { |
06edf0c0 | 13235 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13236 | } |
13237 | ||
e2e4d78b JK |
13238 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13239 | ||
13240 | It gets cleared already on the removal of the first one of such placed | |
13241 | breakpoints. This is OK as they get all removed altogether. */ | |
13242 | ||
c1fc2657 | 13243 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 13244 | { |
c1fc2657 | 13245 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 13246 | |
c1fc2657 | 13247 | if (tp != NULL) |
e2e4d78b | 13248 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
13249 | } |
13250 | ||
55aa24fb SDJ |
13251 | /* Specific methods for probe breakpoints. */ |
13252 | ||
13253 | static int | |
13254 | bkpt_probe_insert_location (struct bp_location *bl) | |
13255 | { | |
13256 | int v = bkpt_insert_location (bl); | |
13257 | ||
13258 | if (v == 0) | |
13259 | { | |
13260 | /* The insertion was successful, now let's set the probe's semaphore | |
13261 | if needed. */ | |
0ea5cda8 SDJ |
13262 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13263 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13264 | bl->probe.objfile, | |
13265 | bl->gdbarch); | |
55aa24fb SDJ |
13266 | } |
13267 | ||
13268 | return v; | |
13269 | } | |
13270 | ||
13271 | static int | |
73971819 PA |
13272 | bkpt_probe_remove_location (struct bp_location *bl, |
13273 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13274 | { |
13275 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13276 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13277 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13278 | bl->probe.objfile, | |
13279 | bl->gdbarch); | |
55aa24fb | 13280 | |
73971819 | 13281 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13282 | } |
13283 | ||
13284 | static void | |
f00aae0f | 13285 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13286 | struct linespec_result *canonical, |
f00aae0f | 13287 | enum bptype type_wanted) |
55aa24fb SDJ |
13288 | { |
13289 | struct linespec_sals lsal; | |
13290 | ||
c2f4122d | 13291 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
13292 | lsal.canonical |
13293 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
55aa24fb SDJ |
13294 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13295 | } | |
13296 | ||
13297 | static void | |
f00aae0f KS |
13298 | bkpt_probe_decode_location (struct breakpoint *b, |
13299 | const struct event_location *location, | |
c2f4122d | 13300 | struct program_space *search_pspace, |
55aa24fb SDJ |
13301 | struct symtabs_and_lines *sals) |
13302 | { | |
c2f4122d | 13303 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13304 | if (!sals->sals) |
13305 | error (_("probe not found")); | |
13306 | } | |
13307 | ||
348d480f | 13308 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13309 | |
348d480f PA |
13310 | static void |
13311 | tracepoint_re_set (struct breakpoint *b) | |
13312 | { | |
13313 | breakpoint_re_set_default (b); | |
13314 | } | |
876fa593 | 13315 | |
348d480f PA |
13316 | static int |
13317 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13318 | struct address_space *aspace, CORE_ADDR bp_addr, |
13319 | const struct target_waitstatus *ws) | |
348d480f PA |
13320 | { |
13321 | /* By definition, the inferior does not report stops at | |
13322 | tracepoints. */ | |
13323 | return 0; | |
74960c60 VP |
13324 | } |
13325 | ||
13326 | static void | |
348d480f PA |
13327 | tracepoint_print_one_detail (const struct breakpoint *self, |
13328 | struct ui_out *uiout) | |
74960c60 | 13329 | { |
d9b3f62e PA |
13330 | struct tracepoint *tp = (struct tracepoint *) self; |
13331 | if (tp->static_trace_marker_id) | |
348d480f PA |
13332 | { |
13333 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13334 | |
112e8700 SM |
13335 | uiout->text ("\tmarker id is "); |
13336 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 13337 | tp->static_trace_marker_id); |
112e8700 | 13338 | uiout->text ("\n"); |
348d480f | 13339 | } |
0d381245 VP |
13340 | } |
13341 | ||
a474d7c2 | 13342 | static void |
348d480f | 13343 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13344 | { |
112e8700 | 13345 | if (current_uiout->is_mi_like_p ()) |
348d480f | 13346 | return; |
cc59ec59 | 13347 | |
348d480f PA |
13348 | switch (b->type) |
13349 | { | |
13350 | case bp_tracepoint: | |
13351 | printf_filtered (_("Tracepoint")); | |
13352 | printf_filtered (_(" %d"), b->number); | |
13353 | break; | |
13354 | case bp_fast_tracepoint: | |
13355 | printf_filtered (_("Fast tracepoint")); | |
13356 | printf_filtered (_(" %d"), b->number); | |
13357 | break; | |
13358 | case bp_static_tracepoint: | |
13359 | printf_filtered (_("Static tracepoint")); | |
13360 | printf_filtered (_(" %d"), b->number); | |
13361 | break; | |
13362 | default: | |
13363 | internal_error (__FILE__, __LINE__, | |
13364 | _("unhandled tracepoint type %d"), (int) b->type); | |
13365 | } | |
13366 | ||
13367 | say_where (b); | |
a474d7c2 PA |
13368 | } |
13369 | ||
348d480f | 13370 | static void |
d9b3f62e | 13371 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13372 | { |
d9b3f62e PA |
13373 | struct tracepoint *tp = (struct tracepoint *) self; |
13374 | ||
13375 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13376 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13377 | else if (self->type == bp_static_tracepoint) |
348d480f | 13378 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13379 | else if (self->type == bp_tracepoint) |
348d480f PA |
13380 | fprintf_unfiltered (fp, "trace"); |
13381 | else | |
13382 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13383 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13384 | |
f00aae0f | 13385 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13386 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
13387 | print_recreate_thread (self, fp); |
13388 | ||
13389 | if (tp->pass_count) | |
13390 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13391 | } |
13392 | ||
983af33b | 13393 | static void |
f00aae0f KS |
13394 | tracepoint_create_sals_from_location (const struct event_location *location, |
13395 | struct linespec_result *canonical, | |
13396 | enum bptype type_wanted) | |
983af33b | 13397 | { |
f00aae0f | 13398 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13399 | } |
13400 | ||
13401 | static void | |
13402 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13403 | struct linespec_result *canonical, | |
e1e01040 PA |
13404 | gdb::unique_xmalloc_ptr<char> cond_string, |
13405 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13406 | enum bptype type_wanted, |
13407 | enum bpdisp disposition, | |
13408 | int thread, | |
13409 | int task, int ignore_count, | |
13410 | const struct breakpoint_ops *ops, | |
13411 | int from_tty, int enabled, | |
44f238bb | 13412 | int internal, unsigned flags) |
983af33b | 13413 | { |
023fa29b | 13414 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13415 | std::move (cond_string), |
13416 | std::move (extra_string), | |
e7e0cddf | 13417 | type_wanted, |
983af33b SDJ |
13418 | disposition, thread, task, |
13419 | ignore_count, ops, from_tty, | |
44f238bb | 13420 | enabled, internal, flags); |
983af33b SDJ |
13421 | } |
13422 | ||
13423 | static void | |
f00aae0f KS |
13424 | tracepoint_decode_location (struct breakpoint *b, |
13425 | const struct event_location *location, | |
c2f4122d | 13426 | struct program_space *search_pspace, |
983af33b SDJ |
13427 | struct symtabs_and_lines *sals) |
13428 | { | |
c2f4122d | 13429 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13430 | } |
13431 | ||
2060206e | 13432 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13433 | |
55aa24fb SDJ |
13434 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13435 | static probe. */ | |
13436 | ||
13437 | static void | |
f00aae0f KS |
13438 | tracepoint_probe_create_sals_from_location |
13439 | (const struct event_location *location, | |
13440 | struct linespec_result *canonical, | |
13441 | enum bptype type_wanted) | |
55aa24fb SDJ |
13442 | { |
13443 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13444 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13445 | } |
13446 | ||
13447 | static void | |
f00aae0f KS |
13448 | tracepoint_probe_decode_location (struct breakpoint *b, |
13449 | const struct event_location *location, | |
c2f4122d | 13450 | struct program_space *search_pspace, |
55aa24fb SDJ |
13451 | struct symtabs_and_lines *sals) |
13452 | { | |
13453 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13454 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13455 | } |
13456 | ||
13457 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13458 | ||
5c2b4418 HZ |
13459 | /* Dprintf breakpoint_ops methods. */ |
13460 | ||
13461 | static void | |
13462 | dprintf_re_set (struct breakpoint *b) | |
13463 | { | |
13464 | breakpoint_re_set_default (b); | |
13465 | ||
f00aae0f KS |
13466 | /* extra_string should never be non-NULL for dprintf. */ |
13467 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13468 | |
13469 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13470 | 2 - create a dprintf, which resolves fine. | |
13471 | 3 - disconnect from target 1 | |
13472 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13473 | ||
13474 | After steps #3/#4, you'll want the dprintf command list to | |
13475 | be updated, because target 1 and 2 may well return different | |
13476 | answers for target_can_run_breakpoint_commands(). | |
13477 | Given absence of finer grained resetting, we get to do | |
13478 | it all the time. */ | |
13479 | if (b->extra_string != NULL) | |
13480 | update_dprintf_command_list (b); | |
13481 | } | |
13482 | ||
2d9442cc HZ |
13483 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13484 | ||
13485 | static void | |
13486 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13487 | { | |
f00aae0f | 13488 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13489 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13490 | tp->extra_string); |
13491 | print_recreate_thread (tp, fp); | |
13492 | } | |
13493 | ||
9d6e6e84 HZ |
13494 | /* Implement the "after_condition_true" breakpoint_ops method for |
13495 | dprintf. | |
13496 | ||
13497 | dprintf's are implemented with regular commands in their command | |
13498 | list, but we run the commands here instead of before presenting the | |
13499 | stop to the user, as dprintf's don't actually cause a stop. This | |
13500 | also makes it so that the commands of multiple dprintfs at the same | |
13501 | address are all handled. */ | |
13502 | ||
13503 | static void | |
13504 | dprintf_after_condition_true (struct bpstats *bs) | |
13505 | { | |
13506 | struct cleanup *old_chain; | |
13507 | struct bpstats tmp_bs = { NULL }; | |
13508 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13509 | ||
13510 | /* dprintf's never cause a stop. This wasn't set in the | |
13511 | check_status hook instead because that would make the dprintf's | |
13512 | condition not be evaluated. */ | |
13513 | bs->stop = 0; | |
13514 | ||
13515 | /* Run the command list here. Take ownership of it instead of | |
13516 | copying. We never want these commands to run later in | |
13517 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13518 | be set at same address as this dprintf, or even if running the | |
13519 | commands here throws. */ | |
13520 | tmp_bs.commands = bs->commands; | |
13521 | bs->commands = NULL; | |
13522 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13523 | ||
13524 | bpstat_do_actions_1 (&tmp_bs_p); | |
13525 | ||
13526 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13527 | bpstat_do_actions_1 may return early without processing the whole | |
13528 | list. */ | |
13529 | do_cleanups (old_chain); | |
13530 | } | |
13531 | ||
983af33b SDJ |
13532 | /* The breakpoint_ops structure to be used on static tracepoints with |
13533 | markers (`-m'). */ | |
13534 | ||
13535 | static void | |
f00aae0f | 13536 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13537 | struct linespec_result *canonical, |
f00aae0f | 13538 | enum bptype type_wanted) |
983af33b SDJ |
13539 | { |
13540 | struct linespec_sals lsal; | |
f00aae0f KS |
13541 | const char *arg_start, *arg; |
13542 | char *str; | |
13543 | struct cleanup *cleanup; | |
983af33b | 13544 | |
f00aae0f KS |
13545 | arg = arg_start = get_linespec_location (location); |
13546 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13547 | |
f00aae0f KS |
13548 | str = savestring (arg_start, arg - arg_start); |
13549 | cleanup = make_cleanup (xfree, str); | |
8e9e35b1 | 13550 | canonical->location = new_linespec_location (&str); |
f00aae0f | 13551 | do_cleanups (cleanup); |
983af33b | 13552 | |
8e9e35b1 TT |
13553 | lsal.canonical |
13554 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
983af33b SDJ |
13555 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13556 | } | |
13557 | ||
13558 | static void | |
13559 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13560 | struct linespec_result *canonical, | |
e1e01040 PA |
13561 | gdb::unique_xmalloc_ptr<char> cond_string, |
13562 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13563 | enum bptype type_wanted, |
13564 | enum bpdisp disposition, | |
13565 | int thread, | |
13566 | int task, int ignore_count, | |
13567 | const struct breakpoint_ops *ops, | |
13568 | int from_tty, int enabled, | |
44f238bb | 13569 | int internal, unsigned flags) |
983af33b SDJ |
13570 | { |
13571 | int i; | |
52d361e1 YQ |
13572 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13573 | canonical->sals, 0); | |
983af33b SDJ |
13574 | |
13575 | /* If the user is creating a static tracepoint by marker id | |
13576 | (strace -m MARKER_ID), then store the sals index, so that | |
13577 | breakpoint_re_set can try to match up which of the newly | |
13578 | found markers corresponds to this one, and, don't try to | |
13579 | expand multiple locations for each sal, given than SALS | |
13580 | already should contain all sals for MARKER_ID. */ | |
13581 | ||
13582 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13583 | { | |
13584 | struct symtabs_and_lines expanded; | |
13585 | struct tracepoint *tp; | |
ffc2605c | 13586 | event_location_up location; |
983af33b SDJ |
13587 | |
13588 | expanded.nelts = 1; | |
13589 | expanded.sals = &lsal->sals.sals[i]; | |
13590 | ||
8e9e35b1 | 13591 | location = copy_event_location (canonical->location.get ()); |
983af33b | 13592 | |
4d01a485 | 13593 | tp = new tracepoint (); |
c1fc2657 | 13594 | init_breakpoint_sal (tp, gdbarch, expanded, |
ffc2605c | 13595 | std::move (location), NULL, |
e1e01040 PA |
13596 | std::move (cond_string), |
13597 | std::move (extra_string), | |
e7e0cddf | 13598 | type_wanted, disposition, |
983af33b | 13599 | thread, task, ignore_count, ops, |
44f238bb | 13600 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13601 | canonical->special_display); |
13602 | /* Given that its possible to have multiple markers with | |
13603 | the same string id, if the user is creating a static | |
13604 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13605 | store the sals index, so that breakpoint_re_set can | |
13606 | try to match up which of the newly found markers | |
13607 | corresponds to this one */ | |
13608 | tp->static_trace_marker_id_idx = i; | |
13609 | ||
c1fc2657 | 13610 | install_breakpoint (internal, tp, 0); |
983af33b SDJ |
13611 | } |
13612 | } | |
13613 | ||
13614 | static void | |
f00aae0f KS |
13615 | strace_marker_decode_location (struct breakpoint *b, |
13616 | const struct event_location *location, | |
c2f4122d | 13617 | struct program_space *search_pspace, |
983af33b SDJ |
13618 | struct symtabs_and_lines *sals) |
13619 | { | |
13620 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13621 | const char *s = get_linespec_location (location); |
983af33b | 13622 | |
f00aae0f | 13623 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13624 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13625 | { | |
13626 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13627 | sals->nelts = 1; | |
13628 | } | |
13629 | else | |
13630 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13631 | } | |
13632 | ||
13633 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13634 | ||
13635 | static int | |
13636 | strace_marker_p (struct breakpoint *b) | |
13637 | { | |
13638 | return b->ops == &strace_marker_breakpoint_ops; | |
13639 | } | |
13640 | ||
53a5351d | 13641 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13642 | structures. */ |
c906108c SS |
13643 | |
13644 | void | |
fba45db2 | 13645 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13646 | { |
52f0bd74 | 13647 | struct breakpoint *b; |
c906108c | 13648 | |
8a3fe4f8 | 13649 | gdb_assert (bpt != NULL); |
c906108c | 13650 | |
4a64f543 MS |
13651 | /* Has this bp already been deleted? This can happen because |
13652 | multiple lists can hold pointers to bp's. bpstat lists are | |
13653 | especial culprits. | |
13654 | ||
13655 | One example of this happening is a watchpoint's scope bp. When | |
13656 | the scope bp triggers, we notice that the watchpoint is out of | |
13657 | scope, and delete it. We also delete its scope bp. But the | |
13658 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13659 | That bpstat is then checked for auto-deleting bp's, which are | |
13660 | deleted. | |
13661 | ||
13662 | A real solution to this problem might involve reference counts in | |
13663 | bp's, and/or giving them pointers back to their referencing | |
13664 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13665 | storage when no more references were extent. A cheaper bandaid | |
13666 | was chosen. */ | |
c906108c SS |
13667 | if (bpt->type == bp_none) |
13668 | return; | |
13669 | ||
4a64f543 MS |
13670 | /* At least avoid this stale reference until the reference counting |
13671 | of breakpoints gets resolved. */ | |
d0fb5eae | 13672 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13673 | { |
d0fb5eae | 13674 | struct breakpoint *related; |
3a5c3e22 | 13675 | struct watchpoint *w; |
d0fb5eae JK |
13676 | |
13677 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13678 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13679 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13680 | w = (struct watchpoint *) bpt; |
13681 | else | |
13682 | w = NULL; | |
13683 | if (w != NULL) | |
13684 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13685 | |
13686 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13687 | for (related = bpt; related->related_breakpoint != bpt; | |
13688 | related = related->related_breakpoint); | |
13689 | related->related_breakpoint = bpt->related_breakpoint; | |
13690 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13691 | } |
13692 | ||
a9634178 TJB |
13693 | /* watch_command_1 creates a watchpoint but only sets its number if |
13694 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13695 | a problem in that process, we'll be asked to delete the half-created | |
13696 | watchpoint. In that case, don't announce the deletion. */ | |
13697 | if (bpt->number) | |
13698 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13699 | |
c906108c SS |
13700 | if (breakpoint_chain == bpt) |
13701 | breakpoint_chain = bpt->next; | |
13702 | ||
c906108c SS |
13703 | ALL_BREAKPOINTS (b) |
13704 | if (b->next == bpt) | |
c5aa993b JM |
13705 | { |
13706 | b->next = bpt->next; | |
13707 | break; | |
13708 | } | |
c906108c | 13709 | |
f431efe5 PA |
13710 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13711 | been freed. */ | |
13712 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13713 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13714 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13715 | commands are associated with the bpstat; if we remove it here, | |
13716 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13717 | event-top.c won't do anything, and temporary breakpoints with | |
13718 | commands won't work. */ | |
13719 | ||
13720 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13721 | ||
4a64f543 MS |
13722 | /* Now that breakpoint is removed from breakpoint list, update the |
13723 | global location list. This will remove locations that used to | |
13724 | belong to this breakpoint. Do this before freeing the breakpoint | |
13725 | itself, since remove_breakpoint looks at location's owner. It | |
13726 | might be better design to have location completely | |
13727 | self-contained, but it's not the case now. */ | |
44702360 | 13728 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13729 | |
4a64f543 MS |
13730 | /* On the chance that someone will soon try again to delete this |
13731 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13732 | bpt->type = bp_none; |
4d01a485 | 13733 | delete bpt; |
c906108c SS |
13734 | } |
13735 | ||
4d6140d9 AC |
13736 | static void |
13737 | do_delete_breakpoint_cleanup (void *b) | |
13738 | { | |
9a3c8263 | 13739 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13740 | } |
13741 | ||
13742 | struct cleanup * | |
13743 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13744 | { | |
13745 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13746 | } | |
13747 | ||
51be5b68 PA |
13748 | /* Iterator function to call a user-provided callback function once |
13749 | for each of B and its related breakpoints. */ | |
13750 | ||
13751 | static void | |
13752 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13753 | void (*function) (struct breakpoint *, | |
13754 | void *), | |
13755 | void *data) | |
13756 | { | |
13757 | struct breakpoint *related; | |
13758 | ||
13759 | related = b; | |
13760 | do | |
13761 | { | |
13762 | struct breakpoint *next; | |
13763 | ||
13764 | /* FUNCTION may delete RELATED. */ | |
13765 | next = related->related_breakpoint; | |
13766 | ||
13767 | if (next == related) | |
13768 | { | |
13769 | /* RELATED is the last ring entry. */ | |
13770 | function (related, data); | |
13771 | ||
13772 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13773 | B. There's nothing left to do anyway, so just break | |
13774 | out. */ | |
13775 | break; | |
13776 | } | |
13777 | else | |
13778 | function (related, data); | |
13779 | ||
13780 | related = next; | |
13781 | } | |
13782 | while (related != b); | |
13783 | } | |
95a42b64 TT |
13784 | |
13785 | static void | |
13786 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13787 | { | |
13788 | delete_breakpoint (b); | |
13789 | } | |
13790 | ||
51be5b68 PA |
13791 | /* A callback for map_breakpoint_numbers that calls |
13792 | delete_breakpoint. */ | |
13793 | ||
13794 | static void | |
13795 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13796 | { | |
13797 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13798 | } | |
13799 | ||
c906108c | 13800 | void |
fba45db2 | 13801 | delete_command (char *arg, int from_tty) |
c906108c | 13802 | { |
35df4500 | 13803 | struct breakpoint *b, *b_tmp; |
c906108c | 13804 | |
ea9365bb TT |
13805 | dont_repeat (); |
13806 | ||
c906108c SS |
13807 | if (arg == 0) |
13808 | { | |
13809 | int breaks_to_delete = 0; | |
13810 | ||
46c6471b PA |
13811 | /* Delete all breakpoints if no argument. Do not delete |
13812 | internal breakpoints, these have to be deleted with an | |
13813 | explicit breakpoint number argument. */ | |
c5aa993b | 13814 | ALL_BREAKPOINTS (b) |
46c6471b | 13815 | if (user_breakpoint_p (b)) |
973d738b DJ |
13816 | { |
13817 | breaks_to_delete = 1; | |
13818 | break; | |
13819 | } | |
c906108c SS |
13820 | |
13821 | /* Ask user only if there are some breakpoints to delete. */ | |
13822 | if (!from_tty | |
e2e0b3e5 | 13823 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13824 | { |
35df4500 | 13825 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13826 | if (user_breakpoint_p (b)) |
c5aa993b | 13827 | delete_breakpoint (b); |
c906108c SS |
13828 | } |
13829 | } | |
13830 | else | |
51be5b68 | 13831 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13832 | } |
13833 | ||
c2f4122d PA |
13834 | /* Return true if all locations of B bound to PSPACE are pending. If |
13835 | PSPACE is NULL, all locations of all program spaces are | |
13836 | considered. */ | |
13837 | ||
0d381245 | 13838 | static int |
c2f4122d | 13839 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13840 | { |
c2f4122d PA |
13841 | struct bp_location *loc; |
13842 | ||
13843 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13844 | if ((pspace == NULL | |
13845 | || loc->pspace == pspace) | |
13846 | && !loc->shlib_disabled | |
8645ff69 | 13847 | && !loc->pspace->executing_startup) |
0d381245 VP |
13848 | return 0; |
13849 | return 1; | |
fe3f5fa8 VP |
13850 | } |
13851 | ||
776592bf DE |
13852 | /* Subroutine of update_breakpoint_locations to simplify it. |
13853 | Return non-zero if multiple fns in list LOC have the same name. | |
13854 | Null names are ignored. */ | |
13855 | ||
13856 | static int | |
13857 | ambiguous_names_p (struct bp_location *loc) | |
13858 | { | |
13859 | struct bp_location *l; | |
13860 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13861 | (int (*) (const void *, |
13862 | const void *)) streq, | |
776592bf DE |
13863 | NULL, xcalloc, xfree); |
13864 | ||
13865 | for (l = loc; l != NULL; l = l->next) | |
13866 | { | |
13867 | const char **slot; | |
13868 | const char *name = l->function_name; | |
13869 | ||
13870 | /* Allow for some names to be NULL, ignore them. */ | |
13871 | if (name == NULL) | |
13872 | continue; | |
13873 | ||
13874 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13875 | INSERT); | |
4a64f543 MS |
13876 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13877 | returns NULL. */ | |
776592bf DE |
13878 | if (*slot != NULL) |
13879 | { | |
13880 | htab_delete (htab); | |
13881 | return 1; | |
13882 | } | |
13883 | *slot = name; | |
13884 | } | |
13885 | ||
13886 | htab_delete (htab); | |
13887 | return 0; | |
13888 | } | |
13889 | ||
0fb4aa4b PA |
13890 | /* When symbols change, it probably means the sources changed as well, |
13891 | and it might mean the static tracepoint markers are no longer at | |
13892 | the same address or line numbers they used to be at last we | |
13893 | checked. Losing your static tracepoints whenever you rebuild is | |
13894 | undesirable. This function tries to resync/rematch gdb static | |
13895 | tracepoints with the markers on the target, for static tracepoints | |
13896 | that have not been set by marker id. Static tracepoint that have | |
13897 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13898 | The heuristic is: | |
13899 | ||
13900 | 1) For a tracepoint set at a specific address, look for a marker at | |
13901 | the old PC. If one is found there, assume to be the same marker. | |
13902 | If the name / string id of the marker found is different from the | |
13903 | previous known name, assume that means the user renamed the marker | |
13904 | in the sources, and output a warning. | |
13905 | ||
13906 | 2) For a tracepoint set at a given line number, look for a marker | |
13907 | at the new address of the old line number. If one is found there, | |
13908 | assume to be the same marker. If the name / string id of the | |
13909 | marker found is different from the previous known name, assume that | |
13910 | means the user renamed the marker in the sources, and output a | |
13911 | warning. | |
13912 | ||
13913 | 3) If a marker is no longer found at the same address or line, it | |
13914 | may mean the marker no longer exists. But it may also just mean | |
13915 | the code changed a bit. Maybe the user added a few lines of code | |
13916 | that made the marker move up or down (in line number terms). Ask | |
13917 | the target for info about the marker with the string id as we knew | |
13918 | it. If found, update line number and address in the matching | |
13919 | static tracepoint. This will get confused if there's more than one | |
13920 | marker with the same ID (possible in UST, although unadvised | |
13921 | precisely because it confuses tools). */ | |
13922 | ||
13923 | static struct symtab_and_line | |
13924 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13925 | { | |
d9b3f62e | 13926 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13927 | struct static_tracepoint_marker marker; |
13928 | CORE_ADDR pc; | |
0fb4aa4b PA |
13929 | |
13930 | pc = sal.pc; | |
13931 | if (sal.line) | |
13932 | find_line_pc (sal.symtab, sal.line, &pc); | |
13933 | ||
13934 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13935 | { | |
d9b3f62e | 13936 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13937 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13938 | b->number, | |
d9b3f62e | 13939 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13940 | |
d9b3f62e PA |
13941 | xfree (tp->static_trace_marker_id); |
13942 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13943 | release_static_tracepoint_marker (&marker); |
13944 | ||
13945 | return sal; | |
13946 | } | |
13947 | ||
13948 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13949 | by string ID. */ | |
13950 | if (!sal.explicit_pc | |
13951 | && sal.line != 0 | |
13952 | && sal.symtab != NULL | |
d9b3f62e | 13953 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13954 | { |
13955 | VEC(static_tracepoint_marker_p) *markers; | |
13956 | ||
13957 | markers | |
d9b3f62e | 13958 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13959 | |
13960 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13961 | { | |
80e1d417 | 13962 | struct symtab_and_line sal2; |
0fb4aa4b | 13963 | struct symbol *sym; |
80e1d417 | 13964 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13965 | struct ui_out *uiout = current_uiout; |
67994074 | 13966 | struct explicit_location explicit_loc; |
0fb4aa4b | 13967 | |
80e1d417 | 13968 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13969 | |
d9b3f62e | 13970 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13971 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13972 | |
13973 | warning (_("marker for static tracepoint %d (%s) not " | |
13974 | "found at previous line number"), | |
d9b3f62e | 13975 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13976 | |
80e1d417 | 13977 | init_sal (&sal2); |
0fb4aa4b | 13978 | |
80e1d417 | 13979 | sal2.pc = tpmarker->address; |
0fb4aa4b | 13980 | |
80e1d417 AS |
13981 | sal2 = find_pc_line (tpmarker->address, 0); |
13982 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
112e8700 | 13983 | uiout->text ("Now in "); |
0fb4aa4b PA |
13984 | if (sym) |
13985 | { | |
112e8700 SM |
13986 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); |
13987 | uiout->text (" at "); | |
0fb4aa4b | 13988 | } |
112e8700 | 13989 | uiout->field_string ("file", |
05cba821 | 13990 | symtab_to_filename_for_display (sal2.symtab)); |
112e8700 | 13991 | uiout->text (":"); |
0fb4aa4b | 13992 | |
112e8700 | 13993 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13994 | { |
0b0865da | 13995 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13996 | |
112e8700 | 13997 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13998 | } |
13999 | ||
112e8700 SM |
14000 | uiout->field_int ("line", sal2.line); |
14001 | uiout->text ("\n"); | |
0fb4aa4b | 14002 | |
80e1d417 | 14003 | b->loc->line_number = sal2.line; |
2f202fde | 14004 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14005 | |
d28cd78a | 14006 | b->location.reset (NULL); |
67994074 KS |
14007 | initialize_explicit_location (&explicit_loc); |
14008 | explicit_loc.source_filename | |
00e52e53 | 14009 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14010 | explicit_loc.line_offset.offset = b->loc->line_number; |
14011 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 14012 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
14013 | |
14014 | /* Might be nice to check if function changed, and warn if | |
14015 | so. */ | |
14016 | ||
80e1d417 | 14017 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14018 | } |
14019 | } | |
14020 | return sal; | |
14021 | } | |
14022 | ||
8d3788bd VP |
14023 | /* Returns 1 iff locations A and B are sufficiently same that |
14024 | we don't need to report breakpoint as changed. */ | |
14025 | ||
14026 | static int | |
14027 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14028 | { | |
14029 | while (a && b) | |
14030 | { | |
14031 | if (a->address != b->address) | |
14032 | return 0; | |
14033 | ||
14034 | if (a->shlib_disabled != b->shlib_disabled) | |
14035 | return 0; | |
14036 | ||
14037 | if (a->enabled != b->enabled) | |
14038 | return 0; | |
14039 | ||
14040 | a = a->next; | |
14041 | b = b->next; | |
14042 | } | |
14043 | ||
14044 | if ((a == NULL) != (b == NULL)) | |
14045 | return 0; | |
14046 | ||
14047 | return 1; | |
14048 | } | |
14049 | ||
c2f4122d PA |
14050 | /* Split all locations of B that are bound to PSPACE out of B's |
14051 | location list to a separate list and return that list's head. If | |
14052 | PSPACE is NULL, hoist out all locations of B. */ | |
14053 | ||
14054 | static struct bp_location * | |
14055 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14056 | { | |
14057 | struct bp_location head; | |
14058 | struct bp_location *i = b->loc; | |
14059 | struct bp_location **i_link = &b->loc; | |
14060 | struct bp_location *hoisted = &head; | |
14061 | ||
14062 | if (pspace == NULL) | |
14063 | { | |
14064 | i = b->loc; | |
14065 | b->loc = NULL; | |
14066 | return i; | |
14067 | } | |
14068 | ||
14069 | head.next = NULL; | |
14070 | ||
14071 | while (i != NULL) | |
14072 | { | |
14073 | if (i->pspace == pspace) | |
14074 | { | |
14075 | *i_link = i->next; | |
14076 | i->next = NULL; | |
14077 | hoisted->next = i; | |
14078 | hoisted = i; | |
14079 | } | |
14080 | else | |
14081 | i_link = &i->next; | |
14082 | i = *i_link; | |
14083 | } | |
14084 | ||
14085 | return head.next; | |
14086 | } | |
14087 | ||
14088 | /* Create new breakpoint locations for B (a hardware or software | |
14089 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14090 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14091 | FILTER_PSPACE. Locations of other program spaces are left | |
14092 | untouched. */ | |
f1310107 | 14093 | |
0e30163f | 14094 | void |
0d381245 | 14095 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14096 | struct program_space *filter_pspace, |
f1310107 TJB |
14097 | struct symtabs_and_lines sals, |
14098 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14099 | { |
14100 | int i; | |
c2f4122d | 14101 | struct bp_location *existing_locations; |
0d381245 | 14102 | |
f8eba3c6 TT |
14103 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14104 | { | |
14105 | /* Ranged breakpoints have only one start location and one end | |
14106 | location. */ | |
14107 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14108 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14109 | "multiple locations found\n"), | |
14110 | b->number); | |
14111 | return; | |
14112 | } | |
f1310107 | 14113 | |
4a64f543 MS |
14114 | /* If there's no new locations, and all existing locations are |
14115 | pending, don't do anything. This optimizes the common case where | |
14116 | all locations are in the same shared library, that was unloaded. | |
14117 | We'd like to retain the location, so that when the library is | |
14118 | loaded again, we don't loose the enabled/disabled status of the | |
14119 | individual locations. */ | |
c2f4122d | 14120 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14121 | return; |
14122 | ||
c2f4122d | 14123 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14124 | |
0d381245 | 14125 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14126 | { |
f8eba3c6 TT |
14127 | struct bp_location *new_loc; |
14128 | ||
14129 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14130 | ||
14131 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14132 | |
0d381245 VP |
14133 | /* Reparse conditions, they might contain references to the |
14134 | old symtab. */ | |
14135 | if (b->cond_string != NULL) | |
14136 | { | |
bbc13ae3 | 14137 | const char *s; |
fe3f5fa8 | 14138 | |
0d381245 | 14139 | s = b->cond_string; |
492d29ea | 14140 | TRY |
0d381245 | 14141 | { |
1bb9788d TT |
14142 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14143 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14144 | 0); |
14145 | } | |
492d29ea | 14146 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14147 | { |
3e43a32a MS |
14148 | warning (_("failed to reevaluate condition " |
14149 | "for breakpoint %d: %s"), | |
0d381245 VP |
14150 | b->number, e.message); |
14151 | new_loc->enabled = 0; | |
14152 | } | |
492d29ea | 14153 | END_CATCH |
0d381245 | 14154 | } |
fe3f5fa8 | 14155 | |
f1310107 TJB |
14156 | if (sals_end.nelts) |
14157 | { | |
14158 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14159 | ||
14160 | new_loc->length = end - sals.sals[0].pc + 1; | |
14161 | } | |
0d381245 | 14162 | } |
fe3f5fa8 | 14163 | |
4a64f543 MS |
14164 | /* If possible, carry over 'disable' status from existing |
14165 | breakpoints. */ | |
0d381245 VP |
14166 | { |
14167 | struct bp_location *e = existing_locations; | |
776592bf DE |
14168 | /* If there are multiple breakpoints with the same function name, |
14169 | e.g. for inline functions, comparing function names won't work. | |
14170 | Instead compare pc addresses; this is just a heuristic as things | |
14171 | may have moved, but in practice it gives the correct answer | |
14172 | often enough until a better solution is found. */ | |
14173 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14174 | ||
0d381245 VP |
14175 | for (; e; e = e->next) |
14176 | { | |
14177 | if (!e->enabled && e->function_name) | |
14178 | { | |
14179 | struct bp_location *l = b->loc; | |
776592bf DE |
14180 | if (have_ambiguous_names) |
14181 | { | |
14182 | for (; l; l = l->next) | |
f1310107 | 14183 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14184 | { |
14185 | l->enabled = 0; | |
14186 | break; | |
14187 | } | |
14188 | } | |
14189 | else | |
14190 | { | |
14191 | for (; l; l = l->next) | |
14192 | if (l->function_name | |
14193 | && strcmp (e->function_name, l->function_name) == 0) | |
14194 | { | |
14195 | l->enabled = 0; | |
14196 | break; | |
14197 | } | |
14198 | } | |
0d381245 VP |
14199 | } |
14200 | } | |
14201 | } | |
fe3f5fa8 | 14202 | |
8d3788bd VP |
14203 | if (!locations_are_equal (existing_locations, b->loc)) |
14204 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14205 | } |
14206 | ||
f00aae0f | 14207 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14208 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14209 | ||
14210 | static struct symtabs_and_lines | |
f00aae0f | 14211 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14212 | struct program_space *search_pspace, int *found) |
ef23e705 | 14213 | { |
02d20e4a | 14214 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14215 | struct gdb_exception exception = exception_none; |
ef23e705 | 14216 | |
983af33b | 14217 | gdb_assert (b->ops != NULL); |
ef23e705 | 14218 | |
492d29ea | 14219 | TRY |
ef23e705 | 14220 | { |
c2f4122d | 14221 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14222 | } |
492d29ea | 14223 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14224 | { |
14225 | int not_found_and_ok = 0; | |
492d29ea PA |
14226 | |
14227 | exception = e; | |
14228 | ||
ef23e705 TJB |
14229 | /* For pending breakpoints, it's expected that parsing will |
14230 | fail until the right shared library is loaded. User has | |
14231 | already told to create pending breakpoints and don't need | |
14232 | extra messages. If breakpoint is in bp_shlib_disabled | |
14233 | state, then user already saw the message about that | |
14234 | breakpoint being disabled, and don't want to see more | |
14235 | errors. */ | |
58438ac1 | 14236 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14237 | && (b->condition_not_parsed |
14238 | || (b->loc != NULL | |
14239 | && search_pspace != NULL | |
14240 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14241 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14242 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14243 | || b->enable_state == bp_disabled)) |
14244 | not_found_and_ok = 1; | |
14245 | ||
14246 | if (!not_found_and_ok) | |
14247 | { | |
14248 | /* We surely don't want to warn about the same breakpoint | |
14249 | 10 times. One solution, implemented here, is disable | |
14250 | the breakpoint on error. Another solution would be to | |
14251 | have separate 'warning emitted' flag. Since this | |
14252 | happens only when a binary has changed, I don't know | |
14253 | which approach is better. */ | |
14254 | b->enable_state = bp_disabled; | |
14255 | throw_exception (e); | |
14256 | } | |
14257 | } | |
492d29ea | 14258 | END_CATCH |
ef23e705 | 14259 | |
492d29ea | 14260 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14261 | { |
f8eba3c6 | 14262 | int i; |
ef23e705 | 14263 | |
f8eba3c6 TT |
14264 | for (i = 0; i < sals.nelts; ++i) |
14265 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14266 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14267 | { |
ed1d1739 KS |
14268 | char *cond_string, *extra_string; |
14269 | int thread, task; | |
ef23e705 | 14270 | |
f00aae0f | 14271 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14272 | &cond_string, &thread, &task, |
14273 | &extra_string); | |
f00aae0f | 14274 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14275 | if (cond_string) |
14276 | b->cond_string = cond_string; | |
14277 | b->thread = thread; | |
14278 | b->task = task; | |
e7e0cddf | 14279 | if (extra_string) |
f00aae0f KS |
14280 | { |
14281 | xfree (b->extra_string); | |
14282 | b->extra_string = extra_string; | |
14283 | } | |
ef23e705 TJB |
14284 | b->condition_not_parsed = 0; |
14285 | } | |
14286 | ||
983af33b | 14287 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14288 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14289 | |
58438ac1 TT |
14290 | *found = 1; |
14291 | } | |
14292 | else | |
14293 | *found = 0; | |
ef23e705 TJB |
14294 | |
14295 | return sals; | |
14296 | } | |
14297 | ||
348d480f PA |
14298 | /* The default re_set method, for typical hardware or software |
14299 | breakpoints. Reevaluate the breakpoint and recreate its | |
14300 | locations. */ | |
14301 | ||
14302 | static void | |
28010a5d | 14303 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14304 | { |
14305 | int found; | |
f1310107 | 14306 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14307 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14308 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14309 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14310 | |
d28cd78a | 14311 | sals = location_to_sals (b, b->location.get (), filter_pspace, &found); |
ef23e705 TJB |
14312 | if (found) |
14313 | { | |
14314 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14315 | expanded = sals; |
ef23e705 TJB |
14316 | } |
14317 | ||
f00aae0f | 14318 | if (b->location_range_end != NULL) |
f1310107 | 14319 | { |
d28cd78a | 14320 | sals_end = location_to_sals (b, b->location_range_end.get (), |
c2f4122d | 14321 | filter_pspace, &found); |
f1310107 TJB |
14322 | if (found) |
14323 | { | |
14324 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14325 | expanded_end = sals_end; |
f1310107 TJB |
14326 | } |
14327 | } | |
14328 | ||
c2f4122d | 14329 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14330 | } |
14331 | ||
983af33b SDJ |
14332 | /* Default method for creating SALs from an address string. It basically |
14333 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14334 | ||
14335 | static void | |
f00aae0f KS |
14336 | create_sals_from_location_default (const struct event_location *location, |
14337 | struct linespec_result *canonical, | |
14338 | enum bptype type_wanted) | |
983af33b | 14339 | { |
f00aae0f | 14340 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14341 | } |
14342 | ||
14343 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14344 | function for the `create_breakpoints_sal' method of | |
14345 | breakpoint_ops. */ | |
14346 | ||
14347 | static void | |
14348 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14349 | struct linespec_result *canonical, | |
e1e01040 PA |
14350 | gdb::unique_xmalloc_ptr<char> cond_string, |
14351 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
14352 | enum bptype type_wanted, |
14353 | enum bpdisp disposition, | |
14354 | int thread, | |
14355 | int task, int ignore_count, | |
14356 | const struct breakpoint_ops *ops, | |
14357 | int from_tty, int enabled, | |
44f238bb | 14358 | int internal, unsigned flags) |
983af33b | 14359 | { |
e1e01040 PA |
14360 | create_breakpoints_sal (gdbarch, canonical, |
14361 | std::move (cond_string), | |
14362 | std::move (extra_string), | |
983af33b SDJ |
14363 | type_wanted, disposition, |
14364 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14365 | enabled, internal, flags); |
983af33b SDJ |
14366 | } |
14367 | ||
14368 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14369 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14370 | |
14371 | static void | |
f00aae0f KS |
14372 | decode_location_default (struct breakpoint *b, |
14373 | const struct event_location *location, | |
c2f4122d | 14374 | struct program_space *search_pspace, |
983af33b SDJ |
14375 | struct symtabs_and_lines *sals) |
14376 | { | |
14377 | struct linespec_result canonical; | |
14378 | ||
c2f4122d | 14379 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14380 | (struct symtab *) NULL, 0, |
14381 | &canonical, multiple_symbols_all, | |
14382 | b->filter); | |
14383 | ||
14384 | /* We should get 0 or 1 resulting SALs. */ | |
14385 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14386 | ||
14387 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14388 | { | |
14389 | struct linespec_sals *lsal; | |
14390 | ||
14391 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14392 | *sals = lsal->sals; | |
14393 | /* Arrange it so the destructor does not free the | |
14394 | contents. */ | |
14395 | lsal->sals.sals = NULL; | |
14396 | } | |
983af33b SDJ |
14397 | } |
14398 | ||
28010a5d PA |
14399 | /* Prepare the global context for a re-set of breakpoint B. */ |
14400 | ||
14401 | static struct cleanup * | |
14402 | prepare_re_set_context (struct breakpoint *b) | |
14403 | { | |
28010a5d | 14404 | input_radix = b->input_radix; |
28010a5d PA |
14405 | set_language (b->language); |
14406 | ||
c2f4122d | 14407 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14408 | } |
14409 | ||
c906108c SS |
14410 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14411 | The value we return ends up being the return value from catch_errors. | |
14412 | Unused in this case. */ | |
14413 | ||
14414 | static int | |
4efb68b1 | 14415 | breakpoint_re_set_one (void *bint) |
c906108c | 14416 | { |
4a64f543 | 14417 | /* Get past catch_errs. */ |
53a5351d | 14418 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14419 | struct cleanup *cleanups; |
c906108c | 14420 | |
348d480f PA |
14421 | cleanups = prepare_re_set_context (b); |
14422 | b->ops->re_set (b); | |
14423 | do_cleanups (cleanups); | |
c906108c SS |
14424 | return 0; |
14425 | } | |
14426 | ||
c2f4122d PA |
14427 | /* Re-set breakpoint locations for the current program space. |
14428 | Locations bound to other program spaces are left untouched. */ | |
14429 | ||
c906108c | 14430 | void |
69de3c6a | 14431 | breakpoint_re_set (void) |
c906108c | 14432 | { |
35df4500 | 14433 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14434 | enum language save_language; |
14435 | int save_input_radix; | |
c5aa993b | 14436 | |
c906108c SS |
14437 | save_language = current_language->la_language; |
14438 | save_input_radix = input_radix; | |
2a7f3dff | 14439 | |
c5aa993b | 14440 | { |
5ed8105e | 14441 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 14442 | |
5ed8105e PA |
14443 | /* Note: we must not try to insert locations until after all |
14444 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14445 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14446 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 14447 | |
5ed8105e PA |
14448 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
14449 | { | |
14450 | /* Format possible error msg. */ | |
14451 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", | |
14452 | b->number); | |
14453 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
14454 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); | |
14455 | do_cleanups (cleanups); | |
14456 | } | |
14457 | set_language (save_language); | |
14458 | input_radix = save_input_radix; | |
14459 | ||
14460 | jit_breakpoint_re_set (); | |
14461 | } | |
6c95b8df | 14462 | |
af02033e PP |
14463 | create_overlay_event_breakpoint (); |
14464 | create_longjmp_master_breakpoint (); | |
14465 | create_std_terminate_master_breakpoint (); | |
186c406b | 14466 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14467 | |
14468 | /* Now we can insert. */ | |
14469 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14470 | } |
14471 | \f | |
c906108c SS |
14472 | /* Reset the thread number of this breakpoint: |
14473 | ||
14474 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14475 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14476 | void |
fba45db2 | 14477 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14478 | { |
14479 | if (b->thread != -1) | |
14480 | { | |
39f77062 | 14481 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14482 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14483 | |
14484 | /* We're being called after following a fork. The new fork is | |
14485 | selected as current, and unless this was a vfork will have a | |
14486 | different program space from the original thread. Reset that | |
14487 | as well. */ | |
14488 | b->loc->pspace = current_program_space; | |
c906108c SS |
14489 | } |
14490 | } | |
14491 | ||
03ac34d5 MS |
14492 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14493 | If from_tty is nonzero, it prints a message to that effect, | |
14494 | which ends with a period (no newline). */ | |
14495 | ||
c906108c | 14496 | void |
fba45db2 | 14497 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14498 | { |
52f0bd74 | 14499 | struct breakpoint *b; |
c906108c SS |
14500 | |
14501 | if (count < 0) | |
14502 | count = 0; | |
14503 | ||
14504 | ALL_BREAKPOINTS (b) | |
14505 | if (b->number == bptnum) | |
c5aa993b | 14506 | { |
d77f58be SS |
14507 | if (is_tracepoint (b)) |
14508 | { | |
14509 | if (from_tty && count != 0) | |
14510 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14511 | bptnum); | |
14512 | return; | |
14513 | } | |
14514 | ||
c5aa993b | 14515 | b->ignore_count = count; |
221ea385 KS |
14516 | if (from_tty) |
14517 | { | |
14518 | if (count == 0) | |
3e43a32a MS |
14519 | printf_filtered (_("Will stop next time " |
14520 | "breakpoint %d is reached."), | |
221ea385 KS |
14521 | bptnum); |
14522 | else if (count == 1) | |
a3f17187 | 14523 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14524 | bptnum); |
14525 | else | |
3e43a32a MS |
14526 | printf_filtered (_("Will ignore next %d " |
14527 | "crossings of breakpoint %d."), | |
221ea385 KS |
14528 | count, bptnum); |
14529 | } | |
8d3788bd | 14530 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14531 | return; |
14532 | } | |
c906108c | 14533 | |
8a3fe4f8 | 14534 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14535 | } |
14536 | ||
c906108c SS |
14537 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14538 | ||
14539 | static void | |
fba45db2 | 14540 | ignore_command (char *args, int from_tty) |
c906108c SS |
14541 | { |
14542 | char *p = args; | |
52f0bd74 | 14543 | int num; |
c906108c SS |
14544 | |
14545 | if (p == 0) | |
e2e0b3e5 | 14546 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14547 | |
c906108c | 14548 | num = get_number (&p); |
5c44784c | 14549 | if (num == 0) |
8a3fe4f8 | 14550 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14551 | if (*p == 0) |
8a3fe4f8 | 14552 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14553 | |
14554 | set_ignore_count (num, | |
14555 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14556 | from_tty); | |
221ea385 KS |
14557 | if (from_tty) |
14558 | printf_filtered ("\n"); | |
c906108c SS |
14559 | } |
14560 | \f | |
14561 | /* Call FUNCTION on each of the breakpoints | |
14562 | whose numbers are given in ARGS. */ | |
14563 | ||
14564 | static void | |
896b6bda PA |
14565 | map_breakpoint_numbers (const char *args, |
14566 | void (*function) (struct breakpoint *, | |
14567 | void *), | |
95a42b64 | 14568 | void *data) |
c906108c | 14569 | { |
52f0bd74 AC |
14570 | int num; |
14571 | struct breakpoint *b, *tmp; | |
c906108c | 14572 | |
b9d61307 | 14573 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14574 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14575 | |
bfd28288 | 14576 | number_or_range_parser parser (args); |
197f0a60 | 14577 | |
bfd28288 | 14578 | while (!parser.finished ()) |
c906108c | 14579 | { |
bfd28288 PA |
14580 | const char *p = parser.cur_tok (); |
14581 | bool match = false; | |
197f0a60 | 14582 | |
bfd28288 | 14583 | num = parser.get_number (); |
5c44784c | 14584 | if (num == 0) |
c5aa993b | 14585 | { |
8a3fe4f8 | 14586 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14587 | } |
14588 | else | |
14589 | { | |
14590 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14591 | if (b->number == num) | |
14592 | { | |
bfd28288 | 14593 | match = true; |
cdac0397 | 14594 | function (b, data); |
11cf8741 | 14595 | break; |
5c44784c | 14596 | } |
bfd28288 | 14597 | if (!match) |
a3f17187 | 14598 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14599 | } |
c906108c SS |
14600 | } |
14601 | } | |
14602 | ||
0d381245 VP |
14603 | static struct bp_location * |
14604 | find_location_by_number (char *number) | |
14605 | { | |
14606 | char *dot = strchr (number, '.'); | |
14607 | char *p1; | |
14608 | int bp_num; | |
14609 | int loc_num; | |
14610 | struct breakpoint *b; | |
14611 | struct bp_location *loc; | |
14612 | ||
14613 | *dot = '\0'; | |
14614 | ||
14615 | p1 = number; | |
197f0a60 | 14616 | bp_num = get_number (&p1); |
0d381245 VP |
14617 | if (bp_num == 0) |
14618 | error (_("Bad breakpoint number '%s'"), number); | |
14619 | ||
14620 | ALL_BREAKPOINTS (b) | |
14621 | if (b->number == bp_num) | |
14622 | { | |
14623 | break; | |
14624 | } | |
14625 | ||
14626 | if (!b || b->number != bp_num) | |
14627 | error (_("Bad breakpoint number '%s'"), number); | |
14628 | ||
14629 | p1 = dot+1; | |
197f0a60 | 14630 | loc_num = get_number (&p1); |
0d381245 VP |
14631 | if (loc_num == 0) |
14632 | error (_("Bad breakpoint location number '%s'"), number); | |
14633 | ||
14634 | --loc_num; | |
14635 | loc = b->loc; | |
14636 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14637 | ; | |
14638 | if (!loc) | |
14639 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14640 | ||
14641 | return loc; | |
14642 | } | |
14643 | ||
14644 | ||
1900040c MS |
14645 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14646 | If from_tty is nonzero, it prints a message to that effect, | |
14647 | which ends with a period (no newline). */ | |
14648 | ||
c906108c | 14649 | void |
fba45db2 | 14650 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14651 | { |
14652 | /* Never disable a watchpoint scope breakpoint; we want to | |
14653 | hit them when we leave scope so we can delete both the | |
14654 | watchpoint and its scope breakpoint at that time. */ | |
14655 | if (bpt->type == bp_watchpoint_scope) | |
14656 | return; | |
14657 | ||
b5de0fa7 | 14658 | bpt->enable_state = bp_disabled; |
c906108c | 14659 | |
b775012e LM |
14660 | /* Mark breakpoint locations modified. */ |
14661 | mark_breakpoint_modified (bpt); | |
14662 | ||
d248b706 KY |
14663 | if (target_supports_enable_disable_tracepoint () |
14664 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14665 | { | |
14666 | struct bp_location *location; | |
14667 | ||
14668 | for (location = bpt->loc; location; location = location->next) | |
14669 | target_disable_tracepoint (location); | |
14670 | } | |
14671 | ||
44702360 | 14672 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14673 | |
8d3788bd | 14674 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14675 | } |
14676 | ||
51be5b68 PA |
14677 | /* A callback for iterate_over_related_breakpoints. */ |
14678 | ||
14679 | static void | |
14680 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14681 | { | |
14682 | disable_breakpoint (b); | |
14683 | } | |
14684 | ||
95a42b64 TT |
14685 | /* A callback for map_breakpoint_numbers that calls |
14686 | disable_breakpoint. */ | |
14687 | ||
14688 | static void | |
14689 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14690 | { | |
51be5b68 | 14691 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14692 | } |
14693 | ||
c906108c | 14694 | static void |
fba45db2 | 14695 | disable_command (char *args, int from_tty) |
c906108c | 14696 | { |
c906108c | 14697 | if (args == 0) |
46c6471b PA |
14698 | { |
14699 | struct breakpoint *bpt; | |
14700 | ||
14701 | ALL_BREAKPOINTS (bpt) | |
14702 | if (user_breakpoint_p (bpt)) | |
14703 | disable_breakpoint (bpt); | |
14704 | } | |
9eaabc75 | 14705 | else |
0d381245 | 14706 | { |
9eaabc75 MW |
14707 | char *num = extract_arg (&args); |
14708 | ||
14709 | while (num) | |
d248b706 | 14710 | { |
9eaabc75 | 14711 | if (strchr (num, '.')) |
b775012e | 14712 | { |
9eaabc75 MW |
14713 | struct bp_location *loc = find_location_by_number (num); |
14714 | ||
14715 | if (loc) | |
14716 | { | |
14717 | if (loc->enabled) | |
14718 | { | |
14719 | loc->enabled = 0; | |
14720 | mark_breakpoint_location_modified (loc); | |
14721 | } | |
14722 | if (target_supports_enable_disable_tracepoint () | |
14723 | && current_trace_status ()->running && loc->owner | |
14724 | && is_tracepoint (loc->owner)) | |
14725 | target_disable_tracepoint (loc); | |
14726 | } | |
44702360 | 14727 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14728 | } |
9eaabc75 MW |
14729 | else |
14730 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14731 | num = extract_arg (&args); | |
d248b706 | 14732 | } |
0d381245 | 14733 | } |
c906108c SS |
14734 | } |
14735 | ||
14736 | static void | |
816338b5 SS |
14737 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14738 | int count) | |
c906108c | 14739 | { |
afe38095 | 14740 | int target_resources_ok; |
c906108c SS |
14741 | |
14742 | if (bpt->type == bp_hardware_breakpoint) | |
14743 | { | |
14744 | int i; | |
c5aa993b | 14745 | i = hw_breakpoint_used_count (); |
53a5351d | 14746 | target_resources_ok = |
d92524f1 | 14747 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14748 | i + 1, 0); |
c906108c | 14749 | if (target_resources_ok == 0) |
8a3fe4f8 | 14750 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14751 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14752 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14753 | } |
14754 | ||
cc60f2e3 | 14755 | if (is_watchpoint (bpt)) |
c906108c | 14756 | { |
d07205c2 | 14757 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14758 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14759 | |
492d29ea | 14760 | TRY |
c906108c | 14761 | { |
3a5c3e22 PA |
14762 | struct watchpoint *w = (struct watchpoint *) bpt; |
14763 | ||
1e718ff1 TJB |
14764 | orig_enable_state = bpt->enable_state; |
14765 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14766 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14767 | } |
492d29ea | 14768 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14769 | { |
1e718ff1 | 14770 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14771 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14772 | bpt->number); | |
14773 | return; | |
c5aa993b | 14774 | } |
492d29ea | 14775 | END_CATCH |
c906108c | 14776 | } |
0101ce28 | 14777 | |
b775012e LM |
14778 | bpt->enable_state = bp_enabled; |
14779 | ||
14780 | /* Mark breakpoint locations modified. */ | |
14781 | mark_breakpoint_modified (bpt); | |
14782 | ||
d248b706 KY |
14783 | if (target_supports_enable_disable_tracepoint () |
14784 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14785 | { | |
14786 | struct bp_location *location; | |
14787 | ||
14788 | for (location = bpt->loc; location; location = location->next) | |
14789 | target_enable_tracepoint (location); | |
14790 | } | |
14791 | ||
b4c291bb | 14792 | bpt->disposition = disposition; |
816338b5 | 14793 | bpt->enable_count = count; |
44702360 | 14794 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14795 | |
8d3788bd | 14796 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14797 | } |
14798 | ||
fe3f5fa8 | 14799 | |
c906108c | 14800 | void |
fba45db2 | 14801 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14802 | { |
816338b5 | 14803 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14804 | } |
14805 | ||
14806 | static void | |
14807 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14808 | { | |
14809 | enable_breakpoint (bpt); | |
c906108c SS |
14810 | } |
14811 | ||
95a42b64 TT |
14812 | /* A callback for map_breakpoint_numbers that calls |
14813 | enable_breakpoint. */ | |
14814 | ||
14815 | static void | |
14816 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14817 | { | |
51be5b68 | 14818 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14819 | } |
14820 | ||
c906108c SS |
14821 | /* The enable command enables the specified breakpoints (or all defined |
14822 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14823 | in stopping the inferior. */ |
c906108c | 14824 | |
c906108c | 14825 | static void |
fba45db2 | 14826 | enable_command (char *args, int from_tty) |
c906108c | 14827 | { |
c906108c | 14828 | if (args == 0) |
46c6471b PA |
14829 | { |
14830 | struct breakpoint *bpt; | |
14831 | ||
14832 | ALL_BREAKPOINTS (bpt) | |
14833 | if (user_breakpoint_p (bpt)) | |
14834 | enable_breakpoint (bpt); | |
14835 | } | |
9eaabc75 | 14836 | else |
0d381245 | 14837 | { |
9eaabc75 MW |
14838 | char *num = extract_arg (&args); |
14839 | ||
14840 | while (num) | |
d248b706 | 14841 | { |
9eaabc75 | 14842 | if (strchr (num, '.')) |
b775012e | 14843 | { |
9eaabc75 MW |
14844 | struct bp_location *loc = find_location_by_number (num); |
14845 | ||
14846 | if (loc) | |
14847 | { | |
14848 | if (!loc->enabled) | |
14849 | { | |
14850 | loc->enabled = 1; | |
14851 | mark_breakpoint_location_modified (loc); | |
14852 | } | |
14853 | if (target_supports_enable_disable_tracepoint () | |
14854 | && current_trace_status ()->running && loc->owner | |
14855 | && is_tracepoint (loc->owner)) | |
14856 | target_enable_tracepoint (loc); | |
14857 | } | |
44702360 | 14858 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14859 | } |
9eaabc75 MW |
14860 | else |
14861 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
14862 | num = extract_arg (&args); | |
d248b706 | 14863 | } |
0d381245 | 14864 | } |
c906108c SS |
14865 | } |
14866 | ||
816338b5 SS |
14867 | /* This struct packages up disposition data for application to multiple |
14868 | breakpoints. */ | |
14869 | ||
14870 | struct disp_data | |
14871 | { | |
14872 | enum bpdisp disp; | |
14873 | int count; | |
14874 | }; | |
14875 | ||
c906108c | 14876 | static void |
51be5b68 PA |
14877 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14878 | { | |
816338b5 | 14879 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14880 | |
816338b5 | 14881 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14882 | } |
14883 | ||
14884 | static void | |
14885 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14886 | { |
816338b5 | 14887 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14888 | |
14889 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14890 | } |
14891 | ||
c906108c | 14892 | static void |
fba45db2 | 14893 | enable_once_command (char *args, int from_tty) |
c906108c | 14894 | { |
51be5b68 | 14895 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14896 | } |
14897 | ||
816338b5 SS |
14898 | static void |
14899 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14900 | { | |
14901 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14902 | ||
14903 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14904 | } | |
14905 | ||
14906 | static void | |
14907 | enable_count_command (char *args, int from_tty) | |
14908 | { | |
b9d61307 SM |
14909 | int count; |
14910 | ||
14911 | if (args == NULL) | |
14912 | error_no_arg (_("hit count")); | |
14913 | ||
14914 | count = get_number (&args); | |
816338b5 SS |
14915 | |
14916 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14917 | } | |
14918 | ||
c906108c | 14919 | static void |
51be5b68 | 14920 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14921 | { |
816338b5 | 14922 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14923 | |
14924 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14925 | } |
14926 | ||
c906108c | 14927 | static void |
fba45db2 | 14928 | enable_delete_command (char *args, int from_tty) |
c906108c | 14929 | { |
51be5b68 | 14930 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14931 | } |
14932 | \f | |
fa8d40ab JJ |
14933 | static void |
14934 | set_breakpoint_cmd (char *args, int from_tty) | |
14935 | { | |
14936 | } | |
14937 | ||
14938 | static void | |
14939 | show_breakpoint_cmd (char *args, int from_tty) | |
14940 | { | |
14941 | } | |
14942 | ||
1f3b5d1b PP |
14943 | /* Invalidate last known value of any hardware watchpoint if |
14944 | the memory which that value represents has been written to by | |
14945 | GDB itself. */ | |
14946 | ||
14947 | static void | |
8de0566d YQ |
14948 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14949 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14950 | const bfd_byte *data) |
14951 | { | |
14952 | struct breakpoint *bp; | |
14953 | ||
14954 | ALL_BREAKPOINTS (bp) | |
14955 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14956 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14957 | { |
3a5c3e22 | 14958 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14959 | |
3a5c3e22 PA |
14960 | if (wp->val_valid && wp->val) |
14961 | { | |
14962 | struct bp_location *loc; | |
14963 | ||
14964 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14965 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14966 | && loc->address + loc->length > addr | |
14967 | && addr + len > loc->address) | |
14968 | { | |
14969 | value_free (wp->val); | |
14970 | wp->val = NULL; | |
14971 | wp->val_valid = 0; | |
14972 | } | |
14973 | } | |
1f3b5d1b PP |
14974 | } |
14975 | } | |
14976 | ||
8181d85f DJ |
14977 | /* Create and insert a breakpoint for software single step. */ |
14978 | ||
14979 | void | |
6c95b8df | 14980 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14981 | struct address_space *aspace, |
14982 | CORE_ADDR next_pc) | |
8181d85f | 14983 | { |
7c16b83e PA |
14984 | struct thread_info *tp = inferior_thread (); |
14985 | struct symtab_and_line sal; | |
14986 | CORE_ADDR pc = next_pc; | |
8181d85f | 14987 | |
34b7e8a6 PA |
14988 | if (tp->control.single_step_breakpoints == NULL) |
14989 | { | |
14990 | tp->control.single_step_breakpoints | |
5d5658a1 | 14991 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14992 | } |
8181d85f | 14993 | |
7c16b83e PA |
14994 | sal = find_pc_line (pc, 0); |
14995 | sal.pc = pc; | |
14996 | sal.section = find_pc_overlay (pc); | |
14997 | sal.explicit_pc = 1; | |
34b7e8a6 | 14998 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14999 | |
7c16b83e | 15000 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15001 | } |
15002 | ||
93f9a11f YQ |
15003 | /* Insert single step breakpoints according to the current state. */ |
15004 | ||
15005 | int | |
15006 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
15007 | { | |
f5ea389a | 15008 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 15009 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 15010 | |
f5ea389a | 15011 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 15012 | |
a0ff9e1a | 15013 | if (!next_pcs.empty ()) |
93f9a11f | 15014 | { |
f5ea389a | 15015 | struct frame_info *frame = get_current_frame (); |
93f9a11f YQ |
15016 | struct address_space *aspace = get_frame_address_space (frame); |
15017 | ||
a0ff9e1a | 15018 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
15019 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
15020 | ||
93f9a11f YQ |
15021 | return 1; |
15022 | } | |
15023 | else | |
15024 | return 0; | |
15025 | } | |
15026 | ||
34b7e8a6 | 15027 | /* See breakpoint.h. */ |
f02253f1 HZ |
15028 | |
15029 | int | |
7c16b83e PA |
15030 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15031 | struct address_space *aspace, | |
15032 | CORE_ADDR pc) | |
1aafd4da | 15033 | { |
7c16b83e | 15034 | struct bp_location *loc; |
1aafd4da | 15035 | |
7c16b83e PA |
15036 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15037 | if (loc->inserted | |
15038 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15039 | return 1; | |
1aafd4da | 15040 | |
7c16b83e | 15041 | return 0; |
ef370185 JB |
15042 | } |
15043 | ||
15044 | /* Check whether a software single-step breakpoint is inserted at | |
15045 | PC. */ | |
15046 | ||
15047 | int | |
15048 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15049 | CORE_ADDR pc) | |
15050 | { | |
34b7e8a6 PA |
15051 | struct breakpoint *bpt; |
15052 | ||
15053 | ALL_BREAKPOINTS (bpt) | |
15054 | { | |
15055 | if (bpt->type == bp_single_step | |
15056 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15057 | return 1; | |
15058 | } | |
15059 | return 0; | |
1aafd4da UW |
15060 | } |
15061 | ||
1042e4c0 SS |
15062 | /* Tracepoint-specific operations. */ |
15063 | ||
15064 | /* Set tracepoint count to NUM. */ | |
15065 | static void | |
15066 | set_tracepoint_count (int num) | |
15067 | { | |
15068 | tracepoint_count = num; | |
4fa62494 | 15069 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15070 | } |
15071 | ||
70221824 | 15072 | static void |
1042e4c0 SS |
15073 | trace_command (char *arg, int from_tty) |
15074 | { | |
55aa24fb | 15075 | struct breakpoint_ops *ops; |
55aa24fb | 15076 | |
ffc2605c TT |
15077 | event_location_up location = string_to_event_location (&arg, |
15078 | current_language); | |
5b56227b | 15079 | if (location != NULL |
ffc2605c | 15080 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
15081 | ops = &tracepoint_probe_breakpoint_ops; |
15082 | else | |
15083 | ops = &tracepoint_breakpoint_ops; | |
15084 | ||
558a9d82 | 15085 | create_breakpoint (get_current_arch (), |
ffc2605c | 15086 | location.get (), |
f00aae0f | 15087 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15088 | 0 /* tempflag */, |
15089 | bp_tracepoint /* type_wanted */, | |
15090 | 0 /* Ignore count */, | |
15091 | pending_break_support, | |
15092 | ops, | |
15093 | from_tty, | |
15094 | 1 /* enabled */, | |
15095 | 0 /* internal */, 0); | |
1042e4c0 SS |
15096 | } |
15097 | ||
70221824 | 15098 | static void |
7a697b8d SS |
15099 | ftrace_command (char *arg, int from_tty) |
15100 | { | |
ffc2605c TT |
15101 | event_location_up location = string_to_event_location (&arg, |
15102 | current_language); | |
558a9d82 | 15103 | create_breakpoint (get_current_arch (), |
ffc2605c | 15104 | location.get (), |
f00aae0f | 15105 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15106 | 0 /* tempflag */, |
15107 | bp_fast_tracepoint /* type_wanted */, | |
15108 | 0 /* Ignore count */, | |
15109 | pending_break_support, | |
15110 | &tracepoint_breakpoint_ops, | |
15111 | from_tty, | |
15112 | 1 /* enabled */, | |
15113 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15114 | } |
15115 | ||
15116 | /* strace command implementation. Creates a static tracepoint. */ | |
15117 | ||
70221824 | 15118 | static void |
0fb4aa4b PA |
15119 | strace_command (char *arg, int from_tty) |
15120 | { | |
983af33b | 15121 | struct breakpoint_ops *ops; |
ffc2605c | 15122 | event_location_up location; |
f00aae0f | 15123 | struct cleanup *back_to; |
983af33b SDJ |
15124 | |
15125 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15126 | or with a normal static tracepoint. */ | |
61012eef | 15127 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15128 | { |
15129 | ops = &strace_marker_breakpoint_ops; | |
15130 | location = new_linespec_location (&arg); | |
15131 | } | |
983af33b | 15132 | else |
f00aae0f KS |
15133 | { |
15134 | ops = &tracepoint_breakpoint_ops; | |
15135 | location = string_to_event_location (&arg, current_language); | |
15136 | } | |
983af33b | 15137 | |
558a9d82 | 15138 | create_breakpoint (get_current_arch (), |
ffc2605c | 15139 | location.get (), |
f00aae0f | 15140 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15141 | 0 /* tempflag */, |
15142 | bp_static_tracepoint /* type_wanted */, | |
15143 | 0 /* Ignore count */, | |
15144 | pending_break_support, | |
15145 | ops, | |
15146 | from_tty, | |
15147 | 1 /* enabled */, | |
15148 | 0 /* internal */, 0); | |
7a697b8d SS |
15149 | } |
15150 | ||
409873ef SS |
15151 | /* Set up a fake reader function that gets command lines from a linked |
15152 | list that was acquired during tracepoint uploading. */ | |
15153 | ||
15154 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15155 | static int next_cmd; |
409873ef SS |
15156 | |
15157 | static char * | |
15158 | read_uploaded_action (void) | |
15159 | { | |
15160 | char *rslt; | |
15161 | ||
3149d8c1 | 15162 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15163 | |
3149d8c1 | 15164 | next_cmd++; |
409873ef SS |
15165 | |
15166 | return rslt; | |
15167 | } | |
15168 | ||
00bf0b85 SS |
15169 | /* Given information about a tracepoint as recorded on a target (which |
15170 | can be either a live system or a trace file), attempt to create an | |
15171 | equivalent GDB tracepoint. This is not a reliable process, since | |
15172 | the target does not necessarily have all the information used when | |
15173 | the tracepoint was originally defined. */ | |
15174 | ||
d9b3f62e | 15175 | struct tracepoint * |
00bf0b85 | 15176 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15177 | { |
409873ef | 15178 | char *addr_str, small_buf[100]; |
d9b3f62e | 15179 | struct tracepoint *tp; |
fd9b8c24 | 15180 | |
409873ef SS |
15181 | if (utp->at_string) |
15182 | addr_str = utp->at_string; | |
15183 | else | |
15184 | { | |
15185 | /* In the absence of a source location, fall back to raw | |
15186 | address. Since there is no way to confirm that the address | |
15187 | means the same thing as when the trace was started, warn the | |
15188 | user. */ | |
3e43a32a MS |
15189 | warning (_("Uploaded tracepoint %d has no " |
15190 | "source location, using raw address"), | |
409873ef | 15191 | utp->number); |
8c042590 | 15192 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15193 | addr_str = small_buf; |
15194 | } | |
15195 | ||
15196 | /* There's not much we can do with a sequence of bytecodes. */ | |
15197 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15198 | warning (_("Uploaded tracepoint %d condition " |
15199 | "has no source form, ignoring it"), | |
409873ef | 15200 | utp->number); |
d5551862 | 15201 | |
ffc2605c TT |
15202 | event_location_up location = string_to_event_location (&addr_str, |
15203 | current_language); | |
8cdf0e15 | 15204 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 15205 | location.get (), |
f00aae0f | 15206 | utp->cond_string, -1, addr_str, |
e7e0cddf | 15207 | 0 /* parse cond/thread */, |
8cdf0e15 | 15208 | 0 /* tempflag */, |
0fb4aa4b | 15209 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15210 | 0 /* Ignore count */, |
15211 | pending_break_support, | |
348d480f | 15212 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15213 | 0 /* from_tty */, |
84f4c1fe | 15214 | utp->enabled /* enabled */, |
44f238bb PA |
15215 | 0 /* internal */, |
15216 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 15217 | return NULL; |
fd9b8c24 | 15218 | |
409873ef | 15219 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15220 | tp = get_tracepoint (tracepoint_count); |
15221 | gdb_assert (tp != NULL); | |
d5551862 | 15222 | |
00bf0b85 SS |
15223 | if (utp->pass > 0) |
15224 | { | |
8c042590 | 15225 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 15226 | tp->number); |
00bf0b85 | 15227 | |
409873ef | 15228 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15229 | } |
15230 | ||
409873ef SS |
15231 | /* If we have uploaded versions of the original commands, set up a |
15232 | special-purpose "reader" function and call the usual command line | |
15233 | reader, then pass the result to the breakpoint command-setting | |
15234 | function. */ | |
3149d8c1 | 15235 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15236 | { |
93921405 | 15237 | command_line_up cmd_list; |
00bf0b85 | 15238 | |
409873ef | 15239 | this_utp = utp; |
3149d8c1 | 15240 | next_cmd = 0; |
d5551862 | 15241 | |
409873ef SS |
15242 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15243 | ||
c1fc2657 | 15244 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 15245 | } |
3149d8c1 SS |
15246 | else if (!VEC_empty (char_ptr, utp->actions) |
15247 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15248 | warning (_("Uploaded tracepoint %d actions " |
15249 | "have no source form, ignoring them"), | |
409873ef | 15250 | utp->number); |
00bf0b85 | 15251 | |
f196051f | 15252 | /* Copy any status information that might be available. */ |
c1fc2657 | 15253 | tp->hit_count = utp->hit_count; |
f196051f SS |
15254 | tp->traceframe_usage = utp->traceframe_usage; |
15255 | ||
00bf0b85 | 15256 | return tp; |
d9b3f62e | 15257 | } |
00bf0b85 | 15258 | |
1042e4c0 SS |
15259 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15260 | omitted. */ | |
15261 | ||
15262 | static void | |
e5a67952 | 15263 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15264 | { |
79a45e25 | 15265 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15266 | int num_printed; |
1042e4c0 | 15267 | |
e5a67952 | 15268 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15269 | |
15270 | if (num_printed == 0) | |
1042e4c0 | 15271 | { |
e5a67952 | 15272 | if (args == NULL || *args == '\0') |
112e8700 | 15273 | uiout->message ("No tracepoints.\n"); |
d77f58be | 15274 | else |
112e8700 | 15275 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15276 | } |
ad443146 SS |
15277 | |
15278 | default_collect_info (); | |
1042e4c0 SS |
15279 | } |
15280 | ||
4a64f543 | 15281 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15282 | Not supported by all targets. */ |
15283 | static void | |
15284 | enable_trace_command (char *args, int from_tty) | |
15285 | { | |
15286 | enable_command (args, from_tty); | |
15287 | } | |
15288 | ||
4a64f543 | 15289 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15290 | Not supported by all targets. */ |
15291 | static void | |
15292 | disable_trace_command (char *args, int from_tty) | |
15293 | { | |
15294 | disable_command (args, from_tty); | |
15295 | } | |
15296 | ||
4a64f543 | 15297 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15298 | static void |
15299 | delete_trace_command (char *arg, int from_tty) | |
15300 | { | |
35df4500 | 15301 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15302 | |
15303 | dont_repeat (); | |
15304 | ||
15305 | if (arg == 0) | |
15306 | { | |
15307 | int breaks_to_delete = 0; | |
15308 | ||
15309 | /* Delete all breakpoints if no argument. | |
15310 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15311 | have to be deleted with an explicit breakpoint number |
15312 | argument. */ | |
1042e4c0 | 15313 | ALL_TRACEPOINTS (b) |
46c6471b | 15314 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15315 | { |
15316 | breaks_to_delete = 1; | |
15317 | break; | |
15318 | } | |
1042e4c0 SS |
15319 | |
15320 | /* Ask user only if there are some breakpoints to delete. */ | |
15321 | if (!from_tty | |
15322 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15323 | { | |
35df4500 | 15324 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15325 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15326 | delete_breakpoint (b); |
1042e4c0 SS |
15327 | } |
15328 | } | |
15329 | else | |
51be5b68 | 15330 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15331 | } |
15332 | ||
197f0a60 TT |
15333 | /* Helper function for trace_pass_command. */ |
15334 | ||
15335 | static void | |
d9b3f62e | 15336 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15337 | { |
d9b3f62e | 15338 | tp->pass_count = count; |
c1fc2657 | 15339 | observer_notify_breakpoint_modified (tp); |
197f0a60 TT |
15340 | if (from_tty) |
15341 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 15342 | tp->number, count); |
197f0a60 TT |
15343 | } |
15344 | ||
1042e4c0 SS |
15345 | /* Set passcount for tracepoint. |
15346 | ||
15347 | First command argument is passcount, second is tracepoint number. | |
15348 | If tracepoint number omitted, apply to most recently defined. | |
15349 | Also accepts special argument "all". */ | |
15350 | ||
15351 | static void | |
15352 | trace_pass_command (char *args, int from_tty) | |
15353 | { | |
d9b3f62e | 15354 | struct tracepoint *t1; |
1042e4c0 | 15355 | unsigned int count; |
1042e4c0 SS |
15356 | |
15357 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15358 | error (_("passcount command requires an " |
15359 | "argument (count + optional TP num)")); | |
1042e4c0 | 15360 | |
4a64f543 | 15361 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15362 | |
529480d0 | 15363 | args = skip_spaces (args); |
1042e4c0 SS |
15364 | if (*args && strncasecmp (args, "all", 3) == 0) |
15365 | { | |
d9b3f62e PA |
15366 | struct breakpoint *b; |
15367 | ||
1042e4c0 | 15368 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15369 | if (*args) |
15370 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15371 | |
d9b3f62e | 15372 | ALL_TRACEPOINTS (b) |
197f0a60 | 15373 | { |
d9b3f62e | 15374 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15375 | trace_pass_set_count (t1, count, from_tty); |
15376 | } | |
15377 | } | |
15378 | else if (*args == '\0') | |
1042e4c0 | 15379 | { |
5fa1d40e | 15380 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15381 | if (t1) |
197f0a60 TT |
15382 | trace_pass_set_count (t1, count, from_tty); |
15383 | } | |
15384 | else | |
15385 | { | |
bfd28288 PA |
15386 | number_or_range_parser parser (args); |
15387 | while (!parser.finished ()) | |
1042e4c0 | 15388 | { |
bfd28288 | 15389 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15390 | if (t1) |
15391 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15392 | } |
15393 | } | |
1042e4c0 SS |
15394 | } |
15395 | ||
d9b3f62e | 15396 | struct tracepoint * |
1042e4c0 SS |
15397 | get_tracepoint (int num) |
15398 | { | |
15399 | struct breakpoint *t; | |
15400 | ||
15401 | ALL_TRACEPOINTS (t) | |
15402 | if (t->number == num) | |
d9b3f62e | 15403 | return (struct tracepoint *) t; |
1042e4c0 SS |
15404 | |
15405 | return NULL; | |
15406 | } | |
15407 | ||
d5551862 SS |
15408 | /* Find the tracepoint with the given target-side number (which may be |
15409 | different from the tracepoint number after disconnecting and | |
15410 | reconnecting). */ | |
15411 | ||
d9b3f62e | 15412 | struct tracepoint * |
d5551862 SS |
15413 | get_tracepoint_by_number_on_target (int num) |
15414 | { | |
d9b3f62e | 15415 | struct breakpoint *b; |
d5551862 | 15416 | |
d9b3f62e PA |
15417 | ALL_TRACEPOINTS (b) |
15418 | { | |
15419 | struct tracepoint *t = (struct tracepoint *) b; | |
15420 | ||
15421 | if (t->number_on_target == num) | |
15422 | return t; | |
15423 | } | |
d5551862 SS |
15424 | |
15425 | return NULL; | |
15426 | } | |
15427 | ||
1042e4c0 | 15428 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15429 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15430 | If the argument is missing, the most recent tracepoint |
15431 | (tracepoint_count) is returned. */ | |
15432 | ||
d9b3f62e | 15433 | struct tracepoint * |
197f0a60 | 15434 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15435 | number_or_range_parser *parser) |
1042e4c0 | 15436 | { |
1042e4c0 SS |
15437 | struct breakpoint *t; |
15438 | int tpnum; | |
15439 | char *instring = arg == NULL ? NULL : *arg; | |
15440 | ||
bfd28288 | 15441 | if (parser != NULL) |
197f0a60 | 15442 | { |
bfd28288 PA |
15443 | gdb_assert (!parser->finished ()); |
15444 | tpnum = parser->get_number (); | |
197f0a60 TT |
15445 | } |
15446 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15447 | tpnum = tracepoint_count; |
1042e4c0 | 15448 | else |
197f0a60 | 15449 | tpnum = get_number (arg); |
1042e4c0 SS |
15450 | |
15451 | if (tpnum <= 0) | |
15452 | { | |
15453 | if (instring && *instring) | |
15454 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15455 | instring); | |
15456 | else | |
5fa1d40e | 15457 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15458 | return NULL; |
15459 | } | |
15460 | ||
15461 | ALL_TRACEPOINTS (t) | |
15462 | if (t->number == tpnum) | |
15463 | { | |
d9b3f62e | 15464 | return (struct tracepoint *) t; |
1042e4c0 SS |
15465 | } |
15466 | ||
1042e4c0 SS |
15467 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15468 | return NULL; | |
15469 | } | |
15470 | ||
d9b3f62e PA |
15471 | void |
15472 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15473 | { | |
15474 | if (b->thread != -1) | |
15475 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15476 | ||
15477 | if (b->task != 0) | |
15478 | fprintf_unfiltered (fp, " task %d", b->task); | |
15479 | ||
15480 | fprintf_unfiltered (fp, "\n"); | |
15481 | } | |
15482 | ||
6149aea9 PA |
15483 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15484 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15485 | on each breakpoint and only include the ones for which it returns | |
15486 | non-zero. */ | |
15487 | ||
1042e4c0 | 15488 | static void |
6149aea9 PA |
15489 | save_breakpoints (char *filename, int from_tty, |
15490 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15491 | { |
15492 | struct breakpoint *tp; | |
6149aea9 | 15493 | int any = 0; |
1042e4c0 | 15494 | struct cleanup *cleanup; |
6149aea9 | 15495 | int extra_trace_bits = 0; |
1042e4c0 | 15496 | |
6149aea9 PA |
15497 | if (filename == 0 || *filename == 0) |
15498 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15499 | |
15500 | /* See if we have anything to save. */ | |
6149aea9 | 15501 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15502 | { |
6149aea9 | 15503 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15504 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15505 | continue; |
15506 | ||
15507 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15508 | if (filter && !filter (tp)) | |
15509 | continue; | |
15510 | ||
15511 | any = 1; | |
15512 | ||
15513 | if (is_tracepoint (tp)) | |
15514 | { | |
15515 | extra_trace_bits = 1; | |
15516 | ||
15517 | /* We can stop searching. */ | |
15518 | break; | |
15519 | } | |
1042e4c0 | 15520 | } |
6149aea9 PA |
15521 | |
15522 | if (!any) | |
1042e4c0 | 15523 | { |
6149aea9 | 15524 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15525 | return; |
15526 | } | |
15527 | ||
c718be47 PA |
15528 | filename = tilde_expand (filename); |
15529 | cleanup = make_cleanup (xfree, filename); | |
d7e74731 PA |
15530 | |
15531 | stdio_file fp; | |
15532 | ||
15533 | if (!fp.open (filename, "w")) | |
6149aea9 PA |
15534 | error (_("Unable to open file '%s' for saving (%s)"), |
15535 | filename, safe_strerror (errno)); | |
8bf6485c | 15536 | |
6149aea9 | 15537 | if (extra_trace_bits) |
d7e74731 | 15538 | save_trace_state_variables (&fp); |
8bf6485c | 15539 | |
6149aea9 | 15540 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15541 | { |
6149aea9 | 15542 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15543 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15544 | continue; |
8bf6485c | 15545 | |
6149aea9 PA |
15546 | /* If we have a filter, only save the breakpoints it accepts. */ |
15547 | if (filter && !filter (tp)) | |
15548 | continue; | |
15549 | ||
d7e74731 | 15550 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15551 | |
6149aea9 PA |
15552 | /* Note, we can't rely on tp->number for anything, as we can't |
15553 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15554 | instead. */ | |
15555 | ||
15556 | if (tp->cond_string) | |
d7e74731 | 15557 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15558 | |
15559 | if (tp->ignore_count) | |
d7e74731 | 15560 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15561 | |
2d9442cc | 15562 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15563 | { |
d7e74731 | 15564 | fp.puts (" commands\n"); |
a7bdde9e | 15565 | |
d7e74731 | 15566 | current_uiout->redirect (&fp); |
492d29ea | 15567 | TRY |
1042e4c0 | 15568 | { |
79a45e25 | 15569 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15570 | } |
492d29ea PA |
15571 | CATCH (ex, RETURN_MASK_ALL) |
15572 | { | |
112e8700 | 15573 | current_uiout->redirect (NULL); |
492d29ea PA |
15574 | throw_exception (ex); |
15575 | } | |
15576 | END_CATCH | |
1042e4c0 | 15577 | |
112e8700 | 15578 | current_uiout->redirect (NULL); |
d7e74731 | 15579 | fp.puts (" end\n"); |
1042e4c0 | 15580 | } |
6149aea9 PA |
15581 | |
15582 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15583 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15584 | |
15585 | /* If this is a multi-location breakpoint, check if the locations | |
15586 | should be individually disabled. Watchpoint locations are | |
15587 | special, and not user visible. */ | |
15588 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15589 | { | |
15590 | struct bp_location *loc; | |
15591 | int n = 1; | |
15592 | ||
15593 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15594 | if (!loc->enabled) | |
d7e74731 | 15595 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15596 | } |
1042e4c0 | 15597 | } |
8bf6485c | 15598 | |
6149aea9 | 15599 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15600 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15601 | |
1042e4c0 | 15602 | if (from_tty) |
6149aea9 | 15603 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15604 | do_cleanups (cleanup); |
6149aea9 PA |
15605 | } |
15606 | ||
15607 | /* The `save breakpoints' command. */ | |
15608 | ||
15609 | static void | |
15610 | save_breakpoints_command (char *args, int from_tty) | |
15611 | { | |
15612 | save_breakpoints (args, from_tty, NULL); | |
15613 | } | |
15614 | ||
15615 | /* The `save tracepoints' command. */ | |
15616 | ||
15617 | static void | |
15618 | save_tracepoints_command (char *args, int from_tty) | |
15619 | { | |
15620 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15621 | } |
15622 | ||
15623 | /* Create a vector of all tracepoints. */ | |
15624 | ||
15625 | VEC(breakpoint_p) * | |
eeae04df | 15626 | all_tracepoints (void) |
1042e4c0 SS |
15627 | { |
15628 | VEC(breakpoint_p) *tp_vec = 0; | |
15629 | struct breakpoint *tp; | |
15630 | ||
15631 | ALL_TRACEPOINTS (tp) | |
15632 | { | |
15633 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15634 | } | |
15635 | ||
15636 | return tp_vec; | |
15637 | } | |
15638 | ||
c906108c | 15639 | \f |
629500fa KS |
15640 | /* This help string is used to consolidate all the help string for specifying |
15641 | locations used by several commands. */ | |
15642 | ||
15643 | #define LOCATION_HELP_STRING \ | |
15644 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15645 | source filename, function name, label name, and line number.\n\ | |
15646 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15647 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15648 | \"factorial.c:fact:the_top\".\n\ | |
15649 | \n\ | |
15650 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15651 | program. Example: To specify the fourth byte past the start function\n\ | |
15652 | \"main\", use \"*main + 4\".\n\ | |
15653 | \n\ | |
15654 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15655 | syntax to specify location parameters.\n\ | |
15656 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15657 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15658 | -function fact -label the_top\".\n" | |
15659 | ||
4a64f543 MS |
15660 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15661 | commands. It is defined as a macro to prevent duplication. | |
15662 | COMMAND should be a string constant containing the name of the | |
15663 | command. */ | |
629500fa | 15664 | |
31e2b00f | 15665 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15666 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15667 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15668 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15669 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15670 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15671 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15672 | below.\n\ | |
15673 | \n\ | |
dc10affe PA |
15674 | With no LOCATION, uses current execution address of the selected\n\ |
15675 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15676 | \n\ |
15677 | THREADNUM is the number from \"info threads\".\n\ | |
15678 | CONDITION is a boolean expression.\n\ | |
629500fa | 15679 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15680 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15681 | conditions are different.\n\ | |
31e2b00f AS |
15682 | \n\ |
15683 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15684 | ||
44feb3ce TT |
15685 | /* List of subcommands for "catch". */ |
15686 | static struct cmd_list_element *catch_cmdlist; | |
15687 | ||
15688 | /* List of subcommands for "tcatch". */ | |
15689 | static struct cmd_list_element *tcatch_cmdlist; | |
15690 | ||
9ac4176b | 15691 | void |
a121b7c1 | 15692 | add_catch_command (const char *name, const char *docstring, |
82ae6c8d | 15693 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15694 | completer_ftype *completer, |
44feb3ce TT |
15695 | void *user_data_catch, |
15696 | void *user_data_tcatch) | |
15697 | { | |
15698 | struct cmd_list_element *command; | |
15699 | ||
15700 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15701 | &catch_cmdlist); | |
15702 | set_cmd_sfunc (command, sfunc); | |
15703 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15704 | set_cmd_completer (command, completer); |
44feb3ce TT |
15705 | |
15706 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15707 | &tcatch_cmdlist); | |
15708 | set_cmd_sfunc (command, sfunc); | |
15709 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15710 | set_cmd_completer (command, completer); |
44feb3ce TT |
15711 | } |
15712 | ||
6149aea9 PA |
15713 | static void |
15714 | save_command (char *arg, int from_tty) | |
15715 | { | |
3e43a32a MS |
15716 | printf_unfiltered (_("\"save\" must be followed by " |
15717 | "the name of a save subcommand.\n")); | |
635c7e8a | 15718 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15719 | } |
15720 | ||
84f4c1fe PM |
15721 | struct breakpoint * |
15722 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15723 | void *data) | |
15724 | { | |
35df4500 | 15725 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15726 | |
35df4500 | 15727 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15728 | { |
15729 | if ((*callback) (b, data)) | |
15730 | return b; | |
15731 | } | |
15732 | ||
15733 | return NULL; | |
15734 | } | |
15735 | ||
0574c78f GB |
15736 | /* Zero if any of the breakpoint's locations could be a location where |
15737 | functions have been inlined, nonzero otherwise. */ | |
15738 | ||
15739 | static int | |
15740 | is_non_inline_function (struct breakpoint *b) | |
15741 | { | |
15742 | /* The shared library event breakpoint is set on the address of a | |
15743 | non-inline function. */ | |
15744 | if (b->type == bp_shlib_event) | |
15745 | return 1; | |
15746 | ||
15747 | return 0; | |
15748 | } | |
15749 | ||
15750 | /* Nonzero if the specified PC cannot be a location where functions | |
15751 | have been inlined. */ | |
15752 | ||
15753 | int | |
09ac7c10 TT |
15754 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15755 | const struct target_waitstatus *ws) | |
0574c78f GB |
15756 | { |
15757 | struct breakpoint *b; | |
15758 | struct bp_location *bl; | |
15759 | ||
15760 | ALL_BREAKPOINTS (b) | |
15761 | { | |
15762 | if (!is_non_inline_function (b)) | |
15763 | continue; | |
15764 | ||
15765 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15766 | { | |
15767 | if (!bl->shlib_disabled | |
09ac7c10 | 15768 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15769 | return 1; |
15770 | } | |
15771 | } | |
15772 | ||
15773 | return 0; | |
15774 | } | |
15775 | ||
2f202fde JK |
15776 | /* Remove any references to OBJFILE which is going to be freed. */ |
15777 | ||
15778 | void | |
15779 | breakpoint_free_objfile (struct objfile *objfile) | |
15780 | { | |
15781 | struct bp_location **locp, *loc; | |
15782 | ||
15783 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15784 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15785 | loc->symtab = NULL; |
15786 | } | |
15787 | ||
2060206e PA |
15788 | void |
15789 | initialize_breakpoint_ops (void) | |
15790 | { | |
15791 | static int initialized = 0; | |
15792 | ||
15793 | struct breakpoint_ops *ops; | |
15794 | ||
15795 | if (initialized) | |
15796 | return; | |
15797 | initialized = 1; | |
15798 | ||
15799 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15800 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15801 | internal and momentary breakpoints, etc.). */ | |
15802 | ops = &bkpt_base_breakpoint_ops; | |
15803 | *ops = base_breakpoint_ops; | |
15804 | ops->re_set = bkpt_re_set; | |
15805 | ops->insert_location = bkpt_insert_location; | |
15806 | ops->remove_location = bkpt_remove_location; | |
15807 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15808 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15809 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15810 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15811 | |
15812 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15813 | ops = &bkpt_breakpoint_ops; | |
15814 | *ops = bkpt_base_breakpoint_ops; | |
15815 | ops->re_set = bkpt_re_set; | |
15816 | ops->resources_needed = bkpt_resources_needed; | |
15817 | ops->print_it = bkpt_print_it; | |
15818 | ops->print_mention = bkpt_print_mention; | |
15819 | ops->print_recreate = bkpt_print_recreate; | |
15820 | ||
15821 | /* Ranged breakpoints. */ | |
15822 | ops = &ranged_breakpoint_ops; | |
15823 | *ops = bkpt_breakpoint_ops; | |
15824 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15825 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15826 | ops->print_it = print_it_ranged_breakpoint; | |
15827 | ops->print_one = print_one_ranged_breakpoint; | |
15828 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15829 | ops->print_mention = print_mention_ranged_breakpoint; | |
15830 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15831 | ||
15832 | /* Internal breakpoints. */ | |
15833 | ops = &internal_breakpoint_ops; | |
15834 | *ops = bkpt_base_breakpoint_ops; | |
15835 | ops->re_set = internal_bkpt_re_set; | |
15836 | ops->check_status = internal_bkpt_check_status; | |
15837 | ops->print_it = internal_bkpt_print_it; | |
15838 | ops->print_mention = internal_bkpt_print_mention; | |
15839 | ||
15840 | /* Momentary breakpoints. */ | |
15841 | ops = &momentary_breakpoint_ops; | |
15842 | *ops = bkpt_base_breakpoint_ops; | |
15843 | ops->re_set = momentary_bkpt_re_set; | |
15844 | ops->check_status = momentary_bkpt_check_status; | |
15845 | ops->print_it = momentary_bkpt_print_it; | |
15846 | ops->print_mention = momentary_bkpt_print_mention; | |
15847 | ||
55aa24fb SDJ |
15848 | /* Probe breakpoints. */ |
15849 | ops = &bkpt_probe_breakpoint_ops; | |
15850 | *ops = bkpt_breakpoint_ops; | |
15851 | ops->insert_location = bkpt_probe_insert_location; | |
15852 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15853 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15854 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15855 | |
2060206e PA |
15856 | /* Watchpoints. */ |
15857 | ops = &watchpoint_breakpoint_ops; | |
15858 | *ops = base_breakpoint_ops; | |
15859 | ops->re_set = re_set_watchpoint; | |
15860 | ops->insert_location = insert_watchpoint; | |
15861 | ops->remove_location = remove_watchpoint; | |
15862 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15863 | ops->check_status = check_status_watchpoint; | |
15864 | ops->resources_needed = resources_needed_watchpoint; | |
15865 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15866 | ops->print_it = print_it_watchpoint; | |
15867 | ops->print_mention = print_mention_watchpoint; | |
15868 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15869 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15870 | |
15871 | /* Masked watchpoints. */ | |
15872 | ops = &masked_watchpoint_breakpoint_ops; | |
15873 | *ops = watchpoint_breakpoint_ops; | |
15874 | ops->insert_location = insert_masked_watchpoint; | |
15875 | ops->remove_location = remove_masked_watchpoint; | |
15876 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15877 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15878 | ops->print_it = print_it_masked_watchpoint; | |
15879 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15880 | ops->print_mention = print_mention_masked_watchpoint; | |
15881 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15882 | ||
15883 | /* Tracepoints. */ | |
15884 | ops = &tracepoint_breakpoint_ops; | |
15885 | *ops = base_breakpoint_ops; | |
15886 | ops->re_set = tracepoint_re_set; | |
15887 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15888 | ops->print_one_detail = tracepoint_print_one_detail; | |
15889 | ops->print_mention = tracepoint_print_mention; | |
15890 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15891 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15892 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15893 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15894 | |
55aa24fb SDJ |
15895 | /* Probe tracepoints. */ |
15896 | ops = &tracepoint_probe_breakpoint_ops; | |
15897 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15898 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15899 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15900 | |
983af33b SDJ |
15901 | /* Static tracepoints with marker (`-m'). */ |
15902 | ops = &strace_marker_breakpoint_ops; | |
15903 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15904 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15905 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15906 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15907 | |
15908 | /* Fork catchpoints. */ | |
15909 | ops = &catch_fork_breakpoint_ops; | |
15910 | *ops = base_breakpoint_ops; | |
15911 | ops->insert_location = insert_catch_fork; | |
15912 | ops->remove_location = remove_catch_fork; | |
15913 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15914 | ops->print_it = print_it_catch_fork; | |
15915 | ops->print_one = print_one_catch_fork; | |
15916 | ops->print_mention = print_mention_catch_fork; | |
15917 | ops->print_recreate = print_recreate_catch_fork; | |
15918 | ||
15919 | /* Vfork catchpoints. */ | |
15920 | ops = &catch_vfork_breakpoint_ops; | |
15921 | *ops = base_breakpoint_ops; | |
15922 | ops->insert_location = insert_catch_vfork; | |
15923 | ops->remove_location = remove_catch_vfork; | |
15924 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15925 | ops->print_it = print_it_catch_vfork; | |
15926 | ops->print_one = print_one_catch_vfork; | |
15927 | ops->print_mention = print_mention_catch_vfork; | |
15928 | ops->print_recreate = print_recreate_catch_vfork; | |
15929 | ||
15930 | /* Exec catchpoints. */ | |
15931 | ops = &catch_exec_breakpoint_ops; | |
15932 | *ops = base_breakpoint_ops; | |
2060206e PA |
15933 | ops->insert_location = insert_catch_exec; |
15934 | ops->remove_location = remove_catch_exec; | |
15935 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15936 | ops->print_it = print_it_catch_exec; | |
15937 | ops->print_one = print_one_catch_exec; | |
15938 | ops->print_mention = print_mention_catch_exec; | |
15939 | ops->print_recreate = print_recreate_catch_exec; | |
15940 | ||
edcc5120 TT |
15941 | /* Solib-related catchpoints. */ |
15942 | ops = &catch_solib_breakpoint_ops; | |
15943 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15944 | ops->insert_location = insert_catch_solib; |
15945 | ops->remove_location = remove_catch_solib; | |
15946 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15947 | ops->check_status = check_status_catch_solib; | |
15948 | ops->print_it = print_it_catch_solib; | |
15949 | ops->print_one = print_one_catch_solib; | |
15950 | ops->print_mention = print_mention_catch_solib; | |
15951 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15952 | |
15953 | ops = &dprintf_breakpoint_ops; | |
15954 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15955 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15956 | ops->resources_needed = bkpt_resources_needed; |
15957 | ops->print_it = bkpt_print_it; | |
15958 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15959 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15960 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15961 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15962 | } |
15963 | ||
8bfd80db YQ |
15964 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15965 | ||
15966 | static struct cmd_list_element *enablebreaklist = NULL; | |
15967 | ||
c906108c | 15968 | void |
fba45db2 | 15969 | _initialize_breakpoint (void) |
c906108c SS |
15970 | { |
15971 | struct cmd_list_element *c; | |
15972 | ||
2060206e PA |
15973 | initialize_breakpoint_ops (); |
15974 | ||
84acb35a | 15975 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15976 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15977 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15978 | |
55aa24fb SDJ |
15979 | breakpoint_objfile_key |
15980 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 15981 | |
c906108c SS |
15982 | breakpoint_chain = 0; |
15983 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15984 | before a breakpoint is set. */ | |
15985 | breakpoint_count = 0; | |
15986 | ||
1042e4c0 SS |
15987 | tracepoint_count = 0; |
15988 | ||
1bedd215 AC |
15989 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15990 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15991 | Usage is `ignore N COUNT'.")); | |
c906108c | 15992 | |
1bedd215 | 15993 | add_com ("commands", class_breakpoint, commands_command, _("\ |
18da0c51 MG |
15994 | Set commands to be executed when the given breakpoints are hit.\n\ |
15995 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15996 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15997 | (e.g. `5-7').\n\ | |
c906108c SS |
15998 | With no argument, the targeted breakpoint is the last one set.\n\ |
15999 | The commands themselves follow starting on the next line.\n\ | |
16000 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16001 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16002 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16003 | |
d55637df | 16004 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16005 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16006 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16007 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16008 | set_cmd_completer (c, condition_completer); |
c906108c | 16009 | |
1bedd215 | 16010 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16011 | Set a temporary breakpoint.\n\ |
c906108c SS |
16012 | Like \"break\" except the breakpoint is only temporary,\n\ |
16013 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16014 | by using \"enable delete\" on the breakpoint number.\n\ |
16015 | \n" | |
16016 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16017 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16018 | |
1bedd215 | 16019 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16020 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16021 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16022 | some target hardware may not have this support.\n\ |
16023 | \n" | |
16024 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16025 | set_cmd_completer (c, location_completer); |
c906108c | 16026 | |
1bedd215 | 16027 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16028 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16029 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16030 | so it will be deleted when hit.\n\ |
16031 | \n" | |
16032 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16033 | set_cmd_completer (c, location_completer); |
c906108c | 16034 | |
1bedd215 AC |
16035 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16036 | Enable some breakpoints.\n\ | |
c906108c SS |
16037 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16038 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16039 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16040 | With a subcommand you can enable temporarily."), |
c906108c | 16041 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16042 | |
16043 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16044 | ||
84951ab5 | 16045 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16046 | Enable some breakpoints.\n\ |
c906108c SS |
16047 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16048 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16049 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16050 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16051 | |
1a966eab AC |
16052 | add_cmd ("once", no_class, enable_once_command, _("\ |
16053 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16054 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16055 | &enablebreaklist); |
16056 | ||
1a966eab AC |
16057 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16058 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16059 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16060 | &enablebreaklist); |
16061 | ||
816338b5 SS |
16062 | add_cmd ("count", no_class, enable_count_command, _("\ |
16063 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16064 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16065 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16066 | &enablebreaklist); | |
16067 | ||
1a966eab AC |
16068 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16069 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16070 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16071 | &enablelist); |
16072 | ||
1a966eab AC |
16073 | add_cmd ("once", no_class, enable_once_command, _("\ |
16074 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16075 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16076 | &enablelist); |
16077 | ||
16078 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16079 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16080 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16081 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16082 | &enablelist); |
16083 | ||
1bedd215 AC |
16084 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16085 | Disable some breakpoints.\n\ | |
c906108c SS |
16086 | Arguments are breakpoint numbers with spaces in between.\n\ |
16087 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16088 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16089 | &disablelist, "disable ", 1, &cmdlist); |
16090 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16091 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16092 | |
1a966eab AC |
16093 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16094 | Disable some breakpoints.\n\ | |
c906108c SS |
16095 | Arguments are breakpoint numbers with spaces in between.\n\ |
16096 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16097 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16098 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16099 | &disablelist); |
16100 | ||
1bedd215 AC |
16101 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16102 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16103 | Arguments are breakpoint numbers with spaces in between.\n\ |
16104 | To delete all breakpoints, give no argument.\n\ | |
16105 | \n\ | |
16106 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16107 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16108 | &deletelist, "delete ", 1, &cmdlist); |
16109 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16110 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16111 | |
1a966eab AC |
16112 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16113 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16114 | Arguments are breakpoint numbers with spaces in between.\n\ |
16115 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16116 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16117 | &deletelist); |
16118 | ||
1bedd215 | 16119 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16120 | Clear breakpoint at specified location.\n\ |
16121 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16122 | \n\ |
16123 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16124 | is executing in.\n" |
16125 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16126 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16127 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16128 | |
1bedd215 | 16129 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16130 | Set breakpoint at specified location.\n" |
31e2b00f | 16131 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16132 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16133 | |
c906108c SS |
16134 | add_com_alias ("b", "break", class_run, 1); |
16135 | add_com_alias ("br", "break", class_run, 1); | |
16136 | add_com_alias ("bre", "break", class_run, 1); | |
16137 | add_com_alias ("brea", "break", class_run, 1); | |
16138 | ||
c906108c SS |
16139 | if (dbx_commands) |
16140 | { | |
1bedd215 AC |
16141 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16142 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16143 | &stoplist, "stop ", 1, &cmdlist); |
16144 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16145 | _("Break in function or address."), &stoplist); |
c5aa993b | 16146 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16147 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16148 | add_com ("status", class_info, breakpoints_info, _("\ |
16149 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16150 | The \"Type\" column indicates one of:\n\ |
16151 | \tbreakpoint - normal breakpoint\n\ | |
16152 | \twatchpoint - watchpoint\n\ | |
16153 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16154 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16155 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16156 | address and file/line number respectively.\n\ |
16157 | \n\ | |
16158 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16159 | are set to the address of the last breakpoint listed unless the command\n\ |
16160 | is prefixed with \"server \".\n\n\ | |
c906108c | 16161 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16162 | breakpoint set.")); |
c906108c SS |
16163 | } |
16164 | ||
1bedd215 | 16165 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16166 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16167 | The \"Type\" column indicates one of:\n\ |
16168 | \tbreakpoint - normal breakpoint\n\ | |
16169 | \twatchpoint - watchpoint\n\ | |
16170 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16171 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16172 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16173 | address and file/line number respectively.\n\ |
16174 | \n\ | |
16175 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16176 | are set to the address of the last breakpoint listed unless the command\n\ |
16177 | is prefixed with \"server \".\n\n\ | |
c906108c | 16178 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16179 | breakpoint set.")); |
c906108c | 16180 | |
6b04bdb7 MS |
16181 | add_info_alias ("b", "breakpoints", 1); |
16182 | ||
1a966eab AC |
16183 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16184 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16185 | The \"Type\" column indicates one of:\n\ |
16186 | \tbreakpoint - normal breakpoint\n\ | |
16187 | \twatchpoint - watchpoint\n\ | |
16188 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16189 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16190 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16191 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16192 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16193 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16194 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16195 | address and file/line number respectively.\n\ |
16196 | \n\ | |
16197 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16198 | are set to the address of the last breakpoint listed unless the command\n\ |
16199 | is prefixed with \"server \".\n\n\ | |
c906108c | 16200 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16201 | breakpoint set."), |
c906108c SS |
16202 | &maintenanceinfolist); |
16203 | ||
44feb3ce TT |
16204 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16205 | Set catchpoints to catch events."), | |
16206 | &catch_cmdlist, "catch ", | |
16207 | 0/*allow-unknown*/, &cmdlist); | |
16208 | ||
16209 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16210 | Set temporary catchpoints to catch events."), | |
16211 | &tcatch_cmdlist, "tcatch ", | |
16212 | 0/*allow-unknown*/, &cmdlist); | |
16213 | ||
44feb3ce TT |
16214 | add_catch_command ("fork", _("Catch calls to fork."), |
16215 | catch_fork_command_1, | |
a96d9b2e | 16216 | NULL, |
44feb3ce TT |
16217 | (void *) (uintptr_t) catch_fork_permanent, |
16218 | (void *) (uintptr_t) catch_fork_temporary); | |
16219 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16220 | catch_fork_command_1, | |
a96d9b2e | 16221 | NULL, |
44feb3ce TT |
16222 | (void *) (uintptr_t) catch_vfork_permanent, |
16223 | (void *) (uintptr_t) catch_vfork_temporary); | |
16224 | add_catch_command ("exec", _("Catch calls to exec."), | |
16225 | catch_exec_command_1, | |
a96d9b2e SDJ |
16226 | NULL, |
16227 | CATCH_PERMANENT, | |
16228 | CATCH_TEMPORARY); | |
edcc5120 TT |
16229 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16230 | Usage: catch load [REGEX]\n\ | |
16231 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16232 | catch_load_command_1, | |
16233 | NULL, | |
16234 | CATCH_PERMANENT, | |
16235 | CATCH_TEMPORARY); | |
16236 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16237 | Usage: catch unload [REGEX]\n\ | |
16238 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16239 | catch_unload_command_1, | |
16240 | NULL, | |
16241 | CATCH_PERMANENT, | |
16242 | CATCH_TEMPORARY); | |
c5aa993b | 16243 | |
1bedd215 AC |
16244 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16245 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16246 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16247 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16248 | an expression changes.\n\ |
16249 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16250 | the memory to which it refers.")); | |
65d12d83 | 16251 | set_cmd_completer (c, expression_completer); |
c906108c | 16252 | |
1bedd215 AC |
16253 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16254 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16255 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16256 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16257 | an expression is read.\n\ |
16258 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16259 | the memory to which it refers.")); | |
65d12d83 | 16260 | set_cmd_completer (c, expression_completer); |
c906108c | 16261 | |
1bedd215 AC |
16262 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16263 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16264 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16265 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16266 | an expression is either read or written.\n\ |
16267 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16268 | the memory to which it refers.")); | |
65d12d83 | 16269 | set_cmd_completer (c, expression_completer); |
c906108c | 16270 | |
d77f58be | 16271 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16272 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16273 | |
920d2a44 AC |
16274 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16275 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16276 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16277 | &can_use_hw_watchpoints, _("\ | |
16278 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16279 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16280 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16281 | such is available. (However, any hardware watchpoints that were\n\ | |
16282 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16283 | hardware.)"), |
16284 | NULL, | |
920d2a44 | 16285 | show_can_use_hw_watchpoints, |
85c07804 | 16286 | &setlist, &showlist); |
c906108c SS |
16287 | |
16288 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16289 | |
1042e4c0 SS |
16290 | /* Tracepoint manipulation commands. */ |
16291 | ||
16292 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16293 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16294 | \n" |
16295 | BREAK_ARGS_HELP ("trace") "\n\ | |
16296 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16297 | set_cmd_completer (c, location_completer); | |
16298 | ||
16299 | add_com_alias ("tp", "trace", class_alias, 0); | |
16300 | add_com_alias ("tr", "trace", class_alias, 1); | |
16301 | add_com_alias ("tra", "trace", class_alias, 1); | |
16302 | add_com_alias ("trac", "trace", class_alias, 1); | |
16303 | ||
7a697b8d | 16304 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16305 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16306 | \n" |
16307 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16308 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16309 | set_cmd_completer (c, location_completer); | |
16310 | ||
0fb4aa4b | 16311 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16312 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16313 | \n\ |
16314 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16315 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16316 | or -m MARKER_ID.\n\n\ | |
16317 | If a marker id is specified, probe the marker with that name. With\n\ | |
16318 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16319 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16320 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16321 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16322 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16323 | \n\ | |
16324 | CONDITION is a boolean expression.\n\ | |
629500fa | 16325 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16326 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16327 | conditions are different.\n\ | |
0fb4aa4b PA |
16328 | \n\ |
16329 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16330 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16331 | set_cmd_completer (c, location_completer); | |
16332 | ||
1042e4c0 | 16333 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16334 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16335 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16336 | last tracepoint set.")); | |
16337 | ||
16338 | add_info_alias ("tp", "tracepoints", 1); | |
16339 | ||
16340 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16341 | Delete specified tracepoints.\n\ | |
16342 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16343 | No argument means delete all tracepoints."), | |
16344 | &deletelist); | |
7e20dfcd | 16345 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16346 | |
16347 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16348 | Disable specified tracepoints.\n\ | |
16349 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16350 | No argument means disable all tracepoints."), | |
16351 | &disablelist); | |
16352 | deprecate_cmd (c, "disable"); | |
16353 | ||
16354 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16355 | Enable specified tracepoints.\n\ | |
16356 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16357 | No argument means enable all tracepoints."), | |
16358 | &enablelist); | |
16359 | deprecate_cmd (c, "enable"); | |
16360 | ||
16361 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16362 | Set the passcount for a tracepoint.\n\ | |
16363 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16364 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16365 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16366 | ||
6149aea9 PA |
16367 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16368 | _("Save breakpoint definitions as a script."), | |
16369 | &save_cmdlist, "save ", | |
16370 | 0/*allow-unknown*/, &cmdlist); | |
16371 | ||
16372 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16373 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16374 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16375 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16376 | session to restore them."), | |
16377 | &save_cmdlist); | |
16378 | set_cmd_completer (c, filename_completer); | |
16379 | ||
16380 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16381 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16382 | Use the 'source' command in another debug session to restore them."), |
16383 | &save_cmdlist); | |
1042e4c0 SS |
16384 | set_cmd_completer (c, filename_completer); |
16385 | ||
6149aea9 PA |
16386 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16387 | deprecate_cmd (c, "save tracepoints"); | |
16388 | ||
1bedd215 | 16389 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16390 | Breakpoint specific settings\n\ |
16391 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16392 | pending breakpoint behavior"), |
fa8d40ab JJ |
16393 | &breakpoint_set_cmdlist, "set breakpoint ", |
16394 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16395 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16396 | Breakpoint specific settings\n\ |
16397 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16398 | pending breakpoint behavior"), |
fa8d40ab JJ |
16399 | &breakpoint_show_cmdlist, "show breakpoint ", |
16400 | 0/*allow-unknown*/, &showlist); | |
16401 | ||
7915a72c AC |
16402 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16403 | &pending_break_support, _("\ | |
16404 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16405 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16406 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16407 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16408 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16409 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16410 | NULL, |
920d2a44 | 16411 | show_pending_break_support, |
6e1d7d6c AC |
16412 | &breakpoint_set_cmdlist, |
16413 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16414 | |
16415 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16416 | |
16417 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16418 | &automatic_hardware_breakpoints, _("\ | |
16419 | Set automatic usage of hardware breakpoints."), _("\ | |
16420 | Show automatic usage of hardware breakpoints."), _("\ | |
16421 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16422 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16423 | a warning will be emitted for such breakpoints."), | |
16424 | NULL, | |
16425 | show_automatic_hardware_breakpoints, | |
16426 | &breakpoint_set_cmdlist, | |
16427 | &breakpoint_show_cmdlist); | |
74960c60 | 16428 | |
a25a5a45 PA |
16429 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16430 | &always_inserted_mode, _("\ | |
74960c60 VP |
16431 | Set mode for inserting breakpoints."), _("\ |
16432 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16433 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16434 | they're created, kept inserted even when execution stops, and removed\n\ | |
16435 | only when the user deletes them. When this mode is off (the default),\n\ | |
16436 | breakpoints are inserted only when execution continues, and removed\n\ | |
16437 | when execution stops."), | |
72d0e2c5 YQ |
16438 | NULL, |
16439 | &show_always_inserted_mode, | |
16440 | &breakpoint_set_cmdlist, | |
16441 | &breakpoint_show_cmdlist); | |
f1310107 | 16442 | |
b775012e LM |
16443 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16444 | condition_evaluation_enums, | |
16445 | &condition_evaluation_mode_1, _("\ | |
16446 | Set mode of breakpoint condition evaluation."), _("\ | |
16447 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16448 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16449 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16450 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16451 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16452 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16453 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16454 | be set to \"gdb\""), | |
16455 | &set_condition_evaluation_mode, | |
16456 | &show_condition_evaluation_mode, | |
16457 | &breakpoint_set_cmdlist, | |
16458 | &breakpoint_show_cmdlist); | |
16459 | ||
f1310107 TJB |
16460 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16461 | Set a breakpoint for an address range.\n\ | |
16462 | break-range START-LOCATION, END-LOCATION\n\ | |
16463 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16464 | LINENUM, for that line in the current file,\n\ | |
16465 | FILE:LINENUM, for that line in that file,\n\ | |
16466 | +OFFSET, for that number of lines after the current line\n\ | |
16467 | or the start of the range\n\ | |
16468 | FUNCTION, for the first line in that function,\n\ | |
16469 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16470 | *ADDRESS, for the instruction at that address.\n\ | |
16471 | \n\ | |
16472 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16473 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16474 | range (including START-LOCATION and END-LOCATION).")); | |
16475 | ||
e7e0cddf | 16476 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16477 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16478 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16479 | location may be a linespec, explicit, or address location.\n" |
16480 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16481 | set_cmd_completer (c, location_completer); |
16482 | ||
16483 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16484 | dprintf_style_enums, &dprintf_style, _("\ | |
16485 | Set the style of usage for dynamic printf."), _("\ | |
16486 | Show the style of usage for dynamic printf."), _("\ | |
16487 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16488 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16489 | console, as with the \"printf\" command.\n\ | |
16490 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16491 | program; by default printf(), but you can choose a different function or\n\ | |
16492 | output stream by setting dprintf-function and dprintf-channel."), | |
16493 | update_dprintf_commands, NULL, | |
16494 | &setlist, &showlist); | |
16495 | ||
16496 | dprintf_function = xstrdup ("printf"); | |
16497 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16498 | &dprintf_function, _("\ | |
16499 | Set the function to use for dynamic printf"), _("\ | |
16500 | Show the function to use for dynamic printf"), NULL, | |
16501 | update_dprintf_commands, NULL, | |
16502 | &setlist, &showlist); | |
16503 | ||
16504 | dprintf_channel = xstrdup (""); | |
16505 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16506 | &dprintf_channel, _("\ | |
16507 | Set the channel to use for dynamic printf"), _("\ | |
16508 | Show the channel to use for dynamic printf"), NULL, | |
16509 | update_dprintf_commands, NULL, | |
16510 | &setlist, &showlist); | |
16511 | ||
d3ce09f5 SS |
16512 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16513 | &disconnected_dprintf, _("\ | |
16514 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16515 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16516 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16517 | even if GDB disconnects or detaches from the target."), | |
16518 | NULL, | |
16519 | NULL, | |
16520 | &setlist, &showlist); | |
16521 | ||
16522 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16523 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16524 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16525 | ||
765dc015 | 16526 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16527 | |
16528 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16529 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16530 | } |