Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
61baf725 | 3 | Copyright (C) 1986-2017 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
7 | This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
12 | This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
a6d9a66e | 21 | #include "arch-utils.h" |
c906108c | 22 | #include <ctype.h> |
776592bf | 23 | #include "hashtab.h" |
c906108c SS |
24 | #include "symtab.h" |
25 | #include "frame.h" | |
26 | #include "breakpoint.h" | |
1042e4c0 | 27 | #include "tracepoint.h" |
c906108c SS |
28 | #include "gdbtypes.h" |
29 | #include "expression.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
32 | #include "value.h" | |
33 | #include "command.h" | |
34 | #include "inferior.h" | |
45741a9c | 35 | #include "infrun.h" |
c906108c SS |
36 | #include "gdbthread.h" |
37 | #include "target.h" | |
38 | #include "language.h" | |
50f182aa | 39 | #include "gdb-demangle.h" |
0ba1096a | 40 | #include "filenames.h" |
c906108c SS |
41 | #include "annotate.h" |
42 | #include "symfile.h" | |
43 | #include "objfiles.h" | |
0378c332 | 44 | #include "source.h" |
c5f0f3d0 | 45 | #include "linespec.h" |
c94fdfd0 | 46 | #include "completer.h" |
5b7f31a4 | 47 | #include "gdb.h" |
8b93c638 | 48 | #include "ui-out.h" |
e1507482 | 49 | #include "cli/cli-script.h" |
fe898f56 | 50 | #include "block.h" |
a77053c2 | 51 | #include "solib.h" |
84acb35a JJ |
52 | #include "solist.h" |
53 | #include "observer.h" | |
765dc015 | 54 | #include "memattr.h" |
f7f9143b | 55 | #include "ada-lang.h" |
d1aa2f50 | 56 | #include "top.h" |
79a45b7d | 57 | #include "valprint.h" |
4efc6507 | 58 | #include "jit.h" |
65d79d4b | 59 | #include "parser-defs.h" |
55aa24fb SDJ |
60 | #include "gdb_regex.h" |
61 | #include "probe.h" | |
e9cafbcc | 62 | #include "cli/cli-utils.h" |
be34f849 | 63 | #include "continuations.h" |
1bfeeb0f JL |
64 | #include "stack.h" |
65 | #include "skip.h" | |
b775012e | 66 | #include "ax-gdb.h" |
e2e4d78b | 67 | #include "dummy-frame.h" |
5589af0e | 68 | #include "interps.h" |
d3ce09f5 | 69 | #include "format.h" |
cfc31633 | 70 | #include "thread-fsm.h" |
5d5658a1 | 71 | #include "tid-parse.h" |
d3ce09f5 | 72 | |
1042e4c0 SS |
73 | /* readline include files */ |
74 | #include "readline/readline.h" | |
75 | #include "readline/history.h" | |
76 | ||
77 | /* readline defines this. */ | |
78 | #undef savestring | |
79 | ||
034dad6f | 80 | #include "mi/mi-common.h" |
6dddc817 | 81 | #include "extension.h" |
325fac50 | 82 | #include <algorithm> |
5ed8105e | 83 | #include "progspace-and-thread.h" |
6c5b2ebe | 84 | #include "common/array-view.h" |
76f9c9cf | 85 | #include "common/gdb_optional.h" |
104c1213 | 86 | |
e7e8980f YQ |
87 | /* Enums for exception-handling support. */ |
88 | enum exception_event_kind | |
89 | { | |
90 | EX_EVENT_THROW, | |
591f19e8 | 91 | EX_EVENT_RETHROW, |
e7e8980f YQ |
92 | EX_EVENT_CATCH |
93 | }; | |
94 | ||
4a64f543 | 95 | /* Prototypes for local functions. */ |
c906108c | 96 | |
a14ed312 | 97 | static void enable_delete_command (char *, int); |
c906108c | 98 | |
a14ed312 | 99 | static void enable_once_command (char *, int); |
c906108c | 100 | |
816338b5 SS |
101 | static void enable_count_command (char *, int); |
102 | ||
a14ed312 | 103 | static void disable_command (char *, int); |
c906108c | 104 | |
a14ed312 | 105 | static void enable_command (char *, int); |
c906108c | 106 | |
896b6bda PA |
107 | static void map_breakpoint_numbers (const char *, |
108 | void (*) (struct breakpoint *, | |
109 | void *), | |
95a42b64 | 110 | void *); |
c906108c | 111 | |
a14ed312 | 112 | static void ignore_command (char *, int); |
c906108c | 113 | |
4efb68b1 | 114 | static int breakpoint_re_set_one (void *); |
c906108c | 115 | |
348d480f PA |
116 | static void breakpoint_re_set_default (struct breakpoint *); |
117 | ||
f00aae0f KS |
118 | static void |
119 | create_sals_from_location_default (const struct event_location *location, | |
120 | struct linespec_result *canonical, | |
121 | enum bptype type_wanted); | |
983af33b SDJ |
122 | |
123 | static void create_breakpoints_sal_default (struct gdbarch *, | |
124 | struct linespec_result *, | |
e1e01040 PA |
125 | gdb::unique_xmalloc_ptr<char>, |
126 | gdb::unique_xmalloc_ptr<char>, | |
127 | enum bptype, | |
983af33b SDJ |
128 | enum bpdisp, int, int, |
129 | int, | |
130 | const struct breakpoint_ops *, | |
44f238bb | 131 | int, int, int, unsigned); |
983af33b | 132 | |
6c5b2ebe PA |
133 | static std::vector<symtab_and_line> decode_location_default |
134 | (struct breakpoint *b, const struct event_location *location, | |
135 | struct program_space *search_pspace); | |
983af33b | 136 | |
a14ed312 | 137 | static void clear_command (char *, int); |
c906108c | 138 | |
a14ed312 | 139 | static void catch_command (char *, int); |
c906108c | 140 | |
a9634178 | 141 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 142 | |
98deb0da | 143 | static void break_command_1 (char *, int, int); |
c906108c | 144 | |
a14ed312 | 145 | static void mention (struct breakpoint *); |
c906108c | 146 | |
348d480f PA |
147 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
148 | enum bptype, | |
c0a91b2b | 149 | const struct breakpoint_ops *); |
3742cc8b YQ |
150 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
151 | const struct symtab_and_line *); | |
152 | ||
4a64f543 MS |
153 | /* This function is used in gdbtk sources and thus can not be made |
154 | static. */ | |
63c252f8 | 155 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 156 | struct symtab_and_line, |
c0a91b2b TT |
157 | enum bptype, |
158 | const struct breakpoint_ops *); | |
c906108c | 159 | |
06edf0c0 PA |
160 | static struct breakpoint * |
161 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
162 | enum bptype type, | |
a1aa2221 LM |
163 | const struct breakpoint_ops *ops, |
164 | int loc_enabled); | |
06edf0c0 | 165 | |
76897487 KB |
166 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
167 | ||
a6d9a66e UW |
168 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
169 | CORE_ADDR bpaddr, | |
88f7da05 | 170 | enum bptype bptype); |
76897487 | 171 | |
6c95b8df PA |
172 | static void describe_other_breakpoints (struct gdbarch *, |
173 | struct program_space *, CORE_ADDR, | |
5af949e3 | 174 | struct obj_section *, int); |
c906108c | 175 | |
85d721b8 PA |
176 | static int watchpoint_locations_match (struct bp_location *loc1, |
177 | struct bp_location *loc2); | |
178 | ||
f1310107 TJB |
179 | static int breakpoint_location_address_match (struct bp_location *bl, |
180 | struct address_space *aspace, | |
181 | CORE_ADDR addr); | |
182 | ||
d35ae833 PA |
183 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
184 | struct address_space *, | |
185 | CORE_ADDR, int); | |
186 | ||
11db9430 | 187 | static void info_breakpoints_command (char *, int); |
c906108c | 188 | |
11db9430 | 189 | static void info_watchpoints_command (char *, int); |
d77f58be | 190 | |
e5a67952 MS |
191 | static int breakpoint_1 (char *, int, |
192 | int (*) (const struct breakpoint *)); | |
c906108c | 193 | |
4efb68b1 | 194 | static int breakpoint_cond_eval (void *); |
c906108c | 195 | |
4efb68b1 | 196 | static void cleanup_executing_breakpoints (void *); |
c906108c | 197 | |
a14ed312 | 198 | static void commands_command (char *, int); |
c906108c | 199 | |
a14ed312 | 200 | static void condition_command (char *, int); |
c906108c | 201 | |
834c0d03 | 202 | static int remove_breakpoint (struct bp_location *); |
b2b6a7da | 203 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
c906108c | 204 | |
e514a9d6 | 205 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 206 | |
4efb68b1 | 207 | static int watchpoint_check (void *); |
c906108c | 208 | |
a14ed312 | 209 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 210 | |
a14ed312 | 211 | static int hw_breakpoint_used_count (void); |
c906108c | 212 | |
a1398e0c PA |
213 | static int hw_watchpoint_use_count (struct breakpoint *); |
214 | ||
215 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
216 | enum bptype type, | |
217 | int *other_type_used); | |
c906108c | 218 | |
a14ed312 | 219 | static void hbreak_command (char *, int); |
c906108c | 220 | |
a14ed312 | 221 | static void thbreak_command (char *, int); |
c906108c | 222 | |
816338b5 SS |
223 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
224 | int count); | |
c906108c | 225 | |
a14ed312 | 226 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 227 | |
a14ed312 | 228 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 229 | |
a14ed312 | 230 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 231 | |
a14ed312 | 232 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 233 | |
fe3f5fa8 | 234 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
235 | static void incref_bp_location (struct bp_location *loc); |
236 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 237 | |
39d61571 | 238 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 239 | |
44702360 PA |
240 | /* update_global_location_list's modes of operation wrt to whether to |
241 | insert locations now. */ | |
242 | enum ugll_insert_mode | |
243 | { | |
244 | /* Don't insert any breakpoint locations into the inferior, only | |
245 | remove already-inserted locations that no longer should be | |
246 | inserted. Functions that delete a breakpoint or breakpoints | |
247 | should specify this mode, so that deleting a breakpoint doesn't | |
248 | have the side effect of inserting the locations of other | |
249 | breakpoints that are marked not-inserted, but should_be_inserted | |
250 | returns true on them. | |
251 | ||
252 | This behavior is useful is situations close to tear-down -- e.g., | |
253 | after an exec, while the target still has execution, but | |
254 | breakpoint shadows of the previous executable image should *NOT* | |
255 | be restored to the new image; or before detaching, where the | |
256 | target still has execution and wants to delete breakpoints from | |
257 | GDB's lists, and all breakpoints had already been removed from | |
258 | the inferior. */ | |
259 | UGLL_DONT_INSERT, | |
260 | ||
a25a5a45 PA |
261 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
262 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
263 | UGLL_MAY_INSERT, |
264 | ||
a25a5a45 PA |
265 | /* Insert locations now, irrespective of |
266 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
267 | stopped right now, and the user did "continue". We need to | |
268 | insert breakpoints _before_ resuming the target, but | |
269 | UGLL_MAY_INSERT wouldn't insert them, because | |
270 | breakpoints_should_be_inserted_now returns false at that point, | |
271 | as no thread is running yet. */ | |
04086b45 | 272 | UGLL_INSERT |
44702360 PA |
273 | }; |
274 | ||
275 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 276 | |
44702360 | 277 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 278 | |
d77f58be | 279 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
280 | |
281 | static void insert_breakpoint_locations (void); | |
a5606eee | 282 | |
11db9430 | 283 | static void info_tracepoints_command (char *, int); |
1042e4c0 SS |
284 | |
285 | static void delete_trace_command (char *, int); | |
286 | ||
287 | static void enable_trace_command (char *, int); | |
288 | ||
289 | static void disable_trace_command (char *, int); | |
290 | ||
291 | static void trace_pass_command (char *, int); | |
292 | ||
558a9d82 YQ |
293 | static void set_tracepoint_count (int num); |
294 | ||
9c06b0b4 TJB |
295 | static int is_masked_watchpoint (const struct breakpoint *b); |
296 | ||
b775012e LM |
297 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
298 | ||
983af33b SDJ |
299 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
300 | otherwise. */ | |
301 | ||
302 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 303 | |
2060206e PA |
304 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
305 | that are implemented on top of software or hardware breakpoints | |
306 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
307 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
308 | ||
309 | /* Internal breakpoints class type. */ | |
06edf0c0 | 310 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
311 | |
312 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
313 | static struct breakpoint_ops momentary_breakpoint_ops; |
314 | ||
2060206e PA |
315 | /* The breakpoint_ops structure to be used in regular user created |
316 | breakpoints. */ | |
317 | struct breakpoint_ops bkpt_breakpoint_ops; | |
318 | ||
55aa24fb SDJ |
319 | /* Breakpoints set on probes. */ |
320 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
321 | ||
e7e0cddf | 322 | /* Dynamic printf class type. */ |
c5867ab6 | 323 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 324 | |
d3ce09f5 SS |
325 | /* The style in which to perform a dynamic printf. This is a user |
326 | option because different output options have different tradeoffs; | |
327 | if GDB does the printing, there is better error handling if there | |
328 | is a problem with any of the arguments, but using an inferior | |
329 | function lets you have special-purpose printers and sending of | |
330 | output to the same place as compiled-in print functions. */ | |
331 | ||
332 | static const char dprintf_style_gdb[] = "gdb"; | |
333 | static const char dprintf_style_call[] = "call"; | |
334 | static const char dprintf_style_agent[] = "agent"; | |
335 | static const char *const dprintf_style_enums[] = { | |
336 | dprintf_style_gdb, | |
337 | dprintf_style_call, | |
338 | dprintf_style_agent, | |
339 | NULL | |
340 | }; | |
341 | static const char *dprintf_style = dprintf_style_gdb; | |
342 | ||
343 | /* The function to use for dynamic printf if the preferred style is to | |
344 | call into the inferior. The value is simply a string that is | |
345 | copied into the command, so it can be anything that GDB can | |
346 | evaluate to a callable address, not necessarily a function name. */ | |
347 | ||
bde6261a | 348 | static char *dprintf_function; |
d3ce09f5 SS |
349 | |
350 | /* The channel to use for dynamic printf if the preferred style is to | |
351 | call into the inferior; if a nonempty string, it will be passed to | |
352 | the call as the first argument, with the format string as the | |
353 | second. As with the dprintf function, this can be anything that | |
354 | GDB knows how to evaluate, so in addition to common choices like | |
355 | "stderr", this could be an app-specific expression like | |
356 | "mystreams[curlogger]". */ | |
357 | ||
bde6261a | 358 | static char *dprintf_channel; |
d3ce09f5 SS |
359 | |
360 | /* True if dprintf commands should continue to operate even if GDB | |
361 | has disconnected. */ | |
362 | static int disconnected_dprintf = 1; | |
363 | ||
5cea2a26 PA |
364 | /* A reference-counted struct command_line. This lets multiple |
365 | breakpoints share a single command list. */ | |
366 | struct counted_command_line | |
367 | { | |
368 | /* The reference count. */ | |
369 | int refc; | |
370 | ||
371 | /* The command list. */ | |
372 | struct command_line *commands; | |
373 | }; | |
374 | ||
375 | struct command_line * | |
376 | breakpoint_commands (struct breakpoint *b) | |
377 | { | |
378 | return b->commands ? b->commands->commands : NULL; | |
379 | } | |
3daf8fe5 | 380 | |
f3b1572e PA |
381 | /* Flag indicating that a command has proceeded the inferior past the |
382 | current breakpoint. */ | |
383 | ||
384 | static int breakpoint_proceeded; | |
385 | ||
956a9fb9 | 386 | const char * |
2cec12e5 AR |
387 | bpdisp_text (enum bpdisp disp) |
388 | { | |
4a64f543 MS |
389 | /* NOTE: the following values are a part of MI protocol and |
390 | represent values of 'disp' field returned when inferior stops at | |
391 | a breakpoint. */ | |
bc043ef3 | 392 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 393 | |
2cec12e5 AR |
394 | return bpdisps[(int) disp]; |
395 | } | |
c906108c | 396 | |
4a64f543 | 397 | /* Prototypes for exported functions. */ |
c906108c | 398 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 399 | if such is available. */ |
c906108c SS |
400 | static int can_use_hw_watchpoints; |
401 | ||
920d2a44 AC |
402 | static void |
403 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
404 | struct cmd_list_element *c, | |
405 | const char *value) | |
406 | { | |
3e43a32a MS |
407 | fprintf_filtered (file, |
408 | _("Debugger's willingness to use " | |
409 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
410 | value); |
411 | } | |
412 | ||
fa8d40ab JJ |
413 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
414 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 415 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
416 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
417 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
418 | static void |
419 | show_pending_break_support (struct ui_file *file, int from_tty, | |
420 | struct cmd_list_element *c, | |
421 | const char *value) | |
422 | { | |
3e43a32a MS |
423 | fprintf_filtered (file, |
424 | _("Debugger's behavior regarding " | |
425 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
426 | value); |
427 | } | |
fa8d40ab | 428 | |
765dc015 | 429 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 430 | set with "break" but falling in read-only memory. |
765dc015 VP |
431 | If 0, gdb will warn about such breakpoints, but won't automatically |
432 | use hardware breakpoints. */ | |
433 | static int automatic_hardware_breakpoints; | |
434 | static void | |
435 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
436 | struct cmd_list_element *c, | |
437 | const char *value) | |
438 | { | |
3e43a32a MS |
439 | fprintf_filtered (file, |
440 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
441 | value); |
442 | } | |
443 | ||
a25a5a45 PA |
444 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
445 | stopped, and immediately inserts any new breakpoints as soon as | |
446 | they're created. If off (default), GDB keeps breakpoints off of | |
447 | the target as long as possible. That is, it delays inserting | |
448 | breakpoints until the next resume, and removes them again when the | |
449 | target fully stops. This is a bit safer in case GDB crashes while | |
450 | processing user input. */ | |
451 | static int always_inserted_mode = 0; | |
72d0e2c5 | 452 | |
33e5cbd6 | 453 | static void |
74960c60 | 454 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 455 | struct cmd_list_element *c, const char *value) |
74960c60 | 456 | { |
a25a5a45 PA |
457 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
458 | value); | |
74960c60 VP |
459 | } |
460 | ||
b57bacec PA |
461 | /* See breakpoint.h. */ |
462 | ||
33e5cbd6 | 463 | int |
a25a5a45 | 464 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 465 | { |
a25a5a45 PA |
466 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
467 | { | |
468 | /* If breakpoints are global, they should be inserted even if no | |
469 | thread under gdb's control is running, or even if there are | |
470 | no threads under GDB's control yet. */ | |
471 | return 1; | |
472 | } | |
473 | else if (target_has_execution) | |
474 | { | |
372316f1 PA |
475 | struct thread_info *tp; |
476 | ||
a25a5a45 PA |
477 | if (always_inserted_mode) |
478 | { | |
479 | /* The user wants breakpoints inserted even if all threads | |
480 | are stopped. */ | |
481 | return 1; | |
482 | } | |
483 | ||
b57bacec PA |
484 | if (threads_are_executing ()) |
485 | return 1; | |
372316f1 PA |
486 | |
487 | /* Don't remove breakpoints yet if, even though all threads are | |
488 | stopped, we still have events to process. */ | |
489 | ALL_NON_EXITED_THREADS (tp) | |
490 | if (tp->resumed | |
491 | && tp->suspend.waitstatus_pending_p) | |
492 | return 1; | |
a25a5a45 PA |
493 | } |
494 | return 0; | |
33e5cbd6 | 495 | } |
765dc015 | 496 | |
b775012e LM |
497 | static const char condition_evaluation_both[] = "host or target"; |
498 | ||
499 | /* Modes for breakpoint condition evaluation. */ | |
500 | static const char condition_evaluation_auto[] = "auto"; | |
501 | static const char condition_evaluation_host[] = "host"; | |
502 | static const char condition_evaluation_target[] = "target"; | |
503 | static const char *const condition_evaluation_enums[] = { | |
504 | condition_evaluation_auto, | |
505 | condition_evaluation_host, | |
506 | condition_evaluation_target, | |
507 | NULL | |
508 | }; | |
509 | ||
510 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
511 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
512 | ||
513 | /* Global that we use to display information to the user (gets its value from | |
514 | condition_evaluation_mode_1. */ | |
515 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
516 | ||
517 | /* Translate a condition evaluation mode MODE into either "host" | |
518 | or "target". This is used mostly to translate from "auto" to the | |
519 | real setting that is being used. It returns the translated | |
520 | evaluation mode. */ | |
521 | ||
522 | static const char * | |
523 | translate_condition_evaluation_mode (const char *mode) | |
524 | { | |
525 | if (mode == condition_evaluation_auto) | |
526 | { | |
527 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
528 | return condition_evaluation_target; | |
529 | else | |
530 | return condition_evaluation_host; | |
531 | } | |
532 | else | |
533 | return mode; | |
534 | } | |
535 | ||
536 | /* Discovers what condition_evaluation_auto translates to. */ | |
537 | ||
538 | static const char * | |
539 | breakpoint_condition_evaluation_mode (void) | |
540 | { | |
541 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
542 | } | |
543 | ||
544 | /* Return true if GDB should evaluate breakpoint conditions or false | |
545 | otherwise. */ | |
546 | ||
547 | static int | |
548 | gdb_evaluates_breakpoint_condition_p (void) | |
549 | { | |
550 | const char *mode = breakpoint_condition_evaluation_mode (); | |
551 | ||
552 | return (mode == condition_evaluation_host); | |
553 | } | |
554 | ||
c906108c SS |
555 | /* Are we executing breakpoint commands? */ |
556 | static int executing_breakpoint_commands; | |
557 | ||
c02f5703 MS |
558 | /* Are overlay event breakpoints enabled? */ |
559 | static int overlay_events_enabled; | |
560 | ||
e09342b5 TJB |
561 | /* See description in breakpoint.h. */ |
562 | int target_exact_watchpoints = 0; | |
563 | ||
c906108c | 564 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 565 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 566 | current breakpoint. */ |
c906108c | 567 | |
5c44784c | 568 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 569 | |
5c44784c JM |
570 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
571 | for (B = breakpoint_chain; \ | |
572 | B ? (TMP=B->next, 1): 0; \ | |
573 | B = TMP) | |
c906108c | 574 | |
4a64f543 MS |
575 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
576 | not provided so update_global_location_list must not be called | |
577 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 578 | |
876fa593 | 579 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
f5336ca5 PA |
580 | for (BP_TMP = bp_locations; \ |
581 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ | |
876fa593 | 582 | BP_TMP++) |
7cc221ef | 583 | |
b775012e LM |
584 | /* Iterates through locations with address ADDRESS for the currently selected |
585 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
586 | to where the loop should start from. | |
587 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
588 | appropriate location to start with. */ | |
589 | ||
590 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
591 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
592 | BP_LOCP_TMP = BP_LOCP_START; \ | |
593 | BP_LOCP_START \ | |
f5336ca5 | 594 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
b775012e LM |
595 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
596 | BP_LOCP_TMP++) | |
597 | ||
1042e4c0 SS |
598 | /* Iterator for tracepoints only. */ |
599 | ||
600 | #define ALL_TRACEPOINTS(B) \ | |
601 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 602 | if (is_tracepoint (B)) |
1042e4c0 | 603 | |
7cc221ef | 604 | /* Chains of all breakpoints defined. */ |
c906108c SS |
605 | |
606 | struct breakpoint *breakpoint_chain; | |
607 | ||
f5336ca5 | 608 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
876fa593 | 609 | |
f5336ca5 | 610 | static struct bp_location **bp_locations; |
876fa593 | 611 | |
f5336ca5 | 612 | /* Number of elements of BP_LOCATIONS. */ |
876fa593 | 613 | |
f5336ca5 | 614 | static unsigned bp_locations_count; |
876fa593 | 615 | |
4a64f543 | 616 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
f5336ca5 | 617 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
4a64f543 | 618 | result from bp_location_has_shadow. You can use it for roughly |
f5336ca5 | 619 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
4a64f543 | 620 | an address you need to read. */ |
876fa593 | 621 | |
f5336ca5 | 622 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
876fa593 | 623 | |
4a64f543 MS |
624 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
625 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
f5336ca5 PA |
626 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
627 | You can use it for roughly limiting the subrange of BP_LOCATIONS to | |
4a64f543 | 628 | scan for shadow bytes for an address you need to read. */ |
876fa593 | 629 | |
f5336ca5 | 630 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
7cc221ef | 631 | |
4a64f543 | 632 | /* The locations that no longer correspond to any breakpoint, unlinked |
f5336ca5 PA |
633 | from the bp_locations array, but for which a hit may still be |
634 | reported by a target. */ | |
20874c92 VP |
635 | VEC(bp_location_p) *moribund_locations = NULL; |
636 | ||
c906108c SS |
637 | /* Number of last breakpoint made. */ |
638 | ||
95a42b64 TT |
639 | static int breakpoint_count; |
640 | ||
86b17b60 PA |
641 | /* The value of `breakpoint_count' before the last command that |
642 | created breakpoints. If the last (break-like) command created more | |
643 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
644 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
645 | static int prev_breakpoint_count; | |
c906108c | 646 | |
1042e4c0 SS |
647 | /* Number of last tracepoint made. */ |
648 | ||
95a42b64 | 649 | static int tracepoint_count; |
1042e4c0 | 650 | |
6149aea9 PA |
651 | static struct cmd_list_element *breakpoint_set_cmdlist; |
652 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 653 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 654 | |
badd37ce SDJ |
655 | /* See declaration at breakpoint.h. */ |
656 | ||
657 | struct breakpoint * | |
658 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
659 | void *user_data) | |
660 | { | |
661 | struct breakpoint *b = NULL; | |
662 | ||
663 | ALL_BREAKPOINTS (b) | |
664 | { | |
665 | if (func (b, user_data) != 0) | |
666 | break; | |
667 | } | |
668 | ||
669 | return b; | |
670 | } | |
671 | ||
468d015d JJ |
672 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
673 | static int | |
674 | breakpoint_enabled (struct breakpoint *b) | |
675 | { | |
0d381245 | 676 | return (b->enable_state == bp_enabled); |
468d015d JJ |
677 | } |
678 | ||
c906108c SS |
679 | /* Set breakpoint count to NUM. */ |
680 | ||
95a42b64 | 681 | static void |
fba45db2 | 682 | set_breakpoint_count (int num) |
c906108c | 683 | { |
86b17b60 | 684 | prev_breakpoint_count = breakpoint_count; |
c906108c | 685 | breakpoint_count = num; |
4fa62494 | 686 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
687 | } |
688 | ||
86b17b60 PA |
689 | /* Used by `start_rbreak_breakpoints' below, to record the current |
690 | breakpoint count before "rbreak" creates any breakpoint. */ | |
691 | static int rbreak_start_breakpoint_count; | |
692 | ||
95a42b64 TT |
693 | /* Called at the start an "rbreak" command to record the first |
694 | breakpoint made. */ | |
86b17b60 | 695 | |
95a42b64 TT |
696 | void |
697 | start_rbreak_breakpoints (void) | |
698 | { | |
86b17b60 | 699 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
700 | } |
701 | ||
702 | /* Called at the end of an "rbreak" command to record the last | |
703 | breakpoint made. */ | |
86b17b60 | 704 | |
95a42b64 TT |
705 | void |
706 | end_rbreak_breakpoints (void) | |
707 | { | |
86b17b60 | 708 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
709 | } |
710 | ||
4a64f543 | 711 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
712 | |
713 | void | |
fba45db2 | 714 | clear_breakpoint_hit_counts (void) |
c906108c SS |
715 | { |
716 | struct breakpoint *b; | |
717 | ||
718 | ALL_BREAKPOINTS (b) | |
719 | b->hit_count = 0; | |
720 | } | |
721 | ||
9add0f1b TT |
722 | /* Allocate a new counted_command_line with reference count of 1. |
723 | The new structure owns COMMANDS. */ | |
724 | ||
725 | static struct counted_command_line * | |
726 | alloc_counted_command_line (struct command_line *commands) | |
727 | { | |
8d749320 | 728 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 729 | |
9add0f1b TT |
730 | result->refc = 1; |
731 | result->commands = commands; | |
8d749320 | 732 | |
9add0f1b TT |
733 | return result; |
734 | } | |
735 | ||
736 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
737 | ||
738 | static void | |
739 | incref_counted_command_line (struct counted_command_line *cmd) | |
740 | { | |
741 | if (cmd) | |
742 | ++cmd->refc; | |
743 | } | |
744 | ||
745 | /* Decrement reference count. If the reference count reaches 0, | |
746 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
747 | nothing if *CMDP is NULL. */ | |
748 | ||
749 | static void | |
750 | decref_counted_command_line (struct counted_command_line **cmdp) | |
751 | { | |
752 | if (*cmdp) | |
753 | { | |
754 | if (--(*cmdp)->refc == 0) | |
755 | { | |
756 | free_command_lines (&(*cmdp)->commands); | |
757 | xfree (*cmdp); | |
758 | } | |
759 | *cmdp = NULL; | |
760 | } | |
761 | } | |
762 | ||
763 | /* A cleanup function that calls decref_counted_command_line. */ | |
764 | ||
765 | static void | |
766 | do_cleanup_counted_command_line (void *arg) | |
767 | { | |
9a3c8263 | 768 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
769 | } |
770 | ||
771 | /* Create a cleanup that calls decref_counted_command_line on the | |
772 | argument. */ | |
773 | ||
774 | static struct cleanup * | |
775 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
776 | { | |
777 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
778 | } | |
779 | ||
c906108c | 780 | \f |
48cb2d85 VP |
781 | /* Return the breakpoint with the specified number, or NULL |
782 | if the number does not refer to an existing breakpoint. */ | |
783 | ||
784 | struct breakpoint * | |
785 | get_breakpoint (int num) | |
786 | { | |
787 | struct breakpoint *b; | |
788 | ||
789 | ALL_BREAKPOINTS (b) | |
790 | if (b->number == num) | |
791 | return b; | |
792 | ||
793 | return NULL; | |
794 | } | |
5c44784c | 795 | |
c906108c | 796 | \f |
adc36818 | 797 | |
b775012e LM |
798 | /* Mark locations as "conditions have changed" in case the target supports |
799 | evaluating conditions on its side. */ | |
800 | ||
801 | static void | |
802 | mark_breakpoint_modified (struct breakpoint *b) | |
803 | { | |
804 | struct bp_location *loc; | |
805 | ||
806 | /* This is only meaningful if the target is | |
807 | evaluating conditions and if the user has | |
808 | opted for condition evaluation on the target's | |
809 | side. */ | |
810 | if (gdb_evaluates_breakpoint_condition_p () | |
811 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
812 | return; | |
813 | ||
814 | if (!is_breakpoint (b)) | |
815 | return; | |
816 | ||
817 | for (loc = b->loc; loc; loc = loc->next) | |
818 | loc->condition_changed = condition_modified; | |
819 | } | |
820 | ||
821 | /* Mark location as "conditions have changed" in case the target supports | |
822 | evaluating conditions on its side. */ | |
823 | ||
824 | static void | |
825 | mark_breakpoint_location_modified (struct bp_location *loc) | |
826 | { | |
827 | /* This is only meaningful if the target is | |
828 | evaluating conditions and if the user has | |
829 | opted for condition evaluation on the target's | |
830 | side. */ | |
831 | if (gdb_evaluates_breakpoint_condition_p () | |
832 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
833 | ||
834 | return; | |
835 | ||
836 | if (!is_breakpoint (loc->owner)) | |
837 | return; | |
838 | ||
839 | loc->condition_changed = condition_modified; | |
840 | } | |
841 | ||
842 | /* Sets the condition-evaluation mode using the static global | |
843 | condition_evaluation_mode. */ | |
844 | ||
845 | static void | |
846 | set_condition_evaluation_mode (char *args, int from_tty, | |
847 | struct cmd_list_element *c) | |
848 | { | |
b775012e LM |
849 | const char *old_mode, *new_mode; |
850 | ||
851 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
852 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
853 | { | |
854 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
855 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
856 | "Using host evaluation mode instead.")); | |
857 | return; | |
858 | } | |
859 | ||
860 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
861 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
862 | ||
abf1152a JK |
863 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
864 | settings was "auto". */ | |
865 | condition_evaluation_mode = condition_evaluation_mode_1; | |
866 | ||
b775012e LM |
867 | /* Only update the mode if the user picked a different one. */ |
868 | if (new_mode != old_mode) | |
869 | { | |
870 | struct bp_location *loc, **loc_tmp; | |
871 | /* If the user switched to a different evaluation mode, we | |
872 | need to synch the changes with the target as follows: | |
873 | ||
874 | "host" -> "target": Send all (valid) conditions to the target. | |
875 | "target" -> "host": Remove all the conditions from the target. | |
876 | */ | |
877 | ||
b775012e LM |
878 | if (new_mode == condition_evaluation_target) |
879 | { | |
880 | /* Mark everything modified and synch conditions with the | |
881 | target. */ | |
882 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
883 | mark_breakpoint_location_modified (loc); | |
884 | } | |
885 | else | |
886 | { | |
887 | /* Manually mark non-duplicate locations to synch conditions | |
888 | with the target. We do this to remove all the conditions the | |
889 | target knows about. */ | |
890 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
891 | if (is_breakpoint (loc->owner) && loc->inserted) | |
892 | loc->needs_update = 1; | |
893 | } | |
894 | ||
895 | /* Do the update. */ | |
44702360 | 896 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
897 | } |
898 | ||
899 | return; | |
900 | } | |
901 | ||
902 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
903 | what "auto" is translating to. */ | |
904 | ||
905 | static void | |
906 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
907 | struct cmd_list_element *c, const char *value) | |
908 | { | |
909 | if (condition_evaluation_mode == condition_evaluation_auto) | |
910 | fprintf_filtered (file, | |
911 | _("Breakpoint condition evaluation " | |
912 | "mode is %s (currently %s).\n"), | |
913 | value, | |
914 | breakpoint_condition_evaluation_mode ()); | |
915 | else | |
916 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
917 | value); | |
918 | } | |
919 | ||
920 | /* A comparison function for bp_location AP and BP that is used by | |
921 | bsearch. This comparison function only cares about addresses, unlike | |
f5336ca5 | 922 | the more general bp_locations_compare function. */ |
b775012e LM |
923 | |
924 | static int | |
f5336ca5 | 925 | bp_locations_compare_addrs (const void *ap, const void *bp) |
b775012e | 926 | { |
9a3c8263 SM |
927 | const struct bp_location *a = *(const struct bp_location **) ap; |
928 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
929 | |
930 | if (a->address == b->address) | |
931 | return 0; | |
932 | else | |
933 | return ((a->address > b->address) - (a->address < b->address)); | |
934 | } | |
935 | ||
936 | /* Helper function to skip all bp_locations with addresses | |
937 | less than ADDRESS. It returns the first bp_location that | |
938 | is greater than or equal to ADDRESS. If none is found, just | |
939 | return NULL. */ | |
940 | ||
941 | static struct bp_location ** | |
942 | get_first_locp_gte_addr (CORE_ADDR address) | |
943 | { | |
944 | struct bp_location dummy_loc; | |
945 | struct bp_location *dummy_locp = &dummy_loc; | |
946 | struct bp_location **locp_found = NULL; | |
947 | ||
948 | /* Initialize the dummy location's address field. */ | |
b775012e LM |
949 | dummy_loc.address = address; |
950 | ||
951 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 | 952 | locp_found = ((struct bp_location **) |
f5336ca5 | 953 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
9a3c8263 | 954 | sizeof (struct bp_location **), |
f5336ca5 | 955 | bp_locations_compare_addrs)); |
b775012e LM |
956 | |
957 | /* Nothing was found, nothing left to do. */ | |
958 | if (locp_found == NULL) | |
959 | return NULL; | |
960 | ||
961 | /* We may have found a location that is at ADDRESS but is not the first in the | |
962 | location's list. Go backwards (if possible) and locate the first one. */ | |
f5336ca5 | 963 | while ((locp_found - 1) >= bp_locations |
b775012e LM |
964 | && (*(locp_found - 1))->address == address) |
965 | locp_found--; | |
966 | ||
967 | return locp_found; | |
968 | } | |
969 | ||
adc36818 | 970 | void |
7a26bd4d | 971 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
972 | int from_tty) |
973 | { | |
3a5c3e22 PA |
974 | xfree (b->cond_string); |
975 | b->cond_string = NULL; | |
adc36818 | 976 | |
3a5c3e22 | 977 | if (is_watchpoint (b)) |
adc36818 | 978 | { |
3a5c3e22 PA |
979 | struct watchpoint *w = (struct watchpoint *) b; |
980 | ||
4d01a485 | 981 | w->cond_exp.reset (); |
3a5c3e22 PA |
982 | } |
983 | else | |
984 | { | |
985 | struct bp_location *loc; | |
986 | ||
987 | for (loc = b->loc; loc; loc = loc->next) | |
988 | { | |
4d01a485 | 989 | loc->cond.reset (); |
b775012e LM |
990 | |
991 | /* No need to free the condition agent expression | |
992 | bytecode (if we have one). We will handle this | |
993 | when we go through update_global_location_list. */ | |
3a5c3e22 | 994 | } |
adc36818 | 995 | } |
adc36818 PM |
996 | |
997 | if (*exp == 0) | |
998 | { | |
999 | if (from_tty) | |
1000 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1001 | } | |
1002 | else | |
1003 | { | |
bbc13ae3 | 1004 | const char *arg = exp; |
cc59ec59 | 1005 | |
adc36818 PM |
1006 | /* I don't know if it matters whether this is the string the user |
1007 | typed in or the decompiled expression. */ | |
1008 | b->cond_string = xstrdup (arg); | |
1009 | b->condition_not_parsed = 0; | |
1010 | ||
1011 | if (is_watchpoint (b)) | |
1012 | { | |
3a5c3e22 PA |
1013 | struct watchpoint *w = (struct watchpoint *) b; |
1014 | ||
adc36818 PM |
1015 | innermost_block = NULL; |
1016 | arg = exp; | |
1bb9788d | 1017 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1018 | if (*arg) |
1019 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1020 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1021 | } |
1022 | else | |
1023 | { | |
3a5c3e22 PA |
1024 | struct bp_location *loc; |
1025 | ||
adc36818 PM |
1026 | for (loc = b->loc; loc; loc = loc->next) |
1027 | { | |
1028 | arg = exp; | |
1029 | loc->cond = | |
1bb9788d TT |
1030 | parse_exp_1 (&arg, loc->address, |
1031 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1032 | if (*arg) |
1033 | error (_("Junk at end of expression")); | |
1034 | } | |
1035 | } | |
1036 | } | |
b775012e LM |
1037 | mark_breakpoint_modified (b); |
1038 | ||
8d3788bd | 1039 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1040 | } |
1041 | ||
d55637df TT |
1042 | /* Completion for the "condition" command. */ |
1043 | ||
eb3ff9a5 | 1044 | static void |
6f937416 | 1045 | condition_completer (struct cmd_list_element *cmd, |
eb3ff9a5 | 1046 | completion_tracker &tracker, |
6f937416 | 1047 | const char *text, const char *word) |
d55637df | 1048 | { |
6f937416 | 1049 | const char *space; |
d55637df | 1050 | |
f1735a53 TT |
1051 | text = skip_spaces (text); |
1052 | space = skip_to_space (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. */ | |
eb3ff9a5 PA |
1062 | if (!isdigit (text[1])) |
1063 | complete_internalvar (tracker, &text[1]); | |
1064 | return; | |
d55637df TT |
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) | |
eb3ff9a5 PA |
1077 | { |
1078 | gdb::unique_xmalloc_ptr<char> copy (xstrdup (number)); | |
1079 | tracker.add_completion (std::move (copy)); | |
1080 | } | |
58ce7251 | 1081 | } |
d55637df | 1082 | |
eb3ff9a5 | 1083 | return; |
d55637df TT |
1084 | } |
1085 | ||
1086 | /* We're completing the expression part. */ | |
f1735a53 | 1087 | text = skip_spaces (space); |
eb3ff9a5 | 1088 | expression_completer (cmd, tracker, text, word); |
d55637df TT |
1089 | } |
1090 | ||
c906108c SS |
1091 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1092 | ||
1093 | static void | |
fba45db2 | 1094 | condition_command (char *arg, int from_tty) |
c906108c | 1095 | { |
52f0bd74 | 1096 | struct breakpoint *b; |
c906108c | 1097 | char *p; |
52f0bd74 | 1098 | int bnum; |
c906108c SS |
1099 | |
1100 | if (arg == 0) | |
e2e0b3e5 | 1101 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1102 | |
1103 | p = arg; | |
1104 | bnum = get_number (&p); | |
5c44784c | 1105 | if (bnum == 0) |
8a3fe4f8 | 1106 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1107 | |
1108 | ALL_BREAKPOINTS (b) | |
1109 | if (b->number == bnum) | |
2f069f6f | 1110 | { |
6dddc817 DE |
1111 | /* Check if this breakpoint has a "stop" method implemented in an |
1112 | extension language. This method and conditions entered into GDB | |
1113 | from the CLI are mutually exclusive. */ | |
1114 | const struct extension_language_defn *extlang | |
1115 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1116 | ||
1117 | if (extlang != NULL) | |
1118 | { | |
1119 | error (_("Only one stop condition allowed. There is currently" | |
1120 | " a %s stop condition defined for this breakpoint."), | |
1121 | ext_lang_capitalized_name (extlang)); | |
1122 | } | |
2566ad2d | 1123 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1124 | |
1125 | if (is_breakpoint (b)) | |
44702360 | 1126 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1127 | |
2f069f6f JB |
1128 | return; |
1129 | } | |
c906108c | 1130 | |
8a3fe4f8 | 1131 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1132 | } |
1133 | ||
a7bdde9e VP |
1134 | /* Check that COMMAND do not contain commands that are suitable |
1135 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1136 | Throw if any such commands is found. */ |
1137 | ||
a7bdde9e VP |
1138 | static void |
1139 | check_no_tracepoint_commands (struct command_line *commands) | |
1140 | { | |
1141 | struct command_line *c; | |
cc59ec59 | 1142 | |
a7bdde9e VP |
1143 | for (c = commands; c; c = c->next) |
1144 | { | |
1145 | int i; | |
1146 | ||
1147 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1148 | error (_("The 'while-stepping' command can " |
1149 | "only be used for tracepoints")); | |
a7bdde9e VP |
1150 | |
1151 | for (i = 0; i < c->body_count; ++i) | |
1152 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1153 | ||
1154 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1155 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1156 | command directly. */ |
1157 | if (strstr (c->line, "collect ") == c->line) | |
1158 | error (_("The 'collect' command can only be used for tracepoints")); | |
1159 | ||
51661e93 VP |
1160 | if (strstr (c->line, "teval ") == c->line) |
1161 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1162 | } |
1163 | } | |
1164 | ||
c1fc2657 | 1165 | struct longjmp_breakpoint : public breakpoint |
3b0871f4 | 1166 | { |
c1fc2657 | 1167 | ~longjmp_breakpoint () override; |
3b0871f4 SM |
1168 | }; |
1169 | ||
d77f58be SS |
1170 | /* Encapsulate tests for different types of tracepoints. */ |
1171 | ||
3b0871f4 SM |
1172 | static bool |
1173 | is_tracepoint_type (bptype type) | |
d9b3f62e PA |
1174 | { |
1175 | return (type == bp_tracepoint | |
1176 | || type == bp_fast_tracepoint | |
1177 | || type == bp_static_tracepoint); | |
1178 | } | |
1179 | ||
3b0871f4 SM |
1180 | static bool |
1181 | is_longjmp_type (bptype type) | |
1182 | { | |
1183 | return type == bp_longjmp || type == bp_exception; | |
1184 | } | |
1185 | ||
a7bdde9e | 1186 | int |
d77f58be | 1187 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1188 | { |
d9b3f62e | 1189 | return is_tracepoint_type (b->type); |
a7bdde9e | 1190 | } |
d9b3f62e | 1191 | |
a5e364af SM |
1192 | /* Factory function to create an appropriate instance of breakpoint given |
1193 | TYPE. */ | |
1194 | ||
1195 | static std::unique_ptr<breakpoint> | |
1196 | new_breakpoint_from_type (bptype type) | |
1197 | { | |
1198 | breakpoint *b; | |
1199 | ||
1200 | if (is_tracepoint_type (type)) | |
c1fc2657 | 1201 | b = new tracepoint (); |
3b0871f4 | 1202 | else if (is_longjmp_type (type)) |
c1fc2657 | 1203 | b = new longjmp_breakpoint (); |
a5e364af SM |
1204 | else |
1205 | b = new breakpoint (); | |
1206 | ||
1207 | return std::unique_ptr<breakpoint> (b); | |
1208 | } | |
1209 | ||
e5dd4106 | 1210 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1211 | breakpoint. This function will throw an exception if a problem is |
1212 | found. */ | |
48cb2d85 | 1213 | |
95a42b64 TT |
1214 | static void |
1215 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1216 | struct command_line *commands) | |
48cb2d85 | 1217 | { |
d77f58be | 1218 | if (is_tracepoint (b)) |
a7bdde9e | 1219 | { |
c9a6ce02 | 1220 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1221 | struct command_line *c; |
1222 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1223 | |
1224 | /* Reset the while-stepping step count. The previous commands | |
1225 | might have included a while-stepping action, while the new | |
1226 | ones might not. */ | |
1227 | t->step_count = 0; | |
1228 | ||
1229 | /* We need to verify that each top-level element of commands is | |
1230 | valid for tracepoints, that there's at most one | |
1231 | while-stepping element, and that the while-stepping's body | |
1232 | has valid tracing commands excluding nested while-stepping. | |
1233 | We also need to validate the tracepoint action line in the | |
1234 | context of the tracepoint --- validate_actionline actually | |
1235 | has side effects, like setting the tracepoint's | |
1236 | while-stepping STEP_COUNT, in addition to checking if the | |
1237 | collect/teval actions parse and make sense in the | |
1238 | tracepoint's context. */ | |
a7bdde9e VP |
1239 | for (c = commands; c; c = c->next) |
1240 | { | |
a7bdde9e VP |
1241 | if (c->control_type == while_stepping_control) |
1242 | { | |
1243 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1244 | error (_("The 'while-stepping' command " |
1245 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1246 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1247 | error (_("The 'while-stepping' command " |
1248 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1249 | |
1250 | if (while_stepping) | |
3e43a32a MS |
1251 | error (_("The 'while-stepping' command " |
1252 | "can be used only once")); | |
a7bdde9e VP |
1253 | else |
1254 | while_stepping = c; | |
1255 | } | |
c9a6ce02 PA |
1256 | |
1257 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1258 | } |
1259 | if (while_stepping) | |
1260 | { | |
1261 | struct command_line *c2; | |
1262 | ||
1263 | gdb_assert (while_stepping->body_count == 1); | |
1264 | c2 = while_stepping->body_list[0]; | |
1265 | for (; c2; c2 = c2->next) | |
1266 | { | |
a7bdde9e VP |
1267 | if (c2->control_type == while_stepping_control) |
1268 | error (_("The 'while-stepping' command cannot be nested")); | |
1269 | } | |
1270 | } | |
1271 | } | |
1272 | else | |
1273 | { | |
1274 | check_no_tracepoint_commands (commands); | |
1275 | } | |
95a42b64 TT |
1276 | } |
1277 | ||
0fb4aa4b PA |
1278 | /* Return a vector of all the static tracepoints set at ADDR. The |
1279 | caller is responsible for releasing the vector. */ | |
1280 | ||
1281 | VEC(breakpoint_p) * | |
1282 | static_tracepoints_here (CORE_ADDR addr) | |
1283 | { | |
1284 | struct breakpoint *b; | |
1285 | VEC(breakpoint_p) *found = 0; | |
1286 | struct bp_location *loc; | |
1287 | ||
1288 | ALL_BREAKPOINTS (b) | |
1289 | if (b->type == bp_static_tracepoint) | |
1290 | { | |
1291 | for (loc = b->loc; loc; loc = loc->next) | |
1292 | if (loc->address == addr) | |
1293 | VEC_safe_push(breakpoint_p, found, b); | |
1294 | } | |
1295 | ||
1296 | return found; | |
1297 | } | |
1298 | ||
95a42b64 | 1299 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1300 | validate that only allowed commands are included. */ |
95a42b64 TT |
1301 | |
1302 | void | |
4a64f543 | 1303 | breakpoint_set_commands (struct breakpoint *b, |
93921405 | 1304 | command_line_up &&commands) |
95a42b64 | 1305 | { |
93921405 | 1306 | validate_commands_for_breakpoint (b, commands.get ()); |
a7bdde9e | 1307 | |
9add0f1b | 1308 | decref_counted_command_line (&b->commands); |
93921405 | 1309 | b->commands = alloc_counted_command_line (commands.release ()); |
8d3788bd | 1310 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1311 | } |
1312 | ||
45a43567 TT |
1313 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1314 | is not the same as the "silent" that may appear in the breakpoint's | |
1315 | commands. */ | |
1316 | ||
1317 | void | |
1318 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1319 | { | |
1320 | int old_silent = b->silent; | |
1321 | ||
1322 | b->silent = silent; | |
1323 | if (old_silent != silent) | |
8d3788bd | 1324 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1325 | } |
1326 | ||
1327 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1328 | breakpoint work for any thread. */ | |
1329 | ||
1330 | void | |
1331 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1332 | { | |
1333 | int old_thread = b->thread; | |
1334 | ||
1335 | b->thread = thread; | |
1336 | if (old_thread != thread) | |
8d3788bd | 1337 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1338 | } |
1339 | ||
1340 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1341 | breakpoint work for any task. */ | |
1342 | ||
1343 | void | |
1344 | breakpoint_set_task (struct breakpoint *b, int task) | |
1345 | { | |
1346 | int old_task = b->task; | |
1347 | ||
1348 | b->task = task; | |
1349 | if (old_task != task) | |
8d3788bd | 1350 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1351 | } |
1352 | ||
95a42b64 TT |
1353 | void |
1354 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1355 | { |
9a3c8263 | 1356 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1357 | |
6f937416 | 1358 | validate_actionline (line, b); |
a7bdde9e VP |
1359 | } |
1360 | ||
95a42b64 TT |
1361 | /* A structure used to pass information through |
1362 | map_breakpoint_numbers. */ | |
1363 | ||
1364 | struct commands_info | |
1365 | { | |
1366 | /* True if the command was typed at a tty. */ | |
1367 | int from_tty; | |
86b17b60 PA |
1368 | |
1369 | /* The breakpoint range spec. */ | |
896b6bda | 1370 | const char *arg; |
86b17b60 | 1371 | |
95a42b64 TT |
1372 | /* Non-NULL if the body of the commands are being read from this |
1373 | already-parsed command. */ | |
1374 | struct command_line *control; | |
86b17b60 | 1375 | |
95a42b64 TT |
1376 | /* The command lines read from the user, or NULL if they have not |
1377 | yet been read. */ | |
1378 | struct counted_command_line *cmd; | |
1379 | }; | |
1380 | ||
1381 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1382 | commands_command. */ | |
1383 | ||
c906108c | 1384 | static void |
95a42b64 | 1385 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1386 | { |
9a3c8263 | 1387 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1388 | |
95a42b64 TT |
1389 | if (info->cmd == NULL) |
1390 | { | |
93921405 | 1391 | command_line_up l; |
5c44784c | 1392 | |
95a42b64 TT |
1393 | if (info->control != NULL) |
1394 | l = copy_command_lines (info->control->body_list[0]); | |
1395 | else | |
86b17b60 PA |
1396 | { |
1397 | struct cleanup *old_chain; | |
1398 | char *str; | |
c5aa993b | 1399 | |
3e43a32a MS |
1400 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1401 | "%s, one per line."), | |
86b17b60 PA |
1402 | info->arg); |
1403 | ||
1404 | old_chain = make_cleanup (xfree, str); | |
1405 | ||
1406 | l = read_command_lines (str, | |
1407 | info->from_tty, 1, | |
d77f58be | 1408 | (is_tracepoint (b) |
86b17b60 PA |
1409 | ? check_tracepoint_command : 0), |
1410 | b); | |
1411 | ||
1412 | do_cleanups (old_chain); | |
1413 | } | |
a7bdde9e | 1414 | |
93921405 | 1415 | info->cmd = alloc_counted_command_line (l.release ()); |
95a42b64 TT |
1416 | } |
1417 | ||
1418 | /* If a breakpoint was on the list more than once, we don't need to | |
1419 | do anything. */ | |
1420 | if (b->commands != info->cmd) | |
1421 | { | |
1422 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1423 | incref_counted_command_line (info->cmd); | |
1424 | decref_counted_command_line (&b->commands); | |
1425 | b->commands = info->cmd; | |
8d3788bd | 1426 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1427 | } |
95a42b64 TT |
1428 | } |
1429 | ||
1430 | static void | |
896b6bda | 1431 | commands_command_1 (const char *arg, int from_tty, |
4a64f543 | 1432 | struct command_line *control) |
95a42b64 TT |
1433 | { |
1434 | struct cleanup *cleanups; | |
1435 | struct commands_info info; | |
1436 | ||
1437 | info.from_tty = from_tty; | |
1438 | info.control = control; | |
1439 | info.cmd = NULL; | |
1440 | /* If we read command lines from the user, then `info' will hold an | |
1441 | extra reference to the commands that we must clean up. */ | |
1442 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1443 | ||
896b6bda PA |
1444 | std::string new_arg; |
1445 | ||
95a42b64 TT |
1446 | if (arg == NULL || !*arg) |
1447 | { | |
86b17b60 | 1448 | if (breakpoint_count - prev_breakpoint_count > 1) |
896b6bda PA |
1449 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
1450 | breakpoint_count); | |
95a42b64 | 1451 | else if (breakpoint_count > 0) |
896b6bda | 1452 | new_arg = string_printf ("%d", breakpoint_count); |
95a42b64 | 1453 | } |
9766ced4 | 1454 | else |
896b6bda | 1455 | new_arg = arg; |
86b17b60 | 1456 | |
896b6bda | 1457 | info.arg = new_arg.c_str (); |
95a42b64 | 1458 | |
896b6bda | 1459 | map_breakpoint_numbers (info.arg, do_map_commands_command, &info); |
95a42b64 TT |
1460 | |
1461 | if (info.cmd == NULL) | |
1462 | error (_("No breakpoints specified.")); | |
1463 | ||
1464 | do_cleanups (cleanups); | |
1465 | } | |
1466 | ||
1467 | static void | |
1468 | commands_command (char *arg, int from_tty) | |
1469 | { | |
1470 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1471 | } |
40c03ae8 EZ |
1472 | |
1473 | /* Like commands_command, but instead of reading the commands from | |
1474 | input stream, takes them from an already parsed command structure. | |
1475 | ||
1476 | This is used by cli-script.c to DTRT with breakpoint commands | |
1477 | that are part of if and while bodies. */ | |
1478 | enum command_control_type | |
896b6bda | 1479 | commands_from_control_command (const char *arg, struct command_line *cmd) |
40c03ae8 | 1480 | { |
95a42b64 TT |
1481 | commands_command_1 (arg, 0, cmd); |
1482 | return simple_control; | |
40c03ae8 | 1483 | } |
876fa593 JK |
1484 | |
1485 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1486 | ||
1487 | static int | |
1488 | bp_location_has_shadow (struct bp_location *bl) | |
1489 | { | |
1490 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1491 | return 0; | |
1492 | if (!bl->inserted) | |
1493 | return 0; | |
1494 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1495 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1496 | return 0; |
1497 | return 1; | |
1498 | } | |
1499 | ||
9d497a19 PA |
1500 | /* Update BUF, which is LEN bytes read from the target address |
1501 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1502 | contents. | |
1503 | ||
1504 | If READBUF is not NULL, this buffer must not overlap with the of | |
1505 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1506 | failed assertion internal error will be raised. */ | |
1507 | ||
1508 | static void | |
1509 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1510 | const gdb_byte *writebuf_org, | |
1511 | ULONGEST memaddr, LONGEST len, | |
1512 | struct bp_target_info *target_info, | |
1513 | struct gdbarch *gdbarch) | |
1514 | { | |
1515 | /* Now do full processing of the found relevant range of elements. */ | |
1516 | CORE_ADDR bp_addr = 0; | |
1517 | int bp_size = 0; | |
1518 | int bptoffset = 0; | |
1519 | ||
1520 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1521 | current_program_space->aspace, 0)) | |
1522 | { | |
1523 | /* The breakpoint is inserted in a different address space. */ | |
1524 | return; | |
1525 | } | |
1526 | ||
1527 | /* Addresses and length of the part of the breakpoint that | |
1528 | we need to copy. */ | |
1529 | bp_addr = target_info->placed_address; | |
1530 | bp_size = target_info->shadow_len; | |
1531 | ||
1532 | if (bp_addr + bp_size <= memaddr) | |
1533 | { | |
1534 | /* The breakpoint is entirely before the chunk of memory we are | |
1535 | reading. */ | |
1536 | return; | |
1537 | } | |
1538 | ||
1539 | if (bp_addr >= memaddr + len) | |
1540 | { | |
1541 | /* The breakpoint is entirely after the chunk of memory we are | |
1542 | reading. */ | |
1543 | return; | |
1544 | } | |
1545 | ||
1546 | /* Offset within shadow_contents. */ | |
1547 | if (bp_addr < memaddr) | |
1548 | { | |
1549 | /* Only copy the second part of the breakpoint. */ | |
1550 | bp_size -= memaddr - bp_addr; | |
1551 | bptoffset = memaddr - bp_addr; | |
1552 | bp_addr = memaddr; | |
1553 | } | |
1554 | ||
1555 | if (bp_addr + bp_size > memaddr + len) | |
1556 | { | |
1557 | /* Only copy the first part of the breakpoint. */ | |
1558 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1559 | } | |
1560 | ||
1561 | if (readbuf != NULL) | |
1562 | { | |
1563 | /* Verify that the readbuf buffer does not overlap with the | |
1564 | shadow_contents buffer. */ | |
1565 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1566 | || readbuf >= (target_info->shadow_contents | |
1567 | + target_info->shadow_len)); | |
1568 | ||
1569 | /* Update the read buffer with this inserted breakpoint's | |
1570 | shadow. */ | |
1571 | memcpy (readbuf + bp_addr - memaddr, | |
1572 | target_info->shadow_contents + bptoffset, bp_size); | |
1573 | } | |
1574 | else | |
1575 | { | |
1576 | const unsigned char *bp; | |
0d5ed153 MR |
1577 | CORE_ADDR addr = target_info->reqstd_address; |
1578 | int placed_size; | |
9d497a19 PA |
1579 | |
1580 | /* Update the shadow with what we want to write to memory. */ | |
1581 | memcpy (target_info->shadow_contents + bptoffset, | |
1582 | writebuf_org + bp_addr - memaddr, bp_size); | |
1583 | ||
1584 | /* Determine appropriate breakpoint contents and size for this | |
1585 | address. */ | |
0d5ed153 | 1586 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1587 | |
1588 | /* Update the final write buffer with this inserted | |
1589 | breakpoint's INSN. */ | |
1590 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1591 | } | |
1592 | } | |
1593 | ||
8defab1a | 1594 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1595 | by replacing any memory breakpoints with their shadowed contents. |
1596 | ||
35c63cd8 JB |
1597 | If READBUF is not NULL, this buffer must not overlap with any of |
1598 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1599 | a failed assertion internal error will be raised. | |
1600 | ||
876fa593 | 1601 | The range of shadowed area by each bp_location is: |
f5336ca5 PA |
1602 | bl->address - bp_locations_placed_address_before_address_max |
1603 | up to bl->address + bp_locations_shadow_len_after_address_max | |
876fa593 JK |
1604 | The range we were requested to resolve shadows for is: |
1605 | memaddr ... memaddr + len | |
1606 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 | 1607 | memaddr + len <= (bl->address |
f5336ca5 | 1608 | - bp_locations_placed_address_before_address_max) |
876fa593 | 1609 | and: |
f5336ca5 | 1610 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
c906108c | 1611 | |
8defab1a | 1612 | void |
f0ba3972 PA |
1613 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1614 | const gdb_byte *writebuf_org, | |
1615 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1616 | { |
4a64f543 MS |
1617 | /* Left boundary, right boundary and median element of our binary |
1618 | search. */ | |
876fa593 JK |
1619 | unsigned bc_l, bc_r, bc; |
1620 | ||
4a64f543 MS |
1621 | /* Find BC_L which is a leftmost element which may affect BUF |
1622 | content. It is safe to report lower value but a failure to | |
1623 | report higher one. */ | |
876fa593 JK |
1624 | |
1625 | bc_l = 0; | |
f5336ca5 | 1626 | bc_r = bp_locations_count; |
876fa593 JK |
1627 | while (bc_l + 1 < bc_r) |
1628 | { | |
35df4500 | 1629 | struct bp_location *bl; |
876fa593 JK |
1630 | |
1631 | bc = (bc_l + bc_r) / 2; | |
f5336ca5 | 1632 | bl = bp_locations[bc]; |
876fa593 | 1633 | |
4a64f543 MS |
1634 | /* Check first BL->ADDRESS will not overflow due to the added |
1635 | constant. Then advance the left boundary only if we are sure | |
1636 | the BC element can in no way affect the BUF content (MEMADDR | |
1637 | to MEMADDR + LEN range). | |
876fa593 | 1638 | |
f5336ca5 | 1639 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
4a64f543 MS |
1640 | offset so that we cannot miss a breakpoint with its shadow |
1641 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1642 | |
f5336ca5 | 1643 | if ((bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1644 | >= bl->address) |
f5336ca5 | 1645 | && (bl->address + bp_locations_shadow_len_after_address_max |
35df4500 | 1646 | <= memaddr)) |
876fa593 JK |
1647 | bc_l = bc; |
1648 | else | |
1649 | bc_r = bc; | |
1650 | } | |
1651 | ||
128070bb PA |
1652 | /* Due to the binary search above, we need to make sure we pick the |
1653 | first location that's at BC_L's address. E.g., if there are | |
1654 | multiple locations at the same address, BC_L may end up pointing | |
1655 | at a duplicate location, and miss the "master"/"inserted" | |
1656 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1657 | B: | |
1658 | ||
1659 | L1@A, L2@A, L3@B, ... | |
1660 | ||
1661 | BC_L could end up pointing at location L2, while the "master" | |
1662 | location could be L1. Since the `loc->inserted' flag is only set | |
1663 | on "master" locations, we'd forget to restore the shadow of L1 | |
1664 | and L2. */ | |
1665 | while (bc_l > 0 | |
f5336ca5 | 1666 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
128070bb PA |
1667 | bc_l--; |
1668 | ||
876fa593 JK |
1669 | /* Now do full processing of the found relevant range of elements. */ |
1670 | ||
f5336ca5 | 1671 | for (bc = bc_l; bc < bp_locations_count; bc++) |
c5aa993b | 1672 | { |
f5336ca5 | 1673 | struct bp_location *bl = bp_locations[bc]; |
876fa593 | 1674 | |
35df4500 TJB |
1675 | /* bp_location array has BL->OWNER always non-NULL. */ |
1676 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1677 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1678 | bl->owner->number); |
ffce0d52 | 1679 | |
e5dd4106 | 1680 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1681 | content. */ |
1682 | ||
f5336ca5 PA |
1683 | if (bl->address >= bp_locations_placed_address_before_address_max |
1684 | && memaddr + len <= (bl->address | |
1685 | - bp_locations_placed_address_before_address_max)) | |
876fa593 JK |
1686 | break; |
1687 | ||
35df4500 | 1688 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1689 | continue; |
6c95b8df | 1690 | |
9d497a19 PA |
1691 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1692 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1693 | } | |
c906108c | 1694 | } |
9d497a19 | 1695 | |
c906108c | 1696 | \f |
c5aa993b | 1697 | |
b775012e LM |
1698 | /* Return true if BPT is either a software breakpoint or a hardware |
1699 | breakpoint. */ | |
1700 | ||
1701 | int | |
1702 | is_breakpoint (const struct breakpoint *bpt) | |
1703 | { | |
1704 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1705 | || bpt->type == bp_hardware_breakpoint |
1706 | || bpt->type == bp_dprintf); | |
b775012e LM |
1707 | } |
1708 | ||
60e1c644 PA |
1709 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1710 | ||
a5606eee | 1711 | static int |
d77f58be | 1712 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1713 | { |
1714 | return (bpt->type == bp_hardware_watchpoint | |
1715 | || bpt->type == bp_read_watchpoint | |
1716 | || bpt->type == bp_access_watchpoint); | |
1717 | } | |
7270d8f2 | 1718 | |
60e1c644 PA |
1719 | /* Return true if BPT is of any watchpoint kind, hardware or |
1720 | software. */ | |
1721 | ||
3a5c3e22 | 1722 | int |
d77f58be | 1723 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1724 | { |
1725 | return (is_hardware_watchpoint (bpt) | |
1726 | || bpt->type == bp_watchpoint); | |
1727 | } | |
1728 | ||
3a5c3e22 PA |
1729 | /* Returns true if the current thread and its running state are safe |
1730 | to evaluate or update watchpoint B. Watchpoints on local | |
1731 | expressions need to be evaluated in the context of the thread that | |
1732 | was current when the watchpoint was created, and, that thread needs | |
1733 | to be stopped to be able to select the correct frame context. | |
1734 | Watchpoints on global expressions can be evaluated on any thread, | |
1735 | and in any state. It is presently left to the target allowing | |
1736 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1737 | |
1738 | static int | |
3a5c3e22 | 1739 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1740 | { |
c1fc2657 | 1741 | return (b->pspace == current_program_space |
d0d8b0c6 JK |
1742 | && (ptid_equal (b->watchpoint_thread, null_ptid) |
1743 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1744 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1745 | } |
1746 | ||
d0fb5eae JK |
1747 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1748 | associated bp_watchpoint_scope breakpoint. */ | |
1749 | ||
1750 | static void | |
3a5c3e22 | 1751 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1752 | { |
c1fc2657 | 1753 | if (w->related_breakpoint != w) |
d0fb5eae | 1754 | { |
c1fc2657 SM |
1755 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
1756 | gdb_assert (w->related_breakpoint->related_breakpoint == w); | |
1757 | w->related_breakpoint->disposition = disp_del_at_next_stop; | |
1758 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; | |
1759 | w->related_breakpoint = w; | |
d0fb5eae | 1760 | } |
c1fc2657 | 1761 | w->disposition = disp_del_at_next_stop; |
d0fb5eae JK |
1762 | } |
1763 | ||
bb9d5f81 PP |
1764 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1765 | watchpoint W. */ | |
1766 | ||
1767 | static struct value * | |
1768 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1769 | { | |
1770 | struct value *bit_val; | |
1771 | ||
1772 | if (val == NULL) | |
1773 | return NULL; | |
1774 | ||
1775 | bit_val = allocate_value (value_type (val)); | |
1776 | ||
1777 | unpack_value_bitfield (bit_val, | |
1778 | w->val_bitpos, | |
1779 | w->val_bitsize, | |
1780 | value_contents_for_printing (val), | |
1781 | value_offset (val), | |
1782 | val); | |
1783 | ||
1784 | return bit_val; | |
1785 | } | |
1786 | ||
c6d81124 PA |
1787 | /* Allocate a dummy location and add it to B, which must be a software |
1788 | watchpoint. This is required because even if a software watchpoint | |
1789 | is not watching any memory, bpstat_stop_status requires a location | |
1790 | to be able to report stops. */ | |
1791 | ||
1792 | static void | |
1793 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1794 | struct program_space *pspace) | |
1795 | { | |
1796 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1797 | ||
1798 | b->loc = allocate_bp_location (b); | |
1799 | b->loc->pspace = pspace; | |
1800 | b->loc->address = -1; | |
1801 | b->loc->length = -1; | |
1802 | } | |
1803 | ||
1804 | /* Returns true if B is a software watchpoint that is not watching any | |
1805 | memory (e.g., "watch $pc"). */ | |
1806 | ||
1807 | static int | |
1808 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1809 | { | |
1810 | return (b->type == bp_watchpoint | |
1811 | && b->loc != NULL | |
1812 | && b->loc->next == NULL | |
1813 | && b->loc->address == -1 | |
1814 | && b->loc->length == -1); | |
1815 | } | |
1816 | ||
567e1b4e JB |
1817 | /* Assuming that B is a watchpoint: |
1818 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1819 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1820 | - Evaluate the condition if there is one, and store the result |
1821 | in b->loc->cond. | |
a5606eee VP |
1822 | - Update the list of values that must be watched in B->loc. |
1823 | ||
4a64f543 MS |
1824 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1825 | nothing. If this is local watchpoint that is out of scope, delete | |
1826 | it. | |
1827 | ||
1828 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1829 | removed + inserted on each stop here. Normal breakpoints must | |
1830 | never be removed because they might be missed by a running thread | |
1831 | when debugging in non-stop mode. On the other hand, hardware | |
1832 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1833 | to each LWP since they are stored in each LWP's hardware debug | |
1834 | registers. Therefore, such LWP must be stopped first in order to | |
1835 | be able to modify its hardware watchpoints. | |
1836 | ||
1837 | Hardware watchpoints must be reset exactly once after being | |
1838 | presented to the user. It cannot be done sooner, because it would | |
1839 | reset the data used to present the watchpoint hit to the user. And | |
1840 | it must not be done later because it could display the same single | |
1841 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1842 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1843 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1844 | not user-visible - its hit is suppressed if the memory content has | |
1845 | not changed. | |
1846 | ||
1847 | The following constraints influence the location where we can reset | |
1848 | hardware watchpoints: | |
1849 | ||
1850 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1851 | called several times when GDB stops. | |
1852 | ||
1853 | [linux] | |
1854 | * Multiple hardware watchpoints can be hit at the same time, | |
1855 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1856 | hit at a time as the reason for stopping, and all the other hits | |
1857 | are presented later, one after the other, each time the user | |
1858 | requests the execution to be resumed. Execution is not resumed | |
1859 | for the threads still having pending hit event stored in | |
1860 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1861 | the inferior on the first stop the thread hit event is kept being | |
1862 | reported from its cached value by linux_nat_stopped_data_address | |
1863 | until the real thread resume happens after the watchpoint gets | |
1864 | presented and thus its LWP_INFO->STATUS gets reset. | |
1865 | ||
1866 | Therefore the hardware watchpoint hit can get safely reset on the | |
1867 | watchpoint removal from inferior. */ | |
a79d3c27 | 1868 | |
b40ce68a | 1869 | static void |
3a5c3e22 | 1870 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1871 | { |
a5606eee | 1872 | int within_current_scope; |
a5606eee | 1873 | struct frame_id saved_frame_id; |
66076460 | 1874 | int frame_saved; |
a5606eee | 1875 | |
f6bc2008 PA |
1876 | /* If this is a local watchpoint, we only want to check if the |
1877 | watchpoint frame is in scope if the current thread is the thread | |
1878 | that was used to create the watchpoint. */ | |
1879 | if (!watchpoint_in_thread_scope (b)) | |
1880 | return; | |
1881 | ||
c1fc2657 | 1882 | if (b->disposition == disp_del_at_next_stop) |
a5606eee VP |
1883 | return; |
1884 | ||
66076460 | 1885 | frame_saved = 0; |
a5606eee VP |
1886 | |
1887 | /* Determine if the watchpoint is within scope. */ | |
1888 | if (b->exp_valid_block == NULL) | |
1889 | within_current_scope = 1; | |
1890 | else | |
1891 | { | |
b5db5dfc UW |
1892 | struct frame_info *fi = get_current_frame (); |
1893 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1894 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1895 | ||
c9cf6e20 MG |
1896 | /* If we're at a point where the stack has been destroyed |
1897 | (e.g. in a function epilogue), unwinding may not work | |
1898 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1899 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1900 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1901 | return; |
66076460 DJ |
1902 | |
1903 | /* Save the current frame's ID so we can restore it after | |
1904 | evaluating the watchpoint expression on its own frame. */ | |
1905 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1906 | took a frame parameter, so that we didn't have to change the | |
1907 | selected frame. */ | |
1908 | frame_saved = 1; | |
1909 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1910 | ||
a5606eee VP |
1911 | fi = frame_find_by_id (b->watchpoint_frame); |
1912 | within_current_scope = (fi != NULL); | |
1913 | if (within_current_scope) | |
1914 | select_frame (fi); | |
1915 | } | |
1916 | ||
b5db5dfc UW |
1917 | /* We don't free locations. They are stored in the bp_location array |
1918 | and update_global_location_list will eventually delete them and | |
1919 | remove breakpoints if needed. */ | |
c1fc2657 | 1920 | b->loc = NULL; |
b5db5dfc | 1921 | |
a5606eee VP |
1922 | if (within_current_scope && reparse) |
1923 | { | |
bbc13ae3 | 1924 | const char *s; |
d63d0675 | 1925 | |
4d01a485 | 1926 | b->exp.reset (); |
d63d0675 | 1927 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1928 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1929 | /* If the meaning of expression itself changed, the old value is |
1930 | no longer relevant. We don't want to report a watchpoint hit | |
1931 | to the user when the old value and the new value may actually | |
1932 | be completely different objects. */ | |
1933 | value_free (b->val); | |
fa4727a6 DJ |
1934 | b->val = NULL; |
1935 | b->val_valid = 0; | |
60e1c644 PA |
1936 | |
1937 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1938 | expression is stored in the breakpoint object, not in the | |
1939 | locations (re)created below. */ | |
c1fc2657 | 1940 | if (b->cond_string != NULL) |
60e1c644 | 1941 | { |
4d01a485 | 1942 | b->cond_exp.reset (); |
60e1c644 | 1943 | |
c1fc2657 | 1944 | s = b->cond_string; |
1bb9788d | 1945 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1946 | } |
a5606eee | 1947 | } |
a5606eee VP |
1948 | |
1949 | /* If we failed to parse the expression, for example because | |
1950 | it refers to a global variable in a not-yet-loaded shared library, | |
1951 | don't try to insert watchpoint. We don't automatically delete | |
1952 | such watchpoint, though, since failure to parse expression | |
1953 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1954 | if (!target_has_execution) |
2d134ed3 PA |
1955 | { |
1956 | /* Without execution, memory can't change. No use to try and | |
1957 | set watchpoint locations. The watchpoint will be reset when | |
1958 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1959 | if (!can_use_hw_watchpoints) |
1960 | { | |
c1fc2657 SM |
1961 | if (b->ops->works_in_software_mode (b)) |
1962 | b->type = bp_watchpoint; | |
e8369a73 | 1963 | else |
638aa5a1 AB |
1964 | error (_("Can't set read/access watchpoint when " |
1965 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1966 | } |
2d134ed3 PA |
1967 | } |
1968 | else if (within_current_scope && b->exp) | |
a5606eee | 1969 | { |
0cf6dd15 | 1970 | int pc = 0; |
fa4727a6 | 1971 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1972 | struct program_space *frame_pspace; |
a5606eee | 1973 | |
4d01a485 | 1974 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
a5606eee | 1975 | |
a5606eee VP |
1976 | /* Avoid setting b->val if it's already set. The meaning of |
1977 | b->val is 'the last value' user saw, and we should update | |
1978 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1979 | happens, the code that reports it updates b->val directly. |
1980 | We don't keep track of the memory value for masked | |
1981 | watchpoints. */ | |
c1fc2657 | 1982 | if (!b->val_valid && !is_masked_watchpoint (b)) |
fa4727a6 | 1983 | { |
bb9d5f81 PP |
1984 | if (b->val_bitsize != 0) |
1985 | { | |
1986 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1987 | if (v != NULL) | |
1988 | release_value (v); | |
1989 | } | |
fa4727a6 DJ |
1990 | b->val = v; |
1991 | b->val_valid = 1; | |
1992 | } | |
a5606eee | 1993 | |
2d134ed3 PA |
1994 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1995 | ||
a5606eee | 1996 | /* Look at each value on the value chain. */ |
9fa40276 | 1997 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1998 | { |
1999 | /* If it's a memory location, and GDB actually needed | |
2000 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
2001 | must watch it. If the first value returned is |
2002 | still lazy, that means an error occurred reading it; | |
2003 | watch it anyway in case it becomes readable. */ | |
a5606eee | 2004 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 2005 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
2006 | { |
2007 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 2008 | |
a5606eee VP |
2009 | /* We only watch structs and arrays if user asked |
2010 | for it explicitly, never if they just happen to | |
2011 | appear in the middle of some value chain. */ | |
fa4727a6 | 2012 | if (v == result |
a5606eee VP |
2013 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
2014 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2015 | { | |
2016 | CORE_ADDR addr; | |
f486487f | 2017 | enum target_hw_bp_type type; |
a5606eee | 2018 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2019 | int bitpos = 0, bitsize = 0; |
2020 | ||
2021 | if (value_bitsize (v) != 0) | |
2022 | { | |
2023 | /* Extract the bit parameters out from the bitfield | |
2024 | sub-expression. */ | |
2025 | bitpos = value_bitpos (v); | |
2026 | bitsize = value_bitsize (v); | |
2027 | } | |
2028 | else if (v == result && b->val_bitsize != 0) | |
2029 | { | |
2030 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2031 | lvalue whose bit parameters are saved in the fields | |
2032 | VAL_BITPOS and VAL_BITSIZE. */ | |
2033 | bitpos = b->val_bitpos; | |
2034 | bitsize = b->val_bitsize; | |
2035 | } | |
a5606eee | 2036 | |
42ae5230 | 2037 | addr = value_address (v); |
bb9d5f81 PP |
2038 | if (bitsize != 0) |
2039 | { | |
2040 | /* Skip the bytes that don't contain the bitfield. */ | |
2041 | addr += bitpos / 8; | |
2042 | } | |
2043 | ||
a5606eee | 2044 | type = hw_write; |
c1fc2657 | 2045 | if (b->type == bp_read_watchpoint) |
a5606eee | 2046 | type = hw_read; |
c1fc2657 | 2047 | else if (b->type == bp_access_watchpoint) |
a5606eee | 2048 | type = hw_access; |
3a5c3e22 | 2049 | |
c1fc2657 SM |
2050 | loc = allocate_bp_location (b); |
2051 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2052 | ; |
2053 | *tmp = loc; | |
a6d9a66e | 2054 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2055 | |
2056 | loc->pspace = frame_pspace; | |
a5606eee | 2057 | loc->address = addr; |
bb9d5f81 PP |
2058 | |
2059 | if (bitsize != 0) | |
2060 | { | |
2061 | /* Just cover the bytes that make up the bitfield. */ | |
2062 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2063 | } | |
2064 | else | |
2065 | loc->length = TYPE_LENGTH (value_type (v)); | |
2066 | ||
a5606eee VP |
2067 | loc->watchpoint_type = type; |
2068 | } | |
2069 | } | |
9fa40276 TJB |
2070 | } |
2071 | ||
2072 | /* Change the type of breakpoint between hardware assisted or | |
2073 | an ordinary watchpoint depending on the hardware support | |
2074 | and free hardware slots. REPARSE is set when the inferior | |
2075 | is started. */ | |
a9634178 | 2076 | if (reparse) |
9fa40276 | 2077 | { |
e09342b5 | 2078 | int reg_cnt; |
9fa40276 TJB |
2079 | enum bp_loc_type loc_type; |
2080 | struct bp_location *bl; | |
a5606eee | 2081 | |
a9634178 | 2082 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2083 | |
2084 | if (reg_cnt) | |
9fa40276 TJB |
2085 | { |
2086 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2087 | enum bptype type; |
9fa40276 | 2088 | |
a9634178 TJB |
2089 | /* Use an exact watchpoint when there's only one memory region to be |
2090 | watched, and only one debug register is needed to watch it. */ | |
2091 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2092 | ||
9fa40276 | 2093 | /* We need to determine how many resources are already |
e09342b5 TJB |
2094 | used for all other hardware watchpoints plus this one |
2095 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2096 | this watchpoint in as well. */ |
2097 | ||
2098 | /* If this is a software watchpoint, we try to turn it | |
2099 | to a hardware one -- count resources as if B was of | |
2100 | hardware watchpoint type. */ | |
c1fc2657 | 2101 | type = b->type; |
a1398e0c PA |
2102 | if (type == bp_watchpoint) |
2103 | type = bp_hardware_watchpoint; | |
2104 | ||
2105 | /* This watchpoint may or may not have been placed on | |
2106 | the list yet at this point (it won't be in the list | |
2107 | if we're trying to create it for the first time, | |
2108 | through watch_command), so always account for it | |
2109 | manually. */ | |
2110 | ||
2111 | /* Count resources used by all watchpoints except B. */ | |
c1fc2657 | 2112 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
a1398e0c PA |
2113 | |
2114 | /* Add in the resources needed for B. */ | |
c1fc2657 | 2115 | i += hw_watchpoint_use_count (b); |
a1398e0c PA |
2116 | |
2117 | target_resources_ok | |
2118 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2119 | if (target_resources_ok <= 0) |
a9634178 | 2120 | { |
c1fc2657 | 2121 | int sw_mode = b->ops->works_in_software_mode (b); |
9c06b0b4 TJB |
2122 | |
2123 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2124 | error (_("Target does not support this type of " |
2125 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2126 | else if (target_resources_ok < 0 && !sw_mode) |
2127 | error (_("There are not enough available hardware " | |
2128 | "resources for this watchpoint.")); | |
a1398e0c PA |
2129 | |
2130 | /* Downgrade to software watchpoint. */ | |
c1fc2657 | 2131 | b->type = bp_watchpoint; |
a1398e0c PA |
2132 | } |
2133 | else | |
2134 | { | |
2135 | /* If this was a software watchpoint, we've just | |
2136 | found we have enough resources to turn it to a | |
2137 | hardware watchpoint. Otherwise, this is a | |
2138 | nop. */ | |
c1fc2657 | 2139 | b->type = type; |
a9634178 | 2140 | } |
9fa40276 | 2141 | } |
c1fc2657 | 2142 | else if (!b->ops->works_in_software_mode (b)) |
638aa5a1 AB |
2143 | { |
2144 | if (!can_use_hw_watchpoints) | |
2145 | error (_("Can't set read/access watchpoint when " | |
2146 | "hardware watchpoints are disabled.")); | |
2147 | else | |
2148 | error (_("Expression cannot be implemented with " | |
2149 | "read/access watchpoint.")); | |
2150 | } | |
9fa40276 | 2151 | else |
c1fc2657 | 2152 | b->type = bp_watchpoint; |
9fa40276 | 2153 | |
c1fc2657 | 2154 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
9fa40276 | 2155 | : bp_loc_hardware_watchpoint); |
c1fc2657 | 2156 | for (bl = b->loc; bl; bl = bl->next) |
9fa40276 TJB |
2157 | bl->loc_type = loc_type; |
2158 | } | |
2159 | ||
2160 | for (v = val_chain; v; v = next) | |
2161 | { | |
a5606eee VP |
2162 | next = value_next (v); |
2163 | if (v != b->val) | |
2164 | value_free (v); | |
2165 | } | |
2166 | ||
c7437ca6 PA |
2167 | /* If a software watchpoint is not watching any memory, then the |
2168 | above left it without any location set up. But, | |
2169 | bpstat_stop_status requires a location to be able to report | |
2170 | stops, so make sure there's at least a dummy one. */ | |
c1fc2657 SM |
2171 | if (b->type == bp_watchpoint && b->loc == NULL) |
2172 | software_watchpoint_add_no_memory_location (b, frame_pspace); | |
a5606eee VP |
2173 | } |
2174 | else if (!within_current_scope) | |
7270d8f2 | 2175 | { |
ac74f770 MS |
2176 | printf_filtered (_("\ |
2177 | Watchpoint %d deleted because the program has left the block\n\ | |
2178 | in which its expression is valid.\n"), | |
c1fc2657 | 2179 | b->number); |
d0fb5eae | 2180 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2181 | } |
a5606eee VP |
2182 | |
2183 | /* Restore the selected frame. */ | |
66076460 DJ |
2184 | if (frame_saved) |
2185 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2186 | } |
2187 | ||
a5606eee | 2188 | |
74960c60 | 2189 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2190 | inserted in the inferior. We don't differentiate the type of BL's owner |
2191 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2192 | breakpoint_ops is not defined, because in insert_bp_location, | |
2193 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2194 | static int |
35df4500 | 2195 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2196 | { |
35df4500 | 2197 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2198 | return 0; |
2199 | ||
35df4500 | 2200 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2201 | return 0; |
2202 | ||
35df4500 | 2203 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2204 | return 0; |
2205 | ||
f8eba3c6 TT |
2206 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2207 | return 0; | |
2208 | ||
56710373 PA |
2209 | /* This is set for example, when we're attached to the parent of a |
2210 | vfork, and have detached from the child. The child is running | |
2211 | free, and we expect it to do an exec or exit, at which point the | |
2212 | OS makes the parent schedulable again (and the target reports | |
2213 | that the vfork is done). Until the child is done with the shared | |
2214 | memory region, do not insert breakpoints in the parent, otherwise | |
2215 | the child could still trip on the parent's breakpoints. Since | |
2216 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2217 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2218 | return 0; |
2219 | ||
31e77af2 | 2220 | /* Don't insert a breakpoint if we're trying to step past its |
21edc42f YQ |
2221 | location, except if the breakpoint is a single-step breakpoint, |
2222 | and the breakpoint's thread is the thread which is stepping past | |
2223 | a breakpoint. */ | |
31e77af2 PA |
2224 | if ((bl->loc_type == bp_loc_software_breakpoint |
2225 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2226 | && stepping_past_instruction_at (bl->pspace->aspace, | |
21edc42f YQ |
2227 | bl->address) |
2228 | /* The single-step breakpoint may be inserted at the location | |
2229 | we're trying to step if the instruction branches to itself. | |
2230 | However, the instruction won't be executed at all and it may | |
2231 | break the semantics of the instruction, for example, the | |
2232 | instruction is a conditional branch or updates some flags. | |
2233 | We can't fix it unless GDB is able to emulate the instruction | |
2234 | or switch to displaced stepping. */ | |
2235 | && !(bl->owner->type == bp_single_step | |
2236 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) | |
e558d7c1 PA |
2237 | { |
2238 | if (debug_infrun) | |
2239 | { | |
2240 | fprintf_unfiltered (gdb_stdlog, | |
2241 | "infrun: skipping breakpoint: " | |
2242 | "stepping past insn at: %s\n", | |
2243 | paddress (bl->gdbarch, bl->address)); | |
2244 | } | |
2245 | return 0; | |
2246 | } | |
31e77af2 | 2247 | |
963f9c80 PA |
2248 | /* Don't insert watchpoints if we're trying to step past the |
2249 | instruction that triggered one. */ | |
2250 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2251 | && stepping_past_nonsteppable_watchpoint ()) | |
2252 | { | |
2253 | if (debug_infrun) | |
2254 | { | |
2255 | fprintf_unfiltered (gdb_stdlog, | |
2256 | "infrun: stepping past non-steppable watchpoint. " | |
2257 | "skipping watchpoint at %s:%d\n", | |
2258 | paddress (bl->gdbarch, bl->address), | |
2259 | bl->length); | |
2260 | } | |
2261 | return 0; | |
2262 | } | |
2263 | ||
74960c60 VP |
2264 | return 1; |
2265 | } | |
2266 | ||
934709f0 PW |
2267 | /* Same as should_be_inserted but does the check assuming |
2268 | that the location is not duplicated. */ | |
2269 | ||
2270 | static int | |
2271 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2272 | { | |
2273 | int result; | |
2274 | const int save_duplicate = bl->duplicate; | |
2275 | ||
2276 | bl->duplicate = 0; | |
2277 | result = should_be_inserted (bl); | |
2278 | bl->duplicate = save_duplicate; | |
2279 | return result; | |
2280 | } | |
2281 | ||
b775012e LM |
2282 | /* Parses a conditional described by an expression COND into an |
2283 | agent expression bytecode suitable for evaluation | |
2284 | by the bytecode interpreter. Return NULL if there was | |
2285 | any error during parsing. */ | |
2286 | ||
833177a4 | 2287 | static agent_expr_up |
b775012e LM |
2288 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
2289 | { | |
833177a4 | 2290 | if (cond == NULL) |
b775012e LM |
2291 | return NULL; |
2292 | ||
833177a4 PA |
2293 | agent_expr_up aexpr; |
2294 | ||
b775012e LM |
2295 | /* We don't want to stop processing, so catch any errors |
2296 | that may show up. */ | |
492d29ea | 2297 | TRY |
b775012e | 2298 | { |
036e657b | 2299 | aexpr = gen_eval_for_expr (scope, cond); |
b775012e LM |
2300 | } |
2301 | ||
492d29ea | 2302 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2303 | { |
2304 | /* If we got here, it means the condition could not be parsed to a valid | |
2305 | bytecode expression and thus can't be evaluated on the target's side. | |
2306 | It's no use iterating through the conditions. */ | |
b775012e | 2307 | } |
492d29ea | 2308 | END_CATCH |
b775012e LM |
2309 | |
2310 | /* We have a valid agent expression. */ | |
2311 | return aexpr; | |
2312 | } | |
2313 | ||
2314 | /* Based on location BL, create a list of breakpoint conditions to be | |
2315 | passed on to the target. If we have duplicated locations with different | |
2316 | conditions, we will add such conditions to the list. The idea is that the | |
2317 | target will evaluate the list of conditions and will only notify GDB when | |
2318 | one of them is true. */ | |
2319 | ||
2320 | static void | |
2321 | build_target_condition_list (struct bp_location *bl) | |
2322 | { | |
2323 | struct bp_location **locp = NULL, **loc2p; | |
2324 | int null_condition_or_parse_error = 0; | |
2325 | int modified = bl->needs_update; | |
2326 | struct bp_location *loc; | |
2327 | ||
8b4f3082 | 2328 | /* Release conditions left over from a previous insert. */ |
3cde5c42 | 2329 | bl->target_info.conditions.clear (); |
8b4f3082 | 2330 | |
b775012e LM |
2331 | /* This is only meaningful if the target is |
2332 | evaluating conditions and if the user has | |
2333 | opted for condition evaluation on the target's | |
2334 | side. */ | |
2335 | if (gdb_evaluates_breakpoint_condition_p () | |
2336 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2337 | return; | |
2338 | ||
2339 | /* Do a first pass to check for locations with no assigned | |
2340 | conditions or conditions that fail to parse to a valid agent expression | |
2341 | bytecode. If any of these happen, then it's no use to send conditions | |
2342 | to the target since this location will always trigger and generate a | |
2343 | response back to GDB. */ | |
2344 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2345 | { | |
2346 | loc = (*loc2p); | |
2347 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2348 | { | |
2349 | if (modified) | |
2350 | { | |
b775012e LM |
2351 | /* Re-parse the conditions since something changed. In that |
2352 | case we already freed the condition bytecodes (see | |
2353 | force_breakpoint_reinsertion). We just | |
2354 | need to parse the condition to bytecodes again. */ | |
833177a4 PA |
2355 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
2356 | loc->cond.get ()); | |
b775012e LM |
2357 | } |
2358 | ||
2359 | /* If we have a NULL bytecode expression, it means something | |
2360 | went wrong or we have a null condition expression. */ | |
2361 | if (!loc->cond_bytecode) | |
2362 | { | |
2363 | null_condition_or_parse_error = 1; | |
2364 | break; | |
2365 | } | |
2366 | } | |
2367 | } | |
2368 | ||
2369 | /* If any of these happened, it means we will have to evaluate the conditions | |
2370 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2371 | for all the other duplicate locations, thus we free all of them here. | |
2372 | ||
2373 | This is so we have a finer control over which locations' conditions are | |
2374 | being evaluated by GDB or the remote stub. */ | |
2375 | if (null_condition_or_parse_error) | |
2376 | { | |
2377 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2378 | { | |
2379 | loc = (*loc2p); | |
2380 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2381 | { | |
2382 | /* Only go as far as the first NULL bytecode is | |
2383 | located. */ | |
2384 | if (!loc->cond_bytecode) | |
2385 | return; | |
2386 | ||
833177a4 | 2387 | loc->cond_bytecode.reset (); |
b775012e LM |
2388 | } |
2389 | } | |
2390 | } | |
2391 | ||
2392 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2393 | for this location's address. */ | |
2394 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2395 | { | |
2396 | loc = (*loc2p); | |
2397 | if (loc->cond | |
2398 | && is_breakpoint (loc->owner) | |
2399 | && loc->pspace->num == bl->pspace->num | |
2400 | && loc->owner->enable_state == bp_enabled | |
2401 | && loc->enabled) | |
3cde5c42 PA |
2402 | { |
2403 | /* Add the condition to the vector. This will be used later | |
2404 | to send the conditions to the target. */ | |
2405 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); | |
2406 | } | |
b775012e LM |
2407 | } |
2408 | ||
2409 | return; | |
2410 | } | |
2411 | ||
d3ce09f5 SS |
2412 | /* Parses a command described by string CMD into an agent expression |
2413 | bytecode suitable for evaluation by the bytecode interpreter. | |
2414 | Return NULL if there was any error during parsing. */ | |
2415 | ||
833177a4 | 2416 | static agent_expr_up |
d3ce09f5 SS |
2417 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
2418 | { | |
2419 | struct cleanup *old_cleanups = 0; | |
4d01a485 | 2420 | struct expression **argvec; |
bbc13ae3 KS |
2421 | const char *cmdrest; |
2422 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2423 | struct format_piece *fpieces; |
2424 | int nargs; | |
2425 | struct gdbarch *gdbarch = get_current_arch (); | |
2426 | ||
833177a4 | 2427 | if (cmd == NULL) |
d3ce09f5 SS |
2428 | return NULL; |
2429 | ||
2430 | cmdrest = cmd; | |
2431 | ||
2432 | if (*cmdrest == ',') | |
2433 | ++cmdrest; | |
f1735a53 | 2434 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2435 | |
2436 | if (*cmdrest++ != '"') | |
2437 | error (_("No format string following the location")); | |
2438 | ||
2439 | format_start = cmdrest; | |
2440 | ||
2441 | fpieces = parse_format_string (&cmdrest); | |
2442 | ||
2443 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2444 | ||
2445 | format_end = cmdrest; | |
2446 | ||
2447 | if (*cmdrest++ != '"') | |
2448 | error (_("Bad format string, non-terminated '\"'.")); | |
2449 | ||
f1735a53 | 2450 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2451 | |
2452 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2453 | error (_("Invalid argument syntax")); | |
2454 | ||
2455 | if (*cmdrest == ',') | |
2456 | cmdrest++; | |
f1735a53 | 2457 | cmdrest = skip_spaces (cmdrest); |
d3ce09f5 SS |
2458 | |
2459 | /* For each argument, make an expression. */ | |
2460 | ||
2461 | argvec = (struct expression **) alloca (strlen (cmd) | |
2462 | * sizeof (struct expression *)); | |
2463 | ||
2464 | nargs = 0; | |
2465 | while (*cmdrest != '\0') | |
2466 | { | |
bbc13ae3 | 2467 | const char *cmd1; |
d3ce09f5 SS |
2468 | |
2469 | cmd1 = cmdrest; | |
4d01a485 PA |
2470 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
2471 | argvec[nargs++] = expr.release (); | |
d3ce09f5 SS |
2472 | cmdrest = cmd1; |
2473 | if (*cmdrest == ',') | |
2474 | ++cmdrest; | |
2475 | } | |
2476 | ||
833177a4 PA |
2477 | agent_expr_up aexpr; |
2478 | ||
d3ce09f5 SS |
2479 | /* We don't want to stop processing, so catch any errors |
2480 | that may show up. */ | |
492d29ea | 2481 | TRY |
d3ce09f5 | 2482 | { |
036e657b JB |
2483 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
2484 | format_start, format_end - format_start, | |
2485 | fpieces, nargs, argvec); | |
d3ce09f5 | 2486 | } |
492d29ea | 2487 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2488 | { |
2489 | /* If we got here, it means the command could not be parsed to a valid | |
2490 | bytecode expression and thus can't be evaluated on the target's side. | |
2491 | It's no use iterating through the other commands. */ | |
d3ce09f5 | 2492 | } |
492d29ea PA |
2493 | END_CATCH |
2494 | ||
2495 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2496 | |
d3ce09f5 SS |
2497 | /* We have a valid agent expression, return it. */ |
2498 | return aexpr; | |
2499 | } | |
2500 | ||
2501 | /* Based on location BL, create a list of breakpoint commands to be | |
2502 | passed on to the target. If we have duplicated locations with | |
2503 | different commands, we will add any such to the list. */ | |
2504 | ||
2505 | static void | |
2506 | build_target_command_list (struct bp_location *bl) | |
2507 | { | |
2508 | struct bp_location **locp = NULL, **loc2p; | |
2509 | int null_command_or_parse_error = 0; | |
2510 | int modified = bl->needs_update; | |
2511 | struct bp_location *loc; | |
2512 | ||
3cde5c42 PA |
2513 | /* Clear commands left over from a previous insert. */ |
2514 | bl->target_info.tcommands.clear (); | |
8b4f3082 | 2515 | |
41fac0cf | 2516 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2517 | return; |
2518 | ||
41fac0cf PA |
2519 | /* For now, limit to agent-style dprintf breakpoints. */ |
2520 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2521 | return; |
2522 | ||
41fac0cf PA |
2523 | /* For now, if we have any duplicate location that isn't a dprintf, |
2524 | don't install the target-side commands, as that would make the | |
2525 | breakpoint not be reported to the core, and we'd lose | |
2526 | control. */ | |
2527 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2528 | { | |
2529 | loc = (*loc2p); | |
2530 | if (is_breakpoint (loc->owner) | |
2531 | && loc->pspace->num == bl->pspace->num | |
2532 | && loc->owner->type != bp_dprintf) | |
2533 | return; | |
2534 | } | |
2535 | ||
d3ce09f5 SS |
2536 | /* Do a first pass to check for locations with no assigned |
2537 | conditions or conditions that fail to parse to a valid agent expression | |
2538 | bytecode. If any of these happen, then it's no use to send conditions | |
2539 | to the target since this location will always trigger and generate a | |
2540 | response back to GDB. */ | |
2541 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2542 | { | |
2543 | loc = (*loc2p); | |
2544 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2545 | { | |
2546 | if (modified) | |
2547 | { | |
d3ce09f5 SS |
2548 | /* Re-parse the commands since something changed. In that |
2549 | case we already freed the command bytecodes (see | |
2550 | force_breakpoint_reinsertion). We just | |
2551 | need to parse the command to bytecodes again. */ | |
833177a4 PA |
2552 | loc->cmd_bytecode |
2553 | = parse_cmd_to_aexpr (bl->address, | |
2554 | loc->owner->extra_string); | |
d3ce09f5 SS |
2555 | } |
2556 | ||
2557 | /* If we have a NULL bytecode expression, it means something | |
2558 | went wrong or we have a null command expression. */ | |
2559 | if (!loc->cmd_bytecode) | |
2560 | { | |
2561 | null_command_or_parse_error = 1; | |
2562 | break; | |
2563 | } | |
2564 | } | |
2565 | } | |
2566 | ||
2567 | /* If anything failed, then we're not doing target-side commands, | |
2568 | and so clean up. */ | |
2569 | if (null_command_or_parse_error) | |
2570 | { | |
2571 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2572 | { | |
2573 | loc = (*loc2p); | |
2574 | if (is_breakpoint (loc->owner) | |
2575 | && loc->pspace->num == bl->pspace->num) | |
2576 | { | |
2577 | /* Only go as far as the first NULL bytecode is | |
2578 | located. */ | |
40fb6c5e | 2579 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2580 | return; |
2581 | ||
833177a4 | 2582 | loc->cmd_bytecode.reset (); |
d3ce09f5 SS |
2583 | } |
2584 | } | |
2585 | } | |
2586 | ||
2587 | /* No NULL commands or failed bytecode generation. Build a command list | |
2588 | for this location's address. */ | |
2589 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2590 | { | |
2591 | loc = (*loc2p); | |
2592 | if (loc->owner->extra_string | |
2593 | && is_breakpoint (loc->owner) | |
2594 | && loc->pspace->num == bl->pspace->num | |
2595 | && loc->owner->enable_state == bp_enabled | |
2596 | && loc->enabled) | |
3cde5c42 PA |
2597 | { |
2598 | /* Add the command to the vector. This will be used later | |
2599 | to send the commands to the target. */ | |
2600 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); | |
2601 | } | |
d3ce09f5 SS |
2602 | } |
2603 | ||
2604 | bl->target_info.persist = 0; | |
2605 | /* Maybe flag this location as persistent. */ | |
2606 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2607 | bl->target_info.persist = 1; | |
2608 | } | |
2609 | ||
833b7ab5 YQ |
2610 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
2611 | of breakpoint according to ADDR except single-step breakpoint. | |
2612 | Get the kind of single-step breakpoint according to the current | |
2613 | registers state. */ | |
cd6c3b4f YQ |
2614 | |
2615 | static int | |
2616 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) | |
2617 | { | |
833b7ab5 YQ |
2618 | if (bl->owner->type == bp_single_step) |
2619 | { | |
2620 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); | |
2621 | struct regcache *regcache; | |
2622 | ||
2623 | regcache = get_thread_regcache (thr->ptid); | |
2624 | ||
2625 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, | |
2626 | regcache, addr); | |
2627 | } | |
2628 | else | |
2629 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); | |
cd6c3b4f YQ |
2630 | } |
2631 | ||
35df4500 TJB |
2632 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2633 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2634 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2635 | Returns 0 for success, 1 if the bp_location type is not supported or |
2636 | -1 for failure. | |
879bfdc2 | 2637 | |
4a64f543 MS |
2638 | NOTE drow/2003-09-09: This routine could be broken down to an |
2639 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2640 | static int |
35df4500 | 2641 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2642 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2643 | int *disabled_breaks, |
dd61ec5c MW |
2644 | int *hw_breakpoint_error, |
2645 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2646 | { |
0000e5cc PA |
2647 | enum errors bp_err = GDB_NO_ERROR; |
2648 | const char *bp_err_message = NULL; | |
879bfdc2 | 2649 | |
b775012e | 2650 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2651 | return 0; |
2652 | ||
35c63cd8 JB |
2653 | /* Note we don't initialize bl->target_info, as that wipes out |
2654 | the breakpoint location's shadow_contents if the breakpoint | |
2655 | is still inserted at that location. This in turn breaks | |
2656 | target_read_memory which depends on these buffers when | |
2657 | a memory read is requested at the breakpoint location: | |
2658 | Once the target_info has been wiped, we fail to see that | |
2659 | we have a breakpoint inserted at that address and thus | |
2660 | read the breakpoint instead of returning the data saved in | |
2661 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2662 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2663 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2664 | bl->target_info.length = bl->length; |
8181d85f | 2665 | |
b775012e LM |
2666 | /* When working with target-side conditions, we must pass all the conditions |
2667 | for the same breakpoint address down to the target since GDB will not | |
2668 | insert those locations. With a list of breakpoint conditions, the target | |
2669 | can decide when to stop and notify GDB. */ | |
2670 | ||
2671 | if (is_breakpoint (bl->owner)) | |
2672 | { | |
2673 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2674 | build_target_command_list (bl); |
2675 | /* Reset the modification marker. */ | |
b775012e LM |
2676 | bl->needs_update = 0; |
2677 | } | |
2678 | ||
35df4500 TJB |
2679 | if (bl->loc_type == bp_loc_software_breakpoint |
2680 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2681 | { |
35df4500 | 2682 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2683 | { |
2684 | /* If the explicitly specified breakpoint type | |
2685 | is not hardware breakpoint, check the memory map to see | |
2686 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2687 | |
765dc015 VP |
2688 | Two important cases are: |
2689 | - location type is not hardware breakpoint, memory | |
2690 | is readonly. We change the type of the location to | |
2691 | hardware breakpoint. | |
4a64f543 MS |
2692 | - location type is hardware breakpoint, memory is |
2693 | read-write. This means we've previously made the | |
2694 | location hardware one, but then the memory map changed, | |
2695 | so we undo. | |
765dc015 | 2696 | |
4a64f543 MS |
2697 | When breakpoints are removed, remove_breakpoints will use |
2698 | location types we've just set here, the only possible | |
2699 | problem is that memory map has changed during running | |
2700 | program, but it's not going to work anyway with current | |
2701 | gdb. */ | |
765dc015 | 2702 | struct mem_region *mr |
0d5ed153 | 2703 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2704 | |
2705 | if (mr) | |
2706 | { | |
2707 | if (automatic_hardware_breakpoints) | |
2708 | { | |
765dc015 VP |
2709 | enum bp_loc_type new_type; |
2710 | ||
2711 | if (mr->attrib.mode != MEM_RW) | |
2712 | new_type = bp_loc_hardware_breakpoint; | |
2713 | else | |
2714 | new_type = bp_loc_software_breakpoint; | |
2715 | ||
35df4500 | 2716 | if (new_type != bl->loc_type) |
765dc015 VP |
2717 | { |
2718 | static int said = 0; | |
cc59ec59 | 2719 | |
35df4500 | 2720 | bl->loc_type = new_type; |
765dc015 VP |
2721 | if (!said) |
2722 | { | |
3e43a32a MS |
2723 | fprintf_filtered (gdb_stdout, |
2724 | _("Note: automatically using " | |
2725 | "hardware breakpoints for " | |
2726 | "read-only addresses.\n")); | |
765dc015 VP |
2727 | said = 1; |
2728 | } | |
2729 | } | |
2730 | } | |
35df4500 | 2731 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2732 | && mr->attrib.mode != MEM_RW) |
2733 | { | |
2734 | fprintf_unfiltered (tmp_error_stream, | |
2735 | _("Cannot insert breakpoint %d.\n" | |
2736 | "Cannot set software breakpoint " | |
2737 | "at read-only address %s\n"), | |
2738 | bl->owner->number, | |
2739 | paddress (bl->gdbarch, bl->address)); | |
2740 | return 1; | |
2741 | } | |
765dc015 VP |
2742 | } |
2743 | } | |
2744 | ||
879bfdc2 DJ |
2745 | /* First check to see if we have to handle an overlay. */ |
2746 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2747 | || bl->section == NULL |
2748 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2749 | { |
2750 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2751 | TRY |
dd61ec5c | 2752 | { |
0000e5cc PA |
2753 | int val; |
2754 | ||
dd61ec5c | 2755 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2756 | if (val) |
2757 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2758 | } |
492d29ea | 2759 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2760 | { |
0000e5cc PA |
2761 | bp_err = e.error; |
2762 | bp_err_message = e.message; | |
dd61ec5c | 2763 | } |
492d29ea | 2764 | END_CATCH |
879bfdc2 DJ |
2765 | } |
2766 | else | |
2767 | { | |
4a64f543 | 2768 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2769 | Shall we set a breakpoint at the LMA? */ |
2770 | if (!overlay_events_enabled) | |
2771 | { | |
2772 | /* Yes -- overlay event support is not active, | |
2773 | so we must try to set a breakpoint at the LMA. | |
2774 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2775 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2776 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2777 | bl->owner->number); |
879bfdc2 DJ |
2778 | else |
2779 | { | |
35df4500 TJB |
2780 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2781 | bl->section); | |
879bfdc2 | 2782 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2783 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2784 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2785 | |
2786 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2787 | TRY |
0000e5cc PA |
2788 | { |
2789 | int val; | |
2790 | ||
579c6ad9 | 2791 | bl->overlay_target_info.kind |
cd6c3b4f YQ |
2792 | = breakpoint_kind (bl, &addr); |
2793 | bl->overlay_target_info.placed_address = addr; | |
0000e5cc PA |
2794 | val = target_insert_breakpoint (bl->gdbarch, |
2795 | &bl->overlay_target_info); | |
2796 | if (val) | |
2797 | bp_err = GENERIC_ERROR; | |
2798 | } | |
492d29ea | 2799 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2800 | { |
2801 | bp_err = e.error; | |
2802 | bp_err_message = e.message; | |
2803 | } | |
492d29ea | 2804 | END_CATCH |
0000e5cc PA |
2805 | |
2806 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2807 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2808 | "Overlay breakpoint %d " |
2809 | "failed: in ROM?\n", | |
35df4500 | 2810 | bl->owner->number); |
879bfdc2 DJ |
2811 | } |
2812 | } | |
2813 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2814 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2815 | { |
2816 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2817 | TRY |
dd61ec5c | 2818 | { |
0000e5cc PA |
2819 | int val; |
2820 | ||
dd61ec5c | 2821 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2822 | if (val) |
2823 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2824 | } |
492d29ea | 2825 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2826 | { |
0000e5cc PA |
2827 | bp_err = e.error; |
2828 | bp_err_message = e.message; | |
dd61ec5c | 2829 | } |
492d29ea | 2830 | END_CATCH |
879bfdc2 DJ |
2831 | } |
2832 | else | |
2833 | { | |
2834 | /* No. This breakpoint will not be inserted. | |
2835 | No error, but do not mark the bp as 'inserted'. */ | |
2836 | return 0; | |
2837 | } | |
2838 | } | |
2839 | ||
0000e5cc | 2840 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2841 | { |
2842 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2843 | |
2844 | /* In some cases, we might not be able to insert a | |
2845 | breakpoint in a shared library that has already been | |
2846 | removed, but we have not yet processed the shlib unload | |
2847 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2848 | breakpoint insertion themselves can't tell why the |
2849 | breakpoint insertion failed (e.g., the remote target | |
2850 | doesn't define error codes), so we must treat generic | |
2851 | errors as memory errors. */ | |
0000e5cc | 2852 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2853 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2854 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2855 | || shared_objfile_contains_address_p (bl->pspace, |
2856 | bl->address))) | |
879bfdc2 | 2857 | { |
4a64f543 | 2858 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2859 | bl->shlib_disabled = 1; |
8d3788bd | 2860 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2861 | if (!*disabled_breaks) |
2862 | { | |
2863 | fprintf_unfiltered (tmp_error_stream, | |
2864 | "Cannot insert breakpoint %d.\n", | |
2865 | bl->owner->number); | |
2866 | fprintf_unfiltered (tmp_error_stream, | |
2867 | "Temporarily disabling shared " | |
2868 | "library breakpoints:\n"); | |
2869 | } | |
2870 | *disabled_breaks = 1; | |
879bfdc2 | 2871 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2872 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2873 | return 0; |
879bfdc2 DJ |
2874 | } |
2875 | else | |
879bfdc2 | 2876 | { |
35df4500 | 2877 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2878 | { |
0000e5cc PA |
2879 | *hw_breakpoint_error = 1; |
2880 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2881 | fprintf_unfiltered (tmp_error_stream, |
2882 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2883 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2884 | if (bp_err_message != NULL) | |
2885 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2886 | } |
2887 | else | |
2888 | { | |
0000e5cc PA |
2889 | if (bp_err_message == NULL) |
2890 | { | |
1ccbe998 | 2891 | std::string message |
0000e5cc PA |
2892 | = memory_error_message (TARGET_XFER_E_IO, |
2893 | bl->gdbarch, bl->address); | |
0000e5cc PA |
2894 | |
2895 | fprintf_unfiltered (tmp_error_stream, | |
2896 | "Cannot insert breakpoint %d.\n" | |
2897 | "%s\n", | |
1ccbe998 | 2898 | bl->owner->number, message.c_str ()); |
0000e5cc PA |
2899 | } |
2900 | else | |
2901 | { | |
2902 | fprintf_unfiltered (tmp_error_stream, | |
2903 | "Cannot insert breakpoint %d: %s\n", | |
2904 | bl->owner->number, | |
2905 | bp_err_message); | |
2906 | } | |
879bfdc2 | 2907 | } |
0000e5cc | 2908 | return 1; |
879bfdc2 DJ |
2909 | |
2910 | } | |
2911 | } | |
2912 | else | |
35df4500 | 2913 | bl->inserted = 1; |
879bfdc2 | 2914 | |
0000e5cc | 2915 | return 0; |
879bfdc2 DJ |
2916 | } |
2917 | ||
35df4500 | 2918 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2919 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2920 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2921 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2922 | { |
0000e5cc PA |
2923 | int val; |
2924 | ||
77b06cd7 TJB |
2925 | gdb_assert (bl->owner->ops != NULL |
2926 | && bl->owner->ops->insert_location != NULL); | |
2927 | ||
2928 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2929 | |
2930 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2931 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2932 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2933 | { |
2934 | struct bp_location *loc, **loc_temp; | |
2935 | ||
2936 | /* But don't try to insert it, if there's already another | |
2937 | hw_access location that would be considered a duplicate | |
2938 | of this one. */ | |
2939 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2940 | if (loc != bl |
85d721b8 | 2941 | && loc->watchpoint_type == hw_access |
35df4500 | 2942 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2943 | { |
35df4500 TJB |
2944 | bl->duplicate = 1; |
2945 | bl->inserted = 1; | |
2946 | bl->target_info = loc->target_info; | |
2947 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2948 | val = 0; |
2949 | break; | |
2950 | } | |
2951 | ||
2952 | if (val == 1) | |
2953 | { | |
77b06cd7 TJB |
2954 | bl->watchpoint_type = hw_access; |
2955 | val = bl->owner->ops->insert_location (bl); | |
2956 | ||
2957 | if (val) | |
2958 | /* Back to the original value. */ | |
2959 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2960 | } |
2961 | } | |
2962 | ||
35df4500 | 2963 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2964 | } |
2965 | ||
35df4500 | 2966 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2967 | { |
0000e5cc PA |
2968 | int val; |
2969 | ||
77b06cd7 TJB |
2970 | gdb_assert (bl->owner->ops != NULL |
2971 | && bl->owner->ops->insert_location != NULL); | |
2972 | ||
2973 | val = bl->owner->ops->insert_location (bl); | |
2974 | if (val) | |
2975 | { | |
2976 | bl->owner->enable_state = bp_disabled; | |
2977 | ||
2978 | if (val == 1) | |
2979 | warning (_("\ | |
2980 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2981 | of catchpoint."), bl->owner->number); | |
2982 | else | |
2983 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2984 | } | |
2985 | ||
2986 | bl->inserted = (val == 0); | |
1640b821 DJ |
2987 | |
2988 | /* We've already printed an error message if there was a problem | |
2989 | inserting this catchpoint, and we've disabled the catchpoint, | |
2990 | so just return success. */ | |
2991 | return 0; | |
879bfdc2 DJ |
2992 | } |
2993 | ||
2994 | return 0; | |
2995 | } | |
2996 | ||
6c95b8df PA |
2997 | /* This function is called when program space PSPACE is about to be |
2998 | deleted. It takes care of updating breakpoints to not reference | |
2999 | PSPACE anymore. */ | |
3000 | ||
3001 | void | |
3002 | breakpoint_program_space_exit (struct program_space *pspace) | |
3003 | { | |
3004 | struct breakpoint *b, *b_temp; | |
876fa593 | 3005 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
3006 | |
3007 | /* Remove any breakpoint that was set through this program space. */ | |
3008 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
3009 | { | |
3010 | if (b->pspace == pspace) | |
3011 | delete_breakpoint (b); | |
3012 | } | |
3013 | ||
3014 | /* Breakpoints set through other program spaces could have locations | |
3015 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 3016 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
3017 | { |
3018 | struct bp_location *tmp; | |
3019 | ||
3020 | if (loc->pspace == pspace) | |
3021 | { | |
2bdf28a0 | 3022 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
3023 | if (loc->owner->loc == loc) |
3024 | loc->owner->loc = loc->next; | |
3025 | else | |
3026 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
3027 | if (tmp->next == loc) | |
3028 | { | |
3029 | tmp->next = loc->next; | |
3030 | break; | |
3031 | } | |
3032 | } | |
3033 | } | |
3034 | ||
3035 | /* Now update the global location list to permanently delete the | |
3036 | removed locations above. */ | |
44702360 | 3037 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3038 | } |
3039 | ||
74960c60 VP |
3040 | /* Make sure all breakpoints are inserted in inferior. |
3041 | Throws exception on any error. | |
3042 | A breakpoint that is already inserted won't be inserted | |
3043 | again, so calling this function twice is safe. */ | |
3044 | void | |
3045 | insert_breakpoints (void) | |
3046 | { | |
3047 | struct breakpoint *bpt; | |
3048 | ||
3049 | ALL_BREAKPOINTS (bpt) | |
3050 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3051 | { |
3052 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3053 | ||
3054 | update_watchpoint (w, 0 /* don't reparse. */); | |
3055 | } | |
74960c60 | 3056 | |
04086b45 PA |
3057 | /* Updating watchpoints creates new locations, so update the global |
3058 | location list. Explicitly tell ugll to insert locations and | |
3059 | ignore breakpoints_always_inserted_mode. */ | |
3060 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3061 | } |
3062 | ||
20388dd6 YQ |
3063 | /* Invoke CALLBACK for each of bp_location. */ |
3064 | ||
3065 | void | |
3066 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3067 | { | |
3068 | struct bp_location *loc, **loc_tmp; | |
3069 | ||
3070 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3071 | { | |
3072 | callback (loc, NULL); | |
3073 | } | |
3074 | } | |
3075 | ||
b775012e LM |
3076 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3077 | target. It is the case with deleting and disabling of breakpoints when using | |
3078 | always-inserted mode. */ | |
3079 | ||
3080 | static void | |
3081 | update_inserted_breakpoint_locations (void) | |
3082 | { | |
3083 | struct bp_location *bl, **blp_tmp; | |
3084 | int error_flag = 0; | |
3085 | int val = 0; | |
3086 | int disabled_breaks = 0; | |
3087 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3088 | int hw_bp_details_reported = 0; |
b775012e | 3089 | |
d7e74731 | 3090 | string_file tmp_error_stream; |
b775012e LM |
3091 | |
3092 | /* Explicitly mark the warning -- this will only be printed if | |
3093 | there was an error. */ | |
d7e74731 | 3094 | tmp_error_stream.puts ("Warning:\n"); |
b775012e | 3095 | |
5ed8105e | 3096 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
b775012e LM |
3097 | |
3098 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3099 | { | |
3100 | /* We only want to update software breakpoints and hardware | |
3101 | breakpoints. */ | |
3102 | if (!is_breakpoint (bl->owner)) | |
3103 | continue; | |
3104 | ||
3105 | /* We only want to update locations that are already inserted | |
3106 | and need updating. This is to avoid unwanted insertion during | |
3107 | deletion of breakpoints. */ | |
3108 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3109 | continue; | |
3110 | ||
3111 | switch_to_program_space_and_thread (bl->pspace); | |
3112 | ||
3113 | /* For targets that support global breakpoints, there's no need | |
3114 | to select an inferior to insert breakpoint to. In fact, even | |
3115 | if we aren't attached to any process yet, we should still | |
3116 | insert breakpoints. */ | |
f5656ead | 3117 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3118 | && ptid_equal (inferior_ptid, null_ptid)) |
3119 | continue; | |
3120 | ||
d7e74731 | 3121 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3122 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3123 | if (val) |
3124 | error_flag = val; | |
3125 | } | |
3126 | ||
3127 | if (error_flag) | |
3128 | { | |
3129 | target_terminal_ours_for_output (); | |
3130 | error_stream (tmp_error_stream); | |
3131 | } | |
b775012e LM |
3132 | } |
3133 | ||
c30eee59 | 3134 | /* Used when starting or continuing the program. */ |
c906108c | 3135 | |
74960c60 VP |
3136 | static void |
3137 | insert_breakpoint_locations (void) | |
c906108c | 3138 | { |
a5606eee | 3139 | struct breakpoint *bpt; |
35df4500 | 3140 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3141 | int error_flag = 0; |
c906108c | 3142 | int val = 0; |
3fbb6ffa | 3143 | int disabled_breaks = 0; |
81d0cc19 | 3144 | int hw_breakpoint_error = 0; |
dd61ec5c | 3145 | int hw_bp_error_explained_already = 0; |
c906108c | 3146 | |
d7e74731 PA |
3147 | string_file tmp_error_stream; |
3148 | ||
81d0cc19 GS |
3149 | /* Explicitly mark the warning -- this will only be printed if |
3150 | there was an error. */ | |
d7e74731 | 3151 | tmp_error_stream.puts ("Warning:\n"); |
6c95b8df | 3152 | |
5ed8105e | 3153 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 3154 | |
35df4500 | 3155 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3156 | { |
b775012e | 3157 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3158 | continue; |
3159 | ||
4a64f543 MS |
3160 | /* There is no point inserting thread-specific breakpoints if |
3161 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3162 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3163 | if (bl->owner->thread != -1 |
5d5658a1 | 3164 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3165 | continue; |
3166 | ||
35df4500 | 3167 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3168 | |
3169 | /* For targets that support global breakpoints, there's no need | |
3170 | to select an inferior to insert breakpoint to. In fact, even | |
3171 | if we aren't attached to any process yet, we should still | |
3172 | insert breakpoints. */ | |
f5656ead | 3173 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3174 | && ptid_equal (inferior_ptid, null_ptid)) |
3175 | continue; | |
3176 | ||
d7e74731 | 3177 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3178 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3179 | if (val) |
eacd795a | 3180 | error_flag = val; |
879bfdc2 | 3181 | } |
c906108c | 3182 | |
4a64f543 MS |
3183 | /* If we failed to insert all locations of a watchpoint, remove |
3184 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3185 | ALL_BREAKPOINTS (bpt) |
3186 | { | |
3187 | int some_failed = 0; | |
3188 | struct bp_location *loc; | |
3189 | ||
3190 | if (!is_hardware_watchpoint (bpt)) | |
3191 | continue; | |
3192 | ||
d6b74ac4 | 3193 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3194 | continue; |
74960c60 VP |
3195 | |
3196 | if (bpt->disposition == disp_del_at_next_stop) | |
3197 | continue; | |
a5606eee VP |
3198 | |
3199 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3200 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3201 | { |
3202 | some_failed = 1; | |
3203 | break; | |
3204 | } | |
3205 | if (some_failed) | |
3206 | { | |
3207 | for (loc = bpt->loc; loc; loc = loc->next) | |
3208 | if (loc->inserted) | |
834c0d03 | 3209 | remove_breakpoint (loc); |
a5606eee VP |
3210 | |
3211 | hw_breakpoint_error = 1; | |
d7e74731 PA |
3212 | tmp_error_stream.printf ("Could not insert " |
3213 | "hardware watchpoint %d.\n", | |
3214 | bpt->number); | |
eacd795a | 3215 | error_flag = -1; |
a5606eee VP |
3216 | } |
3217 | } | |
3218 | ||
eacd795a | 3219 | if (error_flag) |
81d0cc19 GS |
3220 | { |
3221 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3222 | message about possibly exhausted resources. */ | |
dd61ec5c | 3223 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3224 | { |
d7e74731 | 3225 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
c6510018 | 3226 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
81d0cc19 | 3227 | } |
81d0cc19 GS |
3228 | target_terminal_ours_for_output (); |
3229 | error_stream (tmp_error_stream); | |
3230 | } | |
c906108c SS |
3231 | } |
3232 | ||
c30eee59 TJB |
3233 | /* Used when the program stops. |
3234 | Returns zero if successful, or non-zero if there was a problem | |
3235 | removing a breakpoint location. */ | |
3236 | ||
c906108c | 3237 | int |
fba45db2 | 3238 | remove_breakpoints (void) |
c906108c | 3239 | { |
35df4500 | 3240 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3241 | int val = 0; |
c906108c | 3242 | |
35df4500 | 3243 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3244 | { |
1e4d1764 | 3245 | if (bl->inserted && !is_tracepoint (bl->owner)) |
834c0d03 | 3246 | val |= remove_breakpoint (bl); |
c5aa993b | 3247 | } |
3a1bae8e | 3248 | return val; |
c906108c SS |
3249 | } |
3250 | ||
49fa26b0 PA |
3251 | /* When a thread exits, remove breakpoints that are related to |
3252 | that thread. */ | |
3253 | ||
3254 | static void | |
3255 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3256 | { | |
3257 | struct breakpoint *b, *b_tmp; | |
3258 | ||
3259 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3260 | { | |
5d5658a1 | 3261 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3262 | { |
3263 | b->disposition = disp_del_at_next_stop; | |
3264 | ||
3265 | printf_filtered (_("\ | |
43792cf0 PA |
3266 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3267 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3268 | |
3269 | /* Hide it from the user. */ | |
3270 | b->number = 0; | |
3271 | } | |
3272 | } | |
3273 | } | |
3274 | ||
6c95b8df PA |
3275 | /* Remove breakpoints of process PID. */ |
3276 | ||
3277 | int | |
3278 | remove_breakpoints_pid (int pid) | |
3279 | { | |
35df4500 | 3280 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3281 | int val; |
3282 | struct inferior *inf = find_inferior_pid (pid); | |
3283 | ||
35df4500 | 3284 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3285 | { |
35df4500 | 3286 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3287 | continue; |
3288 | ||
fc126975 | 3289 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3290 | { |
834c0d03 | 3291 | val = remove_breakpoint (bl); |
6c95b8df PA |
3292 | if (val != 0) |
3293 | return val; | |
3294 | } | |
3295 | } | |
3296 | return 0; | |
3297 | } | |
3298 | ||
c906108c | 3299 | int |
fba45db2 | 3300 | reattach_breakpoints (int pid) |
c906108c | 3301 | { |
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); | |
6c95b8df | 3313 | |
2989a365 | 3314 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 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 | 3328 | if (val != 0) |
2989a365 | 3329 | return val; |
c5aa993b JM |
3330 | } |
3331 | } | |
c906108c SS |
3332 | return 0; |
3333 | } | |
3334 | ||
e58b0e63 PA |
3335 | static int internal_breakpoint_number = -1; |
3336 | ||
84f4c1fe PM |
3337 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3338 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3339 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3340 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3341 | breakpoint_count and that value incremented. Internal breakpoints |
3342 | do not set the internal var bpnum. */ | |
3343 | static void | |
3344 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3345 | { | |
3346 | if (internal) | |
3347 | b->number = internal_breakpoint_number--; | |
3348 | else | |
3349 | { | |
3350 | set_breakpoint_count (breakpoint_count + 1); | |
3351 | b->number = breakpoint_count; | |
3352 | } | |
3353 | } | |
3354 | ||
e62c965a | 3355 | static struct breakpoint * |
a6d9a66e | 3356 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3357 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3358 | const struct breakpoint_ops *ops) |
e62c965a | 3359 | { |
51abb421 | 3360 | symtab_and_line sal; |
e62c965a PP |
3361 | sal.pc = address; |
3362 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3363 | sal.pspace = current_program_space; |
e62c965a | 3364 | |
51abb421 | 3365 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3366 | b->number = internal_breakpoint_number--; |
3367 | b->disposition = disp_donttouch; | |
3368 | ||
3369 | return b; | |
3370 | } | |
3371 | ||
17450429 PP |
3372 | static const char *const longjmp_names[] = |
3373 | { | |
3374 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3375 | }; | |
3376 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3377 | ||
3378 | /* Per-objfile data private to breakpoint.c. */ | |
3379 | struct breakpoint_objfile_data | |
3380 | { | |
3381 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3382 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3383 | |
3384 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3385 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3386 | |
28106bc2 SDJ |
3387 | /* True if we have looked for longjmp probes. */ |
3388 | int longjmp_searched; | |
3389 | ||
3390 | /* SystemTap probe points for longjmp (if any). */ | |
3391 | VEC (probe_p) *longjmp_probes; | |
3392 | ||
17450429 | 3393 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3394 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3395 | |
3396 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3397 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3398 | |
3399 | /* True if we have looked for exception probes. */ | |
3400 | int exception_searched; | |
3401 | ||
3402 | /* SystemTap probe points for unwinding (if any). */ | |
3403 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3404 | }; |
3405 | ||
3406 | static const struct objfile_data *breakpoint_objfile_key; | |
3407 | ||
3408 | /* Minimal symbol not found sentinel. */ | |
3409 | static struct minimal_symbol msym_not_found; | |
3410 | ||
3411 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3412 | ||
3413 | static int | |
3414 | msym_not_found_p (const struct minimal_symbol *msym) | |
3415 | { | |
3416 | return msym == &msym_not_found; | |
3417 | } | |
3418 | ||
3419 | /* Return per-objfile data needed by breakpoint.c. | |
3420 | Allocate the data if necessary. */ | |
3421 | ||
3422 | static struct breakpoint_objfile_data * | |
3423 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3424 | { | |
3425 | struct breakpoint_objfile_data *bp_objfile_data; | |
3426 | ||
9a3c8263 SM |
3427 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3428 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3429 | if (bp_objfile_data == NULL) |
3430 | { | |
8d749320 SM |
3431 | bp_objfile_data = |
3432 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3433 | |
3434 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3435 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3436 | } | |
3437 | return bp_objfile_data; | |
3438 | } | |
3439 | ||
28106bc2 SDJ |
3440 | static void |
3441 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3442 | { | |
9a3c8263 SM |
3443 | struct breakpoint_objfile_data *bp_objfile_data |
3444 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3445 | |
3446 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3447 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3448 | } | |
3449 | ||
e62c965a | 3450 | static void |
af02033e | 3451 | create_overlay_event_breakpoint (void) |
e62c965a | 3452 | { |
69de3c6a | 3453 | struct objfile *objfile; |
af02033e | 3454 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3455 | |
69de3c6a PP |
3456 | ALL_OBJFILES (objfile) |
3457 | { | |
3458 | struct breakpoint *b; | |
17450429 PP |
3459 | struct breakpoint_objfile_data *bp_objfile_data; |
3460 | CORE_ADDR addr; | |
67994074 | 3461 | struct explicit_location explicit_loc; |
69de3c6a | 3462 | |
17450429 PP |
3463 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3464 | ||
3b7344d5 | 3465 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3466 | continue; |
3467 | ||
3b7344d5 | 3468 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3469 | { |
3b7344d5 | 3470 | struct bound_minimal_symbol m; |
17450429 PP |
3471 | |
3472 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3473 | if (m.minsym == NULL) |
17450429 PP |
3474 | { |
3475 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3476 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3477 | continue; |
3478 | } | |
3479 | bp_objfile_data->overlay_msym = m; | |
3480 | } | |
e62c965a | 3481 | |
77e371c0 | 3482 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3483 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3484 | bp_overlay_event, |
3485 | &internal_breakpoint_ops); | |
67994074 KS |
3486 | initialize_explicit_location (&explicit_loc); |
3487 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3488 | b->location = new_explicit_location (&explicit_loc); |
e62c965a | 3489 | |
69de3c6a PP |
3490 | if (overlay_debugging == ovly_auto) |
3491 | { | |
3492 | b->enable_state = bp_enabled; | |
3493 | overlay_events_enabled = 1; | |
3494 | } | |
3495 | else | |
3496 | { | |
3497 | b->enable_state = bp_disabled; | |
3498 | overlay_events_enabled = 0; | |
3499 | } | |
e62c965a | 3500 | } |
e62c965a PP |
3501 | } |
3502 | ||
0fd8e87f | 3503 | static void |
af02033e | 3504 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3505 | { |
6c95b8df | 3506 | struct program_space *pspace; |
6c95b8df | 3507 | |
5ed8105e | 3508 | scoped_restore_current_program_space restore_pspace; |
0fd8e87f | 3509 | |
6c95b8df | 3510 | ALL_PSPACES (pspace) |
af02033e PP |
3511 | { |
3512 | struct objfile *objfile; | |
3513 | ||
3514 | set_current_program_space (pspace); | |
3515 | ||
3516 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3517 | { |
af02033e PP |
3518 | int i; |
3519 | struct gdbarch *gdbarch; | |
17450429 | 3520 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3521 | |
af02033e | 3522 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3523 | |
17450429 PP |
3524 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3525 | ||
28106bc2 SDJ |
3526 | if (!bp_objfile_data->longjmp_searched) |
3527 | { | |
25f9533e SDJ |
3528 | VEC (probe_p) *ret; |
3529 | ||
3530 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3531 | if (ret != NULL) | |
3532 | { | |
3533 | /* We are only interested in checking one element. */ | |
3534 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3535 | ||
3536 | if (!can_evaluate_probe_arguments (p)) | |
3537 | { | |
3538 | /* We cannot use the probe interface here, because it does | |
3539 | not know how to evaluate arguments. */ | |
3540 | VEC_free (probe_p, ret); | |
3541 | ret = NULL; | |
3542 | } | |
3543 | } | |
3544 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3545 | bp_objfile_data->longjmp_searched = 1; |
3546 | } | |
3547 | ||
3548 | if (bp_objfile_data->longjmp_probes != NULL) | |
3549 | { | |
3550 | int i; | |
3551 | struct probe *probe; | |
3552 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3553 | ||
3554 | for (i = 0; | |
3555 | VEC_iterate (probe_p, | |
3556 | bp_objfile_data->longjmp_probes, | |
3557 | i, probe); | |
3558 | ++i) | |
3559 | { | |
3560 | struct breakpoint *b; | |
3561 | ||
729662a5 TT |
3562 | b = create_internal_breakpoint (gdbarch, |
3563 | get_probe_address (probe, | |
3564 | objfile), | |
28106bc2 SDJ |
3565 | bp_longjmp_master, |
3566 | &internal_breakpoint_ops); | |
d28cd78a | 3567 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
28106bc2 SDJ |
3568 | b->enable_state = bp_disabled; |
3569 | } | |
3570 | ||
3571 | continue; | |
3572 | } | |
3573 | ||
0569175e TSD |
3574 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3575 | continue; | |
3576 | ||
17450429 | 3577 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3578 | { |
3579 | struct breakpoint *b; | |
af02033e | 3580 | const char *func_name; |
17450429 | 3581 | CORE_ADDR addr; |
67994074 | 3582 | struct explicit_location explicit_loc; |
6c95b8df | 3583 | |
3b7344d5 | 3584 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3585 | continue; |
0fd8e87f | 3586 | |
17450429 | 3587 | func_name = longjmp_names[i]; |
3b7344d5 | 3588 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3589 | { |
3b7344d5 | 3590 | struct bound_minimal_symbol m; |
17450429 PP |
3591 | |
3592 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3593 | if (m.minsym == NULL) |
17450429 PP |
3594 | { |
3595 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3596 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3597 | continue; |
3598 | } | |
3599 | bp_objfile_data->longjmp_msym[i] = m; | |
3600 | } | |
3601 | ||
77e371c0 | 3602 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3603 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3604 | &internal_breakpoint_ops); | |
67994074 KS |
3605 | initialize_explicit_location (&explicit_loc); |
3606 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3607 | b->location = new_explicit_location (&explicit_loc); |
af02033e PP |
3608 | b->enable_state = bp_disabled; |
3609 | } | |
0fd8e87f | 3610 | } |
af02033e | 3611 | } |
0fd8e87f UW |
3612 | } |
3613 | ||
af02033e | 3614 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3615 | static void |
af02033e | 3616 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3617 | { |
3618 | struct program_space *pspace; | |
af02033e | 3619 | const char *const func_name = "std::terminate()"; |
aa7d318d | 3620 | |
5ed8105e | 3621 | scoped_restore_current_program_space restore_pspace; |
aa7d318d TT |
3622 | |
3623 | ALL_PSPACES (pspace) | |
17450429 PP |
3624 | { |
3625 | struct objfile *objfile; | |
3626 | CORE_ADDR addr; | |
3627 | ||
3628 | set_current_program_space (pspace); | |
3629 | ||
aa7d318d TT |
3630 | ALL_OBJFILES (objfile) |
3631 | { | |
3632 | struct breakpoint *b; | |
17450429 | 3633 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3634 | struct explicit_location explicit_loc; |
aa7d318d | 3635 | |
17450429 | 3636 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3637 | |
3b7344d5 | 3638 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3639 | continue; |
3640 | ||
3b7344d5 | 3641 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3642 | { |
3b7344d5 | 3643 | struct bound_minimal_symbol m; |
17450429 PP |
3644 | |
3645 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3646 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3647 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3648 | { |
3649 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3650 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3651 | continue; |
3652 | } | |
3653 | bp_objfile_data->terminate_msym = m; | |
3654 | } | |
aa7d318d | 3655 | |
77e371c0 | 3656 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3657 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3658 | bp_std_terminate_master, |
3659 | &internal_breakpoint_ops); | |
67994074 KS |
3660 | initialize_explicit_location (&explicit_loc); |
3661 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3662 | b->location = new_explicit_location (&explicit_loc); |
aa7d318d TT |
3663 | b->enable_state = bp_disabled; |
3664 | } | |
17450429 | 3665 | } |
aa7d318d TT |
3666 | } |
3667 | ||
186c406b TT |
3668 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3669 | ||
70221824 | 3670 | static void |
186c406b TT |
3671 | create_exception_master_breakpoint (void) |
3672 | { | |
3673 | struct objfile *objfile; | |
17450429 | 3674 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3675 | |
3676 | ALL_OBJFILES (objfile) | |
3677 | { | |
17450429 PP |
3678 | struct breakpoint *b; |
3679 | struct gdbarch *gdbarch; | |
3680 | struct breakpoint_objfile_data *bp_objfile_data; | |
3681 | CORE_ADDR addr; | |
67994074 | 3682 | struct explicit_location explicit_loc; |
17450429 PP |
3683 | |
3684 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3685 | ||
28106bc2 SDJ |
3686 | /* We prefer the SystemTap probe point if it exists. */ |
3687 | if (!bp_objfile_data->exception_searched) | |
3688 | { | |
25f9533e SDJ |
3689 | VEC (probe_p) *ret; |
3690 | ||
3691 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3692 | ||
3693 | if (ret != NULL) | |
3694 | { | |
3695 | /* We are only interested in checking one element. */ | |
3696 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3697 | ||
3698 | if (!can_evaluate_probe_arguments (p)) | |
3699 | { | |
3700 | /* We cannot use the probe interface here, because it does | |
3701 | not know how to evaluate arguments. */ | |
3702 | VEC_free (probe_p, ret); | |
3703 | ret = NULL; | |
3704 | } | |
3705 | } | |
3706 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3707 | bp_objfile_data->exception_searched = 1; |
3708 | } | |
3709 | ||
3710 | if (bp_objfile_data->exception_probes != NULL) | |
3711 | { | |
3712 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3713 | int i; | |
3714 | struct probe *probe; | |
3715 | ||
3716 | for (i = 0; | |
3717 | VEC_iterate (probe_p, | |
3718 | bp_objfile_data->exception_probes, | |
3719 | i, probe); | |
3720 | ++i) | |
3721 | { | |
3722 | struct breakpoint *b; | |
3723 | ||
729662a5 TT |
3724 | b = create_internal_breakpoint (gdbarch, |
3725 | get_probe_address (probe, | |
3726 | objfile), | |
28106bc2 SDJ |
3727 | bp_exception_master, |
3728 | &internal_breakpoint_ops); | |
d28cd78a | 3729 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
28106bc2 SDJ |
3730 | b->enable_state = bp_disabled; |
3731 | } | |
3732 | ||
3733 | continue; | |
3734 | } | |
3735 | ||
3736 | /* Otherwise, try the hook function. */ | |
3737 | ||
3b7344d5 | 3738 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3739 | continue; |
3740 | ||
3741 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3742 | |
3b7344d5 | 3743 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3744 | { |
3b7344d5 | 3745 | struct bound_minimal_symbol debug_hook; |
186c406b | 3746 | |
17450429 | 3747 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3748 | if (debug_hook.minsym == NULL) |
17450429 | 3749 | { |
3b7344d5 | 3750 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3751 | continue; |
3752 | } | |
3753 | ||
3754 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3755 | } |
17450429 | 3756 | |
77e371c0 | 3757 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3758 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3759 | ¤t_target); | |
06edf0c0 PA |
3760 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3761 | &internal_breakpoint_ops); | |
67994074 KS |
3762 | initialize_explicit_location (&explicit_loc); |
3763 | explicit_loc.function_name = ASTRDUP (func_name); | |
d28cd78a | 3764 | b->location = new_explicit_location (&explicit_loc); |
17450429 | 3765 | b->enable_state = bp_disabled; |
186c406b | 3766 | } |
186c406b TT |
3767 | } |
3768 | ||
9ef9e6a6 KS |
3769 | /* Does B have a location spec? */ |
3770 | ||
3771 | static int | |
3772 | breakpoint_event_location_empty_p (const struct breakpoint *b) | |
3773 | { | |
d28cd78a | 3774 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
9ef9e6a6 KS |
3775 | } |
3776 | ||
c906108c | 3777 | void |
fba45db2 | 3778 | update_breakpoints_after_exec (void) |
c906108c | 3779 | { |
35df4500 | 3780 | struct breakpoint *b, *b_tmp; |
876fa593 | 3781 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3782 | |
25b22b0a PA |
3783 | /* We're about to delete breakpoints from GDB's lists. If the |
3784 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3785 | writing the breakpoints' "shadow contents" back into memory. The | |
3786 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3787 | do that. Instead, the target is responsible from marking | |
3788 | breakpoints out as soon as it detects an exec. We don't do that | |
3789 | here instead, because there may be other attempts to delete | |
3790 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3791 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3792 | if (bploc->pspace == current_program_space) |
3793 | gdb_assert (!bploc->inserted); | |
c906108c | 3794 | |
35df4500 | 3795 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3796 | { |
6c95b8df PA |
3797 | if (b->pspace != current_program_space) |
3798 | continue; | |
3799 | ||
4a64f543 | 3800 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3801 | if (b->type == bp_shlib_event) |
3802 | { | |
3803 | delete_breakpoint (b); | |
3804 | continue; | |
3805 | } | |
c906108c | 3806 | |
4a64f543 | 3807 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3808 | if (b->type == bp_jit_event) |
3809 | { | |
3810 | delete_breakpoint (b); | |
3811 | continue; | |
3812 | } | |
3813 | ||
1900040c | 3814 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3815 | as must overlay event and longjmp master breakpoints. */ |
3816 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3817 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3818 | || b->type == bp_exception_master) | |
c4093a6a JM |
3819 | { |
3820 | delete_breakpoint (b); | |
3821 | continue; | |
3822 | } | |
3823 | ||
4a64f543 | 3824 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3825 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3826 | { |
3827 | delete_breakpoint (b); | |
3828 | continue; | |
3829 | } | |
3830 | ||
7c16b83e PA |
3831 | /* Just like single-step breakpoints. */ |
3832 | if (b->type == bp_single_step) | |
3833 | { | |
3834 | delete_breakpoint (b); | |
3835 | continue; | |
3836 | } | |
3837 | ||
611c83ae PA |
3838 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3839 | after an exec. */ | |
186c406b | 3840 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3841 | || b->type == bp_longjmp_call_dummy |
186c406b | 3842 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3843 | { |
3844 | delete_breakpoint (b); | |
3845 | continue; | |
3846 | } | |
3847 | ||
ce78b96d JB |
3848 | if (b->type == bp_catchpoint) |
3849 | { | |
3850 | /* For now, none of the bp_catchpoint breakpoints need to | |
3851 | do anything at this point. In the future, if some of | |
3852 | the catchpoints need to something, we will need to add | |
3853 | a new method, and call this method from here. */ | |
3854 | continue; | |
3855 | } | |
3856 | ||
c5aa993b JM |
3857 | /* bp_finish is a special case. The only way we ought to be able |
3858 | to see one of these when an exec() has happened, is if the user | |
3859 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3860 | carries them to the call-site of the current callee, by setting | |
3861 | a temporary bp there and resuming. But in this case, the finish | |
3862 | will carry them entirely through the vfork & exec. | |
3863 | ||
3864 | We don't want to allow a bp_finish to remain inserted now. But | |
3865 | we can't safely delete it, 'cause finish_command has a handle to | |
3866 | the bp on a bpstat, and will later want to delete it. There's a | |
3867 | chance (and I've seen it happen) that if we delete the bp_finish | |
3868 | here, that its storage will get reused by the time finish_command | |
3869 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3870 | We really must allow finish_command to delete a bp_finish. | |
3871 | ||
e5dd4106 | 3872 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3873 | it's safe to delete something others may have handles to?" |
3874 | problem, what we'll do here is just uninsert the bp_finish, and | |
3875 | let finish_command delete it. | |
3876 | ||
3877 | (We know the bp_finish is "doomed" in the sense that it's | |
3878 | momentary, and will be deleted as soon as finish_command sees | |
3879 | the inferior stopped. So it doesn't matter that the bp's | |
3880 | address is probably bogus in the new a.out, unlike e.g., the | |
3881 | solib breakpoints.) */ | |
c5aa993b | 3882 | |
c5aa993b JM |
3883 | if (b->type == bp_finish) |
3884 | { | |
3885 | continue; | |
3886 | } | |
3887 | ||
3888 | /* Without a symbolic address, we have little hope of the | |
3889 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3890 | a.out. */ |
9ef9e6a6 | 3891 | if (breakpoint_event_location_empty_p (b)) |
c5aa993b JM |
3892 | { |
3893 | delete_breakpoint (b); | |
3894 | continue; | |
3895 | } | |
c5aa993b | 3896 | } |
c906108c SS |
3897 | } |
3898 | ||
3899 | int | |
d80ee84f | 3900 | detach_breakpoints (ptid_t ptid) |
c906108c | 3901 | { |
35df4500 | 3902 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3903 | int val = 0; |
2989a365 | 3904 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
6c95b8df | 3905 | struct inferior *inf = current_inferior (); |
c5aa993b | 3906 | |
dfd4cc63 | 3907 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3908 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3909 | |
6c95b8df | 3910 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3911 | inferior_ptid = ptid; |
35df4500 | 3912 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3913 | { |
35df4500 | 3914 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3915 | continue; |
3916 | ||
bd9673a4 PW |
3917 | /* This function must physically remove breakpoints locations |
3918 | from the specified ptid, without modifying the breakpoint | |
3919 | package's state. Locations of type bp_loc_other are only | |
3920 | maintained at GDB side. So, there is no need to remove | |
3921 | these bp_loc_other locations. Moreover, removing these | |
3922 | would modify the breakpoint package's state. */ | |
3923 | if (bl->loc_type == bp_loc_other) | |
3924 | continue; | |
3925 | ||
35df4500 | 3926 | if (bl->inserted) |
b2b6a7da | 3927 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
c5aa993b | 3928 | } |
d03285ec | 3929 | |
3a1bae8e | 3930 | return val; |
c906108c SS |
3931 | } |
3932 | ||
35df4500 | 3933 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3934 | Note that this is used to detach breakpoints from a child fork. |
3935 | When we get here, the child isn't in the inferior list, and neither | |
3936 | do we have objects to represent its address space --- we should | |
35df4500 | 3937 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3938 | |
c906108c | 3939 | static int |
b2b6a7da | 3940 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
c906108c SS |
3941 | { |
3942 | int val; | |
c5aa993b | 3943 | |
35df4500 TJB |
3944 | /* BL is never in moribund_locations by our callers. */ |
3945 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3946 | |
74960c60 VP |
3947 | /* The type of none suggests that owner is actually deleted. |
3948 | This should not ever happen. */ | |
35df4500 | 3949 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3950 | |
35df4500 TJB |
3951 | if (bl->loc_type == bp_loc_software_breakpoint |
3952 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3953 | { |
c02f5703 MS |
3954 | /* "Normal" instruction breakpoint: either the standard |
3955 | trap-instruction bp (bp_breakpoint), or a | |
3956 | bp_hardware_breakpoint. */ | |
3957 | ||
3958 | /* First check to see if we have to handle an overlay. */ | |
3959 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3960 | || bl->section == NULL |
3961 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3962 | { |
3963 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3964 | |
3965 | /* If we're trying to uninsert a memory breakpoint that we | |
3966 | know is set in a dynamic object that is marked | |
3967 | shlib_disabled, then either the dynamic object was | |
3968 | removed with "remove-symbol-file" or with | |
3969 | "nosharedlibrary". In the former case, we don't know | |
3970 | whether another dynamic object might have loaded over the | |
3971 | breakpoint's address -- the user might well let us know | |
3972 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3973 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3974 | list of dynamically loaded objects). If we have the |
3975 | breakpoint's shadow memory, that is, this is a software | |
3976 | breakpoint managed by GDB, check whether the breakpoint | |
3977 | is still inserted in memory, to avoid overwriting wrong | |
3978 | code with stale saved shadow contents. Note that HW | |
3979 | breakpoints don't have shadow memory, as they're | |
3980 | implemented using a mechanism that is not dependent on | |
3981 | being able to modify the target's memory, and as such | |
3982 | they should always be removed. */ | |
3983 | if (bl->shlib_disabled | |
3984 | && bl->target_info.shadow_len != 0 | |
3985 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3986 | val = 0; | |
3987 | else | |
73971819 | 3988 | val = bl->owner->ops->remove_location (bl, reason); |
c02f5703 | 3989 | } |
c906108c SS |
3990 | else |
3991 | { | |
4a64f543 | 3992 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3993 | Did we set a breakpoint at the LMA? */ |
3994 | if (!overlay_events_enabled) | |
3995 | { | |
3996 | /* Yes -- overlay event support is not active, so we | |
3997 | should have set a breakpoint at the LMA. Remove it. | |
3998 | */ | |
c02f5703 MS |
3999 | /* Ignore any failures: if the LMA is in ROM, we will |
4000 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
4001 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
4002 | target_remove_hw_breakpoint (bl->gdbarch, | |
4003 | &bl->overlay_target_info); | |
c02f5703 | 4004 | else |
35df4500 | 4005 | target_remove_breakpoint (bl->gdbarch, |
73971819 PA |
4006 | &bl->overlay_target_info, |
4007 | reason); | |
c02f5703 MS |
4008 | } |
4009 | /* Did we set a breakpoint at the VMA? | |
4010 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4011 | if (bl->inserted) |
c906108c | 4012 | { |
c02f5703 MS |
4013 | /* Yes -- remove it. Previously we did not bother to |
4014 | remove the breakpoint if the section had been | |
4015 | unmapped, but let's not rely on that being safe. We | |
4016 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4017 | |
4018 | /* However, we should remove *software* breakpoints only | |
4019 | if the section is still mapped, or else we overwrite | |
4020 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4021 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4022 | || section_is_mapped (bl->section)) | |
73971819 | 4023 | val = bl->owner->ops->remove_location (bl, reason); |
aa67235e UW |
4024 | else |
4025 | val = 0; | |
c906108c | 4026 | } |
c02f5703 MS |
4027 | else |
4028 | { | |
4029 | /* No -- not inserted, so no need to remove. No error. */ | |
4030 | val = 0; | |
4031 | } | |
c906108c | 4032 | } |
879d1e6b | 4033 | |
08351840 PA |
4034 | /* In some cases, we might not be able to remove a breakpoint in |
4035 | a shared library that has already been removed, but we have | |
4036 | not yet processed the shlib unload event. Similarly for an | |
4037 | unloaded add-symbol-file object - the user might not yet have | |
4038 | had the chance to remove-symbol-file it. shlib_disabled will | |
4039 | be set if the library/object has already been removed, but | |
4040 | the breakpoint hasn't been uninserted yet, e.g., after | |
4041 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4042 | always-inserted mode. */ | |
076855f9 | 4043 | if (val |
08351840 PA |
4044 | && (bl->loc_type == bp_loc_software_breakpoint |
4045 | && (bl->shlib_disabled | |
4046 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4047 | || shared_objfile_contains_address_p (bl->pspace, |
4048 | bl->address)))) | |
879d1e6b UW |
4049 | val = 0; |
4050 | ||
c906108c SS |
4051 | if (val) |
4052 | return val; | |
b2b6a7da | 4053 | bl->inserted = (reason == DETACH_BREAKPOINT); |
c906108c | 4054 | } |
35df4500 | 4055 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4056 | { |
77b06cd7 TJB |
4057 | gdb_assert (bl->owner->ops != NULL |
4058 | && bl->owner->ops->remove_location != NULL); | |
4059 | ||
b2b6a7da | 4060 | bl->inserted = (reason == DETACH_BREAKPOINT); |
73971819 | 4061 | bl->owner->ops->remove_location (bl, reason); |
2e70b7b9 | 4062 | |
c906108c | 4063 | /* Failure to remove any of the hardware watchpoints comes here. */ |
b2b6a7da | 4064 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
8a3fe4f8 | 4065 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4066 | bl->owner->number); |
c906108c | 4067 | } |
35df4500 TJB |
4068 | else if (bl->owner->type == bp_catchpoint |
4069 | && breakpoint_enabled (bl->owner) | |
4070 | && !bl->duplicate) | |
ce78b96d | 4071 | { |
77b06cd7 TJB |
4072 | gdb_assert (bl->owner->ops != NULL |
4073 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4074 | |
73971819 | 4075 | val = bl->owner->ops->remove_location (bl, reason); |
ce78b96d JB |
4076 | if (val) |
4077 | return val; | |
77b06cd7 | 4078 | |
b2b6a7da | 4079 | bl->inserted = (reason == DETACH_BREAKPOINT); |
ce78b96d | 4080 | } |
c906108c SS |
4081 | |
4082 | return 0; | |
4083 | } | |
4084 | ||
6c95b8df | 4085 | static int |
834c0d03 | 4086 | remove_breakpoint (struct bp_location *bl) |
6c95b8df | 4087 | { |
35df4500 TJB |
4088 | /* BL is never in moribund_locations by our callers. */ |
4089 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4090 | |
6c95b8df PA |
4091 | /* The type of none suggests that owner is actually deleted. |
4092 | This should not ever happen. */ | |
35df4500 | 4093 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df | 4094 | |
5ed8105e | 4095 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 4096 | |
35df4500 | 4097 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4098 | |
5ed8105e | 4099 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
6c95b8df PA |
4100 | } |
4101 | ||
c906108c SS |
4102 | /* Clear the "inserted" flag in all breakpoints. */ |
4103 | ||
25b22b0a | 4104 | void |
fba45db2 | 4105 | mark_breakpoints_out (void) |
c906108c | 4106 | { |
35df4500 | 4107 | struct bp_location *bl, **blp_tmp; |
c906108c | 4108 | |
35df4500 | 4109 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4110 | if (bl->pspace == current_program_space) |
35df4500 | 4111 | bl->inserted = 0; |
c906108c SS |
4112 | } |
4113 | ||
53a5351d JM |
4114 | /* Clear the "inserted" flag in all breakpoints and delete any |
4115 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4116 | |
4117 | Plus other such housekeeping that has to be done for breakpoints | |
4118 | between runs. | |
4119 | ||
53a5351d JM |
4120 | Note: this function gets called at the end of a run (by |
4121 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4122 | init_wait_for_inferior). */ |
c906108c SS |
4123 | |
4124 | ||
4125 | ||
4126 | void | |
fba45db2 | 4127 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4128 | { |
35df4500 | 4129 | struct breakpoint *b, *b_tmp; |
870f88f7 | 4130 | struct bp_location *bl; |
1c5cfe86 | 4131 | int ix; |
6c95b8df | 4132 | struct program_space *pspace = current_program_space; |
c906108c | 4133 | |
50c71eaf PA |
4134 | /* If breakpoint locations are shared across processes, then there's |
4135 | nothing to do. */ | |
f5656ead | 4136 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4137 | return; |
4138 | ||
1a853c52 | 4139 | mark_breakpoints_out (); |
075f6582 | 4140 | |
35df4500 | 4141 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4142 | { |
6c95b8df PA |
4143 | if (b->loc && b->loc->pspace != pspace) |
4144 | continue; | |
4145 | ||
c5aa993b JM |
4146 | switch (b->type) |
4147 | { | |
4148 | case bp_call_dummy: | |
e2e4d78b | 4149 | case bp_longjmp_call_dummy: |
c906108c | 4150 | |
c5aa993b | 4151 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4152 | cause problems when the inferior is rerun, so we better get |
4153 | rid of it. */ | |
4154 | ||
4155 | case bp_watchpoint_scope: | |
4156 | ||
4157 | /* Also get rid of scope breakpoints. */ | |
4158 | ||
4159 | case bp_shlib_event: | |
4160 | ||
4161 | /* Also remove solib event breakpoints. Their addresses may | |
4162 | have changed since the last time we ran the program. | |
4163 | Actually we may now be debugging against different target; | |
4164 | and so the solib backend that installed this breakpoint may | |
4165 | not be used in by the target. E.g., | |
4166 | ||
4167 | (gdb) file prog-linux | |
4168 | (gdb) run # native linux target | |
4169 | ... | |
4170 | (gdb) kill | |
4171 | (gdb) file prog-win.exe | |
4172 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4173 | */ | |
c906108c | 4174 | |
f59f708a PA |
4175 | case bp_step_resume: |
4176 | ||
4177 | /* Also remove step-resume breakpoints. */ | |
4178 | ||
7c16b83e PA |
4179 | case bp_single_step: |
4180 | ||
4181 | /* Also remove single-step breakpoints. */ | |
4182 | ||
c5aa993b JM |
4183 | delete_breakpoint (b); |
4184 | break; | |
c906108c | 4185 | |
c5aa993b JM |
4186 | case bp_watchpoint: |
4187 | case bp_hardware_watchpoint: | |
4188 | case bp_read_watchpoint: | |
4189 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4190 | { |
4191 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4192 | |
3a5c3e22 PA |
4193 | /* Likewise for watchpoints on local expressions. */ |
4194 | if (w->exp_valid_block != NULL) | |
4195 | delete_breakpoint (b); | |
63000888 | 4196 | else |
3a5c3e22 | 4197 | { |
63000888 PA |
4198 | /* Get rid of existing locations, which are no longer |
4199 | valid. New ones will be created in | |
4200 | update_watchpoint, when the inferior is restarted. | |
4201 | The next update_global_location_list call will | |
4202 | garbage collect them. */ | |
4203 | b->loc = NULL; | |
4204 | ||
4205 | if (context == inf_starting) | |
4206 | { | |
4207 | /* Reset val field to force reread of starting value in | |
4208 | insert_breakpoints. */ | |
4209 | if (w->val) | |
4210 | value_free (w->val); | |
4211 | w->val = NULL; | |
4212 | w->val_valid = 0; | |
4213 | } | |
4214 | } | |
3a5c3e22 | 4215 | } |
c5aa993b JM |
4216 | break; |
4217 | default: | |
c5aa993b JM |
4218 | break; |
4219 | } | |
4220 | } | |
1c5cfe86 PA |
4221 | |
4222 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4223 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4224 | decref_bp_location (&bl); | |
1c5cfe86 | 4225 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4226 | } |
4227 | ||
6c95b8df PA |
4228 | /* These functions concern about actual breakpoints inserted in the |
4229 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4230 | we need to hop over the bkpt --- so we check for address space | |
4231 | match, not program space. */ | |
4232 | ||
c2c6d25f JM |
4233 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4234 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4235 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4236 | permanent breakpoint. | |
4237 | - When continuing from a location with an ordinary breakpoint, we | |
4238 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4239 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4240 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4241 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4242 | |
c2c6d25f | 4243 | enum breakpoint_here |
6c95b8df | 4244 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4245 | { |
35df4500 | 4246 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4247 | int any_breakpoint_here = 0; |
c906108c | 4248 | |
35df4500 | 4249 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4250 | { |
35df4500 TJB |
4251 | if (bl->loc_type != bp_loc_software_breakpoint |
4252 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4253 | continue; |
4254 | ||
f1310107 | 4255 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4256 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4257 | || bl->permanent) |
f1310107 | 4258 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4259 | { |
4260 | if (overlay_debugging | |
35df4500 TJB |
4261 | && section_is_overlay (bl->section) |
4262 | && !section_is_mapped (bl->section)) | |
075f6582 | 4263 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4264 | else if (bl->permanent) |
075f6582 DJ |
4265 | return permanent_breakpoint_here; |
4266 | else | |
4267 | any_breakpoint_here = 1; | |
4268 | } | |
4269 | } | |
c906108c | 4270 | |
f486487f | 4271 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4272 | } |
4273 | ||
d35ae833 PA |
4274 | /* See breakpoint.h. */ |
4275 | ||
4276 | int | |
4277 | breakpoint_in_range_p (struct address_space *aspace, | |
4278 | CORE_ADDR addr, ULONGEST len) | |
4279 | { | |
4280 | struct bp_location *bl, **blp_tmp; | |
4281 | ||
4282 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4283 | { | |
4284 | if (bl->loc_type != bp_loc_software_breakpoint | |
4285 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4286 | continue; | |
4287 | ||
4288 | if ((breakpoint_enabled (bl->owner) | |
4289 | || bl->permanent) | |
4290 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4291 | addr, len)) | |
4292 | { | |
4293 | if (overlay_debugging | |
4294 | && section_is_overlay (bl->section) | |
4295 | && !section_is_mapped (bl->section)) | |
4296 | { | |
4297 | /* Unmapped overlay -- can't be a match. */ | |
4298 | continue; | |
4299 | } | |
4300 | ||
4301 | return 1; | |
4302 | } | |
4303 | } | |
4304 | ||
4305 | return 0; | |
4306 | } | |
4307 | ||
1c5cfe86 PA |
4308 | /* Return true if there's a moribund breakpoint at PC. */ |
4309 | ||
4310 | int | |
6c95b8df | 4311 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4312 | { |
4313 | struct bp_location *loc; | |
4314 | int ix; | |
4315 | ||
4316 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4317 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4318 | return 1; |
4319 | ||
4320 | return 0; | |
4321 | } | |
c2c6d25f | 4322 | |
f7ce857f PA |
4323 | /* Returns non-zero iff BL is inserted at PC, in address space |
4324 | ASPACE. */ | |
4325 | ||
4326 | static int | |
4327 | bp_location_inserted_here_p (struct bp_location *bl, | |
4328 | struct address_space *aspace, CORE_ADDR pc) | |
4329 | { | |
4330 | if (bl->inserted | |
4331 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4332 | aspace, pc)) | |
4333 | { | |
4334 | if (overlay_debugging | |
4335 | && section_is_overlay (bl->section) | |
4336 | && !section_is_mapped (bl->section)) | |
4337 | return 0; /* unmapped overlay -- can't be a match */ | |
4338 | else | |
4339 | return 1; | |
4340 | } | |
4341 | return 0; | |
4342 | } | |
4343 | ||
a1fd2fa5 | 4344 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4345 | |
4346 | int | |
a1fd2fa5 | 4347 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4348 | { |
f7ce857f | 4349 | struct bp_location **blp, **blp_tmp = NULL; |
c906108c | 4350 | |
f7ce857f | 4351 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4352 | { |
f7ce857f PA |
4353 | struct bp_location *bl = *blp; |
4354 | ||
35df4500 TJB |
4355 | if (bl->loc_type != bp_loc_software_breakpoint |
4356 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4357 | continue; |
4358 | ||
f7ce857f PA |
4359 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4360 | return 1; | |
c5aa993b | 4361 | } |
c36b740a VP |
4362 | return 0; |
4363 | } | |
4364 | ||
a1fd2fa5 PA |
4365 | /* This function returns non-zero iff there is a software breakpoint |
4366 | inserted at PC. */ | |
c36b740a VP |
4367 | |
4368 | int | |
a1fd2fa5 PA |
4369 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4370 | CORE_ADDR pc) | |
4fa8626c | 4371 | { |
f7ce857f | 4372 | struct bp_location **blp, **blp_tmp = NULL; |
4fa8626c | 4373 | |
f7ce857f | 4374 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4375 | { |
f7ce857f PA |
4376 | struct bp_location *bl = *blp; |
4377 | ||
35df4500 | 4378 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4379 | continue; |
4380 | ||
f7ce857f PA |
4381 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4382 | return 1; | |
4fa8626c DJ |
4383 | } |
4384 | ||
4385 | return 0; | |
9c02b525 PA |
4386 | } |
4387 | ||
4388 | /* See breakpoint.h. */ | |
4389 | ||
4390 | int | |
4391 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4392 | CORE_ADDR pc) | |
4393 | { | |
4394 | struct bp_location **blp, **blp_tmp = NULL; | |
9c02b525 PA |
4395 | |
4396 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4397 | { | |
4398 | struct bp_location *bl = *blp; | |
4399 | ||
4400 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4401 | continue; | |
4402 | ||
4403 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4404 | return 1; | |
4405 | } | |
4406 | ||
4407 | return 0; | |
4fa8626c DJ |
4408 | } |
4409 | ||
9093389c PA |
4410 | int |
4411 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4412 | CORE_ADDR addr, ULONGEST len) | |
4413 | { | |
4414 | struct breakpoint *bpt; | |
4415 | ||
4416 | ALL_BREAKPOINTS (bpt) | |
4417 | { | |
4418 | struct bp_location *loc; | |
4419 | ||
4420 | if (bpt->type != bp_hardware_watchpoint | |
4421 | && bpt->type != bp_access_watchpoint) | |
4422 | continue; | |
4423 | ||
4424 | if (!breakpoint_enabled (bpt)) | |
4425 | continue; | |
4426 | ||
4427 | for (loc = bpt->loc; loc; loc = loc->next) | |
4428 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4429 | { | |
4430 | CORE_ADDR l, h; | |
4431 | ||
4432 | /* Check for intersection. */ | |
768adc05 PA |
4433 | l = std::max<CORE_ADDR> (loc->address, addr); |
4434 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); | |
9093389c PA |
4435 | if (l < h) |
4436 | return 1; | |
4437 | } | |
4438 | } | |
4439 | return 0; | |
4440 | } | |
c906108c | 4441 | \f |
c5aa993b | 4442 | |
c906108c SS |
4443 | /* bpstat stuff. External routines' interfaces are documented |
4444 | in breakpoint.h. */ | |
4445 | ||
4446 | int | |
c326b90e | 4447 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4448 | { |
533be4dd | 4449 | return (ep->type == bp_catchpoint); |
c906108c SS |
4450 | } |
4451 | ||
f431efe5 PA |
4452 | /* Frees any storage that is part of a bpstat. Does not walk the |
4453 | 'next' chain. */ | |
4454 | ||
4455 | static void | |
198757a8 VP |
4456 | bpstat_free (bpstat bs) |
4457 | { | |
4458 | if (bs->old_val != NULL) | |
4459 | value_free (bs->old_val); | |
9add0f1b | 4460 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4461 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4462 | xfree (bs); |
4463 | } | |
4464 | ||
c906108c SS |
4465 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4466 | Also free any storage that is part of a bpstat. */ | |
4467 | ||
4468 | void | |
fba45db2 | 4469 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4470 | { |
4471 | bpstat p; | |
4472 | bpstat q; | |
4473 | ||
4474 | if (bsp == 0) | |
4475 | return; | |
4476 | p = *bsp; | |
4477 | while (p != NULL) | |
4478 | { | |
4479 | q = p->next; | |
198757a8 | 4480 | bpstat_free (p); |
c906108c SS |
4481 | p = q; |
4482 | } | |
4483 | *bsp = NULL; | |
4484 | } | |
4485 | ||
4486 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4487 | is part of the bpstat is copied as well. */ | |
4488 | ||
4489 | bpstat | |
fba45db2 | 4490 | bpstat_copy (bpstat bs) |
c906108c SS |
4491 | { |
4492 | bpstat p = NULL; | |
4493 | bpstat tmp; | |
4494 | bpstat retval = NULL; | |
4495 | ||
4496 | if (bs == NULL) | |
4497 | return bs; | |
4498 | ||
4499 | for (; bs != NULL; bs = bs->next) | |
4500 | { | |
4501 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4502 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4503 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4504 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4505 | if (bs->old_val != NULL) |
3c3185ac JK |
4506 | { |
4507 | tmp->old_val = value_copy (bs->old_val); | |
4508 | release_value (tmp->old_val); | |
4509 | } | |
31cc81e9 | 4510 | |
c906108c SS |
4511 | if (p == NULL) |
4512 | /* This is the first thing in the chain. */ | |
4513 | retval = tmp; | |
4514 | else | |
4515 | p->next = tmp; | |
4516 | p = tmp; | |
4517 | } | |
4518 | p->next = NULL; | |
4519 | return retval; | |
4520 | } | |
4521 | ||
4a64f543 | 4522 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4523 | |
4524 | bpstat | |
fba45db2 | 4525 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4526 | { |
c5aa993b JM |
4527 | if (bsp == NULL) |
4528 | return NULL; | |
c906108c | 4529 | |
c5aa993b JM |
4530 | for (; bsp != NULL; bsp = bsp->next) |
4531 | { | |
f431efe5 | 4532 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4533 | return bsp; |
4534 | } | |
c906108c SS |
4535 | return NULL; |
4536 | } | |
4537 | ||
ab04a2af TT |
4538 | /* See breakpoint.h. */ |
4539 | ||
47591c29 | 4540 | int |
427cd150 | 4541 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4542 | { |
ab04a2af TT |
4543 | for (; bsp != NULL; bsp = bsp->next) |
4544 | { | |
427cd150 TT |
4545 | if (bsp->breakpoint_at == NULL) |
4546 | { | |
4547 | /* A moribund location can never explain a signal other than | |
4548 | GDB_SIGNAL_TRAP. */ | |
4549 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4550 | return 1; |
427cd150 TT |
4551 | } |
4552 | else | |
47591c29 PA |
4553 | { |
4554 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4555 | sig)) | |
4556 | return 1; | |
4557 | } | |
ab04a2af TT |
4558 | } |
4559 | ||
47591c29 | 4560 | return 0; |
ab04a2af TT |
4561 | } |
4562 | ||
4a64f543 MS |
4563 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4564 | stopped at. *BSP upon return is a bpstat which points to the | |
4565 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4566 | good for anything but further calls to bpstat_num). | |
4567 | ||
8671a17b PA |
4568 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4569 | Return -1 if stopped at a breakpoint that has been deleted since | |
4570 | we set it. | |
4571 | Return 1 otherwise. */ | |
c906108c SS |
4572 | |
4573 | int | |
8671a17b | 4574 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4575 | { |
4576 | struct breakpoint *b; | |
4577 | ||
4578 | if ((*bsp) == NULL) | |
4579 | return 0; /* No more breakpoint values */ | |
8671a17b | 4580 | |
4a64f543 MS |
4581 | /* We assume we'll never have several bpstats that correspond to a |
4582 | single breakpoint -- otherwise, this function might return the | |
4583 | same number more than once and this will look ugly. */ | |
f431efe5 | 4584 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4585 | *bsp = (*bsp)->next; |
4586 | if (b == NULL) | |
4587 | return -1; /* breakpoint that's been deleted since */ | |
4588 | ||
4589 | *num = b->number; /* We have its number */ | |
4590 | return 1; | |
c906108c SS |
4591 | } |
4592 | ||
e93ca019 | 4593 | /* See breakpoint.h. */ |
c906108c SS |
4594 | |
4595 | void | |
e93ca019 | 4596 | bpstat_clear_actions (void) |
c906108c | 4597 | { |
e93ca019 JK |
4598 | struct thread_info *tp; |
4599 | bpstat bs; | |
4600 | ||
4601 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4602 | return; | |
4603 | ||
4604 | tp = find_thread_ptid (inferior_ptid); | |
4605 | if (tp == NULL) | |
4606 | return; | |
4607 | ||
4608 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4609 | { |
9add0f1b | 4610 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4611 | |
c906108c SS |
4612 | if (bs->old_val != NULL) |
4613 | { | |
4614 | value_free (bs->old_val); | |
4615 | bs->old_val = NULL; | |
4616 | } | |
4617 | } | |
4618 | } | |
4619 | ||
f3b1572e PA |
4620 | /* Called when a command is about to proceed the inferior. */ |
4621 | ||
4622 | static void | |
4623 | breakpoint_about_to_proceed (void) | |
4624 | { | |
4625 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4626 | { | |
4627 | struct thread_info *tp = inferior_thread (); | |
4628 | ||
4629 | /* Allow inferior function calls in breakpoint commands to not | |
4630 | interrupt the command list. When the call finishes | |
4631 | successfully, the inferior will be standing at the same | |
4632 | breakpoint as if nothing happened. */ | |
16c381f0 | 4633 | if (tp->control.in_infcall) |
f3b1572e PA |
4634 | return; |
4635 | } | |
4636 | ||
4637 | breakpoint_proceeded = 1; | |
4638 | } | |
4639 | ||
4a64f543 MS |
4640 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4641 | command. */ | |
c906108c | 4642 | static void |
4efb68b1 | 4643 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4644 | { |
4645 | executing_breakpoint_commands = 0; | |
4646 | } | |
4647 | ||
abf85f46 JK |
4648 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4649 | or its equivalent. */ | |
4650 | ||
4651 | static int | |
4652 | command_line_is_silent (struct command_line *cmd) | |
4653 | { | |
4f45d445 | 4654 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4655 | } |
4656 | ||
4a64f543 MS |
4657 | /* Execute all the commands associated with all the breakpoints at |
4658 | this location. Any of these commands could cause the process to | |
4659 | proceed beyond this point, etc. We look out for such changes by | |
4660 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4661 | |
347bddb7 PA |
4662 | Returns true if a breakpoint command resumed the inferior. In that |
4663 | case, it is the caller's responsibility to recall it again with the | |
4664 | bpstat of the current thread. */ | |
4665 | ||
4666 | static int | |
4667 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4668 | { |
4669 | bpstat bs; | |
4670 | struct cleanup *old_chain; | |
347bddb7 | 4671 | int again = 0; |
c906108c SS |
4672 | |
4673 | /* Avoid endless recursion if a `source' command is contained | |
4674 | in bs->commands. */ | |
4675 | if (executing_breakpoint_commands) | |
347bddb7 | 4676 | return 0; |
c906108c SS |
4677 | |
4678 | executing_breakpoint_commands = 1; | |
4679 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4680 | ||
1ac32117 | 4681 | scoped_restore preventer = prevent_dont_repeat (); |
cf6c5ffb | 4682 | |
4a64f543 | 4683 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4684 | bs = *bsp; |
4685 | ||
4686 | breakpoint_proceeded = 0; | |
4687 | for (; bs != NULL; bs = bs->next) | |
4688 | { | |
9add0f1b | 4689 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4690 | struct command_line *cmd; |
4691 | struct cleanup *this_cmd_tree_chain; | |
4692 | ||
4693 | /* Take ownership of the BSP's command tree, if it has one. | |
4694 | ||
4695 | The command tree could legitimately contain commands like | |
4696 | 'step' and 'next', which call clear_proceed_status, which | |
4697 | frees stop_bpstat's command tree. To make sure this doesn't | |
4698 | free the tree we're executing out from under us, we need to | |
4699 | take ownership of the tree ourselves. Since a given bpstat's | |
4700 | commands are only executed once, we don't need to copy it; we | |
4701 | can clear the pointer in the bpstat, and make sure we free | |
4702 | the tree when we're done. */ | |
9add0f1b TT |
4703 | ccmd = bs->commands; |
4704 | bs->commands = NULL; | |
abf85f46 JK |
4705 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4706 | cmd = ccmd ? ccmd->commands : NULL; | |
4707 | if (command_line_is_silent (cmd)) | |
4708 | { | |
4709 | /* The action has been already done by bpstat_stop_status. */ | |
4710 | cmd = cmd->next; | |
4711 | } | |
6c50ab1c | 4712 | |
c906108c SS |
4713 | while (cmd != NULL) |
4714 | { | |
4715 | execute_control_command (cmd); | |
4716 | ||
4717 | if (breakpoint_proceeded) | |
4718 | break; | |
4719 | else | |
4720 | cmd = cmd->next; | |
4721 | } | |
6c50ab1c JB |
4722 | |
4723 | /* We can free this command tree now. */ | |
4724 | do_cleanups (this_cmd_tree_chain); | |
4725 | ||
c906108c | 4726 | if (breakpoint_proceeded) |
32c1e744 | 4727 | { |
cb814510 | 4728 | if (current_ui->async) |
347bddb7 PA |
4729 | /* If we are in async mode, then the target might be still |
4730 | running, not stopped at any breakpoint, so nothing for | |
4731 | us to do here -- just return to the event loop. */ | |
4732 | ; | |
32c1e744 VP |
4733 | else |
4734 | /* In sync mode, when execute_control_command returns | |
4735 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4736 | Breakpoint commands for that stop were not run, since |
4737 | execute_command does not run breakpoint commands -- | |
4738 | only command_line_handler does, but that one is not | |
4739 | involved in execution of breakpoint commands. So, we | |
4740 | can now execute breakpoint commands. It should be | |
4741 | noted that making execute_command do bpstat actions is | |
4742 | not an option -- in this case we'll have recursive | |
4743 | invocation of bpstat for each breakpoint with a | |
4744 | command, and can easily blow up GDB stack. Instead, we | |
4745 | return true, which will trigger the caller to recall us | |
4746 | with the new stop_bpstat. */ | |
4747 | again = 1; | |
4748 | break; | |
32c1e744 | 4749 | } |
c906108c | 4750 | } |
c2b8ed2c | 4751 | do_cleanups (old_chain); |
347bddb7 PA |
4752 | return again; |
4753 | } | |
4754 | ||
4755 | void | |
4756 | bpstat_do_actions (void) | |
4757 | { | |
353d1d73 JK |
4758 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4759 | ||
347bddb7 PA |
4760 | /* Do any commands attached to breakpoint we are stopped at. */ |
4761 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4762 | && target_has_execution | |
4763 | && !is_exited (inferior_ptid) | |
4764 | && !is_executing (inferior_ptid)) | |
4765 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4766 | and only return when it is stopped at the next breakpoint, we | |
4767 | keep doing breakpoint actions until it returns false to | |
4768 | indicate the inferior was not resumed. */ | |
16c381f0 | 4769 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4770 | break; |
353d1d73 JK |
4771 | |
4772 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4773 | } |
4774 | ||
fa4727a6 DJ |
4775 | /* Print out the (old or new) value associated with a watchpoint. */ |
4776 | ||
4777 | static void | |
4778 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4779 | { | |
4780 | if (val == NULL) | |
4781 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4782 | else | |
79a45b7d TT |
4783 | { |
4784 | struct value_print_options opts; | |
4785 | get_user_print_options (&opts); | |
4786 | value_print (val, stream, &opts); | |
4787 | } | |
fa4727a6 DJ |
4788 | } |
4789 | ||
f303dbd6 PA |
4790 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4791 | debugging multiple threads. */ | |
4792 | ||
4793 | void | |
4794 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4795 | { | |
112e8700 | 4796 | if (uiout->is_mi_like_p ()) |
f303dbd6 PA |
4797 | return; |
4798 | ||
112e8700 | 4799 | uiout->text ("\n"); |
f303dbd6 PA |
4800 | |
4801 | if (show_thread_that_caused_stop ()) | |
4802 | { | |
4803 | const char *name; | |
4804 | struct thread_info *thr = inferior_thread (); | |
4805 | ||
112e8700 SM |
4806 | uiout->text ("Thread "); |
4807 | uiout->field_fmt ("thread-id", "%s", print_thread_id (thr)); | |
f303dbd6 PA |
4808 | |
4809 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4810 | if (name != NULL) | |
4811 | { | |
112e8700 SM |
4812 | uiout->text (" \""); |
4813 | uiout->field_fmt ("name", "%s", name); | |
4814 | uiout->text ("\""); | |
f303dbd6 PA |
4815 | } |
4816 | ||
112e8700 | 4817 | uiout->text (" hit "); |
f303dbd6 PA |
4818 | } |
4819 | } | |
4820 | ||
e514a9d6 | 4821 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4822 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4823 | 'print_it' in the bpstat structure. Under some circumstances we |
4824 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4825 | normal_stop(). */ |
e514a9d6 JM |
4826 | |
4827 | static enum print_stop_action | |
4828 | print_bp_stop_message (bpstat bs) | |
4829 | { | |
4830 | switch (bs->print_it) | |
4831 | { | |
4832 | case print_it_noop: | |
4a64f543 | 4833 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4834 | return PRINT_UNKNOWN; |
4835 | break; | |
4836 | ||
4837 | case print_it_done: | |
4838 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4839 | relevant messages. */ |
e514a9d6 JM |
4840 | return PRINT_SRC_AND_LOC; |
4841 | break; | |
4842 | ||
4843 | case print_it_normal: | |
4f8d1dc6 | 4844 | { |
f431efe5 PA |
4845 | struct breakpoint *b = bs->breakpoint_at; |
4846 | ||
1a6a67de TJB |
4847 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4848 | which has since been deleted. */ | |
4849 | if (b == NULL) | |
4850 | return PRINT_UNKNOWN; | |
4851 | ||
348d480f PA |
4852 | /* Normal case. Call the breakpoint's print_it method. */ |
4853 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4854 | } |
348d480f | 4855 | break; |
3086aeae | 4856 | |
e514a9d6 | 4857 | default: |
8e65ff28 | 4858 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4859 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4860 | break; |
c906108c | 4861 | } |
c906108c SS |
4862 | } |
4863 | ||
edcc5120 TT |
4864 | /* A helper function that prints a shared library stopped event. */ |
4865 | ||
4866 | static void | |
4867 | print_solib_event (int is_catchpoint) | |
4868 | { | |
4869 | int any_deleted | |
4870 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4871 | int any_added | |
4872 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4873 | ||
4874 | if (!is_catchpoint) | |
4875 | { | |
4876 | if (any_added || any_deleted) | |
112e8700 | 4877 | current_uiout->text (_("Stopped due to shared library event:\n")); |
edcc5120 | 4878 | else |
112e8700 SM |
4879 | current_uiout->text (_("Stopped due to shared library event (no " |
4880 | "libraries added or removed)\n")); | |
edcc5120 TT |
4881 | } |
4882 | ||
112e8700 SM |
4883 | if (current_uiout->is_mi_like_p ()) |
4884 | current_uiout->field_string ("reason", | |
4885 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
edcc5120 TT |
4886 | |
4887 | if (any_deleted) | |
4888 | { | |
edcc5120 TT |
4889 | char *name; |
4890 | int ix; | |
4891 | ||
112e8700 | 4892 | current_uiout->text (_(" Inferior unloaded ")); |
10f489e5 | 4893 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
edcc5120 TT |
4894 | for (ix = 0; |
4895 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4896 | ix, name); | |
4897 | ++ix) | |
4898 | { | |
4899 | if (ix > 0) | |
112e8700 SM |
4900 | current_uiout->text (" "); |
4901 | current_uiout->field_string ("library", name); | |
4902 | current_uiout->text ("\n"); | |
edcc5120 | 4903 | } |
edcc5120 TT |
4904 | } |
4905 | ||
4906 | if (any_added) | |
4907 | { | |
4908 | struct so_list *iter; | |
4909 | int ix; | |
edcc5120 | 4910 | |
112e8700 | 4911 | current_uiout->text (_(" Inferior loaded ")); |
10f489e5 | 4912 | ui_out_emit_list list_emitter (current_uiout, "added"); |
edcc5120 TT |
4913 | for (ix = 0; |
4914 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4915 | ix, iter); | |
4916 | ++ix) | |
4917 | { | |
4918 | if (ix > 0) | |
112e8700 SM |
4919 | current_uiout->text (" "); |
4920 | current_uiout->field_string ("library", iter->so_name); | |
4921 | current_uiout->text ("\n"); | |
edcc5120 | 4922 | } |
edcc5120 TT |
4923 | } |
4924 | } | |
4925 | ||
e514a9d6 JM |
4926 | /* Print a message indicating what happened. This is called from |
4927 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4928 | list - a list of the eventpoints that caused this stop. KIND is |
4929 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4930 | routine calls the generic print routine for printing a message |
4931 | about reasons for stopping. This will print (for example) the | |
4932 | "Breakpoint n," part of the output. The return value of this | |
4933 | routine is one of: | |
c906108c | 4934 | |
4a64f543 | 4935 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4936 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4937 | code to print the location. An example is |
c5aa993b JM |
4938 | "Breakpoint 1, " which should be followed by |
4939 | the location. | |
917317f4 | 4940 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4941 | to also print the location part of the message. |
4942 | An example is the catch/throw messages, which | |
4a64f543 | 4943 | don't require a location appended to the end. |
917317f4 | 4944 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4945 | further info to be printed. */ |
c906108c | 4946 | |
917317f4 | 4947 | enum print_stop_action |
36dfb11c | 4948 | bpstat_print (bpstat bs, int kind) |
c906108c | 4949 | { |
f486487f | 4950 | enum print_stop_action val; |
c5aa993b | 4951 | |
c906108c | 4952 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4953 | (Currently all watchpoints go on the bpstat whether hit or not. |
4954 | That probably could (should) be changed, provided care is taken | |
c906108c | 4955 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4956 | for (; bs; bs = bs->next) |
4957 | { | |
4958 | val = print_bp_stop_message (bs); | |
4959 | if (val == PRINT_SRC_ONLY | |
4960 | || val == PRINT_SRC_AND_LOC | |
4961 | || val == PRINT_NOTHING) | |
4962 | return val; | |
4963 | } | |
c906108c | 4964 | |
36dfb11c TT |
4965 | /* If we had hit a shared library event breakpoint, |
4966 | print_bp_stop_message would print out this message. If we hit an | |
4967 | OS-level shared library event, do the same thing. */ | |
4968 | if (kind == TARGET_WAITKIND_LOADED) | |
4969 | { | |
edcc5120 | 4970 | print_solib_event (0); |
36dfb11c TT |
4971 | return PRINT_NOTHING; |
4972 | } | |
4973 | ||
e514a9d6 | 4974 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4975 | with and nothing was printed. */ |
917317f4 | 4976 | return PRINT_UNKNOWN; |
c906108c SS |
4977 | } |
4978 | ||
c42bd95a DE |
4979 | /* Evaluate the expression EXP and return 1 if value is zero. |
4980 | This returns the inverse of the condition because it is called | |
4981 | from catch_errors which returns 0 if an exception happened, and if an | |
4982 | exception happens we want execution to stop. | |
4a64f543 | 4983 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4984 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4985 | |
4986 | static int | |
4efb68b1 | 4987 | breakpoint_cond_eval (void *exp) |
c906108c | 4988 | { |
278cd55f | 4989 | struct value *mark = value_mark (); |
c5aa993b | 4990 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4991 | |
c906108c SS |
4992 | value_free_to_mark (mark); |
4993 | return i; | |
4994 | } | |
4995 | ||
5760d0ab | 4996 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
4997 | |
4998 | static bpstat | |
5760d0ab | 4999 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5000 | { |
5001 | bpstat bs; | |
5002 | ||
5003 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5004 | bs->next = NULL; |
5005 | **bs_link_pointer = bs; | |
5006 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5007 | bs->breakpoint_at = bl->owner; |
5008 | bs->bp_location_at = bl; | |
5009 | incref_bp_location (bl); | |
c906108c SS |
5010 | /* If the condition is false, etc., don't do the commands. */ |
5011 | bs->commands = NULL; | |
5012 | bs->old_val = NULL; | |
5013 | bs->print_it = print_it_normal; | |
5014 | return bs; | |
5015 | } | |
5016 | \f | |
d983da9c DJ |
5017 | /* The target has stopped with waitstatus WS. Check if any hardware |
5018 | watchpoints have triggered, according to the target. */ | |
5019 | ||
5020 | int | |
5021 | watchpoints_triggered (struct target_waitstatus *ws) | |
5022 | { | |
d92524f1 | 5023 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5024 | CORE_ADDR addr; |
5025 | struct breakpoint *b; | |
5026 | ||
5027 | if (!stopped_by_watchpoint) | |
5028 | { | |
5029 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5030 | as not triggered. */ | |
5031 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5032 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5033 | { |
5034 | struct watchpoint *w = (struct watchpoint *) b; | |
5035 | ||
5036 | w->watchpoint_triggered = watch_triggered_no; | |
5037 | } | |
d983da9c DJ |
5038 | |
5039 | return 0; | |
5040 | } | |
5041 | ||
5042 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5043 | { | |
5044 | /* We were stopped by a watchpoint, but we don't know where. | |
5045 | Mark all watchpoints as unknown. */ | |
5046 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5047 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5048 | { |
5049 | struct watchpoint *w = (struct watchpoint *) b; | |
5050 | ||
5051 | w->watchpoint_triggered = watch_triggered_unknown; | |
5052 | } | |
d983da9c | 5053 | |
3c4797ba | 5054 | return 1; |
d983da9c DJ |
5055 | } |
5056 | ||
5057 | /* The target could report the data address. Mark watchpoints | |
5058 | affected by this data address as triggered, and all others as not | |
5059 | triggered. */ | |
5060 | ||
5061 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5062 | if (is_hardware_watchpoint (b)) |
d983da9c | 5063 | { |
3a5c3e22 | 5064 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5065 | struct bp_location *loc; |
d983da9c | 5066 | |
3a5c3e22 | 5067 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5068 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5069 | { |
3a5c3e22 | 5070 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5071 | { |
3a5c3e22 PA |
5072 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5073 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5074 | |
5075 | if (newaddr == start) | |
5076 | { | |
3a5c3e22 | 5077 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5078 | break; |
5079 | } | |
5080 | } | |
5081 | /* Exact match not required. Within range is sufficient. */ | |
5082 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5083 | addr, loc->address, | |
5084 | loc->length)) | |
5085 | { | |
3a5c3e22 | 5086 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5087 | break; |
5088 | } | |
5089 | } | |
d983da9c DJ |
5090 | } |
5091 | ||
5092 | return 1; | |
5093 | } | |
5094 | ||
c906108c SS |
5095 | /* Possible return values for watchpoint_check (this can't be an enum |
5096 | because of check_errors). */ | |
5097 | /* The watchpoint has been deleted. */ | |
5098 | #define WP_DELETED 1 | |
5099 | /* The value has changed. */ | |
5100 | #define WP_VALUE_CHANGED 2 | |
5101 | /* The value has not changed. */ | |
5102 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5103 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5104 | #define WP_IGNORE 4 | |
c906108c SS |
5105 | |
5106 | #define BP_TEMPFLAG 1 | |
5107 | #define BP_HARDWAREFLAG 2 | |
5108 | ||
4a64f543 MS |
5109 | /* Evaluate watchpoint condition expression and check if its value |
5110 | changed. | |
553e4c11 JB |
5111 | |
5112 | P should be a pointer to struct bpstat, but is defined as a void * | |
5113 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5114 | |
5115 | static int | |
4efb68b1 | 5116 | watchpoint_check (void *p) |
c906108c SS |
5117 | { |
5118 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5119 | struct watchpoint *b; |
c906108c SS |
5120 | struct frame_info *fr; |
5121 | int within_current_scope; | |
5122 | ||
f431efe5 | 5123 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5124 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5125 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5126 | |
f6bc2008 PA |
5127 | /* If this is a local watchpoint, we only want to check if the |
5128 | watchpoint frame is in scope if the current thread is the thread | |
5129 | that was used to create the watchpoint. */ | |
5130 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5131 | return WP_IGNORE; |
f6bc2008 | 5132 | |
c906108c SS |
5133 | if (b->exp_valid_block == NULL) |
5134 | within_current_scope = 1; | |
5135 | else | |
5136 | { | |
edb3359d DJ |
5137 | struct frame_info *frame = get_current_frame (); |
5138 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5139 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5140 | ||
c9cf6e20 | 5141 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5142 | still in the function but the stack frame has already been |
5143 | invalidated. Since we can't rely on the values of local | |
5144 | variables after the stack has been destroyed, we are treating | |
5145 | the watchpoint in that state as `not changed' without further | |
5146 | checking. Don't mark watchpoints as changed if the current | |
5147 | frame is in an epilogue - even if they are in some other | |
5148 | frame, our view of the stack is likely to be wrong and | |
5149 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5150 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5151 | return WP_IGNORE; |
a0f49112 | 5152 | |
101dcfbe | 5153 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5154 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5155 | |
5156 | /* If we've gotten confused in the unwinder, we might have | |
5157 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5158 | if (within_current_scope) |
5159 | { | |
5160 | struct symbol *function; | |
5161 | ||
5162 | function = get_frame_function (fr); | |
5163 | if (function == NULL | |
5164 | || !contained_in (b->exp_valid_block, | |
5165 | SYMBOL_BLOCK_VALUE (function))) | |
5166 | within_current_scope = 0; | |
5167 | } | |
69fbadd5 | 5168 | |
edb3359d | 5169 | if (within_current_scope) |
c906108c SS |
5170 | /* If we end up stopping, the current frame will get selected |
5171 | in normal_stop. So this call to select_frame won't affect | |
5172 | the user. */ | |
0f7d239c | 5173 | select_frame (fr); |
c906108c | 5174 | } |
c5aa993b | 5175 | |
c906108c SS |
5176 | if (within_current_scope) |
5177 | { | |
4a64f543 MS |
5178 | /* We use value_{,free_to_}mark because it could be a *long* |
5179 | time before we return to the command level and call | |
5180 | free_all_values. We can't call free_all_values because we | |
5181 | might be in the middle of evaluating a function call. */ | |
c906108c | 5182 | |
0cf6dd15 | 5183 | int pc = 0; |
9c06b0b4 | 5184 | struct value *mark; |
fa4727a6 DJ |
5185 | struct value *new_val; |
5186 | ||
c1fc2657 | 5187 | if (is_masked_watchpoint (b)) |
9c06b0b4 TJB |
5188 | /* Since we don't know the exact trigger address (from |
5189 | stopped_data_address), just tell the user we've triggered | |
5190 | a mask watchpoint. */ | |
5191 | return WP_VALUE_CHANGED; | |
5192 | ||
5193 | mark = value_mark (); | |
4d01a485 | 5194 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5195 | |
bb9d5f81 PP |
5196 | if (b->val_bitsize != 0) |
5197 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5198 | ||
4a64f543 MS |
5199 | /* We use value_equal_contents instead of value_equal because |
5200 | the latter coerces an array to a pointer, thus comparing just | |
5201 | the address of the array instead of its contents. This is | |
5202 | not what we want. */ | |
fa4727a6 | 5203 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5204 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5205 | { |
fa4727a6 DJ |
5206 | if (new_val != NULL) |
5207 | { | |
5208 | release_value (new_val); | |
5209 | value_free_to_mark (mark); | |
5210 | } | |
c906108c SS |
5211 | bs->old_val = b->val; |
5212 | b->val = new_val; | |
fa4727a6 | 5213 | b->val_valid = 1; |
c906108c SS |
5214 | return WP_VALUE_CHANGED; |
5215 | } | |
5216 | else | |
5217 | { | |
60e1c644 | 5218 | /* Nothing changed. */ |
c906108c | 5219 | value_free_to_mark (mark); |
c906108c SS |
5220 | return WP_VALUE_NOT_CHANGED; |
5221 | } | |
5222 | } | |
5223 | else | |
5224 | { | |
5225 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
5226 | if we temporarily ignored the watchpoint, then when |
5227 | we reenter the block in which it is valid it contains | |
5228 | garbage (in the case of a function, it may have two | |
5229 | garbage values, one before and one after the prologue). | |
5230 | So we can't even detect the first assignment to it and | |
5231 | watch after that (since the garbage may or may not equal | |
5232 | the first value assigned). */ | |
348d480f PA |
5233 | /* We print all the stop information in |
5234 | breakpoint_ops->print_it, but in this case, by the time we | |
5235 | call breakpoint_ops->print_it this bp will be deleted | |
5236 | already. So we have no choice but print the information | |
5237 | here. */ | |
468afe6c | 5238 | |
0e454242 | 5239 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5240 | { |
5241 | struct ui_out *uiout = current_uiout; | |
5242 | ||
112e8700 SM |
5243 | if (uiout->is_mi_like_p ()) |
5244 | uiout->field_string | |
5245 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
5246 | uiout->text ("\nWatchpoint "); | |
c1fc2657 | 5247 | uiout->field_int ("wpnum", b->number); |
112e8700 | 5248 | uiout->text (" deleted because the program has left the block in\n" |
468afe6c PA |
5249 | "which its expression is valid.\n"); |
5250 | } | |
4ce44c66 | 5251 | |
cdac0397 | 5252 | /* Make sure the watchpoint's commands aren't executed. */ |
c1fc2657 | 5253 | decref_counted_command_line (&b->commands); |
d0fb5eae | 5254 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5255 | |
5256 | return WP_DELETED; | |
5257 | } | |
5258 | } | |
5259 | ||
18a18393 | 5260 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5261 | breakpoint location BL. This function does not check if we should |
5262 | stop, only if BL explains the stop. */ | |
5263 | ||
18a18393 | 5264 | static int |
6c95b8df | 5265 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5266 | struct address_space *aspace, CORE_ADDR bp_addr, |
5267 | const struct target_waitstatus *ws) | |
18a18393 VP |
5268 | { |
5269 | struct breakpoint *b = bl->owner; | |
5270 | ||
348d480f | 5271 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5272 | gdb_assert (b != NULL); |
5273 | ||
09ac7c10 | 5274 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5275 | } |
5276 | ||
3a5c3e22 PA |
5277 | /* Determine if the watched values have actually changed, and we |
5278 | should stop. If not, set BS->stop to 0. */ | |
5279 | ||
18a18393 VP |
5280 | static void |
5281 | bpstat_check_watchpoint (bpstat bs) | |
5282 | { | |
2bdf28a0 | 5283 | const struct bp_location *bl; |
3a5c3e22 | 5284 | struct watchpoint *b; |
2bdf28a0 JK |
5285 | |
5286 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5287 | bl = bs->bp_location_at; |
2bdf28a0 | 5288 | gdb_assert (bl != NULL); |
3a5c3e22 | 5289 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5290 | gdb_assert (b != NULL); |
18a18393 | 5291 | |
18a18393 | 5292 | { |
18a18393 VP |
5293 | int must_check_value = 0; |
5294 | ||
c1fc2657 | 5295 | if (b->type == bp_watchpoint) |
18a18393 VP |
5296 | /* For a software watchpoint, we must always check the |
5297 | watched value. */ | |
5298 | must_check_value = 1; | |
5299 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5300 | /* We have a hardware watchpoint (read, write, or access) | |
5301 | and the target earlier reported an address watched by | |
5302 | this watchpoint. */ | |
5303 | must_check_value = 1; | |
5304 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
c1fc2657 | 5305 | && b->type == bp_hardware_watchpoint) |
18a18393 VP |
5306 | /* We were stopped by a hardware watchpoint, but the target could |
5307 | not report the data address. We must check the watchpoint's | |
5308 | value. Access and read watchpoints are out of luck; without | |
5309 | a data address, we can't figure it out. */ | |
5310 | must_check_value = 1; | |
3a5c3e22 | 5311 | |
18a18393 VP |
5312 | if (must_check_value) |
5313 | { | |
3e43a32a MS |
5314 | char *message |
5315 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
c1fc2657 | 5316 | b->number); |
18a18393 VP |
5317 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5318 | int e = catch_errors (watchpoint_check, bs, message, | |
5319 | RETURN_MASK_ALL); | |
5320 | do_cleanups (cleanups); | |
5321 | switch (e) | |
5322 | { | |
5323 | case WP_DELETED: | |
5324 | /* We've already printed what needs to be printed. */ | |
5325 | bs->print_it = print_it_done; | |
5326 | /* Stop. */ | |
5327 | break; | |
60e1c644 PA |
5328 | case WP_IGNORE: |
5329 | bs->print_it = print_it_noop; | |
5330 | bs->stop = 0; | |
5331 | break; | |
18a18393 | 5332 | case WP_VALUE_CHANGED: |
c1fc2657 | 5333 | if (b->type == bp_read_watchpoint) |
18a18393 | 5334 | { |
85d721b8 PA |
5335 | /* There are two cases to consider here: |
5336 | ||
4a64f543 | 5337 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5338 | In that case, trust the target, and always report |
5339 | the watchpoint hit to the user. Even though | |
5340 | reads don't cause value changes, the value may | |
5341 | have changed since the last time it was read, and | |
5342 | since we're not trapping writes, we will not see | |
5343 | those, and as such we should ignore our notion of | |
5344 | old value. | |
5345 | ||
4a64f543 | 5346 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5347 | reads and writes. There are two ways this may |
5348 | happen: | |
5349 | ||
4a64f543 | 5350 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5351 | reads only, but can break on accesses (reads or |
5352 | writes), such as e.g., x86. We detect this case | |
5353 | at the time we try to insert read watchpoints. | |
5354 | ||
4a64f543 | 5355 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5356 | watchpoints, but, the user set an access or write |
5357 | watchpoint watching the same memory as this read | |
5358 | watchpoint. | |
5359 | ||
5360 | If we're watching memory writes as well as reads, | |
5361 | ignore watchpoint hits when we find that the | |
5362 | value hasn't changed, as reads don't cause | |
5363 | changes. This still gives false positives when | |
5364 | the program writes the same value to memory as | |
5365 | what there was already in memory (we will confuse | |
5366 | it for a read), but it's much better than | |
5367 | nothing. */ | |
5368 | ||
5369 | int other_write_watchpoint = 0; | |
5370 | ||
5371 | if (bl->watchpoint_type == hw_read) | |
5372 | { | |
5373 | struct breakpoint *other_b; | |
5374 | ||
5375 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5376 | if (other_b->type == bp_hardware_watchpoint |
5377 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5378 | { |
3a5c3e22 PA |
5379 | struct watchpoint *other_w = |
5380 | (struct watchpoint *) other_b; | |
5381 | ||
5382 | if (other_w->watchpoint_triggered | |
5383 | == watch_triggered_yes) | |
5384 | { | |
5385 | other_write_watchpoint = 1; | |
5386 | break; | |
5387 | } | |
85d721b8 PA |
5388 | } |
5389 | } | |
5390 | ||
5391 | if (other_write_watchpoint | |
5392 | || bl->watchpoint_type == hw_access) | |
5393 | { | |
5394 | /* We're watching the same memory for writes, | |
5395 | and the value changed since the last time we | |
5396 | updated it, so this trap must be for a write. | |
5397 | Ignore it. */ | |
5398 | bs->print_it = print_it_noop; | |
5399 | bs->stop = 0; | |
5400 | } | |
18a18393 VP |
5401 | } |
5402 | break; | |
5403 | case WP_VALUE_NOT_CHANGED: | |
c1fc2657 SM |
5404 | if (b->type == bp_hardware_watchpoint |
5405 | || b->type == bp_watchpoint) | |
18a18393 VP |
5406 | { |
5407 | /* Don't stop: write watchpoints shouldn't fire if | |
5408 | the value hasn't changed. */ | |
5409 | bs->print_it = print_it_noop; | |
5410 | bs->stop = 0; | |
5411 | } | |
5412 | /* Stop. */ | |
5413 | break; | |
5414 | default: | |
5415 | /* Can't happen. */ | |
5416 | case 0: | |
5417 | /* Error from catch_errors. */ | |
468afe6c | 5418 | { |
0e454242 | 5419 | SWITCH_THRU_ALL_UIS () |
468afe6c PA |
5420 | { |
5421 | printf_filtered (_("Watchpoint %d deleted.\n"), | |
c1fc2657 | 5422 | b->number); |
468afe6c PA |
5423 | } |
5424 | watchpoint_del_at_next_stop (b); | |
5425 | /* We've already printed what needs to be printed. */ | |
5426 | bs->print_it = print_it_done; | |
5427 | } | |
18a18393 VP |
5428 | break; |
5429 | } | |
5430 | } | |
5431 | else /* must_check_value == 0 */ | |
5432 | { | |
5433 | /* This is a case where some watchpoint(s) triggered, but | |
5434 | not at the address of this watchpoint, or else no | |
5435 | watchpoint triggered after all. So don't print | |
5436 | anything for this watchpoint. */ | |
5437 | bs->print_it = print_it_noop; | |
5438 | bs->stop = 0; | |
5439 | } | |
5440 | } | |
5441 | } | |
5442 | ||
7d4df6a4 DE |
5443 | /* For breakpoints that are currently marked as telling gdb to stop, |
5444 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5445 | of breakpoint referred to by BS. If we should not stop for this |
5446 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5447 | |
18a18393 VP |
5448 | static void |
5449 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5450 | { | |
2bdf28a0 JK |
5451 | const struct bp_location *bl; |
5452 | struct breakpoint *b; | |
7d4df6a4 DE |
5453 | int value_is_zero = 0; |
5454 | struct expression *cond; | |
5455 | ||
5456 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5457 | |
5458 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5459 | bl = bs->bp_location_at; |
2bdf28a0 | 5460 | gdb_assert (bl != NULL); |
f431efe5 | 5461 | b = bs->breakpoint_at; |
2bdf28a0 | 5462 | gdb_assert (b != NULL); |
18a18393 | 5463 | |
b775012e LM |
5464 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5465 | need to do so again since GDB does not know if we stopped due to a | |
5466 | breakpoint or a single step breakpoint. */ | |
5467 | ||
18a18393 | 5468 | if (frame_id_p (b->frame_id) |
edb3359d | 5469 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5470 | { |
7d4df6a4 DE |
5471 | bs->stop = 0; |
5472 | return; | |
5473 | } | |
60e1c644 | 5474 | |
12ab52e9 PA |
5475 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5476 | evaluating the condition if this isn't the specified | |
5477 | thread/task. */ | |
5d5658a1 | 5478 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5479 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5480 | ||
6c1b0f7b DE |
5481 | { |
5482 | bs->stop = 0; | |
5483 | return; | |
5484 | } | |
5485 | ||
6dddc817 DE |
5486 | /* Evaluate extension language breakpoints that have a "stop" method |
5487 | implemented. */ | |
5488 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5489 | |
7d4df6a4 DE |
5490 | if (is_watchpoint (b)) |
5491 | { | |
5492 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5493 | |
4d01a485 | 5494 | cond = w->cond_exp.get (); |
7d4df6a4 DE |
5495 | } |
5496 | else | |
4d01a485 | 5497 | cond = bl->cond.get (); |
60e1c644 | 5498 | |
7d4df6a4 DE |
5499 | if (cond && b->disposition != disp_del_at_next_stop) |
5500 | { | |
5501 | int within_current_scope = 1; | |
5502 | struct watchpoint * w; | |
60e1c644 | 5503 | |
7d4df6a4 DE |
5504 | /* We use value_mark and value_free_to_mark because it could |
5505 | be a long time before we return to the command level and | |
5506 | call free_all_values. We can't call free_all_values | |
5507 | because we might be in the middle of evaluating a | |
5508 | function call. */ | |
5509 | struct value *mark = value_mark (); | |
5510 | ||
5511 | if (is_watchpoint (b)) | |
5512 | w = (struct watchpoint *) b; | |
5513 | else | |
5514 | w = NULL; | |
5515 | ||
5516 | /* Need to select the frame, with all that implies so that | |
5517 | the conditions will have the right context. Because we | |
5518 | use the frame, we will not see an inlined function's | |
5519 | variables when we arrive at a breakpoint at the start | |
5520 | of the inlined function; the current frame will be the | |
5521 | call site. */ | |
5522 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5523 | select_frame (get_current_frame ()); | |
5524 | else | |
18a18393 | 5525 | { |
7d4df6a4 DE |
5526 | struct frame_info *frame; |
5527 | ||
5528 | /* For local watchpoint expressions, which particular | |
5529 | instance of a local is being watched matters, so we | |
5530 | keep track of the frame to evaluate the expression | |
5531 | in. To evaluate the condition however, it doesn't | |
5532 | really matter which instantiation of the function | |
5533 | where the condition makes sense triggers the | |
5534 | watchpoint. This allows an expression like "watch | |
5535 | global if q > 10" set in `func', catch writes to | |
5536 | global on all threads that call `func', or catch | |
5537 | writes on all recursive calls of `func' by a single | |
5538 | thread. We simply always evaluate the condition in | |
5539 | the innermost frame that's executing where it makes | |
5540 | sense to evaluate the condition. It seems | |
5541 | intuitive. */ | |
5542 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5543 | if (frame != NULL) | |
5544 | select_frame (frame); | |
5545 | else | |
5546 | within_current_scope = 0; | |
18a18393 | 5547 | } |
7d4df6a4 DE |
5548 | if (within_current_scope) |
5549 | value_is_zero | |
5550 | = catch_errors (breakpoint_cond_eval, cond, | |
5551 | "Error in testing breakpoint condition:\n", | |
5552 | RETURN_MASK_ALL); | |
5553 | else | |
18a18393 | 5554 | { |
7d4df6a4 DE |
5555 | warning (_("Watchpoint condition cannot be tested " |
5556 | "in the current scope")); | |
5557 | /* If we failed to set the right context for this | |
5558 | watchpoint, unconditionally report it. */ | |
5559 | value_is_zero = 0; | |
18a18393 | 5560 | } |
7d4df6a4 DE |
5561 | /* FIXME-someday, should give breakpoint #. */ |
5562 | value_free_to_mark (mark); | |
18a18393 | 5563 | } |
7d4df6a4 DE |
5564 | |
5565 | if (cond && value_is_zero) | |
5566 | { | |
5567 | bs->stop = 0; | |
5568 | } | |
7d4df6a4 DE |
5569 | else if (b->ignore_count > 0) |
5570 | { | |
5571 | b->ignore_count--; | |
5572 | bs->stop = 0; | |
5573 | /* Increase the hit count even though we don't stop. */ | |
5574 | ++(b->hit_count); | |
5575 | observer_notify_breakpoint_modified (b); | |
5576 | } | |
18a18393 VP |
5577 | } |
5578 | ||
1cf4d951 PA |
5579 | /* Returns true if we need to track moribund locations of LOC's type |
5580 | on the current target. */ | |
5581 | ||
5582 | static int | |
5583 | need_moribund_for_location_type (struct bp_location *loc) | |
5584 | { | |
5585 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5586 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5587 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5588 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5589 | } | |
5590 | ||
18a18393 | 5591 | |
9709f61c | 5592 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5593 | BP_ADDR in thread PTID. |
c906108c | 5594 | |
d983da9c | 5595 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5596 | don't understand this stop. Result is a chain of bpstat's such |
5597 | that: | |
c906108c | 5598 | |
c5aa993b | 5599 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5600 | |
c5aa993b | 5601 | if we understand why we stopped, the result is not null. |
c906108c | 5602 | |
c5aa993b JM |
5603 | Each element of the chain refers to a particular breakpoint or |
5604 | watchpoint at which we have stopped. (We may have stopped for | |
5605 | several reasons concurrently.) | |
c906108c | 5606 | |
c5aa993b JM |
5607 | Each element of the chain has valid next, breakpoint_at, |
5608 | commands, FIXME??? fields. */ | |
c906108c SS |
5609 | |
5610 | bpstat | |
6c95b8df | 5611 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5612 | CORE_ADDR bp_addr, ptid_t ptid, |
5613 | const struct target_waitstatus *ws) | |
c906108c | 5614 | { |
0d381245 | 5615 | struct breakpoint *b = NULL; |
afe38095 | 5616 | struct bp_location *bl; |
20874c92 | 5617 | struct bp_location *loc; |
5760d0ab JK |
5618 | /* First item of allocated bpstat's. */ |
5619 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5620 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5621 | bpstat bs; |
20874c92 | 5622 | int ix; |
429374b8 | 5623 | int need_remove_insert; |
f431efe5 | 5624 | int removed_any; |
c906108c | 5625 | |
f431efe5 PA |
5626 | /* First, build the bpstat chain with locations that explain a |
5627 | target stop, while being careful to not set the target running, | |
5628 | as that may invalidate locations (in particular watchpoint | |
5629 | locations are recreated). Resuming will happen here with | |
5630 | breakpoint conditions or watchpoint expressions that include | |
5631 | inferior function calls. */ | |
c5aa993b | 5632 | |
429374b8 JK |
5633 | ALL_BREAKPOINTS (b) |
5634 | { | |
1a853c52 | 5635 | if (!breakpoint_enabled (b)) |
429374b8 | 5636 | continue; |
a5606eee | 5637 | |
429374b8 JK |
5638 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5639 | { | |
4a64f543 MS |
5640 | /* For hardware watchpoints, we look only at the first |
5641 | location. The watchpoint_check function will work on the | |
5642 | entire expression, not the individual locations. For | |
5643 | read watchpoints, the watchpoints_triggered function has | |
5644 | checked all locations already. */ | |
429374b8 JK |
5645 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5646 | break; | |
18a18393 | 5647 | |
f6592439 | 5648 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5649 | continue; |
c5aa993b | 5650 | |
09ac7c10 | 5651 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5652 | continue; |
c5aa993b | 5653 | |
4a64f543 MS |
5654 | /* Come here if it's a watchpoint, or if the break address |
5655 | matches. */ | |
c5aa993b | 5656 | |
4a64f543 MS |
5657 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5658 | explain stop. */ | |
c5aa993b | 5659 | |
f431efe5 PA |
5660 | /* Assume we stop. Should we find a watchpoint that is not |
5661 | actually triggered, or if the condition of the breakpoint | |
5662 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5663 | bs->stop = 1; |
5664 | bs->print = 1; | |
d983da9c | 5665 | |
f431efe5 PA |
5666 | /* If this is a scope breakpoint, mark the associated |
5667 | watchpoint as triggered so that we will handle the | |
5668 | out-of-scope event. We'll get to the watchpoint next | |
5669 | iteration. */ | |
d0fb5eae | 5670 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5671 | { |
5672 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5673 | ||
5674 | w->watchpoint_triggered = watch_triggered_yes; | |
5675 | } | |
f431efe5 PA |
5676 | } |
5677 | } | |
5678 | ||
7c16b83e | 5679 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5680 | if (!target_supports_stopped_by_sw_breakpoint () |
5681 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5682 | { |
1cf4d951 | 5683 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5684 | { |
1cf4d951 PA |
5685 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5686 | && need_moribund_for_location_type (loc)) | |
5687 | { | |
5688 | bs = bpstat_alloc (loc, &bs_link); | |
5689 | /* For hits of moribund locations, we should just proceed. */ | |
5690 | bs->stop = 0; | |
5691 | bs->print = 0; | |
5692 | bs->print_it = print_it_noop; | |
5693 | } | |
f431efe5 PA |
5694 | } |
5695 | } | |
5696 | ||
edcc5120 TT |
5697 | /* A bit of special processing for shlib breakpoints. We need to |
5698 | process solib loading here, so that the lists of loaded and | |
5699 | unloaded libraries are correct before we handle "catch load" and | |
5700 | "catch unload". */ | |
5701 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5702 | { | |
5d268276 | 5703 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5704 | { |
5705 | handle_solib_event (); | |
5706 | break; | |
5707 | } | |
5708 | } | |
5709 | ||
f431efe5 PA |
5710 | /* Now go through the locations that caused the target to stop, and |
5711 | check whether we're interested in reporting this stop to higher | |
5712 | layers, or whether we should resume the target transparently. */ | |
5713 | ||
5714 | removed_any = 0; | |
5715 | ||
5760d0ab | 5716 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5717 | { |
5718 | if (!bs->stop) | |
5719 | continue; | |
5720 | ||
f431efe5 | 5721 | b = bs->breakpoint_at; |
348d480f PA |
5722 | b->ops->check_status (bs); |
5723 | if (bs->stop) | |
28010a5d | 5724 | { |
348d480f | 5725 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5726 | |
429374b8 JK |
5727 | if (bs->stop) |
5728 | { | |
5729 | ++(b->hit_count); | |
8d3788bd | 5730 | observer_notify_breakpoint_modified (b); |
c906108c | 5731 | |
4a64f543 | 5732 | /* We will stop here. */ |
429374b8 JK |
5733 | if (b->disposition == disp_disable) |
5734 | { | |
816338b5 | 5735 | --(b->enable_count); |
1a853c52 | 5736 | if (b->enable_count <= 0) |
429374b8 | 5737 | b->enable_state = bp_disabled; |
f431efe5 | 5738 | removed_any = 1; |
429374b8 JK |
5739 | } |
5740 | if (b->silent) | |
5741 | bs->print = 0; | |
5742 | bs->commands = b->commands; | |
9add0f1b | 5743 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5744 | if (command_line_is_silent (bs->commands |
5745 | ? bs->commands->commands : NULL)) | |
5746 | bs->print = 0; | |
9d6e6e84 HZ |
5747 | |
5748 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5749 | } |
5750 | ||
348d480f | 5751 | } |
a9b3a50f PA |
5752 | |
5753 | /* Print nothing for this entry if we don't stop or don't | |
5754 | print. */ | |
5755 | if (!bs->stop || !bs->print) | |
5756 | bs->print_it = print_it_noop; | |
429374b8 | 5757 | } |
876fa593 | 5758 | |
d983da9c DJ |
5759 | /* If we aren't stopping, the value of some hardware watchpoint may |
5760 | not have changed, but the intermediate memory locations we are | |
5761 | watching may have. Don't bother if we're stopping; this will get | |
5762 | done later. */ | |
d832cb68 | 5763 | need_remove_insert = 0; |
5760d0ab JK |
5764 | if (! bpstat_causes_stop (bs_head)) |
5765 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5766 | if (!bs->stop |
f431efe5 PA |
5767 | && bs->breakpoint_at |
5768 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5769 | { |
3a5c3e22 PA |
5770 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5771 | ||
5772 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5773 | need_remove_insert = 1; |
d983da9c DJ |
5774 | } |
5775 | ||
d832cb68 | 5776 | if (need_remove_insert) |
44702360 | 5777 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5778 | else if (removed_any) |
44702360 | 5779 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5780 | |
5760d0ab | 5781 | return bs_head; |
c906108c | 5782 | } |
628fe4e4 JK |
5783 | |
5784 | static void | |
5785 | handle_jit_event (void) | |
5786 | { | |
5787 | struct frame_info *frame; | |
5788 | struct gdbarch *gdbarch; | |
5789 | ||
243a9253 PA |
5790 | if (debug_infrun) |
5791 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5792 | ||
628fe4e4 JK |
5793 | /* Switch terminal for any messages produced by |
5794 | breakpoint_re_set. */ | |
5795 | target_terminal_ours_for_output (); | |
5796 | ||
5797 | frame = get_current_frame (); | |
5798 | gdbarch = get_frame_arch (frame); | |
5799 | ||
5800 | jit_event_handler (gdbarch); | |
5801 | ||
5802 | target_terminal_inferior (); | |
5803 | } | |
5804 | ||
5805 | /* Prepare WHAT final decision for infrun. */ | |
5806 | ||
5807 | /* Decide what infrun needs to do with this bpstat. */ | |
5808 | ||
c906108c | 5809 | struct bpstat_what |
0e30163f | 5810 | bpstat_what (bpstat bs_head) |
c906108c | 5811 | { |
c906108c | 5812 | struct bpstat_what retval; |
0e30163f | 5813 | bpstat bs; |
c906108c | 5814 | |
628fe4e4 | 5815 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5816 | retval.call_dummy = STOP_NONE; |
186c406b | 5817 | retval.is_longjmp = 0; |
628fe4e4 | 5818 | |
0e30163f | 5819 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5820 | { |
628fe4e4 JK |
5821 | /* Extract this BS's action. After processing each BS, we check |
5822 | if its action overrides all we've seem so far. */ | |
5823 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5824 | enum bptype bptype; | |
5825 | ||
c906108c | 5826 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5827 | { |
5828 | /* I suspect this can happen if it was a momentary | |
5829 | breakpoint which has since been deleted. */ | |
5830 | bptype = bp_none; | |
5831 | } | |
20874c92 | 5832 | else |
f431efe5 | 5833 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5834 | |
5835 | switch (bptype) | |
c906108c SS |
5836 | { |
5837 | case bp_none: | |
628fe4e4 | 5838 | break; |
c906108c SS |
5839 | case bp_breakpoint: |
5840 | case bp_hardware_breakpoint: | |
7c16b83e | 5841 | case bp_single_step: |
c906108c SS |
5842 | case bp_until: |
5843 | case bp_finish: | |
a9b3a50f | 5844 | case bp_shlib_event: |
c906108c SS |
5845 | if (bs->stop) |
5846 | { | |
5847 | if (bs->print) | |
628fe4e4 | 5848 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5849 | else |
628fe4e4 | 5850 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5851 | } |
5852 | else | |
628fe4e4 | 5853 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5854 | break; |
5855 | case bp_watchpoint: | |
5856 | case bp_hardware_watchpoint: | |
5857 | case bp_read_watchpoint: | |
5858 | case bp_access_watchpoint: | |
5859 | if (bs->stop) | |
5860 | { | |
5861 | if (bs->print) | |
628fe4e4 | 5862 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5863 | else |
628fe4e4 | 5864 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5865 | } |
5866 | else | |
628fe4e4 JK |
5867 | { |
5868 | /* There was a watchpoint, but we're not stopping. | |
5869 | This requires no further action. */ | |
5870 | } | |
c906108c SS |
5871 | break; |
5872 | case bp_longjmp: | |
e2e4d78b | 5873 | case bp_longjmp_call_dummy: |
186c406b | 5874 | case bp_exception: |
0a39bb32 PA |
5875 | if (bs->stop) |
5876 | { | |
5877 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5878 | retval.is_longjmp = bptype != bp_exception; | |
5879 | } | |
5880 | else | |
5881 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5882 | break; |
5883 | case bp_longjmp_resume: | |
186c406b | 5884 | case bp_exception_resume: |
0a39bb32 PA |
5885 | if (bs->stop) |
5886 | { | |
5887 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5888 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5889 | } | |
5890 | else | |
5891 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5892 | break; |
5893 | case bp_step_resume: | |
5894 | if (bs->stop) | |
628fe4e4 JK |
5895 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5896 | else | |
c906108c | 5897 | { |
628fe4e4 JK |
5898 | /* It is for the wrong frame. */ |
5899 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5900 | } |
c906108c | 5901 | break; |
2c03e5be PA |
5902 | case bp_hp_step_resume: |
5903 | if (bs->stop) | |
5904 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5905 | else | |
5906 | { | |
5907 | /* It is for the wrong frame. */ | |
5908 | this_action = BPSTAT_WHAT_SINGLE; | |
5909 | } | |
5910 | break; | |
c906108c | 5911 | case bp_watchpoint_scope: |
c4093a6a | 5912 | case bp_thread_event: |
1900040c | 5913 | case bp_overlay_event: |
0fd8e87f | 5914 | case bp_longjmp_master: |
aa7d318d | 5915 | case bp_std_terminate_master: |
186c406b | 5916 | case bp_exception_master: |
628fe4e4 | 5917 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5918 | break; |
ce78b96d | 5919 | case bp_catchpoint: |
c5aa993b JM |
5920 | if (bs->stop) |
5921 | { | |
5922 | if (bs->print) | |
628fe4e4 | 5923 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5924 | else |
628fe4e4 | 5925 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5926 | } |
5927 | else | |
628fe4e4 JK |
5928 | { |
5929 | /* There was a catchpoint, but we're not stopping. | |
5930 | This requires no further action. */ | |
5931 | } | |
5932 | break; | |
628fe4e4 | 5933 | case bp_jit_event: |
628fe4e4 | 5934 | this_action = BPSTAT_WHAT_SINGLE; |
c5aa993b | 5935 | break; |
c906108c | 5936 | case bp_call_dummy: |
53a5351d JM |
5937 | /* Make sure the action is stop (silent or noisy), |
5938 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5939 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5940 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5941 | break; |
5942 | case bp_std_terminate: | |
5943 | /* Make sure the action is stop (silent or noisy), | |
5944 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5945 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5946 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5947 | break; |
1042e4c0 | 5948 | case bp_tracepoint: |
7a697b8d | 5949 | case bp_fast_tracepoint: |
0fb4aa4b | 5950 | case bp_static_tracepoint: |
1042e4c0 SS |
5951 | /* Tracepoint hits should not be reported back to GDB, and |
5952 | if one got through somehow, it should have been filtered | |
5953 | out already. */ | |
5954 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5955 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5956 | break; |
5957 | case bp_gnu_ifunc_resolver: | |
5958 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5959 | this_action = BPSTAT_WHAT_SINGLE; | |
5960 | break; | |
5961 | case bp_gnu_ifunc_resolver_return: | |
5962 | /* The breakpoint will be removed, execution will restart from the | |
5963 | PC of the former breakpoint. */ | |
5964 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5965 | break; | |
e7e0cddf SS |
5966 | |
5967 | case bp_dprintf: | |
a11cfd87 HZ |
5968 | if (bs->stop) |
5969 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5970 | else | |
5971 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5972 | break; |
5973 | ||
628fe4e4 JK |
5974 | default: |
5975 | internal_error (__FILE__, __LINE__, | |
5976 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5977 | } |
628fe4e4 | 5978 | |
325fac50 | 5979 | retval.main_action = std::max (retval.main_action, this_action); |
c906108c | 5980 | } |
628fe4e4 | 5981 | |
243a9253 PA |
5982 | return retval; |
5983 | } | |
628fe4e4 | 5984 | |
243a9253 PA |
5985 | void |
5986 | bpstat_run_callbacks (bpstat bs_head) | |
5987 | { | |
5988 | bpstat bs; | |
628fe4e4 | 5989 | |
0e30163f JK |
5990 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5991 | { | |
5992 | struct breakpoint *b = bs->breakpoint_at; | |
5993 | ||
5994 | if (b == NULL) | |
5995 | continue; | |
5996 | switch (b->type) | |
5997 | { | |
243a9253 PA |
5998 | case bp_jit_event: |
5999 | handle_jit_event (); | |
6000 | break; | |
0e30163f JK |
6001 | case bp_gnu_ifunc_resolver: |
6002 | gnu_ifunc_resolver_stop (b); | |
6003 | break; | |
6004 | case bp_gnu_ifunc_resolver_return: | |
6005 | gnu_ifunc_resolver_return_stop (b); | |
6006 | break; | |
6007 | } | |
6008 | } | |
c906108c SS |
6009 | } |
6010 | ||
6011 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6012 | without hardware support). This isn't related to a specific bpstat, | |
6013 | just to things like whether watchpoints are set. */ | |
6014 | ||
c5aa993b | 6015 | int |
fba45db2 | 6016 | bpstat_should_step (void) |
c906108c SS |
6017 | { |
6018 | struct breakpoint *b; | |
cc59ec59 | 6019 | |
c906108c | 6020 | ALL_BREAKPOINTS (b) |
717a8278 | 6021 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6022 | return 1; |
c906108c SS |
6023 | return 0; |
6024 | } | |
6025 | ||
67822962 PA |
6026 | int |
6027 | bpstat_causes_stop (bpstat bs) | |
6028 | { | |
6029 | for (; bs != NULL; bs = bs->next) | |
6030 | if (bs->stop) | |
6031 | return 1; | |
6032 | ||
6033 | return 0; | |
6034 | } | |
6035 | ||
c906108c | 6036 | \f |
c5aa993b | 6037 | |
170b53b2 UW |
6038 | /* Compute a string of spaces suitable to indent the next line |
6039 | so it starts at the position corresponding to the table column | |
6040 | named COL_NAME in the currently active table of UIOUT. */ | |
6041 | ||
6042 | static char * | |
6043 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6044 | { | |
6045 | static char wrap_indent[80]; | |
6046 | int i, total_width, width, align; | |
c5209615 | 6047 | const char *text; |
170b53b2 UW |
6048 | |
6049 | total_width = 0; | |
112e8700 | 6050 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
170b53b2 UW |
6051 | { |
6052 | if (strcmp (text, col_name) == 0) | |
6053 | { | |
6054 | gdb_assert (total_width < sizeof wrap_indent); | |
6055 | memset (wrap_indent, ' ', total_width); | |
6056 | wrap_indent[total_width] = 0; | |
6057 | ||
6058 | return wrap_indent; | |
6059 | } | |
6060 | ||
6061 | total_width += width + 1; | |
6062 | } | |
6063 | ||
6064 | return NULL; | |
6065 | } | |
6066 | ||
b775012e LM |
6067 | /* Determine if the locations of this breakpoint will have their conditions |
6068 | evaluated by the target, host or a mix of both. Returns the following: | |
6069 | ||
6070 | "host": Host evals condition. | |
6071 | "host or target": Host or Target evals condition. | |
6072 | "target": Target evals condition. | |
6073 | */ | |
6074 | ||
6075 | static const char * | |
6076 | bp_condition_evaluator (struct breakpoint *b) | |
6077 | { | |
6078 | struct bp_location *bl; | |
6079 | char host_evals = 0; | |
6080 | char target_evals = 0; | |
6081 | ||
6082 | if (!b) | |
6083 | return NULL; | |
6084 | ||
6085 | if (!is_breakpoint (b)) | |
6086 | return NULL; | |
6087 | ||
6088 | if (gdb_evaluates_breakpoint_condition_p () | |
6089 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6090 | return condition_evaluation_host; | |
6091 | ||
6092 | for (bl = b->loc; bl; bl = bl->next) | |
6093 | { | |
6094 | if (bl->cond_bytecode) | |
6095 | target_evals++; | |
6096 | else | |
6097 | host_evals++; | |
6098 | } | |
6099 | ||
6100 | if (host_evals && target_evals) | |
6101 | return condition_evaluation_both; | |
6102 | else if (target_evals) | |
6103 | return condition_evaluation_target; | |
6104 | else | |
6105 | return condition_evaluation_host; | |
6106 | } | |
6107 | ||
6108 | /* Determine the breakpoint location's condition evaluator. This is | |
6109 | similar to bp_condition_evaluator, but for locations. */ | |
6110 | ||
6111 | static const char * | |
6112 | bp_location_condition_evaluator (struct bp_location *bl) | |
6113 | { | |
6114 | if (bl && !is_breakpoint (bl->owner)) | |
6115 | return NULL; | |
6116 | ||
6117 | if (gdb_evaluates_breakpoint_condition_p () | |
6118 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6119 | return condition_evaluation_host; | |
6120 | ||
6121 | if (bl && bl->cond_bytecode) | |
6122 | return condition_evaluation_target; | |
6123 | else | |
6124 | return condition_evaluation_host; | |
6125 | } | |
6126 | ||
859825b8 JK |
6127 | /* Print the LOC location out of the list of B->LOC locations. */ |
6128 | ||
170b53b2 UW |
6129 | static void |
6130 | print_breakpoint_location (struct breakpoint *b, | |
6131 | struct bp_location *loc) | |
0d381245 | 6132 | { |
79a45e25 | 6133 | struct ui_out *uiout = current_uiout; |
5ed8105e PA |
6134 | |
6135 | scoped_restore_current_program_space restore_pspace; | |
6c95b8df | 6136 | |
859825b8 JK |
6137 | if (loc != NULL && loc->shlib_disabled) |
6138 | loc = NULL; | |
6139 | ||
6c95b8df PA |
6140 | if (loc != NULL) |
6141 | set_current_program_space (loc->pspace); | |
6142 | ||
56435ebe | 6143 | if (b->display_canonical) |
d28cd78a | 6144 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
2f202fde | 6145 | else if (loc && loc->symtab) |
0d381245 VP |
6146 | { |
6147 | struct symbol *sym | |
6148 | = find_pc_sect_function (loc->address, loc->section); | |
6149 | if (sym) | |
6150 | { | |
112e8700 SM |
6151 | uiout->text ("in "); |
6152 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); | |
6153 | uiout->text (" "); | |
6154 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); | |
6155 | uiout->text ("at "); | |
0d381245 | 6156 | } |
112e8700 | 6157 | uiout->field_string ("file", |
05cba821 | 6158 | symtab_to_filename_for_display (loc->symtab)); |
112e8700 | 6159 | uiout->text (":"); |
05cba821 | 6160 | |
112e8700 SM |
6161 | if (uiout->is_mi_like_p ()) |
6162 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); | |
0d381245 | 6163 | |
112e8700 | 6164 | uiout->field_int ("line", loc->line_number); |
0d381245 | 6165 | } |
859825b8 | 6166 | else if (loc) |
0d381245 | 6167 | { |
d7e74731 | 6168 | string_file stb; |
170b53b2 | 6169 | |
d7e74731 | 6170 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
22e722e1 | 6171 | demangle, ""); |
112e8700 | 6172 | uiout->field_stream ("at", stb); |
0d381245 | 6173 | } |
859825b8 | 6174 | else |
f00aae0f | 6175 | { |
d28cd78a TT |
6176 | uiout->field_string ("pending", |
6177 | event_location_to_string (b->location.get ())); | |
f00aae0f KS |
6178 | /* If extra_string is available, it could be holding a condition |
6179 | or dprintf arguments. In either case, make sure it is printed, | |
6180 | too, but only for non-MI streams. */ | |
112e8700 | 6181 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
f00aae0f KS |
6182 | { |
6183 | if (b->type == bp_dprintf) | |
112e8700 | 6184 | uiout->text (","); |
f00aae0f | 6185 | else |
112e8700 SM |
6186 | uiout->text (" "); |
6187 | uiout->text (b->extra_string); | |
f00aae0f KS |
6188 | } |
6189 | } | |
6c95b8df | 6190 | |
b775012e LM |
6191 | if (loc && is_breakpoint (b) |
6192 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6193 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6194 | { | |
112e8700 SM |
6195 | uiout->text (" ("); |
6196 | uiout->field_string ("evaluated-by", | |
b775012e | 6197 | bp_location_condition_evaluator (loc)); |
112e8700 | 6198 | uiout->text (")"); |
b775012e | 6199 | } |
0d381245 VP |
6200 | } |
6201 | ||
269b11a2 PA |
6202 | static const char * |
6203 | bptype_string (enum bptype type) | |
c906108c | 6204 | { |
c4093a6a JM |
6205 | struct ep_type_description |
6206 | { | |
6207 | enum bptype type; | |
a121b7c1 | 6208 | const char *description; |
c4093a6a JM |
6209 | }; |
6210 | static struct ep_type_description bptypes[] = | |
c906108c | 6211 | { |
c5aa993b JM |
6212 | {bp_none, "?deleted?"}, |
6213 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6214 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6215 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6216 | {bp_until, "until"}, |
6217 | {bp_finish, "finish"}, | |
6218 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6219 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6220 | {bp_read_watchpoint, "read watchpoint"}, |
6221 | {bp_access_watchpoint, "acc watchpoint"}, | |
6222 | {bp_longjmp, "longjmp"}, | |
6223 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6224 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6225 | {bp_exception, "exception"}, |
6226 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6227 | {bp_step_resume, "step resume"}, |
2c03e5be | 6228 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6229 | {bp_watchpoint_scope, "watchpoint scope"}, |
6230 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6231 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6232 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6233 | {bp_thread_event, "thread events"}, |
1900040c | 6234 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6235 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6236 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6237 | {bp_exception_master, "exception master"}, |
ce78b96d | 6238 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6239 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6240 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6241 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6242 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6243 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6244 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6245 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6246 | }; |
269b11a2 PA |
6247 | |
6248 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6249 | || ((int) type != bptypes[(int) type].type)) | |
6250 | internal_error (__FILE__, __LINE__, | |
6251 | _("bptypes table does not describe type #%d."), | |
6252 | (int) type); | |
6253 | ||
6254 | return bptypes[(int) type].description; | |
6255 | } | |
6256 | ||
998580f1 MK |
6257 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6258 | For CLI, prefix the list with the string 'inf'. */ | |
6259 | ||
6260 | static void | |
6261 | output_thread_groups (struct ui_out *uiout, | |
6262 | const char *field_name, | |
6263 | VEC(int) *inf_num, | |
6264 | int mi_only) | |
6265 | { | |
112e8700 | 6266 | int is_mi = uiout->is_mi_like_p (); |
998580f1 MK |
6267 | int inf; |
6268 | int i; | |
6269 | ||
6270 | /* For backward compatibility, don't display inferiors in CLI unless | |
6271 | there are several. Always display them for MI. */ | |
6272 | if (!is_mi && mi_only) | |
6273 | return; | |
6274 | ||
10f489e5 | 6275 | ui_out_emit_list list_emitter (uiout, field_name); |
752eb8b4 | 6276 | |
998580f1 MK |
6277 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6278 | { | |
6279 | if (is_mi) | |
6280 | { | |
6281 | char mi_group[10]; | |
6282 | ||
6283 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
112e8700 | 6284 | uiout->field_string (NULL, mi_group); |
998580f1 MK |
6285 | } |
6286 | else | |
6287 | { | |
6288 | if (i == 0) | |
112e8700 | 6289 | uiout->text (" inf "); |
998580f1 | 6290 | else |
112e8700 | 6291 | uiout->text (", "); |
998580f1 | 6292 | |
112e8700 | 6293 | uiout->text (plongest (inf)); |
998580f1 MK |
6294 | } |
6295 | } | |
998580f1 MK |
6296 | } |
6297 | ||
269b11a2 PA |
6298 | /* Print B to gdb_stdout. */ |
6299 | ||
6300 | static void | |
6301 | print_one_breakpoint_location (struct breakpoint *b, | |
6302 | struct bp_location *loc, | |
6303 | int loc_number, | |
6304 | struct bp_location **last_loc, | |
269b11a2 PA |
6305 | int allflag) |
6306 | { | |
6307 | struct command_line *l; | |
c2c6d25f | 6308 | static char bpenables[] = "nynny"; |
c906108c | 6309 | |
79a45e25 | 6310 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6311 | int header_of_multiple = 0; |
6312 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6313 | struct value_print_options opts; |
6314 | ||
6315 | get_user_print_options (&opts); | |
0d381245 VP |
6316 | |
6317 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6318 | /* See comment in print_one_breakpoint concerning treatment of |
6319 | breakpoints with single disabled location. */ | |
0d381245 VP |
6320 | if (loc == NULL |
6321 | && (b->loc != NULL | |
6322 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6323 | header_of_multiple = 1; | |
6324 | if (loc == NULL) | |
6325 | loc = b->loc; | |
6326 | ||
c4093a6a JM |
6327 | annotate_record (); |
6328 | ||
6329 | /* 1 */ | |
6330 | annotate_field (0); | |
0d381245 VP |
6331 | if (part_of_multiple) |
6332 | { | |
6333 | char *formatted; | |
0c6773c1 | 6334 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
112e8700 | 6335 | uiout->field_string ("number", formatted); |
0d381245 VP |
6336 | xfree (formatted); |
6337 | } | |
6338 | else | |
6339 | { | |
112e8700 | 6340 | uiout->field_int ("number", b->number); |
0d381245 | 6341 | } |
c4093a6a JM |
6342 | |
6343 | /* 2 */ | |
6344 | annotate_field (1); | |
0d381245 | 6345 | if (part_of_multiple) |
112e8700 | 6346 | uiout->field_skip ("type"); |
269b11a2 | 6347 | else |
112e8700 | 6348 | uiout->field_string ("type", bptype_string (b->type)); |
c4093a6a JM |
6349 | |
6350 | /* 3 */ | |
6351 | annotate_field (2); | |
0d381245 | 6352 | if (part_of_multiple) |
112e8700 | 6353 | uiout->field_skip ("disp"); |
0d381245 | 6354 | else |
112e8700 | 6355 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
0d381245 | 6356 | |
c4093a6a JM |
6357 | |
6358 | /* 4 */ | |
6359 | annotate_field (3); | |
0d381245 | 6360 | if (part_of_multiple) |
112e8700 | 6361 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6362 | else |
112e8700 SM |
6363 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
6364 | uiout->spaces (2); | |
0d381245 | 6365 | |
c4093a6a JM |
6366 | |
6367 | /* 5 and 6 */ | |
3086aeae | 6368 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6369 | { |
4a64f543 MS |
6370 | /* Although the print_one can possibly print all locations, |
6371 | calling it here is not likely to get any nice result. So, | |
6372 | make sure there's just one location. */ | |
0d381245 | 6373 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6374 | b->ops->print_one (b, last_loc); |
0d381245 | 6375 | } |
3086aeae DJ |
6376 | else |
6377 | switch (b->type) | |
6378 | { | |
6379 | case bp_none: | |
6380 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6381 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6382 | break; |
c906108c | 6383 | |
3086aeae DJ |
6384 | case bp_watchpoint: |
6385 | case bp_hardware_watchpoint: | |
6386 | case bp_read_watchpoint: | |
6387 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6388 | { |
6389 | struct watchpoint *w = (struct watchpoint *) b; | |
6390 | ||
6391 | /* Field 4, the address, is omitted (which makes the columns | |
6392 | not line up too nicely with the headers, but the effect | |
6393 | is relatively readable). */ | |
6394 | if (opts.addressprint) | |
112e8700 | 6395 | uiout->field_skip ("addr"); |
3a5c3e22 | 6396 | annotate_field (5); |
112e8700 | 6397 | uiout->field_string ("what", w->exp_string); |
3a5c3e22 | 6398 | } |
3086aeae DJ |
6399 | break; |
6400 | ||
3086aeae DJ |
6401 | case bp_breakpoint: |
6402 | case bp_hardware_breakpoint: | |
7c16b83e | 6403 | case bp_single_step: |
3086aeae DJ |
6404 | case bp_until: |
6405 | case bp_finish: | |
6406 | case bp_longjmp: | |
6407 | case bp_longjmp_resume: | |
e2e4d78b | 6408 | case bp_longjmp_call_dummy: |
186c406b TT |
6409 | case bp_exception: |
6410 | case bp_exception_resume: | |
3086aeae | 6411 | case bp_step_resume: |
2c03e5be | 6412 | case bp_hp_step_resume: |
3086aeae DJ |
6413 | case bp_watchpoint_scope: |
6414 | case bp_call_dummy: | |
aa7d318d | 6415 | case bp_std_terminate: |
3086aeae DJ |
6416 | case bp_shlib_event: |
6417 | case bp_thread_event: | |
6418 | case bp_overlay_event: | |
0fd8e87f | 6419 | case bp_longjmp_master: |
aa7d318d | 6420 | case bp_std_terminate_master: |
186c406b | 6421 | case bp_exception_master: |
1042e4c0 | 6422 | case bp_tracepoint: |
7a697b8d | 6423 | case bp_fast_tracepoint: |
0fb4aa4b | 6424 | case bp_static_tracepoint: |
e7e0cddf | 6425 | case bp_dprintf: |
4efc6507 | 6426 | case bp_jit_event: |
0e30163f JK |
6427 | case bp_gnu_ifunc_resolver: |
6428 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6429 | if (opts.addressprint) |
3086aeae DJ |
6430 | { |
6431 | annotate_field (4); | |
54e52265 | 6432 | if (header_of_multiple) |
112e8700 | 6433 | uiout->field_string ("addr", "<MULTIPLE>"); |
e9bbd7c5 | 6434 | else if (b->loc == NULL || loc->shlib_disabled) |
112e8700 | 6435 | uiout->field_string ("addr", "<PENDING>"); |
0101ce28 | 6436 | else |
112e8700 | 6437 | uiout->field_core_addr ("addr", |
5af949e3 | 6438 | loc->gdbarch, loc->address); |
3086aeae DJ |
6439 | } |
6440 | annotate_field (5); | |
0d381245 | 6441 | if (!header_of_multiple) |
170b53b2 | 6442 | print_breakpoint_location (b, loc); |
0d381245 | 6443 | if (b->loc) |
a6d9a66e | 6444 | *last_loc = b->loc; |
3086aeae DJ |
6445 | break; |
6446 | } | |
c906108c | 6447 | |
6c95b8df | 6448 | |
998580f1 | 6449 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6450 | { |
6451 | struct inferior *inf; | |
998580f1 MK |
6452 | VEC(int) *inf_num = NULL; |
6453 | int mi_only = 1; | |
6c95b8df | 6454 | |
998580f1 | 6455 | ALL_INFERIORS (inf) |
6c95b8df PA |
6456 | { |
6457 | if (inf->pspace == loc->pspace) | |
998580f1 | 6458 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6459 | } |
998580f1 MK |
6460 | |
6461 | /* For backward compatibility, don't display inferiors in CLI unless | |
6462 | there are several. Always display for MI. */ | |
6463 | if (allflag | |
6464 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6465 | && (number_of_program_spaces () > 1 | |
6466 | || number_of_inferiors () > 1) | |
6467 | /* LOC is for existing B, it cannot be in | |
6468 | moribund_locations and thus having NULL OWNER. */ | |
6469 | && loc->owner->type != bp_catchpoint)) | |
6470 | mi_only = 0; | |
6471 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6472 | VEC_free (int, inf_num); | |
6c95b8df PA |
6473 | } |
6474 | ||
4a306c9a | 6475 | if (!part_of_multiple) |
c4093a6a | 6476 | { |
4a306c9a JB |
6477 | if (b->thread != -1) |
6478 | { | |
6479 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6480 | "stop only in" line a little further down. */ |
112e8700 SM |
6481 | uiout->text (" thread "); |
6482 | uiout->field_int ("thread", b->thread); | |
4a306c9a JB |
6483 | } |
6484 | else if (b->task != 0) | |
6485 | { | |
112e8700 SM |
6486 | uiout->text (" task "); |
6487 | uiout->field_int ("task", b->task); | |
4a306c9a | 6488 | } |
c4093a6a | 6489 | } |
f1310107 | 6490 | |
112e8700 | 6491 | uiout->text ("\n"); |
f1310107 | 6492 | |
348d480f | 6493 | if (!part_of_multiple) |
f1310107 TJB |
6494 | b->ops->print_one_detail (b, uiout); |
6495 | ||
0d381245 | 6496 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6497 | { |
6498 | annotate_field (6); | |
112e8700 | 6499 | uiout->text ("\tstop only in stack frame at "); |
e5dd4106 | 6500 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6501 | the frame ID. */ |
112e8700 | 6502 | uiout->field_core_addr ("frame", |
5af949e3 | 6503 | b->gdbarch, b->frame_id.stack_addr); |
112e8700 | 6504 | uiout->text ("\n"); |
c4093a6a JM |
6505 | } |
6506 | ||
28010a5d | 6507 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6508 | { |
6509 | annotate_field (7); | |
d77f58be | 6510 | if (is_tracepoint (b)) |
112e8700 | 6511 | uiout->text ("\ttrace only if "); |
1042e4c0 | 6512 | else |
112e8700 SM |
6513 | uiout->text ("\tstop only if "); |
6514 | uiout->field_string ("cond", b->cond_string); | |
b775012e LM |
6515 | |
6516 | /* Print whether the target is doing the breakpoint's condition | |
6517 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6518 | if (is_breakpoint (b) | |
6519 | && breakpoint_condition_evaluation_mode () | |
6520 | == condition_evaluation_target) | |
6521 | { | |
112e8700 SM |
6522 | uiout->text (" ("); |
6523 | uiout->field_string ("evaluated-by", | |
b775012e | 6524 | bp_condition_evaluator (b)); |
112e8700 | 6525 | uiout->text (" evals)"); |
b775012e | 6526 | } |
112e8700 | 6527 | uiout->text ("\n"); |
0101ce28 JJ |
6528 | } |
6529 | ||
0d381245 | 6530 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6531 | { |
4a64f543 | 6532 | /* FIXME should make an annotation for this. */ |
112e8700 SM |
6533 | uiout->text ("\tstop only in thread "); |
6534 | if (uiout->is_mi_like_p ()) | |
6535 | uiout->field_int ("thread", b->thread); | |
5d5658a1 PA |
6536 | else |
6537 | { | |
6538 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6539 | ||
112e8700 | 6540 | uiout->field_string ("thread", print_thread_id (thr)); |
5d5658a1 | 6541 | } |
112e8700 | 6542 | uiout->text ("\n"); |
c4093a6a JM |
6543 | } |
6544 | ||
556ec64d YQ |
6545 | if (!part_of_multiple) |
6546 | { | |
6547 | if (b->hit_count) | |
31f56a27 YQ |
6548 | { |
6549 | /* FIXME should make an annotation for this. */ | |
6550 | if (is_catchpoint (b)) | |
112e8700 | 6551 | uiout->text ("\tcatchpoint"); |
31f56a27 | 6552 | else if (is_tracepoint (b)) |
112e8700 | 6553 | uiout->text ("\ttracepoint"); |
31f56a27 | 6554 | else |
112e8700 SM |
6555 | uiout->text ("\tbreakpoint"); |
6556 | uiout->text (" already hit "); | |
6557 | uiout->field_int ("times", b->hit_count); | |
31f56a27 | 6558 | if (b->hit_count == 1) |
112e8700 | 6559 | uiout->text (" time\n"); |
31f56a27 | 6560 | else |
112e8700 | 6561 | uiout->text (" times\n"); |
31f56a27 | 6562 | } |
556ec64d YQ |
6563 | else |
6564 | { | |
31f56a27 | 6565 | /* Output the count also if it is zero, but only if this is mi. */ |
112e8700 SM |
6566 | if (uiout->is_mi_like_p ()) |
6567 | uiout->field_int ("times", b->hit_count); | |
556ec64d YQ |
6568 | } |
6569 | } | |
8b93c638 | 6570 | |
0d381245 | 6571 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6572 | { |
6573 | annotate_field (8); | |
112e8700 SM |
6574 | uiout->text ("\tignore next "); |
6575 | uiout->field_int ("ignore", b->ignore_count); | |
6576 | uiout->text (" hits\n"); | |
c4093a6a | 6577 | } |
059fb39f | 6578 | |
816338b5 SS |
6579 | /* Note that an enable count of 1 corresponds to "enable once" |
6580 | behavior, which is reported by the combination of enablement and | |
6581 | disposition, so we don't need to mention it here. */ | |
6582 | if (!part_of_multiple && b->enable_count > 1) | |
6583 | { | |
6584 | annotate_field (8); | |
112e8700 | 6585 | uiout->text ("\tdisable after "); |
816338b5 SS |
6586 | /* Tweak the wording to clarify that ignore and enable counts |
6587 | are distinct, and have additive effect. */ | |
6588 | if (b->ignore_count) | |
112e8700 | 6589 | uiout->text ("additional "); |
816338b5 | 6590 | else |
112e8700 SM |
6591 | uiout->text ("next "); |
6592 | uiout->field_int ("enable", b->enable_count); | |
6593 | uiout->text (" hits\n"); | |
816338b5 SS |
6594 | } |
6595 | ||
f196051f SS |
6596 | if (!part_of_multiple && is_tracepoint (b)) |
6597 | { | |
6598 | struct tracepoint *tp = (struct tracepoint *) b; | |
6599 | ||
6600 | if (tp->traceframe_usage) | |
6601 | { | |
112e8700 SM |
6602 | uiout->text ("\ttrace buffer usage "); |
6603 | uiout->field_int ("traceframe-usage", tp->traceframe_usage); | |
6604 | uiout->text (" bytes\n"); | |
f196051f SS |
6605 | } |
6606 | } | |
d3ce09f5 | 6607 | |
9add0f1b | 6608 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6609 | if (!part_of_multiple && l) |
c4093a6a JM |
6610 | { |
6611 | annotate_field (9); | |
2e783024 | 6612 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
8b93c638 | 6613 | print_command_lines (uiout, l, 4); |
c4093a6a | 6614 | } |
d24317b4 | 6615 | |
d9b3f62e | 6616 | if (is_tracepoint (b)) |
1042e4c0 | 6617 | { |
d9b3f62e PA |
6618 | struct tracepoint *t = (struct tracepoint *) b; |
6619 | ||
6620 | if (!part_of_multiple && t->pass_count) | |
6621 | { | |
6622 | annotate_field (10); | |
112e8700 SM |
6623 | uiout->text ("\tpass count "); |
6624 | uiout->field_int ("pass", t->pass_count); | |
6625 | uiout->text (" \n"); | |
d9b3f62e | 6626 | } |
f2a8bc8a YQ |
6627 | |
6628 | /* Don't display it when tracepoint or tracepoint location is | |
6629 | pending. */ | |
6630 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6631 | { | |
6632 | annotate_field (11); | |
6633 | ||
112e8700 SM |
6634 | if (uiout->is_mi_like_p ()) |
6635 | uiout->field_string ("installed", | |
f2a8bc8a YQ |
6636 | loc->inserted ? "y" : "n"); |
6637 | else | |
6638 | { | |
6639 | if (loc->inserted) | |
112e8700 | 6640 | uiout->text ("\t"); |
f2a8bc8a | 6641 | else |
112e8700 SM |
6642 | uiout->text ("\tnot "); |
6643 | uiout->text ("installed on target\n"); | |
f2a8bc8a YQ |
6644 | } |
6645 | } | |
1042e4c0 SS |
6646 | } |
6647 | ||
112e8700 | 6648 | if (uiout->is_mi_like_p () && !part_of_multiple) |
d24317b4 | 6649 | { |
3a5c3e22 PA |
6650 | if (is_watchpoint (b)) |
6651 | { | |
6652 | struct watchpoint *w = (struct watchpoint *) b; | |
6653 | ||
112e8700 | 6654 | uiout->field_string ("original-location", w->exp_string); |
3a5c3e22 | 6655 | } |
f00aae0f | 6656 | else if (b->location != NULL |
d28cd78a | 6657 | && event_location_to_string (b->location.get ()) != NULL) |
112e8700 | 6658 | uiout->field_string ("original-location", |
d28cd78a | 6659 | event_location_to_string (b->location.get ())); |
d24317b4 | 6660 | } |
c4093a6a | 6661 | } |
c5aa993b | 6662 | |
0d381245 VP |
6663 | static void |
6664 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6665 | struct bp_location **last_loc, |
6c95b8df | 6666 | int allflag) |
0d381245 | 6667 | { |
79a45e25 | 6668 | struct ui_out *uiout = current_uiout; |
8d3788bd | 6669 | |
2e783024 TT |
6670 | { |
6671 | ui_out_emit_tuple tuple_emitter (uiout, "bkpt"); | |
8d3788bd | 6672 | |
2e783024 TT |
6673 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
6674 | } | |
0d381245 VP |
6675 | |
6676 | /* If this breakpoint has custom print function, | |
6677 | it's already printed. Otherwise, print individual | |
6678 | locations, if any. */ | |
6679 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6680 | { | |
4a64f543 MS |
6681 | /* If breakpoint has a single location that is disabled, we |
6682 | print it as if it had several locations, since otherwise it's | |
6683 | hard to represent "breakpoint enabled, location disabled" | |
6684 | situation. | |
6685 | ||
6686 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6687 | internally, that's not a property exposed to user. */ |
0d381245 | 6688 | if (b->loc |
a5606eee | 6689 | && !is_hardware_watchpoint (b) |
8d3788bd | 6690 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6691 | { |
6692 | struct bp_location *loc; | |
6693 | int n = 1; | |
8d3788bd | 6694 | |
0d381245 | 6695 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd | 6696 | { |
2e783024 | 6697 | ui_out_emit_tuple tuple_emitter (uiout, NULL); |
8d3788bd | 6698 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
8d3788bd | 6699 | } |
0d381245 VP |
6700 | } |
6701 | } | |
6702 | } | |
6703 | ||
a6d9a66e UW |
6704 | static int |
6705 | breakpoint_address_bits (struct breakpoint *b) | |
6706 | { | |
6707 | int print_address_bits = 0; | |
6708 | struct bp_location *loc; | |
6709 | ||
c6d81124 PA |
6710 | /* Software watchpoints that aren't watching memory don't have an |
6711 | address to print. */ | |
6712 | if (is_no_memory_software_watchpoint (b)) | |
6713 | return 0; | |
6714 | ||
a6d9a66e UW |
6715 | for (loc = b->loc; loc; loc = loc->next) |
6716 | { | |
c7437ca6 PA |
6717 | int addr_bit; |
6718 | ||
c7437ca6 | 6719 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6720 | if (addr_bit > print_address_bits) |
6721 | print_address_bits = addr_bit; | |
6722 | } | |
6723 | ||
6724 | return print_address_bits; | |
6725 | } | |
0d381245 | 6726 | |
c4093a6a JM |
6727 | struct captured_breakpoint_query_args |
6728 | { | |
6729 | int bnum; | |
6730 | }; | |
c5aa993b | 6731 | |
c4093a6a | 6732 | static int |
2b65245e | 6733 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6734 | { |
9a3c8263 SM |
6735 | struct captured_breakpoint_query_args *args |
6736 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6737 | struct breakpoint *b; |
a6d9a66e | 6738 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6739 | |
c4093a6a JM |
6740 | ALL_BREAKPOINTS (b) |
6741 | { | |
6742 | if (args->bnum == b->number) | |
c5aa993b | 6743 | { |
12c5a436 | 6744 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6745 | return GDB_RC_OK; |
c5aa993b | 6746 | } |
c4093a6a JM |
6747 | } |
6748 | return GDB_RC_NONE; | |
6749 | } | |
c5aa993b | 6750 | |
c4093a6a | 6751 | enum gdb_rc |
4a64f543 MS |
6752 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6753 | char **error_message) | |
c4093a6a JM |
6754 | { |
6755 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6756 | |
c4093a6a JM |
6757 | args.bnum = bnum; |
6758 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6759 | an error. */ |
b0b13bb4 DJ |
6760 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6761 | error_message, RETURN_MASK_ALL) < 0) | |
6762 | return GDB_RC_FAIL; | |
6763 | else | |
6764 | return GDB_RC_OK; | |
c4093a6a | 6765 | } |
c5aa993b | 6766 | |
09d682a4 TT |
6767 | /* Return true if this breakpoint was set by the user, false if it is |
6768 | internal or momentary. */ | |
6769 | ||
6770 | int | |
6771 | user_breakpoint_p (struct breakpoint *b) | |
6772 | { | |
46c6471b | 6773 | return b->number > 0; |
09d682a4 TT |
6774 | } |
6775 | ||
93daf339 TT |
6776 | /* See breakpoint.h. */ |
6777 | ||
6778 | int | |
6779 | pending_breakpoint_p (struct breakpoint *b) | |
6780 | { | |
6781 | return b->loc == NULL; | |
6782 | } | |
6783 | ||
7f3b0473 | 6784 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6785 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6786 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6787 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6788 | ones for which it returns non-zero. Return the total number of | |
6789 | breakpoints listed. */ | |
c906108c | 6790 | |
d77f58be | 6791 | static int |
e5a67952 | 6792 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6793 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6794 | { |
52f0bd74 | 6795 | struct breakpoint *b; |
a6d9a66e | 6796 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6797 | int nr_printable_breakpoints; |
79a45b7d | 6798 | struct value_print_options opts; |
a6d9a66e | 6799 | int print_address_bits = 0; |
269b11a2 | 6800 | int print_type_col_width = 14; |
79a45e25 | 6801 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6802 | |
79a45b7d TT |
6803 | get_user_print_options (&opts); |
6804 | ||
4a64f543 MS |
6805 | /* Compute the number of rows in the table, as well as the size |
6806 | required for address fields. */ | |
7f3b0473 AC |
6807 | nr_printable_breakpoints = 0; |
6808 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6809 | { |
6810 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6811 | if (filter && !filter (b)) | |
6812 | continue; | |
6813 | ||
6814 | /* If we have an "args" string, it is a list of breakpoints to | |
6815 | accept. Skip the others. */ | |
6816 | if (args != NULL && *args != '\0') | |
6817 | { | |
6818 | if (allflag && parse_and_eval_long (args) != b->number) | |
6819 | continue; | |
6820 | if (!allflag && !number_is_in_list (args, b->number)) | |
6821 | continue; | |
6822 | } | |
269b11a2 | 6823 | |
e5a67952 MS |
6824 | if (allflag || user_breakpoint_p (b)) |
6825 | { | |
6826 | int addr_bit, type_len; | |
a6d9a66e | 6827 | |
e5a67952 MS |
6828 | addr_bit = breakpoint_address_bits (b); |
6829 | if (addr_bit > print_address_bits) | |
6830 | print_address_bits = addr_bit; | |
269b11a2 | 6831 | |
e5a67952 MS |
6832 | type_len = strlen (bptype_string (b->type)); |
6833 | if (type_len > print_type_col_width) | |
6834 | print_type_col_width = type_len; | |
6835 | ||
6836 | nr_printable_breakpoints++; | |
6837 | } | |
6838 | } | |
7f3b0473 | 6839 | |
4a2b031d TT |
6840 | { |
6841 | ui_out_emit_table table_emitter (uiout, | |
6842 | opts.addressprint ? 6 : 5, | |
6843 | nr_printable_breakpoints, | |
6844 | "BreakpointTable"); | |
6845 | ||
6846 | if (nr_printable_breakpoints > 0) | |
6847 | annotate_breakpoints_headers (); | |
6848 | if (nr_printable_breakpoints > 0) | |
6849 | annotate_field (0); | |
6850 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ | |
6851 | if (nr_printable_breakpoints > 0) | |
6852 | annotate_field (1); | |
6853 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ | |
6854 | if (nr_printable_breakpoints > 0) | |
6855 | annotate_field (2); | |
6856 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ | |
6857 | if (nr_printable_breakpoints > 0) | |
6858 | annotate_field (3); | |
6859 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ | |
6860 | if (opts.addressprint) | |
6861 | { | |
6862 | if (nr_printable_breakpoints > 0) | |
6863 | annotate_field (4); | |
6864 | if (print_address_bits <= 32) | |
6865 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ | |
6866 | else | |
6867 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ | |
6868 | } | |
6869 | if (nr_printable_breakpoints > 0) | |
6870 | annotate_field (5); | |
6871 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ | |
6872 | uiout->table_body (); | |
6873 | if (nr_printable_breakpoints > 0) | |
6874 | annotate_breakpoints_table (); | |
6875 | ||
6876 | ALL_BREAKPOINTS (b) | |
6877 | { | |
6878 | QUIT; | |
6879 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6880 | if (filter && !filter (b)) | |
6881 | continue; | |
e5a67952 | 6882 | |
4a2b031d TT |
6883 | /* If we have an "args" string, it is a list of breakpoints to |
6884 | accept. Skip the others. */ | |
e5a67952 | 6885 | |
4a2b031d TT |
6886 | if (args != NULL && *args != '\0') |
6887 | { | |
6888 | if (allflag) /* maintenance info breakpoint */ | |
6889 | { | |
6890 | if (parse_and_eval_long (args) != b->number) | |
6891 | continue; | |
6892 | } | |
6893 | else /* all others */ | |
6894 | { | |
6895 | if (!number_is_in_list (args, b->number)) | |
6896 | continue; | |
6897 | } | |
6898 | } | |
6899 | /* We only print out user settable breakpoints unless the | |
6900 | allflag is set. */ | |
6901 | if (allflag || user_breakpoint_p (b)) | |
6902 | print_one_breakpoint (b, &last_loc, allflag); | |
6903 | } | |
6904 | } | |
698384cd | 6905 | |
7f3b0473 | 6906 | if (nr_printable_breakpoints == 0) |
c906108c | 6907 | { |
4a64f543 MS |
6908 | /* If there's a filter, let the caller decide how to report |
6909 | empty list. */ | |
d77f58be SS |
6910 | if (!filter) |
6911 | { | |
e5a67952 | 6912 | if (args == NULL || *args == '\0') |
112e8700 | 6913 | uiout->message ("No breakpoints or watchpoints.\n"); |
d77f58be | 6914 | else |
112e8700 | 6915 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
e5a67952 | 6916 | args); |
d77f58be | 6917 | } |
c906108c SS |
6918 | } |
6919 | else | |
c4093a6a | 6920 | { |
a6d9a66e UW |
6921 | if (last_loc && !server_command) |
6922 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6923 | } |
c906108c | 6924 | |
4a64f543 | 6925 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6926 | there have been breakpoints? */ |
c906108c | 6927 | annotate_breakpoints_table_end (); |
d77f58be SS |
6928 | |
6929 | return nr_printable_breakpoints; | |
c906108c SS |
6930 | } |
6931 | ||
ad443146 SS |
6932 | /* Display the value of default-collect in a way that is generally |
6933 | compatible with the breakpoint list. */ | |
6934 | ||
6935 | static void | |
6936 | default_collect_info (void) | |
6937 | { | |
79a45e25 PA |
6938 | struct ui_out *uiout = current_uiout; |
6939 | ||
ad443146 SS |
6940 | /* If it has no value (which is frequently the case), say nothing; a |
6941 | message like "No default-collect." gets in user's face when it's | |
6942 | not wanted. */ | |
6943 | if (!*default_collect) | |
6944 | return; | |
6945 | ||
6946 | /* The following phrase lines up nicely with per-tracepoint collect | |
6947 | actions. */ | |
112e8700 SM |
6948 | uiout->text ("default collect "); |
6949 | uiout->field_string ("default-collect", default_collect); | |
6950 | uiout->text (" \n"); | |
ad443146 SS |
6951 | } |
6952 | ||
c906108c | 6953 | static void |
11db9430 | 6954 | info_breakpoints_command (char *args, int from_tty) |
c906108c | 6955 | { |
e5a67952 | 6956 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6957 | |
6958 | default_collect_info (); | |
d77f58be SS |
6959 | } |
6960 | ||
6961 | static void | |
11db9430 | 6962 | info_watchpoints_command (char *args, int from_tty) |
d77f58be | 6963 | { |
e5a67952 | 6964 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6965 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6966 | |
6967 | if (num_printed == 0) | |
6968 | { | |
e5a67952 | 6969 | if (args == NULL || *args == '\0') |
112e8700 | 6970 | uiout->message ("No watchpoints.\n"); |
d77f58be | 6971 | else |
112e8700 | 6972 | uiout->message ("No watchpoint matching '%s'.\n", args); |
d77f58be | 6973 | } |
c906108c SS |
6974 | } |
6975 | ||
7a292a7a | 6976 | static void |
e5a67952 | 6977 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6978 | { |
e5a67952 | 6979 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6980 | |
6981 | default_collect_info (); | |
c906108c SS |
6982 | } |
6983 | ||
0d381245 | 6984 | static int |
714835d5 | 6985 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 6986 | struct program_space *pspace, |
714835d5 | 6987 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
6988 | { |
6989 | struct bp_location *bl = b->loc; | |
cc59ec59 | 6990 | |
0d381245 VP |
6991 | for (; bl; bl = bl->next) |
6992 | { | |
6c95b8df PA |
6993 | if (bl->pspace == pspace |
6994 | && bl->address == pc | |
0d381245 VP |
6995 | && (!overlay_debugging || bl->section == section)) |
6996 | return 1; | |
6997 | } | |
6998 | return 0; | |
6999 | } | |
7000 | ||
672f9b60 | 7001 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7002 | concerns with logical breakpoints, so we match program spaces, not |
7003 | address spaces. */ | |
c906108c SS |
7004 | |
7005 | static void | |
6c95b8df PA |
7006 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7007 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7008 | struct obj_section *section, int thread) |
c906108c | 7009 | { |
52f0bd74 AC |
7010 | int others = 0; |
7011 | struct breakpoint *b; | |
c906108c SS |
7012 | |
7013 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7014 | others += (user_breakpoint_p (b) |
7015 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7016 | if (others > 0) |
7017 | { | |
a3f17187 AC |
7018 | if (others == 1) |
7019 | printf_filtered (_("Note: breakpoint ")); | |
7020 | else /* if (others == ???) */ | |
7021 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7022 | ALL_BREAKPOINTS (b) |
672f9b60 | 7023 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7024 | { |
7025 | others--; | |
7026 | printf_filtered ("%d", b->number); | |
7027 | if (b->thread == -1 && thread != -1) | |
7028 | printf_filtered (" (all threads)"); | |
7029 | else if (b->thread != -1) | |
7030 | printf_filtered (" (thread %d)", b->thread); | |
7031 | printf_filtered ("%s%s ", | |
059fb39f | 7032 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7033 | || b->enable_state == bp_call_disabled) |
0d381245 | 7034 | ? " (disabled)" |
0d381245 VP |
7035 | : ""), |
7036 | (others > 1) ? "," | |
7037 | : ((others == 1) ? " and" : "")); | |
7038 | } | |
a3f17187 | 7039 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7040 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7041 | printf_filtered (".\n"); |
7042 | } | |
7043 | } | |
7044 | \f | |
c906108c | 7045 | |
e4f237da | 7046 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7047 | BPT locations. For some breakpoint types, the locations' address members |
7048 | are irrelevant and it makes no sense to attempt to compare them to other | |
7049 | addresses (or use them for any other purpose either). | |
e4f237da | 7050 | |
4a64f543 | 7051 | More specifically, each of the following breakpoint types will |
244558af | 7052 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7053 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7054 | breakpoint location at address zero: |
e4f237da KB |
7055 | |
7056 | bp_watchpoint | |
2d134ed3 PA |
7057 | bp_catchpoint |
7058 | ||
7059 | */ | |
e4f237da KB |
7060 | |
7061 | static int | |
7062 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7063 | { | |
7064 | enum bptype type = bpt->type; | |
7065 | ||
2d134ed3 PA |
7066 | return (type != bp_watchpoint && type != bp_catchpoint); |
7067 | } | |
7068 | ||
7069 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7070 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7071 | ||
7072 | static int | |
4a64f543 MS |
7073 | watchpoint_locations_match (struct bp_location *loc1, |
7074 | struct bp_location *loc2) | |
2d134ed3 | 7075 | { |
3a5c3e22 PA |
7076 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7077 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7078 | ||
7079 | /* Both of them must exist. */ | |
7080 | gdb_assert (w1 != NULL); | |
7081 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7082 | |
4a64f543 MS |
7083 | /* If the target can evaluate the condition expression in hardware, |
7084 | then we we need to insert both watchpoints even if they are at | |
7085 | the same place. Otherwise the watchpoint will only trigger when | |
7086 | the condition of whichever watchpoint was inserted evaluates to | |
7087 | true, not giving a chance for GDB to check the condition of the | |
7088 | other watchpoint. */ | |
3a5c3e22 | 7089 | if ((w1->cond_exp |
4a64f543 MS |
7090 | && target_can_accel_watchpoint_condition (loc1->address, |
7091 | loc1->length, | |
0cf6dd15 | 7092 | loc1->watchpoint_type, |
4d01a485 | 7093 | w1->cond_exp.get ())) |
3a5c3e22 | 7094 | || (w2->cond_exp |
4a64f543 MS |
7095 | && target_can_accel_watchpoint_condition (loc2->address, |
7096 | loc2->length, | |
0cf6dd15 | 7097 | loc2->watchpoint_type, |
4d01a485 | 7098 | w2->cond_exp.get ()))) |
0cf6dd15 TJB |
7099 | return 0; |
7100 | ||
85d721b8 PA |
7101 | /* Note that this checks the owner's type, not the location's. In |
7102 | case the target does not support read watchpoints, but does | |
7103 | support access watchpoints, we'll have bp_read_watchpoint | |
7104 | watchpoints with hw_access locations. Those should be considered | |
7105 | duplicates of hw_read locations. The hw_read locations will | |
7106 | become hw_access locations later. */ | |
2d134ed3 PA |
7107 | return (loc1->owner->type == loc2->owner->type |
7108 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7109 | && loc1->address == loc2->address | |
7110 | && loc1->length == loc2->length); | |
e4f237da KB |
7111 | } |
7112 | ||
31e77af2 | 7113 | /* See breakpoint.h. */ |
6c95b8df | 7114 | |
31e77af2 | 7115 | int |
6c95b8df PA |
7116 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7117 | struct address_space *aspace2, CORE_ADDR addr2) | |
7118 | { | |
f5656ead | 7119 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7120 | || aspace1 == aspace2) |
7121 | && addr1 == addr2); | |
7122 | } | |
7123 | ||
f1310107 TJB |
7124 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7125 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7126 | matches ASPACE2. On targets that have global breakpoints, the address | |
7127 | space doesn't really matter. */ | |
7128 | ||
7129 | static int | |
7130 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7131 | int len1, struct address_space *aspace2, | |
7132 | CORE_ADDR addr2) | |
7133 | { | |
f5656ead | 7134 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7135 | || aspace1 == aspace2) |
7136 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7137 | } | |
7138 | ||
7139 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7140 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7141 | matches the breakpoint's address space. On targets that have global | |
7142 | breakpoints, the address space doesn't really matter. */ | |
7143 | ||
7144 | static int | |
7145 | breakpoint_location_address_match (struct bp_location *bl, | |
7146 | struct address_space *aspace, | |
7147 | CORE_ADDR addr) | |
7148 | { | |
7149 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7150 | aspace, addr) | |
7151 | || (bl->length | |
7152 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7153 | bl->address, bl->length, | |
7154 | aspace, addr))); | |
7155 | } | |
7156 | ||
d35ae833 PA |
7157 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7158 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7159 | match happens only if ASPACE matches the breakpoint's address | |
7160 | space. On targets that have global breakpoints, the address space | |
7161 | doesn't really matter. */ | |
7162 | ||
7163 | static int | |
7164 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7165 | struct address_space *aspace, | |
7166 | CORE_ADDR addr, int len) | |
7167 | { | |
7168 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7169 | || bl->pspace->aspace == aspace) | |
7170 | { | |
7171 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7172 | ||
7173 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7174 | return 1; | |
7175 | } | |
7176 | return 0; | |
7177 | } | |
7178 | ||
1e4d1764 YQ |
7179 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7180 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7181 | true, otherwise returns false. */ | |
7182 | ||
7183 | static int | |
7184 | tracepoint_locations_match (struct bp_location *loc1, | |
7185 | struct bp_location *loc2) | |
7186 | { | |
7187 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7188 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7189 | locations at the same address of different tracepoints are regarded as | |
7190 | different locations. */ | |
7191 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7192 | else | |
7193 | return 0; | |
7194 | } | |
7195 | ||
2d134ed3 PA |
7196 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7197 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7198 | represent the same location. */ | |
7199 | ||
7200 | static int | |
4a64f543 MS |
7201 | breakpoint_locations_match (struct bp_location *loc1, |
7202 | struct bp_location *loc2) | |
2d134ed3 | 7203 | { |
2bdf28a0 JK |
7204 | int hw_point1, hw_point2; |
7205 | ||
7206 | /* Both of them must not be in moribund_locations. */ | |
7207 | gdb_assert (loc1->owner != NULL); | |
7208 | gdb_assert (loc2->owner != NULL); | |
7209 | ||
7210 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7211 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7212 | |
7213 | if (hw_point1 != hw_point2) | |
7214 | return 0; | |
7215 | else if (hw_point1) | |
7216 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7217 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7218 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7219 | else |
f1310107 TJB |
7220 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7221 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7222 | loc2->pspace->aspace, loc2->address) | |
7223 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7224 | } |
7225 | ||
76897487 KB |
7226 | static void |
7227 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7228 | int bnum, int have_bnum) | |
7229 | { | |
f63fbe86 MS |
7230 | /* The longest string possibly returned by hex_string_custom |
7231 | is 50 chars. These must be at least that big for safety. */ | |
7232 | char astr1[64]; | |
7233 | char astr2[64]; | |
76897487 | 7234 | |
bb599908 PH |
7235 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7236 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7237 | if (have_bnum) |
8a3fe4f8 | 7238 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7239 | bnum, astr1, astr2); |
7240 | else | |
8a3fe4f8 | 7241 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7242 | } |
7243 | ||
4a64f543 MS |
7244 | /* Adjust a breakpoint's address to account for architectural |
7245 | constraints on breakpoint placement. Return the adjusted address. | |
7246 | Note: Very few targets require this kind of adjustment. For most | |
7247 | targets, this function is simply the identity function. */ | |
76897487 KB |
7248 | |
7249 | static CORE_ADDR | |
a6d9a66e UW |
7250 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7251 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7252 | { |
a6d9a66e | 7253 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7254 | { |
7255 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7256 | return bpaddr; | |
7257 | } | |
88f7da05 KB |
7258 | else if (bptype == bp_watchpoint |
7259 | || bptype == bp_hardware_watchpoint | |
7260 | || bptype == bp_read_watchpoint | |
7261 | || bptype == bp_access_watchpoint | |
fe798b75 | 7262 | || bptype == bp_catchpoint) |
88f7da05 KB |
7263 | { |
7264 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7265 | have their addresses modified. */ | |
7266 | return bpaddr; | |
7267 | } | |
7c16b83e PA |
7268 | else if (bptype == bp_single_step) |
7269 | { | |
7270 | /* Single-step breakpoints should not have their addresses | |
7271 | modified. If there's any architectural constrain that | |
7272 | applies to this address, then it should have already been | |
7273 | taken into account when the breakpoint was created in the | |
7274 | first place. If we didn't do this, stepping through e.g., | |
7275 | Thumb-2 IT blocks would break. */ | |
7276 | return bpaddr; | |
7277 | } | |
76897487 KB |
7278 | else |
7279 | { | |
7280 | CORE_ADDR adjusted_bpaddr; | |
7281 | ||
7282 | /* Some targets have architectural constraints on the placement | |
7283 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7284 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7285 | |
7286 | /* An adjusted breakpoint address can significantly alter | |
7287 | a user's expectations. Print a warning if an adjustment | |
7288 | is required. */ | |
7289 | if (adjusted_bpaddr != bpaddr) | |
7290 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7291 | ||
7292 | return adjusted_bpaddr; | |
7293 | } | |
7294 | } | |
7295 | ||
5625a286 | 7296 | bp_location::bp_location (const bp_location_ops *ops, breakpoint *owner) |
7cc221ef | 7297 | { |
5625a286 | 7298 | bp_location *loc = this; |
7cc221ef | 7299 | |
348d480f PA |
7300 | gdb_assert (ops != NULL); |
7301 | ||
28010a5d PA |
7302 | loc->ops = ops; |
7303 | loc->owner = owner; | |
b775012e | 7304 | loc->cond_bytecode = NULL; |
0d381245 VP |
7305 | loc->shlib_disabled = 0; |
7306 | loc->enabled = 1; | |
e049a4b5 | 7307 | |
28010a5d | 7308 | switch (owner->type) |
e049a4b5 DJ |
7309 | { |
7310 | case bp_breakpoint: | |
7c16b83e | 7311 | case bp_single_step: |
e049a4b5 DJ |
7312 | case bp_until: |
7313 | case bp_finish: | |
7314 | case bp_longjmp: | |
7315 | case bp_longjmp_resume: | |
e2e4d78b | 7316 | case bp_longjmp_call_dummy: |
186c406b TT |
7317 | case bp_exception: |
7318 | case bp_exception_resume: | |
e049a4b5 | 7319 | case bp_step_resume: |
2c03e5be | 7320 | case bp_hp_step_resume: |
e049a4b5 DJ |
7321 | case bp_watchpoint_scope: |
7322 | case bp_call_dummy: | |
aa7d318d | 7323 | case bp_std_terminate: |
e049a4b5 DJ |
7324 | case bp_shlib_event: |
7325 | case bp_thread_event: | |
7326 | case bp_overlay_event: | |
4efc6507 | 7327 | case bp_jit_event: |
0fd8e87f | 7328 | case bp_longjmp_master: |
aa7d318d | 7329 | case bp_std_terminate_master: |
186c406b | 7330 | case bp_exception_master: |
0e30163f JK |
7331 | case bp_gnu_ifunc_resolver: |
7332 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7333 | case bp_dprintf: |
e049a4b5 | 7334 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7335 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7336 | break; |
7337 | case bp_hardware_breakpoint: | |
7338 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7339 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7340 | break; |
7341 | case bp_hardware_watchpoint: | |
7342 | case bp_read_watchpoint: | |
7343 | case bp_access_watchpoint: | |
7344 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7345 | break; | |
7346 | case bp_watchpoint: | |
ce78b96d | 7347 | case bp_catchpoint: |
15c3d785 PA |
7348 | case bp_tracepoint: |
7349 | case bp_fast_tracepoint: | |
0fb4aa4b | 7350 | case bp_static_tracepoint: |
e049a4b5 DJ |
7351 | loc->loc_type = bp_loc_other; |
7352 | break; | |
7353 | default: | |
e2e0b3e5 | 7354 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7355 | } |
7356 | ||
f431efe5 | 7357 | loc->refc = 1; |
28010a5d PA |
7358 | } |
7359 | ||
7360 | /* Allocate a struct bp_location. */ | |
7361 | ||
7362 | static struct bp_location * | |
7363 | allocate_bp_location (struct breakpoint *bpt) | |
7364 | { | |
348d480f PA |
7365 | return bpt->ops->allocate_location (bpt); |
7366 | } | |
7cc221ef | 7367 | |
f431efe5 PA |
7368 | static void |
7369 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7370 | { |
348d480f | 7371 | loc->ops->dtor (loc); |
4d01a485 | 7372 | delete loc; |
fe3f5fa8 VP |
7373 | } |
7374 | ||
f431efe5 PA |
7375 | /* Increment reference count. */ |
7376 | ||
7377 | static void | |
7378 | incref_bp_location (struct bp_location *bl) | |
7379 | { | |
7380 | ++bl->refc; | |
7381 | } | |
7382 | ||
7383 | /* Decrement reference count. If the reference count reaches 0, | |
7384 | destroy the bp_location. Sets *BLP to NULL. */ | |
7385 | ||
7386 | static void | |
7387 | decref_bp_location (struct bp_location **blp) | |
7388 | { | |
0807b50c PA |
7389 | gdb_assert ((*blp)->refc > 0); |
7390 | ||
f431efe5 PA |
7391 | if (--(*blp)->refc == 0) |
7392 | free_bp_location (*blp); | |
7393 | *blp = NULL; | |
7394 | } | |
7395 | ||
346774a9 | 7396 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7397 | |
b270e6f9 TT |
7398 | static breakpoint * |
7399 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) | |
c906108c | 7400 | { |
346774a9 | 7401 | struct breakpoint *b1; |
b270e6f9 | 7402 | struct breakpoint *result = b.get (); |
c906108c | 7403 | |
346774a9 PA |
7404 | /* Add this breakpoint to the end of the chain so that a list of |
7405 | breakpoints will come out in order of increasing numbers. */ | |
7406 | ||
7407 | b1 = breakpoint_chain; | |
7408 | if (b1 == 0) | |
b270e6f9 | 7409 | breakpoint_chain = b.release (); |
346774a9 PA |
7410 | else |
7411 | { | |
7412 | while (b1->next) | |
7413 | b1 = b1->next; | |
b270e6f9 | 7414 | b1->next = b.release (); |
346774a9 | 7415 | } |
b270e6f9 TT |
7416 | |
7417 | return result; | |
346774a9 PA |
7418 | } |
7419 | ||
7420 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7421 | ||
7422 | static void | |
7423 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7424 | struct gdbarch *gdbarch, | |
28010a5d | 7425 | enum bptype bptype, |
c0a91b2b | 7426 | const struct breakpoint_ops *ops) |
346774a9 | 7427 | { |
348d480f PA |
7428 | gdb_assert (ops != NULL); |
7429 | ||
28010a5d | 7430 | b->ops = ops; |
4d28f7a8 | 7431 | b->type = bptype; |
a6d9a66e | 7432 | b->gdbarch = gdbarch; |
c906108c SS |
7433 | b->language = current_language->la_language; |
7434 | b->input_radix = input_radix; | |
d0fb5eae | 7435 | b->related_breakpoint = b; |
346774a9 PA |
7436 | } |
7437 | ||
7438 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7439 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7440 | |
7441 | static struct breakpoint * | |
7442 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7443 | enum bptype bptype, |
c0a91b2b | 7444 | const struct breakpoint_ops *ops) |
346774a9 | 7445 | { |
3b0871f4 | 7446 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7447 | |
3b0871f4 | 7448 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
b270e6f9 | 7449 | return add_to_breakpoint_chain (std::move (b)); |
0d381245 VP |
7450 | } |
7451 | ||
0e30163f JK |
7452 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7453 | resolutions should be made as the user specified the location explicitly | |
7454 | enough. */ | |
7455 | ||
0d381245 | 7456 | static void |
0e30163f | 7457 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7458 | { |
2bdf28a0 JK |
7459 | gdb_assert (loc->owner != NULL); |
7460 | ||
0d381245 | 7461 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7462 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7463 | || is_tracepoint (loc->owner)) |
0d381245 | 7464 | { |
0e30163f | 7465 | int is_gnu_ifunc; |
2c02bd72 | 7466 | const char *function_name; |
6a3a010b | 7467 | CORE_ADDR func_addr; |
0e30163f | 7468 | |
2c02bd72 | 7469 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7470 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7471 | |
7472 | if (is_gnu_ifunc && !explicit_loc) | |
7473 | { | |
7474 | struct breakpoint *b = loc->owner; | |
7475 | ||
7476 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7477 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7478 | &loc->requested_address)) |
7479 | { | |
7480 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7481 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7482 | loc->requested_address, | |
7483 | b->type); | |
7484 | } | |
7485 | else if (b->type == bp_breakpoint && b->loc == loc | |
7486 | && loc->next == NULL && b->related_breakpoint == b) | |
7487 | { | |
7488 | /* Create only the whole new breakpoint of this type but do not | |
7489 | mess more complicated breakpoints with multiple locations. */ | |
7490 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7491 | /* Remember the resolver's address for use by the return |
7492 | breakpoint. */ | |
7493 | loc->related_address = func_addr; | |
0e30163f JK |
7494 | } |
7495 | } | |
7496 | ||
2c02bd72 DE |
7497 | if (function_name) |
7498 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7499 | } |
7500 | } | |
7501 | ||
a6d9a66e | 7502 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7503 | struct gdbarch * |
a6d9a66e UW |
7504 | get_sal_arch (struct symtab_and_line sal) |
7505 | { | |
7506 | if (sal.section) | |
7507 | return get_objfile_arch (sal.section->objfile); | |
7508 | if (sal.symtab) | |
eb822aa6 | 7509 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7510 | |
7511 | return NULL; | |
7512 | } | |
7513 | ||
346774a9 PA |
7514 | /* Low level routine for partially initializing a breakpoint of type |
7515 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7516 | file name, and line number are provided by SAL. |
0d381245 VP |
7517 | |
7518 | It is expected that the caller will complete the initialization of | |
7519 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 7520 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7521 | |
346774a9 PA |
7522 | static void |
7523 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7524 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7525 | const struct breakpoint_ops *ops) |
0d381245 | 7526 | { |
28010a5d | 7527 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7528 | |
3742cc8b | 7529 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7530 | |
6c95b8df PA |
7531 | if (bptype != bp_catchpoint) |
7532 | gdb_assert (sal.pspace != NULL); | |
7533 | ||
f8eba3c6 TT |
7534 | /* Store the program space that was used to set the breakpoint, |
7535 | except for ordinary breakpoints, which are independent of the | |
7536 | program space. */ | |
7537 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7538 | b->pspace = sal.pspace; | |
346774a9 | 7539 | } |
c906108c | 7540 | |
346774a9 PA |
7541 | /* set_raw_breakpoint is a low level routine for allocating and |
7542 | partially initializing a breakpoint of type BPTYPE. The newly | |
7543 | created breakpoint's address, section, source file name, and line | |
7544 | number are provided by SAL. The newly created and partially | |
7545 | initialized breakpoint is added to the breakpoint chain and | |
7546 | is also returned as the value of this function. | |
7547 | ||
7548 | It is expected that the caller will complete the initialization of | |
7549 | the newly created breakpoint struct as well as output any status | |
7550 | information regarding the creation of a new breakpoint. In | |
7551 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7552 | number! Care should be taken to not allow an error to occur | |
7553 | prior to completing the initialization of the breakpoint. If this | |
7554 | should happen, a bogus breakpoint will be left on the chain. */ | |
7555 | ||
7556 | struct breakpoint * | |
7557 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7558 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7559 | const struct breakpoint_ops *ops) |
346774a9 | 7560 | { |
3b0871f4 | 7561 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
346774a9 | 7562 | |
3b0871f4 | 7563 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
b270e6f9 | 7564 | return add_to_breakpoint_chain (std::move (b)); |
c906108c SS |
7565 | } |
7566 | ||
53a5351d | 7567 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7568 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7569 | initiated the operation. */ | |
c906108c SS |
7570 | |
7571 | void | |
186c406b | 7572 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7573 | { |
35df4500 | 7574 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7575 | int thread = tp->global_num; |
0fd8e87f UW |
7576 | |
7577 | /* To avoid having to rescan all objfile symbols at every step, | |
7578 | we maintain a list of continually-inserted but always disabled | |
7579 | longjmp "master" breakpoints. Here, we simply create momentary | |
7580 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7581 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7582 | if (b->pspace == current_program_space |
186c406b TT |
7583 | && (b->type == bp_longjmp_master |
7584 | || b->type == bp_exception_master)) | |
0fd8e87f | 7585 | { |
06edf0c0 PA |
7586 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7587 | struct breakpoint *clone; | |
cc59ec59 | 7588 | |
e2e4d78b JK |
7589 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7590 | after their removal. */ | |
06edf0c0 | 7591 | clone = momentary_breakpoint_from_master (b, type, |
c1fc2657 | 7592 | &momentary_breakpoint_ops, 1); |
0fd8e87f UW |
7593 | clone->thread = thread; |
7594 | } | |
186c406b TT |
7595 | |
7596 | tp->initiating_frame = frame; | |
c906108c SS |
7597 | } |
7598 | ||
611c83ae | 7599 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7600 | void |
611c83ae | 7601 | delete_longjmp_breakpoint (int thread) |
c906108c | 7602 | { |
35df4500 | 7603 | struct breakpoint *b, *b_tmp; |
c906108c | 7604 | |
35df4500 | 7605 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7606 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7607 | { |
7608 | if (b->thread == thread) | |
7609 | delete_breakpoint (b); | |
7610 | } | |
c906108c SS |
7611 | } |
7612 | ||
f59f708a PA |
7613 | void |
7614 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7615 | { | |
7616 | struct breakpoint *b, *b_tmp; | |
7617 | ||
7618 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7619 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7620 | { | |
7621 | if (b->thread == thread) | |
7622 | b->disposition = disp_del_at_next_stop; | |
7623 | } | |
7624 | } | |
7625 | ||
e2e4d78b JK |
7626 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7627 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7628 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7629 | breakpoints. */ | |
7630 | ||
7631 | struct breakpoint * | |
7632 | set_longjmp_breakpoint_for_call_dummy (void) | |
7633 | { | |
7634 | struct breakpoint *b, *retval = NULL; | |
7635 | ||
7636 | ALL_BREAKPOINTS (b) | |
7637 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7638 | { | |
7639 | struct breakpoint *new_b; | |
7640 | ||
7641 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7642 | &momentary_breakpoint_ops, |
7643 | 1); | |
5d5658a1 | 7644 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7645 | |
7646 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7647 | ||
7648 | gdb_assert (new_b->related_breakpoint == new_b); | |
7649 | if (retval == NULL) | |
7650 | retval = new_b; | |
7651 | new_b->related_breakpoint = retval; | |
7652 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7653 | retval = retval->related_breakpoint; | |
7654 | retval->related_breakpoint = new_b; | |
7655 | } | |
7656 | ||
7657 | return retval; | |
7658 | } | |
7659 | ||
7660 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7661 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7662 | stack. |
7663 | ||
7664 | You should call this function only at places where it is safe to currently | |
7665 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7666 | frames. */ | |
7667 | ||
7668 | void | |
b67a2c6f | 7669 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7670 | { |
7671 | struct breakpoint *b, *b_tmp; | |
7672 | ||
7673 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7674 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7675 | { |
7676 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7677 | ||
7678 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7679 | dummy_b = dummy_b->related_breakpoint; | |
7680 | if (dummy_b->type != bp_call_dummy | |
7681 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7682 | continue; | |
7683 | ||
b67a2c6f | 7684 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7685 | |
7686 | while (b->related_breakpoint != b) | |
7687 | { | |
7688 | if (b_tmp == b->related_breakpoint) | |
7689 | b_tmp = b->related_breakpoint->next; | |
7690 | delete_breakpoint (b->related_breakpoint); | |
7691 | } | |
7692 | delete_breakpoint (b); | |
7693 | } | |
7694 | } | |
7695 | ||
1900040c MS |
7696 | void |
7697 | enable_overlay_breakpoints (void) | |
7698 | { | |
52f0bd74 | 7699 | struct breakpoint *b; |
1900040c MS |
7700 | |
7701 | ALL_BREAKPOINTS (b) | |
7702 | if (b->type == bp_overlay_event) | |
7703 | { | |
7704 | b->enable_state = bp_enabled; | |
44702360 | 7705 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7706 | overlay_events_enabled = 1; |
1900040c MS |
7707 | } |
7708 | } | |
7709 | ||
7710 | void | |
7711 | disable_overlay_breakpoints (void) | |
7712 | { | |
52f0bd74 | 7713 | struct breakpoint *b; |
1900040c MS |
7714 | |
7715 | ALL_BREAKPOINTS (b) | |
7716 | if (b->type == bp_overlay_event) | |
7717 | { | |
7718 | b->enable_state = bp_disabled; | |
44702360 | 7719 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7720 | overlay_events_enabled = 0; |
1900040c MS |
7721 | } |
7722 | } | |
7723 | ||
aa7d318d TT |
7724 | /* Set an active std::terminate breakpoint for each std::terminate |
7725 | master breakpoint. */ | |
7726 | void | |
7727 | set_std_terminate_breakpoint (void) | |
7728 | { | |
35df4500 | 7729 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7730 | |
35df4500 | 7731 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7732 | if (b->pspace == current_program_space |
7733 | && b->type == bp_std_terminate_master) | |
7734 | { | |
06edf0c0 | 7735 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7736 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7737 | } |
7738 | } | |
7739 | ||
7740 | /* Delete all the std::terminate breakpoints. */ | |
7741 | void | |
7742 | delete_std_terminate_breakpoint (void) | |
7743 | { | |
35df4500 | 7744 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7745 | |
35df4500 | 7746 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7747 | if (b->type == bp_std_terminate) |
7748 | delete_breakpoint (b); | |
7749 | } | |
7750 | ||
c4093a6a | 7751 | struct breakpoint * |
a6d9a66e | 7752 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7753 | { |
7754 | struct breakpoint *b; | |
c4093a6a | 7755 | |
06edf0c0 PA |
7756 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7757 | &internal_breakpoint_ops); | |
7758 | ||
b5de0fa7 | 7759 | b->enable_state = bp_enabled; |
f00aae0f | 7760 | /* location has to be used or breakpoint_re_set will delete me. */ |
d28cd78a | 7761 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7762 | |
44702360 | 7763 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7764 | |
c4093a6a JM |
7765 | return b; |
7766 | } | |
7767 | ||
0101ce28 JJ |
7768 | struct lang_and_radix |
7769 | { | |
7770 | enum language lang; | |
7771 | int radix; | |
7772 | }; | |
7773 | ||
4efc6507 DE |
7774 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7775 | ||
7776 | struct breakpoint * | |
7777 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7778 | { | |
2a7f3dff PA |
7779 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7780 | &internal_breakpoint_ops); | |
4efc6507 | 7781 | } |
0101ce28 | 7782 | |
03673fc7 PP |
7783 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7784 | ||
7785 | void | |
7786 | remove_jit_event_breakpoints (void) | |
7787 | { | |
7788 | struct breakpoint *b, *b_tmp; | |
7789 | ||
7790 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7791 | if (b->type == bp_jit_event | |
7792 | && b->loc->pspace == current_program_space) | |
7793 | delete_breakpoint (b); | |
7794 | } | |
7795 | ||
cae688ec JJ |
7796 | void |
7797 | remove_solib_event_breakpoints (void) | |
7798 | { | |
35df4500 | 7799 | struct breakpoint *b, *b_tmp; |
cae688ec | 7800 | |
35df4500 | 7801 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7802 | if (b->type == bp_shlib_event |
7803 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7804 | delete_breakpoint (b); |
7805 | } | |
7806 | ||
f37f681c PA |
7807 | /* See breakpoint.h. */ |
7808 | ||
7809 | void | |
7810 | remove_solib_event_breakpoints_at_next_stop (void) | |
7811 | { | |
7812 | struct breakpoint *b, *b_tmp; | |
7813 | ||
7814 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7815 | if (b->type == bp_shlib_event | |
7816 | && b->loc->pspace == current_program_space) | |
7817 | b->disposition = disp_del_at_next_stop; | |
7818 | } | |
7819 | ||
04086b45 PA |
7820 | /* Helper for create_solib_event_breakpoint / |
7821 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7822 | INSERT_MODE to pass through to update_global_location_list. */ | |
7823 | ||
7824 | static struct breakpoint * | |
7825 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7826 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7827 | { |
7828 | struct breakpoint *b; | |
7829 | ||
06edf0c0 PA |
7830 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7831 | &internal_breakpoint_ops); | |
04086b45 | 7832 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7833 | return b; |
7834 | } | |
7835 | ||
04086b45 PA |
7836 | struct breakpoint * |
7837 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7838 | { | |
7839 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7840 | } | |
7841 | ||
f37f681c PA |
7842 | /* See breakpoint.h. */ |
7843 | ||
7844 | struct breakpoint * | |
7845 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7846 | { | |
7847 | struct breakpoint *b; | |
7848 | ||
04086b45 PA |
7849 | /* Explicitly tell update_global_location_list to insert |
7850 | locations. */ | |
7851 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7852 | if (!b->loc->inserted) |
7853 | { | |
7854 | delete_breakpoint (b); | |
7855 | return NULL; | |
7856 | } | |
7857 | return b; | |
7858 | } | |
7859 | ||
cae688ec JJ |
7860 | /* Disable any breakpoints that are on code in shared libraries. Only |
7861 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7862 | ||
7863 | void | |
cb851954 | 7864 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7865 | { |
876fa593 | 7866 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7867 | |
876fa593 | 7868 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7869 | { |
2bdf28a0 | 7870 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7871 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7872 | |
4a64f543 MS |
7873 | /* We apply the check to all breakpoints, including disabled for |
7874 | those with loc->duplicate set. This is so that when breakpoint | |
7875 | becomes enabled, or the duplicate is removed, gdb will try to | |
7876 | insert all breakpoints. If we don't set shlib_disabled here, | |
7877 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7878 | if (((b->type == bp_breakpoint) |
508ccb1f | 7879 | || (b->type == bp_jit_event) |
1042e4c0 | 7880 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7881 | || (is_tracepoint (b))) |
6c95b8df | 7882 | && loc->pspace == current_program_space |
0d381245 | 7883 | && !loc->shlib_disabled |
6c95b8df | 7884 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7885 | ) |
0d381245 VP |
7886 | { |
7887 | loc->shlib_disabled = 1; | |
7888 | } | |
cae688ec JJ |
7889 | } |
7890 | } | |
7891 | ||
63644780 NB |
7892 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7893 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7894 | disabled ones can just stay disabled. */ | |
84acb35a | 7895 | |
75149521 | 7896 | static void |
84acb35a JJ |
7897 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7898 | { | |
876fa593 | 7899 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7900 | int disabled_shlib_breaks = 0; |
7901 | ||
876fa593 | 7902 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7903 | { |
2bdf28a0 | 7904 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7905 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7906 | |
1e4d1764 | 7907 | if (solib->pspace == loc->pspace |
e2dd7057 | 7908 | && !loc->shlib_disabled |
1e4d1764 YQ |
7909 | && (((b->type == bp_breakpoint |
7910 | || b->type == bp_jit_event | |
7911 | || b->type == bp_hardware_breakpoint) | |
7912 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7913 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7914 | || is_tracepoint (b)) | |
e2dd7057 | 7915 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7916 | { |
e2dd7057 PP |
7917 | loc->shlib_disabled = 1; |
7918 | /* At this point, we cannot rely on remove_breakpoint | |
7919 | succeeding so we must mark the breakpoint as not inserted | |
7920 | to prevent future errors occurring in remove_breakpoints. */ | |
7921 | loc->inserted = 0; | |
8d3788bd VP |
7922 | |
7923 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7924 | observer_notify_breakpoint_modified (b); | |
7925 | ||
e2dd7057 PP |
7926 | if (!disabled_shlib_breaks) |
7927 | { | |
7928 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7929 | warning (_("Temporarily disabling breakpoints " |
7930 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7931 | solib->so_name); |
84acb35a | 7932 | } |
e2dd7057 | 7933 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7934 | } |
7935 | } | |
84acb35a JJ |
7936 | } |
7937 | ||
63644780 NB |
7938 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7939 | notification of free_objfile. Only apply to enabled breakpoints, | |
7940 | disabled ones can just stay disabled. */ | |
7941 | ||
7942 | static void | |
7943 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7944 | { | |
7945 | struct breakpoint *b; | |
7946 | ||
7947 | if (objfile == NULL) | |
7948 | return; | |
7949 | ||
d03de421 PA |
7950 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7951 | managed by the user with add-symbol-file/remove-symbol-file. | |
7952 | Similarly to how breakpoints in shared libraries are handled in | |
7953 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7954 | shlib_disabled so they end up uninserted on the next global |
7955 | location list update. Shared libraries not loaded by the user | |
7956 | aren't handled here -- they're already handled in | |
7957 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
7958 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
7959 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
7960 | main objfile). */ | |
7961 | if ((objfile->flags & OBJF_SHARED) == 0 | |
7962 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
7963 | return; |
7964 | ||
7965 | ALL_BREAKPOINTS (b) | |
7966 | { | |
7967 | struct bp_location *loc; | |
7968 | int bp_modified = 0; | |
7969 | ||
7970 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
7971 | continue; | |
7972 | ||
7973 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
7974 | { | |
7975 | CORE_ADDR loc_addr = loc->address; | |
7976 | ||
7977 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7978 | && loc->loc_type != bp_loc_software_breakpoint) | |
7979 | continue; | |
7980 | ||
7981 | if (loc->shlib_disabled != 0) | |
7982 | continue; | |
7983 | ||
7984 | if (objfile->pspace != loc->pspace) | |
7985 | continue; | |
7986 | ||
7987 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
7988 | && loc->loc_type != bp_loc_software_breakpoint) | |
7989 | continue; | |
7990 | ||
7991 | if (is_addr_in_objfile (loc_addr, objfile)) | |
7992 | { | |
7993 | loc->shlib_disabled = 1; | |
08351840 PA |
7994 | /* At this point, we don't know whether the object was |
7995 | unmapped from the inferior or not, so leave the | |
7996 | inserted flag alone. We'll handle failure to | |
7997 | uninsert quietly, in case the object was indeed | |
7998 | unmapped. */ | |
63644780 NB |
7999 | |
8000 | mark_breakpoint_location_modified (loc); | |
8001 | ||
8002 | bp_modified = 1; | |
8003 | } | |
8004 | } | |
8005 | ||
8006 | if (bp_modified) | |
8007 | observer_notify_breakpoint_modified (b); | |
8008 | } | |
8009 | } | |
8010 | ||
ce78b96d JB |
8011 | /* FORK & VFORK catchpoints. */ |
8012 | ||
e29a4733 | 8013 | /* An instance of this type is used to represent a fork or vfork |
c1fc2657 SM |
8014 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
8015 | to CATCH_FORK_BREAKPOINT_OPS. */ | |
e29a4733 | 8016 | |
c1fc2657 | 8017 | struct fork_catchpoint : public breakpoint |
e29a4733 | 8018 | { |
e29a4733 PA |
8019 | /* Process id of a child process whose forking triggered this |
8020 | catchpoint. This field is only valid immediately after this | |
8021 | catchpoint has triggered. */ | |
8022 | ptid_t forked_inferior_pid; | |
8023 | }; | |
8024 | ||
4a64f543 MS |
8025 | /* Implement the "insert" breakpoint_ops method for fork |
8026 | catchpoints. */ | |
ce78b96d | 8027 | |
77b06cd7 TJB |
8028 | static int |
8029 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8030 | { |
dfd4cc63 | 8031 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8032 | } |
8033 | ||
4a64f543 MS |
8034 | /* Implement the "remove" breakpoint_ops method for fork |
8035 | catchpoints. */ | |
ce78b96d JB |
8036 | |
8037 | static int | |
73971819 | 8038 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8039 | { |
dfd4cc63 | 8040 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8041 | } |
8042 | ||
8043 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8044 | catchpoints. */ | |
8045 | ||
8046 | static int | |
f1310107 | 8047 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8048 | struct address_space *aspace, CORE_ADDR bp_addr, |
8049 | const struct target_waitstatus *ws) | |
ce78b96d | 8050 | { |
e29a4733 PA |
8051 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8052 | ||
f90263c1 TT |
8053 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8054 | return 0; | |
8055 | ||
8056 | c->forked_inferior_pid = ws->value.related_pid; | |
8057 | return 1; | |
ce78b96d JB |
8058 | } |
8059 | ||
4a64f543 MS |
8060 | /* Implement the "print_it" breakpoint_ops method for fork |
8061 | catchpoints. */ | |
ce78b96d JB |
8062 | |
8063 | static enum print_stop_action | |
348d480f | 8064 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8065 | { |
36dfb11c | 8066 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8067 | struct breakpoint *b = bs->breakpoint_at; |
8068 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8069 | |
ce78b96d | 8070 | annotate_catchpoint (b->number); |
f303dbd6 | 8071 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8072 | if (b->disposition == disp_del) |
112e8700 | 8073 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8074 | else |
112e8700 SM |
8075 | uiout->text ("Catchpoint "); |
8076 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8077 | { |
112e8700 SM |
8078 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
8079 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8080 | } |
112e8700 SM |
8081 | uiout->field_int ("bkptno", b->number); |
8082 | uiout->text (" (forked process "); | |
8083 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8084 | uiout->text ("), "); | |
ce78b96d JB |
8085 | return PRINT_SRC_AND_LOC; |
8086 | } | |
8087 | ||
4a64f543 MS |
8088 | /* Implement the "print_one" breakpoint_ops method for fork |
8089 | catchpoints. */ | |
ce78b96d JB |
8090 | |
8091 | static void | |
a6d9a66e | 8092 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8093 | { |
e29a4733 | 8094 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8095 | struct value_print_options opts; |
79a45e25 | 8096 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8097 | |
8098 | get_user_print_options (&opts); | |
8099 | ||
4a64f543 MS |
8100 | /* Field 4, the address, is omitted (which makes the columns not |
8101 | line up too nicely with the headers, but the effect is relatively | |
8102 | readable). */ | |
79a45b7d | 8103 | if (opts.addressprint) |
112e8700 | 8104 | uiout->field_skip ("addr"); |
ce78b96d | 8105 | annotate_field (5); |
112e8700 | 8106 | uiout->text ("fork"); |
e29a4733 | 8107 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8108 | { |
112e8700 SM |
8109 | uiout->text (", process "); |
8110 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8111 | uiout->spaces (1); | |
ce78b96d | 8112 | } |
8ac3646f | 8113 | |
112e8700 SM |
8114 | if (uiout->is_mi_like_p ()) |
8115 | uiout->field_string ("catch-type", "fork"); | |
ce78b96d JB |
8116 | } |
8117 | ||
8118 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8119 | catchpoints. */ | |
8120 | ||
8121 | static void | |
8122 | print_mention_catch_fork (struct breakpoint *b) | |
8123 | { | |
8124 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8125 | } | |
8126 | ||
6149aea9 PA |
8127 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8128 | catchpoints. */ | |
8129 | ||
8130 | static void | |
8131 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8132 | { | |
8133 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8134 | print_recreate_thread (b, fp); |
6149aea9 PA |
8135 | } |
8136 | ||
ce78b96d JB |
8137 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8138 | ||
2060206e | 8139 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8140 | |
4a64f543 MS |
8141 | /* Implement the "insert" breakpoint_ops method for vfork |
8142 | catchpoints. */ | |
ce78b96d | 8143 | |
77b06cd7 TJB |
8144 | static int |
8145 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8146 | { |
dfd4cc63 | 8147 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8148 | } |
8149 | ||
4a64f543 MS |
8150 | /* Implement the "remove" breakpoint_ops method for vfork |
8151 | catchpoints. */ | |
ce78b96d JB |
8152 | |
8153 | static int | |
73971819 | 8154 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
ce78b96d | 8155 | { |
dfd4cc63 | 8156 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8157 | } |
8158 | ||
8159 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8160 | catchpoints. */ | |
8161 | ||
8162 | static int | |
f1310107 | 8163 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8164 | struct address_space *aspace, CORE_ADDR bp_addr, |
8165 | const struct target_waitstatus *ws) | |
ce78b96d | 8166 | { |
e29a4733 PA |
8167 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8168 | ||
f90263c1 TT |
8169 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8170 | return 0; | |
8171 | ||
8172 | c->forked_inferior_pid = ws->value.related_pid; | |
8173 | return 1; | |
ce78b96d JB |
8174 | } |
8175 | ||
4a64f543 MS |
8176 | /* Implement the "print_it" breakpoint_ops method for vfork |
8177 | catchpoints. */ | |
ce78b96d JB |
8178 | |
8179 | static enum print_stop_action | |
348d480f | 8180 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8181 | { |
36dfb11c | 8182 | struct ui_out *uiout = current_uiout; |
348d480f | 8183 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8184 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8185 | ||
ce78b96d | 8186 | annotate_catchpoint (b->number); |
f303dbd6 | 8187 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8188 | if (b->disposition == disp_del) |
112e8700 | 8189 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8190 | else |
112e8700 SM |
8191 | uiout->text ("Catchpoint "); |
8192 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8193 | { |
112e8700 SM |
8194 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
8195 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8196 | } |
112e8700 SM |
8197 | uiout->field_int ("bkptno", b->number); |
8198 | uiout->text (" (vforked process "); | |
8199 | uiout->field_int ("newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8200 | uiout->text ("), "); | |
ce78b96d JB |
8201 | return PRINT_SRC_AND_LOC; |
8202 | } | |
8203 | ||
4a64f543 MS |
8204 | /* Implement the "print_one" breakpoint_ops method for vfork |
8205 | catchpoints. */ | |
ce78b96d JB |
8206 | |
8207 | static void | |
a6d9a66e | 8208 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8209 | { |
e29a4733 | 8210 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8211 | struct value_print_options opts; |
79a45e25 | 8212 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8213 | |
8214 | get_user_print_options (&opts); | |
4a64f543 MS |
8215 | /* Field 4, the address, is omitted (which makes the columns not |
8216 | line up too nicely with the headers, but the effect is relatively | |
8217 | readable). */ | |
79a45b7d | 8218 | if (opts.addressprint) |
112e8700 | 8219 | uiout->field_skip ("addr"); |
ce78b96d | 8220 | annotate_field (5); |
112e8700 | 8221 | uiout->text ("vfork"); |
e29a4733 | 8222 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d | 8223 | { |
112e8700 SM |
8224 | uiout->text (", process "); |
8225 | uiout->field_int ("what", ptid_get_pid (c->forked_inferior_pid)); | |
8226 | uiout->spaces (1); | |
ce78b96d | 8227 | } |
8ac3646f | 8228 | |
112e8700 SM |
8229 | if (uiout->is_mi_like_p ()) |
8230 | uiout->field_string ("catch-type", "vfork"); | |
ce78b96d JB |
8231 | } |
8232 | ||
8233 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8234 | catchpoints. */ | |
8235 | ||
8236 | static void | |
8237 | print_mention_catch_vfork (struct breakpoint *b) | |
8238 | { | |
8239 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8240 | } | |
8241 | ||
6149aea9 PA |
8242 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8243 | catchpoints. */ | |
8244 | ||
8245 | static void | |
8246 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8247 | { | |
8248 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8249 | print_recreate_thread (b, fp); |
6149aea9 PA |
8250 | } |
8251 | ||
ce78b96d JB |
8252 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8253 | ||
2060206e | 8254 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8255 | |
edcc5120 | 8256 | /* An instance of this type is used to represent an solib catchpoint. |
c1fc2657 | 8257 | A breakpoint is really of this type iff its ops pointer points to |
edcc5120 TT |
8258 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
8259 | ||
c1fc2657 | 8260 | struct solib_catchpoint : public breakpoint |
edcc5120 | 8261 | { |
c1fc2657 | 8262 | ~solib_catchpoint () override; |
edcc5120 TT |
8263 | |
8264 | /* True for "catch load", false for "catch unload". */ | |
8265 | unsigned char is_load; | |
8266 | ||
8267 | /* Regular expression to match, if any. COMPILED is only valid when | |
8268 | REGEX is non-NULL. */ | |
8269 | char *regex; | |
2d7cc5c7 | 8270 | std::unique_ptr<compiled_regex> compiled; |
edcc5120 TT |
8271 | }; |
8272 | ||
c1fc2657 | 8273 | solib_catchpoint::~solib_catchpoint () |
edcc5120 | 8274 | { |
c1fc2657 | 8275 | xfree (this->regex); |
edcc5120 TT |
8276 | } |
8277 | ||
8278 | static int | |
8279 | insert_catch_solib (struct bp_location *ignore) | |
8280 | { | |
8281 | return 0; | |
8282 | } | |
8283 | ||
8284 | static int | |
73971819 | 8285 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
edcc5120 TT |
8286 | { |
8287 | return 0; | |
8288 | } | |
8289 | ||
8290 | static int | |
8291 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8292 | struct address_space *aspace, | |
8293 | CORE_ADDR bp_addr, | |
8294 | const struct target_waitstatus *ws) | |
8295 | { | |
8296 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8297 | struct breakpoint *other; | |
8298 | ||
8299 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8300 | return 1; | |
8301 | ||
8302 | ALL_BREAKPOINTS (other) | |
8303 | { | |
8304 | struct bp_location *other_bl; | |
8305 | ||
8306 | if (other == bl->owner) | |
8307 | continue; | |
8308 | ||
8309 | if (other->type != bp_shlib_event) | |
8310 | continue; | |
8311 | ||
c1fc2657 | 8312 | if (self->pspace != NULL && other->pspace != self->pspace) |
edcc5120 TT |
8313 | continue; |
8314 | ||
8315 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8316 | { | |
8317 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8318 | return 1; | |
8319 | } | |
8320 | } | |
8321 | ||
8322 | return 0; | |
8323 | } | |
8324 | ||
8325 | static void | |
8326 | check_status_catch_solib (struct bpstats *bs) | |
8327 | { | |
8328 | struct solib_catchpoint *self | |
8329 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8330 | int ix; | |
8331 | ||
8332 | if (self->is_load) | |
8333 | { | |
8334 | struct so_list *iter; | |
8335 | ||
8336 | for (ix = 0; | |
8337 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8338 | ix, iter); | |
8339 | ++ix) | |
8340 | { | |
8341 | if (!self->regex | |
2d7cc5c7 | 8342 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
edcc5120 TT |
8343 | return; |
8344 | } | |
8345 | } | |
8346 | else | |
8347 | { | |
8348 | char *iter; | |
8349 | ||
8350 | for (ix = 0; | |
8351 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8352 | ix, iter); | |
8353 | ++ix) | |
8354 | { | |
8355 | if (!self->regex | |
2d7cc5c7 | 8356 | || self->compiled->exec (iter, 0, NULL, 0) == 0) |
edcc5120 TT |
8357 | return; |
8358 | } | |
8359 | } | |
8360 | ||
8361 | bs->stop = 0; | |
8362 | bs->print_it = print_it_noop; | |
8363 | } | |
8364 | ||
8365 | static enum print_stop_action | |
8366 | print_it_catch_solib (bpstat bs) | |
8367 | { | |
8368 | struct breakpoint *b = bs->breakpoint_at; | |
8369 | struct ui_out *uiout = current_uiout; | |
8370 | ||
8371 | annotate_catchpoint (b->number); | |
f303dbd6 | 8372 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8373 | if (b->disposition == disp_del) |
112e8700 | 8374 | uiout->text ("Temporary catchpoint "); |
edcc5120 | 8375 | else |
112e8700 SM |
8376 | uiout->text ("Catchpoint "); |
8377 | uiout->field_int ("bkptno", b->number); | |
8378 | uiout->text ("\n"); | |
8379 | if (uiout->is_mi_like_p ()) | |
8380 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
edcc5120 TT |
8381 | print_solib_event (1); |
8382 | return PRINT_SRC_AND_LOC; | |
8383 | } | |
8384 | ||
8385 | static void | |
8386 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8387 | { | |
8388 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8389 | struct value_print_options opts; | |
8390 | struct ui_out *uiout = current_uiout; | |
8391 | char *msg; | |
8392 | ||
8393 | get_user_print_options (&opts); | |
8394 | /* Field 4, the address, is omitted (which makes the columns not | |
8395 | line up too nicely with the headers, but the effect is relatively | |
8396 | readable). */ | |
8397 | if (opts.addressprint) | |
8398 | { | |
8399 | annotate_field (4); | |
112e8700 | 8400 | uiout->field_skip ("addr"); |
edcc5120 TT |
8401 | } |
8402 | ||
8403 | annotate_field (5); | |
8404 | if (self->is_load) | |
8405 | { | |
8406 | if (self->regex) | |
8407 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8408 | else | |
8409 | msg = xstrdup (_("load of library")); | |
8410 | } | |
8411 | else | |
8412 | { | |
8413 | if (self->regex) | |
8414 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8415 | else | |
8416 | msg = xstrdup (_("unload of library")); | |
8417 | } | |
112e8700 | 8418 | uiout->field_string ("what", msg); |
edcc5120 | 8419 | xfree (msg); |
8ac3646f | 8420 | |
112e8700 SM |
8421 | if (uiout->is_mi_like_p ()) |
8422 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8423 | } |
8424 | ||
8425 | static void | |
8426 | print_mention_catch_solib (struct breakpoint *b) | |
8427 | { | |
8428 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8429 | ||
8430 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8431 | self->is_load ? "load" : "unload"); | |
8432 | } | |
8433 | ||
8434 | static void | |
8435 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8436 | { | |
8437 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8438 | ||
8439 | fprintf_unfiltered (fp, "%s %s", | |
8440 | b->disposition == disp_del ? "tcatch" : "catch", | |
8441 | self->is_load ? "load" : "unload"); | |
8442 | if (self->regex) | |
8443 | fprintf_unfiltered (fp, " %s", self->regex); | |
8444 | fprintf_unfiltered (fp, "\n"); | |
8445 | } | |
8446 | ||
8447 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8448 | ||
91985142 MG |
8449 | /* Shared helper function (MI and CLI) for creating and installing |
8450 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8451 | the events to be caught are load events, otherwise they are | |
8452 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8453 | temporary one. If ENABLED is non-zero the catchpoint is | |
8454 | created in an enabled state. */ | |
edcc5120 | 8455 | |
91985142 | 8456 | void |
a121b7c1 | 8457 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
edcc5120 | 8458 | { |
edcc5120 | 8459 | struct gdbarch *gdbarch = get_current_arch (); |
edcc5120 | 8460 | |
edcc5120 TT |
8461 | if (!arg) |
8462 | arg = ""; | |
f1735a53 | 8463 | arg = skip_spaces (arg); |
edcc5120 | 8464 | |
36bd8eaa | 8465 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
edcc5120 TT |
8466 | |
8467 | if (*arg != '\0') | |
8468 | { | |
2d7cc5c7 PA |
8469 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
8470 | _("Invalid regexp"))); | |
edcc5120 TT |
8471 | c->regex = xstrdup (arg); |
8472 | } | |
8473 | ||
8474 | c->is_load = is_load; | |
36bd8eaa | 8475 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
edcc5120 TT |
8476 | &catch_solib_breakpoint_ops); |
8477 | ||
c1fc2657 | 8478 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
91985142 | 8479 | |
b270e6f9 | 8480 | install_breakpoint (0, std::move (c), 1); |
edcc5120 TT |
8481 | } |
8482 | ||
91985142 MG |
8483 | /* A helper function that does all the work for "catch load" and |
8484 | "catch unload". */ | |
8485 | ||
8486 | static void | |
8487 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8488 | struct cmd_list_element *command) | |
8489 | { | |
8490 | int tempflag; | |
8491 | const int enabled = 1; | |
8492 | ||
8493 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8494 | ||
8495 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8496 | } | |
8497 | ||
edcc5120 TT |
8498 | static void |
8499 | catch_load_command_1 (char *arg, int from_tty, | |
8500 | struct cmd_list_element *command) | |
8501 | { | |
8502 | catch_load_or_unload (arg, from_tty, 1, command); | |
8503 | } | |
8504 | ||
8505 | static void | |
8506 | catch_unload_command_1 (char *arg, int from_tty, | |
8507 | struct cmd_list_element *command) | |
8508 | { | |
8509 | catch_load_or_unload (arg, from_tty, 0, command); | |
8510 | } | |
8511 | ||
346774a9 PA |
8512 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8513 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8514 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8515 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8516 | |
ab04a2af | 8517 | void |
346774a9 PA |
8518 | init_catchpoint (struct breakpoint *b, |
8519 | struct gdbarch *gdbarch, int tempflag, | |
63160a43 | 8520 | const char *cond_string, |
c0a91b2b | 8521 | const struct breakpoint_ops *ops) |
c906108c | 8522 | { |
51abb421 | 8523 | symtab_and_line sal; |
6c95b8df | 8524 | sal.pspace = current_program_space; |
c5aa993b | 8525 | |
28010a5d | 8526 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8527 | |
1b36a34b | 8528 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8529 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8530 | } |
8531 | ||
28010a5d | 8532 | void |
b270e6f9 | 8533 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
c56053d2 | 8534 | { |
b270e6f9 | 8535 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
3a5c3e22 | 8536 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8537 | if (is_tracepoint (b)) |
8538 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8539 | if (!internal) |
8540 | mention (b); | |
c56053d2 | 8541 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8542 | |
8543 | if (update_gll) | |
44702360 | 8544 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8545 | } |
8546 | ||
9b70b993 | 8547 | static void |
a6d9a66e | 8548 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
63160a43 | 8549 | int tempflag, const char *cond_string, |
c0a91b2b | 8550 | const struct breakpoint_ops *ops) |
c906108c | 8551 | { |
b270e6f9 | 8552 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
ce78b96d | 8553 | |
b270e6f9 | 8554 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
e29a4733 PA |
8555 | |
8556 | c->forked_inferior_pid = null_ptid; | |
8557 | ||
b270e6f9 | 8558 | install_breakpoint (0, std::move (c), 1); |
c906108c SS |
8559 | } |
8560 | ||
fe798b75 JB |
8561 | /* Exec catchpoints. */ |
8562 | ||
b4d90040 | 8563 | /* An instance of this type is used to represent an exec catchpoint. |
c1fc2657 | 8564 | A breakpoint is really of this type iff its ops pointer points to |
b4d90040 PA |
8565 | CATCH_EXEC_BREAKPOINT_OPS. */ |
8566 | ||
c1fc2657 | 8567 | struct exec_catchpoint : public breakpoint |
b4d90040 | 8568 | { |
c1fc2657 | 8569 | ~exec_catchpoint () override; |
b4d90040 PA |
8570 | |
8571 | /* Filename of a program whose exec triggered this catchpoint. | |
8572 | This field is only valid immediately after this catchpoint has | |
8573 | triggered. */ | |
8574 | char *exec_pathname; | |
8575 | }; | |
8576 | ||
c1fc2657 | 8577 | /* Exec catchpoint destructor. */ |
b4d90040 | 8578 | |
c1fc2657 | 8579 | exec_catchpoint::~exec_catchpoint () |
b4d90040 | 8580 | { |
c1fc2657 | 8581 | xfree (this->exec_pathname); |
b4d90040 PA |
8582 | } |
8583 | ||
77b06cd7 TJB |
8584 | static int |
8585 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8586 | { |
dfd4cc63 | 8587 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8588 | } |
c906108c | 8589 | |
fe798b75 | 8590 | static int |
73971819 | 8591 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
fe798b75 | 8592 | { |
dfd4cc63 | 8593 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8594 | } |
c906108c | 8595 | |
fe798b75 | 8596 | static int |
f1310107 | 8597 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8598 | struct address_space *aspace, CORE_ADDR bp_addr, |
8599 | const struct target_waitstatus *ws) | |
fe798b75 | 8600 | { |
b4d90040 PA |
8601 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8602 | ||
f90263c1 TT |
8603 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8604 | return 0; | |
8605 | ||
8606 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8607 | return 1; | |
fe798b75 | 8608 | } |
c906108c | 8609 | |
fe798b75 | 8610 | static enum print_stop_action |
348d480f | 8611 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8612 | { |
36dfb11c | 8613 | struct ui_out *uiout = current_uiout; |
348d480f | 8614 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8615 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8616 | ||
fe798b75 | 8617 | annotate_catchpoint (b->number); |
f303dbd6 | 8618 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8619 | if (b->disposition == disp_del) |
112e8700 | 8620 | uiout->text ("Temporary catchpoint "); |
36dfb11c | 8621 | else |
112e8700 SM |
8622 | uiout->text ("Catchpoint "); |
8623 | if (uiout->is_mi_like_p ()) | |
36dfb11c | 8624 | { |
112e8700 SM |
8625 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
8626 | uiout->field_string ("disp", bpdisp_text (b->disposition)); | |
36dfb11c | 8627 | } |
112e8700 SM |
8628 | uiout->field_int ("bkptno", b->number); |
8629 | uiout->text (" (exec'd "); | |
8630 | uiout->field_string ("new-exec", c->exec_pathname); | |
8631 | uiout->text ("), "); | |
36dfb11c | 8632 | |
fe798b75 | 8633 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8634 | } |
8635 | ||
fe798b75 | 8636 | static void |
a6d9a66e | 8637 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8638 | { |
b4d90040 | 8639 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8640 | struct value_print_options opts; |
79a45e25 | 8641 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8642 | |
8643 | get_user_print_options (&opts); | |
8644 | ||
8645 | /* Field 4, the address, is omitted (which makes the columns | |
8646 | not line up too nicely with the headers, but the effect | |
8647 | is relatively readable). */ | |
8648 | if (opts.addressprint) | |
112e8700 | 8649 | uiout->field_skip ("addr"); |
fe798b75 | 8650 | annotate_field (5); |
112e8700 | 8651 | uiout->text ("exec"); |
b4d90040 | 8652 | if (c->exec_pathname != NULL) |
fe798b75 | 8653 | { |
112e8700 SM |
8654 | uiout->text (", program \""); |
8655 | uiout->field_string ("what", c->exec_pathname); | |
8656 | uiout->text ("\" "); | |
fe798b75 | 8657 | } |
8ac3646f | 8658 | |
112e8700 SM |
8659 | if (uiout->is_mi_like_p ()) |
8660 | uiout->field_string ("catch-type", "exec"); | |
fe798b75 JB |
8661 | } |
8662 | ||
8663 | static void | |
8664 | print_mention_catch_exec (struct breakpoint *b) | |
8665 | { | |
8666 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8667 | } | |
8668 | ||
6149aea9 PA |
8669 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8670 | catchpoints. */ | |
8671 | ||
8672 | static void | |
8673 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8674 | { | |
8675 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8676 | print_recreate_thread (b, fp); |
6149aea9 PA |
8677 | } |
8678 | ||
2060206e | 8679 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8680 | |
c906108c | 8681 | static int |
fba45db2 | 8682 | hw_breakpoint_used_count (void) |
c906108c | 8683 | { |
c906108c | 8684 | int i = 0; |
f1310107 TJB |
8685 | struct breakpoint *b; |
8686 | struct bp_location *bl; | |
c906108c SS |
8687 | |
8688 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8689 | { |
d6b74ac4 | 8690 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8691 | for (bl = b->loc; bl; bl = bl->next) |
8692 | { | |
8693 | /* Special types of hardware breakpoints may use more than | |
8694 | one register. */ | |
348d480f | 8695 | i += b->ops->resources_needed (bl); |
f1310107 | 8696 | } |
c5aa993b | 8697 | } |
c906108c SS |
8698 | |
8699 | return i; | |
8700 | } | |
8701 | ||
a1398e0c PA |
8702 | /* Returns the resources B would use if it were a hardware |
8703 | watchpoint. */ | |
8704 | ||
c906108c | 8705 | static int |
a1398e0c | 8706 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8707 | { |
c906108c | 8708 | int i = 0; |
e09342b5 | 8709 | struct bp_location *bl; |
c906108c | 8710 | |
a1398e0c PA |
8711 | if (!breakpoint_enabled (b)) |
8712 | return 0; | |
8713 | ||
8714 | for (bl = b->loc; bl; bl = bl->next) | |
8715 | { | |
8716 | /* Special types of hardware watchpoints may use more than | |
8717 | one register. */ | |
8718 | i += b->ops->resources_needed (bl); | |
8719 | } | |
8720 | ||
8721 | return i; | |
8722 | } | |
8723 | ||
8724 | /* Returns the sum the used resources of all hardware watchpoints of | |
8725 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8726 | the sum of the used resources of all hardware watchpoints of other | |
8727 | types _not_ TYPE. */ | |
8728 | ||
8729 | static int | |
8730 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8731 | enum bptype type, int *other_type_used) | |
8732 | { | |
8733 | int i = 0; | |
8734 | struct breakpoint *b; | |
8735 | ||
c906108c SS |
8736 | *other_type_used = 0; |
8737 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8738 | { |
a1398e0c PA |
8739 | if (b == except) |
8740 | continue; | |
e09342b5 TJB |
8741 | if (!breakpoint_enabled (b)) |
8742 | continue; | |
8743 | ||
a1398e0c PA |
8744 | if (b->type == type) |
8745 | i += hw_watchpoint_use_count (b); | |
8746 | else if (is_hardware_watchpoint (b)) | |
8747 | *other_type_used = 1; | |
e09342b5 TJB |
8748 | } |
8749 | ||
c906108c SS |
8750 | return i; |
8751 | } | |
8752 | ||
c906108c | 8753 | void |
fba45db2 | 8754 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8755 | { |
c5aa993b | 8756 | struct breakpoint *b; |
c906108c SS |
8757 | |
8758 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8759 | { |
cc60f2e3 | 8760 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8761 | { |
b5de0fa7 | 8762 | b->enable_state = bp_call_disabled; |
44702360 | 8763 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8764 | } |
8765 | } | |
c906108c SS |
8766 | } |
8767 | ||
8768 | void | |
fba45db2 | 8769 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8770 | { |
c5aa993b | 8771 | struct breakpoint *b; |
c906108c SS |
8772 | |
8773 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8774 | { |
cc60f2e3 | 8775 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8776 | { |
b5de0fa7 | 8777 | b->enable_state = bp_enabled; |
44702360 | 8778 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8779 | } |
8780 | } | |
c906108c SS |
8781 | } |
8782 | ||
8bea4e01 UW |
8783 | void |
8784 | disable_breakpoints_before_startup (void) | |
8785 | { | |
6c95b8df | 8786 | current_program_space->executing_startup = 1; |
44702360 | 8787 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8788 | } |
8789 | ||
8790 | void | |
8791 | enable_breakpoints_after_startup (void) | |
8792 | { | |
6c95b8df | 8793 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8794 | breakpoint_re_set (); |
8bea4e01 UW |
8795 | } |
8796 | ||
7c16b83e PA |
8797 | /* Create a new single-step breakpoint for thread THREAD, with no |
8798 | locations. */ | |
c906108c | 8799 | |
7c16b83e PA |
8800 | static struct breakpoint * |
8801 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8802 | { | |
b270e6f9 | 8803 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
7c16b83e | 8804 | |
b270e6f9 | 8805 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
7c16b83e PA |
8806 | &momentary_breakpoint_ops); |
8807 | ||
8808 | b->disposition = disp_donttouch; | |
8809 | b->frame_id = null_frame_id; | |
8810 | ||
8811 | b->thread = thread; | |
8812 | gdb_assert (b->thread != 0); | |
8813 | ||
b270e6f9 | 8814 | return add_to_breakpoint_chain (std::move (b)); |
7c16b83e PA |
8815 | } |
8816 | ||
8817 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8818 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8819 | frame. */ | |
c906108c SS |
8820 | |
8821 | struct breakpoint * | |
a6d9a66e UW |
8822 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8823 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8824 | { |
52f0bd74 | 8825 | struct breakpoint *b; |
edb3359d | 8826 | |
193facb3 JK |
8827 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8828 | tail-called one. */ | |
8829 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8830 | |
06edf0c0 | 8831 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8832 | b->enable_state = bp_enabled; |
8833 | b->disposition = disp_donttouch; | |
818dd999 | 8834 | b->frame_id = frame_id; |
c906108c | 8835 | |
4a64f543 MS |
8836 | /* If we're debugging a multi-threaded program, then we want |
8837 | momentary breakpoints to be active in only a single thread of | |
8838 | control. */ | |
39f77062 | 8839 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8840 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8841 | |
44702360 | 8842 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8843 | |
c906108c SS |
8844 | return b; |
8845 | } | |
611c83ae | 8846 | |
06edf0c0 | 8847 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8848 | The new breakpoint will have type TYPE, use OPS as its |
8849 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8850 | |
06edf0c0 PA |
8851 | static struct breakpoint * |
8852 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8853 | enum bptype type, | |
a1aa2221 LM |
8854 | const struct breakpoint_ops *ops, |
8855 | int loc_enabled) | |
e58b0e63 PA |
8856 | { |
8857 | struct breakpoint *copy; | |
8858 | ||
06edf0c0 | 8859 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8860 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8861 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8862 | |
a6d9a66e | 8863 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8864 | copy->loc->requested_address = orig->loc->requested_address; |
8865 | copy->loc->address = orig->loc->address; | |
8866 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8867 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8868 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8869 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8870 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8871 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8872 | copy->frame_id = orig->frame_id; |
8873 | copy->thread = orig->thread; | |
6c95b8df | 8874 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8875 | |
8876 | copy->enable_state = bp_enabled; | |
8877 | copy->disposition = disp_donttouch; | |
8878 | copy->number = internal_breakpoint_number--; | |
8879 | ||
44702360 | 8880 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8881 | return copy; |
8882 | } | |
8883 | ||
06edf0c0 PA |
8884 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8885 | ORIG is NULL. */ | |
8886 | ||
8887 | struct breakpoint * | |
8888 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8889 | { | |
8890 | /* If there's nothing to clone, then return nothing. */ | |
8891 | if (orig == NULL) | |
8892 | return NULL; | |
8893 | ||
a1aa2221 | 8894 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8895 | } |
8896 | ||
611c83ae | 8897 | struct breakpoint * |
a6d9a66e UW |
8898 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8899 | enum bptype type) | |
611c83ae PA |
8900 | { |
8901 | struct symtab_and_line sal; | |
8902 | ||
8903 | sal = find_pc_line (pc, 0); | |
8904 | sal.pc = pc; | |
8905 | sal.section = find_pc_overlay (pc); | |
8906 | sal.explicit_pc = 1; | |
8907 | ||
a6d9a66e | 8908 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8909 | } |
c906108c | 8910 | \f |
c5aa993b | 8911 | |
c906108c SS |
8912 | /* Tell the user we have just set a breakpoint B. */ |
8913 | ||
8914 | static void | |
fba45db2 | 8915 | mention (struct breakpoint *b) |
c906108c | 8916 | { |
348d480f | 8917 | b->ops->print_mention (b); |
112e8700 | 8918 | if (current_uiout->is_mi_like_p ()) |
fb40c209 | 8919 | return; |
c906108c SS |
8920 | printf_filtered ("\n"); |
8921 | } | |
c906108c | 8922 | \f |
c5aa993b | 8923 | |
1a853c52 PA |
8924 | static int bp_loc_is_permanent (struct bp_location *loc); |
8925 | ||
0d381245 | 8926 | static struct bp_location * |
39d61571 | 8927 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
8928 | const struct symtab_and_line *sal) |
8929 | { | |
8930 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
8931 | CORE_ADDR adjusted_address; |
8932 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
8933 | ||
8934 | if (loc_gdbarch == NULL) | |
8935 | loc_gdbarch = b->gdbarch; | |
8936 | ||
8937 | /* Adjust the breakpoint's address prior to allocating a location. | |
8938 | Once we call allocate_bp_location(), that mostly uninitialized | |
8939 | location will be placed on the location chain. Adjustment of the | |
8940 | breakpoint may cause target_read_memory() to be called and we do | |
8941 | not want its scan of the location chain to find a breakpoint and | |
8942 | location that's only been partially initialized. */ | |
8943 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
8944 | sal->pc, b->type); | |
0d381245 | 8945 | |
d30113d4 | 8946 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 8947 | loc = allocate_bp_location (b); |
d30113d4 JK |
8948 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
8949 | tmp = &((*tmp)->next)) | |
0d381245 | 8950 | ; |
d30113d4 | 8951 | loc->next = *tmp; |
0d381245 | 8952 | *tmp = loc; |
3742cc8b | 8953 | |
0d381245 | 8954 | loc->requested_address = sal->pc; |
3742cc8b | 8955 | loc->address = adjusted_address; |
6c95b8df | 8956 | loc->pspace = sal->pspace; |
729662a5 TT |
8957 | loc->probe.probe = sal->probe; |
8958 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 8959 | gdb_assert (loc->pspace != NULL); |
0d381245 | 8960 | loc->section = sal->section; |
3742cc8b | 8961 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 8962 | loc->line_number = sal->line; |
2f202fde | 8963 | loc->symtab = sal->symtab; |
f8eba3c6 | 8964 | |
0e30163f JK |
8965 | set_breakpoint_location_function (loc, |
8966 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 8967 | |
6ae88661 LM |
8968 | /* While by definition, permanent breakpoints are already present in the |
8969 | code, we don't mark the location as inserted. Normally one would expect | |
8970 | that GDB could rely on that breakpoint instruction to stop the program, | |
8971 | thus removing the need to insert its own breakpoint, except that executing | |
8972 | the breakpoint instruction can kill the target instead of reporting a | |
8973 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
8974 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
8975 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
8976 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
8977 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
8978 | (If GDB later needs to continue execution past the permanent breakpoint, | |
8979 | it manually increments the PC, thus avoiding executing the breakpoint | |
8980 | instruction.) */ | |
1a853c52 | 8981 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 8982 | loc->permanent = 1; |
1a853c52 | 8983 | |
0d381245 VP |
8984 | return loc; |
8985 | } | |
514f746b AR |
8986 | \f |
8987 | ||
1cf4d951 | 8988 | /* See breakpoint.h. */ |
514f746b | 8989 | |
1cf4d951 PA |
8990 | int |
8991 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
8992 | { |
8993 | int len; | |
8994 | CORE_ADDR addr; | |
1afeeb75 | 8995 | const gdb_byte *bpoint; |
514f746b AR |
8996 | gdb_byte *target_mem; |
8997 | ||
1cf4d951 PA |
8998 | addr = address; |
8999 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9000 | ||
9001 | /* Software breakpoints unsupported? */ | |
9002 | if (bpoint == NULL) | |
9003 | return 0; | |
9004 | ||
224c3ddb | 9005 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9006 | |
9007 | /* Enable the automatic memory restoration from breakpoints while | |
9008 | we read the memory. Otherwise we could say about our temporary | |
9009 | breakpoints they are permanent. */ | |
cb85b21b TT |
9010 | scoped_restore restore_memory |
9011 | = make_scoped_restore_show_memory_breakpoints (0); | |
1cf4d951 PA |
9012 | |
9013 | if (target_read_memory (address, target_mem, len) == 0 | |
9014 | && memcmp (target_mem, bpoint, len) == 0) | |
cb85b21b | 9015 | return 1; |
1cf4d951 | 9016 | |
cb85b21b | 9017 | return 0; |
1cf4d951 PA |
9018 | } |
9019 | ||
9020 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9021 | return 0 otherwise. */ | |
9022 | ||
9023 | static int | |
9024 | bp_loc_is_permanent (struct bp_location *loc) | |
9025 | { | |
514f746b AR |
9026 | gdb_assert (loc != NULL); |
9027 | ||
244558af LM |
9028 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9029 | attempt to read from the addresses the locations of these breakpoint types | |
9030 | point to. program_breakpoint_here_p, below, will attempt to read | |
9031 | memory. */ | |
9032 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9033 | return 0; | |
9034 | ||
5ed8105e | 9035 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9036 | switch_to_program_space_and_thread (loc->pspace); |
5ed8105e | 9037 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b AR |
9038 | } |
9039 | ||
e7e0cddf SS |
9040 | /* Build a command list for the dprintf corresponding to the current |
9041 | settings of the dprintf style options. */ | |
9042 | ||
9043 | static void | |
9044 | update_dprintf_command_list (struct breakpoint *b) | |
9045 | { | |
9046 | char *dprintf_args = b->extra_string; | |
9047 | char *printf_line = NULL; | |
9048 | ||
9049 | if (!dprintf_args) | |
9050 | return; | |
9051 | ||
9052 | dprintf_args = skip_spaces (dprintf_args); | |
9053 | ||
9054 | /* Allow a comma, as it may have terminated a location, but don't | |
9055 | insist on it. */ | |
9056 | if (*dprintf_args == ',') | |
9057 | ++dprintf_args; | |
9058 | dprintf_args = skip_spaces (dprintf_args); | |
9059 | ||
9060 | if (*dprintf_args != '"') | |
9061 | error (_("Bad format string, missing '\"'.")); | |
9062 | ||
d3ce09f5 | 9063 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9064 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9065 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9066 | { |
9067 | if (!dprintf_function) | |
9068 | error (_("No function supplied for dprintf call")); | |
9069 | ||
9070 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9071 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9072 | dprintf_function, | |
9073 | dprintf_channel, | |
9074 | dprintf_args); | |
9075 | else | |
9076 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9077 | dprintf_function, | |
9078 | dprintf_args); | |
9079 | } | |
d3ce09f5 SS |
9080 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9081 | { | |
9082 | if (target_can_run_breakpoint_commands ()) | |
9083 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9084 | else | |
9085 | { | |
9086 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9087 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9088 | } | |
9089 | } | |
e7e0cddf SS |
9090 | else |
9091 | internal_error (__FILE__, __LINE__, | |
9092 | _("Invalid dprintf style.")); | |
9093 | ||
f28045c2 | 9094 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9095 | /* Manufacture a printf sequence. */ |
f28045c2 | 9096 | { |
8d749320 | 9097 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9098 | |
f28045c2 YQ |
9099 | printf_cmd_line->control_type = simple_control; |
9100 | printf_cmd_line->body_count = 0; | |
9101 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9102 | printf_cmd_line->next = NULL; |
f28045c2 | 9103 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9104 | |
93921405 | 9105 | breakpoint_set_commands (b, command_line_up (printf_cmd_line)); |
f28045c2 | 9106 | } |
e7e0cddf SS |
9107 | } |
9108 | ||
9109 | /* Update all dprintf commands, making their command lists reflect | |
9110 | current style settings. */ | |
9111 | ||
9112 | static void | |
9113 | update_dprintf_commands (char *args, int from_tty, | |
9114 | struct cmd_list_element *c) | |
9115 | { | |
9116 | struct breakpoint *b; | |
9117 | ||
9118 | ALL_BREAKPOINTS (b) | |
9119 | { | |
9120 | if (b->type == bp_dprintf) | |
9121 | update_dprintf_command_list (b); | |
9122 | } | |
9123 | } | |
c3f6f71d | 9124 | |
f00aae0f KS |
9125 | /* Create a breakpoint with SAL as location. Use LOCATION |
9126 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9127 | as condition expression. If LOCATION is NULL then create an |
9128 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9129 | |
9130 | static void | |
d9b3f62e | 9131 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
6c5b2ebe | 9132 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9133 | event_location_up &&location, |
e1e01040 PA |
9134 | gdb::unique_xmalloc_ptr<char> filter, |
9135 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9136 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9137 | enum bptype type, enum bpdisp disposition, |
9138 | int thread, int task, int ignore_count, | |
c0a91b2b | 9139 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9140 | int enabled, int internal, unsigned flags, |
9141 | int display_canonical) | |
018d34a4 | 9142 | { |
0d381245 | 9143 | int i; |
018d34a4 VP |
9144 | |
9145 | if (type == bp_hardware_breakpoint) | |
9146 | { | |
fbbd034e AS |
9147 | int target_resources_ok; |
9148 | ||
9149 | i = hw_breakpoint_used_count (); | |
9150 | target_resources_ok = | |
9151 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9152 | i + 1, 0); |
9153 | if (target_resources_ok == 0) | |
9154 | error (_("No hardware breakpoint support in the target.")); | |
9155 | else if (target_resources_ok < 0) | |
9156 | error (_("Hardware breakpoints used exceeds limit.")); | |
9157 | } | |
9158 | ||
6c5b2ebe | 9159 | gdb_assert (!sals.empty ()); |
6c95b8df | 9160 | |
6c5b2ebe | 9161 | for (const auto &sal : sals) |
0d381245 | 9162 | { |
0d381245 VP |
9163 | struct bp_location *loc; |
9164 | ||
9165 | if (from_tty) | |
5af949e3 UW |
9166 | { |
9167 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9168 | if (!loc_gdbarch) | |
9169 | loc_gdbarch = gdbarch; | |
9170 | ||
9171 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9172 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9173 | } |
0d381245 | 9174 | |
6c5b2ebe | 9175 | if (&sal == &sals[0]) |
0d381245 | 9176 | { |
d9b3f62e | 9177 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9178 | b->thread = thread; |
4a306c9a | 9179 | b->task = task; |
855a6e68 | 9180 | |
e1e01040 PA |
9181 | b->cond_string = cond_string.release (); |
9182 | b->extra_string = extra_string.release (); | |
0d381245 | 9183 | b->ignore_count = ignore_count; |
41447f92 | 9184 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9185 | b->disposition = disposition; |
6c95b8df | 9186 | |
44f238bb PA |
9187 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9188 | b->loc->inserted = 1; | |
9189 | ||
0fb4aa4b PA |
9190 | if (type == bp_static_tracepoint) |
9191 | { | |
d9b3f62e | 9192 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9193 | struct static_tracepoint_marker marker; |
9194 | ||
983af33b | 9195 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9196 | { |
9197 | /* We already know the marker exists, otherwise, we | |
9198 | wouldn't see a sal for it. */ | |
d28cd78a TT |
9199 | const char *p |
9200 | = &event_location_to_string (b->location.get ())[3]; | |
f00aae0f | 9201 | const char *endp; |
0fb4aa4b | 9202 | char *marker_str; |
0fb4aa4b | 9203 | |
f1735a53 | 9204 | p = skip_spaces (p); |
0fb4aa4b | 9205 | |
f1735a53 | 9206 | endp = skip_to_space (p); |
0fb4aa4b PA |
9207 | |
9208 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9209 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9210 | |
3e43a32a MS |
9211 | printf_filtered (_("Probed static tracepoint " |
9212 | "marker \"%s\"\n"), | |
d9b3f62e | 9213 | t->static_trace_marker_id); |
0fb4aa4b PA |
9214 | } |
9215 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9216 | { | |
d9b3f62e | 9217 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9218 | release_static_tracepoint_marker (&marker); |
9219 | ||
3e43a32a MS |
9220 | printf_filtered (_("Probed static tracepoint " |
9221 | "marker \"%s\"\n"), | |
d9b3f62e | 9222 | t->static_trace_marker_id); |
0fb4aa4b PA |
9223 | } |
9224 | else | |
3e43a32a MS |
9225 | warning (_("Couldn't determine the static " |
9226 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9227 | } |
9228 | ||
0d381245 VP |
9229 | loc = b->loc; |
9230 | } | |
9231 | else | |
018d34a4 | 9232 | { |
39d61571 | 9233 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9234 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9235 | loc->inserted = 1; | |
0d381245 VP |
9236 | } |
9237 | ||
9238 | if (b->cond_string) | |
9239 | { | |
bbc13ae3 KS |
9240 | const char *arg = b->cond_string; |
9241 | ||
1bb9788d TT |
9242 | loc->cond = parse_exp_1 (&arg, loc->address, |
9243 | block_for_pc (loc->address), 0); | |
0d381245 | 9244 | if (*arg) |
588ae58c | 9245 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9246 | } |
e7e0cddf SS |
9247 | |
9248 | /* Dynamic printf requires and uses additional arguments on the | |
9249 | command line, otherwise it's an error. */ | |
9250 | if (type == bp_dprintf) | |
9251 | { | |
9252 | if (b->extra_string) | |
9253 | update_dprintf_command_list (b); | |
9254 | else | |
9255 | error (_("Format string required")); | |
9256 | } | |
9257 | else if (b->extra_string) | |
588ae58c | 9258 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9259 | } |
018d34a4 | 9260 | |
56435ebe | 9261 | b->display_canonical = display_canonical; |
f00aae0f | 9262 | if (location != NULL) |
d28cd78a | 9263 | b->location = std::move (location); |
018d34a4 | 9264 | else |
d28cd78a | 9265 | b->location = new_address_location (b->loc->address, NULL, 0); |
e1e01040 | 9266 | b->filter = filter.release (); |
d9b3f62e | 9267 | } |
018d34a4 | 9268 | |
d9b3f62e PA |
9269 | static void |
9270 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
6c5b2ebe | 9271 | gdb::array_view<const symtab_and_line> sals, |
ffc2605c | 9272 | event_location_up &&location, |
e1e01040 PA |
9273 | gdb::unique_xmalloc_ptr<char> filter, |
9274 | gdb::unique_xmalloc_ptr<char> cond_string, | |
9275 | gdb::unique_xmalloc_ptr<char> extra_string, | |
d9b3f62e PA |
9276 | enum bptype type, enum bpdisp disposition, |
9277 | int thread, int task, int ignore_count, | |
c0a91b2b | 9278 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9279 | int enabled, int internal, unsigned flags, |
9280 | int display_canonical) | |
d9b3f62e | 9281 | { |
a5e364af | 9282 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
d9b3f62e | 9283 | |
a5e364af | 9284 | init_breakpoint_sal (b.get (), gdbarch, |
ffc2605c | 9285 | sals, std::move (location), |
e1e01040 PA |
9286 | std::move (filter), |
9287 | std::move (cond_string), | |
9288 | std::move (extra_string), | |
d9b3f62e PA |
9289 | type, disposition, |
9290 | thread, task, ignore_count, | |
9291 | ops, from_tty, | |
44f238bb PA |
9292 | enabled, internal, flags, |
9293 | display_canonical); | |
d9b3f62e | 9294 | |
b270e6f9 | 9295 | install_breakpoint (internal, std::move (b), 0); |
018d34a4 VP |
9296 | } |
9297 | ||
9298 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9299 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9300 | value. COND_STRING, if not NULL, specified the condition to be | |
9301 | used for all breakpoints. Essentially the only case where | |
9302 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9303 | function. In that case, it's still not possible to specify | |
9304 | separate conditions for different overloaded functions, so | |
9305 | we take just a single condition string. | |
9306 | ||
c3f6f71d | 9307 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9308 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9309 | array contents). If the function fails (error() is called), the |
9310 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9311 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9312 | |
9313 | static void | |
8cdf0e15 | 9314 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9315 | struct linespec_result *canonical, |
e1e01040 PA |
9316 | gdb::unique_xmalloc_ptr<char> cond_string, |
9317 | gdb::unique_xmalloc_ptr<char> extra_string, | |
8cdf0e15 VP |
9318 | enum bptype type, enum bpdisp disposition, |
9319 | int thread, int task, int ignore_count, | |
c0a91b2b | 9320 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9321 | int enabled, int internal, unsigned flags) |
c906108c | 9322 | { |
f8eba3c6 | 9323 | if (canonical->pre_expanded) |
6c5b2ebe | 9324 | gdb_assert (canonical->lsals.size () == 1); |
f8eba3c6 | 9325 | |
6c5b2ebe | 9326 | for (const auto &lsal : canonical->lsals) |
c3f6f71d | 9327 | { |
f00aae0f | 9328 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9329 | 'break', without arguments. */ |
ffc2605c | 9330 | event_location_up location |
f00aae0f | 9331 | = (canonical->location != NULL |
8e9e35b1 | 9332 | ? copy_event_location (canonical->location.get ()) : NULL); |
e1e01040 | 9333 | gdb::unique_xmalloc_ptr<char> filter_string |
6c5b2ebe | 9334 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
0d381245 | 9335 | |
6c5b2ebe | 9336 | create_breakpoint_sal (gdbarch, lsal.sals, |
ffc2605c | 9337 | std::move (location), |
e1e01040 PA |
9338 | std::move (filter_string), |
9339 | std::move (cond_string), | |
9340 | std::move (extra_string), | |
e7e0cddf | 9341 | type, disposition, |
84f4c1fe | 9342 | thread, task, ignore_count, ops, |
44f238bb | 9343 | from_tty, enabled, internal, flags, |
56435ebe | 9344 | canonical->special_display); |
c3f6f71d | 9345 | } |
c3f6f71d | 9346 | } |
c906108c | 9347 | |
f00aae0f | 9348 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9349 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9350 | addresses found. LOCATION points to the end of the SAL (for |
9351 | linespec locations). | |
9998af43 TJB |
9352 | |
9353 | The array and the line spec strings are allocated on the heap, it is | |
9354 | the caller's responsibility to free them. */ | |
c906108c | 9355 | |
b9362cc7 | 9356 | static void |
f00aae0f | 9357 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9358 | struct linespec_result *canonical) |
c3f6f71d | 9359 | { |
f00aae0f KS |
9360 | struct symtab_and_line cursal; |
9361 | ||
9362 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9363 | { | |
9364 | const char *address = get_linespec_location (location); | |
9365 | ||
9366 | if (address == NULL) | |
9367 | { | |
9368 | /* The last displayed codepoint, if it's valid, is our default | |
9369 | breakpoint address. */ | |
9370 | if (last_displayed_sal_is_valid ()) | |
9371 | { | |
f00aae0f KS |
9372 | /* Set sal's pspace, pc, symtab, and line to the values |
9373 | corresponding to the last call to print_frame_info. | |
9374 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9375 | as the breakpoint line number is inappropriate otherwise. | |
9376 | find_pc_line would adjust PC, re-set it back. */ | |
51abb421 PA |
9377 | symtab_and_line sal = get_last_displayed_sal (); |
9378 | CORE_ADDR pc = sal.pc; | |
9379 | ||
f00aae0f KS |
9380 | sal = find_pc_line (pc, 0); |
9381 | ||
9382 | /* "break" without arguments is equivalent to "break *PC" | |
9383 | where PC is the last displayed codepoint's address. So | |
9384 | make sure to set sal.explicit_pc to prevent GDB from | |
9385 | trying to expand the list of sals to include all other | |
9386 | instances with the same symtab and line. */ | |
9387 | sal.pc = pc; | |
9388 | sal.explicit_pc = 1; | |
9389 | ||
6c5b2ebe PA |
9390 | struct linespec_sals lsal; |
9391 | lsal.sals = {sal}; | |
f00aae0f KS |
9392 | lsal.canonical = NULL; |
9393 | ||
6c5b2ebe | 9394 | canonical->lsals.push_back (std::move (lsal)); |
f00aae0f KS |
9395 | return; |
9396 | } | |
9397 | else | |
9398 | error (_("No default breakpoint address now.")); | |
c906108c | 9399 | } |
c906108c | 9400 | } |
f00aae0f KS |
9401 | |
9402 | /* Force almost all breakpoints to be in terms of the | |
9403 | current_source_symtab (which is decode_line_1's default). | |
9404 | This should produce the results we want almost all of the | |
9405 | time while leaving default_breakpoint_* alone. | |
9406 | ||
9407 | ObjC: However, don't match an Objective-C method name which | |
9408 | may have a '+' or '-' succeeded by a '['. */ | |
9409 | cursal = get_current_source_symtab_and_line (); | |
9410 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9411 | { |
f00aae0f | 9412 | const char *address = NULL; |
cc80f267 | 9413 | |
f00aae0f KS |
9414 | if (event_location_type (location) == LINESPEC_LOCATION) |
9415 | address = get_linespec_location (location); | |
cc80f267 | 9416 | |
f00aae0f KS |
9417 | if (!cursal.symtab |
9418 | || (address != NULL | |
9419 | && strchr ("+-", address[0]) != NULL | |
9420 | && address[1] != '[')) | |
9421 | { | |
c2f4122d | 9422 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9423 | get_last_displayed_symtab (), |
9424 | get_last_displayed_line (), | |
9425 | canonical, NULL, NULL); | |
9426 | return; | |
9427 | } | |
c906108c | 9428 | } |
f00aae0f | 9429 | |
c2f4122d | 9430 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9431 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9432 | } |
c906108c | 9433 | |
c906108c | 9434 | |
c3f6f71d | 9435 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9436 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9437 | |
b9362cc7 | 9438 | static void |
6c5b2ebe | 9439 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
c3f6f71d | 9440 | { |
6c5b2ebe PA |
9441 | for (auto &sal : sals) |
9442 | resolve_sal_pc (&sal); | |
c3f6f71d JM |
9443 | } |
9444 | ||
7a697b8d SS |
9445 | /* Fast tracepoints may have restrictions on valid locations. For |
9446 | instance, a fast tracepoint using a jump instead of a trap will | |
9447 | likely have to overwrite more bytes than a trap would, and so can | |
9448 | only be placed where the instruction is longer than the jump, or a | |
9449 | multi-instruction sequence does not have a jump into the middle of | |
9450 | it, etc. */ | |
9451 | ||
9452 | static void | |
9453 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6c5b2ebe | 9454 | gdb::array_view<const symtab_and_line> sals) |
7a697b8d | 9455 | { |
6c5b2ebe | 9456 | int rslt; |
7a697b8d SS |
9457 | char *msg; |
9458 | struct cleanup *old_chain; | |
9459 | ||
6c5b2ebe | 9460 | for (const auto &sal : sals) |
7a697b8d | 9461 | { |
f8eba3c6 TT |
9462 | struct gdbarch *sarch; |
9463 | ||
6c5b2ebe | 9464 | sarch = get_sal_arch (sal); |
f8eba3c6 TT |
9465 | /* We fall back to GDBARCH if there is no architecture |
9466 | associated with SAL. */ | |
9467 | if (sarch == NULL) | |
9468 | sarch = gdbarch; | |
6c5b2ebe | 9469 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg); |
7a697b8d SS |
9470 | old_chain = make_cleanup (xfree, msg); |
9471 | ||
9472 | if (!rslt) | |
53c3572a | 9473 | error (_("May not have a fast tracepoint at %s%s"), |
6c5b2ebe | 9474 | paddress (sarch, sal.pc), (msg ? msg : "")); |
7a697b8d SS |
9475 | |
9476 | do_cleanups (old_chain); | |
9477 | } | |
9478 | } | |
9479 | ||
018d34a4 VP |
9480 | /* Given TOK, a string specification of condition and thread, as |
9481 | accepted by the 'break' command, extract the condition | |
9482 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9483 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9484 | If no condition is found, *COND_STRING is set to NULL. |
9485 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9486 | |
9487 | static void | |
bbc13ae3 | 9488 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9489 | char **cond_string, int *thread, int *task, |
9490 | char **rest) | |
018d34a4 VP |
9491 | { |
9492 | *cond_string = NULL; | |
9493 | *thread = -1; | |
ed1d1739 KS |
9494 | *task = 0; |
9495 | *rest = NULL; | |
9496 | ||
018d34a4 VP |
9497 | while (tok && *tok) |
9498 | { | |
bbc13ae3 | 9499 | const char *end_tok; |
018d34a4 | 9500 | int toklen; |
bbc13ae3 KS |
9501 | const char *cond_start = NULL; |
9502 | const char *cond_end = NULL; | |
cc59ec59 | 9503 | |
f1735a53 | 9504 | tok = skip_spaces (tok); |
e7e0cddf SS |
9505 | |
9506 | if ((*tok == '"' || *tok == ',') && rest) | |
9507 | { | |
9508 | *rest = savestring (tok, strlen (tok)); | |
9509 | return; | |
9510 | } | |
9511 | ||
f1735a53 | 9512 | end_tok = skip_to_space (tok); |
d634f2de | 9513 | |
018d34a4 | 9514 | toklen = end_tok - tok; |
d634f2de | 9515 | |
018d34a4 VP |
9516 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9517 | { | |
9518 | tok = cond_start = end_tok + 1; | |
4d01a485 | 9519 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
018d34a4 | 9520 | cond_end = tok; |
d634f2de | 9521 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9522 | } |
9523 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9524 | { | |
5d5658a1 PA |
9525 | const char *tmptok; |
9526 | struct thread_info *thr; | |
d634f2de | 9527 | |
018d34a4 | 9528 | tok = end_tok + 1; |
5d5658a1 | 9529 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9530 | if (tok == tmptok) |
9531 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9532 | *thread = thr->global_num; |
bbc13ae3 | 9533 | tok = tmptok; |
018d34a4 | 9534 | } |
4a306c9a JB |
9535 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9536 | { | |
9537 | char *tmptok; | |
9538 | ||
9539 | tok = end_tok + 1; | |
bbc13ae3 | 9540 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9541 | if (tok == tmptok) |
9542 | error (_("Junk after task keyword.")); | |
9543 | if (!valid_task_id (*task)) | |
b6199126 | 9544 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9545 | tok = tmptok; |
4a306c9a | 9546 | } |
e7e0cddf SS |
9547 | else if (rest) |
9548 | { | |
9549 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9550 | return; |
e7e0cddf | 9551 | } |
018d34a4 VP |
9552 | else |
9553 | error (_("Junk at end of arguments.")); | |
9554 | } | |
9555 | } | |
9556 | ||
0fb4aa4b PA |
9557 | /* Decode a static tracepoint marker spec. */ |
9558 | ||
6c5b2ebe | 9559 | static std::vector<symtab_and_line> |
f00aae0f | 9560 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9561 | { |
9562 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
0fb4aa4b | 9563 | struct cleanup *old_chain; |
f00aae0f KS |
9564 | const char *p = &(*arg_p)[3]; |
9565 | const char *endp; | |
0fb4aa4b PA |
9566 | char *marker_str; |
9567 | int i; | |
9568 | ||
f1735a53 | 9569 | p = skip_spaces (p); |
0fb4aa4b | 9570 | |
f1735a53 | 9571 | endp = skip_to_space (p); |
0fb4aa4b PA |
9572 | |
9573 | marker_str = savestring (p, endp - p); | |
9574 | old_chain = make_cleanup (xfree, marker_str); | |
9575 | ||
9576 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9577 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9578 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9579 | ||
6c5b2ebe PA |
9580 | std::vector<symtab_and_line> sals; |
9581 | sals.reserve (VEC_length(static_tracepoint_marker_p, markers)); | |
0fb4aa4b | 9582 | |
6c5b2ebe | 9583 | for (i = 0; i < VEC_length(static_tracepoint_marker_p, markers); i++) |
0fb4aa4b PA |
9584 | { |
9585 | struct static_tracepoint_marker *marker; | |
9586 | ||
9587 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9588 | ||
51abb421 | 9589 | symtab_and_line sal = find_pc_line (marker->address, 0); |
6c5b2ebe PA |
9590 | sal.pc = marker->address; |
9591 | sals.push_back (sal); | |
0fb4aa4b PA |
9592 | |
9593 | release_static_tracepoint_marker (marker); | |
9594 | } | |
9595 | ||
9596 | do_cleanups (old_chain); | |
9597 | ||
9598 | *arg_p = endp; | |
9599 | return sals; | |
9600 | } | |
9601 | ||
f00aae0f | 9602 | /* See breakpoint.h. */ |
0101ce28 | 9603 | |
8cdf0e15 VP |
9604 | int |
9605 | create_breakpoint (struct gdbarch *gdbarch, | |
e1e01040 PA |
9606 | const struct event_location *location, |
9607 | const char *cond_string, | |
9608 | int thread, const char *extra_string, | |
f00aae0f | 9609 | int parse_extra, |
0fb4aa4b | 9610 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9611 | int ignore_count, |
9612 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9613 | const struct breakpoint_ops *ops, |
44f238bb PA |
9614 | int from_tty, int enabled, int internal, |
9615 | unsigned flags) | |
c3f6f71d | 9616 | { |
7efd8fc2 | 9617 | struct linespec_result canonical; |
80c99de1 | 9618 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9619 | int pending = 0; |
4a306c9a | 9620 | int task = 0; |
86b17b60 | 9621 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9622 | |
348d480f PA |
9623 | gdb_assert (ops != NULL); |
9624 | ||
f00aae0f KS |
9625 | /* If extra_string isn't useful, set it to NULL. */ |
9626 | if (extra_string != NULL && *extra_string == '\0') | |
9627 | extra_string = NULL; | |
9628 | ||
492d29ea | 9629 | TRY |
b78a6381 | 9630 | { |
f00aae0f | 9631 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9632 | } |
492d29ea | 9633 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9634 | { |
492d29ea PA |
9635 | /* If caller is interested in rc value from parse, set |
9636 | value. */ | |
9637 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9638 | { |
05ff989b AC |
9639 | /* If pending breakpoint support is turned off, throw |
9640 | error. */ | |
fa8d40ab JJ |
9641 | |
9642 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9643 | throw_exception (e); |
9644 | ||
9645 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9646 | |
05ff989b AC |
9647 | /* If pending breakpoint support is auto query and the user |
9648 | selects no, then simply return the error code. */ | |
059fb39f | 9649 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9650 | && !nquery (_("Make %s pending on future shared library load? "), |
9651 | bptype_string (type_wanted))) | |
fd9b8c24 | 9652 | return 0; |
fa8d40ab | 9653 | |
05ff989b AC |
9654 | /* At this point, either the user was queried about setting |
9655 | a pending breakpoint and selected yes, or pending | |
9656 | breakpoint behavior is on and thus a pending breakpoint | |
9657 | is defaulted on behalf of the user. */ | |
f00aae0f | 9658 | pending = 1; |
0101ce28 | 9659 | } |
492d29ea PA |
9660 | else |
9661 | throw_exception (e); | |
0101ce28 | 9662 | } |
492d29ea PA |
9663 | END_CATCH |
9664 | ||
6c5b2ebe | 9665 | if (!pending && canonical.lsals.empty ()) |
492d29ea | 9666 | return 0; |
c3f6f71d | 9667 | |
c3f6f71d JM |
9668 | /* ----------------------------- SNIP ----------------------------- |
9669 | Anything added to the cleanup chain beyond this point is assumed | |
9670 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9671 | then the memory is not reclaimed. */ |
9672 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9673 | |
c3f6f71d JM |
9674 | /* Resolve all line numbers to PC's and verify that the addresses |
9675 | are ok for the target. */ | |
0101ce28 | 9676 | if (!pending) |
f8eba3c6 | 9677 | { |
6c5b2ebe PA |
9678 | for (auto &lsal : canonical.lsals) |
9679 | breakpoint_sals_to_pc (lsal.sals); | |
f8eba3c6 | 9680 | } |
c3f6f71d | 9681 | |
7a697b8d | 9682 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9683 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 | 9684 | { |
6c5b2ebe PA |
9685 | for (const auto &lsal : canonical.lsals) |
9686 | check_fast_tracepoint_sals (gdbarch, lsal.sals); | |
f8eba3c6 | 9687 | } |
7a697b8d | 9688 | |
c3f6f71d JM |
9689 | /* Verify that condition can be parsed, before setting any |
9690 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9691 | breakpoint. */ |
0101ce28 | 9692 | if (!pending) |
c3f6f71d | 9693 | { |
e1e01040 PA |
9694 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
9695 | gdb::unique_xmalloc_ptr<char> extra_string_copy; | |
9696 | ||
f00aae0f | 9697 | if (parse_extra) |
72b2ff0e | 9698 | { |
0878d0fa | 9699 | char *rest; |
e1e01040 | 9700 | char *cond; |
52d361e1 | 9701 | |
6c5b2ebe | 9702 | const linespec_sals &lsal = canonical.lsals[0]; |
52d361e1 | 9703 | |
0878d0fa YQ |
9704 | /* Here we only parse 'arg' to separate condition |
9705 | from thread number, so parsing in context of first | |
9706 | sal is OK. When setting the breakpoint we'll | |
9707 | re-parse it in context of each sal. */ | |
9708 | ||
6c5b2ebe | 9709 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
e1e01040 PA |
9710 | &cond, &thread, &task, &rest); |
9711 | cond_string_copy.reset (cond); | |
9712 | extra_string_copy.reset (rest); | |
72b2ff0e | 9713 | } |
2f069f6f | 9714 | else |
72b2ff0e | 9715 | { |
f00aae0f KS |
9716 | if (type_wanted != bp_dprintf |
9717 | && extra_string != NULL && *extra_string != '\0') | |
9718 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9719 | |
9720 | /* Create a private copy of condition string. */ | |
9721 | if (cond_string) | |
e1e01040 | 9722 | cond_string_copy.reset (xstrdup (cond_string)); |
0878d0fa YQ |
9723 | /* Create a private copy of any extra string. */ |
9724 | if (extra_string) | |
e1e01040 | 9725 | extra_string_copy.reset (xstrdup (extra_string)); |
72b2ff0e | 9726 | } |
0fb4aa4b | 9727 | |
52d361e1 | 9728 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e1e01040 PA |
9729 | std::move (cond_string_copy), |
9730 | std::move (extra_string_copy), | |
9731 | type_wanted, | |
d9b3f62e PA |
9732 | tempflag ? disp_del : disp_donttouch, |
9733 | thread, task, ignore_count, ops, | |
44f238bb | 9734 | from_tty, enabled, internal, flags); |
c906108c | 9735 | } |
0101ce28 JJ |
9736 | else |
9737 | { | |
a5e364af | 9738 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
bfccc43c | 9739 | |
a5e364af | 9740 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
d28cd78a | 9741 | b->location = copy_event_location (location); |
bfccc43c | 9742 | |
f00aae0f KS |
9743 | if (parse_extra) |
9744 | b->cond_string = NULL; | |
e12c7713 MK |
9745 | else |
9746 | { | |
9747 | /* Create a private copy of condition string. */ | |
e1e01040 | 9748 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
15630549 | 9749 | b->thread = thread; |
e12c7713 | 9750 | } |
f00aae0f KS |
9751 | |
9752 | /* Create a private copy of any extra string. */ | |
e1e01040 | 9753 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
0101ce28 | 9754 | b->ignore_count = ignore_count; |
0101ce28 | 9755 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9756 | b->condition_not_parsed = 1; |
41447f92 | 9757 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9758 | if ((type_wanted != bp_breakpoint |
9759 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9760 | b->pspace = current_program_space; |
8bea4e01 | 9761 | |
b270e6f9 | 9762 | install_breakpoint (internal, std::move (b), 0); |
0101ce28 JJ |
9763 | } |
9764 | ||
6c5b2ebe | 9765 | if (canonical.lsals.size () > 1) |
95a42b64 | 9766 | { |
3e43a32a MS |
9767 | warning (_("Multiple breakpoints were set.\nUse the " |
9768 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9769 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9770 | } |
9771 | ||
80c99de1 PA |
9772 | /* That's it. Discard the cleanups for data inserted into the |
9773 | breakpoint. */ | |
9774 | discard_cleanups (bkpt_chain); | |
217dc9e2 | 9775 | |
80c99de1 | 9776 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9777 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9778 | |
9779 | return 1; | |
c3f6f71d | 9780 | } |
c906108c | 9781 | |
348d480f | 9782 | /* Set a breakpoint. |
72b2ff0e VP |
9783 | ARG is a string describing breakpoint address, |
9784 | condition, and thread. | |
9785 | FLAG specifies if a breakpoint is hardware on, | |
9786 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9787 | and BP_TEMPFLAG. */ | |
348d480f | 9788 | |
98deb0da | 9789 | static void |
72b2ff0e | 9790 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9791 | { |
72b2ff0e | 9792 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9793 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9794 | ? bp_hardware_breakpoint | |
9795 | : bp_breakpoint); | |
55aa24fb | 9796 | struct breakpoint_ops *ops; |
f00aae0f | 9797 | |
ffc2605c | 9798 | event_location_up location = string_to_event_location (&arg, current_language); |
55aa24fb SDJ |
9799 | |
9800 | /* Matching breakpoints on probes. */ | |
5b56227b | 9801 | if (location != NULL |
ffc2605c | 9802 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
9803 | ops = &bkpt_probe_breakpoint_ops; |
9804 | else | |
9805 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9806 | |
8cdf0e15 | 9807 | create_breakpoint (get_current_arch (), |
ffc2605c | 9808 | location.get (), |
f00aae0f | 9809 | NULL, 0, arg, 1 /* parse arg */, |
0fb4aa4b | 9810 | tempflag, type_wanted, |
8cdf0e15 VP |
9811 | 0 /* Ignore count */, |
9812 | pending_break_support, | |
55aa24fb | 9813 | ops, |
8cdf0e15 | 9814 | from_tty, |
84f4c1fe | 9815 | 1 /* enabled */, |
44f238bb PA |
9816 | 0 /* internal */, |
9817 | 0); | |
c906108c SS |
9818 | } |
9819 | ||
c906108c SS |
9820 | /* Helper function for break_command_1 and disassemble_command. */ |
9821 | ||
9822 | void | |
fba45db2 | 9823 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
9824 | { |
9825 | CORE_ADDR pc; | |
9826 | ||
9827 | if (sal->pc == 0 && sal->symtab != NULL) | |
9828 | { | |
9829 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 9830 | error (_("No line %d in file \"%s\"."), |
05cba821 | 9831 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 9832 | sal->pc = pc; |
6a048695 | 9833 | |
4a64f543 MS |
9834 | /* If this SAL corresponds to a breakpoint inserted using a line |
9835 | number, then skip the function prologue if necessary. */ | |
6a048695 | 9836 | if (sal->explicit_line) |
059acae7 | 9837 | skip_prologue_sal (sal); |
c906108c SS |
9838 | } |
9839 | ||
9840 | if (sal->section == 0 && sal->symtab != NULL) | |
9841 | { | |
346d1dfe | 9842 | const struct blockvector *bv; |
3977b71f | 9843 | const struct block *b; |
c5aa993b | 9844 | struct symbol *sym; |
c906108c | 9845 | |
43f3e411 DE |
9846 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
9847 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
9848 | if (bv != NULL) |
9849 | { | |
7f0df278 | 9850 | sym = block_linkage_function (b); |
c906108c SS |
9851 | if (sym != NULL) |
9852 | { | |
eb822aa6 DE |
9853 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
9854 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
9855 | sym); | |
c906108c SS |
9856 | } |
9857 | else | |
9858 | { | |
4a64f543 MS |
9859 | /* It really is worthwhile to have the section, so we'll |
9860 | just have to look harder. This case can be executed | |
9861 | if we have line numbers but no functions (as can | |
9862 | happen in assembly source). */ | |
c906108c | 9863 | |
5ed8105e | 9864 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
6c95b8df | 9865 | switch_to_program_space_and_thread (sal->pspace); |
c906108c | 9866 | |
5ed8105e | 9867 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
7cbd4a93 | 9868 | if (msym.minsym) |
efd66ac6 | 9869 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
c906108c SS |
9870 | } |
9871 | } | |
9872 | } | |
9873 | } | |
9874 | ||
9875 | void | |
fba45db2 | 9876 | break_command (char *arg, int from_tty) |
c906108c | 9877 | { |
db107f19 | 9878 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9879 | } |
9880 | ||
c906108c | 9881 | void |
fba45db2 | 9882 | tbreak_command (char *arg, int from_tty) |
c906108c | 9883 | { |
db107f19 | 9884 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
9885 | } |
9886 | ||
c906108c | 9887 | static void |
fba45db2 | 9888 | hbreak_command (char *arg, int from_tty) |
c906108c | 9889 | { |
db107f19 | 9890 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
9891 | } |
9892 | ||
9893 | static void | |
fba45db2 | 9894 | thbreak_command (char *arg, int from_tty) |
c906108c | 9895 | { |
db107f19 | 9896 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
9897 | } |
9898 | ||
9899 | static void | |
fba45db2 | 9900 | stop_command (char *arg, int from_tty) |
c906108c | 9901 | { |
a3f17187 | 9902 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 9903 | Usage: stop in <function | address>\n\ |
a3f17187 | 9904 | stop at <line>\n")); |
c906108c SS |
9905 | } |
9906 | ||
9907 | static void | |
fba45db2 | 9908 | stopin_command (char *arg, int from_tty) |
c906108c SS |
9909 | { |
9910 | int badInput = 0; | |
9911 | ||
c5aa993b | 9912 | if (arg == (char *) NULL) |
c906108c SS |
9913 | badInput = 1; |
9914 | else if (*arg != '*') | |
9915 | { | |
9916 | char *argptr = arg; | |
9917 | int hasColon = 0; | |
9918 | ||
4a64f543 | 9919 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 9920 | say it is bad, otherwise, it should be an address or |
4a64f543 | 9921 | function/method name. */ |
c906108c | 9922 | while (*argptr && !hasColon) |
c5aa993b JM |
9923 | { |
9924 | hasColon = (*argptr == ':'); | |
9925 | argptr++; | |
9926 | } | |
c906108c SS |
9927 | |
9928 | if (hasColon) | |
c5aa993b | 9929 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 9930 | else |
c5aa993b | 9931 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
9932 | } |
9933 | ||
9934 | if (badInput) | |
a3f17187 | 9935 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 9936 | else |
db107f19 | 9937 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9938 | } |
9939 | ||
9940 | static void | |
fba45db2 | 9941 | stopat_command (char *arg, int from_tty) |
c906108c SS |
9942 | { |
9943 | int badInput = 0; | |
9944 | ||
c5aa993b | 9945 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
9946 | badInput = 1; |
9947 | else | |
9948 | { | |
9949 | char *argptr = arg; | |
9950 | int hasColon = 0; | |
9951 | ||
4a64f543 MS |
9952 | /* Look for a ':'. If there is a '::' then get out, otherwise |
9953 | it is probably a line number. */ | |
c906108c | 9954 | while (*argptr && !hasColon) |
c5aa993b JM |
9955 | { |
9956 | hasColon = (*argptr == ':'); | |
9957 | argptr++; | |
9958 | } | |
c906108c SS |
9959 | |
9960 | if (hasColon) | |
c5aa993b | 9961 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 9962 | else |
c5aa993b | 9963 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
9964 | } |
9965 | ||
9966 | if (badInput) | |
a3f17187 | 9967 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 9968 | else |
db107f19 | 9969 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
9970 | } |
9971 | ||
e7e0cddf SS |
9972 | /* The dynamic printf command is mostly like a regular breakpoint, but |
9973 | with a prewired command list consisting of a single output command, | |
9974 | built from extra arguments supplied on the dprintf command | |
9975 | line. */ | |
9976 | ||
da821c7b | 9977 | static void |
e7e0cddf SS |
9978 | dprintf_command (char *arg, int from_tty) |
9979 | { | |
ffc2605c | 9980 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f KS |
9981 | |
9982 | /* If non-NULL, ARG should have been advanced past the location; | |
9983 | the next character must be ','. */ | |
9984 | if (arg != NULL) | |
9985 | { | |
9986 | if (arg[0] != ',' || arg[1] == '\0') | |
9987 | error (_("Format string required")); | |
9988 | else | |
9989 | { | |
9990 | /* Skip the comma. */ | |
9991 | ++arg; | |
9992 | } | |
9993 | } | |
9994 | ||
e7e0cddf | 9995 | create_breakpoint (get_current_arch (), |
ffc2605c | 9996 | location.get (), |
f00aae0f | 9997 | NULL, 0, arg, 1 /* parse arg */, |
e7e0cddf SS |
9998 | 0, bp_dprintf, |
9999 | 0 /* Ignore count */, | |
10000 | pending_break_support, | |
10001 | &dprintf_breakpoint_ops, | |
10002 | from_tty, | |
10003 | 1 /* enabled */, | |
10004 | 0 /* internal */, | |
10005 | 0); | |
10006 | } | |
10007 | ||
d3ce09f5 SS |
10008 | static void |
10009 | agent_printf_command (char *arg, int from_tty) | |
10010 | { | |
10011 | error (_("May only run agent-printf on the target")); | |
10012 | } | |
10013 | ||
f1310107 TJB |
10014 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10015 | ranged breakpoints. */ | |
10016 | ||
10017 | static int | |
10018 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10019 | struct address_space *aspace, | |
09ac7c10 TT |
10020 | CORE_ADDR bp_addr, |
10021 | const struct target_waitstatus *ws) | |
f1310107 | 10022 | { |
09ac7c10 | 10023 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10024 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10025 | return 0; |
10026 | ||
f1310107 TJB |
10027 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10028 | bl->length, aspace, bp_addr); | |
10029 | } | |
10030 | ||
10031 | /* Implement the "resources_needed" breakpoint_ops method for | |
10032 | ranged breakpoints. */ | |
10033 | ||
10034 | static int | |
10035 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10036 | { | |
10037 | return target_ranged_break_num_registers (); | |
10038 | } | |
10039 | ||
10040 | /* Implement the "print_it" breakpoint_ops method for | |
10041 | ranged breakpoints. */ | |
10042 | ||
10043 | static enum print_stop_action | |
348d480f | 10044 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10045 | { |
348d480f | 10046 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10047 | struct bp_location *bl = b->loc; |
79a45e25 | 10048 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10049 | |
10050 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10051 | ||
10052 | /* Ranged breakpoints have only one location. */ | |
10053 | gdb_assert (bl && bl->next == NULL); | |
10054 | ||
10055 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10056 | |
10057 | maybe_print_thread_hit_breakpoint (uiout); | |
10058 | ||
f1310107 | 10059 | if (b->disposition == disp_del) |
112e8700 | 10060 | uiout->text ("Temporary ranged breakpoint "); |
f1310107 | 10061 | else |
112e8700 SM |
10062 | uiout->text ("Ranged breakpoint "); |
10063 | if (uiout->is_mi_like_p ()) | |
f1310107 | 10064 | { |
112e8700 | 10065 | uiout->field_string ("reason", |
f1310107 | 10066 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 10067 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
f1310107 | 10068 | } |
112e8700 SM |
10069 | uiout->field_int ("bkptno", b->number); |
10070 | uiout->text (", "); | |
f1310107 TJB |
10071 | |
10072 | return PRINT_SRC_AND_LOC; | |
10073 | } | |
10074 | ||
10075 | /* Implement the "print_one" breakpoint_ops method for | |
10076 | ranged breakpoints. */ | |
10077 | ||
10078 | static void | |
10079 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10080 | struct bp_location **last_loc) | |
10081 | { | |
10082 | struct bp_location *bl = b->loc; | |
10083 | struct value_print_options opts; | |
79a45e25 | 10084 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10085 | |
10086 | /* Ranged breakpoints have only one location. */ | |
10087 | gdb_assert (bl && bl->next == NULL); | |
10088 | ||
10089 | get_user_print_options (&opts); | |
10090 | ||
10091 | if (opts.addressprint) | |
10092 | /* We don't print the address range here, it will be printed later | |
10093 | by print_one_detail_ranged_breakpoint. */ | |
112e8700 | 10094 | uiout->field_skip ("addr"); |
f1310107 TJB |
10095 | annotate_field (5); |
10096 | print_breakpoint_location (b, bl); | |
10097 | *last_loc = bl; | |
10098 | } | |
10099 | ||
10100 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10101 | ranged breakpoints. */ | |
10102 | ||
10103 | static void | |
10104 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10105 | struct ui_out *uiout) | |
10106 | { | |
10107 | CORE_ADDR address_start, address_end; | |
10108 | struct bp_location *bl = b->loc; | |
d7e74731 | 10109 | string_file stb; |
f1310107 TJB |
10110 | |
10111 | gdb_assert (bl); | |
10112 | ||
10113 | address_start = bl->address; | |
10114 | address_end = address_start + bl->length - 1; | |
10115 | ||
112e8700 | 10116 | uiout->text ("\taddress range: "); |
d7e74731 PA |
10117 | stb.printf ("[%s, %s]", |
10118 | print_core_address (bl->gdbarch, address_start), | |
10119 | print_core_address (bl->gdbarch, address_end)); | |
112e8700 SM |
10120 | uiout->field_stream ("addr", stb); |
10121 | uiout->text ("\n"); | |
f1310107 TJB |
10122 | } |
10123 | ||
10124 | /* Implement the "print_mention" breakpoint_ops method for | |
10125 | ranged breakpoints. */ | |
10126 | ||
10127 | static void | |
10128 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10129 | { | |
10130 | struct bp_location *bl = b->loc; | |
79a45e25 | 10131 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10132 | |
10133 | gdb_assert (bl); | |
10134 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10135 | ||
112e8700 | 10136 | if (uiout->is_mi_like_p ()) |
f1310107 TJB |
10137 | return; |
10138 | ||
10139 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10140 | b->number, paddress (bl->gdbarch, bl->address), | |
10141 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10142 | } | |
10143 | ||
10144 | /* Implement the "print_recreate" breakpoint_ops method for | |
10145 | ranged breakpoints. */ | |
10146 | ||
10147 | static void | |
10148 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10149 | { | |
f00aae0f | 10150 | fprintf_unfiltered (fp, "break-range %s, %s", |
d28cd78a TT |
10151 | event_location_to_string (b->location.get ()), |
10152 | event_location_to_string (b->location_range_end.get ())); | |
d9b3f62e | 10153 | print_recreate_thread (b, fp); |
f1310107 TJB |
10154 | } |
10155 | ||
10156 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10157 | ||
2060206e | 10158 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10159 | |
10160 | /* Find the address where the end of the breakpoint range should be | |
10161 | placed, given the SAL of the end of the range. This is so that if | |
10162 | the user provides a line number, the end of the range is set to the | |
10163 | last instruction of the given line. */ | |
10164 | ||
10165 | static CORE_ADDR | |
10166 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10167 | { | |
10168 | CORE_ADDR end; | |
10169 | ||
10170 | /* If the user provided a PC value, use it. Otherwise, | |
10171 | find the address of the end of the given location. */ | |
10172 | if (sal.explicit_pc) | |
10173 | end = sal.pc; | |
10174 | else | |
10175 | { | |
10176 | int ret; | |
10177 | CORE_ADDR start; | |
10178 | ||
10179 | ret = find_line_pc_range (sal, &start, &end); | |
10180 | if (!ret) | |
10181 | error (_("Could not find location of the end of the range.")); | |
10182 | ||
10183 | /* find_line_pc_range returns the start of the next line. */ | |
10184 | end--; | |
10185 | } | |
10186 | ||
10187 | return end; | |
10188 | } | |
10189 | ||
10190 | /* Implement the "break-range" CLI command. */ | |
10191 | ||
10192 | static void | |
10193 | break_range_command (char *arg, int from_tty) | |
10194 | { | |
870f88f7 | 10195 | char *arg_start, *addr_string_start; |
f1310107 TJB |
10196 | struct linespec_result canonical_start, canonical_end; |
10197 | int bp_count, can_use_bp, length; | |
10198 | CORE_ADDR end; | |
10199 | struct breakpoint *b; | |
f1310107 TJB |
10200 | struct cleanup *cleanup_bkpt; |
10201 | ||
10202 | /* We don't support software ranged breakpoints. */ | |
10203 | if (target_ranged_break_num_registers () < 0) | |
10204 | error (_("This target does not support hardware ranged breakpoints.")); | |
10205 | ||
10206 | bp_count = hw_breakpoint_used_count (); | |
10207 | bp_count += target_ranged_break_num_registers (); | |
10208 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10209 | bp_count, 0); | |
10210 | if (can_use_bp < 0) | |
10211 | error (_("Hardware breakpoints used exceeds limit.")); | |
10212 | ||
f8eba3c6 | 10213 | arg = skip_spaces (arg); |
f1310107 TJB |
10214 | if (arg == NULL || arg[0] == '\0') |
10215 | error(_("No address range specified.")); | |
10216 | ||
f8eba3c6 | 10217 | arg_start = arg; |
ffc2605c TT |
10218 | event_location_up start_location = string_to_event_location (&arg, |
10219 | current_language); | |
10220 | parse_breakpoint_sals (start_location.get (), &canonical_start); | |
f1310107 TJB |
10221 | |
10222 | if (arg[0] != ',') | |
10223 | error (_("Too few arguments.")); | |
6c5b2ebe | 10224 | else if (canonical_start.lsals.empty ()) |
f1310107 | 10225 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 | 10226 | |
6c5b2ebe | 10227 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
f8eba3c6 | 10228 | |
6c5b2ebe PA |
10229 | if (canonical_start.lsals.size () > 1 |
10230 | || lsal_start.sals.size () != 1) | |
f1310107 TJB |
10231 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10232 | ||
6c5b2ebe | 10233 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
f8eba3c6 | 10234 | addr_string_start = savestring (arg_start, arg - arg_start); |
16e802b9 | 10235 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); |
f1310107 TJB |
10236 | |
10237 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10238 | arg = skip_spaces (arg); |
f1310107 TJB |
10239 | |
10240 | /* Parse the end location. */ | |
10241 | ||
f1310107 TJB |
10242 | arg_start = arg; |
10243 | ||
f8eba3c6 | 10244 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10245 | parse_breakpoint_sals because we need to specify the start location's |
10246 | symtab and line as the default symtab and line for the end of the | |
10247 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10248 | where +14 means 14 lines from the start location. */ | |
ffc2605c TT |
10249 | event_location_up end_location = string_to_event_location (&arg, |
10250 | current_language); | |
10251 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
f8eba3c6 TT |
10252 | sal_start.symtab, sal_start.line, |
10253 | &canonical_end, NULL, NULL); | |
10254 | ||
6c5b2ebe | 10255 | if (canonical_end.lsals.empty ()) |
f1310107 | 10256 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 | 10257 | |
6c5b2ebe PA |
10258 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
10259 | if (canonical_end.lsals.size () > 1 | |
10260 | || lsal_end.sals.size () != 1) | |
f1310107 TJB |
10261 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10262 | ||
6c5b2ebe | 10263 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
f1310107 TJB |
10264 | |
10265 | end = find_breakpoint_range_end (sal_end); | |
10266 | if (sal_start.pc > end) | |
177b42fe | 10267 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10268 | |
10269 | length = end - sal_start.pc + 1; | |
10270 | if (length < 0) | |
10271 | /* Length overflowed. */ | |
10272 | error (_("Address range too large.")); | |
10273 | else if (length == 1) | |
10274 | { | |
10275 | /* This range is simple enough to be handled by | |
10276 | the `hbreak' command. */ | |
10277 | hbreak_command (addr_string_start, 1); | |
10278 | ||
10279 | do_cleanups (cleanup_bkpt); | |
10280 | ||
10281 | return; | |
10282 | } | |
10283 | ||
10284 | /* Now set up the breakpoint. */ | |
10285 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10286 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10287 | set_breakpoint_count (breakpoint_count + 1); |
10288 | b->number = breakpoint_count; | |
10289 | b->disposition = disp_donttouch; | |
d28cd78a TT |
10290 | b->location = std::move (start_location); |
10291 | b->location_range_end = std::move (end_location); | |
f1310107 TJB |
10292 | b->loc->length = length; |
10293 | ||
f8eba3c6 | 10294 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10295 | |
10296 | mention (b); | |
8d3788bd | 10297 | observer_notify_breakpoint_created (b); |
44702360 | 10298 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10299 | } |
10300 | ||
4a64f543 MS |
10301 | /* Return non-zero if EXP is verified as constant. Returned zero |
10302 | means EXP is variable. Also the constant detection may fail for | |
10303 | some constant expressions and in such case still falsely return | |
10304 | zero. */ | |
2e6e3d9c | 10305 | |
65d79d4b SDJ |
10306 | static int |
10307 | watchpoint_exp_is_const (const struct expression *exp) | |
10308 | { | |
10309 | int i = exp->nelts; | |
10310 | ||
10311 | while (i > 0) | |
10312 | { | |
10313 | int oplenp, argsp; | |
10314 | ||
10315 | /* We are only interested in the descriptor of each element. */ | |
10316 | operator_length (exp, i, &oplenp, &argsp); | |
10317 | i -= oplenp; | |
10318 | ||
10319 | switch (exp->elts[i].opcode) | |
10320 | { | |
10321 | case BINOP_ADD: | |
10322 | case BINOP_SUB: | |
10323 | case BINOP_MUL: | |
10324 | case BINOP_DIV: | |
10325 | case BINOP_REM: | |
10326 | case BINOP_MOD: | |
10327 | case BINOP_LSH: | |
10328 | case BINOP_RSH: | |
10329 | case BINOP_LOGICAL_AND: | |
10330 | case BINOP_LOGICAL_OR: | |
10331 | case BINOP_BITWISE_AND: | |
10332 | case BINOP_BITWISE_IOR: | |
10333 | case BINOP_BITWISE_XOR: | |
10334 | case BINOP_EQUAL: | |
10335 | case BINOP_NOTEQUAL: | |
10336 | case BINOP_LESS: | |
10337 | case BINOP_GTR: | |
10338 | case BINOP_LEQ: | |
10339 | case BINOP_GEQ: | |
10340 | case BINOP_REPEAT: | |
10341 | case BINOP_COMMA: | |
10342 | case BINOP_EXP: | |
10343 | case BINOP_MIN: | |
10344 | case BINOP_MAX: | |
10345 | case BINOP_INTDIV: | |
10346 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10347 | case TERNOP_COND: |
10348 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10349 | |
10350 | case OP_LONG: | |
10351 | case OP_DOUBLE: | |
10352 | case OP_DECFLOAT: | |
10353 | case OP_LAST: | |
10354 | case OP_COMPLEX: | |
10355 | case OP_STRING: | |
65d79d4b SDJ |
10356 | case OP_ARRAY: |
10357 | case OP_TYPE: | |
608b4967 TT |
10358 | case OP_TYPEOF: |
10359 | case OP_DECLTYPE: | |
6e72ca20 | 10360 | case OP_TYPEID: |
65d79d4b SDJ |
10361 | case OP_NAME: |
10362 | case OP_OBJC_NSSTRING: | |
10363 | ||
10364 | case UNOP_NEG: | |
10365 | case UNOP_LOGICAL_NOT: | |
10366 | case UNOP_COMPLEMENT: | |
10367 | case UNOP_ADDR: | |
10368 | case UNOP_HIGH: | |
aeaa2474 | 10369 | case UNOP_CAST: |
9eaf6705 TT |
10370 | |
10371 | case UNOP_CAST_TYPE: | |
10372 | case UNOP_REINTERPRET_CAST: | |
10373 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10374 | /* Unary, binary and ternary operators: We have to check |
10375 | their operands. If they are constant, then so is the | |
10376 | result of that operation. For instance, if A and B are | |
10377 | determined to be constants, then so is "A + B". | |
10378 | ||
10379 | UNOP_IND is one exception to the rule above, because the | |
10380 | value of *ADDR is not necessarily a constant, even when | |
10381 | ADDR is. */ | |
65d79d4b SDJ |
10382 | break; |
10383 | ||
10384 | case OP_VAR_VALUE: | |
10385 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10386 | |
65d79d4b | 10387 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10388 | possible that a buggy compiler could mark a variable as |
10389 | constant even when it is not, and TYPE_CONST would return | |
10390 | true in this case, while SYMBOL_CLASS wouldn't. | |
10391 | ||
10392 | We also have to check for function symbols because they | |
10393 | are always constant. */ | |
65d79d4b SDJ |
10394 | { |
10395 | struct symbol *s = exp->elts[i + 2].symbol; | |
10396 | ||
10397 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10398 | && SYMBOL_CLASS (s) != LOC_CONST | |
10399 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10400 | return 0; | |
10401 | break; | |
10402 | } | |
10403 | ||
10404 | /* The default action is to return 0 because we are using | |
10405 | the optimistic approach here: If we don't know something, | |
10406 | then it is not a constant. */ | |
10407 | default: | |
10408 | return 0; | |
10409 | } | |
10410 | } | |
10411 | ||
10412 | return 1; | |
10413 | } | |
10414 | ||
c1fc2657 | 10415 | /* Watchpoint destructor. */ |
3a5c3e22 | 10416 | |
c1fc2657 | 10417 | watchpoint::~watchpoint () |
3a5c3e22 | 10418 | { |
c1fc2657 SM |
10419 | xfree (this->exp_string); |
10420 | xfree (this->exp_string_reparse); | |
10421 | value_free (this->val); | |
3a5c3e22 PA |
10422 | } |
10423 | ||
348d480f PA |
10424 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10425 | ||
10426 | static void | |
10427 | re_set_watchpoint (struct breakpoint *b) | |
10428 | { | |
3a5c3e22 PA |
10429 | struct watchpoint *w = (struct watchpoint *) b; |
10430 | ||
348d480f PA |
10431 | /* Watchpoint can be either on expression using entirely global |
10432 | variables, or it can be on local variables. | |
10433 | ||
10434 | Watchpoints of the first kind are never auto-deleted, and even | |
10435 | persist across program restarts. Since they can use variables | |
10436 | from shared libraries, we need to reparse expression as libraries | |
10437 | are loaded and unloaded. | |
10438 | ||
10439 | Watchpoints on local variables can also change meaning as result | |
10440 | of solib event. For example, if a watchpoint uses both a local | |
10441 | and a global variables in expression, it's a local watchpoint, | |
10442 | but unloading of a shared library will make the expression | |
10443 | invalid. This is not a very common use case, but we still | |
10444 | re-evaluate expression, to avoid surprises to the user. | |
10445 | ||
10446 | Note that for local watchpoints, we re-evaluate it only if | |
10447 | watchpoints frame id is still valid. If it's not, it means the | |
10448 | watchpoint is out of scope and will be deleted soon. In fact, | |
10449 | I'm not sure we'll ever be called in this case. | |
10450 | ||
10451 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10452 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10453 | |
3a5c3e22 PA |
10454 | Don't do anything about disabled watchpoints, since they will be |
10455 | reevaluated again when enabled. */ | |
10456 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10457 | } |
10458 | ||
77b06cd7 TJB |
10459 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10460 | ||
10461 | static int | |
10462 | insert_watchpoint (struct bp_location *bl) | |
10463 | { | |
3a5c3e22 PA |
10464 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10465 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10466 | |
10467 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10468 | w->cond_exp.get ()); |
77b06cd7 TJB |
10469 | } |
10470 | ||
10471 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10472 | ||
10473 | static int | |
73971819 | 10474 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
77b06cd7 | 10475 | { |
3a5c3e22 PA |
10476 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10477 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10478 | |
10479 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
4d01a485 | 10480 | w->cond_exp.get ()); |
e09342b5 TJB |
10481 | } |
10482 | ||
e09342b5 | 10483 | static int |
348d480f | 10484 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10485 | struct address_space *aspace, CORE_ADDR bp_addr, |
10486 | const struct target_waitstatus *ws) | |
e09342b5 | 10487 | { |
348d480f | 10488 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10489 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10490 | |
348d480f PA |
10491 | /* Continuable hardware watchpoints are treated as non-existent if the |
10492 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10493 | some data address). Otherwise gdb won't stop on a break instruction | |
10494 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10495 | been defined. Also skip watchpoints which we know did not trigger | |
10496 | (did not match the data address). */ | |
10497 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10498 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10499 | return 0; |
9c06b0b4 | 10500 | |
348d480f | 10501 | return 1; |
9c06b0b4 TJB |
10502 | } |
10503 | ||
348d480f PA |
10504 | static void |
10505 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10506 | { |
348d480f | 10507 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10508 | |
348d480f | 10509 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10510 | } |
10511 | ||
10512 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10513 | hardware watchpoints. */ |
9c06b0b4 TJB |
10514 | |
10515 | static int | |
348d480f | 10516 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10517 | { |
3a5c3e22 PA |
10518 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10519 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10520 | |
10521 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10522 | } |
10523 | ||
10524 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10525 | hardware watchpoints. */ |
9c06b0b4 TJB |
10526 | |
10527 | static int | |
348d480f | 10528 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10529 | { |
efa80663 PA |
10530 | /* Read and access watchpoints only work with hardware support. */ |
10531 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10532 | } |
10533 | ||
9c06b0b4 | 10534 | static enum print_stop_action |
348d480f | 10535 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10536 | { |
348d480f | 10537 | struct breakpoint *b; |
348d480f | 10538 | enum print_stop_action result; |
3a5c3e22 | 10539 | struct watchpoint *w; |
79a45e25 | 10540 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10541 | |
10542 | gdb_assert (bs->bp_location_at != NULL); | |
10543 | ||
348d480f | 10544 | b = bs->breakpoint_at; |
3a5c3e22 | 10545 | w = (struct watchpoint *) b; |
348d480f | 10546 | |
f303dbd6 PA |
10547 | annotate_watchpoint (b->number); |
10548 | maybe_print_thread_hit_breakpoint (uiout); | |
10549 | ||
d7e74731 PA |
10550 | string_file stb; |
10551 | ||
76f9c9cf | 10552 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
9c06b0b4 TJB |
10553 | switch (b->type) |
10554 | { | |
348d480f | 10555 | case bp_watchpoint: |
9c06b0b4 | 10556 | case bp_hardware_watchpoint: |
112e8700 SM |
10557 | if (uiout->is_mi_like_p ()) |
10558 | uiout->field_string | |
10559 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f | 10560 | mention (b); |
76f9c9cf | 10561 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10562 | uiout->text ("\nOld value = "); |
d7e74731 | 10563 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10564 | uiout->field_stream ("old", stb); |
10565 | uiout->text ("\nNew value = "); | |
d7e74731 | 10566 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10567 | uiout->field_stream ("new", stb); |
10568 | uiout->text ("\n"); | |
348d480f PA |
10569 | /* More than one watchpoint may have been triggered. */ |
10570 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10571 | break; |
10572 | ||
10573 | case bp_read_watchpoint: | |
112e8700 SM |
10574 | if (uiout->is_mi_like_p ()) |
10575 | uiout->field_string | |
10576 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f | 10577 | mention (b); |
76f9c9cf | 10578 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10579 | uiout->text ("\nValue = "); |
d7e74731 | 10580 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10581 | uiout->field_stream ("value", stb); |
10582 | uiout->text ("\n"); | |
348d480f | 10583 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10584 | break; |
10585 | ||
10586 | case bp_access_watchpoint: | |
348d480f PA |
10587 | if (bs->old_val != NULL) |
10588 | { | |
112e8700 SM |
10589 | if (uiout->is_mi_like_p ()) |
10590 | uiout->field_string | |
10591 | ("reason", | |
348d480f PA |
10592 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10593 | mention (b); | |
76f9c9cf | 10594 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10595 | uiout->text ("\nOld value = "); |
d7e74731 | 10596 | watchpoint_value_print (bs->old_val, &stb); |
112e8700 SM |
10597 | uiout->field_stream ("old", stb); |
10598 | uiout->text ("\nNew value = "); | |
348d480f PA |
10599 | } |
10600 | else | |
10601 | { | |
10602 | mention (b); | |
112e8700 SM |
10603 | if (uiout->is_mi_like_p ()) |
10604 | uiout->field_string | |
10605 | ("reason", | |
348d480f | 10606 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
76f9c9cf | 10607 | tuple_emitter.emplace (uiout, "value"); |
112e8700 | 10608 | uiout->text ("\nValue = "); |
348d480f | 10609 | } |
d7e74731 | 10610 | watchpoint_value_print (w->val, &stb); |
112e8700 SM |
10611 | uiout->field_stream ("new", stb); |
10612 | uiout->text ("\n"); | |
348d480f | 10613 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10614 | break; |
10615 | default: | |
348d480f | 10616 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10617 | } |
10618 | ||
348d480f PA |
10619 | return result; |
10620 | } | |
10621 | ||
10622 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10623 | watchpoints. */ | |
10624 | ||
10625 | static void | |
10626 | print_mention_watchpoint (struct breakpoint *b) | |
10627 | { | |
3a5c3e22 | 10628 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10629 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10630 | const char *tuple_name; |
348d480f PA |
10631 | |
10632 | switch (b->type) | |
10633 | { | |
10634 | case bp_watchpoint: | |
112e8700 | 10635 | uiout->text ("Watchpoint "); |
46b9c129 | 10636 | tuple_name = "wpt"; |
348d480f PA |
10637 | break; |
10638 | case bp_hardware_watchpoint: | |
112e8700 | 10639 | uiout->text ("Hardware watchpoint "); |
46b9c129 | 10640 | tuple_name = "wpt"; |
348d480f PA |
10641 | break; |
10642 | case bp_read_watchpoint: | |
112e8700 | 10643 | uiout->text ("Hardware read watchpoint "); |
46b9c129 | 10644 | tuple_name = "hw-rwpt"; |
348d480f PA |
10645 | break; |
10646 | case bp_access_watchpoint: | |
112e8700 | 10647 | uiout->text ("Hardware access (read/write) watchpoint "); |
46b9c129 | 10648 | tuple_name = "hw-awpt"; |
348d480f PA |
10649 | break; |
10650 | default: | |
10651 | internal_error (__FILE__, __LINE__, | |
10652 | _("Invalid hardware watchpoint type.")); | |
10653 | } | |
10654 | ||
46b9c129 | 10655 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10656 | uiout->field_int ("number", b->number); |
10657 | uiout->text (": "); | |
10658 | uiout->field_string ("exp", w->exp_string); | |
348d480f PA |
10659 | } |
10660 | ||
10661 | /* Implement the "print_recreate" breakpoint_ops method for | |
10662 | watchpoints. */ | |
10663 | ||
10664 | static void | |
10665 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10666 | { | |
3a5c3e22 PA |
10667 | struct watchpoint *w = (struct watchpoint *) b; |
10668 | ||
348d480f PA |
10669 | switch (b->type) |
10670 | { | |
10671 | case bp_watchpoint: | |
10672 | case bp_hardware_watchpoint: | |
10673 | fprintf_unfiltered (fp, "watch"); | |
10674 | break; | |
10675 | case bp_read_watchpoint: | |
10676 | fprintf_unfiltered (fp, "rwatch"); | |
10677 | break; | |
10678 | case bp_access_watchpoint: | |
10679 | fprintf_unfiltered (fp, "awatch"); | |
10680 | break; | |
10681 | default: | |
10682 | internal_error (__FILE__, __LINE__, | |
10683 | _("Invalid watchpoint type.")); | |
10684 | } | |
10685 | ||
3a5c3e22 | 10686 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10687 | print_recreate_thread (b, fp); |
348d480f PA |
10688 | } |
10689 | ||
427cd150 TT |
10690 | /* Implement the "explains_signal" breakpoint_ops method for |
10691 | watchpoints. */ | |
10692 | ||
47591c29 | 10693 | static int |
427cd150 TT |
10694 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10695 | { | |
10696 | /* A software watchpoint cannot cause a signal other than | |
10697 | GDB_SIGNAL_TRAP. */ | |
10698 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10699 | return 0; |
427cd150 | 10700 | |
47591c29 | 10701 | return 1; |
427cd150 TT |
10702 | } |
10703 | ||
348d480f PA |
10704 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10705 | ||
2060206e | 10706 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10707 | |
10708 | /* Implement the "insert" breakpoint_ops method for | |
10709 | masked hardware watchpoints. */ | |
10710 | ||
10711 | static int | |
10712 | insert_masked_watchpoint (struct bp_location *bl) | |
10713 | { | |
3a5c3e22 PA |
10714 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10715 | ||
10716 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10717 | bl->watchpoint_type); |
10718 | } | |
10719 | ||
10720 | /* Implement the "remove" breakpoint_ops method for | |
10721 | masked hardware watchpoints. */ | |
10722 | ||
10723 | static int | |
73971819 | 10724 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f | 10725 | { |
3a5c3e22 PA |
10726 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10727 | ||
10728 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10729 | bl->watchpoint_type); |
10730 | } | |
10731 | ||
10732 | /* Implement the "resources_needed" breakpoint_ops method for | |
10733 | masked hardware watchpoints. */ | |
10734 | ||
10735 | static int | |
10736 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10737 | { | |
3a5c3e22 PA |
10738 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10739 | ||
10740 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10741 | } |
10742 | ||
10743 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10744 | masked hardware watchpoints. */ | |
10745 | ||
10746 | static int | |
10747 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10748 | { | |
10749 | return 0; | |
10750 | } | |
10751 | ||
10752 | /* Implement the "print_it" breakpoint_ops method for | |
10753 | masked hardware watchpoints. */ | |
10754 | ||
10755 | static enum print_stop_action | |
10756 | print_it_masked_watchpoint (bpstat bs) | |
10757 | { | |
10758 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10759 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10760 | |
10761 | /* Masked watchpoints have only one location. */ | |
10762 | gdb_assert (b->loc && b->loc->next == NULL); | |
10763 | ||
f303dbd6 PA |
10764 | annotate_watchpoint (b->number); |
10765 | maybe_print_thread_hit_breakpoint (uiout); | |
10766 | ||
348d480f PA |
10767 | switch (b->type) |
10768 | { | |
10769 | case bp_hardware_watchpoint: | |
112e8700 SM |
10770 | if (uiout->is_mi_like_p ()) |
10771 | uiout->field_string | |
10772 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10773 | break; |
10774 | ||
10775 | case bp_read_watchpoint: | |
112e8700 SM |
10776 | if (uiout->is_mi_like_p ()) |
10777 | uiout->field_string | |
10778 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10779 | break; |
10780 | ||
10781 | case bp_access_watchpoint: | |
112e8700 SM |
10782 | if (uiout->is_mi_like_p ()) |
10783 | uiout->field_string | |
10784 | ("reason", | |
348d480f PA |
10785 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
10786 | break; | |
10787 | default: | |
10788 | internal_error (__FILE__, __LINE__, | |
10789 | _("Invalid hardware watchpoint type.")); | |
10790 | } | |
10791 | ||
10792 | mention (b); | |
112e8700 | 10793 | uiout->text (_("\n\ |
9c06b0b4 TJB |
10794 | Check the underlying instruction at PC for the memory\n\ |
10795 | address and value which triggered this watchpoint.\n")); | |
112e8700 | 10796 | uiout->text ("\n"); |
9c06b0b4 TJB |
10797 | |
10798 | /* More than one watchpoint may have been triggered. */ | |
10799 | return PRINT_UNKNOWN; | |
10800 | } | |
10801 | ||
10802 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10803 | masked hardware watchpoints. */ | |
10804 | ||
10805 | static void | |
10806 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
10807 | struct ui_out *uiout) | |
10808 | { | |
3a5c3e22 PA |
10809 | struct watchpoint *w = (struct watchpoint *) b; |
10810 | ||
9c06b0b4 TJB |
10811 | /* Masked watchpoints have only one location. */ |
10812 | gdb_assert (b->loc && b->loc->next == NULL); | |
10813 | ||
112e8700 SM |
10814 | uiout->text ("\tmask "); |
10815 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); | |
10816 | uiout->text ("\n"); | |
9c06b0b4 TJB |
10817 | } |
10818 | ||
10819 | /* Implement the "print_mention" breakpoint_ops method for | |
10820 | masked hardware watchpoints. */ | |
10821 | ||
10822 | static void | |
10823 | print_mention_masked_watchpoint (struct breakpoint *b) | |
10824 | { | |
3a5c3e22 | 10825 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10826 | struct ui_out *uiout = current_uiout; |
46b9c129 | 10827 | const char *tuple_name; |
9c06b0b4 TJB |
10828 | |
10829 | switch (b->type) | |
10830 | { | |
10831 | case bp_hardware_watchpoint: | |
112e8700 | 10832 | uiout->text ("Masked hardware watchpoint "); |
46b9c129 | 10833 | tuple_name = "wpt"; |
9c06b0b4 TJB |
10834 | break; |
10835 | case bp_read_watchpoint: | |
112e8700 | 10836 | uiout->text ("Masked hardware read watchpoint "); |
46b9c129 | 10837 | tuple_name = "hw-rwpt"; |
9c06b0b4 TJB |
10838 | break; |
10839 | case bp_access_watchpoint: | |
112e8700 | 10840 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
46b9c129 | 10841 | tuple_name = "hw-awpt"; |
9c06b0b4 TJB |
10842 | break; |
10843 | default: | |
10844 | internal_error (__FILE__, __LINE__, | |
10845 | _("Invalid hardware watchpoint type.")); | |
10846 | } | |
10847 | ||
46b9c129 | 10848 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
112e8700 SM |
10849 | uiout->field_int ("number", b->number); |
10850 | uiout->text (": "); | |
10851 | uiout->field_string ("exp", w->exp_string); | |
9c06b0b4 TJB |
10852 | } |
10853 | ||
10854 | /* Implement the "print_recreate" breakpoint_ops method for | |
10855 | masked hardware watchpoints. */ | |
10856 | ||
10857 | static void | |
10858 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10859 | { | |
3a5c3e22 | 10860 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
10861 | char tmp[40]; |
10862 | ||
10863 | switch (b->type) | |
10864 | { | |
10865 | case bp_hardware_watchpoint: | |
10866 | fprintf_unfiltered (fp, "watch"); | |
10867 | break; | |
10868 | case bp_read_watchpoint: | |
10869 | fprintf_unfiltered (fp, "rwatch"); | |
10870 | break; | |
10871 | case bp_access_watchpoint: | |
10872 | fprintf_unfiltered (fp, "awatch"); | |
10873 | break; | |
10874 | default: | |
10875 | internal_error (__FILE__, __LINE__, | |
10876 | _("Invalid hardware watchpoint type.")); | |
10877 | } | |
10878 | ||
3a5c3e22 PA |
10879 | sprintf_vma (tmp, w->hw_wp_mask); |
10880 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 10881 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
10882 | } |
10883 | ||
10884 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
10885 | ||
2060206e | 10886 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
10887 | |
10888 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
10889 | ||
10890 | static int | |
10891 | is_masked_watchpoint (const struct breakpoint *b) | |
10892 | { | |
10893 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
10894 | } | |
10895 | ||
53a5351d JM |
10896 | /* accessflag: hw_write: watch write, |
10897 | hw_read: watch read, | |
10898 | hw_access: watch access (read or write) */ | |
c906108c | 10899 | static void |
bbc13ae3 | 10900 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 10901 | int just_location, int internal) |
c906108c | 10902 | { |
c1fc2657 | 10903 | struct breakpoint *scope_breakpoint = NULL; |
270140bd | 10904 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 10905 | struct value *val, *mark, *result; |
bb9d5f81 | 10906 | int saved_bitpos = 0, saved_bitsize = 0; |
bbc13ae3 KS |
10907 | const char *exp_start = NULL; |
10908 | const char *exp_end = NULL; | |
10909 | const char *tok, *end_tok; | |
9c06b0b4 | 10910 | int toklen = -1; |
bbc13ae3 KS |
10911 | const char *cond_start = NULL; |
10912 | const char *cond_end = NULL; | |
c906108c | 10913 | enum bptype bp_type; |
37e4754d | 10914 | int thread = -1; |
0cf6dd15 | 10915 | int pc = 0; |
9c06b0b4 TJB |
10916 | /* Flag to indicate whether we are going to use masks for |
10917 | the hardware watchpoint. */ | |
10918 | int use_mask = 0; | |
10919 | CORE_ADDR mask = 0; | |
bbc13ae3 KS |
10920 | char *expression; |
10921 | struct cleanup *back_to; | |
c906108c | 10922 | |
37e4754d LM |
10923 | /* Make sure that we actually have parameters to parse. */ |
10924 | if (arg != NULL && arg[0] != '\0') | |
10925 | { | |
bbc13ae3 KS |
10926 | const char *value_start; |
10927 | ||
10928 | exp_end = arg + strlen (arg); | |
37e4754d | 10929 | |
9c06b0b4 TJB |
10930 | /* Look for "parameter value" pairs at the end |
10931 | of the arguments string. */ | |
bbc13ae3 | 10932 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
10933 | { |
10934 | /* Skip whitespace at the end of the argument list. */ | |
10935 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10936 | tok--; | |
10937 | ||
10938 | /* Find the beginning of the last token. | |
10939 | This is the value of the parameter. */ | |
10940 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10941 | tok--; | |
10942 | value_start = tok + 1; | |
10943 | ||
10944 | /* Skip whitespace. */ | |
10945 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
10946 | tok--; | |
10947 | ||
10948 | end_tok = tok; | |
10949 | ||
10950 | /* Find the beginning of the second to last token. | |
10951 | This is the parameter itself. */ | |
10952 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
10953 | tok--; | |
10954 | tok++; | |
10955 | toklen = end_tok - tok + 1; | |
10956 | ||
61012eef | 10957 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 10958 | { |
5d5658a1 | 10959 | struct thread_info *thr; |
9c06b0b4 TJB |
10960 | /* At this point we've found a "thread" token, which means |
10961 | the user is trying to set a watchpoint that triggers | |
10962 | only in a specific thread. */ | |
5d5658a1 | 10963 | const char *endp; |
37e4754d | 10964 | |
9c06b0b4 TJB |
10965 | if (thread != -1) |
10966 | error(_("You can specify only one thread.")); | |
37e4754d | 10967 | |
9c06b0b4 | 10968 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 10969 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 10970 | |
5d5658a1 | 10971 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 10972 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 10973 | invalid_thread_id_error (value_start); |
9c06b0b4 | 10974 | |
5d5658a1 | 10975 | thread = thr->global_num; |
9c06b0b4 | 10976 | } |
61012eef | 10977 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
10978 | { |
10979 | /* We've found a "mask" token, which means the user wants to | |
10980 | create a hardware watchpoint that is going to have the mask | |
10981 | facility. */ | |
10982 | struct value *mask_value, *mark; | |
37e4754d | 10983 | |
9c06b0b4 TJB |
10984 | if (use_mask) |
10985 | error(_("You can specify only one mask.")); | |
37e4754d | 10986 | |
9c06b0b4 | 10987 | use_mask = just_location = 1; |
37e4754d | 10988 | |
9c06b0b4 TJB |
10989 | mark = value_mark (); |
10990 | mask_value = parse_to_comma_and_eval (&value_start); | |
10991 | mask = value_as_address (mask_value); | |
10992 | value_free_to_mark (mark); | |
10993 | } | |
10994 | else | |
10995 | /* We didn't recognize what we found. We should stop here. */ | |
10996 | break; | |
37e4754d | 10997 | |
9c06b0b4 TJB |
10998 | /* Truncate the string and get rid of the "parameter value" pair before |
10999 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11000 | exp_end = tok; |
9c06b0b4 | 11001 | } |
37e4754d | 11002 | } |
bbc13ae3 KS |
11003 | else |
11004 | exp_end = arg; | |
37e4754d | 11005 | |
bbc13ae3 KS |
11006 | /* Parse the rest of the arguments. From here on out, everything |
11007 | is in terms of a newly allocated string instead of the original | |
11008 | ARG. */ | |
c906108c | 11009 | innermost_block = NULL; |
bbc13ae3 KS |
11010 | expression = savestring (arg, exp_end - arg); |
11011 | back_to = make_cleanup (xfree, expression); | |
11012 | exp_start = arg = expression; | |
4d01a485 | 11013 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11014 | exp_end = arg; |
fa8a61dc TT |
11015 | /* Remove trailing whitespace from the expression before saving it. |
11016 | This makes the eventual display of the expression string a bit | |
11017 | prettier. */ | |
11018 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11019 | --exp_end; | |
11020 | ||
65d79d4b | 11021 | /* Checking if the expression is not constant. */ |
4d01a485 | 11022 | if (watchpoint_exp_is_const (exp.get ())) |
65d79d4b SDJ |
11023 | { |
11024 | int len; | |
11025 | ||
11026 | len = exp_end - exp_start; | |
11027 | while (len > 0 && isspace (exp_start[len - 1])) | |
11028 | len--; | |
11029 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11030 | } | |
11031 | ||
c906108c SS |
11032 | exp_valid_block = innermost_block; |
11033 | mark = value_mark (); | |
4d01a485 | 11034 | fetch_subexp_value (exp.get (), &pc, &val, &result, NULL, just_location); |
06a64a0b | 11035 | |
bb9d5f81 PP |
11036 | if (val != NULL && just_location) |
11037 | { | |
11038 | saved_bitpos = value_bitpos (val); | |
11039 | saved_bitsize = value_bitsize (val); | |
11040 | } | |
11041 | ||
06a64a0b TT |
11042 | if (just_location) |
11043 | { | |
9c06b0b4 TJB |
11044 | int ret; |
11045 | ||
06a64a0b | 11046 | exp_valid_block = NULL; |
a1442452 | 11047 | val = value_addr (result); |
06a64a0b TT |
11048 | release_value (val); |
11049 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11050 | |
11051 | if (use_mask) | |
11052 | { | |
11053 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11054 | mask); | |
11055 | if (ret == -1) | |
11056 | error (_("This target does not support masked watchpoints.")); | |
11057 | else if (ret == -2) | |
11058 | error (_("Invalid mask or memory region.")); | |
11059 | } | |
06a64a0b TT |
11060 | } |
11061 | else if (val != NULL) | |
fa4727a6 | 11062 | release_value (val); |
c906108c | 11063 | |
f1735a53 TT |
11064 | tok = skip_spaces (arg); |
11065 | end_tok = skip_to_space (tok); | |
c906108c SS |
11066 | |
11067 | toklen = end_tok - tok; | |
11068 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11069 | { | |
60e1c644 | 11070 | innermost_block = NULL; |
c906108c | 11071 | tok = cond_start = end_tok + 1; |
4d01a485 | 11072 | parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11073 | |
11074 | /* The watchpoint expression may not be local, but the condition | |
11075 | may still be. E.g.: `watch global if local > 0'. */ | |
11076 | cond_exp_valid_block = innermost_block; | |
11077 | ||
c906108c SS |
11078 | cond_end = tok; |
11079 | } | |
11080 | if (*tok) | |
8a3fe4f8 | 11081 | error (_("Junk at end of command.")); |
c906108c | 11082 | |
441d7c93 PA |
11083 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
11084 | ||
11085 | /* Save this because create_internal_breakpoint below invalidates | |
11086 | 'wp_frame'. */ | |
11087 | frame_id watchpoint_frame = get_frame_id (wp_frame); | |
d983da9c DJ |
11088 | |
11089 | /* If the expression is "local", then set up a "watchpoint scope" | |
11090 | breakpoint at the point where we've left the scope of the watchpoint | |
11091 | expression. Create the scope breakpoint before the watchpoint, so | |
11092 | that we will encounter it first in bpstat_stop_status. */ | |
441d7c93 | 11093 | if (exp_valid_block != NULL && wp_frame != NULL) |
d983da9c | 11094 | { |
441d7c93 PA |
11095 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
11096 | ||
11097 | if (frame_id_p (caller_frame_id)) | |
edb3359d | 11098 | { |
441d7c93 PA |
11099 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
11100 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); | |
11101 | ||
edb3359d | 11102 | scope_breakpoint |
441d7c93 | 11103 | = create_internal_breakpoint (caller_arch, caller_pc, |
06edf0c0 PA |
11104 | bp_watchpoint_scope, |
11105 | &momentary_breakpoint_ops); | |
d983da9c | 11106 | |
441d7c93 PA |
11107 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
11108 | wp_frame = NULL; | |
11109 | ||
edb3359d | 11110 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11111 | |
edb3359d DJ |
11112 | /* Automatically delete the breakpoint when it hits. */ |
11113 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11114 | |
edb3359d | 11115 | /* Only break in the proper frame (help with recursion). */ |
441d7c93 | 11116 | scope_breakpoint->frame_id = caller_frame_id; |
d983da9c | 11117 | |
edb3359d | 11118 | /* Set the address at which we will stop. */ |
441d7c93 PA |
11119 | scope_breakpoint->loc->gdbarch = caller_arch; |
11120 | scope_breakpoint->loc->requested_address = caller_pc; | |
edb3359d | 11121 | scope_breakpoint->loc->address |
a6d9a66e UW |
11122 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11123 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11124 | scope_breakpoint->type); |
11125 | } | |
d983da9c DJ |
11126 | } |
11127 | ||
e8369a73 AB |
11128 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11129 | watchpoints here even if hardware watchpoints are turned off, a call | |
11130 | to update_watchpoint later in this function will cause the type to | |
11131 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11132 | ||
11133 | if (accessflag == hw_read) | |
11134 | bp_type = bp_read_watchpoint; | |
11135 | else if (accessflag == hw_access) | |
11136 | bp_type = bp_access_watchpoint; | |
11137 | else | |
11138 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 | 11139 | |
b270e6f9 | 11140 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
c1fc2657 | 11141 | |
348d480f | 11142 | if (use_mask) |
b270e6f9 | 11143 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 11144 | &masked_watchpoint_breakpoint_ops); |
348d480f | 11145 | else |
b270e6f9 | 11146 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
3a5c3e22 | 11147 | &watchpoint_breakpoint_ops); |
c1fc2657 SM |
11148 | w->thread = thread; |
11149 | w->disposition = disp_donttouch; | |
11150 | w->pspace = current_program_space; | |
b22e99fd | 11151 | w->exp = std::move (exp); |
3a5c3e22 PA |
11152 | w->exp_valid_block = exp_valid_block; |
11153 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11154 | if (just_location) |
11155 | { | |
11156 | struct type *t = value_type (val); | |
11157 | CORE_ADDR addr = value_as_address (val); | |
06a64a0b | 11158 | |
43cc5389 TT |
11159 | w->exp_string_reparse |
11160 | = current_language->la_watch_location_expression (t, addr).release (); | |
06a64a0b | 11161 | |
3a5c3e22 | 11162 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 | 11163 | (int) (exp_end - exp_start), exp_start); |
06a64a0b TT |
11164 | } |
11165 | else | |
3a5c3e22 | 11166 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11167 | |
11168 | if (use_mask) | |
11169 | { | |
3a5c3e22 | 11170 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11171 | } |
11172 | else | |
11173 | { | |
3a5c3e22 | 11174 | w->val = val; |
bb9d5f81 PP |
11175 | w->val_bitpos = saved_bitpos; |
11176 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11177 | w->val_valid = 1; |
9c06b0b4 | 11178 | } |
77b06cd7 | 11179 | |
c906108c | 11180 | if (cond_start) |
c1fc2657 | 11181 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
c906108c | 11182 | else |
c1fc2657 | 11183 | w->cond_string = 0; |
c5aa993b | 11184 | |
441d7c93 | 11185 | if (frame_id_p (watchpoint_frame)) |
f6bc2008 | 11186 | { |
441d7c93 | 11187 | w->watchpoint_frame = watchpoint_frame; |
3a5c3e22 | 11188 | w->watchpoint_thread = inferior_ptid; |
f6bc2008 | 11189 | } |
c906108c | 11190 | else |
f6bc2008 | 11191 | { |
3a5c3e22 PA |
11192 | w->watchpoint_frame = null_frame_id; |
11193 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11194 | } |
c906108c | 11195 | |
d983da9c | 11196 | if (scope_breakpoint != NULL) |
c906108c | 11197 | { |
d983da9c DJ |
11198 | /* The scope breakpoint is related to the watchpoint. We will |
11199 | need to act on them together. */ | |
c1fc2657 | 11200 | w->related_breakpoint = scope_breakpoint; |
b270e6f9 | 11201 | scope_breakpoint->related_breakpoint = w.get (); |
c906108c | 11202 | } |
d983da9c | 11203 | |
06a64a0b TT |
11204 | if (!just_location) |
11205 | value_free_to_mark (mark); | |
2d134ed3 | 11206 | |
b270e6f9 TT |
11207 | /* Finally update the new watchpoint. This creates the locations |
11208 | that should be inserted. */ | |
11209 | update_watchpoint (w.get (), 1); | |
a9634178 | 11210 | |
b270e6f9 | 11211 | install_breakpoint (internal, std::move (w), 1); |
bbc13ae3 | 11212 | do_cleanups (back_to); |
c906108c SS |
11213 | } |
11214 | ||
e09342b5 | 11215 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11216 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11217 | |
c906108c | 11218 | static int |
a9634178 | 11219 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11220 | { |
11221 | int found_memory_cnt = 0; | |
2e70b7b9 | 11222 | struct value *head = v; |
c906108c SS |
11223 | |
11224 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11225 | if (!can_use_hw_watchpoints) |
c906108c | 11226 | return 0; |
c5aa993b | 11227 | |
5c44784c JM |
11228 | /* Make sure that the value of the expression depends only upon |
11229 | memory contents, and values computed from them within GDB. If we | |
11230 | find any register references or function calls, we can't use a | |
11231 | hardware watchpoint. | |
11232 | ||
11233 | The idea here is that evaluating an expression generates a series | |
11234 | of values, one holding the value of every subexpression. (The | |
11235 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11236 | a*b+c.) GDB's values hold almost enough information to establish | |
11237 | the criteria given above --- they identify memory lvalues, | |
11238 | register lvalues, computed values, etcetera. So we can evaluate | |
11239 | the expression, and then scan the chain of values that leaves | |
11240 | behind to decide whether we can detect any possible change to the | |
11241 | expression's final value using only hardware watchpoints. | |
11242 | ||
11243 | However, I don't think that the values returned by inferior | |
11244 | function calls are special in any way. So this function may not | |
11245 | notice that an expression involving an inferior function call | |
11246 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11247 | for (; v; v = value_next (v)) |
c906108c | 11248 | { |
5c44784c | 11249 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11250 | { |
8464be76 DJ |
11251 | if (v != head && value_lazy (v)) |
11252 | /* A lazy memory lvalue in the chain is one that GDB never | |
11253 | needed to fetch; we either just used its address (e.g., | |
11254 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11255 | in `a,b'). This doesn't apply to HEAD; if that is | |
11256 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11257 | ; |
53a5351d | 11258 | else |
5c44784c JM |
11259 | { |
11260 | /* Ahh, memory we actually used! Check if we can cover | |
11261 | it with hardware watchpoints. */ | |
df407dfe | 11262 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11263 | |
11264 | /* We only watch structs and arrays if user asked for it | |
11265 | explicitly, never if they just happen to appear in a | |
11266 | middle of some value chain. */ | |
11267 | if (v == head | |
11268 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11269 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11270 | { | |
42ae5230 | 11271 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11272 | int len; |
11273 | int num_regs; | |
11274 | ||
a9634178 | 11275 | len = (target_exact_watchpoints |
e09342b5 TJB |
11276 | && is_scalar_type_recursive (vtype))? |
11277 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11278 | |
e09342b5 TJB |
11279 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11280 | if (!num_regs) | |
2e70b7b9 MS |
11281 | return 0; |
11282 | else | |
e09342b5 | 11283 | found_memory_cnt += num_regs; |
2e70b7b9 | 11284 | } |
5c44784c | 11285 | } |
c5aa993b | 11286 | } |
5086187c AC |
11287 | else if (VALUE_LVAL (v) != not_lval |
11288 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11289 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11290 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11291 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11292 | } |
11293 | ||
11294 | /* The expression itself looks suitable for using a hardware | |
11295 | watchpoint, but give the target machine a chance to reject it. */ | |
11296 | return found_memory_cnt; | |
11297 | } | |
11298 | ||
8b93c638 | 11299 | void |
84f4c1fe | 11300 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11301 | { |
84f4c1fe | 11302 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11303 | } |
11304 | ||
06a64a0b TT |
11305 | /* A helper function that looks for the "-location" argument and then |
11306 | calls watch_command_1. */ | |
11307 | ||
11308 | static void | |
11309 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11310 | { | |
11311 | int just_location = 0; | |
11312 | ||
11313 | if (arg | |
11314 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11315 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11316 | { | |
e9cafbcc | 11317 | arg = skip_spaces (arg); |
06a64a0b TT |
11318 | just_location = 1; |
11319 | } | |
11320 | ||
84f4c1fe | 11321 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11322 | } |
8926118c | 11323 | |
c5aa993b | 11324 | static void |
fba45db2 | 11325 | watch_command (char *arg, int from_tty) |
c906108c | 11326 | { |
06a64a0b | 11327 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11328 | } |
11329 | ||
8b93c638 | 11330 | void |
84f4c1fe | 11331 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11332 | { |
84f4c1fe | 11333 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11334 | } |
8926118c | 11335 | |
c5aa993b | 11336 | static void |
fba45db2 | 11337 | rwatch_command (char *arg, int from_tty) |
c906108c | 11338 | { |
06a64a0b | 11339 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11340 | } |
11341 | ||
8b93c638 | 11342 | void |
84f4c1fe | 11343 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11344 | { |
84f4c1fe | 11345 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11346 | } |
8926118c | 11347 | |
c5aa993b | 11348 | static void |
fba45db2 | 11349 | awatch_command (char *arg, int from_tty) |
c906108c | 11350 | { |
06a64a0b | 11351 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11352 | } |
c906108c | 11353 | \f |
c5aa993b | 11354 | |
cfc31633 PA |
11355 | /* Data for the FSM that manages the until(location)/advance commands |
11356 | in infcmd.c. Here because it uses the mechanisms of | |
11357 | breakpoints. */ | |
c906108c | 11358 | |
cfc31633 | 11359 | struct until_break_fsm |
bfec99b2 | 11360 | { |
cfc31633 PA |
11361 | /* The base class. */ |
11362 | struct thread_fsm thread_fsm; | |
11363 | ||
11364 | /* The thread that as current when the command was executed. */ | |
11365 | int thread; | |
11366 | ||
11367 | /* The breakpoint set at the destination location. */ | |
11368 | struct breakpoint *location_breakpoint; | |
11369 | ||
11370 | /* Breakpoint set at the return address in the caller frame. May be | |
11371 | NULL. */ | |
11372 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11373 | }; |
11374 | ||
8980e177 PA |
11375 | static void until_break_fsm_clean_up (struct thread_fsm *self, |
11376 | struct thread_info *thread); | |
11377 | static int until_break_fsm_should_stop (struct thread_fsm *self, | |
11378 | struct thread_info *thread); | |
cfc31633 PA |
11379 | static enum async_reply_reason |
11380 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11381 | ||
11382 | /* until_break_fsm's vtable. */ | |
11383 | ||
11384 | static struct thread_fsm_ops until_break_fsm_ops = | |
11385 | { | |
11386 | NULL, /* dtor */ | |
11387 | until_break_fsm_clean_up, | |
11388 | until_break_fsm_should_stop, | |
11389 | NULL, /* return_value */ | |
11390 | until_break_fsm_async_reply_reason, | |
11391 | }; | |
11392 | ||
11393 | /* Allocate a new until_break_command_fsm. */ | |
11394 | ||
11395 | static struct until_break_fsm * | |
8980e177 | 11396 | new_until_break_fsm (struct interp *cmd_interp, int thread, |
cfc31633 PA |
11397 | struct breakpoint *location_breakpoint, |
11398 | struct breakpoint *caller_breakpoint) | |
11399 | { | |
11400 | struct until_break_fsm *sm; | |
11401 | ||
11402 | sm = XCNEW (struct until_break_fsm); | |
8980e177 | 11403 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); |
cfc31633 PA |
11404 | |
11405 | sm->thread = thread; | |
11406 | sm->location_breakpoint = location_breakpoint; | |
11407 | sm->caller_breakpoint = caller_breakpoint; | |
11408 | ||
11409 | return sm; | |
11410 | } | |
11411 | ||
11412 | /* Implementation of the 'should_stop' FSM method for the | |
11413 | until(location)/advance commands. */ | |
11414 | ||
11415 | static int | |
8980e177 PA |
11416 | until_break_fsm_should_stop (struct thread_fsm *self, |
11417 | struct thread_info *tp) | |
cfc31633 PA |
11418 | { |
11419 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
cfc31633 PA |
11420 | |
11421 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11422 | sm->location_breakpoint) != NULL | |
11423 | || (sm->caller_breakpoint != NULL | |
11424 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11425 | sm->caller_breakpoint) != NULL)) | |
11426 | thread_fsm_set_finished (self); | |
11427 | ||
11428 | return 1; | |
11429 | } | |
11430 | ||
11431 | /* Implementation of the 'clean_up' FSM method for the | |
11432 | until(location)/advance commands. */ | |
11433 | ||
c2c6d25f | 11434 | static void |
8980e177 PA |
11435 | until_break_fsm_clean_up (struct thread_fsm *self, |
11436 | struct thread_info *thread) | |
43ff13b4 | 11437 | { |
cfc31633 | 11438 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11439 | |
cfc31633 PA |
11440 | /* Clean up our temporary breakpoints. */ |
11441 | if (sm->location_breakpoint != NULL) | |
11442 | { | |
11443 | delete_breakpoint (sm->location_breakpoint); | |
11444 | sm->location_breakpoint = NULL; | |
11445 | } | |
11446 | if (sm->caller_breakpoint != NULL) | |
11447 | { | |
11448 | delete_breakpoint (sm->caller_breakpoint); | |
11449 | sm->caller_breakpoint = NULL; | |
11450 | } | |
11451 | delete_longjmp_breakpoint (sm->thread); | |
11452 | } | |
11453 | ||
11454 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11455 | until(location)/advance commands. */ | |
11456 | ||
11457 | static enum async_reply_reason | |
11458 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11459 | { | |
11460 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11461 | } |
11462 | ||
c906108c | 11463 | void |
ae66c1fc | 11464 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c | 11465 | { |
8556afb4 PA |
11466 | struct frame_info *frame; |
11467 | struct gdbarch *frame_gdbarch; | |
11468 | struct frame_id stack_frame_id; | |
11469 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11470 | struct breakpoint *location_breakpoint; |
11471 | struct breakpoint *caller_breakpoint = NULL; | |
ffc2605c | 11472 | struct cleanup *old_chain; |
186c406b TT |
11473 | int thread; |
11474 | struct thread_info *tp; | |
cfc31633 | 11475 | struct until_break_fsm *sm; |
c906108c | 11476 | |
70509625 | 11477 | clear_proceed_status (0); |
c906108c SS |
11478 | |
11479 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11480 | this function. */ |
c5aa993b | 11481 | |
ffc2605c | 11482 | event_location_up location = string_to_event_location (&arg, current_language); |
f00aae0f | 11483 | |
6c5b2ebe PA |
11484 | std::vector<symtab_and_line> sals |
11485 | = (last_displayed_sal_is_valid () | |
11486 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, | |
11487 | get_last_displayed_symtab (), | |
11488 | get_last_displayed_line ()) | |
11489 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, | |
11490 | NULL, (struct symtab *) NULL, 0)); | |
c5aa993b | 11491 | |
6c5b2ebe | 11492 | if (sals.size () != 1) |
8a3fe4f8 | 11493 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11494 | |
6c5b2ebe | 11495 | symtab_and_line &sal = sals[0]; |
c5aa993b | 11496 | |
c906108c | 11497 | if (*arg) |
8a3fe4f8 | 11498 | error (_("Junk at end of arguments.")); |
c5aa993b | 11499 | |
c906108c | 11500 | resolve_sal_pc (&sal); |
c5aa993b | 11501 | |
186c406b | 11502 | tp = inferior_thread (); |
5d5658a1 | 11503 | thread = tp->global_num; |
186c406b | 11504 | |
883bc8d1 PA |
11505 | old_chain = make_cleanup (null_cleanup, NULL); |
11506 | ||
8556afb4 PA |
11507 | /* Note linespec handling above invalidates the frame chain. |
11508 | Installing a breakpoint also invalidates the frame chain (as it | |
11509 | may need to switch threads), so do any frame handling before | |
11510 | that. */ | |
11511 | ||
11512 | frame = get_selected_frame (NULL); | |
11513 | frame_gdbarch = get_frame_arch (frame); | |
11514 | stack_frame_id = get_stack_frame_id (frame); | |
11515 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11516 | |
ae66c1fc EZ |
11517 | /* Keep within the current frame, or in frames called by the current |
11518 | one. */ | |
edb3359d | 11519 | |
883bc8d1 | 11520 | if (frame_id_p (caller_frame_id)) |
c906108c | 11521 | { |
883bc8d1 | 11522 | struct symtab_and_line sal2; |
cfc31633 | 11523 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11524 | |
11525 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11526 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11527 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11528 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11529 | sal2, | |
11530 | caller_frame_id, | |
11531 | bp_until); | |
11532 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11533 | |
883bc8d1 | 11534 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11535 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11536 | } |
c5aa993b | 11537 | |
c70a6932 JK |
11538 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11539 | frame = NULL; | |
11540 | ||
883bc8d1 PA |
11541 | if (anywhere) |
11542 | /* If the user told us to continue until a specified location, | |
11543 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11544 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11545 | null_frame_id, bp_until); | |
883bc8d1 PA |
11546 | else |
11547 | /* Otherwise, specify the selected frame, because we want to stop | |
11548 | only at the very same frame. */ | |
cfc31633 PA |
11549 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11550 | stack_frame_id, bp_until); | |
11551 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11552 | |
8980e177 | 11553 | sm = new_until_break_fsm (command_interp (), tp->global_num, |
5d5658a1 | 11554 | location_breakpoint, caller_breakpoint); |
cfc31633 | 11555 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11556 | |
cfc31633 | 11557 | discard_cleanups (old_chain); |
f107f563 | 11558 | |
cfc31633 | 11559 | proceed (-1, GDB_SIGNAL_DEFAULT); |
c906108c | 11560 | } |
ae66c1fc | 11561 | |
c906108c SS |
11562 | /* This function attempts to parse an optional "if <cond>" clause |
11563 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11564 | |
c906108c SS |
11565 | Else, it returns a pointer to the condition string. (It does not |
11566 | attempt to evaluate the string against a particular block.) And, | |
11567 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11568 | if clause in the arg string. */ |
53a5351d | 11569 | |
63160a43 PA |
11570 | const char * |
11571 | ep_parse_optional_if_clause (const char **arg) | |
c906108c | 11572 | { |
63160a43 | 11573 | const char *cond_string; |
c5aa993b JM |
11574 | |
11575 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11576 | return NULL; |
c5aa993b | 11577 | |
4a64f543 | 11578 | /* Skip the "if" keyword. */ |
c906108c | 11579 | (*arg) += 2; |
c5aa993b | 11580 | |
c906108c | 11581 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11582 | condition string. */ |
f1735a53 | 11583 | *arg = skip_spaces (*arg); |
c906108c | 11584 | cond_string = *arg; |
c5aa993b | 11585 | |
4a64f543 MS |
11586 | /* Assume that the condition occupies the remainder of the arg |
11587 | string. */ | |
c906108c | 11588 | (*arg) += strlen (cond_string); |
c5aa993b | 11589 | |
c906108c SS |
11590 | return cond_string; |
11591 | } | |
c5aa993b | 11592 | |
c906108c SS |
11593 | /* Commands to deal with catching events, such as signals, exceptions, |
11594 | process start/exit, etc. */ | |
c5aa993b JM |
11595 | |
11596 | typedef enum | |
11597 | { | |
44feb3ce TT |
11598 | catch_fork_temporary, catch_vfork_temporary, |
11599 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11600 | } |
11601 | catch_fork_kind; | |
11602 | ||
c906108c | 11603 | static void |
63160a43 | 11604 | catch_fork_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11605 | struct cmd_list_element *command) |
c906108c | 11606 | { |
63160a43 | 11607 | const char *arg = arg_entry; |
a6d9a66e | 11608 | struct gdbarch *gdbarch = get_current_arch (); |
63160a43 | 11609 | const char *cond_string = NULL; |
44feb3ce TT |
11610 | catch_fork_kind fork_kind; |
11611 | int tempflag; | |
11612 | ||
11613 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11614 | tempflag = (fork_kind == catch_fork_temporary | |
11615 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11616 | |
44feb3ce TT |
11617 | if (!arg) |
11618 | arg = ""; | |
f1735a53 | 11619 | arg = skip_spaces (arg); |
c5aa993b | 11620 | |
c906108c | 11621 | /* The allowed syntax is: |
c5aa993b JM |
11622 | catch [v]fork |
11623 | catch [v]fork if <cond> | |
11624 | ||
4a64f543 | 11625 | First, check if there's an if clause. */ |
c906108c | 11626 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11627 | |
c906108c | 11628 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11629 | error (_("Junk at end of arguments.")); |
c5aa993b | 11630 | |
c906108c | 11631 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11632 | and enable reporting of such events. */ |
c5aa993b JM |
11633 | switch (fork_kind) |
11634 | { | |
44feb3ce TT |
11635 | case catch_fork_temporary: |
11636 | case catch_fork_permanent: | |
a6d9a66e | 11637 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11638 | &catch_fork_breakpoint_ops); |
c906108c | 11639 | break; |
44feb3ce TT |
11640 | case catch_vfork_temporary: |
11641 | case catch_vfork_permanent: | |
a6d9a66e | 11642 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11643 | &catch_vfork_breakpoint_ops); |
c906108c | 11644 | break; |
c5aa993b | 11645 | default: |
8a3fe4f8 | 11646 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11647 | break; |
c5aa993b | 11648 | } |
c906108c SS |
11649 | } |
11650 | ||
11651 | static void | |
63160a43 | 11652 | catch_exec_command_1 (char *arg_entry, int from_tty, |
cc59ec59 | 11653 | struct cmd_list_element *command) |
c906108c | 11654 | { |
63160a43 | 11655 | const char *arg = arg_entry; |
a6d9a66e | 11656 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11657 | int tempflag; |
63160a43 | 11658 | const char *cond_string = NULL; |
c906108c | 11659 | |
44feb3ce TT |
11660 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11661 | ||
11662 | if (!arg) | |
11663 | arg = ""; | |
f1735a53 | 11664 | arg = skip_spaces (arg); |
c906108c SS |
11665 | |
11666 | /* The allowed syntax is: | |
c5aa993b JM |
11667 | catch exec |
11668 | catch exec if <cond> | |
c906108c | 11669 | |
4a64f543 | 11670 | First, check if there's an if clause. */ |
c906108c SS |
11671 | cond_string = ep_parse_optional_if_clause (&arg); |
11672 | ||
11673 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11674 | error (_("Junk at end of arguments.")); |
c906108c | 11675 | |
b270e6f9 TT |
11676 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
11677 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, | |
b4d90040 PA |
11678 | &catch_exec_breakpoint_ops); |
11679 | c->exec_pathname = NULL; | |
11680 | ||
b270e6f9 | 11681 | install_breakpoint (0, std::move (c), 1); |
c906108c | 11682 | } |
c5aa993b | 11683 | |
9ac4176b | 11684 | void |
28010a5d PA |
11685 | init_ada_exception_breakpoint (struct breakpoint *b, |
11686 | struct gdbarch *gdbarch, | |
11687 | struct symtab_and_line sal, | |
11688 | char *addr_string, | |
c0a91b2b | 11689 | const struct breakpoint_ops *ops, |
28010a5d | 11690 | int tempflag, |
349774ef | 11691 | int enabled, |
28010a5d | 11692 | int from_tty) |
f7f9143b | 11693 | { |
f7f9143b JB |
11694 | if (from_tty) |
11695 | { | |
5af949e3 UW |
11696 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11697 | if (!loc_gdbarch) | |
11698 | loc_gdbarch = gdbarch; | |
11699 | ||
6c95b8df PA |
11700 | describe_other_breakpoints (loc_gdbarch, |
11701 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11702 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11703 | version for exception catchpoints, because two catchpoints | |
11704 | used for different exception names will use the same address. | |
11705 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11706 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11707 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11708 | the user what type of catchpoint it is. The above is good |
11709 | enough for now, though. */ | |
11710 | } | |
11711 | ||
28010a5d | 11712 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11713 | |
349774ef | 11714 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11715 | b->disposition = tempflag ? disp_del : disp_donttouch; |
d28cd78a TT |
11716 | b->location = string_to_event_location (&addr_string, |
11717 | language_def (language_ada)); | |
f7f9143b | 11718 | b->language = language_ada; |
f7f9143b JB |
11719 | } |
11720 | ||
c906108c | 11721 | static void |
fba45db2 | 11722 | catch_command (char *arg, int from_tty) |
c906108c | 11723 | { |
44feb3ce | 11724 | error (_("Catch requires an event name.")); |
c906108c SS |
11725 | } |
11726 | \f | |
11727 | ||
11728 | static void | |
fba45db2 | 11729 | tcatch_command (char *arg, int from_tty) |
c906108c | 11730 | { |
44feb3ce | 11731 | error (_("Catch requires an event name.")); |
c906108c SS |
11732 | } |
11733 | ||
8a2c437b TT |
11734 | /* A qsort comparison function that sorts breakpoints in order. */ |
11735 | ||
11736 | static int | |
11737 | compare_breakpoints (const void *a, const void *b) | |
11738 | { | |
9a3c8263 | 11739 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11740 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11741 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11742 | uintptr_t ub = (uintptr_t) *bb; |
11743 | ||
11744 | if ((*ba)->number < (*bb)->number) | |
11745 | return -1; | |
11746 | else if ((*ba)->number > (*bb)->number) | |
11747 | return 1; | |
11748 | ||
11749 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11750 | the number 0. */ | |
11751 | if (ua < ub) | |
11752 | return -1; | |
94b0e70d | 11753 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11754 | } |
11755 | ||
80f8a6eb | 11756 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11757 | |
11758 | static void | |
fba45db2 | 11759 | clear_command (char *arg, int from_tty) |
c906108c | 11760 | { |
8a2c437b | 11761 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11762 | VEC(breakpoint_p) *found = 0; |
11763 | int ix; | |
c906108c | 11764 | int default_match; |
c906108c | 11765 | int i; |
8a2c437b | 11766 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c | 11767 | |
6c5b2ebe PA |
11768 | std::vector<symtab_and_line> decoded_sals; |
11769 | symtab_and_line last_sal; | |
11770 | gdb::array_view<symtab_and_line> sals; | |
c906108c SS |
11771 | if (arg) |
11772 | { | |
6c5b2ebe PA |
11773 | decoded_sals |
11774 | = decode_line_with_current_source (arg, | |
11775 | (DECODE_LINE_FUNFIRSTLINE | |
11776 | | DECODE_LINE_LIST_MODE)); | |
c906108c | 11777 | default_match = 0; |
6c5b2ebe | 11778 | sals = decoded_sals; |
c906108c SS |
11779 | } |
11780 | else | |
11781 | { | |
1bfeeb0f JL |
11782 | /* Set sal's line, symtab, pc, and pspace to the values |
11783 | corresponding to the last call to print_frame_info. If the | |
11784 | codepoint is not valid, this will set all the fields to 0. */ | |
51abb421 | 11785 | last_sal = get_last_displayed_sal (); |
6c5b2ebe | 11786 | if (last_sal.symtab == 0) |
8a3fe4f8 | 11787 | error (_("No source file specified.")); |
c906108c | 11788 | |
c906108c | 11789 | default_match = 1; |
6c5b2ebe | 11790 | sals = last_sal; |
c906108c SS |
11791 | } |
11792 | ||
4a64f543 MS |
11793 | /* We don't call resolve_sal_pc here. That's not as bad as it |
11794 | seems, because all existing breakpoints typically have both | |
11795 | file/line and pc set. So, if clear is given file/line, we can | |
11796 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
11797 | |
11798 | We only support clearing given the address explicitly | |
11799 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 11800 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 11801 | due to optimization, all in one block. |
4a64f543 MS |
11802 | |
11803 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
11804 | PC corresponding to the same file:line, the breakpoint won't |
11805 | be cleared. We probably can still clear the breakpoint, but | |
11806 | since the other PC value is never presented to user, user | |
11807 | can only find it by guessing, and it does not seem important | |
11808 | to support that. */ | |
11809 | ||
4a64f543 MS |
11810 | /* For each line spec given, delete bps which correspond to it. Do |
11811 | it in two passes, solely to preserve the current behavior that | |
11812 | from_tty is forced true if we delete more than one | |
11813 | breakpoint. */ | |
c906108c | 11814 | |
80f8a6eb | 11815 | found = NULL; |
8a2c437b | 11816 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
6c5b2ebe | 11817 | for (const auto &sal : sals) |
c906108c | 11818 | { |
05cba821 JK |
11819 | const char *sal_fullname; |
11820 | ||
c906108c | 11821 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
11822 | If line given (pc == 0), clear all bpts on specified line. |
11823 | If defaulting, clear all bpts on default line | |
c906108c | 11824 | or at default pc. |
c5aa993b JM |
11825 | |
11826 | defaulting sal.pc != 0 tests to do | |
11827 | ||
11828 | 0 1 pc | |
11829 | 1 1 pc _and_ line | |
11830 | 0 0 line | |
11831 | 1 0 <can't happen> */ | |
c906108c | 11832 | |
05cba821 JK |
11833 | sal_fullname = (sal.symtab == NULL |
11834 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 11835 | |
4a64f543 | 11836 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 11837 | ALL_BREAKPOINTS (b) |
c5aa993b | 11838 | { |
0d381245 | 11839 | int match = 0; |
4a64f543 | 11840 | /* Are we going to delete b? */ |
cc60f2e3 | 11841 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
11842 | { |
11843 | struct bp_location *loc = b->loc; | |
11844 | for (; loc; loc = loc->next) | |
11845 | { | |
f8eba3c6 TT |
11846 | /* If the user specified file:line, don't allow a PC |
11847 | match. This matches historical gdb behavior. */ | |
11848 | int pc_match = (!sal.explicit_line | |
11849 | && sal.pc | |
11850 | && (loc->pspace == sal.pspace) | |
11851 | && (loc->address == sal.pc) | |
11852 | && (!section_is_overlay (loc->section) | |
11853 | || loc->section == sal.section)); | |
4aac40c8 TT |
11854 | int line_match = 0; |
11855 | ||
11856 | if ((default_match || sal.explicit_line) | |
2f202fde | 11857 | && loc->symtab != NULL |
05cba821 | 11858 | && sal_fullname != NULL |
4aac40c8 | 11859 | && sal.pspace == loc->pspace |
05cba821 JK |
11860 | && loc->line_number == sal.line |
11861 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
11862 | sal_fullname) == 0) | |
11863 | line_match = 1; | |
4aac40c8 | 11864 | |
0d381245 VP |
11865 | if (pc_match || line_match) |
11866 | { | |
11867 | match = 1; | |
11868 | break; | |
11869 | } | |
11870 | } | |
11871 | } | |
11872 | ||
11873 | if (match) | |
d6e956e5 | 11874 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 11875 | } |
80f8a6eb | 11876 | } |
8a2c437b | 11877 | |
80f8a6eb | 11878 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 11879 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
11880 | { |
11881 | if (arg) | |
8a3fe4f8 | 11882 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 11883 | else |
8a3fe4f8 | 11884 | error (_("No breakpoint at this line.")); |
80f8a6eb | 11885 | } |
c906108c | 11886 | |
8a2c437b TT |
11887 | /* Remove duplicates from the vec. */ |
11888 | qsort (VEC_address (breakpoint_p, found), | |
11889 | VEC_length (breakpoint_p, found), | |
11890 | sizeof (breakpoint_p), | |
11891 | compare_breakpoints); | |
11892 | prev = VEC_index (breakpoint_p, found, 0); | |
11893 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
11894 | { | |
11895 | if (b == prev) | |
11896 | { | |
11897 | VEC_ordered_remove (breakpoint_p, found, ix); | |
11898 | --ix; | |
11899 | } | |
11900 | } | |
11901 | ||
d6e956e5 | 11902 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 11903 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 11904 | if (from_tty) |
a3f17187 | 11905 | { |
d6e956e5 | 11906 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
11907 | printf_unfiltered (_("Deleted breakpoint ")); |
11908 | else | |
11909 | printf_unfiltered (_("Deleted breakpoints ")); | |
11910 | } | |
d6e956e5 VP |
11911 | |
11912 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 11913 | { |
c5aa993b | 11914 | if (from_tty) |
d6e956e5 VP |
11915 | printf_unfiltered ("%d ", b->number); |
11916 | delete_breakpoint (b); | |
c906108c | 11917 | } |
80f8a6eb MS |
11918 | if (from_tty) |
11919 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
11920 | |
11921 | do_cleanups (cleanups); | |
c906108c SS |
11922 | } |
11923 | \f | |
11924 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
11925 | all breakpoints that are marked for deletion, whether hit or not. | |
11926 | This is called after any breakpoint is hit, or after errors. */ | |
11927 | ||
11928 | void | |
fba45db2 | 11929 | breakpoint_auto_delete (bpstat bs) |
c906108c | 11930 | { |
35df4500 | 11931 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11932 | |
11933 | for (; bs; bs = bs->next) | |
f431efe5 PA |
11934 | if (bs->breakpoint_at |
11935 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 11936 | && bs->stop) |
f431efe5 | 11937 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 11938 | |
35df4500 | 11939 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11940 | { |
b5de0fa7 | 11941 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
11942 | delete_breakpoint (b); |
11943 | } | |
c906108c SS |
11944 | } |
11945 | ||
4a64f543 MS |
11946 | /* A comparison function for bp_location AP and BP being interfaced to |
11947 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
11948 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 11949 | secondarily by ordering first permanent elements and |
4a64f543 | 11950 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 11951 | qsort being an unstable algorithm. */ |
876fa593 JK |
11952 | |
11953 | static int | |
f5336ca5 | 11954 | bp_locations_compare (const void *ap, const void *bp) |
876fa593 | 11955 | { |
9a3c8263 SM |
11956 | const struct bp_location *a = *(const struct bp_location **) ap; |
11957 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
11958 | |
11959 | if (a->address != b->address) | |
11960 | return (a->address > b->address) - (a->address < b->address); | |
11961 | ||
dea2aa5f LM |
11962 | /* Sort locations at the same address by their pspace number, keeping |
11963 | locations of the same inferior (in a multi-inferior environment) | |
11964 | grouped. */ | |
11965 | ||
11966 | if (a->pspace->num != b->pspace->num) | |
11967 | return ((a->pspace->num > b->pspace->num) | |
11968 | - (a->pspace->num < b->pspace->num)); | |
11969 | ||
876fa593 | 11970 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
11971 | if (a->permanent != b->permanent) |
11972 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 11973 | |
c56a97f9 JK |
11974 | /* Make the internal GDB representation stable across GDB runs |
11975 | where A and B memory inside GDB can differ. Breakpoint locations of | |
11976 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
11977 | |
11978 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
11979 | return ((a->owner->number > b->owner->number) |
11980 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
11981 | |
11982 | return (a > b) - (a < b); | |
11983 | } | |
11984 | ||
f5336ca5 PA |
11985 | /* Set bp_locations_placed_address_before_address_max and |
11986 | bp_locations_shadow_len_after_address_max according to the current | |
11987 | content of the bp_locations array. */ | |
f7545552 TT |
11988 | |
11989 | static void | |
f5336ca5 | 11990 | bp_locations_target_extensions_update (void) |
f7545552 | 11991 | { |
876fa593 JK |
11992 | struct bp_location *bl, **blp_tmp; |
11993 | ||
f5336ca5 PA |
11994 | bp_locations_placed_address_before_address_max = 0; |
11995 | bp_locations_shadow_len_after_address_max = 0; | |
876fa593 JK |
11996 | |
11997 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
11998 | { | |
11999 | CORE_ADDR start, end, addr; | |
12000 | ||
12001 | if (!bp_location_has_shadow (bl)) | |
12002 | continue; | |
12003 | ||
12004 | start = bl->target_info.placed_address; | |
12005 | end = start + bl->target_info.shadow_len; | |
12006 | ||
12007 | gdb_assert (bl->address >= start); | |
12008 | addr = bl->address - start; | |
f5336ca5 PA |
12009 | if (addr > bp_locations_placed_address_before_address_max) |
12010 | bp_locations_placed_address_before_address_max = addr; | |
876fa593 JK |
12011 | |
12012 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12013 | ||
12014 | gdb_assert (bl->address < end); | |
12015 | addr = end - bl->address; | |
f5336ca5 PA |
12016 | if (addr > bp_locations_shadow_len_after_address_max) |
12017 | bp_locations_shadow_len_after_address_max = addr; | |
876fa593 | 12018 | } |
f7545552 TT |
12019 | } |
12020 | ||
1e4d1764 YQ |
12021 | /* Download tracepoint locations if they haven't been. */ |
12022 | ||
12023 | static void | |
12024 | download_tracepoint_locations (void) | |
12025 | { | |
7ed2c994 | 12026 | struct breakpoint *b; |
dd2e65cc | 12027 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 | 12028 | |
5ed8105e | 12029 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
1e4d1764 | 12030 | |
7ed2c994 | 12031 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12032 | { |
7ed2c994 | 12033 | struct bp_location *bl; |
1e4d1764 | 12034 | struct tracepoint *t; |
f2a8bc8a | 12035 | int bp_location_downloaded = 0; |
1e4d1764 | 12036 | |
7ed2c994 | 12037 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12038 | ? !may_insert_fast_tracepoints |
12039 | : !may_insert_tracepoints)) | |
12040 | continue; | |
12041 | ||
dd2e65cc YQ |
12042 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12043 | { | |
12044 | if (target_can_download_tracepoint ()) | |
12045 | can_download_tracepoint = TRIBOOL_TRUE; | |
12046 | else | |
12047 | can_download_tracepoint = TRIBOOL_FALSE; | |
12048 | } | |
12049 | ||
12050 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12051 | break; | |
12052 | ||
7ed2c994 YQ |
12053 | for (bl = b->loc; bl; bl = bl->next) |
12054 | { | |
12055 | /* In tracepoint, locations are _never_ duplicated, so | |
12056 | should_be_inserted is equivalent to | |
12057 | unduplicated_should_be_inserted. */ | |
12058 | if (!should_be_inserted (bl) || bl->inserted) | |
12059 | continue; | |
1e4d1764 | 12060 | |
7ed2c994 | 12061 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12062 | |
7ed2c994 | 12063 | target_download_tracepoint (bl); |
1e4d1764 | 12064 | |
7ed2c994 | 12065 | bl->inserted = 1; |
f2a8bc8a | 12066 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12067 | } |
12068 | t = (struct tracepoint *) b; | |
12069 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12070 | if (bp_location_downloaded) |
12071 | observer_notify_breakpoint_modified (b); | |
1e4d1764 | 12072 | } |
1e4d1764 YQ |
12073 | } |
12074 | ||
934709f0 PW |
12075 | /* Swap the insertion/duplication state between two locations. */ |
12076 | ||
12077 | static void | |
12078 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12079 | { | |
12080 | const int left_inserted = left->inserted; | |
12081 | const int left_duplicate = left->duplicate; | |
b775012e | 12082 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12083 | const struct bp_target_info left_target_info = left->target_info; |
12084 | ||
1e4d1764 YQ |
12085 | /* Locations of tracepoints can never be duplicated. */ |
12086 | if (is_tracepoint (left->owner)) | |
12087 | gdb_assert (!left->duplicate); | |
12088 | if (is_tracepoint (right->owner)) | |
12089 | gdb_assert (!right->duplicate); | |
12090 | ||
934709f0 PW |
12091 | left->inserted = right->inserted; |
12092 | left->duplicate = right->duplicate; | |
b775012e | 12093 | left->needs_update = right->needs_update; |
934709f0 PW |
12094 | left->target_info = right->target_info; |
12095 | right->inserted = left_inserted; | |
12096 | right->duplicate = left_duplicate; | |
b775012e | 12097 | right->needs_update = left_needs_update; |
934709f0 PW |
12098 | right->target_info = left_target_info; |
12099 | } | |
12100 | ||
b775012e LM |
12101 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12102 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12103 | conditions on the target's side. Such conditions need to be updated on | |
12104 | the target. */ | |
12105 | ||
12106 | static void | |
12107 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12108 | { | |
12109 | struct bp_location **locp = NULL, **loc2p; | |
12110 | struct bp_location *loc; | |
12111 | CORE_ADDR address = 0; | |
12112 | int pspace_num; | |
12113 | ||
12114 | address = bl->address; | |
12115 | pspace_num = bl->pspace->num; | |
12116 | ||
12117 | /* This is only meaningful if the target is | |
12118 | evaluating conditions and if the user has | |
12119 | opted for condition evaluation on the target's | |
12120 | side. */ | |
12121 | if (gdb_evaluates_breakpoint_condition_p () | |
12122 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12123 | return; | |
12124 | ||
12125 | /* Flag all breakpoint locations with this address and | |
12126 | the same program space as the location | |
12127 | as "its condition has changed". We need to | |
12128 | update the conditions on the target's side. */ | |
12129 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12130 | { | |
12131 | loc = *loc2p; | |
12132 | ||
12133 | if (!is_breakpoint (loc->owner) | |
12134 | || pspace_num != loc->pspace->num) | |
12135 | continue; | |
12136 | ||
12137 | /* Flag the location appropriately. We use a different state to | |
12138 | let everyone know that we already updated the set of locations | |
12139 | with addr bl->address and program space bl->pspace. This is so | |
12140 | we don't have to keep calling these functions just to mark locations | |
12141 | that have already been marked. */ | |
12142 | loc->condition_changed = condition_updated; | |
12143 | ||
12144 | /* Free the agent expression bytecode as well. We will compute | |
12145 | it later on. */ | |
833177a4 | 12146 | loc->cond_bytecode.reset (); |
b775012e LM |
12147 | } |
12148 | } | |
44702360 PA |
12149 | /* Called whether new breakpoints are created, or existing breakpoints |
12150 | deleted, to update the global location list and recompute which | |
12151 | locations are duplicate of which. | |
b775012e | 12152 | |
04086b45 PA |
12153 | The INSERT_MODE flag determines whether locations may not, may, or |
12154 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12155 | info. */ | |
b60e7edf | 12156 | |
0d381245 | 12157 | static void |
44702360 | 12158 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12159 | { |
74960c60 | 12160 | struct breakpoint *b; |
876fa593 | 12161 | struct bp_location **locp, *loc; |
f7545552 | 12162 | struct cleanup *cleanups; |
b775012e LM |
12163 | /* Last breakpoint location address that was marked for update. */ |
12164 | CORE_ADDR last_addr = 0; | |
12165 | /* Last breakpoint location program space that was marked for update. */ | |
12166 | int last_pspace_num = -1; | |
f7545552 | 12167 | |
2d134ed3 PA |
12168 | /* Used in the duplicates detection below. When iterating over all |
12169 | bp_locations, points to the first bp_location of a given address. | |
12170 | Breakpoints and watchpoints of different types are never | |
12171 | duplicates of each other. Keep one pointer for each type of | |
12172 | breakpoint/watchpoint, so we only need to loop over all locations | |
12173 | once. */ | |
12174 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12175 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12176 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12177 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12178 | |
f5336ca5 PA |
12179 | /* Saved former bp_locations array which we compare against the newly |
12180 | built bp_locations from the current state of ALL_BREAKPOINTS. */ | |
12181 | struct bp_location **old_locations, **old_locp; | |
12182 | unsigned old_locations_count; | |
876fa593 | 12183 | |
f5336ca5 PA |
12184 | old_locations = bp_locations; |
12185 | old_locations_count = bp_locations_count; | |
12186 | bp_locations = NULL; | |
12187 | bp_locations_count = 0; | |
12188 | cleanups = make_cleanup (xfree, old_locations); | |
0d381245 | 12189 | |
74960c60 | 12190 | ALL_BREAKPOINTS (b) |
876fa593 | 12191 | for (loc = b->loc; loc; loc = loc->next) |
f5336ca5 | 12192 | bp_locations_count++; |
876fa593 | 12193 | |
f5336ca5 PA |
12194 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
12195 | locp = bp_locations; | |
876fa593 JK |
12196 | ALL_BREAKPOINTS (b) |
12197 | for (loc = b->loc; loc; loc = loc->next) | |
12198 | *locp++ = loc; | |
f5336ca5 PA |
12199 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
12200 | bp_locations_compare); | |
876fa593 | 12201 | |
f5336ca5 | 12202 | bp_locations_target_extensions_update (); |
74960c60 | 12203 | |
4a64f543 MS |
12204 | /* Identify bp_location instances that are no longer present in the |
12205 | new list, and therefore should be freed. Note that it's not | |
12206 | necessary that those locations should be removed from inferior -- | |
12207 | if there's another location at the same address (previously | |
12208 | marked as duplicate), we don't need to remove/insert the | |
12209 | location. | |
876fa593 | 12210 | |
4a64f543 MS |
12211 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12212 | and former bp_location array state respectively. */ | |
876fa593 | 12213 | |
f5336ca5 PA |
12214 | locp = bp_locations; |
12215 | for (old_locp = old_locations; | |
12216 | old_locp < old_locations + old_locations_count; | |
876fa593 | 12217 | old_locp++) |
74960c60 | 12218 | { |
876fa593 | 12219 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12220 | struct bp_location **loc2p; |
876fa593 | 12221 | |
e5dd4106 | 12222 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12223 | not, we have to free it. */ |
c7d46a38 | 12224 | int found_object = 0; |
20874c92 VP |
12225 | /* Tells if the location should remain inserted in the target. */ |
12226 | int keep_in_target = 0; | |
12227 | int removed = 0; | |
876fa593 | 12228 | |
4a64f543 MS |
12229 | /* Skip LOCP entries which will definitely never be needed. |
12230 | Stop either at or being the one matching OLD_LOC. */ | |
f5336ca5 | 12231 | while (locp < bp_locations + bp_locations_count |
c7d46a38 | 12232 | && (*locp)->address < old_loc->address) |
876fa593 | 12233 | locp++; |
c7d46a38 PA |
12234 | |
12235 | for (loc2p = locp; | |
f5336ca5 | 12236 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 PA |
12237 | && (*loc2p)->address == old_loc->address); |
12238 | loc2p++) | |
12239 | { | |
b775012e LM |
12240 | /* Check if this is a new/duplicated location or a duplicated |
12241 | location that had its condition modified. If so, we want to send | |
12242 | its condition to the target if evaluation of conditions is taking | |
12243 | place there. */ | |
12244 | if ((*loc2p)->condition_changed == condition_modified | |
12245 | && (last_addr != old_loc->address | |
12246 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12247 | { |
b775012e LM |
12248 | force_breakpoint_reinsertion (*loc2p); |
12249 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12250 | } |
b775012e LM |
12251 | |
12252 | if (*loc2p == old_loc) | |
12253 | found_object = 1; | |
c7d46a38 | 12254 | } |
74960c60 | 12255 | |
b775012e LM |
12256 | /* We have already handled this address, update it so that we don't |
12257 | have to go through updates again. */ | |
12258 | last_addr = old_loc->address; | |
12259 | ||
12260 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12261 | if (!found_object) | |
12262 | force_breakpoint_reinsertion (old_loc); | |
12263 | ||
4a64f543 MS |
12264 | /* If this location is no longer present, and inserted, look if |
12265 | there's maybe a new location at the same address. If so, | |
12266 | mark that one inserted, and don't remove this one. This is | |
12267 | needed so that we don't have a time window where a breakpoint | |
12268 | at certain location is not inserted. */ | |
74960c60 | 12269 | |
876fa593 | 12270 | if (old_loc->inserted) |
0d381245 | 12271 | { |
4a64f543 MS |
12272 | /* If the location is inserted now, we might have to remove |
12273 | it. */ | |
74960c60 | 12274 | |
876fa593 | 12275 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12276 | { |
4a64f543 MS |
12277 | /* The location is still present in the location list, |
12278 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12279 | keep_in_target = 1; |
74960c60 VP |
12280 | } |
12281 | else | |
12282 | { | |
b775012e LM |
12283 | /* This location still exists, but it won't be kept in the |
12284 | target since it may have been disabled. We proceed to | |
12285 | remove its target-side condition. */ | |
12286 | ||
4a64f543 MS |
12287 | /* The location is either no longer present, or got |
12288 | disabled. See if there's another location at the | |
12289 | same address, in which case we don't need to remove | |
12290 | this one from the target. */ | |
876fa593 | 12291 | |
2bdf28a0 | 12292 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12293 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12294 | { | |
876fa593 | 12295 | for (loc2p = locp; |
f5336ca5 | 12296 | (loc2p < bp_locations + bp_locations_count |
c7d46a38 | 12297 | && (*loc2p)->address == old_loc->address); |
876fa593 JK |
12298 | loc2p++) |
12299 | { | |
12300 | struct bp_location *loc2 = *loc2p; | |
12301 | ||
2d134ed3 | 12302 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12303 | { |
85d721b8 PA |
12304 | /* Read watchpoint locations are switched to |
12305 | access watchpoints, if the former are not | |
12306 | supported, but the latter are. */ | |
12307 | if (is_hardware_watchpoint (old_loc->owner)) | |
12308 | { | |
12309 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12310 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12311 | } | |
12312 | ||
934709f0 PW |
12313 | /* loc2 is a duplicated location. We need to check |
12314 | if it should be inserted in case it will be | |
12315 | unduplicated. */ | |
12316 | if (loc2 != old_loc | |
12317 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12318 | { |
934709f0 | 12319 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12320 | keep_in_target = 1; |
12321 | break; | |
12322 | } | |
876fa593 JK |
12323 | } |
12324 | } | |
12325 | } | |
74960c60 VP |
12326 | } |
12327 | ||
20874c92 VP |
12328 | if (!keep_in_target) |
12329 | { | |
834c0d03 | 12330 | if (remove_breakpoint (old_loc)) |
20874c92 | 12331 | { |
4a64f543 MS |
12332 | /* This is just about all we can do. We could keep |
12333 | this location on the global list, and try to | |
12334 | remove it next time, but there's no particular | |
12335 | reason why we will succeed next time. | |
20874c92 | 12336 | |
4a64f543 MS |
12337 | Note that at this point, old_loc->owner is still |
12338 | valid, as delete_breakpoint frees the breakpoint | |
12339 | only after calling us. */ | |
3e43a32a MS |
12340 | printf_filtered (_("warning: Error removing " |
12341 | "breakpoint %d\n"), | |
876fa593 | 12342 | old_loc->owner->number); |
20874c92 VP |
12343 | } |
12344 | removed = 1; | |
12345 | } | |
0d381245 | 12346 | } |
74960c60 VP |
12347 | |
12348 | if (!found_object) | |
1c5cfe86 | 12349 | { |
fbea99ea | 12350 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12351 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12352 | { |
db82e815 PA |
12353 | /* This location was removed from the target. In |
12354 | non-stop mode, a race condition is possible where | |
12355 | we've removed a breakpoint, but stop events for that | |
12356 | breakpoint are already queued and will arrive later. | |
12357 | We apply an heuristic to be able to distinguish such | |
12358 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12359 | breakpoint location for a bit, and will retire it | |
12360 | after we see some number of events. The theory here | |
12361 | is that reporting of events should, "on the average", | |
12362 | be fair, so after a while we'll see events from all | |
12363 | threads that have anything of interest, and no longer | |
12364 | need to keep this breakpoint location around. We | |
12365 | don't hold locations forever so to reduce chances of | |
12366 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12367 | SIGTRAP. | |
12368 | ||
12369 | The heuristic failing can be disastrous on | |
12370 | decr_pc_after_break targets. | |
12371 | ||
12372 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12373 | if we fail to recognize a late breakpoint SIGTRAP, | |
12374 | because events_till_retirement has reached 0 too | |
12375 | soon, we'll fail to do the PC adjustment, and report | |
12376 | a random SIGTRAP to the user. When the user resumes | |
12377 | the inferior, it will most likely immediately crash | |
2dec564e | 12378 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12379 | corrupted, because of being resumed e.g., in the |
12380 | middle of a multi-byte instruction, or skipped a | |
12381 | one-byte instruction. This was actually seen happen | |
12382 | on native x86-linux, and should be less rare on | |
12383 | targets that do not support new thread events, like | |
12384 | remote, due to the heuristic depending on | |
12385 | thread_count. | |
12386 | ||
12387 | Mistaking a random SIGTRAP for a breakpoint trap | |
12388 | causes similar symptoms (PC adjustment applied when | |
12389 | it shouldn't), but then again, playing with SIGTRAPs | |
12390 | behind the debugger's back is asking for trouble. | |
12391 | ||
12392 | Since hardware watchpoint traps are always | |
12393 | distinguishable from other traps, so we don't need to | |
12394 | apply keep hardware watchpoint moribund locations | |
12395 | around. We simply always ignore hardware watchpoint | |
12396 | traps we can no longer explain. */ | |
12397 | ||
876fa593 JK |
12398 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12399 | old_loc->owner = NULL; | |
20874c92 | 12400 | |
876fa593 | 12401 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12402 | } |
12403 | else | |
f431efe5 PA |
12404 | { |
12405 | old_loc->owner = NULL; | |
12406 | decref_bp_location (&old_loc); | |
12407 | } | |
20874c92 | 12408 | } |
74960c60 | 12409 | } |
1c5cfe86 | 12410 | |
348d480f PA |
12411 | /* Rescan breakpoints at the same address and section, marking the |
12412 | first one as "first" and any others as "duplicates". This is so | |
12413 | that the bpt instruction is only inserted once. If we have a | |
12414 | permanent breakpoint at the same place as BPT, make that one the | |
12415 | official one, and the rest as duplicates. Permanent breakpoints | |
12416 | are sorted first for the same address. | |
12417 | ||
12418 | Do the same for hardware watchpoints, but also considering the | |
12419 | watchpoint's type (regular/access/read) and length. */ | |
12420 | ||
12421 | bp_loc_first = NULL; | |
12422 | wp_loc_first = NULL; | |
12423 | awp_loc_first = NULL; | |
12424 | rwp_loc_first = NULL; | |
12425 | ALL_BP_LOCATIONS (loc, locp) | |
12426 | { | |
12427 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12428 | non-NULL. */ | |
348d480f | 12429 | struct bp_location **loc_first_p; |
d3fbdd86 | 12430 | b = loc->owner; |
348d480f | 12431 | |
6f380991 | 12432 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12433 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12434 | /* Don't detect duplicate for tracepoint locations because they are |
12435 | never duplicated. See the comments in field `duplicate' of | |
12436 | `struct bp_location'. */ | |
348d480f | 12437 | || is_tracepoint (b)) |
b775012e LM |
12438 | { |
12439 | /* Clear the condition modification flag. */ | |
12440 | loc->condition_changed = condition_unchanged; | |
12441 | continue; | |
12442 | } | |
348d480f | 12443 | |
348d480f PA |
12444 | if (b->type == bp_hardware_watchpoint) |
12445 | loc_first_p = &wp_loc_first; | |
12446 | else if (b->type == bp_read_watchpoint) | |
12447 | loc_first_p = &rwp_loc_first; | |
12448 | else if (b->type == bp_access_watchpoint) | |
12449 | loc_first_p = &awp_loc_first; | |
12450 | else | |
12451 | loc_first_p = &bp_loc_first; | |
12452 | ||
12453 | if (*loc_first_p == NULL | |
12454 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12455 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12456 | { | |
12457 | *loc_first_p = loc; | |
12458 | loc->duplicate = 0; | |
b775012e LM |
12459 | |
12460 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12461 | { | |
12462 | loc->needs_update = 1; | |
12463 | /* Clear the condition modification flag. */ | |
12464 | loc->condition_changed = condition_unchanged; | |
12465 | } | |
348d480f PA |
12466 | continue; |
12467 | } | |
12468 | ||
934709f0 PW |
12469 | |
12470 | /* This and the above ensure the invariant that the first location | |
12471 | is not duplicated, and is the inserted one. | |
12472 | All following are marked as duplicated, and are not inserted. */ | |
12473 | if (loc->inserted) | |
12474 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12475 | loc->duplicate = 1; |
12476 | ||
b775012e LM |
12477 | /* Clear the condition modification flag. */ |
12478 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12479 | } |
12480 | ||
a25a5a45 | 12481 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12482 | { |
04086b45 | 12483 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12484 | insert_breakpoint_locations (); |
12485 | else | |
12486 | { | |
44702360 PA |
12487 | /* Even though the caller told us to not insert new |
12488 | locations, we may still need to update conditions on the | |
12489 | target's side of breakpoints that were already inserted | |
12490 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12491 | only update conditions for locations that are marked |
12492 | "needs_update". */ | |
12493 | update_inserted_breakpoint_locations (); | |
12494 | } | |
12495 | } | |
348d480f | 12496 | |
04086b45 | 12497 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12498 | download_tracepoint_locations (); |
12499 | ||
348d480f PA |
12500 | do_cleanups (cleanups); |
12501 | } | |
12502 | ||
12503 | void | |
12504 | breakpoint_retire_moribund (void) | |
12505 | { | |
12506 | struct bp_location *loc; | |
12507 | int ix; | |
12508 | ||
12509 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12510 | if (--(loc->events_till_retirement) == 0) | |
12511 | { | |
12512 | decref_bp_location (&loc); | |
12513 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12514 | --ix; | |
12515 | } | |
12516 | } | |
12517 | ||
12518 | static void | |
44702360 | 12519 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12520 | { |
348d480f | 12521 | |
492d29ea PA |
12522 | TRY |
12523 | { | |
12524 | update_global_location_list (insert_mode); | |
12525 | } | |
12526 | CATCH (e, RETURN_MASK_ERROR) | |
12527 | { | |
12528 | } | |
12529 | END_CATCH | |
348d480f PA |
12530 | } |
12531 | ||
12532 | /* Clear BKP from a BPS. */ | |
12533 | ||
12534 | static void | |
12535 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12536 | { | |
12537 | bpstat bs; | |
12538 | ||
12539 | for (bs = bps; bs; bs = bs->next) | |
12540 | if (bs->breakpoint_at == bpt) | |
12541 | { | |
12542 | bs->breakpoint_at = NULL; | |
12543 | bs->old_val = NULL; | |
12544 | /* bs->commands will be freed later. */ | |
12545 | } | |
12546 | } | |
12547 | ||
12548 | /* Callback for iterate_over_threads. */ | |
12549 | static int | |
12550 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12551 | { | |
9a3c8263 | 12552 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12553 | |
12554 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12555 | return 0; | |
12556 | } | |
12557 | ||
12558 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12559 | callbacks. */ | |
12560 | ||
12561 | static void | |
12562 | say_where (struct breakpoint *b) | |
12563 | { | |
12564 | struct value_print_options opts; | |
12565 | ||
12566 | get_user_print_options (&opts); | |
12567 | ||
12568 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12569 | single string. */ | |
12570 | if (b->loc == NULL) | |
12571 | { | |
f00aae0f KS |
12572 | /* For pending locations, the output differs slightly based |
12573 | on b->extra_string. If this is non-NULL, it contains either | |
12574 | a condition or dprintf arguments. */ | |
12575 | if (b->extra_string == NULL) | |
12576 | { | |
12577 | printf_filtered (_(" (%s) pending."), | |
d28cd78a | 12578 | event_location_to_string (b->location.get ())); |
f00aae0f KS |
12579 | } |
12580 | else if (b->type == bp_dprintf) | |
12581 | { | |
12582 | printf_filtered (_(" (%s,%s) pending."), | |
d28cd78a | 12583 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12584 | b->extra_string); |
12585 | } | |
12586 | else | |
12587 | { | |
12588 | printf_filtered (_(" (%s %s) pending."), | |
d28cd78a | 12589 | event_location_to_string (b->location.get ()), |
f00aae0f KS |
12590 | b->extra_string); |
12591 | } | |
348d480f PA |
12592 | } |
12593 | else | |
12594 | { | |
2f202fde | 12595 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12596 | { |
12597 | printf_filtered (" at "); | |
12598 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12599 | gdb_stdout); | |
12600 | } | |
2f202fde | 12601 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12602 | { |
12603 | /* If there is a single location, we can print the location | |
12604 | more nicely. */ | |
12605 | if (b->loc->next == NULL) | |
12606 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12607 | symtab_to_filename_for_display (b->loc->symtab), |
12608 | b->loc->line_number); | |
f8eba3c6 TT |
12609 | else |
12610 | /* This is not ideal, but each location may have a | |
12611 | different file name, and this at least reflects the | |
12612 | real situation somewhat. */ | |
f00aae0f | 12613 | printf_filtered (": %s.", |
d28cd78a | 12614 | event_location_to_string (b->location.get ())); |
f8eba3c6 | 12615 | } |
348d480f PA |
12616 | |
12617 | if (b->loc->next) | |
12618 | { | |
12619 | struct bp_location *loc = b->loc; | |
12620 | int n = 0; | |
12621 | for (; loc; loc = loc->next) | |
12622 | ++n; | |
12623 | printf_filtered (" (%d locations)", n); | |
12624 | } | |
12625 | } | |
12626 | } | |
12627 | ||
348d480f PA |
12628 | /* Default bp_location_ops methods. */ |
12629 | ||
12630 | static void | |
12631 | bp_location_dtor (struct bp_location *self) | |
12632 | { | |
348d480f PA |
12633 | xfree (self->function_name); |
12634 | } | |
12635 | ||
12636 | static const struct bp_location_ops bp_location_ops = | |
12637 | { | |
12638 | bp_location_dtor | |
12639 | }; | |
12640 | ||
c1fc2657 | 12641 | /* Destructor for the breakpoint base class. */ |
348d480f | 12642 | |
c1fc2657 | 12643 | breakpoint::~breakpoint () |
348d480f | 12644 | { |
c1fc2657 SM |
12645 | decref_counted_command_line (&this->commands); |
12646 | xfree (this->cond_string); | |
12647 | xfree (this->extra_string); | |
12648 | xfree (this->filter); | |
348d480f PA |
12649 | } |
12650 | ||
2060206e PA |
12651 | static struct bp_location * |
12652 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f | 12653 | { |
5625a286 | 12654 | return new bp_location (&bp_location_ops, self); |
348d480f PA |
12655 | } |
12656 | ||
2060206e PA |
12657 | static void |
12658 | base_breakpoint_re_set (struct breakpoint *b) | |
12659 | { | |
12660 | /* Nothing to re-set. */ | |
12661 | } | |
12662 | ||
12663 | #define internal_error_pure_virtual_called() \ | |
12664 | gdb_assert_not_reached ("pure virtual function called") | |
12665 | ||
12666 | static int | |
12667 | base_breakpoint_insert_location (struct bp_location *bl) | |
12668 | { | |
12669 | internal_error_pure_virtual_called (); | |
12670 | } | |
12671 | ||
12672 | static int | |
73971819 PA |
12673 | base_breakpoint_remove_location (struct bp_location *bl, |
12674 | enum remove_bp_reason reason) | |
2060206e PA |
12675 | { |
12676 | internal_error_pure_virtual_called (); | |
12677 | } | |
12678 | ||
12679 | static int | |
12680 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12681 | struct address_space *aspace, | |
09ac7c10 TT |
12682 | CORE_ADDR bp_addr, |
12683 | const struct target_waitstatus *ws) | |
2060206e PA |
12684 | { |
12685 | internal_error_pure_virtual_called (); | |
12686 | } | |
12687 | ||
12688 | static void | |
12689 | base_breakpoint_check_status (bpstat bs) | |
12690 | { | |
12691 | /* Always stop. */ | |
12692 | } | |
12693 | ||
12694 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12695 | errors. */ | |
12696 | ||
12697 | static int | |
12698 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12699 | { | |
12700 | internal_error_pure_virtual_called (); | |
12701 | } | |
12702 | ||
12703 | /* A "resources_needed" breakpoint_ops method that just internal | |
12704 | errors. */ | |
12705 | ||
12706 | static int | |
12707 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12708 | { | |
12709 | internal_error_pure_virtual_called (); | |
12710 | } | |
12711 | ||
12712 | static enum print_stop_action | |
12713 | base_breakpoint_print_it (bpstat bs) | |
12714 | { | |
12715 | internal_error_pure_virtual_called (); | |
12716 | } | |
12717 | ||
12718 | static void | |
12719 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12720 | struct ui_out *uiout) | |
12721 | { | |
12722 | /* nothing */ | |
12723 | } | |
12724 | ||
12725 | static void | |
12726 | base_breakpoint_print_mention (struct breakpoint *b) | |
12727 | { | |
12728 | internal_error_pure_virtual_called (); | |
12729 | } | |
12730 | ||
12731 | static void | |
12732 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12733 | { | |
12734 | internal_error_pure_virtual_called (); | |
12735 | } | |
12736 | ||
983af33b | 12737 | static void |
f00aae0f KS |
12738 | base_breakpoint_create_sals_from_location |
12739 | (const struct event_location *location, | |
12740 | struct linespec_result *canonical, | |
12741 | enum bptype type_wanted) | |
983af33b SDJ |
12742 | { |
12743 | internal_error_pure_virtual_called (); | |
12744 | } | |
12745 | ||
12746 | static void | |
12747 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12748 | struct linespec_result *c, | |
e1e01040 PA |
12749 | gdb::unique_xmalloc_ptr<char> cond_string, |
12750 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12751 | enum bptype type_wanted, |
12752 | enum bpdisp disposition, | |
12753 | int thread, | |
12754 | int task, int ignore_count, | |
12755 | const struct breakpoint_ops *o, | |
12756 | int from_tty, int enabled, | |
44f238bb | 12757 | int internal, unsigned flags) |
983af33b SDJ |
12758 | { |
12759 | internal_error_pure_virtual_called (); | |
12760 | } | |
12761 | ||
6c5b2ebe | 12762 | static std::vector<symtab_and_line> |
f00aae0f KS |
12763 | base_breakpoint_decode_location (struct breakpoint *b, |
12764 | const struct event_location *location, | |
6c5b2ebe | 12765 | struct program_space *search_pspace) |
983af33b SDJ |
12766 | { |
12767 | internal_error_pure_virtual_called (); | |
12768 | } | |
12769 | ||
ab04a2af TT |
12770 | /* The default 'explains_signal' method. */ |
12771 | ||
47591c29 | 12772 | static int |
427cd150 | 12773 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 12774 | { |
47591c29 | 12775 | return 1; |
ab04a2af TT |
12776 | } |
12777 | ||
9d6e6e84 HZ |
12778 | /* The default "after_condition_true" method. */ |
12779 | ||
12780 | static void | |
12781 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
12782 | { | |
12783 | /* Nothing to do. */ | |
12784 | } | |
12785 | ||
ab04a2af | 12786 | struct breakpoint_ops base_breakpoint_ops = |
2060206e | 12787 | { |
2060206e PA |
12788 | base_breakpoint_allocate_location, |
12789 | base_breakpoint_re_set, | |
12790 | base_breakpoint_insert_location, | |
12791 | base_breakpoint_remove_location, | |
12792 | base_breakpoint_breakpoint_hit, | |
12793 | base_breakpoint_check_status, | |
12794 | base_breakpoint_resources_needed, | |
12795 | base_breakpoint_works_in_software_mode, | |
12796 | base_breakpoint_print_it, | |
12797 | NULL, | |
12798 | base_breakpoint_print_one_detail, | |
12799 | base_breakpoint_print_mention, | |
983af33b | 12800 | base_breakpoint_print_recreate, |
5f700d83 | 12801 | base_breakpoint_create_sals_from_location, |
983af33b | 12802 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 12803 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
12804 | base_breakpoint_explains_signal, |
12805 | base_breakpoint_after_condition_true, | |
2060206e PA |
12806 | }; |
12807 | ||
12808 | /* Default breakpoint_ops methods. */ | |
12809 | ||
12810 | static void | |
348d480f PA |
12811 | bkpt_re_set (struct breakpoint *b) |
12812 | { | |
06edf0c0 | 12813 | /* FIXME: is this still reachable? */ |
9ef9e6a6 | 12814 | if (breakpoint_event_location_empty_p (b)) |
06edf0c0 | 12815 | { |
f00aae0f | 12816 | /* Anything without a location can't be re-set. */ |
348d480f | 12817 | delete_breakpoint (b); |
06edf0c0 | 12818 | return; |
348d480f | 12819 | } |
06edf0c0 PA |
12820 | |
12821 | breakpoint_re_set_default (b); | |
348d480f PA |
12822 | } |
12823 | ||
2060206e | 12824 | static int |
348d480f PA |
12825 | bkpt_insert_location (struct bp_location *bl) |
12826 | { | |
cd6c3b4f YQ |
12827 | CORE_ADDR addr = bl->target_info.reqstd_address; |
12828 | ||
579c6ad9 | 12829 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
cd6c3b4f YQ |
12830 | bl->target_info.placed_address = addr; |
12831 | ||
348d480f | 12832 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
7c16b83e | 12833 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 12834 | else |
7c16b83e | 12835 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
12836 | } |
12837 | ||
2060206e | 12838 | static int |
73971819 | 12839 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
348d480f PA |
12840 | { |
12841 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
12842 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
12843 | else | |
73971819 | 12844 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
348d480f PA |
12845 | } |
12846 | ||
2060206e | 12847 | static int |
348d480f | 12848 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
12849 | struct address_space *aspace, CORE_ADDR bp_addr, |
12850 | const struct target_waitstatus *ws) | |
348d480f | 12851 | { |
09ac7c10 | 12852 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 12853 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
12854 | return 0; |
12855 | ||
348d480f PA |
12856 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
12857 | aspace, bp_addr)) | |
12858 | return 0; | |
12859 | ||
12860 | if (overlay_debugging /* unmapped overlay section */ | |
12861 | && section_is_overlay (bl->section) | |
12862 | && !section_is_mapped (bl->section)) | |
12863 | return 0; | |
12864 | ||
12865 | return 1; | |
12866 | } | |
12867 | ||
cd1608cc PA |
12868 | static int |
12869 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
12870 | struct address_space *aspace, CORE_ADDR bp_addr, | |
12871 | const struct target_waitstatus *ws) | |
12872 | { | |
12873 | if (dprintf_style == dprintf_style_agent | |
12874 | && target_can_run_breakpoint_commands ()) | |
12875 | { | |
12876 | /* An agent-style dprintf never causes a stop. If we see a trap | |
12877 | for this address it must be for a breakpoint that happens to | |
12878 | be set at the same address. */ | |
12879 | return 0; | |
12880 | } | |
12881 | ||
12882 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
12883 | } | |
12884 | ||
2060206e | 12885 | static int |
348d480f PA |
12886 | bkpt_resources_needed (const struct bp_location *bl) |
12887 | { | |
12888 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
12889 | ||
12890 | return 1; | |
12891 | } | |
12892 | ||
2060206e | 12893 | static enum print_stop_action |
348d480f PA |
12894 | bkpt_print_it (bpstat bs) |
12895 | { | |
348d480f PA |
12896 | struct breakpoint *b; |
12897 | const struct bp_location *bl; | |
001c8c33 | 12898 | int bp_temp; |
79a45e25 | 12899 | struct ui_out *uiout = current_uiout; |
348d480f PA |
12900 | |
12901 | gdb_assert (bs->bp_location_at != NULL); | |
12902 | ||
12903 | bl = bs->bp_location_at; | |
12904 | b = bs->breakpoint_at; | |
12905 | ||
001c8c33 PA |
12906 | bp_temp = b->disposition == disp_del; |
12907 | if (bl->address != bl->requested_address) | |
12908 | breakpoint_adjustment_warning (bl->requested_address, | |
12909 | bl->address, | |
12910 | b->number, 1); | |
12911 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
12912 | maybe_print_thread_hit_breakpoint (uiout); |
12913 | ||
001c8c33 | 12914 | if (bp_temp) |
112e8700 | 12915 | uiout->text ("Temporary breakpoint "); |
001c8c33 | 12916 | else |
112e8700 SM |
12917 | uiout->text ("Breakpoint "); |
12918 | if (uiout->is_mi_like_p ()) | |
348d480f | 12919 | { |
112e8700 | 12920 | uiout->field_string ("reason", |
001c8c33 | 12921 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
112e8700 | 12922 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
06edf0c0 | 12923 | } |
112e8700 SM |
12924 | uiout->field_int ("bkptno", b->number); |
12925 | uiout->text (", "); | |
06edf0c0 | 12926 | |
001c8c33 | 12927 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
12928 | } |
12929 | ||
2060206e | 12930 | static void |
06edf0c0 PA |
12931 | bkpt_print_mention (struct breakpoint *b) |
12932 | { | |
112e8700 | 12933 | if (current_uiout->is_mi_like_p ()) |
06edf0c0 PA |
12934 | return; |
12935 | ||
12936 | switch (b->type) | |
12937 | { | |
12938 | case bp_breakpoint: | |
12939 | case bp_gnu_ifunc_resolver: | |
12940 | if (b->disposition == disp_del) | |
12941 | printf_filtered (_("Temporary breakpoint")); | |
12942 | else | |
12943 | printf_filtered (_("Breakpoint")); | |
12944 | printf_filtered (_(" %d"), b->number); | |
12945 | if (b->type == bp_gnu_ifunc_resolver) | |
12946 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
12947 | break; | |
12948 | case bp_hardware_breakpoint: | |
12949 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
12950 | break; | |
e7e0cddf SS |
12951 | case bp_dprintf: |
12952 | printf_filtered (_("Dprintf %d"), b->number); | |
12953 | break; | |
06edf0c0 PA |
12954 | } |
12955 | ||
12956 | say_where (b); | |
12957 | } | |
12958 | ||
2060206e | 12959 | static void |
06edf0c0 PA |
12960 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
12961 | { | |
12962 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12963 | fprintf_unfiltered (fp, "tbreak"); | |
12964 | else if (tp->type == bp_breakpoint) | |
12965 | fprintf_unfiltered (fp, "break"); | |
12966 | else if (tp->type == bp_hardware_breakpoint | |
12967 | && tp->disposition == disp_del) | |
12968 | fprintf_unfiltered (fp, "thbreak"); | |
12969 | else if (tp->type == bp_hardware_breakpoint) | |
12970 | fprintf_unfiltered (fp, "hbreak"); | |
12971 | else | |
12972 | internal_error (__FILE__, __LINE__, | |
12973 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12974 | ||
f00aae0f | 12975 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 12976 | event_location_to_string (tp->location.get ())); |
f00aae0f KS |
12977 | |
12978 | /* Print out extra_string if this breakpoint is pending. It might | |
12979 | contain, for example, conditions that were set by the user. */ | |
12980 | if (tp->loc == NULL && tp->extra_string != NULL) | |
12981 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
12982 | ||
dd11a36c | 12983 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
12984 | } |
12985 | ||
983af33b | 12986 | static void |
f00aae0f KS |
12987 | bkpt_create_sals_from_location (const struct event_location *location, |
12988 | struct linespec_result *canonical, | |
12989 | enum bptype type_wanted) | |
983af33b | 12990 | { |
f00aae0f | 12991 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
12992 | } |
12993 | ||
12994 | static void | |
12995 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
12996 | struct linespec_result *canonical, | |
e1e01040 PA |
12997 | gdb::unique_xmalloc_ptr<char> cond_string, |
12998 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
12999 | enum bptype type_wanted, |
13000 | enum bpdisp disposition, | |
13001 | int thread, | |
13002 | int task, int ignore_count, | |
13003 | const struct breakpoint_ops *ops, | |
13004 | int from_tty, int enabled, | |
44f238bb | 13005 | int internal, unsigned flags) |
983af33b | 13006 | { |
023fa29b | 13007 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13008 | std::move (cond_string), |
13009 | std::move (extra_string), | |
e7e0cddf | 13010 | type_wanted, |
983af33b SDJ |
13011 | disposition, thread, task, |
13012 | ignore_count, ops, from_tty, | |
44f238bb | 13013 | enabled, internal, flags); |
983af33b SDJ |
13014 | } |
13015 | ||
6c5b2ebe | 13016 | static std::vector<symtab_and_line> |
f00aae0f KS |
13017 | bkpt_decode_location (struct breakpoint *b, |
13018 | const struct event_location *location, | |
6c5b2ebe | 13019 | struct program_space *search_pspace) |
983af33b | 13020 | { |
6c5b2ebe | 13021 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13022 | } |
13023 | ||
06edf0c0 PA |
13024 | /* Virtual table for internal breakpoints. */ |
13025 | ||
13026 | static void | |
13027 | internal_bkpt_re_set (struct breakpoint *b) | |
13028 | { | |
13029 | switch (b->type) | |
13030 | { | |
13031 | /* Delete overlay event and longjmp master breakpoints; they | |
13032 | will be reset later by breakpoint_re_set. */ | |
13033 | case bp_overlay_event: | |
13034 | case bp_longjmp_master: | |
13035 | case bp_std_terminate_master: | |
13036 | case bp_exception_master: | |
13037 | delete_breakpoint (b); | |
13038 | break; | |
13039 | ||
13040 | /* This breakpoint is special, it's set up when the inferior | |
13041 | starts and we really don't want to touch it. */ | |
13042 | case bp_shlib_event: | |
13043 | ||
13044 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13045 | it is set up, we do not want to touch it. */ | |
13046 | case bp_thread_event: | |
13047 | break; | |
13048 | } | |
13049 | } | |
13050 | ||
13051 | static void | |
13052 | internal_bkpt_check_status (bpstat bs) | |
13053 | { | |
a9b3a50f PA |
13054 | if (bs->breakpoint_at->type == bp_shlib_event) |
13055 | { | |
13056 | /* If requested, stop when the dynamic linker notifies GDB of | |
13057 | events. This allows the user to get control and place | |
13058 | breakpoints in initializer routines for dynamically loaded | |
13059 | objects (among other things). */ | |
13060 | bs->stop = stop_on_solib_events; | |
13061 | bs->print = stop_on_solib_events; | |
13062 | } | |
13063 | else | |
13064 | bs->stop = 0; | |
06edf0c0 PA |
13065 | } |
13066 | ||
13067 | static enum print_stop_action | |
13068 | internal_bkpt_print_it (bpstat bs) | |
13069 | { | |
06edf0c0 | 13070 | struct breakpoint *b; |
06edf0c0 | 13071 | |
06edf0c0 PA |
13072 | b = bs->breakpoint_at; |
13073 | ||
06edf0c0 PA |
13074 | switch (b->type) |
13075 | { | |
348d480f PA |
13076 | case bp_shlib_event: |
13077 | /* Did we stop because the user set the stop_on_solib_events | |
13078 | variable? (If so, we report this as a generic, "Stopped due | |
13079 | to shlib event" message.) */ | |
edcc5120 | 13080 | print_solib_event (0); |
348d480f PA |
13081 | break; |
13082 | ||
13083 | case bp_thread_event: | |
13084 | /* Not sure how we will get here. | |
13085 | GDB should not stop for these breakpoints. */ | |
13086 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13087 | break; |
13088 | ||
13089 | case bp_overlay_event: | |
13090 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13091 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13092 | break; |
13093 | ||
13094 | case bp_longjmp_master: | |
13095 | /* These should never be enabled. */ | |
13096 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13097 | break; |
13098 | ||
13099 | case bp_std_terminate_master: | |
13100 | /* These should never be enabled. */ | |
13101 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13102 | "gdb should not stop!\n")); | |
348d480f PA |
13103 | break; |
13104 | ||
13105 | case bp_exception_master: | |
13106 | /* These should never be enabled. */ | |
13107 | printf_filtered (_("Exception Master Breakpoint: " | |
13108 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13109 | break; |
13110 | } | |
13111 | ||
001c8c33 | 13112 | return PRINT_NOTHING; |
06edf0c0 PA |
13113 | } |
13114 | ||
13115 | static void | |
13116 | internal_bkpt_print_mention (struct breakpoint *b) | |
13117 | { | |
13118 | /* Nothing to mention. These breakpoints are internal. */ | |
13119 | } | |
13120 | ||
06edf0c0 PA |
13121 | /* Virtual table for momentary breakpoints */ |
13122 | ||
13123 | static void | |
13124 | momentary_bkpt_re_set (struct breakpoint *b) | |
13125 | { | |
13126 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13127 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13128 | Otherwise these should have been blown away via the cleanup chain |
13129 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13130 | } | |
13131 | ||
13132 | static void | |
13133 | momentary_bkpt_check_status (bpstat bs) | |
13134 | { | |
13135 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13136 | } | |
13137 | ||
13138 | static enum print_stop_action | |
13139 | momentary_bkpt_print_it (bpstat bs) | |
13140 | { | |
001c8c33 | 13141 | return PRINT_UNKNOWN; |
348d480f PA |
13142 | } |
13143 | ||
06edf0c0 PA |
13144 | static void |
13145 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13146 | { |
06edf0c0 | 13147 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13148 | } |
13149 | ||
e2e4d78b JK |
13150 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13151 | ||
13152 | It gets cleared already on the removal of the first one of such placed | |
13153 | breakpoints. This is OK as they get all removed altogether. */ | |
13154 | ||
c1fc2657 | 13155 | longjmp_breakpoint::~longjmp_breakpoint () |
e2e4d78b | 13156 | { |
c1fc2657 | 13157 | thread_info *tp = find_thread_global_id (this->thread); |
e2e4d78b | 13158 | |
c1fc2657 | 13159 | if (tp != NULL) |
e2e4d78b | 13160 | tp->initiating_frame = null_frame_id; |
e2e4d78b JK |
13161 | } |
13162 | ||
55aa24fb SDJ |
13163 | /* Specific methods for probe breakpoints. */ |
13164 | ||
13165 | static int | |
13166 | bkpt_probe_insert_location (struct bp_location *bl) | |
13167 | { | |
13168 | int v = bkpt_insert_location (bl); | |
13169 | ||
13170 | if (v == 0) | |
13171 | { | |
13172 | /* The insertion was successful, now let's set the probe's semaphore | |
13173 | if needed. */ | |
0ea5cda8 SDJ |
13174 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13175 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13176 | bl->probe.objfile, | |
13177 | bl->gdbarch); | |
55aa24fb SDJ |
13178 | } |
13179 | ||
13180 | return v; | |
13181 | } | |
13182 | ||
13183 | static int | |
73971819 PA |
13184 | bkpt_probe_remove_location (struct bp_location *bl, |
13185 | enum remove_bp_reason reason) | |
55aa24fb SDJ |
13186 | { |
13187 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13188 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13189 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13190 | bl->probe.objfile, | |
13191 | bl->gdbarch); | |
55aa24fb | 13192 | |
73971819 | 13193 | return bkpt_remove_location (bl, reason); |
55aa24fb SDJ |
13194 | } |
13195 | ||
13196 | static void | |
f00aae0f | 13197 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13198 | struct linespec_result *canonical, |
f00aae0f | 13199 | enum bptype type_wanted) |
55aa24fb SDJ |
13200 | { |
13201 | struct linespec_sals lsal; | |
13202 | ||
c2f4122d | 13203 | lsal.sals = parse_probes (location, NULL, canonical); |
8e9e35b1 TT |
13204 | lsal.canonical |
13205 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13206 | canonical->lsals.push_back (std::move (lsal)); |
55aa24fb SDJ |
13207 | } |
13208 | ||
6c5b2ebe | 13209 | static std::vector<symtab_and_line> |
f00aae0f KS |
13210 | bkpt_probe_decode_location (struct breakpoint *b, |
13211 | const struct event_location *location, | |
6c5b2ebe | 13212 | struct program_space *search_pspace) |
55aa24fb | 13213 | { |
6c5b2ebe PA |
13214 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
13215 | if (sals.empty ()) | |
55aa24fb | 13216 | error (_("probe not found")); |
6c5b2ebe | 13217 | return sals; |
55aa24fb SDJ |
13218 | } |
13219 | ||
348d480f | 13220 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13221 | |
348d480f PA |
13222 | static void |
13223 | tracepoint_re_set (struct breakpoint *b) | |
13224 | { | |
13225 | breakpoint_re_set_default (b); | |
13226 | } | |
876fa593 | 13227 | |
348d480f PA |
13228 | static int |
13229 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13230 | struct address_space *aspace, CORE_ADDR bp_addr, |
13231 | const struct target_waitstatus *ws) | |
348d480f PA |
13232 | { |
13233 | /* By definition, the inferior does not report stops at | |
13234 | tracepoints. */ | |
13235 | return 0; | |
74960c60 VP |
13236 | } |
13237 | ||
13238 | static void | |
348d480f PA |
13239 | tracepoint_print_one_detail (const struct breakpoint *self, |
13240 | struct ui_out *uiout) | |
74960c60 | 13241 | { |
d9b3f62e PA |
13242 | struct tracepoint *tp = (struct tracepoint *) self; |
13243 | if (tp->static_trace_marker_id) | |
348d480f PA |
13244 | { |
13245 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13246 | |
112e8700 SM |
13247 | uiout->text ("\tmarker id is "); |
13248 | uiout->field_string ("static-tracepoint-marker-string-id", | |
d9b3f62e | 13249 | tp->static_trace_marker_id); |
112e8700 | 13250 | uiout->text ("\n"); |
348d480f | 13251 | } |
0d381245 VP |
13252 | } |
13253 | ||
a474d7c2 | 13254 | static void |
348d480f | 13255 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13256 | { |
112e8700 | 13257 | if (current_uiout->is_mi_like_p ()) |
348d480f | 13258 | return; |
cc59ec59 | 13259 | |
348d480f PA |
13260 | switch (b->type) |
13261 | { | |
13262 | case bp_tracepoint: | |
13263 | printf_filtered (_("Tracepoint")); | |
13264 | printf_filtered (_(" %d"), b->number); | |
13265 | break; | |
13266 | case bp_fast_tracepoint: | |
13267 | printf_filtered (_("Fast tracepoint")); | |
13268 | printf_filtered (_(" %d"), b->number); | |
13269 | break; | |
13270 | case bp_static_tracepoint: | |
13271 | printf_filtered (_("Static tracepoint")); | |
13272 | printf_filtered (_(" %d"), b->number); | |
13273 | break; | |
13274 | default: | |
13275 | internal_error (__FILE__, __LINE__, | |
13276 | _("unhandled tracepoint type %d"), (int) b->type); | |
13277 | } | |
13278 | ||
13279 | say_where (b); | |
a474d7c2 PA |
13280 | } |
13281 | ||
348d480f | 13282 | static void |
d9b3f62e | 13283 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13284 | { |
d9b3f62e PA |
13285 | struct tracepoint *tp = (struct tracepoint *) self; |
13286 | ||
13287 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13288 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13289 | else if (self->type == bp_static_tracepoint) |
348d480f | 13290 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13291 | else if (self->type == bp_tracepoint) |
348d480f PA |
13292 | fprintf_unfiltered (fp, "trace"); |
13293 | else | |
13294 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13295 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13296 | |
f00aae0f | 13297 | fprintf_unfiltered (fp, " %s", |
d28cd78a | 13298 | event_location_to_string (self->location.get ())); |
d9b3f62e PA |
13299 | print_recreate_thread (self, fp); |
13300 | ||
13301 | if (tp->pass_count) | |
13302 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13303 | } |
13304 | ||
983af33b | 13305 | static void |
f00aae0f KS |
13306 | tracepoint_create_sals_from_location (const struct event_location *location, |
13307 | struct linespec_result *canonical, | |
13308 | enum bptype type_wanted) | |
983af33b | 13309 | { |
f00aae0f | 13310 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13311 | } |
13312 | ||
13313 | static void | |
13314 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13315 | struct linespec_result *canonical, | |
e1e01040 PA |
13316 | gdb::unique_xmalloc_ptr<char> cond_string, |
13317 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13318 | enum bptype type_wanted, |
13319 | enum bpdisp disposition, | |
13320 | int thread, | |
13321 | int task, int ignore_count, | |
13322 | const struct breakpoint_ops *ops, | |
13323 | int from_tty, int enabled, | |
44f238bb | 13324 | int internal, unsigned flags) |
983af33b | 13325 | { |
023fa29b | 13326 | create_breakpoints_sal_default (gdbarch, canonical, |
e1e01040 PA |
13327 | std::move (cond_string), |
13328 | std::move (extra_string), | |
e7e0cddf | 13329 | type_wanted, |
983af33b SDJ |
13330 | disposition, thread, task, |
13331 | ignore_count, ops, from_tty, | |
44f238bb | 13332 | enabled, internal, flags); |
983af33b SDJ |
13333 | } |
13334 | ||
6c5b2ebe | 13335 | static std::vector<symtab_and_line> |
f00aae0f KS |
13336 | tracepoint_decode_location (struct breakpoint *b, |
13337 | const struct event_location *location, | |
6c5b2ebe | 13338 | struct program_space *search_pspace) |
983af33b | 13339 | { |
6c5b2ebe | 13340 | return decode_location_default (b, location, search_pspace); |
983af33b SDJ |
13341 | } |
13342 | ||
2060206e | 13343 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13344 | |
55aa24fb SDJ |
13345 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13346 | static probe. */ | |
13347 | ||
13348 | static void | |
f00aae0f KS |
13349 | tracepoint_probe_create_sals_from_location |
13350 | (const struct event_location *location, | |
13351 | struct linespec_result *canonical, | |
13352 | enum bptype type_wanted) | |
55aa24fb SDJ |
13353 | { |
13354 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13355 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13356 | } |
13357 | ||
6c5b2ebe | 13358 | static std::vector<symtab_and_line> |
f00aae0f KS |
13359 | tracepoint_probe_decode_location (struct breakpoint *b, |
13360 | const struct event_location *location, | |
6c5b2ebe | 13361 | struct program_space *search_pspace) |
55aa24fb SDJ |
13362 | { |
13363 | /* We use the same method for breakpoint on probes. */ | |
6c5b2ebe | 13364 | return bkpt_probe_decode_location (b, location, search_pspace); |
55aa24fb SDJ |
13365 | } |
13366 | ||
13367 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13368 | ||
5c2b4418 HZ |
13369 | /* Dprintf breakpoint_ops methods. */ |
13370 | ||
13371 | static void | |
13372 | dprintf_re_set (struct breakpoint *b) | |
13373 | { | |
13374 | breakpoint_re_set_default (b); | |
13375 | ||
f00aae0f KS |
13376 | /* extra_string should never be non-NULL for dprintf. */ |
13377 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13378 | |
13379 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13380 | 2 - create a dprintf, which resolves fine. | |
13381 | 3 - disconnect from target 1 | |
13382 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13383 | ||
13384 | After steps #3/#4, you'll want the dprintf command list to | |
13385 | be updated, because target 1 and 2 may well return different | |
13386 | answers for target_can_run_breakpoint_commands(). | |
13387 | Given absence of finer grained resetting, we get to do | |
13388 | it all the time. */ | |
13389 | if (b->extra_string != NULL) | |
13390 | update_dprintf_command_list (b); | |
13391 | } | |
13392 | ||
2d9442cc HZ |
13393 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13394 | ||
13395 | static void | |
13396 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13397 | { | |
f00aae0f | 13398 | fprintf_unfiltered (fp, "dprintf %s,%s", |
d28cd78a | 13399 | event_location_to_string (tp->location.get ()), |
2d9442cc HZ |
13400 | tp->extra_string); |
13401 | print_recreate_thread (tp, fp); | |
13402 | } | |
13403 | ||
9d6e6e84 HZ |
13404 | /* Implement the "after_condition_true" breakpoint_ops method for |
13405 | dprintf. | |
13406 | ||
13407 | dprintf's are implemented with regular commands in their command | |
13408 | list, but we run the commands here instead of before presenting the | |
13409 | stop to the user, as dprintf's don't actually cause a stop. This | |
13410 | also makes it so that the commands of multiple dprintfs at the same | |
13411 | address are all handled. */ | |
13412 | ||
13413 | static void | |
13414 | dprintf_after_condition_true (struct bpstats *bs) | |
13415 | { | |
13416 | struct cleanup *old_chain; | |
13417 | struct bpstats tmp_bs = { NULL }; | |
13418 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13419 | ||
13420 | /* dprintf's never cause a stop. This wasn't set in the | |
13421 | check_status hook instead because that would make the dprintf's | |
13422 | condition not be evaluated. */ | |
13423 | bs->stop = 0; | |
13424 | ||
13425 | /* Run the command list here. Take ownership of it instead of | |
13426 | copying. We never want these commands to run later in | |
13427 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13428 | be set at same address as this dprintf, or even if running the | |
13429 | commands here throws. */ | |
13430 | tmp_bs.commands = bs->commands; | |
13431 | bs->commands = NULL; | |
13432 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13433 | ||
13434 | bpstat_do_actions_1 (&tmp_bs_p); | |
13435 | ||
13436 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13437 | bpstat_do_actions_1 may return early without processing the whole | |
13438 | list. */ | |
13439 | do_cleanups (old_chain); | |
13440 | } | |
13441 | ||
983af33b SDJ |
13442 | /* The breakpoint_ops structure to be used on static tracepoints with |
13443 | markers (`-m'). */ | |
13444 | ||
13445 | static void | |
f00aae0f | 13446 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13447 | struct linespec_result *canonical, |
f00aae0f | 13448 | enum bptype type_wanted) |
983af33b SDJ |
13449 | { |
13450 | struct linespec_sals lsal; | |
f00aae0f KS |
13451 | const char *arg_start, *arg; |
13452 | char *str; | |
13453 | struct cleanup *cleanup; | |
983af33b | 13454 | |
f00aae0f KS |
13455 | arg = arg_start = get_linespec_location (location); |
13456 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13457 | |
f00aae0f KS |
13458 | str = savestring (arg_start, arg - arg_start); |
13459 | cleanup = make_cleanup (xfree, str); | |
8e9e35b1 | 13460 | canonical->location = new_linespec_location (&str); |
f00aae0f | 13461 | do_cleanups (cleanup); |
983af33b | 13462 | |
8e9e35b1 TT |
13463 | lsal.canonical |
13464 | = xstrdup (event_location_to_string (canonical->location.get ())); | |
6c5b2ebe | 13465 | canonical->lsals.push_back (std::move (lsal)); |
983af33b SDJ |
13466 | } |
13467 | ||
13468 | static void | |
13469 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13470 | struct linespec_result *canonical, | |
e1e01040 PA |
13471 | gdb::unique_xmalloc_ptr<char> cond_string, |
13472 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
13473 | enum bptype type_wanted, |
13474 | enum bpdisp disposition, | |
13475 | int thread, | |
13476 | int task, int ignore_count, | |
13477 | const struct breakpoint_ops *ops, | |
13478 | int from_tty, int enabled, | |
44f238bb | 13479 | int internal, unsigned flags) |
983af33b | 13480 | { |
6c5b2ebe | 13481 | const linespec_sals &lsal = canonical->lsals[0]; |
983af33b SDJ |
13482 | |
13483 | /* If the user is creating a static tracepoint by marker id | |
13484 | (strace -m MARKER_ID), then store the sals index, so that | |
13485 | breakpoint_re_set can try to match up which of the newly | |
13486 | found markers corresponds to this one, and, don't try to | |
13487 | expand multiple locations for each sal, given than SALS | |
13488 | already should contain all sals for MARKER_ID. */ | |
13489 | ||
6c5b2ebe | 13490 | for (size_t i = 0; i < lsal.sals.size (); i++) |
983af33b | 13491 | { |
6c5b2ebe PA |
13492 | event_location_up location |
13493 | = copy_event_location (canonical->location.get ()); | |
983af33b | 13494 | |
b270e6f9 | 13495 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
6c5b2ebe | 13496 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
ffc2605c | 13497 | std::move (location), NULL, |
e1e01040 PA |
13498 | std::move (cond_string), |
13499 | std::move (extra_string), | |
e7e0cddf | 13500 | type_wanted, disposition, |
983af33b | 13501 | thread, task, ignore_count, ops, |
44f238bb | 13502 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13503 | canonical->special_display); |
13504 | /* Given that its possible to have multiple markers with | |
13505 | the same string id, if the user is creating a static | |
13506 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13507 | store the sals index, so that breakpoint_re_set can | |
13508 | try to match up which of the newly found markers | |
13509 | corresponds to this one */ | |
13510 | tp->static_trace_marker_id_idx = i; | |
13511 | ||
b270e6f9 | 13512 | install_breakpoint (internal, std::move (tp), 0); |
983af33b SDJ |
13513 | } |
13514 | } | |
13515 | ||
6c5b2ebe | 13516 | static std::vector<symtab_and_line> |
f00aae0f KS |
13517 | strace_marker_decode_location (struct breakpoint *b, |
13518 | const struct event_location *location, | |
6c5b2ebe | 13519 | struct program_space *search_pspace) |
983af33b SDJ |
13520 | { |
13521 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13522 | const char *s = get_linespec_location (location); |
983af33b | 13523 | |
6c5b2ebe PA |
13524 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
13525 | if (sals.size () > tp->static_trace_marker_id_idx) | |
983af33b | 13526 | { |
6c5b2ebe PA |
13527 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
13528 | sals.resize (1); | |
13529 | return sals; | |
983af33b SDJ |
13530 | } |
13531 | else | |
13532 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13533 | } | |
13534 | ||
13535 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13536 | ||
13537 | static int | |
13538 | strace_marker_p (struct breakpoint *b) | |
13539 | { | |
13540 | return b->ops == &strace_marker_breakpoint_ops; | |
13541 | } | |
13542 | ||
53a5351d | 13543 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13544 | structures. */ |
c906108c SS |
13545 | |
13546 | void | |
fba45db2 | 13547 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13548 | { |
52f0bd74 | 13549 | struct breakpoint *b; |
c906108c | 13550 | |
8a3fe4f8 | 13551 | gdb_assert (bpt != NULL); |
c906108c | 13552 | |
4a64f543 MS |
13553 | /* Has this bp already been deleted? This can happen because |
13554 | multiple lists can hold pointers to bp's. bpstat lists are | |
13555 | especial culprits. | |
13556 | ||
13557 | One example of this happening is a watchpoint's scope bp. When | |
13558 | the scope bp triggers, we notice that the watchpoint is out of | |
13559 | scope, and delete it. We also delete its scope bp. But the | |
13560 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13561 | That bpstat is then checked for auto-deleting bp's, which are | |
13562 | deleted. | |
13563 | ||
13564 | A real solution to this problem might involve reference counts in | |
13565 | bp's, and/or giving them pointers back to their referencing | |
13566 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13567 | storage when no more references were extent. A cheaper bandaid | |
13568 | was chosen. */ | |
c906108c SS |
13569 | if (bpt->type == bp_none) |
13570 | return; | |
13571 | ||
4a64f543 MS |
13572 | /* At least avoid this stale reference until the reference counting |
13573 | of breakpoints gets resolved. */ | |
d0fb5eae | 13574 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13575 | { |
d0fb5eae | 13576 | struct breakpoint *related; |
3a5c3e22 | 13577 | struct watchpoint *w; |
d0fb5eae JK |
13578 | |
13579 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13580 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13581 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13582 | w = (struct watchpoint *) bpt; |
13583 | else | |
13584 | w = NULL; | |
13585 | if (w != NULL) | |
13586 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13587 | |
13588 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13589 | for (related = bpt; related->related_breakpoint != bpt; | |
13590 | related = related->related_breakpoint); | |
13591 | related->related_breakpoint = bpt->related_breakpoint; | |
13592 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13593 | } |
13594 | ||
a9634178 TJB |
13595 | /* watch_command_1 creates a watchpoint but only sets its number if |
13596 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13597 | a problem in that process, we'll be asked to delete the half-created | |
13598 | watchpoint. In that case, don't announce the deletion. */ | |
13599 | if (bpt->number) | |
13600 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13601 | |
c906108c SS |
13602 | if (breakpoint_chain == bpt) |
13603 | breakpoint_chain = bpt->next; | |
13604 | ||
c906108c SS |
13605 | ALL_BREAKPOINTS (b) |
13606 | if (b->next == bpt) | |
c5aa993b JM |
13607 | { |
13608 | b->next = bpt->next; | |
13609 | break; | |
13610 | } | |
c906108c | 13611 | |
f431efe5 PA |
13612 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13613 | been freed. */ | |
13614 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13615 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13616 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13617 | commands are associated with the bpstat; if we remove it here, | |
13618 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13619 | event-top.c won't do anything, and temporary breakpoints with | |
13620 | commands won't work. */ | |
13621 | ||
13622 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13623 | ||
4a64f543 MS |
13624 | /* Now that breakpoint is removed from breakpoint list, update the |
13625 | global location list. This will remove locations that used to | |
13626 | belong to this breakpoint. Do this before freeing the breakpoint | |
13627 | itself, since remove_breakpoint looks at location's owner. It | |
13628 | might be better design to have location completely | |
13629 | self-contained, but it's not the case now. */ | |
44702360 | 13630 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13631 | |
4a64f543 MS |
13632 | /* On the chance that someone will soon try again to delete this |
13633 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13634 | bpt->type = bp_none; |
4d01a485 | 13635 | delete bpt; |
c906108c SS |
13636 | } |
13637 | ||
4d6140d9 AC |
13638 | static void |
13639 | do_delete_breakpoint_cleanup (void *b) | |
13640 | { | |
9a3c8263 | 13641 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13642 | } |
13643 | ||
13644 | struct cleanup * | |
13645 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13646 | { | |
13647 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13648 | } | |
13649 | ||
51be5b68 PA |
13650 | /* Iterator function to call a user-provided callback function once |
13651 | for each of B and its related breakpoints. */ | |
13652 | ||
13653 | static void | |
13654 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13655 | void (*function) (struct breakpoint *, | |
13656 | void *), | |
13657 | void *data) | |
13658 | { | |
13659 | struct breakpoint *related; | |
13660 | ||
13661 | related = b; | |
13662 | do | |
13663 | { | |
13664 | struct breakpoint *next; | |
13665 | ||
13666 | /* FUNCTION may delete RELATED. */ | |
13667 | next = related->related_breakpoint; | |
13668 | ||
13669 | if (next == related) | |
13670 | { | |
13671 | /* RELATED is the last ring entry. */ | |
13672 | function (related, data); | |
13673 | ||
13674 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13675 | B. There's nothing left to do anyway, so just break | |
13676 | out. */ | |
13677 | break; | |
13678 | } | |
13679 | else | |
13680 | function (related, data); | |
13681 | ||
13682 | related = next; | |
13683 | } | |
13684 | while (related != b); | |
13685 | } | |
95a42b64 TT |
13686 | |
13687 | static void | |
13688 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13689 | { | |
13690 | delete_breakpoint (b); | |
13691 | } | |
13692 | ||
51be5b68 PA |
13693 | /* A callback for map_breakpoint_numbers that calls |
13694 | delete_breakpoint. */ | |
13695 | ||
13696 | static void | |
13697 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13698 | { | |
13699 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13700 | } | |
13701 | ||
c906108c | 13702 | void |
fba45db2 | 13703 | delete_command (char *arg, int from_tty) |
c906108c | 13704 | { |
35df4500 | 13705 | struct breakpoint *b, *b_tmp; |
c906108c | 13706 | |
ea9365bb TT |
13707 | dont_repeat (); |
13708 | ||
c906108c SS |
13709 | if (arg == 0) |
13710 | { | |
13711 | int breaks_to_delete = 0; | |
13712 | ||
46c6471b PA |
13713 | /* Delete all breakpoints if no argument. Do not delete |
13714 | internal breakpoints, these have to be deleted with an | |
13715 | explicit breakpoint number argument. */ | |
c5aa993b | 13716 | ALL_BREAKPOINTS (b) |
46c6471b | 13717 | if (user_breakpoint_p (b)) |
973d738b DJ |
13718 | { |
13719 | breaks_to_delete = 1; | |
13720 | break; | |
13721 | } | |
c906108c SS |
13722 | |
13723 | /* Ask user only if there are some breakpoints to delete. */ | |
13724 | if (!from_tty | |
e2e0b3e5 | 13725 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13726 | { |
35df4500 | 13727 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13728 | if (user_breakpoint_p (b)) |
c5aa993b | 13729 | delete_breakpoint (b); |
c906108c SS |
13730 | } |
13731 | } | |
13732 | else | |
51be5b68 | 13733 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
13734 | } |
13735 | ||
c2f4122d PA |
13736 | /* Return true if all locations of B bound to PSPACE are pending. If |
13737 | PSPACE is NULL, all locations of all program spaces are | |
13738 | considered. */ | |
13739 | ||
0d381245 | 13740 | static int |
c2f4122d | 13741 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 13742 | { |
c2f4122d PA |
13743 | struct bp_location *loc; |
13744 | ||
13745 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
13746 | if ((pspace == NULL | |
13747 | || loc->pspace == pspace) | |
13748 | && !loc->shlib_disabled | |
8645ff69 | 13749 | && !loc->pspace->executing_startup) |
0d381245 VP |
13750 | return 0; |
13751 | return 1; | |
fe3f5fa8 VP |
13752 | } |
13753 | ||
776592bf DE |
13754 | /* Subroutine of update_breakpoint_locations to simplify it. |
13755 | Return non-zero if multiple fns in list LOC have the same name. | |
13756 | Null names are ignored. */ | |
13757 | ||
13758 | static int | |
13759 | ambiguous_names_p (struct bp_location *loc) | |
13760 | { | |
13761 | struct bp_location *l; | |
13762 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
13763 | (int (*) (const void *, |
13764 | const void *)) streq, | |
776592bf DE |
13765 | NULL, xcalloc, xfree); |
13766 | ||
13767 | for (l = loc; l != NULL; l = l->next) | |
13768 | { | |
13769 | const char **slot; | |
13770 | const char *name = l->function_name; | |
13771 | ||
13772 | /* Allow for some names to be NULL, ignore them. */ | |
13773 | if (name == NULL) | |
13774 | continue; | |
13775 | ||
13776 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
13777 | INSERT); | |
4a64f543 MS |
13778 | /* NOTE: We can assume slot != NULL here because xcalloc never |
13779 | returns NULL. */ | |
776592bf DE |
13780 | if (*slot != NULL) |
13781 | { | |
13782 | htab_delete (htab); | |
13783 | return 1; | |
13784 | } | |
13785 | *slot = name; | |
13786 | } | |
13787 | ||
13788 | htab_delete (htab); | |
13789 | return 0; | |
13790 | } | |
13791 | ||
0fb4aa4b PA |
13792 | /* When symbols change, it probably means the sources changed as well, |
13793 | and it might mean the static tracepoint markers are no longer at | |
13794 | the same address or line numbers they used to be at last we | |
13795 | checked. Losing your static tracepoints whenever you rebuild is | |
13796 | undesirable. This function tries to resync/rematch gdb static | |
13797 | tracepoints with the markers on the target, for static tracepoints | |
13798 | that have not been set by marker id. Static tracepoint that have | |
13799 | been set by marker id are reset by marker id in breakpoint_re_set. | |
13800 | The heuristic is: | |
13801 | ||
13802 | 1) For a tracepoint set at a specific address, look for a marker at | |
13803 | the old PC. If one is found there, assume to be the same marker. | |
13804 | If the name / string id of the marker found is different from the | |
13805 | previous known name, assume that means the user renamed the marker | |
13806 | in the sources, and output a warning. | |
13807 | ||
13808 | 2) For a tracepoint set at a given line number, look for a marker | |
13809 | at the new address of the old line number. If one is found there, | |
13810 | assume to be the same marker. If the name / string id of the | |
13811 | marker found is different from the previous known name, assume that | |
13812 | means the user renamed the marker in the sources, and output a | |
13813 | warning. | |
13814 | ||
13815 | 3) If a marker is no longer found at the same address or line, it | |
13816 | may mean the marker no longer exists. But it may also just mean | |
13817 | the code changed a bit. Maybe the user added a few lines of code | |
13818 | that made the marker move up or down (in line number terms). Ask | |
13819 | the target for info about the marker with the string id as we knew | |
13820 | it. If found, update line number and address in the matching | |
13821 | static tracepoint. This will get confused if there's more than one | |
13822 | marker with the same ID (possible in UST, although unadvised | |
13823 | precisely because it confuses tools). */ | |
13824 | ||
13825 | static struct symtab_and_line | |
13826 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
13827 | { | |
d9b3f62e | 13828 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
13829 | struct static_tracepoint_marker marker; |
13830 | CORE_ADDR pc; | |
0fb4aa4b PA |
13831 | |
13832 | pc = sal.pc; | |
13833 | if (sal.line) | |
13834 | find_line_pc (sal.symtab, sal.line, &pc); | |
13835 | ||
13836 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
13837 | { | |
d9b3f62e | 13838 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
13839 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
13840 | b->number, | |
d9b3f62e | 13841 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 13842 | |
d9b3f62e PA |
13843 | xfree (tp->static_trace_marker_id); |
13844 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
13845 | release_static_tracepoint_marker (&marker); |
13846 | ||
13847 | return sal; | |
13848 | } | |
13849 | ||
13850 | /* Old marker wasn't found on target at lineno. Try looking it up | |
13851 | by string ID. */ | |
13852 | if (!sal.explicit_pc | |
13853 | && sal.line != 0 | |
13854 | && sal.symtab != NULL | |
d9b3f62e | 13855 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
13856 | { |
13857 | VEC(static_tracepoint_marker_p) *markers; | |
13858 | ||
13859 | markers | |
d9b3f62e | 13860 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
13861 | |
13862 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
13863 | { | |
0fb4aa4b | 13864 | struct symbol *sym; |
80e1d417 | 13865 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 13866 | struct ui_out *uiout = current_uiout; |
67994074 | 13867 | struct explicit_location explicit_loc; |
0fb4aa4b | 13868 | |
80e1d417 | 13869 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 13870 | |
d9b3f62e | 13871 | xfree (tp->static_trace_marker_id); |
80e1d417 | 13872 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
13873 | |
13874 | warning (_("marker for static tracepoint %d (%s) not " | |
13875 | "found at previous line number"), | |
d9b3f62e | 13876 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 13877 | |
51abb421 | 13878 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
80e1d417 | 13879 | sym = find_pc_sect_function (tpmarker->address, NULL); |
112e8700 | 13880 | uiout->text ("Now in "); |
0fb4aa4b PA |
13881 | if (sym) |
13882 | { | |
112e8700 SM |
13883 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym)); |
13884 | uiout->text (" at "); | |
0fb4aa4b | 13885 | } |
112e8700 | 13886 | uiout->field_string ("file", |
05cba821 | 13887 | symtab_to_filename_for_display (sal2.symtab)); |
112e8700 | 13888 | uiout->text (":"); |
0fb4aa4b | 13889 | |
112e8700 | 13890 | if (uiout->is_mi_like_p ()) |
0fb4aa4b | 13891 | { |
0b0865da | 13892 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 13893 | |
112e8700 | 13894 | uiout->field_string ("fullname", fullname); |
0fb4aa4b PA |
13895 | } |
13896 | ||
112e8700 SM |
13897 | uiout->field_int ("line", sal2.line); |
13898 | uiout->text ("\n"); | |
0fb4aa4b | 13899 | |
80e1d417 | 13900 | b->loc->line_number = sal2.line; |
2f202fde | 13901 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 13902 | |
d28cd78a | 13903 | b->location.reset (NULL); |
67994074 KS |
13904 | initialize_explicit_location (&explicit_loc); |
13905 | explicit_loc.source_filename | |
00e52e53 | 13906 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
13907 | explicit_loc.line_offset.offset = b->loc->line_number; |
13908 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
d28cd78a | 13909 | b->location = new_explicit_location (&explicit_loc); |
0fb4aa4b PA |
13910 | |
13911 | /* Might be nice to check if function changed, and warn if | |
13912 | so. */ | |
13913 | ||
80e1d417 | 13914 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
13915 | } |
13916 | } | |
13917 | return sal; | |
13918 | } | |
13919 | ||
8d3788bd VP |
13920 | /* Returns 1 iff locations A and B are sufficiently same that |
13921 | we don't need to report breakpoint as changed. */ | |
13922 | ||
13923 | static int | |
13924 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
13925 | { | |
13926 | while (a && b) | |
13927 | { | |
13928 | if (a->address != b->address) | |
13929 | return 0; | |
13930 | ||
13931 | if (a->shlib_disabled != b->shlib_disabled) | |
13932 | return 0; | |
13933 | ||
13934 | if (a->enabled != b->enabled) | |
13935 | return 0; | |
13936 | ||
13937 | a = a->next; | |
13938 | b = b->next; | |
13939 | } | |
13940 | ||
13941 | if ((a == NULL) != (b == NULL)) | |
13942 | return 0; | |
13943 | ||
13944 | return 1; | |
13945 | } | |
13946 | ||
c2f4122d PA |
13947 | /* Split all locations of B that are bound to PSPACE out of B's |
13948 | location list to a separate list and return that list's head. If | |
13949 | PSPACE is NULL, hoist out all locations of B. */ | |
13950 | ||
13951 | static struct bp_location * | |
13952 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
13953 | { | |
13954 | struct bp_location head; | |
13955 | struct bp_location *i = b->loc; | |
13956 | struct bp_location **i_link = &b->loc; | |
13957 | struct bp_location *hoisted = &head; | |
13958 | ||
13959 | if (pspace == NULL) | |
13960 | { | |
13961 | i = b->loc; | |
13962 | b->loc = NULL; | |
13963 | return i; | |
13964 | } | |
13965 | ||
13966 | head.next = NULL; | |
13967 | ||
13968 | while (i != NULL) | |
13969 | { | |
13970 | if (i->pspace == pspace) | |
13971 | { | |
13972 | *i_link = i->next; | |
13973 | i->next = NULL; | |
13974 | hoisted->next = i; | |
13975 | hoisted = i; | |
13976 | } | |
13977 | else | |
13978 | i_link = &i->next; | |
13979 | i = *i_link; | |
13980 | } | |
13981 | ||
13982 | return head.next; | |
13983 | } | |
13984 | ||
13985 | /* Create new breakpoint locations for B (a hardware or software | |
13986 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
13987 | zero, then B is a ranged breakpoint. Only recreates locations for | |
13988 | FILTER_PSPACE. Locations of other program spaces are left | |
13989 | untouched. */ | |
f1310107 | 13990 | |
0e30163f | 13991 | void |
0d381245 | 13992 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 13993 | struct program_space *filter_pspace, |
6c5b2ebe PA |
13994 | gdb::array_view<const symtab_and_line> sals, |
13995 | gdb::array_view<const symtab_and_line> sals_end) | |
fe3f5fa8 VP |
13996 | { |
13997 | int i; | |
c2f4122d | 13998 | struct bp_location *existing_locations; |
0d381245 | 13999 | |
6c5b2ebe | 14000 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
f8eba3c6 TT |
14001 | { |
14002 | /* Ranged breakpoints have only one start location and one end | |
14003 | location. */ | |
14004 | b->enable_state = bp_disabled; | |
f8eba3c6 TT |
14005 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14006 | "multiple locations found\n"), | |
14007 | b->number); | |
14008 | return; | |
14009 | } | |
f1310107 | 14010 | |
4a64f543 MS |
14011 | /* If there's no new locations, and all existing locations are |
14012 | pending, don't do anything. This optimizes the common case where | |
14013 | all locations are in the same shared library, that was unloaded. | |
14014 | We'd like to retain the location, so that when the library is | |
14015 | loaded again, we don't loose the enabled/disabled status of the | |
14016 | individual locations. */ | |
6c5b2ebe | 14017 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
fe3f5fa8 VP |
14018 | return; |
14019 | ||
c2f4122d | 14020 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14021 | |
6c5b2ebe | 14022 | for (const auto &sal : sals) |
fe3f5fa8 | 14023 | { |
f8eba3c6 TT |
14024 | struct bp_location *new_loc; |
14025 | ||
6c5b2ebe | 14026 | switch_to_program_space_and_thread (sal.pspace); |
f8eba3c6 | 14027 | |
6c5b2ebe | 14028 | new_loc = add_location_to_breakpoint (b, &sal); |
fe3f5fa8 | 14029 | |
0d381245 VP |
14030 | /* Reparse conditions, they might contain references to the |
14031 | old symtab. */ | |
14032 | if (b->cond_string != NULL) | |
14033 | { | |
bbc13ae3 | 14034 | const char *s; |
fe3f5fa8 | 14035 | |
0d381245 | 14036 | s = b->cond_string; |
492d29ea | 14037 | TRY |
0d381245 | 14038 | { |
6c5b2ebe PA |
14039 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
14040 | block_for_pc (sal.pc), | |
0d381245 VP |
14041 | 0); |
14042 | } | |
492d29ea | 14043 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14044 | { |
3e43a32a MS |
14045 | warning (_("failed to reevaluate condition " |
14046 | "for breakpoint %d: %s"), | |
0d381245 VP |
14047 | b->number, e.message); |
14048 | new_loc->enabled = 0; | |
14049 | } | |
492d29ea | 14050 | END_CATCH |
0d381245 | 14051 | } |
fe3f5fa8 | 14052 | |
6c5b2ebe | 14053 | if (!sals_end.empty ()) |
f1310107 | 14054 | { |
6c5b2ebe | 14055 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
f1310107 | 14056 | |
6c5b2ebe | 14057 | new_loc->length = end - sals[0].pc + 1; |
f1310107 | 14058 | } |
0d381245 | 14059 | } |
fe3f5fa8 | 14060 | |
4a64f543 MS |
14061 | /* If possible, carry over 'disable' status from existing |
14062 | breakpoints. */ | |
0d381245 VP |
14063 | { |
14064 | struct bp_location *e = existing_locations; | |
776592bf DE |
14065 | /* If there are multiple breakpoints with the same function name, |
14066 | e.g. for inline functions, comparing function names won't work. | |
14067 | Instead compare pc addresses; this is just a heuristic as things | |
14068 | may have moved, but in practice it gives the correct answer | |
14069 | often enough until a better solution is found. */ | |
14070 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14071 | ||
0d381245 VP |
14072 | for (; e; e = e->next) |
14073 | { | |
14074 | if (!e->enabled && e->function_name) | |
14075 | { | |
14076 | struct bp_location *l = b->loc; | |
776592bf DE |
14077 | if (have_ambiguous_names) |
14078 | { | |
14079 | for (; l; l = l->next) | |
f1310107 | 14080 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14081 | { |
14082 | l->enabled = 0; | |
14083 | break; | |
14084 | } | |
14085 | } | |
14086 | else | |
14087 | { | |
14088 | for (; l; l = l->next) | |
14089 | if (l->function_name | |
14090 | && strcmp (e->function_name, l->function_name) == 0) | |
14091 | { | |
14092 | l->enabled = 0; | |
14093 | break; | |
14094 | } | |
14095 | } | |
0d381245 VP |
14096 | } |
14097 | } | |
14098 | } | |
fe3f5fa8 | 14099 | |
8d3788bd VP |
14100 | if (!locations_are_equal (existing_locations, b->loc)) |
14101 | observer_notify_breakpoint_modified (b); | |
fe3f5fa8 VP |
14102 | } |
14103 | ||
f00aae0f | 14104 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14105 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14106 | ||
6c5b2ebe | 14107 | static std::vector<symtab_and_line> |
f00aae0f | 14108 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14109 | struct program_space *search_pspace, int *found) |
ef23e705 | 14110 | { |
492d29ea | 14111 | struct gdb_exception exception = exception_none; |
ef23e705 | 14112 | |
983af33b | 14113 | gdb_assert (b->ops != NULL); |
ef23e705 | 14114 | |
6c5b2ebe PA |
14115 | std::vector<symtab_and_line> sals; |
14116 | ||
492d29ea | 14117 | TRY |
ef23e705 | 14118 | { |
6c5b2ebe | 14119 | sals = b->ops->decode_location (b, location, search_pspace); |
ef23e705 | 14120 | } |
492d29ea | 14121 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14122 | { |
14123 | int not_found_and_ok = 0; | |
492d29ea PA |
14124 | |
14125 | exception = e; | |
14126 | ||
ef23e705 TJB |
14127 | /* For pending breakpoints, it's expected that parsing will |
14128 | fail until the right shared library is loaded. User has | |
14129 | already told to create pending breakpoints and don't need | |
14130 | extra messages. If breakpoint is in bp_shlib_disabled | |
14131 | state, then user already saw the message about that | |
14132 | breakpoint being disabled, and don't want to see more | |
14133 | errors. */ | |
58438ac1 | 14134 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14135 | && (b->condition_not_parsed |
14136 | || (b->loc != NULL | |
14137 | && search_pspace != NULL | |
14138 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14139 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14140 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14141 | || b->enable_state == bp_disabled)) |
14142 | not_found_and_ok = 1; | |
14143 | ||
14144 | if (!not_found_and_ok) | |
14145 | { | |
14146 | /* We surely don't want to warn about the same breakpoint | |
14147 | 10 times. One solution, implemented here, is disable | |
14148 | the breakpoint on error. Another solution would be to | |
14149 | have separate 'warning emitted' flag. Since this | |
14150 | happens only when a binary has changed, I don't know | |
14151 | which approach is better. */ | |
14152 | b->enable_state = bp_disabled; | |
14153 | throw_exception (e); | |
14154 | } | |
14155 | } | |
492d29ea | 14156 | END_CATCH |
ef23e705 | 14157 | |
492d29ea | 14158 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14159 | { |
6c5b2ebe PA |
14160 | for (auto &sal : sals) |
14161 | resolve_sal_pc (&sal); | |
f00aae0f | 14162 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14163 | { |
ed1d1739 KS |
14164 | char *cond_string, *extra_string; |
14165 | int thread, task; | |
ef23e705 | 14166 | |
6c5b2ebe | 14167 | find_condition_and_thread (b->extra_string, sals[0].pc, |
e7e0cddf SS |
14168 | &cond_string, &thread, &task, |
14169 | &extra_string); | |
f00aae0f | 14170 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14171 | if (cond_string) |
14172 | b->cond_string = cond_string; | |
14173 | b->thread = thread; | |
14174 | b->task = task; | |
e7e0cddf | 14175 | if (extra_string) |
f00aae0f KS |
14176 | { |
14177 | xfree (b->extra_string); | |
14178 | b->extra_string = extra_string; | |
14179 | } | |
ef23e705 TJB |
14180 | b->condition_not_parsed = 0; |
14181 | } | |
14182 | ||
983af33b | 14183 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
6c5b2ebe | 14184 | sals[0] = update_static_tracepoint (b, sals[0]); |
ef23e705 | 14185 | |
58438ac1 TT |
14186 | *found = 1; |
14187 | } | |
14188 | else | |
14189 | *found = 0; | |
ef23e705 TJB |
14190 | |
14191 | return sals; | |
14192 | } | |
14193 | ||
348d480f PA |
14194 | /* The default re_set method, for typical hardware or software |
14195 | breakpoints. Reevaluate the breakpoint and recreate its | |
14196 | locations. */ | |
14197 | ||
14198 | static void | |
28010a5d | 14199 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 | 14200 | { |
c2f4122d | 14201 | struct program_space *filter_pspace = current_program_space; |
6c5b2ebe | 14202 | std::vector<symtab_and_line> expanded, expanded_end; |
ef23e705 | 14203 | |
6c5b2ebe PA |
14204 | int found; |
14205 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), | |
14206 | filter_pspace, &found); | |
ef23e705 | 14207 | if (found) |
6c5b2ebe | 14208 | expanded = std::move (sals); |
ef23e705 | 14209 | |
f00aae0f | 14210 | if (b->location_range_end != NULL) |
f1310107 | 14211 | { |
6c5b2ebe PA |
14212 | std::vector<symtab_and_line> sals_end |
14213 | = location_to_sals (b, b->location_range_end.get (), | |
14214 | filter_pspace, &found); | |
f1310107 | 14215 | if (found) |
6c5b2ebe | 14216 | expanded_end = std::move (sals_end); |
f1310107 TJB |
14217 | } |
14218 | ||
c2f4122d | 14219 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14220 | } |
14221 | ||
983af33b SDJ |
14222 | /* Default method for creating SALs from an address string. It basically |
14223 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14224 | ||
14225 | static void | |
f00aae0f KS |
14226 | create_sals_from_location_default (const struct event_location *location, |
14227 | struct linespec_result *canonical, | |
14228 | enum bptype type_wanted) | |
983af33b | 14229 | { |
f00aae0f | 14230 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14231 | } |
14232 | ||
14233 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14234 | function for the `create_breakpoints_sal' method of | |
14235 | breakpoint_ops. */ | |
14236 | ||
14237 | static void | |
14238 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14239 | struct linespec_result *canonical, | |
e1e01040 PA |
14240 | gdb::unique_xmalloc_ptr<char> cond_string, |
14241 | gdb::unique_xmalloc_ptr<char> extra_string, | |
983af33b SDJ |
14242 | enum bptype type_wanted, |
14243 | enum bpdisp disposition, | |
14244 | int thread, | |
14245 | int task, int ignore_count, | |
14246 | const struct breakpoint_ops *ops, | |
14247 | int from_tty, int enabled, | |
44f238bb | 14248 | int internal, unsigned flags) |
983af33b | 14249 | { |
e1e01040 PA |
14250 | create_breakpoints_sal (gdbarch, canonical, |
14251 | std::move (cond_string), | |
14252 | std::move (extra_string), | |
983af33b SDJ |
14253 | type_wanted, disposition, |
14254 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14255 | enabled, internal, flags); |
983af33b SDJ |
14256 | } |
14257 | ||
14258 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14259 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b | 14260 | |
6c5b2ebe | 14261 | static std::vector<symtab_and_line> |
f00aae0f KS |
14262 | decode_location_default (struct breakpoint *b, |
14263 | const struct event_location *location, | |
6c5b2ebe | 14264 | struct program_space *search_pspace) |
983af33b SDJ |
14265 | { |
14266 | struct linespec_result canonical; | |
14267 | ||
c2f4122d | 14268 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14269 | (struct symtab *) NULL, 0, |
14270 | &canonical, multiple_symbols_all, | |
14271 | b->filter); | |
14272 | ||
14273 | /* We should get 0 or 1 resulting SALs. */ | |
6c5b2ebe | 14274 | gdb_assert (canonical.lsals.size () < 2); |
983af33b | 14275 | |
6c5b2ebe | 14276 | if (!canonical.lsals.empty ()) |
983af33b | 14277 | { |
6c5b2ebe PA |
14278 | const linespec_sals &lsal = canonical.lsals[0]; |
14279 | return std::move (lsal.sals); | |
983af33b | 14280 | } |
6c5b2ebe | 14281 | return {}; |
983af33b SDJ |
14282 | } |
14283 | ||
28010a5d PA |
14284 | /* Prepare the global context for a re-set of breakpoint B. */ |
14285 | ||
14286 | static struct cleanup * | |
14287 | prepare_re_set_context (struct breakpoint *b) | |
14288 | { | |
28010a5d | 14289 | input_radix = b->input_radix; |
28010a5d PA |
14290 | set_language (b->language); |
14291 | ||
c2f4122d | 14292 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14293 | } |
14294 | ||
c906108c SS |
14295 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14296 | The value we return ends up being the return value from catch_errors. | |
14297 | Unused in this case. */ | |
14298 | ||
14299 | static int | |
4efb68b1 | 14300 | breakpoint_re_set_one (void *bint) |
c906108c | 14301 | { |
4a64f543 | 14302 | /* Get past catch_errs. */ |
53a5351d | 14303 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14304 | struct cleanup *cleanups; |
c906108c | 14305 | |
348d480f PA |
14306 | cleanups = prepare_re_set_context (b); |
14307 | b->ops->re_set (b); | |
14308 | do_cleanups (cleanups); | |
c906108c SS |
14309 | return 0; |
14310 | } | |
14311 | ||
c2f4122d PA |
14312 | /* Re-set breakpoint locations for the current program space. |
14313 | Locations bound to other program spaces are left untouched. */ | |
14314 | ||
c906108c | 14315 | void |
69de3c6a | 14316 | breakpoint_re_set (void) |
c906108c | 14317 | { |
35df4500 | 14318 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14319 | enum language save_language; |
14320 | int save_input_radix; | |
c5aa993b | 14321 | |
c906108c SS |
14322 | save_language = current_language->la_language; |
14323 | save_input_radix = input_radix; | |
2a7f3dff | 14324 | |
c5aa993b | 14325 | { |
5ed8105e | 14326 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
e62c965a | 14327 | |
5ed8105e PA |
14328 | /* Note: we must not try to insert locations until after all |
14329 | breakpoints have been re-set. Otherwise, e.g., when re-setting | |
14330 | breakpoint 1, we'd insert the locations of breakpoint 2, which | |
14331 | hadn't been re-set yet, and thus may have stale locations. */ | |
4efc6507 | 14332 | |
5ed8105e PA |
14333 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
14334 | { | |
14335 | /* Format possible error msg. */ | |
14336 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", | |
14337 | b->number); | |
14338 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
14339 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); | |
14340 | do_cleanups (cleanups); | |
14341 | } | |
14342 | set_language (save_language); | |
14343 | input_radix = save_input_radix; | |
14344 | ||
14345 | jit_breakpoint_re_set (); | |
14346 | } | |
6c95b8df | 14347 | |
af02033e PP |
14348 | create_overlay_event_breakpoint (); |
14349 | create_longjmp_master_breakpoint (); | |
14350 | create_std_terminate_master_breakpoint (); | |
186c406b | 14351 | create_exception_master_breakpoint (); |
2a7f3dff PA |
14352 | |
14353 | /* Now we can insert. */ | |
14354 | update_global_location_list (UGLL_MAY_INSERT); | |
c906108c SS |
14355 | } |
14356 | \f | |
c906108c SS |
14357 | /* Reset the thread number of this breakpoint: |
14358 | ||
14359 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14360 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14361 | void |
fba45db2 | 14362 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14363 | { |
14364 | if (b->thread != -1) | |
14365 | { | |
39f77062 | 14366 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14367 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14368 | |
14369 | /* We're being called after following a fork. The new fork is | |
14370 | selected as current, and unless this was a vfork will have a | |
14371 | different program space from the original thread. Reset that | |
14372 | as well. */ | |
14373 | b->loc->pspace = current_program_space; | |
c906108c SS |
14374 | } |
14375 | } | |
14376 | ||
03ac34d5 MS |
14377 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14378 | If from_tty is nonzero, it prints a message to that effect, | |
14379 | which ends with a period (no newline). */ | |
14380 | ||
c906108c | 14381 | void |
fba45db2 | 14382 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14383 | { |
52f0bd74 | 14384 | struct breakpoint *b; |
c906108c SS |
14385 | |
14386 | if (count < 0) | |
14387 | count = 0; | |
14388 | ||
14389 | ALL_BREAKPOINTS (b) | |
14390 | if (b->number == bptnum) | |
c5aa993b | 14391 | { |
d77f58be SS |
14392 | if (is_tracepoint (b)) |
14393 | { | |
14394 | if (from_tty && count != 0) | |
14395 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14396 | bptnum); | |
14397 | return; | |
14398 | } | |
14399 | ||
c5aa993b | 14400 | b->ignore_count = count; |
221ea385 KS |
14401 | if (from_tty) |
14402 | { | |
14403 | if (count == 0) | |
3e43a32a MS |
14404 | printf_filtered (_("Will stop next time " |
14405 | "breakpoint %d is reached."), | |
221ea385 KS |
14406 | bptnum); |
14407 | else if (count == 1) | |
a3f17187 | 14408 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14409 | bptnum); |
14410 | else | |
3e43a32a MS |
14411 | printf_filtered (_("Will ignore next %d " |
14412 | "crossings of breakpoint %d."), | |
221ea385 KS |
14413 | count, bptnum); |
14414 | } | |
8d3788bd | 14415 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14416 | return; |
14417 | } | |
c906108c | 14418 | |
8a3fe4f8 | 14419 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14420 | } |
14421 | ||
c906108c SS |
14422 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14423 | ||
14424 | static void | |
fba45db2 | 14425 | ignore_command (char *args, int from_tty) |
c906108c SS |
14426 | { |
14427 | char *p = args; | |
52f0bd74 | 14428 | int num; |
c906108c SS |
14429 | |
14430 | if (p == 0) | |
e2e0b3e5 | 14431 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14432 | |
c906108c | 14433 | num = get_number (&p); |
5c44784c | 14434 | if (num == 0) |
8a3fe4f8 | 14435 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14436 | if (*p == 0) |
8a3fe4f8 | 14437 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14438 | |
14439 | set_ignore_count (num, | |
14440 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14441 | from_tty); | |
221ea385 KS |
14442 | if (from_tty) |
14443 | printf_filtered ("\n"); | |
c906108c SS |
14444 | } |
14445 | \f | |
14446 | /* Call FUNCTION on each of the breakpoints | |
14447 | whose numbers are given in ARGS. */ | |
14448 | ||
14449 | static void | |
896b6bda PA |
14450 | map_breakpoint_numbers (const char *args, |
14451 | void (*function) (struct breakpoint *, | |
14452 | void *), | |
95a42b64 | 14453 | void *data) |
c906108c | 14454 | { |
52f0bd74 AC |
14455 | int num; |
14456 | struct breakpoint *b, *tmp; | |
c906108c | 14457 | |
b9d61307 | 14458 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14459 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14460 | |
bfd28288 | 14461 | number_or_range_parser parser (args); |
197f0a60 | 14462 | |
bfd28288 | 14463 | while (!parser.finished ()) |
c906108c | 14464 | { |
bfd28288 PA |
14465 | const char *p = parser.cur_tok (); |
14466 | bool match = false; | |
197f0a60 | 14467 | |
bfd28288 | 14468 | num = parser.get_number (); |
5c44784c | 14469 | if (num == 0) |
c5aa993b | 14470 | { |
8a3fe4f8 | 14471 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14472 | } |
14473 | else | |
14474 | { | |
14475 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14476 | if (b->number == num) | |
14477 | { | |
bfd28288 | 14478 | match = true; |
cdac0397 | 14479 | function (b, data); |
11cf8741 | 14480 | break; |
5c44784c | 14481 | } |
bfd28288 | 14482 | if (!match) |
a3f17187 | 14483 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14484 | } |
c906108c SS |
14485 | } |
14486 | } | |
14487 | ||
0d381245 | 14488 | static struct bp_location * |
cb791d59 | 14489 | find_location_by_number (const char *number) |
0d381245 | 14490 | { |
cb791d59 | 14491 | const char *p1; |
0d381245 VP |
14492 | int bp_num; |
14493 | int loc_num; | |
14494 | struct breakpoint *b; | |
14495 | struct bp_location *loc; | |
14496 | ||
0d381245 | 14497 | p1 = number; |
cb791d59 TT |
14498 | bp_num = get_number_trailer (&p1, '.'); |
14499 | if (bp_num == 0 || p1[0] != '.') | |
0d381245 VP |
14500 | error (_("Bad breakpoint number '%s'"), number); |
14501 | ||
14502 | ALL_BREAKPOINTS (b) | |
14503 | if (b->number == bp_num) | |
14504 | { | |
14505 | break; | |
14506 | } | |
14507 | ||
14508 | if (!b || b->number != bp_num) | |
14509 | error (_("Bad breakpoint number '%s'"), number); | |
14510 | ||
cb791d59 TT |
14511 | /* Skip the dot. */ |
14512 | ++p1; | |
14513 | const char *save = p1; | |
197f0a60 | 14514 | loc_num = get_number (&p1); |
0d381245 VP |
14515 | if (loc_num == 0) |
14516 | error (_("Bad breakpoint location number '%s'"), number); | |
14517 | ||
14518 | --loc_num; | |
14519 | loc = b->loc; | |
14520 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14521 | ; | |
14522 | if (!loc) | |
cb791d59 | 14523 | error (_("Bad breakpoint location number '%s'"), save); |
0d381245 VP |
14524 | |
14525 | return loc; | |
14526 | } | |
14527 | ||
14528 | ||
1900040c MS |
14529 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14530 | If from_tty is nonzero, it prints a message to that effect, | |
14531 | which ends with a period (no newline). */ | |
14532 | ||
c906108c | 14533 | void |
fba45db2 | 14534 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14535 | { |
14536 | /* Never disable a watchpoint scope breakpoint; we want to | |
14537 | hit them when we leave scope so we can delete both the | |
14538 | watchpoint and its scope breakpoint at that time. */ | |
14539 | if (bpt->type == bp_watchpoint_scope) | |
14540 | return; | |
14541 | ||
b5de0fa7 | 14542 | bpt->enable_state = bp_disabled; |
c906108c | 14543 | |
b775012e LM |
14544 | /* Mark breakpoint locations modified. */ |
14545 | mark_breakpoint_modified (bpt); | |
14546 | ||
d248b706 KY |
14547 | if (target_supports_enable_disable_tracepoint () |
14548 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14549 | { | |
14550 | struct bp_location *location; | |
14551 | ||
14552 | for (location = bpt->loc; location; location = location->next) | |
14553 | target_disable_tracepoint (location); | |
14554 | } | |
14555 | ||
44702360 | 14556 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14557 | |
8d3788bd | 14558 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14559 | } |
14560 | ||
51be5b68 PA |
14561 | /* A callback for iterate_over_related_breakpoints. */ |
14562 | ||
14563 | static void | |
14564 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14565 | { | |
14566 | disable_breakpoint (b); | |
14567 | } | |
14568 | ||
95a42b64 TT |
14569 | /* A callback for map_breakpoint_numbers that calls |
14570 | disable_breakpoint. */ | |
14571 | ||
14572 | static void | |
14573 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14574 | { | |
51be5b68 | 14575 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14576 | } |
14577 | ||
c906108c | 14578 | static void |
fba45db2 | 14579 | disable_command (char *args, int from_tty) |
c906108c | 14580 | { |
c906108c | 14581 | if (args == 0) |
46c6471b PA |
14582 | { |
14583 | struct breakpoint *bpt; | |
14584 | ||
14585 | ALL_BREAKPOINTS (bpt) | |
14586 | if (user_breakpoint_p (bpt)) | |
14587 | disable_breakpoint (bpt); | |
14588 | } | |
9eaabc75 | 14589 | else |
0d381245 | 14590 | { |
cb791d59 | 14591 | std::string num = extract_arg (&args); |
9eaabc75 | 14592 | |
cb791d59 | 14593 | while (!num.empty ()) |
d248b706 | 14594 | { |
cb791d59 | 14595 | if (num.find ('.') != std::string::npos) |
b775012e | 14596 | { |
cb791d59 | 14597 | struct bp_location *loc = find_location_by_number (num.c_str ()); |
9eaabc75 MW |
14598 | |
14599 | if (loc) | |
14600 | { | |
14601 | if (loc->enabled) | |
14602 | { | |
14603 | loc->enabled = 0; | |
14604 | mark_breakpoint_location_modified (loc); | |
14605 | } | |
14606 | if (target_supports_enable_disable_tracepoint () | |
14607 | && current_trace_status ()->running && loc->owner | |
14608 | && is_tracepoint (loc->owner)) | |
14609 | target_disable_tracepoint (loc); | |
14610 | } | |
44702360 | 14611 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14612 | } |
9eaabc75 | 14613 | else |
cb791d59 TT |
14614 | map_breakpoint_numbers (num.c_str (), do_map_disable_breakpoint, |
14615 | NULL); | |
9eaabc75 | 14616 | num = extract_arg (&args); |
d248b706 | 14617 | } |
0d381245 | 14618 | } |
c906108c SS |
14619 | } |
14620 | ||
14621 | static void | |
816338b5 SS |
14622 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14623 | int count) | |
c906108c | 14624 | { |
afe38095 | 14625 | int target_resources_ok; |
c906108c SS |
14626 | |
14627 | if (bpt->type == bp_hardware_breakpoint) | |
14628 | { | |
14629 | int i; | |
c5aa993b | 14630 | i = hw_breakpoint_used_count (); |
53a5351d | 14631 | target_resources_ok = |
d92524f1 | 14632 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14633 | i + 1, 0); |
c906108c | 14634 | if (target_resources_ok == 0) |
8a3fe4f8 | 14635 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14636 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14637 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14638 | } |
14639 | ||
cc60f2e3 | 14640 | if (is_watchpoint (bpt)) |
c906108c | 14641 | { |
d07205c2 | 14642 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14643 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14644 | |
492d29ea | 14645 | TRY |
c906108c | 14646 | { |
3a5c3e22 PA |
14647 | struct watchpoint *w = (struct watchpoint *) bpt; |
14648 | ||
1e718ff1 TJB |
14649 | orig_enable_state = bpt->enable_state; |
14650 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14651 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14652 | } |
492d29ea | 14653 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14654 | { |
1e718ff1 | 14655 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14656 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14657 | bpt->number); | |
14658 | return; | |
c5aa993b | 14659 | } |
492d29ea | 14660 | END_CATCH |
c906108c | 14661 | } |
0101ce28 | 14662 | |
b775012e LM |
14663 | bpt->enable_state = bp_enabled; |
14664 | ||
14665 | /* Mark breakpoint locations modified. */ | |
14666 | mark_breakpoint_modified (bpt); | |
14667 | ||
d248b706 KY |
14668 | if (target_supports_enable_disable_tracepoint () |
14669 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14670 | { | |
14671 | struct bp_location *location; | |
14672 | ||
14673 | for (location = bpt->loc; location; location = location->next) | |
14674 | target_enable_tracepoint (location); | |
14675 | } | |
14676 | ||
b4c291bb | 14677 | bpt->disposition = disposition; |
816338b5 | 14678 | bpt->enable_count = count; |
44702360 | 14679 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14680 | |
8d3788bd | 14681 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14682 | } |
14683 | ||
fe3f5fa8 | 14684 | |
c906108c | 14685 | void |
fba45db2 | 14686 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14687 | { |
816338b5 | 14688 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14689 | } |
14690 | ||
14691 | static void | |
14692 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14693 | { | |
14694 | enable_breakpoint (bpt); | |
c906108c SS |
14695 | } |
14696 | ||
95a42b64 TT |
14697 | /* A callback for map_breakpoint_numbers that calls |
14698 | enable_breakpoint. */ | |
14699 | ||
14700 | static void | |
14701 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14702 | { | |
51be5b68 | 14703 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14704 | } |
14705 | ||
c906108c SS |
14706 | /* The enable command enables the specified breakpoints (or all defined |
14707 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14708 | in stopping the inferior. */ |
c906108c | 14709 | |
c906108c | 14710 | static void |
fba45db2 | 14711 | enable_command (char *args, int from_tty) |
c906108c | 14712 | { |
c906108c | 14713 | if (args == 0) |
46c6471b PA |
14714 | { |
14715 | struct breakpoint *bpt; | |
14716 | ||
14717 | ALL_BREAKPOINTS (bpt) | |
14718 | if (user_breakpoint_p (bpt)) | |
14719 | enable_breakpoint (bpt); | |
14720 | } | |
9eaabc75 | 14721 | else |
0d381245 | 14722 | { |
cb791d59 | 14723 | std::string num = extract_arg (&args); |
9eaabc75 | 14724 | |
cb791d59 | 14725 | while (!num.empty ()) |
d248b706 | 14726 | { |
cb791d59 | 14727 | if (num.find ('.') != std::string::npos) |
b775012e | 14728 | { |
cb791d59 | 14729 | struct bp_location *loc = find_location_by_number (num.c_str ()); |
9eaabc75 MW |
14730 | |
14731 | if (loc) | |
14732 | { | |
14733 | if (!loc->enabled) | |
14734 | { | |
14735 | loc->enabled = 1; | |
14736 | mark_breakpoint_location_modified (loc); | |
14737 | } | |
14738 | if (target_supports_enable_disable_tracepoint () | |
14739 | && current_trace_status ()->running && loc->owner | |
14740 | && is_tracepoint (loc->owner)) | |
14741 | target_enable_tracepoint (loc); | |
14742 | } | |
44702360 | 14743 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 14744 | } |
9eaabc75 | 14745 | else |
cb791d59 TT |
14746 | map_breakpoint_numbers (num.c_str (), do_map_enable_breakpoint, |
14747 | NULL); | |
9eaabc75 | 14748 | num = extract_arg (&args); |
d248b706 | 14749 | } |
0d381245 | 14750 | } |
c906108c SS |
14751 | } |
14752 | ||
816338b5 SS |
14753 | /* This struct packages up disposition data for application to multiple |
14754 | breakpoints. */ | |
14755 | ||
14756 | struct disp_data | |
14757 | { | |
14758 | enum bpdisp disp; | |
14759 | int count; | |
14760 | }; | |
14761 | ||
c906108c | 14762 | static void |
51be5b68 PA |
14763 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
14764 | { | |
816338b5 | 14765 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 14766 | |
816338b5 | 14767 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
14768 | } |
14769 | ||
14770 | static void | |
14771 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 14772 | { |
816338b5 | 14773 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
14774 | |
14775 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14776 | } |
14777 | ||
c906108c | 14778 | static void |
fba45db2 | 14779 | enable_once_command (char *args, int from_tty) |
c906108c | 14780 | { |
51be5b68 | 14781 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
14782 | } |
14783 | ||
816338b5 SS |
14784 | static void |
14785 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
14786 | { | |
14787 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
14788 | ||
14789 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
14790 | } | |
14791 | ||
14792 | static void | |
14793 | enable_count_command (char *args, int from_tty) | |
14794 | { | |
b9d61307 SM |
14795 | int count; |
14796 | ||
14797 | if (args == NULL) | |
14798 | error_no_arg (_("hit count")); | |
14799 | ||
14800 | count = get_number (&args); | |
816338b5 SS |
14801 | |
14802 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
14803 | } | |
14804 | ||
c906108c | 14805 | static void |
51be5b68 | 14806 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 14807 | { |
816338b5 | 14808 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
14809 | |
14810 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
14811 | } |
14812 | ||
c906108c | 14813 | static void |
fba45db2 | 14814 | enable_delete_command (char *args, int from_tty) |
c906108c | 14815 | { |
51be5b68 | 14816 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
14817 | } |
14818 | \f | |
fa8d40ab JJ |
14819 | static void |
14820 | set_breakpoint_cmd (char *args, int from_tty) | |
14821 | { | |
14822 | } | |
14823 | ||
14824 | static void | |
14825 | show_breakpoint_cmd (char *args, int from_tty) | |
14826 | { | |
14827 | } | |
14828 | ||
1f3b5d1b PP |
14829 | /* Invalidate last known value of any hardware watchpoint if |
14830 | the memory which that value represents has been written to by | |
14831 | GDB itself. */ | |
14832 | ||
14833 | static void | |
8de0566d YQ |
14834 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
14835 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
14836 | const bfd_byte *data) |
14837 | { | |
14838 | struct breakpoint *bp; | |
14839 | ||
14840 | ALL_BREAKPOINTS (bp) | |
14841 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 14842 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 14843 | { |
3a5c3e22 | 14844 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 14845 | |
3a5c3e22 PA |
14846 | if (wp->val_valid && wp->val) |
14847 | { | |
14848 | struct bp_location *loc; | |
14849 | ||
14850 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
14851 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
14852 | && loc->address + loc->length > addr | |
14853 | && addr + len > loc->address) | |
14854 | { | |
14855 | value_free (wp->val); | |
14856 | wp->val = NULL; | |
14857 | wp->val_valid = 0; | |
14858 | } | |
14859 | } | |
1f3b5d1b PP |
14860 | } |
14861 | } | |
14862 | ||
8181d85f DJ |
14863 | /* Create and insert a breakpoint for software single step. */ |
14864 | ||
14865 | void | |
6c95b8df | 14866 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
14867 | struct address_space *aspace, |
14868 | CORE_ADDR next_pc) | |
8181d85f | 14869 | { |
7c16b83e PA |
14870 | struct thread_info *tp = inferior_thread (); |
14871 | struct symtab_and_line sal; | |
14872 | CORE_ADDR pc = next_pc; | |
8181d85f | 14873 | |
34b7e8a6 PA |
14874 | if (tp->control.single_step_breakpoints == NULL) |
14875 | { | |
14876 | tp->control.single_step_breakpoints | |
5d5658a1 | 14877 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 14878 | } |
8181d85f | 14879 | |
7c16b83e PA |
14880 | sal = find_pc_line (pc, 0); |
14881 | sal.pc = pc; | |
14882 | sal.section = find_pc_overlay (pc); | |
14883 | sal.explicit_pc = 1; | |
34b7e8a6 | 14884 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 14885 | |
7c16b83e | 14886 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
14887 | } |
14888 | ||
93f9a11f YQ |
14889 | /* Insert single step breakpoints according to the current state. */ |
14890 | ||
14891 | int | |
14892 | insert_single_step_breakpoints (struct gdbarch *gdbarch) | |
14893 | { | |
f5ea389a | 14894 | struct regcache *regcache = get_current_regcache (); |
a0ff9e1a | 14895 | std::vector<CORE_ADDR> next_pcs; |
93f9a11f | 14896 | |
f5ea389a | 14897 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
93f9a11f | 14898 | |
a0ff9e1a | 14899 | if (!next_pcs.empty ()) |
93f9a11f | 14900 | { |
f5ea389a | 14901 | struct frame_info *frame = get_current_frame (); |
93f9a11f YQ |
14902 | struct address_space *aspace = get_frame_address_space (frame); |
14903 | ||
a0ff9e1a | 14904 | for (CORE_ADDR pc : next_pcs) |
93f9a11f YQ |
14905 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
14906 | ||
93f9a11f YQ |
14907 | return 1; |
14908 | } | |
14909 | else | |
14910 | return 0; | |
14911 | } | |
14912 | ||
34b7e8a6 | 14913 | /* See breakpoint.h. */ |
f02253f1 HZ |
14914 | |
14915 | int | |
7c16b83e PA |
14916 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
14917 | struct address_space *aspace, | |
14918 | CORE_ADDR pc) | |
1aafd4da | 14919 | { |
7c16b83e | 14920 | struct bp_location *loc; |
1aafd4da | 14921 | |
7c16b83e PA |
14922 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
14923 | if (loc->inserted | |
14924 | && breakpoint_location_address_match (loc, aspace, pc)) | |
14925 | return 1; | |
1aafd4da | 14926 | |
7c16b83e | 14927 | return 0; |
ef370185 JB |
14928 | } |
14929 | ||
14930 | /* Check whether a software single-step breakpoint is inserted at | |
14931 | PC. */ | |
14932 | ||
14933 | int | |
14934 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
14935 | CORE_ADDR pc) | |
14936 | { | |
34b7e8a6 PA |
14937 | struct breakpoint *bpt; |
14938 | ||
14939 | ALL_BREAKPOINTS (bpt) | |
14940 | { | |
14941 | if (bpt->type == bp_single_step | |
14942 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
14943 | return 1; | |
14944 | } | |
14945 | return 0; | |
1aafd4da UW |
14946 | } |
14947 | ||
1042e4c0 SS |
14948 | /* Tracepoint-specific operations. */ |
14949 | ||
14950 | /* Set tracepoint count to NUM. */ | |
14951 | static void | |
14952 | set_tracepoint_count (int num) | |
14953 | { | |
14954 | tracepoint_count = num; | |
4fa62494 | 14955 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
14956 | } |
14957 | ||
70221824 | 14958 | static void |
1042e4c0 SS |
14959 | trace_command (char *arg, int from_tty) |
14960 | { | |
55aa24fb | 14961 | struct breakpoint_ops *ops; |
55aa24fb | 14962 | |
ffc2605c TT |
14963 | event_location_up location = string_to_event_location (&arg, |
14964 | current_language); | |
5b56227b | 14965 | if (location != NULL |
ffc2605c | 14966 | && event_location_type (location.get ()) == PROBE_LOCATION) |
55aa24fb SDJ |
14967 | ops = &tracepoint_probe_breakpoint_ops; |
14968 | else | |
14969 | ops = &tracepoint_breakpoint_ops; | |
14970 | ||
558a9d82 | 14971 | create_breakpoint (get_current_arch (), |
ffc2605c | 14972 | location.get (), |
f00aae0f | 14973 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14974 | 0 /* tempflag */, |
14975 | bp_tracepoint /* type_wanted */, | |
14976 | 0 /* Ignore count */, | |
14977 | pending_break_support, | |
14978 | ops, | |
14979 | from_tty, | |
14980 | 1 /* enabled */, | |
14981 | 0 /* internal */, 0); | |
1042e4c0 SS |
14982 | } |
14983 | ||
70221824 | 14984 | static void |
7a697b8d SS |
14985 | ftrace_command (char *arg, int from_tty) |
14986 | { | |
ffc2605c TT |
14987 | event_location_up location = string_to_event_location (&arg, |
14988 | current_language); | |
558a9d82 | 14989 | create_breakpoint (get_current_arch (), |
ffc2605c | 14990 | location.get (), |
f00aae0f | 14991 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
14992 | 0 /* tempflag */, |
14993 | bp_fast_tracepoint /* type_wanted */, | |
14994 | 0 /* Ignore count */, | |
14995 | pending_break_support, | |
14996 | &tracepoint_breakpoint_ops, | |
14997 | from_tty, | |
14998 | 1 /* enabled */, | |
14999 | 0 /* internal */, 0); | |
0fb4aa4b PA |
15000 | } |
15001 | ||
15002 | /* strace command implementation. Creates a static tracepoint. */ | |
15003 | ||
70221824 | 15004 | static void |
0fb4aa4b PA |
15005 | strace_command (char *arg, int from_tty) |
15006 | { | |
983af33b | 15007 | struct breakpoint_ops *ops; |
ffc2605c | 15008 | event_location_up location; |
f00aae0f | 15009 | struct cleanup *back_to; |
983af33b SDJ |
15010 | |
15011 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15012 | or with a normal static tracepoint. */ | |
61012eef | 15013 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15014 | { |
15015 | ops = &strace_marker_breakpoint_ops; | |
15016 | location = new_linespec_location (&arg); | |
15017 | } | |
983af33b | 15018 | else |
f00aae0f KS |
15019 | { |
15020 | ops = &tracepoint_breakpoint_ops; | |
15021 | location = string_to_event_location (&arg, current_language); | |
15022 | } | |
983af33b | 15023 | |
558a9d82 | 15024 | create_breakpoint (get_current_arch (), |
ffc2605c | 15025 | location.get (), |
f00aae0f | 15026 | NULL, 0, arg, 1 /* parse arg */, |
558a9d82 YQ |
15027 | 0 /* tempflag */, |
15028 | bp_static_tracepoint /* type_wanted */, | |
15029 | 0 /* Ignore count */, | |
15030 | pending_break_support, | |
15031 | ops, | |
15032 | from_tty, | |
15033 | 1 /* enabled */, | |
15034 | 0 /* internal */, 0); | |
7a697b8d SS |
15035 | } |
15036 | ||
409873ef SS |
15037 | /* Set up a fake reader function that gets command lines from a linked |
15038 | list that was acquired during tracepoint uploading. */ | |
15039 | ||
15040 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15041 | static int next_cmd; |
409873ef SS |
15042 | |
15043 | static char * | |
15044 | read_uploaded_action (void) | |
15045 | { | |
15046 | char *rslt; | |
15047 | ||
3149d8c1 | 15048 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15049 | |
3149d8c1 | 15050 | next_cmd++; |
409873ef SS |
15051 | |
15052 | return rslt; | |
15053 | } | |
15054 | ||
00bf0b85 SS |
15055 | /* Given information about a tracepoint as recorded on a target (which |
15056 | can be either a live system or a trace file), attempt to create an | |
15057 | equivalent GDB tracepoint. This is not a reliable process, since | |
15058 | the target does not necessarily have all the information used when | |
15059 | the tracepoint was originally defined. */ | |
15060 | ||
d9b3f62e | 15061 | struct tracepoint * |
00bf0b85 | 15062 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15063 | { |
409873ef | 15064 | char *addr_str, small_buf[100]; |
d9b3f62e | 15065 | struct tracepoint *tp; |
fd9b8c24 | 15066 | |
409873ef SS |
15067 | if (utp->at_string) |
15068 | addr_str = utp->at_string; | |
15069 | else | |
15070 | { | |
15071 | /* In the absence of a source location, fall back to raw | |
15072 | address. Since there is no way to confirm that the address | |
15073 | means the same thing as when the trace was started, warn the | |
15074 | user. */ | |
3e43a32a MS |
15075 | warning (_("Uploaded tracepoint %d has no " |
15076 | "source location, using raw address"), | |
409873ef | 15077 | utp->number); |
8c042590 | 15078 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15079 | addr_str = small_buf; |
15080 | } | |
15081 | ||
15082 | /* There's not much we can do with a sequence of bytecodes. */ | |
15083 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15084 | warning (_("Uploaded tracepoint %d condition " |
15085 | "has no source form, ignoring it"), | |
409873ef | 15086 | utp->number); |
d5551862 | 15087 | |
ffc2605c TT |
15088 | event_location_up location = string_to_event_location (&addr_str, |
15089 | current_language); | |
8cdf0e15 | 15090 | if (!create_breakpoint (get_current_arch (), |
ffc2605c | 15091 | location.get (), |
f00aae0f | 15092 | utp->cond_string, -1, addr_str, |
e7e0cddf | 15093 | 0 /* parse cond/thread */, |
8cdf0e15 | 15094 | 0 /* tempflag */, |
0fb4aa4b | 15095 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15096 | 0 /* Ignore count */, |
15097 | pending_break_support, | |
348d480f | 15098 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15099 | 0 /* from_tty */, |
84f4c1fe | 15100 | utp->enabled /* enabled */, |
44f238bb PA |
15101 | 0 /* internal */, |
15102 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
ffc2605c | 15103 | return NULL; |
fd9b8c24 | 15104 | |
409873ef | 15105 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15106 | tp = get_tracepoint (tracepoint_count); |
15107 | gdb_assert (tp != NULL); | |
d5551862 | 15108 | |
00bf0b85 SS |
15109 | if (utp->pass > 0) |
15110 | { | |
8c042590 | 15111 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
c1fc2657 | 15112 | tp->number); |
00bf0b85 | 15113 | |
409873ef | 15114 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15115 | } |
15116 | ||
409873ef SS |
15117 | /* If we have uploaded versions of the original commands, set up a |
15118 | special-purpose "reader" function and call the usual command line | |
15119 | reader, then pass the result to the breakpoint command-setting | |
15120 | function. */ | |
3149d8c1 | 15121 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15122 | { |
93921405 | 15123 | command_line_up cmd_list; |
00bf0b85 | 15124 | |
409873ef | 15125 | this_utp = utp; |
3149d8c1 | 15126 | next_cmd = 0; |
d5551862 | 15127 | |
409873ef SS |
15128 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15129 | ||
c1fc2657 | 15130 | breakpoint_set_commands (tp, std::move (cmd_list)); |
00bf0b85 | 15131 | } |
3149d8c1 SS |
15132 | else if (!VEC_empty (char_ptr, utp->actions) |
15133 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15134 | warning (_("Uploaded tracepoint %d actions " |
15135 | "have no source form, ignoring them"), | |
409873ef | 15136 | utp->number); |
00bf0b85 | 15137 | |
f196051f | 15138 | /* Copy any status information that might be available. */ |
c1fc2657 | 15139 | tp->hit_count = utp->hit_count; |
f196051f SS |
15140 | tp->traceframe_usage = utp->traceframe_usage; |
15141 | ||
00bf0b85 | 15142 | return tp; |
d9b3f62e | 15143 | } |
00bf0b85 | 15144 | |
1042e4c0 SS |
15145 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15146 | omitted. */ | |
15147 | ||
15148 | static void | |
11db9430 | 15149 | info_tracepoints_command (char *args, int from_tty) |
1042e4c0 | 15150 | { |
79a45e25 | 15151 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15152 | int num_printed; |
1042e4c0 | 15153 | |
e5a67952 | 15154 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15155 | |
15156 | if (num_printed == 0) | |
1042e4c0 | 15157 | { |
e5a67952 | 15158 | if (args == NULL || *args == '\0') |
112e8700 | 15159 | uiout->message ("No tracepoints.\n"); |
d77f58be | 15160 | else |
112e8700 | 15161 | uiout->message ("No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15162 | } |
ad443146 SS |
15163 | |
15164 | default_collect_info (); | |
1042e4c0 SS |
15165 | } |
15166 | ||
4a64f543 | 15167 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15168 | Not supported by all targets. */ |
15169 | static void | |
15170 | enable_trace_command (char *args, int from_tty) | |
15171 | { | |
15172 | enable_command (args, from_tty); | |
15173 | } | |
15174 | ||
4a64f543 | 15175 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15176 | Not supported by all targets. */ |
15177 | static void | |
15178 | disable_trace_command (char *args, int from_tty) | |
15179 | { | |
15180 | disable_command (args, from_tty); | |
15181 | } | |
15182 | ||
4a64f543 | 15183 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15184 | static void |
15185 | delete_trace_command (char *arg, int from_tty) | |
15186 | { | |
35df4500 | 15187 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15188 | |
15189 | dont_repeat (); | |
15190 | ||
15191 | if (arg == 0) | |
15192 | { | |
15193 | int breaks_to_delete = 0; | |
15194 | ||
15195 | /* Delete all breakpoints if no argument. | |
15196 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15197 | have to be deleted with an explicit breakpoint number |
15198 | argument. */ | |
1042e4c0 | 15199 | ALL_TRACEPOINTS (b) |
46c6471b | 15200 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15201 | { |
15202 | breaks_to_delete = 1; | |
15203 | break; | |
15204 | } | |
1042e4c0 SS |
15205 | |
15206 | /* Ask user only if there are some breakpoints to delete. */ | |
15207 | if (!from_tty | |
15208 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15209 | { | |
35df4500 | 15210 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15211 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15212 | delete_breakpoint (b); |
1042e4c0 SS |
15213 | } |
15214 | } | |
15215 | else | |
51be5b68 | 15216 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15217 | } |
15218 | ||
197f0a60 TT |
15219 | /* Helper function for trace_pass_command. */ |
15220 | ||
15221 | static void | |
d9b3f62e | 15222 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15223 | { |
d9b3f62e | 15224 | tp->pass_count = count; |
c1fc2657 | 15225 | observer_notify_breakpoint_modified (tp); |
197f0a60 TT |
15226 | if (from_tty) |
15227 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
c1fc2657 | 15228 | tp->number, count); |
197f0a60 TT |
15229 | } |
15230 | ||
1042e4c0 SS |
15231 | /* Set passcount for tracepoint. |
15232 | ||
15233 | First command argument is passcount, second is tracepoint number. | |
15234 | If tracepoint number omitted, apply to most recently defined. | |
15235 | Also accepts special argument "all". */ | |
15236 | ||
15237 | static void | |
15238 | trace_pass_command (char *args, int from_tty) | |
15239 | { | |
d9b3f62e | 15240 | struct tracepoint *t1; |
1042e4c0 | 15241 | unsigned int count; |
1042e4c0 SS |
15242 | |
15243 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15244 | error (_("passcount command requires an " |
15245 | "argument (count + optional TP num)")); | |
1042e4c0 | 15246 | |
4a64f543 | 15247 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15248 | |
529480d0 | 15249 | args = skip_spaces (args); |
1042e4c0 SS |
15250 | if (*args && strncasecmp (args, "all", 3) == 0) |
15251 | { | |
d9b3f62e PA |
15252 | struct breakpoint *b; |
15253 | ||
1042e4c0 | 15254 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15255 | if (*args) |
15256 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15257 | |
d9b3f62e | 15258 | ALL_TRACEPOINTS (b) |
197f0a60 | 15259 | { |
d9b3f62e | 15260 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15261 | trace_pass_set_count (t1, count, from_tty); |
15262 | } | |
15263 | } | |
15264 | else if (*args == '\0') | |
1042e4c0 | 15265 | { |
5fa1d40e | 15266 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15267 | if (t1) |
197f0a60 TT |
15268 | trace_pass_set_count (t1, count, from_tty); |
15269 | } | |
15270 | else | |
15271 | { | |
bfd28288 PA |
15272 | number_or_range_parser parser (args); |
15273 | while (!parser.finished ()) | |
1042e4c0 | 15274 | { |
bfd28288 | 15275 | t1 = get_tracepoint_by_number (&args, &parser); |
197f0a60 TT |
15276 | if (t1) |
15277 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15278 | } |
15279 | } | |
1042e4c0 SS |
15280 | } |
15281 | ||
d9b3f62e | 15282 | struct tracepoint * |
1042e4c0 SS |
15283 | get_tracepoint (int num) |
15284 | { | |
15285 | struct breakpoint *t; | |
15286 | ||
15287 | ALL_TRACEPOINTS (t) | |
15288 | if (t->number == num) | |
d9b3f62e | 15289 | return (struct tracepoint *) t; |
1042e4c0 SS |
15290 | |
15291 | return NULL; | |
15292 | } | |
15293 | ||
d5551862 SS |
15294 | /* Find the tracepoint with the given target-side number (which may be |
15295 | different from the tracepoint number after disconnecting and | |
15296 | reconnecting). */ | |
15297 | ||
d9b3f62e | 15298 | struct tracepoint * |
d5551862 SS |
15299 | get_tracepoint_by_number_on_target (int num) |
15300 | { | |
d9b3f62e | 15301 | struct breakpoint *b; |
d5551862 | 15302 | |
d9b3f62e PA |
15303 | ALL_TRACEPOINTS (b) |
15304 | { | |
15305 | struct tracepoint *t = (struct tracepoint *) b; | |
15306 | ||
15307 | if (t->number_on_target == num) | |
15308 | return t; | |
15309 | } | |
d5551862 SS |
15310 | |
15311 | return NULL; | |
15312 | } | |
15313 | ||
1042e4c0 | 15314 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15315 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15316 | If the argument is missing, the most recent tracepoint |
15317 | (tracepoint_count) is returned. */ | |
15318 | ||
d9b3f62e | 15319 | struct tracepoint * |
197f0a60 | 15320 | get_tracepoint_by_number (char **arg, |
bfd28288 | 15321 | number_or_range_parser *parser) |
1042e4c0 | 15322 | { |
1042e4c0 SS |
15323 | struct breakpoint *t; |
15324 | int tpnum; | |
15325 | char *instring = arg == NULL ? NULL : *arg; | |
15326 | ||
bfd28288 | 15327 | if (parser != NULL) |
197f0a60 | 15328 | { |
bfd28288 PA |
15329 | gdb_assert (!parser->finished ()); |
15330 | tpnum = parser->get_number (); | |
197f0a60 TT |
15331 | } |
15332 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15333 | tpnum = tracepoint_count; |
1042e4c0 | 15334 | else |
197f0a60 | 15335 | tpnum = get_number (arg); |
1042e4c0 SS |
15336 | |
15337 | if (tpnum <= 0) | |
15338 | { | |
15339 | if (instring && *instring) | |
15340 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15341 | instring); | |
15342 | else | |
5fa1d40e | 15343 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15344 | return NULL; |
15345 | } | |
15346 | ||
15347 | ALL_TRACEPOINTS (t) | |
15348 | if (t->number == tpnum) | |
15349 | { | |
d9b3f62e | 15350 | return (struct tracepoint *) t; |
1042e4c0 SS |
15351 | } |
15352 | ||
1042e4c0 SS |
15353 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15354 | return NULL; | |
15355 | } | |
15356 | ||
d9b3f62e PA |
15357 | void |
15358 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15359 | { | |
15360 | if (b->thread != -1) | |
15361 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15362 | ||
15363 | if (b->task != 0) | |
15364 | fprintf_unfiltered (fp, " task %d", b->task); | |
15365 | ||
15366 | fprintf_unfiltered (fp, "\n"); | |
15367 | } | |
15368 | ||
6149aea9 PA |
15369 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15370 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15371 | on each breakpoint and only include the ones for which it returns | |
15372 | non-zero. */ | |
15373 | ||
1042e4c0 | 15374 | static void |
6149aea9 PA |
15375 | save_breakpoints (char *filename, int from_tty, |
15376 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15377 | { |
15378 | struct breakpoint *tp; | |
6149aea9 | 15379 | int any = 0; |
6149aea9 | 15380 | int extra_trace_bits = 0; |
1042e4c0 | 15381 | |
6149aea9 PA |
15382 | if (filename == 0 || *filename == 0) |
15383 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15384 | |
15385 | /* See if we have anything to save. */ | |
6149aea9 | 15386 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15387 | { |
6149aea9 | 15388 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15389 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15390 | continue; |
15391 | ||
15392 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15393 | if (filter && !filter (tp)) | |
15394 | continue; | |
15395 | ||
15396 | any = 1; | |
15397 | ||
15398 | if (is_tracepoint (tp)) | |
15399 | { | |
15400 | extra_trace_bits = 1; | |
15401 | ||
15402 | /* We can stop searching. */ | |
15403 | break; | |
15404 | } | |
1042e4c0 | 15405 | } |
6149aea9 PA |
15406 | |
15407 | if (!any) | |
1042e4c0 | 15408 | { |
6149aea9 | 15409 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15410 | return; |
15411 | } | |
15412 | ||
ee0c3293 | 15413 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
d7e74731 PA |
15414 | |
15415 | stdio_file fp; | |
15416 | ||
ee0c3293 | 15417 | if (!fp.open (expanded_filename.get (), "w")) |
6149aea9 | 15418 | error (_("Unable to open file '%s' for saving (%s)"), |
ee0c3293 | 15419 | expanded_filename.get (), safe_strerror (errno)); |
8bf6485c | 15420 | |
6149aea9 | 15421 | if (extra_trace_bits) |
d7e74731 | 15422 | save_trace_state_variables (&fp); |
8bf6485c | 15423 | |
6149aea9 | 15424 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15425 | { |
6149aea9 | 15426 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15427 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15428 | continue; |
8bf6485c | 15429 | |
6149aea9 PA |
15430 | /* If we have a filter, only save the breakpoints it accepts. */ |
15431 | if (filter && !filter (tp)) | |
15432 | continue; | |
15433 | ||
d7e74731 | 15434 | tp->ops->print_recreate (tp, &fp); |
1042e4c0 | 15435 | |
6149aea9 PA |
15436 | /* Note, we can't rely on tp->number for anything, as we can't |
15437 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15438 | instead. */ | |
15439 | ||
15440 | if (tp->cond_string) | |
d7e74731 | 15441 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
6149aea9 PA |
15442 | |
15443 | if (tp->ignore_count) | |
d7e74731 | 15444 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
6149aea9 | 15445 | |
2d9442cc | 15446 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15447 | { |
d7e74731 | 15448 | fp.puts (" commands\n"); |
a7bdde9e | 15449 | |
d7e74731 | 15450 | current_uiout->redirect (&fp); |
492d29ea | 15451 | TRY |
1042e4c0 | 15452 | { |
79a45e25 | 15453 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15454 | } |
492d29ea PA |
15455 | CATCH (ex, RETURN_MASK_ALL) |
15456 | { | |
112e8700 | 15457 | current_uiout->redirect (NULL); |
492d29ea PA |
15458 | throw_exception (ex); |
15459 | } | |
15460 | END_CATCH | |
1042e4c0 | 15461 | |
112e8700 | 15462 | current_uiout->redirect (NULL); |
d7e74731 | 15463 | fp.puts (" end\n"); |
1042e4c0 | 15464 | } |
6149aea9 PA |
15465 | |
15466 | if (tp->enable_state == bp_disabled) | |
d7e74731 | 15467 | fp.puts ("disable $bpnum\n"); |
6149aea9 PA |
15468 | |
15469 | /* If this is a multi-location breakpoint, check if the locations | |
15470 | should be individually disabled. Watchpoint locations are | |
15471 | special, and not user visible. */ | |
15472 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15473 | { | |
15474 | struct bp_location *loc; | |
15475 | int n = 1; | |
15476 | ||
15477 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15478 | if (!loc->enabled) | |
d7e74731 | 15479 | fp.printf ("disable $bpnum.%d\n", n); |
6149aea9 | 15480 | } |
1042e4c0 | 15481 | } |
8bf6485c | 15482 | |
6149aea9 | 15483 | if (extra_trace_bits && *default_collect) |
d7e74731 | 15484 | fp.printf ("set default-collect %s\n", default_collect); |
8bf6485c | 15485 | |
1042e4c0 | 15486 | if (from_tty) |
ee0c3293 | 15487 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
6149aea9 PA |
15488 | } |
15489 | ||
15490 | /* The `save breakpoints' command. */ | |
15491 | ||
15492 | static void | |
15493 | save_breakpoints_command (char *args, int from_tty) | |
15494 | { | |
15495 | save_breakpoints (args, from_tty, NULL); | |
15496 | } | |
15497 | ||
15498 | /* The `save tracepoints' command. */ | |
15499 | ||
15500 | static void | |
15501 | save_tracepoints_command (char *args, int from_tty) | |
15502 | { | |
15503 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15504 | } |
15505 | ||
15506 | /* Create a vector of all tracepoints. */ | |
15507 | ||
15508 | VEC(breakpoint_p) * | |
eeae04df | 15509 | all_tracepoints (void) |
1042e4c0 SS |
15510 | { |
15511 | VEC(breakpoint_p) *tp_vec = 0; | |
15512 | struct breakpoint *tp; | |
15513 | ||
15514 | ALL_TRACEPOINTS (tp) | |
15515 | { | |
15516 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15517 | } | |
15518 | ||
15519 | return tp_vec; | |
15520 | } | |
15521 | ||
c906108c | 15522 | \f |
629500fa KS |
15523 | /* This help string is used to consolidate all the help string for specifying |
15524 | locations used by several commands. */ | |
15525 | ||
15526 | #define LOCATION_HELP_STRING \ | |
15527 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15528 | source filename, function name, label name, and line number.\n\ | |
15529 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15530 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15531 | \"factorial.c:fact:the_top\".\n\ | |
15532 | \n\ | |
15533 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15534 | program. Example: To specify the fourth byte past the start function\n\ | |
15535 | \"main\", use \"*main + 4\".\n\ | |
15536 | \n\ | |
15537 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15538 | syntax to specify location parameters.\n\ | |
15539 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15540 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15541 | -function fact -label the_top\".\n" | |
15542 | ||
4a64f543 MS |
15543 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15544 | commands. It is defined as a macro to prevent duplication. | |
15545 | COMMAND should be a string constant containing the name of the | |
15546 | command. */ | |
629500fa | 15547 | |
31e2b00f | 15548 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15549 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15550 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15551 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15552 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15553 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15554 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15555 | below.\n\ | |
15556 | \n\ | |
dc10affe PA |
15557 | With no LOCATION, uses current execution address of the selected\n\ |
15558 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15559 | \n\ |
15560 | THREADNUM is the number from \"info threads\".\n\ | |
15561 | CONDITION is a boolean expression.\n\ | |
629500fa | 15562 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15563 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15564 | conditions are different.\n\ | |
31e2b00f AS |
15565 | \n\ |
15566 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15567 | ||
44feb3ce TT |
15568 | /* List of subcommands for "catch". */ |
15569 | static struct cmd_list_element *catch_cmdlist; | |
15570 | ||
15571 | /* List of subcommands for "tcatch". */ | |
15572 | static struct cmd_list_element *tcatch_cmdlist; | |
15573 | ||
9ac4176b | 15574 | void |
a121b7c1 | 15575 | add_catch_command (const char *name, const char *docstring, |
82ae6c8d | 15576 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15577 | completer_ftype *completer, |
44feb3ce TT |
15578 | void *user_data_catch, |
15579 | void *user_data_tcatch) | |
15580 | { | |
15581 | struct cmd_list_element *command; | |
15582 | ||
15583 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15584 | &catch_cmdlist); | |
15585 | set_cmd_sfunc (command, sfunc); | |
15586 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15587 | set_cmd_completer (command, completer); |
44feb3ce TT |
15588 | |
15589 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15590 | &tcatch_cmdlist); | |
15591 | set_cmd_sfunc (command, sfunc); | |
15592 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15593 | set_cmd_completer (command, completer); |
44feb3ce TT |
15594 | } |
15595 | ||
6149aea9 PA |
15596 | static void |
15597 | save_command (char *arg, int from_tty) | |
15598 | { | |
3e43a32a MS |
15599 | printf_unfiltered (_("\"save\" must be followed by " |
15600 | "the name of a save subcommand.\n")); | |
635c7e8a | 15601 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15602 | } |
15603 | ||
84f4c1fe PM |
15604 | struct breakpoint * |
15605 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15606 | void *data) | |
15607 | { | |
35df4500 | 15608 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15609 | |
35df4500 | 15610 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15611 | { |
15612 | if ((*callback) (b, data)) | |
15613 | return b; | |
15614 | } | |
15615 | ||
15616 | return NULL; | |
15617 | } | |
15618 | ||
0574c78f GB |
15619 | /* Zero if any of the breakpoint's locations could be a location where |
15620 | functions have been inlined, nonzero otherwise. */ | |
15621 | ||
15622 | static int | |
15623 | is_non_inline_function (struct breakpoint *b) | |
15624 | { | |
15625 | /* The shared library event breakpoint is set on the address of a | |
15626 | non-inline function. */ | |
15627 | if (b->type == bp_shlib_event) | |
15628 | return 1; | |
15629 | ||
15630 | return 0; | |
15631 | } | |
15632 | ||
15633 | /* Nonzero if the specified PC cannot be a location where functions | |
15634 | have been inlined. */ | |
15635 | ||
15636 | int | |
09ac7c10 TT |
15637 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15638 | const struct target_waitstatus *ws) | |
0574c78f GB |
15639 | { |
15640 | struct breakpoint *b; | |
15641 | struct bp_location *bl; | |
15642 | ||
15643 | ALL_BREAKPOINTS (b) | |
15644 | { | |
15645 | if (!is_non_inline_function (b)) | |
15646 | continue; | |
15647 | ||
15648 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15649 | { | |
15650 | if (!bl->shlib_disabled | |
09ac7c10 | 15651 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15652 | return 1; |
15653 | } | |
15654 | } | |
15655 | ||
15656 | return 0; | |
15657 | } | |
15658 | ||
2f202fde JK |
15659 | /* Remove any references to OBJFILE which is going to be freed. */ |
15660 | ||
15661 | void | |
15662 | breakpoint_free_objfile (struct objfile *objfile) | |
15663 | { | |
15664 | struct bp_location **locp, *loc; | |
15665 | ||
15666 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15667 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15668 | loc->symtab = NULL; |
15669 | } | |
15670 | ||
2060206e PA |
15671 | void |
15672 | initialize_breakpoint_ops (void) | |
15673 | { | |
15674 | static int initialized = 0; | |
15675 | ||
15676 | struct breakpoint_ops *ops; | |
15677 | ||
15678 | if (initialized) | |
15679 | return; | |
15680 | initialized = 1; | |
15681 | ||
15682 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15683 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15684 | internal and momentary breakpoints, etc.). */ | |
15685 | ops = &bkpt_base_breakpoint_ops; | |
15686 | *ops = base_breakpoint_ops; | |
15687 | ops->re_set = bkpt_re_set; | |
15688 | ops->insert_location = bkpt_insert_location; | |
15689 | ops->remove_location = bkpt_remove_location; | |
15690 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15691 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15692 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15693 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15694 | |
15695 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15696 | ops = &bkpt_breakpoint_ops; | |
15697 | *ops = bkpt_base_breakpoint_ops; | |
15698 | ops->re_set = bkpt_re_set; | |
15699 | ops->resources_needed = bkpt_resources_needed; | |
15700 | ops->print_it = bkpt_print_it; | |
15701 | ops->print_mention = bkpt_print_mention; | |
15702 | ops->print_recreate = bkpt_print_recreate; | |
15703 | ||
15704 | /* Ranged breakpoints. */ | |
15705 | ops = &ranged_breakpoint_ops; | |
15706 | *ops = bkpt_breakpoint_ops; | |
15707 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15708 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15709 | ops->print_it = print_it_ranged_breakpoint; | |
15710 | ops->print_one = print_one_ranged_breakpoint; | |
15711 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15712 | ops->print_mention = print_mention_ranged_breakpoint; | |
15713 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15714 | ||
15715 | /* Internal breakpoints. */ | |
15716 | ops = &internal_breakpoint_ops; | |
15717 | *ops = bkpt_base_breakpoint_ops; | |
15718 | ops->re_set = internal_bkpt_re_set; | |
15719 | ops->check_status = internal_bkpt_check_status; | |
15720 | ops->print_it = internal_bkpt_print_it; | |
15721 | ops->print_mention = internal_bkpt_print_mention; | |
15722 | ||
15723 | /* Momentary breakpoints. */ | |
15724 | ops = &momentary_breakpoint_ops; | |
15725 | *ops = bkpt_base_breakpoint_ops; | |
15726 | ops->re_set = momentary_bkpt_re_set; | |
15727 | ops->check_status = momentary_bkpt_check_status; | |
15728 | ops->print_it = momentary_bkpt_print_it; | |
15729 | ops->print_mention = momentary_bkpt_print_mention; | |
15730 | ||
55aa24fb SDJ |
15731 | /* Probe breakpoints. */ |
15732 | ops = &bkpt_probe_breakpoint_ops; | |
15733 | *ops = bkpt_breakpoint_ops; | |
15734 | ops->insert_location = bkpt_probe_insert_location; | |
15735 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
15736 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
15737 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 15738 | |
2060206e PA |
15739 | /* Watchpoints. */ |
15740 | ops = &watchpoint_breakpoint_ops; | |
15741 | *ops = base_breakpoint_ops; | |
15742 | ops->re_set = re_set_watchpoint; | |
15743 | ops->insert_location = insert_watchpoint; | |
15744 | ops->remove_location = remove_watchpoint; | |
15745 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
15746 | ops->check_status = check_status_watchpoint; | |
15747 | ops->resources_needed = resources_needed_watchpoint; | |
15748 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
15749 | ops->print_it = print_it_watchpoint; | |
15750 | ops->print_mention = print_mention_watchpoint; | |
15751 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 15752 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
15753 | |
15754 | /* Masked watchpoints. */ | |
15755 | ops = &masked_watchpoint_breakpoint_ops; | |
15756 | *ops = watchpoint_breakpoint_ops; | |
15757 | ops->insert_location = insert_masked_watchpoint; | |
15758 | ops->remove_location = remove_masked_watchpoint; | |
15759 | ops->resources_needed = resources_needed_masked_watchpoint; | |
15760 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
15761 | ops->print_it = print_it_masked_watchpoint; | |
15762 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
15763 | ops->print_mention = print_mention_masked_watchpoint; | |
15764 | ops->print_recreate = print_recreate_masked_watchpoint; | |
15765 | ||
15766 | /* Tracepoints. */ | |
15767 | ops = &tracepoint_breakpoint_ops; | |
15768 | *ops = base_breakpoint_ops; | |
15769 | ops->re_set = tracepoint_re_set; | |
15770 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
15771 | ops->print_one_detail = tracepoint_print_one_detail; | |
15772 | ops->print_mention = tracepoint_print_mention; | |
15773 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 15774 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 15775 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 15776 | ops->decode_location = tracepoint_decode_location; |
983af33b | 15777 | |
55aa24fb SDJ |
15778 | /* Probe tracepoints. */ |
15779 | ops = &tracepoint_probe_breakpoint_ops; | |
15780 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
15781 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
15782 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 15783 | |
983af33b SDJ |
15784 | /* Static tracepoints with marker (`-m'). */ |
15785 | ops = &strace_marker_breakpoint_ops; | |
15786 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 15787 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 15788 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 15789 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
15790 | |
15791 | /* Fork catchpoints. */ | |
15792 | ops = &catch_fork_breakpoint_ops; | |
15793 | *ops = base_breakpoint_ops; | |
15794 | ops->insert_location = insert_catch_fork; | |
15795 | ops->remove_location = remove_catch_fork; | |
15796 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
15797 | ops->print_it = print_it_catch_fork; | |
15798 | ops->print_one = print_one_catch_fork; | |
15799 | ops->print_mention = print_mention_catch_fork; | |
15800 | ops->print_recreate = print_recreate_catch_fork; | |
15801 | ||
15802 | /* Vfork catchpoints. */ | |
15803 | ops = &catch_vfork_breakpoint_ops; | |
15804 | *ops = base_breakpoint_ops; | |
15805 | ops->insert_location = insert_catch_vfork; | |
15806 | ops->remove_location = remove_catch_vfork; | |
15807 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
15808 | ops->print_it = print_it_catch_vfork; | |
15809 | ops->print_one = print_one_catch_vfork; | |
15810 | ops->print_mention = print_mention_catch_vfork; | |
15811 | ops->print_recreate = print_recreate_catch_vfork; | |
15812 | ||
15813 | /* Exec catchpoints. */ | |
15814 | ops = &catch_exec_breakpoint_ops; | |
15815 | *ops = base_breakpoint_ops; | |
2060206e PA |
15816 | ops->insert_location = insert_catch_exec; |
15817 | ops->remove_location = remove_catch_exec; | |
15818 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
15819 | ops->print_it = print_it_catch_exec; | |
15820 | ops->print_one = print_one_catch_exec; | |
15821 | ops->print_mention = print_mention_catch_exec; | |
15822 | ops->print_recreate = print_recreate_catch_exec; | |
15823 | ||
edcc5120 TT |
15824 | /* Solib-related catchpoints. */ |
15825 | ops = &catch_solib_breakpoint_ops; | |
15826 | *ops = base_breakpoint_ops; | |
edcc5120 TT |
15827 | ops->insert_location = insert_catch_solib; |
15828 | ops->remove_location = remove_catch_solib; | |
15829 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
15830 | ops->check_status = check_status_catch_solib; | |
15831 | ops->print_it = print_it_catch_solib; | |
15832 | ops->print_one = print_one_catch_solib; | |
15833 | ops->print_mention = print_mention_catch_solib; | |
15834 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
15835 | |
15836 | ops = &dprintf_breakpoint_ops; | |
15837 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 15838 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
15839 | ops->resources_needed = bkpt_resources_needed; |
15840 | ops->print_it = bkpt_print_it; | |
15841 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 15842 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 15843 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 15844 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
15845 | } |
15846 | ||
8bfd80db YQ |
15847 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
15848 | ||
15849 | static struct cmd_list_element *enablebreaklist = NULL; | |
15850 | ||
c906108c | 15851 | void |
fba45db2 | 15852 | _initialize_breakpoint (void) |
c906108c SS |
15853 | { |
15854 | struct cmd_list_element *c; | |
15855 | ||
2060206e PA |
15856 | initialize_breakpoint_ops (); |
15857 | ||
84acb35a | 15858 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 15859 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 15860 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 15861 | |
55aa24fb SDJ |
15862 | breakpoint_objfile_key |
15863 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 15864 | |
c906108c SS |
15865 | breakpoint_chain = 0; |
15866 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
15867 | before a breakpoint is set. */ | |
15868 | breakpoint_count = 0; | |
15869 | ||
1042e4c0 SS |
15870 | tracepoint_count = 0; |
15871 | ||
1bedd215 AC |
15872 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
15873 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
15874 | Usage is `ignore N COUNT'.")); | |
c906108c | 15875 | |
1bedd215 | 15876 | add_com ("commands", class_breakpoint, commands_command, _("\ |
18da0c51 MG |
15877 | Set commands to be executed when the given breakpoints are hit.\n\ |
15878 | Give a space-separated breakpoint list as argument after \"commands\".\n\ | |
15879 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ | |
15880 | (e.g. `5-7').\n\ | |
c906108c SS |
15881 | With no argument, the targeted breakpoint is the last one set.\n\ |
15882 | The commands themselves follow starting on the next line.\n\ | |
15883 | Type a line containing \"end\" to indicate the end of them.\n\ | |
15884 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 15885 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 15886 | |
d55637df | 15887 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 15888 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 15889 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 15890 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 15891 | set_cmd_completer (c, condition_completer); |
c906108c | 15892 | |
1bedd215 | 15893 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 15894 | Set a temporary breakpoint.\n\ |
c906108c SS |
15895 | Like \"break\" except the breakpoint is only temporary,\n\ |
15896 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
15897 | by using \"enable delete\" on the breakpoint number.\n\ |
15898 | \n" | |
15899 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 15900 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 15901 | |
1bedd215 | 15902 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 15903 | Set a hardware assisted breakpoint.\n\ |
c906108c | 15904 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
15905 | some target hardware may not have this support.\n\ |
15906 | \n" | |
15907 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 15908 | set_cmd_completer (c, location_completer); |
c906108c | 15909 | |
1bedd215 | 15910 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 15911 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 15912 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
15913 | so it will be deleted when hit.\n\ |
15914 | \n" | |
15915 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 15916 | set_cmd_completer (c, location_completer); |
c906108c | 15917 | |
1bedd215 AC |
15918 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
15919 | Enable some breakpoints.\n\ | |
c906108c SS |
15920 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15921 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
15922 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15923 | With a subcommand you can enable temporarily."), |
c906108c | 15924 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
15925 | |
15926 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
15927 | ||
84951ab5 | 15928 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 15929 | Enable some breakpoints.\n\ |
c906108c SS |
15930 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
15931 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 15932 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 15933 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 15934 | |
1a966eab AC |
15935 | add_cmd ("once", no_class, enable_once_command, _("\ |
15936 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15937 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
15938 | &enablebreaklist); |
15939 | ||
1a966eab AC |
15940 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15941 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15942 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15943 | &enablebreaklist); |
15944 | ||
816338b5 SS |
15945 | add_cmd ("count", no_class, enable_count_command, _("\ |
15946 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15947 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15948 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
15949 | &enablebreaklist); | |
15950 | ||
1a966eab AC |
15951 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
15952 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
15953 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
15954 | &enablelist); |
15955 | ||
1a966eab AC |
15956 | add_cmd ("once", no_class, enable_once_command, _("\ |
15957 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
15958 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
15959 | &enablelist); |
15960 | ||
15961 | add_cmd ("count", no_class, enable_count_command, _("\ | |
15962 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
15963 | If a breakpoint is hit while enabled in this fashion,\n\ | |
15964 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
15965 | &enablelist); |
15966 | ||
1bedd215 AC |
15967 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
15968 | Disable some breakpoints.\n\ | |
c906108c SS |
15969 | Arguments are breakpoint numbers with spaces in between.\n\ |
15970 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15971 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
15972 | &disablelist, "disable ", 1, &cmdlist); |
15973 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
15974 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 15975 | |
1a966eab AC |
15976 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
15977 | Disable some breakpoints.\n\ | |
c906108c SS |
15978 | Arguments are breakpoint numbers with spaces in between.\n\ |
15979 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 15980 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 15981 | This command may be abbreviated \"disable\"."), |
c906108c SS |
15982 | &disablelist); |
15983 | ||
1bedd215 AC |
15984 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
15985 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15986 | Arguments are breakpoint numbers with spaces in between.\n\ |
15987 | To delete all breakpoints, give no argument.\n\ | |
15988 | \n\ | |
15989 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 15990 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
15991 | &deletelist, "delete ", 1, &cmdlist); |
15992 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 15993 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 15994 | |
1a966eab AC |
15995 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
15996 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
15997 | Arguments are breakpoint numbers with spaces in between.\n\ |
15998 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 15999 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16000 | &deletelist); |
16001 | ||
1bedd215 | 16002 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16003 | Clear breakpoint at specified location.\n\ |
16004 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16005 | \n\ |
16006 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16007 | is executing in.\n" |
16008 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16009 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16010 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16011 | |
1bedd215 | 16012 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16013 | Set breakpoint at specified location.\n" |
31e2b00f | 16014 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16015 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16016 | |
c906108c SS |
16017 | add_com_alias ("b", "break", class_run, 1); |
16018 | add_com_alias ("br", "break", class_run, 1); | |
16019 | add_com_alias ("bre", "break", class_run, 1); | |
16020 | add_com_alias ("brea", "break", class_run, 1); | |
16021 | ||
c906108c SS |
16022 | if (dbx_commands) |
16023 | { | |
1bedd215 AC |
16024 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16025 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16026 | &stoplist, "stop ", 1, &cmdlist); |
16027 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16028 | _("Break in function or address."), &stoplist); |
c5aa993b | 16029 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16030 | _("Break at a line in the current file."), &stoplist); |
11db9430 | 16031 | add_com ("status", class_info, info_breakpoints_command, _("\ |
1bedd215 | 16032 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
c906108c SS |
16033 | The \"Type\" column indicates one of:\n\ |
16034 | \tbreakpoint - normal breakpoint\n\ | |
16035 | \twatchpoint - watchpoint\n\ | |
16036 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16037 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16038 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16039 | address and file/line number respectively.\n\ |
16040 | \n\ | |
16041 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16042 | are set to the address of the last breakpoint listed unless the command\n\ |
16043 | is prefixed with \"server \".\n\n\ | |
c906108c | 16044 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16045 | breakpoint set.")); |
c906108c SS |
16046 | } |
16047 | ||
11db9430 | 16048 | add_info ("breakpoints", info_breakpoints_command, _("\ |
e5a67952 | 16049 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16050 | The \"Type\" column indicates one of:\n\ |
16051 | \tbreakpoint - normal breakpoint\n\ | |
16052 | \twatchpoint - watchpoint\n\ | |
16053 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16054 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16055 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16056 | address and file/line number respectively.\n\ |
16057 | \n\ | |
16058 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16059 | are set to the address of the last breakpoint listed unless the command\n\ |
16060 | is prefixed with \"server \".\n\n\ | |
c906108c | 16061 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16062 | breakpoint set.")); |
c906108c | 16063 | |
6b04bdb7 MS |
16064 | add_info_alias ("b", "breakpoints", 1); |
16065 | ||
1a966eab AC |
16066 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16067 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16068 | The \"Type\" column indicates one of:\n\ |
16069 | \tbreakpoint - normal breakpoint\n\ | |
16070 | \twatchpoint - watchpoint\n\ | |
16071 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16072 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16073 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16074 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16075 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16076 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16077 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16078 | address and file/line number respectively.\n\ |
16079 | \n\ | |
16080 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16081 | are set to the address of the last breakpoint listed unless the command\n\ |
16082 | is prefixed with \"server \".\n\n\ | |
c906108c | 16083 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16084 | breakpoint set."), |
c906108c SS |
16085 | &maintenanceinfolist); |
16086 | ||
44feb3ce TT |
16087 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16088 | Set catchpoints to catch events."), | |
16089 | &catch_cmdlist, "catch ", | |
16090 | 0/*allow-unknown*/, &cmdlist); | |
16091 | ||
16092 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16093 | Set temporary catchpoints to catch events."), | |
16094 | &tcatch_cmdlist, "tcatch ", | |
16095 | 0/*allow-unknown*/, &cmdlist); | |
16096 | ||
44feb3ce TT |
16097 | add_catch_command ("fork", _("Catch calls to fork."), |
16098 | catch_fork_command_1, | |
a96d9b2e | 16099 | NULL, |
44feb3ce TT |
16100 | (void *) (uintptr_t) catch_fork_permanent, |
16101 | (void *) (uintptr_t) catch_fork_temporary); | |
16102 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16103 | catch_fork_command_1, | |
a96d9b2e | 16104 | NULL, |
44feb3ce TT |
16105 | (void *) (uintptr_t) catch_vfork_permanent, |
16106 | (void *) (uintptr_t) catch_vfork_temporary); | |
16107 | add_catch_command ("exec", _("Catch calls to exec."), | |
16108 | catch_exec_command_1, | |
a96d9b2e SDJ |
16109 | NULL, |
16110 | CATCH_PERMANENT, | |
16111 | CATCH_TEMPORARY); | |
edcc5120 TT |
16112 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16113 | Usage: catch load [REGEX]\n\ | |
16114 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16115 | catch_load_command_1, | |
16116 | NULL, | |
16117 | CATCH_PERMANENT, | |
16118 | CATCH_TEMPORARY); | |
16119 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16120 | Usage: catch unload [REGEX]\n\ | |
16121 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16122 | catch_unload_command_1, | |
16123 | NULL, | |
16124 | CATCH_PERMANENT, | |
16125 | CATCH_TEMPORARY); | |
c5aa993b | 16126 | |
1bedd215 AC |
16127 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16128 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16129 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16130 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16131 | an expression changes.\n\ |
16132 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16133 | the memory to which it refers.")); | |
65d12d83 | 16134 | set_cmd_completer (c, expression_completer); |
c906108c | 16135 | |
1bedd215 AC |
16136 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16137 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16138 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16139 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16140 | an expression is read.\n\ |
16141 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16142 | the memory to which it refers.")); | |
65d12d83 | 16143 | set_cmd_completer (c, expression_completer); |
c906108c | 16144 | |
1bedd215 AC |
16145 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16146 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16147 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16148 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16149 | an expression is either read or written.\n\ |
16150 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16151 | the memory to which it refers.")); | |
65d12d83 | 16152 | set_cmd_completer (c, expression_completer); |
c906108c | 16153 | |
11db9430 | 16154 | add_info ("watchpoints", info_watchpoints_command, _("\ |
e5a67952 | 16155 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16156 | |
920d2a44 AC |
16157 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16158 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16159 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16160 | &can_use_hw_watchpoints, _("\ | |
16161 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16162 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16163 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16164 | such is available. (However, any hardware watchpoints that were\n\ | |
16165 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16166 | hardware.)"), |
16167 | NULL, | |
920d2a44 | 16168 | show_can_use_hw_watchpoints, |
85c07804 | 16169 | &setlist, &showlist); |
c906108c SS |
16170 | |
16171 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16172 | |
1042e4c0 SS |
16173 | /* Tracepoint manipulation commands. */ |
16174 | ||
16175 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16176 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16177 | \n" |
16178 | BREAK_ARGS_HELP ("trace") "\n\ | |
16179 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16180 | set_cmd_completer (c, location_completer); | |
16181 | ||
16182 | add_com_alias ("tp", "trace", class_alias, 0); | |
16183 | add_com_alias ("tr", "trace", class_alias, 1); | |
16184 | add_com_alias ("tra", "trace", class_alias, 1); | |
16185 | add_com_alias ("trac", "trace", class_alias, 1); | |
16186 | ||
7a697b8d | 16187 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16188 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16189 | \n" |
16190 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16191 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16192 | set_cmd_completer (c, location_completer); | |
16193 | ||
0fb4aa4b | 16194 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16195 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16196 | \n\ |
16197 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16198 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16199 | or -m MARKER_ID.\n\n\ | |
16200 | If a marker id is specified, probe the marker with that name. With\n\ | |
16201 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16202 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16203 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16204 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16205 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16206 | \n\ | |
16207 | CONDITION is a boolean expression.\n\ | |
629500fa | 16208 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16209 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16210 | conditions are different.\n\ | |
0fb4aa4b PA |
16211 | \n\ |
16212 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16213 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16214 | set_cmd_completer (c, location_completer); | |
16215 | ||
11db9430 | 16216 | add_info ("tracepoints", info_tracepoints_command, _("\ |
e5a67952 | 16217 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16218 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16219 | last tracepoint set.")); | |
16220 | ||
16221 | add_info_alias ("tp", "tracepoints", 1); | |
16222 | ||
16223 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16224 | Delete specified tracepoints.\n\ | |
16225 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16226 | No argument means delete all tracepoints."), | |
16227 | &deletelist); | |
7e20dfcd | 16228 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16229 | |
16230 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16231 | Disable specified tracepoints.\n\ | |
16232 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16233 | No argument means disable all tracepoints."), | |
16234 | &disablelist); | |
16235 | deprecate_cmd (c, "disable"); | |
16236 | ||
16237 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16238 | Enable specified tracepoints.\n\ | |
16239 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16240 | No argument means enable all tracepoints."), | |
16241 | &enablelist); | |
16242 | deprecate_cmd (c, "enable"); | |
16243 | ||
16244 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16245 | Set the passcount for a tracepoint.\n\ | |
16246 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16247 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16248 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16249 | ||
6149aea9 PA |
16250 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16251 | _("Save breakpoint definitions as a script."), | |
16252 | &save_cmdlist, "save ", | |
16253 | 0/*allow-unknown*/, &cmdlist); | |
16254 | ||
16255 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16256 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16257 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16258 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16259 | session to restore them."), | |
16260 | &save_cmdlist); | |
16261 | set_cmd_completer (c, filename_completer); | |
16262 | ||
16263 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16264 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16265 | Use the 'source' command in another debug session to restore them."), |
16266 | &save_cmdlist); | |
1042e4c0 SS |
16267 | set_cmd_completer (c, filename_completer); |
16268 | ||
6149aea9 PA |
16269 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16270 | deprecate_cmd (c, "save tracepoints"); | |
16271 | ||
1bedd215 | 16272 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16273 | Breakpoint specific settings\n\ |
16274 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16275 | pending breakpoint behavior"), |
fa8d40ab JJ |
16276 | &breakpoint_set_cmdlist, "set breakpoint ", |
16277 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16278 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16279 | Breakpoint specific settings\n\ |
16280 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16281 | pending breakpoint behavior"), |
fa8d40ab JJ |
16282 | &breakpoint_show_cmdlist, "show breakpoint ", |
16283 | 0/*allow-unknown*/, &showlist); | |
16284 | ||
7915a72c AC |
16285 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16286 | &pending_break_support, _("\ | |
16287 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16288 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16289 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16290 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16291 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16292 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16293 | NULL, |
920d2a44 | 16294 | show_pending_break_support, |
6e1d7d6c AC |
16295 | &breakpoint_set_cmdlist, |
16296 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16297 | |
16298 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16299 | |
16300 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16301 | &automatic_hardware_breakpoints, _("\ | |
16302 | Set automatic usage of hardware breakpoints."), _("\ | |
16303 | Show automatic usage of hardware breakpoints."), _("\ | |
16304 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16305 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16306 | a warning will be emitted for such breakpoints."), | |
16307 | NULL, | |
16308 | show_automatic_hardware_breakpoints, | |
16309 | &breakpoint_set_cmdlist, | |
16310 | &breakpoint_show_cmdlist); | |
74960c60 | 16311 | |
a25a5a45 PA |
16312 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16313 | &always_inserted_mode, _("\ | |
74960c60 VP |
16314 | Set mode for inserting breakpoints."), _("\ |
16315 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16316 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16317 | they're created, kept inserted even when execution stops, and removed\n\ | |
16318 | only when the user deletes them. When this mode is off (the default),\n\ | |
16319 | breakpoints are inserted only when execution continues, and removed\n\ | |
16320 | when execution stops."), | |
72d0e2c5 YQ |
16321 | NULL, |
16322 | &show_always_inserted_mode, | |
16323 | &breakpoint_set_cmdlist, | |
16324 | &breakpoint_show_cmdlist); | |
f1310107 | 16325 | |
b775012e LM |
16326 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16327 | condition_evaluation_enums, | |
16328 | &condition_evaluation_mode_1, _("\ | |
16329 | Set mode of breakpoint condition evaluation."), _("\ | |
16330 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16331 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16332 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16333 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16334 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16335 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16336 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16337 | be set to \"gdb\""), | |
16338 | &set_condition_evaluation_mode, | |
16339 | &show_condition_evaluation_mode, | |
16340 | &breakpoint_set_cmdlist, | |
16341 | &breakpoint_show_cmdlist); | |
16342 | ||
f1310107 TJB |
16343 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16344 | Set a breakpoint for an address range.\n\ | |
16345 | break-range START-LOCATION, END-LOCATION\n\ | |
16346 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16347 | LINENUM, for that line in the current file,\n\ | |
16348 | FILE:LINENUM, for that line in that file,\n\ | |
16349 | +OFFSET, for that number of lines after the current line\n\ | |
16350 | or the start of the range\n\ | |
16351 | FUNCTION, for the first line in that function,\n\ | |
16352 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16353 | *ADDRESS, for the instruction at that address.\n\ | |
16354 | \n\ | |
16355 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16356 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16357 | range (including START-LOCATION and END-LOCATION).")); | |
16358 | ||
e7e0cddf | 16359 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16360 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16361 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16362 | location may be a linespec, explicit, or address location.\n" |
16363 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16364 | set_cmd_completer (c, location_completer); |
16365 | ||
16366 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16367 | dprintf_style_enums, &dprintf_style, _("\ | |
16368 | Set the style of usage for dynamic printf."), _("\ | |
16369 | Show the style of usage for dynamic printf."), _("\ | |
16370 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16371 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16372 | console, as with the \"printf\" command.\n\ | |
16373 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16374 | program; by default printf(), but you can choose a different function or\n\ | |
16375 | output stream by setting dprintf-function and dprintf-channel."), | |
16376 | update_dprintf_commands, NULL, | |
16377 | &setlist, &showlist); | |
16378 | ||
16379 | dprintf_function = xstrdup ("printf"); | |
16380 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16381 | &dprintf_function, _("\ | |
16382 | Set the function to use for dynamic printf"), _("\ | |
16383 | Show the function to use for dynamic printf"), NULL, | |
16384 | update_dprintf_commands, NULL, | |
16385 | &setlist, &showlist); | |
16386 | ||
16387 | dprintf_channel = xstrdup (""); | |
16388 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16389 | &dprintf_channel, _("\ | |
16390 | Set the channel to use for dynamic printf"), _("\ | |
16391 | Show the channel to use for dynamic printf"), NULL, | |
16392 | update_dprintf_commands, NULL, | |
16393 | &setlist, &showlist); | |
16394 | ||
d3ce09f5 SS |
16395 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16396 | &disconnected_dprintf, _("\ | |
16397 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16398 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16399 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16400 | even if GDB disconnects or detaches from the target."), | |
16401 | NULL, | |
16402 | NULL, | |
16403 | &setlist, &showlist); | |
16404 | ||
16405 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16406 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16407 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16408 | ||
765dc015 | 16409 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16410 | |
16411 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16412 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16413 | } |