Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
618f726f | 3 | Copyright (C) 1986-2016 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" |
f00aae0f | 70 | #include "location.h" |
cfc31633 | 71 | #include "thread-fsm.h" |
5d5658a1 | 72 | #include "tid-parse.h" |
d3ce09f5 | 73 | |
1042e4c0 SS |
74 | /* readline include files */ |
75 | #include "readline/readline.h" | |
76 | #include "readline/history.h" | |
77 | ||
78 | /* readline defines this. */ | |
79 | #undef savestring | |
80 | ||
034dad6f | 81 | #include "mi/mi-common.h" |
6dddc817 | 82 | #include "extension.h" |
104c1213 | 83 | |
e7e8980f YQ |
84 | /* Enums for exception-handling support. */ |
85 | enum exception_event_kind | |
86 | { | |
87 | EX_EVENT_THROW, | |
591f19e8 | 88 | EX_EVENT_RETHROW, |
e7e8980f YQ |
89 | EX_EVENT_CATCH |
90 | }; | |
91 | ||
4a64f543 | 92 | /* Prototypes for local functions. */ |
c906108c | 93 | |
a14ed312 | 94 | static void enable_delete_command (char *, int); |
c906108c | 95 | |
a14ed312 | 96 | static void enable_once_command (char *, int); |
c906108c | 97 | |
816338b5 SS |
98 | static void enable_count_command (char *, int); |
99 | ||
a14ed312 | 100 | static void disable_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void enable_command (char *, int); |
c906108c | 103 | |
95a42b64 TT |
104 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
105 | void *), | |
106 | void *); | |
c906108c | 107 | |
a14ed312 | 108 | static void ignore_command (char *, int); |
c906108c | 109 | |
4efb68b1 | 110 | static int breakpoint_re_set_one (void *); |
c906108c | 111 | |
348d480f PA |
112 | static void breakpoint_re_set_default (struct breakpoint *); |
113 | ||
f00aae0f KS |
114 | static void |
115 | create_sals_from_location_default (const struct event_location *location, | |
116 | struct linespec_result *canonical, | |
117 | enum bptype type_wanted); | |
983af33b SDJ |
118 | |
119 | static void create_breakpoints_sal_default (struct gdbarch *, | |
120 | struct linespec_result *, | |
e7e0cddf | 121 | char *, char *, enum bptype, |
983af33b SDJ |
122 | enum bpdisp, int, int, |
123 | int, | |
124 | const struct breakpoint_ops *, | |
44f238bb | 125 | int, int, int, unsigned); |
983af33b | 126 | |
f00aae0f KS |
127 | static void decode_location_default (struct breakpoint *b, |
128 | const struct event_location *location, | |
c2f4122d | 129 | struct program_space *search_pspace, |
f00aae0f | 130 | struct symtabs_and_lines *sals); |
983af33b | 131 | |
a14ed312 | 132 | static void clear_command (char *, int); |
c906108c | 133 | |
a14ed312 | 134 | static void catch_command (char *, int); |
c906108c | 135 | |
a9634178 | 136 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 137 | |
98deb0da | 138 | static void break_command_1 (char *, int, int); |
c906108c | 139 | |
a14ed312 | 140 | static void mention (struct breakpoint *); |
c906108c | 141 | |
348d480f PA |
142 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
143 | enum bptype, | |
c0a91b2b | 144 | const struct breakpoint_ops *); |
3742cc8b YQ |
145 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
146 | const struct symtab_and_line *); | |
147 | ||
4a64f543 MS |
148 | /* This function is used in gdbtk sources and thus can not be made |
149 | static. */ | |
63c252f8 | 150 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 151 | struct symtab_and_line, |
c0a91b2b TT |
152 | enum bptype, |
153 | const struct breakpoint_ops *); | |
c906108c | 154 | |
06edf0c0 PA |
155 | static struct breakpoint * |
156 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
157 | enum bptype type, | |
a1aa2221 LM |
158 | const struct breakpoint_ops *ops, |
159 | int loc_enabled); | |
06edf0c0 | 160 | |
76897487 KB |
161 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
162 | ||
a6d9a66e UW |
163 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
164 | CORE_ADDR bpaddr, | |
88f7da05 | 165 | enum bptype bptype); |
76897487 | 166 | |
6c95b8df PA |
167 | static void describe_other_breakpoints (struct gdbarch *, |
168 | struct program_space *, CORE_ADDR, | |
5af949e3 | 169 | struct obj_section *, int); |
c906108c | 170 | |
85d721b8 PA |
171 | static int watchpoint_locations_match (struct bp_location *loc1, |
172 | struct bp_location *loc2); | |
173 | ||
f1310107 TJB |
174 | static int breakpoint_location_address_match (struct bp_location *bl, |
175 | struct address_space *aspace, | |
176 | CORE_ADDR addr); | |
177 | ||
d35ae833 PA |
178 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
179 | struct address_space *, | |
180 | CORE_ADDR, int); | |
181 | ||
a14ed312 | 182 | static void breakpoints_info (char *, int); |
c906108c | 183 | |
d77f58be SS |
184 | static void watchpoints_info (char *, int); |
185 | ||
e5a67952 MS |
186 | static int breakpoint_1 (char *, int, |
187 | int (*) (const struct breakpoint *)); | |
c906108c | 188 | |
4efb68b1 | 189 | static int breakpoint_cond_eval (void *); |
c906108c | 190 | |
4efb68b1 | 191 | static void cleanup_executing_breakpoints (void *); |
c906108c | 192 | |
a14ed312 | 193 | static void commands_command (char *, int); |
c906108c | 194 | |
a14ed312 | 195 | static void condition_command (char *, int); |
c906108c | 196 | |
c5aa993b JM |
197 | typedef enum |
198 | { | |
199 | mark_inserted, | |
200 | mark_uninserted | |
201 | } | |
202 | insertion_state_t; | |
c906108c | 203 | |
0bde7532 | 204 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 205 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 206 | |
e514a9d6 | 207 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 208 | |
4efb68b1 | 209 | static int watchpoint_check (void *); |
c906108c | 210 | |
a14ed312 | 211 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 212 | |
a14ed312 | 213 | static int hw_breakpoint_used_count (void); |
c906108c | 214 | |
a1398e0c PA |
215 | static int hw_watchpoint_use_count (struct breakpoint *); |
216 | ||
217 | static int hw_watchpoint_used_count_others (struct breakpoint *except, | |
218 | enum bptype type, | |
219 | int *other_type_used); | |
c906108c | 220 | |
a14ed312 | 221 | static void hbreak_command (char *, int); |
c906108c | 222 | |
a14ed312 | 223 | static void thbreak_command (char *, int); |
c906108c | 224 | |
816338b5 SS |
225 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
226 | int count); | |
c906108c | 227 | |
a14ed312 | 228 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 229 | |
a14ed312 | 230 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 231 | |
a14ed312 | 232 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 233 | |
a14ed312 | 234 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 235 | |
fe3f5fa8 | 236 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
237 | static void incref_bp_location (struct bp_location *loc); |
238 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 239 | |
39d61571 | 240 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 241 | |
44702360 PA |
242 | /* update_global_location_list's modes of operation wrt to whether to |
243 | insert locations now. */ | |
244 | enum ugll_insert_mode | |
245 | { | |
246 | /* Don't insert any breakpoint locations into the inferior, only | |
247 | remove already-inserted locations that no longer should be | |
248 | inserted. Functions that delete a breakpoint or breakpoints | |
249 | should specify this mode, so that deleting a breakpoint doesn't | |
250 | have the side effect of inserting the locations of other | |
251 | breakpoints that are marked not-inserted, but should_be_inserted | |
252 | returns true on them. | |
253 | ||
254 | This behavior is useful is situations close to tear-down -- e.g., | |
255 | after an exec, while the target still has execution, but | |
256 | breakpoint shadows of the previous executable image should *NOT* | |
257 | be restored to the new image; or before detaching, where the | |
258 | target still has execution and wants to delete breakpoints from | |
259 | GDB's lists, and all breakpoints had already been removed from | |
260 | the inferior. */ | |
261 | UGLL_DONT_INSERT, | |
262 | ||
a25a5a45 PA |
263 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
264 | claims breakpoints should be inserted now. */ | |
04086b45 PA |
265 | UGLL_MAY_INSERT, |
266 | ||
a25a5a45 PA |
267 | /* Insert locations now, irrespective of |
268 | breakpoints_should_be_inserted_now. E.g., say all threads are | |
269 | stopped right now, and the user did "continue". We need to | |
270 | insert breakpoints _before_ resuming the target, but | |
271 | UGLL_MAY_INSERT wouldn't insert them, because | |
272 | breakpoints_should_be_inserted_now returns false at that point, | |
273 | as no thread is running yet. */ | |
04086b45 | 274 | UGLL_INSERT |
44702360 PA |
275 | }; |
276 | ||
277 | static void update_global_location_list (enum ugll_insert_mode); | |
a5606eee | 278 | |
44702360 | 279 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
74960c60 | 280 | |
d77f58be | 281 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
282 | |
283 | static void insert_breakpoint_locations (void); | |
a5606eee | 284 | |
1042e4c0 SS |
285 | static void tracepoints_info (char *, int); |
286 | ||
287 | static void delete_trace_command (char *, int); | |
288 | ||
289 | static void enable_trace_command (char *, int); | |
290 | ||
291 | static void disable_trace_command (char *, int); | |
292 | ||
293 | static void trace_pass_command (char *, int); | |
294 | ||
558a9d82 YQ |
295 | static void set_tracepoint_count (int num); |
296 | ||
9c06b0b4 TJB |
297 | static int is_masked_watchpoint (const struct breakpoint *b); |
298 | ||
b775012e LM |
299 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
300 | ||
983af33b SDJ |
301 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
302 | otherwise. */ | |
303 | ||
304 | static int strace_marker_p (struct breakpoint *b); | |
0fb4aa4b | 305 | |
2060206e PA |
306 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
307 | that are implemented on top of software or hardware breakpoints | |
308 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
309 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
310 | ||
311 | /* Internal breakpoints class type. */ | |
06edf0c0 | 312 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
313 | |
314 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
315 | static struct breakpoint_ops momentary_breakpoint_ops; |
316 | ||
e2e4d78b JK |
317 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
318 | static struct breakpoint_ops longjmp_breakpoint_ops; | |
319 | ||
2060206e PA |
320 | /* The breakpoint_ops structure to be used in regular user created |
321 | breakpoints. */ | |
322 | struct breakpoint_ops bkpt_breakpoint_ops; | |
323 | ||
55aa24fb SDJ |
324 | /* Breakpoints set on probes. */ |
325 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; | |
326 | ||
e7e0cddf | 327 | /* Dynamic printf class type. */ |
c5867ab6 | 328 | struct breakpoint_ops dprintf_breakpoint_ops; |
e7e0cddf | 329 | |
d3ce09f5 SS |
330 | /* The style in which to perform a dynamic printf. This is a user |
331 | option because different output options have different tradeoffs; | |
332 | if GDB does the printing, there is better error handling if there | |
333 | is a problem with any of the arguments, but using an inferior | |
334 | function lets you have special-purpose printers and sending of | |
335 | output to the same place as compiled-in print functions. */ | |
336 | ||
337 | static const char dprintf_style_gdb[] = "gdb"; | |
338 | static const char dprintf_style_call[] = "call"; | |
339 | static const char dprintf_style_agent[] = "agent"; | |
340 | static const char *const dprintf_style_enums[] = { | |
341 | dprintf_style_gdb, | |
342 | dprintf_style_call, | |
343 | dprintf_style_agent, | |
344 | NULL | |
345 | }; | |
346 | static const char *dprintf_style = dprintf_style_gdb; | |
347 | ||
348 | /* The function to use for dynamic printf if the preferred style is to | |
349 | call into the inferior. The value is simply a string that is | |
350 | copied into the command, so it can be anything that GDB can | |
351 | evaluate to a callable address, not necessarily a function name. */ | |
352 | ||
353 | static char *dprintf_function = ""; | |
354 | ||
355 | /* The channel to use for dynamic printf if the preferred style is to | |
356 | call into the inferior; if a nonempty string, it will be passed to | |
357 | the call as the first argument, with the format string as the | |
358 | second. As with the dprintf function, this can be anything that | |
359 | GDB knows how to evaluate, so in addition to common choices like | |
360 | "stderr", this could be an app-specific expression like | |
361 | "mystreams[curlogger]". */ | |
362 | ||
363 | static char *dprintf_channel = ""; | |
364 | ||
365 | /* True if dprintf commands should continue to operate even if GDB | |
366 | has disconnected. */ | |
367 | static int disconnected_dprintf = 1; | |
368 | ||
5cea2a26 PA |
369 | /* A reference-counted struct command_line. This lets multiple |
370 | breakpoints share a single command list. */ | |
371 | struct counted_command_line | |
372 | { | |
373 | /* The reference count. */ | |
374 | int refc; | |
375 | ||
376 | /* The command list. */ | |
377 | struct command_line *commands; | |
378 | }; | |
379 | ||
380 | struct command_line * | |
381 | breakpoint_commands (struct breakpoint *b) | |
382 | { | |
383 | return b->commands ? b->commands->commands : NULL; | |
384 | } | |
3daf8fe5 | 385 | |
f3b1572e PA |
386 | /* Flag indicating that a command has proceeded the inferior past the |
387 | current breakpoint. */ | |
388 | ||
389 | static int breakpoint_proceeded; | |
390 | ||
956a9fb9 | 391 | const char * |
2cec12e5 AR |
392 | bpdisp_text (enum bpdisp disp) |
393 | { | |
4a64f543 MS |
394 | /* NOTE: the following values are a part of MI protocol and |
395 | represent values of 'disp' field returned when inferior stops at | |
396 | a breakpoint. */ | |
bc043ef3 | 397 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 398 | |
2cec12e5 AR |
399 | return bpdisps[(int) disp]; |
400 | } | |
c906108c | 401 | |
4a64f543 | 402 | /* Prototypes for exported functions. */ |
c906108c | 403 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 404 | if such is available. */ |
c906108c SS |
405 | static int can_use_hw_watchpoints; |
406 | ||
920d2a44 AC |
407 | static void |
408 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
409 | struct cmd_list_element *c, | |
410 | const char *value) | |
411 | { | |
3e43a32a MS |
412 | fprintf_filtered (file, |
413 | _("Debugger's willingness to use " | |
414 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
415 | value); |
416 | } | |
417 | ||
fa8d40ab JJ |
418 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
419 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 420 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
421 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
422 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
423 | static void |
424 | show_pending_break_support (struct ui_file *file, int from_tty, | |
425 | struct cmd_list_element *c, | |
426 | const char *value) | |
427 | { | |
3e43a32a MS |
428 | fprintf_filtered (file, |
429 | _("Debugger's behavior regarding " | |
430 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
431 | value); |
432 | } | |
fa8d40ab | 433 | |
765dc015 | 434 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 435 | set with "break" but falling in read-only memory. |
765dc015 VP |
436 | If 0, gdb will warn about such breakpoints, but won't automatically |
437 | use hardware breakpoints. */ | |
438 | static int automatic_hardware_breakpoints; | |
439 | static void | |
440 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
441 | struct cmd_list_element *c, | |
442 | const char *value) | |
443 | { | |
3e43a32a MS |
444 | fprintf_filtered (file, |
445 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
446 | value); |
447 | } | |
448 | ||
a25a5a45 PA |
449 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
450 | stopped, and immediately inserts any new breakpoints as soon as | |
451 | they're created. If off (default), GDB keeps breakpoints off of | |
452 | the target as long as possible. That is, it delays inserting | |
453 | breakpoints until the next resume, and removes them again when the | |
454 | target fully stops. This is a bit safer in case GDB crashes while | |
455 | processing user input. */ | |
456 | static int always_inserted_mode = 0; | |
72d0e2c5 | 457 | |
33e5cbd6 | 458 | static void |
74960c60 | 459 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 460 | struct cmd_list_element *c, const char *value) |
74960c60 | 461 | { |
a25a5a45 PA |
462 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
463 | value); | |
74960c60 VP |
464 | } |
465 | ||
b57bacec PA |
466 | /* See breakpoint.h. */ |
467 | ||
33e5cbd6 | 468 | int |
a25a5a45 | 469 | breakpoints_should_be_inserted_now (void) |
33e5cbd6 | 470 | { |
a25a5a45 PA |
471 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
472 | { | |
473 | /* If breakpoints are global, they should be inserted even if no | |
474 | thread under gdb's control is running, or even if there are | |
475 | no threads under GDB's control yet. */ | |
476 | return 1; | |
477 | } | |
478 | else if (target_has_execution) | |
479 | { | |
372316f1 PA |
480 | struct thread_info *tp; |
481 | ||
a25a5a45 PA |
482 | if (always_inserted_mode) |
483 | { | |
484 | /* The user wants breakpoints inserted even if all threads | |
485 | are stopped. */ | |
486 | return 1; | |
487 | } | |
488 | ||
b57bacec PA |
489 | if (threads_are_executing ()) |
490 | return 1; | |
372316f1 PA |
491 | |
492 | /* Don't remove breakpoints yet if, even though all threads are | |
493 | stopped, we still have events to process. */ | |
494 | ALL_NON_EXITED_THREADS (tp) | |
495 | if (tp->resumed | |
496 | && tp->suspend.waitstatus_pending_p) | |
497 | return 1; | |
a25a5a45 PA |
498 | } |
499 | return 0; | |
33e5cbd6 | 500 | } |
765dc015 | 501 | |
b775012e LM |
502 | static const char condition_evaluation_both[] = "host or target"; |
503 | ||
504 | /* Modes for breakpoint condition evaluation. */ | |
505 | static const char condition_evaluation_auto[] = "auto"; | |
506 | static const char condition_evaluation_host[] = "host"; | |
507 | static const char condition_evaluation_target[] = "target"; | |
508 | static const char *const condition_evaluation_enums[] = { | |
509 | condition_evaluation_auto, | |
510 | condition_evaluation_host, | |
511 | condition_evaluation_target, | |
512 | NULL | |
513 | }; | |
514 | ||
515 | /* Global that holds the current mode for breakpoint condition evaluation. */ | |
516 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; | |
517 | ||
518 | /* Global that we use to display information to the user (gets its value from | |
519 | condition_evaluation_mode_1. */ | |
520 | static const char *condition_evaluation_mode = condition_evaluation_auto; | |
521 | ||
522 | /* Translate a condition evaluation mode MODE into either "host" | |
523 | or "target". This is used mostly to translate from "auto" to the | |
524 | real setting that is being used. It returns the translated | |
525 | evaluation mode. */ | |
526 | ||
527 | static const char * | |
528 | translate_condition_evaluation_mode (const char *mode) | |
529 | { | |
530 | if (mode == condition_evaluation_auto) | |
531 | { | |
532 | if (target_supports_evaluation_of_breakpoint_conditions ()) | |
533 | return condition_evaluation_target; | |
534 | else | |
535 | return condition_evaluation_host; | |
536 | } | |
537 | else | |
538 | return mode; | |
539 | } | |
540 | ||
541 | /* Discovers what condition_evaluation_auto translates to. */ | |
542 | ||
543 | static const char * | |
544 | breakpoint_condition_evaluation_mode (void) | |
545 | { | |
546 | return translate_condition_evaluation_mode (condition_evaluation_mode); | |
547 | } | |
548 | ||
549 | /* Return true if GDB should evaluate breakpoint conditions or false | |
550 | otherwise. */ | |
551 | ||
552 | static int | |
553 | gdb_evaluates_breakpoint_condition_p (void) | |
554 | { | |
555 | const char *mode = breakpoint_condition_evaluation_mode (); | |
556 | ||
557 | return (mode == condition_evaluation_host); | |
558 | } | |
559 | ||
a14ed312 | 560 | void _initialize_breakpoint (void); |
c906108c | 561 | |
c906108c SS |
562 | /* Are we executing breakpoint commands? */ |
563 | static int executing_breakpoint_commands; | |
564 | ||
c02f5703 MS |
565 | /* Are overlay event breakpoints enabled? */ |
566 | static int overlay_events_enabled; | |
567 | ||
e09342b5 TJB |
568 | /* See description in breakpoint.h. */ |
569 | int target_exact_watchpoints = 0; | |
570 | ||
c906108c | 571 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 572 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 573 | current breakpoint. */ |
c906108c | 574 | |
5c44784c | 575 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 576 | |
5c44784c JM |
577 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
578 | for (B = breakpoint_chain; \ | |
579 | B ? (TMP=B->next, 1): 0; \ | |
580 | B = TMP) | |
c906108c | 581 | |
4a64f543 MS |
582 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
583 | not provided so update_global_location_list must not be called | |
584 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 585 | |
876fa593 JK |
586 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
587 | for (BP_TMP = bp_location; \ | |
588 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
589 | BP_TMP++) | |
7cc221ef | 590 | |
b775012e LM |
591 | /* Iterates through locations with address ADDRESS for the currently selected |
592 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points | |
593 | to where the loop should start from. | |
594 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the | |
595 | appropriate location to start with. */ | |
596 | ||
597 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ | |
598 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ | |
599 | BP_LOCP_TMP = BP_LOCP_START; \ | |
600 | BP_LOCP_START \ | |
601 | && (BP_LOCP_TMP < bp_location + bp_location_count \ | |
602 | && (*BP_LOCP_TMP)->address == ADDRESS); \ | |
603 | BP_LOCP_TMP++) | |
604 | ||
1042e4c0 SS |
605 | /* Iterator for tracepoints only. */ |
606 | ||
607 | #define ALL_TRACEPOINTS(B) \ | |
608 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 609 | if (is_tracepoint (B)) |
1042e4c0 | 610 | |
7cc221ef | 611 | /* Chains of all breakpoints defined. */ |
c906108c SS |
612 | |
613 | struct breakpoint *breakpoint_chain; | |
614 | ||
876fa593 JK |
615 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
616 | ||
617 | static struct bp_location **bp_location; | |
618 | ||
619 | /* Number of elements of BP_LOCATION. */ | |
620 | ||
621 | static unsigned bp_location_count; | |
622 | ||
4a64f543 MS |
623 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
624 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
625 | result from bp_location_has_shadow. You can use it for roughly | |
626 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
627 | an address you need to read. */ | |
876fa593 JK |
628 | |
629 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
630 | ||
4a64f543 MS |
631 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
632 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
633 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
634 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
635 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
636 | |
637 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 638 | |
4a64f543 MS |
639 | /* The locations that no longer correspond to any breakpoint, unlinked |
640 | from bp_location array, but for which a hit may still be reported | |
641 | by a target. */ | |
20874c92 VP |
642 | VEC(bp_location_p) *moribund_locations = NULL; |
643 | ||
c906108c SS |
644 | /* Number of last breakpoint made. */ |
645 | ||
95a42b64 TT |
646 | static int breakpoint_count; |
647 | ||
86b17b60 PA |
648 | /* The value of `breakpoint_count' before the last command that |
649 | created breakpoints. If the last (break-like) command created more | |
650 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
651 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
652 | static int prev_breakpoint_count; | |
c906108c | 653 | |
1042e4c0 SS |
654 | /* Number of last tracepoint made. */ |
655 | ||
95a42b64 | 656 | static int tracepoint_count; |
1042e4c0 | 657 | |
6149aea9 PA |
658 | static struct cmd_list_element *breakpoint_set_cmdlist; |
659 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 660 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 661 | |
badd37ce SDJ |
662 | /* See declaration at breakpoint.h. */ |
663 | ||
664 | struct breakpoint * | |
665 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), | |
666 | void *user_data) | |
667 | { | |
668 | struct breakpoint *b = NULL; | |
669 | ||
670 | ALL_BREAKPOINTS (b) | |
671 | { | |
672 | if (func (b, user_data) != 0) | |
673 | break; | |
674 | } | |
675 | ||
676 | return b; | |
677 | } | |
678 | ||
468d015d JJ |
679 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
680 | static int | |
681 | breakpoint_enabled (struct breakpoint *b) | |
682 | { | |
0d381245 | 683 | return (b->enable_state == bp_enabled); |
468d015d JJ |
684 | } |
685 | ||
c906108c SS |
686 | /* Set breakpoint count to NUM. */ |
687 | ||
95a42b64 | 688 | static void |
fba45db2 | 689 | set_breakpoint_count (int num) |
c906108c | 690 | { |
86b17b60 | 691 | prev_breakpoint_count = breakpoint_count; |
c906108c | 692 | breakpoint_count = num; |
4fa62494 | 693 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
694 | } |
695 | ||
86b17b60 PA |
696 | /* Used by `start_rbreak_breakpoints' below, to record the current |
697 | breakpoint count before "rbreak" creates any breakpoint. */ | |
698 | static int rbreak_start_breakpoint_count; | |
699 | ||
95a42b64 TT |
700 | /* Called at the start an "rbreak" command to record the first |
701 | breakpoint made. */ | |
86b17b60 | 702 | |
95a42b64 TT |
703 | void |
704 | start_rbreak_breakpoints (void) | |
705 | { | |
86b17b60 | 706 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
707 | } |
708 | ||
709 | /* Called at the end of an "rbreak" command to record the last | |
710 | breakpoint made. */ | |
86b17b60 | 711 | |
95a42b64 TT |
712 | void |
713 | end_rbreak_breakpoints (void) | |
714 | { | |
86b17b60 | 715 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
716 | } |
717 | ||
4a64f543 | 718 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
719 | |
720 | void | |
fba45db2 | 721 | clear_breakpoint_hit_counts (void) |
c906108c SS |
722 | { |
723 | struct breakpoint *b; | |
724 | ||
725 | ALL_BREAKPOINTS (b) | |
726 | b->hit_count = 0; | |
727 | } | |
728 | ||
9add0f1b TT |
729 | /* Allocate a new counted_command_line with reference count of 1. |
730 | The new structure owns COMMANDS. */ | |
731 | ||
732 | static struct counted_command_line * | |
733 | alloc_counted_command_line (struct command_line *commands) | |
734 | { | |
8d749320 | 735 | struct counted_command_line *result = XNEW (struct counted_command_line); |
cc59ec59 | 736 | |
9add0f1b TT |
737 | result->refc = 1; |
738 | result->commands = commands; | |
8d749320 | 739 | |
9add0f1b TT |
740 | return result; |
741 | } | |
742 | ||
743 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
744 | ||
745 | static void | |
746 | incref_counted_command_line (struct counted_command_line *cmd) | |
747 | { | |
748 | if (cmd) | |
749 | ++cmd->refc; | |
750 | } | |
751 | ||
752 | /* Decrement reference count. If the reference count reaches 0, | |
753 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
754 | nothing if *CMDP is NULL. */ | |
755 | ||
756 | static void | |
757 | decref_counted_command_line (struct counted_command_line **cmdp) | |
758 | { | |
759 | if (*cmdp) | |
760 | { | |
761 | if (--(*cmdp)->refc == 0) | |
762 | { | |
763 | free_command_lines (&(*cmdp)->commands); | |
764 | xfree (*cmdp); | |
765 | } | |
766 | *cmdp = NULL; | |
767 | } | |
768 | } | |
769 | ||
770 | /* A cleanup function that calls decref_counted_command_line. */ | |
771 | ||
772 | static void | |
773 | do_cleanup_counted_command_line (void *arg) | |
774 | { | |
9a3c8263 | 775 | decref_counted_command_line ((struct counted_command_line **) arg); |
9add0f1b TT |
776 | } |
777 | ||
778 | /* Create a cleanup that calls decref_counted_command_line on the | |
779 | argument. */ | |
780 | ||
781 | static struct cleanup * | |
782 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
783 | { | |
784 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
785 | } | |
786 | ||
c906108c | 787 | \f |
48cb2d85 VP |
788 | /* Return the breakpoint with the specified number, or NULL |
789 | if the number does not refer to an existing breakpoint. */ | |
790 | ||
791 | struct breakpoint * | |
792 | get_breakpoint (int num) | |
793 | { | |
794 | struct breakpoint *b; | |
795 | ||
796 | ALL_BREAKPOINTS (b) | |
797 | if (b->number == num) | |
798 | return b; | |
799 | ||
800 | return NULL; | |
801 | } | |
5c44784c | 802 | |
c906108c | 803 | \f |
adc36818 | 804 | |
b775012e LM |
805 | /* Mark locations as "conditions have changed" in case the target supports |
806 | evaluating conditions on its side. */ | |
807 | ||
808 | static void | |
809 | mark_breakpoint_modified (struct breakpoint *b) | |
810 | { | |
811 | struct bp_location *loc; | |
812 | ||
813 | /* This is only meaningful if the target is | |
814 | evaluating conditions and if the user has | |
815 | opted for condition evaluation on the target's | |
816 | side. */ | |
817 | if (gdb_evaluates_breakpoint_condition_p () | |
818 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
819 | return; | |
820 | ||
821 | if (!is_breakpoint (b)) | |
822 | return; | |
823 | ||
824 | for (loc = b->loc; loc; loc = loc->next) | |
825 | loc->condition_changed = condition_modified; | |
826 | } | |
827 | ||
828 | /* Mark location as "conditions have changed" in case the target supports | |
829 | evaluating conditions on its side. */ | |
830 | ||
831 | static void | |
832 | mark_breakpoint_location_modified (struct bp_location *loc) | |
833 | { | |
834 | /* This is only meaningful if the target is | |
835 | evaluating conditions and if the user has | |
836 | opted for condition evaluation on the target's | |
837 | side. */ | |
838 | if (gdb_evaluates_breakpoint_condition_p () | |
839 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
840 | ||
841 | return; | |
842 | ||
843 | if (!is_breakpoint (loc->owner)) | |
844 | return; | |
845 | ||
846 | loc->condition_changed = condition_modified; | |
847 | } | |
848 | ||
849 | /* Sets the condition-evaluation mode using the static global | |
850 | condition_evaluation_mode. */ | |
851 | ||
852 | static void | |
853 | set_condition_evaluation_mode (char *args, int from_tty, | |
854 | struct cmd_list_element *c) | |
855 | { | |
b775012e LM |
856 | const char *old_mode, *new_mode; |
857 | ||
858 | if ((condition_evaluation_mode_1 == condition_evaluation_target) | |
859 | && !target_supports_evaluation_of_breakpoint_conditions ()) | |
860 | { | |
861 | condition_evaluation_mode_1 = condition_evaluation_mode; | |
862 | warning (_("Target does not support breakpoint condition evaluation.\n" | |
863 | "Using host evaluation mode instead.")); | |
864 | return; | |
865 | } | |
866 | ||
867 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); | |
868 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); | |
869 | ||
abf1152a JK |
870 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
871 | settings was "auto". */ | |
872 | condition_evaluation_mode = condition_evaluation_mode_1; | |
873 | ||
b775012e LM |
874 | /* Only update the mode if the user picked a different one. */ |
875 | if (new_mode != old_mode) | |
876 | { | |
877 | struct bp_location *loc, **loc_tmp; | |
878 | /* If the user switched to a different evaluation mode, we | |
879 | need to synch the changes with the target as follows: | |
880 | ||
881 | "host" -> "target": Send all (valid) conditions to the target. | |
882 | "target" -> "host": Remove all the conditions from the target. | |
883 | */ | |
884 | ||
b775012e LM |
885 | if (new_mode == condition_evaluation_target) |
886 | { | |
887 | /* Mark everything modified and synch conditions with the | |
888 | target. */ | |
889 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
890 | mark_breakpoint_location_modified (loc); | |
891 | } | |
892 | else | |
893 | { | |
894 | /* Manually mark non-duplicate locations to synch conditions | |
895 | with the target. We do this to remove all the conditions the | |
896 | target knows about. */ | |
897 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
898 | if (is_breakpoint (loc->owner) && loc->inserted) | |
899 | loc->needs_update = 1; | |
900 | } | |
901 | ||
902 | /* Do the update. */ | |
44702360 | 903 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e LM |
904 | } |
905 | ||
906 | return; | |
907 | } | |
908 | ||
909 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows | |
910 | what "auto" is translating to. */ | |
911 | ||
912 | static void | |
913 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, | |
914 | struct cmd_list_element *c, const char *value) | |
915 | { | |
916 | if (condition_evaluation_mode == condition_evaluation_auto) | |
917 | fprintf_filtered (file, | |
918 | _("Breakpoint condition evaluation " | |
919 | "mode is %s (currently %s).\n"), | |
920 | value, | |
921 | breakpoint_condition_evaluation_mode ()); | |
922 | else | |
923 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), | |
924 | value); | |
925 | } | |
926 | ||
927 | /* A comparison function for bp_location AP and BP that is used by | |
928 | bsearch. This comparison function only cares about addresses, unlike | |
929 | the more general bp_location_compare function. */ | |
930 | ||
931 | static int | |
932 | bp_location_compare_addrs (const void *ap, const void *bp) | |
933 | { | |
9a3c8263 SM |
934 | const struct bp_location *a = *(const struct bp_location **) ap; |
935 | const struct bp_location *b = *(const struct bp_location **) bp; | |
b775012e LM |
936 | |
937 | if (a->address == b->address) | |
938 | return 0; | |
939 | else | |
940 | return ((a->address > b->address) - (a->address < b->address)); | |
941 | } | |
942 | ||
943 | /* Helper function to skip all bp_locations with addresses | |
944 | less than ADDRESS. It returns the first bp_location that | |
945 | is greater than or equal to ADDRESS. If none is found, just | |
946 | return NULL. */ | |
947 | ||
948 | static struct bp_location ** | |
949 | get_first_locp_gte_addr (CORE_ADDR address) | |
950 | { | |
951 | struct bp_location dummy_loc; | |
952 | struct bp_location *dummy_locp = &dummy_loc; | |
953 | struct bp_location **locp_found = NULL; | |
954 | ||
955 | /* Initialize the dummy location's address field. */ | |
956 | memset (&dummy_loc, 0, sizeof (struct bp_location)); | |
957 | dummy_loc.address = address; | |
958 | ||
959 | /* Find a close match to the first location at ADDRESS. */ | |
9a3c8263 SM |
960 | locp_found = ((struct bp_location **) |
961 | bsearch (&dummy_locp, bp_location, bp_location_count, | |
962 | sizeof (struct bp_location **), | |
963 | bp_location_compare_addrs)); | |
b775012e LM |
964 | |
965 | /* Nothing was found, nothing left to do. */ | |
966 | if (locp_found == NULL) | |
967 | return NULL; | |
968 | ||
969 | /* We may have found a location that is at ADDRESS but is not the first in the | |
970 | location's list. Go backwards (if possible) and locate the first one. */ | |
971 | while ((locp_found - 1) >= bp_location | |
972 | && (*(locp_found - 1))->address == address) | |
973 | locp_found--; | |
974 | ||
975 | return locp_found; | |
976 | } | |
977 | ||
adc36818 | 978 | void |
7a26bd4d | 979 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
adc36818 PM |
980 | int from_tty) |
981 | { | |
3a5c3e22 PA |
982 | xfree (b->cond_string); |
983 | b->cond_string = NULL; | |
adc36818 | 984 | |
3a5c3e22 | 985 | if (is_watchpoint (b)) |
adc36818 | 986 | { |
3a5c3e22 PA |
987 | struct watchpoint *w = (struct watchpoint *) b; |
988 | ||
989 | xfree (w->cond_exp); | |
990 | w->cond_exp = NULL; | |
991 | } | |
992 | else | |
993 | { | |
994 | struct bp_location *loc; | |
995 | ||
996 | for (loc = b->loc; loc; loc = loc->next) | |
997 | { | |
998 | xfree (loc->cond); | |
999 | loc->cond = NULL; | |
b775012e LM |
1000 | |
1001 | /* No need to free the condition agent expression | |
1002 | bytecode (if we have one). We will handle this | |
1003 | when we go through update_global_location_list. */ | |
3a5c3e22 | 1004 | } |
adc36818 | 1005 | } |
adc36818 PM |
1006 | |
1007 | if (*exp == 0) | |
1008 | { | |
1009 | if (from_tty) | |
1010 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
1011 | } | |
1012 | else | |
1013 | { | |
bbc13ae3 | 1014 | const char *arg = exp; |
cc59ec59 | 1015 | |
adc36818 PM |
1016 | /* I don't know if it matters whether this is the string the user |
1017 | typed in or the decompiled expression. */ | |
1018 | b->cond_string = xstrdup (arg); | |
1019 | b->condition_not_parsed = 0; | |
1020 | ||
1021 | if (is_watchpoint (b)) | |
1022 | { | |
3a5c3e22 PA |
1023 | struct watchpoint *w = (struct watchpoint *) b; |
1024 | ||
adc36818 PM |
1025 | innermost_block = NULL; |
1026 | arg = exp; | |
1bb9788d | 1027 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
adc36818 PM |
1028 | if (*arg) |
1029 | error (_("Junk at end of expression")); | |
3a5c3e22 | 1030 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
1031 | } |
1032 | else | |
1033 | { | |
3a5c3e22 PA |
1034 | struct bp_location *loc; |
1035 | ||
adc36818 PM |
1036 | for (loc = b->loc; loc; loc = loc->next) |
1037 | { | |
1038 | arg = exp; | |
1039 | loc->cond = | |
1bb9788d TT |
1040 | parse_exp_1 (&arg, loc->address, |
1041 | block_for_pc (loc->address), 0); | |
adc36818 PM |
1042 | if (*arg) |
1043 | error (_("Junk at end of expression")); | |
1044 | } | |
1045 | } | |
1046 | } | |
b775012e LM |
1047 | mark_breakpoint_modified (b); |
1048 | ||
8d3788bd | 1049 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
1050 | } |
1051 | ||
d55637df TT |
1052 | /* Completion for the "condition" command. */ |
1053 | ||
1054 | static VEC (char_ptr) * | |
6f937416 PA |
1055 | condition_completer (struct cmd_list_element *cmd, |
1056 | const char *text, const char *word) | |
d55637df | 1057 | { |
6f937416 | 1058 | const char *space; |
d55637df | 1059 | |
6f937416 PA |
1060 | text = skip_spaces_const (text); |
1061 | space = skip_to_space_const (text); | |
d55637df TT |
1062 | if (*space == '\0') |
1063 | { | |
1064 | int len; | |
1065 | struct breakpoint *b; | |
1066 | VEC (char_ptr) *result = NULL; | |
1067 | ||
1068 | if (text[0] == '$') | |
1069 | { | |
1070 | /* We don't support completion of history indices. */ | |
1071 | if (isdigit (text[1])) | |
1072 | return NULL; | |
1073 | return complete_internalvar (&text[1]); | |
1074 | } | |
1075 | ||
1076 | /* We're completing the breakpoint number. */ | |
1077 | len = strlen (text); | |
1078 | ||
1079 | ALL_BREAKPOINTS (b) | |
58ce7251 SDJ |
1080 | { |
1081 | char number[50]; | |
1082 | ||
1083 | xsnprintf (number, sizeof (number), "%d", b->number); | |
1084 | ||
1085 | if (strncmp (number, text, len) == 0) | |
1086 | VEC_safe_push (char_ptr, result, xstrdup (number)); | |
1087 | } | |
d55637df TT |
1088 | |
1089 | return result; | |
1090 | } | |
1091 | ||
1092 | /* We're completing the expression part. */ | |
6f937416 | 1093 | text = skip_spaces_const (space); |
d55637df TT |
1094 | return expression_completer (cmd, text, word); |
1095 | } | |
1096 | ||
c906108c SS |
1097 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
1098 | ||
1099 | static void | |
fba45db2 | 1100 | condition_command (char *arg, int from_tty) |
c906108c | 1101 | { |
52f0bd74 | 1102 | struct breakpoint *b; |
c906108c | 1103 | char *p; |
52f0bd74 | 1104 | int bnum; |
c906108c SS |
1105 | |
1106 | if (arg == 0) | |
e2e0b3e5 | 1107 | error_no_arg (_("breakpoint number")); |
c906108c SS |
1108 | |
1109 | p = arg; | |
1110 | bnum = get_number (&p); | |
5c44784c | 1111 | if (bnum == 0) |
8a3fe4f8 | 1112 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
1113 | |
1114 | ALL_BREAKPOINTS (b) | |
1115 | if (b->number == bnum) | |
2f069f6f | 1116 | { |
6dddc817 DE |
1117 | /* Check if this breakpoint has a "stop" method implemented in an |
1118 | extension language. This method and conditions entered into GDB | |
1119 | from the CLI are mutually exclusive. */ | |
1120 | const struct extension_language_defn *extlang | |
1121 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); | |
1122 | ||
1123 | if (extlang != NULL) | |
1124 | { | |
1125 | error (_("Only one stop condition allowed. There is currently" | |
1126 | " a %s stop condition defined for this breakpoint."), | |
1127 | ext_lang_capitalized_name (extlang)); | |
1128 | } | |
2566ad2d | 1129 | set_breakpoint_condition (b, p, from_tty); |
b775012e LM |
1130 | |
1131 | if (is_breakpoint (b)) | |
44702360 | 1132 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 1133 | |
2f069f6f JB |
1134 | return; |
1135 | } | |
c906108c | 1136 | |
8a3fe4f8 | 1137 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
1138 | } |
1139 | ||
a7bdde9e VP |
1140 | /* Check that COMMAND do not contain commands that are suitable |
1141 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
1142 | Throw if any such commands is found. */ |
1143 | ||
a7bdde9e VP |
1144 | static void |
1145 | check_no_tracepoint_commands (struct command_line *commands) | |
1146 | { | |
1147 | struct command_line *c; | |
cc59ec59 | 1148 | |
a7bdde9e VP |
1149 | for (c = commands; c; c = c->next) |
1150 | { | |
1151 | int i; | |
1152 | ||
1153 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
1154 | error (_("The 'while-stepping' command can " |
1155 | "only be used for tracepoints")); | |
a7bdde9e VP |
1156 | |
1157 | for (i = 0; i < c->body_count; ++i) | |
1158 | check_no_tracepoint_commands ((c->body_list)[i]); | |
1159 | ||
1160 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 1161 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
1162 | command directly. */ |
1163 | if (strstr (c->line, "collect ") == c->line) | |
1164 | error (_("The 'collect' command can only be used for tracepoints")); | |
1165 | ||
51661e93 VP |
1166 | if (strstr (c->line, "teval ") == c->line) |
1167 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
1168 | } |
1169 | } | |
1170 | ||
d77f58be SS |
1171 | /* Encapsulate tests for different types of tracepoints. */ |
1172 | ||
d9b3f62e PA |
1173 | static int |
1174 | is_tracepoint_type (enum bptype type) | |
1175 | { | |
1176 | return (type == bp_tracepoint | |
1177 | || type == bp_fast_tracepoint | |
1178 | || type == bp_static_tracepoint); | |
1179 | } | |
1180 | ||
a7bdde9e | 1181 | int |
d77f58be | 1182 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 1183 | { |
d9b3f62e | 1184 | return is_tracepoint_type (b->type); |
a7bdde9e | 1185 | } |
d9b3f62e | 1186 | |
e5dd4106 | 1187 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
1188 | breakpoint. This function will throw an exception if a problem is |
1189 | found. */ | |
48cb2d85 | 1190 | |
95a42b64 TT |
1191 | static void |
1192 | validate_commands_for_breakpoint (struct breakpoint *b, | |
1193 | struct command_line *commands) | |
48cb2d85 | 1194 | { |
d77f58be | 1195 | if (is_tracepoint (b)) |
a7bdde9e | 1196 | { |
c9a6ce02 | 1197 | struct tracepoint *t = (struct tracepoint *) b; |
a7bdde9e VP |
1198 | struct command_line *c; |
1199 | struct command_line *while_stepping = 0; | |
c9a6ce02 PA |
1200 | |
1201 | /* Reset the while-stepping step count. The previous commands | |
1202 | might have included a while-stepping action, while the new | |
1203 | ones might not. */ | |
1204 | t->step_count = 0; | |
1205 | ||
1206 | /* We need to verify that each top-level element of commands is | |
1207 | valid for tracepoints, that there's at most one | |
1208 | while-stepping element, and that the while-stepping's body | |
1209 | has valid tracing commands excluding nested while-stepping. | |
1210 | We also need to validate the tracepoint action line in the | |
1211 | context of the tracepoint --- validate_actionline actually | |
1212 | has side effects, like setting the tracepoint's | |
1213 | while-stepping STEP_COUNT, in addition to checking if the | |
1214 | collect/teval actions parse and make sense in the | |
1215 | tracepoint's context. */ | |
a7bdde9e VP |
1216 | for (c = commands; c; c = c->next) |
1217 | { | |
a7bdde9e VP |
1218 | if (c->control_type == while_stepping_control) |
1219 | { | |
1220 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
1221 | error (_("The 'while-stepping' command " |
1222 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 1223 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
1224 | error (_("The 'while-stepping' command " |
1225 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
1226 | |
1227 | if (while_stepping) | |
3e43a32a MS |
1228 | error (_("The 'while-stepping' command " |
1229 | "can be used only once")); | |
a7bdde9e VP |
1230 | else |
1231 | while_stepping = c; | |
1232 | } | |
c9a6ce02 PA |
1233 | |
1234 | validate_actionline (c->line, b); | |
a7bdde9e VP |
1235 | } |
1236 | if (while_stepping) | |
1237 | { | |
1238 | struct command_line *c2; | |
1239 | ||
1240 | gdb_assert (while_stepping->body_count == 1); | |
1241 | c2 = while_stepping->body_list[0]; | |
1242 | for (; c2; c2 = c2->next) | |
1243 | { | |
a7bdde9e VP |
1244 | if (c2->control_type == while_stepping_control) |
1245 | error (_("The 'while-stepping' command cannot be nested")); | |
1246 | } | |
1247 | } | |
1248 | } | |
1249 | else | |
1250 | { | |
1251 | check_no_tracepoint_commands (commands); | |
1252 | } | |
95a42b64 TT |
1253 | } |
1254 | ||
0fb4aa4b PA |
1255 | /* Return a vector of all the static tracepoints set at ADDR. The |
1256 | caller is responsible for releasing the vector. */ | |
1257 | ||
1258 | VEC(breakpoint_p) * | |
1259 | static_tracepoints_here (CORE_ADDR addr) | |
1260 | { | |
1261 | struct breakpoint *b; | |
1262 | VEC(breakpoint_p) *found = 0; | |
1263 | struct bp_location *loc; | |
1264 | ||
1265 | ALL_BREAKPOINTS (b) | |
1266 | if (b->type == bp_static_tracepoint) | |
1267 | { | |
1268 | for (loc = b->loc; loc; loc = loc->next) | |
1269 | if (loc->address == addr) | |
1270 | VEC_safe_push(breakpoint_p, found, b); | |
1271 | } | |
1272 | ||
1273 | return found; | |
1274 | } | |
1275 | ||
95a42b64 | 1276 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 1277 | validate that only allowed commands are included. */ |
95a42b64 TT |
1278 | |
1279 | void | |
4a64f543 MS |
1280 | breakpoint_set_commands (struct breakpoint *b, |
1281 | struct command_line *commands) | |
95a42b64 TT |
1282 | { |
1283 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 1284 | |
9add0f1b TT |
1285 | decref_counted_command_line (&b->commands); |
1286 | b->commands = alloc_counted_command_line (commands); | |
8d3788bd | 1287 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
1288 | } |
1289 | ||
45a43567 TT |
1290 | /* Set the internal `silent' flag on the breakpoint. Note that this |
1291 | is not the same as the "silent" that may appear in the breakpoint's | |
1292 | commands. */ | |
1293 | ||
1294 | void | |
1295 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
1296 | { | |
1297 | int old_silent = b->silent; | |
1298 | ||
1299 | b->silent = silent; | |
1300 | if (old_silent != silent) | |
8d3788bd | 1301 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1302 | } |
1303 | ||
1304 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
1305 | breakpoint work for any thread. */ | |
1306 | ||
1307 | void | |
1308 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
1309 | { | |
1310 | int old_thread = b->thread; | |
1311 | ||
1312 | b->thread = thread; | |
1313 | if (old_thread != thread) | |
8d3788bd | 1314 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1315 | } |
1316 | ||
1317 | /* Set the task for this breakpoint. If TASK is 0, make the | |
1318 | breakpoint work for any task. */ | |
1319 | ||
1320 | void | |
1321 | breakpoint_set_task (struct breakpoint *b, int task) | |
1322 | { | |
1323 | int old_task = b->task; | |
1324 | ||
1325 | b->task = task; | |
1326 | if (old_task != task) | |
8d3788bd | 1327 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
1328 | } |
1329 | ||
95a42b64 TT |
1330 | void |
1331 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e | 1332 | { |
9a3c8263 | 1333 | struct breakpoint *b = (struct breakpoint *) closure; |
cc59ec59 | 1334 | |
6f937416 | 1335 | validate_actionline (line, b); |
a7bdde9e VP |
1336 | } |
1337 | ||
95a42b64 TT |
1338 | /* A structure used to pass information through |
1339 | map_breakpoint_numbers. */ | |
1340 | ||
1341 | struct commands_info | |
1342 | { | |
1343 | /* True if the command was typed at a tty. */ | |
1344 | int from_tty; | |
86b17b60 PA |
1345 | |
1346 | /* The breakpoint range spec. */ | |
1347 | char *arg; | |
1348 | ||
95a42b64 TT |
1349 | /* Non-NULL if the body of the commands are being read from this |
1350 | already-parsed command. */ | |
1351 | struct command_line *control; | |
86b17b60 | 1352 | |
95a42b64 TT |
1353 | /* The command lines read from the user, or NULL if they have not |
1354 | yet been read. */ | |
1355 | struct counted_command_line *cmd; | |
1356 | }; | |
1357 | ||
1358 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1359 | commands_command. */ | |
1360 | ||
c906108c | 1361 | static void |
95a42b64 | 1362 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1363 | { |
9a3c8263 | 1364 | struct commands_info *info = (struct commands_info *) data; |
c906108c | 1365 | |
95a42b64 TT |
1366 | if (info->cmd == NULL) |
1367 | { | |
1368 | struct command_line *l; | |
5c44784c | 1369 | |
95a42b64 TT |
1370 | if (info->control != NULL) |
1371 | l = copy_command_lines (info->control->body_list[0]); | |
1372 | else | |
86b17b60 PA |
1373 | { |
1374 | struct cleanup *old_chain; | |
1375 | char *str; | |
c5aa993b | 1376 | |
3e43a32a MS |
1377 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1378 | "%s, one per line."), | |
86b17b60 PA |
1379 | info->arg); |
1380 | ||
1381 | old_chain = make_cleanup (xfree, str); | |
1382 | ||
1383 | l = read_command_lines (str, | |
1384 | info->from_tty, 1, | |
d77f58be | 1385 | (is_tracepoint (b) |
86b17b60 PA |
1386 | ? check_tracepoint_command : 0), |
1387 | b); | |
1388 | ||
1389 | do_cleanups (old_chain); | |
1390 | } | |
a7bdde9e | 1391 | |
95a42b64 TT |
1392 | info->cmd = alloc_counted_command_line (l); |
1393 | } | |
1394 | ||
1395 | /* If a breakpoint was on the list more than once, we don't need to | |
1396 | do anything. */ | |
1397 | if (b->commands != info->cmd) | |
1398 | { | |
1399 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1400 | incref_counted_command_line (info->cmd); | |
1401 | decref_counted_command_line (&b->commands); | |
1402 | b->commands = info->cmd; | |
8d3788bd | 1403 | observer_notify_breakpoint_modified (b); |
c5aa993b | 1404 | } |
95a42b64 TT |
1405 | } |
1406 | ||
1407 | static void | |
4a64f543 MS |
1408 | commands_command_1 (char *arg, int from_tty, |
1409 | struct command_line *control) | |
95a42b64 TT |
1410 | { |
1411 | struct cleanup *cleanups; | |
1412 | struct commands_info info; | |
1413 | ||
1414 | info.from_tty = from_tty; | |
1415 | info.control = control; | |
1416 | info.cmd = NULL; | |
1417 | /* If we read command lines from the user, then `info' will hold an | |
1418 | extra reference to the commands that we must clean up. */ | |
1419 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1420 | ||
1421 | if (arg == NULL || !*arg) | |
1422 | { | |
86b17b60 | 1423 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1424 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1425 | breakpoint_count); | |
95a42b64 TT |
1426 | else if (breakpoint_count > 0) |
1427 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1428 | else |
1429 | { | |
1430 | /* So that we don't try to free the incoming non-NULL | |
1431 | argument in the cleanup below. Mapping breakpoint | |
1432 | numbers will fail in this case. */ | |
1433 | arg = NULL; | |
1434 | } | |
95a42b64 | 1435 | } |
9766ced4 SS |
1436 | else |
1437 | /* The command loop has some static state, so we need to preserve | |
1438 | our argument. */ | |
1439 | arg = xstrdup (arg); | |
86b17b60 PA |
1440 | |
1441 | if (arg != NULL) | |
1442 | make_cleanup (xfree, arg); | |
1443 | ||
1444 | info.arg = arg; | |
95a42b64 TT |
1445 | |
1446 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1447 | ||
1448 | if (info.cmd == NULL) | |
1449 | error (_("No breakpoints specified.")); | |
1450 | ||
1451 | do_cleanups (cleanups); | |
1452 | } | |
1453 | ||
1454 | static void | |
1455 | commands_command (char *arg, int from_tty) | |
1456 | { | |
1457 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1458 | } |
40c03ae8 EZ |
1459 | |
1460 | /* Like commands_command, but instead of reading the commands from | |
1461 | input stream, takes them from an already parsed command structure. | |
1462 | ||
1463 | This is used by cli-script.c to DTRT with breakpoint commands | |
1464 | that are part of if and while bodies. */ | |
1465 | enum command_control_type | |
1466 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1467 | { | |
95a42b64 TT |
1468 | commands_command_1 (arg, 0, cmd); |
1469 | return simple_control; | |
40c03ae8 | 1470 | } |
876fa593 JK |
1471 | |
1472 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1473 | ||
1474 | static int | |
1475 | bp_location_has_shadow (struct bp_location *bl) | |
1476 | { | |
1477 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1478 | return 0; | |
1479 | if (!bl->inserted) | |
1480 | return 0; | |
1481 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1482 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1483 | return 0; |
1484 | return 1; | |
1485 | } | |
1486 | ||
9d497a19 PA |
1487 | /* Update BUF, which is LEN bytes read from the target address |
1488 | MEMADDR, by replacing a memory breakpoint with its shadowed | |
1489 | contents. | |
1490 | ||
1491 | If READBUF is not NULL, this buffer must not overlap with the of | |
1492 | the breakpoint location's shadow_contents buffer. Otherwise, a | |
1493 | failed assertion internal error will be raised. */ | |
1494 | ||
1495 | static void | |
1496 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, | |
1497 | const gdb_byte *writebuf_org, | |
1498 | ULONGEST memaddr, LONGEST len, | |
1499 | struct bp_target_info *target_info, | |
1500 | struct gdbarch *gdbarch) | |
1501 | { | |
1502 | /* Now do full processing of the found relevant range of elements. */ | |
1503 | CORE_ADDR bp_addr = 0; | |
1504 | int bp_size = 0; | |
1505 | int bptoffset = 0; | |
1506 | ||
1507 | if (!breakpoint_address_match (target_info->placed_address_space, 0, | |
1508 | current_program_space->aspace, 0)) | |
1509 | { | |
1510 | /* The breakpoint is inserted in a different address space. */ | |
1511 | return; | |
1512 | } | |
1513 | ||
1514 | /* Addresses and length of the part of the breakpoint that | |
1515 | we need to copy. */ | |
1516 | bp_addr = target_info->placed_address; | |
1517 | bp_size = target_info->shadow_len; | |
1518 | ||
1519 | if (bp_addr + bp_size <= memaddr) | |
1520 | { | |
1521 | /* The breakpoint is entirely before the chunk of memory we are | |
1522 | reading. */ | |
1523 | return; | |
1524 | } | |
1525 | ||
1526 | if (bp_addr >= memaddr + len) | |
1527 | { | |
1528 | /* The breakpoint is entirely after the chunk of memory we are | |
1529 | reading. */ | |
1530 | return; | |
1531 | } | |
1532 | ||
1533 | /* Offset within shadow_contents. */ | |
1534 | if (bp_addr < memaddr) | |
1535 | { | |
1536 | /* Only copy the second part of the breakpoint. */ | |
1537 | bp_size -= memaddr - bp_addr; | |
1538 | bptoffset = memaddr - bp_addr; | |
1539 | bp_addr = memaddr; | |
1540 | } | |
1541 | ||
1542 | if (bp_addr + bp_size > memaddr + len) | |
1543 | { | |
1544 | /* Only copy the first part of the breakpoint. */ | |
1545 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1546 | } | |
1547 | ||
1548 | if (readbuf != NULL) | |
1549 | { | |
1550 | /* Verify that the readbuf buffer does not overlap with the | |
1551 | shadow_contents buffer. */ | |
1552 | gdb_assert (target_info->shadow_contents >= readbuf + len | |
1553 | || readbuf >= (target_info->shadow_contents | |
1554 | + target_info->shadow_len)); | |
1555 | ||
1556 | /* Update the read buffer with this inserted breakpoint's | |
1557 | shadow. */ | |
1558 | memcpy (readbuf + bp_addr - memaddr, | |
1559 | target_info->shadow_contents + bptoffset, bp_size); | |
1560 | } | |
1561 | else | |
1562 | { | |
1563 | const unsigned char *bp; | |
0d5ed153 MR |
1564 | CORE_ADDR addr = target_info->reqstd_address; |
1565 | int placed_size; | |
9d497a19 PA |
1566 | |
1567 | /* Update the shadow with what we want to write to memory. */ | |
1568 | memcpy (target_info->shadow_contents + bptoffset, | |
1569 | writebuf_org + bp_addr - memaddr, bp_size); | |
1570 | ||
1571 | /* Determine appropriate breakpoint contents and size for this | |
1572 | address. */ | |
0d5ed153 | 1573 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
9d497a19 PA |
1574 | |
1575 | /* Update the final write buffer with this inserted | |
1576 | breakpoint's INSN. */ | |
1577 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); | |
1578 | } | |
1579 | } | |
1580 | ||
8defab1a | 1581 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1582 | by replacing any memory breakpoints with their shadowed contents. |
1583 | ||
35c63cd8 JB |
1584 | If READBUF is not NULL, this buffer must not overlap with any of |
1585 | the breakpoint location's shadow_contents buffers. Otherwise, | |
1586 | a failed assertion internal error will be raised. | |
1587 | ||
876fa593 | 1588 | The range of shadowed area by each bp_location is: |
35df4500 TJB |
1589 | bl->address - bp_location_placed_address_before_address_max |
1590 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1591 | The range we were requested to resolve shadows for is: |
1592 | memaddr ... memaddr + len | |
1593 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1594 | memaddr + len <= (bl->address |
1595 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1596 | and: |
35df4500 | 1597 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1598 | |
8defab1a | 1599 | void |
f0ba3972 PA |
1600 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
1601 | const gdb_byte *writebuf_org, | |
1602 | ULONGEST memaddr, LONGEST len) | |
c906108c | 1603 | { |
4a64f543 MS |
1604 | /* Left boundary, right boundary and median element of our binary |
1605 | search. */ | |
876fa593 | 1606 | unsigned bc_l, bc_r, bc; |
9d497a19 | 1607 | size_t i; |
876fa593 | 1608 | |
4a64f543 MS |
1609 | /* Find BC_L which is a leftmost element which may affect BUF |
1610 | content. It is safe to report lower value but a failure to | |
1611 | report higher one. */ | |
876fa593 JK |
1612 | |
1613 | bc_l = 0; | |
1614 | bc_r = bp_location_count; | |
1615 | while (bc_l + 1 < bc_r) | |
1616 | { | |
35df4500 | 1617 | struct bp_location *bl; |
876fa593 JK |
1618 | |
1619 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1620 | bl = bp_location[bc]; |
876fa593 | 1621 | |
4a64f543 MS |
1622 | /* Check first BL->ADDRESS will not overflow due to the added |
1623 | constant. Then advance the left boundary only if we are sure | |
1624 | the BC element can in no way affect the BUF content (MEMADDR | |
1625 | to MEMADDR + LEN range). | |
876fa593 | 1626 | |
4a64f543 MS |
1627 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1628 | offset so that we cannot miss a breakpoint with its shadow | |
1629 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1630 | |
35df4500 TJB |
1631 | if ((bl->address + bp_location_shadow_len_after_address_max |
1632 | >= bl->address) | |
1633 | && (bl->address + bp_location_shadow_len_after_address_max | |
1634 | <= memaddr)) | |
876fa593 JK |
1635 | bc_l = bc; |
1636 | else | |
1637 | bc_r = bc; | |
1638 | } | |
1639 | ||
128070bb PA |
1640 | /* Due to the binary search above, we need to make sure we pick the |
1641 | first location that's at BC_L's address. E.g., if there are | |
1642 | multiple locations at the same address, BC_L may end up pointing | |
1643 | at a duplicate location, and miss the "master"/"inserted" | |
1644 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1645 | B: | |
1646 | ||
1647 | L1@A, L2@A, L3@B, ... | |
1648 | ||
1649 | BC_L could end up pointing at location L2, while the "master" | |
1650 | location could be L1. Since the `loc->inserted' flag is only set | |
1651 | on "master" locations, we'd forget to restore the shadow of L1 | |
1652 | and L2. */ | |
1653 | while (bc_l > 0 | |
1654 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1655 | bc_l--; | |
1656 | ||
876fa593 JK |
1657 | /* Now do full processing of the found relevant range of elements. */ |
1658 | ||
1659 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1660 | { |
35df4500 | 1661 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1662 | CORE_ADDR bp_addr = 0; |
1663 | int bp_size = 0; | |
1664 | int bptoffset = 0; | |
1665 | ||
35df4500 TJB |
1666 | /* bp_location array has BL->OWNER always non-NULL. */ |
1667 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1668 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1669 | bl->owner->number); |
ffce0d52 | 1670 | |
e5dd4106 | 1671 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1672 | content. */ |
1673 | ||
35df4500 TJB |
1674 | if (bl->address >= bp_location_placed_address_before_address_max |
1675 | && memaddr + len <= (bl->address | |
1676 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1677 | break; |
1678 | ||
35df4500 | 1679 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1680 | continue; |
6c95b8df | 1681 | |
9d497a19 PA |
1682 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
1683 | memaddr, len, &bl->target_info, bl->gdbarch); | |
1684 | } | |
c906108c | 1685 | } |
9d497a19 | 1686 | |
c906108c | 1687 | \f |
c5aa993b | 1688 | |
b775012e LM |
1689 | /* Return true if BPT is either a software breakpoint or a hardware |
1690 | breakpoint. */ | |
1691 | ||
1692 | int | |
1693 | is_breakpoint (const struct breakpoint *bpt) | |
1694 | { | |
1695 | return (bpt->type == bp_breakpoint | |
e7e0cddf SS |
1696 | || bpt->type == bp_hardware_breakpoint |
1697 | || bpt->type == bp_dprintf); | |
b775012e LM |
1698 | } |
1699 | ||
60e1c644 PA |
1700 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1701 | ||
a5606eee | 1702 | static int |
d77f58be | 1703 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1704 | { |
1705 | return (bpt->type == bp_hardware_watchpoint | |
1706 | || bpt->type == bp_read_watchpoint | |
1707 | || bpt->type == bp_access_watchpoint); | |
1708 | } | |
7270d8f2 | 1709 | |
60e1c644 PA |
1710 | /* Return true if BPT is of any watchpoint kind, hardware or |
1711 | software. */ | |
1712 | ||
3a5c3e22 | 1713 | int |
d77f58be | 1714 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1715 | { |
1716 | return (is_hardware_watchpoint (bpt) | |
1717 | || bpt->type == bp_watchpoint); | |
1718 | } | |
1719 | ||
3a5c3e22 PA |
1720 | /* Returns true if the current thread and its running state are safe |
1721 | to evaluate or update watchpoint B. Watchpoints on local | |
1722 | expressions need to be evaluated in the context of the thread that | |
1723 | was current when the watchpoint was created, and, that thread needs | |
1724 | to be stopped to be able to select the correct frame context. | |
1725 | Watchpoints on global expressions can be evaluated on any thread, | |
1726 | and in any state. It is presently left to the target allowing | |
1727 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1728 | |
1729 | static int | |
3a5c3e22 | 1730 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 | 1731 | { |
d0d8b0c6 JK |
1732 | return (b->base.pspace == current_program_space |
1733 | && (ptid_equal (b->watchpoint_thread, null_ptid) | |
1734 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1735 | && !is_executing (inferior_ptid)))); | |
f6bc2008 PA |
1736 | } |
1737 | ||
d0fb5eae JK |
1738 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1739 | associated bp_watchpoint_scope breakpoint. */ | |
1740 | ||
1741 | static void | |
3a5c3e22 | 1742 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1743 | { |
3a5c3e22 | 1744 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1745 | |
1746 | if (b->related_breakpoint != b) | |
1747 | { | |
1748 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1749 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1750 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1751 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1752 | b->related_breakpoint = b; | |
1753 | } | |
1754 | b->disposition = disp_del_at_next_stop; | |
1755 | } | |
1756 | ||
bb9d5f81 PP |
1757 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
1758 | watchpoint W. */ | |
1759 | ||
1760 | static struct value * | |
1761 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) | |
1762 | { | |
1763 | struct value *bit_val; | |
1764 | ||
1765 | if (val == NULL) | |
1766 | return NULL; | |
1767 | ||
1768 | bit_val = allocate_value (value_type (val)); | |
1769 | ||
1770 | unpack_value_bitfield (bit_val, | |
1771 | w->val_bitpos, | |
1772 | w->val_bitsize, | |
1773 | value_contents_for_printing (val), | |
1774 | value_offset (val), | |
1775 | val); | |
1776 | ||
1777 | return bit_val; | |
1778 | } | |
1779 | ||
c6d81124 PA |
1780 | /* Allocate a dummy location and add it to B, which must be a software |
1781 | watchpoint. This is required because even if a software watchpoint | |
1782 | is not watching any memory, bpstat_stop_status requires a location | |
1783 | to be able to report stops. */ | |
1784 | ||
1785 | static void | |
1786 | software_watchpoint_add_no_memory_location (struct breakpoint *b, | |
1787 | struct program_space *pspace) | |
1788 | { | |
1789 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); | |
1790 | ||
1791 | b->loc = allocate_bp_location (b); | |
1792 | b->loc->pspace = pspace; | |
1793 | b->loc->address = -1; | |
1794 | b->loc->length = -1; | |
1795 | } | |
1796 | ||
1797 | /* Returns true if B is a software watchpoint that is not watching any | |
1798 | memory (e.g., "watch $pc"). */ | |
1799 | ||
1800 | static int | |
1801 | is_no_memory_software_watchpoint (struct breakpoint *b) | |
1802 | { | |
1803 | return (b->type == bp_watchpoint | |
1804 | && b->loc != NULL | |
1805 | && b->loc->next == NULL | |
1806 | && b->loc->address == -1 | |
1807 | && b->loc->length == -1); | |
1808 | } | |
1809 | ||
567e1b4e JB |
1810 | /* Assuming that B is a watchpoint: |
1811 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1812 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1813 | - Evaluate the condition if there is one, and store the result |
1814 | in b->loc->cond. | |
a5606eee VP |
1815 | - Update the list of values that must be watched in B->loc. |
1816 | ||
4a64f543 MS |
1817 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1818 | nothing. If this is local watchpoint that is out of scope, delete | |
1819 | it. | |
1820 | ||
1821 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1822 | removed + inserted on each stop here. Normal breakpoints must | |
1823 | never be removed because they might be missed by a running thread | |
1824 | when debugging in non-stop mode. On the other hand, hardware | |
1825 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1826 | to each LWP since they are stored in each LWP's hardware debug | |
1827 | registers. Therefore, such LWP must be stopped first in order to | |
1828 | be able to modify its hardware watchpoints. | |
1829 | ||
1830 | Hardware watchpoints must be reset exactly once after being | |
1831 | presented to the user. It cannot be done sooner, because it would | |
1832 | reset the data used to present the watchpoint hit to the user. And | |
1833 | it must not be done later because it could display the same single | |
1834 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1835 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1836 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1837 | not user-visible - its hit is suppressed if the memory content has | |
1838 | not changed. | |
1839 | ||
1840 | The following constraints influence the location where we can reset | |
1841 | hardware watchpoints: | |
1842 | ||
1843 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1844 | called several times when GDB stops. | |
1845 | ||
1846 | [linux] | |
1847 | * Multiple hardware watchpoints can be hit at the same time, | |
1848 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1849 | hit at a time as the reason for stopping, and all the other hits | |
1850 | are presented later, one after the other, each time the user | |
1851 | requests the execution to be resumed. Execution is not resumed | |
1852 | for the threads still having pending hit event stored in | |
1853 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1854 | the inferior on the first stop the thread hit event is kept being | |
1855 | reported from its cached value by linux_nat_stopped_data_address | |
1856 | until the real thread resume happens after the watchpoint gets | |
1857 | presented and thus its LWP_INFO->STATUS gets reset. | |
1858 | ||
1859 | Therefore the hardware watchpoint hit can get safely reset on the | |
1860 | watchpoint removal from inferior. */ | |
a79d3c27 | 1861 | |
b40ce68a | 1862 | static void |
3a5c3e22 | 1863 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1864 | { |
a5606eee | 1865 | int within_current_scope; |
a5606eee | 1866 | struct frame_id saved_frame_id; |
66076460 | 1867 | int frame_saved; |
a5606eee | 1868 | |
f6bc2008 PA |
1869 | /* If this is a local watchpoint, we only want to check if the |
1870 | watchpoint frame is in scope if the current thread is the thread | |
1871 | that was used to create the watchpoint. */ | |
1872 | if (!watchpoint_in_thread_scope (b)) | |
1873 | return; | |
1874 | ||
3a5c3e22 | 1875 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1876 | return; |
1877 | ||
66076460 | 1878 | frame_saved = 0; |
a5606eee VP |
1879 | |
1880 | /* Determine if the watchpoint is within scope. */ | |
1881 | if (b->exp_valid_block == NULL) | |
1882 | within_current_scope = 1; | |
1883 | else | |
1884 | { | |
b5db5dfc UW |
1885 | struct frame_info *fi = get_current_frame (); |
1886 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1887 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1888 | ||
c9cf6e20 MG |
1889 | /* If we're at a point where the stack has been destroyed |
1890 | (e.g. in a function epilogue), unwinding may not work | |
1891 | properly. Do not attempt to recreate locations at this | |
b5db5dfc | 1892 | point. See similar comments in watchpoint_check. */ |
c9cf6e20 | 1893 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
b5db5dfc | 1894 | return; |
66076460 DJ |
1895 | |
1896 | /* Save the current frame's ID so we can restore it after | |
1897 | evaluating the watchpoint expression on its own frame. */ | |
1898 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1899 | took a frame parameter, so that we didn't have to change the | |
1900 | selected frame. */ | |
1901 | frame_saved = 1; | |
1902 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1903 | ||
a5606eee VP |
1904 | fi = frame_find_by_id (b->watchpoint_frame); |
1905 | within_current_scope = (fi != NULL); | |
1906 | if (within_current_scope) | |
1907 | select_frame (fi); | |
1908 | } | |
1909 | ||
b5db5dfc UW |
1910 | /* We don't free locations. They are stored in the bp_location array |
1911 | and update_global_location_list will eventually delete them and | |
1912 | remove breakpoints if needed. */ | |
3a5c3e22 | 1913 | b->base.loc = NULL; |
b5db5dfc | 1914 | |
a5606eee VP |
1915 | if (within_current_scope && reparse) |
1916 | { | |
bbc13ae3 | 1917 | const char *s; |
d63d0675 | 1918 | |
a5606eee VP |
1919 | if (b->exp) |
1920 | { | |
1921 | xfree (b->exp); | |
1922 | b->exp = NULL; | |
1923 | } | |
d63d0675 | 1924 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
1bb9788d | 1925 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
a5606eee VP |
1926 | /* If the meaning of expression itself changed, the old value is |
1927 | no longer relevant. We don't want to report a watchpoint hit | |
1928 | to the user when the old value and the new value may actually | |
1929 | be completely different objects. */ | |
1930 | value_free (b->val); | |
fa4727a6 DJ |
1931 | b->val = NULL; |
1932 | b->val_valid = 0; | |
60e1c644 PA |
1933 | |
1934 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1935 | expression is stored in the breakpoint object, not in the | |
1936 | locations (re)created below. */ | |
3a5c3e22 | 1937 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1938 | { |
1939 | if (b->cond_exp != NULL) | |
1940 | { | |
1941 | xfree (b->cond_exp); | |
1942 | b->cond_exp = NULL; | |
1943 | } | |
1944 | ||
3a5c3e22 | 1945 | s = b->base.cond_string; |
1bb9788d | 1946 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
60e1c644 | 1947 | } |
a5606eee | 1948 | } |
a5606eee VP |
1949 | |
1950 | /* If we failed to parse the expression, for example because | |
1951 | it refers to a global variable in a not-yet-loaded shared library, | |
1952 | don't try to insert watchpoint. We don't automatically delete | |
1953 | such watchpoint, though, since failure to parse expression | |
1954 | is different from out-of-scope watchpoint. */ | |
e8369a73 | 1955 | if (!target_has_execution) |
2d134ed3 PA |
1956 | { |
1957 | /* Without execution, memory can't change. No use to try and | |
1958 | set watchpoint locations. The watchpoint will be reset when | |
1959 | the target gains execution, through breakpoint_re_set. */ | |
e8369a73 AB |
1960 | if (!can_use_hw_watchpoints) |
1961 | { | |
1962 | if (b->base.ops->works_in_software_mode (&b->base)) | |
1963 | b->base.type = bp_watchpoint; | |
1964 | else | |
638aa5a1 AB |
1965 | error (_("Can't set read/access watchpoint when " |
1966 | "hardware watchpoints are disabled.")); | |
e8369a73 | 1967 | } |
2d134ed3 PA |
1968 | } |
1969 | else if (within_current_scope && b->exp) | |
a5606eee | 1970 | { |
0cf6dd15 | 1971 | int pc = 0; |
fa4727a6 | 1972 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1973 | struct program_space *frame_pspace; |
a5606eee | 1974 | |
3a1115a0 | 1975 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
a5606eee | 1976 | |
a5606eee VP |
1977 | /* Avoid setting b->val if it's already set. The meaning of |
1978 | b->val is 'the last value' user saw, and we should update | |
1979 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1980 | happens, the code that reports it updates b->val directly. |
1981 | We don't keep track of the memory value for masked | |
1982 | watchpoints. */ | |
3a5c3e22 | 1983 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 | 1984 | { |
bb9d5f81 PP |
1985 | if (b->val_bitsize != 0) |
1986 | { | |
1987 | v = extract_bitfield_from_watchpoint_value (b, v); | |
1988 | if (v != NULL) | |
1989 | release_value (v); | |
1990 | } | |
fa4727a6 DJ |
1991 | b->val = v; |
1992 | b->val_valid = 1; | |
1993 | } | |
a5606eee | 1994 | |
2d134ed3 PA |
1995 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1996 | ||
a5606eee | 1997 | /* Look at each value on the value chain. */ |
9fa40276 | 1998 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1999 | { |
2000 | /* If it's a memory location, and GDB actually needed | |
2001 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
2002 | must watch it. If the first value returned is |
2003 | still lazy, that means an error occurred reading it; | |
2004 | watch it anyway in case it becomes readable. */ | |
a5606eee | 2005 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 2006 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
2007 | { |
2008 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 2009 | |
a5606eee VP |
2010 | /* We only watch structs and arrays if user asked |
2011 | for it explicitly, never if they just happen to | |
2012 | appear in the middle of some value chain. */ | |
fa4727a6 | 2013 | if (v == result |
a5606eee VP |
2014 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
2015 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
2016 | { | |
2017 | CORE_ADDR addr; | |
f486487f | 2018 | enum target_hw_bp_type type; |
a5606eee | 2019 | struct bp_location *loc, **tmp; |
bb9d5f81 PP |
2020 | int bitpos = 0, bitsize = 0; |
2021 | ||
2022 | if (value_bitsize (v) != 0) | |
2023 | { | |
2024 | /* Extract the bit parameters out from the bitfield | |
2025 | sub-expression. */ | |
2026 | bitpos = value_bitpos (v); | |
2027 | bitsize = value_bitsize (v); | |
2028 | } | |
2029 | else if (v == result && b->val_bitsize != 0) | |
2030 | { | |
2031 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield | |
2032 | lvalue whose bit parameters are saved in the fields | |
2033 | VAL_BITPOS and VAL_BITSIZE. */ | |
2034 | bitpos = b->val_bitpos; | |
2035 | bitsize = b->val_bitsize; | |
2036 | } | |
a5606eee | 2037 | |
42ae5230 | 2038 | addr = value_address (v); |
bb9d5f81 PP |
2039 | if (bitsize != 0) |
2040 | { | |
2041 | /* Skip the bytes that don't contain the bitfield. */ | |
2042 | addr += bitpos / 8; | |
2043 | } | |
2044 | ||
a5606eee | 2045 | type = hw_write; |
3a5c3e22 | 2046 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 2047 | type = hw_read; |
3a5c3e22 | 2048 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 2049 | type = hw_access; |
3a5c3e22 PA |
2050 | |
2051 | loc = allocate_bp_location (&b->base); | |
2052 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
2053 | ; |
2054 | *tmp = loc; | |
a6d9a66e | 2055 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
2056 | |
2057 | loc->pspace = frame_pspace; | |
a5606eee | 2058 | loc->address = addr; |
bb9d5f81 PP |
2059 | |
2060 | if (bitsize != 0) | |
2061 | { | |
2062 | /* Just cover the bytes that make up the bitfield. */ | |
2063 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; | |
2064 | } | |
2065 | else | |
2066 | loc->length = TYPE_LENGTH (value_type (v)); | |
2067 | ||
a5606eee VP |
2068 | loc->watchpoint_type = type; |
2069 | } | |
2070 | } | |
9fa40276 TJB |
2071 | } |
2072 | ||
2073 | /* Change the type of breakpoint between hardware assisted or | |
2074 | an ordinary watchpoint depending on the hardware support | |
2075 | and free hardware slots. REPARSE is set when the inferior | |
2076 | is started. */ | |
a9634178 | 2077 | if (reparse) |
9fa40276 | 2078 | { |
e09342b5 | 2079 | int reg_cnt; |
9fa40276 TJB |
2080 | enum bp_loc_type loc_type; |
2081 | struct bp_location *bl; | |
a5606eee | 2082 | |
a9634178 | 2083 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
2084 | |
2085 | if (reg_cnt) | |
9fa40276 TJB |
2086 | { |
2087 | int i, target_resources_ok, other_type_used; | |
a1398e0c | 2088 | enum bptype type; |
9fa40276 | 2089 | |
a9634178 TJB |
2090 | /* Use an exact watchpoint when there's only one memory region to be |
2091 | watched, and only one debug register is needed to watch it. */ | |
2092 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
2093 | ||
9fa40276 | 2094 | /* We need to determine how many resources are already |
e09342b5 TJB |
2095 | used for all other hardware watchpoints plus this one |
2096 | to see if we still have enough resources to also fit | |
a1398e0c PA |
2097 | this watchpoint in as well. */ |
2098 | ||
2099 | /* If this is a software watchpoint, we try to turn it | |
2100 | to a hardware one -- count resources as if B was of | |
2101 | hardware watchpoint type. */ | |
2102 | type = b->base.type; | |
2103 | if (type == bp_watchpoint) | |
2104 | type = bp_hardware_watchpoint; | |
2105 | ||
2106 | /* This watchpoint may or may not have been placed on | |
2107 | the list yet at this point (it won't be in the list | |
2108 | if we're trying to create it for the first time, | |
2109 | through watch_command), so always account for it | |
2110 | manually. */ | |
2111 | ||
2112 | /* Count resources used by all watchpoints except B. */ | |
2113 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); | |
2114 | ||
2115 | /* Add in the resources needed for B. */ | |
2116 | i += hw_watchpoint_use_count (&b->base); | |
2117 | ||
2118 | target_resources_ok | |
2119 | = target_can_use_hardware_watchpoint (type, i, other_type_used); | |
e09342b5 | 2120 | if (target_resources_ok <= 0) |
a9634178 | 2121 | { |
3a5c3e22 | 2122 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
2123 | |
2124 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
2125 | error (_("Target does not support this type of " |
2126 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
2127 | else if (target_resources_ok < 0 && !sw_mode) |
2128 | error (_("There are not enough available hardware " | |
2129 | "resources for this watchpoint.")); | |
a1398e0c PA |
2130 | |
2131 | /* Downgrade to software watchpoint. */ | |
2132 | b->base.type = bp_watchpoint; | |
2133 | } | |
2134 | else | |
2135 | { | |
2136 | /* If this was a software watchpoint, we've just | |
2137 | found we have enough resources to turn it to a | |
2138 | hardware watchpoint. Otherwise, this is a | |
2139 | nop. */ | |
2140 | b->base.type = type; | |
a9634178 | 2141 | } |
9fa40276 | 2142 | } |
3a5c3e22 | 2143 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
638aa5a1 AB |
2144 | { |
2145 | if (!can_use_hw_watchpoints) | |
2146 | error (_("Can't set read/access watchpoint when " | |
2147 | "hardware watchpoints are disabled.")); | |
2148 | else | |
2149 | error (_("Expression cannot be implemented with " | |
2150 | "read/access watchpoint.")); | |
2151 | } | |
9fa40276 | 2152 | else |
3a5c3e22 | 2153 | b->base.type = bp_watchpoint; |
9fa40276 | 2154 | |
3a5c3e22 | 2155 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 2156 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 2157 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
2158 | bl->loc_type = loc_type; |
2159 | } | |
2160 | ||
2161 | for (v = val_chain; v; v = next) | |
2162 | { | |
a5606eee VP |
2163 | next = value_next (v); |
2164 | if (v != b->val) | |
2165 | value_free (v); | |
2166 | } | |
2167 | ||
c7437ca6 PA |
2168 | /* If a software watchpoint is not watching any memory, then the |
2169 | above left it without any location set up. But, | |
2170 | bpstat_stop_status requires a location to be able to report | |
2171 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 2172 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c6d81124 | 2173 | software_watchpoint_add_no_memory_location (&b->base, frame_pspace); |
a5606eee VP |
2174 | } |
2175 | else if (!within_current_scope) | |
7270d8f2 | 2176 | { |
ac74f770 MS |
2177 | printf_filtered (_("\ |
2178 | Watchpoint %d deleted because the program has left the block\n\ | |
2179 | in which its expression is valid.\n"), | |
3a5c3e22 | 2180 | b->base.number); |
d0fb5eae | 2181 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 2182 | } |
a5606eee VP |
2183 | |
2184 | /* Restore the selected frame. */ | |
66076460 DJ |
2185 | if (frame_saved) |
2186 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
2187 | } |
2188 | ||
a5606eee | 2189 | |
74960c60 | 2190 | /* Returns 1 iff breakpoint location should be |
1e4d1764 YQ |
2191 | inserted in the inferior. We don't differentiate the type of BL's owner |
2192 | (breakpoint vs. tracepoint), although insert_location in tracepoint's | |
2193 | breakpoint_ops is not defined, because in insert_bp_location, | |
2194 | tracepoint's insert_location will not be called. */ | |
74960c60 | 2195 | static int |
35df4500 | 2196 | should_be_inserted (struct bp_location *bl) |
74960c60 | 2197 | { |
35df4500 | 2198 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
2199 | return 0; |
2200 | ||
35df4500 | 2201 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
2202 | return 0; |
2203 | ||
35df4500 | 2204 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
2205 | return 0; |
2206 | ||
f8eba3c6 TT |
2207 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
2208 | return 0; | |
2209 | ||
56710373 PA |
2210 | /* This is set for example, when we're attached to the parent of a |
2211 | vfork, and have detached from the child. The child is running | |
2212 | free, and we expect it to do an exec or exit, at which point the | |
2213 | OS makes the parent schedulable again (and the target reports | |
2214 | that the vfork is done). Until the child is done with the shared | |
2215 | memory region, do not insert breakpoints in the parent, otherwise | |
2216 | the child could still trip on the parent's breakpoints. Since | |
2217 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 2218 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
2219 | return 0; |
2220 | ||
31e77af2 PA |
2221 | /* Don't insert a breakpoint if we're trying to step past its |
2222 | location. */ | |
2223 | if ((bl->loc_type == bp_loc_software_breakpoint | |
2224 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
2225 | && stepping_past_instruction_at (bl->pspace->aspace, | |
2226 | bl->address)) | |
e558d7c1 PA |
2227 | { |
2228 | if (debug_infrun) | |
2229 | { | |
2230 | fprintf_unfiltered (gdb_stdlog, | |
2231 | "infrun: skipping breakpoint: " | |
2232 | "stepping past insn at: %s\n", | |
2233 | paddress (bl->gdbarch, bl->address)); | |
2234 | } | |
2235 | return 0; | |
2236 | } | |
31e77af2 | 2237 | |
963f9c80 PA |
2238 | /* Don't insert watchpoints if we're trying to step past the |
2239 | instruction that triggered one. */ | |
2240 | if ((bl->loc_type == bp_loc_hardware_watchpoint) | |
2241 | && stepping_past_nonsteppable_watchpoint ()) | |
2242 | { | |
2243 | if (debug_infrun) | |
2244 | { | |
2245 | fprintf_unfiltered (gdb_stdlog, | |
2246 | "infrun: stepping past non-steppable watchpoint. " | |
2247 | "skipping watchpoint at %s:%d\n", | |
2248 | paddress (bl->gdbarch, bl->address), | |
2249 | bl->length); | |
2250 | } | |
2251 | return 0; | |
2252 | } | |
2253 | ||
74960c60 VP |
2254 | return 1; |
2255 | } | |
2256 | ||
934709f0 PW |
2257 | /* Same as should_be_inserted but does the check assuming |
2258 | that the location is not duplicated. */ | |
2259 | ||
2260 | static int | |
2261 | unduplicated_should_be_inserted (struct bp_location *bl) | |
2262 | { | |
2263 | int result; | |
2264 | const int save_duplicate = bl->duplicate; | |
2265 | ||
2266 | bl->duplicate = 0; | |
2267 | result = should_be_inserted (bl); | |
2268 | bl->duplicate = save_duplicate; | |
2269 | return result; | |
2270 | } | |
2271 | ||
b775012e LM |
2272 | /* Parses a conditional described by an expression COND into an |
2273 | agent expression bytecode suitable for evaluation | |
2274 | by the bytecode interpreter. Return NULL if there was | |
2275 | any error during parsing. */ | |
2276 | ||
2277 | static struct agent_expr * | |
2278 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) | |
2279 | { | |
2280 | struct agent_expr *aexpr = NULL; | |
b775012e LM |
2281 | |
2282 | if (!cond) | |
2283 | return NULL; | |
2284 | ||
2285 | /* We don't want to stop processing, so catch any errors | |
2286 | that may show up. */ | |
492d29ea | 2287 | TRY |
b775012e LM |
2288 | { |
2289 | aexpr = gen_eval_for_expr (scope, cond); | |
2290 | } | |
2291 | ||
492d29ea | 2292 | CATCH (ex, RETURN_MASK_ERROR) |
b775012e LM |
2293 | { |
2294 | /* If we got here, it means the condition could not be parsed to a valid | |
2295 | bytecode expression and thus can't be evaluated on the target's side. | |
2296 | It's no use iterating through the conditions. */ | |
2297 | return NULL; | |
2298 | } | |
492d29ea | 2299 | END_CATCH |
b775012e LM |
2300 | |
2301 | /* We have a valid agent expression. */ | |
2302 | return aexpr; | |
2303 | } | |
2304 | ||
2305 | /* Based on location BL, create a list of breakpoint conditions to be | |
2306 | passed on to the target. If we have duplicated locations with different | |
2307 | conditions, we will add such conditions to the list. The idea is that the | |
2308 | target will evaluate the list of conditions and will only notify GDB when | |
2309 | one of them is true. */ | |
2310 | ||
2311 | static void | |
2312 | build_target_condition_list (struct bp_location *bl) | |
2313 | { | |
2314 | struct bp_location **locp = NULL, **loc2p; | |
2315 | int null_condition_or_parse_error = 0; | |
2316 | int modified = bl->needs_update; | |
2317 | struct bp_location *loc; | |
2318 | ||
8b4f3082 PA |
2319 | /* Release conditions left over from a previous insert. */ |
2320 | VEC_free (agent_expr_p, bl->target_info.conditions); | |
2321 | ||
b775012e LM |
2322 | /* This is only meaningful if the target is |
2323 | evaluating conditions and if the user has | |
2324 | opted for condition evaluation on the target's | |
2325 | side. */ | |
2326 | if (gdb_evaluates_breakpoint_condition_p () | |
2327 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
2328 | return; | |
2329 | ||
2330 | /* Do a first pass to check for locations with no assigned | |
2331 | conditions or conditions that fail to parse to a valid agent expression | |
2332 | bytecode. If any of these happen, then it's no use to send conditions | |
2333 | to the target since this location will always trigger and generate a | |
2334 | response back to GDB. */ | |
2335 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2336 | { | |
2337 | loc = (*loc2p); | |
2338 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2339 | { | |
2340 | if (modified) | |
2341 | { | |
2342 | struct agent_expr *aexpr; | |
2343 | ||
2344 | /* Re-parse the conditions since something changed. In that | |
2345 | case we already freed the condition bytecodes (see | |
2346 | force_breakpoint_reinsertion). We just | |
2347 | need to parse the condition to bytecodes again. */ | |
2348 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); | |
2349 | loc->cond_bytecode = aexpr; | |
b775012e LM |
2350 | } |
2351 | ||
2352 | /* If we have a NULL bytecode expression, it means something | |
2353 | went wrong or we have a null condition expression. */ | |
2354 | if (!loc->cond_bytecode) | |
2355 | { | |
2356 | null_condition_or_parse_error = 1; | |
2357 | break; | |
2358 | } | |
2359 | } | |
2360 | } | |
2361 | ||
2362 | /* If any of these happened, it means we will have to evaluate the conditions | |
2363 | for the location's address on gdb's side. It is no use keeping bytecodes | |
2364 | for all the other duplicate locations, thus we free all of them here. | |
2365 | ||
2366 | This is so we have a finer control over which locations' conditions are | |
2367 | being evaluated by GDB or the remote stub. */ | |
2368 | if (null_condition_or_parse_error) | |
2369 | { | |
2370 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2371 | { | |
2372 | loc = (*loc2p); | |
2373 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2374 | { | |
2375 | /* Only go as far as the first NULL bytecode is | |
2376 | located. */ | |
2377 | if (!loc->cond_bytecode) | |
2378 | return; | |
2379 | ||
2380 | free_agent_expr (loc->cond_bytecode); | |
2381 | loc->cond_bytecode = NULL; | |
2382 | } | |
2383 | } | |
2384 | } | |
2385 | ||
2386 | /* No NULL conditions or failed bytecode generation. Build a condition list | |
2387 | for this location's address. */ | |
2388 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2389 | { | |
2390 | loc = (*loc2p); | |
2391 | if (loc->cond | |
2392 | && is_breakpoint (loc->owner) | |
2393 | && loc->pspace->num == bl->pspace->num | |
2394 | && loc->owner->enable_state == bp_enabled | |
2395 | && loc->enabled) | |
2396 | /* Add the condition to the vector. This will be used later to send the | |
2397 | conditions to the target. */ | |
2398 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, | |
2399 | loc->cond_bytecode); | |
2400 | } | |
2401 | ||
2402 | return; | |
2403 | } | |
2404 | ||
d3ce09f5 SS |
2405 | /* Parses a command described by string CMD into an agent expression |
2406 | bytecode suitable for evaluation by the bytecode interpreter. | |
2407 | Return NULL if there was any error during parsing. */ | |
2408 | ||
2409 | static struct agent_expr * | |
2410 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) | |
2411 | { | |
2412 | struct cleanup *old_cleanups = 0; | |
2413 | struct expression *expr, **argvec; | |
2414 | struct agent_expr *aexpr = NULL; | |
bbc13ae3 KS |
2415 | const char *cmdrest; |
2416 | const char *format_start, *format_end; | |
d3ce09f5 SS |
2417 | struct format_piece *fpieces; |
2418 | int nargs; | |
2419 | struct gdbarch *gdbarch = get_current_arch (); | |
2420 | ||
2421 | if (!cmd) | |
2422 | return NULL; | |
2423 | ||
2424 | cmdrest = cmd; | |
2425 | ||
2426 | if (*cmdrest == ',') | |
2427 | ++cmdrest; | |
bbc13ae3 | 2428 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2429 | |
2430 | if (*cmdrest++ != '"') | |
2431 | error (_("No format string following the location")); | |
2432 | ||
2433 | format_start = cmdrest; | |
2434 | ||
2435 | fpieces = parse_format_string (&cmdrest); | |
2436 | ||
2437 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); | |
2438 | ||
2439 | format_end = cmdrest; | |
2440 | ||
2441 | if (*cmdrest++ != '"') | |
2442 | error (_("Bad format string, non-terminated '\"'.")); | |
2443 | ||
bbc13ae3 | 2444 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2445 | |
2446 | if (!(*cmdrest == ',' || *cmdrest == '\0')) | |
2447 | error (_("Invalid argument syntax")); | |
2448 | ||
2449 | if (*cmdrest == ',') | |
2450 | cmdrest++; | |
bbc13ae3 | 2451 | cmdrest = skip_spaces_const (cmdrest); |
d3ce09f5 SS |
2452 | |
2453 | /* For each argument, make an expression. */ | |
2454 | ||
2455 | argvec = (struct expression **) alloca (strlen (cmd) | |
2456 | * sizeof (struct expression *)); | |
2457 | ||
2458 | nargs = 0; | |
2459 | while (*cmdrest != '\0') | |
2460 | { | |
bbc13ae3 | 2461 | const char *cmd1; |
d3ce09f5 SS |
2462 | |
2463 | cmd1 = cmdrest; | |
2464 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); | |
2465 | argvec[nargs++] = expr; | |
2466 | cmdrest = cmd1; | |
2467 | if (*cmdrest == ',') | |
2468 | ++cmdrest; | |
2469 | } | |
2470 | ||
2471 | /* We don't want to stop processing, so catch any errors | |
2472 | that may show up. */ | |
492d29ea | 2473 | TRY |
d3ce09f5 SS |
2474 | { |
2475 | aexpr = gen_printf (scope, gdbarch, 0, 0, | |
2476 | format_start, format_end - format_start, | |
2477 | fpieces, nargs, argvec); | |
2478 | } | |
492d29ea | 2479 | CATCH (ex, RETURN_MASK_ERROR) |
d3ce09f5 SS |
2480 | { |
2481 | /* If we got here, it means the command could not be parsed to a valid | |
2482 | bytecode expression and thus can't be evaluated on the target's side. | |
2483 | It's no use iterating through the other commands. */ | |
492d29ea | 2484 | aexpr = NULL; |
d3ce09f5 | 2485 | } |
492d29ea PA |
2486 | END_CATCH |
2487 | ||
2488 | do_cleanups (old_cleanups); | |
d3ce09f5 | 2489 | |
d3ce09f5 SS |
2490 | /* We have a valid agent expression, return it. */ |
2491 | return aexpr; | |
2492 | } | |
2493 | ||
2494 | /* Based on location BL, create a list of breakpoint commands to be | |
2495 | passed on to the target. If we have duplicated locations with | |
2496 | different commands, we will add any such to the list. */ | |
2497 | ||
2498 | static void | |
2499 | build_target_command_list (struct bp_location *bl) | |
2500 | { | |
2501 | struct bp_location **locp = NULL, **loc2p; | |
2502 | int null_command_or_parse_error = 0; | |
2503 | int modified = bl->needs_update; | |
2504 | struct bp_location *loc; | |
2505 | ||
8b4f3082 PA |
2506 | /* Release commands left over from a previous insert. */ |
2507 | VEC_free (agent_expr_p, bl->target_info.tcommands); | |
2508 | ||
41fac0cf | 2509 | if (!target_can_run_breakpoint_commands ()) |
d3ce09f5 SS |
2510 | return; |
2511 | ||
41fac0cf PA |
2512 | /* For now, limit to agent-style dprintf breakpoints. */ |
2513 | if (dprintf_style != dprintf_style_agent) | |
d3ce09f5 SS |
2514 | return; |
2515 | ||
41fac0cf PA |
2516 | /* For now, if we have any duplicate location that isn't a dprintf, |
2517 | don't install the target-side commands, as that would make the | |
2518 | breakpoint not be reported to the core, and we'd lose | |
2519 | control. */ | |
2520 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2521 | { | |
2522 | loc = (*loc2p); | |
2523 | if (is_breakpoint (loc->owner) | |
2524 | && loc->pspace->num == bl->pspace->num | |
2525 | && loc->owner->type != bp_dprintf) | |
2526 | return; | |
2527 | } | |
2528 | ||
d3ce09f5 SS |
2529 | /* Do a first pass to check for locations with no assigned |
2530 | conditions or conditions that fail to parse to a valid agent expression | |
2531 | bytecode. If any of these happen, then it's no use to send conditions | |
2532 | to the target since this location will always trigger and generate a | |
2533 | response back to GDB. */ | |
2534 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2535 | { | |
2536 | loc = (*loc2p); | |
2537 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) | |
2538 | { | |
2539 | if (modified) | |
2540 | { | |
2541 | struct agent_expr *aexpr; | |
2542 | ||
2543 | /* Re-parse the commands since something changed. In that | |
2544 | case we already freed the command bytecodes (see | |
2545 | force_breakpoint_reinsertion). We just | |
2546 | need to parse the command to bytecodes again. */ | |
2547 | aexpr = parse_cmd_to_aexpr (bl->address, | |
2548 | loc->owner->extra_string); | |
2549 | loc->cmd_bytecode = aexpr; | |
d3ce09f5 SS |
2550 | } |
2551 | ||
2552 | /* If we have a NULL bytecode expression, it means something | |
2553 | went wrong or we have a null command expression. */ | |
2554 | if (!loc->cmd_bytecode) | |
2555 | { | |
2556 | null_command_or_parse_error = 1; | |
2557 | break; | |
2558 | } | |
2559 | } | |
2560 | } | |
2561 | ||
2562 | /* If anything failed, then we're not doing target-side commands, | |
2563 | and so clean up. */ | |
2564 | if (null_command_or_parse_error) | |
2565 | { | |
2566 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2567 | { | |
2568 | loc = (*loc2p); | |
2569 | if (is_breakpoint (loc->owner) | |
2570 | && loc->pspace->num == bl->pspace->num) | |
2571 | { | |
2572 | /* Only go as far as the first NULL bytecode is | |
2573 | located. */ | |
40fb6c5e | 2574 | if (loc->cmd_bytecode == NULL) |
d3ce09f5 SS |
2575 | return; |
2576 | ||
40fb6c5e HZ |
2577 | free_agent_expr (loc->cmd_bytecode); |
2578 | loc->cmd_bytecode = NULL; | |
d3ce09f5 SS |
2579 | } |
2580 | } | |
2581 | } | |
2582 | ||
2583 | /* No NULL commands or failed bytecode generation. Build a command list | |
2584 | for this location's address. */ | |
2585 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) | |
2586 | { | |
2587 | loc = (*loc2p); | |
2588 | if (loc->owner->extra_string | |
2589 | && is_breakpoint (loc->owner) | |
2590 | && loc->pspace->num == bl->pspace->num | |
2591 | && loc->owner->enable_state == bp_enabled | |
2592 | && loc->enabled) | |
2593 | /* Add the command to the vector. This will be used later | |
2594 | to send the commands to the target. */ | |
2595 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, | |
2596 | loc->cmd_bytecode); | |
2597 | } | |
2598 | ||
2599 | bl->target_info.persist = 0; | |
2600 | /* Maybe flag this location as persistent. */ | |
2601 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) | |
2602 | bl->target_info.persist = 1; | |
2603 | } | |
2604 | ||
35df4500 TJB |
2605 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
2606 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 2607 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
2608 | Returns 0 for success, 1 if the bp_location type is not supported or |
2609 | -1 for failure. | |
879bfdc2 | 2610 | |
4a64f543 MS |
2611 | NOTE drow/2003-09-09: This routine could be broken down to an |
2612 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 2613 | static int |
35df4500 | 2614 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 2615 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 2616 | int *disabled_breaks, |
dd61ec5c MW |
2617 | int *hw_breakpoint_error, |
2618 | int *hw_bp_error_explained_already) | |
879bfdc2 | 2619 | { |
0000e5cc PA |
2620 | enum errors bp_err = GDB_NO_ERROR; |
2621 | const char *bp_err_message = NULL; | |
879bfdc2 | 2622 | |
b775012e | 2623 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
2624 | return 0; |
2625 | ||
35c63cd8 JB |
2626 | /* Note we don't initialize bl->target_info, as that wipes out |
2627 | the breakpoint location's shadow_contents if the breakpoint | |
2628 | is still inserted at that location. This in turn breaks | |
2629 | target_read_memory which depends on these buffers when | |
2630 | a memory read is requested at the breakpoint location: | |
2631 | Once the target_info has been wiped, we fail to see that | |
2632 | we have a breakpoint inserted at that address and thus | |
2633 | read the breakpoint instead of returning the data saved in | |
2634 | the breakpoint location's shadow contents. */ | |
0d5ed153 | 2635 | bl->target_info.reqstd_address = bl->address; |
35df4500 | 2636 | bl->target_info.placed_address_space = bl->pspace->aspace; |
f1310107 | 2637 | bl->target_info.length = bl->length; |
8181d85f | 2638 | |
b775012e LM |
2639 | /* When working with target-side conditions, we must pass all the conditions |
2640 | for the same breakpoint address down to the target since GDB will not | |
2641 | insert those locations. With a list of breakpoint conditions, the target | |
2642 | can decide when to stop and notify GDB. */ | |
2643 | ||
2644 | if (is_breakpoint (bl->owner)) | |
2645 | { | |
2646 | build_target_condition_list (bl); | |
d3ce09f5 SS |
2647 | build_target_command_list (bl); |
2648 | /* Reset the modification marker. */ | |
b775012e LM |
2649 | bl->needs_update = 0; |
2650 | } | |
2651 | ||
35df4500 TJB |
2652 | if (bl->loc_type == bp_loc_software_breakpoint |
2653 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 2654 | { |
35df4500 | 2655 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
2656 | { |
2657 | /* If the explicitly specified breakpoint type | |
2658 | is not hardware breakpoint, check the memory map to see | |
2659 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 2660 | |
765dc015 VP |
2661 | Two important cases are: |
2662 | - location type is not hardware breakpoint, memory | |
2663 | is readonly. We change the type of the location to | |
2664 | hardware breakpoint. | |
4a64f543 MS |
2665 | - location type is hardware breakpoint, memory is |
2666 | read-write. This means we've previously made the | |
2667 | location hardware one, but then the memory map changed, | |
2668 | so we undo. | |
765dc015 | 2669 | |
4a64f543 MS |
2670 | When breakpoints are removed, remove_breakpoints will use |
2671 | location types we've just set here, the only possible | |
2672 | problem is that memory map has changed during running | |
2673 | program, but it's not going to work anyway with current | |
2674 | gdb. */ | |
765dc015 | 2675 | struct mem_region *mr |
0d5ed153 | 2676 | = lookup_mem_region (bl->target_info.reqstd_address); |
765dc015 VP |
2677 | |
2678 | if (mr) | |
2679 | { | |
2680 | if (automatic_hardware_breakpoints) | |
2681 | { | |
765dc015 VP |
2682 | enum bp_loc_type new_type; |
2683 | ||
2684 | if (mr->attrib.mode != MEM_RW) | |
2685 | new_type = bp_loc_hardware_breakpoint; | |
2686 | else | |
2687 | new_type = bp_loc_software_breakpoint; | |
2688 | ||
35df4500 | 2689 | if (new_type != bl->loc_type) |
765dc015 VP |
2690 | { |
2691 | static int said = 0; | |
cc59ec59 | 2692 | |
35df4500 | 2693 | bl->loc_type = new_type; |
765dc015 VP |
2694 | if (!said) |
2695 | { | |
3e43a32a MS |
2696 | fprintf_filtered (gdb_stdout, |
2697 | _("Note: automatically using " | |
2698 | "hardware breakpoints for " | |
2699 | "read-only addresses.\n")); | |
765dc015 VP |
2700 | said = 1; |
2701 | } | |
2702 | } | |
2703 | } | |
35df4500 | 2704 | else if (bl->loc_type == bp_loc_software_breakpoint |
0fec99e8 PA |
2705 | && mr->attrib.mode != MEM_RW) |
2706 | { | |
2707 | fprintf_unfiltered (tmp_error_stream, | |
2708 | _("Cannot insert breakpoint %d.\n" | |
2709 | "Cannot set software breakpoint " | |
2710 | "at read-only address %s\n"), | |
2711 | bl->owner->number, | |
2712 | paddress (bl->gdbarch, bl->address)); | |
2713 | return 1; | |
2714 | } | |
765dc015 VP |
2715 | } |
2716 | } | |
2717 | ||
879bfdc2 DJ |
2718 | /* First check to see if we have to handle an overlay. */ |
2719 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2720 | || bl->section == NULL |
2721 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
2722 | { |
2723 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2724 | TRY |
dd61ec5c | 2725 | { |
0000e5cc PA |
2726 | int val; |
2727 | ||
dd61ec5c | 2728 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2729 | if (val) |
2730 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2731 | } |
492d29ea | 2732 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2733 | { |
0000e5cc PA |
2734 | bp_err = e.error; |
2735 | bp_err_message = e.message; | |
dd61ec5c | 2736 | } |
492d29ea | 2737 | END_CATCH |
879bfdc2 DJ |
2738 | } |
2739 | else | |
2740 | { | |
4a64f543 | 2741 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
2742 | Shall we set a breakpoint at the LMA? */ |
2743 | if (!overlay_events_enabled) | |
2744 | { | |
2745 | /* Yes -- overlay event support is not active, | |
2746 | so we must try to set a breakpoint at the LMA. | |
2747 | This will not work for a hardware breakpoint. */ | |
35df4500 | 2748 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 2749 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 2750 | bl->owner->number); |
879bfdc2 DJ |
2751 | else |
2752 | { | |
35df4500 TJB |
2753 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
2754 | bl->section); | |
879bfdc2 | 2755 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 | 2756 | bl->overlay_target_info = bl->target_info; |
0d5ed153 | 2757 | bl->overlay_target_info.reqstd_address = addr; |
0000e5cc PA |
2758 | |
2759 | /* No overlay handling: just set the breakpoint. */ | |
492d29ea | 2760 | TRY |
0000e5cc PA |
2761 | { |
2762 | int val; | |
2763 | ||
2764 | val = target_insert_breakpoint (bl->gdbarch, | |
2765 | &bl->overlay_target_info); | |
2766 | if (val) | |
2767 | bp_err = GENERIC_ERROR; | |
2768 | } | |
492d29ea | 2769 | CATCH (e, RETURN_MASK_ALL) |
0000e5cc PA |
2770 | { |
2771 | bp_err = e.error; | |
2772 | bp_err_message = e.message; | |
2773 | } | |
492d29ea | 2774 | END_CATCH |
0000e5cc PA |
2775 | |
2776 | if (bp_err != GDB_NO_ERROR) | |
99361f52 | 2777 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
2778 | "Overlay breakpoint %d " |
2779 | "failed: in ROM?\n", | |
35df4500 | 2780 | bl->owner->number); |
879bfdc2 DJ |
2781 | } |
2782 | } | |
2783 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 2784 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
2785 | { |
2786 | /* Yes. This overlay section is mapped into memory. */ | |
492d29ea | 2787 | TRY |
dd61ec5c | 2788 | { |
0000e5cc PA |
2789 | int val; |
2790 | ||
dd61ec5c | 2791 | val = bl->owner->ops->insert_location (bl); |
0000e5cc PA |
2792 | if (val) |
2793 | bp_err = GENERIC_ERROR; | |
dd61ec5c | 2794 | } |
492d29ea | 2795 | CATCH (e, RETURN_MASK_ALL) |
dd61ec5c | 2796 | { |
0000e5cc PA |
2797 | bp_err = e.error; |
2798 | bp_err_message = e.message; | |
dd61ec5c | 2799 | } |
492d29ea | 2800 | END_CATCH |
879bfdc2 DJ |
2801 | } |
2802 | else | |
2803 | { | |
2804 | /* No. This breakpoint will not be inserted. | |
2805 | No error, but do not mark the bp as 'inserted'. */ | |
2806 | return 0; | |
2807 | } | |
2808 | } | |
2809 | ||
0000e5cc | 2810 | if (bp_err != GDB_NO_ERROR) |
879bfdc2 DJ |
2811 | { |
2812 | /* Can't set the breakpoint. */ | |
0000e5cc PA |
2813 | |
2814 | /* In some cases, we might not be able to insert a | |
2815 | breakpoint in a shared library that has already been | |
2816 | removed, but we have not yet processed the shlib unload | |
2817 | event. Unfortunately, some targets that implement | |
076855f9 PA |
2818 | breakpoint insertion themselves can't tell why the |
2819 | breakpoint insertion failed (e.g., the remote target | |
2820 | doesn't define error codes), so we must treat generic | |
2821 | errors as memory errors. */ | |
0000e5cc | 2822 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
076855f9 | 2823 | && bl->loc_type == bp_loc_software_breakpoint |
08351840 | 2824 | && (solib_name_from_address (bl->pspace, bl->address) |
d03de421 PA |
2825 | || shared_objfile_contains_address_p (bl->pspace, |
2826 | bl->address))) | |
879bfdc2 | 2827 | { |
4a64f543 | 2828 | /* See also: disable_breakpoints_in_shlibs. */ |
35df4500 | 2829 | bl->shlib_disabled = 1; |
8d3788bd | 2830 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
2831 | if (!*disabled_breaks) |
2832 | { | |
2833 | fprintf_unfiltered (tmp_error_stream, | |
2834 | "Cannot insert breakpoint %d.\n", | |
2835 | bl->owner->number); | |
2836 | fprintf_unfiltered (tmp_error_stream, | |
2837 | "Temporarily disabling shared " | |
2838 | "library breakpoints:\n"); | |
2839 | } | |
2840 | *disabled_breaks = 1; | |
879bfdc2 | 2841 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 2842 | "breakpoint #%d\n", bl->owner->number); |
0000e5cc | 2843 | return 0; |
879bfdc2 DJ |
2844 | } |
2845 | else | |
879bfdc2 | 2846 | { |
35df4500 | 2847 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 | 2848 | { |
0000e5cc PA |
2849 | *hw_breakpoint_error = 1; |
2850 | *hw_bp_error_explained_already = bp_err_message != NULL; | |
dd61ec5c MW |
2851 | fprintf_unfiltered (tmp_error_stream, |
2852 | "Cannot insert hardware breakpoint %d%s", | |
0000e5cc PA |
2853 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
2854 | if (bp_err_message != NULL) | |
2855 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); | |
879bfdc2 DJ |
2856 | } |
2857 | else | |
2858 | { | |
0000e5cc PA |
2859 | if (bp_err_message == NULL) |
2860 | { | |
2861 | char *message | |
2862 | = memory_error_message (TARGET_XFER_E_IO, | |
2863 | bl->gdbarch, bl->address); | |
2864 | struct cleanup *old_chain = make_cleanup (xfree, message); | |
2865 | ||
2866 | fprintf_unfiltered (tmp_error_stream, | |
2867 | "Cannot insert breakpoint %d.\n" | |
2868 | "%s\n", | |
2869 | bl->owner->number, message); | |
2870 | do_cleanups (old_chain); | |
2871 | } | |
2872 | else | |
2873 | { | |
2874 | fprintf_unfiltered (tmp_error_stream, | |
2875 | "Cannot insert breakpoint %d: %s\n", | |
2876 | bl->owner->number, | |
2877 | bp_err_message); | |
2878 | } | |
879bfdc2 | 2879 | } |
0000e5cc | 2880 | return 1; |
879bfdc2 DJ |
2881 | |
2882 | } | |
2883 | } | |
2884 | else | |
35df4500 | 2885 | bl->inserted = 1; |
879bfdc2 | 2886 | |
0000e5cc | 2887 | return 0; |
879bfdc2 DJ |
2888 | } |
2889 | ||
35df4500 | 2890 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 2891 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 2892 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 2893 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 2894 | { |
0000e5cc PA |
2895 | int val; |
2896 | ||
77b06cd7 TJB |
2897 | gdb_assert (bl->owner->ops != NULL |
2898 | && bl->owner->ops->insert_location != NULL); | |
2899 | ||
2900 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
2901 | |
2902 | /* If trying to set a read-watchpoint, and it turns out it's not | |
2903 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 2904 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
2905 | { |
2906 | struct bp_location *loc, **loc_temp; | |
2907 | ||
2908 | /* But don't try to insert it, if there's already another | |
2909 | hw_access location that would be considered a duplicate | |
2910 | of this one. */ | |
2911 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 2912 | if (loc != bl |
85d721b8 | 2913 | && loc->watchpoint_type == hw_access |
35df4500 | 2914 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 2915 | { |
35df4500 TJB |
2916 | bl->duplicate = 1; |
2917 | bl->inserted = 1; | |
2918 | bl->target_info = loc->target_info; | |
2919 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
2920 | val = 0; |
2921 | break; | |
2922 | } | |
2923 | ||
2924 | if (val == 1) | |
2925 | { | |
77b06cd7 TJB |
2926 | bl->watchpoint_type = hw_access; |
2927 | val = bl->owner->ops->insert_location (bl); | |
2928 | ||
2929 | if (val) | |
2930 | /* Back to the original value. */ | |
2931 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
2932 | } |
2933 | } | |
2934 | ||
35df4500 | 2935 | bl->inserted = (val == 0); |
879bfdc2 DJ |
2936 | } |
2937 | ||
35df4500 | 2938 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 2939 | { |
0000e5cc PA |
2940 | int val; |
2941 | ||
77b06cd7 TJB |
2942 | gdb_assert (bl->owner->ops != NULL |
2943 | && bl->owner->ops->insert_location != NULL); | |
2944 | ||
2945 | val = bl->owner->ops->insert_location (bl); | |
2946 | if (val) | |
2947 | { | |
2948 | bl->owner->enable_state = bp_disabled; | |
2949 | ||
2950 | if (val == 1) | |
2951 | warning (_("\ | |
2952 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
2953 | of catchpoint."), bl->owner->number); | |
2954 | else | |
2955 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
2956 | } | |
2957 | ||
2958 | bl->inserted = (val == 0); | |
1640b821 DJ |
2959 | |
2960 | /* We've already printed an error message if there was a problem | |
2961 | inserting this catchpoint, and we've disabled the catchpoint, | |
2962 | so just return success. */ | |
2963 | return 0; | |
879bfdc2 DJ |
2964 | } |
2965 | ||
2966 | return 0; | |
2967 | } | |
2968 | ||
6c95b8df PA |
2969 | /* This function is called when program space PSPACE is about to be |
2970 | deleted. It takes care of updating breakpoints to not reference | |
2971 | PSPACE anymore. */ | |
2972 | ||
2973 | void | |
2974 | breakpoint_program_space_exit (struct program_space *pspace) | |
2975 | { | |
2976 | struct breakpoint *b, *b_temp; | |
876fa593 | 2977 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
2978 | |
2979 | /* Remove any breakpoint that was set through this program space. */ | |
2980 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
2981 | { | |
2982 | if (b->pspace == pspace) | |
2983 | delete_breakpoint (b); | |
2984 | } | |
2985 | ||
2986 | /* Breakpoints set through other program spaces could have locations | |
2987 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 2988 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
2989 | { |
2990 | struct bp_location *tmp; | |
2991 | ||
2992 | if (loc->pspace == pspace) | |
2993 | { | |
2bdf28a0 | 2994 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
2995 | if (loc->owner->loc == loc) |
2996 | loc->owner->loc = loc->next; | |
2997 | else | |
2998 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
2999 | if (tmp->next == loc) | |
3000 | { | |
3001 | tmp->next = loc->next; | |
3002 | break; | |
3003 | } | |
3004 | } | |
3005 | } | |
3006 | ||
3007 | /* Now update the global location list to permanently delete the | |
3008 | removed locations above. */ | |
44702360 | 3009 | update_global_location_list (UGLL_DONT_INSERT); |
6c95b8df PA |
3010 | } |
3011 | ||
74960c60 VP |
3012 | /* Make sure all breakpoints are inserted in inferior. |
3013 | Throws exception on any error. | |
3014 | A breakpoint that is already inserted won't be inserted | |
3015 | again, so calling this function twice is safe. */ | |
3016 | void | |
3017 | insert_breakpoints (void) | |
3018 | { | |
3019 | struct breakpoint *bpt; | |
3020 | ||
3021 | ALL_BREAKPOINTS (bpt) | |
3022 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
3023 | { |
3024 | struct watchpoint *w = (struct watchpoint *) bpt; | |
3025 | ||
3026 | update_watchpoint (w, 0 /* don't reparse. */); | |
3027 | } | |
74960c60 | 3028 | |
04086b45 PA |
3029 | /* Updating watchpoints creates new locations, so update the global |
3030 | location list. Explicitly tell ugll to insert locations and | |
3031 | ignore breakpoints_always_inserted_mode. */ | |
3032 | update_global_location_list (UGLL_INSERT); | |
74960c60 VP |
3033 | } |
3034 | ||
20388dd6 YQ |
3035 | /* Invoke CALLBACK for each of bp_location. */ |
3036 | ||
3037 | void | |
3038 | iterate_over_bp_locations (walk_bp_location_callback callback) | |
3039 | { | |
3040 | struct bp_location *loc, **loc_tmp; | |
3041 | ||
3042 | ALL_BP_LOCATIONS (loc, loc_tmp) | |
3043 | { | |
3044 | callback (loc, NULL); | |
3045 | } | |
3046 | } | |
3047 | ||
b775012e LM |
3048 | /* This is used when we need to synch breakpoint conditions between GDB and the |
3049 | target. It is the case with deleting and disabling of breakpoints when using | |
3050 | always-inserted mode. */ | |
3051 | ||
3052 | static void | |
3053 | update_inserted_breakpoint_locations (void) | |
3054 | { | |
3055 | struct bp_location *bl, **blp_tmp; | |
3056 | int error_flag = 0; | |
3057 | int val = 0; | |
3058 | int disabled_breaks = 0; | |
3059 | int hw_breakpoint_error = 0; | |
dd61ec5c | 3060 | int hw_bp_details_reported = 0; |
b775012e LM |
3061 | |
3062 | struct ui_file *tmp_error_stream = mem_fileopen (); | |
3063 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); | |
3064 | ||
3065 | /* Explicitly mark the warning -- this will only be printed if | |
3066 | there was an error. */ | |
3067 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
3068 | ||
3069 | save_current_space_and_thread (); | |
3070 | ||
3071 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
3072 | { | |
3073 | /* We only want to update software breakpoints and hardware | |
3074 | breakpoints. */ | |
3075 | if (!is_breakpoint (bl->owner)) | |
3076 | continue; | |
3077 | ||
3078 | /* We only want to update locations that are already inserted | |
3079 | and need updating. This is to avoid unwanted insertion during | |
3080 | deletion of breakpoints. */ | |
3081 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) | |
3082 | continue; | |
3083 | ||
3084 | switch_to_program_space_and_thread (bl->pspace); | |
3085 | ||
3086 | /* For targets that support global breakpoints, there's no need | |
3087 | to select an inferior to insert breakpoint to. In fact, even | |
3088 | if we aren't attached to any process yet, we should still | |
3089 | insert breakpoints. */ | |
f5656ead | 3090 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
b775012e LM |
3091 | && ptid_equal (inferior_ptid, null_ptid)) |
3092 | continue; | |
3093 | ||
3094 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, | |
dd61ec5c | 3095 | &hw_breakpoint_error, &hw_bp_details_reported); |
b775012e LM |
3096 | if (val) |
3097 | error_flag = val; | |
3098 | } | |
3099 | ||
3100 | if (error_flag) | |
3101 | { | |
3102 | target_terminal_ours_for_output (); | |
3103 | error_stream (tmp_error_stream); | |
3104 | } | |
3105 | ||
3106 | do_cleanups (cleanups); | |
3107 | } | |
3108 | ||
c30eee59 | 3109 | /* Used when starting or continuing the program. */ |
c906108c | 3110 | |
74960c60 VP |
3111 | static void |
3112 | insert_breakpoint_locations (void) | |
c906108c | 3113 | { |
a5606eee | 3114 | struct breakpoint *bpt; |
35df4500 | 3115 | struct bp_location *bl, **blp_tmp; |
eacd795a | 3116 | int error_flag = 0; |
c906108c | 3117 | int val = 0; |
3fbb6ffa | 3118 | int disabled_breaks = 0; |
81d0cc19 | 3119 | int hw_breakpoint_error = 0; |
dd61ec5c | 3120 | int hw_bp_error_explained_already = 0; |
c906108c | 3121 | |
81d0cc19 | 3122 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 3123 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 3124 | |
81d0cc19 GS |
3125 | /* Explicitly mark the warning -- this will only be printed if |
3126 | there was an error. */ | |
3127 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
3128 | |
3129 | save_current_space_and_thread (); | |
3130 | ||
35df4500 | 3131 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 3132 | { |
b775012e | 3133 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
879bfdc2 DJ |
3134 | continue; |
3135 | ||
4a64f543 MS |
3136 | /* There is no point inserting thread-specific breakpoints if |
3137 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
3138 | has BL->OWNER always non-NULL. */ | |
35df4500 | 3139 | if (bl->owner->thread != -1 |
5d5658a1 | 3140 | && !valid_global_thread_id (bl->owner->thread)) |
f365de73 AS |
3141 | continue; |
3142 | ||
35df4500 | 3143 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
3144 | |
3145 | /* For targets that support global breakpoints, there's no need | |
3146 | to select an inferior to insert breakpoint to. In fact, even | |
3147 | if we aren't attached to any process yet, we should still | |
3148 | insert breakpoints. */ | |
f5656ead | 3149 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
3150 | && ptid_equal (inferior_ptid, null_ptid)) |
3151 | continue; | |
3152 | ||
3fbb6ffa | 3153 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
dd61ec5c | 3154 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
879bfdc2 | 3155 | if (val) |
eacd795a | 3156 | error_flag = val; |
879bfdc2 | 3157 | } |
c906108c | 3158 | |
4a64f543 MS |
3159 | /* If we failed to insert all locations of a watchpoint, remove |
3160 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
3161 | ALL_BREAKPOINTS (bpt) |
3162 | { | |
3163 | int some_failed = 0; | |
3164 | struct bp_location *loc; | |
3165 | ||
3166 | if (!is_hardware_watchpoint (bpt)) | |
3167 | continue; | |
3168 | ||
d6b74ac4 | 3169 | if (!breakpoint_enabled (bpt)) |
a5606eee | 3170 | continue; |
74960c60 VP |
3171 | |
3172 | if (bpt->disposition == disp_del_at_next_stop) | |
3173 | continue; | |
a5606eee VP |
3174 | |
3175 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 3176 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
3177 | { |
3178 | some_failed = 1; | |
3179 | break; | |
3180 | } | |
3181 | if (some_failed) | |
3182 | { | |
3183 | for (loc = bpt->loc; loc; loc = loc->next) | |
3184 | if (loc->inserted) | |
3185 | remove_breakpoint (loc, mark_uninserted); | |
3186 | ||
3187 | hw_breakpoint_error = 1; | |
3188 | fprintf_unfiltered (tmp_error_stream, | |
3189 | "Could not insert hardware watchpoint %d.\n", | |
3190 | bpt->number); | |
eacd795a | 3191 | error_flag = -1; |
a5606eee VP |
3192 | } |
3193 | } | |
3194 | ||
eacd795a | 3195 | if (error_flag) |
81d0cc19 GS |
3196 | { |
3197 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
3198 | message about possibly exhausted resources. */ | |
dd61ec5c | 3199 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
81d0cc19 | 3200 | { |
c6510018 MS |
3201 | fprintf_unfiltered (tmp_error_stream, |
3202 | "Could not insert hardware breakpoints:\n\ | |
3203 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 3204 | } |
81d0cc19 GS |
3205 | target_terminal_ours_for_output (); |
3206 | error_stream (tmp_error_stream); | |
3207 | } | |
f7545552 TT |
3208 | |
3209 | do_cleanups (cleanups); | |
c906108c SS |
3210 | } |
3211 | ||
c30eee59 TJB |
3212 | /* Used when the program stops. |
3213 | Returns zero if successful, or non-zero if there was a problem | |
3214 | removing a breakpoint location. */ | |
3215 | ||
c906108c | 3216 | int |
fba45db2 | 3217 | remove_breakpoints (void) |
c906108c | 3218 | { |
35df4500 | 3219 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3220 | int val = 0; |
c906108c | 3221 | |
35df4500 | 3222 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3223 | { |
1e4d1764 | 3224 | if (bl->inserted && !is_tracepoint (bl->owner)) |
35df4500 | 3225 | val |= remove_breakpoint (bl, mark_uninserted); |
c5aa993b | 3226 | } |
3a1bae8e | 3227 | return val; |
c906108c SS |
3228 | } |
3229 | ||
49fa26b0 PA |
3230 | /* When a thread exits, remove breakpoints that are related to |
3231 | that thread. */ | |
3232 | ||
3233 | static void | |
3234 | remove_threaded_breakpoints (struct thread_info *tp, int silent) | |
3235 | { | |
3236 | struct breakpoint *b, *b_tmp; | |
3237 | ||
3238 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
3239 | { | |
5d5658a1 | 3240 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
49fa26b0 PA |
3241 | { |
3242 | b->disposition = disp_del_at_next_stop; | |
3243 | ||
3244 | printf_filtered (_("\ | |
43792cf0 PA |
3245 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
3246 | b->number, print_thread_id (tp)); | |
49fa26b0 PA |
3247 | |
3248 | /* Hide it from the user. */ | |
3249 | b->number = 0; | |
3250 | } | |
3251 | } | |
3252 | } | |
3253 | ||
6c95b8df PA |
3254 | /* Remove breakpoints of process PID. */ |
3255 | ||
3256 | int | |
3257 | remove_breakpoints_pid (int pid) | |
3258 | { | |
35df4500 | 3259 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
3260 | int val; |
3261 | struct inferior *inf = find_inferior_pid (pid); | |
3262 | ||
35df4500 | 3263 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 3264 | { |
35df4500 | 3265 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3266 | continue; |
3267 | ||
fc126975 | 3268 | if (bl->inserted && !bl->target_info.persist) |
6c95b8df | 3269 | { |
35df4500 | 3270 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
3271 | if (val != 0) |
3272 | return val; | |
3273 | } | |
3274 | } | |
3275 | return 0; | |
3276 | } | |
3277 | ||
c906108c | 3278 | int |
fba45db2 | 3279 | reattach_breakpoints (int pid) |
c906108c | 3280 | { |
6c95b8df | 3281 | struct cleanup *old_chain; |
35df4500 | 3282 | struct bp_location *bl, **blp_tmp; |
c906108c | 3283 | int val; |
86b887df | 3284 | struct ui_file *tmp_error_stream; |
dd61ec5c | 3285 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
6c95b8df PA |
3286 | struct inferior *inf; |
3287 | struct thread_info *tp; | |
3288 | ||
3289 | tp = any_live_thread_of_process (pid); | |
3290 | if (tp == NULL) | |
3291 | return 1; | |
3292 | ||
3293 | inf = find_inferior_pid (pid); | |
3294 | old_chain = save_inferior_ptid (); | |
3295 | ||
3296 | inferior_ptid = tp->ptid; | |
a4954f26 | 3297 | |
86b887df | 3298 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 3299 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 3300 | |
35df4500 | 3301 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3302 | { |
35df4500 | 3303 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3304 | continue; |
3305 | ||
35df4500 | 3306 | if (bl->inserted) |
c5aa993b | 3307 | { |
35df4500 | 3308 | bl->inserted = 0; |
dd61ec5c | 3309 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
c5aa993b JM |
3310 | if (val != 0) |
3311 | { | |
ce696e05 | 3312 | do_cleanups (old_chain); |
c5aa993b JM |
3313 | return val; |
3314 | } | |
3315 | } | |
3316 | } | |
ce696e05 | 3317 | do_cleanups (old_chain); |
c906108c SS |
3318 | return 0; |
3319 | } | |
3320 | ||
e58b0e63 PA |
3321 | static int internal_breakpoint_number = -1; |
3322 | ||
84f4c1fe PM |
3323 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
3324 | If INTERNAL is non-zero, the breakpoint number will be populated | |
3325 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 3326 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
3327 | breakpoint_count and that value incremented. Internal breakpoints |
3328 | do not set the internal var bpnum. */ | |
3329 | static void | |
3330 | set_breakpoint_number (int internal, struct breakpoint *b) | |
3331 | { | |
3332 | if (internal) | |
3333 | b->number = internal_breakpoint_number--; | |
3334 | else | |
3335 | { | |
3336 | set_breakpoint_count (breakpoint_count + 1); | |
3337 | b->number = breakpoint_count; | |
3338 | } | |
3339 | } | |
3340 | ||
e62c965a | 3341 | static struct breakpoint * |
a6d9a66e | 3342 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 3343 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 3344 | const struct breakpoint_ops *ops) |
e62c965a | 3345 | { |
e62c965a PP |
3346 | struct symtab_and_line sal; |
3347 | struct breakpoint *b; | |
3348 | ||
4a64f543 | 3349 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
3350 | |
3351 | sal.pc = address; | |
3352 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 3353 | sal.pspace = current_program_space; |
e62c965a | 3354 | |
06edf0c0 | 3355 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
3356 | b->number = internal_breakpoint_number--; |
3357 | b->disposition = disp_donttouch; | |
3358 | ||
3359 | return b; | |
3360 | } | |
3361 | ||
17450429 PP |
3362 | static const char *const longjmp_names[] = |
3363 | { | |
3364 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
3365 | }; | |
3366 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
3367 | ||
3368 | /* Per-objfile data private to breakpoint.c. */ | |
3369 | struct breakpoint_objfile_data | |
3370 | { | |
3371 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
3b7344d5 | 3372 | struct bound_minimal_symbol overlay_msym; |
17450429 PP |
3373 | |
3374 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
3b7344d5 | 3375 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
17450429 | 3376 | |
28106bc2 SDJ |
3377 | /* True if we have looked for longjmp probes. */ |
3378 | int longjmp_searched; | |
3379 | ||
3380 | /* SystemTap probe points for longjmp (if any). */ | |
3381 | VEC (probe_p) *longjmp_probes; | |
3382 | ||
17450429 | 3383 | /* Minimal symbol for "std::terminate()" (if any). */ |
3b7344d5 | 3384 | struct bound_minimal_symbol terminate_msym; |
17450429 PP |
3385 | |
3386 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
3b7344d5 | 3387 | struct bound_minimal_symbol exception_msym; |
28106bc2 SDJ |
3388 | |
3389 | /* True if we have looked for exception probes. */ | |
3390 | int exception_searched; | |
3391 | ||
3392 | /* SystemTap probe points for unwinding (if any). */ | |
3393 | VEC (probe_p) *exception_probes; | |
17450429 PP |
3394 | }; |
3395 | ||
3396 | static const struct objfile_data *breakpoint_objfile_key; | |
3397 | ||
3398 | /* Minimal symbol not found sentinel. */ | |
3399 | static struct minimal_symbol msym_not_found; | |
3400 | ||
3401 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
3402 | ||
3403 | static int | |
3404 | msym_not_found_p (const struct minimal_symbol *msym) | |
3405 | { | |
3406 | return msym == &msym_not_found; | |
3407 | } | |
3408 | ||
3409 | /* Return per-objfile data needed by breakpoint.c. | |
3410 | Allocate the data if necessary. */ | |
3411 | ||
3412 | static struct breakpoint_objfile_data * | |
3413 | get_breakpoint_objfile_data (struct objfile *objfile) | |
3414 | { | |
3415 | struct breakpoint_objfile_data *bp_objfile_data; | |
3416 | ||
9a3c8263 SM |
3417 | bp_objfile_data = ((struct breakpoint_objfile_data *) |
3418 | objfile_data (objfile, breakpoint_objfile_key)); | |
17450429 PP |
3419 | if (bp_objfile_data == NULL) |
3420 | { | |
8d749320 SM |
3421 | bp_objfile_data = |
3422 | XOBNEW (&objfile->objfile_obstack, struct breakpoint_objfile_data); | |
17450429 PP |
3423 | |
3424 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
3425 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
3426 | } | |
3427 | return bp_objfile_data; | |
3428 | } | |
3429 | ||
28106bc2 SDJ |
3430 | static void |
3431 | free_breakpoint_probes (struct objfile *obj, void *data) | |
3432 | { | |
9a3c8263 SM |
3433 | struct breakpoint_objfile_data *bp_objfile_data |
3434 | = (struct breakpoint_objfile_data *) data; | |
28106bc2 SDJ |
3435 | |
3436 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); | |
3437 | VEC_free (probe_p, bp_objfile_data->exception_probes); | |
3438 | } | |
3439 | ||
e62c965a | 3440 | static void |
af02033e | 3441 | create_overlay_event_breakpoint (void) |
e62c965a | 3442 | { |
69de3c6a | 3443 | struct objfile *objfile; |
af02033e | 3444 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 3445 | |
69de3c6a PP |
3446 | ALL_OBJFILES (objfile) |
3447 | { | |
3448 | struct breakpoint *b; | |
17450429 PP |
3449 | struct breakpoint_objfile_data *bp_objfile_data; |
3450 | CORE_ADDR addr; | |
67994074 | 3451 | struct explicit_location explicit_loc; |
69de3c6a | 3452 | |
17450429 PP |
3453 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3454 | ||
3b7344d5 | 3455 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
17450429 PP |
3456 | continue; |
3457 | ||
3b7344d5 | 3458 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
17450429 | 3459 | { |
3b7344d5 | 3460 | struct bound_minimal_symbol m; |
17450429 PP |
3461 | |
3462 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3463 | if (m.minsym == NULL) |
17450429 PP |
3464 | { |
3465 | /* Avoid future lookups in this objfile. */ | |
3b7344d5 | 3466 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
17450429 PP |
3467 | continue; |
3468 | } | |
3469 | bp_objfile_data->overlay_msym = m; | |
3470 | } | |
e62c965a | 3471 | |
77e371c0 | 3472 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
17450429 | 3473 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3474 | bp_overlay_event, |
3475 | &internal_breakpoint_ops); | |
67994074 KS |
3476 | initialize_explicit_location (&explicit_loc); |
3477 | explicit_loc.function_name = ASTRDUP (func_name); | |
3478 | b->location = new_explicit_location (&explicit_loc); | |
e62c965a | 3479 | |
69de3c6a PP |
3480 | if (overlay_debugging == ovly_auto) |
3481 | { | |
3482 | b->enable_state = bp_enabled; | |
3483 | overlay_events_enabled = 1; | |
3484 | } | |
3485 | else | |
3486 | { | |
3487 | b->enable_state = bp_disabled; | |
3488 | overlay_events_enabled = 0; | |
3489 | } | |
e62c965a | 3490 | } |
44702360 | 3491 | update_global_location_list (UGLL_MAY_INSERT); |
e62c965a PP |
3492 | } |
3493 | ||
0fd8e87f | 3494 | static void |
af02033e | 3495 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 3496 | { |
6c95b8df | 3497 | struct program_space *pspace; |
6c95b8df PA |
3498 | struct cleanup *old_chain; |
3499 | ||
3500 | old_chain = save_current_program_space (); | |
0fd8e87f | 3501 | |
6c95b8df | 3502 | ALL_PSPACES (pspace) |
af02033e PP |
3503 | { |
3504 | struct objfile *objfile; | |
3505 | ||
3506 | set_current_program_space (pspace); | |
3507 | ||
3508 | ALL_OBJFILES (objfile) | |
0fd8e87f | 3509 | { |
af02033e PP |
3510 | int i; |
3511 | struct gdbarch *gdbarch; | |
17450429 | 3512 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 3513 | |
af02033e | 3514 | gdbarch = get_objfile_arch (objfile); |
0fd8e87f | 3515 | |
17450429 PP |
3516 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
3517 | ||
28106bc2 SDJ |
3518 | if (!bp_objfile_data->longjmp_searched) |
3519 | { | |
25f9533e SDJ |
3520 | VEC (probe_p) *ret; |
3521 | ||
3522 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); | |
3523 | if (ret != NULL) | |
3524 | { | |
3525 | /* We are only interested in checking one element. */ | |
3526 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3527 | ||
3528 | if (!can_evaluate_probe_arguments (p)) | |
3529 | { | |
3530 | /* We cannot use the probe interface here, because it does | |
3531 | not know how to evaluate arguments. */ | |
3532 | VEC_free (probe_p, ret); | |
3533 | ret = NULL; | |
3534 | } | |
3535 | } | |
3536 | bp_objfile_data->longjmp_probes = ret; | |
28106bc2 SDJ |
3537 | bp_objfile_data->longjmp_searched = 1; |
3538 | } | |
3539 | ||
3540 | if (bp_objfile_data->longjmp_probes != NULL) | |
3541 | { | |
3542 | int i; | |
3543 | struct probe *probe; | |
3544 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3545 | ||
3546 | for (i = 0; | |
3547 | VEC_iterate (probe_p, | |
3548 | bp_objfile_data->longjmp_probes, | |
3549 | i, probe); | |
3550 | ++i) | |
3551 | { | |
3552 | struct breakpoint *b; | |
3553 | ||
729662a5 TT |
3554 | b = create_internal_breakpoint (gdbarch, |
3555 | get_probe_address (probe, | |
3556 | objfile), | |
28106bc2 SDJ |
3557 | bp_longjmp_master, |
3558 | &internal_breakpoint_ops); | |
5b56227b KS |
3559 | b->location |
3560 | = new_probe_location ("-probe-stap libc:longjmp"); | |
28106bc2 SDJ |
3561 | b->enable_state = bp_disabled; |
3562 | } | |
3563 | ||
3564 | continue; | |
3565 | } | |
3566 | ||
0569175e TSD |
3567 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
3568 | continue; | |
3569 | ||
17450429 | 3570 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
af02033e PP |
3571 | { |
3572 | struct breakpoint *b; | |
af02033e | 3573 | const char *func_name; |
17450429 | 3574 | CORE_ADDR addr; |
67994074 | 3575 | struct explicit_location explicit_loc; |
6c95b8df | 3576 | |
3b7344d5 | 3577 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
af02033e | 3578 | continue; |
0fd8e87f | 3579 | |
17450429 | 3580 | func_name = longjmp_names[i]; |
3b7344d5 | 3581 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
17450429 | 3582 | { |
3b7344d5 | 3583 | struct bound_minimal_symbol m; |
17450429 PP |
3584 | |
3585 | m = lookup_minimal_symbol_text (func_name, objfile); | |
3b7344d5 | 3586 | if (m.minsym == NULL) |
17450429 PP |
3587 | { |
3588 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3589 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
17450429 PP |
3590 | continue; |
3591 | } | |
3592 | bp_objfile_data->longjmp_msym[i] = m; | |
3593 | } | |
3594 | ||
77e371c0 | 3595 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
06edf0c0 PA |
3596 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
3597 | &internal_breakpoint_ops); | |
67994074 KS |
3598 | initialize_explicit_location (&explicit_loc); |
3599 | explicit_loc.function_name = ASTRDUP (func_name); | |
3600 | b->location = new_explicit_location (&explicit_loc); | |
af02033e PP |
3601 | b->enable_state = bp_disabled; |
3602 | } | |
0fd8e87f | 3603 | } |
af02033e | 3604 | } |
44702360 | 3605 | update_global_location_list (UGLL_MAY_INSERT); |
6c95b8df PA |
3606 | |
3607 | do_cleanups (old_chain); | |
0fd8e87f UW |
3608 | } |
3609 | ||
af02033e | 3610 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 3611 | static void |
af02033e | 3612 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
3613 | { |
3614 | struct program_space *pspace; | |
aa7d318d | 3615 | struct cleanup *old_chain; |
af02033e | 3616 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
3617 | |
3618 | old_chain = save_current_program_space (); | |
3619 | ||
3620 | ALL_PSPACES (pspace) | |
17450429 PP |
3621 | { |
3622 | struct objfile *objfile; | |
3623 | CORE_ADDR addr; | |
3624 | ||
3625 | set_current_program_space (pspace); | |
3626 | ||
aa7d318d TT |
3627 | ALL_OBJFILES (objfile) |
3628 | { | |
3629 | struct breakpoint *b; | |
17450429 | 3630 | struct breakpoint_objfile_data *bp_objfile_data; |
67994074 | 3631 | struct explicit_location explicit_loc; |
aa7d318d | 3632 | |
17450429 | 3633 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 3634 | |
3b7344d5 | 3635 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
17450429 PP |
3636 | continue; |
3637 | ||
3b7344d5 | 3638 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
17450429 | 3639 | { |
3b7344d5 | 3640 | struct bound_minimal_symbol m; |
17450429 PP |
3641 | |
3642 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
3b7344d5 TT |
3643 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
3644 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) | |
17450429 PP |
3645 | { |
3646 | /* Prevent future lookups in this objfile. */ | |
3b7344d5 | 3647 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
17450429 PP |
3648 | continue; |
3649 | } | |
3650 | bp_objfile_data->terminate_msym = m; | |
3651 | } | |
aa7d318d | 3652 | |
77e371c0 | 3653 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
17450429 | 3654 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
06edf0c0 PA |
3655 | bp_std_terminate_master, |
3656 | &internal_breakpoint_ops); | |
67994074 KS |
3657 | initialize_explicit_location (&explicit_loc); |
3658 | explicit_loc.function_name = ASTRDUP (func_name); | |
3659 | b->location = new_explicit_location (&explicit_loc); | |
aa7d318d TT |
3660 | b->enable_state = bp_disabled; |
3661 | } | |
17450429 PP |
3662 | } |
3663 | ||
44702360 | 3664 | update_global_location_list (UGLL_MAY_INSERT); |
aa7d318d TT |
3665 | |
3666 | do_cleanups (old_chain); | |
3667 | } | |
3668 | ||
186c406b TT |
3669 | /* Install a master breakpoint on the unwinder's debug hook. */ |
3670 | ||
70221824 | 3671 | static void |
186c406b TT |
3672 | create_exception_master_breakpoint (void) |
3673 | { | |
3674 | struct objfile *objfile; | |
17450429 | 3675 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
3676 | |
3677 | ALL_OBJFILES (objfile) | |
3678 | { | |
17450429 PP |
3679 | struct breakpoint *b; |
3680 | struct gdbarch *gdbarch; | |
3681 | struct breakpoint_objfile_data *bp_objfile_data; | |
3682 | CORE_ADDR addr; | |
67994074 | 3683 | struct explicit_location explicit_loc; |
17450429 PP |
3684 | |
3685 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
3686 | ||
28106bc2 SDJ |
3687 | /* We prefer the SystemTap probe point if it exists. */ |
3688 | if (!bp_objfile_data->exception_searched) | |
3689 | { | |
25f9533e SDJ |
3690 | VEC (probe_p) *ret; |
3691 | ||
3692 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); | |
3693 | ||
3694 | if (ret != NULL) | |
3695 | { | |
3696 | /* We are only interested in checking one element. */ | |
3697 | struct probe *p = VEC_index (probe_p, ret, 0); | |
3698 | ||
3699 | if (!can_evaluate_probe_arguments (p)) | |
3700 | { | |
3701 | /* We cannot use the probe interface here, because it does | |
3702 | not know how to evaluate arguments. */ | |
3703 | VEC_free (probe_p, ret); | |
3704 | ret = NULL; | |
3705 | } | |
3706 | } | |
3707 | bp_objfile_data->exception_probes = ret; | |
28106bc2 SDJ |
3708 | bp_objfile_data->exception_searched = 1; |
3709 | } | |
3710 | ||
3711 | if (bp_objfile_data->exception_probes != NULL) | |
3712 | { | |
3713 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3714 | int i; | |
3715 | struct probe *probe; | |
3716 | ||
3717 | for (i = 0; | |
3718 | VEC_iterate (probe_p, | |
3719 | bp_objfile_data->exception_probes, | |
3720 | i, probe); | |
3721 | ++i) | |
3722 | { | |
3723 | struct breakpoint *b; | |
3724 | ||
729662a5 TT |
3725 | b = create_internal_breakpoint (gdbarch, |
3726 | get_probe_address (probe, | |
3727 | objfile), | |
28106bc2 SDJ |
3728 | bp_exception_master, |
3729 | &internal_breakpoint_ops); | |
5b56227b KS |
3730 | b->location |
3731 | = new_probe_location ("-probe-stap libgcc:unwind"); | |
28106bc2 SDJ |
3732 | b->enable_state = bp_disabled; |
3733 | } | |
3734 | ||
3735 | continue; | |
3736 | } | |
3737 | ||
3738 | /* Otherwise, try the hook function. */ | |
3739 | ||
3b7344d5 | 3740 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
17450429 PP |
3741 | continue; |
3742 | ||
3743 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 3744 | |
3b7344d5 | 3745 | if (bp_objfile_data->exception_msym.minsym == NULL) |
186c406b | 3746 | { |
3b7344d5 | 3747 | struct bound_minimal_symbol debug_hook; |
186c406b | 3748 | |
17450429 | 3749 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
3b7344d5 | 3750 | if (debug_hook.minsym == NULL) |
17450429 | 3751 | { |
3b7344d5 | 3752 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
17450429 PP |
3753 | continue; |
3754 | } | |
3755 | ||
3756 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 3757 | } |
17450429 | 3758 | |
77e371c0 | 3759 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
17450429 PP |
3760 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
3761 | ¤t_target); | |
06edf0c0 PA |
3762 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
3763 | &internal_breakpoint_ops); | |
67994074 KS |
3764 | initialize_explicit_location (&explicit_loc); |
3765 | explicit_loc.function_name = ASTRDUP (func_name); | |
3766 | b->location = new_explicit_location (&explicit_loc); | |
17450429 | 3767 | b->enable_state = bp_disabled; |
186c406b TT |
3768 | } |
3769 | ||
44702360 | 3770 | update_global_location_list (UGLL_MAY_INSERT); |
186c406b TT |
3771 | } |
3772 | ||
c906108c | 3773 | void |
fba45db2 | 3774 | update_breakpoints_after_exec (void) |
c906108c | 3775 | { |
35df4500 | 3776 | struct breakpoint *b, *b_tmp; |
876fa593 | 3777 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 3778 | |
25b22b0a PA |
3779 | /* We're about to delete breakpoints from GDB's lists. If the |
3780 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
3781 | writing the breakpoints' "shadow contents" back into memory. The | |
3782 | "shadow contents" are NOT valid after an exec, so GDB should not | |
3783 | do that. Instead, the target is responsible from marking | |
3784 | breakpoints out as soon as it detects an exec. We don't do that | |
3785 | here instead, because there may be other attempts to delete | |
3786 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 3787 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
3788 | if (bploc->pspace == current_program_space) |
3789 | gdb_assert (!bploc->inserted); | |
c906108c | 3790 | |
35df4500 | 3791 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 3792 | { |
6c95b8df PA |
3793 | if (b->pspace != current_program_space) |
3794 | continue; | |
3795 | ||
4a64f543 | 3796 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
3797 | if (b->type == bp_shlib_event) |
3798 | { | |
3799 | delete_breakpoint (b); | |
3800 | continue; | |
3801 | } | |
c906108c | 3802 | |
4a64f543 | 3803 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
3804 | if (b->type == bp_jit_event) |
3805 | { | |
3806 | delete_breakpoint (b); | |
3807 | continue; | |
3808 | } | |
3809 | ||
1900040c | 3810 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
3811 | as must overlay event and longjmp master breakpoints. */ |
3812 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
3813 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
3814 | || b->type == bp_exception_master) | |
c4093a6a JM |
3815 | { |
3816 | delete_breakpoint (b); | |
3817 | continue; | |
3818 | } | |
3819 | ||
4a64f543 | 3820 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 3821 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
3822 | { |
3823 | delete_breakpoint (b); | |
3824 | continue; | |
3825 | } | |
3826 | ||
7c16b83e PA |
3827 | /* Just like single-step breakpoints. */ |
3828 | if (b->type == bp_single_step) | |
3829 | { | |
3830 | delete_breakpoint (b); | |
3831 | continue; | |
3832 | } | |
3833 | ||
611c83ae PA |
3834 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
3835 | after an exec. */ | |
186c406b | 3836 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
e2e4d78b | 3837 | || b->type == bp_longjmp_call_dummy |
186c406b | 3838 | || b->type == bp_exception || b->type == bp_exception_resume) |
611c83ae PA |
3839 | { |
3840 | delete_breakpoint (b); | |
3841 | continue; | |
3842 | } | |
3843 | ||
ce78b96d JB |
3844 | if (b->type == bp_catchpoint) |
3845 | { | |
3846 | /* For now, none of the bp_catchpoint breakpoints need to | |
3847 | do anything at this point. In the future, if some of | |
3848 | the catchpoints need to something, we will need to add | |
3849 | a new method, and call this method from here. */ | |
3850 | continue; | |
3851 | } | |
3852 | ||
c5aa993b JM |
3853 | /* bp_finish is a special case. The only way we ought to be able |
3854 | to see one of these when an exec() has happened, is if the user | |
3855 | caught a vfork, and then said "finish". Ordinarily a finish just | |
3856 | carries them to the call-site of the current callee, by setting | |
3857 | a temporary bp there and resuming. But in this case, the finish | |
3858 | will carry them entirely through the vfork & exec. | |
3859 | ||
3860 | We don't want to allow a bp_finish to remain inserted now. But | |
3861 | we can't safely delete it, 'cause finish_command has a handle to | |
3862 | the bp on a bpstat, and will later want to delete it. There's a | |
3863 | chance (and I've seen it happen) that if we delete the bp_finish | |
3864 | here, that its storage will get reused by the time finish_command | |
3865 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
3866 | We really must allow finish_command to delete a bp_finish. | |
3867 | ||
e5dd4106 | 3868 | In the absence of a general solution for the "how do we know |
53a5351d JM |
3869 | it's safe to delete something others may have handles to?" |
3870 | problem, what we'll do here is just uninsert the bp_finish, and | |
3871 | let finish_command delete it. | |
3872 | ||
3873 | (We know the bp_finish is "doomed" in the sense that it's | |
3874 | momentary, and will be deleted as soon as finish_command sees | |
3875 | the inferior stopped. So it doesn't matter that the bp's | |
3876 | address is probably bogus in the new a.out, unlike e.g., the | |
3877 | solib breakpoints.) */ | |
c5aa993b | 3878 | |
c5aa993b JM |
3879 | if (b->type == bp_finish) |
3880 | { | |
3881 | continue; | |
3882 | } | |
3883 | ||
3884 | /* Without a symbolic address, we have little hope of the | |
3885 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 3886 | a.out. */ |
f00aae0f | 3887 | if (event_location_empty_p (b->location)) |
c5aa993b JM |
3888 | { |
3889 | delete_breakpoint (b); | |
3890 | continue; | |
3891 | } | |
c5aa993b | 3892 | } |
c906108c SS |
3893 | } |
3894 | ||
3895 | int | |
d80ee84f | 3896 | detach_breakpoints (ptid_t ptid) |
c906108c | 3897 | { |
35df4500 | 3898 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 3899 | int val = 0; |
ce696e05 | 3900 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 3901 | struct inferior *inf = current_inferior (); |
c5aa993b | 3902 | |
dfd4cc63 | 3903 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
8a3fe4f8 | 3904 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 3905 | |
6c95b8df | 3906 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
d80ee84f | 3907 | inferior_ptid = ptid; |
35df4500 | 3908 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3909 | { |
35df4500 | 3910 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
3911 | continue; |
3912 | ||
bd9673a4 PW |
3913 | /* This function must physically remove breakpoints locations |
3914 | from the specified ptid, without modifying the breakpoint | |
3915 | package's state. Locations of type bp_loc_other are only | |
3916 | maintained at GDB side. So, there is no need to remove | |
3917 | these bp_loc_other locations. Moreover, removing these | |
3918 | would modify the breakpoint package's state. */ | |
3919 | if (bl->loc_type == bp_loc_other) | |
3920 | continue; | |
3921 | ||
35df4500 TJB |
3922 | if (bl->inserted) |
3923 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 3924 | } |
d03285ec | 3925 | |
ce696e05 | 3926 | do_cleanups (old_chain); |
3a1bae8e | 3927 | return val; |
c906108c SS |
3928 | } |
3929 | ||
35df4500 | 3930 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
3931 | Note that this is used to detach breakpoints from a child fork. |
3932 | When we get here, the child isn't in the inferior list, and neither | |
3933 | do we have objects to represent its address space --- we should | |
35df4500 | 3934 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 3935 | |
c906108c | 3936 | static int |
35df4500 | 3937 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
3938 | { |
3939 | int val; | |
c5aa993b | 3940 | |
35df4500 TJB |
3941 | /* BL is never in moribund_locations by our callers. */ |
3942 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 3943 | |
74960c60 VP |
3944 | /* The type of none suggests that owner is actually deleted. |
3945 | This should not ever happen. */ | |
35df4500 | 3946 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 3947 | |
35df4500 TJB |
3948 | if (bl->loc_type == bp_loc_software_breakpoint |
3949 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 3950 | { |
c02f5703 MS |
3951 | /* "Normal" instruction breakpoint: either the standard |
3952 | trap-instruction bp (bp_breakpoint), or a | |
3953 | bp_hardware_breakpoint. */ | |
3954 | ||
3955 | /* First check to see if we have to handle an overlay. */ | |
3956 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
3957 | || bl->section == NULL |
3958 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
3959 | { |
3960 | /* No overlay handling: just remove the breakpoint. */ | |
08351840 PA |
3961 | |
3962 | /* If we're trying to uninsert a memory breakpoint that we | |
3963 | know is set in a dynamic object that is marked | |
3964 | shlib_disabled, then either the dynamic object was | |
3965 | removed with "remove-symbol-file" or with | |
3966 | "nosharedlibrary". In the former case, we don't know | |
3967 | whether another dynamic object might have loaded over the | |
3968 | breakpoint's address -- the user might well let us know | |
3969 | about it next with add-symbol-file (the whole point of | |
d03de421 | 3970 | add-symbol-file is letting the user manually maintain a |
08351840 PA |
3971 | list of dynamically loaded objects). If we have the |
3972 | breakpoint's shadow memory, that is, this is a software | |
3973 | breakpoint managed by GDB, check whether the breakpoint | |
3974 | is still inserted in memory, to avoid overwriting wrong | |
3975 | code with stale saved shadow contents. Note that HW | |
3976 | breakpoints don't have shadow memory, as they're | |
3977 | implemented using a mechanism that is not dependent on | |
3978 | being able to modify the target's memory, and as such | |
3979 | they should always be removed. */ | |
3980 | if (bl->shlib_disabled | |
3981 | && bl->target_info.shadow_len != 0 | |
3982 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) | |
3983 | val = 0; | |
3984 | else | |
3985 | val = bl->owner->ops->remove_location (bl); | |
c02f5703 | 3986 | } |
c906108c SS |
3987 | else |
3988 | { | |
4a64f543 | 3989 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
3990 | Did we set a breakpoint at the LMA? */ |
3991 | if (!overlay_events_enabled) | |
3992 | { | |
3993 | /* Yes -- overlay event support is not active, so we | |
3994 | should have set a breakpoint at the LMA. Remove it. | |
3995 | */ | |
c02f5703 MS |
3996 | /* Ignore any failures: if the LMA is in ROM, we will |
3997 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
3998 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
3999 | target_remove_hw_breakpoint (bl->gdbarch, | |
4000 | &bl->overlay_target_info); | |
c02f5703 | 4001 | else |
35df4500 TJB |
4002 | target_remove_breakpoint (bl->gdbarch, |
4003 | &bl->overlay_target_info); | |
c02f5703 MS |
4004 | } |
4005 | /* Did we set a breakpoint at the VMA? | |
4006 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 4007 | if (bl->inserted) |
c906108c | 4008 | { |
c02f5703 MS |
4009 | /* Yes -- remove it. Previously we did not bother to |
4010 | remove the breakpoint if the section had been | |
4011 | unmapped, but let's not rely on that being safe. We | |
4012 | don't know what the overlay manager might do. */ | |
aa67235e UW |
4013 | |
4014 | /* However, we should remove *software* breakpoints only | |
4015 | if the section is still mapped, or else we overwrite | |
4016 | wrong code with the saved shadow contents. */ | |
348d480f PA |
4017 | if (bl->loc_type == bp_loc_hardware_breakpoint |
4018 | || section_is_mapped (bl->section)) | |
4019 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
4020 | else |
4021 | val = 0; | |
c906108c | 4022 | } |
c02f5703 MS |
4023 | else |
4024 | { | |
4025 | /* No -- not inserted, so no need to remove. No error. */ | |
4026 | val = 0; | |
4027 | } | |
c906108c | 4028 | } |
879d1e6b | 4029 | |
08351840 PA |
4030 | /* In some cases, we might not be able to remove a breakpoint in |
4031 | a shared library that has already been removed, but we have | |
4032 | not yet processed the shlib unload event. Similarly for an | |
4033 | unloaded add-symbol-file object - the user might not yet have | |
4034 | had the chance to remove-symbol-file it. shlib_disabled will | |
4035 | be set if the library/object has already been removed, but | |
4036 | the breakpoint hasn't been uninserted yet, e.g., after | |
4037 | "nosharedlibrary" or "remove-symbol-file" with breakpoints | |
4038 | always-inserted mode. */ | |
076855f9 | 4039 | if (val |
08351840 PA |
4040 | && (bl->loc_type == bp_loc_software_breakpoint |
4041 | && (bl->shlib_disabled | |
4042 | || solib_name_from_address (bl->pspace, bl->address) | |
d03de421 PA |
4043 | || shared_objfile_contains_address_p (bl->pspace, |
4044 | bl->address)))) | |
879d1e6b UW |
4045 | val = 0; |
4046 | ||
c906108c SS |
4047 | if (val) |
4048 | return val; | |
35df4500 | 4049 | bl->inserted = (is == mark_inserted); |
c906108c | 4050 | } |
35df4500 | 4051 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 4052 | { |
77b06cd7 TJB |
4053 | gdb_assert (bl->owner->ops != NULL |
4054 | && bl->owner->ops->remove_location != NULL); | |
4055 | ||
35df4500 | 4056 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 4057 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 4058 | |
c906108c | 4059 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 4060 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 4061 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 4062 | bl->owner->number); |
c906108c | 4063 | } |
35df4500 TJB |
4064 | else if (bl->owner->type == bp_catchpoint |
4065 | && breakpoint_enabled (bl->owner) | |
4066 | && !bl->duplicate) | |
ce78b96d | 4067 | { |
77b06cd7 TJB |
4068 | gdb_assert (bl->owner->ops != NULL |
4069 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 4070 | |
77b06cd7 | 4071 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
4072 | if (val) |
4073 | return val; | |
77b06cd7 | 4074 | |
35df4500 | 4075 | bl->inserted = (is == mark_inserted); |
ce78b96d | 4076 | } |
c906108c SS |
4077 | |
4078 | return 0; | |
4079 | } | |
4080 | ||
6c95b8df | 4081 | static int |
35df4500 | 4082 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
4083 | { |
4084 | int ret; | |
4085 | struct cleanup *old_chain; | |
4086 | ||
35df4500 TJB |
4087 | /* BL is never in moribund_locations by our callers. */ |
4088 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 4089 | |
6c95b8df PA |
4090 | /* The type of none suggests that owner is actually deleted. |
4091 | This should not ever happen. */ | |
35df4500 | 4092 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
4093 | |
4094 | old_chain = save_current_space_and_thread (); | |
4095 | ||
35df4500 | 4096 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 4097 | |
35df4500 | 4098 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
4099 | |
4100 | do_cleanups (old_chain); | |
4101 | return ret; | |
4102 | } | |
4103 | ||
c906108c SS |
4104 | /* Clear the "inserted" flag in all breakpoints. */ |
4105 | ||
25b22b0a | 4106 | void |
fba45db2 | 4107 | mark_breakpoints_out (void) |
c906108c | 4108 | { |
35df4500 | 4109 | struct bp_location *bl, **blp_tmp; |
c906108c | 4110 | |
35df4500 | 4111 | ALL_BP_LOCATIONS (bl, blp_tmp) |
66c4b3e8 | 4112 | if (bl->pspace == current_program_space) |
35df4500 | 4113 | bl->inserted = 0; |
c906108c SS |
4114 | } |
4115 | ||
53a5351d JM |
4116 | /* Clear the "inserted" flag in all breakpoints and delete any |
4117 | breakpoints which should go away between runs of the program. | |
c906108c SS |
4118 | |
4119 | Plus other such housekeeping that has to be done for breakpoints | |
4120 | between runs. | |
4121 | ||
53a5351d JM |
4122 | Note: this function gets called at the end of a run (by |
4123 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 4124 | init_wait_for_inferior). */ |
c906108c SS |
4125 | |
4126 | ||
4127 | ||
4128 | void | |
fba45db2 | 4129 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 4130 | { |
35df4500 TJB |
4131 | struct breakpoint *b, *b_tmp; |
4132 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 4133 | int ix; |
6c95b8df | 4134 | struct program_space *pspace = current_program_space; |
c906108c | 4135 | |
50c71eaf PA |
4136 | /* If breakpoint locations are shared across processes, then there's |
4137 | nothing to do. */ | |
f5656ead | 4138 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
50c71eaf PA |
4139 | return; |
4140 | ||
1a853c52 | 4141 | mark_breakpoints_out (); |
075f6582 | 4142 | |
35df4500 | 4143 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 4144 | { |
6c95b8df PA |
4145 | if (b->loc && b->loc->pspace != pspace) |
4146 | continue; | |
4147 | ||
c5aa993b JM |
4148 | switch (b->type) |
4149 | { | |
4150 | case bp_call_dummy: | |
e2e4d78b | 4151 | case bp_longjmp_call_dummy: |
c906108c | 4152 | |
c5aa993b | 4153 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
4154 | cause problems when the inferior is rerun, so we better get |
4155 | rid of it. */ | |
4156 | ||
4157 | case bp_watchpoint_scope: | |
4158 | ||
4159 | /* Also get rid of scope breakpoints. */ | |
4160 | ||
4161 | case bp_shlib_event: | |
4162 | ||
4163 | /* Also remove solib event breakpoints. Their addresses may | |
4164 | have changed since the last time we ran the program. | |
4165 | Actually we may now be debugging against different target; | |
4166 | and so the solib backend that installed this breakpoint may | |
4167 | not be used in by the target. E.g., | |
4168 | ||
4169 | (gdb) file prog-linux | |
4170 | (gdb) run # native linux target | |
4171 | ... | |
4172 | (gdb) kill | |
4173 | (gdb) file prog-win.exe | |
4174 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
4175 | */ | |
c906108c | 4176 | |
f59f708a PA |
4177 | case bp_step_resume: |
4178 | ||
4179 | /* Also remove step-resume breakpoints. */ | |
4180 | ||
7c16b83e PA |
4181 | case bp_single_step: |
4182 | ||
4183 | /* Also remove single-step breakpoints. */ | |
4184 | ||
c5aa993b JM |
4185 | delete_breakpoint (b); |
4186 | break; | |
c906108c | 4187 | |
c5aa993b JM |
4188 | case bp_watchpoint: |
4189 | case bp_hardware_watchpoint: | |
4190 | case bp_read_watchpoint: | |
4191 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4192 | { |
4193 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 4194 | |
3a5c3e22 PA |
4195 | /* Likewise for watchpoints on local expressions. */ |
4196 | if (w->exp_valid_block != NULL) | |
4197 | delete_breakpoint (b); | |
4198 | else if (context == inf_starting) | |
4199 | { | |
4200 | /* Reset val field to force reread of starting value in | |
4201 | insert_breakpoints. */ | |
4202 | if (w->val) | |
4203 | value_free (w->val); | |
4204 | w->val = NULL; | |
4205 | w->val_valid = 0; | |
c860120c | 4206 | } |
3a5c3e22 | 4207 | } |
c5aa993b JM |
4208 | break; |
4209 | default: | |
c5aa993b JM |
4210 | break; |
4211 | } | |
4212 | } | |
1c5cfe86 PA |
4213 | |
4214 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
4215 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
4216 | decref_bp_location (&bl); | |
1c5cfe86 | 4217 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
4218 | } |
4219 | ||
6c95b8df PA |
4220 | /* These functions concern about actual breakpoints inserted in the |
4221 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
4222 | we need to hop over the bkpt --- so we check for address space | |
4223 | match, not program space. */ | |
4224 | ||
c2c6d25f JM |
4225 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
4226 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
4227 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
4228 | permanent breakpoint. | |
4229 | - When continuing from a location with an ordinary breakpoint, we | |
4230 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 4231 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
4232 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
4233 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 4234 | |
c2c6d25f | 4235 | enum breakpoint_here |
6c95b8df | 4236 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4237 | { |
35df4500 | 4238 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 4239 | int any_breakpoint_here = 0; |
c906108c | 4240 | |
35df4500 | 4241 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 4242 | { |
35df4500 TJB |
4243 | if (bl->loc_type != bp_loc_software_breakpoint |
4244 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4245 | continue; |
4246 | ||
f1310107 | 4247 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 | 4248 | if ((breakpoint_enabled (bl->owner) |
1a853c52 | 4249 | || bl->permanent) |
f1310107 | 4250 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
4251 | { |
4252 | if (overlay_debugging | |
35df4500 TJB |
4253 | && section_is_overlay (bl->section) |
4254 | && !section_is_mapped (bl->section)) | |
075f6582 | 4255 | continue; /* unmapped overlay -- can't be a match */ |
1a853c52 | 4256 | else if (bl->permanent) |
075f6582 DJ |
4257 | return permanent_breakpoint_here; |
4258 | else | |
4259 | any_breakpoint_here = 1; | |
4260 | } | |
4261 | } | |
c906108c | 4262 | |
f486487f | 4263 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
c906108c SS |
4264 | } |
4265 | ||
d35ae833 PA |
4266 | /* See breakpoint.h. */ |
4267 | ||
4268 | int | |
4269 | breakpoint_in_range_p (struct address_space *aspace, | |
4270 | CORE_ADDR addr, ULONGEST len) | |
4271 | { | |
4272 | struct bp_location *bl, **blp_tmp; | |
4273 | ||
4274 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
4275 | { | |
4276 | if (bl->loc_type != bp_loc_software_breakpoint | |
4277 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
4278 | continue; | |
4279 | ||
4280 | if ((breakpoint_enabled (bl->owner) | |
4281 | || bl->permanent) | |
4282 | && breakpoint_location_address_range_overlap (bl, aspace, | |
4283 | addr, len)) | |
4284 | { | |
4285 | if (overlay_debugging | |
4286 | && section_is_overlay (bl->section) | |
4287 | && !section_is_mapped (bl->section)) | |
4288 | { | |
4289 | /* Unmapped overlay -- can't be a match. */ | |
4290 | continue; | |
4291 | } | |
4292 | ||
4293 | return 1; | |
4294 | } | |
4295 | } | |
4296 | ||
4297 | return 0; | |
4298 | } | |
4299 | ||
1c5cfe86 PA |
4300 | /* Return true if there's a moribund breakpoint at PC. */ |
4301 | ||
4302 | int | |
6c95b8df | 4303 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
4304 | { |
4305 | struct bp_location *loc; | |
4306 | int ix; | |
4307 | ||
4308 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 4309 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
4310 | return 1; |
4311 | ||
4312 | return 0; | |
4313 | } | |
c2c6d25f | 4314 | |
f7ce857f PA |
4315 | /* Returns non-zero iff BL is inserted at PC, in address space |
4316 | ASPACE. */ | |
4317 | ||
4318 | static int | |
4319 | bp_location_inserted_here_p (struct bp_location *bl, | |
4320 | struct address_space *aspace, CORE_ADDR pc) | |
4321 | { | |
4322 | if (bl->inserted | |
4323 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
4324 | aspace, pc)) | |
4325 | { | |
4326 | if (overlay_debugging | |
4327 | && section_is_overlay (bl->section) | |
4328 | && !section_is_mapped (bl->section)) | |
4329 | return 0; /* unmapped overlay -- can't be a match */ | |
4330 | else | |
4331 | return 1; | |
4332 | } | |
4333 | return 0; | |
4334 | } | |
4335 | ||
a1fd2fa5 | 4336 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
c906108c SS |
4337 | |
4338 | int | |
a1fd2fa5 | 4339 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 4340 | { |
f7ce857f PA |
4341 | struct bp_location **blp, **blp_tmp = NULL; |
4342 | struct bp_location *bl; | |
c906108c | 4343 | |
f7ce857f | 4344 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
c5aa993b | 4345 | { |
f7ce857f PA |
4346 | struct bp_location *bl = *blp; |
4347 | ||
35df4500 TJB |
4348 | if (bl->loc_type != bp_loc_software_breakpoint |
4349 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
4350 | continue; |
4351 | ||
f7ce857f PA |
4352 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4353 | return 1; | |
c5aa993b | 4354 | } |
c36b740a VP |
4355 | return 0; |
4356 | } | |
4357 | ||
a1fd2fa5 PA |
4358 | /* This function returns non-zero iff there is a software breakpoint |
4359 | inserted at PC. */ | |
c36b740a VP |
4360 | |
4361 | int | |
a1fd2fa5 PA |
4362 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
4363 | CORE_ADDR pc) | |
4fa8626c | 4364 | { |
f7ce857f PA |
4365 | struct bp_location **blp, **blp_tmp = NULL; |
4366 | struct bp_location *bl; | |
4fa8626c | 4367 | |
f7ce857f | 4368 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
4fa8626c | 4369 | { |
f7ce857f PA |
4370 | struct bp_location *bl = *blp; |
4371 | ||
35df4500 | 4372 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
4373 | continue; |
4374 | ||
f7ce857f PA |
4375 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
4376 | return 1; | |
4fa8626c DJ |
4377 | } |
4378 | ||
4379 | return 0; | |
9c02b525 PA |
4380 | } |
4381 | ||
4382 | /* See breakpoint.h. */ | |
4383 | ||
4384 | int | |
4385 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, | |
4386 | CORE_ADDR pc) | |
4387 | { | |
4388 | struct bp_location **blp, **blp_tmp = NULL; | |
4389 | struct bp_location *bl; | |
4390 | ||
4391 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) | |
4392 | { | |
4393 | struct bp_location *bl = *blp; | |
4394 | ||
4395 | if (bl->loc_type != bp_loc_hardware_breakpoint) | |
4396 | continue; | |
4397 | ||
4398 | if (bp_location_inserted_here_p (bl, aspace, pc)) | |
4399 | return 1; | |
4400 | } | |
4401 | ||
4402 | return 0; | |
4fa8626c DJ |
4403 | } |
4404 | ||
9093389c PA |
4405 | int |
4406 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
4407 | CORE_ADDR addr, ULONGEST len) | |
4408 | { | |
4409 | struct breakpoint *bpt; | |
4410 | ||
4411 | ALL_BREAKPOINTS (bpt) | |
4412 | { | |
4413 | struct bp_location *loc; | |
4414 | ||
4415 | if (bpt->type != bp_hardware_watchpoint | |
4416 | && bpt->type != bp_access_watchpoint) | |
4417 | continue; | |
4418 | ||
4419 | if (!breakpoint_enabled (bpt)) | |
4420 | continue; | |
4421 | ||
4422 | for (loc = bpt->loc; loc; loc = loc->next) | |
4423 | if (loc->pspace->aspace == aspace && loc->inserted) | |
4424 | { | |
4425 | CORE_ADDR l, h; | |
4426 | ||
4427 | /* Check for intersection. */ | |
4428 | l = max (loc->address, addr); | |
4429 | h = min (loc->address + loc->length, addr + len); | |
4430 | if (l < h) | |
4431 | return 1; | |
4432 | } | |
4433 | } | |
4434 | return 0; | |
4435 | } | |
c906108c | 4436 | \f |
c5aa993b | 4437 | |
c906108c SS |
4438 | /* bpstat stuff. External routines' interfaces are documented |
4439 | in breakpoint.h. */ | |
4440 | ||
4441 | int | |
c326b90e | 4442 | is_catchpoint (struct breakpoint *ep) |
c906108c | 4443 | { |
533be4dd | 4444 | return (ep->type == bp_catchpoint); |
c906108c SS |
4445 | } |
4446 | ||
f431efe5 PA |
4447 | /* Frees any storage that is part of a bpstat. Does not walk the |
4448 | 'next' chain. */ | |
4449 | ||
4450 | static void | |
198757a8 VP |
4451 | bpstat_free (bpstat bs) |
4452 | { | |
4453 | if (bs->old_val != NULL) | |
4454 | value_free (bs->old_val); | |
9add0f1b | 4455 | decref_counted_command_line (&bs->commands); |
f431efe5 | 4456 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
4457 | xfree (bs); |
4458 | } | |
4459 | ||
c906108c SS |
4460 | /* Clear a bpstat so that it says we are not at any breakpoint. |
4461 | Also free any storage that is part of a bpstat. */ | |
4462 | ||
4463 | void | |
fba45db2 | 4464 | bpstat_clear (bpstat *bsp) |
c906108c SS |
4465 | { |
4466 | bpstat p; | |
4467 | bpstat q; | |
4468 | ||
4469 | if (bsp == 0) | |
4470 | return; | |
4471 | p = *bsp; | |
4472 | while (p != NULL) | |
4473 | { | |
4474 | q = p->next; | |
198757a8 | 4475 | bpstat_free (p); |
c906108c SS |
4476 | p = q; |
4477 | } | |
4478 | *bsp = NULL; | |
4479 | } | |
4480 | ||
4481 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
4482 | is part of the bpstat is copied as well. */ | |
4483 | ||
4484 | bpstat | |
fba45db2 | 4485 | bpstat_copy (bpstat bs) |
c906108c SS |
4486 | { |
4487 | bpstat p = NULL; | |
4488 | bpstat tmp; | |
4489 | bpstat retval = NULL; | |
4490 | ||
4491 | if (bs == NULL) | |
4492 | return bs; | |
4493 | ||
4494 | for (; bs != NULL; bs = bs->next) | |
4495 | { | |
4496 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4497 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 4498 | incref_counted_command_line (tmp->commands); |
f431efe5 | 4499 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 4500 | if (bs->old_val != NULL) |
3c3185ac JK |
4501 | { |
4502 | tmp->old_val = value_copy (bs->old_val); | |
4503 | release_value (tmp->old_val); | |
4504 | } | |
31cc81e9 | 4505 | |
c906108c SS |
4506 | if (p == NULL) |
4507 | /* This is the first thing in the chain. */ | |
4508 | retval = tmp; | |
4509 | else | |
4510 | p->next = tmp; | |
4511 | p = tmp; | |
4512 | } | |
4513 | p->next = NULL; | |
4514 | return retval; | |
4515 | } | |
4516 | ||
4a64f543 | 4517 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
4518 | |
4519 | bpstat | |
fba45db2 | 4520 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 4521 | { |
c5aa993b JM |
4522 | if (bsp == NULL) |
4523 | return NULL; | |
c906108c | 4524 | |
c5aa993b JM |
4525 | for (; bsp != NULL; bsp = bsp->next) |
4526 | { | |
f431efe5 | 4527 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
4528 | return bsp; |
4529 | } | |
c906108c SS |
4530 | return NULL; |
4531 | } | |
4532 | ||
ab04a2af TT |
4533 | /* See breakpoint.h. */ |
4534 | ||
47591c29 | 4535 | int |
427cd150 | 4536 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
ab04a2af | 4537 | { |
ab04a2af TT |
4538 | for (; bsp != NULL; bsp = bsp->next) |
4539 | { | |
427cd150 TT |
4540 | if (bsp->breakpoint_at == NULL) |
4541 | { | |
4542 | /* A moribund location can never explain a signal other than | |
4543 | GDB_SIGNAL_TRAP. */ | |
4544 | if (sig == GDB_SIGNAL_TRAP) | |
47591c29 | 4545 | return 1; |
427cd150 TT |
4546 | } |
4547 | else | |
47591c29 PA |
4548 | { |
4549 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, | |
4550 | sig)) | |
4551 | return 1; | |
4552 | } | |
ab04a2af TT |
4553 | } |
4554 | ||
47591c29 | 4555 | return 0; |
ab04a2af TT |
4556 | } |
4557 | ||
4a64f543 MS |
4558 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
4559 | stopped at. *BSP upon return is a bpstat which points to the | |
4560 | remaining breakpoints stopped at (but which is not guaranteed to be | |
4561 | good for anything but further calls to bpstat_num). | |
4562 | ||
8671a17b PA |
4563 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
4564 | Return -1 if stopped at a breakpoint that has been deleted since | |
4565 | we set it. | |
4566 | Return 1 otherwise. */ | |
c906108c SS |
4567 | |
4568 | int | |
8671a17b | 4569 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
4570 | { |
4571 | struct breakpoint *b; | |
4572 | ||
4573 | if ((*bsp) == NULL) | |
4574 | return 0; /* No more breakpoint values */ | |
8671a17b | 4575 | |
4a64f543 MS |
4576 | /* We assume we'll never have several bpstats that correspond to a |
4577 | single breakpoint -- otherwise, this function might return the | |
4578 | same number more than once and this will look ugly. */ | |
f431efe5 | 4579 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
4580 | *bsp = (*bsp)->next; |
4581 | if (b == NULL) | |
4582 | return -1; /* breakpoint that's been deleted since */ | |
4583 | ||
4584 | *num = b->number; /* We have its number */ | |
4585 | return 1; | |
c906108c SS |
4586 | } |
4587 | ||
e93ca019 | 4588 | /* See breakpoint.h. */ |
c906108c SS |
4589 | |
4590 | void | |
e93ca019 | 4591 | bpstat_clear_actions (void) |
c906108c | 4592 | { |
e93ca019 JK |
4593 | struct thread_info *tp; |
4594 | bpstat bs; | |
4595 | ||
4596 | if (ptid_equal (inferior_ptid, null_ptid)) | |
4597 | return; | |
4598 | ||
4599 | tp = find_thread_ptid (inferior_ptid); | |
4600 | if (tp == NULL) | |
4601 | return; | |
4602 | ||
4603 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 4604 | { |
9add0f1b | 4605 | decref_counted_command_line (&bs->commands); |
abf85f46 | 4606 | |
c906108c SS |
4607 | if (bs->old_val != NULL) |
4608 | { | |
4609 | value_free (bs->old_val); | |
4610 | bs->old_val = NULL; | |
4611 | } | |
4612 | } | |
4613 | } | |
4614 | ||
f3b1572e PA |
4615 | /* Called when a command is about to proceed the inferior. */ |
4616 | ||
4617 | static void | |
4618 | breakpoint_about_to_proceed (void) | |
4619 | { | |
4620 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
4621 | { | |
4622 | struct thread_info *tp = inferior_thread (); | |
4623 | ||
4624 | /* Allow inferior function calls in breakpoint commands to not | |
4625 | interrupt the command list. When the call finishes | |
4626 | successfully, the inferior will be standing at the same | |
4627 | breakpoint as if nothing happened. */ | |
16c381f0 | 4628 | if (tp->control.in_infcall) |
f3b1572e PA |
4629 | return; |
4630 | } | |
4631 | ||
4632 | breakpoint_proceeded = 1; | |
4633 | } | |
4634 | ||
4a64f543 MS |
4635 | /* Stub for cleaning up our state if we error-out of a breakpoint |
4636 | command. */ | |
c906108c | 4637 | static void |
4efb68b1 | 4638 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
4639 | { |
4640 | executing_breakpoint_commands = 0; | |
4641 | } | |
4642 | ||
abf85f46 JK |
4643 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
4644 | or its equivalent. */ | |
4645 | ||
4646 | static int | |
4647 | command_line_is_silent (struct command_line *cmd) | |
4648 | { | |
4f45d445 | 4649 | return cmd && (strcmp ("silent", cmd->line) == 0); |
abf85f46 JK |
4650 | } |
4651 | ||
4a64f543 MS |
4652 | /* Execute all the commands associated with all the breakpoints at |
4653 | this location. Any of these commands could cause the process to | |
4654 | proceed beyond this point, etc. We look out for such changes by | |
4655 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 4656 | |
347bddb7 PA |
4657 | Returns true if a breakpoint command resumed the inferior. In that |
4658 | case, it is the caller's responsibility to recall it again with the | |
4659 | bpstat of the current thread. */ | |
4660 | ||
4661 | static int | |
4662 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
4663 | { |
4664 | bpstat bs; | |
4665 | struct cleanup *old_chain; | |
347bddb7 | 4666 | int again = 0; |
c906108c SS |
4667 | |
4668 | /* Avoid endless recursion if a `source' command is contained | |
4669 | in bs->commands. */ | |
4670 | if (executing_breakpoint_commands) | |
347bddb7 | 4671 | return 0; |
c906108c SS |
4672 | |
4673 | executing_breakpoint_commands = 1; | |
4674 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
4675 | ||
cf6c5ffb TT |
4676 | prevent_dont_repeat (); |
4677 | ||
4a64f543 | 4678 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
4679 | bs = *bsp; |
4680 | ||
4681 | breakpoint_proceeded = 0; | |
4682 | for (; bs != NULL; bs = bs->next) | |
4683 | { | |
9add0f1b | 4684 | struct counted_command_line *ccmd; |
6c50ab1c JB |
4685 | struct command_line *cmd; |
4686 | struct cleanup *this_cmd_tree_chain; | |
4687 | ||
4688 | /* Take ownership of the BSP's command tree, if it has one. | |
4689 | ||
4690 | The command tree could legitimately contain commands like | |
4691 | 'step' and 'next', which call clear_proceed_status, which | |
4692 | frees stop_bpstat's command tree. To make sure this doesn't | |
4693 | free the tree we're executing out from under us, we need to | |
4694 | take ownership of the tree ourselves. Since a given bpstat's | |
4695 | commands are only executed once, we don't need to copy it; we | |
4696 | can clear the pointer in the bpstat, and make sure we free | |
4697 | the tree when we're done. */ | |
9add0f1b TT |
4698 | ccmd = bs->commands; |
4699 | bs->commands = NULL; | |
abf85f46 JK |
4700 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
4701 | cmd = ccmd ? ccmd->commands : NULL; | |
4702 | if (command_line_is_silent (cmd)) | |
4703 | { | |
4704 | /* The action has been already done by bpstat_stop_status. */ | |
4705 | cmd = cmd->next; | |
4706 | } | |
6c50ab1c | 4707 | |
c906108c SS |
4708 | while (cmd != NULL) |
4709 | { | |
4710 | execute_control_command (cmd); | |
4711 | ||
4712 | if (breakpoint_proceeded) | |
4713 | break; | |
4714 | else | |
4715 | cmd = cmd->next; | |
4716 | } | |
6c50ab1c JB |
4717 | |
4718 | /* We can free this command tree now. */ | |
4719 | do_cleanups (this_cmd_tree_chain); | |
4720 | ||
c906108c | 4721 | if (breakpoint_proceeded) |
32c1e744 | 4722 | { |
0b333c5e | 4723 | if (interpreter_async) |
347bddb7 PA |
4724 | /* If we are in async mode, then the target might be still |
4725 | running, not stopped at any breakpoint, so nothing for | |
4726 | us to do here -- just return to the event loop. */ | |
4727 | ; | |
32c1e744 VP |
4728 | else |
4729 | /* In sync mode, when execute_control_command returns | |
4730 | we're already standing on the next breakpoint. | |
347bddb7 PA |
4731 | Breakpoint commands for that stop were not run, since |
4732 | execute_command does not run breakpoint commands -- | |
4733 | only command_line_handler does, but that one is not | |
4734 | involved in execution of breakpoint commands. So, we | |
4735 | can now execute breakpoint commands. It should be | |
4736 | noted that making execute_command do bpstat actions is | |
4737 | not an option -- in this case we'll have recursive | |
4738 | invocation of bpstat for each breakpoint with a | |
4739 | command, and can easily blow up GDB stack. Instead, we | |
4740 | return true, which will trigger the caller to recall us | |
4741 | with the new stop_bpstat. */ | |
4742 | again = 1; | |
4743 | break; | |
32c1e744 | 4744 | } |
c906108c | 4745 | } |
c2b8ed2c | 4746 | do_cleanups (old_chain); |
347bddb7 PA |
4747 | return again; |
4748 | } | |
4749 | ||
4750 | void | |
4751 | bpstat_do_actions (void) | |
4752 | { | |
353d1d73 JK |
4753 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
4754 | ||
347bddb7 PA |
4755 | /* Do any commands attached to breakpoint we are stopped at. */ |
4756 | while (!ptid_equal (inferior_ptid, null_ptid) | |
4757 | && target_has_execution | |
4758 | && !is_exited (inferior_ptid) | |
4759 | && !is_executing (inferior_ptid)) | |
4760 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
4761 | and only return when it is stopped at the next breakpoint, we | |
4762 | keep doing breakpoint actions until it returns false to | |
4763 | indicate the inferior was not resumed. */ | |
16c381f0 | 4764 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 4765 | break; |
353d1d73 JK |
4766 | |
4767 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
4768 | } |
4769 | ||
fa4727a6 DJ |
4770 | /* Print out the (old or new) value associated with a watchpoint. */ |
4771 | ||
4772 | static void | |
4773 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
4774 | { | |
4775 | if (val == NULL) | |
4776 | fprintf_unfiltered (stream, _("<unreadable>")); | |
4777 | else | |
79a45b7d TT |
4778 | { |
4779 | struct value_print_options opts; | |
4780 | get_user_print_options (&opts); | |
4781 | value_print (val, stream, &opts); | |
4782 | } | |
fa4727a6 DJ |
4783 | } |
4784 | ||
f303dbd6 PA |
4785 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
4786 | debugging multiple threads. */ | |
4787 | ||
4788 | void | |
4789 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) | |
4790 | { | |
4791 | if (ui_out_is_mi_like_p (uiout)) | |
4792 | return; | |
4793 | ||
4794 | ui_out_text (uiout, "\n"); | |
4795 | ||
4796 | if (show_thread_that_caused_stop ()) | |
4797 | { | |
4798 | const char *name; | |
4799 | struct thread_info *thr = inferior_thread (); | |
4800 | ||
4801 | ui_out_text (uiout, "Thread "); | |
4802 | ui_out_field_fmt (uiout, "thread-id", "%s", print_thread_id (thr)); | |
4803 | ||
4804 | name = thr->name != NULL ? thr->name : target_thread_name (thr); | |
4805 | if (name != NULL) | |
4806 | { | |
4807 | ui_out_text (uiout, " \""); | |
4808 | ui_out_field_fmt (uiout, "name", "%s", name); | |
4809 | ui_out_text (uiout, "\""); | |
4810 | } | |
4811 | ||
4812 | ui_out_text (uiout, " hit "); | |
4813 | } | |
4814 | } | |
4815 | ||
e514a9d6 | 4816 | /* Generic routine for printing messages indicating why we |
4a64f543 | 4817 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
4818 | 'print_it' in the bpstat structure. Under some circumstances we |
4819 | may decide not to print anything here and delegate the task to | |
4a64f543 | 4820 | normal_stop(). */ |
e514a9d6 JM |
4821 | |
4822 | static enum print_stop_action | |
4823 | print_bp_stop_message (bpstat bs) | |
4824 | { | |
4825 | switch (bs->print_it) | |
4826 | { | |
4827 | case print_it_noop: | |
4a64f543 | 4828 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
4829 | return PRINT_UNKNOWN; |
4830 | break; | |
4831 | ||
4832 | case print_it_done: | |
4833 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 4834 | relevant messages. */ |
e514a9d6 JM |
4835 | return PRINT_SRC_AND_LOC; |
4836 | break; | |
4837 | ||
4838 | case print_it_normal: | |
4f8d1dc6 | 4839 | { |
f431efe5 PA |
4840 | struct breakpoint *b = bs->breakpoint_at; |
4841 | ||
1a6a67de TJB |
4842 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
4843 | which has since been deleted. */ | |
4844 | if (b == NULL) | |
4845 | return PRINT_UNKNOWN; | |
4846 | ||
348d480f PA |
4847 | /* Normal case. Call the breakpoint's print_it method. */ |
4848 | return b->ops->print_it (bs); | |
4f8d1dc6 | 4849 | } |
348d480f | 4850 | break; |
3086aeae | 4851 | |
e514a9d6 | 4852 | default: |
8e65ff28 | 4853 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 4854 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 4855 | break; |
c906108c | 4856 | } |
c906108c SS |
4857 | } |
4858 | ||
edcc5120 TT |
4859 | /* A helper function that prints a shared library stopped event. */ |
4860 | ||
4861 | static void | |
4862 | print_solib_event (int is_catchpoint) | |
4863 | { | |
4864 | int any_deleted | |
4865 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); | |
4866 | int any_added | |
4867 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); | |
4868 | ||
4869 | if (!is_catchpoint) | |
4870 | { | |
4871 | if (any_added || any_deleted) | |
4872 | ui_out_text (current_uiout, | |
4873 | _("Stopped due to shared library event:\n")); | |
4874 | else | |
4875 | ui_out_text (current_uiout, | |
4876 | _("Stopped due to shared library event (no " | |
4877 | "libraries added or removed)\n")); | |
4878 | } | |
4879 | ||
4880 | if (ui_out_is_mi_like_p (current_uiout)) | |
4881 | ui_out_field_string (current_uiout, "reason", | |
4882 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); | |
4883 | ||
4884 | if (any_deleted) | |
4885 | { | |
4886 | struct cleanup *cleanup; | |
4887 | char *name; | |
4888 | int ix; | |
4889 | ||
4890 | ui_out_text (current_uiout, _(" Inferior unloaded ")); | |
4891 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4892 | "removed"); | |
4893 | for (ix = 0; | |
4894 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
4895 | ix, name); | |
4896 | ++ix) | |
4897 | { | |
4898 | if (ix > 0) | |
4899 | ui_out_text (current_uiout, " "); | |
4900 | ui_out_field_string (current_uiout, "library", name); | |
4901 | ui_out_text (current_uiout, "\n"); | |
4902 | } | |
4903 | ||
4904 | do_cleanups (cleanup); | |
4905 | } | |
4906 | ||
4907 | if (any_added) | |
4908 | { | |
4909 | struct so_list *iter; | |
4910 | int ix; | |
4911 | struct cleanup *cleanup; | |
4912 | ||
4913 | ui_out_text (current_uiout, _(" Inferior loaded ")); | |
4914 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, | |
4915 | "added"); | |
4916 | for (ix = 0; | |
4917 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
4918 | ix, iter); | |
4919 | ++ix) | |
4920 | { | |
4921 | if (ix > 0) | |
4922 | ui_out_text (current_uiout, " "); | |
4923 | ui_out_field_string (current_uiout, "library", iter->so_name); | |
4924 | ui_out_text (current_uiout, "\n"); | |
4925 | } | |
4926 | ||
4927 | do_cleanups (cleanup); | |
4928 | } | |
4929 | } | |
4930 | ||
e514a9d6 JM |
4931 | /* Print a message indicating what happened. This is called from |
4932 | normal_stop(). The input to this routine is the head of the bpstat | |
36dfb11c TT |
4933 | list - a list of the eventpoints that caused this stop. KIND is |
4934 | the target_waitkind for the stopping event. This | |
e514a9d6 JM |
4935 | routine calls the generic print routine for printing a message |
4936 | about reasons for stopping. This will print (for example) the | |
4937 | "Breakpoint n," part of the output. The return value of this | |
4938 | routine is one of: | |
c906108c | 4939 | |
4a64f543 | 4940 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 4941 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 4942 | code to print the location. An example is |
c5aa993b JM |
4943 | "Breakpoint 1, " which should be followed by |
4944 | the location. | |
917317f4 | 4945 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
4946 | to also print the location part of the message. |
4947 | An example is the catch/throw messages, which | |
4a64f543 | 4948 | don't require a location appended to the end. |
917317f4 | 4949 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 4950 | further info to be printed. */ |
c906108c | 4951 | |
917317f4 | 4952 | enum print_stop_action |
36dfb11c | 4953 | bpstat_print (bpstat bs, int kind) |
c906108c | 4954 | { |
f486487f | 4955 | enum print_stop_action val; |
c5aa993b | 4956 | |
c906108c | 4957 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
4958 | (Currently all watchpoints go on the bpstat whether hit or not. |
4959 | That probably could (should) be changed, provided care is taken | |
c906108c | 4960 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
4961 | for (; bs; bs = bs->next) |
4962 | { | |
4963 | val = print_bp_stop_message (bs); | |
4964 | if (val == PRINT_SRC_ONLY | |
4965 | || val == PRINT_SRC_AND_LOC | |
4966 | || val == PRINT_NOTHING) | |
4967 | return val; | |
4968 | } | |
c906108c | 4969 | |
36dfb11c TT |
4970 | /* If we had hit a shared library event breakpoint, |
4971 | print_bp_stop_message would print out this message. If we hit an | |
4972 | OS-level shared library event, do the same thing. */ | |
4973 | if (kind == TARGET_WAITKIND_LOADED) | |
4974 | { | |
edcc5120 | 4975 | print_solib_event (0); |
36dfb11c TT |
4976 | return PRINT_NOTHING; |
4977 | } | |
4978 | ||
e514a9d6 | 4979 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 4980 | with and nothing was printed. */ |
917317f4 | 4981 | return PRINT_UNKNOWN; |
c906108c SS |
4982 | } |
4983 | ||
c42bd95a DE |
4984 | /* Evaluate the expression EXP and return 1 if value is zero. |
4985 | This returns the inverse of the condition because it is called | |
4986 | from catch_errors which returns 0 if an exception happened, and if an | |
4987 | exception happens we want execution to stop. | |
4a64f543 | 4988 | The argument is a "struct expression *" that has been cast to a |
c42bd95a | 4989 | "void *" to make it pass through catch_errors. */ |
c906108c SS |
4990 | |
4991 | static int | |
4efb68b1 | 4992 | breakpoint_cond_eval (void *exp) |
c906108c | 4993 | { |
278cd55f | 4994 | struct value *mark = value_mark (); |
c5aa993b | 4995 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 4996 | |
c906108c SS |
4997 | value_free_to_mark (mark); |
4998 | return i; | |
4999 | } | |
5000 | ||
5760d0ab | 5001 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
5002 | |
5003 | static bpstat | |
5760d0ab | 5004 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
5005 | { |
5006 | bpstat bs; | |
5007 | ||
5008 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
5009 | bs->next = NULL; |
5010 | **bs_link_pointer = bs; | |
5011 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
5012 | bs->breakpoint_at = bl->owner; |
5013 | bs->bp_location_at = bl; | |
5014 | incref_bp_location (bl); | |
c906108c SS |
5015 | /* If the condition is false, etc., don't do the commands. */ |
5016 | bs->commands = NULL; | |
5017 | bs->old_val = NULL; | |
5018 | bs->print_it = print_it_normal; | |
5019 | return bs; | |
5020 | } | |
5021 | \f | |
d983da9c DJ |
5022 | /* The target has stopped with waitstatus WS. Check if any hardware |
5023 | watchpoints have triggered, according to the target. */ | |
5024 | ||
5025 | int | |
5026 | watchpoints_triggered (struct target_waitstatus *ws) | |
5027 | { | |
d92524f1 | 5028 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
5029 | CORE_ADDR addr; |
5030 | struct breakpoint *b; | |
5031 | ||
5032 | if (!stopped_by_watchpoint) | |
5033 | { | |
5034 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
5035 | as not triggered. */ | |
5036 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5037 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5038 | { |
5039 | struct watchpoint *w = (struct watchpoint *) b; | |
5040 | ||
5041 | w->watchpoint_triggered = watch_triggered_no; | |
5042 | } | |
d983da9c DJ |
5043 | |
5044 | return 0; | |
5045 | } | |
5046 | ||
5047 | if (!target_stopped_data_address (¤t_target, &addr)) | |
5048 | { | |
5049 | /* We were stopped by a watchpoint, but we don't know where. | |
5050 | Mark all watchpoints as unknown. */ | |
5051 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5052 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
5053 | { |
5054 | struct watchpoint *w = (struct watchpoint *) b; | |
5055 | ||
5056 | w->watchpoint_triggered = watch_triggered_unknown; | |
5057 | } | |
d983da9c | 5058 | |
3c4797ba | 5059 | return 1; |
d983da9c DJ |
5060 | } |
5061 | ||
5062 | /* The target could report the data address. Mark watchpoints | |
5063 | affected by this data address as triggered, and all others as not | |
5064 | triggered. */ | |
5065 | ||
5066 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 5067 | if (is_hardware_watchpoint (b)) |
d983da9c | 5068 | { |
3a5c3e22 | 5069 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 5070 | struct bp_location *loc; |
d983da9c | 5071 | |
3a5c3e22 | 5072 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 5073 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 5074 | { |
3a5c3e22 | 5075 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 5076 | { |
3a5c3e22 PA |
5077 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
5078 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
5079 | |
5080 | if (newaddr == start) | |
5081 | { | |
3a5c3e22 | 5082 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5083 | break; |
5084 | } | |
5085 | } | |
5086 | /* Exact match not required. Within range is sufficient. */ | |
5087 | else if (target_watchpoint_addr_within_range (¤t_target, | |
5088 | addr, loc->address, | |
5089 | loc->length)) | |
5090 | { | |
3a5c3e22 | 5091 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
5092 | break; |
5093 | } | |
5094 | } | |
d983da9c DJ |
5095 | } |
5096 | ||
5097 | return 1; | |
5098 | } | |
5099 | ||
c906108c SS |
5100 | /* Possible return values for watchpoint_check (this can't be an enum |
5101 | because of check_errors). */ | |
5102 | /* The watchpoint has been deleted. */ | |
5103 | #define WP_DELETED 1 | |
5104 | /* The value has changed. */ | |
5105 | #define WP_VALUE_CHANGED 2 | |
5106 | /* The value has not changed. */ | |
5107 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
5108 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
5109 | #define WP_IGNORE 4 | |
c906108c SS |
5110 | |
5111 | #define BP_TEMPFLAG 1 | |
5112 | #define BP_HARDWAREFLAG 2 | |
5113 | ||
4a64f543 MS |
5114 | /* Evaluate watchpoint condition expression and check if its value |
5115 | changed. | |
553e4c11 JB |
5116 | |
5117 | P should be a pointer to struct bpstat, but is defined as a void * | |
5118 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
5119 | |
5120 | static int | |
4efb68b1 | 5121 | watchpoint_check (void *p) |
c906108c SS |
5122 | { |
5123 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 5124 | struct watchpoint *b; |
c906108c SS |
5125 | struct frame_info *fr; |
5126 | int within_current_scope; | |
5127 | ||
f431efe5 | 5128 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 5129 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 5130 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 5131 | |
f6bc2008 PA |
5132 | /* If this is a local watchpoint, we only want to check if the |
5133 | watchpoint frame is in scope if the current thread is the thread | |
5134 | that was used to create the watchpoint. */ | |
5135 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 5136 | return WP_IGNORE; |
f6bc2008 | 5137 | |
c906108c SS |
5138 | if (b->exp_valid_block == NULL) |
5139 | within_current_scope = 1; | |
5140 | else | |
5141 | { | |
edb3359d DJ |
5142 | struct frame_info *frame = get_current_frame (); |
5143 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
5144 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
5145 | ||
c9cf6e20 | 5146 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
4a64f543 MS |
5147 | still in the function but the stack frame has already been |
5148 | invalidated. Since we can't rely on the values of local | |
5149 | variables after the stack has been destroyed, we are treating | |
5150 | the watchpoint in that state as `not changed' without further | |
5151 | checking. Don't mark watchpoints as changed if the current | |
5152 | frame is in an epilogue - even if they are in some other | |
5153 | frame, our view of the stack is likely to be wrong and | |
5154 | frame_find_by_id could error out. */ | |
c9cf6e20 | 5155 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
60e1c644 | 5156 | return WP_IGNORE; |
a0f49112 | 5157 | |
101dcfbe | 5158 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 5159 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
5160 | |
5161 | /* If we've gotten confused in the unwinder, we might have | |
5162 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
5163 | if (within_current_scope) |
5164 | { | |
5165 | struct symbol *function; | |
5166 | ||
5167 | function = get_frame_function (fr); | |
5168 | if (function == NULL | |
5169 | || !contained_in (b->exp_valid_block, | |
5170 | SYMBOL_BLOCK_VALUE (function))) | |
5171 | within_current_scope = 0; | |
5172 | } | |
69fbadd5 | 5173 | |
edb3359d | 5174 | if (within_current_scope) |
c906108c SS |
5175 | /* If we end up stopping, the current frame will get selected |
5176 | in normal_stop. So this call to select_frame won't affect | |
5177 | the user. */ | |
0f7d239c | 5178 | select_frame (fr); |
c906108c | 5179 | } |
c5aa993b | 5180 | |
c906108c SS |
5181 | if (within_current_scope) |
5182 | { | |
4a64f543 MS |
5183 | /* We use value_{,free_to_}mark because it could be a *long* |
5184 | time before we return to the command level and call | |
5185 | free_all_values. We can't call free_all_values because we | |
5186 | might be in the middle of evaluating a function call. */ | |
c906108c | 5187 | |
0cf6dd15 | 5188 | int pc = 0; |
9c06b0b4 | 5189 | struct value *mark; |
fa4727a6 DJ |
5190 | struct value *new_val; |
5191 | ||
3a5c3e22 | 5192 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
5193 | /* Since we don't know the exact trigger address (from |
5194 | stopped_data_address), just tell the user we've triggered | |
5195 | a mask watchpoint. */ | |
5196 | return WP_VALUE_CHANGED; | |
5197 | ||
5198 | mark = value_mark (); | |
3a1115a0 | 5199 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
218d2fc6 | 5200 | |
bb9d5f81 PP |
5201 | if (b->val_bitsize != 0) |
5202 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); | |
5203 | ||
4a64f543 MS |
5204 | /* We use value_equal_contents instead of value_equal because |
5205 | the latter coerces an array to a pointer, thus comparing just | |
5206 | the address of the array instead of its contents. This is | |
5207 | not what we want. */ | |
fa4727a6 | 5208 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 5209 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 5210 | { |
fa4727a6 DJ |
5211 | if (new_val != NULL) |
5212 | { | |
5213 | release_value (new_val); | |
5214 | value_free_to_mark (mark); | |
5215 | } | |
c906108c SS |
5216 | bs->old_val = b->val; |
5217 | b->val = new_val; | |
fa4727a6 | 5218 | b->val_valid = 1; |
c906108c SS |
5219 | return WP_VALUE_CHANGED; |
5220 | } | |
5221 | else | |
5222 | { | |
60e1c644 | 5223 | /* Nothing changed. */ |
c906108c | 5224 | value_free_to_mark (mark); |
c906108c SS |
5225 | return WP_VALUE_NOT_CHANGED; |
5226 | } | |
5227 | } | |
5228 | else | |
5229 | { | |
79a45e25 PA |
5230 | struct ui_out *uiout = current_uiout; |
5231 | ||
c906108c | 5232 | /* This seems like the only logical thing to do because |
c5aa993b JM |
5233 | if we temporarily ignored the watchpoint, then when |
5234 | we reenter the block in which it is valid it contains | |
5235 | garbage (in the case of a function, it may have two | |
5236 | garbage values, one before and one after the prologue). | |
5237 | So we can't even detect the first assignment to it and | |
5238 | watch after that (since the garbage may or may not equal | |
5239 | the first value assigned). */ | |
348d480f PA |
5240 | /* We print all the stop information in |
5241 | breakpoint_ops->print_it, but in this case, by the time we | |
5242 | call breakpoint_ops->print_it this bp will be deleted | |
5243 | already. So we have no choice but print the information | |
5244 | here. */ | |
9dc5e2a9 | 5245 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
5246 | ui_out_field_string |
5247 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 5248 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 5249 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
5250 | ui_out_text (uiout, |
5251 | " deleted because the program has left the block in\n\ | |
8b93c638 | 5252 | which its expression is valid.\n"); |
4ce44c66 | 5253 | |
cdac0397 | 5254 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 5255 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 5256 | watchpoint_del_at_next_stop (b); |
c906108c SS |
5257 | |
5258 | return WP_DELETED; | |
5259 | } | |
5260 | } | |
5261 | ||
18a18393 | 5262 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
5263 | breakpoint location BL. This function does not check if we should |
5264 | stop, only if BL explains the stop. */ | |
5265 | ||
18a18393 | 5266 | static int |
6c95b8df | 5267 | bpstat_check_location (const struct bp_location *bl, |
09ac7c10 TT |
5268 | struct address_space *aspace, CORE_ADDR bp_addr, |
5269 | const struct target_waitstatus *ws) | |
18a18393 VP |
5270 | { |
5271 | struct breakpoint *b = bl->owner; | |
5272 | ||
348d480f | 5273 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
5274 | gdb_assert (b != NULL); |
5275 | ||
09ac7c10 | 5276 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
18a18393 VP |
5277 | } |
5278 | ||
3a5c3e22 PA |
5279 | /* Determine if the watched values have actually changed, and we |
5280 | should stop. If not, set BS->stop to 0. */ | |
5281 | ||
18a18393 VP |
5282 | static void |
5283 | bpstat_check_watchpoint (bpstat bs) | |
5284 | { | |
2bdf28a0 | 5285 | const struct bp_location *bl; |
3a5c3e22 | 5286 | struct watchpoint *b; |
2bdf28a0 JK |
5287 | |
5288 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5289 | bl = bs->bp_location_at; |
2bdf28a0 | 5290 | gdb_assert (bl != NULL); |
3a5c3e22 | 5291 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 5292 | gdb_assert (b != NULL); |
18a18393 | 5293 | |
18a18393 | 5294 | { |
18a18393 VP |
5295 | int must_check_value = 0; |
5296 | ||
3a5c3e22 | 5297 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
5298 | /* For a software watchpoint, we must always check the |
5299 | watched value. */ | |
5300 | must_check_value = 1; | |
5301 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
5302 | /* We have a hardware watchpoint (read, write, or access) | |
5303 | and the target earlier reported an address watched by | |
5304 | this watchpoint. */ | |
5305 | must_check_value = 1; | |
5306 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 5307 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
5308 | /* We were stopped by a hardware watchpoint, but the target could |
5309 | not report the data address. We must check the watchpoint's | |
5310 | value. Access and read watchpoints are out of luck; without | |
5311 | a data address, we can't figure it out. */ | |
5312 | must_check_value = 1; | |
3a5c3e22 | 5313 | |
18a18393 VP |
5314 | if (must_check_value) |
5315 | { | |
3e43a32a MS |
5316 | char *message |
5317 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 5318 | b->base.number); |
18a18393 VP |
5319 | struct cleanup *cleanups = make_cleanup (xfree, message); |
5320 | int e = catch_errors (watchpoint_check, bs, message, | |
5321 | RETURN_MASK_ALL); | |
5322 | do_cleanups (cleanups); | |
5323 | switch (e) | |
5324 | { | |
5325 | case WP_DELETED: | |
5326 | /* We've already printed what needs to be printed. */ | |
5327 | bs->print_it = print_it_done; | |
5328 | /* Stop. */ | |
5329 | break; | |
60e1c644 PA |
5330 | case WP_IGNORE: |
5331 | bs->print_it = print_it_noop; | |
5332 | bs->stop = 0; | |
5333 | break; | |
18a18393 | 5334 | case WP_VALUE_CHANGED: |
3a5c3e22 | 5335 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 5336 | { |
85d721b8 PA |
5337 | /* There are two cases to consider here: |
5338 | ||
4a64f543 | 5339 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
5340 | In that case, trust the target, and always report |
5341 | the watchpoint hit to the user. Even though | |
5342 | reads don't cause value changes, the value may | |
5343 | have changed since the last time it was read, and | |
5344 | since we're not trapping writes, we will not see | |
5345 | those, and as such we should ignore our notion of | |
5346 | old value. | |
5347 | ||
4a64f543 | 5348 | 2. We're watching the triggered memory for both |
85d721b8 PA |
5349 | reads and writes. There are two ways this may |
5350 | happen: | |
5351 | ||
4a64f543 | 5352 | 2.1. This is a target that can't break on data |
85d721b8 PA |
5353 | reads only, but can break on accesses (reads or |
5354 | writes), such as e.g., x86. We detect this case | |
5355 | at the time we try to insert read watchpoints. | |
5356 | ||
4a64f543 | 5357 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
5358 | watchpoints, but, the user set an access or write |
5359 | watchpoint watching the same memory as this read | |
5360 | watchpoint. | |
5361 | ||
5362 | If we're watching memory writes as well as reads, | |
5363 | ignore watchpoint hits when we find that the | |
5364 | value hasn't changed, as reads don't cause | |
5365 | changes. This still gives false positives when | |
5366 | the program writes the same value to memory as | |
5367 | what there was already in memory (we will confuse | |
5368 | it for a read), but it's much better than | |
5369 | nothing. */ | |
5370 | ||
5371 | int other_write_watchpoint = 0; | |
5372 | ||
5373 | if (bl->watchpoint_type == hw_read) | |
5374 | { | |
5375 | struct breakpoint *other_b; | |
5376 | ||
5377 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
5378 | if (other_b->type == bp_hardware_watchpoint |
5379 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 5380 | { |
3a5c3e22 PA |
5381 | struct watchpoint *other_w = |
5382 | (struct watchpoint *) other_b; | |
5383 | ||
5384 | if (other_w->watchpoint_triggered | |
5385 | == watch_triggered_yes) | |
5386 | { | |
5387 | other_write_watchpoint = 1; | |
5388 | break; | |
5389 | } | |
85d721b8 PA |
5390 | } |
5391 | } | |
5392 | ||
5393 | if (other_write_watchpoint | |
5394 | || bl->watchpoint_type == hw_access) | |
5395 | { | |
5396 | /* We're watching the same memory for writes, | |
5397 | and the value changed since the last time we | |
5398 | updated it, so this trap must be for a write. | |
5399 | Ignore it. */ | |
5400 | bs->print_it = print_it_noop; | |
5401 | bs->stop = 0; | |
5402 | } | |
18a18393 VP |
5403 | } |
5404 | break; | |
5405 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
5406 | if (b->base.type == bp_hardware_watchpoint |
5407 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
5408 | { |
5409 | /* Don't stop: write watchpoints shouldn't fire if | |
5410 | the value hasn't changed. */ | |
5411 | bs->print_it = print_it_noop; | |
5412 | bs->stop = 0; | |
5413 | } | |
5414 | /* Stop. */ | |
5415 | break; | |
5416 | default: | |
5417 | /* Can't happen. */ | |
5418 | case 0: | |
5419 | /* Error from catch_errors. */ | |
3a5c3e22 | 5420 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 5421 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
5422 | /* We've already printed what needs to be printed. */ |
5423 | bs->print_it = print_it_done; | |
5424 | break; | |
5425 | } | |
5426 | } | |
5427 | else /* must_check_value == 0 */ | |
5428 | { | |
5429 | /* This is a case where some watchpoint(s) triggered, but | |
5430 | not at the address of this watchpoint, or else no | |
5431 | watchpoint triggered after all. So don't print | |
5432 | anything for this watchpoint. */ | |
5433 | bs->print_it = print_it_noop; | |
5434 | bs->stop = 0; | |
5435 | } | |
5436 | } | |
5437 | } | |
5438 | ||
7d4df6a4 DE |
5439 | /* For breakpoints that are currently marked as telling gdb to stop, |
5440 | check conditions (condition proper, frame, thread and ignore count) | |
18a18393 VP |
5441 | of breakpoint referred to by BS. If we should not stop for this |
5442 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 5443 | |
18a18393 VP |
5444 | static void |
5445 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
5446 | { | |
2bdf28a0 JK |
5447 | const struct bp_location *bl; |
5448 | struct breakpoint *b; | |
7d4df6a4 DE |
5449 | int value_is_zero = 0; |
5450 | struct expression *cond; | |
5451 | ||
5452 | gdb_assert (bs->stop); | |
2bdf28a0 JK |
5453 | |
5454 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 5455 | bl = bs->bp_location_at; |
2bdf28a0 | 5456 | gdb_assert (bl != NULL); |
f431efe5 | 5457 | b = bs->breakpoint_at; |
2bdf28a0 | 5458 | gdb_assert (b != NULL); |
18a18393 | 5459 | |
b775012e LM |
5460 | /* Even if the target evaluated the condition on its end and notified GDB, we |
5461 | need to do so again since GDB does not know if we stopped due to a | |
5462 | breakpoint or a single step breakpoint. */ | |
5463 | ||
18a18393 | 5464 | if (frame_id_p (b->frame_id) |
edb3359d | 5465 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 | 5466 | { |
7d4df6a4 DE |
5467 | bs->stop = 0; |
5468 | return; | |
5469 | } | |
60e1c644 | 5470 | |
12ab52e9 PA |
5471 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
5472 | evaluating the condition if this isn't the specified | |
5473 | thread/task. */ | |
5d5658a1 | 5474 | if ((b->thread != -1 && b->thread != ptid_to_global_thread_id (ptid)) |
12ab52e9 PA |
5475 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
5476 | ||
6c1b0f7b DE |
5477 | { |
5478 | bs->stop = 0; | |
5479 | return; | |
5480 | } | |
5481 | ||
6dddc817 DE |
5482 | /* Evaluate extension language breakpoints that have a "stop" method |
5483 | implemented. */ | |
5484 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); | |
7371cf6d | 5485 | |
7d4df6a4 DE |
5486 | if (is_watchpoint (b)) |
5487 | { | |
5488 | struct watchpoint *w = (struct watchpoint *) b; | |
3a5c3e22 | 5489 | |
7d4df6a4 DE |
5490 | cond = w->cond_exp; |
5491 | } | |
5492 | else | |
5493 | cond = bl->cond; | |
60e1c644 | 5494 | |
7d4df6a4 DE |
5495 | if (cond && b->disposition != disp_del_at_next_stop) |
5496 | { | |
5497 | int within_current_scope = 1; | |
5498 | struct watchpoint * w; | |
60e1c644 | 5499 | |
7d4df6a4 DE |
5500 | /* We use value_mark and value_free_to_mark because it could |
5501 | be a long time before we return to the command level and | |
5502 | call free_all_values. We can't call free_all_values | |
5503 | because we might be in the middle of evaluating a | |
5504 | function call. */ | |
5505 | struct value *mark = value_mark (); | |
5506 | ||
5507 | if (is_watchpoint (b)) | |
5508 | w = (struct watchpoint *) b; | |
5509 | else | |
5510 | w = NULL; | |
5511 | ||
5512 | /* Need to select the frame, with all that implies so that | |
5513 | the conditions will have the right context. Because we | |
5514 | use the frame, we will not see an inlined function's | |
5515 | variables when we arrive at a breakpoint at the start | |
5516 | of the inlined function; the current frame will be the | |
5517 | call site. */ | |
5518 | if (w == NULL || w->cond_exp_valid_block == NULL) | |
5519 | select_frame (get_current_frame ()); | |
5520 | else | |
18a18393 | 5521 | { |
7d4df6a4 DE |
5522 | struct frame_info *frame; |
5523 | ||
5524 | /* For local watchpoint expressions, which particular | |
5525 | instance of a local is being watched matters, so we | |
5526 | keep track of the frame to evaluate the expression | |
5527 | in. To evaluate the condition however, it doesn't | |
5528 | really matter which instantiation of the function | |
5529 | where the condition makes sense triggers the | |
5530 | watchpoint. This allows an expression like "watch | |
5531 | global if q > 10" set in `func', catch writes to | |
5532 | global on all threads that call `func', or catch | |
5533 | writes on all recursive calls of `func' by a single | |
5534 | thread. We simply always evaluate the condition in | |
5535 | the innermost frame that's executing where it makes | |
5536 | sense to evaluate the condition. It seems | |
5537 | intuitive. */ | |
5538 | frame = block_innermost_frame (w->cond_exp_valid_block); | |
5539 | if (frame != NULL) | |
5540 | select_frame (frame); | |
5541 | else | |
5542 | within_current_scope = 0; | |
18a18393 | 5543 | } |
7d4df6a4 DE |
5544 | if (within_current_scope) |
5545 | value_is_zero | |
5546 | = catch_errors (breakpoint_cond_eval, cond, | |
5547 | "Error in testing breakpoint condition:\n", | |
5548 | RETURN_MASK_ALL); | |
5549 | else | |
18a18393 | 5550 | { |
7d4df6a4 DE |
5551 | warning (_("Watchpoint condition cannot be tested " |
5552 | "in the current scope")); | |
5553 | /* If we failed to set the right context for this | |
5554 | watchpoint, unconditionally report it. */ | |
5555 | value_is_zero = 0; | |
18a18393 | 5556 | } |
7d4df6a4 DE |
5557 | /* FIXME-someday, should give breakpoint #. */ |
5558 | value_free_to_mark (mark); | |
18a18393 | 5559 | } |
7d4df6a4 DE |
5560 | |
5561 | if (cond && value_is_zero) | |
5562 | { | |
5563 | bs->stop = 0; | |
5564 | } | |
7d4df6a4 DE |
5565 | else if (b->ignore_count > 0) |
5566 | { | |
5567 | b->ignore_count--; | |
5568 | bs->stop = 0; | |
5569 | /* Increase the hit count even though we don't stop. */ | |
5570 | ++(b->hit_count); | |
5571 | observer_notify_breakpoint_modified (b); | |
5572 | } | |
18a18393 VP |
5573 | } |
5574 | ||
1cf4d951 PA |
5575 | /* Returns true if we need to track moribund locations of LOC's type |
5576 | on the current target. */ | |
5577 | ||
5578 | static int | |
5579 | need_moribund_for_location_type (struct bp_location *loc) | |
5580 | { | |
5581 | return ((loc->loc_type == bp_loc_software_breakpoint | |
5582 | && !target_supports_stopped_by_sw_breakpoint ()) | |
5583 | || (loc->loc_type == bp_loc_hardware_breakpoint | |
5584 | && !target_supports_stopped_by_hw_breakpoint ())); | |
5585 | } | |
5586 | ||
18a18393 | 5587 | |
9709f61c | 5588 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 5589 | BP_ADDR in thread PTID. |
c906108c | 5590 | |
d983da9c | 5591 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
5592 | don't understand this stop. Result is a chain of bpstat's such |
5593 | that: | |
c906108c | 5594 | |
c5aa993b | 5595 | if we don't understand the stop, the result is a null pointer. |
c906108c | 5596 | |
c5aa993b | 5597 | if we understand why we stopped, the result is not null. |
c906108c | 5598 | |
c5aa993b JM |
5599 | Each element of the chain refers to a particular breakpoint or |
5600 | watchpoint at which we have stopped. (We may have stopped for | |
5601 | several reasons concurrently.) | |
c906108c | 5602 | |
c5aa993b JM |
5603 | Each element of the chain has valid next, breakpoint_at, |
5604 | commands, FIXME??? fields. */ | |
c906108c SS |
5605 | |
5606 | bpstat | |
6c95b8df | 5607 | bpstat_stop_status (struct address_space *aspace, |
09ac7c10 TT |
5608 | CORE_ADDR bp_addr, ptid_t ptid, |
5609 | const struct target_waitstatus *ws) | |
c906108c | 5610 | { |
0d381245 | 5611 | struct breakpoint *b = NULL; |
afe38095 | 5612 | struct bp_location *bl; |
20874c92 | 5613 | struct bp_location *loc; |
5760d0ab JK |
5614 | /* First item of allocated bpstat's. */ |
5615 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 5616 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 5617 | bpstat bs; |
20874c92 | 5618 | int ix; |
429374b8 | 5619 | int need_remove_insert; |
f431efe5 | 5620 | int removed_any; |
c906108c | 5621 | |
f431efe5 PA |
5622 | /* First, build the bpstat chain with locations that explain a |
5623 | target stop, while being careful to not set the target running, | |
5624 | as that may invalidate locations (in particular watchpoint | |
5625 | locations are recreated). Resuming will happen here with | |
5626 | breakpoint conditions or watchpoint expressions that include | |
5627 | inferior function calls. */ | |
c5aa993b | 5628 | |
429374b8 JK |
5629 | ALL_BREAKPOINTS (b) |
5630 | { | |
1a853c52 | 5631 | if (!breakpoint_enabled (b)) |
429374b8 | 5632 | continue; |
a5606eee | 5633 | |
429374b8 JK |
5634 | for (bl = b->loc; bl != NULL; bl = bl->next) |
5635 | { | |
4a64f543 MS |
5636 | /* For hardware watchpoints, we look only at the first |
5637 | location. The watchpoint_check function will work on the | |
5638 | entire expression, not the individual locations. For | |
5639 | read watchpoints, the watchpoints_triggered function has | |
5640 | checked all locations already. */ | |
429374b8 JK |
5641 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
5642 | break; | |
18a18393 | 5643 | |
f6592439 | 5644 | if (!bl->enabled || bl->shlib_disabled) |
429374b8 | 5645 | continue; |
c5aa993b | 5646 | |
09ac7c10 | 5647 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
429374b8 | 5648 | continue; |
c5aa993b | 5649 | |
4a64f543 MS |
5650 | /* Come here if it's a watchpoint, or if the break address |
5651 | matches. */ | |
c5aa993b | 5652 | |
4a64f543 MS |
5653 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
5654 | explain stop. */ | |
c5aa993b | 5655 | |
f431efe5 PA |
5656 | /* Assume we stop. Should we find a watchpoint that is not |
5657 | actually triggered, or if the condition of the breakpoint | |
5658 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
5659 | bs->stop = 1; |
5660 | bs->print = 1; | |
d983da9c | 5661 | |
f431efe5 PA |
5662 | /* If this is a scope breakpoint, mark the associated |
5663 | watchpoint as triggered so that we will handle the | |
5664 | out-of-scope event. We'll get to the watchpoint next | |
5665 | iteration. */ | |
d0fb5eae | 5666 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
5667 | { |
5668 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
5669 | ||
5670 | w->watchpoint_triggered = watch_triggered_yes; | |
5671 | } | |
f431efe5 PA |
5672 | } |
5673 | } | |
5674 | ||
7c16b83e | 5675 | /* Check if a moribund breakpoint explains the stop. */ |
1cf4d951 PA |
5676 | if (!target_supports_stopped_by_sw_breakpoint () |
5677 | || !target_supports_stopped_by_hw_breakpoint ()) | |
f431efe5 | 5678 | { |
1cf4d951 | 5679 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
f431efe5 | 5680 | { |
1cf4d951 PA |
5681 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
5682 | && need_moribund_for_location_type (loc)) | |
5683 | { | |
5684 | bs = bpstat_alloc (loc, &bs_link); | |
5685 | /* For hits of moribund locations, we should just proceed. */ | |
5686 | bs->stop = 0; | |
5687 | bs->print = 0; | |
5688 | bs->print_it = print_it_noop; | |
5689 | } | |
f431efe5 PA |
5690 | } |
5691 | } | |
5692 | ||
edcc5120 TT |
5693 | /* A bit of special processing for shlib breakpoints. We need to |
5694 | process solib loading here, so that the lists of loaded and | |
5695 | unloaded libraries are correct before we handle "catch load" and | |
5696 | "catch unload". */ | |
5697 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
5698 | { | |
5d268276 | 5699 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
edcc5120 TT |
5700 | { |
5701 | handle_solib_event (); | |
5702 | break; | |
5703 | } | |
5704 | } | |
5705 | ||
f431efe5 PA |
5706 | /* Now go through the locations that caused the target to stop, and |
5707 | check whether we're interested in reporting this stop to higher | |
5708 | layers, or whether we should resume the target transparently. */ | |
5709 | ||
5710 | removed_any = 0; | |
5711 | ||
5760d0ab | 5712 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
5713 | { |
5714 | if (!bs->stop) | |
5715 | continue; | |
5716 | ||
f431efe5 | 5717 | b = bs->breakpoint_at; |
348d480f PA |
5718 | b->ops->check_status (bs); |
5719 | if (bs->stop) | |
28010a5d | 5720 | { |
348d480f | 5721 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 5722 | |
429374b8 JK |
5723 | if (bs->stop) |
5724 | { | |
5725 | ++(b->hit_count); | |
8d3788bd | 5726 | observer_notify_breakpoint_modified (b); |
c906108c | 5727 | |
4a64f543 | 5728 | /* We will stop here. */ |
429374b8 JK |
5729 | if (b->disposition == disp_disable) |
5730 | { | |
816338b5 | 5731 | --(b->enable_count); |
1a853c52 | 5732 | if (b->enable_count <= 0) |
429374b8 | 5733 | b->enable_state = bp_disabled; |
f431efe5 | 5734 | removed_any = 1; |
429374b8 JK |
5735 | } |
5736 | if (b->silent) | |
5737 | bs->print = 0; | |
5738 | bs->commands = b->commands; | |
9add0f1b | 5739 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
5740 | if (command_line_is_silent (bs->commands |
5741 | ? bs->commands->commands : NULL)) | |
5742 | bs->print = 0; | |
9d6e6e84 HZ |
5743 | |
5744 | b->ops->after_condition_true (bs); | |
429374b8 JK |
5745 | } |
5746 | ||
348d480f | 5747 | } |
a9b3a50f PA |
5748 | |
5749 | /* Print nothing for this entry if we don't stop or don't | |
5750 | print. */ | |
5751 | if (!bs->stop || !bs->print) | |
5752 | bs->print_it = print_it_noop; | |
429374b8 | 5753 | } |
876fa593 | 5754 | |
d983da9c DJ |
5755 | /* If we aren't stopping, the value of some hardware watchpoint may |
5756 | not have changed, but the intermediate memory locations we are | |
5757 | watching may have. Don't bother if we're stopping; this will get | |
5758 | done later. */ | |
d832cb68 | 5759 | need_remove_insert = 0; |
5760d0ab JK |
5760 | if (! bpstat_causes_stop (bs_head)) |
5761 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 5762 | if (!bs->stop |
f431efe5 PA |
5763 | && bs->breakpoint_at |
5764 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 5765 | { |
3a5c3e22 PA |
5766 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
5767 | ||
5768 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 5769 | need_remove_insert = 1; |
d983da9c DJ |
5770 | } |
5771 | ||
d832cb68 | 5772 | if (need_remove_insert) |
44702360 | 5773 | update_global_location_list (UGLL_MAY_INSERT); |
f431efe5 | 5774 | else if (removed_any) |
44702360 | 5775 | update_global_location_list (UGLL_DONT_INSERT); |
d832cb68 | 5776 | |
5760d0ab | 5777 | return bs_head; |
c906108c | 5778 | } |
628fe4e4 JK |
5779 | |
5780 | static void | |
5781 | handle_jit_event (void) | |
5782 | { | |
5783 | struct frame_info *frame; | |
5784 | struct gdbarch *gdbarch; | |
5785 | ||
243a9253 PA |
5786 | if (debug_infrun) |
5787 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); | |
5788 | ||
628fe4e4 JK |
5789 | /* Switch terminal for any messages produced by |
5790 | breakpoint_re_set. */ | |
5791 | target_terminal_ours_for_output (); | |
5792 | ||
5793 | frame = get_current_frame (); | |
5794 | gdbarch = get_frame_arch (frame); | |
5795 | ||
5796 | jit_event_handler (gdbarch); | |
5797 | ||
5798 | target_terminal_inferior (); | |
5799 | } | |
5800 | ||
5801 | /* Prepare WHAT final decision for infrun. */ | |
5802 | ||
5803 | /* Decide what infrun needs to do with this bpstat. */ | |
5804 | ||
c906108c | 5805 | struct bpstat_what |
0e30163f | 5806 | bpstat_what (bpstat bs_head) |
c906108c | 5807 | { |
c906108c | 5808 | struct bpstat_what retval; |
628fe4e4 | 5809 | int jit_event = 0; |
0e30163f | 5810 | bpstat bs; |
c906108c | 5811 | |
628fe4e4 | 5812 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 5813 | retval.call_dummy = STOP_NONE; |
186c406b | 5814 | retval.is_longjmp = 0; |
628fe4e4 | 5815 | |
0e30163f | 5816 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 5817 | { |
628fe4e4 JK |
5818 | /* Extract this BS's action. After processing each BS, we check |
5819 | if its action overrides all we've seem so far. */ | |
5820 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5821 | enum bptype bptype; | |
5822 | ||
c906108c | 5823 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
5824 | { |
5825 | /* I suspect this can happen if it was a momentary | |
5826 | breakpoint which has since been deleted. */ | |
5827 | bptype = bp_none; | |
5828 | } | |
20874c92 | 5829 | else |
f431efe5 | 5830 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
5831 | |
5832 | switch (bptype) | |
c906108c SS |
5833 | { |
5834 | case bp_none: | |
628fe4e4 | 5835 | break; |
c906108c SS |
5836 | case bp_breakpoint: |
5837 | case bp_hardware_breakpoint: | |
7c16b83e | 5838 | case bp_single_step: |
c906108c SS |
5839 | case bp_until: |
5840 | case bp_finish: | |
a9b3a50f | 5841 | case bp_shlib_event: |
c906108c SS |
5842 | if (bs->stop) |
5843 | { | |
5844 | if (bs->print) | |
628fe4e4 | 5845 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5846 | else |
628fe4e4 | 5847 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5848 | } |
5849 | else | |
628fe4e4 | 5850 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
5851 | break; |
5852 | case bp_watchpoint: | |
5853 | case bp_hardware_watchpoint: | |
5854 | case bp_read_watchpoint: | |
5855 | case bp_access_watchpoint: | |
5856 | if (bs->stop) | |
5857 | { | |
5858 | if (bs->print) | |
628fe4e4 | 5859 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 5860 | else |
628fe4e4 | 5861 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
5862 | } |
5863 | else | |
628fe4e4 JK |
5864 | { |
5865 | /* There was a watchpoint, but we're not stopping. | |
5866 | This requires no further action. */ | |
5867 | } | |
c906108c SS |
5868 | break; |
5869 | case bp_longjmp: | |
e2e4d78b | 5870 | case bp_longjmp_call_dummy: |
186c406b | 5871 | case bp_exception: |
0a39bb32 PA |
5872 | if (bs->stop) |
5873 | { | |
5874 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; | |
5875 | retval.is_longjmp = bptype != bp_exception; | |
5876 | } | |
5877 | else | |
5878 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5879 | break; |
5880 | case bp_longjmp_resume: | |
186c406b | 5881 | case bp_exception_resume: |
0a39bb32 PA |
5882 | if (bs->stop) |
5883 | { | |
5884 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; | |
5885 | retval.is_longjmp = bptype == bp_longjmp_resume; | |
5886 | } | |
5887 | else | |
5888 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c SS |
5889 | break; |
5890 | case bp_step_resume: | |
5891 | if (bs->stop) | |
628fe4e4 JK |
5892 | this_action = BPSTAT_WHAT_STEP_RESUME; |
5893 | else | |
c906108c | 5894 | { |
628fe4e4 JK |
5895 | /* It is for the wrong frame. */ |
5896 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 5897 | } |
c906108c | 5898 | break; |
2c03e5be PA |
5899 | case bp_hp_step_resume: |
5900 | if (bs->stop) | |
5901 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
5902 | else | |
5903 | { | |
5904 | /* It is for the wrong frame. */ | |
5905 | this_action = BPSTAT_WHAT_SINGLE; | |
5906 | } | |
5907 | break; | |
c906108c | 5908 | case bp_watchpoint_scope: |
c4093a6a | 5909 | case bp_thread_event: |
1900040c | 5910 | case bp_overlay_event: |
0fd8e87f | 5911 | case bp_longjmp_master: |
aa7d318d | 5912 | case bp_std_terminate_master: |
186c406b | 5913 | case bp_exception_master: |
628fe4e4 | 5914 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 5915 | break; |
ce78b96d | 5916 | case bp_catchpoint: |
c5aa993b JM |
5917 | if (bs->stop) |
5918 | { | |
5919 | if (bs->print) | |
628fe4e4 | 5920 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 5921 | else |
628fe4e4 | 5922 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
5923 | } |
5924 | else | |
628fe4e4 JK |
5925 | { |
5926 | /* There was a catchpoint, but we're not stopping. | |
5927 | This requires no further action. */ | |
5928 | } | |
5929 | break; | |
628fe4e4 JK |
5930 | case bp_jit_event: |
5931 | jit_event = 1; | |
5932 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 5933 | break; |
c906108c | 5934 | case bp_call_dummy: |
53a5351d JM |
5935 | /* Make sure the action is stop (silent or noisy), |
5936 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5937 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 5938 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
5939 | break; |
5940 | case bp_std_terminate: | |
5941 | /* Make sure the action is stop (silent or noisy), | |
5942 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 5943 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 5944 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 5945 | break; |
1042e4c0 | 5946 | case bp_tracepoint: |
7a697b8d | 5947 | case bp_fast_tracepoint: |
0fb4aa4b | 5948 | case bp_static_tracepoint: |
1042e4c0 SS |
5949 | /* Tracepoint hits should not be reported back to GDB, and |
5950 | if one got through somehow, it should have been filtered | |
5951 | out already. */ | |
5952 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 5953 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
5954 | break; |
5955 | case bp_gnu_ifunc_resolver: | |
5956 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
5957 | this_action = BPSTAT_WHAT_SINGLE; | |
5958 | break; | |
5959 | case bp_gnu_ifunc_resolver_return: | |
5960 | /* The breakpoint will be removed, execution will restart from the | |
5961 | PC of the former breakpoint. */ | |
5962 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
5963 | break; | |
e7e0cddf SS |
5964 | |
5965 | case bp_dprintf: | |
a11cfd87 HZ |
5966 | if (bs->stop) |
5967 | this_action = BPSTAT_WHAT_STOP_SILENT; | |
5968 | else | |
5969 | this_action = BPSTAT_WHAT_SINGLE; | |
e7e0cddf SS |
5970 | break; |
5971 | ||
628fe4e4 JK |
5972 | default: |
5973 | internal_error (__FILE__, __LINE__, | |
5974 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 5975 | } |
628fe4e4 JK |
5976 | |
5977 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 5978 | } |
628fe4e4 | 5979 | |
243a9253 PA |
5980 | return retval; |
5981 | } | |
628fe4e4 | 5982 | |
243a9253 PA |
5983 | void |
5984 | bpstat_run_callbacks (bpstat bs_head) | |
5985 | { | |
5986 | bpstat bs; | |
628fe4e4 | 5987 | |
0e30163f JK |
5988 | for (bs = bs_head; bs != NULL; bs = bs->next) |
5989 | { | |
5990 | struct breakpoint *b = bs->breakpoint_at; | |
5991 | ||
5992 | if (b == NULL) | |
5993 | continue; | |
5994 | switch (b->type) | |
5995 | { | |
243a9253 PA |
5996 | case bp_jit_event: |
5997 | handle_jit_event (); | |
5998 | break; | |
0e30163f JK |
5999 | case bp_gnu_ifunc_resolver: |
6000 | gnu_ifunc_resolver_stop (b); | |
6001 | break; | |
6002 | case bp_gnu_ifunc_resolver_return: | |
6003 | gnu_ifunc_resolver_return_stop (b); | |
6004 | break; | |
6005 | } | |
6006 | } | |
c906108c SS |
6007 | } |
6008 | ||
6009 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
6010 | without hardware support). This isn't related to a specific bpstat, | |
6011 | just to things like whether watchpoints are set. */ | |
6012 | ||
c5aa993b | 6013 | int |
fba45db2 | 6014 | bpstat_should_step (void) |
c906108c SS |
6015 | { |
6016 | struct breakpoint *b; | |
cc59ec59 | 6017 | |
c906108c | 6018 | ALL_BREAKPOINTS (b) |
717a8278 | 6019 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 6020 | return 1; |
c906108c SS |
6021 | return 0; |
6022 | } | |
6023 | ||
67822962 PA |
6024 | int |
6025 | bpstat_causes_stop (bpstat bs) | |
6026 | { | |
6027 | for (; bs != NULL; bs = bs->next) | |
6028 | if (bs->stop) | |
6029 | return 1; | |
6030 | ||
6031 | return 0; | |
6032 | } | |
6033 | ||
c906108c | 6034 | \f |
c5aa993b | 6035 | |
170b53b2 UW |
6036 | /* Compute a string of spaces suitable to indent the next line |
6037 | so it starts at the position corresponding to the table column | |
6038 | named COL_NAME in the currently active table of UIOUT. */ | |
6039 | ||
6040 | static char * | |
6041 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
6042 | { | |
6043 | static char wrap_indent[80]; | |
6044 | int i, total_width, width, align; | |
6045 | char *text; | |
6046 | ||
6047 | total_width = 0; | |
6048 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
6049 | { | |
6050 | if (strcmp (text, col_name) == 0) | |
6051 | { | |
6052 | gdb_assert (total_width < sizeof wrap_indent); | |
6053 | memset (wrap_indent, ' ', total_width); | |
6054 | wrap_indent[total_width] = 0; | |
6055 | ||
6056 | return wrap_indent; | |
6057 | } | |
6058 | ||
6059 | total_width += width + 1; | |
6060 | } | |
6061 | ||
6062 | return NULL; | |
6063 | } | |
6064 | ||
b775012e LM |
6065 | /* Determine if the locations of this breakpoint will have their conditions |
6066 | evaluated by the target, host or a mix of both. Returns the following: | |
6067 | ||
6068 | "host": Host evals condition. | |
6069 | "host or target": Host or Target evals condition. | |
6070 | "target": Target evals condition. | |
6071 | */ | |
6072 | ||
6073 | static const char * | |
6074 | bp_condition_evaluator (struct breakpoint *b) | |
6075 | { | |
6076 | struct bp_location *bl; | |
6077 | char host_evals = 0; | |
6078 | char target_evals = 0; | |
6079 | ||
6080 | if (!b) | |
6081 | return NULL; | |
6082 | ||
6083 | if (!is_breakpoint (b)) | |
6084 | return NULL; | |
6085 | ||
6086 | if (gdb_evaluates_breakpoint_condition_p () | |
6087 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6088 | return condition_evaluation_host; | |
6089 | ||
6090 | for (bl = b->loc; bl; bl = bl->next) | |
6091 | { | |
6092 | if (bl->cond_bytecode) | |
6093 | target_evals++; | |
6094 | else | |
6095 | host_evals++; | |
6096 | } | |
6097 | ||
6098 | if (host_evals && target_evals) | |
6099 | return condition_evaluation_both; | |
6100 | else if (target_evals) | |
6101 | return condition_evaluation_target; | |
6102 | else | |
6103 | return condition_evaluation_host; | |
6104 | } | |
6105 | ||
6106 | /* Determine the breakpoint location's condition evaluator. This is | |
6107 | similar to bp_condition_evaluator, but for locations. */ | |
6108 | ||
6109 | static const char * | |
6110 | bp_location_condition_evaluator (struct bp_location *bl) | |
6111 | { | |
6112 | if (bl && !is_breakpoint (bl->owner)) | |
6113 | return NULL; | |
6114 | ||
6115 | if (gdb_evaluates_breakpoint_condition_p () | |
6116 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
6117 | return condition_evaluation_host; | |
6118 | ||
6119 | if (bl && bl->cond_bytecode) | |
6120 | return condition_evaluation_target; | |
6121 | else | |
6122 | return condition_evaluation_host; | |
6123 | } | |
6124 | ||
859825b8 JK |
6125 | /* Print the LOC location out of the list of B->LOC locations. */ |
6126 | ||
170b53b2 UW |
6127 | static void |
6128 | print_breakpoint_location (struct breakpoint *b, | |
6129 | struct bp_location *loc) | |
0d381245 | 6130 | { |
79a45e25 | 6131 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
6132 | struct cleanup *old_chain = save_current_program_space (); |
6133 | ||
859825b8 JK |
6134 | if (loc != NULL && loc->shlib_disabled) |
6135 | loc = NULL; | |
6136 | ||
6c95b8df PA |
6137 | if (loc != NULL) |
6138 | set_current_program_space (loc->pspace); | |
6139 | ||
56435ebe | 6140 | if (b->display_canonical) |
f00aae0f KS |
6141 | ui_out_field_string (uiout, "what", |
6142 | event_location_to_string (b->location)); | |
2f202fde | 6143 | else if (loc && loc->symtab) |
0d381245 VP |
6144 | { |
6145 | struct symbol *sym | |
6146 | = find_pc_sect_function (loc->address, loc->section); | |
6147 | if (sym) | |
6148 | { | |
6149 | ui_out_text (uiout, "in "); | |
6150 | ui_out_field_string (uiout, "func", | |
6151 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
6152 | ui_out_text (uiout, " "); |
6153 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
6154 | ui_out_text (uiout, "at "); | |
0d381245 | 6155 | } |
05cba821 JK |
6156 | ui_out_field_string (uiout, "file", |
6157 | symtab_to_filename_for_display (loc->symtab)); | |
0d381245 | 6158 | ui_out_text (uiout, ":"); |
05cba821 | 6159 | |
0d381245 | 6160 | if (ui_out_is_mi_like_p (uiout)) |
2f202fde JK |
6161 | ui_out_field_string (uiout, "fullname", |
6162 | symtab_to_fullname (loc->symtab)); | |
0d381245 | 6163 | |
f8eba3c6 | 6164 | ui_out_field_int (uiout, "line", loc->line_number); |
0d381245 | 6165 | } |
859825b8 | 6166 | else if (loc) |
0d381245 | 6167 | { |
f99d8bf4 PA |
6168 | struct ui_file *stb = mem_fileopen (); |
6169 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); | |
170b53b2 | 6170 | |
f99d8bf4 | 6171 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
22e722e1 | 6172 | demangle, ""); |
0d381245 | 6173 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
6174 | |
6175 | do_cleanups (stb_chain); | |
0d381245 | 6176 | } |
859825b8 | 6177 | else |
f00aae0f KS |
6178 | { |
6179 | ui_out_field_string (uiout, "pending", | |
6180 | event_location_to_string (b->location)); | |
6181 | /* If extra_string is available, it could be holding a condition | |
6182 | or dprintf arguments. In either case, make sure it is printed, | |
6183 | too, but only for non-MI streams. */ | |
6184 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) | |
6185 | { | |
6186 | if (b->type == bp_dprintf) | |
6187 | ui_out_text (uiout, ","); | |
6188 | else | |
6189 | ui_out_text (uiout, " "); | |
6190 | ui_out_text (uiout, b->extra_string); | |
6191 | } | |
6192 | } | |
6c95b8df | 6193 | |
b775012e LM |
6194 | if (loc && is_breakpoint (b) |
6195 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target | |
6196 | && bp_condition_evaluator (b) == condition_evaluation_both) | |
6197 | { | |
6198 | ui_out_text (uiout, " ("); | |
6199 | ui_out_field_string (uiout, "evaluated-by", | |
6200 | bp_location_condition_evaluator (loc)); | |
6201 | ui_out_text (uiout, ")"); | |
6202 | } | |
6203 | ||
6c95b8df | 6204 | do_cleanups (old_chain); |
0d381245 VP |
6205 | } |
6206 | ||
269b11a2 PA |
6207 | static const char * |
6208 | bptype_string (enum bptype type) | |
c906108c | 6209 | { |
c4093a6a JM |
6210 | struct ep_type_description |
6211 | { | |
6212 | enum bptype type; | |
6213 | char *description; | |
6214 | }; | |
6215 | static struct ep_type_description bptypes[] = | |
c906108c | 6216 | { |
c5aa993b JM |
6217 | {bp_none, "?deleted?"}, |
6218 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 6219 | {bp_hardware_breakpoint, "hw breakpoint"}, |
7c16b83e | 6220 | {bp_single_step, "sw single-step"}, |
c5aa993b JM |
6221 | {bp_until, "until"}, |
6222 | {bp_finish, "finish"}, | |
6223 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 6224 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
6225 | {bp_read_watchpoint, "read watchpoint"}, |
6226 | {bp_access_watchpoint, "acc watchpoint"}, | |
6227 | {bp_longjmp, "longjmp"}, | |
6228 | {bp_longjmp_resume, "longjmp resume"}, | |
e2e4d78b | 6229 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
186c406b TT |
6230 | {bp_exception, "exception"}, |
6231 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 6232 | {bp_step_resume, "step resume"}, |
2c03e5be | 6233 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
6234 | {bp_watchpoint_scope, "watchpoint scope"}, |
6235 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 6236 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 6237 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 6238 | {bp_thread_event, "thread events"}, |
1900040c | 6239 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 6240 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 6241 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 6242 | {bp_exception_master, "exception master"}, |
ce78b96d | 6243 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 6244 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 6245 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 6246 | {bp_static_tracepoint, "static tracepoint"}, |
e7e0cddf | 6247 | {bp_dprintf, "dprintf"}, |
4efc6507 | 6248 | {bp_jit_event, "jit events"}, |
0e30163f JK |
6249 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
6250 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 6251 | }; |
269b11a2 PA |
6252 | |
6253 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
6254 | || ((int) type != bptypes[(int) type].type)) | |
6255 | internal_error (__FILE__, __LINE__, | |
6256 | _("bptypes table does not describe type #%d."), | |
6257 | (int) type); | |
6258 | ||
6259 | return bptypes[(int) type].description; | |
6260 | } | |
6261 | ||
998580f1 MK |
6262 | /* For MI, output a field named 'thread-groups' with a list as the value. |
6263 | For CLI, prefix the list with the string 'inf'. */ | |
6264 | ||
6265 | static void | |
6266 | output_thread_groups (struct ui_out *uiout, | |
6267 | const char *field_name, | |
6268 | VEC(int) *inf_num, | |
6269 | int mi_only) | |
6270 | { | |
752eb8b4 | 6271 | struct cleanup *back_to; |
998580f1 MK |
6272 | int is_mi = ui_out_is_mi_like_p (uiout); |
6273 | int inf; | |
6274 | int i; | |
6275 | ||
6276 | /* For backward compatibility, don't display inferiors in CLI unless | |
6277 | there are several. Always display them for MI. */ | |
6278 | if (!is_mi && mi_only) | |
6279 | return; | |
6280 | ||
752eb8b4 TT |
6281 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
6282 | ||
998580f1 MK |
6283 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
6284 | { | |
6285 | if (is_mi) | |
6286 | { | |
6287 | char mi_group[10]; | |
6288 | ||
6289 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); | |
6290 | ui_out_field_string (uiout, NULL, mi_group); | |
6291 | } | |
6292 | else | |
6293 | { | |
6294 | if (i == 0) | |
6295 | ui_out_text (uiout, " inf "); | |
6296 | else | |
6297 | ui_out_text (uiout, ", "); | |
6298 | ||
6299 | ui_out_text (uiout, plongest (inf)); | |
6300 | } | |
6301 | } | |
6302 | ||
6303 | do_cleanups (back_to); | |
6304 | } | |
6305 | ||
269b11a2 PA |
6306 | /* Print B to gdb_stdout. */ |
6307 | ||
6308 | static void | |
6309 | print_one_breakpoint_location (struct breakpoint *b, | |
6310 | struct bp_location *loc, | |
6311 | int loc_number, | |
6312 | struct bp_location **last_loc, | |
269b11a2 PA |
6313 | int allflag) |
6314 | { | |
6315 | struct command_line *l; | |
c2c6d25f | 6316 | static char bpenables[] = "nynny"; |
c906108c | 6317 | |
79a45e25 | 6318 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
6319 | int header_of_multiple = 0; |
6320 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
6321 | struct value_print_options opts; |
6322 | ||
6323 | get_user_print_options (&opts); | |
0d381245 VP |
6324 | |
6325 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
6326 | /* See comment in print_one_breakpoint concerning treatment of |
6327 | breakpoints with single disabled location. */ | |
0d381245 VP |
6328 | if (loc == NULL |
6329 | && (b->loc != NULL | |
6330 | && (b->loc->next != NULL || !b->loc->enabled))) | |
6331 | header_of_multiple = 1; | |
6332 | if (loc == NULL) | |
6333 | loc = b->loc; | |
6334 | ||
c4093a6a JM |
6335 | annotate_record (); |
6336 | ||
6337 | /* 1 */ | |
6338 | annotate_field (0); | |
0d381245 VP |
6339 | if (part_of_multiple) |
6340 | { | |
6341 | char *formatted; | |
0c6773c1 | 6342 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
6343 | ui_out_field_string (uiout, "number", formatted); |
6344 | xfree (formatted); | |
6345 | } | |
6346 | else | |
6347 | { | |
6348 | ui_out_field_int (uiout, "number", b->number); | |
6349 | } | |
c4093a6a JM |
6350 | |
6351 | /* 2 */ | |
6352 | annotate_field (1); | |
0d381245 VP |
6353 | if (part_of_multiple) |
6354 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
6355 | else |
6356 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
6357 | |
6358 | /* 3 */ | |
6359 | annotate_field (2); | |
0d381245 VP |
6360 | if (part_of_multiple) |
6361 | ui_out_field_skip (uiout, "disp"); | |
6362 | else | |
2cec12e5 | 6363 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 6364 | |
c4093a6a JM |
6365 | |
6366 | /* 4 */ | |
6367 | annotate_field (3); | |
0d381245 | 6368 | if (part_of_multiple) |
54e52265 | 6369 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 6370 | else |
4a64f543 MS |
6371 | ui_out_field_fmt (uiout, "enabled", "%c", |
6372 | bpenables[(int) b->enable_state]); | |
54e52265 | 6373 | ui_out_spaces (uiout, 2); |
0d381245 | 6374 | |
c4093a6a JM |
6375 | |
6376 | /* 5 and 6 */ | |
3086aeae | 6377 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 6378 | { |
4a64f543 MS |
6379 | /* Although the print_one can possibly print all locations, |
6380 | calling it here is not likely to get any nice result. So, | |
6381 | make sure there's just one location. */ | |
0d381245 | 6382 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 6383 | b->ops->print_one (b, last_loc); |
0d381245 | 6384 | } |
3086aeae DJ |
6385 | else |
6386 | switch (b->type) | |
6387 | { | |
6388 | case bp_none: | |
6389 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 6390 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 6391 | break; |
c906108c | 6392 | |
3086aeae DJ |
6393 | case bp_watchpoint: |
6394 | case bp_hardware_watchpoint: | |
6395 | case bp_read_watchpoint: | |
6396 | case bp_access_watchpoint: | |
3a5c3e22 PA |
6397 | { |
6398 | struct watchpoint *w = (struct watchpoint *) b; | |
6399 | ||
6400 | /* Field 4, the address, is omitted (which makes the columns | |
6401 | not line up too nicely with the headers, but the effect | |
6402 | is relatively readable). */ | |
6403 | if (opts.addressprint) | |
6404 | ui_out_field_skip (uiout, "addr"); | |
6405 | annotate_field (5); | |
6406 | ui_out_field_string (uiout, "what", w->exp_string); | |
6407 | } | |
3086aeae DJ |
6408 | break; |
6409 | ||
3086aeae DJ |
6410 | case bp_breakpoint: |
6411 | case bp_hardware_breakpoint: | |
7c16b83e | 6412 | case bp_single_step: |
3086aeae DJ |
6413 | case bp_until: |
6414 | case bp_finish: | |
6415 | case bp_longjmp: | |
6416 | case bp_longjmp_resume: | |
e2e4d78b | 6417 | case bp_longjmp_call_dummy: |
186c406b TT |
6418 | case bp_exception: |
6419 | case bp_exception_resume: | |
3086aeae | 6420 | case bp_step_resume: |
2c03e5be | 6421 | case bp_hp_step_resume: |
3086aeae DJ |
6422 | case bp_watchpoint_scope: |
6423 | case bp_call_dummy: | |
aa7d318d | 6424 | case bp_std_terminate: |
3086aeae DJ |
6425 | case bp_shlib_event: |
6426 | case bp_thread_event: | |
6427 | case bp_overlay_event: | |
0fd8e87f | 6428 | case bp_longjmp_master: |
aa7d318d | 6429 | case bp_std_terminate_master: |
186c406b | 6430 | case bp_exception_master: |
1042e4c0 | 6431 | case bp_tracepoint: |
7a697b8d | 6432 | case bp_fast_tracepoint: |
0fb4aa4b | 6433 | case bp_static_tracepoint: |
e7e0cddf | 6434 | case bp_dprintf: |
4efc6507 | 6435 | case bp_jit_event: |
0e30163f JK |
6436 | case bp_gnu_ifunc_resolver: |
6437 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 6438 | if (opts.addressprint) |
3086aeae DJ |
6439 | { |
6440 | annotate_field (4); | |
54e52265 | 6441 | if (header_of_multiple) |
0d381245 | 6442 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 6443 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 6444 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 6445 | else |
5af949e3 UW |
6446 | ui_out_field_core_addr (uiout, "addr", |
6447 | loc->gdbarch, loc->address); | |
3086aeae DJ |
6448 | } |
6449 | annotate_field (5); | |
0d381245 | 6450 | if (!header_of_multiple) |
170b53b2 | 6451 | print_breakpoint_location (b, loc); |
0d381245 | 6452 | if (b->loc) |
a6d9a66e | 6453 | *last_loc = b->loc; |
3086aeae DJ |
6454 | break; |
6455 | } | |
c906108c | 6456 | |
6c95b8df | 6457 | |
998580f1 | 6458 | if (loc != NULL && !header_of_multiple) |
6c95b8df PA |
6459 | { |
6460 | struct inferior *inf; | |
998580f1 MK |
6461 | VEC(int) *inf_num = NULL; |
6462 | int mi_only = 1; | |
6c95b8df | 6463 | |
998580f1 | 6464 | ALL_INFERIORS (inf) |
6c95b8df PA |
6465 | { |
6466 | if (inf->pspace == loc->pspace) | |
998580f1 | 6467 | VEC_safe_push (int, inf_num, inf->num); |
6c95b8df | 6468 | } |
998580f1 MK |
6469 | |
6470 | /* For backward compatibility, don't display inferiors in CLI unless | |
6471 | there are several. Always display for MI. */ | |
6472 | if (allflag | |
6473 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) | |
6474 | && (number_of_program_spaces () > 1 | |
6475 | || number_of_inferiors () > 1) | |
6476 | /* LOC is for existing B, it cannot be in | |
6477 | moribund_locations and thus having NULL OWNER. */ | |
6478 | && loc->owner->type != bp_catchpoint)) | |
6479 | mi_only = 0; | |
6480 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); | |
6481 | VEC_free (int, inf_num); | |
6c95b8df PA |
6482 | } |
6483 | ||
4a306c9a | 6484 | if (!part_of_multiple) |
c4093a6a | 6485 | { |
4a306c9a JB |
6486 | if (b->thread != -1) |
6487 | { | |
6488 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 6489 | "stop only in" line a little further down. */ |
4a306c9a JB |
6490 | ui_out_text (uiout, " thread "); |
6491 | ui_out_field_int (uiout, "thread", b->thread); | |
6492 | } | |
6493 | else if (b->task != 0) | |
6494 | { | |
6495 | ui_out_text (uiout, " task "); | |
6496 | ui_out_field_int (uiout, "task", b->task); | |
6497 | } | |
c4093a6a | 6498 | } |
f1310107 | 6499 | |
8b93c638 | 6500 | ui_out_text (uiout, "\n"); |
f1310107 | 6501 | |
348d480f | 6502 | if (!part_of_multiple) |
f1310107 TJB |
6503 | b->ops->print_one_detail (b, uiout); |
6504 | ||
0d381245 | 6505 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
6506 | { |
6507 | annotate_field (6); | |
8b93c638 | 6508 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 6509 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 6510 | the frame ID. */ |
5af949e3 UW |
6511 | ui_out_field_core_addr (uiout, "frame", |
6512 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 6513 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6514 | } |
6515 | ||
28010a5d | 6516 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
6517 | { |
6518 | annotate_field (7); | |
d77f58be | 6519 | if (is_tracepoint (b)) |
1042e4c0 SS |
6520 | ui_out_text (uiout, "\ttrace only if "); |
6521 | else | |
6522 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 | 6523 | ui_out_field_string (uiout, "cond", b->cond_string); |
b775012e LM |
6524 | |
6525 | /* Print whether the target is doing the breakpoint's condition | |
6526 | evaluation. If GDB is doing the evaluation, don't print anything. */ | |
6527 | if (is_breakpoint (b) | |
6528 | && breakpoint_condition_evaluation_mode () | |
6529 | == condition_evaluation_target) | |
6530 | { | |
6531 | ui_out_text (uiout, " ("); | |
6532 | ui_out_field_string (uiout, "evaluated-by", | |
6533 | bp_condition_evaluator (b)); | |
6534 | ui_out_text (uiout, " evals)"); | |
6535 | } | |
0101ce28 JJ |
6536 | ui_out_text (uiout, "\n"); |
6537 | } | |
6538 | ||
0d381245 | 6539 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 6540 | { |
4a64f543 | 6541 | /* FIXME should make an annotation for this. */ |
8b93c638 | 6542 | ui_out_text (uiout, "\tstop only in thread "); |
5d5658a1 PA |
6543 | if (ui_out_is_mi_like_p (uiout)) |
6544 | ui_out_field_int (uiout, "thread", b->thread); | |
6545 | else | |
6546 | { | |
6547 | struct thread_info *thr = find_thread_global_id (b->thread); | |
6548 | ||
6549 | ui_out_field_string (uiout, "thread", print_thread_id (thr)); | |
6550 | } | |
8b93c638 | 6551 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
6552 | } |
6553 | ||
556ec64d YQ |
6554 | if (!part_of_multiple) |
6555 | { | |
6556 | if (b->hit_count) | |
31f56a27 YQ |
6557 | { |
6558 | /* FIXME should make an annotation for this. */ | |
6559 | if (is_catchpoint (b)) | |
6560 | ui_out_text (uiout, "\tcatchpoint"); | |
6561 | else if (is_tracepoint (b)) | |
6562 | ui_out_text (uiout, "\ttracepoint"); | |
6563 | else | |
6564 | ui_out_text (uiout, "\tbreakpoint"); | |
6565 | ui_out_text (uiout, " already hit "); | |
6566 | ui_out_field_int (uiout, "times", b->hit_count); | |
6567 | if (b->hit_count == 1) | |
6568 | ui_out_text (uiout, " time\n"); | |
6569 | else | |
6570 | ui_out_text (uiout, " times\n"); | |
6571 | } | |
556ec64d YQ |
6572 | else |
6573 | { | |
31f56a27 YQ |
6574 | /* Output the count also if it is zero, but only if this is mi. */ |
6575 | if (ui_out_is_mi_like_p (uiout)) | |
6576 | ui_out_field_int (uiout, "times", b->hit_count); | |
556ec64d YQ |
6577 | } |
6578 | } | |
8b93c638 | 6579 | |
0d381245 | 6580 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
6581 | { |
6582 | annotate_field (8); | |
8b93c638 JM |
6583 | ui_out_text (uiout, "\tignore next "); |
6584 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
6585 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 6586 | } |
059fb39f | 6587 | |
816338b5 SS |
6588 | /* Note that an enable count of 1 corresponds to "enable once" |
6589 | behavior, which is reported by the combination of enablement and | |
6590 | disposition, so we don't need to mention it here. */ | |
6591 | if (!part_of_multiple && b->enable_count > 1) | |
6592 | { | |
6593 | annotate_field (8); | |
6594 | ui_out_text (uiout, "\tdisable after "); | |
6595 | /* Tweak the wording to clarify that ignore and enable counts | |
6596 | are distinct, and have additive effect. */ | |
6597 | if (b->ignore_count) | |
6598 | ui_out_text (uiout, "additional "); | |
6599 | else | |
6600 | ui_out_text (uiout, "next "); | |
6601 | ui_out_field_int (uiout, "enable", b->enable_count); | |
6602 | ui_out_text (uiout, " hits\n"); | |
6603 | } | |
6604 | ||
f196051f SS |
6605 | if (!part_of_multiple && is_tracepoint (b)) |
6606 | { | |
6607 | struct tracepoint *tp = (struct tracepoint *) b; | |
6608 | ||
6609 | if (tp->traceframe_usage) | |
6610 | { | |
6611 | ui_out_text (uiout, "\ttrace buffer usage "); | |
6612 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); | |
6613 | ui_out_text (uiout, " bytes\n"); | |
6614 | } | |
6615 | } | |
d3ce09f5 | 6616 | |
9add0f1b | 6617 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 6618 | if (!part_of_multiple && l) |
c4093a6a | 6619 | { |
3b31d625 EZ |
6620 | struct cleanup *script_chain; |
6621 | ||
c4093a6a | 6622 | annotate_field (9); |
3b31d625 | 6623 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 6624 | print_command_lines (uiout, l, 4); |
3b31d625 | 6625 | do_cleanups (script_chain); |
c4093a6a | 6626 | } |
d24317b4 | 6627 | |
d9b3f62e | 6628 | if (is_tracepoint (b)) |
1042e4c0 | 6629 | { |
d9b3f62e PA |
6630 | struct tracepoint *t = (struct tracepoint *) b; |
6631 | ||
6632 | if (!part_of_multiple && t->pass_count) | |
6633 | { | |
6634 | annotate_field (10); | |
6635 | ui_out_text (uiout, "\tpass count "); | |
6636 | ui_out_field_int (uiout, "pass", t->pass_count); | |
6637 | ui_out_text (uiout, " \n"); | |
6638 | } | |
f2a8bc8a YQ |
6639 | |
6640 | /* Don't display it when tracepoint or tracepoint location is | |
6641 | pending. */ | |
6642 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) | |
6643 | { | |
6644 | annotate_field (11); | |
6645 | ||
6646 | if (ui_out_is_mi_like_p (uiout)) | |
6647 | ui_out_field_string (uiout, "installed", | |
6648 | loc->inserted ? "y" : "n"); | |
6649 | else | |
6650 | { | |
6651 | if (loc->inserted) | |
6652 | ui_out_text (uiout, "\t"); | |
6653 | else | |
6654 | ui_out_text (uiout, "\tnot "); | |
6655 | ui_out_text (uiout, "installed on target\n"); | |
6656 | } | |
6657 | } | |
1042e4c0 SS |
6658 | } |
6659 | ||
d24317b4 VP |
6660 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
6661 | { | |
3a5c3e22 PA |
6662 | if (is_watchpoint (b)) |
6663 | { | |
6664 | struct watchpoint *w = (struct watchpoint *) b; | |
6665 | ||
6666 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
6667 | } | |
f00aae0f KS |
6668 | else if (b->location != NULL |
6669 | && event_location_to_string (b->location) != NULL) | |
6670 | ui_out_field_string (uiout, "original-location", | |
6671 | event_location_to_string (b->location)); | |
d24317b4 | 6672 | } |
c4093a6a | 6673 | } |
c5aa993b | 6674 | |
0d381245 VP |
6675 | static void |
6676 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 6677 | struct bp_location **last_loc, |
6c95b8df | 6678 | int allflag) |
0d381245 | 6679 | { |
8d3788bd | 6680 | struct cleanup *bkpt_chain; |
79a45e25 | 6681 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
6682 | |
6683 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
6684 | ||
12c5a436 | 6685 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 6686 | do_cleanups (bkpt_chain); |
0d381245 VP |
6687 | |
6688 | /* If this breakpoint has custom print function, | |
6689 | it's already printed. Otherwise, print individual | |
6690 | locations, if any. */ | |
6691 | if (b->ops == NULL || b->ops->print_one == NULL) | |
6692 | { | |
4a64f543 MS |
6693 | /* If breakpoint has a single location that is disabled, we |
6694 | print it as if it had several locations, since otherwise it's | |
6695 | hard to represent "breakpoint enabled, location disabled" | |
6696 | situation. | |
6697 | ||
6698 | Note that while hardware watchpoints have several locations | |
a3be7890 | 6699 | internally, that's not a property exposed to user. */ |
0d381245 | 6700 | if (b->loc |
a5606eee | 6701 | && !is_hardware_watchpoint (b) |
8d3788bd | 6702 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
6703 | { |
6704 | struct bp_location *loc; | |
6705 | int n = 1; | |
8d3788bd | 6706 | |
0d381245 | 6707 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
6708 | { |
6709 | struct cleanup *inner2 = | |
6710 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
6711 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
6712 | do_cleanups (inner2); | |
6713 | } | |
0d381245 VP |
6714 | } |
6715 | } | |
6716 | } | |
6717 | ||
a6d9a66e UW |
6718 | static int |
6719 | breakpoint_address_bits (struct breakpoint *b) | |
6720 | { | |
6721 | int print_address_bits = 0; | |
6722 | struct bp_location *loc; | |
6723 | ||
c6d81124 PA |
6724 | /* Software watchpoints that aren't watching memory don't have an |
6725 | address to print. */ | |
6726 | if (is_no_memory_software_watchpoint (b)) | |
6727 | return 0; | |
6728 | ||
a6d9a66e UW |
6729 | for (loc = b->loc; loc; loc = loc->next) |
6730 | { | |
c7437ca6 PA |
6731 | int addr_bit; |
6732 | ||
c7437ca6 | 6733 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
6734 | if (addr_bit > print_address_bits) |
6735 | print_address_bits = addr_bit; | |
6736 | } | |
6737 | ||
6738 | return print_address_bits; | |
6739 | } | |
0d381245 | 6740 | |
c4093a6a JM |
6741 | struct captured_breakpoint_query_args |
6742 | { | |
6743 | int bnum; | |
6744 | }; | |
c5aa993b | 6745 | |
c4093a6a | 6746 | static int |
2b65245e | 6747 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a | 6748 | { |
9a3c8263 SM |
6749 | struct captured_breakpoint_query_args *args |
6750 | = (struct captured_breakpoint_query_args *) data; | |
52f0bd74 | 6751 | struct breakpoint *b; |
a6d9a66e | 6752 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 6753 | |
c4093a6a JM |
6754 | ALL_BREAKPOINTS (b) |
6755 | { | |
6756 | if (args->bnum == b->number) | |
c5aa993b | 6757 | { |
12c5a436 | 6758 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 6759 | return GDB_RC_OK; |
c5aa993b | 6760 | } |
c4093a6a JM |
6761 | } |
6762 | return GDB_RC_NONE; | |
6763 | } | |
c5aa993b | 6764 | |
c4093a6a | 6765 | enum gdb_rc |
4a64f543 MS |
6766 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
6767 | char **error_message) | |
c4093a6a JM |
6768 | { |
6769 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 6770 | |
c4093a6a JM |
6771 | args.bnum = bnum; |
6772 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 6773 | an error. */ |
b0b13bb4 DJ |
6774 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
6775 | error_message, RETURN_MASK_ALL) < 0) | |
6776 | return GDB_RC_FAIL; | |
6777 | else | |
6778 | return GDB_RC_OK; | |
c4093a6a | 6779 | } |
c5aa993b | 6780 | |
09d682a4 TT |
6781 | /* Return true if this breakpoint was set by the user, false if it is |
6782 | internal or momentary. */ | |
6783 | ||
6784 | int | |
6785 | user_breakpoint_p (struct breakpoint *b) | |
6786 | { | |
46c6471b | 6787 | return b->number > 0; |
09d682a4 TT |
6788 | } |
6789 | ||
7f3b0473 | 6790 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
6791 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
6792 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
6793 | FILTER is non-NULL, call it on each breakpoint and only include the | |
6794 | ones for which it returns non-zero. Return the total number of | |
6795 | breakpoints listed. */ | |
c906108c | 6796 | |
d77f58be | 6797 | static int |
e5a67952 | 6798 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 6799 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 6800 | { |
52f0bd74 | 6801 | struct breakpoint *b; |
a6d9a66e | 6802 | struct bp_location *last_loc = NULL; |
7f3b0473 | 6803 | int nr_printable_breakpoints; |
3b31d625 | 6804 | struct cleanup *bkpttbl_chain; |
79a45b7d | 6805 | struct value_print_options opts; |
a6d9a66e | 6806 | int print_address_bits = 0; |
269b11a2 | 6807 | int print_type_col_width = 14; |
79a45e25 | 6808 | struct ui_out *uiout = current_uiout; |
269b11a2 | 6809 | |
79a45b7d TT |
6810 | get_user_print_options (&opts); |
6811 | ||
4a64f543 MS |
6812 | /* Compute the number of rows in the table, as well as the size |
6813 | required for address fields. */ | |
7f3b0473 AC |
6814 | nr_printable_breakpoints = 0; |
6815 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
6816 | { |
6817 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6818 | if (filter && !filter (b)) | |
6819 | continue; | |
6820 | ||
6821 | /* If we have an "args" string, it is a list of breakpoints to | |
6822 | accept. Skip the others. */ | |
6823 | if (args != NULL && *args != '\0') | |
6824 | { | |
6825 | if (allflag && parse_and_eval_long (args) != b->number) | |
6826 | continue; | |
6827 | if (!allflag && !number_is_in_list (args, b->number)) | |
6828 | continue; | |
6829 | } | |
269b11a2 | 6830 | |
e5a67952 MS |
6831 | if (allflag || user_breakpoint_p (b)) |
6832 | { | |
6833 | int addr_bit, type_len; | |
a6d9a66e | 6834 | |
e5a67952 MS |
6835 | addr_bit = breakpoint_address_bits (b); |
6836 | if (addr_bit > print_address_bits) | |
6837 | print_address_bits = addr_bit; | |
269b11a2 | 6838 | |
e5a67952 MS |
6839 | type_len = strlen (bptype_string (b->type)); |
6840 | if (type_len > print_type_col_width) | |
6841 | print_type_col_width = type_len; | |
6842 | ||
6843 | nr_printable_breakpoints++; | |
6844 | } | |
6845 | } | |
7f3b0473 | 6846 | |
79a45b7d | 6847 | if (opts.addressprint) |
3b31d625 | 6848 | bkpttbl_chain |
3e43a32a MS |
6849 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
6850 | nr_printable_breakpoints, | |
3b31d625 | 6851 | "BreakpointTable"); |
8b93c638 | 6852 | else |
3b31d625 | 6853 | bkpttbl_chain |
3e43a32a MS |
6854 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
6855 | nr_printable_breakpoints, | |
3b31d625 | 6856 | "BreakpointTable"); |
8b93c638 | 6857 | |
7f3b0473 | 6858 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
6859 | annotate_breakpoints_headers (); |
6860 | if (nr_printable_breakpoints > 0) | |
6861 | annotate_field (0); | |
4a64f543 | 6862 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
6863 | if (nr_printable_breakpoints > 0) |
6864 | annotate_field (1); | |
269b11a2 | 6865 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 6866 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
6867 | if (nr_printable_breakpoints > 0) |
6868 | annotate_field (2); | |
4a64f543 | 6869 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
6870 | if (nr_printable_breakpoints > 0) |
6871 | annotate_field (3); | |
54e52265 | 6872 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 6873 | if (opts.addressprint) |
e5a67952 MS |
6874 | { |
6875 | if (nr_printable_breakpoints > 0) | |
6876 | annotate_field (4); | |
6877 | if (print_address_bits <= 32) | |
6878 | ui_out_table_header (uiout, 10, ui_left, | |
6879 | "addr", "Address"); /* 5 */ | |
6880 | else | |
6881 | ui_out_table_header (uiout, 18, ui_left, | |
6882 | "addr", "Address"); /* 5 */ | |
6883 | } | |
d7faa9e7 AC |
6884 | if (nr_printable_breakpoints > 0) |
6885 | annotate_field (5); | |
6886 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
6887 | ui_out_table_body (uiout); | |
6888 | if (nr_printable_breakpoints > 0) | |
6889 | annotate_breakpoints_table (); | |
7f3b0473 | 6890 | |
c4093a6a | 6891 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
6892 | { |
6893 | QUIT; | |
6894 | /* If we have a filter, only list the breakpoints it accepts. */ | |
6895 | if (filter && !filter (b)) | |
6896 | continue; | |
6897 | ||
6898 | /* If we have an "args" string, it is a list of breakpoints to | |
6899 | accept. Skip the others. */ | |
6900 | ||
6901 | if (args != NULL && *args != '\0') | |
6902 | { | |
6903 | if (allflag) /* maintenance info breakpoint */ | |
6904 | { | |
6905 | if (parse_and_eval_long (args) != b->number) | |
6906 | continue; | |
6907 | } | |
6908 | else /* all others */ | |
6909 | { | |
6910 | if (!number_is_in_list (args, b->number)) | |
6911 | continue; | |
6912 | } | |
6913 | } | |
6914 | /* We only print out user settable breakpoints unless the | |
6915 | allflag is set. */ | |
6916 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 6917 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
6918 | } |
6919 | ||
3b31d625 | 6920 | do_cleanups (bkpttbl_chain); |
698384cd | 6921 | |
7f3b0473 | 6922 | if (nr_printable_breakpoints == 0) |
c906108c | 6923 | { |
4a64f543 MS |
6924 | /* If there's a filter, let the caller decide how to report |
6925 | empty list. */ | |
d77f58be SS |
6926 | if (!filter) |
6927 | { | |
e5a67952 | 6928 | if (args == NULL || *args == '\0') |
d77f58be SS |
6929 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
6930 | else | |
4a64f543 | 6931 | ui_out_message (uiout, 0, |
e5a67952 MS |
6932 | "No breakpoint or watchpoint matching '%s'.\n", |
6933 | args); | |
d77f58be | 6934 | } |
c906108c SS |
6935 | } |
6936 | else | |
c4093a6a | 6937 | { |
a6d9a66e UW |
6938 | if (last_loc && !server_command) |
6939 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 6940 | } |
c906108c | 6941 | |
4a64f543 | 6942 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 6943 | there have been breakpoints? */ |
c906108c | 6944 | annotate_breakpoints_table_end (); |
d77f58be SS |
6945 | |
6946 | return nr_printable_breakpoints; | |
c906108c SS |
6947 | } |
6948 | ||
ad443146 SS |
6949 | /* Display the value of default-collect in a way that is generally |
6950 | compatible with the breakpoint list. */ | |
6951 | ||
6952 | static void | |
6953 | default_collect_info (void) | |
6954 | { | |
79a45e25 PA |
6955 | struct ui_out *uiout = current_uiout; |
6956 | ||
ad443146 SS |
6957 | /* If it has no value (which is frequently the case), say nothing; a |
6958 | message like "No default-collect." gets in user's face when it's | |
6959 | not wanted. */ | |
6960 | if (!*default_collect) | |
6961 | return; | |
6962 | ||
6963 | /* The following phrase lines up nicely with per-tracepoint collect | |
6964 | actions. */ | |
6965 | ui_out_text (uiout, "default collect "); | |
6966 | ui_out_field_string (uiout, "default-collect", default_collect); | |
6967 | ui_out_text (uiout, " \n"); | |
6968 | } | |
6969 | ||
c906108c | 6970 | static void |
e5a67952 | 6971 | breakpoints_info (char *args, int from_tty) |
c906108c | 6972 | { |
e5a67952 | 6973 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
6974 | |
6975 | default_collect_info (); | |
d77f58be SS |
6976 | } |
6977 | ||
6978 | static void | |
e5a67952 | 6979 | watchpoints_info (char *args, int from_tty) |
d77f58be | 6980 | { |
e5a67952 | 6981 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 6982 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
6983 | |
6984 | if (num_printed == 0) | |
6985 | { | |
e5a67952 | 6986 | if (args == NULL || *args == '\0') |
d77f58be SS |
6987 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
6988 | else | |
e5a67952 | 6989 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 6990 | } |
c906108c SS |
6991 | } |
6992 | ||
7a292a7a | 6993 | static void |
e5a67952 | 6994 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 6995 | { |
e5a67952 | 6996 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
6997 | |
6998 | default_collect_info (); | |
c906108c SS |
6999 | } |
7000 | ||
0d381245 | 7001 | static int |
714835d5 | 7002 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 7003 | struct program_space *pspace, |
714835d5 | 7004 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
7005 | { |
7006 | struct bp_location *bl = b->loc; | |
cc59ec59 | 7007 | |
0d381245 VP |
7008 | for (; bl; bl = bl->next) |
7009 | { | |
6c95b8df PA |
7010 | if (bl->pspace == pspace |
7011 | && bl->address == pc | |
0d381245 VP |
7012 | && (!overlay_debugging || bl->section == section)) |
7013 | return 1; | |
7014 | } | |
7015 | return 0; | |
7016 | } | |
7017 | ||
672f9b60 | 7018 | /* Print a message describing any user-breakpoints set at PC. This |
6c95b8df PA |
7019 | concerns with logical breakpoints, so we match program spaces, not |
7020 | address spaces. */ | |
c906108c SS |
7021 | |
7022 | static void | |
6c95b8df PA |
7023 | describe_other_breakpoints (struct gdbarch *gdbarch, |
7024 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 7025 | struct obj_section *section, int thread) |
c906108c | 7026 | { |
52f0bd74 AC |
7027 | int others = 0; |
7028 | struct breakpoint *b; | |
c906108c SS |
7029 | |
7030 | ALL_BREAKPOINTS (b) | |
672f9b60 KP |
7031 | others += (user_breakpoint_p (b) |
7032 | && breakpoint_has_pc (b, pspace, pc, section)); | |
c906108c SS |
7033 | if (others > 0) |
7034 | { | |
a3f17187 AC |
7035 | if (others == 1) |
7036 | printf_filtered (_("Note: breakpoint ")); | |
7037 | else /* if (others == ???) */ | |
7038 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 7039 | ALL_BREAKPOINTS (b) |
672f9b60 | 7040 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
7041 | { |
7042 | others--; | |
7043 | printf_filtered ("%d", b->number); | |
7044 | if (b->thread == -1 && thread != -1) | |
7045 | printf_filtered (" (all threads)"); | |
7046 | else if (b->thread != -1) | |
7047 | printf_filtered (" (thread %d)", b->thread); | |
7048 | printf_filtered ("%s%s ", | |
059fb39f | 7049 | ((b->enable_state == bp_disabled |
f8eba3c6 | 7050 | || b->enable_state == bp_call_disabled) |
0d381245 | 7051 | ? " (disabled)" |
0d381245 VP |
7052 | : ""), |
7053 | (others > 1) ? "," | |
7054 | : ((others == 1) ? " and" : "")); | |
7055 | } | |
a3f17187 | 7056 | printf_filtered (_("also set at pc ")); |
5af949e3 | 7057 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
7058 | printf_filtered (".\n"); |
7059 | } | |
7060 | } | |
7061 | \f | |
c906108c | 7062 | |
e4f237da | 7063 | /* Return true iff it is meaningful to use the address member of |
244558af LM |
7064 | BPT locations. For some breakpoint types, the locations' address members |
7065 | are irrelevant and it makes no sense to attempt to compare them to other | |
7066 | addresses (or use them for any other purpose either). | |
e4f237da | 7067 | |
4a64f543 | 7068 | More specifically, each of the following breakpoint types will |
244558af | 7069 | always have a zero valued location address and we don't want to mark |
4a64f543 | 7070 | breakpoints of any of these types to be a duplicate of an actual |
244558af | 7071 | breakpoint location at address zero: |
e4f237da KB |
7072 | |
7073 | bp_watchpoint | |
2d134ed3 PA |
7074 | bp_catchpoint |
7075 | ||
7076 | */ | |
e4f237da KB |
7077 | |
7078 | static int | |
7079 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
7080 | { | |
7081 | enum bptype type = bpt->type; | |
7082 | ||
2d134ed3 PA |
7083 | return (type != bp_watchpoint && type != bp_catchpoint); |
7084 | } | |
7085 | ||
7086 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
7087 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
7088 | ||
7089 | static int | |
4a64f543 MS |
7090 | watchpoint_locations_match (struct bp_location *loc1, |
7091 | struct bp_location *loc2) | |
2d134ed3 | 7092 | { |
3a5c3e22 PA |
7093 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
7094 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
7095 | ||
7096 | /* Both of them must exist. */ | |
7097 | gdb_assert (w1 != NULL); | |
7098 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 7099 | |
4a64f543 MS |
7100 | /* If the target can evaluate the condition expression in hardware, |
7101 | then we we need to insert both watchpoints even if they are at | |
7102 | the same place. Otherwise the watchpoint will only trigger when | |
7103 | the condition of whichever watchpoint was inserted evaluates to | |
7104 | true, not giving a chance for GDB to check the condition of the | |
7105 | other watchpoint. */ | |
3a5c3e22 | 7106 | if ((w1->cond_exp |
4a64f543 MS |
7107 | && target_can_accel_watchpoint_condition (loc1->address, |
7108 | loc1->length, | |
0cf6dd15 | 7109 | loc1->watchpoint_type, |
3a5c3e22 PA |
7110 | w1->cond_exp)) |
7111 | || (w2->cond_exp | |
4a64f543 MS |
7112 | && target_can_accel_watchpoint_condition (loc2->address, |
7113 | loc2->length, | |
0cf6dd15 | 7114 | loc2->watchpoint_type, |
3a5c3e22 | 7115 | w2->cond_exp))) |
0cf6dd15 TJB |
7116 | return 0; |
7117 | ||
85d721b8 PA |
7118 | /* Note that this checks the owner's type, not the location's. In |
7119 | case the target does not support read watchpoints, but does | |
7120 | support access watchpoints, we'll have bp_read_watchpoint | |
7121 | watchpoints with hw_access locations. Those should be considered | |
7122 | duplicates of hw_read locations. The hw_read locations will | |
7123 | become hw_access locations later. */ | |
2d134ed3 PA |
7124 | return (loc1->owner->type == loc2->owner->type |
7125 | && loc1->pspace->aspace == loc2->pspace->aspace | |
7126 | && loc1->address == loc2->address | |
7127 | && loc1->length == loc2->length); | |
e4f237da KB |
7128 | } |
7129 | ||
31e77af2 | 7130 | /* See breakpoint.h. */ |
6c95b8df | 7131 | |
31e77af2 | 7132 | int |
6c95b8df PA |
7133 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
7134 | struct address_space *aspace2, CORE_ADDR addr2) | |
7135 | { | |
f5656ead | 7136 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
6c95b8df PA |
7137 | || aspace1 == aspace2) |
7138 | && addr1 == addr2); | |
7139 | } | |
7140 | ||
f1310107 TJB |
7141 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
7142 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
7143 | matches ASPACE2. On targets that have global breakpoints, the address | |
7144 | space doesn't really matter. */ | |
7145 | ||
7146 | static int | |
7147 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
7148 | int len1, struct address_space *aspace2, | |
7149 | CORE_ADDR addr2) | |
7150 | { | |
f5656ead | 7151 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
f1310107 TJB |
7152 | || aspace1 == aspace2) |
7153 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
7154 | } | |
7155 | ||
7156 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
7157 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
7158 | matches the breakpoint's address space. On targets that have global | |
7159 | breakpoints, the address space doesn't really matter. */ | |
7160 | ||
7161 | static int | |
7162 | breakpoint_location_address_match (struct bp_location *bl, | |
7163 | struct address_space *aspace, | |
7164 | CORE_ADDR addr) | |
7165 | { | |
7166 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
7167 | aspace, addr) | |
7168 | || (bl->length | |
7169 | && breakpoint_address_match_range (bl->pspace->aspace, | |
7170 | bl->address, bl->length, | |
7171 | aspace, addr))); | |
7172 | } | |
7173 | ||
d35ae833 PA |
7174 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
7175 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a | |
7176 | match happens only if ASPACE matches the breakpoint's address | |
7177 | space. On targets that have global breakpoints, the address space | |
7178 | doesn't really matter. */ | |
7179 | ||
7180 | static int | |
7181 | breakpoint_location_address_range_overlap (struct bp_location *bl, | |
7182 | struct address_space *aspace, | |
7183 | CORE_ADDR addr, int len) | |
7184 | { | |
7185 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) | |
7186 | || bl->pspace->aspace == aspace) | |
7187 | { | |
7188 | int bl_len = bl->length != 0 ? bl->length : 1; | |
7189 | ||
7190 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) | |
7191 | return 1; | |
7192 | } | |
7193 | return 0; | |
7194 | } | |
7195 | ||
1e4d1764 YQ |
7196 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
7197 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns | |
7198 | true, otherwise returns false. */ | |
7199 | ||
7200 | static int | |
7201 | tracepoint_locations_match (struct bp_location *loc1, | |
7202 | struct bp_location *loc2) | |
7203 | { | |
7204 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) | |
7205 | /* Since tracepoint locations are never duplicated with others', tracepoint | |
7206 | locations at the same address of different tracepoints are regarded as | |
7207 | different locations. */ | |
7208 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); | |
7209 | else | |
7210 | return 0; | |
7211 | } | |
7212 | ||
2d134ed3 PA |
7213 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
7214 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
7215 | represent the same location. */ | |
7216 | ||
7217 | static int | |
4a64f543 MS |
7218 | breakpoint_locations_match (struct bp_location *loc1, |
7219 | struct bp_location *loc2) | |
2d134ed3 | 7220 | { |
2bdf28a0 JK |
7221 | int hw_point1, hw_point2; |
7222 | ||
7223 | /* Both of them must not be in moribund_locations. */ | |
7224 | gdb_assert (loc1->owner != NULL); | |
7225 | gdb_assert (loc2->owner != NULL); | |
7226 | ||
7227 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
7228 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
7229 | |
7230 | if (hw_point1 != hw_point2) | |
7231 | return 0; | |
7232 | else if (hw_point1) | |
7233 | return watchpoint_locations_match (loc1, loc2); | |
1e4d1764 YQ |
7234 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
7235 | return tracepoint_locations_match (loc1, loc2); | |
2d134ed3 | 7236 | else |
f1310107 TJB |
7237 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
7238 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
7239 | loc2->pspace->aspace, loc2->address) | |
7240 | && loc1->length == loc2->length); | |
2d134ed3 PA |
7241 | } |
7242 | ||
76897487 KB |
7243 | static void |
7244 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
7245 | int bnum, int have_bnum) | |
7246 | { | |
f63fbe86 MS |
7247 | /* The longest string possibly returned by hex_string_custom |
7248 | is 50 chars. These must be at least that big for safety. */ | |
7249 | char astr1[64]; | |
7250 | char astr2[64]; | |
76897487 | 7251 | |
bb599908 PH |
7252 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
7253 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 7254 | if (have_bnum) |
8a3fe4f8 | 7255 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
7256 | bnum, astr1, astr2); |
7257 | else | |
8a3fe4f8 | 7258 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
7259 | } |
7260 | ||
4a64f543 MS |
7261 | /* Adjust a breakpoint's address to account for architectural |
7262 | constraints on breakpoint placement. Return the adjusted address. | |
7263 | Note: Very few targets require this kind of adjustment. For most | |
7264 | targets, this function is simply the identity function. */ | |
76897487 KB |
7265 | |
7266 | static CORE_ADDR | |
a6d9a66e UW |
7267 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
7268 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 7269 | { |
a6d9a66e | 7270 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
7271 | { |
7272 | /* Very few targets need any kind of breakpoint adjustment. */ | |
7273 | return bpaddr; | |
7274 | } | |
88f7da05 KB |
7275 | else if (bptype == bp_watchpoint |
7276 | || bptype == bp_hardware_watchpoint | |
7277 | || bptype == bp_read_watchpoint | |
7278 | || bptype == bp_access_watchpoint | |
fe798b75 | 7279 | || bptype == bp_catchpoint) |
88f7da05 KB |
7280 | { |
7281 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
7282 | have their addresses modified. */ | |
7283 | return bpaddr; | |
7284 | } | |
7c16b83e PA |
7285 | else if (bptype == bp_single_step) |
7286 | { | |
7287 | /* Single-step breakpoints should not have their addresses | |
7288 | modified. If there's any architectural constrain that | |
7289 | applies to this address, then it should have already been | |
7290 | taken into account when the breakpoint was created in the | |
7291 | first place. If we didn't do this, stepping through e.g., | |
7292 | Thumb-2 IT blocks would break. */ | |
7293 | return bpaddr; | |
7294 | } | |
76897487 KB |
7295 | else |
7296 | { | |
7297 | CORE_ADDR adjusted_bpaddr; | |
7298 | ||
7299 | /* Some targets have architectural constraints on the placement | |
7300 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 7301 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
7302 | |
7303 | /* An adjusted breakpoint address can significantly alter | |
7304 | a user's expectations. Print a warning if an adjustment | |
7305 | is required. */ | |
7306 | if (adjusted_bpaddr != bpaddr) | |
7307 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
7308 | ||
7309 | return adjusted_bpaddr; | |
7310 | } | |
7311 | } | |
7312 | ||
28010a5d PA |
7313 | void |
7314 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
7315 | struct breakpoint *owner) | |
7cc221ef | 7316 | { |
7cc221ef DJ |
7317 | memset (loc, 0, sizeof (*loc)); |
7318 | ||
348d480f PA |
7319 | gdb_assert (ops != NULL); |
7320 | ||
28010a5d PA |
7321 | loc->ops = ops; |
7322 | loc->owner = owner; | |
511a6cd4 | 7323 | loc->cond = NULL; |
b775012e | 7324 | loc->cond_bytecode = NULL; |
0d381245 VP |
7325 | loc->shlib_disabled = 0; |
7326 | loc->enabled = 1; | |
e049a4b5 | 7327 | |
28010a5d | 7328 | switch (owner->type) |
e049a4b5 DJ |
7329 | { |
7330 | case bp_breakpoint: | |
7c16b83e | 7331 | case bp_single_step: |
e049a4b5 DJ |
7332 | case bp_until: |
7333 | case bp_finish: | |
7334 | case bp_longjmp: | |
7335 | case bp_longjmp_resume: | |
e2e4d78b | 7336 | case bp_longjmp_call_dummy: |
186c406b TT |
7337 | case bp_exception: |
7338 | case bp_exception_resume: | |
e049a4b5 | 7339 | case bp_step_resume: |
2c03e5be | 7340 | case bp_hp_step_resume: |
e049a4b5 DJ |
7341 | case bp_watchpoint_scope: |
7342 | case bp_call_dummy: | |
aa7d318d | 7343 | case bp_std_terminate: |
e049a4b5 DJ |
7344 | case bp_shlib_event: |
7345 | case bp_thread_event: | |
7346 | case bp_overlay_event: | |
4efc6507 | 7347 | case bp_jit_event: |
0fd8e87f | 7348 | case bp_longjmp_master: |
aa7d318d | 7349 | case bp_std_terminate_master: |
186c406b | 7350 | case bp_exception_master: |
0e30163f JK |
7351 | case bp_gnu_ifunc_resolver: |
7352 | case bp_gnu_ifunc_resolver_return: | |
e7e0cddf | 7353 | case bp_dprintf: |
e049a4b5 | 7354 | loc->loc_type = bp_loc_software_breakpoint; |
b775012e | 7355 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7356 | break; |
7357 | case bp_hardware_breakpoint: | |
7358 | loc->loc_type = bp_loc_hardware_breakpoint; | |
b775012e | 7359 | mark_breakpoint_location_modified (loc); |
e049a4b5 DJ |
7360 | break; |
7361 | case bp_hardware_watchpoint: | |
7362 | case bp_read_watchpoint: | |
7363 | case bp_access_watchpoint: | |
7364 | loc->loc_type = bp_loc_hardware_watchpoint; | |
7365 | break; | |
7366 | case bp_watchpoint: | |
ce78b96d | 7367 | case bp_catchpoint: |
15c3d785 PA |
7368 | case bp_tracepoint: |
7369 | case bp_fast_tracepoint: | |
0fb4aa4b | 7370 | case bp_static_tracepoint: |
e049a4b5 DJ |
7371 | loc->loc_type = bp_loc_other; |
7372 | break; | |
7373 | default: | |
e2e0b3e5 | 7374 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
7375 | } |
7376 | ||
f431efe5 | 7377 | loc->refc = 1; |
28010a5d PA |
7378 | } |
7379 | ||
7380 | /* Allocate a struct bp_location. */ | |
7381 | ||
7382 | static struct bp_location * | |
7383 | allocate_bp_location (struct breakpoint *bpt) | |
7384 | { | |
348d480f PA |
7385 | return bpt->ops->allocate_location (bpt); |
7386 | } | |
7cc221ef | 7387 | |
f431efe5 PA |
7388 | static void |
7389 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 7390 | { |
348d480f | 7391 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
7392 | xfree (loc); |
7393 | } | |
7394 | ||
f431efe5 PA |
7395 | /* Increment reference count. */ |
7396 | ||
7397 | static void | |
7398 | incref_bp_location (struct bp_location *bl) | |
7399 | { | |
7400 | ++bl->refc; | |
7401 | } | |
7402 | ||
7403 | /* Decrement reference count. If the reference count reaches 0, | |
7404 | destroy the bp_location. Sets *BLP to NULL. */ | |
7405 | ||
7406 | static void | |
7407 | decref_bp_location (struct bp_location **blp) | |
7408 | { | |
0807b50c PA |
7409 | gdb_assert ((*blp)->refc > 0); |
7410 | ||
f431efe5 PA |
7411 | if (--(*blp)->refc == 0) |
7412 | free_bp_location (*blp); | |
7413 | *blp = NULL; | |
7414 | } | |
7415 | ||
346774a9 | 7416 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 7417 | |
346774a9 PA |
7418 | static void |
7419 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 7420 | { |
346774a9 | 7421 | struct breakpoint *b1; |
c906108c | 7422 | |
346774a9 PA |
7423 | /* Add this breakpoint to the end of the chain so that a list of |
7424 | breakpoints will come out in order of increasing numbers. */ | |
7425 | ||
7426 | b1 = breakpoint_chain; | |
7427 | if (b1 == 0) | |
7428 | breakpoint_chain = b; | |
7429 | else | |
7430 | { | |
7431 | while (b1->next) | |
7432 | b1 = b1->next; | |
7433 | b1->next = b; | |
7434 | } | |
7435 | } | |
7436 | ||
7437 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
7438 | ||
7439 | static void | |
7440 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
7441 | struct gdbarch *gdbarch, | |
28010a5d | 7442 | enum bptype bptype, |
c0a91b2b | 7443 | const struct breakpoint_ops *ops) |
346774a9 | 7444 | { |
c906108c | 7445 | memset (b, 0, sizeof (*b)); |
2219d63c | 7446 | |
348d480f PA |
7447 | gdb_assert (ops != NULL); |
7448 | ||
28010a5d | 7449 | b->ops = ops; |
4d28f7a8 | 7450 | b->type = bptype; |
a6d9a66e | 7451 | b->gdbarch = gdbarch; |
c906108c SS |
7452 | b->language = current_language->la_language; |
7453 | b->input_radix = input_radix; | |
7454 | b->thread = -1; | |
b5de0fa7 | 7455 | b->enable_state = bp_enabled; |
c906108c SS |
7456 | b->next = 0; |
7457 | b->silent = 0; | |
7458 | b->ignore_count = 0; | |
7459 | b->commands = NULL; | |
818dd999 | 7460 | b->frame_id = null_frame_id; |
0d381245 | 7461 | b->condition_not_parsed = 0; |
84f4c1fe | 7462 | b->py_bp_object = NULL; |
d0fb5eae | 7463 | b->related_breakpoint = b; |
f00aae0f | 7464 | b->location = NULL; |
346774a9 PA |
7465 | } |
7466 | ||
7467 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
7468 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
7469 | |
7470 | static struct breakpoint * | |
7471 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 7472 | enum bptype bptype, |
c0a91b2b | 7473 | const struct breakpoint_ops *ops) |
346774a9 PA |
7474 | { |
7475 | struct breakpoint *b = XNEW (struct breakpoint); | |
7476 | ||
348d480f | 7477 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 7478 | add_to_breakpoint_chain (b); |
0d381245 VP |
7479 | return b; |
7480 | } | |
7481 | ||
0e30163f JK |
7482 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
7483 | resolutions should be made as the user specified the location explicitly | |
7484 | enough. */ | |
7485 | ||
0d381245 | 7486 | static void |
0e30163f | 7487 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 7488 | { |
2bdf28a0 JK |
7489 | gdb_assert (loc->owner != NULL); |
7490 | ||
0d381245 | 7491 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 7492 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 7493 | || is_tracepoint (loc->owner)) |
0d381245 | 7494 | { |
0e30163f | 7495 | int is_gnu_ifunc; |
2c02bd72 | 7496 | const char *function_name; |
6a3a010b | 7497 | CORE_ADDR func_addr; |
0e30163f | 7498 | |
2c02bd72 | 7499 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
6a3a010b | 7500 | &func_addr, NULL, &is_gnu_ifunc); |
0e30163f JK |
7501 | |
7502 | if (is_gnu_ifunc && !explicit_loc) | |
7503 | { | |
7504 | struct breakpoint *b = loc->owner; | |
7505 | ||
7506 | gdb_assert (loc->pspace == current_program_space); | |
2c02bd72 | 7507 | if (gnu_ifunc_resolve_name (function_name, |
0e30163f JK |
7508 | &loc->requested_address)) |
7509 | { | |
7510 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
7511 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
7512 | loc->requested_address, | |
7513 | b->type); | |
7514 | } | |
7515 | else if (b->type == bp_breakpoint && b->loc == loc | |
7516 | && loc->next == NULL && b->related_breakpoint == b) | |
7517 | { | |
7518 | /* Create only the whole new breakpoint of this type but do not | |
7519 | mess more complicated breakpoints with multiple locations. */ | |
7520 | b->type = bp_gnu_ifunc_resolver; | |
6a3a010b MR |
7521 | /* Remember the resolver's address for use by the return |
7522 | breakpoint. */ | |
7523 | loc->related_address = func_addr; | |
0e30163f JK |
7524 | } |
7525 | } | |
7526 | ||
2c02bd72 DE |
7527 | if (function_name) |
7528 | loc->function_name = xstrdup (function_name); | |
0d381245 VP |
7529 | } |
7530 | } | |
7531 | ||
a6d9a66e | 7532 | /* Attempt to determine architecture of location identified by SAL. */ |
1bfeeb0f | 7533 | struct gdbarch * |
a6d9a66e UW |
7534 | get_sal_arch (struct symtab_and_line sal) |
7535 | { | |
7536 | if (sal.section) | |
7537 | return get_objfile_arch (sal.section->objfile); | |
7538 | if (sal.symtab) | |
eb822aa6 | 7539 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
a6d9a66e UW |
7540 | |
7541 | return NULL; | |
7542 | } | |
7543 | ||
346774a9 PA |
7544 | /* Low level routine for partially initializing a breakpoint of type |
7545 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 7546 | file name, and line number are provided by SAL. |
0d381245 VP |
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 | |
c56053d2 | 7550 | information regarding the creation of a new breakpoint. */ |
0d381245 | 7551 | |
346774a9 PA |
7552 | static void |
7553 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 7554 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7555 | const struct breakpoint_ops *ops) |
0d381245 | 7556 | { |
28010a5d | 7557 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 7558 | |
3742cc8b | 7559 | add_location_to_breakpoint (b, &sal); |
0d381245 | 7560 | |
6c95b8df PA |
7561 | if (bptype != bp_catchpoint) |
7562 | gdb_assert (sal.pspace != NULL); | |
7563 | ||
f8eba3c6 TT |
7564 | /* Store the program space that was used to set the breakpoint, |
7565 | except for ordinary breakpoints, which are independent of the | |
7566 | program space. */ | |
7567 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) | |
7568 | b->pspace = sal.pspace; | |
346774a9 | 7569 | } |
c906108c | 7570 | |
346774a9 PA |
7571 | /* set_raw_breakpoint is a low level routine for allocating and |
7572 | partially initializing a breakpoint of type BPTYPE. The newly | |
7573 | created breakpoint's address, section, source file name, and line | |
7574 | number are provided by SAL. The newly created and partially | |
7575 | initialized breakpoint is added to the breakpoint chain and | |
7576 | is also returned as the value of this function. | |
7577 | ||
7578 | It is expected that the caller will complete the initialization of | |
7579 | the newly created breakpoint struct as well as output any status | |
7580 | information regarding the creation of a new breakpoint. In | |
7581 | particular, set_raw_breakpoint does NOT set the breakpoint | |
7582 | number! Care should be taken to not allow an error to occur | |
7583 | prior to completing the initialization of the breakpoint. If this | |
7584 | should happen, a bogus breakpoint will be left on the chain. */ | |
7585 | ||
7586 | struct breakpoint * | |
7587 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 7588 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 7589 | const struct breakpoint_ops *ops) |
346774a9 PA |
7590 | { |
7591 | struct breakpoint *b = XNEW (struct breakpoint); | |
7592 | ||
348d480f | 7593 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 7594 | add_to_breakpoint_chain (b); |
c906108c SS |
7595 | return b; |
7596 | } | |
7597 | ||
53a5351d | 7598 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
7599 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
7600 | initiated the operation. */ | |
c906108c SS |
7601 | |
7602 | void | |
186c406b | 7603 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 7604 | { |
35df4500 | 7605 | struct breakpoint *b, *b_tmp; |
5d5658a1 | 7606 | int thread = tp->global_num; |
0fd8e87f UW |
7607 | |
7608 | /* To avoid having to rescan all objfile symbols at every step, | |
7609 | we maintain a list of continually-inserted but always disabled | |
7610 | longjmp "master" breakpoints. Here, we simply create momentary | |
7611 | clones of those and enable them for the requested thread. */ | |
35df4500 | 7612 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 7613 | if (b->pspace == current_program_space |
186c406b TT |
7614 | && (b->type == bp_longjmp_master |
7615 | || b->type == bp_exception_master)) | |
0fd8e87f | 7616 | { |
06edf0c0 PA |
7617 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
7618 | struct breakpoint *clone; | |
cc59ec59 | 7619 | |
e2e4d78b JK |
7620 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
7621 | after their removal. */ | |
06edf0c0 | 7622 | clone = momentary_breakpoint_from_master (b, type, |
a1aa2221 | 7623 | &longjmp_breakpoint_ops, 1); |
0fd8e87f UW |
7624 | clone->thread = thread; |
7625 | } | |
186c406b TT |
7626 | |
7627 | tp->initiating_frame = frame; | |
c906108c SS |
7628 | } |
7629 | ||
611c83ae | 7630 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 7631 | void |
611c83ae | 7632 | delete_longjmp_breakpoint (int thread) |
c906108c | 7633 | { |
35df4500 | 7634 | struct breakpoint *b, *b_tmp; |
c906108c | 7635 | |
35df4500 | 7636 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 7637 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
7638 | { |
7639 | if (b->thread == thread) | |
7640 | delete_breakpoint (b); | |
7641 | } | |
c906108c SS |
7642 | } |
7643 | ||
f59f708a PA |
7644 | void |
7645 | delete_longjmp_breakpoint_at_next_stop (int thread) | |
7646 | { | |
7647 | struct breakpoint *b, *b_tmp; | |
7648 | ||
7649 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7650 | if (b->type == bp_longjmp || b->type == bp_exception) | |
7651 | { | |
7652 | if (b->thread == thread) | |
7653 | b->disposition = disp_del_at_next_stop; | |
7654 | } | |
7655 | } | |
7656 | ||
e2e4d78b JK |
7657 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
7658 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return | |
7659 | pointer to any of them. Return NULL if this system cannot place longjmp | |
7660 | breakpoints. */ | |
7661 | ||
7662 | struct breakpoint * | |
7663 | set_longjmp_breakpoint_for_call_dummy (void) | |
7664 | { | |
7665 | struct breakpoint *b, *retval = NULL; | |
7666 | ||
7667 | ALL_BREAKPOINTS (b) | |
7668 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) | |
7669 | { | |
7670 | struct breakpoint *new_b; | |
7671 | ||
7672 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, | |
a1aa2221 LM |
7673 | &momentary_breakpoint_ops, |
7674 | 1); | |
5d5658a1 | 7675 | new_b->thread = ptid_to_global_thread_id (inferior_ptid); |
e2e4d78b JK |
7676 | |
7677 | /* Link NEW_B into the chain of RETVAL breakpoints. */ | |
7678 | ||
7679 | gdb_assert (new_b->related_breakpoint == new_b); | |
7680 | if (retval == NULL) | |
7681 | retval = new_b; | |
7682 | new_b->related_breakpoint = retval; | |
7683 | while (retval->related_breakpoint != new_b->related_breakpoint) | |
7684 | retval = retval->related_breakpoint; | |
7685 | retval->related_breakpoint = new_b; | |
7686 | } | |
7687 | ||
7688 | return retval; | |
7689 | } | |
7690 | ||
7691 | /* Verify all existing dummy frames and their associated breakpoints for | |
b67a2c6f | 7692 | TP. Remove those which can no longer be found in the current frame |
e2e4d78b JK |
7693 | stack. |
7694 | ||
7695 | You should call this function only at places where it is safe to currently | |
7696 | unwind the whole stack. Failed stack unwind would discard live dummy | |
7697 | frames. */ | |
7698 | ||
7699 | void | |
b67a2c6f | 7700 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
e2e4d78b JK |
7701 | { |
7702 | struct breakpoint *b, *b_tmp; | |
7703 | ||
7704 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5d5658a1 | 7705 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
e2e4d78b JK |
7706 | { |
7707 | struct breakpoint *dummy_b = b->related_breakpoint; | |
7708 | ||
7709 | while (dummy_b != b && dummy_b->type != bp_call_dummy) | |
7710 | dummy_b = dummy_b->related_breakpoint; | |
7711 | if (dummy_b->type != bp_call_dummy | |
7712 | || frame_find_by_id (dummy_b->frame_id) != NULL) | |
7713 | continue; | |
7714 | ||
b67a2c6f | 7715 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
e2e4d78b JK |
7716 | |
7717 | while (b->related_breakpoint != b) | |
7718 | { | |
7719 | if (b_tmp == b->related_breakpoint) | |
7720 | b_tmp = b->related_breakpoint->next; | |
7721 | delete_breakpoint (b->related_breakpoint); | |
7722 | } | |
7723 | delete_breakpoint (b); | |
7724 | } | |
7725 | } | |
7726 | ||
1900040c MS |
7727 | void |
7728 | enable_overlay_breakpoints (void) | |
7729 | { | |
52f0bd74 | 7730 | struct breakpoint *b; |
1900040c MS |
7731 | |
7732 | ALL_BREAKPOINTS (b) | |
7733 | if (b->type == bp_overlay_event) | |
7734 | { | |
7735 | b->enable_state = bp_enabled; | |
44702360 | 7736 | update_global_location_list (UGLL_MAY_INSERT); |
c02f5703 | 7737 | overlay_events_enabled = 1; |
1900040c MS |
7738 | } |
7739 | } | |
7740 | ||
7741 | void | |
7742 | disable_overlay_breakpoints (void) | |
7743 | { | |
52f0bd74 | 7744 | struct breakpoint *b; |
1900040c MS |
7745 | |
7746 | ALL_BREAKPOINTS (b) | |
7747 | if (b->type == bp_overlay_event) | |
7748 | { | |
7749 | b->enable_state = bp_disabled; | |
44702360 | 7750 | update_global_location_list (UGLL_DONT_INSERT); |
c02f5703 | 7751 | overlay_events_enabled = 0; |
1900040c MS |
7752 | } |
7753 | } | |
7754 | ||
aa7d318d TT |
7755 | /* Set an active std::terminate breakpoint for each std::terminate |
7756 | master breakpoint. */ | |
7757 | void | |
7758 | set_std_terminate_breakpoint (void) | |
7759 | { | |
35df4500 | 7760 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7761 | |
35df4500 | 7762 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7763 | if (b->pspace == current_program_space |
7764 | && b->type == bp_std_terminate_master) | |
7765 | { | |
06edf0c0 | 7766 | momentary_breakpoint_from_master (b, bp_std_terminate, |
a1aa2221 | 7767 | &momentary_breakpoint_ops, 1); |
aa7d318d TT |
7768 | } |
7769 | } | |
7770 | ||
7771 | /* Delete all the std::terminate breakpoints. */ | |
7772 | void | |
7773 | delete_std_terminate_breakpoint (void) | |
7774 | { | |
35df4500 | 7775 | struct breakpoint *b, *b_tmp; |
aa7d318d | 7776 | |
35df4500 | 7777 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
7778 | if (b->type == bp_std_terminate) |
7779 | delete_breakpoint (b); | |
7780 | } | |
7781 | ||
c4093a6a | 7782 | struct breakpoint * |
a6d9a66e | 7783 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
7784 | { |
7785 | struct breakpoint *b; | |
c4093a6a | 7786 | |
06edf0c0 PA |
7787 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
7788 | &internal_breakpoint_ops); | |
7789 | ||
b5de0fa7 | 7790 | b->enable_state = bp_enabled; |
f00aae0f | 7791 | /* location has to be used or breakpoint_re_set will delete me. */ |
305e13e6 | 7792 | b->location = new_address_location (b->loc->address, NULL, 0); |
c4093a6a | 7793 | |
44702360 | 7794 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 7795 | |
c4093a6a JM |
7796 | return b; |
7797 | } | |
7798 | ||
0101ce28 JJ |
7799 | struct lang_and_radix |
7800 | { | |
7801 | enum language lang; | |
7802 | int radix; | |
7803 | }; | |
7804 | ||
4efc6507 DE |
7805 | /* Create a breakpoint for JIT code registration and unregistration. */ |
7806 | ||
7807 | struct breakpoint * | |
7808 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7809 | { | |
7810 | struct breakpoint *b; | |
7811 | ||
06edf0c0 PA |
7812 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
7813 | &internal_breakpoint_ops); | |
44702360 | 7814 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
4efc6507 DE |
7815 | return b; |
7816 | } | |
0101ce28 | 7817 | |
03673fc7 PP |
7818 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
7819 | ||
7820 | void | |
7821 | remove_jit_event_breakpoints (void) | |
7822 | { | |
7823 | struct breakpoint *b, *b_tmp; | |
7824 | ||
7825 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7826 | if (b->type == bp_jit_event | |
7827 | && b->loc->pspace == current_program_space) | |
7828 | delete_breakpoint (b); | |
7829 | } | |
7830 | ||
cae688ec JJ |
7831 | void |
7832 | remove_solib_event_breakpoints (void) | |
7833 | { | |
35df4500 | 7834 | struct breakpoint *b, *b_tmp; |
cae688ec | 7835 | |
35df4500 | 7836 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
7837 | if (b->type == bp_shlib_event |
7838 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
7839 | delete_breakpoint (b); |
7840 | } | |
7841 | ||
f37f681c PA |
7842 | /* See breakpoint.h. */ |
7843 | ||
7844 | void | |
7845 | remove_solib_event_breakpoints_at_next_stop (void) | |
7846 | { | |
7847 | struct breakpoint *b, *b_tmp; | |
7848 | ||
7849 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
7850 | if (b->type == bp_shlib_event | |
7851 | && b->loc->pspace == current_program_space) | |
7852 | b->disposition = disp_del_at_next_stop; | |
7853 | } | |
7854 | ||
04086b45 PA |
7855 | /* Helper for create_solib_event_breakpoint / |
7856 | create_and_insert_solib_event_breakpoint. Allows specifying which | |
7857 | INSERT_MODE to pass through to update_global_location_list. */ | |
7858 | ||
7859 | static struct breakpoint * | |
7860 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, | |
7861 | enum ugll_insert_mode insert_mode) | |
cae688ec JJ |
7862 | { |
7863 | struct breakpoint *b; | |
7864 | ||
06edf0c0 PA |
7865 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
7866 | &internal_breakpoint_ops); | |
04086b45 | 7867 | update_global_location_list_nothrow (insert_mode); |
cae688ec JJ |
7868 | return b; |
7869 | } | |
7870 | ||
04086b45 PA |
7871 | struct breakpoint * |
7872 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7873 | { | |
7874 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); | |
7875 | } | |
7876 | ||
f37f681c PA |
7877 | /* See breakpoint.h. */ |
7878 | ||
7879 | struct breakpoint * | |
7880 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
7881 | { | |
7882 | struct breakpoint *b; | |
7883 | ||
04086b45 PA |
7884 | /* Explicitly tell update_global_location_list to insert |
7885 | locations. */ | |
7886 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); | |
f37f681c PA |
7887 | if (!b->loc->inserted) |
7888 | { | |
7889 | delete_breakpoint (b); | |
7890 | return NULL; | |
7891 | } | |
7892 | return b; | |
7893 | } | |
7894 | ||
cae688ec JJ |
7895 | /* Disable any breakpoints that are on code in shared libraries. Only |
7896 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
7897 | ||
7898 | void | |
cb851954 | 7899 | disable_breakpoints_in_shlibs (void) |
cae688ec | 7900 | { |
876fa593 | 7901 | struct bp_location *loc, **locp_tmp; |
cae688ec | 7902 | |
876fa593 | 7903 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 7904 | { |
2bdf28a0 | 7905 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7906 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 7907 | |
4a64f543 MS |
7908 | /* We apply the check to all breakpoints, including disabled for |
7909 | those with loc->duplicate set. This is so that when breakpoint | |
7910 | becomes enabled, or the duplicate is removed, gdb will try to | |
7911 | insert all breakpoints. If we don't set shlib_disabled here, | |
7912 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 7913 | if (((b->type == bp_breakpoint) |
508ccb1f | 7914 | || (b->type == bp_jit_event) |
1042e4c0 | 7915 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 7916 | || (is_tracepoint (b))) |
6c95b8df | 7917 | && loc->pspace == current_program_space |
0d381245 | 7918 | && !loc->shlib_disabled |
6c95b8df | 7919 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 | 7920 | ) |
0d381245 VP |
7921 | { |
7922 | loc->shlib_disabled = 1; | |
7923 | } | |
cae688ec JJ |
7924 | } |
7925 | } | |
7926 | ||
63644780 NB |
7927 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
7928 | notification of unloaded_shlib. Only apply to enabled breakpoints, | |
7929 | disabled ones can just stay disabled. */ | |
84acb35a | 7930 | |
75149521 | 7931 | static void |
84acb35a JJ |
7932 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
7933 | { | |
876fa593 | 7934 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
7935 | int disabled_shlib_breaks = 0; |
7936 | ||
c86cf029 VP |
7937 | /* SunOS a.out shared libraries are always mapped, so do not |
7938 | disable breakpoints; they will only be reported as unloaded | |
7939 | through clear_solib when GDB discards its shared library | |
7940 | list. See clear_solib for more information. */ | |
7941 | if (exec_bfd != NULL | |
7942 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
7943 | return; | |
7944 | ||
876fa593 | 7945 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 7946 | { |
2bdf28a0 | 7947 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 7948 | struct breakpoint *b = loc->owner; |
cc59ec59 | 7949 | |
1e4d1764 | 7950 | if (solib->pspace == loc->pspace |
e2dd7057 | 7951 | && !loc->shlib_disabled |
1e4d1764 YQ |
7952 | && (((b->type == bp_breakpoint |
7953 | || b->type == bp_jit_event | |
7954 | || b->type == bp_hardware_breakpoint) | |
7955 | && (loc->loc_type == bp_loc_hardware_breakpoint | |
7956 | || loc->loc_type == bp_loc_software_breakpoint)) | |
7957 | || is_tracepoint (b)) | |
e2dd7057 | 7958 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 7959 | { |
e2dd7057 PP |
7960 | loc->shlib_disabled = 1; |
7961 | /* At this point, we cannot rely on remove_breakpoint | |
7962 | succeeding so we must mark the breakpoint as not inserted | |
7963 | to prevent future errors occurring in remove_breakpoints. */ | |
7964 | loc->inserted = 0; | |
8d3788bd VP |
7965 | |
7966 | /* This may cause duplicate notifications for the same breakpoint. */ | |
7967 | observer_notify_breakpoint_modified (b); | |
7968 | ||
e2dd7057 PP |
7969 | if (!disabled_shlib_breaks) |
7970 | { | |
7971 | target_terminal_ours_for_output (); | |
3e43a32a MS |
7972 | warning (_("Temporarily disabling breakpoints " |
7973 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 7974 | solib->so_name); |
84acb35a | 7975 | } |
e2dd7057 | 7976 | disabled_shlib_breaks = 1; |
84acb35a JJ |
7977 | } |
7978 | } | |
84acb35a JJ |
7979 | } |
7980 | ||
63644780 NB |
7981 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
7982 | notification of free_objfile. Only apply to enabled breakpoints, | |
7983 | disabled ones can just stay disabled. */ | |
7984 | ||
7985 | static void | |
7986 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) | |
7987 | { | |
7988 | struct breakpoint *b; | |
7989 | ||
7990 | if (objfile == NULL) | |
7991 | return; | |
7992 | ||
d03de421 PA |
7993 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
7994 | managed by the user with add-symbol-file/remove-symbol-file. | |
7995 | Similarly to how breakpoints in shared libraries are handled in | |
7996 | response to "nosharedlibrary", mark breakpoints in such modules | |
08351840 PA |
7997 | shlib_disabled so they end up uninserted on the next global |
7998 | location list update. Shared libraries not loaded by the user | |
7999 | aren't handled here -- they're already handled in | |
8000 | disable_breakpoints_in_unloaded_shlib, called by solib.c's | |
8001 | solib_unloaded observer. We skip objfiles that are not | |
d03de421 PA |
8002 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
8003 | main objfile). */ | |
8004 | if ((objfile->flags & OBJF_SHARED) == 0 | |
8005 | || (objfile->flags & OBJF_USERLOADED) == 0) | |
63644780 NB |
8006 | return; |
8007 | ||
8008 | ALL_BREAKPOINTS (b) | |
8009 | { | |
8010 | struct bp_location *loc; | |
8011 | int bp_modified = 0; | |
8012 | ||
8013 | if (!is_breakpoint (b) && !is_tracepoint (b)) | |
8014 | continue; | |
8015 | ||
8016 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
8017 | { | |
8018 | CORE_ADDR loc_addr = loc->address; | |
8019 | ||
8020 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8021 | && loc->loc_type != bp_loc_software_breakpoint) | |
8022 | continue; | |
8023 | ||
8024 | if (loc->shlib_disabled != 0) | |
8025 | continue; | |
8026 | ||
8027 | if (objfile->pspace != loc->pspace) | |
8028 | continue; | |
8029 | ||
8030 | if (loc->loc_type != bp_loc_hardware_breakpoint | |
8031 | && loc->loc_type != bp_loc_software_breakpoint) | |
8032 | continue; | |
8033 | ||
8034 | if (is_addr_in_objfile (loc_addr, objfile)) | |
8035 | { | |
8036 | loc->shlib_disabled = 1; | |
08351840 PA |
8037 | /* At this point, we don't know whether the object was |
8038 | unmapped from the inferior or not, so leave the | |
8039 | inserted flag alone. We'll handle failure to | |
8040 | uninsert quietly, in case the object was indeed | |
8041 | unmapped. */ | |
63644780 NB |
8042 | |
8043 | mark_breakpoint_location_modified (loc); | |
8044 | ||
8045 | bp_modified = 1; | |
8046 | } | |
8047 | } | |
8048 | ||
8049 | if (bp_modified) | |
8050 | observer_notify_breakpoint_modified (b); | |
8051 | } | |
8052 | } | |
8053 | ||
ce78b96d JB |
8054 | /* FORK & VFORK catchpoints. */ |
8055 | ||
e29a4733 PA |
8056 | /* An instance of this type is used to represent a fork or vfork |
8057 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
8058 | class; users downcast to "struct breakpoint *" when needed. A | |
8059 | breakpoint is really of this type iff its ops pointer points to | |
8060 | CATCH_FORK_BREAKPOINT_OPS. */ | |
8061 | ||
8062 | struct fork_catchpoint | |
8063 | { | |
8064 | /* The base class. */ | |
8065 | struct breakpoint base; | |
8066 | ||
8067 | /* Process id of a child process whose forking triggered this | |
8068 | catchpoint. This field is only valid immediately after this | |
8069 | catchpoint has triggered. */ | |
8070 | ptid_t forked_inferior_pid; | |
8071 | }; | |
8072 | ||
4a64f543 MS |
8073 | /* Implement the "insert" breakpoint_ops method for fork |
8074 | catchpoints. */ | |
ce78b96d | 8075 | |
77b06cd7 TJB |
8076 | static int |
8077 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 8078 | { |
dfd4cc63 | 8079 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8080 | } |
8081 | ||
4a64f543 MS |
8082 | /* Implement the "remove" breakpoint_ops method for fork |
8083 | catchpoints. */ | |
ce78b96d JB |
8084 | |
8085 | static int | |
77b06cd7 | 8086 | remove_catch_fork (struct bp_location *bl) |
ce78b96d | 8087 | { |
dfd4cc63 | 8088 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8089 | } |
8090 | ||
8091 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
8092 | catchpoints. */ | |
8093 | ||
8094 | static int | |
f1310107 | 8095 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
09ac7c10 TT |
8096 | struct address_space *aspace, CORE_ADDR bp_addr, |
8097 | const struct target_waitstatus *ws) | |
ce78b96d | 8098 | { |
e29a4733 PA |
8099 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8100 | ||
f90263c1 TT |
8101 | if (ws->kind != TARGET_WAITKIND_FORKED) |
8102 | return 0; | |
8103 | ||
8104 | c->forked_inferior_pid = ws->value.related_pid; | |
8105 | return 1; | |
ce78b96d JB |
8106 | } |
8107 | ||
4a64f543 MS |
8108 | /* Implement the "print_it" breakpoint_ops method for fork |
8109 | catchpoints. */ | |
ce78b96d JB |
8110 | |
8111 | static enum print_stop_action | |
348d480f | 8112 | print_it_catch_fork (bpstat bs) |
ce78b96d | 8113 | { |
36dfb11c | 8114 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8115 | struct breakpoint *b = bs->breakpoint_at; |
8116 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 8117 | |
ce78b96d | 8118 | annotate_catchpoint (b->number); |
f303dbd6 | 8119 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8120 | if (b->disposition == disp_del) |
f303dbd6 | 8121 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8122 | else |
f303dbd6 | 8123 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8124 | if (ui_out_is_mi_like_p (uiout)) |
8125 | { | |
8126 | ui_out_field_string (uiout, "reason", | |
8127 | async_reason_lookup (EXEC_ASYNC_FORK)); | |
8128 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8129 | } | |
8130 | ui_out_field_int (uiout, "bkptno", b->number); | |
8131 | ui_out_text (uiout, " (forked process "); | |
8132 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8133 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8134 | return PRINT_SRC_AND_LOC; |
8135 | } | |
8136 | ||
4a64f543 MS |
8137 | /* Implement the "print_one" breakpoint_ops method for fork |
8138 | catchpoints. */ | |
ce78b96d JB |
8139 | |
8140 | static void | |
a6d9a66e | 8141 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8142 | { |
e29a4733 | 8143 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8144 | struct value_print_options opts; |
79a45e25 | 8145 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8146 | |
8147 | get_user_print_options (&opts); | |
8148 | ||
4a64f543 MS |
8149 | /* Field 4, the address, is omitted (which makes the columns not |
8150 | line up too nicely with the headers, but the effect is relatively | |
8151 | readable). */ | |
79a45b7d | 8152 | if (opts.addressprint) |
ce78b96d JB |
8153 | ui_out_field_skip (uiout, "addr"); |
8154 | annotate_field (5); | |
8155 | ui_out_text (uiout, "fork"); | |
e29a4733 | 8156 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8157 | { |
8158 | ui_out_text (uiout, ", process "); | |
8159 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8160 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8161 | ui_out_spaces (uiout, 1); |
8162 | } | |
8ac3646f TT |
8163 | |
8164 | if (ui_out_is_mi_like_p (uiout)) | |
8165 | ui_out_field_string (uiout, "catch-type", "fork"); | |
ce78b96d JB |
8166 | } |
8167 | ||
8168 | /* Implement the "print_mention" breakpoint_ops method for fork | |
8169 | catchpoints. */ | |
8170 | ||
8171 | static void | |
8172 | print_mention_catch_fork (struct breakpoint *b) | |
8173 | { | |
8174 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
8175 | } | |
8176 | ||
6149aea9 PA |
8177 | /* Implement the "print_recreate" breakpoint_ops method for fork |
8178 | catchpoints. */ | |
8179 | ||
8180 | static void | |
8181 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
8182 | { | |
8183 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 8184 | print_recreate_thread (b, fp); |
6149aea9 PA |
8185 | } |
8186 | ||
ce78b96d JB |
8187 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
8188 | ||
2060206e | 8189 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 8190 | |
4a64f543 MS |
8191 | /* Implement the "insert" breakpoint_ops method for vfork |
8192 | catchpoints. */ | |
ce78b96d | 8193 | |
77b06cd7 TJB |
8194 | static int |
8195 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 8196 | { |
dfd4cc63 | 8197 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8198 | } |
8199 | ||
4a64f543 MS |
8200 | /* Implement the "remove" breakpoint_ops method for vfork |
8201 | catchpoints. */ | |
ce78b96d JB |
8202 | |
8203 | static int | |
77b06cd7 | 8204 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d | 8205 | { |
dfd4cc63 | 8206 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
ce78b96d JB |
8207 | } |
8208 | ||
8209 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
8210 | catchpoints. */ | |
8211 | ||
8212 | static int | |
f1310107 | 8213 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
09ac7c10 TT |
8214 | struct address_space *aspace, CORE_ADDR bp_addr, |
8215 | const struct target_waitstatus *ws) | |
ce78b96d | 8216 | { |
e29a4733 PA |
8217 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
8218 | ||
f90263c1 TT |
8219 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
8220 | return 0; | |
8221 | ||
8222 | c->forked_inferior_pid = ws->value.related_pid; | |
8223 | return 1; | |
ce78b96d JB |
8224 | } |
8225 | ||
4a64f543 MS |
8226 | /* Implement the "print_it" breakpoint_ops method for vfork |
8227 | catchpoints. */ | |
ce78b96d JB |
8228 | |
8229 | static enum print_stop_action | |
348d480f | 8230 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 8231 | { |
36dfb11c | 8232 | struct ui_out *uiout = current_uiout; |
348d480f | 8233 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
8234 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
8235 | ||
ce78b96d | 8236 | annotate_catchpoint (b->number); |
f303dbd6 | 8237 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8238 | if (b->disposition == disp_del) |
f303dbd6 | 8239 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8240 | else |
f303dbd6 | 8241 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8242 | if (ui_out_is_mi_like_p (uiout)) |
8243 | { | |
8244 | ui_out_field_string (uiout, "reason", | |
8245 | async_reason_lookup (EXEC_ASYNC_VFORK)); | |
8246 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8247 | } | |
8248 | ui_out_field_int (uiout, "bkptno", b->number); | |
8249 | ui_out_text (uiout, " (vforked process "); | |
8250 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); | |
8251 | ui_out_text (uiout, "), "); | |
ce78b96d JB |
8252 | return PRINT_SRC_AND_LOC; |
8253 | } | |
8254 | ||
4a64f543 MS |
8255 | /* Implement the "print_one" breakpoint_ops method for vfork |
8256 | catchpoints. */ | |
ce78b96d JB |
8257 | |
8258 | static void | |
a6d9a66e | 8259 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 8260 | { |
e29a4733 | 8261 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 8262 | struct value_print_options opts; |
79a45e25 | 8263 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
8264 | |
8265 | get_user_print_options (&opts); | |
4a64f543 MS |
8266 | /* Field 4, the address, is omitted (which makes the columns not |
8267 | line up too nicely with the headers, but the effect is relatively | |
8268 | readable). */ | |
79a45b7d | 8269 | if (opts.addressprint) |
ce78b96d JB |
8270 | ui_out_field_skip (uiout, "addr"); |
8271 | annotate_field (5); | |
8272 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 8273 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
8274 | { |
8275 | ui_out_text (uiout, ", process "); | |
8276 | ui_out_field_int (uiout, "what", | |
e29a4733 | 8277 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
8278 | ui_out_spaces (uiout, 1); |
8279 | } | |
8ac3646f TT |
8280 | |
8281 | if (ui_out_is_mi_like_p (uiout)) | |
8282 | ui_out_field_string (uiout, "catch-type", "vfork"); | |
ce78b96d JB |
8283 | } |
8284 | ||
8285 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
8286 | catchpoints. */ | |
8287 | ||
8288 | static void | |
8289 | print_mention_catch_vfork (struct breakpoint *b) | |
8290 | { | |
8291 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
8292 | } | |
8293 | ||
6149aea9 PA |
8294 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
8295 | catchpoints. */ | |
8296 | ||
8297 | static void | |
8298 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
8299 | { | |
8300 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 8301 | print_recreate_thread (b, fp); |
6149aea9 PA |
8302 | } |
8303 | ||
ce78b96d JB |
8304 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
8305 | ||
2060206e | 8306 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 8307 | |
edcc5120 TT |
8308 | /* An instance of this type is used to represent an solib catchpoint. |
8309 | It includes a "struct breakpoint" as a kind of base class; users | |
8310 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8311 | really of this type iff its ops pointer points to | |
8312 | CATCH_SOLIB_BREAKPOINT_OPS. */ | |
8313 | ||
8314 | struct solib_catchpoint | |
8315 | { | |
8316 | /* The base class. */ | |
8317 | struct breakpoint base; | |
8318 | ||
8319 | /* True for "catch load", false for "catch unload". */ | |
8320 | unsigned char is_load; | |
8321 | ||
8322 | /* Regular expression to match, if any. COMPILED is only valid when | |
8323 | REGEX is non-NULL. */ | |
8324 | char *regex; | |
8325 | regex_t compiled; | |
8326 | }; | |
8327 | ||
8328 | static void | |
8329 | dtor_catch_solib (struct breakpoint *b) | |
8330 | { | |
8331 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8332 | ||
8333 | if (self->regex) | |
8334 | regfree (&self->compiled); | |
8335 | xfree (self->regex); | |
8336 | ||
8337 | base_breakpoint_ops.dtor (b); | |
8338 | } | |
8339 | ||
8340 | static int | |
8341 | insert_catch_solib (struct bp_location *ignore) | |
8342 | { | |
8343 | return 0; | |
8344 | } | |
8345 | ||
8346 | static int | |
8347 | remove_catch_solib (struct bp_location *ignore) | |
8348 | { | |
8349 | return 0; | |
8350 | } | |
8351 | ||
8352 | static int | |
8353 | breakpoint_hit_catch_solib (const struct bp_location *bl, | |
8354 | struct address_space *aspace, | |
8355 | CORE_ADDR bp_addr, | |
8356 | const struct target_waitstatus *ws) | |
8357 | { | |
8358 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; | |
8359 | struct breakpoint *other; | |
8360 | ||
8361 | if (ws->kind == TARGET_WAITKIND_LOADED) | |
8362 | return 1; | |
8363 | ||
8364 | ALL_BREAKPOINTS (other) | |
8365 | { | |
8366 | struct bp_location *other_bl; | |
8367 | ||
8368 | if (other == bl->owner) | |
8369 | continue; | |
8370 | ||
8371 | if (other->type != bp_shlib_event) | |
8372 | continue; | |
8373 | ||
8374 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) | |
8375 | continue; | |
8376 | ||
8377 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) | |
8378 | { | |
8379 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) | |
8380 | return 1; | |
8381 | } | |
8382 | } | |
8383 | ||
8384 | return 0; | |
8385 | } | |
8386 | ||
8387 | static void | |
8388 | check_status_catch_solib (struct bpstats *bs) | |
8389 | { | |
8390 | struct solib_catchpoint *self | |
8391 | = (struct solib_catchpoint *) bs->breakpoint_at; | |
8392 | int ix; | |
8393 | ||
8394 | if (self->is_load) | |
8395 | { | |
8396 | struct so_list *iter; | |
8397 | ||
8398 | for (ix = 0; | |
8399 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, | |
8400 | ix, iter); | |
8401 | ++ix) | |
8402 | { | |
8403 | if (!self->regex | |
8404 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) | |
8405 | return; | |
8406 | } | |
8407 | } | |
8408 | else | |
8409 | { | |
8410 | char *iter; | |
8411 | ||
8412 | for (ix = 0; | |
8413 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, | |
8414 | ix, iter); | |
8415 | ++ix) | |
8416 | { | |
8417 | if (!self->regex | |
8418 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) | |
8419 | return; | |
8420 | } | |
8421 | } | |
8422 | ||
8423 | bs->stop = 0; | |
8424 | bs->print_it = print_it_noop; | |
8425 | } | |
8426 | ||
8427 | static enum print_stop_action | |
8428 | print_it_catch_solib (bpstat bs) | |
8429 | { | |
8430 | struct breakpoint *b = bs->breakpoint_at; | |
8431 | struct ui_out *uiout = current_uiout; | |
8432 | ||
8433 | annotate_catchpoint (b->number); | |
f303dbd6 | 8434 | maybe_print_thread_hit_breakpoint (uiout); |
edcc5120 | 8435 | if (b->disposition == disp_del) |
f303dbd6 | 8436 | ui_out_text (uiout, "Temporary catchpoint "); |
edcc5120 | 8437 | else |
f303dbd6 | 8438 | ui_out_text (uiout, "Catchpoint "); |
edcc5120 TT |
8439 | ui_out_field_int (uiout, "bkptno", b->number); |
8440 | ui_out_text (uiout, "\n"); | |
8441 | if (ui_out_is_mi_like_p (uiout)) | |
8442 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8443 | print_solib_event (1); | |
8444 | return PRINT_SRC_AND_LOC; | |
8445 | } | |
8446 | ||
8447 | static void | |
8448 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) | |
8449 | { | |
8450 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8451 | struct value_print_options opts; | |
8452 | struct ui_out *uiout = current_uiout; | |
8453 | char *msg; | |
8454 | ||
8455 | get_user_print_options (&opts); | |
8456 | /* Field 4, the address, is omitted (which makes the columns not | |
8457 | line up too nicely with the headers, but the effect is relatively | |
8458 | readable). */ | |
8459 | if (opts.addressprint) | |
8460 | { | |
8461 | annotate_field (4); | |
8462 | ui_out_field_skip (uiout, "addr"); | |
8463 | } | |
8464 | ||
8465 | annotate_field (5); | |
8466 | if (self->is_load) | |
8467 | { | |
8468 | if (self->regex) | |
8469 | msg = xstrprintf (_("load of library matching %s"), self->regex); | |
8470 | else | |
8471 | msg = xstrdup (_("load of library")); | |
8472 | } | |
8473 | else | |
8474 | { | |
8475 | if (self->regex) | |
8476 | msg = xstrprintf (_("unload of library matching %s"), self->regex); | |
8477 | else | |
8478 | msg = xstrdup (_("unload of library")); | |
8479 | } | |
8480 | ui_out_field_string (uiout, "what", msg); | |
8481 | xfree (msg); | |
8ac3646f TT |
8482 | |
8483 | if (ui_out_is_mi_like_p (uiout)) | |
8484 | ui_out_field_string (uiout, "catch-type", | |
8485 | self->is_load ? "load" : "unload"); | |
edcc5120 TT |
8486 | } |
8487 | ||
8488 | static void | |
8489 | print_mention_catch_solib (struct breakpoint *b) | |
8490 | { | |
8491 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8492 | ||
8493 | printf_filtered (_("Catchpoint %d (%s)"), b->number, | |
8494 | self->is_load ? "load" : "unload"); | |
8495 | } | |
8496 | ||
8497 | static void | |
8498 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) | |
8499 | { | |
8500 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; | |
8501 | ||
8502 | fprintf_unfiltered (fp, "%s %s", | |
8503 | b->disposition == disp_del ? "tcatch" : "catch", | |
8504 | self->is_load ? "load" : "unload"); | |
8505 | if (self->regex) | |
8506 | fprintf_unfiltered (fp, " %s", self->regex); | |
8507 | fprintf_unfiltered (fp, "\n"); | |
8508 | } | |
8509 | ||
8510 | static struct breakpoint_ops catch_solib_breakpoint_ops; | |
8511 | ||
91985142 MG |
8512 | /* Shared helper function (MI and CLI) for creating and installing |
8513 | a shared object event catchpoint. If IS_LOAD is non-zero then | |
8514 | the events to be caught are load events, otherwise they are | |
8515 | unload events. If IS_TEMP is non-zero the catchpoint is a | |
8516 | temporary one. If ENABLED is non-zero the catchpoint is | |
8517 | created in an enabled state. */ | |
edcc5120 | 8518 | |
91985142 MG |
8519 | void |
8520 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) | |
edcc5120 TT |
8521 | { |
8522 | struct solib_catchpoint *c; | |
8523 | struct gdbarch *gdbarch = get_current_arch (); | |
edcc5120 TT |
8524 | struct cleanup *cleanup; |
8525 | ||
edcc5120 TT |
8526 | if (!arg) |
8527 | arg = ""; | |
8528 | arg = skip_spaces (arg); | |
8529 | ||
8530 | c = XCNEW (struct solib_catchpoint); | |
8531 | cleanup = make_cleanup (xfree, c); | |
8532 | ||
8533 | if (*arg != '\0') | |
8534 | { | |
8535 | int errcode; | |
8536 | ||
8537 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); | |
8538 | if (errcode != 0) | |
8539 | { | |
8540 | char *err = get_regcomp_error (errcode, &c->compiled); | |
8541 | ||
8542 | make_cleanup (xfree, err); | |
8543 | error (_("Invalid regexp (%s): %s"), err, arg); | |
8544 | } | |
8545 | c->regex = xstrdup (arg); | |
8546 | } | |
8547 | ||
8548 | c->is_load = is_load; | |
91985142 | 8549 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
edcc5120 TT |
8550 | &catch_solib_breakpoint_ops); |
8551 | ||
91985142 MG |
8552 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
8553 | ||
edcc5120 TT |
8554 | discard_cleanups (cleanup); |
8555 | install_breakpoint (0, &c->base, 1); | |
8556 | } | |
8557 | ||
91985142 MG |
8558 | /* A helper function that does all the work for "catch load" and |
8559 | "catch unload". */ | |
8560 | ||
8561 | static void | |
8562 | catch_load_or_unload (char *arg, int from_tty, int is_load, | |
8563 | struct cmd_list_element *command) | |
8564 | { | |
8565 | int tempflag; | |
8566 | const int enabled = 1; | |
8567 | ||
8568 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8569 | ||
8570 | add_solib_catchpoint (arg, is_load, tempflag, enabled); | |
8571 | } | |
8572 | ||
edcc5120 TT |
8573 | static void |
8574 | catch_load_command_1 (char *arg, int from_tty, | |
8575 | struct cmd_list_element *command) | |
8576 | { | |
8577 | catch_load_or_unload (arg, from_tty, 1, command); | |
8578 | } | |
8579 | ||
8580 | static void | |
8581 | catch_unload_command_1 (char *arg, int from_tty, | |
8582 | struct cmd_list_element *command) | |
8583 | { | |
8584 | catch_load_or_unload (arg, from_tty, 0, command); | |
8585 | } | |
8586 | ||
346774a9 PA |
8587 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
8588 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
8589 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
8590 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 8591 | |
ab04a2af | 8592 | void |
346774a9 PA |
8593 | init_catchpoint (struct breakpoint *b, |
8594 | struct gdbarch *gdbarch, int tempflag, | |
8595 | char *cond_string, | |
c0a91b2b | 8596 | const struct breakpoint_ops *ops) |
c906108c | 8597 | { |
c5aa993b | 8598 | struct symtab_and_line sal; |
346774a9 | 8599 | |
fe39c653 | 8600 | init_sal (&sal); |
6c95b8df | 8601 | sal.pspace = current_program_space; |
c5aa993b | 8602 | |
28010a5d | 8603 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 8604 | |
1b36a34b | 8605 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 8606 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
8607 | } |
8608 | ||
28010a5d | 8609 | void |
3ea46bff | 8610 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
c56053d2 PA |
8611 | { |
8612 | add_to_breakpoint_chain (b); | |
3a5c3e22 | 8613 | set_breakpoint_number (internal, b); |
558a9d82 YQ |
8614 | if (is_tracepoint (b)) |
8615 | set_tracepoint_count (breakpoint_count); | |
3a5c3e22 PA |
8616 | if (!internal) |
8617 | mention (b); | |
c56053d2 | 8618 | observer_notify_breakpoint_created (b); |
3ea46bff YQ |
8619 | |
8620 | if (update_gll) | |
44702360 | 8621 | update_global_location_list (UGLL_MAY_INSERT); |
c56053d2 PA |
8622 | } |
8623 | ||
9b70b993 | 8624 | static void |
a6d9a66e UW |
8625 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
8626 | int tempflag, char *cond_string, | |
c0a91b2b | 8627 | const struct breakpoint_ops *ops) |
c906108c | 8628 | { |
e29a4733 | 8629 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 8630 | |
e29a4733 PA |
8631 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
8632 | ||
8633 | c->forked_inferior_pid = null_ptid; | |
8634 | ||
3ea46bff | 8635 | install_breakpoint (0, &c->base, 1); |
c906108c SS |
8636 | } |
8637 | ||
fe798b75 JB |
8638 | /* Exec catchpoints. */ |
8639 | ||
b4d90040 PA |
8640 | /* An instance of this type is used to represent an exec catchpoint. |
8641 | It includes a "struct breakpoint" as a kind of base class; users | |
8642 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
8643 | really of this type iff its ops pointer points to | |
8644 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
8645 | ||
8646 | struct exec_catchpoint | |
8647 | { | |
8648 | /* The base class. */ | |
8649 | struct breakpoint base; | |
8650 | ||
8651 | /* Filename of a program whose exec triggered this catchpoint. | |
8652 | This field is only valid immediately after this catchpoint has | |
8653 | triggered. */ | |
8654 | char *exec_pathname; | |
8655 | }; | |
8656 | ||
8657 | /* Implement the "dtor" breakpoint_ops method for exec | |
8658 | catchpoints. */ | |
8659 | ||
8660 | static void | |
8661 | dtor_catch_exec (struct breakpoint *b) | |
8662 | { | |
8663 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
8664 | ||
8665 | xfree (c->exec_pathname); | |
348d480f | 8666 | |
2060206e | 8667 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
8668 | } |
8669 | ||
77b06cd7 TJB |
8670 | static int |
8671 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 8672 | { |
dfd4cc63 | 8673 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8674 | } |
c906108c | 8675 | |
fe798b75 | 8676 | static int |
77b06cd7 | 8677 | remove_catch_exec (struct bp_location *bl) |
fe798b75 | 8678 | { |
dfd4cc63 | 8679 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
fe798b75 | 8680 | } |
c906108c | 8681 | |
fe798b75 | 8682 | static int |
f1310107 | 8683 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
09ac7c10 TT |
8684 | struct address_space *aspace, CORE_ADDR bp_addr, |
8685 | const struct target_waitstatus *ws) | |
fe798b75 | 8686 | { |
b4d90040 PA |
8687 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
8688 | ||
f90263c1 TT |
8689 | if (ws->kind != TARGET_WAITKIND_EXECD) |
8690 | return 0; | |
8691 | ||
8692 | c->exec_pathname = xstrdup (ws->value.execd_pathname); | |
8693 | return 1; | |
fe798b75 | 8694 | } |
c906108c | 8695 | |
fe798b75 | 8696 | static enum print_stop_action |
348d480f | 8697 | print_it_catch_exec (bpstat bs) |
fe798b75 | 8698 | { |
36dfb11c | 8699 | struct ui_out *uiout = current_uiout; |
348d480f | 8700 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
8701 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
8702 | ||
fe798b75 | 8703 | annotate_catchpoint (b->number); |
f303dbd6 | 8704 | maybe_print_thread_hit_breakpoint (uiout); |
36dfb11c | 8705 | if (b->disposition == disp_del) |
f303dbd6 | 8706 | ui_out_text (uiout, "Temporary catchpoint "); |
36dfb11c | 8707 | else |
f303dbd6 | 8708 | ui_out_text (uiout, "Catchpoint "); |
36dfb11c TT |
8709 | if (ui_out_is_mi_like_p (uiout)) |
8710 | { | |
8711 | ui_out_field_string (uiout, "reason", | |
8712 | async_reason_lookup (EXEC_ASYNC_EXEC)); | |
8713 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8714 | } | |
8715 | ui_out_field_int (uiout, "bkptno", b->number); | |
8716 | ui_out_text (uiout, " (exec'd "); | |
8717 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); | |
8718 | ui_out_text (uiout, "), "); | |
8719 | ||
fe798b75 | 8720 | return PRINT_SRC_AND_LOC; |
c906108c SS |
8721 | } |
8722 | ||
fe798b75 | 8723 | static void |
a6d9a66e | 8724 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 8725 | { |
b4d90040 | 8726 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 8727 | struct value_print_options opts; |
79a45e25 | 8728 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
8729 | |
8730 | get_user_print_options (&opts); | |
8731 | ||
8732 | /* Field 4, the address, is omitted (which makes the columns | |
8733 | not line up too nicely with the headers, but the effect | |
8734 | is relatively readable). */ | |
8735 | if (opts.addressprint) | |
8736 | ui_out_field_skip (uiout, "addr"); | |
8737 | annotate_field (5); | |
8738 | ui_out_text (uiout, "exec"); | |
b4d90040 | 8739 | if (c->exec_pathname != NULL) |
fe798b75 JB |
8740 | { |
8741 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 8742 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
8743 | ui_out_text (uiout, "\" "); |
8744 | } | |
8ac3646f TT |
8745 | |
8746 | if (ui_out_is_mi_like_p (uiout)) | |
8747 | ui_out_field_string (uiout, "catch-type", "exec"); | |
fe798b75 JB |
8748 | } |
8749 | ||
8750 | static void | |
8751 | print_mention_catch_exec (struct breakpoint *b) | |
8752 | { | |
8753 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
8754 | } | |
8755 | ||
6149aea9 PA |
8756 | /* Implement the "print_recreate" breakpoint_ops method for exec |
8757 | catchpoints. */ | |
8758 | ||
8759 | static void | |
8760 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
8761 | { | |
8762 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 8763 | print_recreate_thread (b, fp); |
6149aea9 PA |
8764 | } |
8765 | ||
2060206e | 8766 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 8767 | |
c906108c | 8768 | static int |
fba45db2 | 8769 | hw_breakpoint_used_count (void) |
c906108c | 8770 | { |
c906108c | 8771 | int i = 0; |
f1310107 TJB |
8772 | struct breakpoint *b; |
8773 | struct bp_location *bl; | |
c906108c SS |
8774 | |
8775 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8776 | { |
d6b74ac4 | 8777 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
8778 | for (bl = b->loc; bl; bl = bl->next) |
8779 | { | |
8780 | /* Special types of hardware breakpoints may use more than | |
8781 | one register. */ | |
348d480f | 8782 | i += b->ops->resources_needed (bl); |
f1310107 | 8783 | } |
c5aa993b | 8784 | } |
c906108c SS |
8785 | |
8786 | return i; | |
8787 | } | |
8788 | ||
a1398e0c PA |
8789 | /* Returns the resources B would use if it were a hardware |
8790 | watchpoint. */ | |
8791 | ||
c906108c | 8792 | static int |
a1398e0c | 8793 | hw_watchpoint_use_count (struct breakpoint *b) |
c906108c | 8794 | { |
c906108c | 8795 | int i = 0; |
e09342b5 | 8796 | struct bp_location *bl; |
c906108c | 8797 | |
a1398e0c PA |
8798 | if (!breakpoint_enabled (b)) |
8799 | return 0; | |
8800 | ||
8801 | for (bl = b->loc; bl; bl = bl->next) | |
8802 | { | |
8803 | /* Special types of hardware watchpoints may use more than | |
8804 | one register. */ | |
8805 | i += b->ops->resources_needed (bl); | |
8806 | } | |
8807 | ||
8808 | return i; | |
8809 | } | |
8810 | ||
8811 | /* Returns the sum the used resources of all hardware watchpoints of | |
8812 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED | |
8813 | the sum of the used resources of all hardware watchpoints of other | |
8814 | types _not_ TYPE. */ | |
8815 | ||
8816 | static int | |
8817 | hw_watchpoint_used_count_others (struct breakpoint *except, | |
8818 | enum bptype type, int *other_type_used) | |
8819 | { | |
8820 | int i = 0; | |
8821 | struct breakpoint *b; | |
8822 | ||
c906108c SS |
8823 | *other_type_used = 0; |
8824 | ALL_BREAKPOINTS (b) | |
e09342b5 | 8825 | { |
a1398e0c PA |
8826 | if (b == except) |
8827 | continue; | |
e09342b5 TJB |
8828 | if (!breakpoint_enabled (b)) |
8829 | continue; | |
8830 | ||
a1398e0c PA |
8831 | if (b->type == type) |
8832 | i += hw_watchpoint_use_count (b); | |
8833 | else if (is_hardware_watchpoint (b)) | |
8834 | *other_type_used = 1; | |
e09342b5 TJB |
8835 | } |
8836 | ||
c906108c SS |
8837 | return i; |
8838 | } | |
8839 | ||
c906108c | 8840 | void |
fba45db2 | 8841 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 8842 | { |
c5aa993b | 8843 | struct breakpoint *b; |
c906108c SS |
8844 | |
8845 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8846 | { |
cc60f2e3 | 8847 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 8848 | { |
b5de0fa7 | 8849 | b->enable_state = bp_call_disabled; |
44702360 | 8850 | update_global_location_list (UGLL_DONT_INSERT); |
c5aa993b JM |
8851 | } |
8852 | } | |
c906108c SS |
8853 | } |
8854 | ||
8855 | void | |
fba45db2 | 8856 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 8857 | { |
c5aa993b | 8858 | struct breakpoint *b; |
c906108c SS |
8859 | |
8860 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8861 | { |
cc60f2e3 | 8862 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 8863 | { |
b5de0fa7 | 8864 | b->enable_state = bp_enabled; |
44702360 | 8865 | update_global_location_list (UGLL_MAY_INSERT); |
c5aa993b JM |
8866 | } |
8867 | } | |
c906108c SS |
8868 | } |
8869 | ||
8bea4e01 UW |
8870 | void |
8871 | disable_breakpoints_before_startup (void) | |
8872 | { | |
6c95b8df | 8873 | current_program_space->executing_startup = 1; |
44702360 | 8874 | update_global_location_list (UGLL_DONT_INSERT); |
8bea4e01 UW |
8875 | } |
8876 | ||
8877 | void | |
8878 | enable_breakpoints_after_startup (void) | |
8879 | { | |
6c95b8df | 8880 | current_program_space->executing_startup = 0; |
f8eba3c6 | 8881 | breakpoint_re_set (); |
8bea4e01 UW |
8882 | } |
8883 | ||
7c16b83e PA |
8884 | /* Create a new single-step breakpoint for thread THREAD, with no |
8885 | locations. */ | |
c906108c | 8886 | |
7c16b83e PA |
8887 | static struct breakpoint * |
8888 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) | |
8889 | { | |
8890 | struct breakpoint *b = XNEW (struct breakpoint); | |
8891 | ||
8892 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, | |
8893 | &momentary_breakpoint_ops); | |
8894 | ||
8895 | b->disposition = disp_donttouch; | |
8896 | b->frame_id = null_frame_id; | |
8897 | ||
8898 | b->thread = thread; | |
8899 | gdb_assert (b->thread != 0); | |
8900 | ||
8901 | add_to_breakpoint_chain (b); | |
8902 | ||
8903 | return b; | |
8904 | } | |
8905 | ||
8906 | /* Set a momentary breakpoint of type TYPE at address specified by | |
8907 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that | |
8908 | frame. */ | |
c906108c SS |
8909 | |
8910 | struct breakpoint * | |
a6d9a66e UW |
8911 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
8912 | struct frame_id frame_id, enum bptype type) | |
c906108c | 8913 | { |
52f0bd74 | 8914 | struct breakpoint *b; |
edb3359d | 8915 | |
193facb3 JK |
8916 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
8917 | tail-called one. */ | |
8918 | gdb_assert (!frame_id_artificial_p (frame_id)); | |
edb3359d | 8919 | |
06edf0c0 | 8920 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
8921 | b->enable_state = bp_enabled; |
8922 | b->disposition = disp_donttouch; | |
818dd999 | 8923 | b->frame_id = frame_id; |
c906108c | 8924 | |
4a64f543 MS |
8925 | /* If we're debugging a multi-threaded program, then we want |
8926 | momentary breakpoints to be active in only a single thread of | |
8927 | control. */ | |
39f77062 | 8928 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 8929 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
c906108c | 8930 | |
44702360 | 8931 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
74960c60 | 8932 | |
c906108c SS |
8933 | return b; |
8934 | } | |
611c83ae | 8935 | |
06edf0c0 | 8936 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
a1aa2221 LM |
8937 | The new breakpoint will have type TYPE, use OPS as its |
8938 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ | |
e58b0e63 | 8939 | |
06edf0c0 PA |
8940 | static struct breakpoint * |
8941 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
8942 | enum bptype type, | |
a1aa2221 LM |
8943 | const struct breakpoint_ops *ops, |
8944 | int loc_enabled) | |
e58b0e63 PA |
8945 | { |
8946 | struct breakpoint *copy; | |
8947 | ||
06edf0c0 | 8948 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 8949 | copy->loc = allocate_bp_location (copy); |
0e30163f | 8950 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 8951 | |
a6d9a66e | 8952 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
8953 | copy->loc->requested_address = orig->loc->requested_address; |
8954 | copy->loc->address = orig->loc->address; | |
8955 | copy->loc->section = orig->loc->section; | |
6c95b8df | 8956 | copy->loc->pspace = orig->loc->pspace; |
55aa24fb | 8957 | copy->loc->probe = orig->loc->probe; |
f8eba3c6 | 8958 | copy->loc->line_number = orig->loc->line_number; |
2f202fde | 8959 | copy->loc->symtab = orig->loc->symtab; |
a1aa2221 | 8960 | copy->loc->enabled = loc_enabled; |
e58b0e63 PA |
8961 | copy->frame_id = orig->frame_id; |
8962 | copy->thread = orig->thread; | |
6c95b8df | 8963 | copy->pspace = orig->pspace; |
e58b0e63 PA |
8964 | |
8965 | copy->enable_state = bp_enabled; | |
8966 | copy->disposition = disp_donttouch; | |
8967 | copy->number = internal_breakpoint_number--; | |
8968 | ||
44702360 | 8969 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
e58b0e63 PA |
8970 | return copy; |
8971 | } | |
8972 | ||
06edf0c0 PA |
8973 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
8974 | ORIG is NULL. */ | |
8975 | ||
8976 | struct breakpoint * | |
8977 | clone_momentary_breakpoint (struct breakpoint *orig) | |
8978 | { | |
8979 | /* If there's nothing to clone, then return nothing. */ | |
8980 | if (orig == NULL) | |
8981 | return NULL; | |
8982 | ||
a1aa2221 | 8983 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
06edf0c0 PA |
8984 | } |
8985 | ||
611c83ae | 8986 | struct breakpoint * |
a6d9a66e UW |
8987 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
8988 | enum bptype type) | |
611c83ae PA |
8989 | { |
8990 | struct symtab_and_line sal; | |
8991 | ||
8992 | sal = find_pc_line (pc, 0); | |
8993 | sal.pc = pc; | |
8994 | sal.section = find_pc_overlay (pc); | |
8995 | sal.explicit_pc = 1; | |
8996 | ||
a6d9a66e | 8997 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 8998 | } |
c906108c | 8999 | \f |
c5aa993b | 9000 | |
c906108c SS |
9001 | /* Tell the user we have just set a breakpoint B. */ |
9002 | ||
9003 | static void | |
fba45db2 | 9004 | mention (struct breakpoint *b) |
c906108c | 9005 | { |
348d480f | 9006 | b->ops->print_mention (b); |
79a45e25 | 9007 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 9008 | return; |
c906108c SS |
9009 | printf_filtered ("\n"); |
9010 | } | |
c906108c | 9011 | \f |
c5aa993b | 9012 | |
1a853c52 PA |
9013 | static int bp_loc_is_permanent (struct bp_location *loc); |
9014 | ||
0d381245 | 9015 | static struct bp_location * |
39d61571 | 9016 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
9017 | const struct symtab_and_line *sal) |
9018 | { | |
9019 | struct bp_location *loc, **tmp; | |
3742cc8b YQ |
9020 | CORE_ADDR adjusted_address; |
9021 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); | |
9022 | ||
9023 | if (loc_gdbarch == NULL) | |
9024 | loc_gdbarch = b->gdbarch; | |
9025 | ||
9026 | /* Adjust the breakpoint's address prior to allocating a location. | |
9027 | Once we call allocate_bp_location(), that mostly uninitialized | |
9028 | location will be placed on the location chain. Adjustment of the | |
9029 | breakpoint may cause target_read_memory() to be called and we do | |
9030 | not want its scan of the location chain to find a breakpoint and | |
9031 | location that's only been partially initialized. */ | |
9032 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, | |
9033 | sal->pc, b->type); | |
0d381245 | 9034 | |
d30113d4 | 9035 | /* Sort the locations by their ADDRESS. */ |
39d61571 | 9036 | loc = allocate_bp_location (b); |
d30113d4 JK |
9037 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
9038 | tmp = &((*tmp)->next)) | |
0d381245 | 9039 | ; |
d30113d4 | 9040 | loc->next = *tmp; |
0d381245 | 9041 | *tmp = loc; |
3742cc8b | 9042 | |
0d381245 | 9043 | loc->requested_address = sal->pc; |
3742cc8b | 9044 | loc->address = adjusted_address; |
6c95b8df | 9045 | loc->pspace = sal->pspace; |
729662a5 TT |
9046 | loc->probe.probe = sal->probe; |
9047 | loc->probe.objfile = sal->objfile; | |
6c95b8df | 9048 | gdb_assert (loc->pspace != NULL); |
0d381245 | 9049 | loc->section = sal->section; |
3742cc8b | 9050 | loc->gdbarch = loc_gdbarch; |
f8eba3c6 | 9051 | loc->line_number = sal->line; |
2f202fde | 9052 | loc->symtab = sal->symtab; |
f8eba3c6 | 9053 | |
0e30163f JK |
9054 | set_breakpoint_location_function (loc, |
9055 | sal->explicit_pc || sal->explicit_line); | |
1a853c52 | 9056 | |
6ae88661 LM |
9057 | /* While by definition, permanent breakpoints are already present in the |
9058 | code, we don't mark the location as inserted. Normally one would expect | |
9059 | that GDB could rely on that breakpoint instruction to stop the program, | |
9060 | thus removing the need to insert its own breakpoint, except that executing | |
9061 | the breakpoint instruction can kill the target instead of reporting a | |
9062 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the | |
9063 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies | |
9064 | with "Trap 0x02 while interrupts disabled, Error state". Letting the | |
9065 | breakpoint be inserted normally results in QEMU knowing about the GDB | |
9066 | breakpoint, and thus trap before the breakpoint instruction is executed. | |
9067 | (If GDB later needs to continue execution past the permanent breakpoint, | |
9068 | it manually increments the PC, thus avoiding executing the breakpoint | |
9069 | instruction.) */ | |
1a853c52 | 9070 | if (bp_loc_is_permanent (loc)) |
6ae88661 | 9071 | loc->permanent = 1; |
1a853c52 | 9072 | |
0d381245 VP |
9073 | return loc; |
9074 | } | |
514f746b AR |
9075 | \f |
9076 | ||
1cf4d951 | 9077 | /* See breakpoint.h. */ |
514f746b | 9078 | |
1cf4d951 PA |
9079 | int |
9080 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) | |
514f746b AR |
9081 | { |
9082 | int len; | |
9083 | CORE_ADDR addr; | |
1afeeb75 | 9084 | const gdb_byte *bpoint; |
514f746b | 9085 | gdb_byte *target_mem; |
939c61fa JK |
9086 | struct cleanup *cleanup; |
9087 | int retval = 0; | |
514f746b | 9088 | |
1cf4d951 PA |
9089 | addr = address; |
9090 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); | |
9091 | ||
9092 | /* Software breakpoints unsupported? */ | |
9093 | if (bpoint == NULL) | |
9094 | return 0; | |
9095 | ||
224c3ddb | 9096 | target_mem = (gdb_byte *) alloca (len); |
1cf4d951 PA |
9097 | |
9098 | /* Enable the automatic memory restoration from breakpoints while | |
9099 | we read the memory. Otherwise we could say about our temporary | |
9100 | breakpoints they are permanent. */ | |
9101 | cleanup = make_show_memory_breakpoints_cleanup (0); | |
9102 | ||
9103 | if (target_read_memory (address, target_mem, len) == 0 | |
9104 | && memcmp (target_mem, bpoint, len) == 0) | |
9105 | retval = 1; | |
9106 | ||
9107 | do_cleanups (cleanup); | |
9108 | ||
9109 | return retval; | |
9110 | } | |
9111 | ||
9112 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
9113 | return 0 otherwise. */ | |
9114 | ||
9115 | static int | |
9116 | bp_loc_is_permanent (struct bp_location *loc) | |
9117 | { | |
9118 | struct cleanup *cleanup; | |
9119 | int retval; | |
9120 | ||
514f746b AR |
9121 | gdb_assert (loc != NULL); |
9122 | ||
244558af LM |
9123 | /* If we have a catchpoint or a watchpoint, just return 0. We should not |
9124 | attempt to read from the addresses the locations of these breakpoint types | |
9125 | point to. program_breakpoint_here_p, below, will attempt to read | |
9126 | memory. */ | |
9127 | if (!breakpoint_address_is_meaningful (loc->owner)) | |
9128 | return 0; | |
9129 | ||
6c95b8df | 9130 | cleanup = save_current_space_and_thread (); |
6c95b8df | 9131 | switch_to_program_space_and_thread (loc->pspace); |
939c61fa | 9132 | |
1cf4d951 | 9133 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
514f746b | 9134 | |
939c61fa JK |
9135 | do_cleanups (cleanup); |
9136 | ||
9137 | return retval; | |
514f746b AR |
9138 | } |
9139 | ||
e7e0cddf SS |
9140 | /* Build a command list for the dprintf corresponding to the current |
9141 | settings of the dprintf style options. */ | |
9142 | ||
9143 | static void | |
9144 | update_dprintf_command_list (struct breakpoint *b) | |
9145 | { | |
9146 | char *dprintf_args = b->extra_string; | |
9147 | char *printf_line = NULL; | |
9148 | ||
9149 | if (!dprintf_args) | |
9150 | return; | |
9151 | ||
9152 | dprintf_args = skip_spaces (dprintf_args); | |
9153 | ||
9154 | /* Allow a comma, as it may have terminated a location, but don't | |
9155 | insist on it. */ | |
9156 | if (*dprintf_args == ',') | |
9157 | ++dprintf_args; | |
9158 | dprintf_args = skip_spaces (dprintf_args); | |
9159 | ||
9160 | if (*dprintf_args != '"') | |
9161 | error (_("Bad format string, missing '\"'.")); | |
9162 | ||
d3ce09f5 | 9163 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
e7e0cddf | 9164 | printf_line = xstrprintf ("printf %s", dprintf_args); |
d3ce09f5 | 9165 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
e7e0cddf SS |
9166 | { |
9167 | if (!dprintf_function) | |
9168 | error (_("No function supplied for dprintf call")); | |
9169 | ||
9170 | if (dprintf_channel && strlen (dprintf_channel) > 0) | |
9171 | printf_line = xstrprintf ("call (void) %s (%s,%s)", | |
9172 | dprintf_function, | |
9173 | dprintf_channel, | |
9174 | dprintf_args); | |
9175 | else | |
9176 | printf_line = xstrprintf ("call (void) %s (%s)", | |
9177 | dprintf_function, | |
9178 | dprintf_args); | |
9179 | } | |
d3ce09f5 SS |
9180 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
9181 | { | |
9182 | if (target_can_run_breakpoint_commands ()) | |
9183 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); | |
9184 | else | |
9185 | { | |
9186 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); | |
9187 | printf_line = xstrprintf ("printf %s", dprintf_args); | |
9188 | } | |
9189 | } | |
e7e0cddf SS |
9190 | else |
9191 | internal_error (__FILE__, __LINE__, | |
9192 | _("Invalid dprintf style.")); | |
9193 | ||
f28045c2 | 9194 | gdb_assert (printf_line != NULL); |
9d6e6e84 | 9195 | /* Manufacture a printf sequence. */ |
f28045c2 | 9196 | { |
8d749320 | 9197 | struct command_line *printf_cmd_line = XNEW (struct command_line); |
e7e0cddf | 9198 | |
f28045c2 YQ |
9199 | printf_cmd_line->control_type = simple_control; |
9200 | printf_cmd_line->body_count = 0; | |
9201 | printf_cmd_line->body_list = NULL; | |
9d6e6e84 | 9202 | printf_cmd_line->next = NULL; |
f28045c2 | 9203 | printf_cmd_line->line = printf_line; |
e7e0cddf | 9204 | |
f28045c2 YQ |
9205 | breakpoint_set_commands (b, printf_cmd_line); |
9206 | } | |
e7e0cddf SS |
9207 | } |
9208 | ||
9209 | /* Update all dprintf commands, making their command lists reflect | |
9210 | current style settings. */ | |
9211 | ||
9212 | static void | |
9213 | update_dprintf_commands (char *args, int from_tty, | |
9214 | struct cmd_list_element *c) | |
9215 | { | |
9216 | struct breakpoint *b; | |
9217 | ||
9218 | ALL_BREAKPOINTS (b) | |
9219 | { | |
9220 | if (b->type == bp_dprintf) | |
9221 | update_dprintf_command_list (b); | |
9222 | } | |
9223 | } | |
c3f6f71d | 9224 | |
f00aae0f KS |
9225 | /* Create a breakpoint with SAL as location. Use LOCATION |
9226 | as a description of the location, and COND_STRING | |
b35a8b2f DE |
9227 | as condition expression. If LOCATION is NULL then create an |
9228 | "address location" from the address in the SAL. */ | |
018d34a4 VP |
9229 | |
9230 | static void | |
d9b3f62e | 9231 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
f00aae0f KS |
9232 | struct symtabs_and_lines sals, |
9233 | struct event_location *location, | |
f8eba3c6 | 9234 | char *filter, char *cond_string, |
e7e0cddf | 9235 | char *extra_string, |
d9b3f62e PA |
9236 | enum bptype type, enum bpdisp disposition, |
9237 | int thread, int task, int ignore_count, | |
c0a91b2b | 9238 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9239 | int enabled, int internal, unsigned flags, |
9240 | int display_canonical) | |
018d34a4 | 9241 | { |
0d381245 | 9242 | int i; |
018d34a4 VP |
9243 | |
9244 | if (type == bp_hardware_breakpoint) | |
9245 | { | |
fbbd034e AS |
9246 | int target_resources_ok; |
9247 | ||
9248 | i = hw_breakpoint_used_count (); | |
9249 | target_resources_ok = | |
9250 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
018d34a4 VP |
9251 | i + 1, 0); |
9252 | if (target_resources_ok == 0) | |
9253 | error (_("No hardware breakpoint support in the target.")); | |
9254 | else if (target_resources_ok < 0) | |
9255 | error (_("Hardware breakpoints used exceeds limit.")); | |
9256 | } | |
9257 | ||
6c95b8df PA |
9258 | gdb_assert (sals.nelts > 0); |
9259 | ||
0d381245 VP |
9260 | for (i = 0; i < sals.nelts; ++i) |
9261 | { | |
9262 | struct symtab_and_line sal = sals.sals[i]; | |
9263 | struct bp_location *loc; | |
9264 | ||
9265 | if (from_tty) | |
5af949e3 UW |
9266 | { |
9267 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
9268 | if (!loc_gdbarch) | |
9269 | loc_gdbarch = gdbarch; | |
9270 | ||
9271 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 9272 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 9273 | } |
0d381245 VP |
9274 | |
9275 | if (i == 0) | |
9276 | { | |
d9b3f62e | 9277 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 9278 | b->thread = thread; |
4a306c9a | 9279 | b->task = task; |
855a6e68 | 9280 | |
0d381245 | 9281 | b->cond_string = cond_string; |
e7e0cddf | 9282 | b->extra_string = extra_string; |
0d381245 | 9283 | b->ignore_count = ignore_count; |
41447f92 | 9284 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 9285 | b->disposition = disposition; |
6c95b8df | 9286 | |
44f238bb PA |
9287 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9288 | b->loc->inserted = 1; | |
9289 | ||
0fb4aa4b PA |
9290 | if (type == bp_static_tracepoint) |
9291 | { | |
d9b3f62e | 9292 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
9293 | struct static_tracepoint_marker marker; |
9294 | ||
983af33b | 9295 | if (strace_marker_p (b)) |
0fb4aa4b PA |
9296 | { |
9297 | /* We already know the marker exists, otherwise, we | |
9298 | wouldn't see a sal for it. */ | |
f00aae0f KS |
9299 | const char *p = &event_location_to_string (b->location)[3]; |
9300 | const char *endp; | |
0fb4aa4b | 9301 | char *marker_str; |
0fb4aa4b | 9302 | |
f00aae0f | 9303 | p = skip_spaces_const (p); |
0fb4aa4b | 9304 | |
f00aae0f | 9305 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9306 | |
9307 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 9308 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 9309 | |
3e43a32a MS |
9310 | printf_filtered (_("Probed static tracepoint " |
9311 | "marker \"%s\"\n"), | |
d9b3f62e | 9312 | t->static_trace_marker_id); |
0fb4aa4b PA |
9313 | } |
9314 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
9315 | { | |
d9b3f62e | 9316 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
9317 | release_static_tracepoint_marker (&marker); |
9318 | ||
3e43a32a MS |
9319 | printf_filtered (_("Probed static tracepoint " |
9320 | "marker \"%s\"\n"), | |
d9b3f62e | 9321 | t->static_trace_marker_id); |
0fb4aa4b PA |
9322 | } |
9323 | else | |
3e43a32a MS |
9324 | warning (_("Couldn't determine the static " |
9325 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
9326 | } |
9327 | ||
0d381245 VP |
9328 | loc = b->loc; |
9329 | } | |
9330 | else | |
018d34a4 | 9331 | { |
39d61571 | 9332 | loc = add_location_to_breakpoint (b, &sal); |
44f238bb PA |
9333 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
9334 | loc->inserted = 1; | |
0d381245 VP |
9335 | } |
9336 | ||
9337 | if (b->cond_string) | |
9338 | { | |
bbc13ae3 KS |
9339 | const char *arg = b->cond_string; |
9340 | ||
1bb9788d TT |
9341 | loc->cond = parse_exp_1 (&arg, loc->address, |
9342 | block_for_pc (loc->address), 0); | |
0d381245 | 9343 | if (*arg) |
588ae58c | 9344 | error (_("Garbage '%s' follows condition"), arg); |
018d34a4 | 9345 | } |
e7e0cddf SS |
9346 | |
9347 | /* Dynamic printf requires and uses additional arguments on the | |
9348 | command line, otherwise it's an error. */ | |
9349 | if (type == bp_dprintf) | |
9350 | { | |
9351 | if (b->extra_string) | |
9352 | update_dprintf_command_list (b); | |
9353 | else | |
9354 | error (_("Format string required")); | |
9355 | } | |
9356 | else if (b->extra_string) | |
588ae58c | 9357 | error (_("Garbage '%s' at end of command"), b->extra_string); |
855a6e68 | 9358 | } |
018d34a4 | 9359 | |
56435ebe | 9360 | b->display_canonical = display_canonical; |
f00aae0f KS |
9361 | if (location != NULL) |
9362 | b->location = location; | |
018d34a4 | 9363 | else |
305e13e6 JB |
9364 | { |
9365 | const char *addr_string = NULL; | |
9366 | int addr_string_len = 0; | |
9367 | ||
9368 | if (location != NULL) | |
9369 | addr_string = event_location_to_string (location); | |
9370 | if (addr_string != NULL) | |
9371 | addr_string_len = strlen (addr_string); | |
9372 | ||
9373 | b->location = new_address_location (b->loc->address, | |
9374 | addr_string, addr_string_len); | |
9375 | } | |
f8eba3c6 | 9376 | b->filter = filter; |
d9b3f62e | 9377 | } |
018d34a4 | 9378 | |
d9b3f62e PA |
9379 | static void |
9380 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
f00aae0f KS |
9381 | struct symtabs_and_lines sals, |
9382 | struct event_location *location, | |
f8eba3c6 | 9383 | char *filter, char *cond_string, |
e7e0cddf | 9384 | char *extra_string, |
d9b3f62e PA |
9385 | enum bptype type, enum bpdisp disposition, |
9386 | int thread, int task, int ignore_count, | |
c0a91b2b | 9387 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb PA |
9388 | int enabled, int internal, unsigned flags, |
9389 | int display_canonical) | |
d9b3f62e PA |
9390 | { |
9391 | struct breakpoint *b; | |
9392 | struct cleanup *old_chain; | |
9393 | ||
9394 | if (is_tracepoint_type (type)) | |
9395 | { | |
9396 | struct tracepoint *t; | |
9397 | ||
9398 | t = XCNEW (struct tracepoint); | |
9399 | b = &t->base; | |
9400 | } | |
9401 | else | |
9402 | b = XNEW (struct breakpoint); | |
9403 | ||
9404 | old_chain = make_cleanup (xfree, b); | |
9405 | ||
9406 | init_breakpoint_sal (b, gdbarch, | |
f00aae0f | 9407 | sals, location, |
e7e0cddf | 9408 | filter, cond_string, extra_string, |
d9b3f62e PA |
9409 | type, disposition, |
9410 | thread, task, ignore_count, | |
9411 | ops, from_tty, | |
44f238bb PA |
9412 | enabled, internal, flags, |
9413 | display_canonical); | |
d9b3f62e PA |
9414 | discard_cleanups (old_chain); |
9415 | ||
3ea46bff | 9416 | install_breakpoint (internal, b, 0); |
018d34a4 VP |
9417 | } |
9418 | ||
9419 | /* Add SALS.nelts breakpoints to the breakpoint table. For each | |
9420 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
9421 | value. COND_STRING, if not NULL, specified the condition to be | |
9422 | used for all breakpoints. Essentially the only case where | |
9423 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
9424 | function. In that case, it's still not possible to specify | |
9425 | separate conditions for different overloaded functions, so | |
9426 | we take just a single condition string. | |
9427 | ||
c3f6f71d | 9428 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 9429 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
9430 | array contents). If the function fails (error() is called), the |
9431 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 9432 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
9433 | |
9434 | static void | |
8cdf0e15 | 9435 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 | 9436 | struct linespec_result *canonical, |
e7e0cddf | 9437 | char *cond_string, char *extra_string, |
8cdf0e15 VP |
9438 | enum bptype type, enum bpdisp disposition, |
9439 | int thread, int task, int ignore_count, | |
c0a91b2b | 9440 | const struct breakpoint_ops *ops, int from_tty, |
44f238bb | 9441 | int enabled, int internal, unsigned flags) |
c906108c | 9442 | { |
018d34a4 | 9443 | int i; |
f8eba3c6 | 9444 | struct linespec_sals *lsal; |
cc59ec59 | 9445 | |
f8eba3c6 TT |
9446 | if (canonical->pre_expanded) |
9447 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); | |
9448 | ||
9449 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) | |
c3f6f71d | 9450 | { |
f00aae0f | 9451 | /* Note that 'location' can be NULL in the case of a plain |
f8eba3c6 | 9452 | 'break', without arguments. */ |
f00aae0f KS |
9453 | struct event_location *location |
9454 | = (canonical->location != NULL | |
9455 | ? copy_event_location (canonical->location) : NULL); | |
f8eba3c6 | 9456 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
f00aae0f | 9457 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
0d381245 | 9458 | |
f8eba3c6 TT |
9459 | make_cleanup (xfree, filter_string); |
9460 | create_breakpoint_sal (gdbarch, lsal->sals, | |
f00aae0f | 9461 | location, |
f8eba3c6 | 9462 | filter_string, |
e7e0cddf SS |
9463 | cond_string, extra_string, |
9464 | type, disposition, | |
84f4c1fe | 9465 | thread, task, ignore_count, ops, |
44f238bb | 9466 | from_tty, enabled, internal, flags, |
56435ebe | 9467 | canonical->special_display); |
f8eba3c6 | 9468 | discard_cleanups (inner); |
c3f6f71d | 9469 | } |
c3f6f71d | 9470 | } |
c906108c | 9471 | |
f00aae0f | 9472 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
c3f6f71d | 9473 | followed by conditionals. On return, SALS contains an array of SAL |
f00aae0f KS |
9474 | addresses found. LOCATION points to the end of the SAL (for |
9475 | linespec locations). | |
9998af43 TJB |
9476 | |
9477 | The array and the line spec strings are allocated on the heap, it is | |
9478 | the caller's responsibility to free them. */ | |
c906108c | 9479 | |
b9362cc7 | 9480 | static void |
f00aae0f | 9481 | parse_breakpoint_sals (const struct event_location *location, |
58438ac1 | 9482 | struct linespec_result *canonical) |
c3f6f71d | 9483 | { |
f00aae0f KS |
9484 | struct symtab_and_line cursal; |
9485 | ||
9486 | if (event_location_type (location) == LINESPEC_LOCATION) | |
9487 | { | |
9488 | const char *address = get_linespec_location (location); | |
9489 | ||
9490 | if (address == NULL) | |
9491 | { | |
9492 | /* The last displayed codepoint, if it's valid, is our default | |
9493 | breakpoint address. */ | |
9494 | if (last_displayed_sal_is_valid ()) | |
9495 | { | |
9496 | struct linespec_sals lsal; | |
9497 | struct symtab_and_line sal; | |
9498 | CORE_ADDR pc; | |
9499 | ||
9500 | init_sal (&sal); /* Initialize to zeroes. */ | |
8d749320 | 9501 | lsal.sals.sals = XNEW (struct symtab_and_line); |
f00aae0f KS |
9502 | |
9503 | /* Set sal's pspace, pc, symtab, and line to the values | |
9504 | corresponding to the last call to print_frame_info. | |
9505 | Be sure to reinitialize LINE with NOTCURRENT == 0 | |
9506 | as the breakpoint line number is inappropriate otherwise. | |
9507 | find_pc_line would adjust PC, re-set it back. */ | |
9508 | get_last_displayed_sal (&sal); | |
9509 | pc = sal.pc; | |
9510 | sal = find_pc_line (pc, 0); | |
9511 | ||
9512 | /* "break" without arguments is equivalent to "break *PC" | |
9513 | where PC is the last displayed codepoint's address. So | |
9514 | make sure to set sal.explicit_pc to prevent GDB from | |
9515 | trying to expand the list of sals to include all other | |
9516 | instances with the same symtab and line. */ | |
9517 | sal.pc = pc; | |
9518 | sal.explicit_pc = 1; | |
9519 | ||
9520 | lsal.sals.sals[0] = sal; | |
9521 | lsal.sals.nelts = 1; | |
9522 | lsal.canonical = NULL; | |
9523 | ||
9524 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); | |
9525 | return; | |
9526 | } | |
9527 | else | |
9528 | error (_("No default breakpoint address now.")); | |
c906108c | 9529 | } |
c906108c | 9530 | } |
f00aae0f KS |
9531 | |
9532 | /* Force almost all breakpoints to be in terms of the | |
9533 | current_source_symtab (which is decode_line_1's default). | |
9534 | This should produce the results we want almost all of the | |
9535 | time while leaving default_breakpoint_* alone. | |
9536 | ||
9537 | ObjC: However, don't match an Objective-C method name which | |
9538 | may have a '+' or '-' succeeded by a '['. */ | |
9539 | cursal = get_current_source_symtab_and_line (); | |
9540 | if (last_displayed_sal_is_valid ()) | |
c906108c | 9541 | { |
f00aae0f | 9542 | const char *address = NULL; |
cc80f267 | 9543 | |
f00aae0f KS |
9544 | if (event_location_type (location) == LINESPEC_LOCATION) |
9545 | address = get_linespec_location (location); | |
cc80f267 | 9546 | |
f00aae0f KS |
9547 | if (!cursal.symtab |
9548 | || (address != NULL | |
9549 | && strchr ("+-", address[0]) != NULL | |
9550 | && address[1] != '[')) | |
9551 | { | |
c2f4122d | 9552 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f KS |
9553 | get_last_displayed_symtab (), |
9554 | get_last_displayed_line (), | |
9555 | canonical, NULL, NULL); | |
9556 | return; | |
9557 | } | |
c906108c | 9558 | } |
f00aae0f | 9559 | |
c2f4122d | 9560 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f00aae0f | 9561 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
c3f6f71d | 9562 | } |
c906108c | 9563 | |
c906108c | 9564 | |
c3f6f71d | 9565 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 9566 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 9567 | |
b9362cc7 | 9568 | static void |
23e7acfb | 9569 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
9570 | { |
9571 | int i; | |
cc59ec59 | 9572 | |
c3f6f71d | 9573 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 9574 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
9575 | } |
9576 | ||
7a697b8d SS |
9577 | /* Fast tracepoints may have restrictions on valid locations. For |
9578 | instance, a fast tracepoint using a jump instead of a trap will | |
9579 | likely have to overwrite more bytes than a trap would, and so can | |
9580 | only be placed where the instruction is longer than the jump, or a | |
9581 | multi-instruction sequence does not have a jump into the middle of | |
9582 | it, etc. */ | |
9583 | ||
9584 | static void | |
9585 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
9586 | struct symtabs_and_lines *sals) | |
9587 | { | |
9588 | int i, rslt; | |
9589 | struct symtab_and_line *sal; | |
9590 | char *msg; | |
9591 | struct cleanup *old_chain; | |
9592 | ||
9593 | for (i = 0; i < sals->nelts; i++) | |
9594 | { | |
f8eba3c6 TT |
9595 | struct gdbarch *sarch; |
9596 | ||
7a697b8d SS |
9597 | sal = &sals->sals[i]; |
9598 | ||
f8eba3c6 TT |
9599 | sarch = get_sal_arch (*sal); |
9600 | /* We fall back to GDBARCH if there is no architecture | |
9601 | associated with SAL. */ | |
9602 | if (sarch == NULL) | |
9603 | sarch = gdbarch; | |
6b940e6a | 9604 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
7a697b8d SS |
9605 | old_chain = make_cleanup (xfree, msg); |
9606 | ||
9607 | if (!rslt) | |
9608 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
f8eba3c6 | 9609 | paddress (sarch, sal->pc), (msg ? msg : "")); |
7a697b8d SS |
9610 | |
9611 | do_cleanups (old_chain); | |
9612 | } | |
9613 | } | |
9614 | ||
018d34a4 VP |
9615 | /* Given TOK, a string specification of condition and thread, as |
9616 | accepted by the 'break' command, extract the condition | |
9617 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 9618 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
9619 | If no condition is found, *COND_STRING is set to NULL. |
9620 | If no thread is found, *THREAD is set to -1. */ | |
d634f2de JB |
9621 | |
9622 | static void | |
bbc13ae3 | 9623 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
e7e0cddf SS |
9624 | char **cond_string, int *thread, int *task, |
9625 | char **rest) | |
018d34a4 VP |
9626 | { |
9627 | *cond_string = NULL; | |
9628 | *thread = -1; | |
ed1d1739 KS |
9629 | *task = 0; |
9630 | *rest = NULL; | |
9631 | ||
018d34a4 VP |
9632 | while (tok && *tok) |
9633 | { | |
bbc13ae3 | 9634 | const char *end_tok; |
018d34a4 | 9635 | int toklen; |
bbc13ae3 KS |
9636 | const char *cond_start = NULL; |
9637 | const char *cond_end = NULL; | |
cc59ec59 | 9638 | |
bbc13ae3 | 9639 | tok = skip_spaces_const (tok); |
e7e0cddf SS |
9640 | |
9641 | if ((*tok == '"' || *tok == ',') && rest) | |
9642 | { | |
9643 | *rest = savestring (tok, strlen (tok)); | |
9644 | return; | |
9645 | } | |
9646 | ||
bbc13ae3 | 9647 | end_tok = skip_to_space_const (tok); |
d634f2de | 9648 | |
018d34a4 | 9649 | toklen = end_tok - tok; |
d634f2de | 9650 | |
018d34a4 VP |
9651 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
9652 | { | |
f7545552 TT |
9653 | struct expression *expr; |
9654 | ||
018d34a4 | 9655 | tok = cond_start = end_tok + 1; |
1bb9788d | 9656 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
f7545552 | 9657 | xfree (expr); |
018d34a4 | 9658 | cond_end = tok; |
d634f2de | 9659 | *cond_string = savestring (cond_start, cond_end - cond_start); |
018d34a4 VP |
9660 | } |
9661 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
9662 | { | |
5d5658a1 PA |
9663 | const char *tmptok; |
9664 | struct thread_info *thr; | |
d634f2de | 9665 | |
018d34a4 | 9666 | tok = end_tok + 1; |
5d5658a1 | 9667 | thr = parse_thread_id (tok, &tmptok); |
018d34a4 VP |
9668 | if (tok == tmptok) |
9669 | error (_("Junk after thread keyword.")); | |
5d5658a1 | 9670 | *thread = thr->global_num; |
bbc13ae3 | 9671 | tok = tmptok; |
018d34a4 | 9672 | } |
4a306c9a JB |
9673 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
9674 | { | |
9675 | char *tmptok; | |
9676 | ||
9677 | tok = end_tok + 1; | |
bbc13ae3 | 9678 | *task = strtol (tok, &tmptok, 0); |
4a306c9a JB |
9679 | if (tok == tmptok) |
9680 | error (_("Junk after task keyword.")); | |
9681 | if (!valid_task_id (*task)) | |
b6199126 | 9682 | error (_("Unknown task %d."), *task); |
bbc13ae3 | 9683 | tok = tmptok; |
4a306c9a | 9684 | } |
e7e0cddf SS |
9685 | else if (rest) |
9686 | { | |
9687 | *rest = savestring (tok, strlen (tok)); | |
ccab2054 | 9688 | return; |
e7e0cddf | 9689 | } |
018d34a4 VP |
9690 | else |
9691 | error (_("Junk at end of arguments.")); | |
9692 | } | |
9693 | } | |
9694 | ||
0fb4aa4b PA |
9695 | /* Decode a static tracepoint marker spec. */ |
9696 | ||
9697 | static struct symtabs_and_lines | |
f00aae0f | 9698 | decode_static_tracepoint_spec (const char **arg_p) |
0fb4aa4b PA |
9699 | { |
9700 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
9701 | struct symtabs_and_lines sals; | |
0fb4aa4b | 9702 | struct cleanup *old_chain; |
f00aae0f KS |
9703 | const char *p = &(*arg_p)[3]; |
9704 | const char *endp; | |
0fb4aa4b PA |
9705 | char *marker_str; |
9706 | int i; | |
9707 | ||
f00aae0f | 9708 | p = skip_spaces_const (p); |
0fb4aa4b | 9709 | |
f00aae0f | 9710 | endp = skip_to_space_const (p); |
0fb4aa4b PA |
9711 | |
9712 | marker_str = savestring (p, endp - p); | |
9713 | old_chain = make_cleanup (xfree, marker_str); | |
9714 | ||
9715 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
9716 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
9717 | error (_("No known static tracepoint marker named %s"), marker_str); | |
9718 | ||
9719 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
8d749320 | 9720 | sals.sals = XNEWVEC (struct symtab_and_line, sals.nelts); |
0fb4aa4b PA |
9721 | |
9722 | for (i = 0; i < sals.nelts; i++) | |
9723 | { | |
9724 | struct static_tracepoint_marker *marker; | |
9725 | ||
9726 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
9727 | ||
9728 | init_sal (&sals.sals[i]); | |
9729 | ||
9730 | sals.sals[i] = find_pc_line (marker->address, 0); | |
9731 | sals.sals[i].pc = marker->address; | |
9732 | ||
9733 | release_static_tracepoint_marker (marker); | |
9734 | } | |
9735 | ||
9736 | do_cleanups (old_chain); | |
9737 | ||
9738 | *arg_p = endp; | |
9739 | return sals; | |
9740 | } | |
9741 | ||
f00aae0f | 9742 | /* See breakpoint.h. */ |
0101ce28 | 9743 | |
8cdf0e15 VP |
9744 | int |
9745 | create_breakpoint (struct gdbarch *gdbarch, | |
f00aae0f | 9746 | const struct event_location *location, char *cond_string, |
e7e0cddf | 9747 | int thread, char *extra_string, |
f00aae0f | 9748 | int parse_extra, |
0fb4aa4b | 9749 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
9750 | int ignore_count, |
9751 | enum auto_boolean pending_break_support, | |
c0a91b2b | 9752 | const struct breakpoint_ops *ops, |
44f238bb PA |
9753 | int from_tty, int enabled, int internal, |
9754 | unsigned flags) | |
c3f6f71d | 9755 | { |
7efd8fc2 | 9756 | struct linespec_result canonical; |
c3f6f71d | 9757 | struct cleanup *old_chain; |
80c99de1 | 9758 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 9759 | int pending = 0; |
4a306c9a | 9760 | int task = 0; |
86b17b60 | 9761 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 9762 | |
348d480f PA |
9763 | gdb_assert (ops != NULL); |
9764 | ||
f00aae0f KS |
9765 | /* If extra_string isn't useful, set it to NULL. */ |
9766 | if (extra_string != NULL && *extra_string == '\0') | |
9767 | extra_string = NULL; | |
9768 | ||
7efd8fc2 | 9769 | init_linespec_result (&canonical); |
c3f6f71d | 9770 | |
492d29ea | 9771 | TRY |
b78a6381 | 9772 | { |
f00aae0f | 9773 | ops->create_sals_from_location (location, &canonical, type_wanted); |
b78a6381 | 9774 | } |
492d29ea | 9775 | CATCH (e, RETURN_MASK_ERROR) |
0101ce28 | 9776 | { |
492d29ea PA |
9777 | /* If caller is interested in rc value from parse, set |
9778 | value. */ | |
9779 | if (e.error == NOT_FOUND_ERROR) | |
0101ce28 | 9780 | { |
05ff989b AC |
9781 | /* If pending breakpoint support is turned off, throw |
9782 | error. */ | |
fa8d40ab JJ |
9783 | |
9784 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
9785 | throw_exception (e); |
9786 | ||
9787 | exception_print (gdb_stderr, e); | |
fa8d40ab | 9788 | |
05ff989b AC |
9789 | /* If pending breakpoint support is auto query and the user |
9790 | selects no, then simply return the error code. */ | |
059fb39f | 9791 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
bfccc43c YQ |
9792 | && !nquery (_("Make %s pending on future shared library load? "), |
9793 | bptype_string (type_wanted))) | |
fd9b8c24 | 9794 | return 0; |
fa8d40ab | 9795 | |
05ff989b AC |
9796 | /* At this point, either the user was queried about setting |
9797 | a pending breakpoint and selected yes, or pending | |
9798 | breakpoint behavior is on and thus a pending breakpoint | |
9799 | is defaulted on behalf of the user. */ | |
f00aae0f | 9800 | pending = 1; |
0101ce28 | 9801 | } |
492d29ea PA |
9802 | else |
9803 | throw_exception (e); | |
0101ce28 | 9804 | } |
492d29ea PA |
9805 | END_CATCH |
9806 | ||
f00aae0f | 9807 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
492d29ea | 9808 | return 0; |
c3f6f71d | 9809 | |
4a64f543 | 9810 | /* Create a chain of things that always need to be cleaned up. */ |
f8eba3c6 | 9811 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
c3f6f71d | 9812 | |
c3f6f71d JM |
9813 | /* ----------------------------- SNIP ----------------------------- |
9814 | Anything added to the cleanup chain beyond this point is assumed | |
9815 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
9816 | then the memory is not reclaimed. */ |
9817 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 9818 | |
c3f6f71d JM |
9819 | /* Resolve all line numbers to PC's and verify that the addresses |
9820 | are ok for the target. */ | |
0101ce28 | 9821 | if (!pending) |
f8eba3c6 TT |
9822 | { |
9823 | int ix; | |
9824 | struct linespec_sals *iter; | |
9825 | ||
9826 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9827 | breakpoint_sals_to_pc (&iter->sals); | |
9828 | } | |
c3f6f71d | 9829 | |
7a697b8d | 9830 | /* Fast tracepoints may have additional restrictions on location. */ |
bfccc43c | 9831 | if (!pending && type_wanted == bp_fast_tracepoint) |
f8eba3c6 TT |
9832 | { |
9833 | int ix; | |
9834 | struct linespec_sals *iter; | |
9835 | ||
9836 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) | |
9837 | check_fast_tracepoint_sals (gdbarch, &iter->sals); | |
9838 | } | |
7a697b8d | 9839 | |
c3f6f71d JM |
9840 | /* Verify that condition can be parsed, before setting any |
9841 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 9842 | breakpoint. */ |
0101ce28 | 9843 | if (!pending) |
c3f6f71d | 9844 | { |
f00aae0f | 9845 | if (parse_extra) |
72b2ff0e | 9846 | { |
0878d0fa | 9847 | char *rest; |
52d361e1 YQ |
9848 | struct linespec_sals *lsal; |
9849 | ||
9850 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
9851 | ||
0878d0fa YQ |
9852 | /* Here we only parse 'arg' to separate condition |
9853 | from thread number, so parsing in context of first | |
9854 | sal is OK. When setting the breakpoint we'll | |
9855 | re-parse it in context of each sal. */ | |
9856 | ||
f00aae0f KS |
9857 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
9858 | &cond_string, &thread, &task, &rest); | |
0878d0fa YQ |
9859 | if (cond_string) |
9860 | make_cleanup (xfree, cond_string); | |
9861 | if (rest) | |
9862 | make_cleanup (xfree, rest); | |
9863 | if (rest) | |
9864 | extra_string = rest; | |
f00aae0f KS |
9865 | else |
9866 | extra_string = NULL; | |
72b2ff0e | 9867 | } |
2f069f6f | 9868 | else |
72b2ff0e | 9869 | { |
f00aae0f KS |
9870 | if (type_wanted != bp_dprintf |
9871 | && extra_string != NULL && *extra_string != '\0') | |
9872 | error (_("Garbage '%s' at end of location"), extra_string); | |
0878d0fa YQ |
9873 | |
9874 | /* Create a private copy of condition string. */ | |
9875 | if (cond_string) | |
9876 | { | |
9877 | cond_string = xstrdup (cond_string); | |
9878 | make_cleanup (xfree, cond_string); | |
9879 | } | |
9880 | /* Create a private copy of any extra string. */ | |
9881 | if (extra_string) | |
9882 | { | |
9883 | extra_string = xstrdup (extra_string); | |
9884 | make_cleanup (xfree, extra_string); | |
9885 | } | |
72b2ff0e | 9886 | } |
0fb4aa4b | 9887 | |
52d361e1 | 9888 | ops->create_breakpoints_sal (gdbarch, &canonical, |
e7e0cddf | 9889 | cond_string, extra_string, type_wanted, |
d9b3f62e PA |
9890 | tempflag ? disp_del : disp_donttouch, |
9891 | thread, task, ignore_count, ops, | |
44f238bb | 9892 | from_tty, enabled, internal, flags); |
c906108c | 9893 | } |
0101ce28 JJ |
9894 | else |
9895 | { | |
0101ce28 JJ |
9896 | struct breakpoint *b; |
9897 | ||
bfccc43c YQ |
9898 | if (is_tracepoint_type (type_wanted)) |
9899 | { | |
9900 | struct tracepoint *t; | |
9901 | ||
9902 | t = XCNEW (struct tracepoint); | |
9903 | b = &t->base; | |
9904 | } | |
9905 | else | |
9906 | b = XNEW (struct breakpoint); | |
9907 | ||
9908 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); | |
f00aae0f | 9909 | b->location = copy_event_location (location); |
bfccc43c | 9910 | |
f00aae0f KS |
9911 | if (parse_extra) |
9912 | b->cond_string = NULL; | |
e12c7713 MK |
9913 | else |
9914 | { | |
9915 | /* Create a private copy of condition string. */ | |
9916 | if (cond_string) | |
9917 | { | |
9918 | cond_string = xstrdup (cond_string); | |
9919 | make_cleanup (xfree, cond_string); | |
9920 | } | |
9921 | b->cond_string = cond_string; | |
15630549 | 9922 | b->thread = thread; |
e12c7713 | 9923 | } |
f00aae0f KS |
9924 | |
9925 | /* Create a private copy of any extra string. */ | |
9926 | if (extra_string != NULL) | |
9927 | { | |
9928 | extra_string = xstrdup (extra_string); | |
9929 | make_cleanup (xfree, extra_string); | |
9930 | } | |
9931 | b->extra_string = extra_string; | |
0101ce28 | 9932 | b->ignore_count = ignore_count; |
0101ce28 | 9933 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 9934 | b->condition_not_parsed = 1; |
41447f92 | 9935 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
cc72b2a2 KP |
9936 | if ((type_wanted != bp_breakpoint |
9937 | && type_wanted != bp_hardware_breakpoint) || thread != -1) | |
f8eba3c6 | 9938 | b->pspace = current_program_space; |
8bea4e01 | 9939 | |
bfccc43c | 9940 | install_breakpoint (internal, b, 0); |
0101ce28 JJ |
9941 | } |
9942 | ||
f8eba3c6 | 9943 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
95a42b64 | 9944 | { |
3e43a32a MS |
9945 | warning (_("Multiple breakpoints were set.\nUse the " |
9946 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 9947 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
9948 | } |
9949 | ||
80c99de1 PA |
9950 | /* That's it. Discard the cleanups for data inserted into the |
9951 | breakpoint. */ | |
9952 | discard_cleanups (bkpt_chain); | |
9953 | /* But cleanup everything else. */ | |
c3f6f71d | 9954 | do_cleanups (old_chain); |
217dc9e2 | 9955 | |
80c99de1 | 9956 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
44702360 | 9957 | update_global_location_list (UGLL_MAY_INSERT); |
fd9b8c24 PA |
9958 | |
9959 | return 1; | |
c3f6f71d | 9960 | } |
c906108c | 9961 | |
348d480f | 9962 | /* Set a breakpoint. |
72b2ff0e VP |
9963 | ARG is a string describing breakpoint address, |
9964 | condition, and thread. | |
9965 | FLAG specifies if a breakpoint is hardware on, | |
9966 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
9967 | and BP_TEMPFLAG. */ | |
348d480f | 9968 | |
98deb0da | 9969 | static void |
72b2ff0e | 9970 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 9971 | { |
72b2ff0e | 9972 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
9973 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
9974 | ? bp_hardware_breakpoint | |
9975 | : bp_breakpoint); | |
55aa24fb | 9976 | struct breakpoint_ops *ops; |
f00aae0f KS |
9977 | struct event_location *location; |
9978 | struct cleanup *cleanup; | |
9979 | ||
9980 | location = string_to_event_location (&arg, current_language); | |
9981 | cleanup = make_cleanup_delete_event_location (location); | |
55aa24fb SDJ |
9982 | |
9983 | /* Matching breakpoints on probes. */ | |
5b56227b KS |
9984 | if (location != NULL |
9985 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
9986 | ops = &bkpt_probe_breakpoint_ops; |
9987 | else | |
9988 | ops = &bkpt_breakpoint_ops; | |
c3f6f71d | 9989 | |
8cdf0e15 | 9990 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
9991 | location, |
9992 | NULL, 0, arg, 1 /* parse arg */, | |
0fb4aa4b | 9993 | tempflag, type_wanted, |
8cdf0e15 VP |
9994 | 0 /* Ignore count */, |
9995 | pending_break_support, | |
55aa24fb | 9996 | ops, |
8cdf0e15 | 9997 | from_tty, |
84f4c1fe | 9998 | 1 /* enabled */, |
44f238bb PA |
9999 | 0 /* internal */, |
10000 | 0); | |
f00aae0f | 10001 | do_cleanups (cleanup); |
c906108c SS |
10002 | } |
10003 | ||
c906108c SS |
10004 | /* Helper function for break_command_1 and disassemble_command. */ |
10005 | ||
10006 | void | |
fba45db2 | 10007 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
10008 | { |
10009 | CORE_ADDR pc; | |
10010 | ||
10011 | if (sal->pc == 0 && sal->symtab != NULL) | |
10012 | { | |
10013 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 10014 | error (_("No line %d in file \"%s\"."), |
05cba821 | 10015 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
c906108c | 10016 | sal->pc = pc; |
6a048695 | 10017 | |
4a64f543 MS |
10018 | /* If this SAL corresponds to a breakpoint inserted using a line |
10019 | number, then skip the function prologue if necessary. */ | |
6a048695 | 10020 | if (sal->explicit_line) |
059acae7 | 10021 | skip_prologue_sal (sal); |
c906108c SS |
10022 | } |
10023 | ||
10024 | if (sal->section == 0 && sal->symtab != NULL) | |
10025 | { | |
346d1dfe | 10026 | const struct blockvector *bv; |
3977b71f | 10027 | const struct block *b; |
c5aa993b | 10028 | struct symbol *sym; |
c906108c | 10029 | |
43f3e411 DE |
10030 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
10031 | SYMTAB_COMPUNIT (sal->symtab)); | |
c906108c SS |
10032 | if (bv != NULL) |
10033 | { | |
7f0df278 | 10034 | sym = block_linkage_function (b); |
c906108c SS |
10035 | if (sym != NULL) |
10036 | { | |
eb822aa6 DE |
10037 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
10038 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), | |
10039 | sym); | |
c906108c SS |
10040 | } |
10041 | else | |
10042 | { | |
4a64f543 MS |
10043 | /* It really is worthwhile to have the section, so we'll |
10044 | just have to look harder. This case can be executed | |
10045 | if we have line numbers but no functions (as can | |
10046 | happen in assembly source). */ | |
c906108c | 10047 | |
7cbd4a93 | 10048 | struct bound_minimal_symbol msym; |
6c95b8df PA |
10049 | struct cleanup *old_chain = save_current_space_and_thread (); |
10050 | ||
10051 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
10052 | |
10053 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7cbd4a93 | 10054 | if (msym.minsym) |
efd66ac6 | 10055 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
6c95b8df PA |
10056 | |
10057 | do_cleanups (old_chain); | |
c906108c SS |
10058 | } |
10059 | } | |
10060 | } | |
10061 | } | |
10062 | ||
10063 | void | |
fba45db2 | 10064 | break_command (char *arg, int from_tty) |
c906108c | 10065 | { |
db107f19 | 10066 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10067 | } |
10068 | ||
c906108c | 10069 | void |
fba45db2 | 10070 | tbreak_command (char *arg, int from_tty) |
c906108c | 10071 | { |
db107f19 | 10072 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
10073 | } |
10074 | ||
c906108c | 10075 | static void |
fba45db2 | 10076 | hbreak_command (char *arg, int from_tty) |
c906108c | 10077 | { |
db107f19 | 10078 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
10079 | } |
10080 | ||
10081 | static void | |
fba45db2 | 10082 | thbreak_command (char *arg, int from_tty) |
c906108c | 10083 | { |
db107f19 | 10084 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
10085 | } |
10086 | ||
10087 | static void | |
fba45db2 | 10088 | stop_command (char *arg, int from_tty) |
c906108c | 10089 | { |
a3f17187 | 10090 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 10091 | Usage: stop in <function | address>\n\ |
a3f17187 | 10092 | stop at <line>\n")); |
c906108c SS |
10093 | } |
10094 | ||
10095 | static void | |
fba45db2 | 10096 | stopin_command (char *arg, int from_tty) |
c906108c SS |
10097 | { |
10098 | int badInput = 0; | |
10099 | ||
c5aa993b | 10100 | if (arg == (char *) NULL) |
c906108c SS |
10101 | badInput = 1; |
10102 | else if (*arg != '*') | |
10103 | { | |
10104 | char *argptr = arg; | |
10105 | int hasColon = 0; | |
10106 | ||
4a64f543 | 10107 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 10108 | say it is bad, otherwise, it should be an address or |
4a64f543 | 10109 | function/method name. */ |
c906108c | 10110 | while (*argptr && !hasColon) |
c5aa993b JM |
10111 | { |
10112 | hasColon = (*argptr == ':'); | |
10113 | argptr++; | |
10114 | } | |
c906108c SS |
10115 | |
10116 | if (hasColon) | |
c5aa993b | 10117 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 10118 | else |
c5aa993b | 10119 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
10120 | } |
10121 | ||
10122 | if (badInput) | |
a3f17187 | 10123 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 10124 | else |
db107f19 | 10125 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10126 | } |
10127 | ||
10128 | static void | |
fba45db2 | 10129 | stopat_command (char *arg, int from_tty) |
c906108c SS |
10130 | { |
10131 | int badInput = 0; | |
10132 | ||
c5aa993b | 10133 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
10134 | badInput = 1; |
10135 | else | |
10136 | { | |
10137 | char *argptr = arg; | |
10138 | int hasColon = 0; | |
10139 | ||
4a64f543 MS |
10140 | /* Look for a ':'. If there is a '::' then get out, otherwise |
10141 | it is probably a line number. */ | |
c906108c | 10142 | while (*argptr && !hasColon) |
c5aa993b JM |
10143 | { |
10144 | hasColon = (*argptr == ':'); | |
10145 | argptr++; | |
10146 | } | |
c906108c SS |
10147 | |
10148 | if (hasColon) | |
c5aa993b | 10149 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 10150 | else |
c5aa993b | 10151 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
10152 | } |
10153 | ||
10154 | if (badInput) | |
a3f17187 | 10155 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 10156 | else |
db107f19 | 10157 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
10158 | } |
10159 | ||
e7e0cddf SS |
10160 | /* The dynamic printf command is mostly like a regular breakpoint, but |
10161 | with a prewired command list consisting of a single output command, | |
10162 | built from extra arguments supplied on the dprintf command | |
10163 | line. */ | |
10164 | ||
da821c7b | 10165 | static void |
e7e0cddf SS |
10166 | dprintf_command (char *arg, int from_tty) |
10167 | { | |
f00aae0f KS |
10168 | struct event_location *location; |
10169 | struct cleanup *cleanup; | |
10170 | ||
10171 | location = string_to_event_location (&arg, current_language); | |
10172 | cleanup = make_cleanup_delete_event_location (location); | |
10173 | ||
10174 | /* If non-NULL, ARG should have been advanced past the location; | |
10175 | the next character must be ','. */ | |
10176 | if (arg != NULL) | |
10177 | { | |
10178 | if (arg[0] != ',' || arg[1] == '\0') | |
10179 | error (_("Format string required")); | |
10180 | else | |
10181 | { | |
10182 | /* Skip the comma. */ | |
10183 | ++arg; | |
10184 | } | |
10185 | } | |
10186 | ||
e7e0cddf | 10187 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
10188 | location, |
10189 | NULL, 0, arg, 1 /* parse arg */, | |
e7e0cddf SS |
10190 | 0, bp_dprintf, |
10191 | 0 /* Ignore count */, | |
10192 | pending_break_support, | |
10193 | &dprintf_breakpoint_ops, | |
10194 | from_tty, | |
10195 | 1 /* enabled */, | |
10196 | 0 /* internal */, | |
10197 | 0); | |
f00aae0f | 10198 | do_cleanups (cleanup); |
e7e0cddf SS |
10199 | } |
10200 | ||
d3ce09f5 SS |
10201 | static void |
10202 | agent_printf_command (char *arg, int from_tty) | |
10203 | { | |
10204 | error (_("May only run agent-printf on the target")); | |
10205 | } | |
10206 | ||
f1310107 TJB |
10207 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
10208 | ranged breakpoints. */ | |
10209 | ||
10210 | static int | |
10211 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
10212 | struct address_space *aspace, | |
09ac7c10 TT |
10213 | CORE_ADDR bp_addr, |
10214 | const struct target_waitstatus *ws) | |
f1310107 | 10215 | { |
09ac7c10 | 10216 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 10217 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
10218 | return 0; |
10219 | ||
f1310107 TJB |
10220 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
10221 | bl->length, aspace, bp_addr); | |
10222 | } | |
10223 | ||
10224 | /* Implement the "resources_needed" breakpoint_ops method for | |
10225 | ranged breakpoints. */ | |
10226 | ||
10227 | static int | |
10228 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
10229 | { | |
10230 | return target_ranged_break_num_registers (); | |
10231 | } | |
10232 | ||
10233 | /* Implement the "print_it" breakpoint_ops method for | |
10234 | ranged breakpoints. */ | |
10235 | ||
10236 | static enum print_stop_action | |
348d480f | 10237 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 10238 | { |
348d480f | 10239 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 10240 | struct bp_location *bl = b->loc; |
79a45e25 | 10241 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10242 | |
10243 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10244 | ||
10245 | /* Ranged breakpoints have only one location. */ | |
10246 | gdb_assert (bl && bl->next == NULL); | |
10247 | ||
10248 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
10249 | |
10250 | maybe_print_thread_hit_breakpoint (uiout); | |
10251 | ||
f1310107 | 10252 | if (b->disposition == disp_del) |
f303dbd6 | 10253 | ui_out_text (uiout, "Temporary ranged breakpoint "); |
f1310107 | 10254 | else |
f303dbd6 | 10255 | ui_out_text (uiout, "Ranged breakpoint "); |
f1310107 TJB |
10256 | if (ui_out_is_mi_like_p (uiout)) |
10257 | { | |
10258 | ui_out_field_string (uiout, "reason", | |
10259 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10260 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
10261 | } | |
10262 | ui_out_field_int (uiout, "bkptno", b->number); | |
10263 | ui_out_text (uiout, ", "); | |
10264 | ||
10265 | return PRINT_SRC_AND_LOC; | |
10266 | } | |
10267 | ||
10268 | /* Implement the "print_one" breakpoint_ops method for | |
10269 | ranged breakpoints. */ | |
10270 | ||
10271 | static void | |
10272 | print_one_ranged_breakpoint (struct breakpoint *b, | |
10273 | struct bp_location **last_loc) | |
10274 | { | |
10275 | struct bp_location *bl = b->loc; | |
10276 | struct value_print_options opts; | |
79a45e25 | 10277 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10278 | |
10279 | /* Ranged breakpoints have only one location. */ | |
10280 | gdb_assert (bl && bl->next == NULL); | |
10281 | ||
10282 | get_user_print_options (&opts); | |
10283 | ||
10284 | if (opts.addressprint) | |
10285 | /* We don't print the address range here, it will be printed later | |
10286 | by print_one_detail_ranged_breakpoint. */ | |
10287 | ui_out_field_skip (uiout, "addr"); | |
10288 | annotate_field (5); | |
10289 | print_breakpoint_location (b, bl); | |
10290 | *last_loc = bl; | |
10291 | } | |
10292 | ||
10293 | /* Implement the "print_one_detail" breakpoint_ops method for | |
10294 | ranged breakpoints. */ | |
10295 | ||
10296 | static void | |
10297 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
10298 | struct ui_out *uiout) | |
10299 | { | |
10300 | CORE_ADDR address_start, address_end; | |
10301 | struct bp_location *bl = b->loc; | |
f99d8bf4 PA |
10302 | struct ui_file *stb = mem_fileopen (); |
10303 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); | |
f1310107 TJB |
10304 | |
10305 | gdb_assert (bl); | |
10306 | ||
10307 | address_start = bl->address; | |
10308 | address_end = address_start + bl->length - 1; | |
10309 | ||
10310 | ui_out_text (uiout, "\taddress range: "); | |
f99d8bf4 | 10311 | fprintf_unfiltered (stb, "[%s, %s]", |
f1310107 TJB |
10312 | print_core_address (bl->gdbarch, address_start), |
10313 | print_core_address (bl->gdbarch, address_end)); | |
10314 | ui_out_field_stream (uiout, "addr", stb); | |
10315 | ui_out_text (uiout, "\n"); | |
10316 | ||
10317 | do_cleanups (cleanup); | |
10318 | } | |
10319 | ||
10320 | /* Implement the "print_mention" breakpoint_ops method for | |
10321 | ranged breakpoints. */ | |
10322 | ||
10323 | static void | |
10324 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
10325 | { | |
10326 | struct bp_location *bl = b->loc; | |
79a45e25 | 10327 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
10328 | |
10329 | gdb_assert (bl); | |
10330 | gdb_assert (b->type == bp_hardware_breakpoint); | |
10331 | ||
10332 | if (ui_out_is_mi_like_p (uiout)) | |
10333 | return; | |
10334 | ||
10335 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
10336 | b->number, paddress (bl->gdbarch, bl->address), | |
10337 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
10338 | } | |
10339 | ||
10340 | /* Implement the "print_recreate" breakpoint_ops method for | |
10341 | ranged breakpoints. */ | |
10342 | ||
10343 | static void | |
10344 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
10345 | { | |
f00aae0f KS |
10346 | fprintf_unfiltered (fp, "break-range %s, %s", |
10347 | event_location_to_string (b->location), | |
10348 | event_location_to_string (b->location_range_end)); | |
d9b3f62e | 10349 | print_recreate_thread (b, fp); |
f1310107 TJB |
10350 | } |
10351 | ||
10352 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
10353 | ||
2060206e | 10354 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
10355 | |
10356 | /* Find the address where the end of the breakpoint range should be | |
10357 | placed, given the SAL of the end of the range. This is so that if | |
10358 | the user provides a line number, the end of the range is set to the | |
10359 | last instruction of the given line. */ | |
10360 | ||
10361 | static CORE_ADDR | |
10362 | find_breakpoint_range_end (struct symtab_and_line sal) | |
10363 | { | |
10364 | CORE_ADDR end; | |
10365 | ||
10366 | /* If the user provided a PC value, use it. Otherwise, | |
10367 | find the address of the end of the given location. */ | |
10368 | if (sal.explicit_pc) | |
10369 | end = sal.pc; | |
10370 | else | |
10371 | { | |
10372 | int ret; | |
10373 | CORE_ADDR start; | |
10374 | ||
10375 | ret = find_line_pc_range (sal, &start, &end); | |
10376 | if (!ret) | |
10377 | error (_("Could not find location of the end of the range.")); | |
10378 | ||
10379 | /* find_line_pc_range returns the start of the next line. */ | |
10380 | end--; | |
10381 | } | |
10382 | ||
10383 | return end; | |
10384 | } | |
10385 | ||
10386 | /* Implement the "break-range" CLI command. */ | |
10387 | ||
10388 | static void | |
10389 | break_range_command (char *arg, int from_tty) | |
10390 | { | |
10391 | char *arg_start, *addr_string_start, *addr_string_end; | |
10392 | struct linespec_result canonical_start, canonical_end; | |
10393 | int bp_count, can_use_bp, length; | |
10394 | CORE_ADDR end; | |
10395 | struct breakpoint *b; | |
10396 | struct symtab_and_line sal_start, sal_end; | |
f1310107 | 10397 | struct cleanup *cleanup_bkpt; |
f8eba3c6 | 10398 | struct linespec_sals *lsal_start, *lsal_end; |
f00aae0f | 10399 | struct event_location *start_location, *end_location; |
f1310107 TJB |
10400 | |
10401 | /* We don't support software ranged breakpoints. */ | |
10402 | if (target_ranged_break_num_registers () < 0) | |
10403 | error (_("This target does not support hardware ranged breakpoints.")); | |
10404 | ||
10405 | bp_count = hw_breakpoint_used_count (); | |
10406 | bp_count += target_ranged_break_num_registers (); | |
10407 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
10408 | bp_count, 0); | |
10409 | if (can_use_bp < 0) | |
10410 | error (_("Hardware breakpoints used exceeds limit.")); | |
10411 | ||
f8eba3c6 | 10412 | arg = skip_spaces (arg); |
f1310107 TJB |
10413 | if (arg == NULL || arg[0] == '\0') |
10414 | error(_("No address range specified.")); | |
10415 | ||
f1310107 TJB |
10416 | init_linespec_result (&canonical_start); |
10417 | ||
f8eba3c6 | 10418 | arg_start = arg; |
f00aae0f KS |
10419 | start_location = string_to_event_location (&arg, current_language); |
10420 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); | |
10421 | parse_breakpoint_sals (start_location, &canonical_start); | |
10422 | make_cleanup_destroy_linespec_result (&canonical_start); | |
f1310107 TJB |
10423 | |
10424 | if (arg[0] != ',') | |
10425 | error (_("Too few arguments.")); | |
f8eba3c6 | 10426 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
f1310107 | 10427 | error (_("Could not find location of the beginning of the range.")); |
f8eba3c6 TT |
10428 | |
10429 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); | |
10430 | ||
10431 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 | |
10432 | || lsal_start->sals.nelts != 1) | |
f1310107 TJB |
10433 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10434 | ||
f8eba3c6 TT |
10435 | sal_start = lsal_start->sals.sals[0]; |
10436 | addr_string_start = savestring (arg_start, arg - arg_start); | |
10437 | make_cleanup (xfree, addr_string_start); | |
f1310107 TJB |
10438 | |
10439 | arg++; /* Skip the comma. */ | |
f8eba3c6 | 10440 | arg = skip_spaces (arg); |
f1310107 TJB |
10441 | |
10442 | /* Parse the end location. */ | |
10443 | ||
f1310107 TJB |
10444 | init_linespec_result (&canonical_end); |
10445 | arg_start = arg; | |
10446 | ||
f8eba3c6 | 10447 | /* We call decode_line_full directly here instead of using |
f1310107 TJB |
10448 | parse_breakpoint_sals because we need to specify the start location's |
10449 | symtab and line as the default symtab and line for the end of the | |
10450 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
10451 | where +14 means 14 lines from the start location. */ | |
f00aae0f KS |
10452 | end_location = string_to_event_location (&arg, current_language); |
10453 | make_cleanup_delete_event_location (end_location); | |
c2f4122d | 10454 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, NULL, |
f8eba3c6 TT |
10455 | sal_start.symtab, sal_start.line, |
10456 | &canonical_end, NULL, NULL); | |
10457 | ||
10458 | make_cleanup_destroy_linespec_result (&canonical_end); | |
f1310107 | 10459 | |
f8eba3c6 | 10460 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
f1310107 | 10461 | error (_("Could not find location of the end of the range.")); |
f8eba3c6 TT |
10462 | |
10463 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); | |
10464 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 | |
10465 | || lsal_end->sals.nelts != 1) | |
f1310107 TJB |
10466 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
10467 | ||
f8eba3c6 | 10468 | sal_end = lsal_end->sals.sals[0]; |
f1310107 TJB |
10469 | |
10470 | end = find_breakpoint_range_end (sal_end); | |
10471 | if (sal_start.pc > end) | |
177b42fe | 10472 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
10473 | |
10474 | length = end - sal_start.pc + 1; | |
10475 | if (length < 0) | |
10476 | /* Length overflowed. */ | |
10477 | error (_("Address range too large.")); | |
10478 | else if (length == 1) | |
10479 | { | |
10480 | /* This range is simple enough to be handled by | |
10481 | the `hbreak' command. */ | |
10482 | hbreak_command (addr_string_start, 1); | |
10483 | ||
10484 | do_cleanups (cleanup_bkpt); | |
10485 | ||
10486 | return; | |
10487 | } | |
10488 | ||
10489 | /* Now set up the breakpoint. */ | |
10490 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 10491 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
10492 | set_breakpoint_count (breakpoint_count + 1); |
10493 | b->number = breakpoint_count; | |
10494 | b->disposition = disp_donttouch; | |
f00aae0f KS |
10495 | b->location = copy_event_location (start_location); |
10496 | b->location_range_end = copy_event_location (end_location); | |
f1310107 TJB |
10497 | b->loc->length = length; |
10498 | ||
f8eba3c6 | 10499 | do_cleanups (cleanup_bkpt); |
f1310107 TJB |
10500 | |
10501 | mention (b); | |
8d3788bd | 10502 | observer_notify_breakpoint_created (b); |
44702360 | 10503 | update_global_location_list (UGLL_MAY_INSERT); |
f1310107 TJB |
10504 | } |
10505 | ||
4a64f543 MS |
10506 | /* Return non-zero if EXP is verified as constant. Returned zero |
10507 | means EXP is variable. Also the constant detection may fail for | |
10508 | some constant expressions and in such case still falsely return | |
10509 | zero. */ | |
2e6e3d9c | 10510 | |
65d79d4b SDJ |
10511 | static int |
10512 | watchpoint_exp_is_const (const struct expression *exp) | |
10513 | { | |
10514 | int i = exp->nelts; | |
10515 | ||
10516 | while (i > 0) | |
10517 | { | |
10518 | int oplenp, argsp; | |
10519 | ||
10520 | /* We are only interested in the descriptor of each element. */ | |
10521 | operator_length (exp, i, &oplenp, &argsp); | |
10522 | i -= oplenp; | |
10523 | ||
10524 | switch (exp->elts[i].opcode) | |
10525 | { | |
10526 | case BINOP_ADD: | |
10527 | case BINOP_SUB: | |
10528 | case BINOP_MUL: | |
10529 | case BINOP_DIV: | |
10530 | case BINOP_REM: | |
10531 | case BINOP_MOD: | |
10532 | case BINOP_LSH: | |
10533 | case BINOP_RSH: | |
10534 | case BINOP_LOGICAL_AND: | |
10535 | case BINOP_LOGICAL_OR: | |
10536 | case BINOP_BITWISE_AND: | |
10537 | case BINOP_BITWISE_IOR: | |
10538 | case BINOP_BITWISE_XOR: | |
10539 | case BINOP_EQUAL: | |
10540 | case BINOP_NOTEQUAL: | |
10541 | case BINOP_LESS: | |
10542 | case BINOP_GTR: | |
10543 | case BINOP_LEQ: | |
10544 | case BINOP_GEQ: | |
10545 | case BINOP_REPEAT: | |
10546 | case BINOP_COMMA: | |
10547 | case BINOP_EXP: | |
10548 | case BINOP_MIN: | |
10549 | case BINOP_MAX: | |
10550 | case BINOP_INTDIV: | |
10551 | case BINOP_CONCAT: | |
65d79d4b SDJ |
10552 | case TERNOP_COND: |
10553 | case TERNOP_SLICE: | |
65d79d4b SDJ |
10554 | |
10555 | case OP_LONG: | |
10556 | case OP_DOUBLE: | |
10557 | case OP_DECFLOAT: | |
10558 | case OP_LAST: | |
10559 | case OP_COMPLEX: | |
10560 | case OP_STRING: | |
65d79d4b SDJ |
10561 | case OP_ARRAY: |
10562 | case OP_TYPE: | |
608b4967 TT |
10563 | case OP_TYPEOF: |
10564 | case OP_DECLTYPE: | |
6e72ca20 | 10565 | case OP_TYPEID: |
65d79d4b SDJ |
10566 | case OP_NAME: |
10567 | case OP_OBJC_NSSTRING: | |
10568 | ||
10569 | case UNOP_NEG: | |
10570 | case UNOP_LOGICAL_NOT: | |
10571 | case UNOP_COMPLEMENT: | |
10572 | case UNOP_ADDR: | |
10573 | case UNOP_HIGH: | |
aeaa2474 | 10574 | case UNOP_CAST: |
9eaf6705 TT |
10575 | |
10576 | case UNOP_CAST_TYPE: | |
10577 | case UNOP_REINTERPRET_CAST: | |
10578 | case UNOP_DYNAMIC_CAST: | |
4a64f543 MS |
10579 | /* Unary, binary and ternary operators: We have to check |
10580 | their operands. If they are constant, then so is the | |
10581 | result of that operation. For instance, if A and B are | |
10582 | determined to be constants, then so is "A + B". | |
10583 | ||
10584 | UNOP_IND is one exception to the rule above, because the | |
10585 | value of *ADDR is not necessarily a constant, even when | |
10586 | ADDR is. */ | |
65d79d4b SDJ |
10587 | break; |
10588 | ||
10589 | case OP_VAR_VALUE: | |
10590 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 10591 | |
65d79d4b | 10592 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
10593 | possible that a buggy compiler could mark a variable as |
10594 | constant even when it is not, and TYPE_CONST would return | |
10595 | true in this case, while SYMBOL_CLASS wouldn't. | |
10596 | ||
10597 | We also have to check for function symbols because they | |
10598 | are always constant. */ | |
65d79d4b SDJ |
10599 | { |
10600 | struct symbol *s = exp->elts[i + 2].symbol; | |
10601 | ||
10602 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
10603 | && SYMBOL_CLASS (s) != LOC_CONST | |
10604 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
10605 | return 0; | |
10606 | break; | |
10607 | } | |
10608 | ||
10609 | /* The default action is to return 0 because we are using | |
10610 | the optimistic approach here: If we don't know something, | |
10611 | then it is not a constant. */ | |
10612 | default: | |
10613 | return 0; | |
10614 | } | |
10615 | } | |
10616 | ||
10617 | return 1; | |
10618 | } | |
10619 | ||
3a5c3e22 PA |
10620 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
10621 | ||
10622 | static void | |
10623 | dtor_watchpoint (struct breakpoint *self) | |
10624 | { | |
10625 | struct watchpoint *w = (struct watchpoint *) self; | |
10626 | ||
10627 | xfree (w->cond_exp); | |
10628 | xfree (w->exp); | |
10629 | xfree (w->exp_string); | |
10630 | xfree (w->exp_string_reparse); | |
10631 | value_free (w->val); | |
10632 | ||
10633 | base_breakpoint_ops.dtor (self); | |
10634 | } | |
10635 | ||
348d480f PA |
10636 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
10637 | ||
10638 | static void | |
10639 | re_set_watchpoint (struct breakpoint *b) | |
10640 | { | |
3a5c3e22 PA |
10641 | struct watchpoint *w = (struct watchpoint *) b; |
10642 | ||
348d480f PA |
10643 | /* Watchpoint can be either on expression using entirely global |
10644 | variables, or it can be on local variables. | |
10645 | ||
10646 | Watchpoints of the first kind are never auto-deleted, and even | |
10647 | persist across program restarts. Since they can use variables | |
10648 | from shared libraries, we need to reparse expression as libraries | |
10649 | are loaded and unloaded. | |
10650 | ||
10651 | Watchpoints on local variables can also change meaning as result | |
10652 | of solib event. For example, if a watchpoint uses both a local | |
10653 | and a global variables in expression, it's a local watchpoint, | |
10654 | but unloading of a shared library will make the expression | |
10655 | invalid. This is not a very common use case, but we still | |
10656 | re-evaluate expression, to avoid surprises to the user. | |
10657 | ||
10658 | Note that for local watchpoints, we re-evaluate it only if | |
10659 | watchpoints frame id is still valid. If it's not, it means the | |
10660 | watchpoint is out of scope and will be deleted soon. In fact, | |
10661 | I'm not sure we'll ever be called in this case. | |
10662 | ||
10663 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 10664 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 10665 | |
3a5c3e22 PA |
10666 | Don't do anything about disabled watchpoints, since they will be |
10667 | reevaluated again when enabled. */ | |
10668 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
10669 | } |
10670 | ||
77b06cd7 TJB |
10671 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
10672 | ||
10673 | static int | |
10674 | insert_watchpoint (struct bp_location *bl) | |
10675 | { | |
3a5c3e22 PA |
10676 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10677 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10678 | |
10679 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10680 | w->cond_exp); |
77b06cd7 TJB |
10681 | } |
10682 | ||
10683 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
10684 | ||
10685 | static int | |
10686 | remove_watchpoint (struct bp_location *bl) | |
10687 | { | |
3a5c3e22 PA |
10688 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10689 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
10690 | |
10691 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 10692 | w->cond_exp); |
e09342b5 TJB |
10693 | } |
10694 | ||
e09342b5 | 10695 | static int |
348d480f | 10696 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
09ac7c10 TT |
10697 | struct address_space *aspace, CORE_ADDR bp_addr, |
10698 | const struct target_waitstatus *ws) | |
e09342b5 | 10699 | { |
348d480f | 10700 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 10701 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 10702 | |
348d480f PA |
10703 | /* Continuable hardware watchpoints are treated as non-existent if the |
10704 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
10705 | some data address). Otherwise gdb won't stop on a break instruction | |
10706 | in the code (not from a breakpoint) when a hardware watchpoint has | |
10707 | been defined. Also skip watchpoints which we know did not trigger | |
10708 | (did not match the data address). */ | |
10709 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 10710 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 10711 | return 0; |
9c06b0b4 | 10712 | |
348d480f | 10713 | return 1; |
9c06b0b4 TJB |
10714 | } |
10715 | ||
348d480f PA |
10716 | static void |
10717 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 10718 | { |
348d480f | 10719 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 10720 | |
348d480f | 10721 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
10722 | } |
10723 | ||
10724 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 10725 | hardware watchpoints. */ |
9c06b0b4 TJB |
10726 | |
10727 | static int | |
348d480f | 10728 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 10729 | { |
3a5c3e22 PA |
10730 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10731 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
10732 | |
10733 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
10734 | } |
10735 | ||
10736 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 10737 | hardware watchpoints. */ |
9c06b0b4 TJB |
10738 | |
10739 | static int | |
348d480f | 10740 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 10741 | { |
efa80663 PA |
10742 | /* Read and access watchpoints only work with hardware support. */ |
10743 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
10744 | } |
10745 | ||
9c06b0b4 | 10746 | static enum print_stop_action |
348d480f | 10747 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 10748 | { |
348d480f PA |
10749 | struct cleanup *old_chain; |
10750 | struct breakpoint *b; | |
f99d8bf4 | 10751 | struct ui_file *stb; |
348d480f | 10752 | enum print_stop_action result; |
3a5c3e22 | 10753 | struct watchpoint *w; |
79a45e25 | 10754 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10755 | |
10756 | gdb_assert (bs->bp_location_at != NULL); | |
10757 | ||
348d480f | 10758 | b = bs->breakpoint_at; |
3a5c3e22 | 10759 | w = (struct watchpoint *) b; |
348d480f | 10760 | |
f99d8bf4 PA |
10761 | stb = mem_fileopen (); |
10762 | old_chain = make_cleanup_ui_file_delete (stb); | |
9c06b0b4 | 10763 | |
f303dbd6 PA |
10764 | annotate_watchpoint (b->number); |
10765 | maybe_print_thread_hit_breakpoint (uiout); | |
10766 | ||
9c06b0b4 TJB |
10767 | switch (b->type) |
10768 | { | |
348d480f | 10769 | case bp_watchpoint: |
9c06b0b4 | 10770 | case bp_hardware_watchpoint: |
9c06b0b4 TJB |
10771 | if (ui_out_is_mi_like_p (uiout)) |
10772 | ui_out_field_string | |
10773 | (uiout, "reason", | |
10774 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10775 | mention (b); |
10776 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10777 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10778 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10779 | ui_out_field_stream (uiout, "old", stb); |
10780 | ui_out_text (uiout, "\nNew value = "); | |
f99d8bf4 | 10781 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10782 | ui_out_field_stream (uiout, "new", stb); |
10783 | ui_out_text (uiout, "\n"); | |
10784 | /* More than one watchpoint may have been triggered. */ | |
10785 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10786 | break; |
10787 | ||
10788 | case bp_read_watchpoint: | |
10789 | if (ui_out_is_mi_like_p (uiout)) | |
10790 | ui_out_field_string | |
10791 | (uiout, "reason", | |
10792 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
10793 | mention (b); |
10794 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10795 | ui_out_text (uiout, "\nValue = "); | |
f99d8bf4 | 10796 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10797 | ui_out_field_stream (uiout, "value", stb); |
10798 | ui_out_text (uiout, "\n"); | |
10799 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10800 | break; |
10801 | ||
10802 | case bp_access_watchpoint: | |
348d480f PA |
10803 | if (bs->old_val != NULL) |
10804 | { | |
348d480f PA |
10805 | if (ui_out_is_mi_like_p (uiout)) |
10806 | ui_out_field_string | |
10807 | (uiout, "reason", | |
10808 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10809 | mention (b); | |
10810 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10811 | ui_out_text (uiout, "\nOld value = "); | |
f99d8bf4 | 10812 | watchpoint_value_print (bs->old_val, stb); |
348d480f PA |
10813 | ui_out_field_stream (uiout, "old", stb); |
10814 | ui_out_text (uiout, "\nNew value = "); | |
10815 | } | |
10816 | else | |
10817 | { | |
10818 | mention (b); | |
10819 | if (ui_out_is_mi_like_p (uiout)) | |
10820 | ui_out_field_string | |
10821 | (uiout, "reason", | |
10822 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
10823 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
10824 | ui_out_text (uiout, "\nValue = "); | |
10825 | } | |
f99d8bf4 | 10826 | watchpoint_value_print (w->val, stb); |
348d480f PA |
10827 | ui_out_field_stream (uiout, "new", stb); |
10828 | ui_out_text (uiout, "\n"); | |
10829 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
10830 | break; |
10831 | default: | |
348d480f | 10832 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
10833 | } |
10834 | ||
348d480f PA |
10835 | do_cleanups (old_chain); |
10836 | return result; | |
10837 | } | |
10838 | ||
10839 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
10840 | watchpoints. */ | |
10841 | ||
10842 | static void | |
10843 | print_mention_watchpoint (struct breakpoint *b) | |
10844 | { | |
10845 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 10846 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 10847 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10848 | |
10849 | switch (b->type) | |
10850 | { | |
10851 | case bp_watchpoint: | |
10852 | ui_out_text (uiout, "Watchpoint "); | |
10853 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10854 | break; | |
10855 | case bp_hardware_watchpoint: | |
10856 | ui_out_text (uiout, "Hardware watchpoint "); | |
10857 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
10858 | break; | |
10859 | case bp_read_watchpoint: | |
10860 | ui_out_text (uiout, "Hardware read watchpoint "); | |
10861 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
10862 | break; | |
10863 | case bp_access_watchpoint: | |
10864 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
10865 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
10866 | break; | |
10867 | default: | |
10868 | internal_error (__FILE__, __LINE__, | |
10869 | _("Invalid hardware watchpoint type.")); | |
10870 | } | |
10871 | ||
10872 | ui_out_field_int (uiout, "number", b->number); | |
10873 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 10874 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
10875 | do_cleanups (ui_out_chain); |
10876 | } | |
10877 | ||
10878 | /* Implement the "print_recreate" breakpoint_ops method for | |
10879 | watchpoints. */ | |
10880 | ||
10881 | static void | |
10882 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
10883 | { | |
3a5c3e22 PA |
10884 | struct watchpoint *w = (struct watchpoint *) b; |
10885 | ||
348d480f PA |
10886 | switch (b->type) |
10887 | { | |
10888 | case bp_watchpoint: | |
10889 | case bp_hardware_watchpoint: | |
10890 | fprintf_unfiltered (fp, "watch"); | |
10891 | break; | |
10892 | case bp_read_watchpoint: | |
10893 | fprintf_unfiltered (fp, "rwatch"); | |
10894 | break; | |
10895 | case bp_access_watchpoint: | |
10896 | fprintf_unfiltered (fp, "awatch"); | |
10897 | break; | |
10898 | default: | |
10899 | internal_error (__FILE__, __LINE__, | |
10900 | _("Invalid watchpoint type.")); | |
10901 | } | |
10902 | ||
3a5c3e22 | 10903 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 10904 | print_recreate_thread (b, fp); |
348d480f PA |
10905 | } |
10906 | ||
427cd150 TT |
10907 | /* Implement the "explains_signal" breakpoint_ops method for |
10908 | watchpoints. */ | |
10909 | ||
47591c29 | 10910 | static int |
427cd150 TT |
10911 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
10912 | { | |
10913 | /* A software watchpoint cannot cause a signal other than | |
10914 | GDB_SIGNAL_TRAP. */ | |
10915 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) | |
47591c29 | 10916 | return 0; |
427cd150 | 10917 | |
47591c29 | 10918 | return 1; |
427cd150 TT |
10919 | } |
10920 | ||
348d480f PA |
10921 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
10922 | ||
2060206e | 10923 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
10924 | |
10925 | /* Implement the "insert" breakpoint_ops method for | |
10926 | masked hardware watchpoints. */ | |
10927 | ||
10928 | static int | |
10929 | insert_masked_watchpoint (struct bp_location *bl) | |
10930 | { | |
3a5c3e22 PA |
10931 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10932 | ||
10933 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10934 | bl->watchpoint_type); |
10935 | } | |
10936 | ||
10937 | /* Implement the "remove" breakpoint_ops method for | |
10938 | masked hardware watchpoints. */ | |
10939 | ||
10940 | static int | |
10941 | remove_masked_watchpoint (struct bp_location *bl) | |
10942 | { | |
3a5c3e22 PA |
10943 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10944 | ||
10945 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
10946 | bl->watchpoint_type); |
10947 | } | |
10948 | ||
10949 | /* Implement the "resources_needed" breakpoint_ops method for | |
10950 | masked hardware watchpoints. */ | |
10951 | ||
10952 | static int | |
10953 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
10954 | { | |
3a5c3e22 PA |
10955 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
10956 | ||
10957 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
10958 | } |
10959 | ||
10960 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
10961 | masked hardware watchpoints. */ | |
10962 | ||
10963 | static int | |
10964 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
10965 | { | |
10966 | return 0; | |
10967 | } | |
10968 | ||
10969 | /* Implement the "print_it" breakpoint_ops method for | |
10970 | masked hardware watchpoints. */ | |
10971 | ||
10972 | static enum print_stop_action | |
10973 | print_it_masked_watchpoint (bpstat bs) | |
10974 | { | |
10975 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 10976 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10977 | |
10978 | /* Masked watchpoints have only one location. */ | |
10979 | gdb_assert (b->loc && b->loc->next == NULL); | |
10980 | ||
f303dbd6 PA |
10981 | annotate_watchpoint (b->number); |
10982 | maybe_print_thread_hit_breakpoint (uiout); | |
10983 | ||
348d480f PA |
10984 | switch (b->type) |
10985 | { | |
10986 | case bp_hardware_watchpoint: | |
348d480f PA |
10987 | if (ui_out_is_mi_like_p (uiout)) |
10988 | ui_out_field_string | |
10989 | (uiout, "reason", | |
10990 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
10991 | break; | |
10992 | ||
10993 | case bp_read_watchpoint: | |
10994 | if (ui_out_is_mi_like_p (uiout)) | |
10995 | ui_out_field_string | |
10996 | (uiout, "reason", | |
10997 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
10998 | break; | |
10999 | ||
11000 | case bp_access_watchpoint: | |
11001 | if (ui_out_is_mi_like_p (uiout)) | |
11002 | ui_out_field_string | |
11003 | (uiout, "reason", | |
11004 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
11005 | break; | |
11006 | default: | |
11007 | internal_error (__FILE__, __LINE__, | |
11008 | _("Invalid hardware watchpoint type.")); | |
11009 | } | |
11010 | ||
11011 | mention (b); | |
9c06b0b4 TJB |
11012 | ui_out_text (uiout, _("\n\ |
11013 | Check the underlying instruction at PC for the memory\n\ | |
11014 | address and value which triggered this watchpoint.\n")); | |
11015 | ui_out_text (uiout, "\n"); | |
11016 | ||
11017 | /* More than one watchpoint may have been triggered. */ | |
11018 | return PRINT_UNKNOWN; | |
11019 | } | |
11020 | ||
11021 | /* Implement the "print_one_detail" breakpoint_ops method for | |
11022 | masked hardware watchpoints. */ | |
11023 | ||
11024 | static void | |
11025 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
11026 | struct ui_out *uiout) | |
11027 | { | |
3a5c3e22 PA |
11028 | struct watchpoint *w = (struct watchpoint *) b; |
11029 | ||
9c06b0b4 TJB |
11030 | /* Masked watchpoints have only one location. */ |
11031 | gdb_assert (b->loc && b->loc->next == NULL); | |
11032 | ||
11033 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 11034 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
11035 | ui_out_text (uiout, "\n"); |
11036 | } | |
11037 | ||
11038 | /* Implement the "print_mention" breakpoint_ops method for | |
11039 | masked hardware watchpoints. */ | |
11040 | ||
11041 | static void | |
11042 | print_mention_masked_watchpoint (struct breakpoint *b) | |
11043 | { | |
3a5c3e22 | 11044 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 11045 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
11046 | struct cleanup *ui_out_chain; |
11047 | ||
11048 | switch (b->type) | |
11049 | { | |
11050 | case bp_hardware_watchpoint: | |
11051 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
11052 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
11053 | break; | |
11054 | case bp_read_watchpoint: | |
11055 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
11056 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
11057 | break; | |
11058 | case bp_access_watchpoint: | |
11059 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
11060 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
11061 | break; | |
11062 | default: | |
11063 | internal_error (__FILE__, __LINE__, | |
11064 | _("Invalid hardware watchpoint type.")); | |
11065 | } | |
11066 | ||
11067 | ui_out_field_int (uiout, "number", b->number); | |
11068 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 11069 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
11070 | do_cleanups (ui_out_chain); |
11071 | } | |
11072 | ||
11073 | /* Implement the "print_recreate" breakpoint_ops method for | |
11074 | masked hardware watchpoints. */ | |
11075 | ||
11076 | static void | |
11077 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
11078 | { | |
3a5c3e22 | 11079 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
11080 | char tmp[40]; |
11081 | ||
11082 | switch (b->type) | |
11083 | { | |
11084 | case bp_hardware_watchpoint: | |
11085 | fprintf_unfiltered (fp, "watch"); | |
11086 | break; | |
11087 | case bp_read_watchpoint: | |
11088 | fprintf_unfiltered (fp, "rwatch"); | |
11089 | break; | |
11090 | case bp_access_watchpoint: | |
11091 | fprintf_unfiltered (fp, "awatch"); | |
11092 | break; | |
11093 | default: | |
11094 | internal_error (__FILE__, __LINE__, | |
11095 | _("Invalid hardware watchpoint type.")); | |
11096 | } | |
11097 | ||
3a5c3e22 PA |
11098 | sprintf_vma (tmp, w->hw_wp_mask); |
11099 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 11100 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
11101 | } |
11102 | ||
11103 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
11104 | ||
2060206e | 11105 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
11106 | |
11107 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
11108 | ||
11109 | static int | |
11110 | is_masked_watchpoint (const struct breakpoint *b) | |
11111 | { | |
11112 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
11113 | } | |
11114 | ||
53a5351d JM |
11115 | /* accessflag: hw_write: watch write, |
11116 | hw_read: watch read, | |
11117 | hw_access: watch access (read or write) */ | |
c906108c | 11118 | static void |
bbc13ae3 | 11119 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
84f4c1fe | 11120 | int just_location, int internal) |
c906108c | 11121 | { |
d983da9c | 11122 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 11123 | struct expression *exp; |
270140bd | 11124 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 11125 | struct value *val, *mark, *result; |
bb9d5f81 | 11126 | int saved_bitpos = 0, saved_bitsize = 0; |
c906108c | 11127 | struct frame_info *frame; |
bbc13ae3 KS |
11128 | const char *exp_start = NULL; |
11129 | const char *exp_end = NULL; | |
11130 | const char *tok, *end_tok; | |
9c06b0b4 | 11131 | int toklen = -1; |
bbc13ae3 KS |
11132 | const char *cond_start = NULL; |
11133 | const char *cond_end = NULL; | |
c906108c | 11134 | enum bptype bp_type; |
37e4754d | 11135 | int thread = -1; |
0cf6dd15 | 11136 | int pc = 0; |
9c06b0b4 TJB |
11137 | /* Flag to indicate whether we are going to use masks for |
11138 | the hardware watchpoint. */ | |
11139 | int use_mask = 0; | |
11140 | CORE_ADDR mask = 0; | |
3a5c3e22 | 11141 | struct watchpoint *w; |
bbc13ae3 KS |
11142 | char *expression; |
11143 | struct cleanup *back_to; | |
c906108c | 11144 | |
37e4754d LM |
11145 | /* Make sure that we actually have parameters to parse. */ |
11146 | if (arg != NULL && arg[0] != '\0') | |
11147 | { | |
bbc13ae3 KS |
11148 | const char *value_start; |
11149 | ||
11150 | exp_end = arg + strlen (arg); | |
37e4754d | 11151 | |
9c06b0b4 TJB |
11152 | /* Look for "parameter value" pairs at the end |
11153 | of the arguments string. */ | |
bbc13ae3 | 11154 | for (tok = exp_end - 1; tok > arg; tok--) |
9c06b0b4 TJB |
11155 | { |
11156 | /* Skip whitespace at the end of the argument list. */ | |
11157 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11158 | tok--; | |
11159 | ||
11160 | /* Find the beginning of the last token. | |
11161 | This is the value of the parameter. */ | |
11162 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11163 | tok--; | |
11164 | value_start = tok + 1; | |
11165 | ||
11166 | /* Skip whitespace. */ | |
11167 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
11168 | tok--; | |
11169 | ||
11170 | end_tok = tok; | |
11171 | ||
11172 | /* Find the beginning of the second to last token. | |
11173 | This is the parameter itself. */ | |
11174 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
11175 | tok--; | |
11176 | tok++; | |
11177 | toklen = end_tok - tok + 1; | |
11178 | ||
61012eef | 11179 | if (toklen == 6 && startswith (tok, "thread")) |
9c06b0b4 | 11180 | { |
5d5658a1 | 11181 | struct thread_info *thr; |
9c06b0b4 TJB |
11182 | /* At this point we've found a "thread" token, which means |
11183 | the user is trying to set a watchpoint that triggers | |
11184 | only in a specific thread. */ | |
5d5658a1 | 11185 | const char *endp; |
37e4754d | 11186 | |
9c06b0b4 TJB |
11187 | if (thread != -1) |
11188 | error(_("You can specify only one thread.")); | |
37e4754d | 11189 | |
9c06b0b4 | 11190 | /* Extract the thread ID from the next token. */ |
5d5658a1 | 11191 | thr = parse_thread_id (value_start, &endp); |
37e4754d | 11192 | |
5d5658a1 | 11193 | /* Check if the user provided a valid thread ID. */ |
9c06b0b4 | 11194 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
5d5658a1 | 11195 | invalid_thread_id_error (value_start); |
9c06b0b4 | 11196 | |
5d5658a1 | 11197 | thread = thr->global_num; |
9c06b0b4 | 11198 | } |
61012eef | 11199 | else if (toklen == 4 && startswith (tok, "mask")) |
9c06b0b4 TJB |
11200 | { |
11201 | /* We've found a "mask" token, which means the user wants to | |
11202 | create a hardware watchpoint that is going to have the mask | |
11203 | facility. */ | |
11204 | struct value *mask_value, *mark; | |
37e4754d | 11205 | |
9c06b0b4 TJB |
11206 | if (use_mask) |
11207 | error(_("You can specify only one mask.")); | |
37e4754d | 11208 | |
9c06b0b4 | 11209 | use_mask = just_location = 1; |
37e4754d | 11210 | |
9c06b0b4 TJB |
11211 | mark = value_mark (); |
11212 | mask_value = parse_to_comma_and_eval (&value_start); | |
11213 | mask = value_as_address (mask_value); | |
11214 | value_free_to_mark (mark); | |
11215 | } | |
11216 | else | |
11217 | /* We didn't recognize what we found. We should stop here. */ | |
11218 | break; | |
37e4754d | 11219 | |
9c06b0b4 TJB |
11220 | /* Truncate the string and get rid of the "parameter value" pair before |
11221 | the arguments string is parsed by the parse_exp_1 function. */ | |
bbc13ae3 | 11222 | exp_end = tok; |
9c06b0b4 | 11223 | } |
37e4754d | 11224 | } |
bbc13ae3 KS |
11225 | else |
11226 | exp_end = arg; | |
37e4754d | 11227 | |
bbc13ae3 KS |
11228 | /* Parse the rest of the arguments. From here on out, everything |
11229 | is in terms of a newly allocated string instead of the original | |
11230 | ARG. */ | |
c906108c | 11231 | innermost_block = NULL; |
bbc13ae3 KS |
11232 | expression = savestring (arg, exp_end - arg); |
11233 | back_to = make_cleanup (xfree, expression); | |
11234 | exp_start = arg = expression; | |
1bb9788d | 11235 | exp = parse_exp_1 (&arg, 0, 0, 0); |
c906108c | 11236 | exp_end = arg; |
fa8a61dc TT |
11237 | /* Remove trailing whitespace from the expression before saving it. |
11238 | This makes the eventual display of the expression string a bit | |
11239 | prettier. */ | |
11240 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
11241 | --exp_end; | |
11242 | ||
65d79d4b SDJ |
11243 | /* Checking if the expression is not constant. */ |
11244 | if (watchpoint_exp_is_const (exp)) | |
11245 | { | |
11246 | int len; | |
11247 | ||
11248 | len = exp_end - exp_start; | |
11249 | while (len > 0 && isspace (exp_start[len - 1])) | |
11250 | len--; | |
11251 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
11252 | } | |
11253 | ||
c906108c SS |
11254 | exp_valid_block = innermost_block; |
11255 | mark = value_mark (); | |
3a1115a0 | 11256 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
06a64a0b | 11257 | |
bb9d5f81 PP |
11258 | if (val != NULL && just_location) |
11259 | { | |
11260 | saved_bitpos = value_bitpos (val); | |
11261 | saved_bitsize = value_bitsize (val); | |
11262 | } | |
11263 | ||
06a64a0b TT |
11264 | if (just_location) |
11265 | { | |
9c06b0b4 TJB |
11266 | int ret; |
11267 | ||
06a64a0b | 11268 | exp_valid_block = NULL; |
a1442452 | 11269 | val = value_addr (result); |
06a64a0b TT |
11270 | release_value (val); |
11271 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
11272 | |
11273 | if (use_mask) | |
11274 | { | |
11275 | ret = target_masked_watch_num_registers (value_as_address (val), | |
11276 | mask); | |
11277 | if (ret == -1) | |
11278 | error (_("This target does not support masked watchpoints.")); | |
11279 | else if (ret == -2) | |
11280 | error (_("Invalid mask or memory region.")); | |
11281 | } | |
06a64a0b TT |
11282 | } |
11283 | else if (val != NULL) | |
fa4727a6 | 11284 | release_value (val); |
c906108c | 11285 | |
bbc13ae3 KS |
11286 | tok = skip_spaces_const (arg); |
11287 | end_tok = skip_to_space_const (tok); | |
c906108c SS |
11288 | |
11289 | toklen = end_tok - tok; | |
11290 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
11291 | { | |
2d134ed3 PA |
11292 | struct expression *cond; |
11293 | ||
60e1c644 | 11294 | innermost_block = NULL; |
c906108c | 11295 | tok = cond_start = end_tok + 1; |
1bb9788d | 11296 | cond = parse_exp_1 (&tok, 0, 0, 0); |
60e1c644 PA |
11297 | |
11298 | /* The watchpoint expression may not be local, but the condition | |
11299 | may still be. E.g.: `watch global if local > 0'. */ | |
11300 | cond_exp_valid_block = innermost_block; | |
11301 | ||
2d134ed3 | 11302 | xfree (cond); |
c906108c SS |
11303 | cond_end = tok; |
11304 | } | |
11305 | if (*tok) | |
8a3fe4f8 | 11306 | error (_("Junk at end of command.")); |
c906108c | 11307 | |
d983da9c | 11308 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
11309 | |
11310 | /* If the expression is "local", then set up a "watchpoint scope" | |
11311 | breakpoint at the point where we've left the scope of the watchpoint | |
11312 | expression. Create the scope breakpoint before the watchpoint, so | |
11313 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 11314 | if (exp_valid_block && frame) |
d983da9c | 11315 | { |
edb3359d DJ |
11316 | if (frame_id_p (frame_unwind_caller_id (frame))) |
11317 | { | |
11318 | scope_breakpoint | |
a6d9a66e UW |
11319 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
11320 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
11321 | bp_watchpoint_scope, |
11322 | &momentary_breakpoint_ops); | |
d983da9c | 11323 | |
edb3359d | 11324 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 11325 | |
edb3359d DJ |
11326 | /* Automatically delete the breakpoint when it hits. */ |
11327 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 11328 | |
edb3359d DJ |
11329 | /* Only break in the proper frame (help with recursion). */ |
11330 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 11331 | |
edb3359d | 11332 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
11333 | scope_breakpoint->loc->gdbarch |
11334 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
11335 | scope_breakpoint->loc->requested_address |
11336 | = frame_unwind_caller_pc (frame); | |
11337 | scope_breakpoint->loc->address | |
a6d9a66e UW |
11338 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
11339 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
11340 | scope_breakpoint->type); |
11341 | } | |
d983da9c DJ |
11342 | } |
11343 | ||
e8369a73 AB |
11344 | /* Now set up the breakpoint. We create all watchpoints as hardware |
11345 | watchpoints here even if hardware watchpoints are turned off, a call | |
11346 | to update_watchpoint later in this function will cause the type to | |
11347 | drop back to bp_watchpoint (software watchpoint) if required. */ | |
11348 | ||
11349 | if (accessflag == hw_read) | |
11350 | bp_type = bp_read_watchpoint; | |
11351 | else if (accessflag == hw_access) | |
11352 | bp_type = bp_access_watchpoint; | |
11353 | else | |
11354 | bp_type = bp_hardware_watchpoint; | |
3a5c3e22 PA |
11355 | |
11356 | w = XCNEW (struct watchpoint); | |
11357 | b = &w->base; | |
348d480f | 11358 | if (use_mask) |
3a5c3e22 PA |
11359 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11360 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 11361 | else |
3a5c3e22 PA |
11362 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
11363 | &watchpoint_breakpoint_ops); | |
37e4754d | 11364 | b->thread = thread; |
b5de0fa7 | 11365 | b->disposition = disp_donttouch; |
348d480f | 11366 | b->pspace = current_program_space; |
3a5c3e22 PA |
11367 | w->exp = exp; |
11368 | w->exp_valid_block = exp_valid_block; | |
11369 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
11370 | if (just_location) |
11371 | { | |
11372 | struct type *t = value_type (val); | |
11373 | CORE_ADDR addr = value_as_address (val); | |
11374 | char *name; | |
11375 | ||
11376 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
11377 | name = type_to_string (t); | |
11378 | ||
3a5c3e22 | 11379 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 11380 | core_addr_to_string (addr)); |
06a64a0b TT |
11381 | xfree (name); |
11382 | ||
3a5c3e22 | 11383 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
11384 | (int) (exp_end - exp_start), exp_start); |
11385 | ||
06a64a0b TT |
11386 | /* The above expression is in C. */ |
11387 | b->language = language_c; | |
11388 | } | |
11389 | else | |
3a5c3e22 | 11390 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
11391 | |
11392 | if (use_mask) | |
11393 | { | |
3a5c3e22 | 11394 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
11395 | } |
11396 | else | |
11397 | { | |
3a5c3e22 | 11398 | w->val = val; |
bb9d5f81 PP |
11399 | w->val_bitpos = saved_bitpos; |
11400 | w->val_bitsize = saved_bitsize; | |
3a5c3e22 | 11401 | w->val_valid = 1; |
9c06b0b4 | 11402 | } |
77b06cd7 | 11403 | |
c906108c SS |
11404 | if (cond_start) |
11405 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
11406 | else | |
11407 | b->cond_string = 0; | |
c5aa993b | 11408 | |
c906108c | 11409 | if (frame) |
f6bc2008 | 11410 | { |
3a5c3e22 PA |
11411 | w->watchpoint_frame = get_frame_id (frame); |
11412 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 11413 | } |
c906108c | 11414 | else |
f6bc2008 | 11415 | { |
3a5c3e22 PA |
11416 | w->watchpoint_frame = null_frame_id; |
11417 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 11418 | } |
c906108c | 11419 | |
d983da9c | 11420 | if (scope_breakpoint != NULL) |
c906108c | 11421 | { |
d983da9c DJ |
11422 | /* The scope breakpoint is related to the watchpoint. We will |
11423 | need to act on them together. */ | |
11424 | b->related_breakpoint = scope_breakpoint; | |
11425 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 11426 | } |
d983da9c | 11427 | |
06a64a0b TT |
11428 | if (!just_location) |
11429 | value_free_to_mark (mark); | |
2d134ed3 | 11430 | |
492d29ea | 11431 | TRY |
a9634178 TJB |
11432 | { |
11433 | /* Finally update the new watchpoint. This creates the locations | |
11434 | that should be inserted. */ | |
3a5c3e22 | 11435 | update_watchpoint (w, 1); |
a9634178 | 11436 | } |
492d29ea | 11437 | CATCH (e, RETURN_MASK_ALL) |
a9634178 TJB |
11438 | { |
11439 | delete_breakpoint (b); | |
11440 | throw_exception (e); | |
11441 | } | |
492d29ea | 11442 | END_CATCH |
a9634178 | 11443 | |
3ea46bff | 11444 | install_breakpoint (internal, b, 1); |
bbc13ae3 | 11445 | do_cleanups (back_to); |
c906108c SS |
11446 | } |
11447 | ||
e09342b5 | 11448 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 11449 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 11450 | |
c906108c | 11451 | static int |
a9634178 | 11452 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
11453 | { |
11454 | int found_memory_cnt = 0; | |
2e70b7b9 | 11455 | struct value *head = v; |
c906108c SS |
11456 | |
11457 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 11458 | if (!can_use_hw_watchpoints) |
c906108c | 11459 | return 0; |
c5aa993b | 11460 | |
5c44784c JM |
11461 | /* Make sure that the value of the expression depends only upon |
11462 | memory contents, and values computed from them within GDB. If we | |
11463 | find any register references or function calls, we can't use a | |
11464 | hardware watchpoint. | |
11465 | ||
11466 | The idea here is that evaluating an expression generates a series | |
11467 | of values, one holding the value of every subexpression. (The | |
11468 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
11469 | a*b+c.) GDB's values hold almost enough information to establish | |
11470 | the criteria given above --- they identify memory lvalues, | |
11471 | register lvalues, computed values, etcetera. So we can evaluate | |
11472 | the expression, and then scan the chain of values that leaves | |
11473 | behind to decide whether we can detect any possible change to the | |
11474 | expression's final value using only hardware watchpoints. | |
11475 | ||
11476 | However, I don't think that the values returned by inferior | |
11477 | function calls are special in any way. So this function may not | |
11478 | notice that an expression involving an inferior function call | |
11479 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 11480 | for (; v; v = value_next (v)) |
c906108c | 11481 | { |
5c44784c | 11482 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 11483 | { |
8464be76 DJ |
11484 | if (v != head && value_lazy (v)) |
11485 | /* A lazy memory lvalue in the chain is one that GDB never | |
11486 | needed to fetch; we either just used its address (e.g., | |
11487 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
11488 | in `a,b'). This doesn't apply to HEAD; if that is | |
11489 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 11490 | ; |
53a5351d | 11491 | else |
5c44784c JM |
11492 | { |
11493 | /* Ahh, memory we actually used! Check if we can cover | |
11494 | it with hardware watchpoints. */ | |
df407dfe | 11495 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
11496 | |
11497 | /* We only watch structs and arrays if user asked for it | |
11498 | explicitly, never if they just happen to appear in a | |
11499 | middle of some value chain. */ | |
11500 | if (v == head | |
11501 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
11502 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
11503 | { | |
42ae5230 | 11504 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
11505 | int len; |
11506 | int num_regs; | |
11507 | ||
a9634178 | 11508 | len = (target_exact_watchpoints |
e09342b5 TJB |
11509 | && is_scalar_type_recursive (vtype))? |
11510 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 11511 | |
e09342b5 TJB |
11512 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
11513 | if (!num_regs) | |
2e70b7b9 MS |
11514 | return 0; |
11515 | else | |
e09342b5 | 11516 | found_memory_cnt += num_regs; |
2e70b7b9 | 11517 | } |
5c44784c | 11518 | } |
c5aa993b | 11519 | } |
5086187c AC |
11520 | else if (VALUE_LVAL (v) != not_lval |
11521 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 11522 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 11523 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 11524 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
11525 | } |
11526 | ||
11527 | /* The expression itself looks suitable for using a hardware | |
11528 | watchpoint, but give the target machine a chance to reject it. */ | |
11529 | return found_memory_cnt; | |
11530 | } | |
11531 | ||
8b93c638 | 11532 | void |
84f4c1fe | 11533 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11534 | { |
84f4c1fe | 11535 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
11536 | } |
11537 | ||
06a64a0b TT |
11538 | /* A helper function that looks for the "-location" argument and then |
11539 | calls watch_command_1. */ | |
11540 | ||
11541 | static void | |
11542 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
11543 | { | |
11544 | int just_location = 0; | |
11545 | ||
11546 | if (arg | |
11547 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
11548 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
11549 | { | |
e9cafbcc | 11550 | arg = skip_spaces (arg); |
06a64a0b TT |
11551 | just_location = 1; |
11552 | } | |
11553 | ||
84f4c1fe | 11554 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 11555 | } |
8926118c | 11556 | |
c5aa993b | 11557 | static void |
fba45db2 | 11558 | watch_command (char *arg, int from_tty) |
c906108c | 11559 | { |
06a64a0b | 11560 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
11561 | } |
11562 | ||
8b93c638 | 11563 | void |
84f4c1fe | 11564 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11565 | { |
84f4c1fe | 11566 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 11567 | } |
8926118c | 11568 | |
c5aa993b | 11569 | static void |
fba45db2 | 11570 | rwatch_command (char *arg, int from_tty) |
c906108c | 11571 | { |
06a64a0b | 11572 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
11573 | } |
11574 | ||
8b93c638 | 11575 | void |
84f4c1fe | 11576 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 11577 | { |
84f4c1fe | 11578 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 11579 | } |
8926118c | 11580 | |
c5aa993b | 11581 | static void |
fba45db2 | 11582 | awatch_command (char *arg, int from_tty) |
c906108c | 11583 | { |
06a64a0b | 11584 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 11585 | } |
c906108c | 11586 | \f |
c5aa993b | 11587 | |
cfc31633 PA |
11588 | /* Data for the FSM that manages the until(location)/advance commands |
11589 | in infcmd.c. Here because it uses the mechanisms of | |
11590 | breakpoints. */ | |
c906108c | 11591 | |
cfc31633 | 11592 | struct until_break_fsm |
bfec99b2 | 11593 | { |
cfc31633 PA |
11594 | /* The base class. */ |
11595 | struct thread_fsm thread_fsm; | |
11596 | ||
11597 | /* The thread that as current when the command was executed. */ | |
11598 | int thread; | |
11599 | ||
11600 | /* The breakpoint set at the destination location. */ | |
11601 | struct breakpoint *location_breakpoint; | |
11602 | ||
11603 | /* Breakpoint set at the return address in the caller frame. May be | |
11604 | NULL. */ | |
11605 | struct breakpoint *caller_breakpoint; | |
bfec99b2 PA |
11606 | }; |
11607 | ||
cfc31633 PA |
11608 | static void until_break_fsm_clean_up (struct thread_fsm *self); |
11609 | static int until_break_fsm_should_stop (struct thread_fsm *self); | |
11610 | static enum async_reply_reason | |
11611 | until_break_fsm_async_reply_reason (struct thread_fsm *self); | |
11612 | ||
11613 | /* until_break_fsm's vtable. */ | |
11614 | ||
11615 | static struct thread_fsm_ops until_break_fsm_ops = | |
11616 | { | |
11617 | NULL, /* dtor */ | |
11618 | until_break_fsm_clean_up, | |
11619 | until_break_fsm_should_stop, | |
11620 | NULL, /* return_value */ | |
11621 | until_break_fsm_async_reply_reason, | |
11622 | }; | |
11623 | ||
11624 | /* Allocate a new until_break_command_fsm. */ | |
11625 | ||
11626 | static struct until_break_fsm * | |
11627 | new_until_break_fsm (int thread, | |
11628 | struct breakpoint *location_breakpoint, | |
11629 | struct breakpoint *caller_breakpoint) | |
11630 | { | |
11631 | struct until_break_fsm *sm; | |
11632 | ||
11633 | sm = XCNEW (struct until_break_fsm); | |
11634 | thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops); | |
11635 | ||
11636 | sm->thread = thread; | |
11637 | sm->location_breakpoint = location_breakpoint; | |
11638 | sm->caller_breakpoint = caller_breakpoint; | |
11639 | ||
11640 | return sm; | |
11641 | } | |
11642 | ||
11643 | /* Implementation of the 'should_stop' FSM method for the | |
11644 | until(location)/advance commands. */ | |
11645 | ||
11646 | static int | |
11647 | until_break_fsm_should_stop (struct thread_fsm *self) | |
11648 | { | |
11649 | struct until_break_fsm *sm = (struct until_break_fsm *) self; | |
11650 | struct thread_info *tp = inferior_thread (); | |
11651 | ||
11652 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11653 | sm->location_breakpoint) != NULL | |
11654 | || (sm->caller_breakpoint != NULL | |
11655 | && bpstat_find_breakpoint (tp->control.stop_bpstat, | |
11656 | sm->caller_breakpoint) != NULL)) | |
11657 | thread_fsm_set_finished (self); | |
11658 | ||
11659 | return 1; | |
11660 | } | |
11661 | ||
11662 | /* Implementation of the 'clean_up' FSM method for the | |
11663 | until(location)/advance commands. */ | |
11664 | ||
c2c6d25f | 11665 | static void |
cfc31633 | 11666 | until_break_fsm_clean_up (struct thread_fsm *self) |
43ff13b4 | 11667 | { |
cfc31633 | 11668 | struct until_break_fsm *sm = (struct until_break_fsm *) self; |
bfec99b2 | 11669 | |
cfc31633 PA |
11670 | /* Clean up our temporary breakpoints. */ |
11671 | if (sm->location_breakpoint != NULL) | |
11672 | { | |
11673 | delete_breakpoint (sm->location_breakpoint); | |
11674 | sm->location_breakpoint = NULL; | |
11675 | } | |
11676 | if (sm->caller_breakpoint != NULL) | |
11677 | { | |
11678 | delete_breakpoint (sm->caller_breakpoint); | |
11679 | sm->caller_breakpoint = NULL; | |
11680 | } | |
11681 | delete_longjmp_breakpoint (sm->thread); | |
11682 | } | |
11683 | ||
11684 | /* Implementation of the 'async_reply_reason' FSM method for the | |
11685 | until(location)/advance commands. */ | |
11686 | ||
11687 | static enum async_reply_reason | |
11688 | until_break_fsm_async_reply_reason (struct thread_fsm *self) | |
11689 | { | |
11690 | return EXEC_ASYNC_LOCATION_REACHED; | |
43ff13b4 JM |
11691 | } |
11692 | ||
c906108c | 11693 | void |
ae66c1fc | 11694 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
11695 | { |
11696 | struct symtabs_and_lines sals; | |
11697 | struct symtab_and_line sal; | |
8556afb4 PA |
11698 | struct frame_info *frame; |
11699 | struct gdbarch *frame_gdbarch; | |
11700 | struct frame_id stack_frame_id; | |
11701 | struct frame_id caller_frame_id; | |
cfc31633 PA |
11702 | struct breakpoint *location_breakpoint; |
11703 | struct breakpoint *caller_breakpoint = NULL; | |
f00aae0f | 11704 | struct cleanup *old_chain, *cleanup; |
186c406b TT |
11705 | int thread; |
11706 | struct thread_info *tp; | |
f00aae0f | 11707 | struct event_location *location; |
cfc31633 | 11708 | struct until_break_fsm *sm; |
c906108c | 11709 | |
70509625 | 11710 | clear_proceed_status (0); |
c906108c SS |
11711 | |
11712 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 11713 | this function. */ |
c5aa993b | 11714 | |
f00aae0f KS |
11715 | location = string_to_event_location (&arg, current_language); |
11716 | cleanup = make_cleanup_delete_event_location (location); | |
11717 | ||
1bfeeb0f | 11718 | if (last_displayed_sal_is_valid ()) |
c2f4122d | 11719 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
1bfeeb0f | 11720 | get_last_displayed_symtab (), |
f8eba3c6 | 11721 | get_last_displayed_line ()); |
c906108c | 11722 | else |
f00aae0f | 11723 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
c2f4122d | 11724 | NULL, (struct symtab *) NULL, 0); |
c5aa993b | 11725 | |
c906108c | 11726 | if (sals.nelts != 1) |
8a3fe4f8 | 11727 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 11728 | |
c906108c | 11729 | sal = sals.sals[0]; |
4a64f543 | 11730 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 11731 | |
c906108c | 11732 | if (*arg) |
8a3fe4f8 | 11733 | error (_("Junk at end of arguments.")); |
c5aa993b | 11734 | |
c906108c | 11735 | resolve_sal_pc (&sal); |
c5aa993b | 11736 | |
186c406b | 11737 | tp = inferior_thread (); |
5d5658a1 | 11738 | thread = tp->global_num; |
186c406b | 11739 | |
883bc8d1 PA |
11740 | old_chain = make_cleanup (null_cleanup, NULL); |
11741 | ||
8556afb4 PA |
11742 | /* Note linespec handling above invalidates the frame chain. |
11743 | Installing a breakpoint also invalidates the frame chain (as it | |
11744 | may need to switch threads), so do any frame handling before | |
11745 | that. */ | |
11746 | ||
11747 | frame = get_selected_frame (NULL); | |
11748 | frame_gdbarch = get_frame_arch (frame); | |
11749 | stack_frame_id = get_stack_frame_id (frame); | |
11750 | caller_frame_id = frame_unwind_caller_id (frame); | |
883bc8d1 | 11751 | |
ae66c1fc EZ |
11752 | /* Keep within the current frame, or in frames called by the current |
11753 | one. */ | |
edb3359d | 11754 | |
883bc8d1 | 11755 | if (frame_id_p (caller_frame_id)) |
c906108c | 11756 | { |
883bc8d1 | 11757 | struct symtab_and_line sal2; |
cfc31633 | 11758 | struct gdbarch *caller_gdbarch; |
883bc8d1 PA |
11759 | |
11760 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); | |
11761 | sal2.pc = frame_unwind_caller_pc (frame); | |
cfc31633 PA |
11762 | caller_gdbarch = frame_unwind_caller_arch (frame); |
11763 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, | |
11764 | sal2, | |
11765 | caller_frame_id, | |
11766 | bp_until); | |
11767 | make_cleanup_delete_breakpoint (caller_breakpoint); | |
186c406b | 11768 | |
883bc8d1 | 11769 | set_longjmp_breakpoint (tp, caller_frame_id); |
186c406b | 11770 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
c906108c | 11771 | } |
c5aa993b | 11772 | |
c70a6932 JK |
11773 | /* set_momentary_breakpoint could invalidate FRAME. */ |
11774 | frame = NULL; | |
11775 | ||
883bc8d1 PA |
11776 | if (anywhere) |
11777 | /* If the user told us to continue until a specified location, | |
11778 | we don't specify a frame at which we need to stop. */ | |
cfc31633 PA |
11779 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11780 | null_frame_id, bp_until); | |
883bc8d1 PA |
11781 | else |
11782 | /* Otherwise, specify the selected frame, because we want to stop | |
11783 | only at the very same frame. */ | |
cfc31633 PA |
11784 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
11785 | stack_frame_id, bp_until); | |
11786 | make_cleanup_delete_breakpoint (location_breakpoint); | |
883bc8d1 | 11787 | |
5d5658a1 PA |
11788 | sm = new_until_break_fsm (tp->global_num, |
11789 | location_breakpoint, caller_breakpoint); | |
cfc31633 | 11790 | tp->thread_fsm = &sm->thread_fsm; |
f107f563 | 11791 | |
cfc31633 | 11792 | discard_cleanups (old_chain); |
f107f563 | 11793 | |
cfc31633 | 11794 | proceed (-1, GDB_SIGNAL_DEFAULT); |
f00aae0f KS |
11795 | |
11796 | do_cleanups (cleanup); | |
c906108c | 11797 | } |
ae66c1fc | 11798 | |
c906108c SS |
11799 | /* This function attempts to parse an optional "if <cond>" clause |
11800 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 11801 | |
c906108c SS |
11802 | Else, it returns a pointer to the condition string. (It does not |
11803 | attempt to evaluate the string against a particular block.) And, | |
11804 | it updates arg to point to the first character following the parsed | |
4a64f543 | 11805 | if clause in the arg string. */ |
53a5351d | 11806 | |
916703c0 | 11807 | char * |
fba45db2 | 11808 | ep_parse_optional_if_clause (char **arg) |
c906108c | 11809 | { |
c5aa993b JM |
11810 | char *cond_string; |
11811 | ||
11812 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 11813 | return NULL; |
c5aa993b | 11814 | |
4a64f543 | 11815 | /* Skip the "if" keyword. */ |
c906108c | 11816 | (*arg) += 2; |
c5aa993b | 11817 | |
c906108c | 11818 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 11819 | condition string. */ |
e9cafbcc | 11820 | *arg = skip_spaces (*arg); |
c906108c | 11821 | cond_string = *arg; |
c5aa993b | 11822 | |
4a64f543 MS |
11823 | /* Assume that the condition occupies the remainder of the arg |
11824 | string. */ | |
c906108c | 11825 | (*arg) += strlen (cond_string); |
c5aa993b | 11826 | |
c906108c SS |
11827 | return cond_string; |
11828 | } | |
c5aa993b | 11829 | |
c906108c SS |
11830 | /* Commands to deal with catching events, such as signals, exceptions, |
11831 | process start/exit, etc. */ | |
c5aa993b JM |
11832 | |
11833 | typedef enum | |
11834 | { | |
44feb3ce TT |
11835 | catch_fork_temporary, catch_vfork_temporary, |
11836 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
11837 | } |
11838 | catch_fork_kind; | |
11839 | ||
c906108c | 11840 | static void |
cc59ec59 MS |
11841 | catch_fork_command_1 (char *arg, int from_tty, |
11842 | struct cmd_list_element *command) | |
c906108c | 11843 | { |
a6d9a66e | 11844 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 11845 | char *cond_string = NULL; |
44feb3ce TT |
11846 | catch_fork_kind fork_kind; |
11847 | int tempflag; | |
11848 | ||
11849 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
11850 | tempflag = (fork_kind == catch_fork_temporary | |
11851 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 11852 | |
44feb3ce TT |
11853 | if (!arg) |
11854 | arg = ""; | |
e9cafbcc | 11855 | arg = skip_spaces (arg); |
c5aa993b | 11856 | |
c906108c | 11857 | /* The allowed syntax is: |
c5aa993b JM |
11858 | catch [v]fork |
11859 | catch [v]fork if <cond> | |
11860 | ||
4a64f543 | 11861 | First, check if there's an if clause. */ |
c906108c | 11862 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 11863 | |
c906108c | 11864 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 11865 | error (_("Junk at end of arguments.")); |
c5aa993b | 11866 | |
c906108c | 11867 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 11868 | and enable reporting of such events. */ |
c5aa993b JM |
11869 | switch (fork_kind) |
11870 | { | |
44feb3ce TT |
11871 | case catch_fork_temporary: |
11872 | case catch_fork_permanent: | |
a6d9a66e | 11873 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11874 | &catch_fork_breakpoint_ops); |
c906108c | 11875 | break; |
44feb3ce TT |
11876 | case catch_vfork_temporary: |
11877 | case catch_vfork_permanent: | |
a6d9a66e | 11878 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 11879 | &catch_vfork_breakpoint_ops); |
c906108c | 11880 | break; |
c5aa993b | 11881 | default: |
8a3fe4f8 | 11882 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 11883 | break; |
c5aa993b | 11884 | } |
c906108c SS |
11885 | } |
11886 | ||
11887 | static void | |
cc59ec59 MS |
11888 | catch_exec_command_1 (char *arg, int from_tty, |
11889 | struct cmd_list_element *command) | |
c906108c | 11890 | { |
b4d90040 | 11891 | struct exec_catchpoint *c; |
a6d9a66e | 11892 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 11893 | int tempflag; |
c5aa993b | 11894 | char *cond_string = NULL; |
c906108c | 11895 | |
44feb3ce TT |
11896 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
11897 | ||
11898 | if (!arg) | |
11899 | arg = ""; | |
e9cafbcc | 11900 | arg = skip_spaces (arg); |
c906108c SS |
11901 | |
11902 | /* The allowed syntax is: | |
c5aa993b JM |
11903 | catch exec |
11904 | catch exec if <cond> | |
c906108c | 11905 | |
4a64f543 | 11906 | First, check if there's an if clause. */ |
c906108c SS |
11907 | cond_string = ep_parse_optional_if_clause (&arg); |
11908 | ||
11909 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 11910 | error (_("Junk at end of arguments.")); |
c906108c | 11911 | |
b4d90040 PA |
11912 | c = XNEW (struct exec_catchpoint); |
11913 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
11914 | &catch_exec_breakpoint_ops); | |
11915 | c->exec_pathname = NULL; | |
11916 | ||
3ea46bff | 11917 | install_breakpoint (0, &c->base, 1); |
c906108c | 11918 | } |
c5aa993b | 11919 | |
9ac4176b | 11920 | void |
28010a5d PA |
11921 | init_ada_exception_breakpoint (struct breakpoint *b, |
11922 | struct gdbarch *gdbarch, | |
11923 | struct symtab_and_line sal, | |
11924 | char *addr_string, | |
c0a91b2b | 11925 | const struct breakpoint_ops *ops, |
28010a5d | 11926 | int tempflag, |
349774ef | 11927 | int enabled, |
28010a5d | 11928 | int from_tty) |
f7f9143b | 11929 | { |
f7f9143b JB |
11930 | if (from_tty) |
11931 | { | |
5af949e3 UW |
11932 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
11933 | if (!loc_gdbarch) | |
11934 | loc_gdbarch = gdbarch; | |
11935 | ||
6c95b8df PA |
11936 | describe_other_breakpoints (loc_gdbarch, |
11937 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
11938 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
11939 | version for exception catchpoints, because two catchpoints | |
11940 | used for different exception names will use the same address. | |
11941 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 11942 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 11943 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
11944 | the user what type of catchpoint it is. The above is good |
11945 | enough for now, though. */ | |
11946 | } | |
11947 | ||
28010a5d | 11948 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b | 11949 | |
349774ef | 11950 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
f7f9143b | 11951 | b->disposition = tempflag ? disp_del : disp_donttouch; |
f00aae0f KS |
11952 | b->location = string_to_event_location (&addr_string, |
11953 | language_def (language_ada)); | |
f7f9143b | 11954 | b->language = language_ada; |
f7f9143b JB |
11955 | } |
11956 | ||
c906108c | 11957 | static void |
fba45db2 | 11958 | catch_command (char *arg, int from_tty) |
c906108c | 11959 | { |
44feb3ce | 11960 | error (_("Catch requires an event name.")); |
c906108c SS |
11961 | } |
11962 | \f | |
11963 | ||
11964 | static void | |
fba45db2 | 11965 | tcatch_command (char *arg, int from_tty) |
c906108c | 11966 | { |
44feb3ce | 11967 | error (_("Catch requires an event name.")); |
c906108c SS |
11968 | } |
11969 | ||
8a2c437b TT |
11970 | /* A qsort comparison function that sorts breakpoints in order. */ |
11971 | ||
11972 | static int | |
11973 | compare_breakpoints (const void *a, const void *b) | |
11974 | { | |
9a3c8263 | 11975 | const breakpoint_p *ba = (const breakpoint_p *) a; |
8a2c437b | 11976 | uintptr_t ua = (uintptr_t) *ba; |
9a3c8263 | 11977 | const breakpoint_p *bb = (const breakpoint_p *) b; |
8a2c437b TT |
11978 | uintptr_t ub = (uintptr_t) *bb; |
11979 | ||
11980 | if ((*ba)->number < (*bb)->number) | |
11981 | return -1; | |
11982 | else if ((*ba)->number > (*bb)->number) | |
11983 | return 1; | |
11984 | ||
11985 | /* Now sort by address, in case we see, e..g, two breakpoints with | |
11986 | the number 0. */ | |
11987 | if (ua < ub) | |
11988 | return -1; | |
94b0e70d | 11989 | return ua > ub ? 1 : 0; |
8a2c437b TT |
11990 | } |
11991 | ||
80f8a6eb | 11992 | /* Delete breakpoints by address or line. */ |
c906108c SS |
11993 | |
11994 | static void | |
fba45db2 | 11995 | clear_command (char *arg, int from_tty) |
c906108c | 11996 | { |
8a2c437b | 11997 | struct breakpoint *b, *prev; |
d6e956e5 VP |
11998 | VEC(breakpoint_p) *found = 0; |
11999 | int ix; | |
c906108c SS |
12000 | int default_match; |
12001 | struct symtabs_and_lines sals; | |
12002 | struct symtab_and_line sal; | |
c906108c | 12003 | int i; |
8a2c437b | 12004 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
12005 | |
12006 | if (arg) | |
12007 | { | |
39cf75f7 DE |
12008 | sals = decode_line_with_current_source (arg, |
12009 | (DECODE_LINE_FUNFIRSTLINE | |
12010 | | DECODE_LINE_LIST_MODE)); | |
cf4ded82 | 12011 | make_cleanup (xfree, sals.sals); |
c906108c SS |
12012 | default_match = 0; |
12013 | } | |
12014 | else | |
12015 | { | |
8d749320 | 12016 | sals.sals = XNEW (struct symtab_and_line); |
80f8a6eb | 12017 | make_cleanup (xfree, sals.sals); |
4a64f543 | 12018 | init_sal (&sal); /* Initialize to zeroes. */ |
1bfeeb0f JL |
12019 | |
12020 | /* Set sal's line, symtab, pc, and pspace to the values | |
12021 | corresponding to the last call to print_frame_info. If the | |
12022 | codepoint is not valid, this will set all the fields to 0. */ | |
12023 | get_last_displayed_sal (&sal); | |
c906108c | 12024 | if (sal.symtab == 0) |
8a3fe4f8 | 12025 | error (_("No source file specified.")); |
c906108c SS |
12026 | |
12027 | sals.sals[0] = sal; | |
12028 | sals.nelts = 1; | |
12029 | ||
12030 | default_match = 1; | |
12031 | } | |
12032 | ||
4a64f543 MS |
12033 | /* We don't call resolve_sal_pc here. That's not as bad as it |
12034 | seems, because all existing breakpoints typically have both | |
12035 | file/line and pc set. So, if clear is given file/line, we can | |
12036 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
12037 | |
12038 | We only support clearing given the address explicitly | |
12039 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 12040 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 12041 | due to optimization, all in one block. |
4a64f543 MS |
12042 | |
12043 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
12044 | PC corresponding to the same file:line, the breakpoint won't |
12045 | be cleared. We probably can still clear the breakpoint, but | |
12046 | since the other PC value is never presented to user, user | |
12047 | can only find it by guessing, and it does not seem important | |
12048 | to support that. */ | |
12049 | ||
4a64f543 MS |
12050 | /* For each line spec given, delete bps which correspond to it. Do |
12051 | it in two passes, solely to preserve the current behavior that | |
12052 | from_tty is forced true if we delete more than one | |
12053 | breakpoint. */ | |
c906108c | 12054 | |
80f8a6eb | 12055 | found = NULL; |
8a2c437b | 12056 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
c906108c SS |
12057 | for (i = 0; i < sals.nelts; i++) |
12058 | { | |
05cba821 JK |
12059 | const char *sal_fullname; |
12060 | ||
c906108c | 12061 | /* If exact pc given, clear bpts at that pc. |
c5aa993b JM |
12062 | If line given (pc == 0), clear all bpts on specified line. |
12063 | If defaulting, clear all bpts on default line | |
c906108c | 12064 | or at default pc. |
c5aa993b JM |
12065 | |
12066 | defaulting sal.pc != 0 tests to do | |
12067 | ||
12068 | 0 1 pc | |
12069 | 1 1 pc _and_ line | |
12070 | 0 0 line | |
12071 | 1 0 <can't happen> */ | |
c906108c SS |
12072 | |
12073 | sal = sals.sals[i]; | |
05cba821 JK |
12074 | sal_fullname = (sal.symtab == NULL |
12075 | ? NULL : symtab_to_fullname (sal.symtab)); | |
c906108c | 12076 | |
4a64f543 | 12077 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 12078 | ALL_BREAKPOINTS (b) |
c5aa993b | 12079 | { |
0d381245 | 12080 | int match = 0; |
4a64f543 | 12081 | /* Are we going to delete b? */ |
cc60f2e3 | 12082 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
12083 | { |
12084 | struct bp_location *loc = b->loc; | |
12085 | for (; loc; loc = loc->next) | |
12086 | { | |
f8eba3c6 TT |
12087 | /* If the user specified file:line, don't allow a PC |
12088 | match. This matches historical gdb behavior. */ | |
12089 | int pc_match = (!sal.explicit_line | |
12090 | && sal.pc | |
12091 | && (loc->pspace == sal.pspace) | |
12092 | && (loc->address == sal.pc) | |
12093 | && (!section_is_overlay (loc->section) | |
12094 | || loc->section == sal.section)); | |
4aac40c8 TT |
12095 | int line_match = 0; |
12096 | ||
12097 | if ((default_match || sal.explicit_line) | |
2f202fde | 12098 | && loc->symtab != NULL |
05cba821 | 12099 | && sal_fullname != NULL |
4aac40c8 | 12100 | && sal.pspace == loc->pspace |
05cba821 JK |
12101 | && loc->line_number == sal.line |
12102 | && filename_cmp (symtab_to_fullname (loc->symtab), | |
12103 | sal_fullname) == 0) | |
12104 | line_match = 1; | |
4aac40c8 | 12105 | |
0d381245 VP |
12106 | if (pc_match || line_match) |
12107 | { | |
12108 | match = 1; | |
12109 | break; | |
12110 | } | |
12111 | } | |
12112 | } | |
12113 | ||
12114 | if (match) | |
d6e956e5 | 12115 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 12116 | } |
80f8a6eb | 12117 | } |
8a2c437b | 12118 | |
80f8a6eb | 12119 | /* Now go thru the 'found' chain and delete them. */ |
d6e956e5 | 12120 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
12121 | { |
12122 | if (arg) | |
8a3fe4f8 | 12123 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 12124 | else |
8a3fe4f8 | 12125 | error (_("No breakpoint at this line.")); |
80f8a6eb | 12126 | } |
c906108c | 12127 | |
8a2c437b TT |
12128 | /* Remove duplicates from the vec. */ |
12129 | qsort (VEC_address (breakpoint_p, found), | |
12130 | VEC_length (breakpoint_p, found), | |
12131 | sizeof (breakpoint_p), | |
12132 | compare_breakpoints); | |
12133 | prev = VEC_index (breakpoint_p, found, 0); | |
12134 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) | |
12135 | { | |
12136 | if (b == prev) | |
12137 | { | |
12138 | VEC_ordered_remove (breakpoint_p, found, ix); | |
12139 | --ix; | |
12140 | } | |
12141 | } | |
12142 | ||
d6e956e5 | 12143 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 12144 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 12145 | if (from_tty) |
a3f17187 | 12146 | { |
d6e956e5 | 12147 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
12148 | printf_unfiltered (_("Deleted breakpoint ")); |
12149 | else | |
12150 | printf_unfiltered (_("Deleted breakpoints ")); | |
12151 | } | |
d6e956e5 VP |
12152 | |
12153 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 12154 | { |
c5aa993b | 12155 | if (from_tty) |
d6e956e5 VP |
12156 | printf_unfiltered ("%d ", b->number); |
12157 | delete_breakpoint (b); | |
c906108c | 12158 | } |
80f8a6eb MS |
12159 | if (from_tty) |
12160 | putchar_unfiltered ('\n'); | |
8a2c437b TT |
12161 | |
12162 | do_cleanups (cleanups); | |
c906108c SS |
12163 | } |
12164 | \f | |
12165 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
12166 | all breakpoints that are marked for deletion, whether hit or not. | |
12167 | This is called after any breakpoint is hit, or after errors. */ | |
12168 | ||
12169 | void | |
fba45db2 | 12170 | breakpoint_auto_delete (bpstat bs) |
c906108c | 12171 | { |
35df4500 | 12172 | struct breakpoint *b, *b_tmp; |
c906108c SS |
12173 | |
12174 | for (; bs; bs = bs->next) | |
f431efe5 PA |
12175 | if (bs->breakpoint_at |
12176 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 12177 | && bs->stop) |
f431efe5 | 12178 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 12179 | |
35df4500 | 12180 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 12181 | { |
b5de0fa7 | 12182 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
12183 | delete_breakpoint (b); |
12184 | } | |
c906108c SS |
12185 | } |
12186 | ||
4a64f543 MS |
12187 | /* A comparison function for bp_location AP and BP being interfaced to |
12188 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
12189 | does breakpoint_address_is_meaningful say for its OWNER), | |
1a853c52 | 12190 | secondarily by ordering first permanent elements and |
4a64f543 | 12191 | terciarily just ensuring the array is sorted stable way despite |
e5dd4106 | 12192 | qsort being an unstable algorithm. */ |
876fa593 JK |
12193 | |
12194 | static int | |
494cfb0f | 12195 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 12196 | { |
9a3c8263 SM |
12197 | const struct bp_location *a = *(const struct bp_location **) ap; |
12198 | const struct bp_location *b = *(const struct bp_location **) bp; | |
876fa593 JK |
12199 | |
12200 | if (a->address != b->address) | |
12201 | return (a->address > b->address) - (a->address < b->address); | |
12202 | ||
dea2aa5f LM |
12203 | /* Sort locations at the same address by their pspace number, keeping |
12204 | locations of the same inferior (in a multi-inferior environment) | |
12205 | grouped. */ | |
12206 | ||
12207 | if (a->pspace->num != b->pspace->num) | |
12208 | return ((a->pspace->num > b->pspace->num) | |
12209 | - (a->pspace->num < b->pspace->num)); | |
12210 | ||
876fa593 | 12211 | /* Sort permanent breakpoints first. */ |
1a853c52 PA |
12212 | if (a->permanent != b->permanent) |
12213 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); | |
876fa593 | 12214 | |
c56a97f9 JK |
12215 | /* Make the internal GDB representation stable across GDB runs |
12216 | where A and B memory inside GDB can differ. Breakpoint locations of | |
12217 | the same type at the same address can be sorted in arbitrary order. */ | |
876fa593 JK |
12218 | |
12219 | if (a->owner->number != b->owner->number) | |
c56a97f9 JK |
12220 | return ((a->owner->number > b->owner->number) |
12221 | - (a->owner->number < b->owner->number)); | |
876fa593 JK |
12222 | |
12223 | return (a > b) - (a < b); | |
12224 | } | |
12225 | ||
876fa593 | 12226 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
12227 | bp_location_shadow_len_after_address_max according to the current |
12228 | content of the bp_location array. */ | |
f7545552 TT |
12229 | |
12230 | static void | |
876fa593 | 12231 | bp_location_target_extensions_update (void) |
f7545552 | 12232 | { |
876fa593 JK |
12233 | struct bp_location *bl, **blp_tmp; |
12234 | ||
12235 | bp_location_placed_address_before_address_max = 0; | |
12236 | bp_location_shadow_len_after_address_max = 0; | |
12237 | ||
12238 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
12239 | { | |
12240 | CORE_ADDR start, end, addr; | |
12241 | ||
12242 | if (!bp_location_has_shadow (bl)) | |
12243 | continue; | |
12244 | ||
12245 | start = bl->target_info.placed_address; | |
12246 | end = start + bl->target_info.shadow_len; | |
12247 | ||
12248 | gdb_assert (bl->address >= start); | |
12249 | addr = bl->address - start; | |
12250 | if (addr > bp_location_placed_address_before_address_max) | |
12251 | bp_location_placed_address_before_address_max = addr; | |
12252 | ||
12253 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
12254 | ||
12255 | gdb_assert (bl->address < end); | |
12256 | addr = end - bl->address; | |
12257 | if (addr > bp_location_shadow_len_after_address_max) | |
12258 | bp_location_shadow_len_after_address_max = addr; | |
12259 | } | |
f7545552 TT |
12260 | } |
12261 | ||
1e4d1764 YQ |
12262 | /* Download tracepoint locations if they haven't been. */ |
12263 | ||
12264 | static void | |
12265 | download_tracepoint_locations (void) | |
12266 | { | |
7ed2c994 | 12267 | struct breakpoint *b; |
1e4d1764 | 12268 | struct cleanup *old_chain; |
dd2e65cc | 12269 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
1e4d1764 YQ |
12270 | |
12271 | old_chain = save_current_space_and_thread (); | |
12272 | ||
7ed2c994 | 12273 | ALL_TRACEPOINTS (b) |
1e4d1764 | 12274 | { |
7ed2c994 | 12275 | struct bp_location *bl; |
1e4d1764 | 12276 | struct tracepoint *t; |
f2a8bc8a | 12277 | int bp_location_downloaded = 0; |
1e4d1764 | 12278 | |
7ed2c994 | 12279 | if ((b->type == bp_fast_tracepoint |
1e4d1764 YQ |
12280 | ? !may_insert_fast_tracepoints |
12281 | : !may_insert_tracepoints)) | |
12282 | continue; | |
12283 | ||
dd2e65cc YQ |
12284 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
12285 | { | |
12286 | if (target_can_download_tracepoint ()) | |
12287 | can_download_tracepoint = TRIBOOL_TRUE; | |
12288 | else | |
12289 | can_download_tracepoint = TRIBOOL_FALSE; | |
12290 | } | |
12291 | ||
12292 | if (can_download_tracepoint == TRIBOOL_FALSE) | |
12293 | break; | |
12294 | ||
7ed2c994 YQ |
12295 | for (bl = b->loc; bl; bl = bl->next) |
12296 | { | |
12297 | /* In tracepoint, locations are _never_ duplicated, so | |
12298 | should_be_inserted is equivalent to | |
12299 | unduplicated_should_be_inserted. */ | |
12300 | if (!should_be_inserted (bl) || bl->inserted) | |
12301 | continue; | |
1e4d1764 | 12302 | |
7ed2c994 | 12303 | switch_to_program_space_and_thread (bl->pspace); |
1e4d1764 | 12304 | |
7ed2c994 | 12305 | target_download_tracepoint (bl); |
1e4d1764 | 12306 | |
7ed2c994 | 12307 | bl->inserted = 1; |
f2a8bc8a | 12308 | bp_location_downloaded = 1; |
7ed2c994 YQ |
12309 | } |
12310 | t = (struct tracepoint *) b; | |
12311 | t->number_on_target = b->number; | |
f2a8bc8a YQ |
12312 | if (bp_location_downloaded) |
12313 | observer_notify_breakpoint_modified (b); | |
1e4d1764 YQ |
12314 | } |
12315 | ||
12316 | do_cleanups (old_chain); | |
12317 | } | |
12318 | ||
934709f0 PW |
12319 | /* Swap the insertion/duplication state between two locations. */ |
12320 | ||
12321 | static void | |
12322 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
12323 | { | |
12324 | const int left_inserted = left->inserted; | |
12325 | const int left_duplicate = left->duplicate; | |
b775012e | 12326 | const int left_needs_update = left->needs_update; |
934709f0 PW |
12327 | const struct bp_target_info left_target_info = left->target_info; |
12328 | ||
1e4d1764 YQ |
12329 | /* Locations of tracepoints can never be duplicated. */ |
12330 | if (is_tracepoint (left->owner)) | |
12331 | gdb_assert (!left->duplicate); | |
12332 | if (is_tracepoint (right->owner)) | |
12333 | gdb_assert (!right->duplicate); | |
12334 | ||
934709f0 PW |
12335 | left->inserted = right->inserted; |
12336 | left->duplicate = right->duplicate; | |
b775012e | 12337 | left->needs_update = right->needs_update; |
934709f0 PW |
12338 | left->target_info = right->target_info; |
12339 | right->inserted = left_inserted; | |
12340 | right->duplicate = left_duplicate; | |
b775012e | 12341 | right->needs_update = left_needs_update; |
934709f0 PW |
12342 | right->target_info = left_target_info; |
12343 | } | |
12344 | ||
b775012e LM |
12345 | /* Force the re-insertion of the locations at ADDRESS. This is called |
12346 | once a new/deleted/modified duplicate location is found and we are evaluating | |
12347 | conditions on the target's side. Such conditions need to be updated on | |
12348 | the target. */ | |
12349 | ||
12350 | static void | |
12351 | force_breakpoint_reinsertion (struct bp_location *bl) | |
12352 | { | |
12353 | struct bp_location **locp = NULL, **loc2p; | |
12354 | struct bp_location *loc; | |
12355 | CORE_ADDR address = 0; | |
12356 | int pspace_num; | |
12357 | ||
12358 | address = bl->address; | |
12359 | pspace_num = bl->pspace->num; | |
12360 | ||
12361 | /* This is only meaningful if the target is | |
12362 | evaluating conditions and if the user has | |
12363 | opted for condition evaluation on the target's | |
12364 | side. */ | |
12365 | if (gdb_evaluates_breakpoint_condition_p () | |
12366 | || !target_supports_evaluation_of_breakpoint_conditions ()) | |
12367 | return; | |
12368 | ||
12369 | /* Flag all breakpoint locations with this address and | |
12370 | the same program space as the location | |
12371 | as "its condition has changed". We need to | |
12372 | update the conditions on the target's side. */ | |
12373 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) | |
12374 | { | |
12375 | loc = *loc2p; | |
12376 | ||
12377 | if (!is_breakpoint (loc->owner) | |
12378 | || pspace_num != loc->pspace->num) | |
12379 | continue; | |
12380 | ||
12381 | /* Flag the location appropriately. We use a different state to | |
12382 | let everyone know that we already updated the set of locations | |
12383 | with addr bl->address and program space bl->pspace. This is so | |
12384 | we don't have to keep calling these functions just to mark locations | |
12385 | that have already been marked. */ | |
12386 | loc->condition_changed = condition_updated; | |
12387 | ||
12388 | /* Free the agent expression bytecode as well. We will compute | |
12389 | it later on. */ | |
12390 | if (loc->cond_bytecode) | |
12391 | { | |
12392 | free_agent_expr (loc->cond_bytecode); | |
12393 | loc->cond_bytecode = NULL; | |
12394 | } | |
12395 | } | |
12396 | } | |
44702360 PA |
12397 | /* Called whether new breakpoints are created, or existing breakpoints |
12398 | deleted, to update the global location list and recompute which | |
12399 | locations are duplicate of which. | |
b775012e | 12400 | |
04086b45 PA |
12401 | The INSERT_MODE flag determines whether locations may not, may, or |
12402 | shall be inserted now. See 'enum ugll_insert_mode' for more | |
12403 | info. */ | |
b60e7edf | 12404 | |
0d381245 | 12405 | static void |
44702360 | 12406 | update_global_location_list (enum ugll_insert_mode insert_mode) |
0d381245 | 12407 | { |
74960c60 | 12408 | struct breakpoint *b; |
876fa593 | 12409 | struct bp_location **locp, *loc; |
f7545552 | 12410 | struct cleanup *cleanups; |
b775012e LM |
12411 | /* Last breakpoint location address that was marked for update. */ |
12412 | CORE_ADDR last_addr = 0; | |
12413 | /* Last breakpoint location program space that was marked for update. */ | |
12414 | int last_pspace_num = -1; | |
f7545552 | 12415 | |
2d134ed3 PA |
12416 | /* Used in the duplicates detection below. When iterating over all |
12417 | bp_locations, points to the first bp_location of a given address. | |
12418 | Breakpoints and watchpoints of different types are never | |
12419 | duplicates of each other. Keep one pointer for each type of | |
12420 | breakpoint/watchpoint, so we only need to loop over all locations | |
12421 | once. */ | |
12422 | struct bp_location *bp_loc_first; /* breakpoint */ | |
12423 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
12424 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
12425 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 12426 | |
4a64f543 MS |
12427 | /* Saved former bp_location array which we compare against the newly |
12428 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
12429 | struct bp_location **old_location, **old_locp; |
12430 | unsigned old_location_count; | |
12431 | ||
12432 | old_location = bp_location; | |
12433 | old_location_count = bp_location_count; | |
12434 | bp_location = NULL; | |
12435 | bp_location_count = 0; | |
12436 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 12437 | |
74960c60 | 12438 | ALL_BREAKPOINTS (b) |
876fa593 JK |
12439 | for (loc = b->loc; loc; loc = loc->next) |
12440 | bp_location_count++; | |
12441 | ||
8d749320 | 12442 | bp_location = XNEWVEC (struct bp_location *, bp_location_count); |
876fa593 JK |
12443 | locp = bp_location; |
12444 | ALL_BREAKPOINTS (b) | |
12445 | for (loc = b->loc; loc; loc = loc->next) | |
12446 | *locp++ = loc; | |
12447 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 12448 | bp_location_compare); |
876fa593 JK |
12449 | |
12450 | bp_location_target_extensions_update (); | |
74960c60 | 12451 | |
4a64f543 MS |
12452 | /* Identify bp_location instances that are no longer present in the |
12453 | new list, and therefore should be freed. Note that it's not | |
12454 | necessary that those locations should be removed from inferior -- | |
12455 | if there's another location at the same address (previously | |
12456 | marked as duplicate), we don't need to remove/insert the | |
12457 | location. | |
876fa593 | 12458 | |
4a64f543 MS |
12459 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
12460 | and former bp_location array state respectively. */ | |
876fa593 JK |
12461 | |
12462 | locp = bp_location; | |
12463 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
12464 | old_locp++) | |
74960c60 | 12465 | { |
876fa593 | 12466 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 12467 | struct bp_location **loc2p; |
876fa593 | 12468 | |
e5dd4106 | 12469 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 12470 | not, we have to free it. */ |
c7d46a38 | 12471 | int found_object = 0; |
20874c92 VP |
12472 | /* Tells if the location should remain inserted in the target. */ |
12473 | int keep_in_target = 0; | |
12474 | int removed = 0; | |
876fa593 | 12475 | |
4a64f543 MS |
12476 | /* Skip LOCP entries which will definitely never be needed. |
12477 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 12478 | while (locp < bp_location + bp_location_count |
c7d46a38 | 12479 | && (*locp)->address < old_loc->address) |
876fa593 | 12480 | locp++; |
c7d46a38 PA |
12481 | |
12482 | for (loc2p = locp; | |
12483 | (loc2p < bp_location + bp_location_count | |
12484 | && (*loc2p)->address == old_loc->address); | |
12485 | loc2p++) | |
12486 | { | |
b775012e LM |
12487 | /* Check if this is a new/duplicated location or a duplicated |
12488 | location that had its condition modified. If so, we want to send | |
12489 | its condition to the target if evaluation of conditions is taking | |
12490 | place there. */ | |
12491 | if ((*loc2p)->condition_changed == condition_modified | |
12492 | && (last_addr != old_loc->address | |
12493 | || last_pspace_num != old_loc->pspace->num)) | |
c7d46a38 | 12494 | { |
b775012e LM |
12495 | force_breakpoint_reinsertion (*loc2p); |
12496 | last_pspace_num = old_loc->pspace->num; | |
c7d46a38 | 12497 | } |
b775012e LM |
12498 | |
12499 | if (*loc2p == old_loc) | |
12500 | found_object = 1; | |
c7d46a38 | 12501 | } |
74960c60 | 12502 | |
b775012e LM |
12503 | /* We have already handled this address, update it so that we don't |
12504 | have to go through updates again. */ | |
12505 | last_addr = old_loc->address; | |
12506 | ||
12507 | /* Target-side condition evaluation: Handle deleted locations. */ | |
12508 | if (!found_object) | |
12509 | force_breakpoint_reinsertion (old_loc); | |
12510 | ||
4a64f543 MS |
12511 | /* If this location is no longer present, and inserted, look if |
12512 | there's maybe a new location at the same address. If so, | |
12513 | mark that one inserted, and don't remove this one. This is | |
12514 | needed so that we don't have a time window where a breakpoint | |
12515 | at certain location is not inserted. */ | |
74960c60 | 12516 | |
876fa593 | 12517 | if (old_loc->inserted) |
0d381245 | 12518 | { |
4a64f543 MS |
12519 | /* If the location is inserted now, we might have to remove |
12520 | it. */ | |
74960c60 | 12521 | |
876fa593 | 12522 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 12523 | { |
4a64f543 MS |
12524 | /* The location is still present in the location list, |
12525 | and still should be inserted. Don't do anything. */ | |
20874c92 | 12526 | keep_in_target = 1; |
74960c60 VP |
12527 | } |
12528 | else | |
12529 | { | |
b775012e LM |
12530 | /* This location still exists, but it won't be kept in the |
12531 | target since it may have been disabled. We proceed to | |
12532 | remove its target-side condition. */ | |
12533 | ||
4a64f543 MS |
12534 | /* The location is either no longer present, or got |
12535 | disabled. See if there's another location at the | |
12536 | same address, in which case we don't need to remove | |
12537 | this one from the target. */ | |
876fa593 | 12538 | |
2bdf28a0 | 12539 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
12540 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
12541 | { | |
876fa593 | 12542 | for (loc2p = locp; |
c7d46a38 PA |
12543 | (loc2p < bp_location + bp_location_count |
12544 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
12545 | loc2p++) |
12546 | { | |
12547 | struct bp_location *loc2 = *loc2p; | |
12548 | ||
2d134ed3 | 12549 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 12550 | { |
85d721b8 PA |
12551 | /* Read watchpoint locations are switched to |
12552 | access watchpoints, if the former are not | |
12553 | supported, but the latter are. */ | |
12554 | if (is_hardware_watchpoint (old_loc->owner)) | |
12555 | { | |
12556 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
12557 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
12558 | } | |
12559 | ||
934709f0 PW |
12560 | /* loc2 is a duplicated location. We need to check |
12561 | if it should be inserted in case it will be | |
12562 | unduplicated. */ | |
12563 | if (loc2 != old_loc | |
12564 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 12565 | { |
934709f0 | 12566 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
12567 | keep_in_target = 1; |
12568 | break; | |
12569 | } | |
876fa593 JK |
12570 | } |
12571 | } | |
12572 | } | |
74960c60 VP |
12573 | } |
12574 | ||
20874c92 VP |
12575 | if (!keep_in_target) |
12576 | { | |
876fa593 | 12577 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 12578 | { |
4a64f543 MS |
12579 | /* This is just about all we can do. We could keep |
12580 | this location on the global list, and try to | |
12581 | remove it next time, but there's no particular | |
12582 | reason why we will succeed next time. | |
20874c92 | 12583 | |
4a64f543 MS |
12584 | Note that at this point, old_loc->owner is still |
12585 | valid, as delete_breakpoint frees the breakpoint | |
12586 | only after calling us. */ | |
3e43a32a MS |
12587 | printf_filtered (_("warning: Error removing " |
12588 | "breakpoint %d\n"), | |
876fa593 | 12589 | old_loc->owner->number); |
20874c92 VP |
12590 | } |
12591 | removed = 1; | |
12592 | } | |
0d381245 | 12593 | } |
74960c60 VP |
12594 | |
12595 | if (!found_object) | |
1c5cfe86 | 12596 | { |
fbea99ea | 12597 | if (removed && target_is_non_stop_p () |
1cf4d951 | 12598 | && need_moribund_for_location_type (old_loc)) |
20874c92 | 12599 | { |
db82e815 PA |
12600 | /* This location was removed from the target. In |
12601 | non-stop mode, a race condition is possible where | |
12602 | we've removed a breakpoint, but stop events for that | |
12603 | breakpoint are already queued and will arrive later. | |
12604 | We apply an heuristic to be able to distinguish such | |
12605 | SIGTRAPs from other random SIGTRAPs: we keep this | |
12606 | breakpoint location for a bit, and will retire it | |
12607 | after we see some number of events. The theory here | |
12608 | is that reporting of events should, "on the average", | |
12609 | be fair, so after a while we'll see events from all | |
12610 | threads that have anything of interest, and no longer | |
12611 | need to keep this breakpoint location around. We | |
12612 | don't hold locations forever so to reduce chances of | |
12613 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
12614 | SIGTRAP. | |
12615 | ||
12616 | The heuristic failing can be disastrous on | |
12617 | decr_pc_after_break targets. | |
12618 | ||
12619 | On decr_pc_after_break targets, like e.g., x86-linux, | |
12620 | if we fail to recognize a late breakpoint SIGTRAP, | |
12621 | because events_till_retirement has reached 0 too | |
12622 | soon, we'll fail to do the PC adjustment, and report | |
12623 | a random SIGTRAP to the user. When the user resumes | |
12624 | the inferior, it will most likely immediately crash | |
2dec564e | 12625 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
12626 | corrupted, because of being resumed e.g., in the |
12627 | middle of a multi-byte instruction, or skipped a | |
12628 | one-byte instruction. This was actually seen happen | |
12629 | on native x86-linux, and should be less rare on | |
12630 | targets that do not support new thread events, like | |
12631 | remote, due to the heuristic depending on | |
12632 | thread_count. | |
12633 | ||
12634 | Mistaking a random SIGTRAP for a breakpoint trap | |
12635 | causes similar symptoms (PC adjustment applied when | |
12636 | it shouldn't), but then again, playing with SIGTRAPs | |
12637 | behind the debugger's back is asking for trouble. | |
12638 | ||
12639 | Since hardware watchpoint traps are always | |
12640 | distinguishable from other traps, so we don't need to | |
12641 | apply keep hardware watchpoint moribund locations | |
12642 | around. We simply always ignore hardware watchpoint | |
12643 | traps we can no longer explain. */ | |
12644 | ||
876fa593 JK |
12645 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
12646 | old_loc->owner = NULL; | |
20874c92 | 12647 | |
876fa593 | 12648 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
12649 | } |
12650 | else | |
f431efe5 PA |
12651 | { |
12652 | old_loc->owner = NULL; | |
12653 | decref_bp_location (&old_loc); | |
12654 | } | |
20874c92 | 12655 | } |
74960c60 | 12656 | } |
1c5cfe86 | 12657 | |
348d480f PA |
12658 | /* Rescan breakpoints at the same address and section, marking the |
12659 | first one as "first" and any others as "duplicates". This is so | |
12660 | that the bpt instruction is only inserted once. If we have a | |
12661 | permanent breakpoint at the same place as BPT, make that one the | |
12662 | official one, and the rest as duplicates. Permanent breakpoints | |
12663 | are sorted first for the same address. | |
12664 | ||
12665 | Do the same for hardware watchpoints, but also considering the | |
12666 | watchpoint's type (regular/access/read) and length. */ | |
12667 | ||
12668 | bp_loc_first = NULL; | |
12669 | wp_loc_first = NULL; | |
12670 | awp_loc_first = NULL; | |
12671 | rwp_loc_first = NULL; | |
12672 | ALL_BP_LOCATIONS (loc, locp) | |
12673 | { | |
12674 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
12675 | non-NULL. */ | |
348d480f | 12676 | struct bp_location **loc_first_p; |
d3fbdd86 | 12677 | b = loc->owner; |
348d480f | 12678 | |
6f380991 | 12679 | if (!unduplicated_should_be_inserted (loc) |
348d480f | 12680 | || !breakpoint_address_is_meaningful (b) |
1e4d1764 YQ |
12681 | /* Don't detect duplicate for tracepoint locations because they are |
12682 | never duplicated. See the comments in field `duplicate' of | |
12683 | `struct bp_location'. */ | |
348d480f | 12684 | || is_tracepoint (b)) |
b775012e LM |
12685 | { |
12686 | /* Clear the condition modification flag. */ | |
12687 | loc->condition_changed = condition_unchanged; | |
12688 | continue; | |
12689 | } | |
348d480f | 12690 | |
348d480f PA |
12691 | if (b->type == bp_hardware_watchpoint) |
12692 | loc_first_p = &wp_loc_first; | |
12693 | else if (b->type == bp_read_watchpoint) | |
12694 | loc_first_p = &rwp_loc_first; | |
12695 | else if (b->type == bp_access_watchpoint) | |
12696 | loc_first_p = &awp_loc_first; | |
12697 | else | |
12698 | loc_first_p = &bp_loc_first; | |
12699 | ||
12700 | if (*loc_first_p == NULL | |
12701 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
12702 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
12703 | { | |
12704 | *loc_first_p = loc; | |
12705 | loc->duplicate = 0; | |
b775012e LM |
12706 | |
12707 | if (is_breakpoint (loc->owner) && loc->condition_changed) | |
12708 | { | |
12709 | loc->needs_update = 1; | |
12710 | /* Clear the condition modification flag. */ | |
12711 | loc->condition_changed = condition_unchanged; | |
12712 | } | |
348d480f PA |
12713 | continue; |
12714 | } | |
12715 | ||
934709f0 PW |
12716 | |
12717 | /* This and the above ensure the invariant that the first location | |
12718 | is not duplicated, and is the inserted one. | |
12719 | All following are marked as duplicated, and are not inserted. */ | |
12720 | if (loc->inserted) | |
12721 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
12722 | loc->duplicate = 1; |
12723 | ||
b775012e LM |
12724 | /* Clear the condition modification flag. */ |
12725 | loc->condition_changed = condition_unchanged; | |
348d480f PA |
12726 | } |
12727 | ||
a25a5a45 | 12728 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
b775012e | 12729 | { |
04086b45 | 12730 | if (insert_mode != UGLL_DONT_INSERT) |
b775012e LM |
12731 | insert_breakpoint_locations (); |
12732 | else | |
12733 | { | |
44702360 PA |
12734 | /* Even though the caller told us to not insert new |
12735 | locations, we may still need to update conditions on the | |
12736 | target's side of breakpoints that were already inserted | |
12737 | if the target is evaluating breakpoint conditions. We | |
b775012e LM |
12738 | only update conditions for locations that are marked |
12739 | "needs_update". */ | |
12740 | update_inserted_breakpoint_locations (); | |
12741 | } | |
12742 | } | |
348d480f | 12743 | |
04086b45 | 12744 | if (insert_mode != UGLL_DONT_INSERT) |
1e4d1764 YQ |
12745 | download_tracepoint_locations (); |
12746 | ||
348d480f PA |
12747 | do_cleanups (cleanups); |
12748 | } | |
12749 | ||
12750 | void | |
12751 | breakpoint_retire_moribund (void) | |
12752 | { | |
12753 | struct bp_location *loc; | |
12754 | int ix; | |
12755 | ||
12756 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
12757 | if (--(loc->events_till_retirement) == 0) | |
12758 | { | |
12759 | decref_bp_location (&loc); | |
12760 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
12761 | --ix; | |
12762 | } | |
12763 | } | |
12764 | ||
12765 | static void | |
44702360 | 12766 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
348d480f | 12767 | { |
348d480f | 12768 | |
492d29ea PA |
12769 | TRY |
12770 | { | |
12771 | update_global_location_list (insert_mode); | |
12772 | } | |
12773 | CATCH (e, RETURN_MASK_ERROR) | |
12774 | { | |
12775 | } | |
12776 | END_CATCH | |
348d480f PA |
12777 | } |
12778 | ||
12779 | /* Clear BKP from a BPS. */ | |
12780 | ||
12781 | static void | |
12782 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
12783 | { | |
12784 | bpstat bs; | |
12785 | ||
12786 | for (bs = bps; bs; bs = bs->next) | |
12787 | if (bs->breakpoint_at == bpt) | |
12788 | { | |
12789 | bs->breakpoint_at = NULL; | |
12790 | bs->old_val = NULL; | |
12791 | /* bs->commands will be freed later. */ | |
12792 | } | |
12793 | } | |
12794 | ||
12795 | /* Callback for iterate_over_threads. */ | |
12796 | static int | |
12797 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
12798 | { | |
9a3c8263 | 12799 | struct breakpoint *bpt = (struct breakpoint *) data; |
348d480f PA |
12800 | |
12801 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
12802 | return 0; | |
12803 | } | |
12804 | ||
12805 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
12806 | callbacks. */ | |
12807 | ||
12808 | static void | |
12809 | say_where (struct breakpoint *b) | |
12810 | { | |
12811 | struct value_print_options opts; | |
12812 | ||
12813 | get_user_print_options (&opts); | |
12814 | ||
12815 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
12816 | single string. */ | |
12817 | if (b->loc == NULL) | |
12818 | { | |
f00aae0f KS |
12819 | /* For pending locations, the output differs slightly based |
12820 | on b->extra_string. If this is non-NULL, it contains either | |
12821 | a condition or dprintf arguments. */ | |
12822 | if (b->extra_string == NULL) | |
12823 | { | |
12824 | printf_filtered (_(" (%s) pending."), | |
12825 | event_location_to_string (b->location)); | |
12826 | } | |
12827 | else if (b->type == bp_dprintf) | |
12828 | { | |
12829 | printf_filtered (_(" (%s,%s) pending."), | |
12830 | event_location_to_string (b->location), | |
12831 | b->extra_string); | |
12832 | } | |
12833 | else | |
12834 | { | |
12835 | printf_filtered (_(" (%s %s) pending."), | |
12836 | event_location_to_string (b->location), | |
12837 | b->extra_string); | |
12838 | } | |
348d480f PA |
12839 | } |
12840 | else | |
12841 | { | |
2f202fde | 12842 | if (opts.addressprint || b->loc->symtab == NULL) |
348d480f PA |
12843 | { |
12844 | printf_filtered (" at "); | |
12845 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
12846 | gdb_stdout); | |
12847 | } | |
2f202fde | 12848 | if (b->loc->symtab != NULL) |
f8eba3c6 TT |
12849 | { |
12850 | /* If there is a single location, we can print the location | |
12851 | more nicely. */ | |
12852 | if (b->loc->next == NULL) | |
12853 | printf_filtered (": file %s, line %d.", | |
05cba821 JK |
12854 | symtab_to_filename_for_display (b->loc->symtab), |
12855 | b->loc->line_number); | |
f8eba3c6 TT |
12856 | else |
12857 | /* This is not ideal, but each location may have a | |
12858 | different file name, and this at least reflects the | |
12859 | real situation somewhat. */ | |
f00aae0f KS |
12860 | printf_filtered (": %s.", |
12861 | event_location_to_string (b->location)); | |
f8eba3c6 | 12862 | } |
348d480f PA |
12863 | |
12864 | if (b->loc->next) | |
12865 | { | |
12866 | struct bp_location *loc = b->loc; | |
12867 | int n = 0; | |
12868 | for (; loc; loc = loc->next) | |
12869 | ++n; | |
12870 | printf_filtered (" (%d locations)", n); | |
12871 | } | |
12872 | } | |
12873 | } | |
12874 | ||
348d480f PA |
12875 | /* Default bp_location_ops methods. */ |
12876 | ||
12877 | static void | |
12878 | bp_location_dtor (struct bp_location *self) | |
12879 | { | |
12880 | xfree (self->cond); | |
b775012e LM |
12881 | if (self->cond_bytecode) |
12882 | free_agent_expr (self->cond_bytecode); | |
348d480f | 12883 | xfree (self->function_name); |
8b4f3082 PA |
12884 | |
12885 | VEC_free (agent_expr_p, self->target_info.conditions); | |
12886 | VEC_free (agent_expr_p, self->target_info.tcommands); | |
348d480f PA |
12887 | } |
12888 | ||
12889 | static const struct bp_location_ops bp_location_ops = | |
12890 | { | |
12891 | bp_location_dtor | |
12892 | }; | |
12893 | ||
2060206e PA |
12894 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
12895 | inherit from. */ | |
348d480f | 12896 | |
2060206e PA |
12897 | static void |
12898 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
12899 | { |
12900 | decref_counted_command_line (&self->commands); | |
12901 | xfree (self->cond_string); | |
fb81d016 | 12902 | xfree (self->extra_string); |
f8eba3c6 | 12903 | xfree (self->filter); |
f00aae0f KS |
12904 | delete_event_location (self->location); |
12905 | delete_event_location (self->location_range_end); | |
348d480f PA |
12906 | } |
12907 | ||
2060206e PA |
12908 | static struct bp_location * |
12909 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
12910 | { |
12911 | struct bp_location *loc; | |
12912 | ||
12913 | loc = XNEW (struct bp_location); | |
12914 | init_bp_location (loc, &bp_location_ops, self); | |
12915 | return loc; | |
12916 | } | |
12917 | ||
2060206e PA |
12918 | static void |
12919 | base_breakpoint_re_set (struct breakpoint *b) | |
12920 | { | |
12921 | /* Nothing to re-set. */ | |
12922 | } | |
12923 | ||
12924 | #define internal_error_pure_virtual_called() \ | |
12925 | gdb_assert_not_reached ("pure virtual function called") | |
12926 | ||
12927 | static int | |
12928 | base_breakpoint_insert_location (struct bp_location *bl) | |
12929 | { | |
12930 | internal_error_pure_virtual_called (); | |
12931 | } | |
12932 | ||
12933 | static int | |
12934 | base_breakpoint_remove_location (struct bp_location *bl) | |
12935 | { | |
12936 | internal_error_pure_virtual_called (); | |
12937 | } | |
12938 | ||
12939 | static int | |
12940 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
12941 | struct address_space *aspace, | |
09ac7c10 TT |
12942 | CORE_ADDR bp_addr, |
12943 | const struct target_waitstatus *ws) | |
2060206e PA |
12944 | { |
12945 | internal_error_pure_virtual_called (); | |
12946 | } | |
12947 | ||
12948 | static void | |
12949 | base_breakpoint_check_status (bpstat bs) | |
12950 | { | |
12951 | /* Always stop. */ | |
12952 | } | |
12953 | ||
12954 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
12955 | errors. */ | |
12956 | ||
12957 | static int | |
12958 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
12959 | { | |
12960 | internal_error_pure_virtual_called (); | |
12961 | } | |
12962 | ||
12963 | /* A "resources_needed" breakpoint_ops method that just internal | |
12964 | errors. */ | |
12965 | ||
12966 | static int | |
12967 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
12968 | { | |
12969 | internal_error_pure_virtual_called (); | |
12970 | } | |
12971 | ||
12972 | static enum print_stop_action | |
12973 | base_breakpoint_print_it (bpstat bs) | |
12974 | { | |
12975 | internal_error_pure_virtual_called (); | |
12976 | } | |
12977 | ||
12978 | static void | |
12979 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
12980 | struct ui_out *uiout) | |
12981 | { | |
12982 | /* nothing */ | |
12983 | } | |
12984 | ||
12985 | static void | |
12986 | base_breakpoint_print_mention (struct breakpoint *b) | |
12987 | { | |
12988 | internal_error_pure_virtual_called (); | |
12989 | } | |
12990 | ||
12991 | static void | |
12992 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
12993 | { | |
12994 | internal_error_pure_virtual_called (); | |
12995 | } | |
12996 | ||
983af33b | 12997 | static void |
f00aae0f KS |
12998 | base_breakpoint_create_sals_from_location |
12999 | (const struct event_location *location, | |
13000 | struct linespec_result *canonical, | |
13001 | enum bptype type_wanted) | |
983af33b SDJ |
13002 | { |
13003 | internal_error_pure_virtual_called (); | |
13004 | } | |
13005 | ||
13006 | static void | |
13007 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13008 | struct linespec_result *c, | |
983af33b | 13009 | char *cond_string, |
e7e0cddf | 13010 | char *extra_string, |
983af33b SDJ |
13011 | enum bptype type_wanted, |
13012 | enum bpdisp disposition, | |
13013 | int thread, | |
13014 | int task, int ignore_count, | |
13015 | const struct breakpoint_ops *o, | |
13016 | int from_tty, int enabled, | |
44f238bb | 13017 | int internal, unsigned flags) |
983af33b SDJ |
13018 | { |
13019 | internal_error_pure_virtual_called (); | |
13020 | } | |
13021 | ||
13022 | static void | |
f00aae0f KS |
13023 | base_breakpoint_decode_location (struct breakpoint *b, |
13024 | const struct event_location *location, | |
c2f4122d | 13025 | struct program_space *search_pspace, |
983af33b SDJ |
13026 | struct symtabs_and_lines *sals) |
13027 | { | |
13028 | internal_error_pure_virtual_called (); | |
13029 | } | |
13030 | ||
ab04a2af TT |
13031 | /* The default 'explains_signal' method. */ |
13032 | ||
47591c29 | 13033 | static int |
427cd150 | 13034 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
ab04a2af | 13035 | { |
47591c29 | 13036 | return 1; |
ab04a2af TT |
13037 | } |
13038 | ||
9d6e6e84 HZ |
13039 | /* The default "after_condition_true" method. */ |
13040 | ||
13041 | static void | |
13042 | base_breakpoint_after_condition_true (struct bpstats *bs) | |
13043 | { | |
13044 | /* Nothing to do. */ | |
13045 | } | |
13046 | ||
ab04a2af | 13047 | struct breakpoint_ops base_breakpoint_ops = |
2060206e PA |
13048 | { |
13049 | base_breakpoint_dtor, | |
13050 | base_breakpoint_allocate_location, | |
13051 | base_breakpoint_re_set, | |
13052 | base_breakpoint_insert_location, | |
13053 | base_breakpoint_remove_location, | |
13054 | base_breakpoint_breakpoint_hit, | |
13055 | base_breakpoint_check_status, | |
13056 | base_breakpoint_resources_needed, | |
13057 | base_breakpoint_works_in_software_mode, | |
13058 | base_breakpoint_print_it, | |
13059 | NULL, | |
13060 | base_breakpoint_print_one_detail, | |
13061 | base_breakpoint_print_mention, | |
983af33b | 13062 | base_breakpoint_print_recreate, |
5f700d83 | 13063 | base_breakpoint_create_sals_from_location, |
983af33b | 13064 | base_breakpoint_create_breakpoints_sal, |
5f700d83 | 13065 | base_breakpoint_decode_location, |
9d6e6e84 HZ |
13066 | base_breakpoint_explains_signal, |
13067 | base_breakpoint_after_condition_true, | |
2060206e PA |
13068 | }; |
13069 | ||
13070 | /* Default breakpoint_ops methods. */ | |
13071 | ||
13072 | static void | |
348d480f PA |
13073 | bkpt_re_set (struct breakpoint *b) |
13074 | { | |
06edf0c0 | 13075 | /* FIXME: is this still reachable? */ |
f00aae0f | 13076 | if (event_location_empty_p (b->location)) |
06edf0c0 | 13077 | { |
f00aae0f | 13078 | /* Anything without a location can't be re-set. */ |
348d480f | 13079 | delete_breakpoint (b); |
06edf0c0 | 13080 | return; |
348d480f | 13081 | } |
06edf0c0 PA |
13082 | |
13083 | breakpoint_re_set_default (b); | |
348d480f PA |
13084 | } |
13085 | ||
2060206e | 13086 | static int |
348d480f PA |
13087 | bkpt_insert_location (struct bp_location *bl) |
13088 | { | |
13089 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
7c16b83e | 13090 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f | 13091 | else |
7c16b83e | 13092 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13093 | } |
13094 | ||
2060206e | 13095 | static int |
348d480f PA |
13096 | bkpt_remove_location (struct bp_location *bl) |
13097 | { | |
13098 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
13099 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
13100 | else | |
7c16b83e | 13101 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
348d480f PA |
13102 | } |
13103 | ||
2060206e | 13104 | static int |
348d480f | 13105 | bkpt_breakpoint_hit (const struct bp_location *bl, |
09ac7c10 TT |
13106 | struct address_space *aspace, CORE_ADDR bp_addr, |
13107 | const struct target_waitstatus *ws) | |
348d480f | 13108 | { |
09ac7c10 | 13109 | if (ws->kind != TARGET_WAITKIND_STOPPED |
a493e3e2 | 13110 | || ws->value.sig != GDB_SIGNAL_TRAP) |
09ac7c10 TT |
13111 | return 0; |
13112 | ||
348d480f PA |
13113 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
13114 | aspace, bp_addr)) | |
13115 | return 0; | |
13116 | ||
13117 | if (overlay_debugging /* unmapped overlay section */ | |
13118 | && section_is_overlay (bl->section) | |
13119 | && !section_is_mapped (bl->section)) | |
13120 | return 0; | |
13121 | ||
13122 | return 1; | |
13123 | } | |
13124 | ||
cd1608cc PA |
13125 | static int |
13126 | dprintf_breakpoint_hit (const struct bp_location *bl, | |
13127 | struct address_space *aspace, CORE_ADDR bp_addr, | |
13128 | const struct target_waitstatus *ws) | |
13129 | { | |
13130 | if (dprintf_style == dprintf_style_agent | |
13131 | && target_can_run_breakpoint_commands ()) | |
13132 | { | |
13133 | /* An agent-style dprintf never causes a stop. If we see a trap | |
13134 | for this address it must be for a breakpoint that happens to | |
13135 | be set at the same address. */ | |
13136 | return 0; | |
13137 | } | |
13138 | ||
13139 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); | |
13140 | } | |
13141 | ||
2060206e | 13142 | static int |
348d480f PA |
13143 | bkpt_resources_needed (const struct bp_location *bl) |
13144 | { | |
13145 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
13146 | ||
13147 | return 1; | |
13148 | } | |
13149 | ||
2060206e | 13150 | static enum print_stop_action |
348d480f PA |
13151 | bkpt_print_it (bpstat bs) |
13152 | { | |
348d480f PA |
13153 | struct breakpoint *b; |
13154 | const struct bp_location *bl; | |
001c8c33 | 13155 | int bp_temp; |
79a45e25 | 13156 | struct ui_out *uiout = current_uiout; |
348d480f PA |
13157 | |
13158 | gdb_assert (bs->bp_location_at != NULL); | |
13159 | ||
13160 | bl = bs->bp_location_at; | |
13161 | b = bs->breakpoint_at; | |
13162 | ||
001c8c33 PA |
13163 | bp_temp = b->disposition == disp_del; |
13164 | if (bl->address != bl->requested_address) | |
13165 | breakpoint_adjustment_warning (bl->requested_address, | |
13166 | bl->address, | |
13167 | b->number, 1); | |
13168 | annotate_breakpoint (b->number); | |
f303dbd6 PA |
13169 | maybe_print_thread_hit_breakpoint (uiout); |
13170 | ||
001c8c33 | 13171 | if (bp_temp) |
f303dbd6 | 13172 | ui_out_text (uiout, "Temporary breakpoint "); |
001c8c33 | 13173 | else |
f303dbd6 | 13174 | ui_out_text (uiout, "Breakpoint "); |
001c8c33 | 13175 | if (ui_out_is_mi_like_p (uiout)) |
348d480f | 13176 | { |
001c8c33 PA |
13177 | ui_out_field_string (uiout, "reason", |
13178 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
13179 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 13180 | } |
001c8c33 PA |
13181 | ui_out_field_int (uiout, "bkptno", b->number); |
13182 | ui_out_text (uiout, ", "); | |
06edf0c0 | 13183 | |
001c8c33 | 13184 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
13185 | } |
13186 | ||
2060206e | 13187 | static void |
06edf0c0 PA |
13188 | bkpt_print_mention (struct breakpoint *b) |
13189 | { | |
79a45e25 | 13190 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
13191 | return; |
13192 | ||
13193 | switch (b->type) | |
13194 | { | |
13195 | case bp_breakpoint: | |
13196 | case bp_gnu_ifunc_resolver: | |
13197 | if (b->disposition == disp_del) | |
13198 | printf_filtered (_("Temporary breakpoint")); | |
13199 | else | |
13200 | printf_filtered (_("Breakpoint")); | |
13201 | printf_filtered (_(" %d"), b->number); | |
13202 | if (b->type == bp_gnu_ifunc_resolver) | |
13203 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
13204 | break; | |
13205 | case bp_hardware_breakpoint: | |
13206 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
13207 | break; | |
e7e0cddf SS |
13208 | case bp_dprintf: |
13209 | printf_filtered (_("Dprintf %d"), b->number); | |
13210 | break; | |
06edf0c0 PA |
13211 | } |
13212 | ||
13213 | say_where (b); | |
13214 | } | |
13215 | ||
2060206e | 13216 | static void |
06edf0c0 PA |
13217 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
13218 | { | |
13219 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
13220 | fprintf_unfiltered (fp, "tbreak"); | |
13221 | else if (tp->type == bp_breakpoint) | |
13222 | fprintf_unfiltered (fp, "break"); | |
13223 | else if (tp->type == bp_hardware_breakpoint | |
13224 | && tp->disposition == disp_del) | |
13225 | fprintf_unfiltered (fp, "thbreak"); | |
13226 | else if (tp->type == bp_hardware_breakpoint) | |
13227 | fprintf_unfiltered (fp, "hbreak"); | |
13228 | else | |
13229 | internal_error (__FILE__, __LINE__, | |
13230 | _("unhandled breakpoint type %d"), (int) tp->type); | |
13231 | ||
f00aae0f KS |
13232 | fprintf_unfiltered (fp, " %s", |
13233 | event_location_to_string (tp->location)); | |
13234 | ||
13235 | /* Print out extra_string if this breakpoint is pending. It might | |
13236 | contain, for example, conditions that were set by the user. */ | |
13237 | if (tp->loc == NULL && tp->extra_string != NULL) | |
13238 | fprintf_unfiltered (fp, " %s", tp->extra_string); | |
13239 | ||
dd11a36c | 13240 | print_recreate_thread (tp, fp); |
06edf0c0 PA |
13241 | } |
13242 | ||
983af33b | 13243 | static void |
f00aae0f KS |
13244 | bkpt_create_sals_from_location (const struct event_location *location, |
13245 | struct linespec_result *canonical, | |
13246 | enum bptype type_wanted) | |
983af33b | 13247 | { |
f00aae0f | 13248 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13249 | } |
13250 | ||
13251 | static void | |
13252 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13253 | struct linespec_result *canonical, | |
983af33b | 13254 | char *cond_string, |
e7e0cddf | 13255 | char *extra_string, |
983af33b SDJ |
13256 | enum bptype type_wanted, |
13257 | enum bpdisp disposition, | |
13258 | int thread, | |
13259 | int task, int ignore_count, | |
13260 | const struct breakpoint_ops *ops, | |
13261 | int from_tty, int enabled, | |
44f238bb | 13262 | int internal, unsigned flags) |
983af33b | 13263 | { |
023fa29b | 13264 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13265 | cond_string, extra_string, |
13266 | type_wanted, | |
983af33b SDJ |
13267 | disposition, thread, task, |
13268 | ignore_count, ops, from_tty, | |
44f238bb | 13269 | enabled, internal, flags); |
983af33b SDJ |
13270 | } |
13271 | ||
13272 | static void | |
f00aae0f KS |
13273 | bkpt_decode_location (struct breakpoint *b, |
13274 | const struct event_location *location, | |
c2f4122d | 13275 | struct program_space *search_pspace, |
983af33b SDJ |
13276 | struct symtabs_and_lines *sals) |
13277 | { | |
c2f4122d | 13278 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13279 | } |
13280 | ||
06edf0c0 PA |
13281 | /* Virtual table for internal breakpoints. */ |
13282 | ||
13283 | static void | |
13284 | internal_bkpt_re_set (struct breakpoint *b) | |
13285 | { | |
13286 | switch (b->type) | |
13287 | { | |
13288 | /* Delete overlay event and longjmp master breakpoints; they | |
13289 | will be reset later by breakpoint_re_set. */ | |
13290 | case bp_overlay_event: | |
13291 | case bp_longjmp_master: | |
13292 | case bp_std_terminate_master: | |
13293 | case bp_exception_master: | |
13294 | delete_breakpoint (b); | |
13295 | break; | |
13296 | ||
13297 | /* This breakpoint is special, it's set up when the inferior | |
13298 | starts and we really don't want to touch it. */ | |
13299 | case bp_shlib_event: | |
13300 | ||
13301 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
13302 | it is set up, we do not want to touch it. */ | |
13303 | case bp_thread_event: | |
13304 | break; | |
13305 | } | |
13306 | } | |
13307 | ||
13308 | static void | |
13309 | internal_bkpt_check_status (bpstat bs) | |
13310 | { | |
a9b3a50f PA |
13311 | if (bs->breakpoint_at->type == bp_shlib_event) |
13312 | { | |
13313 | /* If requested, stop when the dynamic linker notifies GDB of | |
13314 | events. This allows the user to get control and place | |
13315 | breakpoints in initializer routines for dynamically loaded | |
13316 | objects (among other things). */ | |
13317 | bs->stop = stop_on_solib_events; | |
13318 | bs->print = stop_on_solib_events; | |
13319 | } | |
13320 | else | |
13321 | bs->stop = 0; | |
06edf0c0 PA |
13322 | } |
13323 | ||
13324 | static enum print_stop_action | |
13325 | internal_bkpt_print_it (bpstat bs) | |
13326 | { | |
06edf0c0 | 13327 | struct breakpoint *b; |
06edf0c0 | 13328 | |
06edf0c0 PA |
13329 | b = bs->breakpoint_at; |
13330 | ||
06edf0c0 PA |
13331 | switch (b->type) |
13332 | { | |
348d480f PA |
13333 | case bp_shlib_event: |
13334 | /* Did we stop because the user set the stop_on_solib_events | |
13335 | variable? (If so, we report this as a generic, "Stopped due | |
13336 | to shlib event" message.) */ | |
edcc5120 | 13337 | print_solib_event (0); |
348d480f PA |
13338 | break; |
13339 | ||
13340 | case bp_thread_event: | |
13341 | /* Not sure how we will get here. | |
13342 | GDB should not stop for these breakpoints. */ | |
13343 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13344 | break; |
13345 | ||
13346 | case bp_overlay_event: | |
13347 | /* By analogy with the thread event, GDB should not stop for these. */ | |
13348 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13349 | break; |
13350 | ||
13351 | case bp_longjmp_master: | |
13352 | /* These should never be enabled. */ | |
13353 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
13354 | break; |
13355 | ||
13356 | case bp_std_terminate_master: | |
13357 | /* These should never be enabled. */ | |
13358 | printf_filtered (_("std::terminate Master Breakpoint: " | |
13359 | "gdb should not stop!\n")); | |
348d480f PA |
13360 | break; |
13361 | ||
13362 | case bp_exception_master: | |
13363 | /* These should never be enabled. */ | |
13364 | printf_filtered (_("Exception Master Breakpoint: " | |
13365 | "gdb should not stop!\n")); | |
06edf0c0 PA |
13366 | break; |
13367 | } | |
13368 | ||
001c8c33 | 13369 | return PRINT_NOTHING; |
06edf0c0 PA |
13370 | } |
13371 | ||
13372 | static void | |
13373 | internal_bkpt_print_mention (struct breakpoint *b) | |
13374 | { | |
13375 | /* Nothing to mention. These breakpoints are internal. */ | |
13376 | } | |
13377 | ||
06edf0c0 PA |
13378 | /* Virtual table for momentary breakpoints */ |
13379 | ||
13380 | static void | |
13381 | momentary_bkpt_re_set (struct breakpoint *b) | |
13382 | { | |
13383 | /* Keep temporary breakpoints, which can be encountered when we step | |
4d1eb6b4 | 13384 | over a dlopen call and solib_add is resetting the breakpoints. |
06edf0c0 PA |
13385 | Otherwise these should have been blown away via the cleanup chain |
13386 | or by breakpoint_init_inferior when we rerun the executable. */ | |
13387 | } | |
13388 | ||
13389 | static void | |
13390 | momentary_bkpt_check_status (bpstat bs) | |
13391 | { | |
13392 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
13393 | } | |
13394 | ||
13395 | static enum print_stop_action | |
13396 | momentary_bkpt_print_it (bpstat bs) | |
13397 | { | |
001c8c33 | 13398 | return PRINT_UNKNOWN; |
348d480f PA |
13399 | } |
13400 | ||
06edf0c0 PA |
13401 | static void |
13402 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 13403 | { |
06edf0c0 | 13404 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
13405 | } |
13406 | ||
e2e4d78b JK |
13407 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
13408 | ||
13409 | It gets cleared already on the removal of the first one of such placed | |
13410 | breakpoints. This is OK as they get all removed altogether. */ | |
13411 | ||
13412 | static void | |
13413 | longjmp_bkpt_dtor (struct breakpoint *self) | |
13414 | { | |
5d5658a1 | 13415 | struct thread_info *tp = find_thread_global_id (self->thread); |
e2e4d78b JK |
13416 | |
13417 | if (tp) | |
13418 | tp->initiating_frame = null_frame_id; | |
13419 | ||
13420 | momentary_breakpoint_ops.dtor (self); | |
13421 | } | |
13422 | ||
55aa24fb SDJ |
13423 | /* Specific methods for probe breakpoints. */ |
13424 | ||
13425 | static int | |
13426 | bkpt_probe_insert_location (struct bp_location *bl) | |
13427 | { | |
13428 | int v = bkpt_insert_location (bl); | |
13429 | ||
13430 | if (v == 0) | |
13431 | { | |
13432 | /* The insertion was successful, now let's set the probe's semaphore | |
13433 | if needed. */ | |
0ea5cda8 SDJ |
13434 | if (bl->probe.probe->pops->set_semaphore != NULL) |
13435 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, | |
13436 | bl->probe.objfile, | |
13437 | bl->gdbarch); | |
55aa24fb SDJ |
13438 | } |
13439 | ||
13440 | return v; | |
13441 | } | |
13442 | ||
13443 | static int | |
13444 | bkpt_probe_remove_location (struct bp_location *bl) | |
13445 | { | |
13446 | /* Let's clear the semaphore before removing the location. */ | |
0ea5cda8 SDJ |
13447 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
13448 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, | |
13449 | bl->probe.objfile, | |
13450 | bl->gdbarch); | |
55aa24fb SDJ |
13451 | |
13452 | return bkpt_remove_location (bl); | |
13453 | } | |
13454 | ||
13455 | static void | |
f00aae0f | 13456 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13457 | struct linespec_result *canonical, |
f00aae0f | 13458 | enum bptype type_wanted) |
55aa24fb SDJ |
13459 | { |
13460 | struct linespec_sals lsal; | |
13461 | ||
c2f4122d | 13462 | lsal.sals = parse_probes (location, NULL, canonical); |
f00aae0f | 13463 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
55aa24fb SDJ |
13464 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13465 | } | |
13466 | ||
13467 | static void | |
f00aae0f KS |
13468 | bkpt_probe_decode_location (struct breakpoint *b, |
13469 | const struct event_location *location, | |
c2f4122d | 13470 | struct program_space *search_pspace, |
55aa24fb SDJ |
13471 | struct symtabs_and_lines *sals) |
13472 | { | |
c2f4122d | 13473 | *sals = parse_probes (location, search_pspace, NULL); |
55aa24fb SDJ |
13474 | if (!sals->sals) |
13475 | error (_("probe not found")); | |
13476 | } | |
13477 | ||
348d480f | 13478 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 13479 | |
348d480f PA |
13480 | static void |
13481 | tracepoint_re_set (struct breakpoint *b) | |
13482 | { | |
13483 | breakpoint_re_set_default (b); | |
13484 | } | |
876fa593 | 13485 | |
348d480f PA |
13486 | static int |
13487 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
09ac7c10 TT |
13488 | struct address_space *aspace, CORE_ADDR bp_addr, |
13489 | const struct target_waitstatus *ws) | |
348d480f PA |
13490 | { |
13491 | /* By definition, the inferior does not report stops at | |
13492 | tracepoints. */ | |
13493 | return 0; | |
74960c60 VP |
13494 | } |
13495 | ||
13496 | static void | |
348d480f PA |
13497 | tracepoint_print_one_detail (const struct breakpoint *self, |
13498 | struct ui_out *uiout) | |
74960c60 | 13499 | { |
d9b3f62e PA |
13500 | struct tracepoint *tp = (struct tracepoint *) self; |
13501 | if (tp->static_trace_marker_id) | |
348d480f PA |
13502 | { |
13503 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 13504 | |
348d480f PA |
13505 | ui_out_text (uiout, "\tmarker id is "); |
13506 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 13507 | tp->static_trace_marker_id); |
348d480f PA |
13508 | ui_out_text (uiout, "\n"); |
13509 | } | |
0d381245 VP |
13510 | } |
13511 | ||
a474d7c2 | 13512 | static void |
348d480f | 13513 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 13514 | { |
79a45e25 | 13515 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 13516 | return; |
cc59ec59 | 13517 | |
348d480f PA |
13518 | switch (b->type) |
13519 | { | |
13520 | case bp_tracepoint: | |
13521 | printf_filtered (_("Tracepoint")); | |
13522 | printf_filtered (_(" %d"), b->number); | |
13523 | break; | |
13524 | case bp_fast_tracepoint: | |
13525 | printf_filtered (_("Fast tracepoint")); | |
13526 | printf_filtered (_(" %d"), b->number); | |
13527 | break; | |
13528 | case bp_static_tracepoint: | |
13529 | printf_filtered (_("Static tracepoint")); | |
13530 | printf_filtered (_(" %d"), b->number); | |
13531 | break; | |
13532 | default: | |
13533 | internal_error (__FILE__, __LINE__, | |
13534 | _("unhandled tracepoint type %d"), (int) b->type); | |
13535 | } | |
13536 | ||
13537 | say_where (b); | |
a474d7c2 PA |
13538 | } |
13539 | ||
348d480f | 13540 | static void |
d9b3f62e | 13541 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 13542 | { |
d9b3f62e PA |
13543 | struct tracepoint *tp = (struct tracepoint *) self; |
13544 | ||
13545 | if (self->type == bp_fast_tracepoint) | |
348d480f | 13546 | fprintf_unfiltered (fp, "ftrace"); |
c93e8391 | 13547 | else if (self->type == bp_static_tracepoint) |
348d480f | 13548 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 13549 | else if (self->type == bp_tracepoint) |
348d480f PA |
13550 | fprintf_unfiltered (fp, "trace"); |
13551 | else | |
13552 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 13553 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 13554 | |
f00aae0f KS |
13555 | fprintf_unfiltered (fp, " %s", |
13556 | event_location_to_string (self->location)); | |
d9b3f62e PA |
13557 | print_recreate_thread (self, fp); |
13558 | ||
13559 | if (tp->pass_count) | |
13560 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
13561 | } |
13562 | ||
983af33b | 13563 | static void |
f00aae0f KS |
13564 | tracepoint_create_sals_from_location (const struct event_location *location, |
13565 | struct linespec_result *canonical, | |
13566 | enum bptype type_wanted) | |
983af33b | 13567 | { |
f00aae0f | 13568 | create_sals_from_location_default (location, canonical, type_wanted); |
983af33b SDJ |
13569 | } |
13570 | ||
13571 | static void | |
13572 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13573 | struct linespec_result *canonical, | |
983af33b | 13574 | char *cond_string, |
e7e0cddf | 13575 | char *extra_string, |
983af33b SDJ |
13576 | enum bptype type_wanted, |
13577 | enum bpdisp disposition, | |
13578 | int thread, | |
13579 | int task, int ignore_count, | |
13580 | const struct breakpoint_ops *ops, | |
13581 | int from_tty, int enabled, | |
44f238bb | 13582 | int internal, unsigned flags) |
983af33b | 13583 | { |
023fa29b | 13584 | create_breakpoints_sal_default (gdbarch, canonical, |
e7e0cddf SS |
13585 | cond_string, extra_string, |
13586 | type_wanted, | |
983af33b SDJ |
13587 | disposition, thread, task, |
13588 | ignore_count, ops, from_tty, | |
44f238bb | 13589 | enabled, internal, flags); |
983af33b SDJ |
13590 | } |
13591 | ||
13592 | static void | |
f00aae0f KS |
13593 | tracepoint_decode_location (struct breakpoint *b, |
13594 | const struct event_location *location, | |
c2f4122d | 13595 | struct program_space *search_pspace, |
983af33b SDJ |
13596 | struct symtabs_and_lines *sals) |
13597 | { | |
c2f4122d | 13598 | decode_location_default (b, location, search_pspace, sals); |
983af33b SDJ |
13599 | } |
13600 | ||
2060206e | 13601 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 13602 | |
55aa24fb SDJ |
13603 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
13604 | static probe. */ | |
13605 | ||
13606 | static void | |
f00aae0f KS |
13607 | tracepoint_probe_create_sals_from_location |
13608 | (const struct event_location *location, | |
13609 | struct linespec_result *canonical, | |
13610 | enum bptype type_wanted) | |
55aa24fb SDJ |
13611 | { |
13612 | /* We use the same method for breakpoint on probes. */ | |
f00aae0f | 13613 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
55aa24fb SDJ |
13614 | } |
13615 | ||
13616 | static void | |
f00aae0f KS |
13617 | tracepoint_probe_decode_location (struct breakpoint *b, |
13618 | const struct event_location *location, | |
c2f4122d | 13619 | struct program_space *search_pspace, |
55aa24fb SDJ |
13620 | struct symtabs_and_lines *sals) |
13621 | { | |
13622 | /* We use the same method for breakpoint on probes. */ | |
c2f4122d | 13623 | bkpt_probe_decode_location (b, location, search_pspace, sals); |
55aa24fb SDJ |
13624 | } |
13625 | ||
13626 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; | |
13627 | ||
5c2b4418 HZ |
13628 | /* Dprintf breakpoint_ops methods. */ |
13629 | ||
13630 | static void | |
13631 | dprintf_re_set (struct breakpoint *b) | |
13632 | { | |
13633 | breakpoint_re_set_default (b); | |
13634 | ||
f00aae0f KS |
13635 | /* extra_string should never be non-NULL for dprintf. */ |
13636 | gdb_assert (b->extra_string != NULL); | |
5c2b4418 HZ |
13637 | |
13638 | /* 1 - connect to target 1, that can run breakpoint commands. | |
13639 | 2 - create a dprintf, which resolves fine. | |
13640 | 3 - disconnect from target 1 | |
13641 | 4 - connect to target 2, that can NOT run breakpoint commands. | |
13642 | ||
13643 | After steps #3/#4, you'll want the dprintf command list to | |
13644 | be updated, because target 1 and 2 may well return different | |
13645 | answers for target_can_run_breakpoint_commands(). | |
13646 | Given absence of finer grained resetting, we get to do | |
13647 | it all the time. */ | |
13648 | if (b->extra_string != NULL) | |
13649 | update_dprintf_command_list (b); | |
13650 | } | |
13651 | ||
2d9442cc HZ |
13652 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
13653 | ||
13654 | static void | |
13655 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) | |
13656 | { | |
f00aae0f KS |
13657 | fprintf_unfiltered (fp, "dprintf %s,%s", |
13658 | event_location_to_string (tp->location), | |
2d9442cc HZ |
13659 | tp->extra_string); |
13660 | print_recreate_thread (tp, fp); | |
13661 | } | |
13662 | ||
9d6e6e84 HZ |
13663 | /* Implement the "after_condition_true" breakpoint_ops method for |
13664 | dprintf. | |
13665 | ||
13666 | dprintf's are implemented with regular commands in their command | |
13667 | list, but we run the commands here instead of before presenting the | |
13668 | stop to the user, as dprintf's don't actually cause a stop. This | |
13669 | also makes it so that the commands of multiple dprintfs at the same | |
13670 | address are all handled. */ | |
13671 | ||
13672 | static void | |
13673 | dprintf_after_condition_true (struct bpstats *bs) | |
13674 | { | |
13675 | struct cleanup *old_chain; | |
13676 | struct bpstats tmp_bs = { NULL }; | |
13677 | struct bpstats *tmp_bs_p = &tmp_bs; | |
13678 | ||
13679 | /* dprintf's never cause a stop. This wasn't set in the | |
13680 | check_status hook instead because that would make the dprintf's | |
13681 | condition not be evaluated. */ | |
13682 | bs->stop = 0; | |
13683 | ||
13684 | /* Run the command list here. Take ownership of it instead of | |
13685 | copying. We never want these commands to run later in | |
13686 | bpstat_do_actions, if a breakpoint that causes a stop happens to | |
13687 | be set at same address as this dprintf, or even if running the | |
13688 | commands here throws. */ | |
13689 | tmp_bs.commands = bs->commands; | |
13690 | bs->commands = NULL; | |
13691 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); | |
13692 | ||
13693 | bpstat_do_actions_1 (&tmp_bs_p); | |
13694 | ||
13695 | /* 'tmp_bs.commands' will usually be NULL by now, but | |
13696 | bpstat_do_actions_1 may return early without processing the whole | |
13697 | list. */ | |
13698 | do_cleanups (old_chain); | |
13699 | } | |
13700 | ||
983af33b SDJ |
13701 | /* The breakpoint_ops structure to be used on static tracepoints with |
13702 | markers (`-m'). */ | |
13703 | ||
13704 | static void | |
f00aae0f | 13705 | strace_marker_create_sals_from_location (const struct event_location *location, |
5f700d83 | 13706 | struct linespec_result *canonical, |
f00aae0f | 13707 | enum bptype type_wanted) |
983af33b SDJ |
13708 | { |
13709 | struct linespec_sals lsal; | |
f00aae0f KS |
13710 | const char *arg_start, *arg; |
13711 | char *str; | |
13712 | struct cleanup *cleanup; | |
983af33b | 13713 | |
f00aae0f KS |
13714 | arg = arg_start = get_linespec_location (location); |
13715 | lsal.sals = decode_static_tracepoint_spec (&arg); | |
983af33b | 13716 | |
f00aae0f KS |
13717 | str = savestring (arg_start, arg - arg_start); |
13718 | cleanup = make_cleanup (xfree, str); | |
13719 | canonical->location = new_linespec_location (&str); | |
13720 | do_cleanups (cleanup); | |
983af33b | 13721 | |
f00aae0f | 13722 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
983af33b SDJ |
13723 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
13724 | } | |
13725 | ||
13726 | static void | |
13727 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, | |
13728 | struct linespec_result *canonical, | |
983af33b | 13729 | char *cond_string, |
e7e0cddf | 13730 | char *extra_string, |
983af33b SDJ |
13731 | enum bptype type_wanted, |
13732 | enum bpdisp disposition, | |
13733 | int thread, | |
13734 | int task, int ignore_count, | |
13735 | const struct breakpoint_ops *ops, | |
13736 | int from_tty, int enabled, | |
44f238bb | 13737 | int internal, unsigned flags) |
983af33b SDJ |
13738 | { |
13739 | int i; | |
52d361e1 YQ |
13740 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
13741 | canonical->sals, 0); | |
983af33b SDJ |
13742 | |
13743 | /* If the user is creating a static tracepoint by marker id | |
13744 | (strace -m MARKER_ID), then store the sals index, so that | |
13745 | breakpoint_re_set can try to match up which of the newly | |
13746 | found markers corresponds to this one, and, don't try to | |
13747 | expand multiple locations for each sal, given than SALS | |
13748 | already should contain all sals for MARKER_ID. */ | |
13749 | ||
13750 | for (i = 0; i < lsal->sals.nelts; ++i) | |
13751 | { | |
13752 | struct symtabs_and_lines expanded; | |
13753 | struct tracepoint *tp; | |
13754 | struct cleanup *old_chain; | |
f00aae0f | 13755 | struct event_location *location; |
983af33b SDJ |
13756 | |
13757 | expanded.nelts = 1; | |
13758 | expanded.sals = &lsal->sals.sals[i]; | |
13759 | ||
f00aae0f KS |
13760 | location = copy_event_location (canonical->location); |
13761 | old_chain = make_cleanup_delete_event_location (location); | |
983af33b SDJ |
13762 | |
13763 | tp = XCNEW (struct tracepoint); | |
13764 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
f00aae0f | 13765 | location, NULL, |
e7e0cddf SS |
13766 | cond_string, extra_string, |
13767 | type_wanted, disposition, | |
983af33b | 13768 | thread, task, ignore_count, ops, |
44f238bb | 13769 | from_tty, enabled, internal, flags, |
983af33b SDJ |
13770 | canonical->special_display); |
13771 | /* Given that its possible to have multiple markers with | |
13772 | the same string id, if the user is creating a static | |
13773 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
13774 | store the sals index, so that breakpoint_re_set can | |
13775 | try to match up which of the newly found markers | |
13776 | corresponds to this one */ | |
13777 | tp->static_trace_marker_id_idx = i; | |
13778 | ||
13779 | install_breakpoint (internal, &tp->base, 0); | |
13780 | ||
13781 | discard_cleanups (old_chain); | |
13782 | } | |
13783 | } | |
13784 | ||
13785 | static void | |
f00aae0f KS |
13786 | strace_marker_decode_location (struct breakpoint *b, |
13787 | const struct event_location *location, | |
c2f4122d | 13788 | struct program_space *search_pspace, |
983af33b SDJ |
13789 | struct symtabs_and_lines *sals) |
13790 | { | |
13791 | struct tracepoint *tp = (struct tracepoint *) b; | |
f00aae0f | 13792 | const char *s = get_linespec_location (location); |
983af33b | 13793 | |
f00aae0f | 13794 | *sals = decode_static_tracepoint_spec (&s); |
983af33b SDJ |
13795 | if (sals->nelts > tp->static_trace_marker_id_idx) |
13796 | { | |
13797 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; | |
13798 | sals->nelts = 1; | |
13799 | } | |
13800 | else | |
13801 | error (_("marker %s not found"), tp->static_trace_marker_id); | |
13802 | } | |
13803 | ||
13804 | static struct breakpoint_ops strace_marker_breakpoint_ops; | |
13805 | ||
13806 | static int | |
13807 | strace_marker_p (struct breakpoint *b) | |
13808 | { | |
13809 | return b->ops == &strace_marker_breakpoint_ops; | |
13810 | } | |
13811 | ||
53a5351d | 13812 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 13813 | structures. */ |
c906108c SS |
13814 | |
13815 | void | |
fba45db2 | 13816 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 13817 | { |
52f0bd74 | 13818 | struct breakpoint *b; |
c906108c | 13819 | |
8a3fe4f8 | 13820 | gdb_assert (bpt != NULL); |
c906108c | 13821 | |
4a64f543 MS |
13822 | /* Has this bp already been deleted? This can happen because |
13823 | multiple lists can hold pointers to bp's. bpstat lists are | |
13824 | especial culprits. | |
13825 | ||
13826 | One example of this happening is a watchpoint's scope bp. When | |
13827 | the scope bp triggers, we notice that the watchpoint is out of | |
13828 | scope, and delete it. We also delete its scope bp. But the | |
13829 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
13830 | That bpstat is then checked for auto-deleting bp's, which are | |
13831 | deleted. | |
13832 | ||
13833 | A real solution to this problem might involve reference counts in | |
13834 | bp's, and/or giving them pointers back to their referencing | |
13835 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
13836 | storage when no more references were extent. A cheaper bandaid | |
13837 | was chosen. */ | |
c906108c SS |
13838 | if (bpt->type == bp_none) |
13839 | return; | |
13840 | ||
4a64f543 MS |
13841 | /* At least avoid this stale reference until the reference counting |
13842 | of breakpoints gets resolved. */ | |
d0fb5eae | 13843 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 13844 | { |
d0fb5eae | 13845 | struct breakpoint *related; |
3a5c3e22 | 13846 | struct watchpoint *w; |
d0fb5eae JK |
13847 | |
13848 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 13849 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 13850 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
13851 | w = (struct watchpoint *) bpt; |
13852 | else | |
13853 | w = NULL; | |
13854 | if (w != NULL) | |
13855 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
13856 | |
13857 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
13858 | for (related = bpt; related->related_breakpoint != bpt; | |
13859 | related = related->related_breakpoint); | |
13860 | related->related_breakpoint = bpt->related_breakpoint; | |
13861 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
13862 | } |
13863 | ||
a9634178 TJB |
13864 | /* watch_command_1 creates a watchpoint but only sets its number if |
13865 | update_watchpoint succeeds in creating its bp_locations. If there's | |
13866 | a problem in that process, we'll be asked to delete the half-created | |
13867 | watchpoint. In that case, don't announce the deletion. */ | |
13868 | if (bpt->number) | |
13869 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 13870 | |
c906108c SS |
13871 | if (breakpoint_chain == bpt) |
13872 | breakpoint_chain = bpt->next; | |
13873 | ||
c906108c SS |
13874 | ALL_BREAKPOINTS (b) |
13875 | if (b->next == bpt) | |
c5aa993b JM |
13876 | { |
13877 | b->next = bpt->next; | |
13878 | break; | |
13879 | } | |
c906108c | 13880 | |
f431efe5 PA |
13881 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
13882 | been freed. */ | |
13883 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 13884 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
13885 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
13886 | commands are associated with the bpstat; if we remove it here, | |
13887 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
13888 | event-top.c won't do anything, and temporary breakpoints with | |
13889 | commands won't work. */ | |
13890 | ||
13891 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
13892 | ||
4a64f543 MS |
13893 | /* Now that breakpoint is removed from breakpoint list, update the |
13894 | global location list. This will remove locations that used to | |
13895 | belong to this breakpoint. Do this before freeing the breakpoint | |
13896 | itself, since remove_breakpoint looks at location's owner. It | |
13897 | might be better design to have location completely | |
13898 | self-contained, but it's not the case now. */ | |
44702360 | 13899 | update_global_location_list (UGLL_DONT_INSERT); |
74960c60 | 13900 | |
348d480f | 13901 | bpt->ops->dtor (bpt); |
4a64f543 MS |
13902 | /* On the chance that someone will soon try again to delete this |
13903 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 13904 | bpt->type = bp_none; |
b8c9b27d | 13905 | xfree (bpt); |
c906108c SS |
13906 | } |
13907 | ||
4d6140d9 AC |
13908 | static void |
13909 | do_delete_breakpoint_cleanup (void *b) | |
13910 | { | |
9a3c8263 | 13911 | delete_breakpoint ((struct breakpoint *) b); |
4d6140d9 AC |
13912 | } |
13913 | ||
13914 | struct cleanup * | |
13915 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
13916 | { | |
13917 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
13918 | } | |
13919 | ||
51be5b68 PA |
13920 | /* Iterator function to call a user-provided callback function once |
13921 | for each of B and its related breakpoints. */ | |
13922 | ||
13923 | static void | |
13924 | iterate_over_related_breakpoints (struct breakpoint *b, | |
13925 | void (*function) (struct breakpoint *, | |
13926 | void *), | |
13927 | void *data) | |
13928 | { | |
13929 | struct breakpoint *related; | |
13930 | ||
13931 | related = b; | |
13932 | do | |
13933 | { | |
13934 | struct breakpoint *next; | |
13935 | ||
13936 | /* FUNCTION may delete RELATED. */ | |
13937 | next = related->related_breakpoint; | |
13938 | ||
13939 | if (next == related) | |
13940 | { | |
13941 | /* RELATED is the last ring entry. */ | |
13942 | function (related, data); | |
13943 | ||
13944 | /* FUNCTION may have deleted it, so we'd never reach back to | |
13945 | B. There's nothing left to do anyway, so just break | |
13946 | out. */ | |
13947 | break; | |
13948 | } | |
13949 | else | |
13950 | function (related, data); | |
13951 | ||
13952 | related = next; | |
13953 | } | |
13954 | while (related != b); | |
13955 | } | |
95a42b64 TT |
13956 | |
13957 | static void | |
13958 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13959 | { | |
13960 | delete_breakpoint (b); | |
13961 | } | |
13962 | ||
51be5b68 PA |
13963 | /* A callback for map_breakpoint_numbers that calls |
13964 | delete_breakpoint. */ | |
13965 | ||
13966 | static void | |
13967 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
13968 | { | |
13969 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
13970 | } | |
13971 | ||
c906108c | 13972 | void |
fba45db2 | 13973 | delete_command (char *arg, int from_tty) |
c906108c | 13974 | { |
35df4500 | 13975 | struct breakpoint *b, *b_tmp; |
c906108c | 13976 | |
ea9365bb TT |
13977 | dont_repeat (); |
13978 | ||
c906108c SS |
13979 | if (arg == 0) |
13980 | { | |
13981 | int breaks_to_delete = 0; | |
13982 | ||
46c6471b PA |
13983 | /* Delete all breakpoints if no argument. Do not delete |
13984 | internal breakpoints, these have to be deleted with an | |
13985 | explicit breakpoint number argument. */ | |
c5aa993b | 13986 | ALL_BREAKPOINTS (b) |
46c6471b | 13987 | if (user_breakpoint_p (b)) |
973d738b DJ |
13988 | { |
13989 | breaks_to_delete = 1; | |
13990 | break; | |
13991 | } | |
c906108c SS |
13992 | |
13993 | /* Ask user only if there are some breakpoints to delete. */ | |
13994 | if (!from_tty | |
e2e0b3e5 | 13995 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 13996 | { |
35df4500 | 13997 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 13998 | if (user_breakpoint_p (b)) |
c5aa993b | 13999 | delete_breakpoint (b); |
c906108c SS |
14000 | } |
14001 | } | |
14002 | else | |
51be5b68 | 14003 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
14004 | } |
14005 | ||
c2f4122d PA |
14006 | /* Return true if all locations of B bound to PSPACE are pending. If |
14007 | PSPACE is NULL, all locations of all program spaces are | |
14008 | considered. */ | |
14009 | ||
0d381245 | 14010 | static int |
c2f4122d | 14011 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
fe3f5fa8 | 14012 | { |
c2f4122d PA |
14013 | struct bp_location *loc; |
14014 | ||
14015 | for (loc = b->loc; loc != NULL; loc = loc->next) | |
14016 | if ((pspace == NULL | |
14017 | || loc->pspace == pspace) | |
14018 | && !loc->shlib_disabled | |
8645ff69 | 14019 | && !loc->pspace->executing_startup) |
0d381245 VP |
14020 | return 0; |
14021 | return 1; | |
fe3f5fa8 VP |
14022 | } |
14023 | ||
776592bf DE |
14024 | /* Subroutine of update_breakpoint_locations to simplify it. |
14025 | Return non-zero if multiple fns in list LOC have the same name. | |
14026 | Null names are ignored. */ | |
14027 | ||
14028 | static int | |
14029 | ambiguous_names_p (struct bp_location *loc) | |
14030 | { | |
14031 | struct bp_location *l; | |
14032 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
14033 | (int (*) (const void *, |
14034 | const void *)) streq, | |
776592bf DE |
14035 | NULL, xcalloc, xfree); |
14036 | ||
14037 | for (l = loc; l != NULL; l = l->next) | |
14038 | { | |
14039 | const char **slot; | |
14040 | const char *name = l->function_name; | |
14041 | ||
14042 | /* Allow for some names to be NULL, ignore them. */ | |
14043 | if (name == NULL) | |
14044 | continue; | |
14045 | ||
14046 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
14047 | INSERT); | |
4a64f543 MS |
14048 | /* NOTE: We can assume slot != NULL here because xcalloc never |
14049 | returns NULL. */ | |
776592bf DE |
14050 | if (*slot != NULL) |
14051 | { | |
14052 | htab_delete (htab); | |
14053 | return 1; | |
14054 | } | |
14055 | *slot = name; | |
14056 | } | |
14057 | ||
14058 | htab_delete (htab); | |
14059 | return 0; | |
14060 | } | |
14061 | ||
0fb4aa4b PA |
14062 | /* When symbols change, it probably means the sources changed as well, |
14063 | and it might mean the static tracepoint markers are no longer at | |
14064 | the same address or line numbers they used to be at last we | |
14065 | checked. Losing your static tracepoints whenever you rebuild is | |
14066 | undesirable. This function tries to resync/rematch gdb static | |
14067 | tracepoints with the markers on the target, for static tracepoints | |
14068 | that have not been set by marker id. Static tracepoint that have | |
14069 | been set by marker id are reset by marker id in breakpoint_re_set. | |
14070 | The heuristic is: | |
14071 | ||
14072 | 1) For a tracepoint set at a specific address, look for a marker at | |
14073 | the old PC. If one is found there, assume to be the same marker. | |
14074 | If the name / string id of the marker found is different from the | |
14075 | previous known name, assume that means the user renamed the marker | |
14076 | in the sources, and output a warning. | |
14077 | ||
14078 | 2) For a tracepoint set at a given line number, look for a marker | |
14079 | at the new address of the old line number. If one is found there, | |
14080 | assume to be the same marker. If the name / string id of the | |
14081 | marker found is different from the previous known name, assume that | |
14082 | means the user renamed the marker in the sources, and output a | |
14083 | warning. | |
14084 | ||
14085 | 3) If a marker is no longer found at the same address or line, it | |
14086 | may mean the marker no longer exists. But it may also just mean | |
14087 | the code changed a bit. Maybe the user added a few lines of code | |
14088 | that made the marker move up or down (in line number terms). Ask | |
14089 | the target for info about the marker with the string id as we knew | |
14090 | it. If found, update line number and address in the matching | |
14091 | static tracepoint. This will get confused if there's more than one | |
14092 | marker with the same ID (possible in UST, although unadvised | |
14093 | precisely because it confuses tools). */ | |
14094 | ||
14095 | static struct symtab_and_line | |
14096 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
14097 | { | |
d9b3f62e | 14098 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
14099 | struct static_tracepoint_marker marker; |
14100 | CORE_ADDR pc; | |
0fb4aa4b PA |
14101 | |
14102 | pc = sal.pc; | |
14103 | if (sal.line) | |
14104 | find_line_pc (sal.symtab, sal.line, &pc); | |
14105 | ||
14106 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
14107 | { | |
d9b3f62e | 14108 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
14109 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
14110 | b->number, | |
d9b3f62e | 14111 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 14112 | |
d9b3f62e PA |
14113 | xfree (tp->static_trace_marker_id); |
14114 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
14115 | release_static_tracepoint_marker (&marker); |
14116 | ||
14117 | return sal; | |
14118 | } | |
14119 | ||
14120 | /* Old marker wasn't found on target at lineno. Try looking it up | |
14121 | by string ID. */ | |
14122 | if (!sal.explicit_pc | |
14123 | && sal.line != 0 | |
14124 | && sal.symtab != NULL | |
d9b3f62e | 14125 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
14126 | { |
14127 | VEC(static_tracepoint_marker_p) *markers; | |
14128 | ||
14129 | markers | |
d9b3f62e | 14130 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
14131 | |
14132 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
14133 | { | |
80e1d417 | 14134 | struct symtab_and_line sal2; |
0fb4aa4b | 14135 | struct symbol *sym; |
80e1d417 | 14136 | struct static_tracepoint_marker *tpmarker; |
79a45e25 | 14137 | struct ui_out *uiout = current_uiout; |
67994074 | 14138 | struct explicit_location explicit_loc; |
0fb4aa4b | 14139 | |
80e1d417 | 14140 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
0fb4aa4b | 14141 | |
d9b3f62e | 14142 | xfree (tp->static_trace_marker_id); |
80e1d417 | 14143 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
0fb4aa4b PA |
14144 | |
14145 | warning (_("marker for static tracepoint %d (%s) not " | |
14146 | "found at previous line number"), | |
d9b3f62e | 14147 | b->number, tp->static_trace_marker_id); |
0fb4aa4b | 14148 | |
80e1d417 | 14149 | init_sal (&sal2); |
0fb4aa4b | 14150 | |
80e1d417 | 14151 | sal2.pc = tpmarker->address; |
0fb4aa4b | 14152 | |
80e1d417 AS |
14153 | sal2 = find_pc_line (tpmarker->address, 0); |
14154 | sym = find_pc_sect_function (tpmarker->address, NULL); | |
0fb4aa4b PA |
14155 | ui_out_text (uiout, "Now in "); |
14156 | if (sym) | |
14157 | { | |
14158 | ui_out_field_string (uiout, "func", | |
14159 | SYMBOL_PRINT_NAME (sym)); | |
14160 | ui_out_text (uiout, " at "); | |
14161 | } | |
05cba821 JK |
14162 | ui_out_field_string (uiout, "file", |
14163 | symtab_to_filename_for_display (sal2.symtab)); | |
0fb4aa4b PA |
14164 | ui_out_text (uiout, ":"); |
14165 | ||
14166 | if (ui_out_is_mi_like_p (uiout)) | |
14167 | { | |
0b0865da | 14168 | const char *fullname = symtab_to_fullname (sal2.symtab); |
0fb4aa4b | 14169 | |
f35a17b5 | 14170 | ui_out_field_string (uiout, "fullname", fullname); |
0fb4aa4b PA |
14171 | } |
14172 | ||
80e1d417 | 14173 | ui_out_field_int (uiout, "line", sal2.line); |
0fb4aa4b PA |
14174 | ui_out_text (uiout, "\n"); |
14175 | ||
80e1d417 | 14176 | b->loc->line_number = sal2.line; |
2f202fde | 14177 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
0fb4aa4b | 14178 | |
f00aae0f | 14179 | delete_event_location (b->location); |
67994074 KS |
14180 | initialize_explicit_location (&explicit_loc); |
14181 | explicit_loc.source_filename | |
00e52e53 | 14182 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
67994074 KS |
14183 | explicit_loc.line_offset.offset = b->loc->line_number; |
14184 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; | |
14185 | b->location = new_explicit_location (&explicit_loc); | |
0fb4aa4b PA |
14186 | |
14187 | /* Might be nice to check if function changed, and warn if | |
14188 | so. */ | |
14189 | ||
80e1d417 | 14190 | release_static_tracepoint_marker (tpmarker); |
0fb4aa4b PA |
14191 | } |
14192 | } | |
14193 | return sal; | |
14194 | } | |
14195 | ||
8d3788bd VP |
14196 | /* Returns 1 iff locations A and B are sufficiently same that |
14197 | we don't need to report breakpoint as changed. */ | |
14198 | ||
14199 | static int | |
14200 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
14201 | { | |
14202 | while (a && b) | |
14203 | { | |
14204 | if (a->address != b->address) | |
14205 | return 0; | |
14206 | ||
14207 | if (a->shlib_disabled != b->shlib_disabled) | |
14208 | return 0; | |
14209 | ||
14210 | if (a->enabled != b->enabled) | |
14211 | return 0; | |
14212 | ||
14213 | a = a->next; | |
14214 | b = b->next; | |
14215 | } | |
14216 | ||
14217 | if ((a == NULL) != (b == NULL)) | |
14218 | return 0; | |
14219 | ||
14220 | return 1; | |
14221 | } | |
14222 | ||
c2f4122d PA |
14223 | /* Split all locations of B that are bound to PSPACE out of B's |
14224 | location list to a separate list and return that list's head. If | |
14225 | PSPACE is NULL, hoist out all locations of B. */ | |
14226 | ||
14227 | static struct bp_location * | |
14228 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) | |
14229 | { | |
14230 | struct bp_location head; | |
14231 | struct bp_location *i = b->loc; | |
14232 | struct bp_location **i_link = &b->loc; | |
14233 | struct bp_location *hoisted = &head; | |
14234 | ||
14235 | if (pspace == NULL) | |
14236 | { | |
14237 | i = b->loc; | |
14238 | b->loc = NULL; | |
14239 | return i; | |
14240 | } | |
14241 | ||
14242 | head.next = NULL; | |
14243 | ||
14244 | while (i != NULL) | |
14245 | { | |
14246 | if (i->pspace == pspace) | |
14247 | { | |
14248 | *i_link = i->next; | |
14249 | i->next = NULL; | |
14250 | hoisted->next = i; | |
14251 | hoisted = i; | |
14252 | } | |
14253 | else | |
14254 | i_link = &i->next; | |
14255 | i = *i_link; | |
14256 | } | |
14257 | ||
14258 | return head.next; | |
14259 | } | |
14260 | ||
14261 | /* Create new breakpoint locations for B (a hardware or software | |
14262 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not | |
14263 | zero, then B is a ranged breakpoint. Only recreates locations for | |
14264 | FILTER_PSPACE. Locations of other program spaces are left | |
14265 | untouched. */ | |
f1310107 | 14266 | |
0e30163f | 14267 | void |
0d381245 | 14268 | update_breakpoint_locations (struct breakpoint *b, |
c2f4122d | 14269 | struct program_space *filter_pspace, |
f1310107 TJB |
14270 | struct symtabs_and_lines sals, |
14271 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
14272 | { |
14273 | int i; | |
c2f4122d | 14274 | struct bp_location *existing_locations; |
0d381245 | 14275 | |
f8eba3c6 TT |
14276 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
14277 | { | |
14278 | /* Ranged breakpoints have only one start location and one end | |
14279 | location. */ | |
14280 | b->enable_state = bp_disabled; | |
44702360 | 14281 | update_global_location_list (UGLL_MAY_INSERT); |
f8eba3c6 TT |
14282 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
14283 | "multiple locations found\n"), | |
14284 | b->number); | |
14285 | return; | |
14286 | } | |
f1310107 | 14287 | |
4a64f543 MS |
14288 | /* If there's no new locations, and all existing locations are |
14289 | pending, don't do anything. This optimizes the common case where | |
14290 | all locations are in the same shared library, that was unloaded. | |
14291 | We'd like to retain the location, so that when the library is | |
14292 | loaded again, we don't loose the enabled/disabled status of the | |
14293 | individual locations. */ | |
c2f4122d | 14294 | if (all_locations_are_pending (b, filter_pspace) && sals.nelts == 0) |
fe3f5fa8 VP |
14295 | return; |
14296 | ||
c2f4122d | 14297 | existing_locations = hoist_existing_locations (b, filter_pspace); |
fe3f5fa8 | 14298 | |
0d381245 | 14299 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 14300 | { |
f8eba3c6 TT |
14301 | struct bp_location *new_loc; |
14302 | ||
14303 | switch_to_program_space_and_thread (sals.sals[i].pspace); | |
14304 | ||
14305 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); | |
fe3f5fa8 | 14306 | |
0d381245 VP |
14307 | /* Reparse conditions, they might contain references to the |
14308 | old symtab. */ | |
14309 | if (b->cond_string != NULL) | |
14310 | { | |
bbc13ae3 | 14311 | const char *s; |
fe3f5fa8 | 14312 | |
0d381245 | 14313 | s = b->cond_string; |
492d29ea | 14314 | TRY |
0d381245 | 14315 | { |
1bb9788d TT |
14316 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
14317 | block_for_pc (sals.sals[i].pc), | |
0d381245 VP |
14318 | 0); |
14319 | } | |
492d29ea | 14320 | CATCH (e, RETURN_MASK_ERROR) |
0d381245 | 14321 | { |
3e43a32a MS |
14322 | warning (_("failed to reevaluate condition " |
14323 | "for breakpoint %d: %s"), | |
0d381245 VP |
14324 | b->number, e.message); |
14325 | new_loc->enabled = 0; | |
14326 | } | |
492d29ea | 14327 | END_CATCH |
0d381245 | 14328 | } |
fe3f5fa8 | 14329 | |
f1310107 TJB |
14330 | if (sals_end.nelts) |
14331 | { | |
14332 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
14333 | ||
14334 | new_loc->length = end - sals.sals[0].pc + 1; | |
14335 | } | |
0d381245 | 14336 | } |
fe3f5fa8 | 14337 | |
4a64f543 MS |
14338 | /* If possible, carry over 'disable' status from existing |
14339 | breakpoints. */ | |
0d381245 VP |
14340 | { |
14341 | struct bp_location *e = existing_locations; | |
776592bf DE |
14342 | /* If there are multiple breakpoints with the same function name, |
14343 | e.g. for inline functions, comparing function names won't work. | |
14344 | Instead compare pc addresses; this is just a heuristic as things | |
14345 | may have moved, but in practice it gives the correct answer | |
14346 | often enough until a better solution is found. */ | |
14347 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
14348 | ||
0d381245 VP |
14349 | for (; e; e = e->next) |
14350 | { | |
14351 | if (!e->enabled && e->function_name) | |
14352 | { | |
14353 | struct bp_location *l = b->loc; | |
776592bf DE |
14354 | if (have_ambiguous_names) |
14355 | { | |
14356 | for (; l; l = l->next) | |
f1310107 | 14357 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
14358 | { |
14359 | l->enabled = 0; | |
14360 | break; | |
14361 | } | |
14362 | } | |
14363 | else | |
14364 | { | |
14365 | for (; l; l = l->next) | |
14366 | if (l->function_name | |
14367 | && strcmp (e->function_name, l->function_name) == 0) | |
14368 | { | |
14369 | l->enabled = 0; | |
14370 | break; | |
14371 | } | |
14372 | } | |
0d381245 VP |
14373 | } |
14374 | } | |
14375 | } | |
fe3f5fa8 | 14376 | |
8d3788bd VP |
14377 | if (!locations_are_equal (existing_locations, b->loc)) |
14378 | observer_notify_breakpoint_modified (b); | |
14379 | ||
44702360 | 14380 | update_global_location_list (UGLL_MAY_INSERT); |
fe3f5fa8 VP |
14381 | } |
14382 | ||
f00aae0f | 14383 | /* Find the SaL locations corresponding to the given LOCATION. |
ef23e705 TJB |
14384 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
14385 | ||
14386 | static struct symtabs_and_lines | |
f00aae0f | 14387 | location_to_sals (struct breakpoint *b, struct event_location *location, |
c2f4122d | 14388 | struct program_space *search_pspace, int *found) |
ef23e705 | 14389 | { |
02d20e4a | 14390 | struct symtabs_and_lines sals = {0}; |
492d29ea | 14391 | struct gdb_exception exception = exception_none; |
ef23e705 | 14392 | |
983af33b | 14393 | gdb_assert (b->ops != NULL); |
ef23e705 | 14394 | |
492d29ea | 14395 | TRY |
ef23e705 | 14396 | { |
c2f4122d | 14397 | b->ops->decode_location (b, location, search_pspace, &sals); |
ef23e705 | 14398 | } |
492d29ea | 14399 | CATCH (e, RETURN_MASK_ERROR) |
ef23e705 TJB |
14400 | { |
14401 | int not_found_and_ok = 0; | |
492d29ea PA |
14402 | |
14403 | exception = e; | |
14404 | ||
ef23e705 TJB |
14405 | /* For pending breakpoints, it's expected that parsing will |
14406 | fail until the right shared library is loaded. User has | |
14407 | already told to create pending breakpoints and don't need | |
14408 | extra messages. If breakpoint is in bp_shlib_disabled | |
14409 | state, then user already saw the message about that | |
14410 | breakpoint being disabled, and don't want to see more | |
14411 | errors. */ | |
58438ac1 | 14412 | if (e.error == NOT_FOUND_ERROR |
c2f4122d PA |
14413 | && (b->condition_not_parsed |
14414 | || (b->loc != NULL | |
14415 | && search_pspace != NULL | |
14416 | && b->loc->pspace != search_pspace) | |
ef23e705 | 14417 | || (b->loc && b->loc->shlib_disabled) |
f8eba3c6 | 14418 | || (b->loc && b->loc->pspace->executing_startup) |
ef23e705 TJB |
14419 | || b->enable_state == bp_disabled)) |
14420 | not_found_and_ok = 1; | |
14421 | ||
14422 | if (!not_found_and_ok) | |
14423 | { | |
14424 | /* We surely don't want to warn about the same breakpoint | |
14425 | 10 times. One solution, implemented here, is disable | |
14426 | the breakpoint on error. Another solution would be to | |
14427 | have separate 'warning emitted' flag. Since this | |
14428 | happens only when a binary has changed, I don't know | |
14429 | which approach is better. */ | |
14430 | b->enable_state = bp_disabled; | |
14431 | throw_exception (e); | |
14432 | } | |
14433 | } | |
492d29ea | 14434 | END_CATCH |
ef23e705 | 14435 | |
492d29ea | 14436 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
ef23e705 | 14437 | { |
f8eba3c6 | 14438 | int i; |
ef23e705 | 14439 | |
f8eba3c6 TT |
14440 | for (i = 0; i < sals.nelts; ++i) |
14441 | resolve_sal_pc (&sals.sals[i]); | |
f00aae0f | 14442 | if (b->condition_not_parsed && b->extra_string != NULL) |
ef23e705 | 14443 | { |
ed1d1739 KS |
14444 | char *cond_string, *extra_string; |
14445 | int thread, task; | |
ef23e705 | 14446 | |
f00aae0f | 14447 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
e7e0cddf SS |
14448 | &cond_string, &thread, &task, |
14449 | &extra_string); | |
f00aae0f | 14450 | gdb_assert (b->cond_string == NULL); |
ef23e705 TJB |
14451 | if (cond_string) |
14452 | b->cond_string = cond_string; | |
14453 | b->thread = thread; | |
14454 | b->task = task; | |
e7e0cddf | 14455 | if (extra_string) |
f00aae0f KS |
14456 | { |
14457 | xfree (b->extra_string); | |
14458 | b->extra_string = extra_string; | |
14459 | } | |
ef23e705 TJB |
14460 | b->condition_not_parsed = 0; |
14461 | } | |
14462 | ||
983af33b | 14463 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
ef23e705 | 14464 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
ef23e705 | 14465 | |
58438ac1 TT |
14466 | *found = 1; |
14467 | } | |
14468 | else | |
14469 | *found = 0; | |
ef23e705 TJB |
14470 | |
14471 | return sals; | |
14472 | } | |
14473 | ||
348d480f PA |
14474 | /* The default re_set method, for typical hardware or software |
14475 | breakpoints. Reevaluate the breakpoint and recreate its | |
14476 | locations. */ | |
14477 | ||
14478 | static void | |
28010a5d | 14479 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
14480 | { |
14481 | int found; | |
f1310107 | 14482 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 14483 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 14484 | struct symtabs_and_lines expanded_end = {0}; |
c2f4122d | 14485 | struct program_space *filter_pspace = current_program_space; |
ef23e705 | 14486 | |
c2f4122d | 14487 | sals = location_to_sals (b, b->location, filter_pspace, &found); |
ef23e705 TJB |
14488 | if (found) |
14489 | { | |
14490 | make_cleanup (xfree, sals.sals); | |
f8eba3c6 | 14491 | expanded = sals; |
ef23e705 TJB |
14492 | } |
14493 | ||
f00aae0f | 14494 | if (b->location_range_end != NULL) |
f1310107 | 14495 | { |
c2f4122d PA |
14496 | sals_end = location_to_sals (b, b->location_range_end, |
14497 | filter_pspace, &found); | |
f1310107 TJB |
14498 | if (found) |
14499 | { | |
14500 | make_cleanup (xfree, sals_end.sals); | |
f8eba3c6 | 14501 | expanded_end = sals_end; |
f1310107 TJB |
14502 | } |
14503 | } | |
14504 | ||
c2f4122d | 14505 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
28010a5d PA |
14506 | } |
14507 | ||
983af33b SDJ |
14508 | /* Default method for creating SALs from an address string. It basically |
14509 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ | |
14510 | ||
14511 | static void | |
f00aae0f KS |
14512 | create_sals_from_location_default (const struct event_location *location, |
14513 | struct linespec_result *canonical, | |
14514 | enum bptype type_wanted) | |
983af33b | 14515 | { |
f00aae0f | 14516 | parse_breakpoint_sals (location, canonical); |
983af33b SDJ |
14517 | } |
14518 | ||
14519 | /* Call create_breakpoints_sal for the given arguments. This is the default | |
14520 | function for the `create_breakpoints_sal' method of | |
14521 | breakpoint_ops. */ | |
14522 | ||
14523 | static void | |
14524 | create_breakpoints_sal_default (struct gdbarch *gdbarch, | |
14525 | struct linespec_result *canonical, | |
983af33b | 14526 | char *cond_string, |
e7e0cddf | 14527 | char *extra_string, |
983af33b SDJ |
14528 | enum bptype type_wanted, |
14529 | enum bpdisp disposition, | |
14530 | int thread, | |
14531 | int task, int ignore_count, | |
14532 | const struct breakpoint_ops *ops, | |
14533 | int from_tty, int enabled, | |
44f238bb | 14534 | int internal, unsigned flags) |
983af33b SDJ |
14535 | { |
14536 | create_breakpoints_sal (gdbarch, canonical, cond_string, | |
e7e0cddf | 14537 | extra_string, |
983af33b SDJ |
14538 | type_wanted, disposition, |
14539 | thread, task, ignore_count, ops, from_tty, | |
44f238bb | 14540 | enabled, internal, flags); |
983af33b SDJ |
14541 | } |
14542 | ||
14543 | /* Decode the line represented by S by calling decode_line_full. This is the | |
5f700d83 | 14544 | default function for the `decode_location' method of breakpoint_ops. */ |
983af33b SDJ |
14545 | |
14546 | static void | |
f00aae0f KS |
14547 | decode_location_default (struct breakpoint *b, |
14548 | const struct event_location *location, | |
c2f4122d | 14549 | struct program_space *search_pspace, |
983af33b SDJ |
14550 | struct symtabs_and_lines *sals) |
14551 | { | |
14552 | struct linespec_result canonical; | |
14553 | ||
14554 | init_linespec_result (&canonical); | |
c2f4122d | 14555 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
983af33b SDJ |
14556 | (struct symtab *) NULL, 0, |
14557 | &canonical, multiple_symbols_all, | |
14558 | b->filter); | |
14559 | ||
14560 | /* We should get 0 or 1 resulting SALs. */ | |
14561 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); | |
14562 | ||
14563 | if (VEC_length (linespec_sals, canonical.sals) > 0) | |
14564 | { | |
14565 | struct linespec_sals *lsal; | |
14566 | ||
14567 | lsal = VEC_index (linespec_sals, canonical.sals, 0); | |
14568 | *sals = lsal->sals; | |
14569 | /* Arrange it so the destructor does not free the | |
14570 | contents. */ | |
14571 | lsal->sals.sals = NULL; | |
14572 | } | |
14573 | ||
14574 | destroy_linespec_result (&canonical); | |
14575 | } | |
14576 | ||
28010a5d PA |
14577 | /* Prepare the global context for a re-set of breakpoint B. */ |
14578 | ||
14579 | static struct cleanup * | |
14580 | prepare_re_set_context (struct breakpoint *b) | |
14581 | { | |
28010a5d | 14582 | input_radix = b->input_radix; |
28010a5d PA |
14583 | set_language (b->language); |
14584 | ||
c2f4122d | 14585 | return make_cleanup (null_cleanup, NULL); |
ef23e705 TJB |
14586 | } |
14587 | ||
c906108c SS |
14588 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
14589 | The value we return ends up being the return value from catch_errors. | |
14590 | Unused in this case. */ | |
14591 | ||
14592 | static int | |
4efb68b1 | 14593 | breakpoint_re_set_one (void *bint) |
c906108c | 14594 | { |
4a64f543 | 14595 | /* Get past catch_errs. */ |
53a5351d | 14596 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 14597 | struct cleanup *cleanups; |
c906108c | 14598 | |
348d480f PA |
14599 | cleanups = prepare_re_set_context (b); |
14600 | b->ops->re_set (b); | |
14601 | do_cleanups (cleanups); | |
c906108c SS |
14602 | return 0; |
14603 | } | |
14604 | ||
c2f4122d PA |
14605 | /* Re-set breakpoint locations for the current program space. |
14606 | Locations bound to other program spaces are left untouched. */ | |
14607 | ||
c906108c | 14608 | void |
69de3c6a | 14609 | breakpoint_re_set (void) |
c906108c | 14610 | { |
35df4500 | 14611 | struct breakpoint *b, *b_tmp; |
c906108c SS |
14612 | enum language save_language; |
14613 | int save_input_radix; | |
6c95b8df | 14614 | struct cleanup *old_chain; |
c5aa993b | 14615 | |
c906108c SS |
14616 | save_language = current_language->la_language; |
14617 | save_input_radix = input_radix; | |
c2f4122d | 14618 | old_chain = save_current_space_and_thread (); |
6c95b8df | 14619 | |
35df4500 | 14620 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 14621 | { |
4a64f543 | 14622 | /* Format possible error msg. */ |
fe3f5fa8 | 14623 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
14624 | b->number); |
14625 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 14626 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 14627 | do_cleanups (cleanups); |
c5aa993b | 14628 | } |
c906108c SS |
14629 | set_language (save_language); |
14630 | input_radix = save_input_radix; | |
e62c965a | 14631 | |
0756c555 | 14632 | jit_breakpoint_re_set (); |
4efc6507 | 14633 | |
6c95b8df PA |
14634 | do_cleanups (old_chain); |
14635 | ||
af02033e PP |
14636 | create_overlay_event_breakpoint (); |
14637 | create_longjmp_master_breakpoint (); | |
14638 | create_std_terminate_master_breakpoint (); | |
186c406b | 14639 | create_exception_master_breakpoint (); |
c906108c SS |
14640 | } |
14641 | \f | |
c906108c SS |
14642 | /* Reset the thread number of this breakpoint: |
14643 | ||
14644 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 14645 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 14646 | void |
fba45db2 | 14647 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
14648 | { |
14649 | if (b->thread != -1) | |
14650 | { | |
39f77062 | 14651 | if (in_thread_list (inferior_ptid)) |
5d5658a1 | 14652 | b->thread = ptid_to_global_thread_id (inferior_ptid); |
6c95b8df PA |
14653 | |
14654 | /* We're being called after following a fork. The new fork is | |
14655 | selected as current, and unless this was a vfork will have a | |
14656 | different program space from the original thread. Reset that | |
14657 | as well. */ | |
14658 | b->loc->pspace = current_program_space; | |
c906108c SS |
14659 | } |
14660 | } | |
14661 | ||
03ac34d5 MS |
14662 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14663 | If from_tty is nonzero, it prints a message to that effect, | |
14664 | which ends with a period (no newline). */ | |
14665 | ||
c906108c | 14666 | void |
fba45db2 | 14667 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 14668 | { |
52f0bd74 | 14669 | struct breakpoint *b; |
c906108c SS |
14670 | |
14671 | if (count < 0) | |
14672 | count = 0; | |
14673 | ||
14674 | ALL_BREAKPOINTS (b) | |
14675 | if (b->number == bptnum) | |
c5aa993b | 14676 | { |
d77f58be SS |
14677 | if (is_tracepoint (b)) |
14678 | { | |
14679 | if (from_tty && count != 0) | |
14680 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
14681 | bptnum); | |
14682 | return; | |
14683 | } | |
14684 | ||
c5aa993b | 14685 | b->ignore_count = count; |
221ea385 KS |
14686 | if (from_tty) |
14687 | { | |
14688 | if (count == 0) | |
3e43a32a MS |
14689 | printf_filtered (_("Will stop next time " |
14690 | "breakpoint %d is reached."), | |
221ea385 KS |
14691 | bptnum); |
14692 | else if (count == 1) | |
a3f17187 | 14693 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
14694 | bptnum); |
14695 | else | |
3e43a32a MS |
14696 | printf_filtered (_("Will ignore next %d " |
14697 | "crossings of breakpoint %d."), | |
221ea385 KS |
14698 | count, bptnum); |
14699 | } | |
8d3788bd | 14700 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
14701 | return; |
14702 | } | |
c906108c | 14703 | |
8a3fe4f8 | 14704 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
14705 | } |
14706 | ||
c906108c SS |
14707 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
14708 | ||
14709 | static void | |
fba45db2 | 14710 | ignore_command (char *args, int from_tty) |
c906108c SS |
14711 | { |
14712 | char *p = args; | |
52f0bd74 | 14713 | int num; |
c906108c SS |
14714 | |
14715 | if (p == 0) | |
e2e0b3e5 | 14716 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 14717 | |
c906108c | 14718 | num = get_number (&p); |
5c44784c | 14719 | if (num == 0) |
8a3fe4f8 | 14720 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 14721 | if (*p == 0) |
8a3fe4f8 | 14722 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
14723 | |
14724 | set_ignore_count (num, | |
14725 | longest_to_int (value_as_long (parse_and_eval (p))), | |
14726 | from_tty); | |
221ea385 KS |
14727 | if (from_tty) |
14728 | printf_filtered ("\n"); | |
c906108c SS |
14729 | } |
14730 | \f | |
14731 | /* Call FUNCTION on each of the breakpoints | |
14732 | whose numbers are given in ARGS. */ | |
14733 | ||
14734 | static void | |
95a42b64 TT |
14735 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
14736 | void *), | |
14737 | void *data) | |
c906108c | 14738 | { |
52f0bd74 AC |
14739 | int num; |
14740 | struct breakpoint *b, *tmp; | |
11cf8741 | 14741 | int match; |
197f0a60 | 14742 | struct get_number_or_range_state state; |
c906108c | 14743 | |
b9d61307 | 14744 | if (args == 0 || *args == '\0') |
e2e0b3e5 | 14745 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 14746 | |
197f0a60 TT |
14747 | init_number_or_range (&state, args); |
14748 | ||
14749 | while (!state.finished) | |
c906108c | 14750 | { |
e799154c | 14751 | const char *p = state.string; |
197f0a60 | 14752 | |
11cf8741 | 14753 | match = 0; |
c5aa993b | 14754 | |
197f0a60 | 14755 | num = get_number_or_range (&state); |
5c44784c | 14756 | if (num == 0) |
c5aa993b | 14757 | { |
8a3fe4f8 | 14758 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
14759 | } |
14760 | else | |
14761 | { | |
14762 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
14763 | if (b->number == num) | |
14764 | { | |
11cf8741 | 14765 | match = 1; |
cdac0397 | 14766 | function (b, data); |
11cf8741 | 14767 | break; |
5c44784c | 14768 | } |
11cf8741 | 14769 | if (match == 0) |
a3f17187 | 14770 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 14771 | } |
c906108c SS |
14772 | } |
14773 | } | |
14774 | ||
0d381245 VP |
14775 | static struct bp_location * |
14776 | find_location_by_number (char *number) | |
14777 | { | |
14778 | char *dot = strchr (number, '.'); | |
14779 | char *p1; | |
14780 | int bp_num; | |
14781 | int loc_num; | |
14782 | struct breakpoint *b; | |
14783 | struct bp_location *loc; | |
14784 | ||
14785 | *dot = '\0'; | |
14786 | ||
14787 | p1 = number; | |
197f0a60 | 14788 | bp_num = get_number (&p1); |
0d381245 VP |
14789 | if (bp_num == 0) |
14790 | error (_("Bad breakpoint number '%s'"), number); | |
14791 | ||
14792 | ALL_BREAKPOINTS (b) | |
14793 | if (b->number == bp_num) | |
14794 | { | |
14795 | break; | |
14796 | } | |
14797 | ||
14798 | if (!b || b->number != bp_num) | |
14799 | error (_("Bad breakpoint number '%s'"), number); | |
14800 | ||
14801 | p1 = dot+1; | |
197f0a60 | 14802 | loc_num = get_number (&p1); |
0d381245 VP |
14803 | if (loc_num == 0) |
14804 | error (_("Bad breakpoint location number '%s'"), number); | |
14805 | ||
14806 | --loc_num; | |
14807 | loc = b->loc; | |
14808 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
14809 | ; | |
14810 | if (!loc) | |
14811 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
14812 | ||
14813 | return loc; | |
14814 | } | |
14815 | ||
14816 | ||
1900040c MS |
14817 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
14818 | If from_tty is nonzero, it prints a message to that effect, | |
14819 | which ends with a period (no newline). */ | |
14820 | ||
c906108c | 14821 | void |
fba45db2 | 14822 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
14823 | { |
14824 | /* Never disable a watchpoint scope breakpoint; we want to | |
14825 | hit them when we leave scope so we can delete both the | |
14826 | watchpoint and its scope breakpoint at that time. */ | |
14827 | if (bpt->type == bp_watchpoint_scope) | |
14828 | return; | |
14829 | ||
b5de0fa7 | 14830 | bpt->enable_state = bp_disabled; |
c906108c | 14831 | |
b775012e LM |
14832 | /* Mark breakpoint locations modified. */ |
14833 | mark_breakpoint_modified (bpt); | |
14834 | ||
d248b706 KY |
14835 | if (target_supports_enable_disable_tracepoint () |
14836 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14837 | { | |
14838 | struct bp_location *location; | |
14839 | ||
14840 | for (location = bpt->loc; location; location = location->next) | |
14841 | target_disable_tracepoint (location); | |
14842 | } | |
14843 | ||
44702360 | 14844 | update_global_location_list (UGLL_DONT_INSERT); |
c906108c | 14845 | |
8d3788bd | 14846 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14847 | } |
14848 | ||
51be5b68 PA |
14849 | /* A callback for iterate_over_related_breakpoints. */ |
14850 | ||
14851 | static void | |
14852 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14853 | { | |
14854 | disable_breakpoint (b); | |
14855 | } | |
14856 | ||
95a42b64 TT |
14857 | /* A callback for map_breakpoint_numbers that calls |
14858 | disable_breakpoint. */ | |
14859 | ||
14860 | static void | |
14861 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
14862 | { | |
51be5b68 | 14863 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
14864 | } |
14865 | ||
c906108c | 14866 | static void |
fba45db2 | 14867 | disable_command (char *args, int from_tty) |
c906108c | 14868 | { |
c906108c | 14869 | if (args == 0) |
46c6471b PA |
14870 | { |
14871 | struct breakpoint *bpt; | |
14872 | ||
14873 | ALL_BREAKPOINTS (bpt) | |
14874 | if (user_breakpoint_p (bpt)) | |
14875 | disable_breakpoint (bpt); | |
14876 | } | |
9eaabc75 | 14877 | else |
0d381245 | 14878 | { |
9eaabc75 MW |
14879 | char *num = extract_arg (&args); |
14880 | ||
14881 | while (num) | |
d248b706 | 14882 | { |
9eaabc75 | 14883 | if (strchr (num, '.')) |
b775012e | 14884 | { |
9eaabc75 MW |
14885 | struct bp_location *loc = find_location_by_number (num); |
14886 | ||
14887 | if (loc) | |
14888 | { | |
14889 | if (loc->enabled) | |
14890 | { | |
14891 | loc->enabled = 0; | |
14892 | mark_breakpoint_location_modified (loc); | |
14893 | } | |
14894 | if (target_supports_enable_disable_tracepoint () | |
14895 | && current_trace_status ()->running && loc->owner | |
14896 | && is_tracepoint (loc->owner)) | |
14897 | target_disable_tracepoint (loc); | |
14898 | } | |
44702360 | 14899 | update_global_location_list (UGLL_DONT_INSERT); |
b775012e | 14900 | } |
9eaabc75 MW |
14901 | else |
14902 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); | |
14903 | num = extract_arg (&args); | |
d248b706 | 14904 | } |
0d381245 | 14905 | } |
c906108c SS |
14906 | } |
14907 | ||
14908 | static void | |
816338b5 SS |
14909 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
14910 | int count) | |
c906108c | 14911 | { |
afe38095 | 14912 | int target_resources_ok; |
c906108c SS |
14913 | |
14914 | if (bpt->type == bp_hardware_breakpoint) | |
14915 | { | |
14916 | int i; | |
c5aa993b | 14917 | i = hw_breakpoint_used_count (); |
53a5351d | 14918 | target_resources_ok = |
d92524f1 | 14919 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 14920 | i + 1, 0); |
c906108c | 14921 | if (target_resources_ok == 0) |
8a3fe4f8 | 14922 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 14923 | else if (target_resources_ok < 0) |
8a3fe4f8 | 14924 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
14925 | } |
14926 | ||
cc60f2e3 | 14927 | if (is_watchpoint (bpt)) |
c906108c | 14928 | { |
d07205c2 | 14929 | /* Initialize it just to avoid a GCC false warning. */ |
f486487f | 14930 | enum enable_state orig_enable_state = bp_disabled; |
dde02812 | 14931 | |
492d29ea | 14932 | TRY |
c906108c | 14933 | { |
3a5c3e22 PA |
14934 | struct watchpoint *w = (struct watchpoint *) bpt; |
14935 | ||
1e718ff1 TJB |
14936 | orig_enable_state = bpt->enable_state; |
14937 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 14938 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 14939 | } |
492d29ea | 14940 | CATCH (e, RETURN_MASK_ALL) |
c5aa993b | 14941 | { |
1e718ff1 | 14942 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
14943 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
14944 | bpt->number); | |
14945 | return; | |
c5aa993b | 14946 | } |
492d29ea | 14947 | END_CATCH |
c906108c | 14948 | } |
0101ce28 | 14949 | |
b775012e LM |
14950 | bpt->enable_state = bp_enabled; |
14951 | ||
14952 | /* Mark breakpoint locations modified. */ | |
14953 | mark_breakpoint_modified (bpt); | |
14954 | ||
d248b706 KY |
14955 | if (target_supports_enable_disable_tracepoint () |
14956 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
14957 | { | |
14958 | struct bp_location *location; | |
14959 | ||
14960 | for (location = bpt->loc; location; location = location->next) | |
14961 | target_enable_tracepoint (location); | |
14962 | } | |
14963 | ||
b4c291bb | 14964 | bpt->disposition = disposition; |
816338b5 | 14965 | bpt->enable_count = count; |
44702360 | 14966 | update_global_location_list (UGLL_MAY_INSERT); |
9c97429f | 14967 | |
8d3788bd | 14968 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
14969 | } |
14970 | ||
fe3f5fa8 | 14971 | |
c906108c | 14972 | void |
fba45db2 | 14973 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 14974 | { |
816338b5 | 14975 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
51be5b68 PA |
14976 | } |
14977 | ||
14978 | static void | |
14979 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
14980 | { | |
14981 | enable_breakpoint (bpt); | |
c906108c SS |
14982 | } |
14983 | ||
95a42b64 TT |
14984 | /* A callback for map_breakpoint_numbers that calls |
14985 | enable_breakpoint. */ | |
14986 | ||
14987 | static void | |
14988 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
14989 | { | |
51be5b68 | 14990 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
14991 | } |
14992 | ||
c906108c SS |
14993 | /* The enable command enables the specified breakpoints (or all defined |
14994 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 14995 | in stopping the inferior. */ |
c906108c | 14996 | |
c906108c | 14997 | static void |
fba45db2 | 14998 | enable_command (char *args, int from_tty) |
c906108c | 14999 | { |
c906108c | 15000 | if (args == 0) |
46c6471b PA |
15001 | { |
15002 | struct breakpoint *bpt; | |
15003 | ||
15004 | ALL_BREAKPOINTS (bpt) | |
15005 | if (user_breakpoint_p (bpt)) | |
15006 | enable_breakpoint (bpt); | |
15007 | } | |
9eaabc75 | 15008 | else |
0d381245 | 15009 | { |
9eaabc75 MW |
15010 | char *num = extract_arg (&args); |
15011 | ||
15012 | while (num) | |
d248b706 | 15013 | { |
9eaabc75 | 15014 | if (strchr (num, '.')) |
b775012e | 15015 | { |
9eaabc75 MW |
15016 | struct bp_location *loc = find_location_by_number (num); |
15017 | ||
15018 | if (loc) | |
15019 | { | |
15020 | if (!loc->enabled) | |
15021 | { | |
15022 | loc->enabled = 1; | |
15023 | mark_breakpoint_location_modified (loc); | |
15024 | } | |
15025 | if (target_supports_enable_disable_tracepoint () | |
15026 | && current_trace_status ()->running && loc->owner | |
15027 | && is_tracepoint (loc->owner)) | |
15028 | target_enable_tracepoint (loc); | |
15029 | } | |
44702360 | 15030 | update_global_location_list (UGLL_MAY_INSERT); |
b775012e | 15031 | } |
9eaabc75 MW |
15032 | else |
15033 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); | |
15034 | num = extract_arg (&args); | |
d248b706 | 15035 | } |
0d381245 | 15036 | } |
c906108c SS |
15037 | } |
15038 | ||
816338b5 SS |
15039 | /* This struct packages up disposition data for application to multiple |
15040 | breakpoints. */ | |
15041 | ||
15042 | struct disp_data | |
15043 | { | |
15044 | enum bpdisp disp; | |
15045 | int count; | |
15046 | }; | |
15047 | ||
c906108c | 15048 | static void |
51be5b68 PA |
15049 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
15050 | { | |
816338b5 | 15051 | struct disp_data disp_data = *(struct disp_data *) arg; |
51be5b68 | 15052 | |
816338b5 | 15053 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
51be5b68 PA |
15054 | } |
15055 | ||
15056 | static void | |
15057 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 15058 | { |
816338b5 | 15059 | struct disp_data disp = { disp_disable, 1 }; |
51be5b68 PA |
15060 | |
15061 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15062 | } |
15063 | ||
c906108c | 15064 | static void |
fba45db2 | 15065 | enable_once_command (char *args, int from_tty) |
c906108c | 15066 | { |
51be5b68 | 15067 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
15068 | } |
15069 | ||
816338b5 SS |
15070 | static void |
15071 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) | |
15072 | { | |
15073 | struct disp_data disp = { disp_disable, *(int *) countptr }; | |
15074 | ||
15075 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
15076 | } | |
15077 | ||
15078 | static void | |
15079 | enable_count_command (char *args, int from_tty) | |
15080 | { | |
b9d61307 SM |
15081 | int count; |
15082 | ||
15083 | if (args == NULL) | |
15084 | error_no_arg (_("hit count")); | |
15085 | ||
15086 | count = get_number (&args); | |
816338b5 SS |
15087 | |
15088 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); | |
15089 | } | |
15090 | ||
c906108c | 15091 | static void |
51be5b68 | 15092 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 15093 | { |
816338b5 | 15094 | struct disp_data disp = { disp_del, 1 }; |
51be5b68 PA |
15095 | |
15096 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
15097 | } |
15098 | ||
c906108c | 15099 | static void |
fba45db2 | 15100 | enable_delete_command (char *args, int from_tty) |
c906108c | 15101 | { |
51be5b68 | 15102 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
15103 | } |
15104 | \f | |
fa8d40ab JJ |
15105 | static void |
15106 | set_breakpoint_cmd (char *args, int from_tty) | |
15107 | { | |
15108 | } | |
15109 | ||
15110 | static void | |
15111 | show_breakpoint_cmd (char *args, int from_tty) | |
15112 | { | |
15113 | } | |
15114 | ||
1f3b5d1b PP |
15115 | /* Invalidate last known value of any hardware watchpoint if |
15116 | the memory which that value represents has been written to by | |
15117 | GDB itself. */ | |
15118 | ||
15119 | static void | |
8de0566d YQ |
15120 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
15121 | CORE_ADDR addr, ssize_t len, | |
1f3b5d1b PP |
15122 | const bfd_byte *data) |
15123 | { | |
15124 | struct breakpoint *bp; | |
15125 | ||
15126 | ALL_BREAKPOINTS (bp) | |
15127 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 15128 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 15129 | { |
3a5c3e22 | 15130 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 15131 | |
3a5c3e22 PA |
15132 | if (wp->val_valid && wp->val) |
15133 | { | |
15134 | struct bp_location *loc; | |
15135 | ||
15136 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
15137 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
15138 | && loc->address + loc->length > addr | |
15139 | && addr + len > loc->address) | |
15140 | { | |
15141 | value_free (wp->val); | |
15142 | wp->val = NULL; | |
15143 | wp->val_valid = 0; | |
15144 | } | |
15145 | } | |
1f3b5d1b PP |
15146 | } |
15147 | } | |
15148 | ||
8181d85f DJ |
15149 | /* Create and insert a breakpoint for software single step. */ |
15150 | ||
15151 | void | |
6c95b8df | 15152 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
15153 | struct address_space *aspace, |
15154 | CORE_ADDR next_pc) | |
8181d85f | 15155 | { |
7c16b83e PA |
15156 | struct thread_info *tp = inferior_thread (); |
15157 | struct symtab_and_line sal; | |
15158 | CORE_ADDR pc = next_pc; | |
8181d85f | 15159 | |
34b7e8a6 PA |
15160 | if (tp->control.single_step_breakpoints == NULL) |
15161 | { | |
15162 | tp->control.single_step_breakpoints | |
5d5658a1 | 15163 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
34b7e8a6 | 15164 | } |
8181d85f | 15165 | |
7c16b83e PA |
15166 | sal = find_pc_line (pc, 0); |
15167 | sal.pc = pc; | |
15168 | sal.section = find_pc_overlay (pc); | |
15169 | sal.explicit_pc = 1; | |
34b7e8a6 | 15170 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
8181d85f | 15171 | |
7c16b83e | 15172 | update_global_location_list (UGLL_INSERT); |
8181d85f DJ |
15173 | } |
15174 | ||
34b7e8a6 | 15175 | /* See breakpoint.h. */ |
f02253f1 HZ |
15176 | |
15177 | int | |
7c16b83e PA |
15178 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
15179 | struct address_space *aspace, | |
15180 | CORE_ADDR pc) | |
1aafd4da | 15181 | { |
7c16b83e | 15182 | struct bp_location *loc; |
1aafd4da | 15183 | |
7c16b83e PA |
15184 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
15185 | if (loc->inserted | |
15186 | && breakpoint_location_address_match (loc, aspace, pc)) | |
15187 | return 1; | |
1aafd4da | 15188 | |
7c16b83e | 15189 | return 0; |
ef370185 JB |
15190 | } |
15191 | ||
15192 | /* Check whether a software single-step breakpoint is inserted at | |
15193 | PC. */ | |
15194 | ||
15195 | int | |
15196 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, | |
15197 | CORE_ADDR pc) | |
15198 | { | |
34b7e8a6 PA |
15199 | struct breakpoint *bpt; |
15200 | ||
15201 | ALL_BREAKPOINTS (bpt) | |
15202 | { | |
15203 | if (bpt->type == bp_single_step | |
15204 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) | |
15205 | return 1; | |
15206 | } | |
15207 | return 0; | |
1aafd4da UW |
15208 | } |
15209 | ||
1042e4c0 SS |
15210 | /* Tracepoint-specific operations. */ |
15211 | ||
15212 | /* Set tracepoint count to NUM. */ | |
15213 | static void | |
15214 | set_tracepoint_count (int num) | |
15215 | { | |
15216 | tracepoint_count = num; | |
4fa62494 | 15217 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
15218 | } |
15219 | ||
70221824 | 15220 | static void |
1042e4c0 SS |
15221 | trace_command (char *arg, int from_tty) |
15222 | { | |
55aa24fb | 15223 | struct breakpoint_ops *ops; |
f00aae0f KS |
15224 | struct event_location *location; |
15225 | struct cleanup *back_to; | |
55aa24fb | 15226 | |
f00aae0f KS |
15227 | location = string_to_event_location (&arg, current_language); |
15228 | back_to = make_cleanup_delete_event_location (location); | |
5b56227b KS |
15229 | if (location != NULL |
15230 | && event_location_type (location) == PROBE_LOCATION) | |
55aa24fb SDJ |
15231 | ops = &tracepoint_probe_breakpoint_ops; |
15232 | else | |
15233 | ops = &tracepoint_breakpoint_ops; | |
15234 | ||
558a9d82 | 15235 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15236 | location, |
15237 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15238 | 0 /* tempflag */, |
15239 | bp_tracepoint /* type_wanted */, | |
15240 | 0 /* Ignore count */, | |
15241 | pending_break_support, | |
15242 | ops, | |
15243 | from_tty, | |
15244 | 1 /* enabled */, | |
15245 | 0 /* internal */, 0); | |
f00aae0f | 15246 | do_cleanups (back_to); |
1042e4c0 SS |
15247 | } |
15248 | ||
70221824 | 15249 | static void |
7a697b8d SS |
15250 | ftrace_command (char *arg, int from_tty) |
15251 | { | |
f00aae0f KS |
15252 | struct event_location *location; |
15253 | struct cleanup *back_to; | |
15254 | ||
15255 | location = string_to_event_location (&arg, current_language); | |
15256 | back_to = make_cleanup_delete_event_location (location); | |
558a9d82 | 15257 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15258 | location, |
15259 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15260 | 0 /* tempflag */, |
15261 | bp_fast_tracepoint /* type_wanted */, | |
15262 | 0 /* Ignore count */, | |
15263 | pending_break_support, | |
15264 | &tracepoint_breakpoint_ops, | |
15265 | from_tty, | |
15266 | 1 /* enabled */, | |
15267 | 0 /* internal */, 0); | |
f00aae0f | 15268 | do_cleanups (back_to); |
0fb4aa4b PA |
15269 | } |
15270 | ||
15271 | /* strace command implementation. Creates a static tracepoint. */ | |
15272 | ||
70221824 | 15273 | static void |
0fb4aa4b PA |
15274 | strace_command (char *arg, int from_tty) |
15275 | { | |
983af33b | 15276 | struct breakpoint_ops *ops; |
f00aae0f KS |
15277 | struct event_location *location; |
15278 | struct cleanup *back_to; | |
983af33b SDJ |
15279 | |
15280 | /* Decide if we are dealing with a static tracepoint marker (`-m'), | |
15281 | or with a normal static tracepoint. */ | |
61012eef | 15282 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
f00aae0f KS |
15283 | { |
15284 | ops = &strace_marker_breakpoint_ops; | |
15285 | location = new_linespec_location (&arg); | |
15286 | } | |
983af33b | 15287 | else |
f00aae0f KS |
15288 | { |
15289 | ops = &tracepoint_breakpoint_ops; | |
15290 | location = string_to_event_location (&arg, current_language); | |
15291 | } | |
983af33b | 15292 | |
f00aae0f | 15293 | back_to = make_cleanup_delete_event_location (location); |
558a9d82 | 15294 | create_breakpoint (get_current_arch (), |
f00aae0f KS |
15295 | location, |
15296 | NULL, 0, arg, 1 /* parse arg */, | |
558a9d82 YQ |
15297 | 0 /* tempflag */, |
15298 | bp_static_tracepoint /* type_wanted */, | |
15299 | 0 /* Ignore count */, | |
15300 | pending_break_support, | |
15301 | ops, | |
15302 | from_tty, | |
15303 | 1 /* enabled */, | |
15304 | 0 /* internal */, 0); | |
f00aae0f | 15305 | do_cleanups (back_to); |
7a697b8d SS |
15306 | } |
15307 | ||
409873ef SS |
15308 | /* Set up a fake reader function that gets command lines from a linked |
15309 | list that was acquired during tracepoint uploading. */ | |
15310 | ||
15311 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 15312 | static int next_cmd; |
409873ef SS |
15313 | |
15314 | static char * | |
15315 | read_uploaded_action (void) | |
15316 | { | |
15317 | char *rslt; | |
15318 | ||
3149d8c1 | 15319 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 15320 | |
3149d8c1 | 15321 | next_cmd++; |
409873ef SS |
15322 | |
15323 | return rslt; | |
15324 | } | |
15325 | ||
00bf0b85 SS |
15326 | /* Given information about a tracepoint as recorded on a target (which |
15327 | can be either a live system or a trace file), attempt to create an | |
15328 | equivalent GDB tracepoint. This is not a reliable process, since | |
15329 | the target does not necessarily have all the information used when | |
15330 | the tracepoint was originally defined. */ | |
15331 | ||
d9b3f62e | 15332 | struct tracepoint * |
00bf0b85 | 15333 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 15334 | { |
409873ef | 15335 | char *addr_str, small_buf[100]; |
d9b3f62e | 15336 | struct tracepoint *tp; |
f00aae0f KS |
15337 | struct event_location *location; |
15338 | struct cleanup *cleanup; | |
fd9b8c24 | 15339 | |
409873ef SS |
15340 | if (utp->at_string) |
15341 | addr_str = utp->at_string; | |
15342 | else | |
15343 | { | |
15344 | /* In the absence of a source location, fall back to raw | |
15345 | address. Since there is no way to confirm that the address | |
15346 | means the same thing as when the trace was started, warn the | |
15347 | user. */ | |
3e43a32a MS |
15348 | warning (_("Uploaded tracepoint %d has no " |
15349 | "source location, using raw address"), | |
409873ef | 15350 | utp->number); |
8c042590 | 15351 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
409873ef SS |
15352 | addr_str = small_buf; |
15353 | } | |
15354 | ||
15355 | /* There's not much we can do with a sequence of bytecodes. */ | |
15356 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
15357 | warning (_("Uploaded tracepoint %d condition " |
15358 | "has no source form, ignoring it"), | |
409873ef | 15359 | utp->number); |
d5551862 | 15360 | |
f00aae0f KS |
15361 | location = string_to_event_location (&addr_str, current_language); |
15362 | cleanup = make_cleanup_delete_event_location (location); | |
8cdf0e15 | 15363 | if (!create_breakpoint (get_current_arch (), |
f00aae0f KS |
15364 | location, |
15365 | utp->cond_string, -1, addr_str, | |
e7e0cddf | 15366 | 0 /* parse cond/thread */, |
8cdf0e15 | 15367 | 0 /* tempflag */, |
0fb4aa4b | 15368 | utp->type /* type_wanted */, |
8cdf0e15 VP |
15369 | 0 /* Ignore count */, |
15370 | pending_break_support, | |
348d480f | 15371 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 15372 | 0 /* from_tty */, |
84f4c1fe | 15373 | utp->enabled /* enabled */, |
44f238bb PA |
15374 | 0 /* internal */, |
15375 | CREATE_BREAKPOINT_FLAGS_INSERTED)) | |
f00aae0f KS |
15376 | { |
15377 | do_cleanups (cleanup); | |
15378 | return NULL; | |
15379 | } | |
15380 | ||
15381 | do_cleanups (cleanup); | |
fd9b8c24 | 15382 | |
409873ef | 15383 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
15384 | tp = get_tracepoint (tracepoint_count); |
15385 | gdb_assert (tp != NULL); | |
d5551862 | 15386 | |
00bf0b85 SS |
15387 | if (utp->pass > 0) |
15388 | { | |
8c042590 PM |
15389 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
15390 | tp->base.number); | |
00bf0b85 | 15391 | |
409873ef | 15392 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
15393 | } |
15394 | ||
409873ef SS |
15395 | /* If we have uploaded versions of the original commands, set up a |
15396 | special-purpose "reader" function and call the usual command line | |
15397 | reader, then pass the result to the breakpoint command-setting | |
15398 | function. */ | |
3149d8c1 | 15399 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 15400 | { |
409873ef | 15401 | struct command_line *cmd_list; |
00bf0b85 | 15402 | |
409873ef | 15403 | this_utp = utp; |
3149d8c1 | 15404 | next_cmd = 0; |
d5551862 | 15405 | |
409873ef SS |
15406 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
15407 | ||
d9b3f62e | 15408 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 15409 | } |
3149d8c1 SS |
15410 | else if (!VEC_empty (char_ptr, utp->actions) |
15411 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
15412 | warning (_("Uploaded tracepoint %d actions " |
15413 | "have no source form, ignoring them"), | |
409873ef | 15414 | utp->number); |
00bf0b85 | 15415 | |
f196051f SS |
15416 | /* Copy any status information that might be available. */ |
15417 | tp->base.hit_count = utp->hit_count; | |
15418 | tp->traceframe_usage = utp->traceframe_usage; | |
15419 | ||
00bf0b85 | 15420 | return tp; |
d9b3f62e | 15421 | } |
00bf0b85 | 15422 | |
1042e4c0 SS |
15423 | /* Print information on tracepoint number TPNUM_EXP, or all if |
15424 | omitted. */ | |
15425 | ||
15426 | static void | |
e5a67952 | 15427 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 15428 | { |
79a45e25 | 15429 | struct ui_out *uiout = current_uiout; |
e5a67952 | 15430 | int num_printed; |
1042e4c0 | 15431 | |
e5a67952 | 15432 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
15433 | |
15434 | if (num_printed == 0) | |
1042e4c0 | 15435 | { |
e5a67952 | 15436 | if (args == NULL || *args == '\0') |
d77f58be SS |
15437 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
15438 | else | |
e5a67952 | 15439 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 15440 | } |
ad443146 SS |
15441 | |
15442 | default_collect_info (); | |
1042e4c0 SS |
15443 | } |
15444 | ||
4a64f543 | 15445 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
15446 | Not supported by all targets. */ |
15447 | static void | |
15448 | enable_trace_command (char *args, int from_tty) | |
15449 | { | |
15450 | enable_command (args, from_tty); | |
15451 | } | |
15452 | ||
4a64f543 | 15453 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
15454 | Not supported by all targets. */ |
15455 | static void | |
15456 | disable_trace_command (char *args, int from_tty) | |
15457 | { | |
15458 | disable_command (args, from_tty); | |
15459 | } | |
15460 | ||
4a64f543 | 15461 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
15462 | static void |
15463 | delete_trace_command (char *arg, int from_tty) | |
15464 | { | |
35df4500 | 15465 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
15466 | |
15467 | dont_repeat (); | |
15468 | ||
15469 | if (arg == 0) | |
15470 | { | |
15471 | int breaks_to_delete = 0; | |
15472 | ||
15473 | /* Delete all breakpoints if no argument. | |
15474 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
15475 | have to be deleted with an explicit breakpoint number |
15476 | argument. */ | |
1042e4c0 | 15477 | ALL_TRACEPOINTS (b) |
46c6471b | 15478 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
15479 | { |
15480 | breaks_to_delete = 1; | |
15481 | break; | |
15482 | } | |
1042e4c0 SS |
15483 | |
15484 | /* Ask user only if there are some breakpoints to delete. */ | |
15485 | if (!from_tty | |
15486 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
15487 | { | |
35df4500 | 15488 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 15489 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 15490 | delete_breakpoint (b); |
1042e4c0 SS |
15491 | } |
15492 | } | |
15493 | else | |
51be5b68 | 15494 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
15495 | } |
15496 | ||
197f0a60 TT |
15497 | /* Helper function for trace_pass_command. */ |
15498 | ||
15499 | static void | |
d9b3f62e | 15500 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 15501 | { |
d9b3f62e | 15502 | tp->pass_count = count; |
6f6484cd | 15503 | observer_notify_breakpoint_modified (&tp->base); |
197f0a60 TT |
15504 | if (from_tty) |
15505 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 15506 | tp->base.number, count); |
197f0a60 TT |
15507 | } |
15508 | ||
1042e4c0 SS |
15509 | /* Set passcount for tracepoint. |
15510 | ||
15511 | First command argument is passcount, second is tracepoint number. | |
15512 | If tracepoint number omitted, apply to most recently defined. | |
15513 | Also accepts special argument "all". */ | |
15514 | ||
15515 | static void | |
15516 | trace_pass_command (char *args, int from_tty) | |
15517 | { | |
d9b3f62e | 15518 | struct tracepoint *t1; |
1042e4c0 | 15519 | unsigned int count; |
1042e4c0 SS |
15520 | |
15521 | if (args == 0 || *args == 0) | |
3e43a32a MS |
15522 | error (_("passcount command requires an " |
15523 | "argument (count + optional TP num)")); | |
1042e4c0 | 15524 | |
4a64f543 | 15525 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 | 15526 | |
529480d0 | 15527 | args = skip_spaces (args); |
1042e4c0 SS |
15528 | if (*args && strncasecmp (args, "all", 3) == 0) |
15529 | { | |
d9b3f62e PA |
15530 | struct breakpoint *b; |
15531 | ||
1042e4c0 | 15532 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
15533 | if (*args) |
15534 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 15535 | |
d9b3f62e | 15536 | ALL_TRACEPOINTS (b) |
197f0a60 | 15537 | { |
d9b3f62e | 15538 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
15539 | trace_pass_set_count (t1, count, from_tty); |
15540 | } | |
15541 | } | |
15542 | else if (*args == '\0') | |
1042e4c0 | 15543 | { |
5fa1d40e | 15544 | t1 = get_tracepoint_by_number (&args, NULL); |
1042e4c0 | 15545 | if (t1) |
197f0a60 TT |
15546 | trace_pass_set_count (t1, count, from_tty); |
15547 | } | |
15548 | else | |
15549 | { | |
15550 | struct get_number_or_range_state state; | |
15551 | ||
15552 | init_number_or_range (&state, args); | |
15553 | while (!state.finished) | |
1042e4c0 | 15554 | { |
5fa1d40e | 15555 | t1 = get_tracepoint_by_number (&args, &state); |
197f0a60 TT |
15556 | if (t1) |
15557 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
15558 | } |
15559 | } | |
1042e4c0 SS |
15560 | } |
15561 | ||
d9b3f62e | 15562 | struct tracepoint * |
1042e4c0 SS |
15563 | get_tracepoint (int num) |
15564 | { | |
15565 | struct breakpoint *t; | |
15566 | ||
15567 | ALL_TRACEPOINTS (t) | |
15568 | if (t->number == num) | |
d9b3f62e | 15569 | return (struct tracepoint *) t; |
1042e4c0 SS |
15570 | |
15571 | return NULL; | |
15572 | } | |
15573 | ||
d5551862 SS |
15574 | /* Find the tracepoint with the given target-side number (which may be |
15575 | different from the tracepoint number after disconnecting and | |
15576 | reconnecting). */ | |
15577 | ||
d9b3f62e | 15578 | struct tracepoint * |
d5551862 SS |
15579 | get_tracepoint_by_number_on_target (int num) |
15580 | { | |
d9b3f62e | 15581 | struct breakpoint *b; |
d5551862 | 15582 | |
d9b3f62e PA |
15583 | ALL_TRACEPOINTS (b) |
15584 | { | |
15585 | struct tracepoint *t = (struct tracepoint *) b; | |
15586 | ||
15587 | if (t->number_on_target == num) | |
15588 | return t; | |
15589 | } | |
d5551862 SS |
15590 | |
15591 | return NULL; | |
15592 | } | |
15593 | ||
1042e4c0 | 15594 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 | 15595 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
5fa1d40e YQ |
15596 | If the argument is missing, the most recent tracepoint |
15597 | (tracepoint_count) is returned. */ | |
15598 | ||
d9b3f62e | 15599 | struct tracepoint * |
197f0a60 | 15600 | get_tracepoint_by_number (char **arg, |
5fa1d40e | 15601 | struct get_number_or_range_state *state) |
1042e4c0 | 15602 | { |
1042e4c0 SS |
15603 | struct breakpoint *t; |
15604 | int tpnum; | |
15605 | char *instring = arg == NULL ? NULL : *arg; | |
15606 | ||
197f0a60 TT |
15607 | if (state) |
15608 | { | |
15609 | gdb_assert (!state->finished); | |
15610 | tpnum = get_number_or_range (state); | |
15611 | } | |
15612 | else if (arg == NULL || *arg == NULL || ! **arg) | |
5fa1d40e | 15613 | tpnum = tracepoint_count; |
1042e4c0 | 15614 | else |
197f0a60 | 15615 | tpnum = get_number (arg); |
1042e4c0 SS |
15616 | |
15617 | if (tpnum <= 0) | |
15618 | { | |
15619 | if (instring && *instring) | |
15620 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
15621 | instring); | |
15622 | else | |
5fa1d40e | 15623 | printf_filtered (_("No previous tracepoint\n")); |
1042e4c0 SS |
15624 | return NULL; |
15625 | } | |
15626 | ||
15627 | ALL_TRACEPOINTS (t) | |
15628 | if (t->number == tpnum) | |
15629 | { | |
d9b3f62e | 15630 | return (struct tracepoint *) t; |
1042e4c0 SS |
15631 | } |
15632 | ||
1042e4c0 SS |
15633 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
15634 | return NULL; | |
15635 | } | |
15636 | ||
d9b3f62e PA |
15637 | void |
15638 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
15639 | { | |
15640 | if (b->thread != -1) | |
15641 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
15642 | ||
15643 | if (b->task != 0) | |
15644 | fprintf_unfiltered (fp, " task %d", b->task); | |
15645 | ||
15646 | fprintf_unfiltered (fp, "\n"); | |
15647 | } | |
15648 | ||
6149aea9 PA |
15649 | /* Save information on user settable breakpoints (watchpoints, etc) to |
15650 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
15651 | on each breakpoint and only include the ones for which it returns | |
15652 | non-zero. */ | |
15653 | ||
1042e4c0 | 15654 | static void |
6149aea9 PA |
15655 | save_breakpoints (char *filename, int from_tty, |
15656 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
15657 | { |
15658 | struct breakpoint *tp; | |
6149aea9 | 15659 | int any = 0; |
1042e4c0 | 15660 | struct cleanup *cleanup; |
a7bdde9e | 15661 | struct ui_file *fp; |
6149aea9 | 15662 | int extra_trace_bits = 0; |
1042e4c0 | 15663 | |
6149aea9 PA |
15664 | if (filename == 0 || *filename == 0) |
15665 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
15666 | |
15667 | /* See if we have anything to save. */ | |
6149aea9 | 15668 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15669 | { |
6149aea9 | 15670 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15671 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
15672 | continue; |
15673 | ||
15674 | /* If we have a filter, only save the breakpoints it accepts. */ | |
15675 | if (filter && !filter (tp)) | |
15676 | continue; | |
15677 | ||
15678 | any = 1; | |
15679 | ||
15680 | if (is_tracepoint (tp)) | |
15681 | { | |
15682 | extra_trace_bits = 1; | |
15683 | ||
15684 | /* We can stop searching. */ | |
15685 | break; | |
15686 | } | |
1042e4c0 | 15687 | } |
6149aea9 PA |
15688 | |
15689 | if (!any) | |
1042e4c0 | 15690 | { |
6149aea9 | 15691 | warning (_("Nothing to save.")); |
1042e4c0 SS |
15692 | return; |
15693 | } | |
15694 | ||
c718be47 PA |
15695 | filename = tilde_expand (filename); |
15696 | cleanup = make_cleanup (xfree, filename); | |
15697 | fp = gdb_fopen (filename, "w"); | |
059fb39f | 15698 | if (!fp) |
6149aea9 PA |
15699 | error (_("Unable to open file '%s' for saving (%s)"), |
15700 | filename, safe_strerror (errno)); | |
a7bdde9e | 15701 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 15702 | |
6149aea9 PA |
15703 | if (extra_trace_bits) |
15704 | save_trace_state_variables (fp); | |
8bf6485c | 15705 | |
6149aea9 | 15706 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 15707 | { |
6149aea9 | 15708 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 15709 | if (!user_breakpoint_p (tp)) |
6149aea9 | 15710 | continue; |
8bf6485c | 15711 | |
6149aea9 PA |
15712 | /* If we have a filter, only save the breakpoints it accepts. */ |
15713 | if (filter && !filter (tp)) | |
15714 | continue; | |
15715 | ||
348d480f | 15716 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 15717 | |
6149aea9 PA |
15718 | /* Note, we can't rely on tp->number for anything, as we can't |
15719 | assume the recreated breakpoint numbers will match. Use $bpnum | |
15720 | instead. */ | |
15721 | ||
15722 | if (tp->cond_string) | |
15723 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
15724 | ||
15725 | if (tp->ignore_count) | |
15726 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
15727 | ||
2d9442cc | 15728 | if (tp->type != bp_dprintf && tp->commands) |
1042e4c0 | 15729 | { |
6c63c96a | 15730 | struct gdb_exception exception; |
a7bdde9e | 15731 | |
6149aea9 | 15732 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 15733 | |
79a45e25 | 15734 | ui_out_redirect (current_uiout, fp); |
492d29ea | 15735 | TRY |
1042e4c0 | 15736 | { |
79a45e25 | 15737 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 15738 | } |
492d29ea PA |
15739 | CATCH (ex, RETURN_MASK_ALL) |
15740 | { | |
6c63c96a | 15741 | ui_out_redirect (current_uiout, NULL); |
492d29ea PA |
15742 | throw_exception (ex); |
15743 | } | |
15744 | END_CATCH | |
1042e4c0 | 15745 | |
6c63c96a | 15746 | ui_out_redirect (current_uiout, NULL); |
a7bdde9e | 15747 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 15748 | } |
6149aea9 PA |
15749 | |
15750 | if (tp->enable_state == bp_disabled) | |
99894e11 | 15751 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
6149aea9 PA |
15752 | |
15753 | /* If this is a multi-location breakpoint, check if the locations | |
15754 | should be individually disabled. Watchpoint locations are | |
15755 | special, and not user visible. */ | |
15756 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
15757 | { | |
15758 | struct bp_location *loc; | |
15759 | int n = 1; | |
15760 | ||
15761 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
15762 | if (!loc->enabled) | |
15763 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
15764 | } | |
1042e4c0 | 15765 | } |
8bf6485c | 15766 | |
6149aea9 | 15767 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
15768 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
15769 | ||
1042e4c0 | 15770 | if (from_tty) |
6149aea9 | 15771 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
c718be47 | 15772 | do_cleanups (cleanup); |
6149aea9 PA |
15773 | } |
15774 | ||
15775 | /* The `save breakpoints' command. */ | |
15776 | ||
15777 | static void | |
15778 | save_breakpoints_command (char *args, int from_tty) | |
15779 | { | |
15780 | save_breakpoints (args, from_tty, NULL); | |
15781 | } | |
15782 | ||
15783 | /* The `save tracepoints' command. */ | |
15784 | ||
15785 | static void | |
15786 | save_tracepoints_command (char *args, int from_tty) | |
15787 | { | |
15788 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
15789 | } |
15790 | ||
15791 | /* Create a vector of all tracepoints. */ | |
15792 | ||
15793 | VEC(breakpoint_p) * | |
eeae04df | 15794 | all_tracepoints (void) |
1042e4c0 SS |
15795 | { |
15796 | VEC(breakpoint_p) *tp_vec = 0; | |
15797 | struct breakpoint *tp; | |
15798 | ||
15799 | ALL_TRACEPOINTS (tp) | |
15800 | { | |
15801 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
15802 | } | |
15803 | ||
15804 | return tp_vec; | |
15805 | } | |
15806 | ||
c906108c | 15807 | \f |
629500fa KS |
15808 | /* This help string is used to consolidate all the help string for specifying |
15809 | locations used by several commands. */ | |
15810 | ||
15811 | #define LOCATION_HELP_STRING \ | |
15812 | "Linespecs are colon-separated lists of location parameters, such as\n\ | |
15813 | source filename, function name, label name, and line number.\n\ | |
15814 | Example: To specify the start of a label named \"the_top\" in the\n\ | |
15815 | function \"fact\" in the file \"factorial.c\", use\n\ | |
15816 | \"factorial.c:fact:the_top\".\n\ | |
15817 | \n\ | |
15818 | Address locations begin with \"*\" and specify an exact address in the\n\ | |
15819 | program. Example: To specify the fourth byte past the start function\n\ | |
15820 | \"main\", use \"*main + 4\".\n\ | |
15821 | \n\ | |
15822 | Explicit locations are similar to linespecs but use an option/argument\n\ | |
15823 | syntax to specify location parameters.\n\ | |
15824 | Example: To specify the start of the label named \"the_top\" in the\n\ | |
15825 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ | |
15826 | -function fact -label the_top\".\n" | |
15827 | ||
4a64f543 MS |
15828 | /* This help string is used for the break, hbreak, tbreak and thbreak |
15829 | commands. It is defined as a macro to prevent duplication. | |
15830 | COMMAND should be a string constant containing the name of the | |
15831 | command. */ | |
629500fa | 15832 | |
31e2b00f | 15833 | #define BREAK_ARGS_HELP(command) \ |
fb7b5af4 SDJ |
15834 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
15835 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ | |
15836 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ | |
d4777acb JM |
15837 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
15838 | `-probe-dtrace' (for a DTrace probe).\n\ | |
629500fa KS |
15839 | LOCATION may be a linespec, address, or explicit location as described\n\ |
15840 | below.\n\ | |
15841 | \n\ | |
dc10affe PA |
15842 | With no LOCATION, uses current execution address of the selected\n\ |
15843 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
15844 | \n\ |
15845 | THREADNUM is the number from \"info threads\".\n\ | |
15846 | CONDITION is a boolean expression.\n\ | |
629500fa | 15847 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
15848 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
15849 | conditions are different.\n\ | |
31e2b00f AS |
15850 | \n\ |
15851 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
15852 | ||
44feb3ce TT |
15853 | /* List of subcommands for "catch". */ |
15854 | static struct cmd_list_element *catch_cmdlist; | |
15855 | ||
15856 | /* List of subcommands for "tcatch". */ | |
15857 | static struct cmd_list_element *tcatch_cmdlist; | |
15858 | ||
9ac4176b | 15859 | void |
44feb3ce | 15860 | add_catch_command (char *name, char *docstring, |
82ae6c8d | 15861 | cmd_sfunc_ftype *sfunc, |
625e8578 | 15862 | completer_ftype *completer, |
44feb3ce TT |
15863 | void *user_data_catch, |
15864 | void *user_data_tcatch) | |
15865 | { | |
15866 | struct cmd_list_element *command; | |
15867 | ||
15868 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15869 | &catch_cmdlist); | |
15870 | set_cmd_sfunc (command, sfunc); | |
15871 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 15872 | set_cmd_completer (command, completer); |
44feb3ce TT |
15873 | |
15874 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
15875 | &tcatch_cmdlist); | |
15876 | set_cmd_sfunc (command, sfunc); | |
15877 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 15878 | set_cmd_completer (command, completer); |
44feb3ce TT |
15879 | } |
15880 | ||
6149aea9 PA |
15881 | static void |
15882 | save_command (char *arg, int from_tty) | |
15883 | { | |
3e43a32a MS |
15884 | printf_unfiltered (_("\"save\" must be followed by " |
15885 | "the name of a save subcommand.\n")); | |
635c7e8a | 15886 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
6149aea9 PA |
15887 | } |
15888 | ||
84f4c1fe PM |
15889 | struct breakpoint * |
15890 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
15891 | void *data) | |
15892 | { | |
35df4500 | 15893 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 15894 | |
35df4500 | 15895 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
15896 | { |
15897 | if ((*callback) (b, data)) | |
15898 | return b; | |
15899 | } | |
15900 | ||
15901 | return NULL; | |
15902 | } | |
15903 | ||
0574c78f GB |
15904 | /* Zero if any of the breakpoint's locations could be a location where |
15905 | functions have been inlined, nonzero otherwise. */ | |
15906 | ||
15907 | static int | |
15908 | is_non_inline_function (struct breakpoint *b) | |
15909 | { | |
15910 | /* The shared library event breakpoint is set on the address of a | |
15911 | non-inline function. */ | |
15912 | if (b->type == bp_shlib_event) | |
15913 | return 1; | |
15914 | ||
15915 | return 0; | |
15916 | } | |
15917 | ||
15918 | /* Nonzero if the specified PC cannot be a location where functions | |
15919 | have been inlined. */ | |
15920 | ||
15921 | int | |
09ac7c10 TT |
15922 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
15923 | const struct target_waitstatus *ws) | |
0574c78f GB |
15924 | { |
15925 | struct breakpoint *b; | |
15926 | struct bp_location *bl; | |
15927 | ||
15928 | ALL_BREAKPOINTS (b) | |
15929 | { | |
15930 | if (!is_non_inline_function (b)) | |
15931 | continue; | |
15932 | ||
15933 | for (bl = b->loc; bl != NULL; bl = bl->next) | |
15934 | { | |
15935 | if (!bl->shlib_disabled | |
09ac7c10 | 15936 | && bpstat_check_location (bl, aspace, pc, ws)) |
0574c78f GB |
15937 | return 1; |
15938 | } | |
15939 | } | |
15940 | ||
15941 | return 0; | |
15942 | } | |
15943 | ||
2f202fde JK |
15944 | /* Remove any references to OBJFILE which is going to be freed. */ |
15945 | ||
15946 | void | |
15947 | breakpoint_free_objfile (struct objfile *objfile) | |
15948 | { | |
15949 | struct bp_location **locp, *loc; | |
15950 | ||
15951 | ALL_BP_LOCATIONS (loc, locp) | |
eb822aa6 | 15952 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
2f202fde JK |
15953 | loc->symtab = NULL; |
15954 | } | |
15955 | ||
2060206e PA |
15956 | void |
15957 | initialize_breakpoint_ops (void) | |
15958 | { | |
15959 | static int initialized = 0; | |
15960 | ||
15961 | struct breakpoint_ops *ops; | |
15962 | ||
15963 | if (initialized) | |
15964 | return; | |
15965 | initialized = 1; | |
15966 | ||
15967 | /* The breakpoint_ops structure to be inherit by all kinds of | |
15968 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
15969 | internal and momentary breakpoints, etc.). */ | |
15970 | ops = &bkpt_base_breakpoint_ops; | |
15971 | *ops = base_breakpoint_ops; | |
15972 | ops->re_set = bkpt_re_set; | |
15973 | ops->insert_location = bkpt_insert_location; | |
15974 | ops->remove_location = bkpt_remove_location; | |
15975 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
5f700d83 | 15976 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
983af33b | 15977 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
5f700d83 | 15978 | ops->decode_location = bkpt_decode_location; |
2060206e PA |
15979 | |
15980 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
15981 | ops = &bkpt_breakpoint_ops; | |
15982 | *ops = bkpt_base_breakpoint_ops; | |
15983 | ops->re_set = bkpt_re_set; | |
15984 | ops->resources_needed = bkpt_resources_needed; | |
15985 | ops->print_it = bkpt_print_it; | |
15986 | ops->print_mention = bkpt_print_mention; | |
15987 | ops->print_recreate = bkpt_print_recreate; | |
15988 | ||
15989 | /* Ranged breakpoints. */ | |
15990 | ops = &ranged_breakpoint_ops; | |
15991 | *ops = bkpt_breakpoint_ops; | |
15992 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
15993 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
15994 | ops->print_it = print_it_ranged_breakpoint; | |
15995 | ops->print_one = print_one_ranged_breakpoint; | |
15996 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
15997 | ops->print_mention = print_mention_ranged_breakpoint; | |
15998 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
15999 | ||
16000 | /* Internal breakpoints. */ | |
16001 | ops = &internal_breakpoint_ops; | |
16002 | *ops = bkpt_base_breakpoint_ops; | |
16003 | ops->re_set = internal_bkpt_re_set; | |
16004 | ops->check_status = internal_bkpt_check_status; | |
16005 | ops->print_it = internal_bkpt_print_it; | |
16006 | ops->print_mention = internal_bkpt_print_mention; | |
16007 | ||
16008 | /* Momentary breakpoints. */ | |
16009 | ops = &momentary_breakpoint_ops; | |
16010 | *ops = bkpt_base_breakpoint_ops; | |
16011 | ops->re_set = momentary_bkpt_re_set; | |
16012 | ops->check_status = momentary_bkpt_check_status; | |
16013 | ops->print_it = momentary_bkpt_print_it; | |
16014 | ops->print_mention = momentary_bkpt_print_mention; | |
16015 | ||
e2e4d78b JK |
16016 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
16017 | ops = &longjmp_breakpoint_ops; | |
16018 | *ops = momentary_breakpoint_ops; | |
16019 | ops->dtor = longjmp_bkpt_dtor; | |
16020 | ||
55aa24fb SDJ |
16021 | /* Probe breakpoints. */ |
16022 | ops = &bkpt_probe_breakpoint_ops; | |
16023 | *ops = bkpt_breakpoint_ops; | |
16024 | ops->insert_location = bkpt_probe_insert_location; | |
16025 | ops->remove_location = bkpt_probe_remove_location; | |
5f700d83 KS |
16026 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
16027 | ops->decode_location = bkpt_probe_decode_location; | |
55aa24fb | 16028 | |
2060206e PA |
16029 | /* Watchpoints. */ |
16030 | ops = &watchpoint_breakpoint_ops; | |
16031 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 16032 | ops->dtor = dtor_watchpoint; |
2060206e PA |
16033 | ops->re_set = re_set_watchpoint; |
16034 | ops->insert_location = insert_watchpoint; | |
16035 | ops->remove_location = remove_watchpoint; | |
16036 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
16037 | ops->check_status = check_status_watchpoint; | |
16038 | ops->resources_needed = resources_needed_watchpoint; | |
16039 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
16040 | ops->print_it = print_it_watchpoint; | |
16041 | ops->print_mention = print_mention_watchpoint; | |
16042 | ops->print_recreate = print_recreate_watchpoint; | |
427cd150 | 16043 | ops->explains_signal = explains_signal_watchpoint; |
2060206e PA |
16044 | |
16045 | /* Masked watchpoints. */ | |
16046 | ops = &masked_watchpoint_breakpoint_ops; | |
16047 | *ops = watchpoint_breakpoint_ops; | |
16048 | ops->insert_location = insert_masked_watchpoint; | |
16049 | ops->remove_location = remove_masked_watchpoint; | |
16050 | ops->resources_needed = resources_needed_masked_watchpoint; | |
16051 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
16052 | ops->print_it = print_it_masked_watchpoint; | |
16053 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
16054 | ops->print_mention = print_mention_masked_watchpoint; | |
16055 | ops->print_recreate = print_recreate_masked_watchpoint; | |
16056 | ||
16057 | /* Tracepoints. */ | |
16058 | ops = &tracepoint_breakpoint_ops; | |
16059 | *ops = base_breakpoint_ops; | |
16060 | ops->re_set = tracepoint_re_set; | |
16061 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
16062 | ops->print_one_detail = tracepoint_print_one_detail; | |
16063 | ops->print_mention = tracepoint_print_mention; | |
16064 | ops->print_recreate = tracepoint_print_recreate; | |
5f700d83 | 16065 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
983af33b | 16066 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
5f700d83 | 16067 | ops->decode_location = tracepoint_decode_location; |
983af33b | 16068 | |
55aa24fb SDJ |
16069 | /* Probe tracepoints. */ |
16070 | ops = &tracepoint_probe_breakpoint_ops; | |
16071 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 KS |
16072 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
16073 | ops->decode_location = tracepoint_probe_decode_location; | |
55aa24fb | 16074 | |
983af33b SDJ |
16075 | /* Static tracepoints with marker (`-m'). */ |
16076 | ops = &strace_marker_breakpoint_ops; | |
16077 | *ops = tracepoint_breakpoint_ops; | |
5f700d83 | 16078 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
983af33b | 16079 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
5f700d83 | 16080 | ops->decode_location = strace_marker_decode_location; |
2060206e PA |
16081 | |
16082 | /* Fork catchpoints. */ | |
16083 | ops = &catch_fork_breakpoint_ops; | |
16084 | *ops = base_breakpoint_ops; | |
16085 | ops->insert_location = insert_catch_fork; | |
16086 | ops->remove_location = remove_catch_fork; | |
16087 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
16088 | ops->print_it = print_it_catch_fork; | |
16089 | ops->print_one = print_one_catch_fork; | |
16090 | ops->print_mention = print_mention_catch_fork; | |
16091 | ops->print_recreate = print_recreate_catch_fork; | |
16092 | ||
16093 | /* Vfork catchpoints. */ | |
16094 | ops = &catch_vfork_breakpoint_ops; | |
16095 | *ops = base_breakpoint_ops; | |
16096 | ops->insert_location = insert_catch_vfork; | |
16097 | ops->remove_location = remove_catch_vfork; | |
16098 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
16099 | ops->print_it = print_it_catch_vfork; | |
16100 | ops->print_one = print_one_catch_vfork; | |
16101 | ops->print_mention = print_mention_catch_vfork; | |
16102 | ops->print_recreate = print_recreate_catch_vfork; | |
16103 | ||
16104 | /* Exec catchpoints. */ | |
16105 | ops = &catch_exec_breakpoint_ops; | |
16106 | *ops = base_breakpoint_ops; | |
16107 | ops->dtor = dtor_catch_exec; | |
16108 | ops->insert_location = insert_catch_exec; | |
16109 | ops->remove_location = remove_catch_exec; | |
16110 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
16111 | ops->print_it = print_it_catch_exec; | |
16112 | ops->print_one = print_one_catch_exec; | |
16113 | ops->print_mention = print_mention_catch_exec; | |
16114 | ops->print_recreate = print_recreate_catch_exec; | |
16115 | ||
edcc5120 TT |
16116 | /* Solib-related catchpoints. */ |
16117 | ops = &catch_solib_breakpoint_ops; | |
16118 | *ops = base_breakpoint_ops; | |
16119 | ops->dtor = dtor_catch_solib; | |
16120 | ops->insert_location = insert_catch_solib; | |
16121 | ops->remove_location = remove_catch_solib; | |
16122 | ops->breakpoint_hit = breakpoint_hit_catch_solib; | |
16123 | ops->check_status = check_status_catch_solib; | |
16124 | ops->print_it = print_it_catch_solib; | |
16125 | ops->print_one = print_one_catch_solib; | |
16126 | ops->print_mention = print_mention_catch_solib; | |
16127 | ops->print_recreate = print_recreate_catch_solib; | |
e7e0cddf SS |
16128 | |
16129 | ops = &dprintf_breakpoint_ops; | |
16130 | *ops = bkpt_base_breakpoint_ops; | |
5c2b4418 | 16131 | ops->re_set = dprintf_re_set; |
e7e0cddf SS |
16132 | ops->resources_needed = bkpt_resources_needed; |
16133 | ops->print_it = bkpt_print_it; | |
16134 | ops->print_mention = bkpt_print_mention; | |
2d9442cc | 16135 | ops->print_recreate = dprintf_print_recreate; |
9d6e6e84 | 16136 | ops->after_condition_true = dprintf_after_condition_true; |
cd1608cc | 16137 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
2060206e PA |
16138 | } |
16139 | ||
8bfd80db YQ |
16140 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
16141 | ||
16142 | static struct cmd_list_element *enablebreaklist = NULL; | |
16143 | ||
c906108c | 16144 | void |
fba45db2 | 16145 | _initialize_breakpoint (void) |
c906108c SS |
16146 | { |
16147 | struct cmd_list_element *c; | |
16148 | ||
2060206e PA |
16149 | initialize_breakpoint_ops (); |
16150 | ||
84acb35a | 16151 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
63644780 | 16152 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
1f3b5d1b | 16153 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 16154 | |
55aa24fb SDJ |
16155 | breakpoint_objfile_key |
16156 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); | |
17450429 | 16157 | |
c906108c SS |
16158 | breakpoint_chain = 0; |
16159 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
16160 | before a breakpoint is set. */ | |
16161 | breakpoint_count = 0; | |
16162 | ||
1042e4c0 SS |
16163 | tracepoint_count = 0; |
16164 | ||
1bedd215 AC |
16165 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
16166 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
16167 | Usage is `ignore N COUNT'.")); | |
c906108c | 16168 | |
1bedd215 AC |
16169 | add_com ("commands", class_breakpoint, commands_command, _("\ |
16170 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
16171 | Give breakpoint number as argument after \"commands\".\n\ |
16172 | With no argument, the targeted breakpoint is the last one set.\n\ | |
16173 | The commands themselves follow starting on the next line.\n\ | |
16174 | Type a line containing \"end\" to indicate the end of them.\n\ | |
16175 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 16176 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 16177 | |
d55637df | 16178 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
1bedd215 | 16179 | Specify breakpoint number N to break only if COND is true.\n\ |
c906108c | 16180 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 16181 | expression to be evaluated whenever breakpoint N is reached.")); |
d55637df | 16182 | set_cmd_completer (c, condition_completer); |
c906108c | 16183 | |
1bedd215 | 16184 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 16185 | Set a temporary breakpoint.\n\ |
c906108c SS |
16186 | Like \"break\" except the breakpoint is only temporary,\n\ |
16187 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
16188 | by using \"enable delete\" on the breakpoint number.\n\ |
16189 | \n" | |
16190 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 16191 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16192 | |
1bedd215 | 16193 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 16194 | Set a hardware assisted breakpoint.\n\ |
c906108c | 16195 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
16196 | some target hardware may not have this support.\n\ |
16197 | \n" | |
16198 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 16199 | set_cmd_completer (c, location_completer); |
c906108c | 16200 | |
1bedd215 | 16201 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 16202 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 16203 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
16204 | so it will be deleted when hit.\n\ |
16205 | \n" | |
16206 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 16207 | set_cmd_completer (c, location_completer); |
c906108c | 16208 | |
1bedd215 AC |
16209 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
16210 | Enable some breakpoints.\n\ | |
c906108c SS |
16211 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16212 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
16213 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16214 | With a subcommand you can enable temporarily."), |
c906108c | 16215 | &enablelist, "enable ", 1, &cmdlist); |
c906108c SS |
16216 | |
16217 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
16218 | ||
84951ab5 | 16219 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 16220 | Enable some breakpoints.\n\ |
c906108c SS |
16221 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
16222 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 16223 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 16224 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 16225 | |
1a966eab AC |
16226 | add_cmd ("once", no_class, enable_once_command, _("\ |
16227 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16228 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
16229 | &enablebreaklist); |
16230 | ||
1a966eab AC |
16231 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16232 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16233 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16234 | &enablebreaklist); |
16235 | ||
816338b5 SS |
16236 | add_cmd ("count", no_class, enable_count_command, _("\ |
16237 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16238 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16239 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
16240 | &enablebreaklist); | |
16241 | ||
1a966eab AC |
16242 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
16243 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
16244 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
16245 | &enablelist); |
16246 | ||
1a966eab AC |
16247 | add_cmd ("once", no_class, enable_once_command, _("\ |
16248 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
16249 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
816338b5 SS |
16250 | &enablelist); |
16251 | ||
16252 | add_cmd ("count", no_class, enable_count_command, _("\ | |
16253 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ | |
16254 | If a breakpoint is hit while enabled in this fashion,\n\ | |
16255 | the count is decremented; when it reaches zero, the breakpoint is disabled."), | |
c906108c SS |
16256 | &enablelist); |
16257 | ||
1bedd215 AC |
16258 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
16259 | Disable some breakpoints.\n\ | |
c906108c SS |
16260 | Arguments are breakpoint numbers with spaces in between.\n\ |
16261 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16262 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
16263 | &disablelist, "disable ", 1, &cmdlist); |
16264 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
16265 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
c906108c | 16266 | |
1a966eab AC |
16267 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
16268 | Disable some breakpoints.\n\ | |
c906108c SS |
16269 | Arguments are breakpoint numbers with spaces in between.\n\ |
16270 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 16271 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 16272 | This command may be abbreviated \"disable\"."), |
c906108c SS |
16273 | &disablelist); |
16274 | ||
1bedd215 AC |
16275 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
16276 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16277 | Arguments are breakpoint numbers with spaces in between.\n\ |
16278 | To delete all breakpoints, give no argument.\n\ | |
16279 | \n\ | |
16280 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 16281 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
16282 | &deletelist, "delete ", 1, &cmdlist); |
16283 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 16284 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 16285 | |
1a966eab AC |
16286 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
16287 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
16288 | Arguments are breakpoint numbers with spaces in between.\n\ |
16289 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 16290 | This command may be abbreviated \"delete\"."), |
c906108c SS |
16291 | &deletelist); |
16292 | ||
1bedd215 | 16293 | add_com ("clear", class_breakpoint, clear_command, _("\ |
629500fa KS |
16294 | Clear breakpoint at specified location.\n\ |
16295 | Argument may be a linespec, explicit, or address location as described below.\n\ | |
1bedd215 AC |
16296 | \n\ |
16297 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
629500fa KS |
16298 | is executing in.\n" |
16299 | "\n" LOCATION_HELP_STRING "\n\ | |
1bedd215 | 16300 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 16301 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 16302 | |
1bedd215 | 16303 | c = add_com ("break", class_breakpoint, break_command, _("\ |
629500fa | 16304 | Set breakpoint at specified location.\n" |
31e2b00f | 16305 | BREAK_ARGS_HELP ("break"))); |
5ba2abeb | 16306 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 16307 | |
c906108c SS |
16308 | add_com_alias ("b", "break", class_run, 1); |
16309 | add_com_alias ("br", "break", class_run, 1); | |
16310 | add_com_alias ("bre", "break", class_run, 1); | |
16311 | add_com_alias ("brea", "break", class_run, 1); | |
16312 | ||
c906108c SS |
16313 | if (dbx_commands) |
16314 | { | |
1bedd215 AC |
16315 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
16316 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
16317 | &stoplist, "stop ", 1, &cmdlist); |
16318 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 16319 | _("Break in function or address."), &stoplist); |
c5aa993b | 16320 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 16321 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
16322 | add_com ("status", class_info, breakpoints_info, _("\ |
16323 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16324 | The \"Type\" column indicates one of:\n\ |
16325 | \tbreakpoint - normal breakpoint\n\ | |
16326 | \twatchpoint - watchpoint\n\ | |
16327 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16328 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16329 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16330 | address and file/line number respectively.\n\ |
16331 | \n\ | |
16332 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16333 | are set to the address of the last breakpoint listed unless the command\n\ |
16334 | is prefixed with \"server \".\n\n\ | |
c906108c | 16335 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16336 | breakpoint set.")); |
c906108c SS |
16337 | } |
16338 | ||
1bedd215 | 16339 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 16340 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
16341 | The \"Type\" column indicates one of:\n\ |
16342 | \tbreakpoint - normal breakpoint\n\ | |
16343 | \twatchpoint - watchpoint\n\ | |
16344 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
16345 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
16346 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
16347 | address and file/line number respectively.\n\ |
16348 | \n\ | |
16349 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16350 | are set to the address of the last breakpoint listed unless the command\n\ |
16351 | is prefixed with \"server \".\n\n\ | |
c906108c | 16352 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 16353 | breakpoint set.")); |
c906108c | 16354 | |
6b04bdb7 MS |
16355 | add_info_alias ("b", "breakpoints", 1); |
16356 | ||
1a966eab AC |
16357 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
16358 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
16359 | The \"Type\" column indicates one of:\n\ |
16360 | \tbreakpoint - normal breakpoint\n\ | |
16361 | \twatchpoint - watchpoint\n\ | |
16362 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
16363 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
16364 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
16365 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
16366 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
16367 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
16368 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
16369 | address and file/line number respectively.\n\ |
16370 | \n\ | |
16371 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
16372 | are set to the address of the last breakpoint listed unless the command\n\ |
16373 | is prefixed with \"server \".\n\n\ | |
c906108c | 16374 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 16375 | breakpoint set."), |
c906108c SS |
16376 | &maintenanceinfolist); |
16377 | ||
44feb3ce TT |
16378 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
16379 | Set catchpoints to catch events."), | |
16380 | &catch_cmdlist, "catch ", | |
16381 | 0/*allow-unknown*/, &cmdlist); | |
16382 | ||
16383 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
16384 | Set temporary catchpoints to catch events."), | |
16385 | &tcatch_cmdlist, "tcatch ", | |
16386 | 0/*allow-unknown*/, &cmdlist); | |
16387 | ||
44feb3ce TT |
16388 | add_catch_command ("fork", _("Catch calls to fork."), |
16389 | catch_fork_command_1, | |
a96d9b2e | 16390 | NULL, |
44feb3ce TT |
16391 | (void *) (uintptr_t) catch_fork_permanent, |
16392 | (void *) (uintptr_t) catch_fork_temporary); | |
16393 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
16394 | catch_fork_command_1, | |
a96d9b2e | 16395 | NULL, |
44feb3ce TT |
16396 | (void *) (uintptr_t) catch_vfork_permanent, |
16397 | (void *) (uintptr_t) catch_vfork_temporary); | |
16398 | add_catch_command ("exec", _("Catch calls to exec."), | |
16399 | catch_exec_command_1, | |
a96d9b2e SDJ |
16400 | NULL, |
16401 | CATCH_PERMANENT, | |
16402 | CATCH_TEMPORARY); | |
edcc5120 TT |
16403 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
16404 | Usage: catch load [REGEX]\n\ | |
16405 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16406 | catch_load_command_1, | |
16407 | NULL, | |
16408 | CATCH_PERMANENT, | |
16409 | CATCH_TEMPORARY); | |
16410 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ | |
16411 | Usage: catch unload [REGEX]\n\ | |
16412 | If REGEX is given, only stop for libraries matching the regular expression."), | |
16413 | catch_unload_command_1, | |
16414 | NULL, | |
16415 | CATCH_PERMANENT, | |
16416 | CATCH_TEMPORARY); | |
c5aa993b | 16417 | |
1bedd215 AC |
16418 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
16419 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16420 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 16421 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16422 | an expression changes.\n\ |
16423 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16424 | the memory to which it refers.")); | |
65d12d83 | 16425 | set_cmd_completer (c, expression_completer); |
c906108c | 16426 | |
1bedd215 AC |
16427 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
16428 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 16429 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 16430 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16431 | an expression is read.\n\ |
16432 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16433 | the memory to which it refers.")); | |
65d12d83 | 16434 | set_cmd_completer (c, expression_completer); |
c906108c | 16435 | |
1bedd215 AC |
16436 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
16437 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 16438 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 16439 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
16440 | an expression is either read or written.\n\ |
16441 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
16442 | the memory to which it refers.")); | |
65d12d83 | 16443 | set_cmd_completer (c, expression_completer); |
c906108c | 16444 | |
d77f58be | 16445 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 16446 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 16447 | |
920d2a44 AC |
16448 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
16449 | respond to changes - contrary to the description. */ | |
85c07804 AC |
16450 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
16451 | &can_use_hw_watchpoints, _("\ | |
16452 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
16453 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
16454 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
16455 | such is available. (However, any hardware watchpoints that were\n\ | |
16456 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
16457 | hardware.)"), |
16458 | NULL, | |
920d2a44 | 16459 | show_can_use_hw_watchpoints, |
85c07804 | 16460 | &setlist, &showlist); |
c906108c SS |
16461 | |
16462 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 16463 | |
1042e4c0 SS |
16464 | /* Tracepoint manipulation commands. */ |
16465 | ||
16466 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
629500fa | 16467 | Set a tracepoint at specified location.\n\ |
1042e4c0 SS |
16468 | \n" |
16469 | BREAK_ARGS_HELP ("trace") "\n\ | |
16470 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16471 | set_cmd_completer (c, location_completer); | |
16472 | ||
16473 | add_com_alias ("tp", "trace", class_alias, 0); | |
16474 | add_com_alias ("tr", "trace", class_alias, 1); | |
16475 | add_com_alias ("tra", "trace", class_alias, 1); | |
16476 | add_com_alias ("trac", "trace", class_alias, 1); | |
16477 | ||
7a697b8d | 16478 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
629500fa | 16479 | Set a fast tracepoint at specified location.\n\ |
7a697b8d SS |
16480 | \n" |
16481 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
16482 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16483 | set_cmd_completer (c, location_completer); | |
16484 | ||
0fb4aa4b | 16485 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
629500fa | 16486 | Set a static tracepoint at location or marker.\n\ |
0fb4aa4b PA |
16487 | \n\ |
16488 | strace [LOCATION] [if CONDITION]\n\ | |
629500fa KS |
16489 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
16490 | or -m MARKER_ID.\n\n\ | |
16491 | If a marker id is specified, probe the marker with that name. With\n\ | |
16492 | no LOCATION, uses current execution address of the selected stack frame.\n\ | |
0fb4aa4b PA |
16493 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
16494 | This collects arbitrary user data passed in the probe point call to the\n\ | |
16495 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
16496 | by printing the $_sdata variable like any other convenience variable.\n\ | |
16497 | \n\ | |
16498 | CONDITION is a boolean expression.\n\ | |
629500fa | 16499 | \n" LOCATION_HELP_STRING "\n\ |
d41c0fc8 PA |
16500 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
16501 | conditions are different.\n\ | |
0fb4aa4b PA |
16502 | \n\ |
16503 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
16504 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
16505 | set_cmd_completer (c, location_completer); | |
16506 | ||
1042e4c0 | 16507 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 16508 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
16509 | Convenience variable \"$tpnum\" contains the number of the\n\ |
16510 | last tracepoint set.")); | |
16511 | ||
16512 | add_info_alias ("tp", "tracepoints", 1); | |
16513 | ||
16514 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
16515 | Delete specified tracepoints.\n\ | |
16516 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16517 | No argument means delete all tracepoints."), | |
16518 | &deletelist); | |
7e20dfcd | 16519 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
1042e4c0 SS |
16520 | |
16521 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
16522 | Disable specified tracepoints.\n\ | |
16523 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16524 | No argument means disable all tracepoints."), | |
16525 | &disablelist); | |
16526 | deprecate_cmd (c, "disable"); | |
16527 | ||
16528 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
16529 | Enable specified tracepoints.\n\ | |
16530 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
16531 | No argument means enable all tracepoints."), | |
16532 | &enablelist); | |
16533 | deprecate_cmd (c, "enable"); | |
16534 | ||
16535 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
16536 | Set the passcount for a tracepoint.\n\ | |
16537 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
16538 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
16539 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
16540 | ||
6149aea9 PA |
16541 | add_prefix_cmd ("save", class_breakpoint, save_command, |
16542 | _("Save breakpoint definitions as a script."), | |
16543 | &save_cmdlist, "save ", | |
16544 | 0/*allow-unknown*/, &cmdlist); | |
16545 | ||
16546 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
16547 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 16548 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
16549 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
16550 | session to restore them."), | |
16551 | &save_cmdlist); | |
16552 | set_cmd_completer (c, filename_completer); | |
16553 | ||
16554 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 16555 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
16556 | Use the 'source' command in another debug session to restore them."), |
16557 | &save_cmdlist); | |
1042e4c0 SS |
16558 | set_cmd_completer (c, filename_completer); |
16559 | ||
6149aea9 PA |
16560 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
16561 | deprecate_cmd (c, "save tracepoints"); | |
16562 | ||
1bedd215 | 16563 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16564 | Breakpoint specific settings\n\ |
16565 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16566 | pending breakpoint behavior"), |
fa8d40ab JJ |
16567 | &breakpoint_set_cmdlist, "set breakpoint ", |
16568 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 16569 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
16570 | Breakpoint specific settings\n\ |
16571 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 16572 | pending breakpoint behavior"), |
fa8d40ab JJ |
16573 | &breakpoint_show_cmdlist, "show breakpoint ", |
16574 | 0/*allow-unknown*/, &showlist); | |
16575 | ||
7915a72c AC |
16576 | add_setshow_auto_boolean_cmd ("pending", no_class, |
16577 | &pending_break_support, _("\ | |
16578 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
16579 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
16580 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
16581 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
16582 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 16583 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 16584 | NULL, |
920d2a44 | 16585 | show_pending_break_support, |
6e1d7d6c AC |
16586 | &breakpoint_set_cmdlist, |
16587 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
16588 | |
16589 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
16590 | |
16591 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
16592 | &automatic_hardware_breakpoints, _("\ | |
16593 | Set automatic usage of hardware breakpoints."), _("\ | |
16594 | Show automatic usage of hardware breakpoints."), _("\ | |
16595 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
16596 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
16597 | a warning will be emitted for such breakpoints."), | |
16598 | NULL, | |
16599 | show_automatic_hardware_breakpoints, | |
16600 | &breakpoint_set_cmdlist, | |
16601 | &breakpoint_show_cmdlist); | |
74960c60 | 16602 | |
a25a5a45 PA |
16603 | add_setshow_boolean_cmd ("always-inserted", class_support, |
16604 | &always_inserted_mode, _("\ | |
74960c60 VP |
16605 | Set mode for inserting breakpoints."), _("\ |
16606 | Show mode for inserting breakpoints."), _("\ | |
a25a5a45 PA |
16607 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
16608 | they're created, kept inserted even when execution stops, and removed\n\ | |
16609 | only when the user deletes them. When this mode is off (the default),\n\ | |
16610 | breakpoints are inserted only when execution continues, and removed\n\ | |
16611 | when execution stops."), | |
72d0e2c5 YQ |
16612 | NULL, |
16613 | &show_always_inserted_mode, | |
16614 | &breakpoint_set_cmdlist, | |
16615 | &breakpoint_show_cmdlist); | |
f1310107 | 16616 | |
b775012e LM |
16617 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
16618 | condition_evaluation_enums, | |
16619 | &condition_evaluation_mode_1, _("\ | |
16620 | Set mode of breakpoint condition evaluation."), _("\ | |
16621 | Show mode of breakpoint condition evaluation."), _("\ | |
d1cda5d9 | 16622 | When this is set to \"host\", breakpoint conditions will be\n\ |
b775012e LM |
16623 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
16624 | breakpoint conditions will be downloaded to the target (if the target\n\ | |
16625 | supports such feature) and conditions will be evaluated on the target's side.\n\ | |
16626 | If this is set to \"auto\" (default), this will be automatically set to\n\ | |
16627 | \"target\" if it supports condition evaluation, otherwise it will\n\ | |
16628 | be set to \"gdb\""), | |
16629 | &set_condition_evaluation_mode, | |
16630 | &show_condition_evaluation_mode, | |
16631 | &breakpoint_set_cmdlist, | |
16632 | &breakpoint_show_cmdlist); | |
16633 | ||
f1310107 TJB |
16634 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
16635 | Set a breakpoint for an address range.\n\ | |
16636 | break-range START-LOCATION, END-LOCATION\n\ | |
16637 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
16638 | LINENUM, for that line in the current file,\n\ | |
16639 | FILE:LINENUM, for that line in that file,\n\ | |
16640 | +OFFSET, for that number of lines after the current line\n\ | |
16641 | or the start of the range\n\ | |
16642 | FUNCTION, for the first line in that function,\n\ | |
16643 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
16644 | *ADDRESS, for the instruction at that address.\n\ | |
16645 | \n\ | |
16646 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
16647 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
16648 | range (including START-LOCATION and END-LOCATION).")); | |
16649 | ||
e7e0cddf | 16650 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
629500fa | 16651 | Set a dynamic printf at specified location.\n\ |
e7e0cddf | 16652 | dprintf location,format string,arg1,arg2,...\n\ |
629500fa KS |
16653 | location may be a linespec, explicit, or address location.\n" |
16654 | "\n" LOCATION_HELP_STRING)); | |
e7e0cddf SS |
16655 | set_cmd_completer (c, location_completer); |
16656 | ||
16657 | add_setshow_enum_cmd ("dprintf-style", class_support, | |
16658 | dprintf_style_enums, &dprintf_style, _("\ | |
16659 | Set the style of usage for dynamic printf."), _("\ | |
16660 | Show the style of usage for dynamic printf."), _("\ | |
16661 | This setting chooses how GDB will do a dynamic printf.\n\ | |
16662 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ | |
16663 | console, as with the \"printf\" command.\n\ | |
16664 | If the value is \"call\", the print is done by calling a function in your\n\ | |
16665 | program; by default printf(), but you can choose a different function or\n\ | |
16666 | output stream by setting dprintf-function and dprintf-channel."), | |
16667 | update_dprintf_commands, NULL, | |
16668 | &setlist, &showlist); | |
16669 | ||
16670 | dprintf_function = xstrdup ("printf"); | |
16671 | add_setshow_string_cmd ("dprintf-function", class_support, | |
16672 | &dprintf_function, _("\ | |
16673 | Set the function to use for dynamic printf"), _("\ | |
16674 | Show the function to use for dynamic printf"), NULL, | |
16675 | update_dprintf_commands, NULL, | |
16676 | &setlist, &showlist); | |
16677 | ||
16678 | dprintf_channel = xstrdup (""); | |
16679 | add_setshow_string_cmd ("dprintf-channel", class_support, | |
16680 | &dprintf_channel, _("\ | |
16681 | Set the channel to use for dynamic printf"), _("\ | |
16682 | Show the channel to use for dynamic printf"), NULL, | |
16683 | update_dprintf_commands, NULL, | |
16684 | &setlist, &showlist); | |
16685 | ||
d3ce09f5 SS |
16686 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
16687 | &disconnected_dprintf, _("\ | |
16688 | Set whether dprintf continues after GDB disconnects."), _("\ | |
16689 | Show whether dprintf continues after GDB disconnects."), _("\ | |
16690 | Use this to let dprintf commands continue to hit and produce output\n\ | |
16691 | even if GDB disconnects or detaches from the target."), | |
16692 | NULL, | |
16693 | NULL, | |
16694 | &setlist, &showlist); | |
16695 | ||
16696 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ | |
16697 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ | |
16698 | (target agent only) This is useful for formatted output in user-defined commands.")); | |
16699 | ||
765dc015 | 16700 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
16701 | |
16702 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
49fa26b0 | 16703 | observer_attach_thread_exit (remove_threaded_breakpoints); |
c906108c | 16704 | } |